xref: /openbsd-src/usr.sbin/ldpd/ldpd.c (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1 /*	$OpenBSD: ldpd.c,v 1.13 2011/08/20 19:02:28 sthen Exp $ */
2 
3 /*
4  * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
5  * Copyright (c) 2004, 2008 Esben Norby <norby@openbsd.org>
6  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <sys/queue.h>
24 #include <sys/time.h>
25 #include <sys/stat.h>
26 #include <sys/wait.h>
27 #include <sys/param.h>
28 
29 #include <netinet/in.h>
30 #include <arpa/inet.h>
31 #include <netmpls/mpls.h>
32 
33 #include <event.h>
34 #include <err.h>
35 #include <errno.h>
36 #include <pwd.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <signal.h>
41 #include <unistd.h>
42 
43 #include "ldpd.h"
44 #include "ldp.h"
45 #include "ldpe.h"
46 #include "control.h"
47 #include "log.h"
48 #include "lde.h"
49 
50 void		main_sig_handler(int, short, void *);
51 __dead void	usage(void);
52 void		ldpd_shutdown(void);
53 int		check_child(pid_t, const char *);
54 
55 void	main_dispatch_ldpe(int, short, void *);
56 void	main_dispatch_lde(int, short, void *);
57 
58 /*int	ldp_reload(void); */
59 int	ldp_sendboth(enum imsg_type, void *, u_int16_t);
60 /*int	merge_interfaces(struct lspace *, struct lspace *); */
61 /*struct iface *iface_lookup(struct lspace *, struct iface *); */
62 
63 int	pipe_parent2ldpe[2];
64 int	pipe_parent2lde[2];
65 int	pipe_ldpe2lde[2];
66 
67 struct ldpd_conf	*ldpd_conf = NULL;
68 struct imsgev		*iev_ldpe;
69 struct imsgev		*iev_lde;
70 char			*conffile;
71 
72 pid_t			 ldpe_pid = 0;
73 pid_t			 lde_pid = 0;
74 
75 /* ARGSUSED */
76 void
77 main_sig_handler(int sig, short event, void *arg)
78 {
79 	/*
80 	 * signal handler rules don't apply, libevent decouples for us
81 	 */
82 
83 	int	die = 0;
84 
85 	switch (sig) {
86 	case SIGTERM:
87 	case SIGINT:
88 		die = 1;
89 		/* FALLTHROUGH */
90 	case SIGCHLD:
91 		if (check_child(ldpe_pid, "ldp engine")) {
92 			ldpe_pid = 0;
93 			die = 1;
94 		}
95 		if (check_child(lde_pid, "label decision engine")) {
96 			lde_pid = 0;
97 			die = 1;
98 		}
99 		if (die)
100 			ldpd_shutdown();
101 		break;
102 	case SIGHUP:
103 /*
104 		if (ldp_reload() == -1)
105 			log_warnx("configuration reload failed");
106 		else
107 			log_debug("configuration reloaded");
108 */
109 		break;
110 	default:
111 		fatalx("unexpected signal");
112 		/* NOTREACHED */
113 	}
114 }
115 
116 __dead void
117 usage(void)
118 {
119 	extern char *__progname;
120 
121 	fprintf(stderr, "usage: %s [-dnv] [-D macro=value] [-f file]\n",
122 	    __progname);
123 	exit(1);
124 }
125 
126 int
127 main(int argc, char *argv[])
128 {
129 	struct event		 ev_sigint, ev_sigterm, ev_sigchld, ev_sighup;
130 	int			 ch, opts = 0;
131 	int			 debug = 0;
132 
133 	conffile = CONF_FILE;
134 	ldpd_process = PROC_MAIN;
135 
136 	log_init(1);	/* log to stderr until daemonized */
137 	log_verbose(1);
138 
139 	while ((ch = getopt(argc, argv, "dD:f:nv")) != -1) {
140 		switch (ch) {
141 		case 'd':
142 			debug = 1;
143 			break;
144 		case 'D':
145 			if (cmdline_symset(optarg) < 0)
146 				log_warnx("could not parse macro definition %s",
147 				    optarg);
148 			break;
149 		case 'f':
150 			conffile = optarg;
151 			break;
152 		case 'n':
153 			opts |= LDPD_OPT_NOACTION;
154 			break;
155 		case 'v':
156 			if (opts & LDPD_OPT_VERBOSE)
157 				opts |= LDPD_OPT_VERBOSE2;
158 			opts |= LDPD_OPT_VERBOSE;
159 			break;
160 		default:
161 			usage();
162 			/* NOTREACHED */
163 		}
164 	}
165 
166 	/* fetch interfaces early */
167 	kif_init();
168 
169 	/* parse config file */
170 	if ((ldpd_conf = parse_config(conffile, opts)) == NULL )
171 		exit(1);
172 
173 	/* parse config file */
174 
175 	if (ldpd_conf->opts & LDPD_OPT_NOACTION) {
176 		if (ldpd_conf->opts & LDPD_OPT_VERBOSE)
177 			print_config(ldpd_conf);
178 		else
179 			fprintf(stderr, "configuration OK\n");
180 		exit(0);
181 	}
182 
183 	/* check for root privileges  */
184 	if (geteuid())
185 		errx(1, "need root privileges");
186 
187 	/* check for ldpd user */
188 	if (getpwnam(LDPD_USER) == NULL)
189 		errx(1, "unknown user %s", LDPD_USER);
190 
191 	log_init(debug);
192 	log_verbose(opts & LDPD_OPT_VERBOSE);
193 
194 	if (!debug)
195 		daemon(1, 0);
196 
197 	log_info("startup");
198 
199 	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC,
200 	    pipe_parent2ldpe) == -1)
201 		fatal("socketpair");
202 	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_parent2lde) == -1)
203 		fatal("socketpair");
204 	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_ldpe2lde) == -1)
205 		fatal("socketpair");
206 	session_socket_blockmode(pipe_parent2ldpe[0], BM_NONBLOCK);
207 	session_socket_blockmode(pipe_parent2ldpe[1], BM_NONBLOCK);
208 	session_socket_blockmode(pipe_parent2lde[0], BM_NONBLOCK);
209 	session_socket_blockmode(pipe_parent2lde[1], BM_NONBLOCK);
210 	session_socket_blockmode(pipe_ldpe2lde[0], BM_NONBLOCK);
211 	session_socket_blockmode(pipe_ldpe2lde[1], BM_NONBLOCK);
212 
213 	/* start children */
214 	lde_pid = lde(ldpd_conf, pipe_parent2lde, pipe_ldpe2lde,
215 	    pipe_parent2ldpe);
216 	ldpe_pid = ldpe(ldpd_conf, pipe_parent2ldpe, pipe_ldpe2lde,
217 	    pipe_parent2lde);
218 
219 	/* show who we are */
220 	setproctitle("parent");
221 
222 	event_init();
223 
224 	/* setup signal handler */
225 	signal_set(&ev_sigint, SIGINT, main_sig_handler, NULL);
226 	signal_set(&ev_sigterm, SIGTERM, main_sig_handler, NULL);
227 	signal_set(&ev_sigchld, SIGCHLD, main_sig_handler, NULL);
228 	signal_set(&ev_sighup, SIGHUP, main_sig_handler, NULL);
229 	signal_add(&ev_sigint, NULL);
230 	signal_add(&ev_sigterm, NULL);
231 	signal_add(&ev_sigchld, NULL);
232 	signal_add(&ev_sighup, NULL);
233 	signal(SIGPIPE, SIG_IGN);
234 
235 	/* setup pipes to children */
236 	close(pipe_parent2ldpe[1]);
237 	close(pipe_parent2lde[1]);
238 	close(pipe_ldpe2lde[0]);
239 	close(pipe_ldpe2lde[1]);
240 
241 	if ((iev_ldpe = malloc(sizeof(struct imsgev))) == NULL ||
242 	    (iev_lde = malloc(sizeof(struct imsgev))) == NULL)
243 		fatal(NULL);
244 	imsg_init(&iev_ldpe->ibuf, pipe_parent2ldpe[0]);
245 	iev_ldpe->handler = main_dispatch_ldpe;
246 	imsg_init(&iev_lde->ibuf, pipe_parent2lde[0]);
247 	iev_lde->handler = main_dispatch_lde;
248 
249 	/* setup event handler */
250 	iev_ldpe->events = EV_READ;
251 	event_set(&iev_ldpe->ev, iev_ldpe->ibuf.fd, iev_ldpe->events,
252 	    iev_ldpe->handler, iev_ldpe);
253 	event_add(&iev_ldpe->ev, NULL);
254 
255 	iev_lde->events = EV_READ;
256 	event_set(&iev_lde->ev, iev_lde->ibuf.fd, iev_lde->events,
257 	    iev_lde->handler, iev_lde);
258 	event_add(&iev_lde->ev, NULL);
259 
260 	if (kr_init(!(ldpd_conf->flags & LDPD_FLAG_NO_FIB_UPDATE)) == -1)
261 		fatalx("kr_init failed");
262 
263 	/* remove unneded stuff from config */
264 		/* ... */
265 
266 
267 	event_dispatch();
268 
269 	ldpd_shutdown();
270 	/* NOTREACHED */
271 	return (0);
272 }
273 
274 void
275 ldpd_shutdown(void)
276 {
277 	pid_t		 pid;
278 
279 	if (ldpe_pid)
280 		kill(ldpe_pid, SIGTERM);
281 
282 	if (lde_pid)
283 		kill(lde_pid, SIGTERM);
284 
285 	control_cleanup();
286 	kr_shutdown();
287 
288 	do {
289 		if ((pid = wait(NULL)) == -1 &&
290 		    errno != EINTR && errno != ECHILD)
291 			fatal("wait");
292 	} while (pid != -1 || (pid == -1 && errno == EINTR));
293 
294 	msgbuf_clear(&iev_ldpe->ibuf.w);
295 	free(iev_ldpe);
296 	msgbuf_clear(&iev_lde->ibuf.w);
297 	free(iev_lde);
298 	free(ldpd_conf);
299 
300 	close(ldpd_conf->ldp_session_socket);
301 
302 	log_info("terminating");
303 	exit(0);
304 }
305 
306 int
307 check_child(pid_t pid, const char *pname)
308 {
309 	int	status;
310 
311 	if (waitpid(pid, &status, WNOHANG) > 0) {
312 		if (WIFEXITED(status)) {
313 			log_warnx("lost child: %s exited", pname);
314 			return (1);
315 		}
316 		if (WIFSIGNALED(status)) {
317 			log_warnx("lost child: %s terminated; signal %d",
318 			    pname, WTERMSIG(status));
319 			return (1);
320 		}
321 	}
322 
323 	return (0);
324 }
325 
326 /* imsg handling */
327 /* ARGSUSED */
328 void
329 main_dispatch_ldpe(int fd, short event, void *bula)
330 {
331 	struct imsgev		*iev = bula;
332 	struct imsgbuf		*ibuf = &iev->ibuf;
333 	struct imsg		 imsg;
334 	ssize_t			 n;
335 	int			 shut = 0, verbose;
336 
337 	if (event & EV_READ) {
338 		if ((n = imsg_read(ibuf)) == -1)
339 			fatal("imsg_read error");
340 		if (n == 0)	/* connection closed */
341 			shut = 1;
342 	}
343 	if (event & EV_WRITE) {
344 		if (msgbuf_write(&ibuf->w) == -1)
345 			fatal("msgbuf_write");
346 	}
347 
348 	for (;;) {
349 		if ((n = imsg_get(ibuf, &imsg)) == -1)
350 			fatal("imsg_get");
351 
352 		if (n == 0)
353 			break;
354 
355 		switch (imsg.hdr.type) {
356 		case IMSG_CTL_RELOAD:
357 /*
358 			if (ldp_reload() == -1)
359 				log_warnx("configuration reload failed");
360 			else
361 				log_debug("configuration reloaded");
362 			break;
363 */
364 		case IMSG_CTL_FIB_COUPLE:
365 			kr_fib_couple();
366 			break;
367 		case IMSG_CTL_FIB_DECOUPLE:
368 			kr_fib_decouple();
369 			break;
370 		case IMSG_CTL_KROUTE:
371 		case IMSG_CTL_KROUTE_ADDR:
372 			kr_show_route(&imsg);
373 			break;
374 		case IMSG_CTL_IFINFO:
375 			if (imsg.hdr.len == IMSG_HEADER_SIZE)
376 				kr_ifinfo(NULL, imsg.hdr.pid);
377 			else if (imsg.hdr.len == IMSG_HEADER_SIZE + IFNAMSIZ)
378 				kr_ifinfo(imsg.data, imsg.hdr.pid);
379 			else
380 				log_warnx("IFINFO request with wrong len");
381 			break;
382 		case IMSG_CTL_LOG_VERBOSE:
383 			/* already checked by ldpe */
384 			memcpy(&verbose, imsg.data, sizeof(verbose));
385 			log_verbose(verbose);
386 			break;
387 		default:
388 			log_debug("main_dispatch_ldpe: error handling imsg %d",
389 			    imsg.hdr.type);
390 			break;
391 		}
392 		imsg_free(&imsg);
393 	}
394 	if (!shut)
395 		imsg_event_add(iev);
396 	else {
397 		/* this pipe is dead, so remove the event handler */
398 		event_del(&iev->ev);
399 		event_loopexit(NULL);
400 	}
401 }
402 
403 /* ARGSUSED */
404 void
405 main_dispatch_lde(int fd, short event, void *bula)
406 {
407 	struct imsgev  *iev = bula;
408 	struct imsgbuf *ibuf = &iev->ibuf;
409 	struct imsg	 imsg;
410 	ssize_t		 n;
411 	int		 shut = 0;
412 
413 	if (event & EV_READ) {
414 		if ((n = imsg_read(ibuf)) == -1)
415 			fatal("imsg_read error");
416 		if (n == 0)	/* connection closed */
417 			shut = 1;
418 	}
419 	if (event & EV_WRITE) {
420 		if (msgbuf_write(&ibuf->w) == -1)
421 			fatal("msgbuf_write");
422 	}
423 
424 	for (;;) {
425 		if ((n = imsg_get(ibuf, &imsg)) == -1)
426 			fatal("imsg_get");
427 
428 		if (n == 0)
429 			break;
430 
431 		switch (imsg.hdr.type) {
432 		case IMSG_KLABEL_CHANGE:
433 			if (imsg.hdr.len - IMSG_HEADER_SIZE !=
434 			    sizeof(struct kroute))
435 				fatalx("invalid size of IMSG_KLABEL_CHANGE");
436 			if (kr_change(imsg.data))
437 				log_warn("main_dispatch_lde: error changing "
438 				    "route");
439 			break;
440 		case IMSG_KLABEL_DELETE:
441 			if (imsg.hdr.len - IMSG_HEADER_SIZE !=
442 			    sizeof(struct kroute))
443 				fatalx("invalid size of IMSG_KLABEL_DELETE");
444 			if (kr_delete(imsg.data))
445 				log_warn("main_dispatch_lde: error deleting "
446 				    "route");
447 			break;
448 		default:
449 			log_debug("main_dispatch_lde: error handling imsg %d",
450 			    imsg.hdr.type);
451 			break;
452 		}
453 		imsg_free(&imsg);
454 	}
455 	if (!shut)
456 		imsg_event_add(iev);
457 	else {
458 		/* this pipe is dead, so remove the event handler */
459 		event_del(&iev->ev);
460 		event_loopexit(NULL);
461 	}
462 }
463 
464 void
465 main_imsg_compose_ldpe(int type, pid_t pid, void *data, u_int16_t datalen)
466 {
467 	if (iev_ldpe == NULL)
468 		return;
469 	imsg_compose_event(iev_ldpe, type, 0, pid, -1, data, datalen);
470 }
471 
472 void
473 main_imsg_compose_lde(int type, pid_t pid, void *data, u_int16_t datalen)
474 {
475 	imsg_compose_event(iev_lde, type, 0, pid, -1, data, datalen);
476 }
477 
478 void
479 imsg_event_add(struct imsgev *iev)
480 {
481 	iev->events = EV_READ;
482 	if (iev->ibuf.w.queued)
483 		iev->events |= EV_WRITE;
484 
485 	event_del(&iev->ev);
486 	event_set(&iev->ev, iev->ibuf.fd, iev->events, iev->handler, iev);
487 	event_add(&iev->ev, NULL);
488 }
489 
490 int
491 imsg_compose_event(struct imsgev *iev, u_int16_t type,
492     u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen)
493 {
494 	int	ret;
495 
496 	if ((ret = imsg_compose(&iev->ibuf, type, peerid,
497 	    pid, fd, data, datalen)) != -1)
498 		imsg_event_add(iev);
499 	return (ret);
500 }
501 
502 void
503 evbuf_enqueue(struct evbuf *eb, struct ibuf *buf)
504 {
505 	ibuf_close(&eb->wbuf, buf);
506 	evbuf_event_add(eb);
507 }
508 
509 void
510 evbuf_event_add(struct evbuf *eb)
511 {
512 	if (eb->wbuf.queued)
513 		event_add(&eb->ev, NULL);
514 }
515 
516 void
517 evbuf_init(struct evbuf *eb, int fd, void (*handler)(int, short, void *),
518     void *arg)
519 {
520 	msgbuf_init(&eb->wbuf);
521 	eb->wbuf.fd = fd;
522 	event_set(&eb->ev, eb->wbuf.fd, EV_WRITE, handler, arg);
523 }
524 
525 void
526 evbuf_clear(struct evbuf *eb)
527 {
528 	event_del(&eb->ev);
529 	msgbuf_clear(&eb->wbuf);
530 	eb->wbuf.fd = -1;
531 }
532 
533 /*
534 int
535 ldp_reload(void)
536 {
537 	struct lspace		*lspace;
538 	struct iface		*iface;
539 	struct ldpd_conf	*xconf;
540 
541 	if ((xconf = parse_config(conffile, ldpd_conf->opts)) == NULL)
542 		return (-1);
543 
544 	if (ldp_sendboth(IMSG_RECONF_CONF, xconf, sizeof(*xconf)) == -1)
545 		return (-1);
546 
547 	LIST_FOREACH(lspace, &xconf->lspace_list, entry) {
548 		if (ldp_sendboth(IMSG_RECONF_AREA, lspace, sizeof(*lspace)) == -1)
549 			return (-1);
550 
551 		LIST_FOREACH(iface, &lspace->iface_list, entry) {
552 			if (ldp_sendboth(IMSG_RECONF_IFACE, iface,
553 			    sizeof(*iface)) == -1)
554 				return (-1);
555 		}
556 	}
557 
558 	if (ldp_sendboth(IMSG_RECONF_END, NULL, 0) == -1)
559 		return (-1);
560 
561 	merge_config(ldpd_conf, xconf);
562 
563 	kr_reload();
564 	return (0);
565 }
566 
567 int
568 ldp_sendboth(enum imsg_type type, void *buf, u_int16_t len)
569 {
570 	if (imsg_compose_event(iev_ldpe, type, 0, 0, -1, buf, len) == -1)
571 		return (-1);
572 	if (imsg_compose_event(iev_lde, type, 0, 0, -1, buf, len) == -1)
573 		return (-1);
574 	return (0);
575 }
576 
577 void
578 merge_config(struct ldpd_conf *conf, struct ldpd_conf *xconf)
579 {
580 	struct lspace		*a, *xa, *na;
581 	struct iface		*iface;
582 	struct redistribute	*r;
583 	int			 rchange = 0;
584 
585 	conf->flags = xconf->flags;
586 	conf->spf_delay = xconf->spf_delay;
587 	conf->spf_hold_time = xconf->spf_hold_time;
588 	if ((conf->redistribute & REDISTRIBUTE_ON) !=
589 	    (xconf->redistribute & REDISTRIBUTE_ON))
590 		rchange = 1;
591 	conf->redistribute = xconf->redistribute;
592 	conf->rfc1583compat = xconf->rfc1583compat;
593 
594 	if (ldpd_process == PROC_MAIN) {
595 		while ((r = SIMPLEQ_FIRST(&conf->redist_list)) != NULL) {
596 			SIMPLEQ_REMOVE_HEAD(&conf->redist_list, entry);
597 			free(r);
598 		}
599 		while ((r = SIMPLEQ_FIRST(&xconf->redist_list)) != NULL) {
600 			SIMPLEQ_REMOVE_HEAD(&xconf->redist_list, entry);
601 			SIMPLEQ_INSERT_TAIL(&conf->redist_list, r, entry);
602 		}
603 		goto done;
604 	}
605 
606 	for (a = LIST_FIRST(&conf->lspace_list); a != NULL; a = na) {
607 		na = LIST_NEXT(a, entry);
608 		if ((xa = lspace_find(xconf, a->id)) == NULL) {
609 			if (ldpd_process == PROC_LDP_ENGINE) {
610 				LIST_FOREACH(iface, &a->iface_list, entry)
611 					if_fsm(iface, IF_EVT_DOWN);
612 			}
613 			LIST_REMOVE(a, entry);
614 			lspace_del(a);
615 		}
616 	}
617 
618 	for (xa = LIST_FIRST(&xconf->lspace_list); xa != NULL; xa = na) {
619 		na = LIST_NEXT(xa, entry);
620 		if ((a = lspace_find(conf, xa->id)) == NULL) {
621 			LIST_REMOVE(xa, entry);
622 			LIST_INSERT_HEAD(&conf->lspace_list, xa, entry);
623 			if (ldpd_process == PROC_LDP_ENGINE) {
624 				LIST_FOREACH(iface, &xa->iface_list, entry) {
625 					if_init(conf, iface);
626 					if (if_fsm(iface, IF_EVT_UP)) {
627 						log_debug("error starting "
628 						    "interface %s",
629 						    iface->name);
630 					}
631 				}
632 			}
633 			continue;
634 		}
635 		a->stub = xa->stub;
636 		a->stub_default_cost = xa->stub_default_cost;
637 		if (ldpd_process == PROC_LDE_ENGINE)
638 			a->dirty = 1;
639 
640 		if (merge_interfaces(a, xa) &&
641 		    ldpd_process == PROC_LDP_ENGINE)
642 			a->dirty = 1;
643 	}
644 
645 	if (ldpd_process == PROC_LDP_ENGINE) {
646 		LIST_FOREACH(a, &conf->lspace_list, entry) {
647 			LIST_FOREACH(iface, &a->iface_list, entry) {
648 				if (iface->state == IF_STA_NEW) {
649 					iface->state = IF_STA_DOWN;
650 					if_init(conf, iface);
651 					if (if_fsm(iface, IF_EVT_UP)) {
652 						log_debug("error starting "
653 						    "interface %s",
654 						    iface->name);
655 					}
656 				}
657 			}
658 		}
659 	}
660 
661 done:
662 	while ((a = LIST_FIRST(&xconf->lspace_list)) != NULL) {
663 		LIST_REMOVE(a, entry);
664 		lspace_del(a);
665 	}
666 	free(xconf);
667 }
668 
669 int
670 merge_interfaces(struct lspace *a, struct lspace *xa)
671 {
672 	struct iface	*i, *xi, *ni;
673 	int		 dirty = 0;
674 
675 	for (i = LIST_FIRST(&a->iface_list); i != NULL; i = ni) {
676 		ni = LIST_NEXT(i, entry);
677 		if (iface_lookup(xa, i) == NULL) {
678 			log_debug("merge_config: proc %d label space %s removing "
679 			    "interface %s", ldpd_process, inet_ntoa(a->id),
680 			    i->name);
681 			if (ldpd_process == PROC_LDP_ENGINE)
682 				if_fsm(i, IF_EVT_DOWN);
683 			LIST_REMOVE(i, entry);
684 			if_del(i);
685 		}
686 	}
687 
688 	for (xi = LIST_FIRST(&xa->iface_list); xi != NULL; xi = ni) {
689 		ni = LIST_NEXT(xi, entry);
690 		if ((i = iface_lookup(a, xi)) == NULL) {
691 			log_debug("merge_config: proc %d label space %s adding "
692 			    "interface %s", ldpd_process, inet_ntoa(a->id),
693 			    xi->name);
694 			LIST_REMOVE(xi, entry);
695 			LIST_INSERT_HEAD(&a->iface_list, xi, entry);
696 			xi->lspace = a;
697 			if (ldpd_process == PROC_LDP_ENGINE)
698 				xi->state = IF_STA_NEW;
699 			continue;
700 		}
701 		log_debug("merge_config: proc %d label space %s merging interface %s",
702 		    ldpd_process, inet_ntoa(a->id), i->name);
703 		i->addr = xi->addr;
704 		i->dst = xi->dst;
705 		i->mask = xi->mask;
706 		i->abr_id = xi->abr_id;
707 		i->baudrate = xi->baudrate;
708 		i->dead_interval = xi->dead_interval;
709 		i->mtu = xi->mtu;
710 		i->transmit_delay = xi->transmit_delay;
711 		i->hello_interval = xi->hello_interval;
712 		i->rxmt_interval = xi->rxmt_interval;
713 		if (i->metric != xi->metric)
714 			dirty = 1;
715 		i->metric = xi->metric;
716 		i->priority = xi->priority;
717 		i->flags = xi->flags;
718 		i->type = xi->type;
719 		i->media_type = xi->media_type;
720 		i->linkstate = xi->linkstate;
721 
722 		if (i->passive != xi->passive) {
723 			if (ldpd_process == PROC_LDP_ENGINE)
724 				if_fsm(i, IF_EVT_DOWN);
725 			i->passive = xi->passive;
726 			if (ldpd_process == PROC_LDP_ENGINE)
727 				if_fsm(i, IF_EVT_UP);
728 		}
729 	}
730 	return (dirty);
731 }
732 
733 struct iface *
734 iface_lookup(struct lspace *lspace, struct iface *iface)
735 {
736 	struct iface	*i;
737 
738 	LIST_FOREACH(i, &lspace->iface_list, entry)
739 		if (i->ifindex == iface->ifindex)
740 			return (i);
741 	return (NULL);
742 }
743 */
744