2 * Layer Two Tunnelling Protocol Daemon
3 * Copyright (C) 1998 Adtran, Inc.
4 * Copyright (C) 2002 Jeff McAdams
8 * This software is distributed under the terms
9 * of the GPL, which you should have received
10 * along with this source.
12 * File format handling
21 #include <netinet/in.h>
23 #include <sys/types.h>
24 #include <sys/socket.h>
32 struct global gconfig
;
35 int parse_config (FILE *);
36 struct keyword words
[];
43 gconfig
.port
= UDP_LISTEN_PORT
;
44 gconfig
.listenaddr
= htonl(INADDR_ANY
); /* Default is to bind (listen) to all interfaces */
45 gconfig
.debug_avp
= 0;
46 gconfig
.debug_network
= 0;
47 gconfig
.packet_dump
= 0;
48 gconfig
.debug_tunnel
= 0;
49 gconfig
.debug_state
= 0;
52 deflac
= (struct lac
*) calloc (1, sizeof (struct lac
));
54 f
= fopen (gconfig
.configfile
, "r");
57 f
= fopen (gconfig
.altconfigfile
, "r");
60 l2tp_log (LOG_WARNING
, "%s: Using old style config files %s and %s\n",
61 __FUNCTION__
, gconfig
.altconfigfile
, gconfig
.altauthfile
);
62 strncpy (gconfig
.authfile
, gconfig
.altauthfile
,
63 sizeof (gconfig
.authfile
));
67 l2tp_log (LOG_CRIT
, "%s: Unable to open config file %s or %s\n",
68 __FUNCTION__
, gconfig
.configfile
, gconfig
.altconfigfile
);
73 returnedValue
= parse_config (f
);
75 return (returnedValue
);
79 struct lns
*new_lns ()
82 tmp
= (struct lns
*) calloc (1, sizeof (struct lns
));
85 l2tp_log (LOG_CRIT
, "%s: Unable to allocate memory for new LNS\n",
92 tmp
->tun_rws
= DEFAULT_RWS_SIZE
;
93 tmp
->call_rws
= DEFAULT_RWS_SIZE
;
94 tmp
->rxspeed
= DEFAULT_RX_BPS
;
95 tmp
->txspeed
= DEFAULT_TX_BPS
;
100 tmp
->authname
[0] = 0;
101 tmp
->peername
[0] = 0;
102 tmp
->hostname
[0] = 0;
105 tmp
->assign_ip
= 1; /* default to 'yes' */
108 tmp
->pap_require
= 0;
110 tmp
->chap_require
= 0;
111 tmp
->chap_refuse
= 0;
121 tmp
->pppoptfile
[0] = 0;
126 struct lac
*new_lac ()
129 tmp
= (struct lac
*) calloc (1, sizeof (struct lac
));
132 l2tp_log (LOG_CRIT
, "%s: Unable to allocate memory for lac entry!\n",
141 tmp
->tun_rws
= DEFAULT_RWS_SIZE
;
142 tmp
->call_rws
= DEFAULT_RWS_SIZE
;
147 tmp
->authname
[0] = 0;
148 tmp
->peername
[0] = 0;
149 tmp
->hostname
[0] = 0;
151 tmp
->pap_require
= 0;
153 tmp
->chap_require
= 0;
154 tmp
->chap_refuse
= 0;
164 tmp
->pppoptfile
[0] = 0;
165 tmp
->defaultroute
= 0;
169 int yesno (char *value
)
171 if (!strcasecmp (value
, "yes") || !strcasecmp (value
, "y") ||
172 !strcasecmp (value
, "true"))
174 else if (!strcasecmp (value
, "no") || !strcasecmp (value
, "n") ||
175 !strcasecmp (value
, "false"))
181 int set_boolean (char *word
, char *value
, int *ptr
)
185 l2tp_log (LOG_DEBUG
, "set_%s: %s flag to '%s'\n", word
, word
, value
);
187 if ((val
= yesno (value
)) < 0)
189 snprintf (filerr
, sizeof (filerr
), "%s must be 'yes' or 'no'\n",
197 int set_int (char *word
, char *value
, int *ptr
)
201 l2tp_log (LOG_DEBUG
, "set_%s: %s flag to '%s'\n", word
, word
, value
);
203 if ((val
= atoi (value
)) < 0)
205 snprintf (filerr
, sizeof (filerr
), "%s must be a number\n", word
);
212 int set_string (char *word
, char *value
, char *ptr
, int len
)
215 l2tp_log (LOG_DEBUG
, "set_%s: %s flag to '%s'\n", word
, word
, value
);
217 strncpy (ptr
, value
, len
);
221 int set_port (char *word
, char *value
, int context
, void *item
)
223 switch (context
& ~CONTEXT_DEFAULT
)
227 l2tp_log (LOG_DEBUG
, "set_port: Setting global port number to %s\n",
230 set_int (word
, value
, &(((struct global
*) item
)->port
));
233 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
240 int set_rtimeout (char *word
, char *value
, int context
, void *item
)
242 if (atoi (value
) < 1)
244 snprintf (filerr
, sizeof (filerr
),
245 "rtimeout value must be at least 1\n");
248 switch (context
& ~CONTEXT_DEFAULT
)
252 l2tp_log (LOG_DEBUG
, "set_rtimeout: Setting redial timeout to %s\n",
255 set_int (word
, value
, &(((struct lac
*) item
)->rtimeout
));
258 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
265 int set_rws (char *word
, char *value
, int context
, void *item
)
267 if (atoi (value
) < -1)
269 snprintf (filerr
, sizeof (filerr
),
270 "receive window size must be at least -1\n");
273 switch (context
& ~CONTEXT_DEFAULT
)
277 set_int (word
, value
, &(((struct lac
*) item
)->call_rws
));
280 set_int (word
, value
, &(((struct lac
*) item
)->tun_rws
));
281 if (((struct lac
*) item
)->tun_rws
< 1)
283 snprintf (filerr
, sizeof (filerr
),
284 "receive window size for tunnels must be at least 1\n");
291 set_int (word
, value
, &(((struct lns
*) item
)->call_rws
));
294 set_int (word
, value
, &(((struct lns
*) item
)->tun_rws
));
295 if (((struct lns
*) item
)->tun_rws
< 1)
297 snprintf (filerr
, sizeof (filerr
),
298 "receive window size for tunnels must be at least 1\n");
304 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
311 int set_speed (char *word
, char *value
, int context
, void *item
)
313 if (atoi (value
) < 1 )
315 snprintf (filerr
, sizeof (filerr
),
316 "bps must be greater than zero\n");
319 switch (context
& ~CONTEXT_DEFAULT
)
323 set_int (word
, value
, &(((struct lac
*) item
)->txspeed
));
324 else if (word
[0] == 'r')
325 set_int (word
, value
, &(((struct lac
*) item
)->rxspeed
));
328 set_int (word
, value
, &(((struct lac
*) item
)->rxspeed
));
329 set_int (word
, value
, &(((struct lac
*) item
)->txspeed
));
334 set_int (word
, value
, &(((struct lns
*) item
)->txspeed
));
335 else if (word
[0] == 'r')
336 set_int (word
, value
, &(((struct lns
*) item
)->rxspeed
));
339 set_int (word
, value
, &(((struct lns
*) item
)->rxspeed
));
340 set_int (word
, value
, &(((struct lns
*) item
)->txspeed
));
344 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
351 int set_rmax (char *word
, char *value
, int context
, void *item
)
353 if (atoi (value
) < 1)
355 snprintf (filerr
, sizeof (filerr
), "rmax value must be at least 1\n");
358 switch (context
& ~CONTEXT_DEFAULT
)
362 l2tp_log (LOG_DEBUG
, "set_rmax: Setting max redials to %s\n", value
);
364 set_int (word
, value
, &(((struct lac
*) item
)->rmax
));
367 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
374 int set_authfile (char *word
, char *value
, int context
, void *item
)
378 snprintf (filerr
, sizeof (filerr
),
379 "no filename specified for authentication\n");
382 switch (context
& ~CONTEXT_DEFAULT
)
386 l2tp_log (LOG_DEBUG
, "set_authfile: Setting global auth file to '%s'\n",
389 strncpy (((struct global
*) item
)->authfile
, value
,
390 sizeof (((struct global
*)item
)->authfile
));
393 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
400 int set_autodial (char *word
, char *value
, int context
, void *item
)
402 switch (context
& ~CONTEXT_DEFAULT
)
405 if (set_boolean (word
, value
, &(((struct lac
*) item
)->autodial
)))
409 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
416 int set_flow (char *word
, char *value
, int context
, void *item
)
419 set_boolean (word
, value
, &v
);
422 switch (context
& ~CONTEXT_DEFAULT
)
427 if (((struct lac
*) item
)->call_rws
< 0)
428 ((struct lac
*) item
)->call_rws
= 0;
432 ((struct lac
*) item
)->call_rws
= -1;
438 if (((struct lns
*) item
)->call_rws
< 0)
439 ((struct lns
*) item
)->call_rws
= 0;
443 ((struct lns
*) item
)->call_rws
= -1;
447 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
454 int set_defaultroute (char *word
, char *value
, int context
, void *item
)
456 switch (context
& ~CONTEXT_DEFAULT
)
459 if (set_boolean (word
, value
, &(((struct lac
*) item
)->defaultroute
)))
463 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
470 int set_authname (char *word
, char *value
, int context
, void *item
)
472 struct lac
*l
= (struct lac
*) item
;
473 struct lns
*n
= (struct lns
*) item
;
474 switch (context
& ~CONTEXT_DEFAULT
)
477 if (set_string (word
, value
, n
->authname
, sizeof (n
->authname
)))
481 if (set_string (word
, value
, l
->authname
, sizeof (l
->authname
)))
485 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
492 int set_hostname (char *word
, char *value
, int context
, void *item
)
494 struct lac
*l
= (struct lac
*) item
;
495 struct lns
*n
= (struct lns
*) item
;
496 switch (context
& ~CONTEXT_DEFAULT
)
499 if (set_string (word
, value
, n
->hostname
, sizeof (n
->hostname
)))
503 if (set_string (word
, value
, l
->hostname
, sizeof (l
->hostname
)))
507 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
514 int set_passwdauth (char *word
, char *value
, int context
, void *item
)
516 switch (context
& ~CONTEXT_DEFAULT
)
519 if (set_boolean (word
, value
, &(((struct lns
*) item
)->passwdauth
)))
523 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
530 int set_hbit (char *word
, char *value
, int context
, void *item
)
532 switch (context
& ~CONTEXT_DEFAULT
)
535 if (set_boolean (word
, value
, &(((struct lac
*) item
)->hbit
)))
539 if (set_boolean (word
, value
, &(((struct lns
*) item
)->hbit
)))
543 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
550 int set_challenge (char *word
, char *value
, int context
, void *item
)
552 switch (context
& ~CONTEXT_DEFAULT
)
555 if (set_boolean (word
, value
, &(((struct lac
*) item
)->challenge
)))
559 if (set_boolean (word
, value
, &(((struct lns
*) item
)->challenge
)))
563 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
570 int set_lbit (char *word
, char *value
, int context
, void *item
)
572 switch (context
& ~CONTEXT_DEFAULT
)
575 if (set_boolean (word
, value
, &(((struct lac
*) item
)->lbit
)))
579 if (set_boolean (word
, value
, &(((struct lns
*) item
)->lbit
)))
583 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
591 int set_debug (char *word
, char *value
, int context
, void *item
)
593 switch (context
& ~CONTEXT_DEFAULT
)
596 if (set_boolean (word
, value
, &(((struct lac
*) item
)->debug
)))
600 if (set_boolean (word
, value
, &(((struct lns
*) item
)->debug
)))
604 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
611 int set_pppoptfile (char *word
, char *value
, int context
, void *item
)
613 struct lac
*l
= (struct lac
*) item
;
614 struct lns
*n
= (struct lns
*) item
;
615 switch (context
& ~CONTEXT_DEFAULT
)
618 if (set_string (word
, value
, n
->pppoptfile
, sizeof (n
->pppoptfile
)))
622 if (set_string (word
, value
, l
->pppoptfile
, sizeof (l
->pppoptfile
)))
626 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
633 int set_papchap (char *word
, char *value
, int context
, void *item
)
637 struct lac
*l
= (struct lac
*) item
;
638 struct lns
*n
= (struct lns
*) item
;
639 if (set_boolean (word
, value
, &result
))
641 c
= strchr (word
, ' ');
643 switch (context
& ~CONTEXT_DEFAULT
)
646 if (c
[0] == 'p') /* PAP */
648 l
->pap_refuse
= result
;
650 l
->pap_require
= result
;
651 else if (c
[0] == 'a') /* Authentication */
653 l
->authself
= !result
;
655 l
->authpeer
= result
;
656 else /* CHAP */ if (word
[2] == 'f')
657 l
->chap_refuse
= result
;
659 l
->chap_require
= result
;
662 if (c
[0] == 'p') /* PAP */
664 n
->pap_refuse
= result
;
666 n
->pap_require
= result
;
667 else if (c
[0] == 'a') /* Authentication */
669 n
->authself
= !result
;
671 n
->authpeer
= result
;
672 else /* CHAP */ if (word
[2] == 'f')
673 n
->chap_refuse
= result
;
675 n
->chap_require
= result
;
678 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
685 int set_redial (char *word
, char *value
, int context
, void *item
)
687 switch (context
& ~CONTEXT_DEFAULT
)
690 if (set_boolean (word
, value
, &(((struct lac
*) item
)->redial
)))
694 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
701 int set_accesscontrol (char *word
, char *value
, int context
, void *item
)
703 switch (context
& ~CONTEXT_DEFAULT
)
707 (word
, value
, &(((struct global
*) item
)->accesscontrol
)))
711 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
718 int set_userspace (char *word
, char *value
, int context
, void *item
)
720 switch (context
& ~CONTEXT_DEFAULT
)
724 (word
, value
, &(((struct global
*) item
)->forceuserspace
)))
728 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
735 int set_debugavp (char *word
, char *value
, int context
, void *item
)
737 switch (context
& ~CONTEXT_DEFAULT
)
741 (word
, value
, &(((struct global
*) item
)->debug_avp
)))
745 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
752 int set_debugnetwork (char *word
, char *value
, int context
, void *item
)
754 switch (context
& ~CONTEXT_DEFAULT
)
758 (word
, value
, &(((struct global
*) item
)->debug_network
)))
762 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
769 int set_debugpacket (char *word
, char *value
, int context
, void *item
)
771 switch (context
& ~CONTEXT_DEFAULT
)
775 (word
, value
, &(((struct global
*) item
)->packet_dump
)))
779 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
786 int set_debugtunnel (char *word
, char *value
, int context
, void *item
)
788 switch (context
& ~CONTEXT_DEFAULT
)
792 (word
, value
, &(((struct global
*) item
)->debug_tunnel
)))
796 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
803 int set_debugstate (char *word
, char *value
, int context
, void *item
)
805 switch (context
& ~CONTEXT_DEFAULT
)
809 (word
, value
, &(((struct global
*) item
)->debug_state
)))
813 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
820 int set_assignip (char *word
, char *value
, int context
, void *item
)
822 switch (context
& ~CONTEXT_DEFAULT
)
825 if (set_boolean (word
, value
, &(((struct lns
*) item
)->assign_ip
)))
829 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
836 struct iprange
*set_range (char *word
, char *value
, struct iprange
*in
)
838 char *c
, *d
= NULL
, *e
= NULL
;
839 struct iprange
*ipr
, *p
;
842 c
= strchr (value
, '-');
847 while ((c
>= value
) && (*c
< 33))
849 while (*d
&& (*d
< 33))
852 if (!strlen (value
) || (c
&& !strlen (d
)))
854 snprintf (filerr
, sizeof (filerr
),
855 "format is '%s <host or ip> - <host or ip>'\n", word
);
858 ipr
= (struct iprange
*) malloc (sizeof (struct iprange
));
860 hp
= gethostbyname (value
);
863 snprintf (filerr
, sizeof (filerr
), "Unknown host %s\n", value
);
867 bcopy (hp
->h_addr
, &ipr
->start
, sizeof (unsigned int));
878 strcpy(ip_hi
, value
);
879 e
= strrchr(ip_hi
, '.')+1;
880 /* Copy the last field + null terminator */
884 hp
= gethostbyname (d
);
887 snprintf (filerr
, sizeof (filerr
), "Unknown host %s\n", d
);
891 bcopy (hp
->h_addr
, &ipr
->end
, sizeof (unsigned int));
894 ipr
->end
= ipr
->start
;
895 if (ntohl (ipr
->start
) > ntohl (ipr
->end
))
897 snprintf (filerr
, sizeof (filerr
), "start is greater than end!\n");
902 ipr
->sense
= SENSE_DENY
;
904 ipr
->sense
= SENSE_ALLOW
;
917 int set_iprange (char *word
, char *value
, int context
, void *item
)
919 struct lns
*lns
= (struct lns
*) item
;
920 switch (context
& ~CONTEXT_DEFAULT
)
925 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
929 lns
->range
= set_range (word
, value
, lns
->range
);
933 l2tp_log (LOG_DEBUG
, "range start = %x, end = %x, sense=%ud\n",
934 ntohl (lns
->range
->start
), ntohl (lns
->range
->end
), lns
->range
->sense
);
939 int set_lac (char *word
, char *value
, int context
, void *item
)
941 struct lns
*lns
= (struct lns
*) item
;
942 switch (context
& ~CONTEXT_DEFAULT
)
947 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
951 lns
->lacs
= set_range (word
, value
, lns
->lacs
);
955 l2tp_log (LOG_DEBUG
, "lac start = %x, end = %x, sense=%ud\n",
956 ntohl (lns
->lacs
->start
), ntohl (lns
->lacs
->end
), lns
->lacs
->sense
);
961 int set_exclusive (char *word
, char *value
, int context
, void *item
)
963 switch (context
& ~CONTEXT_DEFAULT
)
966 if (set_boolean (word
, value
, &(((struct lns
*) item
)->exclusive
)))
970 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
977 int set_ip (char *word
, char *value
, unsigned int *addr
)
980 hp
= gethostbyname (value
);
983 snprintf (filerr
, sizeof (filerr
), "%s: host '%s' not found\n",
984 __FUNCTION__
, value
);
987 bcopy (hp
->h_addr
, addr
, sizeof (unsigned int));
991 int set_listenaddr (char *word
, char *value
, int context
, void *item
)
993 switch (context
& ~CONTEXT_DEFAULT
)
997 l2tp_log (LOG_DEBUG
, "set_listenaddr: Setting listen address to %s\n",
1000 if (set_ip (word
, value
, &(((struct global
*) item
)->listenaddr
)))
1004 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1011 int set_localaddr (char *word
, char *value
, int context
, void *item
)
1015 switch (context
& ~CONTEXT_DEFAULT
)
1018 l
= (struct lac
*) item
;
1019 return set_ip (word
, value
, &(l
->localaddr
));
1021 n
= (struct lns
*) item
;
1022 return set_ip (word
, value
, &(n
->localaddr
));
1024 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1031 int set_remoteaddr (char *word
, char *value
, int context
, void *item
)
1034 switch (context
& ~CONTEXT_DEFAULT
)
1037 l
= (struct lac
*) item
;
1038 return set_ip (word
, value
, &(l
->remoteaddr
));
1040 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1047 int set_lns (char *word
, char *value
, int context
, void *item
)
1053 struct host
*ipr
, *pos
;
1055 switch (context
& ~CONTEXT_DEFAULT
)
1059 l2tp_log (LOG_DEBUG
, "set_lns: setting LNS to '%s'\n", value
);
1061 l
= (struct lac
*) item
;
1062 d
= strchr (value
, ':');
1069 // why would you want to lookup hostnames at this time?
1070 hp
= gethostbyname (value
);
1073 snprintf (filerr
, sizeof (filerr
), "no such host '%s'\n", value
);
1077 ipr
= malloc (sizeof (struct host
));
1090 strncpy (ipr
->hostname
, value
, sizeof (ipr
->hostname
));
1092 ipr
->port
= atoi (d
);
1094 ipr
->port
= UDP_LISTEN_PORT
;
1097 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1106 l2tp_log(LOG_WARNING
, "The \"rand()\" function call is not a very good source"
1108 rand_source
= RAND_SYS
;
1112 int set_ipsec_saref (char *word
, char *value
, int context
, void *item
)
1114 struct global
*g
= ((struct global
*) item
);
1115 switch (context
& ~CONTEXT_DEFAULT
)
1117 case CONTEXT_GLOBAL
:
1119 (word
, value
, &(g
->ipsecsaref
)))
1122 l2tp_log(LOG_WARNING
, "Enabling IPsec SAref processing for L2TP transport mode SAs\n");
1124 if(g
->forceuserspace
!= 1) {
1125 l2tp_log(LOG_WARNING
, "IPsec SAref does not work with L2TP kernel mode yet, enabling forceuserspace=yes\n");
1129 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1138 rand_source
= RAND_DEV
;
1142 int set_rand_egd (char *value
)
1144 l2tp_log(LOG_WARNING
, "%s: not yet implemented!\n", __FUNCTION__
);
1145 rand_source
= RAND_EGD
;
1149 int set_rand_source (char *word
, char *value
, int context
, void *item
)
1153 * We're going to go ahead and seed the rand() function with srand()
1154 * because even if we set the randomness source to dev or egd, they
1155 * can fall back to sys if they fail, so we want to make sure we at
1156 * least have *some* semblance of randomness available from the
1160 * This is a sucky random number seed...just the result from the
1161 * time() call...but...the user requested to use the rand()
1162 * function, which is a pretty sucky source of randomness
1163 * regardless...at least we can get a almost sorta decent seed. If
1164 * you have any better suggestions for creating a seed...lemme know
1167 seconds
= time(NULL
);
1170 if (context
!= CONTEXT_GLOBAL
)
1172 l2tp_log(LOG_WARNING
, "%s: %s not valid in context %d\n",
1173 __FUNCTION__
, word
, context
);
1177 if (strlen(value
) == 0)
1179 snprintf(filerr
, sizeof (filerr
), "no randomness source specified\n");
1182 if (strncmp(value
, "egd", 3) == 0)
1184 return set_rand_egd(value
);
1186 else if (strncmp(value
, "dev", 3) == 0)
1188 return set_rand_dev();
1190 else if (strncmp(value
, "sys", 3) == 0)
1192 return set_rand_sys();
1196 l2tp_log(LOG_WARNING
, "%s: %s is not a valid randomness source\n",
1197 __FUNCTION__
, value
);
1203 int parse_config (FILE * f
)
1205 /* Read in the configuration file handed to us */
1206 /* FIXME: I should check for incompatible options */
1218 fgets (buf
, sizeof (buf
), f
);
1223 /* Strip comments */
1224 while (*s
&& *s
!= ';')
1230 while ((*s
< 33) && *s
)
1231 s
++; /* Skip over beginning white space */
1233 while ((t
>= s
) && (*t
< 33))
1234 *(t
--) = 0; /* Ditch trailing white space */
1239 /* We've got a context description */
1240 if (!(t
= strchr (s
, ']')))
1242 l2tp_log (LOG_CRIT
, "parse_config: line %d: No closing bracket\n",
1248 if ((d
= strchr (s
, ' ')))
1250 /* There's a parameter */
1254 if (d
&& !strcasecmp (d
, "default"))
1255 def
= CONTEXT_DEFAULT
;
1258 if (!strcasecmp (s
, "global"))
1260 context
= CONTEXT_GLOBAL
;
1262 l2tp_log (LOG_DEBUG
,
1263 "parse_config: global context descriptor %s\n",
1268 else if (!strcasecmp (s
, "lns"))
1270 context
= CONTEXT_LNS
;
1275 deflns
= new_lns ();
1276 strncpy (deflns
->entname
, "default",
1277 sizeof (deflns
->entname
));
1288 if (!strcasecmp (d
, tl
->entname
))
1300 ((struct lns
*) data
)->next
= lnslist
;
1301 lnslist
= (struct lns
*) data
;
1304 strncpy (((struct lns
*) data
)->entname
,
1305 d
, sizeof (((struct lns
*) data
)->entname
));
1307 l2tp_log (LOG_DEBUG
, "parse_config: lns context descriptor %s\n",
1311 else if (!strcasecmp (s
, "lac"))
1313 context
= CONTEXT_LAC
;
1318 deflac
= new_lac ();
1319 strncpy (deflac
->entname
, "default",
1320 sizeof (deflac
->entname
));
1331 if (!strcasecmp (d
, tc
->entname
))
1343 ((struct lac
*) data
)->next
= laclist
;
1344 laclist
= (struct lac
*) data
;
1347 strncpy (((struct lac
*) data
)->entname
,
1348 d
, sizeof (((struct lac
*) data
)->entname
));
1350 l2tp_log (LOG_DEBUG
, "parse_config: lac context descriptor %s\n",
1356 l2tp_log (LOG_WARNING
,
1357 "parse_config: line %d: unknown context '%s'\n", linenum
,
1366 l2tp_log (LOG_WARNING
,
1367 "parse_config: line %d: data '%s' occurs with no context\n",
1371 if (!(t
= strchr (s
, '=')))
1373 l2tp_log (LOG_WARNING
, "parse_config: line %d: no '=' in data\n",
1380 while ((d
>= s
) && (*d
< 33))
1384 while (*t
&& (*t
< 33))
1387 l2tp_log (LOG_DEBUG
, "parse_config: field is %s, value is %s\n", s
, t
);
1389 /* Okay, bit twidling is done. Let's handle this */
1390 for (kw
= words
; kw
->keyword
; kw
++)
1392 if (!strcasecmp (s
, kw
->keyword
))
1394 if (kw
->handler (s
, t
, context
| def
, data
))
1396 l2tp_log (LOG_WARNING
, "parse_config: line %d: %s", linenum
,
1405 l2tp_log (LOG_CRIT
, "parse_config: line %d: Unknown field '%s'\n",
1414 struct keyword words
[] = {
1415 {"listen-addr", &set_listenaddr
},
1416 {"port", &set_port
},
1417 {"rand source", &set_rand_source
},
1418 {"auth file", &set_authfile
},
1419 {"exclusive", &set_exclusive
},
1420 {"autodial", &set_autodial
},
1421 {"redial", &set_redial
},
1422 {"redial timeout", &set_rtimeout
},
1424 {"max redials", &set_rmax
},
1425 {"access control", &set_accesscontrol
},
1426 {"force userspace", &set_userspace
},
1427 {"ip range", &set_iprange
},
1428 {"no ip range", &set_iprange
},
1429 {"debug avp", &set_debugavp
},
1430 {"debug network", &set_debugnetwork
},
1431 {"debug packet", &set_debugpacket
},
1432 {"debug tunnel", &set_debugtunnel
},
1433 {"debug state", &set_debugstate
},
1434 {"ipsec saref", &set_ipsec_saref
},
1436 {"no lac", &set_lac
},
1437 {"assign ip", &set_assignip
},
1438 {"local ip", &set_localaddr
},
1439 {"remote ip", &set_remoteaddr
},
1440 {"defaultroute", &set_defaultroute
},
1441 {"length bit", &set_lbit
},
1442 {"hidden bit", &set_hbit
},
1443 {"require pap", &set_papchap
},
1444 {"require chap", &set_papchap
},
1445 {"require authentication", &set_papchap
},
1446 {"require auth", &set_papchap
},
1447 {"refuse pap", &set_papchap
},
1448 {"refuse chap", &set_papchap
},
1449 {"refuse authentication", &set_papchap
},
1450 {"refuse auth", &set_papchap
},
1451 {"unix authentication", &set_passwdauth
},
1452 {"unix auth", &set_passwdauth
},
1453 {"name", &set_authname
},
1454 {"hostname", &set_hostname
},
1455 {"ppp debug", &set_debug
},
1456 {"pppoptfile", &set_pppoptfile
},
1457 {"call rws", &set_rws
},
1458 {"tunnel rws", &set_rws
},
1459 {"flow bit", &set_flow
},
1460 {"challenge", &set_challenge
},
1461 {"tx bps", &set_speed
},
1462 {"rx bps", &set_speed
},
1463 {"bps", &set_speed
},