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