Skip to content

Commit

Permalink
Rework default route handling.
Browse files Browse the repository at this point in the history
1.  replacedefaultroute option is being removed.
2.  default route will now always be appended at defaultroute-metric (both
    IPv4 and IPv6) if defaultroute{.6} is given.

Closes: ppp-project#473
Signed-off-by: Jaco Kroon <[email protected]>
  • Loading branch information
jkroonza committed Jan 7, 2025
1 parent 9f612dc commit 3fc321e
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 290 deletions.
29 changes: 8 additions & 21 deletions pppd/ipcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,6 @@ static struct option ipcp_option_list[] = {
"disable defaultroute option", OPT_ALIAS | OPT_A2CLR,
&ipcp_wantoptions[0].default_route },

#ifdef __linux__
{ "replacedefaultroute", o_bool,
&ipcp_wantoptions[0].replace_default_route,
"Replace default route", OPT_PRIV | 1
},
{ "noreplacedefaultroute", o_bool,
&ipcp_wantoptions[0].replace_default_route,
"Do not replace default route", 0 },
#endif
{ "proxyarp", o_bool, &ipcp_wantoptions[0].proxy_arp,
"Add proxy ARP entry", OPT_ENABLE|1, &ipcp_allowoptions[0].proxy_arp },
{ "noproxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
Expand Down Expand Up @@ -284,7 +275,7 @@ struct protent ipcp_protent = {
ip_active_pkt
};

static void ipcp_clear_addrs (int, u_int32_t, u_int32_t, bool);
static void ipcp_clear_addrs (int, u_int32_t, u_int32_t);
static void ipcp_script (char *, int); /* Run an up/down script */
static void ipcp_script_done (void *);

Expand Down Expand Up @@ -1776,8 +1767,7 @@ ip_demand_conf(int u)
if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
return 0;
if (wo->default_route)
if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr,
wo->replace_default_route))
if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr))
default_route_set[u] = 1;
if (wo->proxy_arp)
if (sifproxyarp(u, wo->hisaddr))
Expand Down Expand Up @@ -1878,8 +1868,7 @@ ipcp_up(fsm *f)
*/
if (demand) {
if (go->ouraddr != wo->ouraddr || ho->hisaddr != wo->hisaddr) {
ipcp_clear_addrs(f->unit, wo->ouraddr, wo->hisaddr,
wo->replace_default_route);
ipcp_clear_addrs(f->unit, wo->ouraddr, wo->hisaddr);
if (go->ouraddr != wo->ouraddr) {
warn("Local IP address changed to %I", go->ouraddr);
ppp_script_setenv("OLDIPLOCAL", ip_ntoa(wo->ouraddr), 0);
Expand All @@ -1905,8 +1894,7 @@ ipcp_up(fsm *f)

/* assign a default route through the interface if required */
if (ipcp_wantoptions[f->unit].default_route)
if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr,
wo->replace_default_route))
if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
default_route_set[f->unit] = 1;

/* Make a proxy ARP entry if requested. */
Expand Down Expand Up @@ -1965,8 +1953,7 @@ ipcp_up(fsm *f)

/* assign a default route through the interface if required */
if (ipcp_wantoptions[f->unit].default_route)
if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr,
wo->replace_default_route))
if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
default_route_set[f->unit] = 1;

/* Make a proxy ARP entry if requested. */
Expand Down Expand Up @@ -2043,7 +2030,7 @@ ipcp_down(fsm *f)
sifnpmode(f->unit, PPP_IP, NPMODE_DROP);
sifdown(f->unit);
ipcp_clear_addrs(f->unit, ipcp_gotoptions[f->unit].ouraddr,
ipcp_hisoptions[f->unit].hisaddr, 0);
ipcp_hisoptions[f->unit].hisaddr);
}

