From a399694f39c6492e61e72d2145f4a2f4beed8ee2 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 27 Nov 2015 08:46:54 -0800 Subject: [PATCH] Quagga: Nexthop refactoring Upstream wanted some nexthop code to be refactored. Signed-off-by: Donald Sharp --- lib/nexthop.c | 76 +++++++++++++- lib/nexthop.h | 23 ++--- zebra/redistribute.c | 2 +- zebra/rib.h | 37 ++++--- zebra/rt_netlink.c | 12 +-- zebra/zebra_rib.c | 219 ++++++++++++----------------------------- zebra/zebra_rnh.c | 29 +++++- zebra/zebra_rnh.h | 1 + zebra/zebra_rnh_null.c | 3 + zebra/zserv.c | 24 ++--- 10 files changed, 214 insertions(+), 212 deletions(-) diff --git a/lib/nexthop.c b/lib/nexthop.c index 2478dca7a4..5eb2182de0 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -1,20 +1,20 @@ /* A generic nexthop structure * Copyright (C) 2013 Cumulus Networks, Inc. * - * This file is part of GNU Zebra. + * This file is part of Quagga. * - * GNU Zebra is free software; you can redistribute it and/or modify it + * Quagga is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * - * GNU Zebra is distributed in the hope that it will be useful, but + * Quagga is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with GNU Zebra; see the file COPYING. If not, write to the Free + * along with Quagga; see the file COPYING. If not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ @@ -98,3 +98,71 @@ nexthop_type_to_str (enum nexthop_types_t nh_type) return desc[nh_type]; } + +struct nexthop * +nexthop_new (void) +{ + return XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); +} + +/* Add nexthop to the end of a nexthop list. */ +void +nexthop_add (struct nexthop **target, struct nexthop *nexthop) +{ + struct nexthop *last; + + for (last = *target; last && last->next; last = last->next) + ; + if (last) + last->next = nexthop; + else + *target = nexthop; + nexthop->prev = last; +} + +void +copy_nexthops (struct nexthop **tnh, struct nexthop *nh) +{ + struct nexthop *nexthop; + struct nexthop *nh1; + + for (nh1 = nh; nh1; nh1 = nh1->next) + { + nexthop = nexthop_new(); + nexthop->flags = nh->flags; + nexthop->type = nh->type; + nexthop->ifindex = nh->ifindex; + if (nh->ifname) + nexthop->ifname = XSTRDUP(0, nh->ifname); + memcpy(&(nexthop->gate), &(nh->gate), sizeof(union g_addr)); + memcpy(&(nexthop->src), &(nh->src), sizeof(union g_addr)); + nexthop_add(tnh, nexthop); + + if (CHECK_FLAG(nh1->flags, NEXTHOP_FLAG_RECURSIVE)) + copy_nexthops(&nexthop->resolved, nh1->resolved); + } +} + +/* Free nexthop. */ +void +nexthop_free (struct nexthop *nexthop) +{ + if (nexthop->ifname) + XFREE (0, nexthop->ifname); + if (nexthop->resolved) + nexthops_free(nexthop->resolved); + XFREE (MTYPE_NEXTHOP, nexthop); +} + +/* Frees a list of nexthops */ +void +nexthops_free (struct nexthop *nexthop) +{ + struct nexthop *nh, *next; + + for (nh = nexthop; nh; nh = next) + { + next = nh->next; + nexthop_free (nh); + } +} diff --git a/lib/nexthop.h b/lib/nexthop.h index 6909775a06..8a3a7620ab 100644 --- a/lib/nexthop.h +++ b/lib/nexthop.h @@ -1,21 +1,22 @@ /* * Nexthop structure definition. + * Copyright (C) 1997, 98, 99, 2001 Kunihiro Ishiguro * Copyright (C) 2013 Cumulus Networks, Inc. * - * This file is part of GNU Zebra. + * This file is part of Quagga. * - * GNU Zebra is free software; you can redistribute it and/or modify it + * Quagga is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * - * GNU Zebra is distributed in the hope that it will be useful, but + * Quagga is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with GNU Zebra; see the file COPYING. If not, write to the Free + * along with Quagga; see the file COPYING. If not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ @@ -77,13 +78,6 @@ struct nexthop struct nexthop *resolved; }; -#define nexthop_new() \ -({ \ - struct nexthop *n = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); \ - n; \ -}) - - extern int zebra_rnh_ip_default_route; extern int zebra_rnh_ipv6_default_route; @@ -97,6 +91,13 @@ nh_resolve_via_default(int family) return 0; } +struct nexthop *nexthop_new (void); +void nexthop_add (struct nexthop **target, struct nexthop *nexthop); + +void copy_nexthops (struct nexthop **tnh, struct nexthop *nh); +void nexthop_free (struct nexthop *nexthop); +void nexthops_free (struct nexthop *nexthop); + extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type); extern int nexthop_same_no_recurse (struct nexthop *next1, struct nexthop *next2); diff --git a/zebra/redistribute.c b/zebra/redistribute.c index a17b9a8c09..e547d1e2d3 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -544,7 +544,7 @@ zebra_add_import_table_entry (struct route_node *rn, struct rib *rib) /* Assuming these routes are never recursive */ for (nhop = rib->nexthop; nhop; nhop = nhop->next) - copy_nexthops(newrib, nhop); + rib_copy_nexthops(newrib, nhop); rib_add_ipv4_multipath(&p4, newrib, SAFI_UNICAST); } diff --git a/zebra/rib.h b/zebra/rib.h index 3656646c9b..56ea597550 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -380,19 +380,17 @@ typedef struct rib_tables_iter_t_ rib_tables_iter_state_t state; } rib_tables_iter_t; -extern struct nexthop *nexthop_ifindex_add (struct rib *, unsigned int); -extern struct nexthop *nexthop_ifname_add (struct rib *, char *); -extern struct nexthop *nexthop_blackhole_add (struct rib *); -extern struct nexthop *nexthop_ipv4_add (struct rib *, struct in_addr *, - struct in_addr *); -extern struct nexthop *nexthop_ipv4_ifindex_add (struct rib *, - struct in_addr *, - struct in_addr *, - unsigned int); -extern void nexthop_free (struct nexthop *nexthop, struct route_node *); -extern void nexthops_free (struct nexthop *nexthop, struct route_node *); -extern void nexthop_add (struct rib *rib, struct nexthop *nexthop); -extern void copy_nexthops (struct rib *rib, struct nexthop *nh); +extern struct nexthop *rib_nexthop_ifindex_add (struct rib *, unsigned int); +extern struct nexthop *rib_nexthop_ifname_add (struct rib *, char *); +extern struct nexthop *rib_nexthop_blackhole_add (struct rib *); +extern struct nexthop *rib_nexthop_ipv4_add (struct rib *, struct in_addr *, + struct in_addr *); +extern struct nexthop *rib_nexthop_ipv4_ifindex_add (struct rib *, + struct in_addr *, + struct in_addr *, + unsigned int); +extern void rib_nexthop_add (struct rib *rib, struct nexthop *nexthop); +extern void rib_copy_nexthops (struct rib *rib, struct nexthop *nh); extern int nexthop_has_fib_child(struct nexthop *); extern void rib_lookup_and_dump (struct prefix_ipv4 *); @@ -408,12 +406,13 @@ extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *, #define ZEBRA_RIB_FOUND_CONNECTED 2 #define ZEBRA_RIB_NOTFOUND 3 -extern struct nexthop *nexthop_ipv6_add (struct rib *, struct in6_addr *); -extern struct nexthop *nexthop_ipv6_ifindex_add (struct rib *rib, - struct in6_addr *ipv6, unsigned int ifindex); -extern struct nexthop *nexthop_ipv6_ifname_add (struct rib *rib, - struct in6_addr *ipv6, - char *ifname); +extern struct nexthop *rib_nexthop_ipv6_add (struct rib *, struct in6_addr *); +extern struct nexthop *rib_nexthop_ipv6_ifindex_add (struct rib *rib, + struct in6_addr *ipv6, + unsigned int ifindex); +extern struct nexthop *rib_nexthop_ipv6_ifname_add (struct rib *rib, + struct in6_addr *ipv6, + char *ifname); extern struct zebra_vrf *zebra_vrf_lookup (vrf_id_t vrf_id); extern struct zebra_vrf *zebra_vrf_alloc (vrf_id_t); diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index a4da7f079d..d528c0352e 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -791,12 +791,12 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h, if (gate) { if (index) - nexthop_ipv4_ifindex_add (rib, gate, src, index); + rib_nexthop_ipv4_ifindex_add (rib, gate, src, index); else - nexthop_ipv4_add (rib, gate, src); + rib_nexthop_ipv4_add (rib, gate, src); } else - nexthop_ifindex_add (rib, index); + rib_nexthop_ifindex_add (rib, index); len -= NLMSG_ALIGN(rtnh->rtnh_len); rtnh = RTNH_NEXT(rtnh); @@ -996,12 +996,12 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h, if (gate) { if (index) - nexthop_ipv4_ifindex_add (rib, gate, src, index); + rib_nexthop_ipv4_ifindex_add (rib, gate, src, index); else - nexthop_ipv4_add (rib, gate, src); + rib_nexthop_ipv4_add (rib, gate, src); } else - nexthop_ifindex_add (rib, index); + rib_nexthop_ifindex_add (rib, index); len -= NLMSG_ALIGN(rtnh->rtnh_len); rtnh = RTNH_NEXT(rtnh); diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index a9ea4f2d1d..36bcfc859f 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -80,31 +80,6 @@ static const struct /* no entry/default: 150 */ }; -/* - * nexthop_type_to_str - */ -const char * -nexthop_type_to_str (enum nexthop_types_t nh_type) -{ - static const char *desc[] = { - "none", - "Directly connected", - "Interface route", - "IPv4 nexthop", - "IPv4 nexthop with ifindex", - "IPv4 nexthop with ifname", - "IPv6 nexthop", - "IPv6 nexthop with ifindex", - "IPv6 nexthop with ifname", - "Null0 nexthop", - }; - - if (nh_type >= ZEBRA_NUM_OF (desc)) - return ""; - - return desc[nh_type]; -} - int is_zebra_valid_kernel_table(u_int32_t table_id) { @@ -150,57 +125,21 @@ zebra_check_addr (struct prefix *p) return 1; } -/* Add nexthop to the end of a nexthop list. */ -static void -_nexthop_add (struct nexthop **target, struct nexthop *nexthop) -{ - struct nexthop *last; - - for (last = *target; last && last->next; last = last->next) - ; - if (last) - last->next = nexthop; - else - *target = nexthop; - nexthop->prev = last; -} - /* Add nexthop to the end of a rib node's nexthop list */ void -nexthop_add (struct rib *rib, struct nexthop *nexthop) +rib_nexthop_add (struct rib *rib, struct nexthop *nexthop) { - _nexthop_add(&rib->nexthop, nexthop); + nexthop_add(&rib->nexthop, nexthop); rib->nexthop_num++; } -static void -_copy_nexthops (struct nexthop **tnh, struct nexthop *nh) -{ - struct nexthop *nexthop; - struct nexthop *nh1; - for (nh1 = nh; nh1; nh1 = nh1->next) - { - nexthop = nexthop_new(); - nexthop->flags = nh->flags; - nexthop->type = nh->type; - nexthop->ifindex = nh->ifindex; - if (nh->ifname) - nexthop->ifname = XSTRDUP(0, nh->ifname); - memcpy(&(nexthop->gate), &(nh->gate), sizeof(union g_addr)); - memcpy(&(nexthop->src), &(nh->src), sizeof(union g_addr)); - _nexthop_add(tnh, nexthop); - - if (CHECK_FLAG(nh1->flags, NEXTHOP_FLAG_RECURSIVE)) - _copy_nexthops(&nexthop->resolved, nh1->resolved); - } -} /** * copy_nexthop - copy a nexthop to the rib structure. */ void -copy_nexthops (struct rib *rib, struct nexthop *nh) +rib_copy_nexthops (struct rib *rib, struct nexthop *nh) { struct nexthop *nexthop; @@ -212,14 +151,14 @@ copy_nexthops (struct rib *rib, struct nexthop *nh) nexthop->ifname = XSTRDUP(0, nh->ifname); memcpy(&(nexthop->gate), &(nh->gate), sizeof(union g_addr)); memcpy(&(nexthop->src), &(nh->src), sizeof(union g_addr)); - nexthop_add(rib, nexthop); + rib_nexthop_add(rib, nexthop); if (CHECK_FLAG(nh->flags, NEXTHOP_FLAG_RECURSIVE)) - _copy_nexthops(&nexthop->resolved, nh->resolved); + copy_nexthops(&nexthop->resolved, nh->resolved); } /* Delete specified nexthop from the list. */ static void -nexthop_delete (struct rib *rib, struct nexthop *nexthop) +rib_nexthop_delete (struct rib *rib, struct nexthop *nexthop) { if (nexthop->next) nexthop->next->prev = nexthop->prev; @@ -230,97 +169,60 @@ nexthop_delete (struct rib *rib, struct nexthop *nexthop) rib->nexthop_num--; } -/* Free nexthop. */ -void -nexthop_free (struct nexthop *nexthop, struct route_node *rn) -{ - if (nexthop->ifname) - XFREE (0, nexthop->ifname); - if (nexthop->resolved) - nexthops_free(nexthop->resolved, rn); - XFREE (MTYPE_NEXTHOP, nexthop); -} - -/* Frees a list of nexthops */ -void -nexthops_free (struct nexthop *nexthop, struct route_node *rn) -{ - struct nexthop *nh, *next; - struct prefix nh_p; - for (nh = nexthop; nh; nh = next) - { - next = nh->next; - if (nh->type == NEXTHOP_TYPE_IPV4) - { - nh_p.family = AF_INET; - nh_p.prefixlen = IPV4_MAX_BITLEN; - nh_p.u.prefix4 = nh->gate.ipv4; - zebra_deregister_rnh_static_nh(&nh_p, rn); - } - else if (nh->type == NEXTHOP_TYPE_IPV6) - { - nh_p.family = AF_INET6; - nh_p.prefixlen = IPV6_MAX_BITLEN; - nh_p.u.prefix6 = nh->gate.ipv6; - zebra_deregister_rnh_static_nh(&nh_p, rn); - } - nexthop_free (nh, rn); - } -} struct nexthop * -nexthop_ifindex_add (struct rib *rib, unsigned int ifindex) +rib_nexthop_ifindex_add (struct rib *rib, unsigned int ifindex) { struct nexthop *nexthop; - nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); + nexthop = nexthop_new(); nexthop->type = NEXTHOP_TYPE_IFINDEX; nexthop->ifindex = ifindex; - nexthop_add (rib, nexthop); + rib_nexthop_add (rib, nexthop); return nexthop; } struct nexthop * -nexthop_ifname_add (struct rib *rib, char *ifname) +rib_nexthop_ifname_add (struct rib *rib, char *ifname) { struct nexthop *nexthop; - nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); + nexthop = nexthop_new(); nexthop->type = NEXTHOP_TYPE_IFNAME; nexthop->ifname = XSTRDUP (0, ifname); - nexthop_add (rib, nexthop); + rib_nexthop_add (rib, nexthop); return nexthop; } struct nexthop * -nexthop_ipv4_add (struct rib *rib, struct in_addr *ipv4, struct in_addr *src) +rib_nexthop_ipv4_add (struct rib *rib, struct in_addr *ipv4, struct in_addr *src) { struct nexthop *nexthop; - nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); + nexthop = nexthop_new(); nexthop->type = NEXTHOP_TYPE_IPV4; nexthop->gate.ipv4 = *ipv4; if (src) nexthop->src.ipv4 = *src; - nexthop_add (rib, nexthop); + rib_nexthop_add (rib, nexthop); return nexthop; } struct nexthop * -nexthop_ipv4_ifindex_add (struct rib *rib, struct in_addr *ipv4, - struct in_addr *src, unsigned int ifindex) +rib_nexthop_ipv4_ifindex_add (struct rib *rib, struct in_addr *ipv4, + struct in_addr *src, unsigned int ifindex) { struct nexthop *nexthop; struct interface *ifp; - nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); + nexthop = nexthop_new(); nexthop->type = NEXTHOP_TYPE_IPV4_IFINDEX; nexthop->gate.ipv4 = *ipv4; if (src) @@ -331,44 +233,44 @@ nexthop_ipv4_ifindex_add (struct rib *rib, struct in_addr *ipv4, SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK); } - nexthop_add (rib, nexthop); + rib_nexthop_add (rib, nexthop); return nexthop; } struct nexthop * -nexthop_ipv6_add (struct rib *rib, struct in6_addr *ipv6) +rib_nexthop_ipv6_add (struct rib *rib, struct in6_addr *ipv6) { struct nexthop *nexthop; - nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); + nexthop = nexthop_new(); nexthop->type = NEXTHOP_TYPE_IPV6; nexthop->gate.ipv6 = *ipv6; - nexthop_add (rib, nexthop); + rib_nexthop_add (rib, nexthop); return nexthop; } struct nexthop * -nexthop_ipv6_ifname_add (struct rib *rib, struct in6_addr *ipv6, - char *ifname) +rib_nexthop_ipv6_ifname_add (struct rib *rib, struct in6_addr *ipv6, + char *ifname) { struct nexthop *nexthop; - nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); + nexthop = nexthop_new(); nexthop->type = NEXTHOP_TYPE_IPV6_IFNAME; nexthop->gate.ipv6 = *ipv6; nexthop->ifname = XSTRDUP (0, ifname); - nexthop_add (rib, nexthop); + rib_nexthop_add (rib, nexthop); return nexthop; } struct nexthop * -nexthop_ipv6_ifindex_add (struct rib *rib, struct in6_addr *ipv6, - unsigned int ifindex) +rib_nexthop_ipv6_ifindex_add (struct rib *rib, struct in6_addr *ipv6, + unsigned int ifindex) { struct nexthop *nexthop; @@ -377,21 +279,21 @@ nexthop_ipv6_ifindex_add (struct rib *rib, struct in6_addr *ipv6, nexthop->gate.ipv6 = *ipv6; nexthop->ifindex = ifindex; - nexthop_add (rib, nexthop); + rib_nexthop_add (rib, nexthop); return nexthop; } struct nexthop * -nexthop_blackhole_add (struct rib *rib) +rib_nexthop_blackhole_add (struct rib *rib) { struct nexthop *nexthop; - nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); + nexthop = nexthop_new(); nexthop->type = NEXTHOP_TYPE_BLACKHOLE; SET_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE); - nexthop_add (rib, nexthop); + rib_nexthop_add (rib, nexthop); return nexthop; } @@ -436,7 +338,8 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set, if (set) { UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE); - nexthops_free(nexthop->resolved, top); + zebra_deregister_rnh_static_nexthops(nexthop->resolved, top); + nexthops_free(nexthop->resolved); nexthop->resolved = NULL; } @@ -574,7 +477,7 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set, resolved_hop->ifindex = newhop->ifindex; } - _nexthop_add(&nexthop->resolved, resolved_hop); + nexthop_add(&nexthop->resolved, resolved_hop); } resolved = 1; } @@ -627,7 +530,7 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set, resolved_hop->ifindex = newhop->ifindex; } - _nexthop_add(&nexthop->resolved, resolved_hop); + nexthop_add(&nexthop->resolved, resolved_hop); } resolved = 1; } @@ -663,7 +566,8 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set, if (set) { UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE); - nexthops_free(nexthop->resolved, top); + zebra_deregister_rnh_static_nexthops (nexthop->resolved, top); + nexthops_free(nexthop->resolved); nexthop->resolved = NULL; } @@ -774,7 +678,7 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set, resolved_hop->ifindex = newhop->ifindex; } - _nexthop_add(&nexthop->resolved, resolved_hop); + nexthop_add(&nexthop->resolved, resolved_hop); } resolved = 1; } @@ -817,7 +721,7 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set, resolved_hop->ifindex = newhop->ifindex; } - _nexthop_add(&nexthop->resolved, resolved_hop); + nexthop_add(&nexthop->resolved, resolved_hop); } resolved = 1; } @@ -2095,7 +1999,8 @@ rib_unlink (struct route_node *rn, struct rib *rib) } /* free RIB and nexthops */ - nexthops_free(rib->nexthop, rn); + zebra_deregister_rnh_static_nexthops (rib->nexthop, rn); + nexthops_free(rib->nexthop); XFREE (MTYPE_RIB, rib); } @@ -2214,12 +2119,12 @@ rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, if (gate) { if (ifindex) - nexthop_ipv4_ifindex_add (rib, gate, src, ifindex); + rib_nexthop_ipv4_ifindex_add (rib, gate, src, ifindex); else - nexthop_ipv4_add (rib, gate, src); + rib_nexthop_ipv4_add (rib, gate, src); } else - nexthop_ifindex_add (rib, ifindex); + rib_nexthop_ifindex_add (rib, ifindex); /* If this route is kernel route, set FIB flag to the route. */ if (type == ZEBRA_ROUTE_KERNEL || type == ZEBRA_ROUTE_CONNECT) @@ -2694,30 +2599,30 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro switch (si->type) { case STATIC_IPV4_GATEWAY: - nexthop_ipv4_add (rib, &si->addr.ipv4, NULL); + rib_nexthop_ipv4_add (rib, &si->addr.ipv4, NULL); nh_p.family = AF_INET; nh_p.prefixlen = IPV4_MAX_BITLEN; nh_p.u.prefix4 = si->addr.ipv4; zebra_register_rnh_static_nh(&nh_p, rn); break; case STATIC_IPV4_IFNAME: - nexthop_ifname_add (rib, si->ifname); + rib_nexthop_ifname_add (rib, si->ifname); break; case STATIC_IPV4_BLACKHOLE: - nexthop_blackhole_add (rib); + rib_nexthop_blackhole_add (rib); break; case STATIC_IPV6_GATEWAY: - nexthop_ipv6_add (rib, &si->addr.ipv6); + rib_nexthop_ipv6_add (rib, &si->addr.ipv6); nh_p.family = AF_INET6; nh_p.prefixlen = IPV6_MAX_BITLEN; nh_p.u.prefix6 = si->addr.ipv6; zebra_register_rnh_static_nh(&nh_p, rn); break; case STATIC_IPV6_IFNAME: - nexthop_ifname_add (rib, si->ifname); + rib_nexthop_ifname_add (rib, si->ifname); break; case STATIC_IPV6_GATEWAY_IFNAME: - nexthop_ipv6_ifname_add (rib, &si->addr.ipv6, si->ifname); + rib_nexthop_ipv6_ifname_add (rib, &si->addr.ipv6, si->ifname); break; } rib_queue_add (&zebrad, rn); @@ -2739,30 +2644,30 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro switch (si->type) { case STATIC_IPV4_GATEWAY: - nexthop_ipv4_add (rib, &si->addr.ipv4, NULL); + rib_nexthop_ipv4_add (rib, &si->addr.ipv4, NULL); nh_p.family = AF_INET; nh_p.prefixlen = IPV4_MAX_BITLEN; nh_p.u.prefix4 = si->addr.ipv4; zebra_register_rnh_static_nh(&nh_p, rn); break; case STATIC_IPV4_IFNAME: - nexthop_ifname_add (rib, si->ifname); + rib_nexthop_ifname_add (rib, si->ifname); break; case STATIC_IPV4_BLACKHOLE: - nexthop_blackhole_add (rib); + rib_nexthop_blackhole_add (rib); break; case STATIC_IPV6_GATEWAY: - nexthop_ipv6_add (rib, &si->addr.ipv6); + rib_nexthop_ipv6_add (rib, &si->addr.ipv6); nh_p.family = AF_INET6; nh_p.prefixlen = IPV6_MAX_BITLEN; nh_p.u.prefix6 = si->addr.ipv6; zebra_register_rnh_static_nh(&nh_p, rn); break; case STATIC_IPV6_IFNAME: - nexthop_ifname_add (rib, si->ifname); + rib_nexthop_ifname_add (rib, si->ifname); break; case STATIC_IPV6_GATEWAY_IFNAME: - nexthop_ipv6_ifname_add (rib, &si->addr.ipv6, si->ifname); + rib_nexthop_ipv6_ifname_add (rib, &si->addr.ipv6, si->ifname); break; } @@ -2904,9 +2809,9 @@ static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ nh_p.prefixlen = IPV6_MAX_BITLEN; nh_p.u.prefix6 = nexthop->gate.ipv6; } - nexthop_delete (rib, nexthop); + rib_nexthop_delete (rib, nexthop); zebra_deregister_rnh_static_nh(&nh_p, rn); - nexthop_free (nexthop, rn); + nexthop_free (nexthop); } /* Unlock node. */ route_unlock_node (rn); @@ -3152,12 +3057,12 @@ rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, if (gate) { if (ifindex) - nexthop_ipv6_ifindex_add (rib, gate, ifindex); + rib_nexthop_ipv6_ifindex_add (rib, gate, ifindex); else - nexthop_ipv6_add (rib, gate); + rib_nexthop_ipv6_add (rib, gate); } else - nexthop_ifindex_add (rib, ifindex); + rib_nexthop_ifindex_add (rib, ifindex); /* If this route is kernel route, set FIB flag to the route. */ if (type == ZEBRA_ROUTE_KERNEL || type == ZEBRA_ROUTE_CONNECT) diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index 76b038d1b9..587527dd62 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -244,6 +244,30 @@ zebra_deregister_rnh_static_nh(struct prefix *nh, struct route_node *static_rn) zebra_delete_rnh(rnh, RNH_NEXTHOP_TYPE); } +void +zebra_deregister_rnh_static_nexthops (struct nexthop *nexthop, struct route_node *rn) +{ + struct nexthop *nh; + struct prefix nh_p; + + for (nh = nexthop; nh ; nh = nh->next) + { + if (nh->type == NEXTHOP_TYPE_IPV4) + { + nh_p.family = AF_INET; + nh_p.prefixlen = IPV4_MAX_BITLEN; + nh_p.u.prefix4 = nh->gate.ipv4; + } + else if (nh->type == NEXTHOP_TYPE_IPV6) + { + nh_p.family = AF_INET6; + nh_p.prefixlen = IPV6_MAX_BITLEN; + nh_p.u.prefix6 = nh->gate.ipv6; + } + zebra_deregister_rnh_static_nh(&nh_p, rn); + } +} + static int zebra_evaluate_rnh_nexthops(int family, struct rib *rib, struct route_node *prn, int proto) @@ -666,7 +690,8 @@ free_state (struct rib *rib, struct route_node *rn) return; /* free RIB and nexthops */ - nexthops_free(rib->nexthop, rn); + nexthops_free(rib->nexthop); + zebra_deregister_rnh_static_nexthops (rib->nexthop, rn); XFREE (MTYPE_RIB, rib); } @@ -690,7 +715,7 @@ copy_state (struct rnh *rnh, struct rib *rib, struct route_node *rn) state->metric = rib->metric; for (nh = rib->nexthop; nh; nh = nh->next) - copy_nexthops(state, nh); + rib_copy_nexthops(state, nh); rnh->state = state; } diff --git a/zebra/zebra_rnh.h b/zebra/zebra_rnh.h index 8e5ee8b952..bed21c1987 100644 --- a/zebra/zebra_rnh.h +++ b/zebra/zebra_rnh.h @@ -60,6 +60,7 @@ extern void zebra_delete_rnh(struct rnh *rnh, rnh_type_t type); extern void zebra_add_rnh_client(struct rnh *rnh, struct zserv *client, rnh_type_t type, vrf_id_t vrfid); extern void zebra_register_rnh_static_nh(struct prefix *, struct route_node *); +extern void zebra_deregister_rnh_static_nexthops (struct nexthop *nexthop, struct route_node *rn); extern void zebra_deregister_rnh_static_nh(struct prefix *, struct route_node *); extern void zebra_remove_rnh_client(struct rnh *rnh, struct zserv *client, rnh_type_t type); diff --git a/zebra/zebra_rnh_null.c b/zebra/zebra_rnh_null.c index 58fba418af..0b8f4b0d8c 100644 --- a/zebra/zebra_rnh_null.c +++ b/zebra/zebra_rnh_null.c @@ -19,3 +19,6 @@ void zebra_register_rnh_static_nh(struct prefix *p, struct route_node *rn) void zebra_deregister_rnh_static_nh(struct prefix *p, struct route_node *rn) {} + +void zebra_deregister_rnh_static_nexthops (struct nexthop *nexthop, struct route_node *rn) +{} diff --git a/zebra/zserv.c b/zebra/zserv.c index 87fa5ce49c..f8bf18d1e1 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -1109,7 +1109,7 @@ zread_ipv4_add (struct zserv *client, u_short length, vrf_id_t vrf_id) { case ZEBRA_NEXTHOP_IFINDEX: ifindex = stream_getl (s); - nexthop_ifindex_add (rib, ifindex); + rib_nexthop_ifindex_add (rib, ifindex); break; case ZEBRA_NEXTHOP_IFNAME: ifname_len = stream_getc (s); @@ -1117,18 +1117,18 @@ zread_ipv4_add (struct zserv *client, u_short length, vrf_id_t vrf_id) break; case ZEBRA_NEXTHOP_IPV4: nexthop.s_addr = stream_get_ipv4 (s); - nexthop_ipv4_add (rib, &nexthop, NULL); + rib_nexthop_ipv4_add (rib, &nexthop, NULL); break; case ZEBRA_NEXTHOP_IPV4_IFINDEX: nexthop.s_addr = stream_get_ipv4 (s); ifindex = stream_getl (s); - nexthop_ipv4_ifindex_add (rib, &nexthop, NULL, ifindex); + rib_nexthop_ipv4_ifindex_add (rib, &nexthop, NULL, ifindex); break; case ZEBRA_NEXTHOP_IPV6: stream_forward_getp (s, IPV6_MAX_BYTELEN); break; case ZEBRA_NEXTHOP_BLACKHOLE: - nexthop_blackhole_add (rib); + rib_nexthop_blackhole_add (rib); break; } } @@ -1351,7 +1351,7 @@ zread_ipv4_route_ipv6_nexthop_add (struct zserv *client, u_short length) } break; case ZEBRA_NEXTHOP_BLACKHOLE: - nexthop_blackhole_add (rib); + rib_nexthop_blackhole_add (rib); break; } } @@ -1361,15 +1361,15 @@ zread_ipv4_route_ipv6_nexthop_add (struct zserv *client, u_short length) { if ((i < nh_count) && !IN6_IS_ADDR_UNSPECIFIED (&nexthops[i])) { if ((i < if_count) && ifindices[i]) { - nexthop_ipv6_ifindex_add (rib, &nexthops[i], ifindices[i]); + rib_nexthop_ipv6_ifindex_add (rib, &nexthops[i], ifindices[i]); } else { - nexthop_ipv6_add (rib, &nexthops[i]); + rib_nexthop_ipv6_add (rib, &nexthops[i]); } } else { if ((i < if_count) && ifindices[i]) { - nexthop_ifindex_add (rib, ifindices[i]); + rib_nexthop_ifindex_add (rib, ifindices[i]); } } } @@ -1471,7 +1471,7 @@ zread_ipv6_add (struct zserv *client, u_short length, vrf_id_t vrf_id) } break; case ZEBRA_NEXTHOP_BLACKHOLE: - nexthop_blackhole_add (rib); + rib_nexthop_blackhole_add (rib); break; } } @@ -1481,13 +1481,13 @@ zread_ipv6_add (struct zserv *client, u_short length, vrf_id_t vrf_id) { if ((i < nh_count) && !IN6_IS_ADDR_UNSPECIFIED (&nexthops[i])) { if ((i < if_count) && ifindices[i]) - nexthop_ipv6_ifindex_add (rib, &nexthops[i], ifindices[i]); + rib_nexthop_ipv6_ifindex_add (rib, &nexthops[i], ifindices[i]); else - nexthop_ipv6_add (rib, &nexthops[i]); + rib_nexthop_ipv6_add (rib, &nexthops[i]); } else { if ((i < if_count) && ifindices[i]) - nexthop_ifindex_add (rib, ifindices[i]); + rib_nexthop_ifindex_add (rib, ifindices[i]); } } } -- 2.39.5