]> git.proxmox.com Git - mirror_frr.git/blob - ldpd/ldpd.c
Merge pull request #5985 from Naveenaidu/5984-cleanup-is_selfroute
[mirror_frr.git] / ldpd / ldpd.c
1 /* $OpenBSD$ */
2
3 /*
4 * Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
5 * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
6 * Copyright (c) 2004, 2008 Esben Norby <norby@openbsd.org>
7 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
8 *
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 */
21
22 #include <zebra.h>
23 #include <sys/wait.h>
24
25 #include "ldpd.h"
26 #include "ldpe.h"
27 #include "lde.h"
28 #include "log.h"
29 #include "ldp_vty.h"
30 #include "ldp_debug.h"
31
32 #include <lib/version.h>
33 #include <lib/log.h>
34 #include "getopt.h"
35 #include "vty.h"
36 #include "command.h"
37 #include "memory.h"
38 #include "privs.h"
39 #include "sigevent.h"
40 #include "zclient.h"
41 #include "vrf.h"
42 #include "filter.h"
43 #include "qobj.h"
44 #include "libfrr.h"
45 #include "lib_errors.h"
46
47 static void ldpd_shutdown(void);
48 static pid_t start_child(enum ldpd_process, char *, int, int);
49 static int main_dispatch_ldpe(struct thread *);
50 static int main_dispatch_lde(struct thread *);
51 static int main_imsg_send_ipc_sockets(struct imsgbuf *,
52 struct imsgbuf *);
53 static void main_imsg_send_net_sockets(int);
54 static void main_imsg_send_net_socket(int, enum socket_type);
55 static int main_imsg_send_config(struct ldpd_conf *);
56 static void ldp_config_normalize(struct ldpd_conf *);
57 static void ldp_config_reset(struct ldpd_conf *);
58 static void ldp_config_reset_main(struct ldpd_conf *);
59 static void ldp_config_reset_af(struct ldpd_conf *, int);
60 static void ldp_config_reset_l2vpns(struct ldpd_conf *);
61 static void merge_global(struct ldpd_conf *, struct ldpd_conf *);
62 static void merge_af(int, struct ldpd_af_conf *,
63 struct ldpd_af_conf *);
64 static void merge_ifaces(struct ldpd_conf *, struct ldpd_conf *);
65 static void merge_iface_af(struct iface_af *, struct iface_af *);
66 static void merge_tnbrs(struct ldpd_conf *, struct ldpd_conf *);
67 static void merge_nbrps(struct ldpd_conf *, struct ldpd_conf *);
68 static void merge_l2vpns(struct ldpd_conf *, struct ldpd_conf *);
69 static void merge_l2vpn(struct ldpd_conf *, struct l2vpn *,
70 struct l2vpn *);
71
72 DEFINE_QOBJ_TYPE(iface)
73 DEFINE_QOBJ_TYPE(tnbr)
74 DEFINE_QOBJ_TYPE(nbr_params)
75 DEFINE_QOBJ_TYPE(l2vpn_if)
76 DEFINE_QOBJ_TYPE(l2vpn_pw)
77 DEFINE_QOBJ_TYPE(l2vpn)
78 DEFINE_QOBJ_TYPE(ldpd_conf)
79
80 struct ldpd_global global;
81 struct ldpd_init init;
82 struct ldpd_conf *ldpd_conf, *vty_conf;
83
84 static struct imsgev *iev_ldpe, *iev_ldpe_sync;
85 static struct imsgev *iev_lde, *iev_lde_sync;
86 static pid_t ldpe_pid;
87 static pid_t lde_pid;
88
89 enum ldpd_process ldpd_process;
90
91 #define LDP_DEFAULT_CONFIG "ldpd.conf"
92 #define LDP_VTY_PORT 2612
93
94 /* Master of threads. */
95 struct thread_master *master;
96
97 static struct frr_daemon_info ldpd_di;
98
99 /* ldpd privileges */
100 static zebra_capabilities_t _caps_p [] =
101 {
102 ZCAP_BIND,
103 ZCAP_NET_ADMIN
104 };
105
106 struct zebra_privs_t ldpd_privs =
107 {
108 #if defined(FRR_USER) && defined(FRR_GROUP)
109 .user = FRR_USER,
110 .group = FRR_GROUP,
111 #endif
112 #if defined(VTY_GROUP)
113 .vty_group = VTY_GROUP,
114 #endif
115 .caps_p = _caps_p,
116 .cap_num_p = array_size(_caps_p),
117 .cap_num_i = 0
118 };
119
120 /* CTL Socket path */
121 char ctl_sock_path[MAXPATHLEN];
122
123 /* LDPd options. */
124 #define OPTION_CTLSOCK 1001
125 static const struct option longopts[] =
126 {
127 { "ctl_socket", required_argument, NULL, OPTION_CTLSOCK},
128 { "instance", required_argument, NULL, 'n'},
129 { 0 }
130 };
131
132 /* SIGHUP handler. */
133 static void
134 sighup(void)
135 {
136 log_info("SIGHUP received");
137
138 /*
139 * Do a full configuration reload. In other words, reset vty_conf
140 * and build a new configuartion from scratch.
141 */
142 ldp_config_reset(vty_conf);
143 vty_read_config(NULL, ldpd_di.config_file, config_default);
144 ldp_config_apply(NULL, vty_conf);
145 }
146
147 /* SIGINT / SIGTERM handler. */
148 static void
149 sigint(void)
150 {
151 log_info("SIGINT received");
152 ldpd_shutdown();
153 }
154
155 /* SIGUSR1 handler. */
156 static void
157 sigusr1(void)
158 {
159 zlog_rotate();
160 }
161
162 static struct quagga_signal_t ldp_signals[] =
163 {
164 {
165 .signal = SIGHUP,
166 .handler = &sighup,
167 },
168 {
169 .signal = SIGINT,
170 .handler = &sigint,
171 },
172 {
173 .signal = SIGTERM,
174 .handler = &sigint,
175 },
176 {
177 .signal = SIGUSR1,
178 .handler = &sigusr1,
179 }
180 };
181
182 static const struct frr_yang_module_info *const ldpd_yang_modules[] = {
183 };
184
185 FRR_DAEMON_INFO(ldpd, LDP,
186 .vty_port = LDP_VTY_PORT,
187
188 .proghelp = "Implementation of the LDP protocol.",
189
190 .signals = ldp_signals,
191 .n_signals = array_size(ldp_signals),
192
193 .privs = &ldpd_privs,
194
195 .yang_modules = ldpd_yang_modules,
196 .n_yang_modules = array_size(ldpd_yang_modules),
197 )
198
199 static int ldp_config_fork_apply(struct thread *t)
200 {
201 /*
202 * So the frr_config_fork() function schedules
203 * the read of the vty config( if there is a
204 * non-integrated config ) to be after the
205 * end of startup and we are starting the
206 * main process loop. We need to schedule
207 * the application of this if necessary
208 * after the read in of the config.
209 */
210 ldp_config_apply(NULL, vty_conf);
211
212 return 0;
213 }
214
215 int
216 main(int argc, char *argv[])
217 {
218 char *saved_argv0;
219 int lflag = 0, eflag = 0;
220 int pipe_parent2ldpe[2], pipe_parent2ldpe_sync[2];
221 int pipe_parent2lde[2], pipe_parent2lde_sync[2];
222 char *ctl_sock_name;
223 struct thread *thread = NULL;
224 bool ctl_sock_used = false;
225
226 snprintf(ctl_sock_path, sizeof(ctl_sock_path), LDPD_SOCKET,
227 "", "");
228
229 ldpd_process = PROC_MAIN;
230 log_procname = log_procnames[ldpd_process];
231
232 saved_argv0 = argv[0];
233 if (saved_argv0 == NULL)
234 saved_argv0 = (char *)"ldpd";
235
236 frr_preinit(&ldpd_di, argc, argv);
237 frr_opt_add("LEn:", longopts,
238 " --ctl_socket Override ctl socket path\n"
239 " -n, --instance Instance id\n");
240
241 /* set default instance (to differentiate ldpd socket from lde one */
242 init.instance = 1;
243
244 while (1) {
245 int opt;
246
247 opt = frr_getopt(argc, argv, NULL);
248
249 if (opt == EOF)
250 break;
251
252 switch (opt) {
253 case 0:
254 break;
255 case OPTION_CTLSOCK:
256 ctl_sock_used = true;
257 ctl_sock_name = strrchr(LDPD_SOCKET, '/');
258 if (ctl_sock_name)
259 /* skip '/' */
260 ctl_sock_name++;
261 else
262 /*
263 * LDPD_SOCKET configured as relative path
264 * during config? Should really never happen for
265 * sensible config
266 */
267 ctl_sock_name = (char *)LDPD_SOCKET;
268 strlcpy(ctl_sock_path, optarg, sizeof(ctl_sock_path));
269 strlcat(ctl_sock_path, "/", sizeof(ctl_sock_path));
270 strlcat(ctl_sock_path, ctl_sock_name,
271 sizeof(ctl_sock_path));
272 break;
273 case 'n':
274 init.instance = atoi(optarg);
275 if (init.instance < 1)
276 exit(0);
277 break;
278 case 'L':
279 lflag = 1;
280 break;
281 case 'E':
282 eflag = 1;
283 break;
284 default:
285 frr_help_exit(1);
286 break;
287 }
288 }
289
290 if (ldpd_di.pathspace && !ctl_sock_used)
291 snprintf(ctl_sock_path, sizeof(ctl_sock_path), LDPD_SOCKET,
292 "/", ldpd_di.pathspace);
293
294 strlcpy(init.user, ldpd_privs.user, sizeof(init.user));
295 strlcpy(init.group, ldpd_privs.group, sizeof(init.group));
296 strlcpy(init.ctl_sock_path, ctl_sock_path, sizeof(init.ctl_sock_path));
297 strlcpy(init.zclient_serv_path, frr_zclientpath,
298 sizeof(init.zclient_serv_path));
299
300 argc -= optind;
301 if (argc > 0 || (lflag && eflag))
302 frr_help_exit(1);
303
304 /* check for root privileges */
305 if (geteuid() != 0) {
306 errno = EPERM;
307 perror(ldpd_di.progname);
308 exit(1);
309 }
310
311 if (lflag || eflag)
312 openzlog(ldpd_di.progname, "LDP", 0,
313 LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
314 if (lflag)
315 lde();
316 else if (eflag)
317 ldpe();
318
319 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_parent2ldpe) == -1)
320 fatal("socketpair");
321 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC,
322 pipe_parent2ldpe_sync) == -1)
323 fatal("socketpair");
324 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_parent2lde) == -1)
325 fatal("socketpair");
326 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC,
327 pipe_parent2lde_sync) == -1)
328 fatal("socketpair");
329 sock_set_nonblock(pipe_parent2ldpe[0]);
330 sock_set_cloexec(pipe_parent2ldpe[0]);
331 sock_set_nonblock(pipe_parent2ldpe[1]);
332 sock_set_cloexec(pipe_parent2ldpe[1]);
333 sock_set_nonblock(pipe_parent2ldpe_sync[0]);
334 sock_set_cloexec(pipe_parent2ldpe_sync[0]);
335 sock_set_cloexec(pipe_parent2ldpe_sync[1]);
336 sock_set_nonblock(pipe_parent2lde[0]);
337 sock_set_cloexec(pipe_parent2lde[0]);
338 sock_set_nonblock(pipe_parent2lde[1]);
339 sock_set_cloexec(pipe_parent2lde[1]);
340 sock_set_nonblock(pipe_parent2lde_sync[0]);
341 sock_set_cloexec(pipe_parent2lde_sync[0]);
342 sock_set_cloexec(pipe_parent2lde_sync[1]);
343
344 /* start children */
345 lde_pid = start_child(PROC_LDE_ENGINE, saved_argv0,
346 pipe_parent2lde[1], pipe_parent2lde_sync[1]);
347 ldpe_pid = start_child(PROC_LDP_ENGINE, saved_argv0,
348 pipe_parent2ldpe[1], pipe_parent2ldpe_sync[1]);
349
350 master = frr_init();
351
352 vrf_init(NULL, NULL, NULL, NULL, NULL);
353 access_list_init();
354 ldp_vty_init();
355 ldp_zebra_init(master);
356
357 /*
358 * Create base configuration with sane defaults. All configuration
359 * requests (e.g. CLI) act on vty_conf and then call ldp_config_apply()
360 * to merge the changes into ldpd_conf, which contains the actual
361 * running configuration.
362 */
363 ldpd_conf = config_new_empty();
364 vty_conf = config_new_empty();
365 QOBJ_REG(vty_conf, ldpd_conf);
366
367 /* read configuration file and daemonize */
368 frr_config_fork();
369
370 /* apply configuration */
371 thread_add_event(master, ldp_config_fork_apply, NULL, 0, &thread);
372
373 /* setup pipes to children */
374 if ((iev_ldpe = calloc(1, sizeof(struct imsgev))) == NULL ||
375 (iev_ldpe_sync = calloc(1, sizeof(struct imsgev))) == NULL ||
376 (iev_lde = calloc(1, sizeof(struct imsgev))) == NULL ||
377 (iev_lde_sync = calloc(1, sizeof(struct imsgev))) == NULL)
378 fatal(NULL);
379 imsg_init(&iev_ldpe->ibuf, pipe_parent2ldpe[0]);
380 iev_ldpe->handler_read = main_dispatch_ldpe;
381 iev_ldpe->ev_read = NULL;
382 thread_add_read(master, iev_ldpe->handler_read, iev_ldpe, iev_ldpe->ibuf.fd,
383 &iev_ldpe->ev_read);
384 iev_ldpe->handler_write = ldp_write_handler;
385
386 imsg_init(&iev_ldpe_sync->ibuf, pipe_parent2ldpe_sync[0]);
387 iev_ldpe_sync->handler_read = main_dispatch_ldpe;
388 iev_ldpe_sync->ev_read = NULL;
389 thread_add_read(master, iev_ldpe_sync->handler_read, iev_ldpe_sync, iev_ldpe_sync->ibuf.fd,
390 &iev_ldpe_sync->ev_read);
391 iev_ldpe_sync->handler_write = ldp_write_handler;
392
393 imsg_init(&iev_lde->ibuf, pipe_parent2lde[0]);
394 iev_lde->handler_read = main_dispatch_lde;
395 iev_lde->ev_read = NULL;
396 thread_add_read(master, iev_lde->handler_read, iev_lde, iev_lde->ibuf.fd,
397 &iev_lde->ev_read);
398 iev_lde->handler_write = ldp_write_handler;
399
400 imsg_init(&iev_lde_sync->ibuf, pipe_parent2lde_sync[0]);
401 iev_lde_sync->handler_read = main_dispatch_lde;
402 iev_lde_sync->ev_read = NULL;
403 thread_add_read(master, iev_lde_sync->handler_read, iev_lde_sync, iev_lde_sync->ibuf.fd,
404 &iev_lde_sync->ev_read);
405 iev_lde_sync->handler_write = ldp_write_handler;
406
407 if (main_imsg_send_ipc_sockets(&iev_ldpe->ibuf, &iev_lde->ibuf))
408 fatal("could not establish imsg links");
409 main_imsg_compose_both(IMSG_DEBUG_UPDATE, &ldp_debug,
410 sizeof(ldp_debug));
411 main_imsg_compose_both(IMSG_INIT, &init, sizeof(init));
412 main_imsg_send_config(ldpd_conf);
413
414 if (ldpd_conf->ipv4.flags & F_LDPD_AF_ENABLED)
415 main_imsg_send_net_sockets(AF_INET);
416 if (ldpd_conf->ipv6.flags & F_LDPD_AF_ENABLED)
417 main_imsg_send_net_sockets(AF_INET6);
418
419 frr_run(master);
420
421 /* NOTREACHED */
422 return (0);
423 }
424
425 static void
426 ldpd_shutdown(void)
427 {
428 pid_t pid;
429 int status;
430
431 frr_early_fini();
432
433 /* close pipes */
434 msgbuf_clear(&iev_ldpe->ibuf.w);
435 close(iev_ldpe->ibuf.fd);
436 msgbuf_clear(&iev_lde->ibuf.w);
437 close(iev_lde->ibuf.fd);
438
439 config_clear(ldpd_conf);
440
441 ldp_config_reset(vty_conf);
442 QOBJ_UNREG(vty_conf);
443 free(vty_conf);
444
445 log_debug("waiting for children to terminate");
446
447 while (true) {
448 /* Wait for child process. */
449 pid = wait(&status);
450 if (pid == -1) {
451 /* We got interrupted, try again. */
452 if (errno == EINTR)
453 continue;
454 /* No more processes were found. */
455 if (errno == ECHILD)
456 break;
457
458 /* Unhandled errno condition. */
459 fatal("wait");
460 /* UNREACHABLE */
461 }
462
463 /* We found something, lets announce it. */
464 if (WIFSIGNALED(status))
465 log_warnx("%s terminated; signal %d",
466 (pid == lde_pid ? "label decision engine"
467 : "ldp engine"),
468 WTERMSIG(status));
469
470 /* Repeat until there are no more child processes. */
471 }
472
473 free(iev_ldpe);
474 free(iev_lde);
475
476 log_info("terminating");
477
478 vrf_terminate();
479 access_list_reset();
480 ldp_zebra_destroy();
481
482 frr_fini();
483 exit(0);
484 }
485
486 static pid_t
487 start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync)
488 {
489 char *argv[3];
490 int argc = 0, nullfd;
491 pid_t pid;
492
493 switch (pid = fork()) {
494 case -1:
495 fatal("cannot fork");
496 case 0:
497 break;
498 default:
499 close(fd_async);
500 close(fd_sync);
501 return (pid);
502 }
503
504 nullfd = open("/dev/null", O_RDONLY | O_NOCTTY);
505 if (nullfd == -1) {
506 flog_err_sys(EC_LIB_SYSTEM_CALL,
507 "%s: failed to open /dev/null: %s", __func__,
508 safe_strerror(errno));
509 } else {
510 dup2(nullfd, 0);
511 dup2(nullfd, 1);
512 dup2(nullfd, 2);
513 close(nullfd);
514 }
515
516 if (dup2(fd_async, LDPD_FD_ASYNC) == -1)
517 fatal("cannot setup imsg async fd");
518 if (dup2(fd_sync, LDPD_FD_SYNC) == -1)
519 fatal("cannot setup imsg sync fd");
520
521 argv[argc++] = argv0;
522 switch (p) {
523 case PROC_MAIN:
524 fatalx("Can not start main process");
525 case PROC_LDE_ENGINE:
526 argv[argc++] = (char *)"-L";
527 break;
528 case PROC_LDP_ENGINE:
529 argv[argc++] = (char *)"-E";
530 break;
531 }
532 argv[argc++] = NULL;
533
534 execvp(argv0, argv);
535 fatal("execvp");
536 }
537
538 /* imsg handling */
539 /* ARGSUSED */
540 static int
541 main_dispatch_ldpe(struct thread *thread)
542 {
543 struct imsgev *iev = THREAD_ARG(thread);
544 struct imsgbuf *ibuf = &iev->ibuf;
545 struct imsg imsg;
546 int af;
547 ssize_t n;
548 int shut = 0;
549
550 iev->ev_read = NULL;
551
552 if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN)
553 fatal("imsg_read error");
554 if (n == 0) /* connection closed */
555 shut = 1;
556
557 for (;;) {
558 if ((n = imsg_get(ibuf, &imsg)) == -1)
559 fatal("imsg_get");
560
561 if (n == 0)
562 break;
563
564 switch (imsg.hdr.type) {
565 case IMSG_LOG:
566 logit(imsg.hdr.pid, "%s", (const char *)imsg.data);
567 break;
568 case IMSG_REQUEST_SOCKETS:
569 af = imsg.hdr.pid;
570 main_imsg_send_net_sockets(af);
571 break;
572 case IMSG_ACL_CHECK:
573 if (imsg.hdr.len != IMSG_HEADER_SIZE +
574 sizeof(struct acl_check))
575 fatalx("IMSG_ACL_CHECK imsg with wrong len");
576 ldp_acl_reply(iev, (struct acl_check *)imsg.data);
577 break;
578 default:
579 log_debug("%s: error handling imsg %d", __func__,
580 imsg.hdr.type);
581 break;
582 }
583 imsg_free(&imsg);
584 }
585 if (!shut)
586 imsg_event_add(iev);
587 else {
588 /* this pipe is dead, so remove the event handlers and exit */
589 THREAD_READ_OFF(iev->ev_read);
590 THREAD_WRITE_OFF(iev->ev_write);
591 ldpe_pid = 0;
592 if (lde_pid == 0)
593 ldpd_shutdown();
594 else
595 kill(lde_pid, SIGTERM);
596 }
597
598 return (0);
599 }
600
601 /* ARGSUSED */
602 static int
603 main_dispatch_lde(struct thread *thread)
604 {
605 struct imsgev *iev = THREAD_ARG(thread);
606 struct imsgbuf *ibuf = &iev->ibuf;
607 struct imsg imsg;
608 ssize_t n;
609 int shut = 0;
610
611 iev->ev_read = NULL;
612
613 if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN)
614 fatal("imsg_read error");
615 if (n == 0) /* connection closed */
616 shut = 1;
617
618 for (;;) {
619 if ((n = imsg_get(ibuf, &imsg)) == -1)
620 fatal("imsg_get");
621
622 if (n == 0)
623 break;
624
625 switch (imsg.hdr.type) {
626 case IMSG_LOG:
627 logit(imsg.hdr.pid, "%s", (const char *)imsg.data);
628 break;
629 case IMSG_KLABEL_CHANGE:
630 if (imsg.hdr.len - IMSG_HEADER_SIZE !=
631 sizeof(struct kroute))
632 fatalx("invalid size of IMSG_KLABEL_CHANGE");
633 if (kr_change(imsg.data))
634 log_warnx("%s: error changing route", __func__);
635 break;
636 case IMSG_KLABEL_DELETE:
637 if (imsg.hdr.len - IMSG_HEADER_SIZE !=
638 sizeof(struct kroute))
639 fatalx("invalid size of IMSG_KLABEL_DELETE");
640 if (kr_delete(imsg.data))
641 log_warnx("%s: error deleting route", __func__);
642 break;
643 case IMSG_KPW_ADD:
644 case IMSG_KPW_DELETE:
645 case IMSG_KPW_SET:
646 case IMSG_KPW_UNSET:
647 if (imsg.hdr.len - IMSG_HEADER_SIZE !=
648 sizeof(struct zapi_pw))
649 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
650
651 switch (imsg.hdr.type) {
652 case IMSG_KPW_ADD:
653 if (kmpw_add(imsg.data))
654 log_warnx("%s: error adding "
655 "pseudowire", __func__);
656 break;
657 case IMSG_KPW_DELETE:
658 if (kmpw_del(imsg.data))
659 log_warnx("%s: error deleting "
660 "pseudowire", __func__);
661 break;
662 case IMSG_KPW_SET:
663 if (kmpw_set(imsg.data))
664 log_warnx("%s: error setting "
665 "pseudowire", __func__);
666 break;
667 case IMSG_KPW_UNSET:
668 if (kmpw_unset(imsg.data))
669 log_warnx("%s: error unsetting "
670 "pseudowire", __func__);
671 break;
672 }
673 break;
674 case IMSG_ACL_CHECK:
675 if (imsg.hdr.len != IMSG_HEADER_SIZE +
676 sizeof(struct acl_check))
677 fatalx("IMSG_ACL_CHECK imsg with wrong len");
678 ldp_acl_reply(iev, (struct acl_check *)imsg.data);
679 break;
680 default:
681 log_debug("%s: error handling imsg %d", __func__,
682 imsg.hdr.type);
683 break;
684 }
685 imsg_free(&imsg);
686 }
687 if (!shut)
688 imsg_event_add(iev);
689 else {
690 /* this pipe is dead, so remove the event handlers and exit */
691 THREAD_READ_OFF(iev->ev_read);
692 THREAD_WRITE_OFF(iev->ev_write);
693 lde_pid = 0;
694 if (ldpe_pid == 0)
695 ldpd_shutdown();
696 else
697 kill(ldpe_pid, SIGTERM);
698 }
699
700 return (0);
701 }
702
703 /* ARGSUSED */
704 int
705 ldp_write_handler(struct thread *thread)
706 {
707 struct imsgev *iev = THREAD_ARG(thread);
708 struct imsgbuf *ibuf = &iev->ibuf;
709 ssize_t n;
710
711 iev->ev_write = NULL;
712
713 if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
714 fatal("msgbuf_write");
715 if (n == 0) {
716 /* this pipe is dead, so remove the event handlers */
717 THREAD_READ_OFF(iev->ev_read);
718 THREAD_WRITE_OFF(iev->ev_write);
719 return (0);
720 }
721
722 imsg_event_add(iev);
723
724 return (0);
725 }
726
727 void
728 main_imsg_compose_ldpe(int type, pid_t pid, void *data, uint16_t datalen)
729 {
730 if (iev_ldpe == NULL)
731 return;
732 imsg_compose_event(iev_ldpe, type, 0, pid, -1, data, datalen);
733 }
734
735 void
736 main_imsg_compose_lde(int type, pid_t pid, void *data, uint16_t datalen)
737 {
738 imsg_compose_event(iev_lde, type, 0, pid, -1, data, datalen);
739 }
740
741 int
742 main_imsg_compose_both(enum imsg_type type, void *buf, uint16_t len)
743 {
744 if (iev_ldpe == NULL || iev_lde == NULL)
745 return (0);
746 if (imsg_compose_event(iev_ldpe, type, 0, 0, -1, buf, len) == -1)
747 return (-1);
748 if (imsg_compose_event(iev_lde, type, 0, 0, -1, buf, len) == -1)
749 return (-1);
750 return (0);
751 }
752
753 void
754 imsg_event_add(struct imsgev *iev)
755 {
756 if (iev->handler_read)
757 thread_add_read(master, iev->handler_read, iev, iev->ibuf.fd,
758 &iev->ev_read);
759
760 if (iev->handler_write && iev->ibuf.w.queued)
761 thread_add_write(master, iev->handler_write, iev,
762 iev->ibuf.fd, &iev->ev_write);
763 }
764
765 int
766 imsg_compose_event(struct imsgev *iev, uint16_t type, uint32_t peerid,
767 pid_t pid, int fd, void *data, uint16_t datalen)
768 {
769 int ret;
770
771 if ((ret = imsg_compose(&iev->ibuf, type, peerid,
772 pid, fd, data, datalen)) != -1)
773 imsg_event_add(iev);
774 return (ret);
775 }
776
777 void
778 evbuf_enqueue(struct evbuf *eb, struct ibuf *buf)
779 {
780 ibuf_close(&eb->wbuf, buf);
781 evbuf_event_add(eb);
782 }
783
784 void
785 evbuf_event_add(struct evbuf *eb)
786 {
787 if (eb->wbuf.queued)
788 thread_add_write(master, eb->handler, eb->arg, eb->wbuf.fd,
789 &eb->ev);
790 }
791
792 void
793 evbuf_init(struct evbuf *eb, int fd, int (*handler)(struct thread *),
794 void *arg)
795 {
796 msgbuf_init(&eb->wbuf);
797 eb->wbuf.fd = fd;
798 eb->handler = handler;
799 eb->arg = arg;
800 }
801
802 void
803 evbuf_clear(struct evbuf *eb)
804 {
805 THREAD_WRITE_OFF(eb->ev);
806 msgbuf_clear(&eb->wbuf);
807 eb->wbuf.fd = -1;
808 }
809
810 static int
811 main_imsg_send_ipc_sockets(struct imsgbuf *ldpe_buf, struct imsgbuf *lde_buf)
812 {
813 int pipe_ldpe2lde[2];
814
815 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_ldpe2lde) == -1)
816 return (-1);
817 sock_set_nonblock(pipe_ldpe2lde[0]);
818 sock_set_nonblock(pipe_ldpe2lde[1]);
819
820 if (imsg_compose(ldpe_buf, IMSG_SOCKET_IPC, 0, 0, pipe_ldpe2lde[0],
821 NULL, 0) == -1)
822 return (-1);
823 if (imsg_compose(lde_buf, IMSG_SOCKET_IPC, 0, 0, pipe_ldpe2lde[1],
824 NULL, 0) == -1)
825 return (-1);
826
827 return (0);
828 }
829
830 static void
831 main_imsg_send_net_sockets(int af)
832 {
833 if (!ldp_addrisset(af, &(ldp_af_conf_get(ldpd_conf, af))->trans_addr))
834 return;
835
836 main_imsg_send_net_socket(af, LDP_SOCKET_DISC);
837 main_imsg_send_net_socket(af, LDP_SOCKET_EDISC);
838 main_imsg_send_net_socket(af, LDP_SOCKET_SESSION);
839 imsg_compose_event(iev_ldpe, IMSG_SETUP_SOCKETS, af, 0, -1, NULL, 0);
840 }
841
842 static void
843 main_imsg_send_net_socket(int af, enum socket_type type)
844 {
845 int fd;
846
847 fd = ldp_create_socket(af, type);
848 if (fd == -1) {
849 log_warnx("%s: failed to create %s socket for address-family "
850 "%s", __func__, socket_name(type), af_name(af));
851 return;
852 }
853
854 imsg_compose_event(iev_ldpe, IMSG_SOCKET_NET, af, 0, fd, &type,
855 sizeof(type));
856 }
857
858 int
859 ldp_acl_request(struct imsgev *iev, char *acl_name, int af,
860 union ldpd_addr *addr, uint8_t prefixlen)
861 {
862 struct imsg imsg;
863 struct acl_check acl_check;
864
865 if (acl_name[0] == '\0')
866 return FILTER_PERMIT;
867
868 /* build request */
869 strlcpy(acl_check.acl, acl_name, sizeof(acl_check.acl));
870 acl_check.af = af;
871 acl_check.addr = *addr;
872 acl_check.prefixlen = prefixlen;
873
874 /* send (blocking) */
875 imsg_compose_event(iev, IMSG_ACL_CHECK, 0, 0, -1, &acl_check,
876 sizeof(acl_check));
877 imsg_flush(&iev->ibuf);
878
879 /* receive (blocking) and parse result */
880 if (imsg_read(&iev->ibuf) == -1)
881 fatal("imsg_read error");
882 if (imsg_get(&iev->ibuf, &imsg) == -1)
883 fatal("imsg_get");
884 if (imsg.hdr.type != IMSG_ACL_CHECK ||
885 imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(int))
886 fatalx("ldp_acl_request: invalid response");
887
888 return (*((int *)imsg.data));
889 }
890
891 void
892 ldp_acl_reply(struct imsgev *iev, struct acl_check *acl_check)
893 {
894 struct access_list *alist;
895 struct prefix prefix;
896 int result;
897
898 alist = access_list_lookup(family2afi(acl_check->af), acl_check->acl);
899 if (alist == NULL)
900 result = FILTER_DENY;
901 else {
902 prefix.family = acl_check->af;
903 switch (prefix.family) {
904 case AF_INET:
905 prefix.u.prefix4 = acl_check->addr.v4;
906 break;
907 case AF_INET6:
908 prefix.u.prefix6 = acl_check->addr.v6;
909 break;
910 default:
911 fatalx("ldp_acl_reply: unknown af");
912 }
913 prefix.prefixlen = acl_check->prefixlen;
914 result = access_list_apply(alist, &prefix);
915 }
916
917 imsg_compose_event(iev, IMSG_ACL_CHECK, 0, 0, -1, &result,
918 sizeof(result));
919 }
920
921 struct ldpd_af_conf *
922 ldp_af_conf_get(struct ldpd_conf *xconf, int af)
923 {
924 switch (af) {
925 case AF_INET:
926 return (&xconf->ipv4);
927 case AF_INET6:
928 return (&xconf->ipv6);
929 default:
930 fatalx("ldp_af_conf_get: unknown af");
931 }
932 }
933
934 struct ldpd_af_global *
935 ldp_af_global_get(struct ldpd_global *xglobal, int af)
936 {
937 switch (af) {
938 case AF_INET:
939 return (&xglobal->ipv4);
940 case AF_INET6:
941 return (&xglobal->ipv6);
942 default:
943 fatalx("ldp_af_global_get: unknown af");
944 }
945 }
946
947 int
948 ldp_is_dual_stack(struct ldpd_conf *xconf)
949 {
950 return ((xconf->ipv4.flags & F_LDPD_AF_ENABLED) &&
951 (xconf->ipv6.flags & F_LDPD_AF_ENABLED));
952 }
953
954 in_addr_t
955 ldp_rtr_id_get(struct ldpd_conf *xconf)
956 {
957 if (xconf->rtr_id.s_addr != INADDR_ANY)
958 return (xconf->rtr_id.s_addr);
959 else
960 return (global.rtr_id.s_addr);
961 }
962
963 static int
964 main_imsg_send_config(struct ldpd_conf *xconf)
965 {
966 struct iface *iface;
967 struct tnbr *tnbr;
968 struct nbr_params *nbrp;
969 struct l2vpn *l2vpn;
970 struct l2vpn_if *lif;
971 struct l2vpn_pw *pw;
972
973 if (main_imsg_compose_both(IMSG_RECONF_CONF, xconf,
974 sizeof(*xconf)) == -1)
975 return (-1);
976
977 RB_FOREACH(iface, iface_head, &xconf->iface_tree) {
978 if (main_imsg_compose_both(IMSG_RECONF_IFACE, iface,
979 sizeof(*iface)) == -1)
980 return (-1);
981 }
982
983 RB_FOREACH(tnbr, tnbr_head, &xconf->tnbr_tree) {
984 if (main_imsg_compose_both(IMSG_RECONF_TNBR, tnbr,
985 sizeof(*tnbr)) == -1)
986 return (-1);
987 }
988
989 RB_FOREACH(nbrp, nbrp_head, &xconf->nbrp_tree) {
990 if (main_imsg_compose_both(IMSG_RECONF_NBRP, nbrp,
991 sizeof(*nbrp)) == -1)
992 return (-1);
993 }
994
995 RB_FOREACH(l2vpn, l2vpn_head, &xconf->l2vpn_tree) {
996 if (main_imsg_compose_both(IMSG_RECONF_L2VPN, l2vpn,
997 sizeof(*l2vpn)) == -1)
998 return (-1);
999
1000 RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) {
1001 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF, lif,
1002 sizeof(*lif)) == -1)
1003 return (-1);
1004 }
1005 RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) {
1006 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW, pw,
1007 sizeof(*pw)) == -1)
1008 return (-1);
1009 }
1010 RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) {
1011 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW, pw,
1012 sizeof(*pw)) == -1)
1013 return (-1);
1014 }
1015 }
1016
1017 if (main_imsg_compose_both(IMSG_RECONF_END, NULL, 0) == -1)
1018 return (-1);
1019
1020 return (0);
1021 }
1022
1023 int
1024 ldp_config_apply(struct vty *vty, struct ldpd_conf *xconf)
1025 {
1026 /*
1027 * When reading from a configuration file (startup and sighup), we
1028 * call merge_config() only once after the whole config has been read.
1029 * This is the optimal and least disruptive way to update the running
1030 * configuration.
1031 */
1032 if (vty && vty->type == VTY_FILE)
1033 return (0);
1034
1035 ldp_config_normalize(xconf);
1036
1037 if (main_imsg_send_config(xconf) == -1)
1038 return (-1);
1039
1040 merge_config(ldpd_conf, xconf);
1041
1042 return (0);
1043 }
1044
1045 static void
1046 ldp_config_normalize(struct ldpd_conf *xconf)
1047 {
1048 struct iface *iface, *itmp;
1049 struct nbr_params *nbrp, *ntmp;
1050 struct l2vpn *l2vpn;
1051 struct l2vpn_pw *pw, *ptmp;
1052
1053 if (!(xconf->flags & F_LDPD_ENABLED))
1054 ldp_config_reset_main(xconf);
1055 else {
1056 if (!(xconf->ipv4.flags & F_LDPD_AF_ENABLED))
1057 ldp_config_reset_af(xconf, AF_INET);
1058 if (!(xconf->ipv6.flags & F_LDPD_AF_ENABLED))
1059 ldp_config_reset_af(xconf, AF_INET6);
1060
1061 RB_FOREACH_SAFE(iface, iface_head, &xconf->iface_tree, itmp) {
1062 if (iface->ipv4.enabled || iface->ipv6.enabled)
1063 continue;
1064
1065 QOBJ_UNREG(iface);
1066 RB_REMOVE(iface_head, &vty_conf->iface_tree, iface);
1067 free(iface);
1068 }
1069
1070 RB_FOREACH_SAFE(nbrp, nbrp_head, &xconf->nbrp_tree, ntmp) {
1071 if (nbrp->flags & (F_NBRP_KEEPALIVE|F_NBRP_GTSM))
1072 continue;
1073 if (nbrp->auth.method != AUTH_NONE)
1074 continue;
1075
1076 QOBJ_UNREG(nbrp);
1077 RB_REMOVE(nbrp_head, &vty_conf->nbrp_tree, nbrp);
1078 free(nbrp);
1079 }
1080 }
1081
1082 RB_FOREACH(l2vpn, l2vpn_head, &xconf->l2vpn_tree) {
1083 RB_FOREACH_SAFE(pw, l2vpn_pw_head, &l2vpn->pw_tree, ptmp) {
1084 if (!(pw->flags & F_PW_STATIC_NBR_ADDR)) {
1085 pw->af = AF_INET;
1086 pw->addr.v4 = pw->lsr_id;
1087 }
1088
1089 if (pw->lsr_id.s_addr != INADDR_ANY && pw->pwid != 0)
1090 continue;
1091 RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw);
1092 RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
1093 }
1094 RB_FOREACH_SAFE(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree,
1095 ptmp) {
1096 if (!(pw->flags & F_PW_STATIC_NBR_ADDR)) {
1097 pw->af = AF_INET;
1098 pw->addr.v4 = pw->lsr_id;
1099 }
1100
1101 if (pw->lsr_id.s_addr == INADDR_ANY || pw->pwid == 0)
1102 continue;
1103 RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
1104 RB_INSERT(l2vpn_pw_head, &l2vpn->pw_tree, pw);
1105 }
1106 }
1107 }
1108
1109 static void
1110 ldp_config_reset(struct ldpd_conf *conf)
1111 {
1112 ldp_config_reset_main(conf);
1113 ldp_config_reset_l2vpns(conf);
1114 }
1115
1116 static void
1117 ldp_config_reset_main(struct ldpd_conf *conf)
1118 {
1119 struct iface *iface;
1120 struct nbr_params *nbrp;
1121
1122 while (!RB_EMPTY(iface_head, &conf->iface_tree)) {
1123 iface = RB_ROOT(iface_head, &conf->iface_tree);
1124
1125 QOBJ_UNREG(iface);
1126 RB_REMOVE(iface_head, &conf->iface_tree, iface);
1127 free(iface);
1128 }
1129
1130 while (!RB_EMPTY(nbrp_head, &conf->nbrp_tree)) {
1131 nbrp = RB_ROOT(nbrp_head, &conf->nbrp_tree);
1132
1133 QOBJ_UNREG(nbrp);
1134 RB_REMOVE(nbrp_head, &conf->nbrp_tree, nbrp);
1135 free(nbrp);
1136 }
1137
1138 conf->rtr_id.s_addr = INADDR_ANY;
1139 ldp_config_reset_af(conf, AF_INET);
1140 ldp_config_reset_af(conf, AF_INET6);
1141 conf->lhello_holdtime = LINK_DFLT_HOLDTIME;
1142 conf->lhello_interval = DEFAULT_HELLO_INTERVAL;
1143 conf->thello_holdtime = TARGETED_DFLT_HOLDTIME;
1144 conf->thello_interval = DEFAULT_HELLO_INTERVAL;
1145 conf->trans_pref = DUAL_STACK_LDPOV6;
1146 conf->flags = 0;
1147 }
1148
1149 static void
1150 ldp_config_reset_af(struct ldpd_conf *conf, int af)
1151 {
1152 struct ldpd_af_conf *af_conf;
1153 struct iface *iface;
1154 struct iface_af *ia;
1155 struct tnbr *tnbr, *ttmp;
1156
1157 RB_FOREACH(iface, iface_head, &conf->iface_tree) {
1158 ia = iface_af_get(iface, af);
1159 ia->enabled = 0;
1160 }
1161
1162 RB_FOREACH_SAFE(tnbr, tnbr_head, &conf->tnbr_tree, ttmp) {
1163 if (tnbr->af != af)
1164 continue;
1165
1166 QOBJ_UNREG(tnbr);
1167 RB_REMOVE(tnbr_head, &conf->tnbr_tree, tnbr);
1168 free(tnbr);
1169 }
1170
1171 af_conf = ldp_af_conf_get(conf, af);
1172 af_conf->keepalive = 180;
1173 af_conf->lhello_holdtime = 0;
1174 af_conf->lhello_interval = 0;
1175 af_conf->thello_holdtime = 0;
1176 af_conf->thello_interval = 0;
1177 memset(&af_conf->trans_addr, 0, sizeof(af_conf->trans_addr));
1178 af_conf->flags = 0;
1179 }
1180
1181 static void
1182 ldp_config_reset_l2vpns(struct ldpd_conf *conf)
1183 {
1184 struct l2vpn *l2vpn;
1185 struct l2vpn_if *lif;
1186 struct l2vpn_pw *pw;
1187
1188 while (!RB_EMPTY(l2vpn_head, &conf->l2vpn_tree)) {
1189 l2vpn = RB_ROOT(l2vpn_head, &conf->l2vpn_tree);
1190 while (!RB_EMPTY(l2vpn_if_head, &l2vpn->if_tree)) {
1191 lif = RB_ROOT(l2vpn_if_head, &l2vpn->if_tree);
1192
1193 QOBJ_UNREG(lif);
1194 RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif);
1195 free(lif);
1196 }
1197 while (!RB_EMPTY(l2vpn_pw_head, &l2vpn->pw_tree)) {
1198 pw = RB_ROOT(l2vpn_pw_head, &l2vpn->pw_tree);
1199
1200 QOBJ_UNREG(pw);
1201 RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw);
1202 free(pw);
1203 }
1204 while (!RB_EMPTY(l2vpn_pw_head, &l2vpn->pw_inactive_tree)) {
1205 pw = RB_ROOT(l2vpn_pw_head, &l2vpn->pw_inactive_tree);
1206
1207 QOBJ_UNREG(pw);
1208 RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
1209 free(pw);
1210 }
1211 QOBJ_UNREG(l2vpn);
1212 RB_REMOVE(l2vpn_head, &conf->l2vpn_tree, l2vpn);
1213 free(l2vpn);
1214 }
1215 }
1216
1217 void
1218 ldp_clear_config(struct ldpd_conf *xconf)
1219 {
1220 struct iface *iface;
1221 struct tnbr *tnbr;
1222 struct nbr_params *nbrp;
1223 struct l2vpn *l2vpn;
1224
1225 while (!RB_EMPTY(iface_head, &xconf->iface_tree)) {
1226 iface = RB_ROOT(iface_head, &xconf->iface_tree);
1227
1228 RB_REMOVE(iface_head, &xconf->iface_tree, iface);
1229 free(iface);
1230 }
1231 while (!RB_EMPTY(tnbr_head, &xconf->tnbr_tree)) {
1232 tnbr = RB_ROOT(tnbr_head, &xconf->tnbr_tree);
1233
1234 RB_REMOVE(tnbr_head, &xconf->tnbr_tree, tnbr);
1235 free(tnbr);
1236 }
1237 while (!RB_EMPTY(nbrp_head, &xconf->nbrp_tree)) {
1238 nbrp = RB_ROOT(nbrp_head, &xconf->nbrp_tree);
1239
1240 RB_REMOVE(nbrp_head, &xconf->nbrp_tree, nbrp);
1241 free(nbrp);
1242 }
1243 while (!RB_EMPTY(l2vpn_head, &xconf->l2vpn_tree)) {
1244 l2vpn = RB_ROOT(l2vpn_head, &xconf->l2vpn_tree);
1245
1246 RB_REMOVE(l2vpn_head, &xconf->l2vpn_tree, l2vpn);
1247 l2vpn_del(l2vpn);
1248 }
1249
1250 free(xconf);
1251 }
1252
1253 #define COPY(a, b) do { \
1254 a = malloc(sizeof(*a)); \
1255 if (a == NULL) \
1256 fatal(__func__); \
1257 *a = *b; \
1258 } while (0)
1259
1260 void
1261 merge_config(struct ldpd_conf *conf, struct ldpd_conf *xconf)
1262 {
1263 merge_global(conf, xconf);
1264 merge_af(AF_INET, &conf->ipv4, &xconf->ipv4);
1265 merge_af(AF_INET6, &conf->ipv6, &xconf->ipv6);
1266 merge_ifaces(conf, xconf);
1267 merge_tnbrs(conf, xconf);
1268 merge_nbrps(conf, xconf);
1269 merge_l2vpns(conf, xconf);
1270 }
1271
1272 static void
1273 merge_global(struct ldpd_conf *conf, struct ldpd_conf *xconf)
1274 {
1275 /* change of router-id requires resetting all neighborships */
1276 if (conf->rtr_id.s_addr != xconf->rtr_id.s_addr) {
1277 if (ldpd_process == PROC_LDP_ENGINE) {
1278 ldpe_reset_nbrs(AF_UNSPEC);
1279 if (conf->rtr_id.s_addr == INADDR_ANY ||
1280 xconf->rtr_id.s_addr == INADDR_ANY) {
1281 if_update_all(AF_UNSPEC);
1282 tnbr_update_all(AF_UNSPEC);
1283 }
1284 }
1285 conf->rtr_id = xconf->rtr_id;
1286 }
1287
1288 conf->lhello_holdtime = xconf->lhello_holdtime;
1289 conf->lhello_interval = xconf->lhello_interval;
1290 conf->thello_holdtime = xconf->thello_holdtime;
1291 conf->thello_interval = xconf->thello_interval;
1292
1293 if (conf->trans_pref != xconf->trans_pref) {
1294 if (ldpd_process == PROC_LDP_ENGINE)
1295 ldpe_reset_ds_nbrs();
1296 conf->trans_pref = xconf->trans_pref;
1297 }
1298
1299 if ((conf->flags & F_LDPD_DS_CISCO_INTEROP) !=
1300 (xconf->flags & F_LDPD_DS_CISCO_INTEROP)) {
1301 if (ldpd_process == PROC_LDP_ENGINE)
1302 ldpe_reset_ds_nbrs();
1303 }
1304
1305 conf->flags = xconf->flags;
1306 }
1307
1308 static void
1309 merge_af(int af, struct ldpd_af_conf *af_conf, struct ldpd_af_conf *xa)
1310 {
1311 int stop_init_backoff = 0;
1312 int remove_dynamic_tnbrs = 0;
1313 int change_egress_label = 0;
1314 int reset_nbrs_ipv4 = 0;
1315 int reset_nbrs = 0;
1316 int update_sockets = 0;
1317
1318 /* update timers */
1319 if (af_conf->keepalive != xa->keepalive) {
1320 af_conf->keepalive = xa->keepalive;
1321 stop_init_backoff = 1;
1322 }
1323 af_conf->lhello_holdtime = xa->lhello_holdtime;
1324 af_conf->lhello_interval = xa->lhello_interval;
1325 af_conf->thello_holdtime = xa->thello_holdtime;
1326 af_conf->thello_interval = xa->thello_interval;
1327
1328 /* update flags */
1329 if ((af_conf->flags & F_LDPD_AF_THELLO_ACCEPT) &&
1330 !(xa->flags & F_LDPD_AF_THELLO_ACCEPT))
1331 remove_dynamic_tnbrs = 1;
1332 if ((af_conf->flags & F_LDPD_AF_NO_GTSM) !=
1333 (xa->flags & F_LDPD_AF_NO_GTSM)) {
1334 if (af == AF_INET6)
1335 /* need to set/unset IPV6_MINHOPCOUNT */
1336 update_sockets = 1;
1337 else
1338 /* for LDPv4 just resetting the neighbors is enough */
1339 reset_nbrs_ipv4 = 1;
1340 }
1341 if ((af_conf->flags & F_LDPD_AF_EXPNULL) !=
1342 (xa->flags & F_LDPD_AF_EXPNULL))
1343 change_egress_label = 1;
1344 af_conf->flags = xa->flags;
1345
1346 /* update the transport address */
1347 if (ldp_addrcmp(af, &af_conf->trans_addr, &xa->trans_addr)) {
1348 af_conf->trans_addr = xa->trans_addr;
1349 update_sockets = 1;
1350 }
1351
1352 /* update ACLs */
1353 if (strcmp(af_conf->acl_label_advertise_to,
1354 xa->acl_label_advertise_to) ||
1355 strcmp(af_conf->acl_label_advertise_for,
1356 xa->acl_label_advertise_for) ||
1357 strcmp(af_conf->acl_label_accept_from,
1358 xa->acl_label_accept_from) ||
1359 strcmp(af_conf->acl_label_accept_for,
1360 xa->acl_label_accept_for))
1361 reset_nbrs = 1;
1362 if (strcmp(af_conf->acl_thello_accept_from, xa->acl_thello_accept_from))
1363 remove_dynamic_tnbrs = 1;
1364 if (strcmp(af_conf->acl_label_expnull_for, xa->acl_label_expnull_for))
1365 change_egress_label = 1;
1366 strlcpy(af_conf->acl_thello_accept_from, xa->acl_thello_accept_from,
1367 sizeof(af_conf->acl_thello_accept_from));
1368 strlcpy(af_conf->acl_label_allocate_for, xa->acl_label_allocate_for,
1369 sizeof(af_conf->acl_label_allocate_for));
1370 strlcpy(af_conf->acl_label_advertise_to, xa->acl_label_advertise_to,
1371 sizeof(af_conf->acl_label_advertise_to));
1372 strlcpy(af_conf->acl_label_advertise_for, xa->acl_label_advertise_for,
1373 sizeof(af_conf->acl_label_advertise_for));
1374 strlcpy(af_conf->acl_label_accept_from, xa->acl_label_accept_from,
1375 sizeof(af_conf->acl_label_accept_from));
1376 strlcpy(af_conf->acl_label_accept_for, xa->acl_label_accept_for,
1377 sizeof(af_conf->acl_label_accept_for));
1378 strlcpy(af_conf->acl_label_expnull_for, xa->acl_label_expnull_for,
1379 sizeof(af_conf->acl_label_expnull_for));
1380
1381 /* apply the new configuration */
1382 switch (ldpd_process) {
1383 case PROC_LDE_ENGINE:
1384 if (change_egress_label)
1385 lde_change_egress_label(af);
1386 break;
1387 case PROC_LDP_ENGINE:
1388 if (stop_init_backoff)
1389 ldpe_stop_init_backoff(af);
1390 if (remove_dynamic_tnbrs)
1391 ldpe_remove_dynamic_tnbrs(af);
1392 if (reset_nbrs)
1393 ldpe_reset_nbrs(AF_UNSPEC);
1394 else if (reset_nbrs_ipv4)
1395 ldpe_reset_nbrs(AF_INET);
1396 break;
1397 case PROC_MAIN:
1398 if (update_sockets && iev_ldpe)
1399 imsg_compose_event(iev_ldpe, IMSG_CLOSE_SOCKETS, af,
1400 0, -1, NULL, 0);
1401 break;
1402 }
1403 }
1404
1405 static void
1406 merge_ifaces(struct ldpd_conf *conf, struct ldpd_conf *xconf)
1407 {
1408 struct iface *iface, *itmp, *xi;
1409
1410 RB_FOREACH_SAFE(iface, iface_head, &conf->iface_tree, itmp) {
1411 /* find deleted interfaces */
1412 if (if_lookup_name(xconf, iface->name) == NULL) {
1413 switch (ldpd_process) {
1414 case PROC_LDP_ENGINE:
1415 ldpe_if_exit(iface);
1416 break;
1417 case PROC_LDE_ENGINE:
1418 case PROC_MAIN:
1419 break;
1420 }
1421 RB_REMOVE(iface_head, &conf->iface_tree, iface);
1422 free(iface);
1423 }
1424 }
1425 RB_FOREACH_SAFE(xi, iface_head, &xconf->iface_tree, itmp) {
1426 /* find new interfaces */
1427 if ((iface = if_lookup_name(conf, xi->name)) == NULL) {
1428 COPY(iface, xi);
1429 RB_INSERT(iface_head, &conf->iface_tree, iface);
1430
1431 switch (ldpd_process) {
1432 case PROC_LDP_ENGINE:
1433 ldpe_if_init(iface);
1434 break;
1435 case PROC_LDE_ENGINE:
1436 break;
1437 case PROC_MAIN:
1438 /* resend addresses to activate new interfaces */
1439 kif_redistribute(iface->name);
1440 break;
1441 }
1442 continue;
1443 }
1444
1445 /* update existing interfaces */
1446 merge_iface_af(&iface->ipv4, &xi->ipv4);
1447 merge_iface_af(&iface->ipv6, &xi->ipv6);
1448 }
1449 }
1450
1451 static void
1452 merge_iface_af(struct iface_af *ia, struct iface_af *xi)
1453 {
1454 if (ia->enabled != xi->enabled) {
1455 ia->enabled = xi->enabled;
1456 if (ldpd_process == PROC_LDP_ENGINE)
1457 ldp_if_update(ia->iface, ia->af);
1458 }
1459 ia->hello_holdtime = xi->hello_holdtime;
1460 ia->hello_interval = xi->hello_interval;
1461 }
1462
1463 static void
1464 merge_tnbrs(struct ldpd_conf *conf, struct ldpd_conf *xconf)
1465 {
1466 struct tnbr *tnbr, *ttmp, *xt;
1467
1468 RB_FOREACH_SAFE(tnbr, tnbr_head, &conf->tnbr_tree, ttmp) {
1469 if (!(tnbr->flags & F_TNBR_CONFIGURED))
1470 continue;
1471
1472 /* find deleted tnbrs */
1473 if (tnbr_find(xconf, tnbr->af, &tnbr->addr) == NULL) {
1474 switch (ldpd_process) {
1475 case PROC_LDP_ENGINE:
1476 tnbr->flags &= ~F_TNBR_CONFIGURED;
1477 tnbr_check(conf, tnbr);
1478 break;
1479 case PROC_LDE_ENGINE:
1480 case PROC_MAIN:
1481 RB_REMOVE(tnbr_head, &conf->tnbr_tree, tnbr);
1482 free(tnbr);
1483 break;
1484 }
1485 }
1486 }
1487 RB_FOREACH_SAFE(xt, tnbr_head, &xconf->tnbr_tree, ttmp) {
1488 /* find new tnbrs */
1489 if ((tnbr = tnbr_find(conf, xt->af, &xt->addr)) == NULL) {
1490 COPY(tnbr, xt);
1491 RB_INSERT(tnbr_head, &conf->tnbr_tree, tnbr);
1492
1493 switch (ldpd_process) {
1494 case PROC_LDP_ENGINE:
1495 tnbr_update(tnbr);
1496 break;
1497 case PROC_LDE_ENGINE:
1498 case PROC_MAIN:
1499 break;
1500 }
1501 continue;
1502 }
1503
1504 /* update existing tnbrs */
1505 if (!(tnbr->flags & F_TNBR_CONFIGURED))
1506 tnbr->flags |= F_TNBR_CONFIGURED;
1507 }
1508 }
1509
1510 static void
1511 merge_nbrps(struct ldpd_conf *conf, struct ldpd_conf *xconf)
1512 {
1513 struct nbr_params *nbrp, *ntmp, *xn;
1514 struct nbr *nbr;
1515 int nbrp_changed;
1516
1517 RB_FOREACH_SAFE(nbrp, nbrp_head, &conf->nbrp_tree, ntmp) {
1518 /* find deleted nbrps */
1519 if (nbr_params_find(xconf, nbrp->lsr_id) != NULL)
1520 continue;
1521
1522 switch (ldpd_process) {
1523 case PROC_LDP_ENGINE:
1524 nbr = nbr_find_ldpid(nbrp->lsr_id.s_addr);
1525 if (nbr) {
1526 session_shutdown(nbr, S_SHUTDOWN, 0, 0);
1527 #ifdef __OpenBSD__
1528 pfkey_remove(nbr);
1529 #else
1530 sock_set_md5sig(
1531 (ldp_af_global_get(&global, nbr->af))
1532 ->ldp_session_socket,
1533 nbr->af, &nbr->raddr, NULL);
1534 #endif
1535 nbr->auth.method = AUTH_NONE;
1536 if (nbr_session_active_role(nbr))
1537 nbr_establish_connection(nbr);
1538 }
1539 break;
1540 case PROC_LDE_ENGINE:
1541 case PROC_MAIN:
1542 break;
1543 }
1544 RB_REMOVE(nbrp_head, &conf->nbrp_tree, nbrp);
1545 free(nbrp);
1546 }
1547
1548 RB_FOREACH_SAFE(xn, nbrp_head, &xconf->nbrp_tree, ntmp) {
1549 /* find new nbrps */
1550 if ((nbrp = nbr_params_find(conf, xn->lsr_id)) == NULL) {
1551 COPY(nbrp, xn);
1552 RB_INSERT(nbrp_head, &conf->nbrp_tree, nbrp);
1553
1554 switch (ldpd_process) {
1555 case PROC_LDP_ENGINE:
1556 nbr = nbr_find_ldpid(nbrp->lsr_id.s_addr);
1557 if (nbr) {
1558 session_shutdown(nbr, S_SHUTDOWN, 0, 0);
1559 nbr->auth.method = nbrp->auth.method;
1560 #ifdef __OpenBSD__
1561 if (pfkey_establish(nbr, nbrp) == -1)
1562 fatalx("pfkey setup failed");
1563 #else
1564 sock_set_md5sig(
1565 (ldp_af_global_get(&global,
1566 nbr->af))->ldp_session_socket,
1567 nbr->af, &nbr->raddr,
1568 nbrp->auth.md5key);
1569 #endif
1570 if (nbr_session_active_role(nbr))
1571 nbr_establish_connection(nbr);
1572 }
1573 break;
1574 case PROC_LDE_ENGINE:
1575 case PROC_MAIN:
1576 break;
1577 }
1578 continue;
1579 }
1580
1581 /* update existing nbrps */
1582 if (nbrp->flags != xn->flags ||
1583 nbrp->keepalive != xn->keepalive ||
1584 nbrp->gtsm_enabled != xn->gtsm_enabled ||
1585 nbrp->gtsm_hops != xn->gtsm_hops ||
1586 nbrp->auth.method != xn->auth.method ||
1587 strcmp(nbrp->auth.md5key, xn->auth.md5key) != 0)
1588 nbrp_changed = 1;
1589 else
1590 nbrp_changed = 0;
1591
1592 nbrp->keepalive = xn->keepalive;
1593 nbrp->gtsm_enabled = xn->gtsm_enabled;
1594 nbrp->gtsm_hops = xn->gtsm_hops;
1595 nbrp->auth.method = xn->auth.method;
1596 strlcpy(nbrp->auth.md5key, xn->auth.md5key,
1597 sizeof(nbrp->auth.md5key));
1598 nbrp->auth.md5key_len = xn->auth.md5key_len;
1599 nbrp->flags = xn->flags;
1600
1601 if (ldpd_process == PROC_LDP_ENGINE) {
1602 nbr = nbr_find_ldpid(nbrp->lsr_id.s_addr);
1603 if (nbr && nbrp_changed) {
1604 session_shutdown(nbr, S_SHUTDOWN, 0, 0);
1605 #ifdef __OpenBSD__
1606 pfkey_remove(nbr);
1607 nbr->auth.method = nbrp->auth.method;
1608 if (pfkey_establish(nbr, nbrp) == -1)
1609 fatalx("pfkey setup failed");
1610 #else
1611 nbr->auth.method = nbrp->auth.method;
1612 sock_set_md5sig((ldp_af_global_get(&global,
1613 nbr->af))->ldp_session_socket, nbr->af,
1614 &nbr->raddr, nbrp->auth.md5key);
1615 #endif
1616 if (nbr_session_active_role(nbr))
1617 nbr_establish_connection(nbr);
1618 }
1619 }
1620 }
1621 }
1622
1623 static void
1624 merge_l2vpns(struct ldpd_conf *conf, struct ldpd_conf *xconf)
1625 {
1626 struct l2vpn *l2vpn, *ltmp, *xl;
1627
1628 RB_FOREACH_SAFE(l2vpn, l2vpn_head, &conf->l2vpn_tree, ltmp) {
1629 /* find deleted l2vpns */
1630 if (l2vpn_find(xconf, l2vpn->name) == NULL) {
1631 switch (ldpd_process) {
1632 case PROC_LDE_ENGINE:
1633 l2vpn_exit(l2vpn);
1634 break;
1635 case PROC_LDP_ENGINE:
1636 ldpe_l2vpn_exit(l2vpn);
1637 break;
1638 case PROC_MAIN:
1639 break;
1640 }
1641 RB_REMOVE(l2vpn_head, &conf->l2vpn_tree, l2vpn);
1642 l2vpn_del(l2vpn);
1643 }
1644 }
1645 RB_FOREACH_SAFE(xl, l2vpn_head, &xconf->l2vpn_tree, ltmp) {
1646 /* find new l2vpns */
1647 if ((l2vpn = l2vpn_find(conf, xl->name)) == NULL) {
1648 COPY(l2vpn, xl);
1649 RB_INSERT(l2vpn_head, &conf->l2vpn_tree, l2vpn);
1650 RB_INIT(l2vpn_if_head, &l2vpn->if_tree);
1651 RB_INIT(l2vpn_pw_head, &l2vpn->pw_tree);
1652 RB_INIT(l2vpn_pw_head, &l2vpn->pw_inactive_tree);
1653
1654 switch (ldpd_process) {
1655 case PROC_LDE_ENGINE:
1656 l2vpn_init(l2vpn);
1657 break;
1658 case PROC_LDP_ENGINE:
1659 ldpe_l2vpn_init(l2vpn);
1660 break;
1661 case PROC_MAIN:
1662 break;
1663 }
1664 }
1665
1666 /* update existing l2vpns */
1667 merge_l2vpn(conf, l2vpn, xl);
1668 }
1669 }
1670
1671 static void
1672 merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl)
1673 {
1674 struct l2vpn_if *lif, *ftmp, *xf;
1675 struct l2vpn_pw *pw, *ptmp, *xp;
1676 struct nbr *nbr;
1677 int reset_nbr, reinstall_pwfec, reinstall_tnbr;
1678 int previous_pw_type, previous_mtu;
1679
1680 previous_pw_type = l2vpn->pw_type;
1681 previous_mtu = l2vpn->mtu;
1682
1683 /* merge intefaces */
1684 RB_FOREACH_SAFE(lif, l2vpn_if_head, &l2vpn->if_tree, ftmp) {
1685 /* find deleted interfaces */
1686 if (l2vpn_if_find(xl, lif->ifname) == NULL) {
1687 RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif);
1688 free(lif);
1689 }
1690 }
1691 RB_FOREACH_SAFE(xf, l2vpn_if_head, &xl->if_tree, ftmp) {
1692 /* find new interfaces */
1693 if (l2vpn_if_find(l2vpn, xf->ifname) == NULL) {
1694 COPY(lif, xf);
1695 RB_INSERT(l2vpn_if_head, &l2vpn->if_tree, lif);
1696 lif->l2vpn = l2vpn;
1697
1698 switch (ldpd_process) {
1699 case PROC_LDP_ENGINE:
1700 case PROC_LDE_ENGINE:
1701 break;
1702 case PROC_MAIN:
1703 kif_redistribute(lif->ifname);
1704 break;
1705 }
1706 }
1707 }
1708
1709 /* merge active pseudowires */
1710 RB_FOREACH_SAFE(pw, l2vpn_pw_head, &l2vpn->pw_tree, ptmp) {
1711 /* find deleted active pseudowires */
1712 if (l2vpn_pw_find_active(xl, pw->ifname) == NULL) {
1713 switch (ldpd_process) {
1714 case PROC_LDE_ENGINE:
1715 l2vpn_pw_exit(pw);
1716 break;
1717 case PROC_LDP_ENGINE:
1718 ldpe_l2vpn_pw_exit(pw);
1719 break;
1720 case PROC_MAIN:
1721 break;
1722 }
1723
1724 RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw);
1725 free(pw);
1726 }
1727 }
1728 RB_FOREACH_SAFE(xp, l2vpn_pw_head, &xl->pw_tree, ptmp) {
1729 /* find new active pseudowires */
1730 if ((pw = l2vpn_pw_find_active(l2vpn, xp->ifname)) == NULL) {
1731 COPY(pw, xp);
1732 RB_INSERT(l2vpn_pw_head, &l2vpn->pw_tree, pw);
1733 pw->l2vpn = l2vpn;
1734
1735 switch (ldpd_process) {
1736 case PROC_LDE_ENGINE:
1737 l2vpn_pw_init(pw);
1738 break;
1739 case PROC_LDP_ENGINE:
1740 ldpe_l2vpn_pw_init(pw);
1741 break;
1742 case PROC_MAIN:
1743 kif_redistribute(pw->ifname);
1744 break;
1745 }
1746 continue;
1747 }
1748
1749 /* update existing active pseudowire */
1750 if (pw->af != xp->af ||
1751 ldp_addrcmp(pw->af, &pw->addr, &xp->addr))
1752 reinstall_tnbr = 1;
1753 else
1754 reinstall_tnbr = 0;
1755
1756 /* changes that require a session restart */
1757 if ((pw->flags & (F_PW_STATUSTLV_CONF|F_PW_CWORD_CONF)) !=
1758 (xp->flags & (F_PW_STATUSTLV_CONF|F_PW_CWORD_CONF)))
1759 reset_nbr = 1;
1760 else
1761 reset_nbr = 0;
1762
1763 if (l2vpn->pw_type != xl->pw_type || l2vpn->mtu != xl->mtu ||
1764 pw->pwid != xp->pwid || reinstall_tnbr || reset_nbr ||
1765 pw->lsr_id.s_addr != xp->lsr_id.s_addr)
1766 reinstall_pwfec = 1;
1767 else
1768 reinstall_pwfec = 0;
1769
1770 if (ldpd_process == PROC_LDP_ENGINE) {
1771 if (reinstall_tnbr)
1772 ldpe_l2vpn_pw_exit(pw);
1773 if (reset_nbr) {
1774 nbr = nbr_find_ldpid(pw->lsr_id.s_addr);
1775 if (nbr && nbr->state == NBR_STA_OPER)
1776 session_shutdown(nbr, S_SHUTDOWN, 0, 0);
1777 }
1778 }
1779 if (ldpd_process == PROC_LDE_ENGINE && reinstall_pwfec)
1780 l2vpn_pw_exit(pw);
1781 pw->lsr_id = xp->lsr_id;
1782 pw->af = xp->af;
1783 pw->addr = xp->addr;
1784 pw->pwid = xp->pwid;
1785 strlcpy(pw->ifname, xp->ifname, sizeof(pw->ifname));
1786 pw->ifindex = xp->ifindex;
1787 if (xp->flags & F_PW_CWORD_CONF)
1788 pw->flags |= F_PW_CWORD_CONF;
1789 else
1790 pw->flags &= ~F_PW_CWORD_CONF;
1791 if (xp->flags & F_PW_STATUSTLV_CONF)
1792 pw->flags |= F_PW_STATUSTLV_CONF;
1793 else
1794 pw->flags &= ~F_PW_STATUSTLV_CONF;
1795 if (xp->flags & F_PW_STATIC_NBR_ADDR)
1796 pw->flags |= F_PW_STATIC_NBR_ADDR;
1797 else
1798 pw->flags &= ~F_PW_STATIC_NBR_ADDR;
1799 if (ldpd_process == PROC_LDP_ENGINE && reinstall_tnbr)
1800 ldpe_l2vpn_pw_init(pw);
1801 if (ldpd_process == PROC_LDE_ENGINE && reinstall_pwfec) {
1802 l2vpn->pw_type = xl->pw_type;
1803 l2vpn->mtu = xl->mtu;
1804 l2vpn_pw_init(pw);
1805 l2vpn->pw_type = previous_pw_type;
1806 l2vpn->mtu = previous_mtu;
1807 }
1808 }
1809
1810 /* merge inactive pseudowires */
1811 RB_FOREACH_SAFE(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree, ptmp) {
1812 /* find deleted inactive pseudowires */
1813 if (l2vpn_pw_find_inactive(xl, pw->ifname) == NULL) {
1814 RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
1815 free(pw);
1816 }
1817 }
1818 RB_FOREACH_SAFE(xp, l2vpn_pw_head, &xl->pw_inactive_tree, ptmp) {
1819 /* find new inactive pseudowires */
1820 if ((pw = l2vpn_pw_find_inactive(l2vpn, xp->ifname)) == NULL) {
1821 COPY(pw, xp);
1822 RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
1823 pw->l2vpn = l2vpn;
1824
1825 switch (ldpd_process) {
1826 case PROC_LDE_ENGINE:
1827 case PROC_LDP_ENGINE:
1828 break;
1829 case PROC_MAIN:
1830 kif_redistribute(pw->ifname);
1831 break;
1832 }
1833 continue;
1834 }
1835
1836 /* update existing inactive pseudowire */
1837 pw->lsr_id.s_addr = xp->lsr_id.s_addr;
1838 pw->af = xp->af;
1839 pw->addr = xp->addr;
1840 pw->pwid = xp->pwid;
1841 strlcpy(pw->ifname, xp->ifname, sizeof(pw->ifname));
1842 pw->ifindex = xp->ifindex;
1843 pw->flags = xp->flags;
1844 }
1845
1846 l2vpn->pw_type = xl->pw_type;
1847 l2vpn->mtu = xl->mtu;
1848 strlcpy(l2vpn->br_ifname, xl->br_ifname, sizeof(l2vpn->br_ifname));
1849 l2vpn->br_ifindex = xl->br_ifindex;
1850 }
1851
1852 struct ldpd_conf *
1853 config_new_empty(void)
1854 {
1855 struct ldpd_conf *xconf;
1856
1857 xconf = calloc(1, sizeof(*xconf));
1858 if (xconf == NULL)
1859 fatal(NULL);
1860
1861 RB_INIT(iface_head, &xconf->iface_tree);
1862 RB_INIT(tnbr_head, &xconf->tnbr_tree);
1863 RB_INIT(nbrp_head, &xconf->nbrp_tree);
1864 RB_INIT(l2vpn_head, &xconf->l2vpn_tree);
1865
1866 /* set default values */
1867 ldp_config_reset(xconf);
1868
1869 return (xconf);
1870 }
1871
1872 void
1873 config_clear(struct ldpd_conf *conf)
1874 {
1875 struct ldpd_conf *xconf;
1876
1877 /*
1878 * Merge current config with an empty config, this will deactivate
1879 * and deallocate all the interfaces, pseudowires and so on. Before
1880 * merging, copy the router-id and other variables to avoid some
1881 * unnecessary operations, like trying to reset the neighborships.
1882 */
1883 xconf = config_new_empty();
1884 xconf->ipv4 = conf->ipv4;
1885 xconf->ipv6 = conf->ipv6;
1886 xconf->rtr_id = conf->rtr_id;
1887 xconf->trans_pref = conf->trans_pref;
1888 xconf->flags = conf->flags;
1889 merge_config(conf, xconf);
1890 free(xconf);
1891 free(conf);
1892 }