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