From 35cadacd2bb9383686753731e31bd7e145fb2506 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 06:24:32 +0200 Subject: Merging upstream version 10.0. Signed-off-by: Daniel Baumann --- nhrpd/linux.c | 21 +-------------------- nhrpd/netlink.h | 1 - nhrpd/netlink_arp.c | 26 +++++++++++++++++++------- nhrpd/nhrp_cache.c | 2 ++ nhrpd/nhrp_interface.c | 4 ++-- nhrpd/nhrp_main.c | 25 +++++++++++++++++-------- nhrpd/nhrp_multicast.c | 4 ++++ nhrpd/nhrp_packet.c | 2 +- nhrpd/nhrp_peer.c | 9 +++++---- nhrpd/nhrp_route.c | 47 ++++++++++++++++++----------------------------- nhrpd/nhrp_vc.c | 1 + nhrpd/nhrpd.h | 2 +- nhrpd/vici.c | 1 + 13 files changed, 72 insertions(+), 73 deletions(-) (limited to 'nhrpd') diff --git a/nhrpd/linux.c b/nhrpd/linux.c index eb98166..e4df0dd 100644 --- a/nhrpd/linux.c +++ b/nhrpd/linux.c @@ -5,6 +5,7 @@ #include "zebra.h" +#include #include #include @@ -96,25 +97,6 @@ int os_recvmsg(uint8_t *buf, size_t *len, int *ifindex, uint8_t *addr, return 0; } -static int linux_configure_arp(const char *iface, int on) -{ - struct ifreq ifr; - - strlcpy(ifr.ifr_name, iface, IFNAMSIZ); - if (ioctl(nhrp_socket_fd, SIOCGIFFLAGS, &ifr)) - return -1; - - if (on) - ifr.ifr_flags &= ~IFF_NOARP; - else - ifr.ifr_flags |= IFF_NOARP; - - if (ioctl(nhrp_socket_fd, SIOCSIFFLAGS, &ifr)) - return -1; - - return 0; -} - static int linux_icmp_redirect_off(const char *iface) { char fname[PATH_MAX]; @@ -142,7 +124,6 @@ int os_configure_dmvpn(unsigned int ifindex, const char *ifname, int af) ret |= linux_icmp_redirect_off(ifname); break; } - ret |= linux_configure_arp(ifname, 1); return ret; } diff --git a/nhrpd/netlink.h b/nhrpd/netlink.h index 7a3029b..33af1a0 100644 --- a/nhrpd/netlink.h +++ b/nhrpd/netlink.h @@ -11,7 +11,6 @@ extern int netlink_nflog_group; extern int netlink_mcast_nflog_group; -int netlink_configure_arp(unsigned int ifindex, int pf); void netlink_update_binding(struct interface *ifp, union sockunion *proto, union sockunion *nbma); void netlink_set_nflog_group(int nlgroup); diff --git a/nhrpd/netlink_arp.c b/nhrpd/netlink_arp.c index 2e22f8e..be909c8 100644 --- a/nhrpd/netlink_arp.c +++ b/nhrpd/netlink_arp.c @@ -7,6 +7,10 @@ #include "config.h" #endif +#ifdef GNU_LINUX +#include +#endif + #include #include #include @@ -150,6 +154,10 @@ int nhrp_neighbor_operation(ZAPI_CALLBACK_ARGS) struct zapi_neigh_ip api = {}; zclient_neigh_ip_decode(zclient->ibuf, &api); + + if (api.ip_len != IPV4_MAX_BYTELEN && api.ip_len != 0) + return 0; + if (api.ip_in.ipa_type == AF_UNSPEC) return 0; sockunion_family(&addr) = api.ip_in.ipa_type; @@ -172,26 +180,30 @@ int nhrp_neighbor_operation(ZAPI_CALLBACK_ARGS) return 0; debugf(NHRP_DEBUG_KERNEL, "Netlink: %s %pSU dev %s lladdr %pSU nud 0x%x cache used %u type %u", - (cmd == ZEBRA_NHRP_NEIGH_GET) - ? "who-has" - : (cmd == ZEBRA_NHRP_NEIGH_ADDED) ? "new-neigh" - : "del-neigh", + (cmd == ZEBRA_NEIGH_GET) ? "who-has" + : (cmd == ZEBRA_NEIGH_ADDED) ? "new-neigh" + : "del-neigh", &addr, ifp->name, &lladdr, ndm_state, c->used, c->cur.type); - if (cmd == ZEBRA_NHRP_NEIGH_GET) { + if (cmd == ZEBRA_NEIGH_GET) { if (c->cur.type >= NHRP_CACHE_CACHED) { nhrp_cache_set_used(c, 1); debugf(NHRP_DEBUG_KERNEL, "Netlink: update binding for %pSU dev %s from c %pSU peer.vc.nbma %pSU to lladdr %pSU", &addr, ifp->name, &c->cur.remote_nbma_natoa, &c->cur.peer->vc->remote.nbma, &lladdr); + + if (lladdr.sa.sa_family == AF_UNSPEC) + /* nothing from zebra, so use nhrp peer */ + lladdr = c->cur.peer->vc->remote.nbma; + /* In case of shortcuts, nbma is given by lladdr, not * vc->remote.nbma. */ netlink_update_binding(ifp, &addr, &lladdr); } } else { - state = (cmd == ZEBRA_NHRP_NEIGH_ADDED) ? ndm_state - : ZEBRA_NEIGH_STATE_FAILED; + state = (cmd == ZEBRA_NEIGH_ADDED) ? ndm_state + : ZEBRA_NEIGH_STATE_FAILED; nhrp_cache_set_used(c, state == ZEBRA_NEIGH_STATE_REACHABLE); } return 0; diff --git a/nhrpd/nhrp_cache.c b/nhrpd/nhrp_cache.c index 1a11e0d..e0b8f7b 100644 --- a/nhrpd/nhrp_cache.c +++ b/nhrpd/nhrp_cache.c @@ -70,6 +70,8 @@ static void nhrp_cache_free(struct nhrp_cache *c) notifier_call(&c->notifier_list, NOTIFY_CACHE_DELETE); assert(!notifier_active(&c->notifier_list)); hash_release(nifp->cache_hash, c); + if (c->cur.peer) + nhrp_peer_notify_del(c->cur.peer, &c->peer_notifier); nhrp_peer_unref(c->cur.peer); nhrp_peer_unref(c->new.peer); EVENT_OFF(c->t_timeout); diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c index 7c84fde..7d0ab97 100644 --- a/nhrpd/nhrp_interface.c +++ b/nhrpd/nhrp_interface.c @@ -259,13 +259,12 @@ static void nhrp_interface_update_address(struct interface *ifp, afi_t afi, struct nhrp_afi_data *if_ad = &nifp->afi[afi]; struct nhrp_cache *nc; struct connected *c, *best; - struct listnode *cnode; union sockunion addr; char buf[PREFIX_STRLEN]; /* Select new best match preferring primary address */ best = NULL; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { + frr_each (if_connected, ifp->connected, c) { if (PREFIX_FAMILY(c->address) != family) continue; if (best == NULL) { @@ -352,6 +351,7 @@ void nhrp_interface_update(struct interface *ifp) if (!if_ad->configured) { os_configure_dmvpn(ifp->ifindex, ifp->name, afi2family(afi)); + nhrp_interface_update_arp(ifp, true); nhrp_send_zebra_configure_arp(ifp, afi2family(afi)); if_ad->configured = 1; nhrp_interface_update_address(ifp, afi, 1); diff --git a/nhrpd/nhrp_main.c b/nhrpd/nhrp_main.c index 593498c..adb8be3 100644 --- a/nhrpd/nhrp_main.c +++ b/nhrpd/nhrp_main.c @@ -88,10 +88,12 @@ static void nhrp_request_stop(void) nhrp_zebra_terminate(); vici_terminate(); evmgr_terminate(); - nhrp_vc_terminate(); vrf_terminate(); + nhrp_vc_terminate(); debugf(NHRP_DEBUG_COMMON, "Done."); + + resolver_terminate(); frr_fini(); exit(0); @@ -118,15 +120,20 @@ static const struct frr_yang_module_info *const nhrpd_yang_modules[] = { &frr_vrf_info, }; -FRR_DAEMON_INFO(nhrpd, NHRP, .vty_port = NHRP_VTY_PORT, +/* clang-format off */ +FRR_DAEMON_INFO(nhrpd, NHRP, + .vty_port = NHRP_VTY_PORT, + .proghelp = "Implementation of the NHRP routing protocol.", - .proghelp = "Implementation of the NHRP routing protocol.", + .signals = sighandlers, + .n_signals = array_size(sighandlers), - .signals = sighandlers, .n_signals = array_size(sighandlers), + .privs = &nhrpd_privs, - .privs = &nhrpd_privs, .yang_modules = nhrpd_yang_modules, - .n_yang_modules = array_size(nhrpd_yang_modules), + .yang_modules = nhrpd_yang_modules, + .n_yang_modules = array_size(nhrpd_yang_modules), ); +/* clang-format on */ int main(int argc, char **argv) { @@ -155,8 +162,10 @@ int main(int argc, char **argv) nhrp_vc_init(); nhrp_packet_init(); vici_init(); - if_zapi_callbacks(nhrp_ifp_create, nhrp_ifp_up, - nhrp_ifp_down, nhrp_ifp_destroy); + hook_register_prio(if_real, 0, nhrp_ifp_create); + hook_register_prio(if_up, 0, nhrp_ifp_up); + hook_register_prio(if_down, 0, nhrp_ifp_down); + hook_register_prio(if_unreal, 0, nhrp_ifp_destroy); nhrp_zebra_init(); nhrp_shortcut_init(); diff --git a/nhrpd/nhrp_multicast.c b/nhrpd/nhrp_multicast.c index fdc1a31..aead982 100644 --- a/nhrpd/nhrp_multicast.c +++ b/nhrpd/nhrp_multicast.c @@ -7,6 +7,10 @@ #include "config.h" #endif +#ifdef GNU_LINUX +#include +#endif + #include #include #include diff --git a/nhrpd/nhrp_packet.c b/nhrpd/nhrp_packet.c index 9d0b30c..c6bd3bb 100644 --- a/nhrpd/nhrp_packet.c +++ b/nhrpd/nhrp_packet.c @@ -270,7 +270,7 @@ int nhrp_ext_reply(struct zbuf *zb, struct nhrp_packet_header *hdr, default: if (type & NHRP_EXTENSION_FLAG_COMPULSORY) goto err; - /* fallthru */ + fallthrough; case NHRP_EXTENSION_FORWARD_TRANSIT_NHS: case NHRP_EXTENSION_REVERSE_TRANSIT_NHS: /* Supported compulsory extensions, and any diff --git a/nhrpd/nhrp_peer.c b/nhrpd/nhrp_peer.c index ffb6cf7..6e7857c 100644 --- a/nhrpd/nhrp_peer.c +++ b/nhrpd/nhrp_peer.c @@ -45,7 +45,8 @@ static void nhrp_peer_check_delete(struct nhrp_peer *p) EVENT_OFF(p->t_fallback); EVENT_OFF(p->t_timer); - hash_release(nifp->peer_hash, p); + if (nifp->peer_hash) + hash_release(nifp->peer_hash, p); nhrp_interface_notify_del(p->ifp, &p->ifp_notifier); nhrp_vc_notify_del(p->vc, &p->vc_notifier); XFREE(MTYPE_NHRP_PEER, p); @@ -139,7 +140,7 @@ static void nhrp_peer_ifp_notify(struct notifier_block *n, unsigned long cmd) nhrp_peer_vc_notify); __nhrp_peer_check(p); } - /* fallthru */ /* to post config update */ + fallthrough; /* to post config update */ case NOTIFY_INTERFACE_ADDRESS_CHANGED: notifier_call(&p->notifier_list, NOTIFY_PEER_IFCONFIG_CHANGED); break; @@ -1050,7 +1051,7 @@ static void nhrp_peer_forward(struct nhrp_peer *p, * append our selves to the transit NHS list */ goto err; - /* fallthru */ + fallthrough; case NHRP_EXTENSION_RESPONDER_ADDRESS: /* Supported compulsory extensions, and any * non-compulsory that is not explicitly handled, @@ -1220,7 +1221,7 @@ void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb) /* FIXME: send error-indication */ } } - /* fallthru */ /* FIXME: double check, is this correct? */ + fallthrough; /* FIXME: double check, is this correct? */ case NHRP_ROUTE_OFF_NBMA: if (packet_types[hdr->type].handler) { packet_types[hdr->type].handler(&pp); diff --git a/nhrpd/nhrp_route.c b/nhrpd/nhrp_route.c index 060e603..fd9090b 100644 --- a/nhrpd/nhrp_route.c +++ b/nhrpd/nhrp_route.c @@ -75,24 +75,6 @@ static void nhrp_route_update_zebra(const struct prefix *p, } } -static void nhrp_zebra_register_neigh(vrf_id_t vrf_id, afi_t afi, bool reg) -{ - struct stream *s; - - if (!zclient || zclient->sock < 0) - return; - - s = zclient->obuf; - stream_reset(s); - - zclient_create_header(s, reg ? ZEBRA_NHRP_NEIGH_REGISTER : - ZEBRA_NHRP_NEIGH_UNREGISTER, - vrf_id); - stream_putw(s, afi); - stream_putw_at(s, 0, stream_get_endp(s)); - zclient_send_message(zclient); -} - void nhrp_route_update_nhrp(const struct prefix *p, struct interface *ifp) { struct route_node *rn; @@ -368,8 +350,8 @@ static void nhrp_zebra_connected(struct zclient *zclient) ZEBRA_ROUTE_ALL, 0, VRF_DEFAULT); zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, ZEBRA_ROUTE_ALL, 0, VRF_DEFAULT); - nhrp_zebra_register_neigh(VRF_DEFAULT, AFI_IP, true); - nhrp_zebra_register_neigh(VRF_DEFAULT, AFI_IP6, true); + zclient_register_neigh(zclient, VRF_DEFAULT, AFI_IP, true); + zclient_register_neigh(zclient, VRF_DEFAULT, AFI_IP6, true); } static zclient_handler *const nhrp_handlers[] = { @@ -377,9 +359,9 @@ static zclient_handler *const nhrp_handlers[] = { [ZEBRA_INTERFACE_ADDRESS_DELETE] = nhrp_interface_address_delete, [ZEBRA_REDISTRIBUTE_ROUTE_ADD] = nhrp_route_read, [ZEBRA_REDISTRIBUTE_ROUTE_DEL] = nhrp_route_read, - [ZEBRA_NHRP_NEIGH_ADDED] = nhrp_neighbor_operation, - [ZEBRA_NHRP_NEIGH_REMOVED] = nhrp_neighbor_operation, - [ZEBRA_NHRP_NEIGH_GET] = nhrp_neighbor_operation, + [ZEBRA_NEIGH_ADDED] = nhrp_neighbor_operation, + [ZEBRA_NEIGH_REMOVED] = nhrp_neighbor_operation, + [ZEBRA_NEIGH_GET] = nhrp_neighbor_operation, [ZEBRA_GRE_UPDATE] = nhrp_gre_update, }; @@ -456,10 +438,11 @@ void nhrp_send_zebra_nbr(union sockunion *in, return; s = zclient->obuf; stream_reset(s); - zclient_neigh_ip_encode(s, out ? ZEBRA_NEIGH_IP_ADD : - ZEBRA_NEIGH_IP_DEL, in, out, - ifp, out ? ZEBRA_NEIGH_STATE_REACHABLE - : ZEBRA_NEIGH_STATE_FAILED); + zclient_neigh_ip_encode(s, out ? ZEBRA_NEIGH_IP_ADD : ZEBRA_NEIGH_IP_DEL, + in, out, ifp, + out ? ZEBRA_NEIGH_STATE_REACHABLE + : ZEBRA_NEIGH_STATE_FAILED, + 0); stream_putw_at(s, 0, stream_get_endp(s)); zclient_send_message(zclient); } @@ -469,10 +452,16 @@ int nhrp_send_zebra_gre_request(struct interface *ifp) return zclient_send_zebra_gre_request(zclient, ifp); } +void nhrp_interface_update_arp(struct interface *ifp, bool arp_enable) +{ + zclient_interface_set_arp(zclient, ifp, arp_enable); +} + + void nhrp_zebra_terminate(void) { - nhrp_zebra_register_neigh(VRF_DEFAULT, AFI_IP, false); - nhrp_zebra_register_neigh(VRF_DEFAULT, AFI_IP6, false); + zclient_register_neigh(zclient, VRF_DEFAULT, AFI_IP, false); + zclient_register_neigh(zclient, VRF_DEFAULT, AFI_IP6, false); zclient_stop(zclient); zclient_free(zclient); diff --git a/nhrpd/nhrp_vc.c b/nhrpd/nhrp_vc.c index 2c32014..6f3346c 100644 --- a/nhrpd/nhrp_vc.c +++ b/nhrpd/nhrp_vc.c @@ -214,4 +214,5 @@ void nhrp_vc_terminate(void) { nhrp_vc_reset(); hash_clean(nhrp_vc_hash, nhrp_vc_free); + hash_free(nhrp_vc_hash); } diff --git a/nhrpd/nhrpd.h b/nhrpd/nhrpd.h index 1421f0f..e389b74 100644 --- a/nhrpd/nhrpd.h +++ b/nhrpd/nhrpd.h @@ -16,7 +16,6 @@ DECLARE_MGROUP(NHRPD); #define NHRPD_DEFAULT_HOLDTIME 7200 -#define NHRP_VTY_PORT 2610 #define NHRP_DEFAULT_CONFIG "nhrpd.conf" extern struct event_loop *master; @@ -362,6 +361,7 @@ int sock_open_unix(const char *path); void nhrp_interface_init(void); void nhrp_interface_update(struct interface *ifp); +void nhrp_interface_update_arp(struct interface *ifp, bool arp_enable); void nhrp_interface_update_mtu(struct interface *ifp, afi_t afi); void nhrp_interface_update_nbma(struct interface *ifp, struct nhrp_gre_info *gre_info); diff --git a/nhrpd/vici.c b/nhrpd/vici.c index 2f76362..8162ac0 100644 --- a/nhrpd/vici.c +++ b/nhrpd/vici.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "frrevent.h" #include "zbuf.h" -- cgit v1.2.3