bgpd.c revision 1.129
1/* $OpenBSD: bgpd.c,v 1.129 2006/01/03 16:49:23 claudio Exp $ */ 2 3/* 4 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19#include <sys/types.h> 20#include <sys/socket.h> 21#include <sys/wait.h> 22#include <netinet/in.h> 23#include <arpa/inet.h> 24#include <err.h> 25#include <errno.h> 26#include <fcntl.h> 27#include <poll.h> 28#include <pwd.h> 29#include <signal.h> 30#include <stdio.h> 31#include <stdlib.h> 32#include <string.h> 33#include <unistd.h> 34 35#include "mrt.h" 36#include "bgpd.h" 37#include "session.h" 38 39void sighdlr(int); 40__dead void usage(void); 41int main(int, char *[]); 42int check_child(pid_t, const char *); 43int send_filterset(struct imsgbuf *, struct filter_set_head *, 44 int); 45int reconfigure(char *, struct bgpd_config *, struct mrt_head *, 46 struct peer **, struct filter_head *); 47int dispatch_imsg(struct imsgbuf *, int); 48 49int rfd = -1; 50int cflags = 0; 51struct filter_set_head *connectset; 52struct filter_set_head *connectset6; 53struct filter_set_head *staticset; 54struct filter_set_head *staticset6; 55volatile sig_atomic_t mrtdump = 0; 56volatile sig_atomic_t quit = 0; 57volatile sig_atomic_t reconfig = 0; 58volatile sig_atomic_t sigchld = 0; 59struct imsgbuf *ibuf_se; 60struct imsgbuf *ibuf_rde; 61 62void 63sighdlr(int sig) 64{ 65 switch (sig) { 66 case SIGTERM: 67 case SIGINT: 68 quit = 1; 69 break; 70 case SIGCHLD: 71 sigchld = 1; 72 break; 73 case SIGHUP: 74 reconfig = 1; 75 break; 76 case SIGALRM: 77 case SIGUSR1: 78 mrtdump = 1; 79 break; 80 } 81} 82 83__dead void 84usage(void) 85{ 86 extern char *__progname; 87 88 fprintf(stderr, "usage: %s [-dnv] ", __progname); 89 fprintf(stderr, "[-D macro=value] [-f file]\n"); 90 exit(1); 91} 92 93#define PFD_PIPE_SESSION 0 94#define PFD_PIPE_ROUTE 1 95#define PFD_SOCK_ROUTE 2 96#define POLL_MAX 3 97#define MAX_TIMEOUT 3600 98 99int 100main(int argc, char *argv[]) 101{ 102 struct bgpd_config conf; 103 struct peer *peer_l, *p; 104 struct mrt_head mrt_l; 105 struct network_head net_l; 106 struct filter_head *rules_l; 107 struct network *net; 108 struct filter_rule *r; 109 struct mrt *m; 110 struct listen_addr *la; 111 struct pollfd pfd[POLL_MAX]; 112 pid_t io_pid = 0, rde_pid = 0, pid; 113 char *conffile; 114 int debug = 0; 115 int ch, timeout, nfds; 116 int pipe_m2s[2]; 117 int pipe_m2r[2]; 118 int pipe_s2r[2]; 119 120 conffile = CONFFILE; 121 bgpd_process = PROC_MAIN; 122 123 log_init(1); /* log to stderr until daemonized */ 124 125 if ((rules_l = calloc(1, sizeof(struct filter_head))) == NULL) 126 err(1, NULL); 127 128 bzero(&conf, sizeof(conf)); 129 LIST_INIT(&mrt_l); 130 TAILQ_INIT(&net_l); 131 TAILQ_INIT(rules_l); 132 peer_l = NULL; 133 134 while ((ch = getopt(argc, argv, "dD:f:nv")) != -1) { 135 switch (ch) { 136 case 'd': 137 debug = 1; 138 break; 139 case 'D': 140 if (cmdline_symset(optarg) < 0) 141 log_warnx("could not parse macro definition %s", 142 optarg); 143 break; 144 case 'f': 145 conffile = optarg; 146 break; 147 case 'n': 148 conf.opts |= BGPD_OPT_NOACTION; 149 break; 150 case 'v': 151 if (conf.opts & BGPD_OPT_VERBOSE) 152 conf.opts |= BGPD_OPT_VERBOSE2; 153 conf.opts |= BGPD_OPT_VERBOSE; 154 break; 155 default: 156 usage(); 157 /* NOTREACHED */ 158 } 159 } 160 161 if (parse_config(conffile, &conf, &mrt_l, &peer_l, &net_l, rules_l)) { 162 free(rules_l); 163 exit(1); 164 } 165 166 if (conf.opts & BGPD_OPT_NOACTION) { 167 if (conf.opts & BGPD_OPT_VERBOSE) 168 print_config(&conf, &net_l, peer_l, rules_l, &mrt_l); 169 else 170 fprintf(stderr, "configuration OK\n"); 171 exit(0); 172 } 173 cflags = conf.flags; 174 connectset = &conf.connectset; 175 staticset = &conf.staticset; 176 connectset6 = &conf.connectset6; 177 staticset6 = &conf.staticset6; 178 179 if (geteuid()) 180 errx(1, "need root privileges"); 181 182 if (getpwnam(BGPD_USER) == NULL) 183 errx(1, "unknown user %s", BGPD_USER); 184 185 log_init(debug); 186 187 if (!debug) 188 daemon(1, 0); 189 190 log_info("startup"); 191 192 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_m2s) == -1) 193 fatal("socketpair"); 194 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_m2r) == -1) 195 fatal("socketpair"); 196 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_s2r) == -1) 197 fatal("socketpair"); 198 session_socket_blockmode(pipe_m2s[0], BM_NONBLOCK); 199 session_socket_blockmode(pipe_m2s[1], BM_NONBLOCK); 200 session_socket_blockmode(pipe_m2r[0], BM_NONBLOCK); 201 session_socket_blockmode(pipe_m2r[1], BM_NONBLOCK); 202 session_socket_blockmode(pipe_s2r[0], BM_NONBLOCK); 203 session_socket_blockmode(pipe_s2r[1], BM_NONBLOCK); 204 205 prepare_listeners(&conf); 206 207 /* fork children */ 208 rde_pid = rde_main(&conf, peer_l, &net_l, rules_l, &mrt_l, 209 pipe_m2r, pipe_s2r, pipe_m2s); 210 io_pid = session_main(&conf, peer_l, &net_l, rules_l, &mrt_l, 211 pipe_m2s, pipe_s2r, pipe_m2r); 212 213 setproctitle("parent"); 214 215 signal(SIGTERM, sighdlr); 216 signal(SIGINT, sighdlr); 217 signal(SIGCHLD, sighdlr); 218 signal(SIGHUP, sighdlr); 219 signal(SIGALRM, sighdlr); 220 signal(SIGUSR1, sighdlr); 221 222 close(pipe_m2s[1]); 223 close(pipe_m2r[1]); 224 close(pipe_s2r[0]); 225 close(pipe_s2r[1]); 226 227 if ((ibuf_se = malloc(sizeof(struct imsgbuf))) == NULL || 228 (ibuf_rde = malloc(sizeof(struct imsgbuf))) == NULL) 229 fatal(NULL); 230 imsg_init(ibuf_se, pipe_m2s[0]); 231 imsg_init(ibuf_rde, pipe_m2r[0]); 232 mrt_init(ibuf_rde, ibuf_se); 233 if ((rfd = kr_init(!(conf.flags & BGPD_FLAG_NO_FIB_UPDATE))) == -1) 234 quit = 1; 235 if (pftable_clear_all() != 0) 236 quit = 1; 237 238 while ((net = TAILQ_FIRST(&net_l)) != NULL) { 239 TAILQ_REMOVE(&net_l, net, entry); 240 filterset_free(&net->net.attrset); 241 free(net); 242 } 243 244 while ((r = TAILQ_FIRST(rules_l)) != NULL) { 245 TAILQ_REMOVE(rules_l, r, entry); 246 free(r); 247 } 248 TAILQ_FOREACH(la, conf.listen_addrs, entry) { 249 close(la->fd); 250 la->fd = -1; 251 } 252 253 mrt_reconfigure(&mrt_l); 254 255 while (quit == 0) { 256 bzero(pfd, sizeof(pfd)); 257 pfd[PFD_PIPE_SESSION].fd = ibuf_se->fd; 258 pfd[PFD_PIPE_SESSION].events = POLLIN; 259 if (ibuf_se->w.queued) 260 pfd[PFD_PIPE_SESSION].events |= POLLOUT; 261 pfd[PFD_PIPE_ROUTE].fd = ibuf_rde->fd; 262 pfd[PFD_PIPE_ROUTE].events = POLLIN; 263 if (ibuf_rde->w.queued) 264 pfd[PFD_PIPE_ROUTE].events |= POLLOUT; 265 pfd[PFD_SOCK_ROUTE].fd = rfd; 266 pfd[PFD_SOCK_ROUTE].events = POLLIN; 267 268 timeout = mrt_timeout(&mrt_l); 269 if (timeout > MAX_TIMEOUT) 270 timeout = MAX_TIMEOUT; 271 272 if ((nfds = poll(pfd, POLL_MAX, timeout * 1000)) == -1) 273 if (errno != EINTR) { 274 log_warn("poll error"); 275 quit = 1; 276 } 277 278 if (reconfig) { 279 reconfig = 0; 280 log_info("rereading config"); 281 reconfigure(conffile, &conf, &mrt_l, &peer_l, rules_l); 282 } 283 284 if (sigchld) { 285 sigchld = 0; 286 if (check_child(io_pid, "session engine")) { 287 quit = 1; 288 io_pid = 0; 289 } 290 if (check_child(rde_pid, "route decision engine")) { 291 quit = 1; 292 rde_pid = 0; 293 } 294 } 295 296 if (mrtdump == 1) { 297 mrtdump = 0; 298 mrt_handler(&mrt_l); 299 } 300 301 if (nfds == -1 || nfds == 0) 302 continue; 303 304 if (pfd[PFD_PIPE_SESSION].revents & POLLOUT) 305 if (msgbuf_write(&ibuf_se->w) < 0) { 306 log_warn("pipe write error (to SE)"); 307 quit = 1; 308 } 309 310 if (pfd[PFD_PIPE_ROUTE].revents & POLLOUT) 311 if (msgbuf_write(&ibuf_rde->w) < 0) { 312 log_warn("pipe write error (to RDE)"); 313 quit = 1; 314 } 315 316 if (pfd[PFD_PIPE_SESSION].revents & POLLIN) { 317 if (dispatch_imsg(ibuf_se, PFD_PIPE_SESSION) == -1) 318 quit = 1; 319 } 320 321 if (pfd[PFD_PIPE_ROUTE].revents & POLLIN) { 322 if (dispatch_imsg(ibuf_rde, PFD_PIPE_ROUTE) == -1) 323 quit = 1; 324 } 325 326 if (pfd[PFD_SOCK_ROUTE].revents & POLLIN) { 327 if (kr_dispatch_msg() == -1) 328 quit = 1; 329 } 330 } 331 332 signal(SIGCHLD, SIG_IGN); 333 334 if (io_pid) 335 kill(io_pid, SIGTERM); 336 337 if (rde_pid) 338 kill(rde_pid, SIGTERM); 339 340 while ((p = peer_l) != NULL) { 341 peer_l = p->next; 342 free(p); 343 } 344 while ((m = LIST_FIRST(&mrt_l)) != NULL) { 345 LIST_REMOVE(m, entry); 346 free(m); 347 } 348 while ((la = TAILQ_FIRST(conf.listen_addrs)) != NULL) { 349 TAILQ_REMOVE(conf.listen_addrs, la, entry); 350 close(la->fd); 351 free(la); 352 } 353 354 free(rules_l); 355 control_cleanup(); 356 kr_shutdown(); 357 pftable_clear_all(); 358 free(conf.listen_addrs); 359 360 do { 361 if ((pid = wait(NULL)) == -1 && 362 errno != EINTR && errno != ECHILD) 363 fatal("wait"); 364 } while (pid != -1 || (pid == -1 && errno == EINTR)); 365 366 msgbuf_clear(&ibuf_se->w); 367 free(ibuf_se); 368 msgbuf_clear(&ibuf_rde->w); 369 free(ibuf_rde); 370 371 log_info("Terminating"); 372 return (0); 373} 374 375int 376check_child(pid_t pid, const char *pname) 377{ 378 int status; 379 380 if (waitpid(pid, &status, WNOHANG) > 0) { 381 if (WIFEXITED(status)) { 382 log_warnx("Lost child: %s exited", pname); 383 return (1); 384 } 385 if (WIFSIGNALED(status)) { 386 log_warnx("Lost child: %s terminated; signal %d", 387 pname, WTERMSIG(status)); 388 return (1); 389 } 390 } 391 392 return (0); 393} 394 395int 396send_filterset(struct imsgbuf *i, struct filter_set_head *set, int id) 397{ 398 struct filter_set *s; 399 400 TAILQ_FOREACH(s, set, entry) 401 if (imsg_compose(i, IMSG_FILTER_SET, id, 0, -1, s, 402 sizeof(struct filter_set)) == -1) 403 return (-1); 404 return (0); 405} 406 407int 408reconfigure(char *conffile, struct bgpd_config *conf, struct mrt_head *mrt_l, 409 struct peer **peer_l, struct filter_head *rules_l) 410{ 411 struct network_head net_l; 412 struct network *n; 413 struct peer *p; 414 struct filter_rule *r; 415 struct listen_addr *la; 416 417 if (parse_config(conffile, conf, mrt_l, peer_l, &net_l, rules_l)) { 418 log_warnx("config file %s has errors, not reloading", 419 conffile); 420 return (-1); 421 } 422 423 cflags = conf->flags; 424 connectset = &conf->connectset; 425 staticset = &conf->staticset; 426 connectset6 = &conf->connectset6; 427 staticset6 = &conf->staticset6; 428 429 prepare_listeners(conf); 430 431 /* start reconfiguration */ 432 if (imsg_compose(ibuf_se, IMSG_RECONF_CONF, 0, 0, -1, 433 conf, sizeof(struct bgpd_config)) == -1) 434 return (-1); 435 if (imsg_compose(ibuf_rde, IMSG_RECONF_CONF, 0, 0, -1, 436 conf, sizeof(struct bgpd_config)) == -1) 437 return (-1); 438 439 /* send peer list and listeners to the SE */ 440 for (p = *peer_l; p != NULL; p = p->next) 441 if (imsg_compose(ibuf_se, IMSG_RECONF_PEER, p->conf.id, 0, -1, 442 &p->conf, sizeof(struct peer_config)) == -1) 443 return (-1); 444 445 TAILQ_FOREACH(la, conf->listen_addrs, entry) { 446 if (imsg_compose(ibuf_se, IMSG_RECONF_LISTENER, 0, 0, la->fd, 447 la, sizeof(struct listen_addr)) == -1) 448 return (-1); 449 la->fd = -1; 450 } 451 452 /* networks for the RDE */ 453 while ((n = TAILQ_FIRST(&net_l)) != NULL) { 454 if (imsg_compose(ibuf_rde, IMSG_NETWORK_ADD, 0, 0, -1, 455 &n->net, sizeof(struct network_config)) == -1) 456 return (-1); 457 if (send_filterset(ibuf_rde, &n->net.attrset, 0) == -1) 458 return (-1); 459 if (imsg_compose(ibuf_rde, IMSG_NETWORK_DONE, 0, 0, -1, 460 NULL, 0) == -1) 461 return (-1); 462 TAILQ_REMOVE(&net_l, n, entry); 463 filterset_free(&n->net.attrset); 464 free(n); 465 } 466 467 /* redistribute list needs to be reloaded too */ 468 if (kr_redist_reload() == -1) 469 return (-1); 470 471 /* filters for the RDE */ 472 while ((r = TAILQ_FIRST(rules_l)) != NULL) { 473 if (imsg_compose(ibuf_rde, IMSG_RECONF_FILTER, 0, 0, -1, 474 r, sizeof(struct filter_rule)) == -1) 475 return (-1); 476 if (send_filterset(ibuf_rde, &r->set, 0) == -1) 477 return (-1); 478 TAILQ_REMOVE(rules_l, r, entry); 479 filterset_free(&r->set); 480 free(r); 481 } 482 483 /* singal both childs to replace their config */ 484 if (imsg_compose(ibuf_se, IMSG_RECONF_DONE, 0, 0, -1, NULL, 0) == -1 || 485 imsg_compose(ibuf_rde, IMSG_RECONF_DONE, 0, 0, -1, NULL, 0) == -1) 486 return (-1); 487 488 /* mrt changes can be sent out of bound */ 489 mrt_reconfigure(mrt_l); 490 return (0); 491} 492 493int 494dispatch_imsg(struct imsgbuf *ibuf, int idx) 495{ 496 struct imsg imsg; 497 int n; 498 int rv; 499 500 if ((n = imsg_read(ibuf)) == -1) 501 return (-1); 502 503 if (n == 0) { /* connection closed */ 504 log_warnx("dispatch_imsg in main: pipe closed"); 505 return (-1); 506 } 507 508 rv = 0; 509 for (;;) { 510 if ((n = imsg_get(ibuf, &imsg)) == -1) 511 return (-1); 512 513 if (n == 0) 514 break; 515 516 switch (imsg.hdr.type) { 517 case IMSG_KROUTE_CHANGE: 518 if (idx != PFD_PIPE_ROUTE) 519 log_warnx("route request not from RDE"); 520 else if (kr_change(imsg.data)) 521 rv = -1; 522 break; 523 case IMSG_KROUTE_DELETE: 524 if (idx != PFD_PIPE_ROUTE) 525 log_warnx("route request not from RDE"); 526 else if (kr_delete(imsg.data)) 527 rv = -1; 528 break; 529 case IMSG_KROUTE6_CHANGE: 530 if (idx != PFD_PIPE_ROUTE) 531 log_warnx("route request not from RDE"); 532 else if (kr6_change(imsg.data)) 533 rv = -1; 534 break; 535 case IMSG_KROUTE6_DELETE: 536 if (idx != PFD_PIPE_ROUTE) 537 log_warnx("route request not from RDE"); 538 else if (kr6_delete(imsg.data)) 539 rv = -1; 540 break; 541 case IMSG_NEXTHOP_ADD: 542 if (idx != PFD_PIPE_ROUTE) 543 log_warnx("nexthop request not from RDE"); 544 else 545 if (imsg.hdr.len != IMSG_HEADER_SIZE + 546 sizeof(struct bgpd_addr)) 547 log_warnx("wrong imsg len"); 548 else if (kr_nexthop_add(imsg.data) == -1) 549 rv = -1; 550 break; 551 case IMSG_NEXTHOP_REMOVE: 552 if (idx != PFD_PIPE_ROUTE) 553 log_warnx("nexthop request not from RDE"); 554 else 555 if (imsg.hdr.len != IMSG_HEADER_SIZE + 556 sizeof(struct bgpd_addr)) 557 log_warnx("wrong imsg len"); 558 else 559 kr_nexthop_delete(imsg.data); 560 break; 561 case IMSG_PFTABLE_ADD: 562 if (idx != PFD_PIPE_ROUTE) 563 log_warnx("pftable request not from RDE"); 564 else 565 if (imsg.hdr.len != IMSG_HEADER_SIZE + 566 sizeof(struct pftable_msg)) 567 log_warnx("wrong imsg len"); 568 else if (pftable_addr_add(imsg.data) != 0) 569 rv = -1; 570 break; 571 case IMSG_PFTABLE_REMOVE: 572 if (idx != PFD_PIPE_ROUTE) 573 log_warnx("pftable request not from RDE"); 574 else 575 if (imsg.hdr.len != IMSG_HEADER_SIZE + 576 sizeof(struct pftable_msg)) 577 log_warnx("wrong imsg len"); 578 else if (pftable_addr_remove(imsg.data) != 0) 579 rv = -1; 580 break; 581 case IMSG_PFTABLE_COMMIT: 582 if (idx != PFD_PIPE_ROUTE) 583 log_warnx("pftable request not from RDE"); 584 else 585 if (imsg.hdr.len != IMSG_HEADER_SIZE) 586 log_warnx("wrong imsg len"); 587 else if (pftable_commit() != 0) 588 rv = -1; 589 break; 590 case IMSG_CTL_RELOAD: 591 if (idx != PFD_PIPE_SESSION) 592 log_warnx("reload request not from SE"); 593 else 594 reconfig = 1; 595 break; 596 case IMSG_CTL_FIB_COUPLE: 597 if (idx != PFD_PIPE_SESSION) 598 log_warnx("couple request not from SE"); 599 else 600 kr_fib_couple(); 601 break; 602 case IMSG_CTL_FIB_DECOUPLE: 603 if (idx != PFD_PIPE_SESSION) 604 log_warnx("decouple request not from SE"); 605 else 606 kr_fib_decouple(); 607 break; 608 case IMSG_CTL_KROUTE: 609 case IMSG_CTL_KROUTE_ADDR: 610 case IMSG_CTL_SHOW_NEXTHOP: 611 case IMSG_CTL_SHOW_INTERFACE: 612 if (idx != PFD_PIPE_SESSION) 613 log_warnx("kroute request not from SE"); 614 else 615 kr_show_route(&imsg); 616 break; 617 case IMSG_IFINFO: 618 if (idx != PFD_PIPE_SESSION) 619 log_warnx("IFINFO request not from SE"); 620 else if (imsg.hdr.len != IMSG_HEADER_SIZE + IFNAMSIZ) 621 log_warnx("IFINFO request with wrong len"); 622 else 623 kr_ifinfo(imsg.data); 624 break; 625 default: 626 break; 627 } 628 imsg_free(&imsg); 629 if (rv != 0) 630 return (rv); 631 } 632 return (0); 633} 634 635void 636send_nexthop_update(struct kroute_nexthop *msg) 637{ 638 char *gw = NULL; 639 640 if (msg->gateway.af) 641 if (asprintf(&gw, ": via %s", 642 log_addr(&msg->gateway)) == -1) { 643 log_warn("send_nexthop_update"); 644 quit = 1; 645 } 646 647 log_info("nexthop %s now %s%s%s", log_addr(&msg->nexthop), 648 msg->valid ? "valid" : "invalid", 649 msg->connected ? ": directly connected" : "", 650 msg->gateway.af ? gw : ""); 651 652 free(gw); 653 654 if (imsg_compose(ibuf_rde, IMSG_NEXTHOP_UPDATE, 0, 0, -1, 655 msg, sizeof(struct kroute_nexthop)) == -1) 656 quit = 1; 657} 658 659void 660send_imsg_session(int type, pid_t pid, void *data, u_int16_t datalen) 661{ 662 imsg_compose(ibuf_se, type, 0, pid, -1, data, datalen); 663} 664 665int 666bgpd_redistribute(int type, struct kroute *kr, struct kroute6 *kr6) 667{ 668 struct network_config net; 669 struct filter_set_head *h; 670 671 if ((cflags & BGPD_FLAG_REDIST_CONNECTED) && kr && 672 (kr->flags & F_CONNECTED)) 673 h = connectset; 674 else if ((cflags & BGPD_FLAG_REDIST_STATIC) && kr && 675 (kr->flags & F_STATIC)) 676 h = staticset; 677 else if ((cflags & BGPD_FLAG_REDIST6_CONNECTED) && kr6 && 678 (kr6->flags & F_CONNECTED)) 679 h = connectset6; 680 else if ((cflags & BGPD_FLAG_REDIST6_STATIC) && kr6 && 681 (kr6->flags & F_STATIC)) 682 h = staticset6; 683 else 684 return (0); 685 686 bzero(&net, sizeof(net)); 687 if (kr && kr6) 688 fatalx("bgpd_redistribute: unable to redistribute v4 and v6" 689 "together"); 690 if (kr != NULL) { 691 net.prefix.af = AF_INET; 692 net.prefix.v4.s_addr = kr->prefix.s_addr; 693 net.prefixlen = kr->prefixlen; 694 } 695 if (kr6 != NULL) { 696 net.prefix.af = AF_INET6; 697 memcpy(&net.prefix.v6, &kr6->prefix, sizeof(struct in6_addr)); 698 net.prefixlen = kr6->prefixlen; 699 } 700 701 702 if (imsg_compose(ibuf_rde, type, 0, 0, -1, &net, 703 sizeof(struct network_config)) == -1) 704 return (-1); 705 706 /* networks that get deleted don't need to send the filter set */ 707 if (type == IMSG_NETWORK_REMOVE) 708 return (1); 709 710 if (send_filterset(ibuf_rde, h, 0) == -1) 711 return (-1); 712 if (imsg_compose(ibuf_rde, IMSG_NETWORK_DONE, 0, 0, -1, NULL, 0) == -1) 713 return (-1); 714 715 return (1); 716} 717 718