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 for (e
= ip_hi
+ sizeof(ip_hi
); e
>= ip_hi
; e
--) {
880 if (*e
== '.') count
--;
886 /* Copy the last field + null terminator */
887 if (ip_hi
+ sizeof(ip_hi
)-e
> strlen(d
)) {
892 hp
= gethostbyname (d
);
895 snprintf (filerr
, sizeof (filerr
), "Unknown host %s\n", d
);
899 bcopy (hp
->h_addr
, &ipr
->end
, sizeof (unsigned int));
902 ipr
->end
= ipr
->start
;
903 if (ntohl (ipr
->start
) > ntohl (ipr
->end
))
905 snprintf (filerr
, sizeof (filerr
), "start is greater than end!\n");
910 ipr
->sense
= SENSE_DENY
;
912 ipr
->sense
= SENSE_ALLOW
;
925 int set_iprange (char *word
, char *value
, int context
, void *item
)
927 struct lns
*lns
= (struct lns
*) item
;
928 switch (context
& ~CONTEXT_DEFAULT
)
933 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
937 lns
->range
= set_range (word
, value
, lns
->range
);
941 l2tp_log (LOG_DEBUG
, "range start = %x, end = %x, sense=%ud\n",
942 ntohl (lns
->range
->start
), ntohl (lns
->range
->end
), lns
->range
->sense
);
947 int set_lac (char *word
, char *value
, int context
, void *item
)
949 struct lns
*lns
= (struct lns
*) item
;
950 switch (context
& ~CONTEXT_DEFAULT
)
955 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
959 lns
->lacs
= set_range (word
, value
, lns
->lacs
);
963 l2tp_log (LOG_DEBUG
, "lac start = %x, end = %x, sense=%ud\n",
964 ntohl (lns
->lacs
->start
), ntohl (lns
->lacs
->end
), lns
->lacs
->sense
);
969 int set_exclusive (char *word
, char *value
, int context
, void *item
)
971 switch (context
& ~CONTEXT_DEFAULT
)
974 if (set_boolean (word
, value
, &(((struct lns
*) item
)->exclusive
)))
978 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
985 int set_ip (char *word
, char *value
, unsigned int *addr
)
988 hp
= gethostbyname (value
);
991 snprintf (filerr
, sizeof (filerr
), "%s: host '%s' not found\n",
992 __FUNCTION__
, value
);
995 bcopy (hp
->h_addr
, addr
, sizeof (unsigned int));
999 int set_listenaddr (char *word
, char *value
, int context
, void *item
)
1001 switch (context
& ~CONTEXT_DEFAULT
)
1003 case CONTEXT_GLOBAL
:
1005 l2tp_log (LOG_DEBUG
, "set_listenaddr: Setting listen address to %s\n",
1008 if (set_ip (word
, value
, &(((struct global
*) item
)->listenaddr
)))
1012 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1019 int set_localaddr (char *word
, char *value
, int context
, void *item
)
1023 switch (context
& ~CONTEXT_DEFAULT
)
1026 l
= (struct lac
*) item
;
1027 return set_ip (word
, value
, &(l
->localaddr
));
1029 n
= (struct lns
*) item
;
1030 return set_ip (word
, value
, &(n
->localaddr
));
1032 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1039 int set_remoteaddr (char *word
, char *value
, int context
, void *item
)
1042 switch (context
& ~CONTEXT_DEFAULT
)
1045 l
= (struct lac
*) item
;
1046 return set_ip (word
, value
, &(l
->remoteaddr
));
1048 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1055 int set_lns (char *word
, char *value
, int context
, void *item
)
1061 struct host
*ipr
, *pos
;
1063 switch (context
& ~CONTEXT_DEFAULT
)
1067 l2tp_log (LOG_DEBUG
, "set_lns: setting LNS to '%s'\n", value
);
1069 l
= (struct lac
*) item
;
1070 d
= strchr (value
, ':');
1077 // why would you want to lookup hostnames at this time?
1078 hp
= gethostbyname (value
);
1081 snprintf (filerr
, sizeof (filerr
), "no such host '%s'\n", value
);
1085 ipr
= malloc (sizeof (struct host
));
1098 strncpy (ipr
->hostname
, value
, sizeof (ipr
->hostname
));
1100 ipr
->port
= atoi (d
);
1102 ipr
->port
= UDP_LISTEN_PORT
;
1105 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1114 l2tp_log(LOG_WARNING
, "The \"rand()\" function call is not a very good source"
1116 rand_source
= RAND_SYS
;
1120 int set_ipsec_saref (char *word
, char *value
, int context
, void *item
)
1122 struct global
*g
= ((struct global
*) item
);
1123 switch (context
& ~CONTEXT_DEFAULT
)
1125 case CONTEXT_GLOBAL
:
1127 (word
, value
, &(g
->ipsecsaref
)))
1130 l2tp_log(LOG_WARNING
, "Enabling IPsec SAref processing for L2TP transport mode SAs\n");
1132 if(g
->forceuserspace
!= 1) {
1133 l2tp_log(LOG_WARNING
, "IPsec SAref does not work with L2TP kernel mode yet, enabling forceuserspace=yes\n");
1137 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1146 rand_source
= RAND_DEV
;
1150 int set_rand_egd (char *value
)
1152 l2tp_log(LOG_WARNING
, "%s: not yet implemented!\n", __FUNCTION__
);
1153 rand_source
= RAND_EGD
;
1157 int set_rand_source (char *word
, char *value
, int context
, void *item
)
1161 * We're going to go ahead and seed the rand() function with srand()
1162 * because even if we set the randomness source to dev or egd, they
1163 * can fall back to sys if they fail, so we want to make sure we at
1164 * least have *some* semblance of randomness available from the
1168 * This is a sucky random number seed...just the result from the
1169 * time() call...but...the user requested to use the rand()
1170 * function, which is a pretty sucky source of randomness
1171 * regardless...at least we can get a almost sorta decent seed. If
1172 * you have any better suggestions for creating a seed...lemme know
1175 seconds
= time(NULL
);
1178 if (context
!= CONTEXT_GLOBAL
)
1180 l2tp_log(LOG_WARNING
, "%s: %s not valid in context %d\n",
1181 __FUNCTION__
, word
, context
);
1185 if (strlen(value
) == 0)
1187 snprintf(filerr
, sizeof (filerr
), "no randomness source specified\n");
1190 if (strncmp(value
, "egd", 3) == 0)
1192 return set_rand_egd(value
);
1194 else if (strncmp(value
, "dev", 3) == 0)
1196 return set_rand_dev();
1198 else if (strncmp(value
, "sys", 3) == 0)
1200 return set_rand_sys();
1204 l2tp_log(LOG_WARNING
, "%s: %s is not a valid randomness source\n",
1205 __FUNCTION__
, value
);
1211 int parse_config (FILE * f
)
1213 /* Read in the configuration file handed to us */
1214 /* FIXME: I should check for incompatible options */
1225 if (NULL
== fgets (buf
, sizeof (buf
), f
))
1232 /* Strip comments */
1233 while (*s
&& *s
!= ';')
1239 while ((*s
< 33) && *s
)
1240 s
++; /* Skip over beginning white space */
1242 while ((t
>= s
) && (*t
< 33))
1243 *(t
--) = 0; /* Ditch trailing white space */
1248 /* We've got a context description */
1249 if (!(t
= strchr (s
, ']')))
1251 l2tp_log (LOG_CRIT
, "parse_config: line %d: No closing bracket\n",
1257 if ((d
= strchr (s
, ' ')))
1259 /* There's a parameter */
1263 if (d
&& !strcasecmp (d
, "default"))
1264 def
= CONTEXT_DEFAULT
;
1267 if (!strcasecmp (s
, "global"))
1269 context
= CONTEXT_GLOBAL
;
1271 l2tp_log (LOG_DEBUG
,
1272 "parse_config: global context descriptor %s\n",
1277 else if (!strcasecmp (s
, "lns"))
1279 context
= CONTEXT_LNS
;
1284 deflns
= new_lns ();
1285 strncpy (deflns
->entname
, "default",
1286 sizeof (deflns
->entname
));
1297 if (!strcasecmp (d
, tl
->entname
))
1309 ((struct lns
*) data
)->next
= lnslist
;
1310 lnslist
= (struct lns
*) data
;
1313 strncpy (((struct lns
*) data
)->entname
,
1314 d
, sizeof (((struct lns
*) data
)->entname
));
1316 l2tp_log (LOG_DEBUG
, "parse_config: lns context descriptor %s\n",
1320 else if (!strcasecmp (s
, "lac"))
1322 context
= CONTEXT_LAC
;
1327 deflac
= new_lac ();
1328 strncpy (deflac
->entname
, "default",
1329 sizeof (deflac
->entname
));
1340 if (!strcasecmp (d
, tc
->entname
))
1352 ((struct lac
*) data
)->next
= laclist
;
1353 laclist
= (struct lac
*) data
;
1356 strncpy (((struct lac
*) data
)->entname
,
1357 d
, sizeof (((struct lac
*) data
)->entname
));
1359 l2tp_log (LOG_DEBUG
, "parse_config: lac context descriptor %s\n",
1365 l2tp_log (LOG_WARNING
,
1366 "parse_config: line %d: unknown context '%s'\n", linenum
,
1375 l2tp_log (LOG_WARNING
,
1376 "parse_config: line %d: data '%s' occurs with no context\n",
1380 if (!(t
= strchr (s
, '=')))
1382 l2tp_log (LOG_WARNING
, "parse_config: line %d: no '=' in data\n",
1389 while ((d
>= s
) && (*d
< 33))
1393 while (*t
&& (*t
< 33))
1396 l2tp_log (LOG_DEBUG
, "parse_config: field is %s, value is %s\n", s
, t
);
1398 /* Okay, bit twidling is done. Let's handle this */
1400 switch (parse_one_option (s
, t
, context
| def
, data
))
1403 l2tp_log (LOG_WARNING
, "parse_config: line %d: %s", linenum
,
1407 l2tp_log (LOG_CRIT
, "parse_config: line %d: Unknown field '%s'\n",
1416 int parse_one_option(char *word
, char *value
, int context
, void *item
)
1420 for (kw
= words
; kw
->keyword
; kw
++)
1422 if (!strcasecmp (word
, kw
->keyword
))
1424 if (kw
->handler (word
, value
, context
, item
))
1438 struct keyword words
[] = {
1439 {"listen-addr", &set_listenaddr
},
1440 {"port", &set_port
},
1441 {"rand source", &set_rand_source
},
1442 {"auth file", &set_authfile
},
1443 {"exclusive", &set_exclusive
},
1444 {"autodial", &set_autodial
},
1445 {"redial", &set_redial
},
1446 {"redial timeout", &set_rtimeout
},
1448 {"max redials", &set_rmax
},
1449 {"access control", &set_accesscontrol
},
1450 {"force userspace", &set_userspace
},
1451 {"ip range", &set_iprange
},
1452 {"no ip range", &set_iprange
},
1453 {"debug avp", &set_debugavp
},
1454 {"debug network", &set_debugnetwork
},
1455 {"debug packet", &set_debugpacket
},
1456 {"debug tunnel", &set_debugtunnel
},
1457 {"debug state", &set_debugstate
},
1458 {"ipsec saref", &set_ipsec_saref
},
1460 {"no lac", &set_lac
},
1461 {"assign ip", &set_assignip
},
1462 {"local ip", &set_localaddr
},
1463 {"remote ip", &set_remoteaddr
},
1464 {"defaultroute", &set_defaultroute
},
1465 {"length bit", &set_lbit
},
1466 {"hidden bit", &set_hbit
},
1467 {"require pap", &set_papchap
},
1468 {"require chap", &set_papchap
},
1469 {"require authentication", &set_papchap
},
1470 {"require auth", &set_papchap
},
1471 {"refuse pap", &set_papchap
},
1472 {"refuse chap", &set_papchap
},
1473 {"refuse authentication", &set_papchap
},
1474 {"refuse auth", &set_papchap
},
1475 {"unix authentication", &set_passwdauth
},
1476 {"unix auth", &set_passwdauth
},
1477 {"name", &set_authname
},
1478 {"hostname", &set_hostname
},
1479 {"ppp debug", &set_debug
},
1480 {"pppoptfile", &set_pppoptfile
},
1481 {"call rws", &set_rws
},
1482 {"tunnel rws", &set_rws
},
1483 {"flow bit", &set_flow
},
1484 {"challenge", &set_challenge
},
1485 {"tx bps", &set_speed
},
1486 {"rx bps", &set_speed
},
1487 {"bps", &set_speed
},