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