cfparse.y revision 1.14 1 1.1 mycroft %{
2 1.14 itojun /* $NetBSD: cfparse.y,v 1.14 2003/07/13 12:40:17 itojun Exp $ */
3 1.3 thorpej
4 1.1 mycroft /*
5 1.1 mycroft * Configuration file parser for mrouted.
6 1.1 mycroft *
7 1.1 mycroft * Written by Bill Fenner, NRL, 1994
8 1.7 itojun * Copyright (c) 1994
9 1.7 itojun * Naval Research Laboratory (NRL/CCS)
10 1.7 itojun * and the
11 1.7 itojun * Defense Advanced Research Projects Agency (DARPA)
12 1.7 itojun *
13 1.7 itojun * All Rights Reserved.
14 1.7 itojun *
15 1.7 itojun * Permission to use, copy, modify and distribute this software and its
16 1.7 itojun * documentation is hereby granted, provided that both the copyright notice and
17 1.7 itojun * this permission notice appear in all copies of the software, derivative
18 1.7 itojun * works or modified versions, and any portions thereof, and that both notices
19 1.7 itojun * appear in supporting documentation.
20 1.7 itojun *
21 1.7 itojun * NRL AND DARPA ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
22 1.7 itojun * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM
23 1.7 itojun * THE USE OF THIS SOFTWARE.
24 1.1 mycroft */
25 1.1 mycroft #include <stdio.h>
26 1.4 mycroft #include <stdarg.h>
27 1.1 mycroft #include "defs.h"
28 1.4 mycroft #include <netdb.h>
29 1.4 mycroft
30 1.4 mycroft /*
31 1.4 mycroft * Local function declarations
32 1.4 mycroft */
33 1.8 wiz static void fatal(char *fmt, ...)
34 1.6 is __attribute__((__format__(__printf__, 1, 2)));
35 1.8 wiz static void warn(char *fmt, ...)
36 1.6 is __attribute__((__format__(__printf__, 1, 2)));
37 1.8 wiz static void yyerror(char *s);
38 1.8 wiz static char * next_word(void);
39 1.8 wiz static int yylex(void);
40 1.8 wiz static u_int32_t valid_if(char *s);
41 1.8 wiz static struct ifreq * ifconfaddr(struct ifconf *ifcp, u_int32_t a);
42 1.8 wiz int yyparse(void);
43 1.1 mycroft
44 1.5 mrg static FILE *f __attribute__((__unused__)); /* XXX egcs */
45 1.1 mycroft extern int udp_socket;
46 1.1 mycroft char *configfilename = _PATH_MROUTED_CONF;
47 1.1 mycroft
48 1.1 mycroft extern int cache_lifetime;
49 1.1 mycroft extern int max_prune_lifetime;
50 1.1 mycroft
51 1.1 mycroft static int lineno;
52 1.1 mycroft static struct ifreq ifbuf[32];
53 1.1 mycroft static struct ifconf ifc;
54 1.1 mycroft
55 1.1 mycroft static struct uvif *v;
56 1.1 mycroft
57 1.1 mycroft static int order;
58 1.1 mycroft
59 1.1 mycroft struct addrmask {
60 1.1 mycroft u_int32_t addr;
61 1.1 mycroft int mask;
62 1.1 mycroft };
63 1.1 mycroft
64 1.1 mycroft struct boundnam {
65 1.1 mycroft char *name;
66 1.1 mycroft struct addrmask bound;
67 1.1 mycroft };
68 1.1 mycroft
69 1.1 mycroft #define MAXBOUNDS 20
70 1.1 mycroft
71 1.1 mycroft struct boundnam boundlist[MAXBOUNDS]; /* Max. of 20 named boundaries */
72 1.1 mycroft int numbounds = 0; /* Number of named boundaries */
73 1.1 mycroft
74 1.1 mycroft %}
75 1.1 mycroft
76 1.1 mycroft %union
77 1.1 mycroft {
78 1.1 mycroft int num;
79 1.1 mycroft char *ptr;
80 1.1 mycroft struct addrmask addrmask;
81 1.1 mycroft u_int32_t addr;
82 1.1 mycroft };
83 1.1 mycroft
84 1.1 mycroft %token CACHE_LIFETIME PRUNING
85 1.1 mycroft %token PHYINT TUNNEL NAME
86 1.4 mycroft %token DISABLE IGMPV1 SRCRT
87 1.4 mycroft %token METRIC THRESHOLD RATE_LIMIT BOUNDARY NETMASK ALTNET
88 1.4 mycroft %token SYSNAM SYSCONTACT SYSVERSION SYSLOCATION
89 1.1 mycroft %token <num> BOOLEAN
90 1.1 mycroft %token <num> NUMBER
91 1.1 mycroft %token <ptr> STRING
92 1.1 mycroft %token <addrmask> ADDRMASK
93 1.1 mycroft %token <addr> ADDR
94 1.1 mycroft
95 1.4 mycroft %type <addr> interface addrname
96 1.1 mycroft %type <addrmask> bound boundary addrmask
97 1.1 mycroft
98 1.1 mycroft %start conf
99 1.1 mycroft
100 1.1 mycroft %%
101 1.1 mycroft
102 1.1 mycroft conf : stmts
103 1.1 mycroft ;
104 1.1 mycroft
105 1.1 mycroft stmts : /* Empty */
106 1.1 mycroft | stmts stmt
107 1.1 mycroft ;
108 1.1 mycroft
109 1.1 mycroft stmt : error
110 1.1 mycroft | PHYINT interface {
111 1.1 mycroft
112 1.1 mycroft vifi_t vifi;
113 1.1 mycroft
114 1.1 mycroft if (order)
115 1.1 mycroft fatal("phyints must appear before tunnels");
116 1.1 mycroft
117 1.1 mycroft for (vifi = 0, v = uvifs;
118 1.1 mycroft vifi < numvifs;
119 1.1 mycroft ++vifi, ++v)
120 1.1 mycroft if (!(v->uv_flags & VIFF_TUNNEL) &&
121 1.1 mycroft $2 == v->uv_lcl_addr)
122 1.1 mycroft break;
123 1.1 mycroft
124 1.1 mycroft if (vifi == numvifs)
125 1.1 mycroft fatal("%s is not a configured interface",
126 1.13 dsl inet_fmt($2));
127 1.1 mycroft
128 1.1 mycroft }
129 1.1 mycroft ifmods
130 1.4 mycroft | TUNNEL interface addrname {
131 1.1 mycroft
132 1.1 mycroft struct ifreq *ifr;
133 1.1 mycroft struct ifreq ffr;
134 1.1 mycroft vifi_t vifi;
135 1.1 mycroft
136 1.1 mycroft order++;
137 1.1 mycroft
138 1.1 mycroft ifr = ifconfaddr(&ifc, $2);
139 1.1 mycroft if (ifr == 0)
140 1.1 mycroft fatal("Tunnel local address %s is not mine",
141 1.13 dsl inet_fmt($2));
142 1.1 mycroft
143 1.1 mycroft strncpy(ffr.ifr_name, ifr->ifr_name, IFNAMSIZ);
144 1.1 mycroft if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ffr)<0)
145 1.1 mycroft fatal("ioctl SIOCGIFFLAGS on %s",ffr.ifr_name);
146 1.1 mycroft if (ffr.ifr_flags & IFF_LOOPBACK)
147 1.1 mycroft fatal("Tunnel local address %s is a loopback interface",
148 1.13 dsl inet_fmt($2));
149 1.1 mycroft
150 1.1 mycroft if (ifconfaddr(&ifc, $3) != 0)
151 1.1 mycroft fatal("Tunnel remote address %s is one of mine",
152 1.13 dsl inet_fmt($3));
153 1.1 mycroft
154 1.1 mycroft for (vifi = 0, v = uvifs;
155 1.1 mycroft vifi < numvifs;
156 1.1 mycroft ++vifi, ++v)
157 1.1 mycroft if (v->uv_flags & VIFF_TUNNEL) {
158 1.1 mycroft if ($3 == v->uv_rmt_addr)
159 1.1 mycroft fatal("Duplicate tunnel to %s",
160 1.13 dsl inet_fmt($3));
161 1.1 mycroft } else if (!(v->uv_flags & VIFF_DISABLED)) {
162 1.1 mycroft if (($3 & v->uv_subnetmask) == v->uv_subnet)
163 1.1 mycroft fatal("Unnecessary tunnel to %s",
164 1.13 dsl inet_fmt($3));
165 1.1 mycroft }
166 1.1 mycroft
167 1.1 mycroft if (numvifs == MAXVIFS)
168 1.1 mycroft fatal("too many vifs");
169 1.1 mycroft
170 1.1 mycroft v = &uvifs[numvifs];
171 1.1 mycroft v->uv_flags = VIFF_TUNNEL;
172 1.1 mycroft v->uv_metric = DEFAULT_METRIC;
173 1.1 mycroft v->uv_rate_limit= DEFAULT_TUN_RATE_LIMIT;
174 1.1 mycroft v->uv_threshold = DEFAULT_THRESHOLD;
175 1.1 mycroft v->uv_lcl_addr = $2;
176 1.1 mycroft v->uv_rmt_addr = $3;
177 1.1 mycroft v->uv_subnet = 0;
178 1.1 mycroft v->uv_subnetmask= 0;
179 1.1 mycroft v->uv_subnetbcast= 0;
180 1.1 mycroft strncpy(v->uv_name, ffr.ifr_name, IFNAMSIZ);
181 1.1 mycroft v->uv_groups = NULL;
182 1.1 mycroft v->uv_neighbors = NULL;
183 1.1 mycroft v->uv_acl = NULL;
184 1.1 mycroft v->uv_addrs = NULL;
185 1.1 mycroft
186 1.1 mycroft if (!(ffr.ifr_flags & IFF_UP)) {
187 1.1 mycroft v->uv_flags |= VIFF_DOWN;
188 1.1 mycroft vifs_down = TRUE;
189 1.1 mycroft }
190 1.1 mycroft }
191 1.1 mycroft tunnelmods
192 1.1 mycroft {
193 1.10 wiz logit(LOG_INFO, 0,
194 1.1 mycroft "installing tunnel from %s to %s as vif #%u - rate=%d",
195 1.13 dsl inet_fmt($2),
196 1.13 dsl inet_fmt($3),
197 1.1 mycroft numvifs, v->uv_rate_limit);
198 1.1 mycroft
199 1.1 mycroft ++numvifs;
200 1.1 mycroft }
201 1.1 mycroft | PRUNING BOOLEAN { pruning = $2; }
202 1.1 mycroft | CACHE_LIFETIME NUMBER { cache_lifetime = $2;
203 1.1 mycroft max_prune_lifetime = cache_lifetime * 2;
204 1.1 mycroft }
205 1.1 mycroft | NAME STRING boundary { if (numbounds >= MAXBOUNDS) {
206 1.1 mycroft fatal("Too many named boundaries (max %d)", MAXBOUNDS);
207 1.1 mycroft }
208 1.1 mycroft
209 1.14 itojun boundlist[numbounds].name = strdup($2);
210 1.1 mycroft boundlist[numbounds++].bound = $3;
211 1.1 mycroft }
212 1.4 mycroft | SYSNAM STRING {
213 1.4 mycroft #ifdef SNMP
214 1.4 mycroft set_sysName($2);
215 1.4 mycroft #endif /* SNMP */
216 1.4 mycroft }
217 1.4 mycroft | SYSCONTACT STRING {
218 1.4 mycroft #ifdef SNMP
219 1.4 mycroft set_sysContact($2);
220 1.4 mycroft #endif /* SNMP */
221 1.4 mycroft }
222 1.4 mycroft | SYSVERSION STRING {
223 1.4 mycroft #ifdef SNMP
224 1.4 mycroft set_sysVersion($2);
225 1.4 mycroft #endif /* SNMP */
226 1.4 mycroft }
227 1.4 mycroft | SYSLOCATION STRING {
228 1.4 mycroft #ifdef SNMP
229 1.4 mycroft set_sysLocation($2);
230 1.4 mycroft #endif /* SNMP */
231 1.4 mycroft }
232 1.1 mycroft ;
233 1.1 mycroft
234 1.1 mycroft tunnelmods : /* empty */
235 1.4 mycroft | tunnelmods tunnelmod
236 1.1 mycroft ;
237 1.1 mycroft
238 1.1 mycroft tunnelmod : mod
239 1.1 mycroft | SRCRT { fatal("Source-route tunnels not supported"); }
240 1.1 mycroft ;
241 1.1 mycroft
242 1.1 mycroft ifmods : /* empty */
243 1.4 mycroft | ifmods ifmod
244 1.1 mycroft ;
245 1.1 mycroft
246 1.1 mycroft ifmod : mod
247 1.1 mycroft | DISABLE { v->uv_flags |= VIFF_DISABLED; }
248 1.4 mycroft | IGMPV1 { v->uv_flags |= VIFF_IGMPV1; }
249 1.4 mycroft | NETMASK addrname {
250 1.4 mycroft u_int32_t subnet, mask;
251 1.4 mycroft
252 1.4 mycroft mask = $2;
253 1.4 mycroft subnet = v->uv_lcl_addr & mask;
254 1.4 mycroft if (!inet_valid_subnet(subnet, mask))
255 1.4 mycroft fatal("Invalid netmask");
256 1.4 mycroft v->uv_subnet = subnet;
257 1.4 mycroft v->uv_subnetmask = mask;
258 1.4 mycroft v->uv_subnetbcast = subnet | ~mask;
259 1.4 mycroft }
260 1.4 mycroft | NETMASK {
261 1.4 mycroft
262 1.4 mycroft warn("Expected address after netmask keyword, ignored");
263 1.4 mycroft
264 1.4 mycroft }
265 1.1 mycroft | ALTNET addrmask {
266 1.1 mycroft
267 1.1 mycroft struct phaddr *ph;
268 1.1 mycroft
269 1.1 mycroft ph = (struct phaddr *)malloc(sizeof(struct phaddr));
270 1.1 mycroft if (ph == NULL)
271 1.1 mycroft fatal("out of memory");
272 1.1 mycroft if ($2.mask) {
273 1.4 mycroft VAL_TO_MASK(ph->pa_subnetmask, $2.mask);
274 1.1 mycroft } else
275 1.4 mycroft ph->pa_subnetmask = v->uv_subnetmask;
276 1.4 mycroft ph->pa_subnet = $2.addr & ph->pa_subnetmask;
277 1.4 mycroft ph->pa_subnetbcast = ph->pa_subnet | ~ph->pa_subnetmask;
278 1.4 mycroft if ($2.addr & ~ph->pa_subnetmask)
279 1.4 mycroft warn("Extra subnet %s/%d has host bits set",
280 1.13 dsl inet_fmt($2.addr), $2.mask);
281 1.1 mycroft ph->pa_next = v->uv_addrs;
282 1.1 mycroft v->uv_addrs = ph;
283 1.1 mycroft
284 1.1 mycroft }
285 1.4 mycroft | ALTNET {
286 1.4 mycroft
287 1.4 mycroft warn("Expected address after altnet keyword, ignored");
288 1.4 mycroft
289 1.4 mycroft }
290 1.1 mycroft ;
291 1.1 mycroft
292 1.1 mycroft mod : THRESHOLD NUMBER { if ($2 < 1 || $2 > 255)
293 1.1 mycroft fatal("Invalid threshold %d",$2);
294 1.1 mycroft v->uv_threshold = $2;
295 1.1 mycroft }
296 1.1 mycroft | THRESHOLD {
297 1.1 mycroft
298 1.4 mycroft warn("Expected number after threshold keyword, ignored");
299 1.1 mycroft
300 1.1 mycroft }
301 1.1 mycroft | METRIC NUMBER { if ($2 < 1 || $2 > UNREACHABLE)
302 1.1 mycroft fatal("Invalid metric %d",$2);
303 1.1 mycroft v->uv_metric = $2;
304 1.1 mycroft }
305 1.1 mycroft | METRIC {
306 1.1 mycroft
307 1.4 mycroft warn("Expected number after metric keyword, ignored");
308 1.1 mycroft
309 1.1 mycroft }
310 1.1 mycroft | RATE_LIMIT NUMBER { if ($2 > MAX_RATE_LIMIT)
311 1.1 mycroft fatal("Invalid rate_limit %d",$2);
312 1.1 mycroft v->uv_rate_limit = $2;
313 1.1 mycroft }
314 1.1 mycroft | RATE_LIMIT {
315 1.1 mycroft
316 1.4 mycroft warn("Expected number after rate_limit keyword, ignored");
317 1.1 mycroft
318 1.1 mycroft }
319 1.1 mycroft | BOUNDARY bound {
320 1.1 mycroft
321 1.1 mycroft struct vif_acl *v_acl;
322 1.1 mycroft
323 1.1 mycroft v_acl = (struct vif_acl *)malloc(sizeof(struct vif_acl));
324 1.1 mycroft if (v_acl == NULL)
325 1.1 mycroft fatal("out of memory");
326 1.1 mycroft VAL_TO_MASK(v_acl->acl_mask, $2.mask);
327 1.1 mycroft v_acl->acl_addr = $2.addr & v_acl->acl_mask;
328 1.1 mycroft if ($2.addr & ~v_acl->acl_mask)
329 1.1 mycroft warn("Boundary spec %s/%d has host bits set",
330 1.13 dsl inet_fmt($2.addr),$2.mask);
331 1.1 mycroft v_acl->acl_next = v->uv_acl;
332 1.1 mycroft v->uv_acl = v_acl;
333 1.1 mycroft
334 1.1 mycroft }
335 1.1 mycroft | BOUNDARY {
336 1.1 mycroft
337 1.4 mycroft warn("Expected boundary spec after boundary keyword, ignored");
338 1.1 mycroft
339 1.1 mycroft }
340 1.1 mycroft ;
341 1.1 mycroft
342 1.1 mycroft interface : ADDR { $$ = $1; }
343 1.1 mycroft | STRING {
344 1.1 mycroft $$ = valid_if($1);
345 1.1 mycroft if ($$ == 0)
346 1.1 mycroft fatal("Invalid interface name %s",$1);
347 1.1 mycroft }
348 1.1 mycroft ;
349 1.1 mycroft
350 1.4 mycroft addrname : ADDR { $$ = $1; }
351 1.4 mycroft | STRING { struct hostent *hp;
352 1.4 mycroft
353 1.4 mycroft if ((hp = gethostbyname($1)) == NULL)
354 1.4 mycroft fatal("No such host %s", $1);
355 1.4 mycroft
356 1.4 mycroft if (hp->h_addr_list[1])
357 1.4 mycroft fatal("Hostname %s does not %s",
358 1.4 mycroft $1, "map to a unique address");
359 1.4 mycroft
360 1.4 mycroft bcopy(hp->h_addr_list[0], &$$,
361 1.4 mycroft hp->h_length);
362 1.4 mycroft }
363 1.4 mycroft
364 1.1 mycroft bound : boundary { $$ = $1; }
365 1.1 mycroft | STRING { int i;
366 1.1 mycroft
367 1.1 mycroft for (i=0; i < numbounds; i++) {
368 1.1 mycroft if (!strcmp(boundlist[i].name, $1)) {
369 1.1 mycroft $$ = boundlist[i].bound;
370 1.1 mycroft break;
371 1.1 mycroft }
372 1.1 mycroft }
373 1.1 mycroft if (i == numbounds) {
374 1.1 mycroft fatal("Invalid boundary name %s",$1);
375 1.1 mycroft }
376 1.1 mycroft }
377 1.1 mycroft ;
378 1.1 mycroft
379 1.1 mycroft boundary : ADDRMASK {
380 1.1 mycroft
381 1.1 mycroft if ((ntohl($1.addr) & 0xff000000) != 0xef000000) {
382 1.1 mycroft fatal("Boundaries must be 239.x.x.x, not %s/%d",
383 1.13 dsl inet_fmt($1.addr), $1.mask);
384 1.1 mycroft }
385 1.1 mycroft $$ = $1;
386 1.1 mycroft
387 1.1 mycroft }
388 1.1 mycroft ;
389 1.1 mycroft
390 1.1 mycroft addrmask : ADDRMASK { $$ = $1; }
391 1.1 mycroft | ADDR { $$.addr = $1; $$.mask = 0; }
392 1.1 mycroft ;
393 1.1 mycroft %%
394 1.4 mycroft static void
395 1.4 mycroft fatal(char *fmt, ...)
396 1.4 mycroft {
397 1.4 mycroft va_list ap;
398 1.4 mycroft char buf[200];
399 1.4 mycroft
400 1.4 mycroft va_start(ap, fmt);
401 1.11 wiz vsnprintf(buf, sizeof(buf), fmt, ap);
402 1.1 mycroft va_end(ap);
403 1.1 mycroft
404 1.10 wiz logit(LOG_ERR,0,"%s: %s near line %d", configfilename, buf, lineno);
405 1.1 mycroft }
406 1.1 mycroft
407 1.4 mycroft static void
408 1.4 mycroft warn(char *fmt, ...)
409 1.4 mycroft {
410 1.4 mycroft va_list ap;
411 1.4 mycroft char buf[200];
412 1.4 mycroft
413 1.4 mycroft va_start(ap, fmt);
414 1.11 wiz vsnprintf(buf, sizeof(buf), fmt, ap);
415 1.1 mycroft va_end(ap);
416 1.1 mycroft
417 1.10 wiz logit(LOG_WARNING,0,"%s: %s near line %d", configfilename, buf, lineno);
418 1.1 mycroft }
419 1.1 mycroft
420 1.4 mycroft static void
421 1.4 mycroft yyerror(s)
422 1.1 mycroft char *s;
423 1.1 mycroft {
424 1.10 wiz logit(LOG_ERR, 0, "%s: %s near line %d", configfilename, s, lineno);
425 1.1 mycroft }
426 1.1 mycroft
427 1.4 mycroft static char *
428 1.4 mycroft next_word()
429 1.1 mycroft {
430 1.1 mycroft static char buf[1024];
431 1.1 mycroft static char *p=NULL;
432 1.1 mycroft extern FILE *f;
433 1.1 mycroft char *q;
434 1.1 mycroft
435 1.1 mycroft while (1) {
436 1.1 mycroft if (!p || !*p) {
437 1.1 mycroft lineno++;
438 1.1 mycroft if (fgets(buf, sizeof(buf), f) == NULL)
439 1.1 mycroft return NULL;
440 1.1 mycroft p = buf;
441 1.1 mycroft }
442 1.1 mycroft while (*p && (*p == ' ' || *p == '\t')) /* skip whitespace */
443 1.1 mycroft p++;
444 1.1 mycroft if (*p == '#') {
445 1.1 mycroft p = NULL; /* skip comments */
446 1.1 mycroft continue;
447 1.1 mycroft }
448 1.1 mycroft q = p;
449 1.4 mycroft #ifdef SNMP
450 1.4 mycroft if (*p == '"') {
451 1.4 mycroft p++;
452 1.4 mycroft while (*p && *p != '"' && *p != '\n')
453 1.4 mycroft p++; /* find next whitespace */
454 1.4 mycroft if (*p == '"')
455 1.4 mycroft p++;
456 1.4 mycroft } else
457 1.4 mycroft #endif
458 1.1 mycroft while (*p && *p != ' ' && *p != '\t' && *p != '\n')
459 1.1 mycroft p++; /* find next whitespace */
460 1.1 mycroft *p++ = '\0'; /* null-terminate string */
461 1.1 mycroft
462 1.1 mycroft if (!*q) {
463 1.1 mycroft p = NULL;
464 1.1 mycroft continue; /* if 0-length string, read another line */
465 1.1 mycroft }
466 1.1 mycroft
467 1.1 mycroft return q;
468 1.1 mycroft }
469 1.1 mycroft }
470 1.1 mycroft
471 1.4 mycroft static int
472 1.4 mycroft yylex()
473 1.1 mycroft {
474 1.1 mycroft int n;
475 1.1 mycroft u_int32_t addr;
476 1.1 mycroft char *q;
477 1.13 dsl char c;
478 1.1 mycroft
479 1.1 mycroft if ((q = next_word()) == NULL) {
480 1.1 mycroft return 0;
481 1.1 mycroft }
482 1.1 mycroft
483 1.1 mycroft if (!strcmp(q,"cache_lifetime"))
484 1.1 mycroft return CACHE_LIFETIME;
485 1.1 mycroft if (!strcmp(q,"pruning"))
486 1.1 mycroft return PRUNING;
487 1.1 mycroft if (!strcmp(q,"phyint"))
488 1.1 mycroft return PHYINT;
489 1.1 mycroft if (!strcmp(q,"tunnel"))
490 1.1 mycroft return TUNNEL;
491 1.1 mycroft if (!strcmp(q,"disable"))
492 1.1 mycroft return DISABLE;
493 1.1 mycroft if (!strcmp(q,"metric"))
494 1.1 mycroft return METRIC;
495 1.1 mycroft if (!strcmp(q,"threshold"))
496 1.1 mycroft return THRESHOLD;
497 1.1 mycroft if (!strcmp(q,"rate_limit"))
498 1.1 mycroft return RATE_LIMIT;
499 1.1 mycroft if (!strcmp(q,"srcrt") || !strcmp(q,"sourceroute"))
500 1.1 mycroft return SRCRT;
501 1.1 mycroft if (!strcmp(q,"boundary"))
502 1.1 mycroft return BOUNDARY;
503 1.1 mycroft if (!strcmp(q,"netmask"))
504 1.1 mycroft return NETMASK;
505 1.4 mycroft if (!strcmp(q,"igmpv1"))
506 1.4 mycroft return IGMPV1;
507 1.4 mycroft if (!strcmp(q,"altnet"))
508 1.4 mycroft return ALTNET;
509 1.1 mycroft if (!strcmp(q,"name"))
510 1.1 mycroft return NAME;
511 1.1 mycroft if (!strcmp(q,"on") || !strcmp(q,"yes")) {
512 1.1 mycroft yylval.num = 1;
513 1.1 mycroft return BOOLEAN;
514 1.1 mycroft }
515 1.1 mycroft if (!strcmp(q,"off") || !strcmp(q,"no")) {
516 1.1 mycroft yylval.num = 0;
517 1.1 mycroft return BOOLEAN;
518 1.1 mycroft }
519 1.13 dsl if ((addr = inet_parse(q, &n)) != 0xffffffff) {
520 1.13 dsl yylval.addrmask.mask = n;
521 1.13 dsl yylval.addrmask.addr = addr;
522 1.13 dsl return ADDRMASK;
523 1.1 mycroft }
524 1.13 dsl if ((addr = inet_parse(q,0)) != 0xffffffff &&
525 1.13 dsl inet_valid_host(addr)) {
526 1.13 dsl yylval.addr = addr;
527 1.13 dsl return ADDR;
528 1.1 mycroft }
529 1.13 dsl if (sscanf(q,"0x%8x%c",&n,&c) == 1) {
530 1.1 mycroft yylval.addr = n;
531 1.1 mycroft return ADDR;
532 1.1 mycroft }
533 1.13 dsl if (sscanf(q,"%d%c",&n,&c) == 1) {
534 1.1 mycroft yylval.num = n;
535 1.1 mycroft return NUMBER;
536 1.1 mycroft }
537 1.4 mycroft #ifdef SNMP
538 1.4 mycroft if (!strcmp(q,"sysName"))
539 1.4 mycroft return SYSNAM;
540 1.4 mycroft if (!strcmp(q,"sysContact"))
541 1.4 mycroft return SYSCONTACT;
542 1.4 mycroft if (!strcmp(q,"sysVersion"))
543 1.4 mycroft return SYSVERSION;
544 1.4 mycroft if (!strcmp(q,"sysLocation"))
545 1.4 mycroft return SYSLOCATION;
546 1.4 mycroft if (*q=='"') {
547 1.4 mycroft if (q[ strlen(q)-1 ]=='"')
548 1.4 mycroft q[ strlen(q)-1 ]='\0'; /* trash trailing quote */
549 1.4 mycroft yylval.ptr = q+1;
550 1.4 mycroft return STRING;
551 1.4 mycroft }
552 1.4 mycroft #endif
553 1.1 mycroft yylval.ptr = q;
554 1.1 mycroft return STRING;
555 1.1 mycroft }
556 1.1 mycroft
557 1.4 mycroft void
558 1.4 mycroft config_vifs_from_file()
559 1.1 mycroft {
560 1.1 mycroft extern FILE *f;
561 1.1 mycroft
562 1.1 mycroft order = 0;
563 1.1 mycroft numbounds = 0;
564 1.1 mycroft lineno = 0;
565 1.1 mycroft
566 1.1 mycroft if ((f = fopen(configfilename, "r")) == NULL) {
567 1.1 mycroft if (errno != ENOENT)
568 1.10 wiz logit(LOG_ERR, errno, "can't open %s", configfilename);
569 1.1 mycroft return;
570 1.1 mycroft }
571 1.1 mycroft
572 1.1 mycroft ifc.ifc_buf = (char *)ifbuf;
573 1.1 mycroft ifc.ifc_len = sizeof(ifbuf);
574 1.1 mycroft if (ioctl(udp_socket, SIOCGIFCONF, (char *)&ifc) < 0)
575 1.10 wiz logit(LOG_ERR, errno, "ioctl SIOCGIFCONF");
576 1.1 mycroft
577 1.1 mycroft yyparse();
578 1.1 mycroft
579 1.4 mycroft fclose(f);
580 1.1 mycroft }
581 1.1 mycroft
582 1.1 mycroft static u_int32_t
583 1.1 mycroft valid_if(s)
584 1.1 mycroft char *s;
585 1.1 mycroft {
586 1.8 wiz vifi_t vifi;
587 1.8 wiz struct uvif *v;
588 1.1 mycroft
589 1.1 mycroft for (vifi=0, v=uvifs; vifi<numvifs; vifi++, v++)
590 1.1 mycroft if (!strcmp(v->uv_name, s))
591 1.1 mycroft return v->uv_lcl_addr;
592 1.1 mycroft
593 1.1 mycroft return 0;
594 1.1 mycroft }
595 1.1 mycroft
596 1.1 mycroft static struct ifreq *
597 1.1 mycroft ifconfaddr(ifcp, a)
598 1.1 mycroft struct ifconf *ifcp;
599 1.1 mycroft u_int32_t a;
600 1.1 mycroft {
601 1.1 mycroft int n;
602 1.1 mycroft struct ifreq *ifrp = (struct ifreq *)ifcp->ifc_buf;
603 1.1 mycroft struct ifreq *ifend = (struct ifreq *)((char *)ifrp + ifcp->ifc_len);
604 1.1 mycroft
605 1.1 mycroft while (ifrp < ifend) {
606 1.1 mycroft if (ifrp->ifr_addr.sa_family == AF_INET &&
607 1.1 mycroft ((struct sockaddr_in *)&ifrp->ifr_addr)->sin_addr.s_addr == a)
608 1.1 mycroft return (ifrp);
609 1.1 mycroft #if (defined(BSD) && (BSD >= 199006))
610 1.1 mycroft n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name);
611 1.1 mycroft if (n < sizeof(*ifrp))
612 1.1 mycroft ++ifrp;
613 1.1 mycroft else
614 1.1 mycroft ifrp = (struct ifreq *)((char *)ifrp + n);
615 1.1 mycroft #else
616 1.1 mycroft ++ifrp;
617 1.1 mycroft #endif
618 1.1 mycroft }
619 1.1 mycroft return (0);
620 1.1 mycroft }
621