From 72c0b1a2991fe70301be3056c82d3c46509bc615 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Sat, 29 Apr 2000 08:57:24 +0000 Subject: [PATCH] Fixed bug in ipppd: MPdiscr is now random added option deldefaultroute --- ipppd/ipppd.h | 1 + ipppd/ipppd.man.in | 5 +++++ ipppd/lcp.c | 1 + ipppd/main.c | 10 +++++----- ipppd/options.c | 9 +++++++++ ipppd/sys-linux.c | 36 +++++++++++++++++++++++++----------- 6 files changed, 46 insertions(+), 16 deletions(-) diff --git a/ipppd/ipppd.h b/ipppd/ipppd.h index 6b6c139d..ee27c8a2 100644 --- a/ipppd/ipppd.h +++ b/ipppd/ipppd.h @@ -179,6 +179,7 @@ extern char sys_rcsid[]; extern int maxconnect; extern int usefirstip,useifip,useifmtu; +extern int deldefaultroute;/* delete default gw, if it exists */ extern int numdev; /* number of handled devices */ extern int debug; /* Debug flag */ extern int kdebugflag; /* Tell kernel to print debug messages */ diff --git a/ipppd/ipppd.man.in b/ipppd/ipppd.man.in index 9cdb9982..693e41f8 100644 --- a/ipppd/ipppd.man.in +++ b/ipppd/ipppd.man.in @@ -163,6 +163,11 @@ Disable the \fBdefaultroute\fR option. The system administrator who wishes to prevent users from creating default routes with \fIipppd\fR can do so by placing this option in the /etc/ppp/ioptions file. .TP +.B deldefaultroute +Replace default route if it already exists. Together with the option +\fBdefaultroute\fR, this will replace any existing default route by a new +one through this ipppd's interface when it comes up. +.TP .B -detach Don't fork to become a background process (otherwise .I ipppd diff --git a/ipppd/lcp.c b/ipppd/lcp.c index a023f3e9..028afb6d 100644 --- a/ipppd/lcp.c +++ b/ipppd/lcp.c @@ -190,6 +190,7 @@ static void lcp_init(int unit) { *(u_int32_t *) (&our_discr_addr[0]) = magic(); *(u_int32_t *) (&our_discr_addr[4]) = magic(); + first_call = 0; } diff --git a/ipppd/main.c b/ipppd/main.c index afd1f474..3560f9b4 100644 --- a/ipppd/main.c +++ b/ipppd/main.c @@ -165,6 +165,11 @@ int main(int argc,char **argv) exit(1); } + /* + * Initialize magic number package. + */ + magic_init(); + for(i=0;i #include #include +#include #include #include @@ -92,6 +93,10 @@ static void decode_version (char *buf, int *version, int sockfd; /* socket for doing interface ioctls */ static char *lock_file; +static int kernel_version; + +#define SIN_ADDR(x) (((struct sockaddr_in *) (&(x)))->sin_addr.s_addr) +#define KVERSION(j,n,p) ((j)*1000000 + (n)*1000 + (p)) #define MAX_IFS 4096 @@ -857,26 +862,35 @@ static int defaultroute_exists (void) int result = 0; if (!open_route_table()) - { - return 0; - } + return 0; while (read_route_table(&rt) != 0) { + if (kernel_version > KVERSION(2,1,0) && SIN_ADDR(rt.rt_genmask) != 0) + continue; + if ((rt.rt_flags & RTF_UP) == 0) - { - continue; - } + continue; if (((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr == 0L) { struct in_addr ina; ina.s_addr = ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr; - syslog (LOG_ERR, - "ppp not replacing existing default route to %s[%s]", - rt.rt_dev, inet_ntoa (ina) ); - result = 1; - break; + if (!deldefaultroute) + { + syslog (LOG_ERR, + "ppp not replacing existing default route to %s[%s]", + rt.rt_dev, inet_ntoa (ina) ); + result = 1; + break; + } + else + { + SET_SA_FAMILY (rt.rt_dst, AF_INET); + SET_SA_FAMILY (rt.rt_gateway, AF_INET); + rt.rt_flags = RTF_UP | RTF_GATEWAY; + ioctl(sockfd, SIOCDELRT, &rt); + } } }