summaryrefslogtreecommitdiffstats
path: root/meta/recipes-connectivity/ppp/ppp-2.4.5/cifdefroute.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-connectivity/ppp/ppp-2.4.5/cifdefroute.patch')
-rw-r--r--meta/recipes-connectivity/ppp/ppp-2.4.5/cifdefroute.patch290
1 files changed, 290 insertions, 0 deletions
diff --git a/meta/recipes-connectivity/ppp/ppp-2.4.5/cifdefroute.patch b/meta/recipes-connectivity/ppp/ppp-2.4.5/cifdefroute.patch
new file mode 100644
index 0000000000..6473a08bc7
--- /dev/null
+++ b/meta/recipes-connectivity/ppp/ppp-2.4.5/cifdefroute.patch
@@ -0,0 +1,290 @@
1This patch comes from OpenEmbedded.
2The original patch is from Debian / SuSE to implement replacedefaultroute
3Rebased it to fit ppp-2.4.5. Dongxiao Xu <dongxiao.xu@intel.com>
4
5diff -urN ppp-2.4.5-orig/pppd/ipcp.c ppp-2.4.5/pppd/ipcp.c
6--- ppp-2.4.5-orig/pppd/ipcp.c 2010-06-30 15:51:12.050166398 +0800
7+++ ppp-2.4.5/pppd/ipcp.c 2010-06-30 16:40:00.478716855 +0800
8@@ -198,6 +198,16 @@
9 "disable defaultroute option", OPT_ALIAS | OPT_A2CLR,
10 &ipcp_wantoptions[0].default_route },
11
12+#ifdef __linux__
13+ { "replacedefaultroute", o_bool,
14+ &ipcp_wantoptions[0].replace_default_route,
15+ "Replace default route", 1
16+ },
17+ { "noreplacedefaultroute", o_bool,
18+ &ipcp_allowoptions[0].replace_default_route,
19+ "Never replace default route", OPT_A2COPY,
20+ &ipcp_wantoptions[0].replace_default_route },
21+#endif
22 { "proxyarp", o_bool, &ipcp_wantoptions[0].proxy_arp,
23 "Add proxy ARP entry", OPT_ENABLE|1, &ipcp_allowoptions[0].proxy_arp },
24 { "noproxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
25@@ -271,7 +281,7 @@
26 ip_active_pkt
27 };
28
29-static void ipcp_clear_addrs __P((int, u_int32_t, u_int32_t));
30+static void ipcp_clear_addrs __P((int, u_int32_t, u_int32_t, bool));
31 static void ipcp_script __P((char *, int)); /* Run an up/down script */
32 static void ipcp_script_done __P((void *));
33
34@@ -1742,7 +1752,12 @@
35 if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
36 return 0;
37 if (wo->default_route)
38+#ifndef __linux__
39 if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr))
40+#else
41+ if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr,
42+ wo->replace_default_route))
43+#endif
44 default_route_set[u] = 1;
45 if (wo->proxy_arp)
46 if (sifproxyarp(u, wo->hisaddr))
47@@ -1830,7 +1845,8 @@
48 */
49 if (demand) {
50 if (go->ouraddr != wo->ouraddr || ho->hisaddr != wo->hisaddr) {
51- ipcp_clear_addrs(f->unit, wo->ouraddr, wo->hisaddr);
52+ ipcp_clear_addrs(f->unit, wo->ouraddr, wo->hisaddr,
53+ wo->replace_default_route);
54 if (go->ouraddr != wo->ouraddr) {
55 warn("Local IP address changed to %I", go->ouraddr);
56 script_setenv("OLDIPLOCAL", ip_ntoa(wo->ouraddr), 0);
57@@ -1855,7 +1871,12 @@
58
59 /* assign a default route through the interface if required */
60 if (ipcp_wantoptions[f->unit].default_route)
61+#ifndef __linux__
62 if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
63+#else
64+ if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr,
65+ wo->replace_default_route))
66+#endif
67 default_route_set[f->unit] = 1;
68
69 /* Make a proxy ARP entry if requested. */
70@@ -1905,7 +1926,12 @@
71
72 /* assign a default route through the interface if required */
73 if (ipcp_wantoptions[f->unit].default_route)
74+#ifndef __linux__
75 if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
76+#else
77+ if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr,
78+ wo->replace_default_route))
79+#endif
80 default_route_set[f->unit] = 1;
81
82 /* Make a proxy ARP entry if requested. */
83@@ -1983,7 +2009,7 @@
84 sifnpmode(f->unit, PPP_IP, NPMODE_DROP);
85 sifdown(f->unit);
86 ipcp_clear_addrs(f->unit, ipcp_gotoptions[f->unit].ouraddr,
87- ipcp_hisoptions[f->unit].hisaddr);
88+ ipcp_hisoptions[f->unit].hisaddr, 0);
89 }
90
91 /* Execute the ip-down script */
92@@ -1999,12 +2025,21 @@
93 * proxy arp entries, etc.
94 */
95 static void
96-ipcp_clear_addrs(unit, ouraddr, hisaddr)
97+ipcp_clear_addrs(unit, ouraddr, hisaddr, replacedefaultroute)
98 int unit;
99 u_int32_t ouraddr; /* local address */
100 u_int32_t hisaddr; /* remote address */
101+ bool replacedefaultroute;
102 {
103- if (proxy_arp_set[unit]) {
104+ /* If replacedefaultroute, sifdefaultroute will be called soon
105+ * with replacedefaultroute set and that will overwrite the current
106+ * default route. This is the case only when doing demand, otherwise
107+ * during demand, this cifdefaultroute would restore the old default
108+ * route which is not what we want in this case. In the non-demand
109+ * case, we'll delete the default route and restore the old if there
110+ * is one saved by an sifdefaultroute with replacedefaultroute.
111+ */
112+ if (!replacedefaultroute && default_route_set[unit]) {
113 cifproxyarp(unit, hisaddr);
114 proxy_arp_set[unit] = 0;
115 }
116diff -urN ppp-2.4.5-orig/pppd/ipcp.h ppp-2.4.5/pppd/ipcp.h
117--- ppp-2.4.5-orig/pppd/ipcp.h 2010-06-30 15:51:12.043682063 +0800
118+++ ppp-2.4.5/pppd/ipcp.h 2010-06-30 16:40:49.586203129 +0800
119@@ -70,6 +70,7 @@
120 bool old_addrs; /* Use old (IP-Addresses) option? */
121 bool req_addr; /* Ask peer to send IP address? */
122 bool default_route; /* Assign default route through interface? */
123+ bool replace_default_route; /* Replace default route through interface? */
124 bool proxy_arp; /* Make proxy ARP entry for peer? */
125 bool neg_vj; /* Van Jacobson Compression? */
126 bool old_vj; /* use old (short) form of VJ option? */
127diff -urN ppp-2.4.5-orig/pppd/pppd.8 ppp-2.4.5/pppd/pppd.8
128--- ppp-2.4.5-orig/pppd/pppd.8 2010-06-30 15:51:12.043682063 +0800
129+++ ppp-2.4.5/pppd/pppd.8 2010-06-30 16:42:47.102413859 +0800
130@@ -121,6 +121,13 @@
131 This entry is removed when the PPP connection is broken. This option
132 is privileged if the \fInodefaultroute\fR option has been specified.
133 .TP
134+.B replacedefaultroute
135+This option is a flag to the defaultroute option. If defaultroute is
136+set and this flag is also set, pppd replaces an existing default route
137+with the new default route.
138+
139+
140+.TP
141 .B disconnect \fIscript
142 Execute the command specified by \fIscript\fR, by passing it to a
143 shell, after
144@@ -717,7 +724,12 @@
145 .TP
146 .B nodefaultroute
147 Disable the \fIdefaultroute\fR option. The system administrator who
148-wishes to prevent users from creating default routes with pppd
149+wishes to prevent users from adding a default route with pppd
150+can do so by placing this option in the /etc/ppp/options file.
151+.TP
152+.B noreplacedefaultroute
153+Disable the \fIreplacedefaultroute\fR option. The system administrator who
154+wishes to prevent users from replacing a default route with pppd
155 can do so by placing this option in the /etc/ppp/options file.
156 .TP
157 .B nodeflate
158diff -urN ppp-2.4.5-orig/pppd/pppd.h ppp-2.4.5/pppd/pppd.h
159--- ppp-2.4.5-orig/pppd/pppd.h 2010-06-30 15:51:12.050166398 +0800
160+++ ppp-2.4.5/pppd/pppd.h 2010-06-30 16:43:36.514148327 +0800
161@@ -643,7 +643,11 @@
162 int cif6addr __P((int, eui64_t, eui64_t));
163 /* Remove an IPv6 address from i/f */
164 #endif
165+#ifndef __linux__
166 int sifdefaultroute __P((int, u_int32_t, u_int32_t));
167+#else
168+int sifdefaultroute __P((int, u_int32_t, u_int32_t, bool replace_default_rt));
169+#endif
170 /* Create default route through i/f */
171 int cifdefaultroute __P((int, u_int32_t, u_int32_t));
172 /* Delete default route through i/f */
173diff -urN ppp-2.4.5-orig/pppd/sys-linux.c ppp-2.4.5/pppd/sys-linux.c
174--- ppp-2.4.5-orig/pppd/sys-linux.c 2010-06-30 15:51:12.050166398 +0800
175+++ ppp-2.4.5/pppd/sys-linux.c 2010-06-30 16:54:00.362716231 +0800
176@@ -206,6 +206,8 @@
177
178 static int if_is_up; /* Interface has been marked up */
179 static int have_default_route; /* Gateway for default route added */
180+static struct rtentry old_def_rt; /* Old default route */
181+static int default_rt_repl_rest; /* replace and restore old default rt */
182 static u_int32_t proxy_arp_addr; /* Addr for proxy arp entry added */
183 static char proxy_arp_dev[16]; /* Device for proxy arp entry */
184 static u_int32_t our_old_addr; /* for detecting address changes */
185@@ -1537,6 +1539,9 @@
186 p = NULL;
187 }
188
189+ SET_SA_FAMILY (rt->rt_dst, AF_INET);
190+ SET_SA_FAMILY (rt->rt_gateway, AF_INET);
191+
192 SIN_ADDR(rt->rt_dst) = strtoul(cols[route_dest_col], NULL, 16);
193 SIN_ADDR(rt->rt_gateway) = strtoul(cols[route_gw_col], NULL, 16);
194 SIN_ADDR(rt->rt_genmask) = strtoul(cols[route_mask_col], NULL, 16);
195@@ -1606,20 +1611,51 @@
196 /********************************************************************
197 *
198 * sifdefaultroute - assign a default route through the address given.
199- */
200-
201-int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway)
202-{
203- struct rtentry rt;
204-
205- if (defaultroute_exists(&rt) && strcmp(rt.rt_dev, ifname) != 0) {
206- if (rt.rt_flags & RTF_GATEWAY)
207- error("not replacing existing default route via %I",
208- SIN_ADDR(rt.rt_gateway));
209- else
210- error("not replacing existing default route through %s",
211- rt.rt_dev);
212- return 0;
213+ *
214+ * If the global default_rt_repl_rest flag is set, then this function
215+ * already replaced the original system defaultroute with some other
216+ * route and it should just replace the current defaultroute with
217+ * another one, without saving the current route. Use: demand mode,
218+ * when pppd sets first a defaultroute it it's temporary ppp0 addresses
219+ * and then changes the temporary addresses to the addresses for the real
220+ * ppp connection when it has come up.
221+ */
222+
223+int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway, bool replace)
224+{
225+ struct rtentry rt, tmp_rt;
226+ struct rtentry *del_rt = NULL;
227+
228+ if (default_rt_repl_rest) {
229+ /* We have already reclaced the original defaultroute, if we
230+ * are called again, we will delete the current default route
231+ * and set the new default route in this function.
232+ * - this is normally only the case the doing demand: */
233+ if (defaultroute_exists( &tmp_rt ))
234+ del_rt = &tmp_rt;
235+ } else if ( defaultroute_exists( &old_def_rt ) &&
236+ strcmp( old_def_rt.rt_dev, ifname ) != 0) {
237+ /* We did not yet replace an existing default route, let's
238+ * check if we should save and replace a default route:
239+ */
240+ u_int32_t old_gateway = SIN_ADDR(old_def_rt.rt_gateway);
241+ if (old_gateway != gateway) {
242+ if (!replace) {
243+ error("not replacing default route to %s [%I]",
244+ old_def_rt.rt_dev, old_gateway);
245+ return 0;
246+ } else {
247+ // we need to copy rt_dev because we need it permanent too:
248+ char * tmp_dev = malloc(strlen(old_def_rt.rt_dev)+1);
249+ strcpy(tmp_dev, old_def_rt.rt_dev);
250+ old_def_rt.rt_dev = tmp_dev;
251+
252+ notice("replacing old default route to %s [%I]",
253+ old_def_rt.rt_dev, old_gateway);
254+ default_rt_repl_rest = 1;
255+ del_rt = &old_def_rt;
256+ }
257+ }
258 }
259
260 memset (&rt, 0, sizeof (rt));
261@@ -1638,6 +1674,12 @@
262 error("default route ioctl(SIOCADDRT): %m");
263 return 0;
264 }
265+ if (default_rt_repl_rest && del_rt)
266+ if (ioctl(sock_fd, SIOCDELRT, del_rt) < 0) {
267+ if ( ! ok_error ( errno ))
268+ error("del old default route ioctl(SIOCDELRT): %m(%d)", errno);
269+ return 0;
270+ }
271
272 have_default_route = 1;
273 return 1;
274@@ -1673,6 +1715,16 @@
275 return 0;
276 }
277 }
278+ if (default_rt_repl_rest) {
279+ notice("restoring old default route to %s [%I]",
280+ old_def_rt.rt_dev, SIN_ADDR(old_def_rt.rt_gateway));
281+ if (ioctl(sock_fd, SIOCADDRT, &old_def_rt) < 0) {
282+ if ( ! ok_error ( errno ))
283+ error("restore default route ioctl(SIOCADDRT): %m(%d)", errno);
284+ return 0;
285+ }
286+ default_rt_repl_rest = 0;
287+ }
288
289 return 1;
290 }