#include <sys/errno.h>
#include <sys/file.h>
#include <sys/stat.h>
+#include <sys/utsname.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <ctype.h>
+#include <termios.h>
+#include <unistd.h>
/* This is in netdevice.h. However, this compile will fail miserably if
you attempt to include netdevice.h because it has so many references
#define MAX_ADDR_LEN 7
#endif
+#if __GLIBC__ >= 2
#include <net/if.h>
-#include <linux/ppp_defs.h>
#include <net/if_arp.h>
-#include <linux/if_ppp.h>
#include <net/route.h>
+#include <netinet/if_ether.h>
+#else
+#include <linux/if.h>
+#include <linux/if_arp.h>
+#include <linux/route.h>
#include <linux/if_ether.h>
+#endif
#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <linux/types.h>
+#include <linux/ppp_defs.h>
+#include <linux/if_ppp.h>
#include "pppd.h"
#include "fsm.h"
#include "ipcp.h"
+#include "patchlevel.h"
#ifdef IPX_CHANGE
#include "ipxcp.h"
+#include <linux/ipx.h>
+#endif /* IPX_CHANGE */
+
+#ifdef LOCKLIB
+#include <sys/locks.h>
+#endif
+
+#ifndef RTF_DEFAULT /* Normally in <linux/route.h> from <net/route.h> */
+#define RTF_DEFAULT 0
#endif
#define ok_error(num) ((num)==EIO)
static int driver_version = 0;
static int driver_modification = 0;
static int driver_patch = 0;
+static int driver_is_old = 0;
static int restore_term = 0; /* 1 => we've munged the terminal */
static struct termios inittermios; /* Initial TTY termios */
static char *lock_file;
+static struct utsname utsname; /* for the kernel version */
+
#define MAX_IFS 100
#define FLAGS_GOOD (IFF_UP | IFF_BROADCAST)
*/
extern int hungup;
-#define still_ppp() (hungup == 0)
#ifndef LOCK_PREFIX
#define LOCK_PREFIX "/var/lock/LCK.."
#endif
-/********************************************************************
- *
- * Functions to read and set the flags value in the device driver
- */
-
static void set_ppp_fd (int new_fd)
- {
- SYSDEBUG ((LOG_DEBUG, "setting ppp_fd to %d\n", ppp_fd));
- ppp_fd = new_fd;
- }
+{
+ SYSDEBUG ((LOG_DEBUG, "setting ppp_fd to %d\n", ppp_fd));
+ ppp_fd = new_fd;
+}
+
+static int still_ppp(void)
+{
+ if (!hungup || ppp_fd == slave_fd)
+ return 1;
+ if (slave_fd >= 0) {
+ set_ppp_fd(slave_fd);
+ return 1;
+ }
+ return 0;
+}
/********************************************************************
*
die(1);
}
}
+
+ uname(&utsname);
}
/********************************************************************
void sys_cleanup(void)
{
- struct ifreq ifr;
/*
* Take down the device
*/
*/
if (default_route_gateway != 0)
{
- cifdefaultroute(0, default_route_gateway);
+ cifdefaultroute(0, 0, default_route_gateway);
}
if (has_proxy_arp)
void disestablish_ppp(int tty_fd)
{
- int x;
- char *s;
-
/*
* Attempt to restore the previous tty settings
*/
#endif
#ifdef EXTB
{ 38400, EXTB },
+#endif
+#ifdef B230400
+ { 230400, B230400 },
+#endif
+#ifdef B460800
+ { 460800, B460800 },
#endif
{ 0, 0 }
};
void set_up_tty (int tty_fd, int local)
{
- int speed, x;
+ int speed;
struct termios tios;
if (tcgetattr(tty_fd, &tios) < 0)
{
if (debug)
{
- log_packet(p, len, "sent ");
+ log_packet(p, len, "sent ", LOG_DEBUG);
}
if (write(ppp_fd, p, len) < 0)
}
fclose (fp);
}
- return 0;
+
+ /* Default the mount location of /proc */
+ strncpy (route_buffer, "/proc", sizeof (route_buffer)-10);
+ return 1;
}
/********************************************************************
static int read_route_table (struct rtentry *rt)
{
static char delims[] = " \t\n";
- char *dev_ptr, *ptr, *dst_ptr, *gw_ptr, *flag_ptr;
+ char *dev_ptr, *dst_ptr, *gw_ptr, *flag_ptr;
memset (rt, '\0', sizeof (struct rtentry));
* sifdefaultroute - assign a default route through the address given.
*/
-int sifdefaultroute (int unit, u_int32_t gateway)
+int sifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway)
{
struct rtentry rt;
if (defaultroute_exists(&rt))
{
- u_int32_t old_gateway = ((struct sockaddr_in *) (&rt.rt_gateway))->
- sin_addr.s_addr;
+ struct in_addr old_gateway =
+ ((struct sockaddr_in *) (&rt.rt_gateway))-> sin_addr;
- if (old_gateway != gateway)
+ if (old_gateway.s_addr != gateway)
{
syslog (LOG_ERR,
- "ppp not replacing existing default route to %s[%s]",
+ "not replacing existing default route to %s [%s]",
rt.rt_dev,
inet_ntoa (old_gateway));
}
memset (&rt, '\0', sizeof (rt));
SET_SA_FAMILY (rt.rt_dst, AF_INET);
SET_SA_FAMILY (rt.rt_gateway, AF_INET);
+
+ if (strcmp(utsname.release, "2.1.0") > 0) {
+ SET_SA_FAMILY (rt.rt_genmask, AF_INET);
+ ((struct sockaddr_in *) &rt.rt_genmask)->sin_addr.s_addr = 0L;
+ }
+
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = gateway;
- rt.rt_flags = RTF_UP | RTF_GATEWAY;
+ rt.rt_flags = RTF_UP | RTF_GATEWAY | RTF_DEFAULT;
if (ioctl(sock_fd, SIOCADDRT, &rt) < 0)
{
if ( ! ok_error ( errno ))
* cifdefaultroute - delete a default route through the address given.
*/
-int cifdefaultroute (int unit, u_int32_t gateway)
+int cifdefaultroute (int unit, u_int32_t ouraddr, u_int32_t gateway)
{
struct rtentry rt;
memset (&rt, '\0', sizeof (rt));
SET_SA_FAMILY (rt.rt_dst, AF_INET);
SET_SA_FAMILY (rt.rt_gateway, AF_INET);
+
+ if (strcmp(utsname.release, "2.1.0") > 0) {
+ SET_SA_FAMILY (rt.rt_genmask, AF_INET);
+ ((struct sockaddr_in *) &rt.rt_genmask)->sin_addr.s_addr = 0L;
+ }
+
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = gateway;
- rt.rt_flags = RTF_UP | RTF_GATEWAY;
+ rt.rt_flags = RTF_UP | RTF_GATEWAY | RTF_DEFAULT;
if (ioctl(sock_fd, SIOCDELRT, &rt) < 0 && errno != ESRCH)
{
if (still_ppp())
{
memset (&arpreq, '\0', sizeof(arpreq));
SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
-
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = his_adr;
+ arpreq.arp_flags = ATF_PERM | ATF_PUBL;
+
if (ioctl(sock_fd, SIOCDARP, (caddr_t)&arpreq) < 0)
{
if ( ! ok_error ( errno ))
struct sockaddr *hwaddr,
char *name)
{
- struct ifreq *ifr, *ifend, *ifp;
- int i;
+ struct ifreq *ifr, *ifend;
u_int32_t ina, mask;
- struct sockaddr_dl *dla;
struct ifreq ifreq;
struct ifconf ifc;
struct ifreq ifs[MAX_IFS];
/********************************************************************
*
- * Procedure to determine if the PPP line dicipline is registered.
+ * Procedure to determine if the PPP line discipline is registered.
*/
int
if (!ok)
{
no_ppp_msg =
- "This system lacks kernel support for PPP. To include PPP support\n"
- "in the kernel, please follow the steps detailed in the "
- "README.linux\nfile in the ppp-2.3 distribution.\n";
+ "This system lacks kernel support for PPP. This could be because\n"
+ "the PPP kernel module is not loaded, or because the kernel is\n"
+ "not configured for PPP. See the README.linux file in the\n"
+ "ppp-2.3.3 distribution.\n";
}
/*
* This is the PPP device. Validate the version of the driver at this
/*
* Validate the version of the driver against the version that we used.
*/
- decode_version (PPP_VERSION,
+ decode_version (VERSION,
&my_version,
&my_modification,
&my_patch);
/* The modification levels must be legal */
if (driver_modification < my_modification)
{
- ok = 0;
+ if (driver_modification >= 2) {
+ /* we can cope with 2.2.0 and above */
+ driver_is_old = 1;
+ } else {
+ ok = 0;
+ }
}
close (s);
* Update the wtmp file with the appropriate user name and tty device.
*/
-int logwtmp (char *line, char *name, char *host)
+void logwtmp (const char *line, const char *name, const char *host)
{
int wtmp;
struct utmp ut, *utp;
int lock (char *dev)
{
+#ifdef LOCKLIB
+ int result;
+ lock_file = malloc(strlen(dev) + 1);
+ if (lock_file == NULL)
+ {
+ novm("lock file name");
+ }
+ strcpy (lock_file, dev);
+ result = mklock (dev, (void *) 0);
+
+ if (result > 0)
+ {
+ syslog (LOG_NOTICE, "Device %s is locked by pid %d", dev, result);
+ free (lock_file);
+ lock_file = NULL;
+ result = -1;
+ }
+ else
+ {
+ if (result < 0)
+ {
+ syslog (LOG_ERR, "Can't create lock file %s", lock_file);
+ free (lock_file);
+ lock_file = NULL;
+ result = -1;
+ }
+ }
+ return (result);
+#else
char hdb_lock_buffer[12];
int fd, n;
int pid = getpid();
#else
pid = ((int *) hdb_lock_buffer)[0];
#endif
- if (pid == 0 || (kill(pid, 0) == -1 && errno == ESRCH))
+ if (pid == 0 || pid == getpid()
+ || (kill(pid, 0) == -1 && errno == ESRCH))
{
n = 0;
}
free(lock_file);
lock_file = NULL;
return -1;
+#endif
}
{
if (lock_file)
{
+#ifdef LOCKLIB
+ (void) rmlock (lock_file, (void *) 0);
+#else
unlink(lock_file);
+#endif
free(lock_file);
lock_file = NULL;
}
{
if (! ok_error (errno))
{
- syslog (LOG_ERR, "ioctl(PPPIOCSFLAGS): %m(%d)", errno);
+ syslog (LOG_ERR, "ioctl(PPPIOCSMAXCID): %m(%d)", errno);
}
vjcomp = 0;
}
return (0);
}
/*
- * Set the netmask
+ * Set the netmask.
+ * For recent kernels, force the netmask to 255.255.255.255.
*/
+ if (strcmp(utsname.release, "2.1.16") >= 0)
+ net_mask = ~0L;
if (net_mask != 0)
{
((struct sockaddr_in *) &ifr.ifr_netmask)->sin_addr.s_addr = net_mask;
/*
* Add the device route
*/
- SET_SA_FAMILY (rt.rt_dst, AF_INET);
- SET_SA_FAMILY (rt.rt_gateway, AF_INET);
- rt.rt_dev = ifname; /* MJC */
+ if (strcmp(utsname.release, "2.1.16") < 0) {
+ SET_SA_FAMILY (rt.rt_dst, AF_INET);
+ SET_SA_FAMILY (rt.rt_gateway, AF_INET);
+ rt.rt_dev = ifname;
- ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = 0L;
- ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = his_adr;
- rt.rt_flags = RTF_UP | RTF_HOST;
+ ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = 0L;
+ ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = his_adr;
+ rt.rt_flags = RTF_UP | RTF_HOST;
- if (ioctl(sock_fd, SIOCADDRT, &rt) < 0)
- {
- if (! ok_error (errno))
- {
- syslog (LOG_ERR, "ioctl(SIOCADDRT) device route: %m(%d)", errno);
- }
- return (0);
+ if (strcmp(utsname.release, "2.1.0") > 0) {
+ SET_SA_FAMILY (rt.rt_genmask, AF_INET);
+ ((struct sockaddr_in *) &rt.rt_genmask)->sin_addr.s_addr = -1L;
}
+
+ if (ioctl(sock_fd, SIOCADDRT, &rt) < 0)
+ {
+ if (! ok_error (errno))
+ {
+ syslog (LOG_ERR, "ioctl(SIOCADDRT) device route: %m(%d)", errno);
+ }
+ return (0);
+ }
+ }
return 1;
}
int cifaddr (int unit, u_int32_t our_adr, u_int32_t his_adr)
{
struct rtentry rt;
+
+ if (strcmp(utsname.release, "2.1.16") < 0) {
/*
* Delete the route through the device
*/
- memset (&rt, '\0', sizeof (rt));
+ memset (&rt, '\0', sizeof (rt));
- SET_SA_FAMILY (rt.rt_dst, AF_INET);
- SET_SA_FAMILY (rt.rt_gateway, AF_INET);
- rt.rt_dev = ifname; /* MJC */
+ SET_SA_FAMILY (rt.rt_dst, AF_INET);
+ SET_SA_FAMILY (rt.rt_gateway, AF_INET);
+ rt.rt_dev = ifname;
- ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = 0;
- ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = his_adr;
- rt.rt_flags = RTF_UP | RTF_HOST;
+ ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = 0;
+ ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = his_adr;
+ rt.rt_flags = RTF_UP | RTF_HOST;
- if (ioctl(sock_fd, SIOCDELRT, &rt) < 0 && errno != ESRCH)
- {
- if (still_ppp() && ! ok_error (errno))
- {
- syslog (LOG_ERR, "ioctl(SIOCDELRT) device route: %m(%d)", errno);
- }
- return (0);
+ if (strcmp(utsname.release, "2.1.0") > 0) {
+ SET_SA_FAMILY (rt.rt_genmask, AF_INET);
+ ((struct sockaddr_in *) &rt.rt_genmask)->sin_addr.s_addr = -1L;
}
+
+ if (ioctl(sock_fd, SIOCDELRT, &rt) < 0 && errno != ESRCH)
+ {
+ if (still_ppp() && ! ok_error (errno))
+ {
+ syslog (LOG_ERR, "ioctl(SIOCDELRT) device route: %m(%d)", errno);
+ }
+ return (0);
+ }
+ }
return 1;
}
void
open_ppp_loopback(void)
{
- int flags;
+ int flags, i;
struct termios tios;
- if (openpty (&master_fd, &slave_fd, loop_name, NULL, NULL) < 0)
- {
- syslog(LOG_ERR, "No free pty for loopback");
- die(1);
- }
+ master_fd = -1;
+ for (i = 0; i < 64; ++i) {
+ sprintf(loop_name, "/dev/pty%c%x", 'p' + i / 16, i % 16);
+ master_fd = open(loop_name, O_RDWR | O_NOCTTY, 0);
+ if (master_fd >= 0)
+ break;
+ }
+ if (master_fd < 0) {
+ syslog(LOG_ERR, "No free pty for loopback");
+ die(1);
+ }
SYSDEBUG((LOG_DEBUG, "using %s for loopback", loop_name));
+ loop_name[5] = 't';
+ slave_fd = open(loop_name, O_RDWR | O_NOCTTY, 0);
+ if (slave_fd < 0) {
+ syslog(LOG_ERR, "Couldn't open %s for loopback: %m", loop_name);
+ die(1);
+ }
set_ppp_fd(slave_fd);
}
\f
-#include <linux/ipx.h>
-
/********************************************************************
*
* sipxfaddr - Config the interface IPX networknumber
int sipxfaddr (int unit, unsigned long int network, unsigned char * node )
{
- int skfd;
int result = 1;
- struct sockaddr_ipx ipx_addr;
+
+#ifdef IPX_CHANGE
+ int skfd;
struct ifreq ifr;
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) &ifr.ifr_addr;
-#ifdef IPX_CHANGE
skfd = socket (AF_IPX, SOCK_DGRAM, 0);
if (skfd < 0)
{
int cipxfaddr (int unit)
{
- int skfd;
int result = 1;
- struct sockaddr_ipx ipx_addr;
+
+#ifdef IPX_CHANGE
+ int skfd;
struct ifreq ifr;
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) &ifr.ifr_addr;
-#ifdef IPX_CHANGE
skfd = socket (AF_IPX, SOCK_DGRAM, 0);
if (skfd < 0)
{
return result;
}
+/*
+ * daemon - Detach us from controlling terminal session.
+ */
+int
+daemon(nochdir, noclose)
+ int nochdir, noclose;
+{
+ int pid;
+
+ if ((pid = fork()) < 0)
+ return -1;
+ if (pid != 0)
+ exit(0); /* parent dies */
+ setsid();
+ if (!nochdir)
+ chdir("/");
+ if (!noclose) {
+ fclose(stdin); /* don't need stdin, stdout, stderr */
+ fclose(stdout);
+ fclose(stderr);
+ }
+ return 0;
+}
+
+/*
+ * Use the hostname as part of the random number seed.
+ */
+int
+get_host_seed()
+{
+ int h;
+ char *p = hostname;
+
+ h = 407;
+ for (p = hostname; *p != 0; ++p)
+ h = h * 37 + *p;
+ return h;
+}
+
/********************************************************************
*
* sys_check_options - check the options that the user specified
break;
}
#endif
+ if (demand && driver_is_old) {
+ option_error("demand dialling is not supported by kernel driver version "
+ "%d.%d.%d", driver_version, driver_modification,
+ driver_patch);
+ demand = 0;
+ }
}