From 6ec75fbe5bd7d4b229f16453c61ba50b06d2760a Mon Sep 17 00:00:00 2001 From: claudio Date: Thu, 9 Jun 2022 16:45:19 +0000 Subject: [PATCH] Remove the rdomain / rtableid passed to some kroute functions. kr_nexthop_add() and kr_nexthop_delete() only operate on the main table so just pass in the right rdomain id. kr_shutdown() and kr_dispatch_msg() don't really need the rdomain passed. The was done for kif_remove(), since that function needs to remove connected routes from the rdomain table. Connected routes can only exists in the interfaces rdomain so just use kif->k.rdomain. If such routes exist that table exists as well. If the table does not exists there are also no connected routes to track. OK tb@ --- usr.sbin/bgpd/bgpd.c | 22 ++++++++++------- usr.sbin/bgpd/bgpd.h | 12 ++++----- usr.sbin/bgpd/kroute.c | 55 ++++++++++++++++++------------------------ 3 files changed, 41 insertions(+), 48 deletions(-) diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index ef989046b01..0fa941e040e 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.244 2022/06/05 12:43:13 claudio Exp $ */ +/* $OpenBSD: bgpd.c,v 1.245 2022/06/09 16:45:19 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -388,7 +388,7 @@ BROKEN if (pledge("stdio rpath wpath cpath fattr unix route recvfd sendfd", } if (pfd[PFD_SOCK_ROUTE].revents & POLLIN) { - if (kr_dispatch_msg(conf->default_tableid) == -1) + if (kr_dispatch_msg() == -1) quit = 1; } @@ -460,7 +460,7 @@ BROKEN if (pledge("stdio rpath wpath cpath fattr unix route recvfd sendfd", /* cleanup kernel data structures */ carp_demote_shutdown(); - kr_shutdown(conf->default_tableid); + kr_shutdown(); pftable_clear_all(); RB_FOREACH(p, peer_head, &conf->peers) @@ -800,6 +800,7 @@ dispatch_imsg(struct imsgbuf *ibuf, int idx, struct bgpd_config *conf) struct peer *p; struct rtr_config *r; ssize_t n; + u_int rtableid; int rv, verbose; rv = 0; @@ -843,9 +844,11 @@ dispatch_imsg(struct imsgbuf *ibuf, int idx, struct bgpd_config *conf) else if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct bgpd_addr)) log_warnx("wrong imsg len"); - else if (kr_nexthop_add(imsg.hdr.peerid, imsg.data, - conf) == -1) - rv = -1; + else { + rtableid = conf->default_tableid; + if (kr_nexthop_add(rtableid, imsg.data) == -1) + rv = -1; + } break; case IMSG_NEXTHOP_REMOVE: if (idx != PFD_PIPE_RDE) @@ -853,9 +856,10 @@ dispatch_imsg(struct imsgbuf *ibuf, int idx, struct bgpd_config *conf) else if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct bgpd_addr)) log_warnx("wrong imsg len"); - else - kr_nexthop_delete(imsg.hdr.peerid, imsg.data, - conf); + else { + rtableid = conf->default_tableid; + kr_nexthop_delete(rtableid, imsg.data); + } break; case IMSG_PFTABLE_ADD: if (idx != PFD_PIPE_RDE) diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 29181ce6e13..91fb68c04c4 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.427 2022/06/07 15:57:47 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.428 2022/06/09 16:45:19 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -1291,17 +1291,15 @@ int ktable_exists(u_int, u_int *); int kr_change(u_int, struct kroute_full *); int kr_delete(u_int, struct kroute_full *); int kr_flush(u_int); -void kr_shutdown(u_int); +void kr_shutdown(void); void kr_fib_couple(u_int); void kr_fib_couple_all(void); void kr_fib_decouple(u_int); void kr_fib_decouple_all(void); void kr_fib_prio_set(uint8_t); -int kr_dispatch_msg(u_int rdomain); -int kr_nexthop_add(uint32_t, struct bgpd_addr *, - struct bgpd_config *); -void kr_nexthop_delete(uint32_t, struct bgpd_addr *, - struct bgpd_config *); +int kr_dispatch_msg(void); +int kr_nexthop_add(uint32_t, struct bgpd_addr *); +void kr_nexthop_delete(uint32_t, struct bgpd_addr *); void kr_show_route(struct imsg *); void kr_ifinfo(char *); void kr_net_reload(u_int, uint64_t, struct network_head *); diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c index 69201531f1b..18e587f747e 100644 --- a/usr.sbin/bgpd/kroute.c +++ b/usr.sbin/bgpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.251 2022/06/07 16:42:07 claudio Exp $ */ +/* $OpenBSD: kroute.c,v 1.252 2022/06/09 16:45:19 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -152,8 +152,8 @@ void knexthop_clear(struct ktable *); struct kif_node *kif_find(int); int kif_insert(struct kif_node *); -int kif_remove(struct kif_node *, u_int); -void kif_clear(u_int); +int kif_remove(struct kif_node *); +void kif_clear(void); int kif_kr_insert(struct kroute_node *); int kif_kr_remove(struct kroute_node *); @@ -180,12 +180,12 @@ uint64_t ift2ifm(uint8_t); const char *get_media_descr(uint64_t); const char *get_linkstate(uint8_t, int); void get_rtaddrs(int, struct sockaddr *, struct sockaddr **); -void if_change(u_short, int, struct if_data *, u_int); -void if_announce(void *, u_int); +void if_change(u_short, int, struct if_data *); +void if_announce(void *); int send_rtmsg(int, int, struct ktable *, struct kroute *); int send_rt6msg(int, int, struct ktable *, struct kroute6 *); -int dispatch_rtmsg(u_int); +int dispatch_rtmsg(void); int fetchtable(struct ktable *); int fetchifs(int); int dispatch_rtmsg_addr(struct rt_msghdr *, @@ -882,13 +882,13 @@ krVPN6_delete(struct ktable *kt, struct kroute_full *kl) } void -kr_shutdown(u_int rdomain) +kr_shutdown(void) { u_int i; for (i = krt_size; i > 0; i--) ktable_free(i - 1); - kif_clear(rdomain); + kif_clear(); free(krt); } @@ -969,20 +969,17 @@ kr_fib_prio_set(uint8_t prio) } int -kr_dispatch_msg(u_int rdomain) +kr_dispatch_msg(void) { - return (dispatch_rtmsg(rdomain)); + return (dispatch_rtmsg()); } int -kr_nexthop_add(u_int rtableid, struct bgpd_addr *addr, struct bgpd_config *conf) +kr_nexthop_add(u_int rtableid, struct bgpd_addr *addr) { struct ktable *kt; struct knexthop_node *h; - if (rtableid == 0) - rtableid = conf->default_tableid; - if ((kt = ktable_get(rtableid)) == NULL) { log_warnx("%s: non-existent rtableid %d", __func__, rtableid); return (0); @@ -1005,15 +1002,11 @@ kr_nexthop_add(u_int rtableid, struct bgpd_addr *addr, struct bgpd_config *conf) } void -kr_nexthop_delete(u_int rtableid, struct bgpd_addr *addr, - struct bgpd_config *conf) +kr_nexthop_delete(u_int rtableid, struct bgpd_addr *addr) { struct ktable *kt; struct knexthop_node *kn; - if (rtableid == 0) - rtableid = conf->default_tableid; - if ((kt = ktable_get(rtableid)) == NULL) { log_warnx("%s: non-existent rtableid %d", __func__, rtableid); @@ -2140,7 +2133,7 @@ kif_insert(struct kif_node *kif) } int -kif_remove(struct kif_node *kif, u_int rdomain) +kif_remove(struct kif_node *kif) { struct ktable *kt; struct kif_kr *kkr; @@ -2151,7 +2144,7 @@ kif_remove(struct kif_node *kif, u_int rdomain) return (-1); } - if ((kt = ktable_get(rdomain)) == NULL) + if ((kt = ktable_get(kif->k.rdomain)) == NULL) goto done; while ((kkr = LIST_FIRST(&kif->kroute_l)) != NULL) { @@ -2173,12 +2166,12 @@ done: } void -kif_clear(u_int rdomain) +kif_clear(void) { struct kif_node *kif; while ((kif = RB_MIN(kif_tree, &kit)) != NULL) - kif_remove(kif, rdomain); + kif_remove(kif); } int @@ -2766,8 +2759,7 @@ get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info) } void -if_change(u_short ifindex, int flags, struct if_data *ifd, - u_int rdomain) +if_change(u_short ifindex, int flags, struct if_data *ifd) { struct ktable *kt; struct kif_node *kif; @@ -2802,7 +2794,7 @@ if_change(u_short ifindex, int flags, struct if_data *ifd, kif->k.nh_reachable = reachable; - kt = ktable_get(rdomain); + kt = ktable_get(ifd->ifi_rdomain); LIST_FOREACH(kkr, &kif->kroute_l, entry) { if (reachable) @@ -2829,7 +2821,7 @@ if_change(u_short ifindex, int flags, struct if_data *ifd, } void -if_announce(void *msg, u_int rdomain) +if_announce(void *msg) { struct if_announcemsghdr *ifan; struct kif_node *kif; @@ -2849,7 +2841,7 @@ if_announce(void *msg, u_int rdomain) break; case IFAN_DEPARTURE: kif = kif_find(ifan->ifan_index); - kif_remove(kif, rdomain); + kif_remove(kif); break; } } @@ -3447,7 +3439,7 @@ fetchifs(int ifindex) } int -dispatch_rtmsg(u_int rdomain) +dispatch_rtmsg(void) { char buf[RT_BUF_SIZE]; ssize_t n; @@ -3502,11 +3494,10 @@ dispatch_rtmsg(u_int rdomain) break; case RTM_IFINFO: memcpy(&ifm, next, sizeof(ifm)); - if_change(ifm.ifm_index, ifm.ifm_flags, - &ifm.ifm_data, rdomain); + if_change(ifm.ifm_index, ifm.ifm_flags, &ifm.ifm_data); break; case RTM_IFANNOUNCE: - if_announce(next, rdomain); + if_announce(next); break; default: /* ignore for now */ -- 2.20.1