Home | History | Annotate | Line # | Download | only in mrouted
cfparse.y revision 1.1
      1  1.1  mycroft %{
      2  1.1  mycroft /*
      3  1.1  mycroft  * Configuration file parser for mrouted.
      4  1.1  mycroft  *
      5  1.1  mycroft  * Written by Bill Fenner, NRL, 1994
      6  1.1  mycroft  *
      7  1.1  mycroft  * $Id: cfparse.y,v 1.1 1995/06/01 02:25:48 mycroft Exp $
      8  1.1  mycroft  */
      9  1.1  mycroft #include <stdio.h>
     10  1.1  mycroft #include <varargs.h>
     11  1.1  mycroft #include "defs.h"
     12  1.1  mycroft 
     13  1.1  mycroft static FILE *f;
     14  1.1  mycroft 
     15  1.1  mycroft extern int udp_socket;
     16  1.1  mycroft char *configfilename = _PATH_MROUTED_CONF;
     17  1.1  mycroft 
     18  1.1  mycroft extern int cache_lifetime;
     19  1.1  mycroft extern int max_prune_lifetime;
     20  1.1  mycroft 
     21  1.1  mycroft static int lineno;
     22  1.1  mycroft static struct ifreq ifbuf[32];
     23  1.1  mycroft static struct ifconf ifc;
     24  1.1  mycroft 
     25  1.1  mycroft static struct uvif *v;
     26  1.1  mycroft 
     27  1.1  mycroft static int order;
     28  1.1  mycroft 
     29  1.1  mycroft struct addrmask {
     30  1.1  mycroft 	u_int32_t	addr;
     31  1.1  mycroft 	int	mask;
     32  1.1  mycroft };
     33  1.1  mycroft 
     34  1.1  mycroft struct boundnam {
     35  1.1  mycroft 	char		*name;
     36  1.1  mycroft 	struct addrmask	 bound;
     37  1.1  mycroft };
     38  1.1  mycroft 
     39  1.1  mycroft #define MAXBOUNDS 20
     40  1.1  mycroft 
     41  1.1  mycroft struct boundnam boundlist[MAXBOUNDS];	/* Max. of 20 named boundaries */
     42  1.1  mycroft int numbounds = 0;			/* Number of named boundaries */
     43  1.1  mycroft 
     44  1.1  mycroft %}
     45  1.1  mycroft 
     46  1.1  mycroft %union
     47  1.1  mycroft {
     48  1.1  mycroft 	int num;
     49  1.1  mycroft 	char *ptr;
     50  1.1  mycroft 	struct addrmask addrmask;
     51  1.1  mycroft 	u_int32_t addr;
     52  1.1  mycroft };
     53  1.1  mycroft 
     54  1.1  mycroft %token CACHE_LIFETIME PRUNING
     55  1.1  mycroft %token PHYINT TUNNEL NAME
     56  1.1  mycroft %token DISABLE METRIC THRESHOLD RATE_LIMIT SRCRT BOUNDARY NETMASK ALTNET
     57  1.1  mycroft %token <num> BOOLEAN
     58  1.1  mycroft %token <num> NUMBER
     59  1.1  mycroft %token <ptr> STRING
     60  1.1  mycroft %token <addrmask> ADDRMASK
     61  1.1  mycroft %token <addr> ADDR
     62  1.1  mycroft 
     63  1.1  mycroft %type <addr> interface
     64  1.1  mycroft %type <addrmask> bound boundary addrmask
     65  1.1  mycroft 
     66  1.1  mycroft %start conf
     67  1.1  mycroft 
     68  1.1  mycroft %%
     69  1.1  mycroft 
     70  1.1  mycroft conf	: stmts
     71  1.1  mycroft 	;
     72  1.1  mycroft 
     73  1.1  mycroft stmts	: /* Empty */
     74  1.1  mycroft 	| stmts stmt
     75  1.1  mycroft 	;
     76  1.1  mycroft 
     77  1.1  mycroft stmt	: error
     78  1.1  mycroft 	| PHYINT interface 		{
     79  1.1  mycroft 
     80  1.1  mycroft 			vifi_t vifi;
     81  1.1  mycroft 
     82  1.1  mycroft 			if (order)
     83  1.1  mycroft 			    fatal("phyints must appear before tunnels");
     84  1.1  mycroft 
     85  1.1  mycroft 			for (vifi = 0, v = uvifs;
     86  1.1  mycroft 			     vifi < numvifs;
     87  1.1  mycroft 			     ++vifi, ++v)
     88  1.1  mycroft 			    if (!(v->uv_flags & VIFF_TUNNEL) &&
     89  1.1  mycroft 				$2 == v->uv_lcl_addr)
     90  1.1  mycroft 				break;
     91  1.1  mycroft 
     92  1.1  mycroft 			if (vifi == numvifs)
     93  1.1  mycroft 			    fatal("%s is not a configured interface",
     94  1.1  mycroft 				inet_fmt($2,s1));
     95  1.1  mycroft 
     96  1.1  mycroft 			/*log(LOG_INFO, 0, "phyint: %x\n", v);*/
     97  1.1  mycroft 					}
     98  1.1  mycroft 		ifmods
     99  1.1  mycroft 	| TUNNEL interface ADDR		{
    100  1.1  mycroft 
    101  1.1  mycroft 			struct ifreq *ifr;
    102  1.1  mycroft 			struct ifreq ffr;
    103  1.1  mycroft 			vifi_t vifi;
    104  1.1  mycroft 
    105  1.1  mycroft 			order++;
    106  1.1  mycroft 
    107  1.1  mycroft 			ifr = ifconfaddr(&ifc, $2);
    108  1.1  mycroft 			if (ifr == 0)
    109  1.1  mycroft 			    fatal("Tunnel local address %s is not mine",
    110  1.1  mycroft 				inet_fmt($2, s1));
    111  1.1  mycroft 
    112  1.1  mycroft 			strncpy(ffr.ifr_name, ifr->ifr_name, IFNAMSIZ);
    113  1.1  mycroft 			if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ffr)<0)
    114  1.1  mycroft 			    fatal("ioctl SIOCGIFFLAGS on %s",ffr.ifr_name);
    115  1.1  mycroft 			if (ffr.ifr_flags & IFF_LOOPBACK)
    116  1.1  mycroft 			    fatal("Tunnel local address %s is a loopback interface",
    117  1.1  mycroft 				inet_fmt($2, s1));
    118  1.1  mycroft 
    119  1.1  mycroft 			if (ifconfaddr(&ifc, $3) != 0)
    120  1.1  mycroft 			    fatal("Tunnel remote address %s is one of mine",
    121  1.1  mycroft 				inet_fmt($3, s1));
    122  1.1  mycroft 
    123  1.1  mycroft 			for (vifi = 0, v = uvifs;
    124  1.1  mycroft 			     vifi < numvifs;
    125  1.1  mycroft 			     ++vifi, ++v)
    126  1.1  mycroft 			    if (v->uv_flags & VIFF_TUNNEL) {
    127  1.1  mycroft 				if ($3 == v->uv_rmt_addr)
    128  1.1  mycroft 				    fatal("Duplicate tunnel to %s",
    129  1.1  mycroft 					inet_fmt($3, s1));
    130  1.1  mycroft 			    } else if (!(v->uv_flags & VIFF_DISABLED)) {
    131  1.1  mycroft 				if (($3 & v->uv_subnetmask) == v->uv_subnet)
    132  1.1  mycroft 				    fatal("Unnecessary tunnel to %s",
    133  1.1  mycroft 					inet_fmt($3,s1));
    134  1.1  mycroft 			    }
    135  1.1  mycroft 
    136  1.1  mycroft 			if (numvifs == MAXVIFS)
    137  1.1  mycroft 			    fatal("too many vifs");
    138  1.1  mycroft 
    139  1.1  mycroft 			v = &uvifs[numvifs];
    140  1.1  mycroft 			v->uv_flags	= VIFF_TUNNEL;
    141  1.1  mycroft 			v->uv_metric	= DEFAULT_METRIC;
    142  1.1  mycroft 			v->uv_rate_limit= DEFAULT_TUN_RATE_LIMIT;
    143  1.1  mycroft 			v->uv_threshold	= DEFAULT_THRESHOLD;
    144  1.1  mycroft 			v->uv_lcl_addr	= $2;
    145  1.1  mycroft 			v->uv_rmt_addr	= $3;
    146  1.1  mycroft 			v->uv_subnet	= 0;
    147  1.1  mycroft 			v->uv_subnetmask= 0;
    148  1.1  mycroft 			v->uv_subnetbcast= 0;
    149  1.1  mycroft 			strncpy(v->uv_name, ffr.ifr_name, IFNAMSIZ);
    150  1.1  mycroft 			v->uv_groups	= NULL;
    151  1.1  mycroft 			v->uv_neighbors	= NULL;
    152  1.1  mycroft 			v->uv_acl	= NULL;
    153  1.1  mycroft 			v->uv_addrs	= NULL;
    154  1.1  mycroft 
    155  1.1  mycroft 			if (!(ffr.ifr_flags & IFF_UP)) {
    156  1.1  mycroft 			    v->uv_flags |= VIFF_DOWN;
    157  1.1  mycroft 			    vifs_down = TRUE;
    158  1.1  mycroft 			}
    159  1.1  mycroft 			/*log(LOG_INFO, 0, "tunnel: %x\n", v);*/
    160  1.1  mycroft 					}
    161  1.1  mycroft 		tunnelmods
    162  1.1  mycroft 					{
    163  1.1  mycroft 			log(LOG_INFO, 0,
    164  1.1  mycroft 			    "installing tunnel from %s to %s as vif #%u - rate=%d",
    165  1.1  mycroft 			    inet_fmt($2, s1), inet_fmt($3, s2),
    166  1.1  mycroft 			    numvifs, v->uv_rate_limit);
    167  1.1  mycroft 
    168  1.1  mycroft 			++numvifs;
    169  1.1  mycroft 					}
    170  1.1  mycroft 	| PRUNING BOOLEAN	    { pruning = $2; }
    171  1.1  mycroft 	| CACHE_LIFETIME NUMBER     { cache_lifetime = $2;
    172  1.1  mycroft 				      max_prune_lifetime = cache_lifetime * 2;
    173  1.1  mycroft 				    }
    174  1.1  mycroft 	| NAME STRING boundary	    { if (numbounds >= MAXBOUNDS) {
    175  1.1  mycroft 					fatal("Too many named boundaries (max %d)", MAXBOUNDS);
    176  1.1  mycroft 				      }
    177  1.1  mycroft 
    178  1.1  mycroft 				      boundlist[numbounds].name = malloc(strlen($2) + 1);
    179  1.1  mycroft 				      strcpy(boundlist[numbounds].name, $2);
    180  1.1  mycroft 				      boundlist[numbounds++].bound = $3;
    181  1.1  mycroft 				    }
    182  1.1  mycroft 	;
    183  1.1  mycroft 
    184  1.1  mycroft tunnelmods	: /* empty */
    185  1.1  mycroft 	| tunnelmods /*{ log(LOG_INFO, 0, "tunnelmod: %x", v); }*/ tunnelmod
    186  1.1  mycroft 	;
    187  1.1  mycroft 
    188  1.1  mycroft tunnelmod	: mod
    189  1.1  mycroft 	| SRCRT			{ fatal("Source-route tunnels not supported"); }
    190  1.1  mycroft 	;
    191  1.1  mycroft 
    192  1.1  mycroft ifmods	: /* empty */
    193  1.1  mycroft 	| ifmods /*{ log(LOG_INFO, 0, "ifmod: %x", v); }*/ ifmod
    194  1.1  mycroft 	;
    195  1.1  mycroft 
    196  1.1  mycroft ifmod	: mod
    197  1.1  mycroft 	| DISABLE		{ v->uv_flags |= VIFF_DISABLED; }
    198  1.1  mycroft 	| NETMASK ADDR		{ v->uv_subnetmask = $2; }
    199  1.1  mycroft 	| ALTNET addrmask	{
    200  1.1  mycroft 
    201  1.1  mycroft 		    struct phaddr *ph;
    202  1.1  mycroft 
    203  1.1  mycroft 		    ph = (struct phaddr *)malloc(sizeof(struct phaddr));
    204  1.1  mycroft 		    if (ph == NULL)
    205  1.1  mycroft 			fatal("out of memory");
    206  1.1  mycroft 		    if ($2.mask) {
    207  1.1  mycroft 			VAL_TO_MASK(ph->pa_mask, $2.mask);
    208  1.1  mycroft 		    } else
    209  1.1  mycroft 			ph->pa_mask = v->uv_subnetmask;
    210  1.1  mycroft 		    ph->pa_addr = $2.addr & ph->pa_mask;
    211  1.1  mycroft 		    if ($2.addr & ~ph->pa_mask)
    212  1.1  mycroft 			warn("Extra addr %s/%d has host bits set",
    213  1.1  mycroft 				inet_fmt($2.addr,s1), $2.mask);
    214  1.1  mycroft 		    ph->pa_next = v->uv_addrs;
    215  1.1  mycroft 		    v->uv_addrs = ph;
    216  1.1  mycroft 
    217  1.1  mycroft 				}
    218  1.1  mycroft 	;
    219  1.1  mycroft 
    220  1.1  mycroft mod	: THRESHOLD NUMBER	{ if ($2 < 1 || $2 > 255)
    221  1.1  mycroft 				    fatal("Invalid threshold %d",$2);
    222  1.1  mycroft 				  v->uv_threshold = $2;
    223  1.1  mycroft 				}
    224  1.1  mycroft 	| THRESHOLD		{
    225  1.1  mycroft 
    226  1.1  mycroft 		    warn("Expected number after threshold keyword");
    227  1.1  mycroft 
    228  1.1  mycroft 				}
    229  1.1  mycroft 	| METRIC NUMBER		{ if ($2 < 1 || $2 > UNREACHABLE)
    230  1.1  mycroft 				    fatal("Invalid metric %d",$2);
    231  1.1  mycroft 				  v->uv_metric = $2;
    232  1.1  mycroft 				}
    233  1.1  mycroft 	| METRIC		{
    234  1.1  mycroft 
    235  1.1  mycroft 		    warn("Expected number after metric keyword");
    236  1.1  mycroft 
    237  1.1  mycroft 				}
    238  1.1  mycroft 	| RATE_LIMIT NUMBER	{ if ($2 > MAX_RATE_LIMIT)
    239  1.1  mycroft 				    fatal("Invalid rate_limit %d",$2);
    240  1.1  mycroft 				  v->uv_rate_limit = $2;
    241  1.1  mycroft 				}
    242  1.1  mycroft 	| RATE_LIMIT		{
    243  1.1  mycroft 
    244  1.1  mycroft 		    warn("Expected number after rate_limit keyword");
    245  1.1  mycroft 
    246  1.1  mycroft 				}
    247  1.1  mycroft 	| BOUNDARY bound	{
    248  1.1  mycroft 
    249  1.1  mycroft 		    struct vif_acl *v_acl;
    250  1.1  mycroft 
    251  1.1  mycroft 		    v_acl = (struct vif_acl *)malloc(sizeof(struct vif_acl));
    252  1.1  mycroft 		    if (v_acl == NULL)
    253  1.1  mycroft 			fatal("out of memory");
    254  1.1  mycroft 		    VAL_TO_MASK(v_acl->acl_mask, $2.mask);
    255  1.1  mycroft 		    v_acl->acl_addr = $2.addr & v_acl->acl_mask;
    256  1.1  mycroft 		    if ($2.addr & ~v_acl->acl_mask)
    257  1.1  mycroft 			warn("Boundary spec %s/%d has host bits set",
    258  1.1  mycroft 				inet_fmt($2.addr,s1),$2.mask);
    259  1.1  mycroft 		    v_acl->acl_next = v->uv_acl;
    260  1.1  mycroft 		    v->uv_acl = v_acl;
    261  1.1  mycroft 
    262  1.1  mycroft 				}
    263  1.1  mycroft 	| BOUNDARY		{
    264  1.1  mycroft 
    265  1.1  mycroft 		    warn("Expected boundary spec after boundary keyword");
    266  1.1  mycroft 
    267  1.1  mycroft 				}
    268  1.1  mycroft 	;
    269  1.1  mycroft 
    270  1.1  mycroft interface	: ADDR		{ $$ = $1; }
    271  1.1  mycroft 	| STRING		{
    272  1.1  mycroft 				  $$ = valid_if($1);
    273  1.1  mycroft 				  if ($$ == 0)
    274  1.1  mycroft 					fatal("Invalid interface name %s",$1);
    275  1.1  mycroft 				}
    276  1.1  mycroft 	;
    277  1.1  mycroft 
    278  1.1  mycroft bound	: boundary		{ $$ = $1; }
    279  1.1  mycroft 	| STRING		{ int i;
    280  1.1  mycroft 
    281  1.1  mycroft 				  for (i=0; i < numbounds; i++) {
    282  1.1  mycroft 				    if (!strcmp(boundlist[i].name, $1)) {
    283  1.1  mycroft 					$$ = boundlist[i].bound;
    284  1.1  mycroft 					break;
    285  1.1  mycroft 				    }
    286  1.1  mycroft 				  }
    287  1.1  mycroft 				  if (i == numbounds) {
    288  1.1  mycroft 				    fatal("Invalid boundary name %s",$1);
    289  1.1  mycroft 				  }
    290  1.1  mycroft 				}
    291  1.1  mycroft 	;
    292  1.1  mycroft 
    293  1.1  mycroft boundary	: ADDRMASK	{
    294  1.1  mycroft 
    295  1.1  mycroft 			if ((ntohl($1.addr) & 0xff000000) != 0xef000000) {
    296  1.1  mycroft 			    fatal("Boundaries must be 239.x.x.x, not %s/%d",
    297  1.1  mycroft 				inet_fmt($1.addr, s1), $1.mask);
    298  1.1  mycroft 			}
    299  1.1  mycroft 			$$ = $1;
    300  1.1  mycroft 
    301  1.1  mycroft 				}
    302  1.1  mycroft 	;
    303  1.1  mycroft 
    304  1.1  mycroft addrmask	: ADDRMASK	{ $$ = $1; }
    305  1.1  mycroft 	| ADDR			{ $$.addr = $1; $$.mask = 0; }
    306  1.1  mycroft 	;
    307  1.1  mycroft %%
    308  1.1  mycroft /*VARARGS1*/
    309  1.1  mycroft static void fatal(fmt, va_alist)
    310  1.1  mycroft char *fmt;
    311  1.1  mycroft va_dcl
    312  1.1  mycroft {
    313  1.1  mycroft 	va_list ap;
    314  1.1  mycroft 	char buf[200];
    315  1.1  mycroft 
    316  1.1  mycroft 	va_start(ap);
    317  1.1  mycroft 	vsprintf(buf, fmt, ap);
    318  1.1  mycroft 	va_end(ap);
    319  1.1  mycroft 
    320  1.1  mycroft 	log(LOG_ERR,0,"%s: %s near line %d", configfilename, buf, lineno);
    321  1.1  mycroft }
    322  1.1  mycroft 
    323  1.1  mycroft /*VARARGS1*/
    324  1.1  mycroft static void warn(fmt, va_alist)
    325  1.1  mycroft char *fmt;
    326  1.1  mycroft va_dcl
    327  1.1  mycroft {
    328  1.1  mycroft 	va_list ap;
    329  1.1  mycroft 	char buf[200];
    330  1.1  mycroft 
    331  1.1  mycroft 	va_start(ap);
    332  1.1  mycroft 	vsprintf(buf, fmt, ap);
    333  1.1  mycroft 	va_end(ap);
    334  1.1  mycroft 
    335  1.1  mycroft 	log(LOG_WARNING,0,"%s: %s near line %d", configfilename, buf, lineno);
    336  1.1  mycroft }
    337  1.1  mycroft 
    338  1.1  mycroft void yyerror(s)
    339  1.1  mycroft char *s;
    340  1.1  mycroft {
    341  1.1  mycroft 	log(LOG_ERR, 0, "%s: %s near line %d", configfilename, s, lineno);
    342  1.1  mycroft }
    343  1.1  mycroft 
    344  1.1  mycroft char *next_word()
    345  1.1  mycroft {
    346  1.1  mycroft 	static char buf[1024];
    347  1.1  mycroft 	static char *p=NULL;
    348  1.1  mycroft 	extern FILE *f;
    349  1.1  mycroft 	char *q;
    350  1.1  mycroft 
    351  1.1  mycroft 	while (1) {
    352  1.1  mycroft 	    if (!p || !*p) {
    353  1.1  mycroft 		lineno++;
    354  1.1  mycroft 		if (fgets(buf, sizeof(buf), f) == NULL)
    355  1.1  mycroft 		    return NULL;
    356  1.1  mycroft 		p = buf;
    357  1.1  mycroft 	    }
    358  1.1  mycroft 	    while (*p && (*p == ' ' || *p == '\t'))	/* skip whitespace */
    359  1.1  mycroft 		p++;
    360  1.1  mycroft 	    if (*p == '#') {
    361  1.1  mycroft 		p = NULL;		/* skip comments */
    362  1.1  mycroft 		continue;
    363  1.1  mycroft 	    }
    364  1.1  mycroft 	    q = p;
    365  1.1  mycroft 	    while (*p && *p != ' ' && *p != '\t' && *p != '\n')
    366  1.1  mycroft 		p++;		/* find next whitespace */
    367  1.1  mycroft 	    *p++ = '\0';	/* null-terminate string */
    368  1.1  mycroft 
    369  1.1  mycroft 	    if (!*q) {
    370  1.1  mycroft 		p = NULL;
    371  1.1  mycroft 		continue;	/* if 0-length string, read another line */
    372  1.1  mycroft 	    }
    373  1.1  mycroft 
    374  1.1  mycroft 	    return q;
    375  1.1  mycroft 	}
    376  1.1  mycroft }
    377  1.1  mycroft 
    378  1.1  mycroft int yylex()
    379  1.1  mycroft {
    380  1.1  mycroft 	int n;
    381  1.1  mycroft 	u_int32_t addr;
    382  1.1  mycroft 	char *q;
    383  1.1  mycroft 
    384  1.1  mycroft 	if ((q = next_word()) == NULL) {
    385  1.1  mycroft 		return 0;
    386  1.1  mycroft 	}
    387  1.1  mycroft 
    388  1.1  mycroft 	if (!strcmp(q,"cache_lifetime"))
    389  1.1  mycroft 		return CACHE_LIFETIME;
    390  1.1  mycroft 	if (!strcmp(q,"pruning"))
    391  1.1  mycroft 		return PRUNING;
    392  1.1  mycroft 	if (!strcmp(q,"phyint"))
    393  1.1  mycroft 		return PHYINT;
    394  1.1  mycroft 	if (!strcmp(q,"tunnel"))
    395  1.1  mycroft 		return TUNNEL;
    396  1.1  mycroft 	if (!strcmp(q,"disable"))
    397  1.1  mycroft 		return DISABLE;
    398  1.1  mycroft 	if (!strcmp(q,"metric"))
    399  1.1  mycroft 		return METRIC;
    400  1.1  mycroft 	if (!strcmp(q,"threshold"))
    401  1.1  mycroft 		return THRESHOLD;
    402  1.1  mycroft 	if (!strcmp(q,"rate_limit"))
    403  1.1  mycroft 		return RATE_LIMIT;
    404  1.1  mycroft 	if (!strcmp(q,"srcrt") || !strcmp(q,"sourceroute"))
    405  1.1  mycroft 		return SRCRT;
    406  1.1  mycroft 	if (!strcmp(q,"boundary"))
    407  1.1  mycroft 		return BOUNDARY;
    408  1.1  mycroft 	if (!strcmp(q,"netmask"))
    409  1.1  mycroft 		return NETMASK;
    410  1.1  mycroft 	if (!strcmp(q,"name"))
    411  1.1  mycroft 		return NAME;
    412  1.1  mycroft 	if (!strcmp(q,"altnet"))
    413  1.1  mycroft 		return ALTNET;
    414  1.1  mycroft 	if (!strcmp(q,"on") || !strcmp(q,"yes")) {
    415  1.1  mycroft 		yylval.num = 1;
    416  1.1  mycroft 		return BOOLEAN;
    417  1.1  mycroft 	}
    418  1.1  mycroft 	if (!strcmp(q,"off") || !strcmp(q,"no")) {
    419  1.1  mycroft 		yylval.num = 0;
    420  1.1  mycroft 		return BOOLEAN;
    421  1.1  mycroft 	}
    422  1.1  mycroft 	if (sscanf(q,"%[.0-9]/%d%c",s1,&n,s2) == 2) {
    423  1.1  mycroft 		if ((addr = inet_parse(s1)) != 0xffffffff) {
    424  1.1  mycroft 			yylval.addrmask.mask = n;
    425  1.1  mycroft 			yylval.addrmask.addr = addr;
    426  1.1  mycroft 			return ADDRMASK;
    427  1.1  mycroft 		}
    428  1.1  mycroft 		/* fall through to returning STRING */
    429  1.1  mycroft 	}
    430  1.1  mycroft 	if (sscanf(q,"%[.0-9]%c",s1,s2) == 1) {
    431  1.1  mycroft 		if ((addr = inet_parse(s1)) != 0xffffffff &&
    432  1.1  mycroft 		    inet_valid_host(addr)) {
    433  1.1  mycroft 			yylval.addr = addr;
    434  1.1  mycroft 			return ADDR;
    435  1.1  mycroft 		}
    436  1.1  mycroft 	}
    437  1.1  mycroft 	if (sscanf(q,"0x%8x%c",&n,s1) == 1) {
    438  1.1  mycroft 		yylval.addr = n;
    439  1.1  mycroft 		return ADDR;
    440  1.1  mycroft 	}
    441  1.1  mycroft 	if (sscanf(q,"%d%c",&n,s1) == 1) {
    442  1.1  mycroft 		yylval.num = n;
    443  1.1  mycroft 		return NUMBER;
    444  1.1  mycroft 	}
    445  1.1  mycroft 	yylval.ptr = q;
    446  1.1  mycroft 	return STRING;
    447  1.1  mycroft }
    448  1.1  mycroft 
    449  1.1  mycroft void config_vifs_from_file()
    450  1.1  mycroft {
    451  1.1  mycroft 	extern FILE *f;
    452  1.1  mycroft 
    453  1.1  mycroft 	order = 0;
    454  1.1  mycroft 	numbounds = 0;
    455  1.1  mycroft 	lineno = 0;
    456  1.1  mycroft 
    457  1.1  mycroft 	if ((f = fopen(configfilename, "r")) == NULL) {
    458  1.1  mycroft 	    if (errno != ENOENT)
    459  1.1  mycroft 		log(LOG_ERR, errno, "can't open %s", configfilename);
    460  1.1  mycroft 	    return;
    461  1.1  mycroft 	}
    462  1.1  mycroft 
    463  1.1  mycroft 	ifc.ifc_buf = (char *)ifbuf;
    464  1.1  mycroft 	ifc.ifc_len = sizeof(ifbuf);
    465  1.1  mycroft 	if (ioctl(udp_socket, SIOCGIFCONF, (char *)&ifc) < 0)
    466  1.1  mycroft 	    log(LOG_ERR, errno, "ioctl SIOCGIFCONF");
    467  1.1  mycroft 
    468  1.1  mycroft 	yyparse();
    469  1.1  mycroft 
    470  1.1  mycroft 	close(f);
    471  1.1  mycroft }
    472  1.1  mycroft 
    473  1.1  mycroft static u_int32_t
    474  1.1  mycroft valid_if(s)
    475  1.1  mycroft char *s;
    476  1.1  mycroft {
    477  1.1  mycroft 	register vifi_t vifi;
    478  1.1  mycroft 	register struct uvif *v;
    479  1.1  mycroft 
    480  1.1  mycroft 	for (vifi=0, v=uvifs; vifi<numvifs; vifi++, v++)
    481  1.1  mycroft 	    if (!strcmp(v->uv_name, s))
    482  1.1  mycroft 		return v->uv_lcl_addr;
    483  1.1  mycroft 
    484  1.1  mycroft 	return 0;
    485  1.1  mycroft }
    486  1.1  mycroft 
    487  1.1  mycroft static struct ifreq *
    488  1.1  mycroft ifconfaddr(ifcp, a)
    489  1.1  mycroft     struct ifconf *ifcp;
    490  1.1  mycroft     u_int32_t a;
    491  1.1  mycroft {
    492  1.1  mycroft     int n;
    493  1.1  mycroft     struct ifreq *ifrp = (struct ifreq *)ifcp->ifc_buf;
    494  1.1  mycroft     struct ifreq *ifend = (struct ifreq *)((char *)ifrp + ifcp->ifc_len);
    495  1.1  mycroft 
    496  1.1  mycroft     while (ifrp < ifend) {
    497  1.1  mycroft 	    if (ifrp->ifr_addr.sa_family == AF_INET &&
    498  1.1  mycroft 		((struct sockaddr_in *)&ifrp->ifr_addr)->sin_addr.s_addr == a)
    499  1.1  mycroft 		    return (ifrp);
    500  1.1  mycroft #if (defined(BSD) && (BSD >= 199006))
    501  1.1  mycroft 		n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name);
    502  1.1  mycroft 		if (n < sizeof(*ifrp))
    503  1.1  mycroft 			++ifrp;
    504  1.1  mycroft 		else
    505  1.1  mycroft 			ifrp = (struct ifreq *)((char *)ifrp + n);
    506  1.1  mycroft #else
    507  1.1  mycroft 		++ifrp;
    508  1.1  mycroft #endif
    509  1.1  mycroft     }
    510  1.1  mycroft     return (0);
    511  1.1  mycroft }
    512