Skip to contentSkip to conversation

Support to disable IPv4LL fallback

PATCH New Adinath Mhatre 1 participant 3 messages Jun 4, 2023

lore
Share & tools
lore
#0 lore raw

cover Support to disable IPv4LL fallback

From: Adinath Mhatre <[email protected]>

In current design of connman, if a client fails to discover
DHCP server, it will fallback to IPv4LL address.
In some systems it is not desirable.
Therefore, added config, D-Bus API and connmanctl option to disable IPv4LL fallback.

Adinath Mhatre (2):
service:config: Support to disable IPv4LL fallback
commands: IPv4LL fallback config support

 client/commands.c               | 50 ++++++++++++++++++---
 doc/config-format.txt           |  5 +++
 doc/connman-service.config.5.in |  6 +++
 doc/connmanctl.1.in             | 10 +++--
 doc/service-api.txt             | 10 +++++
 src/config.c                    | 23 ++++++++++
 src/connman.h                   |  2 +
 src/dhcp.c                      |  7 +++
 src/ipconfig.c                  | 80 +++++++++++++++++++++++++++++++--
 test/set-ipv4-method            | 34 +++++++++++---
 10 files changed, 206 insertions(+), 21 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 service:config: Support to disable IPv4LL fallback

From: Adinath Mhatre <[email protected]>

In current design of connman, if a client fails to discover DHCP server, it will fallback to IPv4LL address.
In some systems it is not desirable.
Therefore, added config and D-Bus API to disable IPv4LL fallback.

---
 doc/config-format.txt           |  5 +++
 doc/connman-service.config.5.in |  6 +++
 doc/service-api.txt             | 10 +++++
 src/config.c                    | 23 ++++++++++
 src/connman.h                   |  2 +
 src/dhcp.c                      |  7 +++
 src/ipconfig.c                  | 80 +++++++++++++++++++++++++++++++--
 test/set-ipv4-method            | 34 +++++++++++---
 8 files changed, 157 insertions(+), 10 deletions(-)
doc/config-format.txt +5 -0
index cdde9cbc..a870a68c 100644
@@ -42,6 +42,11 @@ Allowed fields:
   Example: 192.168.1.2/24/192.168.1.1
            192.168.200.100/255.255.255.0/192.168.200.1
            10.0.0.2/24
+- IPv4.FallbackIPv4LL: Option to disable IPv4LL fallback.
+  IPv4LL fallback is applied when an IPv4 address could not be assigned
+  using DHCP method.
+  If set "false", an IPv4LL address will not be assigned if DHCP failed.
+  Default value is "true".
 - IPv6: The IPv6 address, prefix length and gateway. Format of the entry
   is network/prefixlen/gateway. For IPv6 addresses only prefix length is
   accepted. The gateway can be omitted if necessary.
doc/connman-service.config.5.in +6 -0
index 701f61f9..e83f9d25 100644
@@ -48,6 +48,12 @@ If set to \fBdhcp\fP, dhcp will be used to obtain the network settings.
 \fInetmask\fP can be specified as length of the mask rather than the
 mask itself. The gateway can be omitted when using a static IP.
 .TP
+.B IPv4.FallbackIPv4LL=true \fR|\fB false
+IPv4LL fallback is applied when an IPv4 address could not be assigned
+using DHCP method.
+If set \fBfalse\fP, an IPv4LL address will not be assigned if DHCP failed.
+Default value is \fBtrue\fP.
+.TP
 .BI IPv6=off \ \fR|\  auto\ \fR|\  network / prefixlength / gateway
 IPv6 settings for the service. If set to \fBoff\fP, IPv6 won't be used.
 If set to \fBauto\fP, settings will be obtained from the network.
doc/service-api.txt +10 -0
index c0d5adbb..4f329903 100644
@@ -340,6 +340,16 @@ Properties	string State [readonly]
 
 				The current configured IPv4 gateway.
 
