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