/* Execute the ip-down script */
Expand All @@ -2059,7 +2046,7 @@ ipcp_down(fsm *f)
* proxy arp entries, etc.
*/
static void
ipcp_clear_addrs(int unit, u_int32_t ouraddr, u_int32_t hisaddr, bool replacedefaultroute)
ipcp_clear_addrs(int unit, u_int32_t ouraddr, u_int32_t hisaddr)
{
if (proxy_arp_set[unit]) {
cifproxyarp(unit, hisaddr);
Expand All @@ -2073,7 +2060,7 @@ ipcp_clear_addrs(int unit, u_int32_t ouraddr, u_int32_t hisaddr, bool replacedef
* case, we'll delete the default route and restore the old if there
* is one saved by an sifdefaultroute with replacedefaultroute.
*/
if (!replacedefaultroute && default_route_set[unit]) {
if (default_route_set[unit]) {
cifdefaultroute(unit, ouraddr, hisaddr);
default_route_set[unit] = 0;
}
Expand Down
1 change: 0 additions & 1 deletion pppd/ipcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ typedef struct ipcp_options {
bool old_addrs; /* Use old (IP-Addresses) option? */
bool req_addr; /* Ask peer to send IP address? */
bool default_route; /* Assign default route through interface? */
bool replace_default_route; /* Replace default route through interface? */
bool proxy_arp; /* Make proxy ARP entry for peer? */
bool neg_vj; /* Van Jacobson Compression? */
bool old_vj; /* use old (short) form of VJ option? */
Expand Down
8 changes: 6 additions & 2 deletions pppd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ bool dryrun; /* print out option values and exit */
char *domain; /* domain name set by domain option */
int child_wait = 5; /* # seconds to wait for children at exit */
struct userenv *userenv_list; /* user environment variables */
int dfl_route_metric = -1; /* metric of the default route to set over the PPP link */
unsigned dfl_route_metric = 0; /* metric of the default route to set over the PPP link */
unsigned dfl_route6_metric = 0; /* metric of the default route to set over the PPP link */

#ifdef PPP_WITH_IPV6CP
char path_ipv6up[MAXPATHLEN]; /* pathname of ipv6-up script */
Expand Down Expand Up @@ -332,7 +333,10 @@ struct option general_options[] = {
OPT_A2PRINTER | OPT_NOPRINT, (void *)user_unsetprint },

{ "defaultroute-metric", o_int, &dfl_route_metric,
"Metric to use for the default route (Linux only; -1 for default behavior)",
"Metric to use for the default route (Linux only; default 0)",
OPT_PRIV|OPT_LLIMIT|OPT_INITONLY, NULL, 0, -1 },
{ "defaultroute6-metric", o_int, &dfl_route6_metric,
"Metric to use for the default route (Linux only; default 0)",
OPT_PRIV|OPT_LLIMIT|OPT_INITONLY, NULL, 0, -1 },

{ "net-init-script", o_string, path_net_init,
Expand Down
2 changes: 1 addition & 1 deletion pppd/pppd-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ int sif6addr(int, eui64_t, eui64_t);
int cif6addr(int, eui64_t, eui64_t);
/* Remove an IPv6 address from i/f */
#endif
int sifdefaultroute(int, u_int32_t, u_int32_t, bool replace_default_rt);
int sifdefaultroute(int, u_int32_t, u_int32_t);
/* Create default route through i/f */
int cifdefaultroute(int, u_int32_t, u_int32_t);
/* Delete default route through i/f */
Expand Down
19 changes: 6 additions & 13 deletions pppd/pppd.8
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,8 @@ This entry is removed when the PPP connection is broken. This option
is privileged if the \fInodefaultroute\fR option has been specified.
.TP
.B defaultroute-metric
Define the metric of the \fIdefaultroute\fR and only add it if there
is no other default route with the same metric. With the default
value of -1, the route is only added if there is no default route at
all.
.TP
.B replacedefaultroute
This option is a flag to the defaultroute option. If defaultroute is
set and this flag is also set, pppd replaces an existing default route
with the new default route. This option is privileged.
Define the metric of the \fIdefaultroute\fR. By default the default route will
be added with a metric of 0.
.TP
.B disconnect \fIscript
Execute the command specified by \fIscript\fR, by passing it to a
Expand Down Expand Up @@ -367,6 +360,10 @@ configured by kernel automatically too based on ICMPv6 Router Advertisement
packets. This option may conflict with kernel IPv6 route setup and should
be used only for broken IPv6 networks.
.TP
.B defaultroute6-metric
Define the metric of the \fIdefaultroute6\fR. By default the default route will
be added with a metric of 0.
.TP
.B deflate \fInr,nt
Request that the peer compress packets that it sends, using the
Deflate scheme, with a maximum window size of \fI2**nr\fR bytes, and
Expand Down Expand Up @@ -802,10 +799,6 @@ Disable the \fIdefaultroute\fR option. The system administrator who
wishes to prevent users from adding a default route with pppd
can do so by placing this option in the /etc/ppp/options file.
.TP
.B noreplacedefaultroute
Disable the \fIreplacedefaultroute\fR option. This allows to disable a
\fIreplacedefaultroute\fR option set previously in the configuration.
.TP
.B nodefaultroute6
Disable the \fIdefaultroute6\fR option. The system administrator who
wishes to prevent users from adding a default route with pppd
Expand Down
Loading

0 comments on commit 3fc321e

Please sign in to comment.