+			boolean FallbackIPv4LL [readonly]
+
+				The current IPv4LL fallback configuration. The
+				value has only meaning if Method is set to "dhcp".
+
+				Value "false" means an IPv4LL address will
+				not be assigned if DHCP failed.
+
+				Default value is "true".
+
 		dict IPv4.Configuration [readwrite]
 
 			Same values as IPv4 property. The IPv4 represents
src/config.c +23 -0
index 33fdc737..476e0d37 100644
@@ -67,6 +67,7 @@ struct connman_config_service {
 	char *ipv4_address;
 	char *ipv4_netmask;
 	char *ipv4_gateway;
+	bool ipv4_fallback_ll;
 	char *ipv6_address;
 	unsigned char ipv6_prefix_length;
 	char *ipv6_gateway;
@@ -117,6 +118,7 @@ static bool cleanup = false;
 #define SERVICE_KEY_MDNS               "mDNS"
 
 #define SERVICE_KEY_IPv4               "IPv4"
+#define SERVICE_KEY_IPv4_FALLBACK_LL   "IPv4.FallbackIPv4LL"
 #define SERVICE_KEY_IPv6               "IPv6"
 #define SERVICE_KEY_IPv6_PRIVACY       "IPv6.Privacy"
 #define SERVICE_KEY_MAC                "MAC"
@@ -153,6 +155,7 @@ static const char *service_possible_keys[] = {
 	SERVICE_KEY_SECURITY,
 	SERVICE_KEY_HIDDEN,
 	SERVICE_KEY_IPv4,
+	SERVICE_KEY_IPv4_FALLBACK_LL,
 	SERVICE_KEY_IPv6,
 	SERVICE_KEY_IPv6_PRIVACY,
 	SERVICE_KEY_MAC,
@@ -444,6 +447,17 @@ static bool load_service_generic(GKeyFile *keyfile,
 		g_free(str);
 	}
 
+	service->ipv4_fallback_ll = true;
+	str = g_key_file_get_value(keyfile, group, SERVICE_KEY_IPv4_FALLBACK_LL, NULL);
+
+	if (str) {
+		str = g_strchomp(str);
+		if (strcmp(str, "false") == 0)
+			service->ipv4_fallback_ll = false;
+
+		g_free(str);
+	}
+
 	str =  __connman_config_get_string(keyfile, group, SERVICE_KEY_IPv6, NULL);
 	if (str && check_address(str, &service->ipv6_address)) {
 		long int value;
@@ -1380,6 +1394,15 @@ static int try_provision_service(struct connman_config_service *config,
 		connman_ipaddress_free(address);
 	}
 
+	if (g_ascii_strcasecmp(config->ipv4_address, "dhcp") == 0) {
+		struct connman_ipconfig *ipconfig;
+
+		ipconfig = __connman_service_get_ip4config(service);
+		if (ipconfig)
+			__connman_ipconfig_set_ipv4_fallback_ll(ipconfig,
+							config->ipv4_fallback_ll);
+	}
+
 	__connman_service_disconnect(service);
 
 	service_id = connman_service_get_identifier(service);
src/connman.h +2 -0
index b955d98b..dae79162 100644
@@ -435,6 +435,8 @@ bool __connman_ipconfig_ipv6_is_enabled(struct connman_ipconfig *ipconfig);
 
 int __connman_ipconfig_set_rp_filter();
 void __connman_ipconfig_unset_rp_filter(int old_value);
+bool __connman_ipconfig_get_ipv4_fallback_ll(struct connman_ipconfig *ipconfig);
+int __connman_ipconfig_set_ipv4_fallback_ll(struct connman_ipconfig *ipconfig, bool val);
 
 #include <connman/utsname.h>
 
src/dhcp.c +7 -0
index 18dbab27..2766252e 100644
@@ -252,6 +252,7 @@ static gboolean dhcp_retry_cb(gpointer user_data)
 static void no_lease_cb(GDHCPClient *dhcp_client, gpointer user_data)
 {
 	struct connman_dhcp *dhcp = user_data;
+	struct connman_service *service;
 	int err;
 
 	DBG("No lease available ipv4ll %d client %p", dhcp->ipv4ll_running,
@@ -266,6 +267,12 @@ static void no_lease_cb(GDHCPClient *dhcp_client, gpointer user_data)
 	if (dhcp->ipv4ll_running)
 		return;
 
+	if (!__connman_ipconfig_get_ipv4_fallback_ll(dhcp->ipconfig)) {
+		service = connman_service_lookup_from_network(dhcp->network);
+		__connman_service_save(service);
+		return;
+	}
+
 	err = ipv4ll_start_client(dhcp);
 	if (err < 0)
 		DBG("Cannot start ipv4ll client (%d/%s)", err, strerror(-err));
src/ipconfig.c +77 -3

163 lines not on this page · raw message

test/set-ipv4-method +27 -7
index 09c194d7..3e949681 100755
@@ -6,8 +6,20 @@ import dbus
 def make_variant(string):
 	return dbus.String(string, variant_level=1)
 
+def make_bool_variant(string):
+        if string == "true":
+                return dbus.Boolean(1)
+        if string == "false":
+                return dbus.Boolean(0)
+        else:
+                print("Invalid argument")
+                sys.exit(1)
+
 def print_usage():
-	print("Usage: %s <service> [off|dhcp|manual <address> [netmask] [gateway]]" % (sys.argv[0]))
+	print(
+                "Usage: %s <service> [off|dhcp|manual [fallback_ipv4ll=true|false] "\
+                "[<address> [netmask] [gateway]]]" % (sys.argv[0])
+        )
 
 
 if (len(sys.argv) < 3):
@@ -24,12 +36,20 @@ properties = service.GetProperties()
 print("Setting method %s for %s" % (sys.argv[2], sys.argv[1]))
 
 ipv4_configuration = { "Method": make_variant(sys.argv[2]) }
-if (len(sys.argv) > 3):
-	ipv4_configuration["Address"] = make_variant(sys.argv[3])
-if (len(sys.argv) > 4):
-	ipv4_configuration["Netmask"] = make_variant(sys.argv[4])
-if (len(sys.argv) > 5):
-        ipv4_configuration["Gateway"] = make_variant(sys.argv[5])
+if (sys.argv[2] == "dhcp") and (len(sys.argv) > 3):
+        if "fallback_ipv4ll=" in sys.argv[3]:
+                bool_val = sys.argv[3].split("fallback_ipv4ll=", 1)[1]
+                ipv4_configuration["FallbackIPv4LL"] = make_bool_variant(bool_val)
+        else:
+                print("Invalid argument")
+                sys.exit(1)
+else:
+	if (len(sys.argv) > 3):
+		ipv4_configuration["Address"] = make_variant(sys.argv[3])
+	if (len(sys.argv) > 4):
+		ipv4_configuration["Netmask"] = make_variant(sys.argv[4])
+	if (len(sys.argv) > 5):
+		ipv4_configuration["Gateway"] = make_variant(sys.argv[5])
 
 service.SetProperty("IPv4.Configuration", ipv4_configuration)
 print("New IPv4.Configuration: ", ipv4_configuration)
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/2 commands: IPv4LL fallback config support

In reply to Adinath Mhatre

From: Adinath Mhatre <[email protected]>

Added support to set IPv4LL fallback configuration from connmanctl.

---
 client/commands.c   | 50 ++++++++++++++++++++++++++++++++++++++-------
 doc/connmanctl.1.in | 10 +++++----
 2 files changed, 49 insertions(+), 11 deletions(-)
client/commands.c +43 -7
index 53cc14c8..c967102f 100644
@@ -985,18 +985,53 @@ static void config_append_ipv4(DBusMessageIter *iter,
 {
 	struct config_append *append = user_data;
 	char **opts = append->opts;
-	int i = 0;
 
 	if (!opts)
 		return;
 
-	while (opts[i] && ipv4[i]) {
-		__connmanctl_dbus_append_dict_entry(iter, ipv4[i],
-				DBUS_TYPE_STRING, &opts[i]);
-		i++;
+	append->values = 1;
+
+	if (g_strcmp0(opts[0], "dhcp") == 0) {
+		dbus_bool_t val;
+
+		append->values = 2;
+
+		if (opts[1]) {
+			switch (parse_boolean(opts[1])) {
+			case 1:
+				val = TRUE;
+				break;
+			case 0:
+				val = FALSE;
+				break;
+			default:
+				fprintf(stderr, "Error %s: %s\n", opts[1], strerror(EINVAL));
+				return;
+			}
+
+			__connmanctl_dbus_append_dict_entry(iter, "FallbackIPv4LL",
+						DBUS_TYPE_BOOLEAN, &val);
+		}
+
+	} else if (g_strcmp0(opts[0], "manual") == 0) {
+		int i = 1;
+
+		while (opts[i] && ipv4[i]) {
+			__connmanctl_dbus_append_dict_entry(iter, ipv4[i],
+						DBUS_TYPE_STRING, &opts[i]);
+			i++;
+		}
+
+		append->values = i;
+
+	} else if (g_strcmp0(opts[0], "off") != 0) {
+		fprintf(stderr, "Error %s: %s\n", opts[0], strerror(EINVAL));
+
+		return;
 	}
 
-	append->values = i;
+	__connmanctl_dbus_append_dict_entry(iter, "Method", DBUS_TYPE_STRING,
+				&opts[0]);
 }
 
 static void config_append_ipv6(DBusMessageIter *iter, void *user_data)
@@ -2435,7 +2470,8 @@ static struct connman_option config_options[] = {
 	{"proxy", 'x', "direct|auto <URL>|manual <URL1> [<URL2>] [...]\n"
 	               "\t\t\t[exclude <exclude1> [<exclude2>] [...]]"},
 	{"autoconnect", 'a', "yes|no"},
-	{"ipv4", 'i', "off|dhcp|manual <address> <netmask> <gateway>"},
+	{"ipv4", 'i', "off|dhcp [true|false]|\n"
+		      "\t\t\tmanual <address> <netmask> <gateway>"},
 	{"remove", 'r', "                 Remove service"},
 	{ NULL, }
 };
doc/connmanctl.1.in +6 -4
index d87472c3..00fa4208 100644
@@ -164,11 +164,13 @@ Config Options:
 Sets the autoconnect property of the service.
 .PP
 .TP
-.BR ipv4\ off \ |\  dhcp \ |\  manual\ \fIaddress\ netmask\ gateway
+.BR ipv4\ off \ |\  dhcp \ <\fIfallback-ipv4ll\fR>\ |\  manual\ \fIaddress\ netmask\ gateway
 Configures the IPv4 settings for the service. The argument
-\fBoff\fR means that IPv4 won't be used, \fBdhcp\fR means that
-dhcp will be used to get the settings and \fBmanual\fR means
-that the given arguments will be used as IPv4 settings.
+\fBoff\fR means that IPv4 won't be used, \fBdhcp\fR means that dhcp will be used
+to get the settings. \fIfallback-ipv4ll\fR is boolean parameter.
+if set \fBfalse\fR, an IPv4LL address will not be assigned if DHCP failed.
+Default is \fBtrue\fR. \fBmanual\fR means that the given arguments will be
+used as IPv4 settings.
 .IR address ,\  netmask " and " gateway
 must be valid IPv4 addresses. See the \fBEXAMPLE\fR section
 of this man page for details.
Signature · 1 line
2.25.1