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
.sarefnum
= IP_IPSEC_REFINFO
; /* default use the latest we know */
45 gconfig
.listenaddr
= htonl(INADDR_ANY
); /* Default is to bind (listen) to all interfaces */
46 gconfig
.debug_avp
= 0;
47 gconfig
.debug_network
= 0;
48 gconfig
.packet_dump
= 0;
49 gconfig
.debug_tunnel
= 0;
50 gconfig
.debug_state
= 0;
53 deflac
= (struct lac
*) calloc (1, sizeof (struct lac
));
55 f
= fopen (gconfig
.configfile
, "r");
58 f
= fopen (gconfig
.altconfigfile
, "r");
61 l2tp_log (LOG_WARNING
, "%s: Using old style config files %s and %s\n",
62 __FUNCTION__
, gconfig
.altconfigfile
, gconfig
.altauthfile
);
63 strncpy (gconfig
.authfile
, gconfig
.altauthfile
,
64 sizeof (gconfig
.authfile
));
68 l2tp_log (LOG_CRIT
, "%s: Unable to open config file %s or %s\n",
69 __FUNCTION__
, gconfig
.configfile
, gconfig
.altconfigfile
);
74 returnedValue
= parse_config (f
);
76 return (returnedValue
);
80 struct lns
*new_lns ()
83 tmp
= (struct lns
*) calloc (1, sizeof (struct lns
));
86 l2tp_log (LOG_CRIT
, "%s: Unable to allocate memory for new LNS\n",
93 tmp
->tun_rws
= DEFAULT_RWS_SIZE
;
94 tmp
->call_rws
= DEFAULT_RWS_SIZE
;
95 tmp
->rxspeed
= DEFAULT_RX_BPS
;
96 tmp
->txspeed
= DEFAULT_TX_BPS
;
101 tmp
->authname
[0] = 0;
102 tmp
->peername
[0] = 0;
103 tmp
->hostname
[0] = 0;
106 tmp
->assign_ip
= 1; /* default to 'yes' */
109 tmp
->pap_require
= 0;
111 tmp
->chap_require
= 0;
112 tmp
->chap_refuse
= 0;
122 tmp
->pppoptfile
[0] = 0;
127 struct lac
*new_lac ()
130 tmp
= (struct lac
*) calloc (1, sizeof (struct lac
));
133 l2tp_log (LOG_CRIT
, "%s: Unable to allocate memory for lac entry!\n",
142 tmp
->tun_rws
= DEFAULT_RWS_SIZE
;
143 tmp
->call_rws
= DEFAULT_RWS_SIZE
;
148 tmp
->authname
[0] = 0;
149 tmp
->peername
[0] = 0;
150 tmp
->hostname
[0] = 0;
152 tmp
->pap_require
= 0;
154 tmp
->chap_require
= 0;
155 tmp
->chap_refuse
= 0;
165 tmp
->pppoptfile
[0] = 0;
166 tmp
->defaultroute
= 0;
170 int yesno (char *value
)
172 if (!strcasecmp (value
, "yes") || !strcasecmp (value
, "y") ||
173 !strcasecmp (value
, "true"))
175 else if (!strcasecmp (value
, "no") || !strcasecmp (value
, "n") ||
176 !strcasecmp (value
, "false"))
182 int set_boolean (char *word
, char *value
, int *ptr
)
186 l2tp_log (LOG_DEBUG
, "set_%s: %s flag to '%s'\n", word
, word
, value
);
188 if ((val
= yesno (value
)) < 0)
190 snprintf (filerr
, sizeof (filerr
), "%s must be 'yes' or 'no'\n",
198 int set_int (char *word
, char *value
, int *ptr
)
202 l2tp_log (LOG_DEBUG
, "set_%s: %s flag to '%s'\n", word
, word
, value
);
204 if ((val
= atoi (value
)) < 0)
206 snprintf (filerr
, sizeof (filerr
), "%s must be a number\n", word
);
213 int set_string (char *word
, char *value
, char *ptr
, int len
)
216 l2tp_log (LOG_DEBUG
, "set_%s: %s flag to '%s'\n", word
, word
, value
);
218 strncpy (ptr
, value
, len
);
222 int set_port (char *word
, char *value
, int context
, void *item
)
224 switch (context
& ~CONTEXT_DEFAULT
)
228 l2tp_log (LOG_DEBUG
, "set_port: Setting global port number to %s\n",
231 set_int (word
, value
, &(((struct global
*) item
)->port
));
234 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
241 int set_rtimeout (char *word
, char *value
, int context
, void *item
)
243 if (atoi (value
) < 1)
245 snprintf (filerr
, sizeof (filerr
),
246 "rtimeout value must be at least 1\n");
249 switch (context
& ~CONTEXT_DEFAULT
)
253 l2tp_log (LOG_DEBUG
, "set_rtimeout: Setting redial timeout to %s\n",
256 set_int (word
, value
, &(((struct lac
*) item
)->rtimeout
));
259 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
266 int set_rws (char *word
, char *value
, int context
, void *item
)
268 if (atoi (value
) < -1)
270 snprintf (filerr
, sizeof (filerr
),
271 "receive window size must be at least -1\n");
274 switch (context
& ~CONTEXT_DEFAULT
)
278 set_int (word
, value
, &(((struct lac
*) item
)->call_rws
));
281 set_int (word
, value
, &(((struct lac
*) item
)->tun_rws
));
282 if (((struct lac
*) item
)->tun_rws
< 1)
284 snprintf (filerr
, sizeof (filerr
),
285 "receive window size for tunnels must be at least 1\n");
292 set_int (word
, value
, &(((struct lns
*) item
)->call_rws
));
295 set_int (word
, value
, &(((struct lns
*) item
)->tun_rws
));
296 if (((struct lns
*) item
)->tun_rws
< 1)
298 snprintf (filerr
, sizeof (filerr
),
299 "receive window size for tunnels must be at least 1\n");
305 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
312 int set_speed (char *word
, char *value
, int context
, void *item
)
314 if (atoi (value
) < 1 )
316 snprintf (filerr
, sizeof (filerr
),
317 "bps must be greater than zero\n");
320 switch (context
& ~CONTEXT_DEFAULT
)
324 set_int (word
, value
, &(((struct lac
*) item
)->txspeed
));
325 else if (word
[0] == 'r')
326 set_int (word
, value
, &(((struct lac
*) item
)->rxspeed
));
329 set_int (word
, value
, &(((struct lac
*) item
)->rxspeed
));
330 set_int (word
, value
, &(((struct lac
*) item
)->txspeed
));
335 set_int (word
, value
, &(((struct lns
*) item
)->txspeed
));
336 else if (word
[0] == 'r')
337 set_int (word
, value
, &(((struct lns
*) item
)->rxspeed
));
340 set_int (word
, value
, &(((struct lns
*) item
)->rxspeed
));
341 set_int (word
, value
, &(((struct lns
*) item
)->txspeed
));
345 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
352 int set_rmax (char *word
, char *value
, int context
, void *item
)
354 if (atoi (value
) < 1)
356 snprintf (filerr
, sizeof (filerr
), "rmax value must be at least 1\n");
359 switch (context
& ~CONTEXT_DEFAULT
)
363 l2tp_log (LOG_DEBUG
, "set_rmax: Setting max redials to %s\n", value
);
365 set_int (word
, value
, &(((struct lac
*) item
)->rmax
));
368 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
375 int set_authfile (char *word
, char *value
, int context
, void *item
)
379 snprintf (filerr
, sizeof (filerr
),
380 "no filename specified for authentication\n");
383 switch (context
& ~CONTEXT_DEFAULT
)
387 l2tp_log (LOG_DEBUG
, "set_authfile: Setting global auth file to '%s'\n",
390 strncpy (((struct global
*) item
)->authfile
, value
,
391 sizeof (((struct global
*)item
)->authfile
));
394 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
401 int set_autodial (char *word
, char *value
, int context
, void *item
)
403 switch (context
& ~CONTEXT_DEFAULT
)
406 if (set_boolean (word
, value
, &(((struct lac
*) item
)->autodial
)))
410 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
417 int set_flow (char *word
, char *value
, int context
, void *item
)
420 set_boolean (word
, value
, &v
);
423 switch (context
& ~CONTEXT_DEFAULT
)
428 if (((struct lac
*) item
)->call_rws
< 0)
429 ((struct lac
*) item
)->call_rws
= 0;
433 ((struct lac
*) item
)->call_rws
= -1;
439 if (((struct lns
*) item
)->call_rws
< 0)
440 ((struct lns
*) item
)->call_rws
= 0;
444 ((struct lns
*) item
)->call_rws
= -1;
448 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
455 int set_defaultroute (char *word
, char *value
, int context
, void *item
)
457 switch (context
& ~CONTEXT_DEFAULT
)
460 if (set_boolean (word
, value
, &(((struct lac
*) item
)->defaultroute
)))
464 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
471 int set_authname (char *word
, char *value
, int context
, void *item
)
473 struct lac
*l
= (struct lac
*) item
;
474 struct lns
*n
= (struct lns
*) item
;
475 switch (context
& ~CONTEXT_DEFAULT
)
478 if (set_string (word
, value
, n
->authname
, sizeof (n
->authname
)))
482 if (set_string (word
, value
, l
->authname
, sizeof (l
->authname
)))
486 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
493 int set_hostname (char *word
, char *value
, int context
, void *item
)
495 struct lac
*l
= (struct lac
*) item
;
496 struct lns
*n
= (struct lns
*) item
;
497 switch (context
& ~CONTEXT_DEFAULT
)
500 if (set_string (word
, value
, n
->hostname
, sizeof (n
->hostname
)))
504 if (set_string (word
, value
, l
->hostname
, sizeof (l
->hostname
)))
508 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
515 int set_passwdauth (char *word
, char *value
, int context
, void *item
)
517 switch (context
& ~CONTEXT_DEFAULT
)
520 if (set_boolean (word
, value
, &(((struct lns
*) item
)->passwdauth
)))
524 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
531 int set_hbit (char *word
, char *value
, int context
, void *item
)
533 switch (context
& ~CONTEXT_DEFAULT
)
536 if (set_boolean (word
, value
, &(((struct lac
*) item
)->hbit
)))
540 if (set_boolean (word
, value
, &(((struct lns
*) item
)->hbit
)))
544 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
551 int set_challenge (char *word
, char *value
, int context
, void *item
)
553 switch (context
& ~CONTEXT_DEFAULT
)
556 if (set_boolean (word
, value
, &(((struct lac
*) item
)->challenge
)))
560 if (set_boolean (word
, value
, &(((struct lns
*) item
)->challenge
)))
564 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
571 int set_lbit (char *word
, char *value
, int context
, void *item
)
573 switch (context
& ~CONTEXT_DEFAULT
)
576 if (set_boolean (word
, value
, &(((struct lac
*) item
)->lbit
)))
580 if (set_boolean (word
, value
, &(((struct lns
*) item
)->lbit
)))
584 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
592 int set_debug (char *word
, char *value
, int context
, void *item
)
594 switch (context
& ~CONTEXT_DEFAULT
)
597 if (set_boolean (word
, value
, &(((struct lac
*) item
)->debug
)))
601 if (set_boolean (word
, value
, &(((struct lns
*) item
)->debug
)))
605 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
612 int set_pppoptfile (char *word
, char *value
, int context
, void *item
)
614 struct lac
*l
= (struct lac
*) item
;
615 struct lns
*n
= (struct lns
*) item
;
616 switch (context
& ~CONTEXT_DEFAULT
)
619 if (set_string (word
, value
, n
->pppoptfile
, sizeof (n
->pppoptfile
)))
623 if (set_string (word
, value
, l
->pppoptfile
, sizeof (l
->pppoptfile
)))
627 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
634 int set_papchap (char *word
, char *value
, int context
, void *item
)
638 struct lac
*l
= (struct lac
*) item
;
639 struct lns
*n
= (struct lns
*) item
;
640 if (set_boolean (word
, value
, &result
))
642 c
= strchr (word
, ' ');
644 switch (context
& ~CONTEXT_DEFAULT
)
647 if (c
[0] == 'p') /* PAP */
649 l
->pap_refuse
= result
;
651 l
->pap_require
= result
;
652 else if (c
[0] == 'a') /* Authentication */
654 l
->authself
= !result
;
656 l
->authpeer
= result
;
657 else /* CHAP */ if (word
[2] == 'f')
658 l
->chap_refuse
= result
;
660 l
->chap_require
= result
;
663 if (c
[0] == 'p') /* PAP */
665 n
->pap_refuse
= result
;
667 n
->pap_require
= result
;
668 else if (c
[0] == 'a') /* Authentication */
670 n
->authself
= !result
;
672 n
->authpeer
= result
;
673 else /* CHAP */ if (word
[2] == 'f')
674 n
->chap_refuse
= result
;
676 n
->chap_require
= result
;
679 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
686 int set_redial (char *word
, char *value
, int context
, void *item
)
688 switch (context
& ~CONTEXT_DEFAULT
)
691 if (set_boolean (word
, value
, &(((struct lac
*) item
)->redial
)))
695 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
702 int set_accesscontrol (char *word
, char *value
, int context
, void *item
)
704 switch (context
& ~CONTEXT_DEFAULT
)
708 (word
, value
, &(((struct global
*) item
)->accesscontrol
)))
712 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
719 int set_userspace (char *word
, char *value
, int context
, void *item
)
721 switch (context
& ~CONTEXT_DEFAULT
)
725 (word
, value
, &(((struct global
*) item
)->forceuserspace
)))
729 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
736 int set_debugavp (char *word
, char *value
, int context
, void *item
)
738 switch (context
& ~CONTEXT_DEFAULT
)
742 (word
, value
, &(((struct global
*) item
)->debug_avp
)))
746 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
753 int set_debugnetwork (char *word
, char *value
, int context
, void *item
)
755 switch (context
& ~CONTEXT_DEFAULT
)
759 (word
, value
, &(((struct global
*) item
)->debug_network
)))
763 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
770 int set_debugpacket (char *word
, char *value
, int context
, void *item
)
772 switch (context
& ~CONTEXT_DEFAULT
)
776 (word
, value
, &(((struct global
*) item
)->packet_dump
)))
780 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
787 int set_debugtunnel (char *word
, char *value
, int context
, void *item
)
789 switch (context
& ~CONTEXT_DEFAULT
)
793 (word
, value
, &(((struct global
*) item
)->debug_tunnel
)))
797 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
804 int set_debugstate (char *word
, char *value
, int context
, void *item
)
806 switch (context
& ~CONTEXT_DEFAULT
)
810 (word
, value
, &(((struct global
*) item
)->debug_state
)))
814 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
821 int set_assignip (char *word
, char *value
, int context
, void *item
)
823 switch (context
& ~CONTEXT_DEFAULT
)
826 if (set_boolean (word
, value
, &(((struct lns
*) item
)->assign_ip
)))
830 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
837 struct iprange
*set_range (char *word
, char *value
, struct iprange
*in
)
839 char *c
, *d
= NULL
, *e
= NULL
;
840 struct iprange
*ipr
, *p
;
843 c
= strchr (value
, '-');
848 while ((c
>= value
) && (*c
< 33))
850 while (*d
&& (*d
< 33))
853 if (!strlen (value
) || (c
&& !strlen (d
)))
855 snprintf (filerr
, sizeof (filerr
),
856 "format is '%s <host or ip> - <host or ip>'\n", word
);
859 ipr
= (struct iprange
*) malloc (sizeof (struct iprange
));
861 hp
= gethostbyname (value
);
864 snprintf (filerr
, sizeof (filerr
), "Unknown host %s\n", value
);
868 bcopy (hp
->h_addr
, &ipr
->start
, sizeof (unsigned int));
879 strcpy(ip_hi
, value
);
880 for (e
= ip_hi
+ sizeof(ip_hi
); e
>= ip_hi
; e
--) {
881 if (*e
== '.') count
--;
887 /* Copy the last field + null terminator */
888 if (ip_hi
+ sizeof(ip_hi
)-e
> strlen(d
)) {
893 hp
= gethostbyname (d
);
896 snprintf (filerr
, sizeof (filerr
), "Unknown host %s\n", d
);
900 bcopy (hp
->h_addr
, &ipr
->end
, sizeof (unsigned int));
903 ipr
->end
= ipr
->start
;
904 if (ntohl (ipr
->start
) > ntohl (ipr
->end
))
906 snprintf (filerr
, sizeof (filerr
), "start is greater than end!\n");
911 ipr
->sense
= SENSE_DENY
;
913 ipr
->sense
= SENSE_ALLOW
;
926 int set_iprange (char *word
, char *value
, int context
, void *item
)
928 struct lns
*lns
= (struct lns
*) item
;
929 switch (context
& ~CONTEXT_DEFAULT
)
934 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
938 lns
->range
= set_range (word
, value
, lns
->range
);
942 l2tp_log (LOG_DEBUG
, "range start = %x, end = %x, sense=%ud\n",
943 ntohl (lns
->range
->start
), ntohl (lns
->range
->end
), lns
->range
->sense
);
948 int set_lac (char *word
, char *value
, int context
, void *item
)
950 struct lns
*lns
= (struct lns
*) item
;
951 switch (context
& ~CONTEXT_DEFAULT
)
956 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
960 lns
->lacs
= set_range (word
, value
, lns
->lacs
);
964 l2tp_log (LOG_DEBUG
, "lac start = %x, end = %x, sense=%ud\n",
965 ntohl (lns
->lacs
->start
), ntohl (lns
->lacs
->end
), lns
->lacs
->sense
);
970 int set_exclusive (char *word
, char *value
, int context
, void *item
)
972 switch (context
& ~CONTEXT_DEFAULT
)
975 if (set_boolean (word
, value
, &(((struct lns
*) item
)->exclusive
)))
979 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
986 int set_ip (char *word
, char *value
, unsigned int *addr
)
989 hp
= gethostbyname (value
);
992 snprintf (filerr
, sizeof (filerr
), "%s: host '%s' not found\n",
993 __FUNCTION__
, value
);
996 bcopy (hp
->h_addr
, addr
, sizeof (unsigned int));
1000 int set_listenaddr (char *word
, char *value
, int context
, void *item
)
1002 switch (context
& ~CONTEXT_DEFAULT
)
1004 case CONTEXT_GLOBAL
:
1006 l2tp_log (LOG_DEBUG
, "set_listenaddr: Setting listen address to %s\n",
1009 if (set_ip (word
, value
, &(((struct global
*) item
)->listenaddr
)))
1013 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1020 int set_localaddr (char *word
, char *value
, int context
, void *item
)
1024 switch (context
& ~CONTEXT_DEFAULT
)
1027 l
= (struct lac
*) item
;
1028 return set_ip (word
, value
, &(l
->localaddr
));
1030 n
= (struct lns
*) item
;
1031 return set_ip (word
, value
, &(n
->localaddr
));
1033 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1040 int set_remoteaddr (char *word
, char *value
, int context
, void *item
)
1043 switch (context
& ~CONTEXT_DEFAULT
)
1046 l
= (struct lac
*) item
;
1047 return set_ip (word
, value
, &(l
->remoteaddr
));
1049 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1056 int set_lns (char *word
, char *value
, int context
, void *item
)
1062 struct host
*ipr
, *pos
;
1064 switch (context
& ~CONTEXT_DEFAULT
)
1068 l2tp_log (LOG_DEBUG
, "set_lns: setting LNS to '%s'\n", value
);
1070 l
= (struct lac
*) item
;
1071 d
= strchr (value
, ':');
1078 // why would you want to lookup hostnames at this time?
1079 hp
= gethostbyname (value
);
1082 snprintf (filerr
, sizeof (filerr
), "no such host '%s'\n", value
);
1086 ipr
= malloc (sizeof (struct host
));
1099 strncpy (ipr
->hostname
, value
, sizeof (ipr
->hostname
));
1101 ipr
->port
= atoi (d
);
1103 ipr
->port
= UDP_LISTEN_PORT
;
1106 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1115 l2tp_log(LOG_WARNING
, "The \"rand()\" function call is not a very good source"
1117 rand_source
= RAND_SYS
;
1121 int set_ipsec_saref (char *word
, char *value
, int context
, void *item
)
1123 struct global
*g
= ((struct global
*) item
);
1124 switch (context
& ~CONTEXT_DEFAULT
)
1126 case CONTEXT_GLOBAL
:
1128 (word
, value
, &(g
->ipsecsaref
)))
1131 l2tp_log(LOG_INFO
, "Enabling IPsec SAref processing for L2TP transport mode SAs\n");
1133 if(g
->forceuserspace
!= 1) {
1134 l2tp_log(LOG_WARNING
, "IPsec SAref does not work with L2TP kernel mode yet, enabling forceuserspace=yes\n");
1138 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n",
1145 int set_saref_num (char *word
, char *value
, int context
, void *item
)
1147 switch (context
& ~CONTEXT_DEFAULT
)
1149 case CONTEXT_GLOBAL
:
1150 l2tp_log (LOG_INFO
, "Setting SAref IP_IPSEC_REFINFO number to %s\n", value
);
1151 set_int (word
, value
, &(((struct global
*) item
)->sarefnum
));
1154 snprintf (filerr
, sizeof (filerr
), "'%s' not valid in this context\n", word
);
1162 rand_source
= RAND_DEV
;
1166 int set_rand_egd (char *value
)
1168 l2tp_log(LOG_WARNING
, "%s: not yet implemented!\n", __FUNCTION__
);
1169 rand_source
= RAND_EGD
;
1173 int set_rand_source (char *word
, char *value
, int context
, void *item
)
1177 * We're going to go ahead and seed the rand() function with srand()
1178 * because even if we set the randomness source to dev or egd, they
1179 * can fall back to sys if they fail, so we want to make sure we at
1180 * least have *some* semblance of randomness available from the
1184 * This is a sucky random number seed...just the result from the
1185 * time() call...but...the user requested to use the rand()
1186 * function, which is a pretty sucky source of randomness
1187 * regardless...at least we can get a almost sorta decent seed. If
1188 * you have any better suggestions for creating a seed...lemme know
1191 seconds
= time(NULL
);
1194 if (context
!= CONTEXT_GLOBAL
)
1196 l2tp_log(LOG_WARNING
, "%s: %s not valid in context %d\n",
1197 __FUNCTION__
, word
, context
);
1201 if (strlen(value
) == 0)
1203 snprintf(filerr
, sizeof (filerr
), "no randomness source specified\n");
1206 if (strncmp(value
, "egd", 3) == 0)
1208 return set_rand_egd(value
);
1210 else if (strncmp(value
, "dev", 3) == 0)
1212 return set_rand_dev();
1214 else if (strncmp(value
, "sys", 3) == 0)
1216 return set_rand_sys();
1220 l2tp_log(LOG_WARNING
, "%s: %s is not a valid randomness source\n",
1221 __FUNCTION__
, value
);
1227 int parse_config (FILE * f
)
1229 /* Read in the configuration file handed to us */
1230 /* FIXME: I should check for incompatible options */
1241 if (NULL
== fgets (buf
, sizeof (buf
), f
))
1248 /* Strip comments */
1249 while (*s
&& *s
!= ';')
1255 while ((*s
< 33) && *s
)
1256 s
++; /* Skip over beginning white space */
1258 while ((t
>= s
) && (*t
< 33))
1259 *(t
--) = 0; /* Ditch trailing white space */
1264 /* We've got a context description */
1265 if (!(t
= strchr (s
, ']')))
1267 l2tp_log (LOG_CRIT
, "parse_config: line %d: No closing bracket\n",
1273 if ((d
= strchr (s
, ' ')))
1275 /* There's a parameter */
1279 if (d
&& !strcasecmp (d
, "default"))
1280 def
= CONTEXT_DEFAULT
;
1283 if (!strcasecmp (s
, "global"))
1285 context
= CONTEXT_GLOBAL
;
1287 l2tp_log (LOG_DEBUG
,
1288 "parse_config: global context descriptor %s\n",
1293 else if (!strcasecmp (s
, "lns"))
1295 context
= CONTEXT_LNS
;
1300 deflns
= new_lns ();
1301 strncpy (deflns
->entname
, "default",
1302 sizeof (deflns
->entname
));
1313 if (!strcasecmp (d
, tl
->entname
))
1325 ((struct lns
*) data
)->next
= lnslist
;
1326 lnslist
= (struct lns
*) data
;
1329 strncpy (((struct lns
*) data
)->entname
,
1330 d
, sizeof (((struct lns
*) data
)->entname
));
1332 l2tp_log (LOG_DEBUG
, "parse_config: lns context descriptor %s\n",
1336 else if (!strcasecmp (s
, "lac"))
1338 context
= CONTEXT_LAC
;
1343 deflac
= new_lac ();
1344 strncpy (deflac
->entname
, "default",
1345 sizeof (deflac
->entname
));
1356 if (!strcasecmp (d
, tc
->entname
))
1368 ((struct lac
*) data
)->next
= laclist
;
1369 laclist
= (struct lac
*) data
;
1372 strncpy (((struct lac
*) data
)->entname
,
1373 d
, sizeof (((struct lac
*) data
)->entname
));
1375 l2tp_log (LOG_DEBUG
, "parse_config: lac context descriptor %s\n",
1381 l2tp_log (LOG_WARNING
,
1382 "parse_config: line %d: unknown context '%s'\n", linenum
,
1391 l2tp_log (LOG_WARNING
,
1392 "parse_config: line %d: data '%s' occurs with no context\n",
1396 if (!(t
= strchr (s
, '=')))
1398 l2tp_log (LOG_WARNING
, "parse_config: line %d: no '=' in data\n",
1405 while ((d
>= s
) && (*d
< 33))
1409 while (*t
&& (*t
< 33))
1412 l2tp_log (LOG_DEBUG
, "parse_config: field is %s, value is %s\n", s
, t
);
1414 /* Okay, bit twidling is done. Let's handle this */
1416 switch (parse_one_option (s
, t
, context
| def
, data
))
1419 l2tp_log (LOG_WARNING
, "parse_config: line %d: %s", linenum
,
1423 l2tp_log (LOG_CRIT
, "parse_config: line %d: Unknown field '%s'\n",
1432 int parse_one_option(char *word
, char *value
, int context
, void *item
)
1436 for (kw
= words
; kw
->keyword
; kw
++)
1438 if (!strcasecmp (word
, kw
->keyword
))
1440 if (kw
->handler (word
, value
, context
, item
))
1454 struct keyword words
[] = {
1455 {"listen-addr", &set_listenaddr
},
1456 {"port", &set_port
},
1457 {"saref refinfo", &set_saref_num
},
1458 {"rand source", &set_rand_source
},
1459 {"auth file", &set_authfile
},
1460 {"exclusive", &set_exclusive
},
1461 {"autodial", &set_autodial
},
1462 {"redial", &set_redial
},
1463 {"redial timeout", &set_rtimeout
},
1465 {"max redials", &set_rmax
},
1466 {"access control", &set_accesscontrol
},
1467 {"force userspace", &set_userspace
},
1468 {"ip range", &set_iprange
},
1469 {"no ip range", &set_iprange
},
1470 {"debug avp", &set_debugavp
},
1471 {"debug network", &set_debugnetwork
},
1472 {"debug packet", &set_debugpacket
},
1473 {"debug tunnel", &set_debugtunnel
},
1474 {"debug state", &set_debugstate
},
1475 {"ipsec saref", &set_ipsec_saref
},
1477 {"no lac", &set_lac
},
1478 {"assign ip", &set_assignip
},
1479 {"local ip", &set_localaddr
},
1480 {"remote ip", &set_remoteaddr
},
1481 {"defaultroute", &set_defaultroute
},
1482 {"length bit", &set_lbit
},
1483 {"hidden bit", &set_hbit
},
1484 {"require pap", &set_papchap
},
1485 {"require chap", &set_papchap
},
1486 {"require authentication", &set_papchap
},
1487 {"require auth", &set_papchap
},
1488 {"refuse pap", &set_papchap
},
1489 {"refuse chap", &set_papchap
},
1490 {"refuse authentication", &set_papchap
},
1491 {"refuse auth", &set_papchap
},
1492 {"unix authentication", &set_passwdauth
},
1493 {"unix auth", &set_passwdauth
},
1494 {"name", &set_authname
},
1495 {"hostname", &set_hostname
},
1496 {"ppp debug", &set_debug
},
1497 {"pppoptfile", &set_pppoptfile
},
1498 {"call rws", &set_rws
},
1499 {"tunnel rws", &set_rws
},
1500 {"flow bit", &set_flow
},
1501 {"challenge", &set_challenge
},
1502 {"tx bps", &set_speed
},
1503 {"rx bps", &set_speed
},
1504 {"bps", &set_speed
},