1 diff -ruN l2tpd-0.70pre-old/l2tpd.c l2tpd-0.70pre-new/l2tpd.c
2 --- l2tpd-0.70pre-old/l2tpd.c 2005-12-16 12:34:12.000000000 +0100
3 +++ l2tpd-0.70pre-new/l2tpd.c 2005-12-16 12:34:54.000000000 +0100
8 +#include <sys/types.h>
9 #include <sys/utsname.h>
14 int start_pppd (struct call *c, struct ppp_opts *opts)
27 - if ((c->fd = getPtyMaster (&a, &b)) < 0)
28 + c->fd = open("/dev/ptmx", O_RDWR);
31 + log (LOG_WARN, "%s: unable to open /dev/ptmx to allocate pty\n",
38 + log (LOG_WARN, "%s: unable to grantpt() on pty\n",
43 + if (unlockpt(c->fd))
45 + log (LOG_WARN, "%s: unable to unlockpt() on pty\n",
50 + tty = ptsname(c->fd);
53 + log (LOG_WARN, "%s: unable to obtain name of slave tty\n",
61 + /* if ((c->fd = getPtyMaster (&a, &b)) < 0)
63 log (LOG_WARN, "%s: unable to allocate pty, abandoning!\n",
69 /* set fd opened above to not echo so we don't see read our own packets
70 back of the file descriptor that we just wrote them to */
72 ptyconf.c_cflag &= ~(ICANON | ECHO);
73 tcsetattr (c->fd, TCSANOW, &ptyconf);
75 - snprintf (tty, sizeof (tty), "/dev/tty%c%c", a, b);
76 +/* snprintf (tty, sizeof (tty), "/dev/tty%c%c", a, b); */
77 fd2 = open (tty, O_RDWR);
80 + log (LOG_WARN, "%s: unable to open slave tty %s\n", __FUNCTION__, tty);
87 diff -ruN l2tpd-0.70pre-old/l2tpd.c.orig l2tpd-0.70pre-new/l2tpd.c.orig
88 --- l2tpd-0.70pre-old/l2tpd.c.orig 1970-01-01 01:00:00.000000000 +0100
89 +++ l2tpd-0.70pre-new/l2tpd.c.orig 2005-12-16 12:14:24.000000000 +0100
94 + * Layer Two Tunnelling Protocol Daemon
95 + * Copyright (C) 1998 Adtran, Inc.
96 + * Copyright (C) 2002 Jeff McAdams
100 + * This software is distributed under the terms
101 + * of the GPL, which you should have received
102 + * along with this source.
104 + * Main Daemon source.
109 +#include <sys/utsname.h>
110 +#include <sys/stat.h>
111 +#include <sys/wait.h>
117 +# if defined(FREEBSD)
118 +# include <sys/signal.h>
119 +# elif defined(LINUX)
120 +# include <bsd/signal.h>
121 +# elif defined(SOLARIS)
122 +# include <signal.h>
125 +# include <signal.h>
130 +#include <netinet/in.h>
131 +#include <arpa/inet.h>
133 +#include <sys/ioctl.h>
137 +struct tunnel_list tunnels;
138 +int max_tunnels = DEF_MAX_TUNNELS;
140 +int ppd = 1; /* Packet processing delay */
141 +int control_fd; /* descriptor of control area */
144 +char *dial_no_tmp; /* jz: Dialnumber for Outgoing Call */
145 +int switch_io = 0; /* jz: Switch for Incoming or Outgoing Call */
147 +void init_tunnel_list (struct tunnel_list *t)
154 +/* Now sends to syslog instead - MvO */
155 +void show_status (void)
157 + struct schedule_entry *se;
164 + log (LOG_WARN, "====== l2tpd statistics ========\n");
165 + log (LOG_WARN, " Scheduler entries:\n");
170 + t = (struct tunnel *) se->data;
171 + tlac = (struct lac *) se->data;
172 + c = (struct call *) se->data;
173 + if (se->func == &hello)
175 + log (LOG_WARN, "%d: HELLO to %d\n", s, t->tid);
177 + else if (se->func == &magic_lac_dial)
179 + log (LOG_WARN, "%d: Magic dial on %s\n", s, tlac->entname);
181 + else if (se->func == &send_zlb)
183 + log (LOG_WARN, "%d: Send payload ZLB on call %d:%d\n", s,
184 + c->container->tid, c->cid);
186 + else if (se->func == &dethrottle)
188 + log (LOG_WARN, "%d: Dethrottle call %d:%d\n", s, c->container->tid,
192 + log (LOG_WARN, "%d: Unknown event\n", s);
195 + log (LOG_WARN, "Total Events scheduled: %d\n", s);
196 + log (LOG_WARN, "Number of tunnels open: %d\n", tunnels.count);
200 + log (LOG_WARN, "Tunnel %s, ID = %d (local), %d (remote) to %s:%d\n"
201 + " control_seq_num = %d, control_rec_seq_num = %d,\n"
203 + (t->lac ? t->lac->entname : (t->lns ? t->lns->entname : "")),
204 + t->ourtid, t->tid, IPADDY (t->peer.sin_addr),
205 + ntohs (t->peer.sin_port), t->control_seq_num,
206 + t->control_rec_seq_num, t->cLr);
211 + "Call %s, ID = %d (local), %d (remote), serno = %u,\n"
212 + " data_seq_num = %d, data_rec_seq_num = %d,\n"
213 + " pLr = %d, tx = %u bytes (%u), rx= %u bytes (%u)\n",
215 + entname : (c->lns ? c->lns->entname : "")), c->ourcid,
216 + c->cid, c->serno, c->data_seq_num, c->data_rec_seq_num,
217 + c->pLr, c->tx_bytes, c->tx_pkts, c->rx_bytes, c->rx_pkts);
222 + log (LOG_WARN, "==========Config File===========\n");
226 + log (LOG_WARN, "LNS entry %s\n",
227 + tlns->entname[0] ? tlns->entname : "(unnamed)");
233 + log (LOG_WARN, "LAC entry %s, LNS is/are:",
234 + tlac->entname[0] ? tlac->entname : "(unnamed)");
240 + log (LOG_WARN, " %s", h->hostname);
245 + log (LOG_WARN, " [none]");
246 + log (LOG_WARN, "\n");
249 + log (LOG_WARN, "================================\n");
252 +void null_handler(int sig)
255 + * A sighup is received when a call is terminated, unknown origine ..
256 + * I catch it and ll looks good, but ..
260 +void status_handler (int sig)
265 +void child_handler (int signal)
268 + * Oops, somebody we launched was killed.
269 + * It's time to reap them and close that call.
270 + * But first, we have to find out what PID died.
271 + * unfortunately, pppd will
278 + /* Keep looping until all are cleared */
281 + pid = waitpid (-1, &status, WNOHANG);
285 + * Oh well, nobody there. Maybe we reaped it
286 + * somewhere else already
295 + if (c->pppd == pid)
297 + if ( WIFEXITED( status ) )
299 + log (LOG_DEBUG, "%s : pppd exited for call %d with code %d\n", __FUNCTION__,
300 + c->cid, WEXITSTATUS( status ) );
302 + else if( WIFSIGNALED( status ) )
304 + log (LOG_DEBUG, "%s : pppd terminated for call %d by signal %d\n", __FUNCTION__,
305 + c->cid, WTERMSIG( status ) );
309 + log (LOG_DEBUG, "%s : pppd exited for call %d for unknown reason\n", __FUNCTION__,
314 + * OK...pppd died, we can go ahead and close the pty for
328 +void death_handler (int signal)
331 + * If we get here, somebody terminated us with a kill or a control-c.
332 + * we call call_close on each tunnel twice to get a StopCCN out
333 + * for each one (we can't pause to make sure it's received.
334 + * Then we close the connections
336 + struct tunnel *st, *st2;
338 + log (LOG_CRIT, "%s: Fatal signal %d received\n", __FUNCTION__, signal);
343 + strcpy (st->self->errormsg, "Server closing");
344 + sec = st->self->closing;
346 + st->lac->redial = 0;
347 + call_close (st->self);
350 + st->self->closing = -1;
351 + call_close (st->self);
356 + /* erase pid file */
357 + unlink (gconfig.pidfile);
359 + /* erase control pipe */
360 + unlink(CONTROL_PIPE);
365 +int start_pppd (struct call *c, struct ppp_opts *opts)
370 + struct ppp_opts *p;
372 + struct l2tp_call_opts co;
379 + struct termios ptyconf;
382 + stropt[0] = strdup (PPPD);
385 + stropt[pos] = (char *) malloc (strlen (p->option) + 1);
386 + strncpy (stropt[pos], p->option, strlen (p->option) + 1);
390 + stropt[pos] = NULL;
393 + log (LOG_WARN, "%s: PPP already started on call!\n", __FUNCTION__);
398 + log (LOG_WARN, "%s: file descriptor already assigned!\n",
403 + if (kernel_support)
405 + co.ourtid = c->container->ourtid;
406 + co.ourcid = c->ourcid;
407 + ioctl (server_socket, L2TPIOCGETCALLOPTS, &co);
408 + stropt[pos++] = strdup ("channel");
409 + stropt[pos] = (char *) malloc (10);
410 + snprintf (stropt[pos], 10, "%d", co.id);
412 + stropt[pos] = NULL;
417 + if ((c->fd = getPtyMaster (&a, &b)) < 0)
419 + log (LOG_WARN, "%s: unable to allocate pty, abandoning!\n",
424 + /* set fd opened above to not echo so we don't see read our own packets
425 + back of the file descriptor that we just wrote them to */
426 + tcgetattr (c->fd, &ptyconf);
427 + *(c->oldptyconf) = ptyconf;
428 + ptyconf.c_cflag &= ~(ICANON | ECHO);
429 + tcsetattr (c->fd, TCSANOW, &ptyconf);
431 + snprintf (tty, sizeof (tty), "/dev/tty%c%c", a, b);
432 + fd2 = open (tty, O_RDWR);
439 + log (LOG_DEBUG, "%s: I'm running: ", __FUNCTION__);
440 + for (x = 0; stropt[x]; x++)
442 + log (LOG_DEBUG, "\"%s\" ", stropt[x]);
444 + log (LOG_DEBUG, "\n");
449 + log (LOG_WARN, "%s: unable to fork(), abandoning!\n", __FUNCTION__);
461 + if (!kernel_support && (fd2 < 0))
466 + log (LOG_WARN, "%s: Unable to open %s to launch pppd!\n",
467 + __FUNCTION__, tty);
474 + /* close all the calls pty fds */
478 + sc = st->call_head;
487 + /* close the UDP socket fd */
488 + close (server_socket);
490 + /* close the control pipe fd */
491 + close (control_fd);
493 + if( c->dialing[0] )
495 + setenv( "CALLER_ID", c->dialing, 1 );
497 + execv (PPPD, stropt);
498 + log (LOG_WARN, "%s: Exec of %s failed!\n", __FUNCTION__, PPPD);
503 + while (stropt[pos])
505 + free (stropt[pos]);
511 +void destroy_tunnel (struct tunnel *t)
514 + * Immediately destroy a tunnel (and all its calls)
515 + * and free its resources. This may be called
516 + * by the tunnel itself,so it needs to be
520 + struct call *c, *me;
527 + * Save ourselves until the very
528 + * end, since we might be calling this ourselves.
529 + * We must divorce ourself from the tunnel
530 + * structure, however, to avoid recursion
531 + * because of the logic of the destroy_call
536 + * Destroy all the member calls
545 + * Remove ourselves from the list of tunnels
548 + if (tunnels.head == t)
550 + tunnels.head = t->next;
558 + while (p->next && (p->next != t))
568 + "%s: unable to locate tunnel in tunnel list\n",
574 + log (LOG_WARN, "%s: tunnel list is empty!\n", __FUNCTION__);
580 + if (t->lac->redial && (t->lac->rtimeout > 0) && !t->lac->rsched &&
583 + log (LOG_LOG, "%s: Will redial in %d seconds\n", __FUNCTION__,
585 + tv.tv_sec = t->lac->rtimeout;
587 + t->lac->rsched = schedule (tv, magic_lac_dial, t->lac);
590 + /* XXX L2TP/IPSec: remove relevant SAs here? NTB 20011010
591 + * XXX But what if another tunnel is using same SA?
599 +struct tunnel *l2tp_call (char *host, int port, struct lac *lac,
603 + * Establish a tunnel from us to host
606 + struct call *tmp = NULL;
607 + struct hostent *hp;
609 + port = htons (port);
610 + hp = gethostbyname (host);
613 + log (LOG_WARN, "%s: gethostbyname() failed for %s.\n", __FUNCTION__,
617 + bcopy (hp->h_addr, &addr, hp->h_length);
618 + /* Force creation of a new tunnel
619 + and set it's tid to 0 to cause
620 + negotiation to occur */
621 + /* XXX L2TP/IPSec: Set up SA to addr:port here? NTB 20011010
623 + tmp = get_call (0, 0, addr, port);
626 + log (LOG_WARN, "%s: Unable to create tunnel to %s.\n", __FUNCTION__,
630 + tmp->container->tid = 0;
631 + tmp->container->lac = lac;
632 + tmp->container->lns = lns;
636 + lac->t = tmp->container;
638 + lns->t = tmp->container;
640 + * Since our state is 0, we will establish a tunnel now
642 + log (LOG_LOG, "%s:Connecting to host %s, port %d\n", __FUNCTION__, host,
644 + control_finish (tmp->container, tmp);
645 + return tmp->container;
648 +void magic_lac_tunnel (void *data)
651 + lac = (struct lac *) data;
654 + log (LOG_WARN, "%s: magic_lac_tunnel: called on NULL lac!\n",
660 + /* FIXME: I should try different LNS's if I get failures */
661 + l2tp_call (lac->lns->hostname, lac->lns->port, lac, NULL);
664 + else if (deflac && deflac->lns)
666 + l2tp_call (deflac->lns->hostname, deflac->lns->port, lac, NULL);
671 + log (LOG_WARN, "%s: Unable to find hostname to dial for '%s'\n",
672 + __FUNCTION__, lac->entname);
677 +struct call *lac_call (int tid, struct lac *lac, struct lns *lns)
679 + struct tunnel *t = tunnels.head;
683 + if (t->ourtid == tid)
685 + tmp = new_call (t);
688 + log (LOG_WARN, "%s: unable to create new call\n",
692 + tmp->next = t->call_head;
693 + t->call_head = tmp;
700 + log (LOG_LOG, "%s: Calling on tunnel %d\n", __FUNCTION__, tid);
701 + strcpy (tmp->dial_no, dial_no_tmp); /* jz: copy dialnumber to tmp->dial_no */
702 + control_finish (t, tmp);
707 + log (LOG_DEBUG, "%s: No such tunnel %d to generate call.\n", __FUNCTION__,
712 +void magic_lac_dial (void *data)
715 + lac = (struct lac *) data;
719 + log (LOG_WARN, "%s : called on NULL lac!\n", __FUNCTION__);
724 + log (LOG_DEBUG, "%s: LAC %s not active", __FUNCTION__, lac->entname);
727 + lac->rsched = NULL;
729 + if (lac->rmax && (lac->rtries > lac->rmax))
731 + log (LOG_LOG, "%s: maximum retries exceeded.\n", __FUNCTION__);
737 + log (LOG_DEBUG, "%s : tunnel not up! Connecting!\n", __FUNCTION__);
739 + magic_lac_tunnel (lac);
742 + lac_call (lac->t->ourtid, lac, NULL);
745 +void lac_hangup (int cid)
747 + struct tunnel *t = tunnels.head;
751 + tmp = t->call_head;
754 + if (tmp->ourcid == cid)
757 + "%s :Hanging up call %d, Local: %d, Remote: %d\n",
758 + __FUNCTION__, tmp->serno, tmp->ourcid, tmp->cid);
759 + strcpy (tmp->errormsg, "Goodbye!");
760 +/* tmp->needclose = -1; */
761 + kill (tmp->pppd, SIGTERM);
768 + log (LOG_DEBUG, "%s : No such call %d to hang up.\n", __FUNCTION__, cid);
772 +void lac_disconnect (int tid)
774 + struct tunnel *t = tunnels.head;
777 + if (t->ourtid == tid)
780 + "%s: Disconnecting from %s, Local: %d, Remote: %d\n",
781 + __FUNCTION__, IPADDY (t->peer.sin_addr), t->ourtid, t->tid);
782 + t->self->needclose = -1;
783 + strcpy (t->self->errormsg, "Goodbye!");
784 + call_close (t->self);
789 + log (LOG_DEBUG, "%s: No such tunnel %d to hang up.\n", __FUNCTION__, tid);
793 +struct tunnel *new_tunnel ()
795 + struct tunnel *tmp = malloc (sizeof (struct tunnel));
796 + char entropy_buf[2] = "\0";
799 + tmp->control_seq_num = 0;
800 + tmp->control_rec_seq_num = 0;
802 + tmp->call_head = NULL;
808 +/* while(get_call((tmp->ourtid = rand() & 0xFFFF),0,0,0)); */
810 + if (kernel_support)
811 + tmp->ourtid = ioctl (server_socket, L2TPIOCADDTUNNEL, 0);
814 +/* tmp->ourtid = rand () & 0xFFFF; */
815 + /* get_entropy((char *)&tmp->ourtid, 2); */
816 + get_entropy(entropy_buf, 2);
819 + temp = (int *)entropy_buf;
820 + tmp->ourtid = *temp & 0xFFFF;
821 +#ifdef DEBUG_ENTROPY
822 + log(LOG_DEBUG, "ourtid = %u, entropy_buf = %hx\n", tmp->ourtid, *temp);
826 + tmp->ourtid = 0x6227;
830 + tmp->state = 0; /* Nothing */
831 + tmp->peer.sin_family = AF_INET;
832 + tmp->peer.sin_port = 0;
833 + bzero (&(tmp->peer.sin_addr), sizeof (tmp->peer.sin_addr));
836 + tmp->ourfc = ASYNC_FRAMING | SYNC_FRAMING;
838 + tmp->ourtb = (((_u64) rand ()) << 32) | ((_u64) rand ());
839 + tmp->fc = -1; /* These really need to be specified by the peer */
840 + tmp->bc = -1; /* And we want to know if they forgot */
841 + tmp->hostname[0] = 0;
842 + tmp->vendor[0] = 0;
843 + tmp->secret[0] = 0;
844 + if (!(tmp->self = new_call (tmp)))
849 + tmp->ourrws = DEFAULT_RWS_SIZE;
850 + tmp->self->ourfbit = FBIT;
853 + tmp->chal_us.state = 0;
854 + tmp->chal_us.secret[0] = 0;
855 + memset (tmp->chal_us.reply, 0, MD_SIG_SIZE);
856 + tmp->chal_them.state = 0;
857 + tmp->chal_them.secret[0] = 0;
858 + memset (tmp->chal_them.reply, 0, MD_SIG_SIZE);
859 + tmp->chal_them.vector = (unsigned char *) malloc (VECTOR_SIZE);
860 + tmp->chal_us.vector = NULL;
868 + char *host, *tunstr, *callstr, *tmpstr;
875 + cnt = read (control_fd, buf, sizeof (buf));
878 + if (buf[cnt - 1] == '\n')
880 +#ifdef DEBUG_CONTROL
881 + log (LOG_DEBUG, "%s: Got message \"%s\" (%d bytes long)\n",
882 + __FUNCTION__, buf, cnt);
887 + host = strchr (buf, ' ');
891 +#ifdef DEBUG_CONTROL
892 + log (LOG_DEBUG, "%s: Attempting to tunnel to %s\n",
893 + __FUNCTION__, host);
895 + l2tp_call (host, UDP_LISTEN_PORT, NULL, NULL);
897 + case 'c': /* option 'c' for incoming call */
898 + case 'o': /* option 'o' for outgoing call */
899 + tunstr = strchr (buf, ' ');
905 + switch_io = 1; /* Switch for Incoming Calls */
907 + switch_io = 0; /* Switch for Outgoing Calls */
908 + tmpstr = strchr(tunstr, ' ');
911 + strncpy(dial_no_tmp,tmpstr, sizeof(*dial_no_tmp));
917 + if (!strcasecmp (lac->entname, tunstr))
922 + magic_lac_dial (lac);
925 + "%s: Session '%s' already active!\n",
926 + __FUNCTION__, lac->entname);
933 + tunl = atoi (tunstr);
936 + log (LOG_DEBUG, "%s: No such tunnel '%s'\n", __FUNCTION__,
940 +#ifdef DEBUG_CONTROL
941 + log (LOG_DEBUG, "%s: Attempting to call on tunnel %d\n",
942 + __FUNCTION__, tunl);
944 + lac_call (tunl, NULL, NULL);
947 + callstr = strchr (buf, ' ');
952 + call = atoi (callstr);
953 +#ifdef DEBUG_CONTROL
954 + log (LOG_DEBUG, "%s: Attempting to call %d\n", __FUNCTION__,
960 + tunstr = strchr (buf, ' ');
968 + if (!strcasecmp (lac->entname, tunstr))
973 + lac_disconnect (lac->t->ourtid);
975 + log (LOG_DEBUG, "%s: Session '%s' not up\n",
976 + __FUNCTION__, lac->entname);
983 + tunl = atoi (tunstr);
986 + log (LOG_DEBUG, "%s: No such tunnel '%s'\n", __FUNCTION__,
990 +#ifdef DEBUG_CONTROL
991 + log (LOG_DEBUG, "%s: Attempting to disconnect tunnel %d\n",
992 + __FUNCTION__, tunl);
994 + lac_disconnect (tunl);
1000 + log (LOG_DEBUG, "%s: Unknown command %c\n", __FUNCTION__,
1007 + /* Otherwise select goes nuts */
1008 + close (control_fd);
1009 + control_fd = open (CONTROL_PIPE, O_RDONLY | O_NONBLOCK, 0600);
1013 + printf("Usage: l2tpd -D -c [config file] -s [secret file] -p [pid file]\n");
1018 +void init_args(int argc, char *argv[]) {
1021 + memset(gconfig.altauthfile,0,STRLEN);
1022 + memset(gconfig.altconfigfile,0,STRLEN);
1023 + memset(gconfig.authfile,0,STRLEN);
1024 + memset(gconfig.configfile,0,STRLEN);
1025 + memset(gconfig.pidfile,0,STRLEN);
1026 + strncpy(gconfig.altauthfile,ALT_DEFAULT_AUTH_FILE,
1027 + sizeof(gconfig.altauthfile) - 1);
1028 + strncpy(gconfig.altconfigfile,ALT_DEFAULT_CONFIG_FILE,
1029 + sizeof(gconfig.altconfigfile) - 1);
1030 + strncpy(gconfig.authfile,DEFAULT_AUTH_FILE,
1031 + sizeof(gconfig.authfile) - 1);
1032 + strncpy(gconfig.configfile,DEFAULT_CONFIG_FILE,
1033 + sizeof(gconfig.configfile) - 1);
1034 + strncpy(gconfig.pidfile,DEFAULT_PID_FILE,
1035 + sizeof(gconfig.pidfile) - 1);
1036 + for (i = 1; i < argc; i++) {
1037 + if(! strncmp(argv[i],"-c",2)) {
1041 + strncpy(gconfig.configfile,argv[i],
1042 + sizeof(gconfig.configfile) - 1);
1044 + else if (! strncmp(argv[i],"-D",2)) {
1047 + else if (! strncmp(argv[i],"-s",2)) {
1051 + strncpy(gconfig.authfile,argv[i],
1052 + sizeof(gconfig.authfile) - 1);
1054 + else if (! strncmp(argv[i],"-p",2)) {
1058 + strncpy(gconfig.pidfile,argv[i],
1059 + sizeof(gconfig.pidfile) - 1);
1073 + if((pid = fork()) < 0) {
1074 + log(LOG_LOG, "%s: Unable to fork ()\n",__FUNCTION__);
1075 + close(server_socket);
1085 + dup2(open("/dev/null", O_RDONLY), 0);
1086 + dup2(open("/dev/null", O_RDONLY), 1);
1087 + dup2(open("/dev/null", O_RDONLY), 2);
1089 + /* Read previous pid file. */
1090 + if((i = open(gconfig.pidfile,O_RDONLY)) > 0) {
1091 + l=read(i,buf,sizeof(buf)-1);
1098 + /* if pid is read and process exist exit */
1099 + if(pid && !kill(pid, 0)) {
1100 + log(LOG_LOG, "%s: There's already a l2tpd server running.\n",
1102 + close(server_socket);
1106 + /* remove stalled pid file */
1107 + unlink(gconfig.pidfile);
1112 + /* create new pid file */
1113 + if ((i = open (gconfig.pidfile, O_WRONLY | O_CREAT, 0644)) >= 0) {
1114 + snprintf (buf, sizeof(buf), "%d", (int)getpid());
1115 + write (i, buf, strlen(buf));
1119 + log(LOG_LOG, "%s: could not write pid file %s error %d",
1120 + __FUNCTION__, gconfig.pidfile, i);
1121 + close(server_socket);
1127 +void init (int argc,char *argv[])
1130 + struct in_addr listenaddr;
1132 + init_args (argc,argv);
1133 + srand( time(NULL) );
1136 + if (init_config ())
1138 + log (LOG_CRIT, "%s: Unable to load config file\n", __FUNCTION__);
1143 + log (LOG_CRIT, "%s : Unable to determine host system\n",
1147 + init_tunnel_list (&tunnels);
1148 + if (init_network ())
1150 + if (gconfig.daemon)
1152 + signal (SIGTERM, &death_handler);
1153 + signal (SIGINT, &death_handler);
1154 + signal (SIGCHLD, &child_handler);
1155 + signal (SIGUSR1, &status_handler);
1156 + signal (SIGHUP, &null_handler);
1157 + init_scheduler ();
1158 + mkfifo (CONTROL_PIPE, 0600);
1159 + control_fd = open (CONTROL_PIPE, O_RDONLY | O_NONBLOCK, 0600);
1160 + if (control_fd < 0)
1162 + log (LOG_CRIT, "%s: Unable to open " CONTROL_PIPE " for reading.",
1166 + log (LOG_LOG, "l2tpd version " SERVER_VERSION " started on %s PID:%d\n",
1167 + hostname, getpid ());
1168 + listenaddr.s_addr = gconfig.listenaddr;
1169 + log (LOG_LOG, "%s version %s on a %s, listening on IP address %s, port %d\n", uts.sysname,
1170 + uts.release, uts.machine, inet_ntoa(listenaddr), gconfig.port);
1174 + if (lac->autodial)
1177 + log (LOG_DEBUG, "%s: Autodialing '%s'\n", __FUNCTION__,
1178 + lac->entname[0] ? lac->entname : "(unnamed)");
1181 + switch_io = 1; /* If we're a LAC, autodials will be ICRQ's */
1182 + magic_lac_dial (lac);
1188 +int main (int argc, char *argv[])
1191 + dial_no_tmp = calloc (128, sizeof (char));
1192 + network_thread ();