parms.c revision 1.2 1 1.2 thorpej /* $NetBSD: parms.c,v 1.2 1996/08/10 01:29:30 thorpej Exp $ */
2 1.2 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 1983, 1993
5 1.1 thorpej * The Regents of the University of California. All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Redistribution and use in source and binary forms, with or without
8 1.1 thorpej * modification, are permitted provided that the following conditions
9 1.1 thorpej * are met:
10 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.1 thorpej * notice, this list of conditions and the following disclaimer.
12 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.1 thorpej * documentation and/or other materials provided with the distribution.
15 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
16 1.1 thorpej * must display the following acknowledgement:
17 1.1 thorpej * This product includes software developed by the University of
18 1.1 thorpej * California, Berkeley and its contributors.
19 1.1 thorpej * 4. Neither the name of the University nor the names of its contributors
20 1.1 thorpej * may be used to endorse or promote products derived from this software
21 1.1 thorpej * without specific prior written permission.
22 1.1 thorpej *
23 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 thorpej * SUCH DAMAGE.
34 1.1 thorpej */
35 1.1 thorpej
36 1.1 thorpej #if !defined(lint) && !defined(sgi)
37 1.2 thorpej #if 0
38 1.1 thorpej static char sccsid[] = "@(#)if.c 8.1 (Berkeley) 6/5/93";
39 1.2 thorpej #else
40 1.2 thorpej static char rcsid[] = "$NetBSD: parms.c,v 1.2 1996/08/10 01:29:30 thorpej Exp $";
41 1.2 thorpej #endif
42 1.1 thorpej #endif /* not lint */
43 1.1 thorpej
44 1.1 thorpej #include "defs.h"
45 1.1 thorpej #include "pathnames.h"
46 1.1 thorpej
47 1.1 thorpej
48 1.1 thorpej struct parm *parms;
49 1.1 thorpej struct intnet *intnets;
50 1.1 thorpej
51 1.1 thorpej
52 1.1 thorpej /* use configured parameters
53 1.1 thorpej */
54 1.1 thorpej void
55 1.1 thorpej get_parms(struct interface *ifp)
56 1.1 thorpej {
57 1.1 thorpej struct parm *parmp;
58 1.1 thorpej
59 1.1 thorpej /* get all relevant parameters
60 1.1 thorpej */
61 1.1 thorpej for (parmp = parms; parmp != 0; parmp = parmp->parm_next) {
62 1.1 thorpej if ((parmp->parm_name[0] == '\0'
63 1.1 thorpej && on_net(ifp->int_addr,
64 1.1 thorpej parmp->parm_addr_h, parmp->parm_mask))
65 1.1 thorpej || (parmp->parm_name[0] != '\0'
66 1.1 thorpej && !strcmp(ifp->int_name, parmp->parm_name))) {
67 1.1 thorpej /* this group of parameters is relevant,
68 1.1 thorpej * so get its settings
69 1.1 thorpej */
70 1.1 thorpej ifp->int_state |= parmp->parm_int_state;
71 1.1 thorpej if (parmp->parm_passwd[0] != '\0')
72 1.1 thorpej bcopy(parmp->parm_passwd, ifp->int_passwd,
73 1.1 thorpej sizeof(ifp->int_passwd));
74 1.1 thorpej if (parmp->parm_rdisc_pref != 0)
75 1.1 thorpej ifp->int_rdisc_pref = parmp->parm_rdisc_pref;
76 1.1 thorpej if (parmp->parm_rdisc_int != 0)
77 1.1 thorpej ifp->int_rdisc_int = parmp->parm_rdisc_int;
78 1.1 thorpej if (parmp->parm_d_metric != 0)
79 1.1 thorpej ifp->int_d_metric = parmp->parm_d_metric;
80 1.1 thorpej }
81 1.1 thorpej }
82 1.1 thorpej /* default poor-man's router discovery to a metric that will
83 1.1 thorpej * be heard by old versions of routed.
84 1.1 thorpej */
85 1.1 thorpej if ((ifp->int_state & IS_PM_RDISC)
86 1.1 thorpej && ifp->int_d_metric == 0)
87 1.1 thorpej ifp->int_d_metric = HOPCNT_INFINITY-2;
88 1.1 thorpej
89 1.1 thorpej if (IS_RIP_IN_OFF(ifp->int_state))
90 1.1 thorpej ifp->int_state |= IS_NO_RIP_OUT;
91 1.1 thorpej
92 1.1 thorpej if (ifp->int_rdisc_int == 0)
93 1.1 thorpej ifp->int_rdisc_int = DefMaxAdvertiseInterval;
94 1.1 thorpej
95 1.1 thorpej if (!(ifp->int_if_flags & IFF_MULTICAST)
96 1.1 thorpej && !(ifp->int_if_flags & IFF_POINTOPOINT))
97 1.1 thorpej ifp->int_state |= IS_NO_RIPV2_OUT;
98 1.1 thorpej
99 1.1 thorpej if (!(ifp->int_if_flags & IFF_MULTICAST))
100 1.1 thorpej ifp->int_state |= IS_BCAST_RDISC;
101 1.1 thorpej
102 1.1 thorpej if (ifp->int_if_flags & IFF_POINTOPOINT) {
103 1.1 thorpej ifp->int_state |= IS_BCAST_RDISC;
104 1.1 thorpej /* By default, point-to-point links should be passive
105 1.1 thorpej * about router-discovery for the sake of demand-dialing.
106 1.1 thorpej */
107 1.1 thorpej if (0 == (ifp->int_state & GROUP_IS_SOL))
108 1.1 thorpej ifp->int_state |= IS_NO_SOL_OUT;
109 1.1 thorpej if (0 == (ifp->int_state & GROUP_IS_ADV))
110 1.1 thorpej ifp->int_state |= IS_NO_ADV_OUT;
111 1.1 thorpej }
112 1.1 thorpej
113 1.1 thorpej if (0 != (ifp->int_state & (IS_PASSIVE | IS_REMOTE)))
114 1.1 thorpej ifp->int_state |= IS_NO_RDISC;
115 1.1 thorpej if (ifp->int_state & IS_PASSIVE)
116 1.1 thorpej ifp->int_state |= (IS_NO_RIP | IS_NO_RDISC);
117 1.2 thorpej if ((ifp->int_state&(IS_NO_RIP|IS_NO_RDISC)) == (IS_NO_RIP|IS_NO_RDISC))
118 1.1 thorpej ifp->int_state |= IS_PASSIVE;
119 1.1 thorpej }
120 1.1 thorpej
121 1.1 thorpej
122 1.1 thorpej /* Read a list of gateways from /etc/gateways and add them to our tables.
123 1.1 thorpej *
124 1.1 thorpej * This file contains a list of "remote" gateways. That is usually
125 1.1 thorpej * a gateway which we cannot immediately determine if it is present or
126 1.1 thorpej * not as we can do for those provided by directly connected hardware.
127 1.1 thorpej *
128 1.1 thorpej * If a gateway is marked "passive" in the file, then we assume it
129 1.1 thorpej * does not understand RIP and assume it is always present. Those
130 1.1 thorpej * not marked passive are treated as if they were directly connected
131 1.1 thorpej * and assumed to be broken if they do not send us advertisements.
132 1.1 thorpej * All remote interfaces are added to our list, and those not marked
133 1.1 thorpej * passive are sent routing updates.
134 1.1 thorpej *
135 1.1 thorpej * A passive interface can also be local, hardware interface exempt
136 1.1 thorpej * from RIP.
137 1.1 thorpej */
138 1.1 thorpej void
139 1.1 thorpej gwkludge(void)
140 1.1 thorpej {
141 1.1 thorpej FILE *fp;
142 1.1 thorpej char *p, *lptr;
143 1.1 thorpej char lbuf[200], net_host[5], dname[64+1+64+1], gname[64+1], qual[9];
144 1.1 thorpej struct interface *ifp;
145 1.1 thorpej naddr dst, netmask, gate;
146 1.1 thorpej int metric, n;
147 1.1 thorpej u_int state;
148 1.1 thorpej char *type;
149 1.1 thorpej struct parm *parmp;
150 1.1 thorpej
151 1.1 thorpej
152 1.1 thorpej fp = fopen(_PATH_GATEWAYS, "r");
153 1.1 thorpej if (fp == 0)
154 1.1 thorpej return;
155 1.1 thorpej
156 1.1 thorpej for (;;) {
157 1.1 thorpej if (0 == fgets(lbuf, sizeof(lbuf)-1, fp))
158 1.1 thorpej break;
159 1.1 thorpej lptr = lbuf;
160 1.1 thorpej while (*lptr == ' ')
161 1.1 thorpej lptr++;
162 1.1 thorpej if (*lptr == '\n' /* ignore null and comment lines */
163 1.1 thorpej || *lptr == '#')
164 1.1 thorpej continue;
165 1.1 thorpej p = lptr+strlen(lptr)-1;
166 1.1 thorpej while (*p == '\n'
167 1.1 thorpej || *p == ' ')
168 1.1 thorpej *p-- = '\0';
169 1.1 thorpej
170 1.1 thorpej /* notice newfangled parameter lines
171 1.1 thorpej */
172 1.1 thorpej if (strncasecmp("net", lptr, 3)
173 1.1 thorpej && strncasecmp("host", lptr, 4)) {
174 1.1 thorpej p = parse_parms(lptr);
175 1.1 thorpej if (p != 0) {
176 1.1 thorpej if (strcmp(p,lptr))
177 1.1 thorpej msglog("bad \"%s\" in "_PATH_GATEWAYS
178 1.1 thorpej " entry \"%s\"", lptr, p);
179 1.1 thorpej else
180 1.1 thorpej msglog("bad \"%s\" in "_PATH_GATEWAYS,
181 1.1 thorpej lptr);
182 1.1 thorpej }
183 1.1 thorpej continue;
184 1.1 thorpej }
185 1.1 thorpej
186 1.1 thorpej /* {net | host} XX[/M] XX gateway XX metric DD [passive | external]\n */
187 1.1 thorpej n = sscanf(lptr, "%4s %129[^ \t] gateway"
188 1.1 thorpej " %64[^ / \t] metric %d %8s\n",
189 1.1 thorpej net_host, dname, gname, &metric, qual);
190 1.1 thorpej if (n != 5) {
191 1.1 thorpej msglog("bad "_PATH_GATEWAYS" entry \"%s\"", lptr);
192 1.1 thorpej continue;
193 1.1 thorpej }
194 1.1 thorpej if (metric < 0 || metric >= HOPCNT_INFINITY) {
195 1.1 thorpej msglog("bad metric in "_PATH_GATEWAYS" entry \"%s\"",
196 1.1 thorpej lptr);
197 1.1 thorpej continue;
198 1.1 thorpej }
199 1.1 thorpej if (!strcmp(net_host, "host")) {
200 1.1 thorpej if (!gethost(dname, &dst)) {
201 1.1 thorpej msglog("bad host \"%s\" in "_PATH_GATEWAYS
202 1.1 thorpej " entry \"%s\"", dname, lptr);
203 1.1 thorpej continue;
204 1.1 thorpej }
205 1.1 thorpej netmask = HOST_MASK;
206 1.1 thorpej } else if (!strcmp(net_host, "net")) {
207 1.1 thorpej if (!getnet(dname, &dst, &netmask)) {
208 1.1 thorpej msglog("bad net \"%s\" in "_PATH_GATEWAYS
209 1.1 thorpej " entry \"%s\"", dname, lptr);
210 1.1 thorpej continue;
211 1.1 thorpej }
212 1.1 thorpej } else {
213 1.1 thorpej msglog("bad \"%s\" in "_PATH_GATEWAYS
214 1.1 thorpej " entry \"%s\"", lptr);
215 1.1 thorpej continue;
216 1.1 thorpej }
217 1.1 thorpej
218 1.1 thorpej if (!gethost(gname, &gate)) {
219 1.1 thorpej msglog("bad gateway \"%s\" in "_PATH_GATEWAYS
220 1.1 thorpej " entry \"%s\"", gname, lptr);
221 1.1 thorpej continue;
222 1.1 thorpej }
223 1.1 thorpej
224 1.1 thorpej if (strcmp(qual, type = "passive") == 0) {
225 1.1 thorpej /* Passive entries are not placed in our tables,
226 1.1 thorpej * only the kernel's, so we don't copy all of the
227 1.1 thorpej * external routing information within a net.
228 1.1 thorpej * Internal machines should use the default
229 1.1 thorpej * route to a suitable gateway (like us).
230 1.1 thorpej */
231 1.1 thorpej state = IS_REMOTE | IS_PASSIVE;
232 1.1 thorpej if (metric == 0)
233 1.1 thorpej metric = 1;
234 1.1 thorpej
235 1.1 thorpej } else if (strcmp(qual, type = "external") == 0) {
236 1.1 thorpej /* External entries are handled by other means
237 1.1 thorpej * such as EGP, and are placed only in the daemon
238 1.1 thorpej * tables to prevent overriding them with something
239 1.1 thorpej * else.
240 1.1 thorpej */
241 1.1 thorpej state = IS_REMOTE | IS_PASSIVE | IS_EXTERNAL;
242 1.1 thorpej if (metric == 0)
243 1.1 thorpej metric = 1;
244 1.1 thorpej
245 1.1 thorpej } else if (qual[0] == '\0') {
246 1.1 thorpej if (metric != 0) {
247 1.1 thorpej /* Entries that are neither "passive" nor
248 1.1 thorpej * "external" are "remote" and must behave
249 1.1 thorpej * like physical interfaces. If they are not
250 1.1 thorpej * heard from regularly, they are deleted.
251 1.1 thorpej */
252 1.1 thorpej state = IS_REMOTE;
253 1.1 thorpej type = "remote";
254 1.1 thorpej } else {
255 1.1 thorpej /* "remote" entries with a metric of 0
256 1.1 thorpej * are aliases for our own interfaces
257 1.1 thorpej */
258 1.1 thorpej state = IS_REMOTE | IS_PASSIVE;
259 1.1 thorpej type = "alias";
260 1.1 thorpej }
261 1.1 thorpej
262 1.1 thorpej } else {
263 1.1 thorpej msglog("bad "_PATH_GATEWAYS" entry \"%s\"", lptr);
264 1.1 thorpej continue;
265 1.1 thorpej }
266 1.1 thorpej
267 1.1 thorpej /* Remember to advertise the corresponding logical network.
268 1.1 thorpej */
269 1.1 thorpej if (!(state & IS_EXTERNAL)
270 1.1 thorpej && netmask != std_mask(dst))
271 1.1 thorpej state |= IS_SUBNET;
272 1.1 thorpej
273 1.1 thorpej if (0 != (state & (IS_PASSIVE | IS_REMOTE)))
274 1.1 thorpej state |= IS_NO_RDISC;
275 1.1 thorpej if (state & IS_PASSIVE)
276 1.1 thorpej state |= (IS_NO_RIP | IS_NO_RDISC);
277 1.2 thorpej if ((state & (IS_NO_RIP|IS_NO_RDISC)) ==
278 1.2 thorpej (IS_NO_RIP|IS_NO_RDISC))
279 1.1 thorpej state |= IS_PASSIVE;
280 1.1 thorpej
281 1.1 thorpej parmp = (struct parm*)malloc(sizeof(*parmp));
282 1.1 thorpej bzero(parmp, sizeof(*parmp));
283 1.1 thorpej parmp->parm_next = parms;
284 1.1 thorpej parms = parmp;
285 1.1 thorpej parmp->parm_addr_h = ntohl(dst);
286 1.1 thorpej parmp->parm_mask = -1;
287 1.1 thorpej parmp->parm_d_metric = 0;
288 1.1 thorpej parmp->parm_int_state = state;
289 1.1 thorpej
290 1.1 thorpej /* See if this new interface duplicates an existing
291 1.1 thorpej * interface.
292 1.1 thorpej */
293 1.1 thorpej for (ifp = ifnet; 0 != ifp; ifp = ifp->int_next) {
294 1.1 thorpej if (ifp->int_mask == netmask
295 1.1 thorpej && ((ifp->int_addr == dst
296 1.1 thorpej && netmask != HOST_MASK)
297 1.1 thorpej || (ifp->int_dstaddr == dst
298 1.1 thorpej && netmask == HOST_MASK)))
299 1.1 thorpej break;
300 1.1 thorpej }
301 1.1 thorpej if (ifp != 0) {
302 1.1 thorpej /* Let one of our real interfaces be marked passive.
303 1.1 thorpej */
304 1.1 thorpej if ((state & IS_PASSIVE) && !(state & IS_EXTERNAL)) {
305 1.1 thorpej ifp->int_state |= state;
306 1.1 thorpej } else {
307 1.1 thorpej msglog("%s is duplicated in "_PATH_GATEWAYS
308 1.1 thorpej " by %s",
309 1.1 thorpej ifp->int_name, lptr);
310 1.1 thorpej }
311 1.1 thorpej continue;
312 1.1 thorpej }
313 1.1 thorpej
314 1.1 thorpej tot_interfaces++;
315 1.1 thorpej
316 1.1 thorpej ifp = (struct interface *)malloc(sizeof(*ifp));
317 1.1 thorpej bzero(ifp, sizeof(*ifp));
318 1.1 thorpej if (ifnet != 0) {
319 1.1 thorpej ifp->int_next = ifnet;
320 1.1 thorpej ifnet->int_prev = ifp;
321 1.1 thorpej }
322 1.1 thorpej ifnet = ifp;
323 1.1 thorpej
324 1.1 thorpej ifp->int_state = state;
325 1.1 thorpej ifp->int_net = ntohl(dst) & netmask;
326 1.1 thorpej ifp->int_mask = netmask;
327 1.1 thorpej if (netmask == HOST_MASK)
328 1.1 thorpej ifp->int_if_flags |= IFF_POINTOPOINT;
329 1.1 thorpej ifp->int_dstaddr = dst;
330 1.1 thorpej ifp->int_addr = gate;
331 1.1 thorpej ifp->int_metric = metric;
332 1.1 thorpej (void)sprintf(ifp->int_name, "%s-%s", type, naddr_ntoa(dst));
333 1.1 thorpej ifp->int_index = -1;
334 1.1 thorpej
335 1.1 thorpej get_parms(ifp);
336 1.1 thorpej
337 1.1 thorpej trace_if("Add", ifp);
338 1.1 thorpej }
339 1.1 thorpej }
340 1.1 thorpej
341 1.1 thorpej
342 1.1 thorpej /* parse a set of parameters for an interface
343 1.1 thorpej */
344 1.1 thorpej char * /* 0 or error message */
345 1.1 thorpej parse_parms(char *line)
346 1.1 thorpej {
347 1.1 thorpej #define PARS(str) (0 == (tgt = str, strcasecmp(tok, tgt)))
348 1.1 thorpej #define PARSE(str) (0 == (tgt = str, strncasecmp(tok, str "=", sizeof(str))))
349 1.1 thorpej #define CKF(g,b) {if (0 != (parm.parm_int_state & ((g) & ~(b)))) break; \
350 1.1 thorpej parm.parm_int_state |= (b);}
351 1.1 thorpej #define DELIMS " ,\t\n"
352 1.1 thorpej struct parm parm;
353 1.1 thorpej struct intnet *intnetp;
354 1.1 thorpej char *tok, *tgt, *p;
355 1.1 thorpej
356 1.1 thorpej
357 1.1 thorpej /* "subnet=x.y.z.u/mask" must be alone on the line */
358 1.1 thorpej if (!strncasecmp("subnet=",line,7)) {
359 1.1 thorpej intnetp = (struct intnet*)malloc(sizeof(*intnetp));
360 1.1 thorpej intnetp->intnet_metric = 1;
361 1.2 thorpej if ((p = strrchr(line,','))) {
362 1.1 thorpej *p++ = '\0';
363 1.1 thorpej intnetp->intnet_metric = (int)strtol(p,&p,0);
364 1.1 thorpej if (*p != '\0'
365 1.1 thorpej || intnetp->intnet_metric <= 0
366 1.1 thorpej || intnetp->intnet_metric >= HOPCNT_INFINITY)
367 1.1 thorpej return line;
368 1.1 thorpej }
369 1.1 thorpej if (!getnet(&line[7], &intnetp->intnet_addr,
370 1.1 thorpej &intnetp->intnet_mask)
371 1.1 thorpej || intnetp->intnet_mask == HOST_MASK
372 1.1 thorpej || intnetp->intnet_addr == RIP_DEFAULT) {
373 1.1 thorpej free(intnetp);
374 1.1 thorpej return line;
375 1.1 thorpej }
376 1.1 thorpej intnetp->intnet_next = intnets;
377 1.1 thorpej intnets = intnetp;
378 1.1 thorpej return 0;
379 1.1 thorpej }
380 1.1 thorpej
381 1.1 thorpej bzero(&parm, sizeof(parm));
382 1.1 thorpej
383 1.1 thorpej tgt = "null";
384 1.1 thorpej for (tok = strtok(line, DELIMS);
385 1.1 thorpej tok != 0 && tok[0] != '\0';
386 1.1 thorpej tgt = 0, tok = strtok(0,DELIMS)) {
387 1.1 thorpej if (PARSE("if")) {
388 1.1 thorpej if (parm.parm_name[0] != '\0'
389 1.1 thorpej || tok[3] == '\0'
390 1.1 thorpej || strlen(tok) > IFNAMSIZ+3)
391 1.1 thorpej break;
392 1.1 thorpej strcpy(parm.parm_name, tok+3);
393 1.1 thorpej
394 1.1 thorpej } else if (PARSE("passwd")) {
395 1.1 thorpej if (tok[7] == '\0'
396 1.1 thorpej || strlen(tok) > RIP_AUTH_PW_LEN+7)
397 1.1 thorpej break;
398 1.1 thorpej strcpy(parm.parm_passwd, tok+7);
399 1.1 thorpej
400 1.1 thorpej } else if (PARS("no_ag")) {
401 1.1 thorpej parm.parm_int_state |= (IS_NO_AG | IS_NO_SUPER_AG);
402 1.1 thorpej
403 1.1 thorpej } else if (PARS("no_super_ag")) {
404 1.1 thorpej parm.parm_int_state |= IS_NO_SUPER_AG;
405 1.1 thorpej
406 1.1 thorpej } else if (PARS("no_ripv1_in")) {
407 1.1 thorpej parm.parm_int_state |= IS_NO_RIPV1_IN;
408 1.1 thorpej
409 1.1 thorpej } else if (PARS("no_ripv2_in")) {
410 1.1 thorpej parm.parm_int_state |= IS_NO_RIPV2_IN;
411 1.1 thorpej
412 1.1 thorpej } else if (PARS("ripv2_out")) {
413 1.1 thorpej if (parm.parm_int_state & IS_NO_RIPV2_OUT)
414 1.1 thorpej break;
415 1.1 thorpej parm.parm_int_state |= IS_NO_RIPV1_OUT;
416 1.1 thorpej
417 1.1 thorpej } else if (PARS("no_rip")) {
418 1.1 thorpej parm.parm_int_state |= IS_NO_RIP;
419 1.1 thorpej
420 1.1 thorpej } else if (PARS("no_rdisc")) {
421 1.1 thorpej CKF((GROUP_IS_SOL|GROUP_IS_ADV), IS_NO_RDISC);
422 1.1 thorpej
423 1.1 thorpej } else if (PARS("no_solicit")) {
424 1.1 thorpej CKF(GROUP_IS_SOL, IS_NO_SOL_OUT);
425 1.1 thorpej
426 1.1 thorpej } else if (PARS("send_solicit")) {
427 1.1 thorpej CKF(GROUP_IS_SOL, IS_SOL_OUT);
428 1.1 thorpej
429 1.1 thorpej } else if (PARS("no_rdisc_adv")) {
430 1.1 thorpej CKF(GROUP_IS_ADV, IS_NO_ADV_OUT);
431 1.1 thorpej
432 1.1 thorpej } else if (PARS("rdisc_adv")) {
433 1.1 thorpej CKF(GROUP_IS_ADV, IS_ADV_OUT);
434 1.1 thorpej
435 1.1 thorpej } else if (PARS("bcast_rdisc")) {
436 1.1 thorpej parm.parm_int_state |= IS_BCAST_RDISC;
437 1.1 thorpej
438 1.1 thorpej } else if (PARS("passive")) {
439 1.1 thorpej CKF((GROUP_IS_SOL|GROUP_IS_ADV), IS_NO_RDISC);
440 1.1 thorpej parm.parm_int_state |= IS_NO_RIP;
441 1.1 thorpej
442 1.1 thorpej } else if (PARSE("rdisc_pref")) {
443 1.1 thorpej if (parm.parm_rdisc_pref != 0
444 1.1 thorpej || tok[11] == '\0'
445 1.1 thorpej || (parm.parm_rdisc_pref = (int)strtol(&tok[11],
446 1.1 thorpej &p,0),
447 1.1 thorpej *p != '\0'))
448 1.1 thorpej break;
449 1.1 thorpej
450 1.1 thorpej } else if (PARS("pm_rdisc")) {
451 1.1 thorpej parm.parm_int_state |= IS_PM_RDISC;
452 1.1 thorpej
453 1.1 thorpej } else if (PARSE("rdisc_interval")) {
454 1.1 thorpej if (parm.parm_rdisc_int != 0
455 1.1 thorpej || tok[15] == '\0'
456 1.1 thorpej || (parm.parm_rdisc_int = (int)strtol(&tok[15],
457 1.1 thorpej &p,0),
458 1.1 thorpej *p != '\0')
459 1.1 thorpej || parm.parm_rdisc_int < MinMaxAdvertiseInterval
460 1.1 thorpej || parm.parm_rdisc_int > MaxMaxAdvertiseInterval)
461 1.1 thorpej break;
462 1.1 thorpej
463 1.1 thorpej } else if (PARSE("fake_default")) {
464 1.1 thorpej if (parm.parm_d_metric != 0
465 1.1 thorpej || tok[13] == '\0'
466 1.1 thorpej || (parm.parm_d_metric=(int)strtol(&tok[13],&p,0),
467 1.1 thorpej *p != '\0')
468 1.1 thorpej || parm.parm_d_metric > HOPCNT_INFINITY-1)
469 1.1 thorpej break;
470 1.1 thorpej
471 1.1 thorpej } else {
472 1.1 thorpej tgt = tok;
473 1.1 thorpej break;
474 1.1 thorpej }
475 1.1 thorpej }
476 1.1 thorpej if (tgt != 0)
477 1.1 thorpej return tgt;
478 1.1 thorpej
479 1.1 thorpej if (parm.parm_int_state & IS_NO_ADV_IN)
480 1.1 thorpej parm.parm_int_state |= IS_NO_SOL_OUT;
481 1.1 thorpej
482 1.1 thorpej if ((parm.parm_int_state & (IS_NO_RIP | IS_NO_RDISC))
483 1.1 thorpej == (IS_NO_RIP | IS_NO_RDISC))
484 1.1 thorpej parm.parm_int_state |= IS_PASSIVE;
485 1.1 thorpej
486 1.1 thorpej return check_parms(&parm);
487 1.1 thorpej #undef DELIMS
488 1.1 thorpej #undef PARS
489 1.1 thorpej #undef PARSE
490 1.1 thorpej }
491 1.1 thorpej
492 1.1 thorpej
493 1.1 thorpej /* check for duplicate parameter specifications */
494 1.1 thorpej char * /* 0 or error message */
495 1.1 thorpej check_parms(struct parm *new)
496 1.1 thorpej {
497 1.1 thorpej struct parm *parmp;
498 1.1 thorpej
499 1.1 thorpej
500 1.1 thorpej for (parmp = parms; parmp != 0; parmp = parmp->parm_next) {
501 1.1 thorpej if (strcmp(new->parm_name, parmp->parm_name))
502 1.1 thorpej continue;
503 1.1 thorpej if (!on_net(htonl(parmp->parm_addr_h),
504 1.1 thorpej new->parm_addr_h, new->parm_mask)
505 1.1 thorpej && !on_net(htonl(new->parm_addr_h),
506 1.1 thorpej parmp->parm_addr_h, parmp->parm_mask))
507 1.1 thorpej continue;
508 1.1 thorpej
509 1.1 thorpej if (strcmp(parmp->parm_passwd, new->parm_passwd)
510 1.1 thorpej || (0 != (new->parm_int_state & GROUP_IS_SOL)
511 1.1 thorpej && 0 != (parmp->parm_int_state & GROUP_IS_SOL)
512 1.1 thorpej && 0 != ((new->parm_int_state ^ parmp->parm_int_state)
513 1.1 thorpej && GROUP_IS_SOL))
514 1.1 thorpej || (0 != (new->parm_int_state & GROUP_IS_ADV)
515 1.1 thorpej && 0 != (parmp->parm_int_state & GROUP_IS_ADV)
516 1.1 thorpej && 0 != ((new->parm_int_state ^ parmp->parm_int_state)
517 1.1 thorpej && GROUP_IS_ADV))
518 1.1 thorpej || (new->parm_rdisc_pref != 0
519 1.1 thorpej && parmp->parm_rdisc_pref != 0
520 1.1 thorpej && new->parm_rdisc_pref != parmp->parm_rdisc_pref)
521 1.1 thorpej || (new->parm_rdisc_int != 0
522 1.1 thorpej && parmp->parm_rdisc_int != 0
523 1.1 thorpej && new->parm_rdisc_int != parmp->parm_rdisc_int)
524 1.1 thorpej || (new->parm_d_metric != 0
525 1.1 thorpej && parmp->parm_d_metric != 0
526 1.1 thorpej && new->parm_d_metric != parmp->parm_d_metric))
527 1.1 thorpej return "duplicate";
528 1.1 thorpej }
529 1.1 thorpej
530 1.1 thorpej parmp = (struct parm*)malloc(sizeof(*parmp));
531 1.1 thorpej bcopy(new, parmp, sizeof(*parmp));
532 1.1 thorpej parmp->parm_next = parms;
533 1.1 thorpej parms = parmp;
534 1.1 thorpej
535 1.1 thorpej return 0;
536 1.1 thorpej }
537 1.1 thorpej
538 1.1 thorpej
539 1.1 thorpej /* get a network number as a name or a number, with an optional "/xx"
540 1.1 thorpej * netmask.
541 1.1 thorpej */
542 1.1 thorpej int /* 0=bad */
543 1.1 thorpej getnet(char *name,
544 1.1 thorpej naddr *addrp, /* host byte order */
545 1.1 thorpej naddr *maskp)
546 1.1 thorpej {
547 1.1 thorpej int i;
548 1.1 thorpej struct netent *np;
549 1.1 thorpej naddr mask;
550 1.1 thorpej struct in_addr in;
551 1.1 thorpej char hname[MAXHOSTNAMELEN+1];
552 1.1 thorpej char *mname, *p;
553 1.1 thorpej
554 1.1 thorpej
555 1.1 thorpej /* Detect and separate "1.2.3.4/24"
556 1.1 thorpej */
557 1.1 thorpej if (0 != (mname = rindex(name,'/'))) {
558 1.1 thorpej i = (int)(mname - name);
559 1.1 thorpej if (i > sizeof(hname)-1) /* name too long */
560 1.1 thorpej return 0;
561 1.1 thorpej bcopy(name, hname, i);
562 1.1 thorpej hname[i] = '\0';
563 1.1 thorpej mname++;
564 1.1 thorpej name = hname;
565 1.1 thorpej }
566 1.1 thorpej
567 1.1 thorpej np = getnetbyname(name);
568 1.1 thorpej if (np != 0) {
569 1.1 thorpej in.s_addr = (naddr)np->n_net;
570 1.1 thorpej } else if (inet_aton(name, &in) == 1) {
571 1.1 thorpej HTONL(in.s_addr);
572 1.1 thorpej } else {
573 1.1 thorpej return 0;
574 1.1 thorpej }
575 1.1 thorpej
576 1.1 thorpej if (mname == 0) {
577 1.1 thorpej /* we cannot use the interfaces here because we have not
578 1.1 thorpej * looked at them yet.
579 1.1 thorpej */
580 1.1 thorpej mask = std_mask(in.s_addr);
581 1.1 thorpej if ((~mask & ntohl(in.s_addr)) != 0)
582 1.1 thorpej mask = HOST_MASK;
583 1.1 thorpej } else {
584 1.1 thorpej mask = (naddr)strtoul(mname, &p, 0);
585 1.1 thorpej if (*p != '\0' || mask > 32)
586 1.1 thorpej return 0;
587 1.1 thorpej mask = HOST_MASK << (32-mask);
588 1.1 thorpej }
589 1.1 thorpej if (mask != 0 && in.s_addr == RIP_DEFAULT)
590 1.1 thorpej return 0;
591 1.1 thorpej if ((~mask & ntohl(in.s_addr)) != 0)
592 1.1 thorpej return 0;
593 1.1 thorpej
594 1.1 thorpej *addrp = in.s_addr;
595 1.1 thorpej *maskp = mask;
596 1.1 thorpej return 1;
597 1.1 thorpej }
598 1.1 thorpej
599 1.1 thorpej
600 1.1 thorpej int /* 0=bad */
601 1.1 thorpej gethost(char *name,
602 1.1 thorpej naddr *addrp)
603 1.1 thorpej {
604 1.1 thorpej struct hostent *hp;
605 1.1 thorpej struct in_addr in;
606 1.1 thorpej
607 1.1 thorpej
608 1.1 thorpej /* Try for a number first, even in IRIX where gethostbyname()
609 1.1 thorpej * is smart. This avoids hitting the name server which
610 1.1 thorpej * might be sick because routing is.
611 1.1 thorpej */
612 1.1 thorpej if (inet_aton(name, &in) == 1) {
613 1.1 thorpej *addrp = in.s_addr;
614 1.1 thorpej return 1;
615 1.1 thorpej }
616 1.1 thorpej
617 1.1 thorpej hp = gethostbyname(name);
618 1.1 thorpej if (hp) {
619 1.1 thorpej bcopy(hp->h_addr, addrp, sizeof(*addrp));
620 1.1 thorpej return 1;
621 1.1 thorpej }
622 1.1 thorpej
623 1.1 thorpej return 0;
624 1.1 thorpej }
625