1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
|
/* $OpenBSD: ldpe.c,v 1.39 2015/07/21 05:04:12 renato Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2004, 2008 Esben Norby <norby@openbsd.org>
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/queue.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <net/if_types.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <fcntl.h>
#include <pwd.h>
#include <unistd.h>
#include <event.h>
#include <err.h>
#include <errno.h>
#include <stdio.h>
#include "ldp.h"
#include "ldpd.h"
#include "ldpe.h"
#include "lde.h"
#include "control.h"
#include "log.h"
extern struct nbr_id_head nbrs_by_id;
RB_PROTOTYPE(nbr_id_head, nbr, id_tree, nbr_id_compare)
void ldpe_sig_handler(int, short, void *);
void ldpe_shutdown(void);
struct ldpd_conf *leconf = NULL, *nconf;
struct imsgev *iev_main;
struct imsgev *iev_lde;
struct event disc_ev;
struct event edisc_ev;
struct event pfkey_ev;
struct ldpd_sysdep sysdep;
/* ARGSUSED */
void
ldpe_sig_handler(int sig, short event, void *bula)
{
switch (sig) {
case SIGINT:
case SIGTERM:
ldpe_shutdown();
/* NOTREACHED */
default:
fatalx("unexpected signal");
}
}
/* label distribution protocol engine */
pid_t
ldpe(struct ldpd_conf *xconf, int pipe_parent2ldpe[2], int pipe_ldpe2lde[2],
int pipe_parent2lde[2])
{
struct iface *iface;
struct tnbr *tnbr;
struct passwd *pw;
struct event ev_sigint, ev_sigterm;
struct sockaddr_in disc_addr, sess_addr;
pid_t pid;
int pfkeysock, opt;
switch (pid = fork()) {
case -1:
fatal("cannot fork");
case 0:
break;
default:
return (pid);
}
leconf = xconf;
setproctitle("ldp engine");
ldpd_process = PROC_LDP_ENGINE;
pfkeysock = pfkey_init(&sysdep);
/* create ldpd control socket outside chroot */
if (control_init() == -1)
fatalx("control socket setup failed");
/* create the discovery UDP socket */
disc_addr.sin_family = AF_INET;
disc_addr.sin_port = htons(LDP_PORT);
disc_addr.sin_addr.s_addr = INADDR_ANY;
if ((xconf->ldp_discovery_socket = socket(AF_INET,
SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
IPPROTO_UDP)) == -1)
fatal("error creating discovery socket");
if (if_set_reuse(xconf->ldp_discovery_socket, 1) == -1)
fatal("if_set_reuse");
if (bind(xconf->ldp_discovery_socket, (struct sockaddr *)&disc_addr,
sizeof(disc_addr)) == -1)
fatal("error binding discovery socket");
/* set some defaults */
if (if_set_mcast_ttl(xconf->ldp_discovery_socket,
IP_DEFAULT_MULTICAST_TTL) == -1)
fatal("if_set_mcast_ttl");
if (if_set_mcast_loop(xconf->ldp_discovery_socket) == -1)
fatal("if_set_mcast_loop");
if (if_set_tos(xconf->ldp_discovery_socket,
IPTOS_PREC_INTERNETCONTROL) == -1)
fatal("if_set_tos");
if (if_set_recvif(xconf->ldp_discovery_socket, 1) == -1)
fatal("if_set_recvif");
if_set_recvbuf(xconf->ldp_discovery_socket);
/* create the extended discovery UDP socket */
disc_addr.sin_family = AF_INET;
disc_addr.sin_port = htons(LDP_PORT);
disc_addr.sin_addr.s_addr = xconf->rtr_id.s_addr;
if ((xconf->ldp_ediscovery_socket = socket(AF_INET,
SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
IPPROTO_UDP)) == -1)
fatal("error creating extended discovery socket");
if (if_set_reuse(xconf->ldp_ediscovery_socket, 1) == -1)
fatal("if_set_reuse");
if (bind(xconf->ldp_ediscovery_socket, (struct sockaddr *)&disc_addr,
sizeof(disc_addr)) == -1)
fatal("error binding extended discovery socket");
/* set some defaults */
if (if_set_tos(xconf->ldp_ediscovery_socket,
IPTOS_PREC_INTERNETCONTROL) == -1)
fatal("if_set_tos");
if (if_set_recvif(xconf->ldp_ediscovery_socket, 1) == -1)
fatal("if_set_recvif");
if_set_recvbuf(xconf->ldp_ediscovery_socket);
/* create the session TCP socket */
sess_addr.sin_family = AF_INET;
sess_addr.sin_port = htons(LDP_PORT);
sess_addr.sin_addr.s_addr = INADDR_ANY;
if ((xconf->ldp_session_socket = socket(AF_INET,
SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
IPPROTO_TCP)) == -1)
fatal("error creating session socket");
if (if_set_reuse(xconf->ldp_session_socket, 1) == -1)
fatal("if_set_reuse");
if (bind(xconf->ldp_session_socket, (struct sockaddr *)&sess_addr,
sizeof(sess_addr)) == -1)
fatal("error binding session socket");
if (listen(xconf->ldp_session_socket, LDP_BACKLOG) == -1)
fatal("error in listen on session socket");
opt = 1;
if (setsockopt(xconf->ldp_session_socket, IPPROTO_TCP, TCP_MD5SIG,
&opt, sizeof(opt)) == -1) {
if (errno == ENOPROTOOPT) { /* system w/o md5sig */
log_warnx("md5sig not available, disabling");
sysdep.no_md5sig = 1;
} else
fatal("setsockopt TCP_MD5SIG");
}
/* set some defaults */
if (if_set_tos(xconf->ldp_session_socket,
IPTOS_PREC_INTERNETCONTROL) == -1)
fatal("if_set_tos");
if ((pw = getpwnam(LDPD_USER)) == NULL)
fatal("getpwnam");
if (chroot(pw->pw_dir) == -1)
fatal("chroot");
if (chdir("/") == -1)
fatal("chdir(\"/\")");
if (setgroups(1, &pw->pw_gid) ||
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
fatal("can't drop privileges");
event_init();
accept_init();
/* setup signal handler */
signal_set(&ev_sigint, SIGINT, ldpe_sig_handler, NULL);
signal_set(&ev_sigterm, SIGTERM, ldpe_sig_handler, NULL);
signal_add(&ev_sigint, NULL);
signal_add(&ev_sigterm, NULL);
signal(SIGPIPE, SIG_IGN);
signal(SIGHUP, SIG_IGN);
/* setup pipes */
close(pipe_parent2ldpe[0]);
close(pipe_ldpe2lde[1]);
close(pipe_parent2lde[0]);
close(pipe_parent2lde[1]);
if ((iev_lde = malloc(sizeof(struct imsgev))) == NULL ||
(iev_main = malloc(sizeof(struct imsgev))) == NULL)
fatal(NULL);
imsg_init(&iev_lde->ibuf, pipe_ldpe2lde[0]);
iev_lde->handler = ldpe_dispatch_lde;
imsg_init(&iev_main->ibuf, pipe_parent2ldpe[1]);
iev_main->handler = ldpe_dispatch_main;
/* setup event handler */
iev_lde->events = EV_READ;
event_set(&iev_lde->ev, iev_lde->ibuf.fd, iev_lde->events,
iev_lde->handler, iev_lde);
event_add(&iev_lde->ev, NULL);
iev_main->events = EV_READ;
event_set(&iev_main->ev, iev_main->ibuf.fd, iev_main->events,
iev_main->handler, iev_main);
event_add(&iev_main->ev, NULL);
event_set(&pfkey_ev, pfkeysock, EV_READ | EV_PERSIST,
ldpe_dispatch_pfkey, NULL);
event_add(&pfkey_ev, NULL);
event_set(&disc_ev, leconf->ldp_discovery_socket,
EV_READ|EV_PERSIST, disc_recv_packet, NULL);
event_add(&disc_ev, NULL);
event_set(&edisc_ev, leconf->ldp_ediscovery_socket,
EV_READ|EV_PERSIST, disc_recv_packet, NULL);
event_add(&edisc_ev, NULL);
accept_add(leconf->ldp_session_socket, session_accept, NULL);
/* listen on ldpd control socket */
TAILQ_INIT(&ctl_conns);
control_listen();
if ((pkt_ptr = calloc(1, IBUF_READ_SIZE)) == NULL)
fatal("ldpe");
/* initialize interfaces */
LIST_FOREACH(iface, &leconf->iface_list, entry)
if_init(xconf, iface);
/* start configured targeted neighbors */
LIST_FOREACH(tnbr, &leconf->tnbr_list, entry)
tnbr_init(xconf, tnbr);
event_dispatch();
ldpe_shutdown();
/* NOTREACHED */
return (0);
}
void
ldpe_shutdown(void)
{
struct if_addr *if_addr;
control_cleanup();
event_del(&disc_ev);
event_del(&edisc_ev);
event_del(&pfkey_ev);
close(leconf->ldp_discovery_socket);
close(leconf->ldp_ediscovery_socket);
close(leconf->ldp_session_socket);
/* remove addresses from global list */
while ((if_addr = LIST_FIRST(&leconf->addr_list)) != NULL) {
LIST_REMOVE(if_addr, entry);
free(if_addr);
}
config_clear(leconf);
/* clean up */
msgbuf_write(&iev_lde->ibuf.w);
msgbuf_clear(&iev_lde->ibuf.w);
free(iev_lde);
msgbuf_write(&iev_main->ibuf.w);
msgbuf_clear(&iev_main->ibuf.w);
free(iev_main);
free(pkt_ptr);
log_info("ldp engine exiting");
_exit(0);
}
/* imesg */
int
ldpe_imsg_compose_parent(int type, pid_t pid, void *data, u_int16_t datalen)
{
return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen));
}
int
ldpe_imsg_compose_lde(int type, u_int32_t peerid, pid_t pid,
void *data, u_int16_t datalen)
{
return (imsg_compose_event(iev_lde, type, peerid, pid, -1,
data, datalen));
}
/* ARGSUSED */
void
ldpe_dispatch_main(int fd, short event, void *bula)
{
struct iface *niface;
struct tnbr *ntnbr;
struct nbr_params *nnbrp;
static struct l2vpn *nl2vpn;
struct l2vpn_if *nlif;
struct l2vpn_pw *npw;
struct imsg imsg;
struct imsgev *iev = bula;
struct imsgbuf *ibuf = &iev->ibuf;
struct iface *iface = NULL;
struct if_addr *if_addr = NULL;
struct kif *kif;
struct kaddr *ka;
int n, shut = 0;
struct nbr *nbr;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read error");
if (n == 0) /* connection closed */
shut = 1;
}
if (event & EV_WRITE) {
if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
fatal("ldpe_dispatch_main: msgbuf_write");
if (n == 0)
shut = 1;
}
for (;;) {
if ((n = imsg_get(ibuf, &imsg)) == -1)
fatal("ldpe_dispatch_main: imsg_read error");
if (n == 0)
break;
switch (imsg.hdr.type) {
case IMSG_IFSTATUS:
if (imsg.hdr.len != IMSG_HEADER_SIZE +
sizeof(struct kif))
fatalx("IFSTATUS imsg with wrong len");
kif = imsg.data;
iface = if_lookup(leconf, kif->ifindex);
if (!iface)
break;
iface->flags = kif->flags;
iface->linkstate = kif->link_state;
if_update(iface);
break;
case IMSG_NEWADDR:
if (imsg.hdr.len != IMSG_HEADER_SIZE +
sizeof(struct kaddr))
fatalx("NEWADDR imsg with wrong len");
ka = imsg.data;
if (if_addr_lookup(&leconf->addr_list, ka) == NULL) {
if_addr = if_addr_new(ka);
LIST_INSERT_HEAD(&leconf->addr_list, if_addr,
entry);
RB_FOREACH(nbr, nbr_id_head, &nbrs_by_id) {
if (nbr->state != NBR_STA_OPER)
continue;
send_address(nbr, if_addr);
}
}
iface = if_lookup(leconf, ka->ifindex);
if (iface &&
if_addr_lookup(&iface->addr_list, ka) == NULL) {
if_addr = if_addr_new(ka);
LIST_INSERT_HEAD(&iface->addr_list, if_addr,
entry);
if_update(iface);
}
break;
case IMSG_DELADDR:
if (imsg.hdr.len != IMSG_HEADER_SIZE +
sizeof(struct kaddr))
fatalx("DELADDR imsg with wrong len");
ka = imsg.data;
iface = if_lookup(leconf, ka->ifindex);
if (iface) {
if_addr = if_addr_lookup(&iface->addr_list, ka);
if (if_addr) {
LIST_REMOVE(if_addr, entry);
free(if_addr);
if_update(iface);
}
}
if_addr = if_addr_lookup(&leconf->addr_list, ka);
if (if_addr) {
RB_FOREACH(nbr, nbr_id_head, &nbrs_by_id) {
if (nbr->state != NBR_STA_OPER)
continue;
send_address_withdraw(nbr, if_addr);
}
LIST_REMOVE(if_addr, entry);
free(if_addr);
}
break;
case IMSG_RECONF_CONF:
if ((nconf = malloc(sizeof(struct ldpd_conf))) ==
NULL)
fatal(NULL);
memcpy(nconf, imsg.data, sizeof(struct ldpd_conf));
LIST_INIT(&nconf->iface_list);
LIST_INIT(&nconf->addr_list);
LIST_INIT(&nconf->tnbr_list);
LIST_INIT(&nconf->nbrp_list);
LIST_INIT(&nconf->l2vpn_list);
break;
case IMSG_RECONF_IFACE:
if ((niface = malloc(sizeof(struct iface))) == NULL)
fatal(NULL);
memcpy(niface, imsg.data, sizeof(struct iface));
LIST_INIT(&niface->addr_list);
LIST_INIT(&niface->adj_list);
LIST_INSERT_HEAD(&nconf->iface_list, niface, entry);
break;
case IMSG_RECONF_TNBR:
if ((ntnbr = malloc(sizeof(struct tnbr))) == NULL)
fatal(NULL);
memcpy(ntnbr, imsg.data, sizeof(struct tnbr));
LIST_INSERT_HEAD(&nconf->tnbr_list, ntnbr, entry);
break;
case IMSG_RECONF_NBRP:
if ((nnbrp = malloc(sizeof(struct nbr_params))) == NULL)
fatal(NULL);
memcpy(nnbrp, imsg.data, sizeof(struct nbr_params));
LIST_INSERT_HEAD(&nconf->nbrp_list, nnbrp, entry);
break;
case IMSG_RECONF_L2VPN:
if ((nl2vpn = malloc(sizeof(struct l2vpn))) == NULL)
fatal(NULL);
memcpy(nl2vpn, imsg.data, sizeof(struct l2vpn));
LIST_INIT(&nl2vpn->if_list);
LIST_INIT(&nl2vpn->pw_list);
LIST_INSERT_HEAD(&nconf->l2vpn_list, nl2vpn, entry);
break;
case IMSG_RECONF_L2VPN_IF:
if ((nlif = malloc(sizeof(struct l2vpn_if))) == NULL)
fatal(NULL);
memcpy(nlif, imsg.data, sizeof(struct l2vpn_if));
nlif->l2vpn = nl2vpn;
LIST_INSERT_HEAD(&nl2vpn->if_list, nlif, entry);
break;
case IMSG_RECONF_L2VPN_PW:
if ((npw = malloc(sizeof(struct l2vpn_pw))) == NULL)
fatal(NULL);
memcpy(npw, imsg.data, sizeof(struct l2vpn_pw));
npw->l2vpn = nl2vpn;
LIST_INSERT_HEAD(&nl2vpn->pw_list, npw, entry);
break;
case IMSG_RECONF_END:
merge_config(leconf, nconf);
nconf = NULL;
break;
case IMSG_CTL_KROUTE:
case IMSG_CTL_KROUTE_ADDR:
case IMSG_CTL_IFINFO:
case IMSG_CTL_END:
control_imsg_relay(&imsg);
break;
default:
log_debug("ldpe_dispatch_main: error handling imsg %d",
imsg.hdr.type);
break;
}
imsg_free(&imsg);
}
if (!shut)
imsg_event_add(iev);
else {
/* this pipe is dead, so remove the event handler */
event_del(&iev->ev);
event_loopexit(NULL);
}
}
/* ARGSUSED */
void
ldpe_dispatch_lde(int fd, short event, void *bula)
{
struct imsgev *iev = bula;
struct imsgbuf *ibuf = &iev->ibuf;
struct imsg imsg;
struct map map;
struct notify_msg nm;
int n, shut = 0;
struct nbr *nbr = NULL;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read error");
if (n == 0) /* connection closed */
shut = 1;
}
if (event & EV_WRITE) {
if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN)
fatal("ldpe_dispatch_lde: msgbuf_write");
if (n == 0)
shut = 1;
}
for (;;) {
if ((n = imsg_get(ibuf, &imsg)) == -1)
fatal("ldpe_dispatch_lde: imsg_read error");
if (n == 0)
break;
switch (imsg.hdr.type) {
case IMSG_MAPPING_ADD:
case IMSG_RELEASE_ADD:
case IMSG_REQUEST_ADD:
case IMSG_WITHDRAW_ADD:
if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(map))
fatalx("invalid size of map request");
memcpy(&map, imsg.data, sizeof(map));
nbr = nbr_find_peerid(imsg.hdr.peerid);
if (nbr == NULL) {
log_debug("ldpe_dispatch_lde: cannot find "
"neighbor");
break;
}
if (nbr->state != NBR_STA_OPER)
break;
switch (imsg.hdr.type) {
case IMSG_MAPPING_ADD:
mapping_list_add(&nbr->mapping_list, &map);
break;
case IMSG_RELEASE_ADD:
mapping_list_add(&nbr->release_list, &map);
break;
case IMSG_REQUEST_ADD:
mapping_list_add(&nbr->request_list, &map);
break;
case IMSG_WITHDRAW_ADD:
mapping_list_add(&nbr->withdraw_list, &map);
break;
}
break;
case IMSG_MAPPING_ADD_END:
case IMSG_RELEASE_ADD_END:
case IMSG_REQUEST_ADD_END:
case IMSG_WITHDRAW_ADD_END:
nbr = nbr_find_peerid(imsg.hdr.peerid);
if (nbr == NULL) {
log_debug("ldpe_dispatch_lde: cannot find "
"neighbor");
break;
}
if (nbr->state != NBR_STA_OPER)
break;
switch (imsg.hdr.type) {
case IMSG_MAPPING_ADD_END:
send_labelmessage(nbr, MSG_TYPE_LABELMAPPING,
&nbr->mapping_list);
break;
case IMSG_RELEASE_ADD_END:
send_labelmessage(nbr, MSG_TYPE_LABELRELEASE,
&nbr->release_list);
break;
case IMSG_REQUEST_ADD_END:
send_labelmessage(nbr, MSG_TYPE_LABELREQUEST,
&nbr->request_list);
break;
case IMSG_WITHDRAW_ADD_END:
send_labelmessage(nbr, MSG_TYPE_LABELWITHDRAW,
&nbr->withdraw_list);
break;
}
break;
case IMSG_NOTIFICATION_SEND:
if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(nm))
fatalx("invalid size of OE request");
memcpy(&nm, imsg.data, sizeof(nm));
nbr = nbr_find_peerid(imsg.hdr.peerid);
if (nbr == NULL) {
log_debug("ldpe_dispatch_lde: cannot find "
"neighbor");
break;
}
if (nbr->state != NBR_STA_OPER)
break;
send_notification_full(nbr->tcp, &nm);
break;
case IMSG_CTL_END:
case IMSG_CTL_SHOW_LIB:
case IMSG_CTL_SHOW_L2VPN_PW:
case IMSG_CTL_SHOW_L2VPN_BINDING:
control_imsg_relay(&imsg);
break;
default:
log_debug("ldpe_dispatch_lde: error handling imsg %d",
imsg.hdr.type);
break;
}
imsg_free(&imsg);
}
if (!shut)
imsg_event_add(iev);
else {
/* this pipe is dead, so remove the event handler */
event_del(&iev->ev);
event_loopexit(NULL);
}
}
/* ARGSUSED */
void
ldpe_dispatch_pfkey(int fd, short event, void *bula)
{
if (event & EV_READ) {
if (pfkey_read(fd, NULL) == -1) {
fatal("pfkey_read failed, exiting...");
}
}
}
u_int32_t
ldpe_router_id(void)
{
return (leconf->rtr_id.s_addr);
}
void
mapping_list_add(struct mapping_head *mh, struct map *map)
{
struct mapping_entry *me;
me = calloc(1, sizeof(*me));
if (me == NULL)
fatal("mapping_list_add");
me->map = *map;
TAILQ_INSERT_TAIL(mh, me, entry);
}
void
mapping_list_clr(struct mapping_head *mh)
{
struct mapping_entry *me;
while ((me = TAILQ_FIRST(mh)) != NULL) {
TAILQ_REMOVE(mh, me, entry);
free(me);
}
}
void
ldpe_iface_ctl(struct ctl_conn *c, unsigned int idx)
{
struct iface *iface;
struct ctl_iface *ictl;
LIST_FOREACH(iface, &leconf->iface_list, entry) {
if (idx == 0 || idx == iface->ifindex) {
ictl = if_to_ctl(iface);
imsg_compose_event(&c->iev,
IMSG_CTL_SHOW_INTERFACE,
0, 0, -1, ictl, sizeof(struct ctl_iface));
}
}
}
|