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