summaryrefslogtreecommitdiff
path: root/user/ppp/10_all_defaultgateway.patch
blob: 1b7ae639607610d6021fdf3caefaec2dc1bb92d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
This patch reverses revision 1.114 of the pppd/sys-linux.c file.
The default gateway is needed by the openswan's %defaultroute.

--- ppp-2.4.7/pppd/sys-linux.c
+++ ppp-2.4.7/pppd/sys-linux.c
@@ -206,7 +206,7 @@
 
 static int	if_is_up;	/* Interface has been marked up */
 static int	if6_is_up;	/* Interface has been marked up for IPv6, to help differentiate */
-static int	have_default_route;	/* Gateway for default route added */
+static u_int32_t default_route_gateway;	/* Gateway for default route added */
 static u_int32_t proxy_arp_addr;	/* Addr for proxy arp entry added */
 static char proxy_arp_dev[16];		/* Device for proxy arp entry */
 static u_int32_t our_old_addr;		/* for detecting address changes */
@@ -346,8 +346,8 @@
 /*
  * Delete any routes through the device.
  */
-    if (have_default_route)
-	cifdefaultroute(0, 0, 0);
+    if (default_route_gateway != 0)
+	cifdefaultroute(0, 0, default_route_gateway);
 
     if (has_proxy_arp)
 	cifproxyarp(0, proxy_arp_addr);
@@ -1621,17 +1621,17 @@
     struct rtentry rt;
 
     if (defaultroute_exists(&rt) && strcmp(rt.rt_dev, ifname) != 0) {
-	if (rt.rt_flags & RTF_GATEWAY)
-	    error("not replacing existing default route via %I",
-		  SIN_ADDR(rt.rt_gateway));
-	else
-	    error("not replacing existing default route through %s",
-		  rt.rt_dev);
+	u_int32_t old_gateway = SIN_ADDR(rt.rt_gateway);
+
+	if (old_gateway != gateway)
+	    error("not replacing existing default route to %s [%I]",
+		  rt.rt_dev, old_gateway);
 	return 0;
     }
 
-    memset (&rt, 0, sizeof (rt));
-    SET_SA_FAMILY (rt.rt_dst, AF_INET);
+    memset (&rt, '\0', sizeof (rt));
+    SET_SA_FAMILY (rt.rt_dst,     AF_INET);
+    SET_SA_FAMILY (rt.rt_gateway, AF_INET);
 
     rt.rt_dev = ifname;
 
@@ -1640,14 +1640,16 @@
 	SIN_ADDR(rt.rt_genmask) = 0L;
     }
 
-    rt.rt_flags = RTF_UP;
+    SIN_ADDR(rt.rt_gateway) = gateway;
+
+    rt.rt_flags = RTF_UP | RTF_GATEWAY;
     if (ioctl(sock_fd, SIOCADDRT, &rt) < 0) {
 	if ( ! ok_error ( errno ))
 	    error("default route ioctl(SIOCADDRT): %m");
 	return 0;
     }
 
-    have_default_route = 1;
+    default_route_gateway = gateway;
     return 1;
 }
 
@@ -1660,7 +1662,7 @@
 {
     struct rtentry rt;
 
-    have_default_route = 0;
+    default_route_gateway = 0;
 
     memset (&rt, '\0', sizeof (rt));
     SET_SA_FAMILY (rt.rt_dst,     AF_INET);
@@ -1673,7 +1675,9 @@
 	SIN_ADDR(rt.rt_genmask) = 0L;
     }
 
-    rt.rt_flags = RTF_UP;
+    SIN_ADDR(rt.rt_gateway) = gateway;
+
+    rt.rt_flags = RTF_UP | RTF_GATEWAY;
     if (ioctl(sock_fd, SIOCDELRT, &rt) < 0 && errno != ESRCH) {
 	if (still_ppp()) {
 	    if ( ! ok_error ( errno ))