Skip to content

Commit

Permalink
config: Add FallbackDeviceTypes configuration option
Browse files Browse the repository at this point in the history
In some devices some /sys/class/net/<interface>/uevent files might be
completely missing DEVTYPE information. Heuristics exist for detecting
wifi devices, but everything else is assumed to be ethernet device.

For example for rndis interfaces gadget might be more appropriate
device type assumption than ethernet. This can be accomplished by
adding to main.conf, in General section:

FallbackDeviceTypes = rndis0:gadget

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Jan 27, 2020
1 parent a460a4a commit b4dfd0e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions connman/doc/connman.conf.5.in
Expand Up @@ -130,6 +130,12 @@ See RFC6343. Default value is false (as recommended by RFC6343 section 4.1).
Set DHCP option 60 (Vendor Class ID) to the given string. This option can
be used by DHCP servers to identify specific clients without having to
rely on MAC address ranges, etc
.TP
.BI FallbackDeviceTypes= interface:devtype\fR[,...]
If /sys/class/net/<interface>/uevent does not contain DEVTYPE information,
heuristics are used to choose between wifi and ethernet device types. If
neither is appropriate, this setting can be used to provide more suitable
fallback value - e.g. rndis0:gadget.
.SH "EXAMPLE"
The following example configuration disables hostname updates and enables
ethernet tethering.
Expand Down
2 changes: 2 additions & 0 deletions connman/src/connman.h
Expand Up @@ -142,6 +142,8 @@ void __connman_log_enable(struct connman_debug_desc *start,

#include <connman/setting.h>

const char *__connman_setting_get_fallback_device_type(const char *interface);

#include <connman/plugin.h>

int __connman_plugin_init(const char *pattern, const char *exclude);
Expand Down
54 changes: 54 additions & 0 deletions connman/src/main.c
Expand Up @@ -94,6 +94,7 @@ static struct {
mode_t umask;
bool enable_6to4;
char *vendor_class_id;
GHashTable *fallback_device_types;
} connman_settings = {
.bg_scan = true,
.pref_timeservers = NULL,
Expand All @@ -112,6 +113,7 @@ static struct {
.umask = DEFAULT_UMASK,
.enable_6to4 = false,
.vendor_class_id = NULL,
.fallback_device_types = NULL,
};

#define CONF_BG_SCAN "BackgroundScanning"
Expand All @@ -135,6 +137,7 @@ static struct {
#define CONF_UMASK "Umask"
#define CONF_ENABLE_6TO4 "Enable6to4"
#define CONF_VENDOR_CLASS_ID "VendorClassID"
#define CONF_FALLBACK_DEVICE_TYPES "FallbackDeviceTypes"

static const char *supported_options[] = {
CONF_BG_SCAN,
Expand All @@ -161,6 +164,7 @@ static const char *supported_options[] = {
CONF_DISABLE_PLUGINS,
CONF_ENABLE_6TO4,
CONF_VENDOR_CLASS_ID,
CONF_FALLBACK_DEVICE_TYPES,
NULL
};

Expand Down Expand Up @@ -243,6 +247,33 @@ static char **parse_fallback_nameservers(char **nameservers, gsize len)
return servers;
}

static GHashTable *parse_fallback_device_types(char **devtypes, gsize len)
{
GHashTable *h;

h = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);

for (gsize i = 0; i < len; ++i) {
char **v;

v = g_strsplit(devtypes[i], ":", 2);
if (!v)
continue;

if (v[0] && v[1])
g_hash_table_replace(h, g_strdup(v[0]),
g_strdup(v[1]));

g_strfreev(v);
}

if (g_hash_table_size(h) > 0)
return h;

g_hash_table_unref(h);
return NULL;
}

static void check_config(GKeyFile *config)
{
char **keys;
Expand Down Expand Up @@ -493,6 +524,17 @@ static void parse_config(GKeyFile *config)
connman_settings.vendor_class_id = vendor_class_id;

g_clear_error(&error);

str_list = __connman_config_get_string_list(config, "General",
CONF_FALLBACK_DEVICE_TYPES, &len, &error);

if (!error)
connman_settings.fallback_device_types =
parse_fallback_device_types(str_list, len);

g_strfreev(str_list);

g_clear_error(&error);
}

static int config_init(const char *file)
Expand Down Expand Up @@ -767,6 +809,15 @@ unsigned int connman_timeout_browser_launch(void)
return connman_settings.timeout_browserlaunch;
}

const char *__connman_setting_get_fallback_device_type(const char *interface)
{
if (!connman_settings.fallback_device_types)
return NULL;

return g_hash_table_lookup(connman_settings.fallback_device_types,
interface);
}

int main(int argc, char *argv[])
{
GOptionContext *context;
Expand Down Expand Up @@ -986,6 +1037,9 @@ int main(int argc, char *argv[])
g_free(connman_settings.storage_root);
g_free(connman_settings.fs_identity);

if (connman_settings.fallback_device_types)
g_hash_table_unref(connman_settings.fallback_device_types);

g_free(option_debug);
g_free(option_wifi);

Expand Down

0 comments on commit b4dfd0e

Please sign in to comment.