netconfig: Add IP configuration properties on Station and P2P
Andrew Zaborowski
PATCH 1/1 netconfig: Add IP configuration properties on Station and P2P
Add the IPv{4,6}Configuration D-Bus interfaces on the station and P2P objects that expose current netconfig values. Access Point and P2P-GO are not handled yet.
--- src/dbus.h | 2 + src/netconfig.c | 651 +++++++++++++++++++++++++++++++++++++++++++----- src/netconfig.h | 2 +- src/p2p.c | 4 +- src/station.c | 8 +- 5 files changed, 604 insertions(+), 63 deletions(-)
src/dbus.h +2 -0
@@ -43,6 +43,8 @@#define IWD_STATION_DIAGNOSTIC_INTERFACE "net.connman.iwd.StationDiagnostic"#define IWD_AP_DIAGNOSTIC_INTERFACE "net.connman.iwd.AccessPointDiagnostic"#define IWD_STATION_DEBUG_INTERFACE "net.connman.iwd.StationDebug" +#define IWD_IPV4_CONFIG_INTERFACE "net.connman.iwd.IPv4Configuration" +#define IWD_IPV6_CONFIG_INTERFACE "net.connman.iwd.IPv6Configuration"#define IWD_BASE_PATH "/net/connman/iwd"#define IWD_AGENT_MANAGER_PATH IWD_BASE_PATH
src/netconfig.c +593 -58
970 lines not on this page · raw message
src/netconfig.h +1 -1
@@ -45,5 +45,5 @@ bool netconfig_get_fils_ip_req(struct netconfig *netconfig,void netconfig_handle_fils_ip_resp (struct netconfig *netconfig,const struct ie_fils_ip_addr_response_info *info); -struct netconfig *netconfig_new (uint32_t ifindex); +struct netconfig *netconfig_new (uint32_t ifindex,const char *dbus_path);void netconfig_destroy (struct netconfig *netconfig);
src/p2p.c +3 -1
@@ -1320,7 +1320,9 @@ static void p2p_start_client_netconfig(struct p2p_device *dev)struct l_settings *settings;if (!dev->conn_netconfig) { - dev->conn_netconfig =netconfig_new (ifindex); +const char *peer_path =p2p_peer_get_path (dev->conn_peer); + + dev->conn_netconfig =netconfig_new (ifindex, peer_path);if (!dev->conn_netconfig) {p2p_connect_failed (dev);return ;
src/station.c +5 -3
@@ -3577,6 +3577,7 @@ static struct station *station_create(struct netdev *netdev)struct station *station;struct l_dbus *dbus =dbus_get_bus ();bool autoconnect = true; +const char *path; station = l_new(struct station, 1);watchlist_init (&station->state_watches,NULL );
@@ -3594,11 +3595,12 @@ static struct station *station_create(struct netdev *netdev)l_queue_push_head (station_list, station); -l_dbus_object_add_interface (dbus,netdev_get_path (netdev), -IWD_STATION_INTERFACE , station); + path =netdev_get_path (netdev); +l_dbus_object_add_interface (dbus, path,IWD_STATION_INTERFACE , station);if (netconfig_enabled) - station->netconfig =netconfig_new (netdev_get_ifindex (netdev)); + station->netconfig =netconfig_new (netdev_get_ifindex (netdev), + path); station->anqp_pending =l_queue_new ();
Signature · 1 line
2.30.2
Denis Kenzior
Hi Andrew,
Quoted 11 lines · Andrew Zaborowski
Add the IPv{4,6}Configuration D-Bus interfaces on the station and P2P objects that expose current netconfig values. Access Point and P2P-GO are not handled yet.
--- src/dbus.h | 2 + src/netconfig.c | 651 +++++++++++++++++++++++++++++++++++++++++++----- src/netconfig.h | 2 +- src/p2p.c | 4 +- src/station.c | 8 +- 5 files changed, 604 insertions(+), 63 deletions(-)
Can you split this patch up a bit more, there's just way too much going on. It is really hard to review in this form.
Quoted 29 lines
src/dbus.h +2
-0@@ -43,6 +43,8 @@#define IWD_STATION_DIAGNOSTIC_INTERFACE "net.connman.iwd.StationDiagnostic"#define IWD_AP_DIAGNOSTIC_INTERFACE "net.connman.iwd.AccessPointDiagnostic"#define IWD_STATION_DEBUG_INTERFACE "net.connman.iwd.StationDebug" +#define IWD_IPV4_CONFIG_INTERFACE "net.connman.iwd.IPv4Configuration" +#define IWD_IPV6_CONFIG_INTERFACE "net.connman.iwd.IPv6Configuration"#define IWD_BASE_PATH "/net/connman/iwd"#define IWD_AGENT_MANAGER_PATH IWD_BASE_PATHsrc/netconfig.c +1
-0@@ -49,6 +49,7 @@#include "src/resolve.h" #include "src/util.h" #include "src/ie.h" +#include "src/dbus.h" #include "src/netconfig.h" struct netconfig {@@ -58,14 +59,23 @@ struct netconfig {uint8_t rtm_protocol;uint8_t rtm_v6_protocol;struct l_rtnl_address *v4_address;
src/netconfig.c struct netconfig { · line 71
Quoted 10 lines
src/netconfig.c +7
-0+struct l_rtnl_address *v6_address;char **dns4_overrides;char **dns6_overrides; +char **dns4_list; +char **dns6_list;struct ie_fils_ip_addr_response_info *fils_override; +char *v4_gateway_str; +char *v6_gateway_str; +char *v4_domain; +char **v6_domains;
Maybe a commit for each member you're adding and a short blurb why..
src/netconfig.c struct netconfig { · line 78
Quoted 7 lines
src/netconfig.c +2
-0const struct l_settings *active_settings;netconfig_notify_func_t notify;void *user_data; +bool v4_configured; +bool v6_configured;
Then the IPv4 & IPv6 DBus interfaces
src/netconfig.c struct netconfig { · line 87
Quoted 8 lines
src/netconfig.c +1
-0struct resolve *resolve;@@ -74,6 +84,13 @@ struct netconfig {uint32_t addr4_add_cmd_id;uint32_t addr6_add_cmd_id;uint32_t route4_add_gateway_cmd_id; +uint32_t route6_add_cmd_id;
This seems like it would belong in a separate commit?
Quoted 21 lines
src/netconfig.c +7
-0+ +char *dbus_path; +struct interface_data { +bool is_ipv4; +struct netconfig *netconfig; + } v4_data, v6_data; };static struct l_netlink *rtnl;@@ -132,6 +149,7 @@ static void netconfig_free(void *data)l_dhcp_client_destroy (netconfig->dhcp_client);l_dhcp6_client_destroy (netconfig->dhcp6_client); +l_free (netconfig->dbus_path);l_free (netconfig); }@@ -257,6 +275,18 @@ static void netconfig_set_neighbor_entry_cb(int error, strerror(-error), error); }
src/netconfig.c static void netconfig_set_neighbor_entry_cb(int error, · line 287
Quoted 10 lines
src/netconfig.c +10
-0+static bool netconfig_strv_eq (char *const *a,char *const *b) +{ +if (l_strv_length ((char **) a) !=l_strv_length ((char **) b)) +return false; + +for (; a && *a; a++, b++) +if (strcmp (*a, *b)) +return false; + +return true;
This probably belongs in ell?
Quoted 28 lines
src/netconfig.c +9
-7+} +static int netconfig_set_dns (struct netconfig *netconfig) {const uint8_t *fils_dns4_mac =NULL ;@@ -270,23 +300,25 @@ static int netconfig_set_dns(struct netconfig *netconfig)char **dns_list;const struct ie_fils_ip_addr_response_info *fils = netconfig->fils_override; +struct l_dbus *dbus =dbus_get_bus (); -if (!dns4_list && !dns6_list) -return 0 ; +if (dns6_list) { + dns_list =l_malloc (sizeof (char *) * + (n_entries4 + n_entries6 +1 )); - dns_list = dns4_list; +if (dns4_list) +memcpy (dns_list, dns4_list, +sizeof (char *) * n_entries4); -if (dns6_list) { - dns_list =l_realloc (dns_list, -sizeof (char *) * (n_entries4 + n_entries6 +1 ));memcpy (dns_list + n_entries4, dns6_list,sizeof (char *) * (n_entries6 +1 )); -/* Contents now belong to dns_list, so no l_strfreev */
src/netconfig.c static int netconfig_set_dns(struct netconfig *netconfig) · line 321
Quoted 10 lines
src/netconfig.c +5
-3-l_free (dns6_list); - } + }else + dns_list = dns4_list;resolve_set_dns (netconfig->resolve, dns_list); -l_strv_free (dns_list); + +if (dns6_list) +l_free (dns_list);
Why are you doing all this when you can just check for dns[4|6]_list being changed prior to building the list for submission to resolve_set_dns?
Quoted 21 lines
src/netconfig.c +14
-0if (fils_dns4_mac && !l_rtnl_neighbor_set_hwaddr(rtnl, netconfig->ifindex, AF_INET,@@ -302,6 +334,30 @@ static int netconfig_set_dns(struct netconfig *netconfig) NULL))l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); +if (netconfig_strv_eq (netconfig->dns4_list, dns4_list)) +l_strv_free (dns4_list); +else { +l_strv_free (netconfig->dns4_list); + netconfig->dns4_list = dns4_list; + +if (netconfig->dbus_path && netconfig->v4_configured) +l_dbus_property_changed (dbus, netconfig->dbus_path, +IWD_IPV4_CONFIG_INTERFACE , +"DomainNameServers" ); + } + +if (netconfig_strv_eq (netconfig->dns6_list, dns6_list)) +l_strv_free (dns6_list);
src/netconfig.c static int netconfig_set_dns(struct netconfig *netconfig) · line 360
Quoted 10 lines
src/netconfig.c +10
-0+else { +l_strv_free (netconfig->dns6_list); + netconfig->dns6_list = dns6_list; + +if (netconfig->dbus_path && netconfig->v6_configured) +l_dbus_property_changed (dbus, netconfig->dbus_path, +IWD_IPV6_CONFIG_INTERFACE , +"DomainNameServers" ); + } +
This really needs a convenience method instead of copy-pasting it all over.
Quoted 31 lines
src/netconfig.c +15
-2return 0 ; }@@ -328,6 +384,7 @@ static int netconfig_set_domains(struct netconfig *netconfig)char *v4_domain =NULL ;char **v6_domains =NULL ;char **p; +struct l_dbus *dbus =dbus_get_bus ();memset (domains,0 ,sizeof (domains));@@ -358,8 +415,30 @@ static int netconfig_set_domains(struct netconfig *netconfig) L_ARRAY_SIZE(domains) - 1, *p);resolve_set_domains (netconfig->resolve, domains); -l_strv_free (v6_domains); -l_free (v4_domain); + +if (l_streq0 (v4_domain, netconfig->v4_domain)) +l_free (v4_domain); +else { +l_free (netconfig->v4_domain); + netconfig->v4_domain = v4_domain; + +if (netconfig->dbus_path && netconfig->v4_configured) +l_dbus_property_changed (dbus, netconfig->dbus_path, +IWD_IPV4_CONFIG_INTERFACE , +"DomainNames" ); + } + +if (netconfig_strv_eq (netconfig->v6_domains, v6_domains))
src/netconfig.c static int netconfig_set_domains(struct netconfig *netconfig) · line 441
Quoted 10 lines
src/netconfig.c +10
-0+l_strv_free (v6_domains); + else { +l_strv_free (netconfig->v6_domains); + netconfig->v6_domains = v6_domains; + +if (netconfig->dbus_path && netconfig->v6_configured) +l_dbus_property_changed (dbus, netconfig->dbus_path, +IWD_IPV6_CONFIG_INTERFACE , +"DomainNames" ); + }
As above. And I still wonder whether this belongs in the methods that invoke the resolve_* functionality. The logic that invokes these methods might actually have a better idea if anything actually changed or it is being invoked for the first time due to a lease being obtained...
src/netconfig.c static int netconfig_set_domains(struct netconfig *netconfig) · line 443
Quoted 3 lines
src/netconfig.c +0
-0return 0 ; }
Regards,
-Denis
Andrew Zaborowski
Hi Denis,
Quoted 16 lines · Denis Kenzior
Hi Andrew,
Quoted 11 lines · Andrew Zaborowski
Add the IPv{4,6}Configuration D-Bus interfaces on the station and P2P objects that expose current netconfig values. Access Point and P2P-GO are not handled yet.
--- src/dbus.h | 2 + src/netconfig.c | 651 +++++++++++++++++++++++++++++++++++++++++++----- src/netconfig.h | 2 +- src/p2p.c | 4 +- src/station.c | 8 +- 5 files changed, 604 insertions(+), 63 deletions(-)
Quoted 2 lines
Can you split this patch up a bit more, there's just way too much going on. It is really hard to review in this form.
Ok, it's grown a bit.
Quoted 56 lines
Quoted 30 lines
src/dbus.h +2
-0@@ -43,6 +43,8 @@#define IWD_STATION_DIAGNOSTIC_INTERFACE "net.connman.iwd.StationDiagnostic"#define IWD_AP_DIAGNOSTIC_INTERFACE "net.connman.iwd.AccessPointDiagnostic"#define IWD_STATION_DEBUG_INTERFACE "net.connman.iwd.StationDebug" +#define IWD_IPV4_CONFIG_INTERFACE "net.connman.iwd.IPv4Configuration" +#define IWD_IPV6_CONFIG_INTERFACE "net.connman.iwd.IPv6Configuration"#define IWD_BASE_PATH "/net/connman/iwd"#define IWD_AGENT_MANAGER_PATH IWD_BASE_PATHsrc/netconfig.c +1
-0@@ -49,6 +49,7 @@#include "src/resolve.h" #include "src/util.h" #include "src/ie.h" +#include "src/dbus.h" #include "src/netconfig.h" struct netconfig {@@ -58,14 +59,23 @@ struct netconfig {uint8_t rtm_protocol;uint8_t rtm_v6_protocol;struct l_rtnl_address *v4_address;src/netconfig.c struct netconfig { · line 71
Quoted 10 lines
src/netconfig.c +7
-0+struct l_rtnl_address *v6_address;char **dns4_overrides;char **dns6_overrides; +char **dns4_list; +char **dns6_list;struct ie_fils_ip_addr_response_info *fils_override; +char *v4_gateway_str; +char *v6_gateway_str; +char *v4_domain; +char **v6_domains;Maybe a commit for each member you're adding and a short blurb why..
src/netconfig.c struct netconfig { · line 78
Quoted 7 lines
src/netconfig.c +2
-0const struct l_settings *active_settings;netconfig_notify_func_t notify;void *user_data; +bool v4_configured; +bool v6_configured;Then the IPv4 & IPv6 DBus interfaces
Quoted 3 lines
src/netconfig.c +0
-0struct resolve *resolve;
Quoted 7 lines
src/netconfig.c struct netconfig { · line 87
Quoted 5 lines
src/netconfig.c +1
-0@@ -74,6 +84,13 @@ struct netconfig {uint32_t addr4_add_cmd_id;uint32_t addr6_add_cmd_id;uint32_t route4_add_gateway_cmd_id; +uint32_t route6_add_cmd_id;This seems like it would belong in a separate commit?
Ok.
Quoted 22 lines
Quoted 22 lines
src/netconfig.c +7
-0+ +char *dbus_path; +struct interface_data { +bool is_ipv4; +struct netconfig *netconfig; + } v4_data, v6_data; };static struct l_netlink *rtnl;@@ -132,6 +149,7 @@ static void netconfig_free(void *data)l_dhcp_client_destroy (netconfig->dhcp_client);l_dhcp6_client_destroy (netconfig->dhcp6_client); +l_free (netconfig->dbus_path);l_free (netconfig); }@@ -257,6 +275,18 @@ static void netconfig_set_neighbor_entry_cb(int error, strerror(-error), error); }
Quoted 12 lines
src/netconfig.c static void netconfig_set_neighbor_entry_cb(int error, · line 287
Quoted 10 lines
src/netconfig.c +10
-0+static bool netconfig_strv_eq (char *const *a,char *const *b) +{ +if (l_strv_length ((char **) a) !=l_strv_length ((char **) b)) +return false; + +for (; a && *a; a++, b++) +if (strcmp (*a, *b)) +return false; + +return true;This probably belongs in ell?
Ok.
Quoted 34 lines
Quoted 34 lines
src/netconfig.c +11
-9+} +static int netconfig_set_dns (struct netconfig *netconfig) {const uint8_t *fils_dns4_mac =NULL ;@@ -270,23 +300,25 @@ static int netconfig_set_dns(struct netconfig *netconfig)char **dns_list;const struct ie_fils_ip_addr_response_info *fils = netconfig->fils_override; +struct l_dbus *dbus =dbus_get_bus (); -if (!dns4_list && !dns6_list) -return 0 ; +if (dns6_list) { + dns_list =l_malloc (sizeof (char *) * + (n_entries4 + n_entries6 +1 )); - dns_list = dns4_list; +if (dns4_list) +memcpy (dns_list, dns4_list, +sizeof (char *) * n_entries4); -if (dns6_list) { - dns_list =l_realloc (dns_list, -sizeof (char *) * (n_entries4 + n_entries6 +1 ));memcpy (dns_list + n_entries4, dns6_list,sizeof (char *) * (n_entries6 +1 )); -/* Contents now belong to dns_list, so no l_strfreev */ -l_free (dns6_list); - } + }else + dns_list = dns4_list;
Quoted 8 lines
src/netconfig.c static int netconfig_set_dns(struct netconfig *netconfig) · line 321
Quoted 5 lines
src/netconfig.c +3
-1resolve_set_dns (netconfig->resolve, dns_list); -l_strv_free (dns_list); + +if (dns6_list) +l_free (dns_list);Why are you doing all this when you can just check for dns[4|6]_list being changed prior to building the list for submission to
resolve_set_dns?
Do you mean why is the code calling resolve_set_dns() even if the values haven't changed? Mostly to keep the current behaviour.
I can check for changes first, this might save cycles if the call isn't necessary -- I wasn't sure if it's only needed when the lists have changed. It won't save lines of code
Quoted 26 lines
Quoted 26 lines
src/netconfig.c +18
-0if (fils_dns4_mac && !l_rtnl_neighbor_set_hwaddr(rtnl, netconfig->ifindex, AF_INET,@@ -302,6 +334,30 @@ static int netconfig_set_dns(struct netconfig *netconfig) NULL))l_debug ("l_rtnl_neighbor_set_hwaddr failed" ); +if (netconfig_strv_eq (netconfig->dns4_list, dns4_list)) +l_strv_free (dns4_list); +else { +l_strv_free (netconfig->dns4_list); + netconfig->dns4_list = dns4_list; + +if (netconfig->dbus_path && netconfig->v4_configured) +l_dbus_property_changed (dbus, netconfig->dbus_path, +IWD_IPV4_CONFIG_INTERFACE , +"DomainNameServers" ); + } + +if (netconfig_strv_eq (netconfig->dns6_list, dns6_list)) +l_strv_free (dns6_list); +else { +l_strv_free (netconfig->dns6_list); + netconfig->dns6_list = dns6_list; +
Quoted 8 lines
src/netconfig.c static int netconfig_set_dns(struct netconfig *netconfig) · line 360
Quoted 6 lines
src/netconfig.c +6
-0+if (netconfig->dbus_path && netconfig->v6_configured) +l_dbus_property_changed (dbus, netconfig->dbus_path, +IWD_IPV6_CONFIG_INTERFACE , +"DomainNameServers" ); + } +This really needs a convenience method instead of copy-pasting it all over.
Ok.
Quoted 39 lines
Quoted 39 lines
src/netconfig.c +22
-2return 0 ; }@@ -328,6 +384,7 @@ static int netconfig_set_domains(struct netconfig *netconfig)char *v4_domain =NULL ;char **v6_domains =NULL ;char **p; +struct l_dbus *dbus =dbus_get_bus ();memset (domains,0 ,sizeof (domains));@@ -358,8 +415,30 @@ static int netconfig_set_domains(struct netconfig *netconfig) L_ARRAY_SIZE(domains) - 1, *p);resolve_set_domains (netconfig->resolve, domains); -l_strv_free (v6_domains); -l_free (v4_domain); + +if (l_streq0 (v4_domain, netconfig->v4_domain)) +l_free (v4_domain); +else { +l_free (netconfig->v4_domain); + netconfig->v4_domain = v4_domain; + +if (netconfig->dbus_path && netconfig->v4_configured) +l_dbus_property_changed (dbus, netconfig->dbus_path, +IWD_IPV4_CONFIG_INTERFACE , +"DomainNames" ); + } + +if (netconfig_strv_eq (netconfig->v6_domains, v6_domains)) +l_strv_free (v6_domains); +else { +l_strv_free (netconfig->v6_domains); + netconfig->v6_domains = v6_domains; + +if (netconfig->dbus_path && netconfig->v6_configured) + l_dbus_property_changed(dbus, netconfig->dbus_path,
Quoted 8 lines
src/netconfig.c static int netconfig_set_domains(struct netconfig *netconfig) · line 441
Quoted 3 lines
src/netconfig.c +3
-0+IWD_IPV6_CONFIG_INTERFACE , + "DomainNames"); + }As above. And I still wonder whether this belongs in the methods that invoke the resolve_* functionality. The logic that invokes these methods might actually have a better idea if anything actually changed or it is being invoked for the first time due to a lease being obtained...
It'd probably be an intermediate function that builds the lists, checks for changes and then calls resolve_set_domains/dns() and emits the events, so as to avoid duplication, I can do that.
Best regards
Denis Kenzior
Hi Andrew,
Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
src/netconfig.c +9
-9@@ -270,23 +300,25 @@ static int netconfig_set_dns(struct netconfig *netconfig)char **dns_list;const struct ie_fils_ip_addr_response_info *fils = netconfig->fils_override; +struct l_dbus *dbus =dbus_get_bus (); -if (!dns4_list && !dns6_list) -return 0 ; +if (dns6_list) { + dns_list =l_malloc (sizeof (char *) * + (n_entries4 + n_entries6 +1 )); - dns_list = dns4_list; +if (dns4_list) +memcpy (dns_list, dns4_list, +sizeof (char *) * n_entries4); -if (dns6_list) { - dns_list =l_realloc (dns_list, -sizeof (char *) * (n_entries4 + n_entries6 +1 ));memcpy (dns_list + n_entries4, dns6_list,sizeof (char *) * (n_entries6 +1 )); -/* Contents now belong to dns_list, so no l_strfreev */ -l_free (dns6_list); - } + }else + dns_list = dns4_list;Quoted 8 lines
src/netconfig.c static int netconfig_set_dns(struct netconfig *netconfig) · line 321
Quoted 5 lines
src/netconfig.c +3
-1resolve_set_dns (netconfig->resolve, dns_list); -l_strv_free (dns_list); + +if (dns6_list) +l_free (dns_list);Why are you doing all this when you can just check for dns[4|6]_list being changed prior to building the list for submission to
resolve_set_dns?
Quoted 3 lines
Do you mean why is the code calling
resolve_set_dns()even if the values haven't changed? Mostly to keep the current behaviour.
No. You're building a brand new dns_list so that you're not messing with the dns4_list / dns6_list because you want to check those for changes & send PropertyChanged signals. But you can take care of the PropertyChanged signals up front (and you probably want to prior to the 'both lists are NULL' check anyway). All the changes above are not necessary.
Regards,
-Denis