Merge lp:~kvalo/connman/ptp-default-gateway into lp:~indicator-network-developers/connman/trunk

Proposed by Kalle Valo
Status: Merged
Merged at revision: 2272
Proposed branch: lp:~kvalo/connman/ptp-default-gateway
Merge into: lp:~indicator-network-developers/connman/trunk
Diff against target: 150 lines (+72/-9)
4 files modified
include/inet.h (+1/-0)
src/connection.c (+14/-7)
src/inet.c (+45/-0)
src/rtnl.c (+12/-2)
To merge this branch: bzr merge lp:~kvalo/connman/ptp-default-gateway
Reviewer Review Type Date Requested Status
David Barth (community) Approve
Review via email: mp+26694@code.launchpad.net

Description of the change

Fix for default interface problem.

To post a comment you must log in.
Revision history for this message
David Barth (dbarth) wrote :

Comments and needs info:
- the del_routes changes seem correct to me
- connman_inet_clear_gateway_interface looks good to me
- rntl: sounds ok, but i'm not sure how safe it is to skip those host-specific routes

My only worry is about swapping a NULL for a "0.0.0.0" string. You've done the changes locally, but are there other parts of the code (or of plugins) where gateway != NULL (because it's now "0.0.0.0") would be mis-interpreted? Have you grepped for that in the rest of the code?

review: Needs Information
Revision history for this message
Kalle Valo (kvalo) wrote :

Fortunately struct gateway_data is only used inside src/connections.c and I reviewed the cases in that file and they look to be ok.

Revision history for this message
David Barth (dbarth) wrote :

