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>
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.
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.
30 #include "ldp_debug.h"
32 #include <lib/version.h>
45 static void ldpd_shutdown(void);
46 static pid_t
start_child(enum ldpd_process
, char *, int,
47 const char *, const char *, const char *);
48 static int main_dispatch_ldpe(struct thread
*);
49 static int main_dispatch_lde(struct thread
*);
50 static int main_imsg_send_ipc_sockets(struct imsgbuf
*,
52 static void main_imsg_send_net_sockets(int);
53 static void main_imsg_send_net_socket(int, enum socket_type
);
54 static int main_imsg_send_config(struct ldpd_conf
*);
55 static void ldp_config_normalize(struct ldpd_conf
*, void **);
56 static void ldp_config_reset_main(struct ldpd_conf
*, void **);
57 static void ldp_config_reset_af(struct ldpd_conf
*, int, void **);
58 static void merge_config_ref(struct ldpd_conf
*, struct ldpd_conf
*, void **);
59 static void merge_global(struct ldpd_conf
*, struct ldpd_conf
*);
60 static void merge_af(int, struct ldpd_af_conf
*,
61 struct ldpd_af_conf
*);
62 static void merge_ifaces(struct ldpd_conf
*, struct ldpd_conf
*, void **);
63 static void merge_iface_af(struct iface_af
*, struct iface_af
*);
64 static void merge_tnbrs(struct ldpd_conf
*, struct ldpd_conf
*, void **);
65 static void merge_nbrps(struct ldpd_conf
*, struct ldpd_conf
*, void **);
66 static void merge_l2vpns(struct ldpd_conf
*, struct ldpd_conf
*, void **);
67 static void merge_l2vpn(struct ldpd_conf
*, struct l2vpn
*,
68 struct l2vpn
*, void **);
70 DEFINE_QOBJ_TYPE(iface
)
71 DEFINE_QOBJ_TYPE(tnbr
)
72 DEFINE_QOBJ_TYPE(nbr_params
)
73 DEFINE_QOBJ_TYPE(l2vpn_if
)
74 DEFINE_QOBJ_TYPE(l2vpn_pw
)
75 DEFINE_QOBJ_TYPE(l2vpn
)
76 DEFINE_QOBJ_TYPE(ldpd_conf
)
78 struct ldpd_global global
;
79 struct ldpd_conf
*ldpd_conf
;
81 static struct imsgev
*iev_ldpe
;
82 static struct imsgev
*iev_lde
;
83 static pid_t ldpe_pid
;
86 #define LDP_DEFAULT_CONFIG "ldpd.conf"
87 #define LDP_VTY_PORT 2612
89 /* Master of threads. */
90 struct thread_master
*master
;
92 /* Process ID saved for use by init system */
93 static const char *pid_file
= PATH_LDPD_PID
;
95 /* Configuration filename and directory. */
96 static char config_default
[] = SYSCONFDIR LDP_DEFAULT_CONFIG
;
99 static zebra_capabilities_t _caps_p
[] =
105 struct zebra_privs_t ldpd_privs
=
107 #if defined(FRR_USER) && defined(FRR_GROUP)
111 #if defined(VTY_GROUP)
112 .vty_group
= VTY_GROUP
,
115 .cap_num_p
= array_size(_caps_p
),
119 /* VTY Socket prefix */
120 char vty_sock_path
[MAXPATHLEN
] = LDP_VTYSH_PATH
;
122 /* CTL Socket path */
123 char ctl_sock_path
[MAXPATHLEN
] = LDPD_SOCKET
;
126 #define OPTION_VTYSOCK 1000
127 #define OPTION_CTLSOCK 1001
128 static struct option longopts
[] =
130 { "daemon", no_argument
, NULL
, 'd'},
131 { "config_file", required_argument
, NULL
, 'f'},
132 { "pid_file", required_argument
, NULL
, 'i'},
133 { "socket", required_argument
, NULL
, 'z'},
134 { "dryrun", no_argument
, NULL
, 'C'},
135 { "help", no_argument
, NULL
, 'h'},
136 { "vty_addr", required_argument
, NULL
, 'A'},
137 { "vty_port", required_argument
, NULL
, 'P'},
138 { "vty_socket", required_argument
, NULL
, OPTION_VTYSOCK
},
139 { "ctl_socket", required_argument
, NULL
, OPTION_CTLSOCK
},
140 { "user", required_argument
, NULL
, 'u'},
141 { "group", required_argument
, NULL
, 'g'},
142 { "version", no_argument
, NULL
, 'v'},
146 /* Help information display. */
147 static void __attribute__ ((noreturn
))
148 usage(char *progname
, int status
)
151 fprintf(stderr
, "Try `%s --help' for more information.\n",
154 printf("Usage : %s [OPTION...]\n\
155 Daemon which manages LDP.\n\n\
156 -d, --daemon Runs in daemon mode\n\
157 -f, --config_file Set configuration file name\n\
158 -i, --pid_file Set process identifier file name\n\
159 -z, --socket Set path of zebra socket\n\
160 -A, --vty_addr Set vty's bind address\n\
161 -P, --vty_port Set vty's port number\n\
162 --vty_socket Override vty socket path\n\
163 --ctl_socket Override ctl socket path\n\
164 -u, --user User to run as\n\
165 -g, --group Group to run as\n\
166 -v, --version Print program version\n\
167 -C, --dryrun Check configuration for validity and exit\n\
168 -h, --help Display this help and exit\n\
170 Report bugs to %s\n", progname
, FRR_BUG_ADDRESS
);
176 /* SIGHUP handler. */
180 log_info("SIGHUP received");
183 /* SIGINT / SIGTERM handler. */
187 log_info("SIGINT received");
191 /* SIGUSR1 handler. */
198 static struct quagga_signal_t ldp_signals
[] =
219 main(int argc
, char *argv
[])
222 int lflag
= 0, eflag
= 0;
223 int pipe_parent2ldpe
[2];
224 int pipe_parent2lde
[2];
226 char *vty_addr
= NULL
;
227 int vty_port
= LDP_VTY_PORT
;
228 char *ctl_sock_custom_path
= NULL
;
231 const char *user
= NULL
;
232 const char *group
= NULL
;
233 char *config_file
= NULL
;
235 struct thread thread
;
238 ldpd_process
= PROC_MAIN
;
240 /* Set umask before anything for security */
243 /* get program name */
244 progname
= ((p
= strrchr(argv
[0], '/')) ? ++p
: argv
[0]);
246 saved_argv0
= argv
[0];
247 if (saved_argv0
== NULL
)
248 saved_argv0
= (char *)"ldpd";
253 opt
= getopt_long(argc
, argv
, "df:i:z:hA:P:u:g:vCLE",
266 config_file
= optarg
;
275 zclient_serv_path_set(optarg
);
279 * Deal with atoi() returning 0 on failure, and ldpd
280 * not listening on ldpd port.
282 if (strcmp(optarg
, "0") == 0) {
286 vty_port
= atoi(optarg
);
287 if (vty_port
<= 0 || vty_port
> 0xffff)
288 vty_port
= LDP_VTY_PORT
;
291 set_socket_path(vty_sock_path
, LDP_VTYSH_PATH
, optarg
, sizeof (vty_sock_path
));
294 ctl_sock_name
= strrchr(LDPD_SOCKET
, '/');
300 * LDPD_SOCKET configured as relative path
301 * during config? Should really never happen for
304 ctl_sock_name
= (char *)LDPD_SOCKET
;
305 ctl_sock_custom_path
= optarg
;
306 strlcpy(ctl_sock_path
, ctl_sock_custom_path
,
307 sizeof(ctl_sock_path
));
308 strlcat(ctl_sock_path
, "/", sizeof(ctl_sock_path
));
309 strlcat(ctl_sock_path
, ctl_sock_name
,
310 sizeof(ctl_sock_path
));
319 print_version(progname
);
342 if (argc
> 0 || (lflag
&& eflag
))
345 /* check for root privileges */
346 if (geteuid() != 0) {
352 zlog_default
= openzlog(progname
, ZLOG_LDP
, 0,
353 LOG_CONS
| LOG_NDELAY
| LOG_PID
, LOG_DAEMON
);
358 ldpe(user
, group
, ctl_sock_path
);
360 master
= thread_master_create();
363 vty_config_lockless ();
369 /* Get configuration file. */
370 ldpd_conf
= config_new_empty();
371 ldp_config_reset_main(ldpd_conf
, NULL
);
372 vty_read_config(config_file
, config_default
);
374 /* Start execution only if not in dry-run mode */
378 QOBJ_REG (ldpd_conf
, ldpd_conf
);
380 if (daemon_mode
&& daemon(0, 0) < 0) {
381 log_warn("LDPd daemon failed");
385 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2ldpe
) == -1)
387 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_parent2lde
) == -1)
389 sock_set_nonblock(pipe_parent2ldpe
[0]);
390 sock_set_cloexec(pipe_parent2ldpe
[0]);
391 sock_set_nonblock(pipe_parent2ldpe
[1]);
392 sock_set_cloexec(pipe_parent2ldpe
[1]);
393 sock_set_nonblock(pipe_parent2lde
[0]);
394 sock_set_cloexec(pipe_parent2lde
[0]);
395 sock_set_nonblock(pipe_parent2lde
[1]);
396 sock_set_cloexec(pipe_parent2lde
[1]);
399 lde_pid
= start_child(PROC_LDE_ENGINE
, saved_argv0
,
400 pipe_parent2lde
[1], user
, group
, ctl_sock_custom_path
);
401 ldpe_pid
= start_child(PROC_LDP_ENGINE
, saved_argv0
,
402 pipe_parent2ldpe
[1], user
, group
, ctl_sock_custom_path
);
404 /* drop privileges */
406 ldpd_privs
.user
= user
;
408 ldpd_privs
.group
= group
;
409 zprivs_init(&ldpd_privs
);
411 /* setup signal handler */
412 signal_init(master
, array_size(ldp_signals
), ldp_signals
);
415 ldp_zebra_init(master
);
417 /* setup pipes to children */
418 if ((iev_ldpe
= malloc(sizeof(struct imsgev
))) == NULL
||
419 (iev_lde
= malloc(sizeof(struct imsgev
))) == NULL
)
421 imsg_init(&iev_ldpe
->ibuf
, pipe_parent2ldpe
[0]);
422 iev_ldpe
->handler_read
= main_dispatch_ldpe
;
423 iev_ldpe
->ev_read
= thread_add_read(master
, iev_ldpe
->handler_read
,
424 iev_ldpe
, iev_ldpe
->ibuf
.fd
);
425 iev_ldpe
->handler_write
= ldp_write_handler
;
426 iev_ldpe
->ev_write
= NULL
;
428 imsg_init(&iev_lde
->ibuf
, pipe_parent2lde
[0]);
429 iev_lde
->handler_read
= main_dispatch_lde
;
430 iev_lde
->ev_read
= thread_add_read(master
, iev_lde
->handler_read
,
431 iev_lde
, iev_lde
->ibuf
.fd
);
432 iev_lde
->handler_write
= ldp_write_handler
;
433 iev_lde
->ev_write
= NULL
;
435 if (main_imsg_send_ipc_sockets(&iev_ldpe
->ibuf
, &iev_lde
->ibuf
))
436 fatal("could not establish imsg links");
437 main_imsg_compose_both(IMSG_DEBUG_UPDATE
, &ldp_debug
,
439 main_imsg_send_config(ldpd_conf
);
441 if (ldpd_conf
->ipv4
.flags
& F_LDPD_AF_ENABLED
)
442 main_imsg_send_net_sockets(AF_INET
);
443 if (ldpd_conf
->ipv6
.flags
& F_LDPD_AF_ENABLED
)
444 main_imsg_send_net_sockets(AF_INET6
);
446 /* Process id file create. */
447 pid_output(pid_file
);
449 /* Create VTY socket */
450 vty_serv_sock(vty_addr
, vty_port
, vty_sock_path
);
453 log_notice("LDPd %s starting: vty@%d", FRR_VERSION
, vty_port
);
455 /* Fetch next active thread. */
456 while (thread_fetch(master
, &thread
))
457 thread_call(&thread
);
470 msgbuf_clear(&iev_ldpe
->ibuf
.w
);
471 close(iev_ldpe
->ibuf
.fd
);
472 msgbuf_clear(&iev_lde
->ibuf
.w
);
473 close(iev_lde
->ibuf
.fd
);
475 config_clear(ldpd_conf
);
477 log_debug("waiting for children to terminate");
481 if (errno
!= EINTR
&& errno
!= ECHILD
)
483 } else if (WIFSIGNALED(status
))
484 log_warnx("%s terminated; signal %d",
485 (pid
== lde_pid
) ? "label decision engine" :
486 "ldp engine", WTERMSIG(status
));
487 } while (pid
!= -1 || (pid
== -1 && errno
== EINTR
));
492 log_info("terminating");
497 start_child(enum ldpd_process p
, char *argv0
, int fd
, const char *user
,
498 const char *group
, const char *ctl_sock_custom_path
)
504 switch (pid
= fork()) {
506 fatal("cannot fork");
514 if (dup2(fd
, 3) == -1)
515 fatal("cannot setup imsg fd");
517 argv
[argc
++] = argv0
;
520 fatalx("Can not start main process");
521 case PROC_LDE_ENGINE
:
522 argv
[argc
++] = (char *)"-L";
524 case PROC_LDP_ENGINE
:
525 argv
[argc
++] = (char *)"-E";
529 argv
[argc
++] = (char *)"-u";
530 argv
[argc
++] = (char *)user
;
533 argv
[argc
++] = (char *)"-g";
534 argv
[argc
++] = (char *)group
;
536 if (ctl_sock_custom_path
) {
537 argv
[argc
++] = (char *)"--ctl_socket";
538 argv
[argc
++] = (char *)ctl_sock_custom_path
;
549 main_dispatch_ldpe(struct thread
*thread
)
551 struct imsgev
*iev
= THREAD_ARG(thread
);
552 struct imsgbuf
*ibuf
= &iev
->ibuf
;
560 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
561 fatal("imsg_read error");
562 if (n
== 0) /* connection closed */
566 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
572 switch (imsg
.hdr
.type
) {
574 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
576 case IMSG_REQUEST_SOCKETS
:
578 main_imsg_send_net_sockets(af
);
581 log_debug("%s: error handling imsg %d", __func__
,
590 /* this pipe is dead, so remove the event handlers and exit */
591 THREAD_READ_OFF(iev
->ev_read
);
592 THREAD_WRITE_OFF(iev
->ev_write
);
597 kill(lde_pid
, SIGTERM
);
605 main_dispatch_lde(struct thread
*thread
)
607 struct imsgev
*iev
= THREAD_ARG(thread
);
608 struct imsgbuf
*ibuf
= &iev
->ibuf
;
615 if ((n
= imsg_read(ibuf
)) == -1 && errno
!= EAGAIN
)
616 fatal("imsg_read error");
617 if (n
== 0) /* connection closed */
621 if ((n
= imsg_get(ibuf
, &imsg
)) == -1)
627 switch (imsg
.hdr
.type
) {
629 logit(imsg
.hdr
.pid
, "%s", (const char *)imsg
.data
);
631 case IMSG_KLABEL_CHANGE
:
632 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
633 sizeof(struct kroute
))
634 fatalx("invalid size of IMSG_KLABEL_CHANGE");
635 if (kr_change(imsg
.data
))
636 log_warnx("%s: error changing route", __func__
);
638 case IMSG_KLABEL_DELETE
:
639 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
640 sizeof(struct kroute
))
641 fatalx("invalid size of IMSG_KLABEL_DELETE");
642 if (kr_delete(imsg
.data
))
643 log_warnx("%s: error deleting route", __func__
);
645 case IMSG_KPWLABEL_CHANGE
:
646 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
648 fatalx("invalid size of IMSG_KPWLABEL_CHANGE");
649 if (kmpw_set(imsg
.data
))
650 log_warnx("%s: error changing pseudowire",
653 case IMSG_KPWLABEL_DELETE
:
654 if (imsg
.hdr
.len
- IMSG_HEADER_SIZE
!=
656 fatalx("invalid size of IMSG_KPWLABEL_DELETE");
657 if (kmpw_unset(imsg
.data
))
658 log_warnx("%s: error unsetting pseudowire",
662 log_debug("%s: error handling imsg %d", __func__
,
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
);
678 kill(ldpe_pid
, SIGTERM
);
686 ldp_write_handler(struct thread
*thread
)
688 struct imsgev
*iev
= THREAD_ARG(thread
);
689 struct imsgbuf
*ibuf
= &iev
->ibuf
;
692 iev
->ev_write
= NULL
;
694 if ((n
= msgbuf_write(&ibuf
->w
)) == -1 && errno
!= EAGAIN
)
695 fatal("msgbuf_write");
697 /* this pipe is dead, so remove the event handlers */
698 THREAD_READ_OFF(iev
->ev_read
);
699 THREAD_WRITE_OFF(iev
->ev_write
);
709 main_imsg_compose_ldpe(int type
, pid_t pid
, void *data
, uint16_t datalen
)
711 if (iev_ldpe
== NULL
)
713 imsg_compose_event(iev_ldpe
, type
, 0, pid
, -1, data
, datalen
);
717 main_imsg_compose_lde(int type
, pid_t pid
, void *data
, uint16_t datalen
)
719 imsg_compose_event(iev_lde
, type
, 0, pid
, -1, data
, datalen
);
723 main_imsg_compose_both(enum imsg_type type
, void *buf
, uint16_t len
)
725 if (iev_ldpe
== NULL
|| iev_lde
== NULL
)
727 if (imsg_compose_event(iev_ldpe
, type
, 0, 0, -1, buf
, len
) == -1)
729 if (imsg_compose_event(iev_lde
, type
, 0, 0, -1, buf
, len
) == -1)
735 imsg_event_add(struct imsgev
*iev
)
737 THREAD_READ_ON(master
, iev
->ev_read
, iev
->handler_read
, iev
,
740 if (iev
->ibuf
.w
.queued
)
741 THREAD_WRITE_ON(master
, iev
->ev_write
, iev
->handler_write
, iev
,
746 imsg_compose_event(struct imsgev
*iev
, uint16_t type
, uint32_t peerid
,
747 pid_t pid
, int fd
, void *data
, uint16_t datalen
)
751 if ((ret
= imsg_compose(&iev
->ibuf
, type
, peerid
,
752 pid
, fd
, data
, datalen
)) != -1)
758 evbuf_enqueue(struct evbuf
*eb
, struct ibuf
*buf
)
760 ibuf_close(&eb
->wbuf
, buf
);
765 evbuf_event_add(struct evbuf
*eb
)
768 THREAD_WRITE_ON(master
, eb
->ev
, eb
->handler
, eb
->arg
,
773 evbuf_init(struct evbuf
*eb
, int fd
, int (*handler
)(struct thread
*),
776 msgbuf_init(&eb
->wbuf
);
778 eb
->handler
= handler
;
783 evbuf_clear(struct evbuf
*eb
)
785 THREAD_WRITE_OFF(eb
->ev
);
786 msgbuf_clear(&eb
->wbuf
);
791 main_imsg_send_ipc_sockets(struct imsgbuf
*ldpe_buf
, struct imsgbuf
*lde_buf
)
793 int pipe_ldpe2lde
[2];
795 if (socketpair(AF_UNIX
, SOCK_STREAM
, PF_UNSPEC
, pipe_ldpe2lde
) == -1)
797 sock_set_nonblock(pipe_ldpe2lde
[0]);
798 sock_set_nonblock(pipe_ldpe2lde
[1]);
800 if (imsg_compose(ldpe_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[0],
803 if (imsg_compose(lde_buf
, IMSG_SOCKET_IPC
, 0, 0, pipe_ldpe2lde
[1],
811 main_imsg_send_net_sockets(int af
)
813 if (!ldp_addrisset(af
, &(ldp_af_conf_get(ldpd_conf
, af
))->trans_addr
))
816 main_imsg_send_net_socket(af
, LDP_SOCKET_DISC
);
817 main_imsg_send_net_socket(af
, LDP_SOCKET_EDISC
);
818 main_imsg_send_net_socket(af
, LDP_SOCKET_SESSION
);
819 imsg_compose_event(iev_ldpe
, IMSG_SETUP_SOCKETS
, af
, 0, -1, NULL
, 0);
823 main_imsg_send_net_socket(int af
, enum socket_type type
)
827 fd
= ldp_create_socket(af
, type
);
829 log_warnx("%s: failed to create %s socket for address-family "
830 "%s", __func__
, socket_name(type
), af_name(af
));
834 imsg_compose_event(iev_ldpe
, IMSG_SOCKET_NET
, af
, 0, fd
, &type
,
838 struct ldpd_af_conf
*
839 ldp_af_conf_get(struct ldpd_conf
*xconf
, int af
)
843 return (&xconf
->ipv4
);
845 return (&xconf
->ipv6
);
847 fatalx("ldp_af_conf_get: unknown af");
851 struct ldpd_af_global
*
852 ldp_af_global_get(struct ldpd_global
*xglobal
, int af
)
856 return (&xglobal
->ipv4
);
858 return (&xglobal
->ipv6
);
860 fatalx("ldp_af_global_get: unknown af");
865 ldp_is_dual_stack(struct ldpd_conf
*xconf
)
867 return ((xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
) &&
868 (xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
));
872 ldp_rtr_id_get(struct ldpd_conf
*xconf
)
874 if (xconf
->rtr_id
.s_addr
!= INADDR_ANY
)
875 return (xconf
->rtr_id
.s_addr
);
877 return (global
.rtr_id
.s_addr
);
881 main_imsg_send_config(struct ldpd_conf
*xconf
)
885 struct nbr_params
*nbrp
;
887 struct l2vpn_if
*lif
;
890 if (main_imsg_compose_both(IMSG_RECONF_CONF
, xconf
,
891 sizeof(*xconf
)) == -1)
894 LIST_FOREACH(iface
, &xconf
->iface_list
, entry
) {
895 if (main_imsg_compose_both(IMSG_RECONF_IFACE
, iface
,
896 sizeof(*iface
)) == -1)
900 LIST_FOREACH(tnbr
, &xconf
->tnbr_list
, entry
) {
901 if (main_imsg_compose_both(IMSG_RECONF_TNBR
, tnbr
,
902 sizeof(*tnbr
)) == -1)
906 LIST_FOREACH(nbrp
, &xconf
->nbrp_list
, entry
) {
907 if (main_imsg_compose_both(IMSG_RECONF_NBRP
, nbrp
,
908 sizeof(*nbrp
)) == -1)
912 LIST_FOREACH(l2vpn
, &xconf
->l2vpn_list
, entry
) {
913 if (main_imsg_compose_both(IMSG_RECONF_L2VPN
, l2vpn
,
914 sizeof(*l2vpn
)) == -1)
917 LIST_FOREACH(lif
, &l2vpn
->if_list
, entry
) {
918 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF
, lif
,
922 LIST_FOREACH(pw
, &l2vpn
->pw_list
, entry
) {
923 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW
, pw
,
927 LIST_FOREACH(pw
, &l2vpn
->pw_inactive_list
, entry
) {
928 if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW
, pw
,
934 if (main_imsg_compose_both(IMSG_RECONF_END
, NULL
, 0) == -1)
941 ldp_reload_ref(struct ldpd_conf
*xconf
, void **ref
)
943 ldp_config_normalize(xconf
, ref
);
945 if (main_imsg_send_config(xconf
) == -1)
948 merge_config_ref(ldpd_conf
, xconf
, ref
);
954 ldp_reload(struct ldpd_conf
*xconf
)
956 return ldp_reload_ref(xconf
, NULL
);
960 ldp_config_normalize(struct ldpd_conf
*xconf
, void **ref
)
965 if (!(xconf
->flags
& F_LDPD_ENABLED
))
966 ldp_config_reset_main(xconf
, ref
);
968 if (!(xconf
->ipv4
.flags
& F_LDPD_AF_ENABLED
))
969 ldp_config_reset_af(xconf
, AF_INET
, ref
);
970 if (!(xconf
->ipv6
.flags
& F_LDPD_AF_ENABLED
))
971 ldp_config_reset_af(xconf
, AF_INET6
, ref
);
974 LIST_FOREACH(l2vpn
, &xconf
->l2vpn_list
, entry
) {
975 LIST_FOREACH(pw
, &l2vpn
->pw_list
, entry
) {
976 if (pw
->flags
& F_PW_STATIC_NBR_ADDR
)
980 pw
->addr
.v4
= pw
->lsr_id
;
982 LIST_FOREACH(pw
, &l2vpn
->pw_inactive_list
, entry
) {
983 if (pw
->flags
& F_PW_STATIC_NBR_ADDR
)
987 pw
->addr
.v4
= pw
->lsr_id
;
993 ldp_config_reset_main(struct ldpd_conf
*conf
, void **ref
)
996 struct nbr_params
*nbrp
;
998 while ((iface
= LIST_FIRST(&conf
->iface_list
)) != NULL
) {
999 if (ref
&& *ref
== iface
)
1001 LIST_REMOVE(iface
, entry
);
1005 while ((nbrp
= LIST_FIRST(&conf
->nbrp_list
)) != NULL
) {
1006 if (ref
&& *ref
== nbrp
)
1008 LIST_REMOVE(nbrp
, entry
);
1012 conf
->rtr_id
.s_addr
= INADDR_ANY
;
1013 ldp_config_reset_af(conf
, AF_INET
, ref
);
1014 ldp_config_reset_af(conf
, AF_INET6
, ref
);
1015 conf
->lhello_holdtime
= LINK_DFLT_HOLDTIME
;
1016 conf
->lhello_interval
= DEFAULT_HELLO_INTERVAL
;
1017 conf
->thello_holdtime
= TARGETED_DFLT_HOLDTIME
;
1018 conf
->thello_interval
= DEFAULT_HELLO_INTERVAL
;
1019 conf
->trans_pref
= DUAL_STACK_LDPOV6
;
1024 ldp_config_reset_af(struct ldpd_conf
*conf
, int af
, void **ref
)
1026 struct ldpd_af_conf
*af_conf
;
1027 struct iface
*iface
;
1028 struct iface_af
*ia
;
1029 struct tnbr
*tnbr
, *ttmp
;
1031 LIST_FOREACH(iface
, &conf
->iface_list
, entry
) {
1032 ia
= iface_af_get(iface
, af
);
1036 LIST_FOREACH_SAFE(tnbr
, &conf
->tnbr_list
, entry
, ttmp
) {
1040 if (ref
&& *ref
== tnbr
)
1042 LIST_REMOVE(tnbr
, entry
);
1046 af_conf
= ldp_af_conf_get(conf
, af
);
1047 af_conf
->keepalive
= 180;
1048 af_conf
->lhello_holdtime
= 0;
1049 af_conf
->lhello_interval
= 0;
1050 af_conf
->thello_holdtime
= 0;
1051 af_conf
->thello_interval
= 0;
1052 memset(&af_conf
->trans_addr
, 0, sizeof(af_conf
->trans_addr
));
1057 ldp_dup_config_ref(struct ldpd_conf
*conf
, void **ref
)
1059 struct ldpd_conf
*xconf
;
1060 struct iface
*iface
, *xi
;
1061 struct tnbr
*tnbr
, *xt
;
1062 struct nbr_params
*nbrp
, *xn
;
1063 struct l2vpn
*l2vpn
, *xl
;
1064 struct l2vpn_if
*lif
, *xf
;
1065 struct l2vpn_pw
*pw
, *xp
;
1067 #define COPY(a, b) do { \
1068 a = calloc(1, sizeof(*a)); \
1072 if (ref && *ref == b) *ref = a; \
1076 LIST_INIT(&xconf
->iface_list
);
1077 LIST_INIT(&xconf
->tnbr_list
);
1078 LIST_INIT(&xconf
->nbrp_list
);
1079 LIST_INIT(&xconf
->l2vpn_list
);
1081 LIST_FOREACH(iface
, &conf
->iface_list
, entry
) {
1083 xi
->ipv4
.iface
= xi
;
1084 xi
->ipv6
.iface
= xi
;
1085 LIST_INSERT_HEAD(&xconf
->iface_list
, xi
, entry
);
1087 LIST_FOREACH(tnbr
, &conf
->tnbr_list
, entry
) {
1089 LIST_INSERT_HEAD(&xconf
->tnbr_list
, xt
, entry
);
1091 LIST_FOREACH(nbrp
, &conf
->nbrp_list
, entry
) {
1093 LIST_INSERT_HEAD(&xconf
->nbrp_list
, xn
, entry
);
1095 LIST_FOREACH(l2vpn
, &conf
->l2vpn_list
, entry
) {
1097 LIST_INIT(&xl
->if_list
);
1098 LIST_INIT(&xl
->pw_list
);
1099 LIST_INIT(&xl
->pw_inactive_list
);
1100 LIST_INSERT_HEAD(&xconf
->l2vpn_list
, xl
, entry
);
1102 LIST_FOREACH(lif
, &l2vpn
->if_list
, entry
) {
1105 LIST_INSERT_HEAD(&xl
->if_list
, xf
, entry
);
1107 LIST_FOREACH(pw
, &l2vpn
->pw_list
, entry
) {
1110 LIST_INSERT_HEAD(&xl
->pw_list
, xp
, entry
);
1112 LIST_FOREACH(pw
, &l2vpn
->pw_inactive_list
, entry
) {
1115 LIST_INSERT_HEAD(&xl
->pw_inactive_list
, xp
, entry
);
1124 ldp_dup_config(struct ldpd_conf
*conf
)
1126 return ldp_dup_config_ref(conf
, NULL
);
1130 ldp_clear_config(struct ldpd_conf
*xconf
)
1132 struct iface
*iface
;
1134 struct nbr_params
*nbrp
;
1135 struct l2vpn
*l2vpn
;
1137 while ((iface
= LIST_FIRST(&xconf
->iface_list
)) != NULL
) {
1138 LIST_REMOVE(iface
, entry
);
1141 while ((tnbr
= LIST_FIRST(&xconf
->tnbr_list
)) != NULL
) {
1142 LIST_REMOVE(tnbr
, entry
);
1145 while ((nbrp
= LIST_FIRST(&xconf
->nbrp_list
)) != NULL
) {
1146 LIST_REMOVE(nbrp
, entry
);
1149 while ((l2vpn
= LIST_FIRST(&xconf
->l2vpn_list
)) != NULL
) {
1150 LIST_REMOVE(l2vpn
, entry
);
1158 merge_config_ref(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1160 merge_global(conf
, xconf
);
1161 merge_af(AF_INET
, &conf
->ipv4
, &xconf
->ipv4
);
1162 merge_af(AF_INET6
, &conf
->ipv6
, &xconf
->ipv6
);
1163 merge_ifaces(conf
, xconf
, ref
);
1164 merge_tnbrs(conf
, xconf
, ref
);
1165 merge_nbrps(conf
, xconf
, ref
);
1166 merge_l2vpns(conf
, xconf
, ref
);
1167 if (ref
&& *ref
== xconf
)
1173 merge_config(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1175 merge_config_ref(conf
, xconf
, NULL
);
1179 merge_global(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
)
1181 /* change of router-id requires resetting all neighborships */
1182 if (conf
->rtr_id
.s_addr
!= xconf
->rtr_id
.s_addr
) {
1183 if (ldpd_process
== PROC_LDP_ENGINE
) {
1184 ldpe_reset_nbrs(AF_INET
);
1185 ldpe_reset_nbrs(AF_INET6
);
1186 if (conf
->rtr_id
.s_addr
== INADDR_ANY
||
1187 xconf
->rtr_id
.s_addr
== INADDR_ANY
) {
1188 if_update_all(AF_UNSPEC
);
1189 tnbr_update_all(AF_UNSPEC
);
1192 conf
->rtr_id
= xconf
->rtr_id
;
1195 conf
->lhello_holdtime
= xconf
->lhello_holdtime
;
1196 conf
->lhello_interval
= xconf
->lhello_interval
;
1197 conf
->thello_holdtime
= xconf
->thello_holdtime
;
1198 conf
->thello_interval
= xconf
->thello_interval
;
1200 if (conf
->trans_pref
!= xconf
->trans_pref
) {
1201 if (ldpd_process
== PROC_LDP_ENGINE
)
1202 ldpe_reset_ds_nbrs();
1203 conf
->trans_pref
= xconf
->trans_pref
;
1206 if ((conf
->flags
& F_LDPD_DS_CISCO_INTEROP
) !=
1207 (xconf
->flags
& F_LDPD_DS_CISCO_INTEROP
)) {
1208 if (ldpd_process
== PROC_LDP_ENGINE
)
1209 ldpe_reset_ds_nbrs();
1212 conf
->flags
= xconf
->flags
;
1216 merge_af(int af
, struct ldpd_af_conf
*af_conf
, struct ldpd_af_conf
*xa
)
1218 int egress_label_changed
= 0;
1219 int update_sockets
= 0;
1221 if (af_conf
->keepalive
!= xa
->keepalive
) {
1222 af_conf
->keepalive
= xa
->keepalive
;
1223 if (ldpd_process
== PROC_LDP_ENGINE
)
1224 ldpe_stop_init_backoff(af
);
1227 af_conf
->lhello_holdtime
= xa
->lhello_holdtime
;
1228 af_conf
->lhello_interval
= xa
->lhello_interval
;
1229 af_conf
->thello_holdtime
= xa
->thello_holdtime
;
1230 af_conf
->thello_interval
= xa
->thello_interval
;
1233 if (ldpd_process
== PROC_LDP_ENGINE
&&
1234 (af_conf
->flags
& F_LDPD_AF_THELLO_ACCEPT
) &&
1235 !(xa
->flags
& F_LDPD_AF_THELLO_ACCEPT
))
1236 ldpe_remove_dynamic_tnbrs(af
);
1238 if ((af_conf
->flags
& F_LDPD_AF_NO_GTSM
) !=
1239 (xa
->flags
& F_LDPD_AF_NO_GTSM
)) {
1241 /* need to set/unset IPV6_MINHOPCOUNT */
1243 else if (ldpd_process
== PROC_LDP_ENGINE
)
1244 /* for LDPv4 just resetting the neighbors is enough */
1245 ldpe_reset_nbrs(af
);
1248 if ((af_conf
->flags
& F_LDPD_AF_EXPNULL
) !=
1249 (xa
->flags
& F_LDPD_AF_EXPNULL
))
1250 egress_label_changed
= 1;
1252 af_conf
->flags
= xa
->flags
;
1254 if (egress_label_changed
) {
1255 switch (ldpd_process
) {
1256 case PROC_LDE_ENGINE
:
1257 lde_change_egress_label(af
, af_conf
->flags
&
1265 if (ldp_addrcmp(af
, &af_conf
->trans_addr
, &xa
->trans_addr
)) {
1266 af_conf
->trans_addr
= xa
->trans_addr
;
1270 if (ldpd_process
== PROC_MAIN
&& iev_ldpe
&& update_sockets
)
1271 imsg_compose_event(iev_ldpe
, IMSG_CLOSE_SOCKETS
, af
, 0, -1,
1276 merge_ifaces(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1278 struct iface
*iface
, *itmp
, *xi
;
1280 LIST_FOREACH_SAFE(iface
, &conf
->iface_list
, entry
, itmp
) {
1281 /* find deleted interfaces */
1282 if ((xi
= if_lookup_name(xconf
, iface
->name
)) == NULL
) {
1283 LIST_REMOVE(iface
, entry
);
1285 switch (ldpd_process
) {
1286 case PROC_LDE_ENGINE
:
1288 case PROC_LDP_ENGINE
:
1298 LIST_FOREACH_SAFE(xi
, &xconf
->iface_list
, entry
, itmp
) {
1299 /* find new interfaces */
1300 if ((iface
= if_lookup_name(conf
, xi
->name
)) == NULL
) {
1301 LIST_REMOVE(xi
, entry
);
1302 LIST_INSERT_HEAD(&conf
->iface_list
, xi
, entry
);
1304 if (ldpd_process
== PROC_MAIN
) {
1305 QOBJ_REG (xi
, iface
);
1306 /* resend addresses to activate new interfaces */
1307 kif_redistribute(xi
->name
);
1312 /* update existing interfaces */
1313 merge_iface_af(&iface
->ipv4
, &xi
->ipv4
);
1314 merge_iface_af(&iface
->ipv6
, &xi
->ipv6
);
1315 LIST_REMOVE(xi
, entry
);
1316 if (ref
&& *ref
== xi
)
1323 merge_iface_af(struct iface_af
*ia
, struct iface_af
*xi
)
1325 if (ia
->enabled
!= xi
->enabled
) {
1326 ia
->enabled
= xi
->enabled
;
1327 if (ldpd_process
== PROC_LDP_ENGINE
)
1328 if_update(ia
->iface
, ia
->af
);
1330 ia
->hello_holdtime
= xi
->hello_holdtime
;
1331 ia
->hello_interval
= xi
->hello_interval
;
1335 merge_tnbrs(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1337 struct tnbr
*tnbr
, *ttmp
, *xt
;
1339 LIST_FOREACH_SAFE(tnbr
, &conf
->tnbr_list
, entry
, ttmp
) {
1340 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1343 /* find deleted tnbrs */
1344 if ((xt
= tnbr_find(xconf
, tnbr
->af
, &tnbr
->addr
)) == NULL
) {
1345 switch (ldpd_process
) {
1346 case PROC_LDE_ENGINE
:
1347 LIST_REMOVE(tnbr
, entry
);
1350 case PROC_LDP_ENGINE
:
1351 tnbr
->flags
&= ~F_TNBR_CONFIGURED
;
1355 LIST_REMOVE(tnbr
, entry
);
1362 LIST_FOREACH_SAFE(xt
, &xconf
->tnbr_list
, entry
, ttmp
) {
1363 /* find new tnbrs */
1364 if ((tnbr
= tnbr_find(conf
, xt
->af
, &xt
->addr
)) == NULL
) {
1365 LIST_REMOVE(xt
, entry
);
1366 LIST_INSERT_HEAD(&conf
->tnbr_list
, xt
, entry
);
1368 switch (ldpd_process
) {
1369 case PROC_LDE_ENGINE
:
1371 case PROC_LDP_ENGINE
:
1375 QOBJ_REG (xt
, tnbr
);
1381 /* update existing tnbrs */
1382 if (!(tnbr
->flags
& F_TNBR_CONFIGURED
))
1383 tnbr
->flags
|= F_TNBR_CONFIGURED
;
1384 LIST_REMOVE(xt
, entry
);
1385 if (ref
&& *ref
== xt
)
1392 merge_nbrps(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1394 struct nbr_params
*nbrp
, *ntmp
, *xn
;
1398 LIST_FOREACH_SAFE(nbrp
, &conf
->nbrp_list
, entry
, ntmp
) {
1399 /* find deleted nbrps */
1400 if ((xn
= nbr_params_find(xconf
, nbrp
->lsr_id
)) == NULL
) {
1401 switch (ldpd_process
) {
1402 case PROC_LDE_ENGINE
:
1404 case PROC_LDP_ENGINE
:
1405 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1407 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1412 (ldp_af_global_get(&global
,
1413 nbr
->af
))->ldp_session_socket
,
1414 nbr
->af
, &nbr
->raddr
, NULL
);
1416 if (nbr_session_active_role(nbr
))
1417 nbr_establish_connection(nbr
);
1424 LIST_REMOVE(nbrp
, entry
);
1428 LIST_FOREACH_SAFE(xn
, &xconf
->nbrp_list
, entry
, ntmp
) {
1429 /* find new nbrps */
1430 if ((nbrp
= nbr_params_find(conf
, xn
->lsr_id
)) == NULL
) {
1431 LIST_REMOVE(xn
, entry
);
1432 LIST_INSERT_HEAD(&conf
->nbrp_list
, xn
, entry
);
1434 switch (ldpd_process
) {
1435 case PROC_LDE_ENGINE
:
1437 case PROC_LDP_ENGINE
:
1438 nbr
= nbr_find_ldpid(xn
->lsr_id
.s_addr
);
1440 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1442 if (pfkey_establish(nbr
, xn
) == -1)
1443 fatalx("pfkey setup failed");
1446 (ldp_af_global_get(&global
,
1447 nbr
->af
))->ldp_session_socket
,
1448 nbr
->af
, &nbr
->raddr
,
1451 if (nbr_session_active_role(nbr
))
1452 nbr_establish_connection(nbr
);
1456 QOBJ_REG (xn
, nbr_params
);
1462 /* update existing nbrps */
1463 if (nbrp
->flags
!= xn
->flags
||
1464 nbrp
->keepalive
!= xn
->keepalive
||
1465 nbrp
->gtsm_enabled
!= xn
->gtsm_enabled
||
1466 nbrp
->gtsm_hops
!= xn
->gtsm_hops
||
1467 nbrp
->auth
.method
!= xn
->auth
.method
||
1468 strcmp(nbrp
->auth
.md5key
, xn
->auth
.md5key
) != 0)
1473 nbrp
->keepalive
= xn
->keepalive
;
1474 nbrp
->gtsm_enabled
= xn
->gtsm_enabled
;
1475 nbrp
->gtsm_hops
= xn
->gtsm_hops
;
1476 nbrp
->auth
.method
= xn
->auth
.method
;
1477 strlcpy(nbrp
->auth
.md5key
, xn
->auth
.md5key
,
1478 sizeof(nbrp
->auth
.md5key
));
1479 nbrp
->auth
.md5key_len
= xn
->auth
.md5key_len
;
1480 nbrp
->flags
= xn
->flags
;
1482 if (ldpd_process
== PROC_LDP_ENGINE
) {
1483 nbr
= nbr_find_ldpid(nbrp
->lsr_id
.s_addr
);
1484 if (nbr
&& nbrp_changed
) {
1485 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1488 if (pfkey_establish(nbr
, nbrp
) == -1)
1489 fatalx("pfkey setup failed");
1491 sock_set_md5sig((ldp_af_global_get(&global
,
1492 nbr
->af
))->ldp_session_socket
, nbr
->af
,
1493 &nbr
->raddr
, nbrp
->auth
.md5key
);
1495 if (nbr_session_active_role(nbr
))
1496 nbr_establish_connection(nbr
);
1499 LIST_REMOVE(xn
, entry
);
1500 if (ref
&& *ref
== xn
)
1507 merge_l2vpns(struct ldpd_conf
*conf
, struct ldpd_conf
*xconf
, void **ref
)
1509 struct l2vpn
*l2vpn
, *ltmp
, *xl
;
1510 struct l2vpn_if
*lif
;
1511 struct l2vpn_pw
*pw
;
1513 LIST_FOREACH_SAFE(l2vpn
, &conf
->l2vpn_list
, entry
, ltmp
) {
1514 /* find deleted l2vpns */
1515 if ((xl
= l2vpn_find(xconf
, l2vpn
->name
)) == NULL
) {
1516 LIST_REMOVE(l2vpn
, entry
);
1518 switch (ldpd_process
) {
1519 case PROC_LDE_ENGINE
:
1522 case PROC_LDP_ENGINE
:
1523 ldpe_l2vpn_exit(l2vpn
);
1526 LIST_FOREACH(lif
, &l2vpn
->if_list
, entry
)
1528 LIST_FOREACH(pw
, &l2vpn
->pw_list
, entry
)
1530 LIST_FOREACH(pw
, &l2vpn
->pw_inactive_list
, entry
)
1538 LIST_FOREACH_SAFE(xl
, &xconf
->l2vpn_list
, entry
, ltmp
) {
1539 /* find new l2vpns */
1540 if ((l2vpn
= l2vpn_find(conf
, xl
->name
)) == NULL
) {
1541 LIST_REMOVE(xl
, entry
);
1542 LIST_INSERT_HEAD(&conf
->l2vpn_list
, xl
, entry
);
1544 switch (ldpd_process
) {
1545 case PROC_LDE_ENGINE
:
1548 case PROC_LDP_ENGINE
:
1549 ldpe_l2vpn_init(xl
);
1552 QOBJ_REG (xl
, l2vpn
);
1558 /* update existing l2vpns */
1559 merge_l2vpn(conf
, l2vpn
, xl
, ref
);
1560 LIST_REMOVE(xl
, entry
);
1561 if (ref
&& *ref
== xl
)
1568 merge_l2vpn(struct ldpd_conf
*xconf
, struct l2vpn
*l2vpn
, struct l2vpn
*xl
, void **ref
)
1570 struct l2vpn_if
*lif
, *ftmp
, *xf
;
1571 struct l2vpn_pw
*pw
, *ptmp
, *xp
;
1573 int reset_nbr
, reinstall_pwfec
, reinstall_tnbr
;
1574 LIST_HEAD(, l2vpn_pw
) pw_aux_list
;
1575 int previous_pw_type
, previous_mtu
;
1577 previous_pw_type
= l2vpn
->pw_type
;
1578 previous_mtu
= l2vpn
->mtu
;
1580 /* merge intefaces */
1581 LIST_FOREACH_SAFE(lif
, &l2vpn
->if_list
, entry
, ftmp
) {
1582 /* find deleted interfaces */
1583 if ((xf
= l2vpn_if_find_name(xl
, lif
->ifname
)) == NULL
) {
1584 if (ldpd_process
== PROC_MAIN
)
1586 LIST_REMOVE(lif
, entry
);
1590 LIST_FOREACH_SAFE(xf
, &xl
->if_list
, entry
, ftmp
) {
1591 /* find new interfaces */
1592 if ((lif
= l2vpn_if_find_name(l2vpn
, xf
->ifname
)) == NULL
) {
1593 LIST_REMOVE(xf
, entry
);
1594 LIST_INSERT_HEAD(&l2vpn
->if_list
, xf
, entry
);
1596 if (ldpd_process
== PROC_MAIN
)
1597 QOBJ_REG (xf
, l2vpn_if
);
1601 LIST_REMOVE(xf
, entry
);
1602 if (ref
&& *ref
== xf
)
1607 /* merge active pseudowires */
1608 LIST_INIT(&pw_aux_list
);
1609 LIST_FOREACH_SAFE(pw
, &l2vpn
->pw_list
, entry
, ptmp
) {
1610 /* find deleted active pseudowires */
1611 if ((xp
= l2vpn_pw_find_name(xl
, pw
->ifname
)) == NULL
) {
1612 switch (ldpd_process
) {
1613 case PROC_LDE_ENGINE
:
1616 case PROC_LDP_ENGINE
:
1617 ldpe_l2vpn_pw_exit(pw
);
1624 LIST_REMOVE(pw
, entry
);
1628 LIST_FOREACH_SAFE(xp
, &xl
->pw_list
, entry
, ptmp
) {
1629 /* find new active pseudowires */
1630 if ((pw
= l2vpn_pw_find_name(l2vpn
, xp
->ifname
)) == NULL
) {
1631 LIST_REMOVE(xp
, entry
);
1632 LIST_INSERT_HEAD(&l2vpn
->pw_list
, xp
, entry
);
1635 switch (ldpd_process
) {
1636 case PROC_LDE_ENGINE
:
1639 case PROC_LDP_ENGINE
:
1640 ldpe_l2vpn_pw_init(xp
);
1643 QOBJ_REG (xp
, l2vpn_pw
);
1649 /* update existing active pseudowire */
1650 if (pw
->af
!= xp
->af
||
1651 ldp_addrcmp(pw
->af
, &pw
->addr
, &xp
->addr
))
1656 /* changes that require a session restart */
1657 if ((pw
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)) !=
1658 (xp
->flags
& (F_PW_STATUSTLV_CONF
|F_PW_CWORD_CONF
)))
1663 if (l2vpn
->pw_type
!= xl
->pw_type
|| l2vpn
->mtu
!= xl
->mtu
||
1664 pw
->pwid
!= xp
->pwid
|| reinstall_tnbr
|| reset_nbr
||
1665 pw
->lsr_id
.s_addr
!= xp
->lsr_id
.s_addr
)
1666 reinstall_pwfec
= 1;
1668 reinstall_pwfec
= 0;
1670 /* check if the pseudowire should be disabled */
1671 if (xp
->lsr_id
.s_addr
== INADDR_ANY
|| xp
->pwid
== 0) {
1674 reinstall_pwfec
= 0;
1676 switch (ldpd_process
) {
1677 case PROC_LDE_ENGINE
:
1680 case PROC_LDP_ENGINE
:
1681 ldpe_l2vpn_pw_exit(pw
);
1687 /* remove from active list */
1688 LIST_REMOVE(pw
, entry
);
1689 LIST_INSERT_HEAD(&pw_aux_list
, pw
, entry
);
1692 if (ldpd_process
== PROC_LDP_ENGINE
) {
1694 ldpe_l2vpn_pw_exit(pw
);
1696 nbr
= nbr_find_ldpid(pw
->lsr_id
.s_addr
);
1697 if (nbr
&& nbr
->state
== NBR_STA_OPER
)
1698 session_shutdown(nbr
, S_SHUTDOWN
, 0, 0);
1701 if (ldpd_process
== PROC_LDE_ENGINE
&&
1702 !reset_nbr
&& reinstall_pwfec
)
1704 pw
->lsr_id
= xp
->lsr_id
;
1706 pw
->addr
= xp
->addr
;
1707 pw
->pwid
= xp
->pwid
;
1708 strlcpy(pw
->ifname
, xp
->ifname
, sizeof(pw
->ifname
));
1709 pw
->ifindex
= xp
->ifindex
;
1710 if (xp
->flags
& F_PW_CWORD_CONF
)
1711 pw
->flags
|= F_PW_CWORD_CONF
;
1713 pw
->flags
&= ~F_PW_CWORD_CONF
;
1714 if (xp
->flags
& F_PW_STATUSTLV_CONF
)
1715 pw
->flags
|= F_PW_STATUSTLV_CONF
;
1717 pw
->flags
&= ~F_PW_STATUSTLV_CONF
;
1718 if (xp
->flags
& F_PW_STATIC_NBR_ADDR
)
1719 pw
->flags
|= F_PW_STATIC_NBR_ADDR
;
1721 pw
->flags
&= ~F_PW_STATIC_NBR_ADDR
;
1722 if (ldpd_process
== PROC_LDP_ENGINE
&& reinstall_tnbr
)
1723 ldpe_l2vpn_pw_init(pw
);
1724 if (ldpd_process
== PROC_LDE_ENGINE
&&
1725 !reset_nbr
&& reinstall_pwfec
) {
1726 l2vpn
->pw_type
= xl
->pw_type
;
1727 l2vpn
->mtu
= xl
->mtu
;
1729 l2vpn
->pw_type
= previous_pw_type
;
1730 l2vpn
->mtu
= previous_mtu
;
1733 LIST_REMOVE(xp
, entry
);
1734 if (ref
&& *ref
== xp
)
1739 /* merge inactive pseudowires */
1740 LIST_FOREACH_SAFE(pw
, &l2vpn
->pw_inactive_list
, entry
, ptmp
) {
1741 /* find deleted inactive pseudowires */
1742 if ((xp
= l2vpn_pw_find_name(xl
, pw
->ifname
)) == NULL
) {
1743 LIST_REMOVE(pw
, entry
);
1744 if (ldpd_process
== PROC_MAIN
)
1749 LIST_FOREACH_SAFE(xp
, &xl
->pw_inactive_list
, entry
, ptmp
) {
1750 /* find new inactive pseudowires */
1751 if ((pw
= l2vpn_pw_find_name(l2vpn
, xp
->ifname
)) == NULL
) {
1752 LIST_REMOVE(xp
, entry
);
1753 LIST_INSERT_HEAD(&l2vpn
->pw_inactive_list
, xp
, entry
);
1755 if (ldpd_process
== PROC_MAIN
)
1756 QOBJ_REG (xp
, l2vpn_pw
);
1760 /* update existing inactive pseudowire */
1761 pw
->lsr_id
.s_addr
= xp
->lsr_id
.s_addr
;
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 pw
->flags
= xp
->flags
;
1769 /* check if the pseudowire should be activated */
1770 if (pw
->lsr_id
.s_addr
!= INADDR_ANY
&& pw
->pwid
!= 0) {
1771 /* remove from inactive list */
1772 LIST_REMOVE(pw
, entry
);
1773 LIST_INSERT_HEAD(&l2vpn
->pw_list
, pw
, entry
);
1775 switch (ldpd_process
) {
1776 case PROC_LDE_ENGINE
:
1779 case PROC_LDP_ENGINE
:
1780 ldpe_l2vpn_pw_init(pw
);
1787 LIST_REMOVE(xp
, entry
);
1788 if (ref
&& *ref
== xp
)
1793 /* insert pseudowires that were disabled in the inactive list */
1794 LIST_FOREACH_SAFE(pw
, &pw_aux_list
, entry
, ptmp
) {
1795 LIST_REMOVE(pw
, entry
);
1796 LIST_INSERT_HEAD(&l2vpn
->pw_inactive_list
, pw
, entry
);
1799 l2vpn
->pw_type
= xl
->pw_type
;
1800 l2vpn
->mtu
= xl
->mtu
;
1801 strlcpy(l2vpn
->br_ifname
, xl
->br_ifname
, sizeof(l2vpn
->br_ifname
));
1802 l2vpn
->br_ifindex
= xl
->br_ifindex
;
1806 config_new_empty(void)
1808 struct ldpd_conf
*xconf
;
1810 xconf
= calloc(1, sizeof(*xconf
));
1814 LIST_INIT(&xconf
->iface_list
);
1815 LIST_INIT(&xconf
->tnbr_list
);
1816 LIST_INIT(&xconf
->nbrp_list
);
1817 LIST_INIT(&xconf
->l2vpn_list
);
1823 config_clear(struct ldpd_conf
*conf
)
1825 struct ldpd_conf
*xconf
;
1828 * Merge current config with an empty config, this will deactivate
1829 * and deallocate all the interfaces, pseudowires and so on. Before
1830 * merging, copy the router-id and other variables to avoid some
1831 * unnecessary operations, like trying to reset the neighborships.
1833 xconf
= config_new_empty();
1834 xconf
->ipv4
= conf
->ipv4
;
1835 xconf
->ipv6
= conf
->ipv6
;
1836 xconf
->rtr_id
= conf
->rtr_id
;
1837 xconf
->trans_pref
= conf
->trans_pref
;
1838 xconf
->flags
= conf
->flags
;
1839 merge_config(conf
, xconf
);
1840 if (ldpd_process
== PROC_MAIN
)