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