3 # Patch managed by http://www.holgerschurig.de/patcher.html
6 --- ppp-2.4.3/pppd/ipcp.c~cifdefroute.patch
7 +++ ppp-2.4.3/pppd/ipcp.c
9 "disable defaultroute option", OPT_ALIAS | OPT_A2CLR,
10 &ipcp_wantoptions[0].default_route },
13 + { "replacedefaultroute", o_bool,
14 + &ipcp_wantoptions[0].replace_default_route,
15 + "Replace default route", 1
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 },
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,
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 *)); /* Run an up/down script */
32 static void ipcp_script_done __P((void *));
34 @@ -1659,7 +1669,12 @@
35 if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
37 if (wo->default_route)
39 if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr))
41 + if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr,
42 + wo->replace_default_route))
44 default_route_set[u] = 1;
46 if (sifproxyarp(u, wo->hisaddr))
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 @@ -1766,7 +1782,12 @@
59 /* assign a default route through the interface if required */
60 if (ipcp_wantoptions[f->unit].default_route)
62 if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
64 + if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr,
65 + wo->replace_default_route))
67 default_route_set[f->unit] = 1;
69 /* Make a proxy ARP entry if requested. */
70 @@ -1813,7 +1834,12 @@
72 /* assign a default route through the interface if required */
73 if (ipcp_wantoptions[f->unit].default_route)
75 if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
77 + if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr,
78 + wo->replace_default_route))
80 default_route_set[f->unit] = 1;
82 /* Make a proxy ARP entry if requested. */
84 sifnpmode(f->unit, PPP_IP, NPMODE_DROP);
86 ipcp_clear_addrs(f->unit, ipcp_gotoptions[f->unit].ouraddr,
87 - ipcp_hisoptions[f->unit].hisaddr);
88 + ipcp_hisoptions[f->unit].hisaddr, 0);
91 /* Execute the ip-down script */
92 @@ -1906,16 +1932,25 @@
93 * proxy arp entries, etc.
96 -ipcp_clear_addrs(unit, ouraddr, hisaddr)
97 +ipcp_clear_addrs(unit, ouraddr, hisaddr, replacedefaultroute)
99 u_int32_t ouraddr; /* local address */
100 u_int32_t hisaddr; /* remote address */
101 + bool replacedefaultroute;
103 if (proxy_arp_set[unit]) {
104 cifproxyarp(unit, hisaddr);
105 proxy_arp_set[unit] = 0;
107 - if (default_route_set[unit]) {
108 + /* If replacedefaultroute, sifdefaultroute will be called soon
109 + * with replacedefaultroute set and that will overwrite the current
110 + * default route. This is the case only when doing demand, otherwise
111 + * during demand, this cifdefaultroute would restore the old default
112 + * route which is not what we want in this case. In the non-demand
113 + * case, we'll delete the default route and restore the old if there
114 + * is one saved by an sifdefaultroute with replacedefaultroute.
116 + if (!replacedefaultroute && default_route_set[unit]) {
117 cifdefaultroute(unit, ouraddr, hisaddr);
118 default_route_set[unit] = 0;
120 --- ppp-2.4.3/pppd/ipcp.h~cifdefroute.patch
121 +++ ppp-2.4.3/pppd/ipcp.h
123 bool old_addrs; /* Use old (IP-Addresses) option? */
124 bool req_addr; /* Ask peer to send IP address? */
125 bool default_route; /* Assign default route through interface? */
126 + bool replace_default_route; /* Replace default route through interface? */
127 bool proxy_arp; /* Make proxy ARP entry for peer? */
128 bool neg_vj; /* Van Jacobson Compression? */
129 bool old_vj; /* use old (short) form of VJ option? */
130 --- ppp-2.4.3/pppd/pppd.8~cifdefroute.patch
131 +++ ppp-2.4.3/pppd/pppd.8
133 This entry is removed when the PPP connection is broken. This option
134 is privileged if the \fInodefaultroute\fR option has been specified.
136 +.B replacedefaultroute
137 +This option is a flag to the defaultroute option. If defaultroute is
138 +set and this flag is also set, pppd replaces an existing default route
139 +with the new default route.
143 .B disconnect \fIscript
144 Execute the command specified by \fIscript\fR, by passing it to a
149 Disable the \fIdefaultroute\fR option. The system administrator who
150 -wishes to prevent users from creating default routes with pppd
151 +wishes to prevent users from adding a default route with pppd
152 +can do so by placing this option in the /etc/ppp/options file.
154 +.B noreplacedefaultroute
155 +Disable the \fIreplacedefaultroute\fR option. The system administrator who
156 +wishes to prevent users from replacing a default route with pppd
157 can do so by placing this option in the /etc/ppp/options file.
160 --- ppp-2.4.3/pppd/pppd.h~cifdefroute.patch
161 +++ ppp-2.4.3/pppd/pppd.h
163 int cif6addr __P((int, eui64_t, eui64_t));
164 /* Remove an IPv6 address from i/f */
167 int sifdefaultroute __P((int, u_int32_t, u_int32_t));
169 +int sifdefaultroute __P((int, u_int32_t, u_int32_t, bool replace_default_rt));
171 /* Create default route through i/f */
172 int cifdefaultroute __P((int, u_int32_t, u_int32_t));
173 /* Delete default route through i/f */
174 --- ppp-2.4.3/pppd/sys-linux.c~cifdefroute.patch
175 +++ ppp-2.4.3/pppd/sys-linux.c
178 static int if_is_up; /* Interface has been marked up */
179 static u_int32_t default_route_gateway; /* 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 @@ -1513,6 +1515,9 @@
189 + SET_SA_FAMILY (rt->rt_dst, AF_INET);
190 + SET_SA_FAMILY (rt->rt_gateway, AF_INET);
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 @@ -1582,19 +1587,53 @@
196 /********************************************************************
198 * sifdefaultroute - assign a default route through the address given.
200 + * If the global default_rt_repl_rest flag is set, then this function
201 + * already replaced the original system defaultroute with some other
202 + * route and it should just replace the current defaultroute with
203 + * another one, without saving the current route. Use: demand mode,
204 + * when pppd sets first a defaultroute it it's temporary ppp0 addresses
205 + * and then changes the temporary addresses to the addresses for the real
206 + * ppp connection when it has come up.
209 -int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway)
210 +int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway, bool replace)
213 + struct rtentry rt, tmp_rt;
214 + struct rtentry *del_rt = NULL;
216 - if (defaultroute_exists(&rt) && strcmp(rt.rt_dev, ifname) != 0) {
217 - u_int32_t old_gateway = SIN_ADDR(rt.rt_gateway);
219 + if (default_rt_repl_rest) {
220 + /* We have already reclaced the original defaultroute, if we
221 + * are called again, we will delete the current default route
222 + * and set the new default route in this function.
223 + * - this is normally only the case the doing demand: */
224 + if (defaultroute_exists( &tmp_rt ))
226 + } else if ( defaultroute_exists( &old_def_rt ) &&
227 + strcmp( old_def_rt.rt_dev, ifname ) != 0) {
228 + /* We did not yet replace an existing default route, let's
229 + * check if we should save and replace a default route:
231 + u_int32_t old_gateway = SIN_ADDR(old_def_rt.rt_gateway);
233 - if (old_gateway != gateway)
234 - error("not replacing existing default route to %s [%I]",
235 - rt.rt_dev, old_gateway);
237 + if (old_gateway != gateway) {
239 + error("not replacing default route to %s [%I]",
240 + old_def_rt.rt_dev, old_gateway);
243 + // we need to copy rt_dev because we need it permanent too:
244 + char * tmp_dev = malloc(strlen(old_def_rt.rt_dev)+1);
245 + strcpy(tmp_dev, old_def_rt.rt_dev);
246 + old_def_rt.rt_dev = tmp_dev;
248 + notice("replacing old default route to %s [%I]",
249 + old_def_rt.rt_dev, old_gateway);
250 + default_rt_repl_rest = 1;
251 + del_rt = &old_def_rt;
256 memset (&rt, '\0', sizeof (rt));
257 @@ -1616,6 +1655,12 @@
258 error("default route ioctl(SIOCADDRT): %m");
261 + if (default_rt_repl_rest && del_rt)
262 + if (ioctl(sock_fd, SIOCDELRT, del_rt) < 0) {
263 + if ( ! ok_error ( errno ))
264 + error("del old default route ioctl(SIOCDELRT): %m(%d)", errno);
268 default_route_gateway = gateway;
270 @@ -1651,6 +1696,16 @@
274 + if (default_rt_repl_rest) {
275 + notice("restoring old default route to %s [%I]",
276 + old_def_rt.rt_dev, SIN_ADDR(old_def_rt.rt_gateway));
277 + if (ioctl(sock_fd, SIOCADDRT, &old_def_rt) < 0) {
278 + if ( ! ok_error ( errno ))
279 + error("restore default route ioctl(SIOCADDRT): %m(%d)", errno);
282 + default_rt_repl_rest = 0;