Line
Link Here
|
0 |
-- pppd/ipcp.c |
0 |
++ pppd/ipcp.c |
Lines 197-202
Link Here
|
197 |
"disable defaultroute option", OPT_ALIAS | OPT_A2CLR, |
197 |
"disable defaultroute option", OPT_ALIAS | OPT_A2CLR, |
198 |
&ipcp_wantoptions[0].default_route }, |
198 |
&ipcp_wantoptions[0].default_route }, |
199 |
|
199 |
|
|
|
200 |
#ifdef __linux__ |
201 |
{ "replacedefaultroute", o_bool, |
202 |
&ipcp_wantoptions[0].replace_default_route, |
203 |
"Replace default route", 1 |
204 |
}, |
205 |
{ "noreplacedefaultroute", o_bool, |
206 |
&ipcp_allowoptions[0].replace_default_route, |
207 |
"Never replace default route", OPT_A2COPY, |
208 |
&ipcp_wantoptions[0].replace_default_route }, |
209 |
#endif |
200 |
{ "proxyarp", o_bool, &ipcp_wantoptions[0].proxy_arp, |
210 |
{ "proxyarp", o_bool, &ipcp_wantoptions[0].proxy_arp, |
201 |
"Add proxy ARP entry", OPT_ENABLE|1, &ipcp_allowoptions[0].proxy_arp }, |
211 |
"Add proxy ARP entry", OPT_ENABLE|1, &ipcp_allowoptions[0].proxy_arp }, |
202 |
{ "noproxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp, |
212 |
{ "noproxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp, |
Lines 263-269
Link Here
|
263 |
ip_active_pkt |
273 |
ip_active_pkt |
264 |
}; |
274 |
}; |
265 |
|
275 |
|
266 |
static void ipcp_clear_addrs __P((int, u_int32_t, u_int32_t)); |
276 |
static void ipcp_clear_addrs __P((int, u_int32_t, u_int32_t, bool)); |
267 |
static void ipcp_script __P((char *, int)); /* Run an up/down script */ |
277 |
static void ipcp_script __P((char *, int)); /* Run an up/down script */ |
268 |
static void ipcp_script_done __P((void *)); |
278 |
static void ipcp_script_done __P((void *)); |
269 |
|
279 |
|
Lines 1660-1666
Link Here
|
1660 |
if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE)) |
1670 |
if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE)) |
1661 |
return 0; |
1671 |
return 0; |
1662 |
if (wo->default_route) |
1672 |
if (wo->default_route) |
|
|
1673 |
#ifndef __linux__ |
1663 |
if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr)) |
1674 |
if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr)) |
|
|
1675 |
#else |
1676 |
if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr, |
1677 |
wo->replace_default_route)) |
1678 |
#endif |
1664 |
default_route_set[u] = 1; |
1679 |
default_route_set[u] = 1; |
1665 |
if (wo->proxy_arp) |
1680 |
if (wo->proxy_arp) |
1666 |
if (sifproxyarp(u, wo->hisaddr)) |
1681 |
if (sifproxyarp(u, wo->hisaddr)) |
Lines 1742-1748
Link Here
|
1742 |
*/ |
1757 |
*/ |
1743 |
if (demand) { |
1758 |
if (demand) { |
1744 |
if (go->ouraddr != wo->ouraddr || ho->hisaddr != wo->hisaddr) { |
1759 |
if (go->ouraddr != wo->ouraddr || ho->hisaddr != wo->hisaddr) { |
1745 |
ipcp_clear_addrs(f->unit, wo->ouraddr, wo->hisaddr); |
1760 |
ipcp_clear_addrs(f->unit, wo->ouraddr, wo->hisaddr, |
|
|
1761 |
wo->replace_default_route); |
1746 |
if (go->ouraddr != wo->ouraddr) { |
1762 |
if (go->ouraddr != wo->ouraddr) { |
1747 |
warn("Local IP address changed to %I", go->ouraddr); |
1763 |
warn("Local IP address changed to %I", go->ouraddr); |
1748 |
script_setenv("OLDIPLOCAL", ip_ntoa(wo->ouraddr), 0); |
1764 |
script_setenv("OLDIPLOCAL", ip_ntoa(wo->ouraddr), 0); |
Lines 1767-1773
Link Here
|
1767 |
|
1783 |
|
1768 |
/* assign a default route through the interface if required */ |
1784 |
/* assign a default route through the interface if required */ |
1769 |
if (ipcp_wantoptions[f->unit].default_route) |
1785 |
if (ipcp_wantoptions[f->unit].default_route) |
|
|
1786 |
#ifndef __linux__ |
1770 |
if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr)) |
1787 |
if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr)) |
|
|
1788 |
#else |
1789 |
if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr, |
1790 |
wo->replace_default_route)) |
1791 |
#endif |
1771 |
default_route_set[f->unit] = 1; |
1792 |
default_route_set[f->unit] = 1; |
1772 |
|
1793 |
|
1773 |
/* Make a proxy ARP entry if requested. */ |
1794 |
/* Make a proxy ARP entry if requested. */ |
Lines 1817-1823
Link Here
|
1817 |
|
1838 |
|
1818 |
/* assign a default route through the interface if required */ |
1839 |
/* assign a default route through the interface if required */ |
1819 |
if (ipcp_wantoptions[f->unit].default_route) |
1840 |
if (ipcp_wantoptions[f->unit].default_route) |
|
|
1841 |
#ifndef __linux__ |
1820 |
if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr)) |
1842 |
if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr)) |
|
|
1843 |
#else |
1844 |
if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr, |
1845 |
wo->replace_default_route)) |
1846 |
#endif |
1821 |
default_route_set[f->unit] = 1; |
1847 |
default_route_set[f->unit] = 1; |
1822 |
|
1848 |
|
1823 |
/* Make a proxy ARP entry if requested. */ |
1849 |
/* Make a proxy ARP entry if requested. */ |
Lines 1894-1900
Link Here
|
1894 |
sifnpmode(f->unit, PPP_IP, NPMODE_DROP); |
1920 |
sifnpmode(f->unit, PPP_IP, NPMODE_DROP); |
1895 |
sifdown(f->unit); |
1921 |
sifdown(f->unit); |
1896 |
ipcp_clear_addrs(f->unit, ipcp_gotoptions[f->unit].ouraddr, |
1922 |
ipcp_clear_addrs(f->unit, ipcp_gotoptions[f->unit].ouraddr, |
1897 |
ipcp_hisoptions[f->unit].hisaddr); |
1923 |
ipcp_hisoptions[f->unit].hisaddr, 0); |
1898 |
} |
1924 |
} |
1899 |
|
1925 |
|
1900 |
/* Execute the ip-down script */ |
1926 |
/* Execute the ip-down script */ |
Lines 1910-1925
Link Here
|
1910 |
* proxy arp entries, etc. |
1936 |
* proxy arp entries, etc. |
1911 |
*/ |
1937 |
*/ |
1912 |
static void |
1938 |
static void |
1913 |
ipcp_clear_addrs(unit, ouraddr, hisaddr) |
1939 |
ipcp_clear_addrs(unit, ouraddr, hisaddr, replacedefaultroute) |
1914 |
int unit; |
1940 |
int unit; |
1915 |
u_int32_t ouraddr; /* local address */ |
1941 |
u_int32_t ouraddr; /* local address */ |
1916 |
u_int32_t hisaddr; /* remote address */ |
1942 |
u_int32_t hisaddr; /* remote address */ |
|
|
1943 |
bool replacedefaultroute; |
1917 |
{ |
1944 |
{ |
1918 |
if (proxy_arp_set[unit]) { |
1945 |
if (proxy_arp_set[unit]) { |
1919 |
cifproxyarp(unit, hisaddr); |
1946 |
cifproxyarp(unit, hisaddr); |
1920 |
proxy_arp_set[unit] = 0; |
1947 |
proxy_arp_set[unit] = 0; |
1921 |
} |
1948 |
} |
1922 |
if (default_route_set[unit]) { |
1949 |
/* If replacedefaultroute, sifdefaultroute will be called soon |
|
|
1950 |
* with replacedefaultroute set and that will overwrite the current |
1951 |
* default route. This is the case only when doing demand, otherwise |
1952 |
* during demand, this cifdefaultroute would restore the old default |
1953 |
* route which is not what we want in this case. In the non-demand |
1954 |
* case, we'll delete the default route and restore the old if there |
1955 |
* is one saved by an sifdefaultroute with replacedefaultroute. |
1956 |
*/ |
1957 |
if (!replacedefaultroute && default_route_set[unit]) { |
1923 |
cifdefaultroute(unit, ouraddr, hisaddr); |
1958 |
cifdefaultroute(unit, ouraddr, hisaddr); |
1924 |
default_route_set[unit] = 0; |
1959 |
default_route_set[unit] = 0; |
1925 |
} |
1960 |
} |
1926 |
-- pppd/ipcp.h |
1961 |
++ pppd/ipcp.h |
Lines 70-75
Link Here
|
70 |
bool old_addrs; /* Use old (IP-Addresses) option? */ |
70 |
bool old_addrs; /* Use old (IP-Addresses) option? */ |
71 |
bool req_addr; /* Ask peer to send IP address? */ |
71 |
bool req_addr; /* Ask peer to send IP address? */ |
72 |
bool default_route; /* Assign default route through interface? */ |
72 |
bool default_route; /* Assign default route through interface? */ |
|
|
73 |
bool replace_default_route; /* Replace default route through interface? */ |
73 |
bool proxy_arp; /* Make proxy ARP entry for peer? */ |
74 |
bool proxy_arp; /* Make proxy ARP entry for peer? */ |
74 |
bool neg_vj; /* Van Jacobson Compression? */ |
75 |
bool neg_vj; /* Van Jacobson Compression? */ |
75 |
bool old_vj; /* use old (short) form of VJ option? */ |
76 |
bool old_vj; /* use old (short) form of VJ option? */ |
76 |
-- pppd/pppd.8 |
77 |
++ pppd/pppd.8 |
Lines 121-126
Link Here
|
121 |
This entry is removed when the PPP connection is broken. This option |
121 |
This entry is removed when the PPP connection is broken. This option |
122 |
is privileged if the \fInodefaultroute\fR option has been specified. |
122 |
is privileged if the \fInodefaultroute\fR option has been specified. |
123 |
.TP |
123 |
.TP |
|
|
124 |
.B replacedefaultroute |
125 |
This option is a flag to the defaultroute option. If defaultroute is |
126 |
set and this flag is also set, pppd replaces an existing default route |
127 |
with the new default route. |
128 |
|
129 |
|
130 |
.TP |
124 |
.B disconnect \fIscript |
131 |
.B disconnect \fIscript |
125 |
Execute the command specified by \fIscript\fR, by passing it to a |
132 |
Execute the command specified by \fIscript\fR, by passing it to a |
126 |
shell, after |
133 |
shell, after |
Lines 706-712
Link Here
|
706 |
.TP |
713 |
.TP |
707 |
.B nodefaultroute |
714 |
.B nodefaultroute |
708 |
Disable the \fIdefaultroute\fR option. The system administrator who |
715 |
Disable the \fIdefaultroute\fR option. The system administrator who |
709 |
wishes to prevent users from creating default routes with pppd |
716 |
wishes to prevent users from adding a default route with pppd |
|
|
717 |
can do so by placing this option in the /etc/ppp/options file. |
718 |
.TP |
719 |
.B noreplacedefaultroute |
720 |
Disable the \fIreplacedefaultroute\fR option. The system administrator who |
721 |
wishes to prevent users from replacing a default route with pppd |
710 |
can do so by placing this option in the /etc/ppp/options file. |
722 |
can do so by placing this option in the /etc/ppp/options file. |
711 |
.TP |
723 |
.TP |
712 |
.B nodeflate |
724 |
.B nodeflate |
713 |
-- pppd/pppd.h |
725 |
++ pppd/pppd.h |
Lines 642-648
Link Here
|
642 |
int cif6addr __P((int, eui64_t, eui64_t)); |
642 |
int cif6addr __P((int, eui64_t, eui64_t)); |
643 |
/* Remove an IPv6 address from i/f */ |
643 |
/* Remove an IPv6 address from i/f */ |
644 |
#endif |
644 |
#endif |
|
|
645 |
#ifndef __linux__ |
645 |
int sifdefaultroute __P((int, u_int32_t, u_int32_t)); |
646 |
int sifdefaultroute __P((int, u_int32_t, u_int32_t)); |
|
|
647 |
#else |
648 |
int sifdefaultroute __P((int, u_int32_t, u_int32_t, bool replace_default_rt)); |
649 |
#endif |
646 |
/* Create default route through i/f */ |
650 |
/* Create default route through i/f */ |
647 |
int cifdefaultroute __P((int, u_int32_t, u_int32_t)); |
651 |
int cifdefaultroute __P((int, u_int32_t, u_int32_t)); |
648 |
/* Delete default route through i/f */ |
652 |
/* Delete default route through i/f */ |
649 |
-- pppd/sys-linux.c |
653 |
++ pppd/sys-linux.c |
Lines 206-211
Link Here
|
206 |
|
206 |
|
207 |
static int if_is_up; /* Interface has been marked up */ |
207 |
static int if_is_up; /* Interface has been marked up */ |
208 |
static int have_default_route; /* Gateway for default route added */ |
208 |
static int have_default_route; /* Gateway for default route added */ |
|
|
209 |
static struct rtentry old_def_rt; /* Old default route */ |
210 |
static int default_rt_repl_rest; /* replace and restore old default rt */ |
209 |
static u_int32_t proxy_arp_addr; /* Addr for proxy arp entry added */ |
211 |
static u_int32_t proxy_arp_addr; /* Addr for proxy arp entry added */ |
210 |
static char proxy_arp_dev[16]; /* Device for proxy arp entry */ |
212 |
static char proxy_arp_dev[16]; /* Device for proxy arp entry */ |
211 |
static u_int32_t our_old_addr; /* for detecting address changes */ |
213 |
static u_int32_t our_old_addr; /* for detecting address changes */ |
Lines 1513-1518
Link Here
|
1513 |
p = NULL; |
1515 |
p = NULL; |
1514 |
} |
1516 |
} |
1515 |
|
1517 |
|
|
|
1518 |
SET_SA_FAMILY (rt->rt_dst, AF_INET); |
1519 |
SET_SA_FAMILY (rt->rt_gateway, AF_INET); |
1520 |
|
1516 |
SIN_ADDR(rt->rt_dst) = strtoul(cols[route_dest_col], NULL, 16); |
1521 |
SIN_ADDR(rt->rt_dst) = strtoul(cols[route_dest_col], NULL, 16); |
1517 |
SIN_ADDR(rt->rt_gateway) = strtoul(cols[route_gw_col], NULL, 16); |
1522 |
SIN_ADDR(rt->rt_gateway) = strtoul(cols[route_gw_col], NULL, 16); |
1518 |
SIN_ADDR(rt->rt_genmask) = strtoul(cols[route_mask_col], NULL, 16); |
1523 |
SIN_ADDR(rt->rt_genmask) = strtoul(cols[route_mask_col], NULL, 16); |
Lines 1582-1603
Link Here
|
1582 |
/******************************************************************** |
1587 |
/******************************************************************** |
1583 |
* |
1588 |
* |
1584 |
* sifdefaultroute - assign a default route through the address given. |
1589 |
* sifdefaultroute - assign a default route through the address given. |
1585 |
*/ |
1590 |
* |
1586 |
|
1591 |
* If the global default_rt_repl_rest flag is set, then this function |
1587 |
int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway) |
1592 |
* already replaced the original system defaultroute with some other |
1588 |
{ |
1593 |
* route and it should just replace the current defaultroute with |
1589 |
struct rtentry rt; |
1594 |
* another one, without saving the current route. Use: demand mode, |
1590 |
|
1595 |
* when pppd sets first a defaultroute it it's temporary ppp0 addresses |
1591 |
if (defaultroute_exists(&rt) && strcmp(rt.rt_dev, ifname) != 0) { |
1596 |
* and then changes the temporary addresses to the addresses for the real |
1592 |
if (rt.rt_flags & RTF_GATEWAY) |
1597 |
* ppp connection when it has come up. |
1593 |
error("not replacing existing default route via %I", |
1598 |
*/ |
1594 |
SIN_ADDR(rt.rt_gateway)); |
1599 |
|
1595 |
else |
1600 |
int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway, bool replace) |
1596 |
error("not replacing existing default route through %s", |
1601 |
{ |
1597 |
rt.rt_dev); |
1602 |
struct rtentry rt, tmp_rt; |
1598 |
return 0; |
1603 |
struct rtentry *del_rt = NULL; |
|
|
1604 |
|
1605 |
if (default_rt_repl_rest) { |
1606 |
/* We have already reclaced the original defaultroute, if we |
1607 |
* are called again, we will delete the current default route |
1608 |
* and set the new default route in this function. |
1609 |
* - this is normally only the case the doing demand: */ |
1610 |
if (defaultroute_exists( &tmp_rt )) |
1611 |
del_rt = &tmp_rt; |
1612 |
} else if ( defaultroute_exists( &old_def_rt ) && |
1613 |
strcmp( old_def_rt.rt_dev, ifname ) != 0) { |
1614 |
/* We did not yet replace an existing default route, let's |
1615 |
* check if we should save and replace a default route: |
1616 |
*/ |
1617 |
u_int32_t old_gateway = SIN_ADDR(old_def_rt.rt_gateway); |
1618 |
|
1619 |
if (old_gateway != gateway) { |
1620 |
if (!replace) { |
1621 |
error("not replacing default route to %s [%I]", |
1622 |
old_def_rt.rt_dev, old_gateway); |
1623 |
return 0; |
1624 |
} else { |
1625 |
// we need to copy rt_dev because we need it permanent too: |
1626 |
char * tmp_dev = malloc(strlen(old_def_rt.rt_dev)+1); |
1627 |
strcpy(tmp_dev, old_def_rt.rt_dev); |
1628 |
old_def_rt.rt_dev = tmp_dev; |
1629 |
|
1630 |
notice("replacing old default route to %s [%I]", |
1631 |
old_def_rt.rt_dev, old_gateway); |
1632 |
default_rt_repl_rest = 1; |
1633 |
del_rt = &old_def_rt; |
1634 |
} |
1635 |
} |
1599 |
} |
1636 |
} |
1600 |
|
|
|
1601 |
memset (&rt, 0, sizeof (rt)); |
1637 |
memset (&rt, 0, sizeof (rt)); |
1602 |
SET_SA_FAMILY (rt.rt_dst, AF_INET); |
1638 |
SET_SA_FAMILY (rt.rt_dst, AF_INET); |
1603 |
|
1639 |
|
Lines 1614-1619
Link Here
|
1614 |
error("default route ioctl(SIOCADDRT): %m"); |
1650 |
error("default route ioctl(SIOCADDRT): %m"); |
1615 |
return 0; |
1651 |
return 0; |
1616 |
} |
1652 |
} |
|
|
1653 |
if (default_rt_repl_rest && del_rt) |
1654 |
if (ioctl(sock_fd, SIOCDELRT, del_rt) < 0) { |
1655 |
if ( ! ok_error ( errno )) |
1656 |
error("del old default route ioctl(SIOCDELRT): %m(%d)", errno); |
1657 |
return 0; |
1658 |
} |
1617 |
|
1659 |
|
1618 |
have_default_route = 1; |
1660 |
have_default_route = 1; |
1619 |
return 1; |
1661 |
return 1; |
Lines 1647-1652
Link Here
|
1647 |
return 0; |
1689 |
return 0; |
1648 |
} |
1690 |
} |
1649 |
} |
1691 |
} |
|
|
1692 |
if (default_rt_repl_rest) { |
1693 |
notice("restoring old default route to %s [%I]", |
1694 |
old_def_rt.rt_dev, SIN_ADDR(old_def_rt.rt_gateway)); |
1695 |
if (ioctl(sock_fd, SIOCADDRT, &old_def_rt) < 0) { |
1696 |
if ( ! ok_error ( errno )) |
1697 |
error("restore default route ioctl(SIOCADDRT): %m(%d)", errno); |
1698 |
return 0; |
1699 |
} |
1700 |
default_rt_repl_rest = 0; |
1701 |
} |
1650 |
|
1702 |
|
1651 |
return 1; |
1703 |
return 1; |
1652 |
} |
1704 |
} |