Disabling interface index for desired interfaces so that all methods dealing with those indexes (ifup, ifdown, new route, new gateway, etc.) will exit immediately. This is obtained through a new option called "noipconfig". Helpful when dealing with NFS dhcp method like: root=/dev/nfs rw nfsroot=172.21.3.8:/unix/enea_linux_rootfs/user/p2041rdb \ ip=dhcp console=ttyS0,115200 memmap=16M$0xf7000000 \ mem=4080M max_addr=f6ffffff This ports the https://www.cvg.de/people/ensc/0001-added-noipconfig-option.patch change to connman_1.25. In http://patchwork.openembedded.org/patch/57539/ that change is considered too intrusive and specific to be upstreamed. Signed-off-by: George Nita Upstream-Status: Not Applicable diff --git a/src/connman.h b/src/connman.h index db6461f..8f4f4d0 100644 --- a/src/connman.h +++ b/src/connman.h @@ -544,7 +544,8 @@ void __connman_technology_notify_regdom_by_device(struct connman_device *device, #include -int __connman_device_init(const char *device, const char *nodevice); +int __connman_device_init(const char *device, const char *nodevice, + const char *noipconfig); void __connman_device_cleanup(void); void __connman_device_list(DBusMessageIter *iter, void *user_data); diff --git a/src/device.c b/src/device.c index c0683ab..6582c51 100644 --- a/src/device.c +++ b/src/device.c @@ -37,6 +37,7 @@ static GSList *device_list = NULL; static gchar **device_filter = NULL; static gchar **nodevice_filter = NULL; +static gchar **noipconfig_filter = NULL; enum connman_pending_type { PENDING_NONE = 0, @@ -1314,6 +1315,20 @@ done: return device; } +static bool __connman_device_noipconfig(const char *devname) +{ + char **pattern; + + for (pattern = noipconfig_filter; *pattern; pattern++) { + if (g_pattern_match_simple(*pattern, devname) == TRUE) { + DBG("do not configure device %s", devname); + return TRUE; + } + } + + return FALSE; +} + bool __connman_device_isfiltered(const char *devname) { char **pattern; @@ -1403,6 +1418,9 @@ static void cleanup_devices(void) if (index < 0) continue; + if (__connman_device_noipconfig(interfaces[i])) + __connman_inet_disable_index(index); + if (!__connman_inet_get_address_netmask(index, &sin_addr, &sin_mask)) { char *address = g_strdup(inet_ntoa(sin_addr.sin_addr)); @@ -1435,7 +1453,8 @@ static void cleanup_devices(void) g_strfreev(interfaces); } -int __connman_device_init(const char *device, const char *nodevice) +int __connman_device_init(const char *device, const char *nodevice, + const char *noipconfig) { DBG(""); @@ -1445,6 +1464,9 @@ int __connman_device_init(const char *device, const char *nodevice) if (nodevice) nodevice_filter = g_strsplit(nodevice, ",", -1); + if (noipconfig != NULL) + noipconfig_filter = g_strsplit(noipconfig, ",", -1); + cleanup_devices(); return 0; diff --git a/src/inet.c b/src/inet.c index fb37143..d1f2c2f 100644 --- a/src/inet.c +++ b/src/inet.c @@ -55,6 +55,45 @@ ((struct rtattr *) (((uint8_t*) (nmsg)) + \ NLMSG_ALIGN((nmsg)->nlmsg_len))) +static GHashTable *g_disabled_indices; + +static guint g_intptr_hash(gconstpointer p) +{ + uintptr_t v = (uintptr_t)p; + return g_int_hash(&v); +} + +static gboolean g_intptr_equal(gconstpointer p1, + gconstpointer p2) +{ + uintptr_t v1 = (uintptr_t)p1; + uintptr_t v2 = (uintptr_t)p2; + + return g_int_equal(&v1, &v2); +} + +void __connman_inet_disable_index(int index) +{ + connman_info("disabling interface #%d for ipconfig", index); + + if (g_disabled_indices == NULL) + g_disabled_indices = g_hash_table_new_full(g_intptr_hash, + g_intptr_equal, + NULL, NULL); + + g_hash_table_add(g_disabled_indices, (void *)index); +} + +static bool __connman_inet_is_disabled_index(int index) +{ + bool rc; + + rc = (g_disabled_indices != NULL && + g_hash_table_contains(g_disabled_indices, (void *)index)); + + return rc; +} + int __connman_inet_rtnl_addattr_l(struct nlmsghdr *n, size_t max_length, int type, const void *data, size_t data_length) { @@ -98,6 +137,11 @@ int __connman_inet_modify_address(int cmd, int flags, "prefixlen %hhu broadcast %s", cmd, flags, index, family, address, peer, prefixlen, broadcast); + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping %s", __func__); + return 0; + } + if (!address) return -EINVAL; @@ -275,6 +319,11 @@ int connman_inet_ifup(int index) struct ifreq ifr; int sk, err; + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping %s", __func__); + return 0; + } + sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sk < 0) return -errno; @@ -318,6 +367,11 @@ int connman_inet_ifdown(int index) struct sockaddr_in *addr; int sk, err; + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping %s", __func__); + return 0; + } + sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sk < 0) return -errno; @@ -519,6 +573,11 @@ int connman_inet_add_network_route(int index, const char *host, DBG("index %d host %s gateway %s netmask %s", index, host, gateway, netmask); + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping %s", __func__); + return 0; + } + sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sk < 0) { err = -errno; @@ -589,6 +648,11 @@ int connman_inet_del_network_route(int index, const char *host) DBG("index %d host %s", index, host); + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping %s", __func__); + return 0; + } + sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sk < 0) { err = -errno; @@ -637,6 +701,11 @@ int connman_inet_del_ipv6_network_route(int index, const char *host, DBG("index %d host %s", index, host); + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping %s", __func__); + return 0; + } + if (!host) return -EINVAL; @@ -687,6 +756,11 @@ int connman_inet_add_ipv6_network_route(int index, const char *host, DBG("index %d host %s gateway %s", index, host, gateway); + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping %s", __func__); + return 0; + } + if (!host) return -EINVAL; @@ -741,6 +815,11 @@ int connman_inet_clear_ipv6_gateway_address(int index, const char *gateway) DBG("index %d gateway %s", index, gateway); + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping clear_ipv6_gateway operation"); + return 0; + } + if (!gateway) return -EINVAL; @@ -784,6 +863,11 @@ int connman_inet_set_gateway_interface(int index) DBG("index %d", index); + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping %s", __func__); + return 0; + } + sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sk < 0) { err = -errno; @@ -837,6 +921,11 @@ int connman_inet_set_ipv6_gateway_interface(int index) DBG("index %d", index); + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping %s", __func__); + return 0; + } + sk = socket(PF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sk < 0) { err = -errno; @@ -889,6 +978,11 @@ int connman_inet_clear_gateway_address(int index, const char *gateway) DBG("index %d gateway %s", index, gateway); + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping %s", __func__); + return 0; + } + sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sk < 0) { err = -errno; @@ -946,6 +1040,11 @@ int connman_inet_clear_gateway_interface(int index) DBG("index %d", index); + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping %s", __func__); + return 0; + } + sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sk < 0) { err = -errno; @@ -999,6 +1098,11 @@ int connman_inet_clear_ipv6_gateway_interface(int index) DBG("index %d", index); + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping %s", __func__); + return 0; + } + sk = socket(PF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sk < 0) { err = -errno; @@ -1059,6 +1163,11 @@ bool connman_inet_compare_subnet(int index, const char *host) return -1; host_addr = _host_addr.s_addr; + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping %s", __func__); + return 0; + } + sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sk < 0) return false; @@ -1159,6 +1268,11 @@ int connman_inet_set_mtu(int index, int mtu) struct ifreq ifr; int sk, err; + if (__connman_inet_is_disabled_index(index)) { + connman_info("index disabled; skipping %s", __func__); + return 0; + } + sk = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (sk < 0) return sk; diff --git a/src/main.c b/src/main.c index 7cf6c9a..e06f25c 100644 --- a/src/main.c +++ b/src/main.c @@ -453,6 +453,7 @@ static gchar *option_debug = NULL; static gchar *option_device = NULL; static gchar *option_plugin = NULL; static gchar *option_nodevice = NULL; +static gchar *option_noipconfig = NULL; static gchar *option_noplugin = NULL; static gchar *option_wifi = NULL; static gboolean option_detach = TRUE; @@ -482,6 +483,8 @@ static GOptionEntry options[] = { "Specify networking device or interface", "DEV" }, { "nodevice", 'I', 0, G_OPTION_ARG_STRING, &option_nodevice, "Specify networking interface to ignore", "DEV" }, + { "noipconfig", 0, 0, G_OPTION_ARG_STRING, &option_noipconfig, + "Specify networking interface which shall not be configured", "DEV" }, { "plugin", 'p', 0, G_OPTION_ARG_STRING, &option_plugin, "Specify plugins to load", "NAME,..." }, { "noplugin", 'P', 0, G_OPTION_ARG_STRING, &option_noplugin, @@ -648,7 +651,7 @@ int main(int argc, char *argv[]) __connman_provider_init(); __connman_network_init(); __connman_config_init(); - __connman_device_init(option_device, option_nodevice); + __connman_device_init(option_device, option_nodevice, option_noipconfig); __connman_ippool_init(); __connman_iptables_init();