Ok +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'include/inet.h'
--- include/inet.h 2010-02-11 04:33:05 +0000
+++ include/inet.h 2010-06-03 12:42:23 +0000
@@ -50,6 +50,7 @@
50int connman_inet_set_gateway_address(int index, const char *gateway);50int connman_inet_set_gateway_address(int index, const char *gateway);
51int connman_inet_clear_gateway_address(int index, const char *gateway);51int connman_inet_clear_gateway_address(int index, const char *gateway);
52int connman_inet_set_gateway_interface(int index);52int connman_inet_set_gateway_interface(int index);
53int connman_inet_clear_gateway_interface(int index);
5354
54#ifdef __cplusplus55#ifdef __cplusplus
55}56}
5657
=== modified file 'src/connection.c'
--- src/connection.c 2010-05-06 05:32:30 +0000
+++ src/connection.c 2010-06-03 12:42:23 +0000
@@ -66,18 +66,21 @@
6666
67static int del_routes(struct gateway_data *data)67static int del_routes(struct gateway_data *data)
68{68{
69 const char *address;69 DBG("gateway %s", data->gateway);
7070
71 if (data->vpn) {71 if (data->vpn) {
72 if (data->vpn_phy_index >= 0)72 if (data->vpn_phy_index >= 0)
73 connman_inet_del_host_route(data->vpn_phy_index,73 connman_inet_del_host_route(data->vpn_phy_index,
74 data->gateway);74 data->gateway);
75 address = data->vpn_ip;75 return connman_inet_clear_gateway_address(data->index,
76 data->vpn_ip);
77 } else if (g_strcmp0(data->gateway, "0.0.0.0") == 0) {
78 return connman_inet_clear_gateway_interface(data->index);
76 } else {79 } else {
77 connman_inet_del_host_route(data->index, data->gateway);80 connman_inet_del_host_route(data->index, data->gateway);
78 address = data->gateway;81 return connman_inet_clear_gateway_address(data->index,
82 data->gateway);
79 }83 }
80 return connman_inet_clear_gateway_address(data->index, address);
81}84}
8285
83static void find_element(struct connman_element *element, gpointer user_data)86static void find_element(struct connman_element *element, gpointer user_data)
@@ -104,6 +107,13 @@
104 if (data == NULL)107 if (data == NULL)
105 return NULL;108 return NULL;
106109
110 /*
111 * If gateway is NULL, it's a point to point link and the default
112 * gateway is 0.0.0.0, meaning the interface.
113 */
114 if (gateway == NULL)
115 gateway = "0.0.0.0";
116
107 data->index = index;117 data->index = index;
108 data->gateway = g_strdup(gateway);118 data->gateway = g_strdup(gateway);
109 data->active = FALSE;119 data->active = FALSE;
@@ -272,9 +282,6 @@
272282
273 connman_element_set_enabled(element, TRUE);283 connman_element_set_enabled(element, TRUE);
274284
275 if (gateway == NULL)
276 return 0;
277
278 active_gateway = find_active_gateway();285 active_gateway = find_active_gateway();
279 new_gateway = add_gateway(element->index, gateway);286 new_gateway = add_gateway(element->index, gateway);
280287
281288
=== modified file 'src/inet.c'
--- src/inet.c 2010-03-07 23:01:29 +0000
+++ src/inet.c 2010-06-03 12:42:23 +0000
@@ -899,3 +899,48 @@
899899
900 return err;900 return err;
901}901}
902
903int connman_inet_clear_gateway_interface(int index)
904{
905 struct ifreq ifr;
906 struct rtentry rt;
907 struct sockaddr_in addr;
908 int sk, err;
909
910 DBG("");
911
912 sk = socket(PF_INET, SOCK_DGRAM, 0);
913 if (sk < 0)
914 return -1;
915
916 memset(&ifr, 0, sizeof(ifr));
917 ifr.ifr_ifindex = index;
918
919 if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
920 close(sk);
921 return -1;
922 }
923
924 DBG("ifname %s", ifr.ifr_name);
925
926 memset(&rt, 0, sizeof(rt));
927 rt.rt_flags = RTF_UP;
928
929 memset(&addr, 0, sizeof(addr));
930 addr.sin_family = AF_INET;
931 addr.sin_addr.s_addr = INADDR_ANY;
932
933 memcpy(&rt.rt_genmask, &addr, sizeof(rt.rt_genmask));
934 memcpy(&rt.rt_dst, &addr, sizeof(rt.rt_dst));
935 memcpy(&rt.rt_gateway, &addr, sizeof(rt.rt_gateway));
936
937 rt.rt_dev = ifr.ifr_name;
938
939 err = ioctl(sk, SIOCDELRT, &rt);
940 if (err < 0)
941 connman_error("Removing default interface route failed (%s)",
942 strerror(errno));
943 close(sk);
944
945 return err;
946}
902947
=== modified file 'src/rtnl.c'
--- src/rtnl.c 2010-05-18 21:48:47 +0000
+++ src/rtnl.c 2010-06-03 12:42:23 +0000
@@ -485,7 +485,12 @@
485485
486 __connman_ipconfig_newroute(index, scope, dststr, gatewaystr);486 __connman_ipconfig_newroute(index, scope, dststr, gatewaystr);
487487
488 if (scope != RT_SCOPE_UNIVERSE || dst.s_addr != INADDR_ANY)488 /* skip host specific routes */
489 if (scope != RT_SCOPE_UNIVERSE &&
490 !(scope == RT_SCOPE_LINK && dst.s_addr == INADDR_ANY))
491 return;
492
493 if (dst.s_addr != INADDR_ANY)
489 return;494 return;
490495
491 for (list = rtnl_list; list; list = list->next) {496 for (list = rtnl_list; list; list = list->next) {
@@ -514,7 +519,12 @@
514519
515 __connman_ipconfig_delroute(index, scope, dststr, gatewaystr);520 __connman_ipconfig_delroute(index, scope, dststr, gatewaystr);
516521
517 if (scope != RT_SCOPE_UNIVERSE || dst.s_addr != INADDR_ANY)522 /* skip host specific routes */
523 if (scope != RT_SCOPE_UNIVERSE &&
524 !(scope == RT_SCOPE_LINK && dst.s_addr == INADDR_ANY))
525 return;
526
527 if (dst.s_addr != INADDR_ANY)
518 return;528 return;
519529
520 for (list = rtnl_list; list; list = list->next) {530 for (list = rtnl_list; list; list = list->next) {

Subscribers

People subscribed via source and target branches