From 633e504d0a87cbaac2a700ceb667be04281064bf Mon Sep 17 00:00:00 2001 From: Don Slice Date: Fri, 15 Jul 2016 06:33:48 -0700 Subject: zebra: Eliminate use of imported arp entries as next-hops for other routes Ticket: CM-8228 Signed-off-by: Donald Slice Reviewed By: Testing Done: Manual testing succesful. bgp-min and ospf-smoke successful. redistribute-neighbor-smoke has the same failures as the base image. Problem was due to considering imported /32 arp entries as elible next-hops for other routes (in this case a static route.) This confuses the rib since this next-hop is considered both recursive and onlink. Disallowed the use of this imported arp entry in next-hop determination. --- zebra/zebra_rib.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'zebra/zebra_rib.c') diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index d70f528f5a..8a2728a890 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -405,6 +405,10 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set, { if (CHECK_FLAG (match->status, RIB_ENTRY_REMOVED)) continue; + + /* if the next hop is imported from another table, skip it */ + if (match->type == ZEBRA_ROUTE_TABLE) + continue; if (CHECK_FLAG (match->flags, ZEBRA_FLAG_SELECTED)) break; } -- cgit v1.2.3 From 8f500a1cf156c6033f2e0b1ef40db09f9d6f34a2 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 4 Aug 2016 10:07:33 -0300 Subject: *: fix trivial build errors on *BSD Signed-off-by: Renato Westphal --- bgpd/bgpd.c | 4 ++-- cumulus/start-stop-daemon.c | 7 ++++++- pimd/test_igmpv3_join.c | 2 ++ zebra/if_ioctl.c | 2 +- zebra/kernel_socket.c | 20 ++++++++++---------- zebra/zebra_ptm.c | 5 ++++- zebra/zebra_rib.c | 12 ++++++++---- 7 files changed, 33 insertions(+), 19 deletions(-) (limited to 'zebra/zebra_rib.c') diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 1a5270874c..b3721a03ea 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -1315,7 +1315,7 @@ bgp_peer_conf_if_to_su_update_v4 (struct peer *peer, struct interface *ifp) else if (s_addr % 4 == 2) peer->su.sin.sin_addr.s_addr = htonl(s_addr-1); #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN - peer->su->sin.sin_len = sizeof(struct sockaddr_in); + peer->su.sin.sin_len = sizeof(struct sockaddr_in); #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ return 1; } @@ -1328,7 +1328,7 @@ bgp_peer_conf_if_to_su_update_v4 (struct peer *peer, struct interface *ifp) else peer->su.sin.sin_addr.s_addr = htonl(s_addr-1); #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN - peer->su->sin.sin_len = sizeof(struct sockaddr_in); + peer->su.sin.sin_len = sizeof(struct sockaddr_in); #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ return 1; } diff --git a/cumulus/start-stop-daemon.c b/cumulus/start-stop-daemon.c index ea63fbc217..4d447d9051 100644 --- a/cumulus/start-stop-daemon.c +++ b/cumulus/start-stop-daemon.c @@ -56,8 +56,9 @@ #include #include #include -#include +#ifdef linux #include +#endif static int testmode = 0; static int quietmode = 0; @@ -241,6 +242,7 @@ next_dirname(const char *s) return cur; } +#ifdef linux static void add_namespace(const char *path) { @@ -270,6 +272,7 @@ add_namespace(const char *path) namespace->nstype = nstype; LIST_INSERT_HEAD(&namespace_head, namespace, list); } +#endif #ifdef HAVE_LXC static void @@ -567,7 +570,9 @@ parse_options(int argc, char * const *argv) changeroot = optarg; break; case 'd': /* --namespace /.../||/name */ +#ifdef linux add_namespace(optarg); +#endif break; case 'N': /* --nice */ nicelevel = atoi(optarg); diff --git a/pimd/test_igmpv3_join.c b/pimd/test_igmpv3_join.c index fe64fbc005..7fcf38bcec 100644 --- a/pimd/test_igmpv3_join.c +++ b/pimd/test_igmpv3_join.c @@ -20,6 +20,8 @@ $QuaggaId: $Format:%an, %ai, %h$ $ */ +#include + #include #include #include diff --git a/zebra/if_ioctl.c b/zebra/if_ioctl.c index 88fea3427f..0a9807b8b9 100644 --- a/zebra/if_ioctl.c +++ b/zebra/if_ioctl.c @@ -427,7 +427,7 @@ interface_info_ioctl () struct listnode *node, *nnode; struct interface *ifp; - for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp)) + for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT), node, nnode, ifp)) { if_get_index (ifp); #ifdef SIOCGIFHWADDR diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index f9df983abf..23224dc241 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -927,7 +927,7 @@ rtm_read (struct rt_msghdr *rtm) case ZEBRA_RIB_FOUND_EXACT: /* RIB RR == FIB RR */ zlog_debug ("%s: %s %s: done Ok", __func__, lookup (rtm_type_str, rtm->rtm_type), buf); - rib_lookup_and_dump (&p); + rib_lookup_and_dump (&p, VRF_DEFAULT); return; break; } @@ -940,18 +940,18 @@ rtm_read (struct rt_msghdr *rtm) case ZEBRA_RIB_FOUND_EXACT: zlog_debug ("%s: %s %s: desync: RR is still in RIB, while already not in FIB", __func__, lookup (rtm_type_str, rtm->rtm_type), buf); - rib_lookup_and_dump (&p); + rib_lookup_and_dump (&p, VRF_DEFAULT); break; case ZEBRA_RIB_FOUND_CONNECTED: case ZEBRA_RIB_FOUND_NOGATE: zlog_debug ("%s: %s %s: desync: RR is still in RIB, plus gate differs", __func__, lookup (rtm_type_str, rtm->rtm_type), buf); - rib_lookup_and_dump (&p); + rib_lookup_and_dump (&p, VRF_DEFAULT); break; case ZEBRA_RIB_NOTFOUND: /* RIB RR == FIB RR */ zlog_debug ("%s: %s %s: done Ok", __func__, lookup (rtm_type_str, rtm->rtm_type), buf); - rib_lookup_and_dump (&p); + rib_lookup_and_dump (&p, VRF_DEFAULT); return; break; } @@ -968,7 +968,7 @@ rtm_read (struct rt_msghdr *rtm) */ if (rtm->rtm_type == RTM_CHANGE) rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, - NULL, 0, VRF_DEFAULT, SAFI_UNICAST); + NULL, 0, VRF_DEFAULT, 0, SAFI_UNICAST); if (rtm->rtm_type == RTM_GET || rtm->rtm_type == RTM_ADD @@ -976,8 +976,8 @@ rtm_read (struct rt_msghdr *rtm) rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, &gate.sin.sin_addr, NULL, 0, VRF_DEFAULT, 0, 0, 0, SAFI_UNICAST); else - rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0 zebra_flags, - &p, &gate.sin.sin_addr, 0, VRF_DEFAULT, SAFI_UNICAST); + rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, + &p, &gate.sin.sin_addr, 0, VRF_DEFAULT, 0, SAFI_UNICAST); } #ifdef HAVE_IPV6 if (dest.sa.sa_family == AF_INET6) @@ -1010,16 +1010,16 @@ rtm_read (struct rt_msghdr *rtm) */ if (rtm->rtm_type == RTM_CHANGE) rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, - NULL, 0, VRF_DEFAULT, SAFI_UNICAST); + NULL, 0, VRF_DEFAULT, 0, SAFI_UNICAST); if (rtm->rtm_type == RTM_GET || rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_CHANGE) rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, - &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, 0, 0, SAFI_UNICAST); + &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, 0, 0, 0, SAFI_UNICAST); else rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, - &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, SAFI_UNICAST); + &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, 0, SAFI_UNICAST); } #endif /* HAVE_IPV6 */ } diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index 931fc73e43..133b0fc2e9 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -31,6 +31,7 @@ #include "command.h" #include "stream.h" #include "ptm_lib.h" +#include "network.h" #include "buffer.h" #include "zebra/zebra_ptm_redistribute.h" #include "bfd.h" @@ -383,9 +384,11 @@ zebra_ptm_socket_init (void) ptm_cb.ptm_sock = -1; - sock = socket (PF_UNIX, (SOCK_STREAM | SOCK_NONBLOCK), 0); + sock = socket (PF_UNIX, SOCK_STREAM, 0); if (sock < 0) return -1; + if (set_nonblocking(sock) < 0) + return -1; /* Make server socket. */ memset (&addr, 0, sizeof (struct sockaddr_un)); diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 8a2728a890..3aa9356fe6 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -119,13 +119,17 @@ _rnode_zlog(const char *_func, vrf_id_t vrf_id, struct route_node *rn, int prior int is_zebra_valid_kernel_table(u_int32_t table_id) { - if ((table_id > ZEBRA_KERNEL_TABLE_MAX) || - (table_id == RT_TABLE_UNSPEC) || + if ((table_id > ZEBRA_KERNEL_TABLE_MAX)) + return 0; + +#ifdef linux + if ((table_id == RT_TABLE_UNSPEC) || (table_id == RT_TABLE_LOCAL) || (table_id == RT_TABLE_COMPAT)) return 0; - else - return 1; +#endif + + return 1; } int -- cgit v1.2.3 From b892f1ddfe42a620d84b6c245d1997e4b560eea8 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Mon, 18 Jan 2016 10:12:10 +0000 Subject: *: use an ifindex_t type, defined in lib/if.h, for ifindex values (cherry picked from commit 9099f9b2a66e86f8a90d7fe18f61bd2bb1bc6744) --- bgpd/bgp_attr.h | 2 +- bgpd/bgp_btoa.c | 2 +- bgpd/bgp_network.c | 2 +- bgpd/bgp_zebra.c | 8 ++++---- bgpd/bgp_zebra.h | 4 ++-- bgpd/bgpd.h | 2 +- isisd/isis_route.c | 10 +++++----- isisd/isis_route.h | 4 ++-- isisd/isis_zebra.c | 8 ++++---- lib/if.c | 26 +++++++++++++------------- lib/if.h | 24 +++++++++++++----------- lib/nexthop.h | 2 +- lib/sockopt.c | 16 ++++++++-------- lib/sockopt.h | 8 ++++---- lib/sockunion.c | 2 +- lib/sockunion.h | 3 ++- lib/zclient.c | 2 +- lib/zclient.h | 4 ++-- ospf6d/ospf6_asbr.c | 5 +++-- ospf6d/ospf6_asbr.h | 6 +++--- ospf6d/ospf6_interface.c | 2 +- ospf6d/ospf6_interface.h | 2 +- ospf6d/ospf6_message.c | 4 ++-- ospf6d/ospf6_message.h | 2 +- ospf6d/ospf6_neighbor.h | 2 +- ospf6d/ospf6_network.c | 6 +++--- ospf6d/ospf6_network.h | 6 +++--- ospf6d/ospf6_route.c | 2 +- ospf6d/ospf6_route.h | 4 ++-- ospf6d/ospf6_snmp.c | 12 ++++++------ ospf6d/ospf6_spf.c | 2 +- ospf6d/ospf6_zebra.c | 4 ++-- ospfd/ospf_asbr.c | 2 +- ospfd/ospf_asbr.h | 4 ++-- ospfd/ospf_lsa.c | 2 +- ospfd/ospf_lsa.h | 2 +- ospfd/ospf_network.c | 12 +++++------- ospfd/ospf_network.h | 10 +++++----- ospfd/ospf_packet.c | 2 +- ospfd/ospf_route.h | 2 +- ospfd/ospf_snmp.c | 30 +++++++++++++++--------------- pimd/pim_iface.c | 7 ++++--- pimd/pim_iface.h | 6 +++--- pimd/pim_igmp.c | 8 ++++---- pimd/pim_igmp_join.h | 2 +- pimd/pim_pim.c | 4 ++-- pimd/pim_sock.c | 6 +++--- pimd/pim_sock.h | 6 +++--- pimd/pim_ssmpingd.c | 2 +- pimd/pim_static.c | 8 ++++---- pimd/pim_static.h | 2 +- pimd/pim_zebra.c | 8 ++++---- pimd/pim_zlookup.h | 2 +- pimd/test_igmpv3_join.c | 5 +++-- ripd/rip_interface.c | 4 ++-- ripd/ripd.c | 8 ++++---- ripd/ripd.h | 8 ++++---- ripngd/ripng_zebra.c | 2 +- ripngd/ripngd.c | 8 ++++---- ripngd/ripngd.h | 6 +++--- zebra/kernel_socket.c | 2 +- zebra/rib.h | 27 +++++++++++++-------------- zebra/rt_netlink.c | 2 +- zebra/rt_socket.c | 4 ++-- zebra/rtadv.c | 8 ++++---- zebra/test_main.c | 2 +- zebra/zebra_rib.c | 30 +++++++++++++++--------------- zebra/zebra_routemap.c | 2 +- zebra/zserv.c | 2 +- 69 files changed, 219 insertions(+), 216 deletions(-) (limited to 'zebra/zebra_rib.c') diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index a279674af2..b8cdfea137 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -131,7 +131,7 @@ struct attr struct in_addr nexthop; u_int32_t med; u_int32_t local_pref; - u_int32_t nh_ifindex; + ifindex_t nh_ifindex; /* Path origin attribute */ u_char origin; diff --git a/bgpd/bgp_btoa.c b/bgpd/bgp_btoa.c index 904ae66e10..cd52c94b1f 100644 --- a/bgpd/bgp_btoa.c +++ b/bgpd/bgp_btoa.c @@ -144,7 +144,7 @@ main (int argc, char **argv) size_t len; int source_as; int dest_as; - int ifindex; + ifindex_t ifindex; int family; struct in_addr sip; struct in_addr dip; diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index 0caada488b..ed1c5600ee 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -579,7 +579,7 @@ bgp_update_source (struct peer *peer) int bgp_connect (struct peer *peer) { - unsigned int ifindex = 0; + ifindex_t ifindex = 0; if (peer->conf_if && BGP_PEER_SU_UNSPEC(peer)) { diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index ce5d1b498e..81bede0e92 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -856,7 +856,7 @@ if_lookup_by_ipv4_exact (struct in_addr *addr, vrf_id_t vrf_id) #ifdef HAVE_IPV6 struct interface * -if_lookup_by_ipv6 (struct in6_addr *addr, unsigned int ifindex, vrf_id_t vrf_id) +if_lookup_by_ipv6 (struct in6_addr *addr, ifindex_t ifindex, vrf_id_t vrf_id) { struct listnode *ifnode; struct listnode *cnode; @@ -892,7 +892,7 @@ if_lookup_by_ipv6 (struct in6_addr *addr, unsigned int ifindex, vrf_id_t vrf_id) } struct interface * -if_lookup_by_ipv6_exact (struct in6_addr *addr, unsigned int ifindex, vrf_id_t vrf_id) +if_lookup_by_ipv6_exact (struct in6_addr *addr, ifindex_t ifindex, vrf_id_t vrf_id) { struct listnode *ifnode; struct listnode *cnode; @@ -1381,7 +1381,7 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, if (p->family == AF_INET6 || (p->family == AF_INET && BGP_ATTR_NEXTHOP_AFI_IP6(info->attr))) { - unsigned int ifindex; + ifindex_t ifindex; struct in6_addr *nexthop; struct zapi_ipv6 api; int valid_nh_count = 0; @@ -1527,7 +1527,7 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, api.nexthop = (struct in6_addr **)STREAM_DATA (bgp_nexthop_buf); SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); api.ifindex_num = valid_nh_count; - api.ifindex = (unsigned int *)STREAM_DATA (bgp_ifindices_buf); + api.ifindex = (ifindex_t *)STREAM_DATA (bgp_ifindices_buf); SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); api.metric = metric; api.tag = 0; diff --git a/bgpd/bgp_zebra.h b/bgpd/bgp_zebra.h index 1f845bd918..af921af82f 100644 --- a/bgpd/bgp_zebra.h +++ b/bgpd/bgp_zebra.h @@ -58,8 +58,8 @@ extern int bgp_redistribute_unreg (struct bgp *, afi_t, int, u_short); extern struct interface *if_lookup_by_ipv4 (struct in_addr *, vrf_id_t); extern struct interface *if_lookup_by_ipv4_exact (struct in_addr *, vrf_id_t); #ifdef HAVE_IPV6 -extern struct interface *if_lookup_by_ipv6 (struct in6_addr *, unsigned int, vrf_id_t); -extern struct interface *if_lookup_by_ipv6_exact (struct in6_addr *, unsigned int, vrf_id_t); +extern struct interface *if_lookup_by_ipv6 (struct in6_addr *, ifindex_t, vrf_id_t); +extern struct interface *if_lookup_by_ipv6_exact (struct in6_addr *, ifindex_t, vrf_id_t); #endif /* HAVE_IPV6 */ #endif /* _QUAGGA_BGP_ZEBRA_H */ diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 991afdf7cc..d9a68599c5 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -583,7 +583,7 @@ struct peer time_t readtime; /* Last read time */ time_t resettime; /* Last reset time */ - unsigned int ifindex; /* ifindex of the BGP connection. */ + ifindex_t ifindex; /* ifindex of the BGP connection. */ char *conf_if; /* neighbor interface config name. */ struct interface *ifp; /* corresponding interface */ char *ifname; /* bind interface name. */ diff --git a/isisd/isis_route.c b/isisd/isis_route.c index e72e0cac7a..67d45c8f10 100644 --- a/isisd/isis_route.c +++ b/isisd/isis_route.c @@ -50,7 +50,7 @@ #include "isis_zebra.h" static struct isis_nexthop * -isis_nexthop_create (struct in_addr *ip, unsigned int ifindex) +isis_nexthop_create (struct in_addr *ip, ifindex_t ifindex) { struct listnode *node; struct isis_nexthop *nexthop; @@ -91,7 +91,7 @@ isis_nexthop_delete (struct isis_nexthop *nexthop) static int nexthoplookup (struct list *nexthops, struct in_addr *ip, - unsigned int ifindex) + ifindex_t ifindex) { struct listnode *node; struct isis_nexthop *nh; @@ -130,7 +130,7 @@ nexthops_print (struct list *nhs) #ifdef HAVE_IPV6 static struct isis_nexthop6 * -isis_nexthop6_new (struct in6_addr *ip6, unsigned int ifindex) +isis_nexthop6_new (struct in6_addr *ip6, ifindex_t ifindex) { struct isis_nexthop6 *nexthop6; @@ -144,7 +144,7 @@ isis_nexthop6_new (struct in6_addr *ip6, unsigned int ifindex) } static struct isis_nexthop6 * -isis_nexthop6_create (struct in6_addr *ip6, unsigned int ifindex) +isis_nexthop6_create (struct in6_addr *ip6, ifindex_t ifindex) { struct listnode *node; struct isis_nexthop6 *nexthop6; @@ -181,7 +181,7 @@ isis_nexthop6_delete (struct isis_nexthop6 *nexthop6) static int nexthop6lookup (struct list *nexthops6, struct in6_addr *ip6, - unsigned int ifindex) + ifindex_t ifindex) { struct listnode *node; struct isis_nexthop6 *nh6; diff --git a/isisd/isis_route.h b/isisd/isis_route.h index 5adea2293b..0d2379cbe8 100644 --- a/isisd/isis_route.h +++ b/isisd/isis_route.h @@ -28,7 +28,7 @@ #ifdef HAVE_IPV6 struct isis_nexthop6 { - unsigned int ifindex; + ifindex_t ifindex; struct in6_addr ip6; struct in6_addr router_address6; unsigned int lock; @@ -37,7 +37,7 @@ struct isis_nexthop6 struct isis_nexthop { - unsigned int ifindex; + ifindex_t ifindex; struct in_addr ip; struct in_addr router_address; unsigned int lock; diff --git a/isisd/isis_zebra.c b/isisd/isis_zebra.c index 125a2f63d3..81f9d86930 100644 --- a/isisd/isis_zebra.c +++ b/isisd/isis_zebra.c @@ -333,7 +333,7 @@ isis_zebra_route_add_ipv6 (struct prefix *prefix, { struct zapi_ipv6 api; struct in6_addr **nexthop_list; - unsigned int *ifindex_list; + ifindex_t *ifindex_list; struct isis_nexthop6 *nexthop6; int i, size; struct listnode *node; @@ -370,7 +370,7 @@ isis_zebra_route_add_ipv6 (struct prefix *prefix, /* allocate memory for ifindex_list */ size = sizeof (unsigned int) * listcount (route_info->nexthops6); - ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size); + ifindex_list = (ifindex_t *) XMALLOC (MTYPE_ISIS_TMP, size); if (!ifindex_list) { zlog_err ("isis_zebra_add_route_ipv6: out of memory!"); @@ -420,7 +420,7 @@ isis_zebra_route_del_ipv6 (struct prefix *prefix, { struct zapi_ipv6 api; struct in6_addr **nexthop_list; - unsigned int *ifindex_list; + ifindex_t *ifindex_list; struct isis_nexthop6 *nexthop6; int i, size; struct listnode *node; @@ -451,7 +451,7 @@ isis_zebra_route_del_ipv6 (struct prefix *prefix, /* allocate memory for ifindex_list */ size = sizeof (unsigned int) * listcount (route_info->nexthops6); - ifindex_list = (unsigned int *) XMALLOC (MTYPE_ISIS_TMP, size); + ifindex_list = (ifindex_t *) XMALLOC (MTYPE_ISIS_TMP, size); if (!ifindex_list) { zlog_err ("isis_zebra_route_del_ipv6: out of memory!"); diff --git a/lib/if.c b/lib/if.c index 8f1461326f..2c63c985dc 100644 --- a/lib/if.c +++ b/lib/if.c @@ -226,41 +226,41 @@ if_add_hook (int type, int (*func)(struct interface *ifp)) /* Interface existance check by index. */ struct interface * -if_lookup_by_index_vrf (unsigned int index, vrf_id_t vrf_id) +if_lookup_by_index_vrf (ifindex_t ifindex, vrf_id_t vrf_id) { struct listnode *node; struct interface *ifp; for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp)) { - if (ifp->ifindex == index) + if (ifp->ifindex == ifindex) return ifp; } return NULL; } struct interface * -if_lookup_by_index (unsigned int index) +if_lookup_by_index (ifindex_t ifindex) { - return if_lookup_by_index_vrf (index, VRF_DEFAULT); + return if_lookup_by_index_vrf (ifindex, VRF_DEFAULT); } const char * -ifindex2ifname_vrf (unsigned int index, vrf_id_t vrf_id) +ifindex2ifname_vrf (ifindex_t ifindex, vrf_id_t vrf_id) { struct interface *ifp; - return ((ifp = if_lookup_by_index_vrf (index, vrf_id)) != NULL) ? + return ((ifp = if_lookup_by_index_vrf (ifindex, vrf_id)) != NULL) ? ifp->name : "unknown"; } const char * -ifindex2ifname (unsigned int index) +ifindex2ifname (ifindex_t ifindex) { - return ifindex2ifname_vrf (index, VRF_DEFAULT); + return ifindex2ifname_vrf (ifindex, VRF_DEFAULT); } -unsigned int +ifindex_t ifname2ifindex_vrf (const char *name, vrf_id_t vrf_id) { struct interface *ifp; @@ -269,7 +269,7 @@ ifname2ifindex_vrf (const char *name, vrf_id_t vrf_id) : IFINDEX_INTERNAL; } -unsigned int +ifindex_t ifname2ifindex (const char *name) { return ifname2ifindex_vrf (name, VRF_DEFAULT); @@ -1167,7 +1167,7 @@ connected_add_by_prefix (struct interface *ifp, struct prefix *p, } #ifndef HAVE_IF_NAMETOINDEX -unsigned int +ifindex_t if_nametoindex (const char *name) { struct interface *ifp; @@ -1179,7 +1179,7 @@ if_nametoindex (const char *name) #ifndef HAVE_IF_INDEXTONAME char * -if_indextoname (unsigned int ifindex, char *name) +if_indextoname (ifindex_t ifindex, char *name) { struct interface *ifp; @@ -1244,7 +1244,7 @@ ifaddr_ipv4_delete (struct in_addr *ifaddr, struct interface *ifp) /* Lookup interface by interface's IP address or interface index. */ static struct interface * -ifaddr_ipv4_lookup (struct in_addr *addr, unsigned int ifindex) +ifaddr_ipv4_lookup (struct in_addr *addr, ifindex_t ifindex) { struct prefix_ipv4 p; struct route_node *rn; diff --git a/lib/if.h b/lib/if.h index 4ec85bc841..35d91f0cfa 100644 --- a/lib/if.h +++ b/lib/if.h @@ -21,6 +21,7 @@ Boston, MA 02111-1307, USA. */ #ifndef _ZEBRA_IF_H #define _ZEBRA_IF_H +#include "zebra.h" #include "linklist.h" /* @@ -36,6 +37,8 @@ Boston, MA 02111-1307, USA. */ #define INTERFACE_NAMSIZ 20 #define INTERFACE_HWADDR_MAX 20 +typedef signed int ifindex_t; + #ifdef HAVE_PROC_NET_DEV struct if_stats { @@ -82,9 +85,9 @@ struct interface /* Interface index (should be IFINDEX_INTERNAL for non-kernel or deleted interfaces). */ - unsigned int ifindex; + ifindex_t ifindex; #define IFINDEX_INTERNAL 0 -#define IFINDEX_DELETED UINT_MAX +#define IFINDEX_DELETED INT_MAX /* Zebra internal interface status */ u_char status; @@ -264,7 +267,7 @@ struct nbr_connected /* Prototypes. */ extern int if_cmp_name_func (char *, char *); extern struct interface *if_create (const char *name, int namelen); -extern struct interface *if_lookup_by_index (unsigned int); +extern struct interface *if_lookup_by_index (ifindex_t); extern struct interface *if_lookup_exact_address (void *matchaddr, int family); extern struct interface *if_lookup_address (void *matchaddr, int family); extern struct interface *if_lookup_prefix (struct prefix *prefix); @@ -273,8 +276,7 @@ extern void if_update_vrf (struct interface *, const char *name, int namelen, vrf_id_t vrf_id); extern struct interface *if_create_vrf (const char *name, int namelen, vrf_id_t vrf_id); -extern struct interface *if_lookup_by_index_vrf (unsigned int, - vrf_id_t vrf_id); +extern struct interface *if_lookup_by_index_vrf (ifindex_t, vrf_id_t vrf_id); extern struct interface *if_lookup_exact_address_vrf (void *matchaddr, int family, vrf_id_t vrf_id); extern struct interface *if_lookup_address_vrf (void *matchaddr, int family, @@ -332,14 +334,14 @@ extern const char *if_flag_dump(unsigned long); /* Please use ifindex2ifname instead of if_indextoname where possible; ifindex2ifname uses internal interface info, whereas if_indextoname must make a system call. */ -extern const char *ifindex2ifname (unsigned int); -extern const char *ifindex2ifname_vrf (unsigned int, vrf_id_t vrf_id); +extern const char *ifindex2ifname (ifindex_t); +extern const char *ifindex2ifname_vrf (ifindex_t, vrf_id_t vrf_id); /* Please use ifname2ifindex instead of if_nametoindex where possible; ifname2ifindex uses internal interface info, whereas if_nametoindex must make a system call. */ -extern unsigned int ifname2ifindex(const char *ifname); -extern unsigned int ifname2ifindex_vrf(const char *ifname, vrf_id_t vrf_id); +extern ifindex_t ifname2ifindex(const char *ifname); +extern ifindex_t ifname2ifindex_vrf(const char *ifname, vrf_id_t vrf_id); /* Connected address functions. */ extern struct connected *connected_new (void); @@ -359,10 +361,10 @@ extern void nbr_connected_free (struct nbr_connected *); struct nbr_connected *nbr_connected_check (struct interface *, struct prefix *); #ifndef HAVE_IF_NAMETOINDEX -extern unsigned int if_nametoindex (const char *); +extern ifindex_t if_nametoindex (const char *); #endif #ifndef HAVE_IF_INDEXTONAME -extern char *if_indextoname (unsigned int, char *); +extern char *if_indextoname (ifindex_t, char *); #endif /* Exported variables. */ diff --git a/lib/nexthop.h b/lib/nexthop.h index eb9b27ea9e..4445c4ad27 100644 --- a/lib/nexthop.h +++ b/lib/nexthop.h @@ -48,7 +48,7 @@ struct nexthop struct nexthop *prev; /* Interface index. */ - unsigned int ifindex; + ifindex_t ifindex; enum nexthop_types_t type; diff --git a/lib/sockopt.c b/lib/sockopt.c index d8204936f9..31b2edbacf 100644 --- a/lib/sockopt.c +++ b/lib/sockopt.c @@ -221,7 +221,7 @@ setsockopt_ipv4_multicast(int sock, int optname, struct in_addr if_addr, unsigned int mcast_addr, - unsigned int ifindex) + ifindex_t ifindex) { #ifdef HAVE_RFC3678 struct group_req gr; @@ -322,7 +322,7 @@ setsockopt_ipv4_multicast(int sock, */ int setsockopt_ipv4_multicast_if(int sock, struct in_addr if_addr, - unsigned int ifindex) + ifindex_t ifindex) { #ifdef HAVE_STRUCT_IP_MREQN_IMR_IFINDEX @@ -352,7 +352,7 @@ setsockopt_ipv4_multicast_if(int sock, struct in_addr if_addr, } static int -setsockopt_ipv4_ifindex (int sock, int val) +setsockopt_ipv4_ifindex (int sock, ifindex_t val) { int ret; @@ -388,7 +388,7 @@ setsockopt_ipv4_tos(int sock, int tos) int -setsockopt_ifindex (int af, int sock, int val) +setsockopt_ifindex (int af, int sock, ifindex_t val) { int ret = -1; @@ -415,11 +415,11 @@ setsockopt_ifindex (int af, int sock, int val) * Returns the interface index (small integer >= 1) if it can be * determined, or else 0. */ -static int +static ifindex_t getsockopt_ipv4_ifindex (struct msghdr *msgh) { /* XXX: initialize to zero? (Always overwritten, so just cosmetic.) */ - int ifindex = -1; + ifindex_t ifindex = -1; #if defined(IP_PKTINFO) /* Linux pktinfo based ifindex retrieval */ @@ -439,7 +439,7 @@ getsockopt_ipv4_ifindex (struct msghdr *msgh) struct sockaddr_dl *sdl; #else /* SUNOS_5 uses an integer with the index. */ - int *ifindex_p; + ifindex_t *ifindex_p; #endif /* SUNOS_5 */ #ifndef SUNOS_5 @@ -480,7 +480,7 @@ getsockopt_ipv4_ifindex (struct msghdr *msgh) } /* return ifindex, 0 if none found */ -int +ifindex_t getsockopt_ifindex (int af, struct msghdr *msgh) { switch (af) diff --git a/lib/sockopt.h b/lib/sockopt.h index a597314c3d..d67b510b66 100644 --- a/lib/sockopt.h +++ b/lib/sockopt.h @@ -84,16 +84,16 @@ extern int setsockopt_ipv6_tclass (int, int); ? SOPT_SIZE_CMSG_PKTINFO_IPV6()) extern int setsockopt_ipv4_multicast_if(int sock, struct in_addr if_addr, - unsigned int ifindex); + ifindex_t ifindex); extern int setsockopt_ipv4_multicast(int sock, int optname, struct in_addr if_addr, unsigned int mcast_addr, - unsigned int ifindex); + ifindex_t ifindex); extern int setsockopt_ipv4_tos(int sock, int tos); /* Ask for, and get, ifindex, by whatever method is supported. */ -extern int setsockopt_ifindex (int, int, int); -extern int getsockopt_ifindex (int, struct msghdr *); +extern int setsockopt_ifindex (int, int, ifindex_t); +extern ifindex_t getsockopt_ifindex (int, struct msghdr *); /* swab the fields in iph between the host order and system order expected * for IP_HDRINCL. diff --git a/lib/sockunion.c b/lib/sockunion.c index b5a2eb954a..9184e500fc 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -291,7 +291,7 @@ sockunion_sizeof (const union sockunion *su) 1 : connect is in progress */ enum connect_result sockunion_connect (int fd, const union sockunion *peersu, unsigned short port, - unsigned int ifindex) + ifindex_t ifindex) { int ret; int val; diff --git a/lib/sockunion.h b/lib/sockunion.h index a33051ae57..105b11a24c 100644 --- a/lib/sockunion.h +++ b/lib/sockunion.h @@ -24,6 +24,7 @@ #define _ZEBRA_SOCKUNION_H #include "privs.h" +#include "if.h" union sockunion { @@ -95,7 +96,7 @@ extern int sockunion_socket (const union sockunion *su); extern const char *inet_sutop (const union sockunion *su, char *str); extern enum connect_result sockunion_connect (int fd, const union sockunion *su, unsigned short port, - unsigned int); + ifindex_t); extern union sockunion *sockunion_getsockname (int); extern union sockunion *sockunion_getpeername (int); extern union sockunion *sockunion_dup (const union sockunion *); diff --git a/lib/zclient.c b/lib/zclient.c index ef9516c912..a28db083cb 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1133,7 +1133,7 @@ memconstant(const void *s, int c, size_t n) struct connected * zebra_interface_address_read (int type, struct stream *s, vrf_id_t vrf_id) { - unsigned int ifindex; + ifindex_t ifindex; struct interface *ifp; struct connected *ifc; struct prefix p, d; diff --git a/lib/zclient.h b/lib/zclient.h index f30190c1b4..8926bbbe63 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -146,7 +146,7 @@ struct zapi_ipv4 struct in_addr **nexthop; u_char ifindex_num; - unsigned int *ifindex; + ifindex_t *ifindex; u_char distance; @@ -229,7 +229,7 @@ struct zapi_ipv6 struct in6_addr **nexthop; u_char ifindex_num; - unsigned int *ifindex; + ifindex_t *ifindex; u_char distance; diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index 1207419e58..208d3b8c4c 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -426,7 +426,7 @@ ospf6_asbr_send_externals_to_area (struct ospf6_area *oa) } void -ospf6_asbr_redistribute_add (int type, int ifindex, struct prefix *prefix, +ospf6_asbr_redistribute_add (int type, ifindex_t ifindex, struct prefix *prefix, u_int nexthop_num, struct in6_addr *nexthop) { int ret; @@ -575,7 +575,8 @@ ospf6_asbr_redistribute_add (int type, int ifindex, struct prefix *prefix, } void -ospf6_asbr_redistribute_remove (int type, int ifindex, struct prefix *prefix) +ospf6_asbr_redistribute_remove (int type, ifindex_t ifindex, + struct prefix *prefix) { struct ospf6_route *match; struct ospf6_external_info *info = NULL; diff --git a/ospf6d/ospf6_asbr.h b/ospf6d/ospf6_asbr.h index 90befdc0dd..645e8fd9cf 100644 --- a/ospf6d/ospf6_asbr.h +++ b/ospf6d/ospf6_asbr.h @@ -49,7 +49,7 @@ struct ospf6_external_info struct in6_addr forwarding; /* u_int32_t tag; */ - unsigned int ifindex; + ifindex_t ifindex; }; /* AS-External-LSA */ @@ -79,11 +79,11 @@ extern void ospf6_asbr_lsentry_add (struct ospf6_route *asbr_entry); extern void ospf6_asbr_lsentry_remove (struct ospf6_route *asbr_entry); extern int ospf6_asbr_is_asbr (struct ospf6 *o); -extern void ospf6_asbr_redistribute_add (int type, int ifindex, +extern void ospf6_asbr_redistribute_add (int type, ifindex_t ifindex, struct prefix *prefix, u_int nexthop_num, struct in6_addr *nexthop); -extern void ospf6_asbr_redistribute_remove (int type, int ifindex, +extern void ospf6_asbr_redistribute_remove (int type, ifindex_t ifindex, struct prefix *prefix); extern int ospf6_redistribute_config_write (struct vty *vty); diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index 720a3e0e69..f24ec46da7 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -61,7 +61,7 @@ const char *ospf6_interface_state_str[] = }; struct ospf6_interface * -ospf6_interface_lookup_by_ifindex (int ifindex) +ospf6_interface_lookup_by_ifindex (ifindex_t ifindex) { struct ospf6_interface *oi; struct interface *ifp; diff --git a/ospf6d/ospf6_interface.h b/ospf6d/ospf6_interface.h index 5e6b455682..3e09bfb930 100644 --- a/ospf6d/ospf6_interface.h +++ b/ospf6d/ospf6_interface.h @@ -152,7 +152,7 @@ extern const char *ospf6_interface_state_str[]; /* Function Prototypes */ -extern struct ospf6_interface *ospf6_interface_lookup_by_ifindex (int); +extern struct ospf6_interface *ospf6_interface_lookup_by_ifindex (ifindex_t); extern struct ospf6_interface *ospf6_interface_create (struct interface *); extern void ospf6_interface_delete (struct ospf6_interface *); diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c index fe57f2f423..b0e94288b4 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -290,7 +290,7 @@ ospf6_hello_recv (struct in6_addr *src, struct in6_addr *dst, memcpy (&on->linklocal_addr, src, sizeof (struct in6_addr)); /* Neighbor ifindex check */ - if (on->ifindex != ntohl (hello->interface_id)) + if (on->ifindex != (ifindex_t)ntohl (hello->interface_id)) { on->ifindex = ntohl (hello->interface_id); neighbor_ifindex_change++; @@ -1525,7 +1525,7 @@ ospf6_receive (struct thread *thread) unsigned int len; char srcname[64], dstname[64]; struct in6_addr src, dst; - unsigned int ifindex; + ifindex_t ifindex; struct iovec iovector[2]; struct ospf6_interface *oi; struct ospf6_header *oh; diff --git a/ospf6d/ospf6_message.h b/ospf6d/ospf6_message.h index b085a9673b..4a9e0c7a66 100644 --- a/ospf6d/ospf6_message.h +++ b/ospf6d/ospf6_message.h @@ -64,7 +64,7 @@ struct ospf6_header #define OSPF6_HELLO_MIN_SIZE 20U struct ospf6_hello { - u_int32_t interface_id; + ifindex_t interface_id; u_char priority; u_char options[3]; u_int16_t hello_interval; diff --git a/ospf6d/ospf6_neighbor.h b/ospf6d/ospf6_neighbor.h index fad7fd578a..f9e197e99b 100644 --- a/ospf6d/ospf6_neighbor.h +++ b/ospf6d/ospf6_neighbor.h @@ -53,7 +53,7 @@ struct ospf6_neighbor u_int32_t router_id; /* Neighbor Interface ID */ - u_int32_t ifindex; + ifindex_t ifindex; /* Router Priority of this neighbor */ u_char priority; diff --git a/ospf6d/ospf6_network.c b/ospf6d/ospf6_network.c index 5e254661f1..2227d03477 100644 --- a/ospf6d/ospf6_network.c +++ b/ospf6d/ospf6_network.c @@ -113,7 +113,7 @@ ospf6_serv_sock (void) /* ospf6 set socket option */ int -ospf6_sso (u_int ifindex, struct in6_addr *group, int option) +ospf6_sso (ifindex_t ifindex, struct in6_addr *group, int option) { struct ipv6_mreq mreq6; int ret; @@ -193,7 +193,7 @@ iov_totallen (struct iovec *iov) int ospf6_sendmsg (struct in6_addr *src, struct in6_addr *dst, - unsigned int *ifindex, struct iovec *message) + ifindex_t *ifindex, struct iovec *message) { int retval; struct msghdr smsghdr; @@ -255,7 +255,7 @@ ospf6_sendmsg (struct in6_addr *src, struct in6_addr *dst, int ospf6_recvmsg (struct in6_addr *src, struct in6_addr *dst, - unsigned int *ifindex, struct iovec *message) + ifindex_t *ifindex, struct iovec *message) { int retval; struct msghdr rmsghdr; diff --git a/ospf6d/ospf6_network.h b/ospf6d/ospf6_network.h index 2aeafe5041..4fa2839519 100644 --- a/ospf6d/ospf6_network.h +++ b/ospf6d/ospf6_network.h @@ -29,12 +29,12 @@ extern struct in6_addr allspfrouters6; extern struct in6_addr alldrouters6; extern int ospf6_serv_sock (void); -extern int ospf6_sso (u_int ifindex, struct in6_addr *group, int option); +extern int ospf6_sso (ifindex_t ifindex, struct in6_addr *group, int option); extern int ospf6_sendmsg (struct in6_addr *, struct in6_addr *, - unsigned int *, struct iovec *); + ifindex_t *, struct iovec *); extern int ospf6_recvmsg (struct in6_addr *, struct in6_addr *, - unsigned int *, struct iovec *); + ifindex_t *, struct iovec *); #endif /* OSPF6_NETWORK_H */ diff --git a/ospf6d/ospf6_route.c b/ospf6d/ospf6_route.c index 0a98c8f082..5172eee48d 100644 --- a/ospf6d/ospf6_route.c +++ b/ospf6d/ospf6_route.c @@ -331,7 +331,7 @@ ospf6_add_nexthop (struct list *nh_list, int ifindex, void ospf6_route_zebra_copy_nexthops (struct ospf6_route *route, - unsigned int *ifindexes, + ifindex_t *ifindexes, struct in6_addr **nexthop_addr, int entries) { diff --git a/ospf6d/ospf6_route.h b/ospf6d/ospf6_route.h index e783b72d8e..610b0970b0 100644 --- a/ospf6d/ospf6_route.h +++ b/ospf6d/ospf6_route.h @@ -41,7 +41,7 @@ extern unsigned char conf_debug_ospf6_route; struct ospf6_nexthop { /* Interface index */ - unsigned int ifindex; + ifindex_t ifindex; /* IP address, if any */ struct in6_addr address; @@ -278,7 +278,7 @@ extern int ospf6_num_nexthops (struct list *nh_list); extern int ospf6_route_cmp_nexthops (struct ospf6_route *a, struct ospf6_route *b); extern void ospf6_route_zebra_copy_nexthops (struct ospf6_route *route, - unsigned int *ifindices, + ifindex_t *ifindices, struct in6_addr **addr, int entries); extern int ospf6_route_get_first_nh_index (struct ospf6_route *route); diff --git a/ospf6d/ospf6_snmp.c b/ospf6d/ospf6_snmp.c index cf1630bbc9..382cf62f72 100644 --- a/ospf6d/ospf6_snmp.c +++ b/ospf6d/ospf6_snmp.c @@ -625,7 +625,7 @@ ospfv3WwLsdbEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { struct ospf6_lsa *lsa = NULL; - u_int32_t ifindex, area_id, id, instid, adv_router; + ifindex_t ifindex, area_id, id, instid, adv_router; u_int16_t type; int len; oid *offset; @@ -837,7 +837,8 @@ static u_char * ospfv3IfEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { - unsigned int ifindex, instid; + ifindex_t ifindex = 0; + unsigned int instid = 0; struct ospf6_interface *oi = NULL; struct ospf6_lsa *lsa = NULL; struct interface *iif; @@ -851,8 +852,6 @@ ospfv3IfEntry (struct variable *v, oid *name, size_t *length, == MATCH_FAILED) return NULL; - ifindex = instid = 0; - /* Check OSPFv3 instance. */ if (ospf6 == NULL) return NULL; @@ -990,7 +989,8 @@ static u_char * ospfv3NbrEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { - unsigned int ifindex, instid, rtrid; + ifindex_t ifindex = 0; + unsigned int instid, rtrid; struct ospf6_interface *oi = NULL; struct ospf6_neighbor *on = NULL; struct interface *iif; @@ -1003,7 +1003,7 @@ ospfv3NbrEntry (struct variable *v, oid *name, size_t *length, == MATCH_FAILED) return NULL; - ifindex = instid = rtrid = 0; + instid = rtrid = 0; /* Check OSPFv3 instance. */ if (ospf6 == NULL) diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c index ab1213ebb6..957988b53d 100644 --- a/ospf6d/ospf6_spf.c +++ b/ospf6d/ospf6_spf.c @@ -266,7 +266,7 @@ ospf6_nexthop_calc (struct ospf6_vertex *w, struct ospf6_vertex *v, caddr_t lsdesc) { int i; - unsigned int ifindex; + ifindex_t ifindex; struct ospf6_interface *oi; u_int16_t type; u_int32_t adv_router; diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c index 0395b082da..77ea01e53d 100644 --- a/ospf6d/ospf6_zebra.c +++ b/ospf6d/ospf6_zebra.c @@ -377,7 +377,7 @@ ospf6_zebra_route_update (int type, struct ospf6_route *request) char buf[PREFIX2STR_BUFFER]; int nhcount; struct in6_addr **nexthops; - unsigned int *ifindexes; + ifindex_t *ifindexes; int ret = 0; struct prefix_ipv6 *dest; @@ -443,7 +443,7 @@ ospf6_zebra_route_update (int type, struct ospf6_route *request) /* allocate memory for ifindex_list */ ifindexes = XCALLOC (MTYPE_OSPF6_OTHER, - nhcount * sizeof (unsigned int)); + nhcount * sizeof (ifindex_t)); if (ifindexes == NULL) { zlog_warn ("Can't send route to zebra: malloc failed"); diff --git a/ospfd/ospf_asbr.c b/ospfd/ospf_asbr.c index ddb26dd543..21f99af128 100644 --- a/ospfd/ospf_asbr.c +++ b/ospfd/ospf_asbr.c @@ -136,7 +136,7 @@ ospf_route_map_set_compare (struct route_map_set_values *values1, /* Add an External info for AS-external-LSA. */ struct external_info * ospf_external_info_add (u_char type, u_short instance, struct prefix_ipv4 p, - unsigned int ifindex, struct in_addr nexthop, + ifindex_t ifindex, struct in_addr nexthop, u_short tag) { struct external_info *new; diff --git a/ospfd/ospf_asbr.h b/ospfd/ospf_asbr.h index ade671013a..25a53aad4f 100644 --- a/ospfd/ospf_asbr.h +++ b/ospfd/ospf_asbr.h @@ -41,7 +41,7 @@ struct external_info struct prefix_ipv4 p; /* Interface index. */ - unsigned int ifindex; + ifindex_t ifindex; /* Nexthop address. */ struct in_addr nexthop; @@ -63,7 +63,7 @@ extern int ospf_route_map_set_compare (struct route_map_set_values *, struct route_map_set_values *); extern struct external_info *ospf_external_info_add (u_char, u_short, struct prefix_ipv4, - unsigned int, + ifindex_t, struct in_addr, u_short); extern void ospf_external_info_delete (u_char, u_short, struct prefix_ipv4); diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 68a3946b3a..b96ed452c1 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -2251,7 +2251,7 @@ ospf_nssa_lsa_flush (struct ospf *ospf, struct prefix_ipv4 *p) void ospf_external_lsa_flush (struct ospf *ospf, u_char type, struct prefix_ipv4 *p, - unsigned int ifindex /*, struct in_addr nexthop */) + ifindex_t ifindex /*, struct in_addr nexthop */) { struct ospf_lsa *lsa; diff --git a/ospfd/ospf_lsa.h b/ospfd/ospf_lsa.h index b3d72109d6..28ecc9d4d6 100644 --- a/ospfd/ospf_lsa.h +++ b/ospfd/ospf_lsa.h @@ -277,7 +277,7 @@ extern struct ospf_lsa *ospf_lsa_install (struct ospf *, extern void ospf_nssa_lsa_flush (struct ospf *ospf, struct prefix_ipv4 *p); extern void ospf_external_lsa_flush (struct ospf *, u_char, struct prefix_ipv4 *, - unsigned int /* , struct in_addr nexthop */); + ifindex_t /* , struct in_addr nexthop */); extern struct in_addr ospf_get_ip_from_ifp (struct ospf_interface *); diff --git a/ospfd/ospf_network.c b/ospfd/ospf_network.c index 9f516d7390..6caa38d68b 100644 --- a/ospfd/ospf_network.c +++ b/ospfd/ospf_network.c @@ -48,7 +48,7 @@ extern struct zebra_privs_t ospfd_privs; /* Join to the OSPF ALL SPF ROUTERS multicast group. */ int ospf_if_add_allspfrouters (struct ospf *top, struct prefix *p, - unsigned int ifindex) + ifindex_t ifindex) { int ret; @@ -69,7 +69,7 @@ ospf_if_add_allspfrouters (struct ospf *top, struct prefix *p, int ospf_if_drop_allspfrouters (struct ospf *top, struct prefix *p, - unsigned int ifindex) + ifindex_t ifindex) { int ret; @@ -89,8 +89,7 @@ ospf_if_drop_allspfrouters (struct ospf *top, struct prefix *p, /* Join to the OSPF ALL Designated ROUTERS multicast group. */ int -ospf_if_add_alldrouters (struct ospf *top, struct prefix *p, unsigned int - ifindex) +ospf_if_add_alldrouters (struct ospf *top, struct prefix *p, ifindex_t ifindex) { int ret; @@ -110,8 +109,7 @@ ospf_if_add_alldrouters (struct ospf *top, struct prefix *p, unsigned int } int -ospf_if_drop_alldrouters (struct ospf *top, struct prefix *p, unsigned int - ifindex) +ospf_if_drop_alldrouters (struct ospf *top, struct prefix *p, ifindex_t ifindex) { int ret; @@ -130,7 +128,7 @@ ospf_if_drop_alldrouters (struct ospf *top, struct prefix *p, unsigned int } int -ospf_if_ipmulticast (struct ospf *top, struct prefix *p, unsigned int ifindex) +ospf_if_ipmulticast (struct ospf *top, struct prefix *p, ifindex_t ifindex) { u_char val; int ret, len; diff --git a/ospfd/ospf_network.h b/ospfd/ospf_network.h index e0a5c69d5c..8257adb4af 100644 --- a/ospfd/ospf_network.h +++ b/ospfd/ospf_network.h @@ -25,14 +25,14 @@ /* Prototypes. */ extern int ospf_if_add_allspfrouters (struct ospf *, struct prefix *, - unsigned int); + ifindex_t); extern int ospf_if_drop_allspfrouters (struct ospf *, struct prefix *, - unsigned int); + ifindex_t); extern int ospf_if_add_alldrouters (struct ospf *, struct prefix *, - unsigned int); + ifindex_t); extern int ospf_if_drop_alldrouters (struct ospf *, struct prefix *, - unsigned int); -extern int ospf_if_ipmulticast (struct ospf *, struct prefix *, unsigned int); + ifindex_t); +extern int ospf_if_ipmulticast (struct ospf *, struct prefix *, ifindex_t); extern int ospf_sock_init (void); extern void ospf_adjust_sndbuflen (struct ospf *, unsigned int); diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index 2df1596ee3..e6014a14c6 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -2143,7 +2143,7 @@ ospf_recv_packet (int fd, struct interface **ifp, struct stream *ibuf) int ret; struct ip *iph; u_int16_t ip_len; - unsigned int ifindex = 0; + ifindex_t ifindex = 0; struct iovec iov; /* Header and data both require alignment. */ char buff [CMSG_SPACE(SOPT_SIZE_CMSG_IFINDEX_IPV4())]; diff --git a/ospfd/ospf_route.h b/ospfd/ospf_route.h index d0b121db38..6b6d9f1fab 100644 --- a/ospfd/ospf_route.h +++ b/ospfd/ospf_route.h @@ -39,7 +39,7 @@ struct ospf_path { struct in_addr nexthop; struct in_addr adv_router; - unsigned int ifindex; + ifindex_t ifindex; unsigned char unnumbered; }; diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c index bedcb559bf..676756d6d9 100644 --- a/ospfd/ospf_snmp.c +++ b/ospfd/ospf_snmp.c @@ -1413,7 +1413,7 @@ static struct list *ospf_snmp_iflist; struct ospf_snmp_if { struct in_addr addr; - unsigned int ifindex; + ifindex_t ifindex; struct interface *ifp; }; @@ -1455,7 +1455,7 @@ ospf_snmp_if_update (struct interface *ifp) struct prefix *p; struct ospf_snmp_if *osif; struct in_addr *addr; - unsigned int ifindex; + ifindex_t ifindex; ospf_snmp_if_delete (ifp); @@ -1530,7 +1530,7 @@ ospf_snmp_is_if_have_addr (struct interface *ifp) } static struct ospf_interface * -ospf_snmp_if_lookup (struct in_addr *ifaddr, unsigned int *ifindex) +ospf_snmp_if_lookup (struct in_addr *ifaddr, ifindex_t *ifindex) { struct listnode *node; struct ospf_snmp_if *osif; @@ -1554,8 +1554,8 @@ ospf_snmp_if_lookup (struct in_addr *ifaddr, unsigned int *ifindex) } static struct ospf_interface * -ospf_snmp_if_lookup_next (struct in_addr *ifaddr, unsigned int *ifindex, - int ifaddr_next, int ifindex_next) +ospf_snmp_if_lookup_next (struct in_addr *ifaddr, ifindex_t *ifindex, + int ifaddr_next, ifindex_t ifindex_next) { struct ospf_snmp_if *osif; struct listnode *nn; @@ -1638,11 +1638,11 @@ ospf_snmp_iftype (struct interface *ifp) static struct ospf_interface * ospfIfLookup (struct variable *v, oid *name, size_t *length, - struct in_addr *ifaddr, unsigned int *ifindex, int exact) + struct in_addr *ifaddr, ifindex_t *ifindex, int exact) { unsigned int len; int ifaddr_next = 0; - int ifindex_next = 0; + ifindex_t ifindex_next = 0; struct ospf_interface *oi; oid *offset; @@ -1694,7 +1694,7 @@ static u_char * ospfIfEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { - unsigned int ifindex; + ifindex_t ifindex; struct in_addr ifaddr; struct ospf_interface *oi; struct ospf *ospf; @@ -1802,11 +1802,11 @@ ospfIfEntry (struct variable *v, oid *name, size_t *length, int exact, static struct ospf_interface * ospfIfMetricLookup (struct variable *v, oid *name, size_t *length, - struct in_addr *ifaddr, unsigned int *ifindex, int exact) + struct in_addr *ifaddr, ifindex_t *ifindex, int exact) { unsigned int len; int ifaddr_next = 0; - int ifindex_next = 0; + ifindex_t ifindex_next = 0; struct ospf_interface *oi; oid *offset; int metric; @@ -1866,7 +1866,7 @@ ospfIfMetricEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { /* Currently we support metric 1 only. */ - unsigned int ifindex; + ifindex_t ifindex; struct in_addr ifaddr; struct ospf_interface *oi; struct ospf *ospf; @@ -2133,7 +2133,7 @@ ospfVirtIfEntry (struct variable *v, oid *name, size_t *length, int exact, static struct ospf_neighbor * ospf_snmp_nbr_lookup (struct ospf *ospf, struct in_addr *nbr_addr, - unsigned int *ifindex) + ifindex_t *ifindex) { struct listnode *node, *nnode; struct ospf_interface *oi; @@ -2161,7 +2161,7 @@ ospf_snmp_nbr_lookup (struct ospf *ospf, struct in_addr *nbr_addr, } static struct ospf_neighbor * -ospf_snmp_nbr_lookup_next (struct in_addr *nbr_addr, unsigned int *ifindex, +ospf_snmp_nbr_lookup_next (struct in_addr *nbr_addr, ifindex_t *ifindex, int first) { struct listnode *nn; @@ -2208,7 +2208,7 @@ ospf_snmp_nbr_lookup_next (struct in_addr *nbr_addr, unsigned int *ifindex, static struct ospf_neighbor * ospfNbrLookup (struct variable *v, oid *name, size_t *length, - struct in_addr *nbr_addr, unsigned int *ifindex, int exact) + struct in_addr *nbr_addr, ifindex_t *ifindex, int exact) { unsigned int len; int first; @@ -2303,7 +2303,7 @@ ospfNbrEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { struct in_addr nbr_addr; - unsigned int ifindex; + ifindex_t ifindex; struct ospf_neighbor *nbr; struct ospf_interface *oi; diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 3c60275027..a8a1d08805 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -772,7 +772,7 @@ void pim_if_del_vif_all() } } -struct interface *pim_if_find_by_vif_index(int vif_index) +struct interface *pim_if_find_by_vif_index(ifindex_t vif_index) { struct listnode *ifnode; struct interface *ifp; @@ -784,6 +784,7 @@ struct interface *pim_if_find_by_vif_index(int vif_index) if (ifp->info) { struct pim_interface *pim_ifp; pim_ifp = ifp->info; + if (vif_index == pim_ifp->mroute_vif_index) return ifp; } @@ -795,7 +796,7 @@ struct interface *pim_if_find_by_vif_index(int vif_index) /* pim_if_add_vif() uses ifindex as vif_index */ -int pim_if_find_vifindex_by_ifindex(int ifindex) +int pim_if_find_vifindex_by_ifindex(ifindex_t ifindex) { struct pim_interface *pim_ifp; struct interface *ifp; @@ -954,7 +955,7 @@ static struct igmp_join *igmp_join_find(struct list *join_list, } static int igmp_join_sock(const char *ifname, - int ifindex, + ifindex_t ifindex, struct in_addr group_addr, struct in_addr source_addr) { diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h index 15489f81fa..790afabea1 100644 --- a/pimd/pim_iface.h +++ b/pimd/pim_iface.h @@ -63,7 +63,7 @@ enum pim_interface_type { struct pim_interface { enum pim_interface_type itype; uint32_t options; /* bit vector */ - int mroute_vif_index; + ifindex_t mroute_vif_index; struct in_addr primary_address; /* remember addr to detect change */ int igmp_default_robustness_variable; /* IGMPv3 QRV */ @@ -133,8 +133,8 @@ int pim_if_del_vif(struct interface *ifp); void pim_if_add_vif_all(void); void pim_if_del_vif_all(void); -struct interface *pim_if_find_by_vif_index(int vif_index); -int pim_if_find_vifindex_by_ifindex(int ifindex); +struct interface *pim_if_find_by_vif_index(ifindex_t vif_index); +int pim_if_find_vifindex_by_ifindex(ifindex_t ifindex); int pim_if_lan_delay_enabled(struct interface *ifp); uint16_t pim_if_effective_propagation_delay_msec(struct interface *ifp); diff --git a/pimd/pim_igmp.c b/pimd/pim_igmp.c index 440d648723..3b63b10e0d 100644 --- a/pimd/pim_igmp.c +++ b/pimd/pim_igmp.c @@ -46,7 +46,7 @@ static void group_timer_off(struct igmp_group *group); -static int igmp_sock_open(struct in_addr ifaddr, int ifindex, uint32_t pim_options) +static int igmp_sock_open(struct in_addr ifaddr, ifindex_t ifindex, uint32_t pim_options) { int fd; int join = 0; @@ -971,7 +971,7 @@ static int pim_igmp_read(struct thread *t) socklen_t tolen = sizeof(to); uint8_t buf[PIM_IGMP_BUFSIZE_READ]; int len; - int ifindex = -1; + ifindex_t ifindex = -1; int result = -1; /* defaults to bad */ zassert(t); @@ -1009,7 +1009,7 @@ static int pim_igmp_read(struct thread *t) #ifdef PIM_CHECK_RECV_IFINDEX_SANITY /* ifindex sanity check */ - if (ifindex != (int) igmp->interface->ifindex) { + if (ifindex != igmp->interface->ifindex) { char from_str[100]; char to_str[100]; struct interface *ifp; @@ -1021,7 +1021,7 @@ static int pim_igmp_read(struct thread *t) ifp = if_lookup_by_index(ifindex); if (ifp) { - zassert(ifindex == (int) ifp->ifindex); + zassert(ifindex == ifp->ifindex); } #ifdef PIM_REPORT_RECV_IFINDEX_MISMATCH diff --git a/pimd/pim_igmp_join.h b/pimd/pim_igmp_join.h index 95519ff974..1700276de8 100644 --- a/pimd/pim_igmp_join.h +++ b/pimd/pim_igmp_join.h @@ -39,7 +39,7 @@ struct group_source_req }; #endif -static int pim_igmp_join_source(int fd, int ifindex, +static int pim_igmp_join_source(int fd, ifindex_t ifindex, struct in_addr group_addr, struct in_addr source_addr) { diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index eedbc116d8..0dfd39cd16 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -278,7 +278,7 @@ static int pim_sock_read(struct thread *t) socklen_t tolen = sizeof(to); uint8_t buf[PIM_PIM_BUFSIZE_READ]; int len; - int ifindex = -1; + ifindex_t ifindex = -1; int result = -1; /* defaults to bad */ zassert(t); @@ -386,7 +386,7 @@ static void pim_sock_read_on(struct interface *ifp) pim_ifp->pim_sock_fd); } -static int pim_sock_open(struct in_addr ifaddr, int ifindex) +static int pim_sock_open(struct in_addr ifaddr, ifindex_t ifindex) { int fd; diff --git a/pimd/pim_sock.c b/pimd/pim_sock.c index e04cd41575..a024e3ae01 100644 --- a/pimd/pim_sock.c +++ b/pimd/pim_sock.c @@ -213,7 +213,7 @@ int pim_socket_mcast(int protocol, struct in_addr ifaddr, int ifindex, int loop) } int pim_socket_join(int fd, struct in_addr group, - struct in_addr ifaddr, int ifindex) + struct in_addr ifaddr, ifindex_t ifindex) { int ret; @@ -261,7 +261,7 @@ int pim_socket_join(int fd, struct in_addr group, return ret; } -int pim_socket_join_source(int fd, int ifindex, +int pim_socket_join_source(int fd, ifindex_t ifindex, struct in_addr group_addr, struct in_addr source_addr, const char *ifname) @@ -285,7 +285,7 @@ int pim_socket_join_source(int fd, int ifindex, int pim_socket_recvfromto(int fd, uint8_t *buf, size_t len, struct sockaddr_in *from, socklen_t *fromlen, struct sockaddr_in *to, socklen_t *tolen, - int *ifindex) + ifindex_t *ifindex) { struct msghdr msgh; struct cmsghdr *cmsg; diff --git a/pimd/pim_sock.h b/pimd/pim_sock.h index 9a9b64a4a3..f0a1600818 100644 --- a/pimd/pim_sock.h +++ b/pimd/pim_sock.h @@ -41,15 +41,15 @@ int pim_socket_raw(int protocol); int pim_socket_mcast(int protocol, struct in_addr ifaddr, int ifindex, int loop); int pim_socket_join(int fd, struct in_addr group, - struct in_addr ifaddr, int ifindex); -int pim_socket_join_source(int fd, int ifindex, + struct in_addr ifaddr, ifindex_t ifindex); +int pim_socket_join_source(int fd, ifindex_t ifindex, struct in_addr group_addr, struct in_addr source_addr, const char *ifname); int pim_socket_recvfromto(int fd, uint8_t *buf, size_t len, struct sockaddr_in *from, socklen_t *fromlen, struct sockaddr_in *to, socklen_t *tolen, - int *ifindex); + ifindex_t *ifindex); int pim_socket_mcastloop_get(int fd); diff --git a/pimd/pim_ssmpingd.c b/pimd/pim_ssmpingd.c index d564bf57bc..fe88eba271 100644 --- a/pimd/pim_ssmpingd.c +++ b/pimd/pim_ssmpingd.c @@ -250,7 +250,7 @@ static int ssmpingd_read_msg(struct ssmpingd_sock *ss) struct sockaddr_in to; socklen_t fromlen = sizeof(from); socklen_t tolen = sizeof(to); - int ifindex = -1; + ifindex_t ifindex = -1; uint8_t buf[1000]; int len; diff --git a/pimd/pim_static.c b/pimd/pim_static.c index 1931f1ee6c..c1154dc088 100644 --- a/pimd/pim_static.c +++ b/pimd/pim_static.c @@ -85,8 +85,8 @@ int pim_static_add(struct interface *iif, struct interface *oif, struct in_addr struct static_route *original_s_route = 0; struct pim_interface *pim_iif = iif ? iif->info : 0; struct pim_interface *pim_oif = oif ? oif->info : 0; - unsigned int iif_index = pim_iif ? pim_iif->mroute_vif_index : 0; - unsigned int oif_index = pim_oif ? pim_oif->mroute_vif_index : 0; + ifindex_t iif_index = pim_iif ? pim_iif->mroute_vif_index : 0; + ifindex_t oif_index = pim_oif ? pim_oif->mroute_vif_index : 0; if (!iif_index || !oif_index) { zlog_warn("%s %s: Unable to add static route: Invalid interface index(iif=%d,oif=%d)", @@ -229,8 +229,8 @@ int pim_static_del(struct interface *iif, struct interface *oif, struct in_addr struct static_route *s_route = 0; struct pim_interface *pim_iif = iif ? iif->info : 0; struct pim_interface *pim_oif = oif ? oif->info : 0; - unsigned int iif_index = pim_iif ? pim_iif->mroute_vif_index : 0; - unsigned int oif_index = pim_oif ? pim_oif->mroute_vif_index : 0; + ifindex_t iif_index = pim_iif ? pim_iif->mroute_vif_index : 0; + ifindex_t oif_index = pim_oif ? pim_oif->mroute_vif_index : 0; if (!iif_index || !oif_index) { zlog_warn("%s %s: Unable to remove static route: Invalid interface index(iif=%d,oif=%d)", diff --git a/pimd/pim_static.h b/pimd/pim_static.h index ff89fb150e..07d31d59b7 100644 --- a/pimd/pim_static.h +++ b/pimd/pim_static.h @@ -33,7 +33,7 @@ struct static_route { struct in_addr source; struct channel_oil c_oil; - unsigned int iif; + ifindex_t iif; unsigned char oif_ttls[MAXVIFS]; }; diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index efab00e227..d357e5cc83 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -533,7 +533,7 @@ static int redist_read_ipv4_route(int command, struct zclient *zclient, { struct stream *s; struct zapi_ipv4 api; - unsigned long ifindex; + ifindex_t ifindex; struct in_addr nexthop; struct prefix_ipv4 p; int min_len = 4; @@ -620,7 +620,7 @@ static int redist_read_ipv4_route(int command, struct zclient *zclient, if (PIM_DEBUG_ZEBRA) { char buf[2][INET_ADDRSTRLEN]; zlog_debug("%s: add %s %s/%d " - "nexthop %s ifindex %ld metric%s %u distance%s %u", + "nexthop %s ifindex %d metric%s %u distance%s %u", __PRETTY_FUNCTION__, zebra_route_string(api.type), inet_ntop(AF_INET, &p.prefix, buf[0], sizeof(buf[0])), @@ -638,7 +638,7 @@ static int redist_read_ipv4_route(int command, struct zclient *zclient, if (PIM_DEBUG_ZEBRA) { char buf[2][INET_ADDRSTRLEN]; zlog_debug("%s: delete %s %s/%d " - "nexthop %s ifindex %ld metric%s %u distance%s %u", + "nexthop %s ifindex %d metric%s %u distance%s %u", __PRETTY_FUNCTION__, zebra_route_string(api.type), inet_ntop(AF_INET, &p.prefix, buf[0], sizeof(buf[0])), @@ -763,7 +763,7 @@ static int fib_lookup_if_vif_index(struct in_addr addr) struct pim_zlookup_nexthop nexthop_tab[PIM_NEXTHOP_IFINDEX_TAB_SIZE]; int num_ifindex; int vif_index; - int first_ifindex; + ifindex_t first_ifindex; num_ifindex = zclient_lookup_nexthop(qpim_zclient_lookup, nexthop_tab, PIM_NEXTHOP_IFINDEX_TAB_SIZE, addr, diff --git a/pimd/pim_zlookup.h b/pimd/pim_zlookup.h index 1f184942ca..f2be6d4fa0 100644 --- a/pimd/pim_zlookup.h +++ b/pimd/pim_zlookup.h @@ -31,7 +31,7 @@ struct pim_zlookup_nexthop { struct in_addr nexthop_addr; - int ifindex; + ifindex_t ifindex; uint32_t route_metric; uint8_t protocol_distance; }; diff --git a/pimd/test_igmpv3_join.c b/pimd/test_igmpv3_join.c index 7fcf38bcec..5c4574024b 100644 --- a/pimd/test_igmpv3_join.c +++ b/pimd/test_igmpv3_join.c @@ -32,6 +32,7 @@ #include #include +#include "if.h" #include "pim_igmp_join.h" const char *prog_name = 0; @@ -39,7 +40,7 @@ const char *prog_name = 0; static int iface_solve_index(const char *ifname) { struct if_nameindex *ini; - int ifindex = -1; + ifindex_t ifindex = -1; int i; if (!ifname) @@ -79,7 +80,7 @@ int main(int argc, const char *argv[]) const char *ifname; const char *group; const char *source; - int ifindex; + ifindex_t ifindex; int result; int fd; diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index 4499966ad0..09b35d00b9 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -74,7 +74,7 @@ static int ipv4_multicast_join (int sock, struct in_addr group, struct in_addr ifa, - unsigned int ifindex) + ifindex_t ifindex) { int ret; @@ -96,7 +96,7 @@ static int ipv4_multicast_leave (int sock, struct in_addr group, struct in_addr ifa, - unsigned int ifindex) + ifindex_t ifindex) { int ret; diff --git a/ripd/ripd.c b/ripd/ripd.c index 42f1015453..3a8cd80e7a 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -1579,7 +1579,7 @@ rip_send_packet (u_char * buf, int size, struct sockaddr_in *to, /* Add redistributed route to RIP table. */ void rip_redistribute_add (int type, int sub_type, struct prefix_ipv4 *p, - unsigned int ifindex, struct in_addr *nexthop, + ifindex_t ifindex, struct in_addr *nexthop, unsigned int metric, unsigned char distance) { int ret; @@ -1653,7 +1653,7 @@ rip_redistribute_add (int type, int sub_type, struct prefix_ipv4 *p, /* Delete redistributed route from RIP table. */ void rip_redistribute_delete (int type, int sub_type, struct prefix_ipv4 *p, - unsigned int ifindex) + ifindex_t ifindex) { int ret; struct route_node *rp; @@ -1795,7 +1795,7 @@ setsockopt_pktinfo (int sock) /* Read RIP packet by recvmsg function. */ int rip_recvmsg (int sock, u_char *buf, int size, struct sockaddr_in *from, - int *ifindex) + ifindex_t *ifindex) { int ret; struct msghdr msg; @@ -1836,7 +1836,7 @@ rip_read_new (struct thread *t) int sock; char buf[RIP_PACKET_MAXSIZ]; struct sockaddr_in from; - unsigned int ifindex; + ifindex_t ifindex; /* Fetch socket then register myself. */ sock = THREAD_FD (t); diff --git a/ripd/ripd.h b/ripd/ripd.h index fe9e521d88..d01d0b6bbe 100644 --- a/ripd/ripd.h +++ b/ripd/ripd.h @@ -198,7 +198,7 @@ struct rip_info struct in_addr from; /* Which interface does this route come from. */ - unsigned int ifindex; + ifindex_t ifindex; /* Metric of this route. */ u_int32_t metric; @@ -224,7 +224,7 @@ struct rip_info u_char metric_set; u_int32_t metric_out; u_short tag_out; - unsigned int ifindex_out; + ifindex_t ifindex_out; struct route_node *rp; @@ -400,9 +400,9 @@ extern int rip_request_send (struct sockaddr_in *, struct interface *, u_char, extern int rip_neighbor_lookup (struct sockaddr_in *); extern int rip_redistribute_check (int); -extern void rip_redistribute_add (int, int, struct prefix_ipv4 *, unsigned int, +extern void rip_redistribute_add (int, int, struct prefix_ipv4 *, ifindex_t, struct in_addr *, unsigned int, unsigned char); -extern void rip_redistribute_delete (int, int, struct prefix_ipv4 *, unsigned int); +extern void rip_redistribute_delete (int, int, struct prefix_ipv4 *, ifindex_t); extern void rip_redistribute_withdraw (int); extern void rip_zebra_ipv4_add (struct route_node *); extern void rip_zebra_ipv4_delete (struct route_node *); diff --git a/ripngd/ripng_zebra.c b/ripngd/ripng_zebra.c index ecfe2d5154..d8667cb68c 100644 --- a/ripngd/ripng_zebra.c +++ b/ripngd/ripng_zebra.c @@ -42,7 +42,7 @@ static void ripng_zebra_ipv6_send (struct route_node *rp, u_char cmd) { static struct in6_addr **nexthops = NULL; - static unsigned int *ifindexes = NULL; + static ifindex_t *ifindexes = NULL; static unsigned int nexthops_len = 0; struct list *list = (struct list *)rp->info; diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index b786c6f938..2858bb6462 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -229,7 +229,7 @@ ripng_send_packet (caddr_t buf, int bufsize, struct sockaddr_in6 *to, /* Receive UDP RIPng packet from socket. */ static int ripng_recv_packet (int sock, u_char *buf, int bufsize, - struct sockaddr_in6 *from, unsigned int *ifindex, + struct sockaddr_in6 *from, ifindex_t *ifindex, int *hoplimit) { int ret; @@ -973,7 +973,7 @@ ripng_route_process (struct rte *rte, struct sockaddr_in6 *from, /* Add redistributed route to RIPng table. */ void ripng_redistribute_add (int type, int sub_type, struct prefix_ipv6 *p, - unsigned int ifindex, struct in6_addr *nexthop) + ifindex_t ifindex, struct in6_addr *nexthop) { struct route_node *rp; struct ripng_info *rinfo = NULL, newinfo; @@ -1043,7 +1043,7 @@ ripng_redistribute_add (int type, int sub_type, struct prefix_ipv6 *p, /* Delete redistributed route to RIPng table. */ void ripng_redistribute_delete (int type, int sub_type, struct prefix_ipv6 *p, - unsigned int ifindex) + ifindex_t ifindex) { struct route_node *rp; struct ripng_info *rinfo; @@ -1361,7 +1361,7 @@ ripng_read (struct thread *thread) int sock; struct sockaddr_in6 from; struct ripng_packet *packet; - unsigned int ifindex = 0; + ifindex_t ifindex = 0; struct interface *ifp; int hoplimit = -1; diff --git a/ripngd/ripngd.h b/ripngd/ripngd.h index 1496de08bf..b87b927f48 100644 --- a/ripngd/ripngd.h +++ b/ripngd/ripngd.h @@ -176,7 +176,7 @@ struct ripng_info struct in6_addr from; /* Which interface does this route come from. */ - unsigned int ifindex; + ifindex_t ifindex; /* Metric of this route. */ u_char metric; @@ -381,9 +381,9 @@ extern void ripng_info_free (struct ripng_info *rinfo); extern void ripng_event (enum ripng_event, int); extern int ripng_request (struct interface *ifp); extern void ripng_redistribute_add (int, int, struct prefix_ipv6 *, - unsigned int, struct in6_addr *); + ifindex_t, struct in6_addr *); extern void ripng_redistribute_delete (int, int, struct prefix_ipv6 *, - unsigned int); + ifindex_t); extern void ripng_redistribute_withdraw (int type); extern void ripng_distribute_update_interface (struct interface *); diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 23224dc241..638062d5d6 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -988,7 +988,7 @@ rtm_read (struct rt_msghdr *rtm) if (rtm->rtm_type != RTM_GET && rtm->rtm_pid == pid) return; struct prefix_ipv6 p; - unsigned int ifindex = 0; + ifindex_t ifindex = 0; p.family = AF_INET6; p.prefix = dest.sin6.sin6_addr; diff --git a/zebra/rib.h b/zebra/rib.h index 5e0bce4461..291ee0b714 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -203,7 +203,7 @@ struct static_route * STATIC_IFINDEX uses ifindex */ union g_addr addr; - unsigned int ifindex; + ifindex_t ifindex; char ifname[INTERFACE_NAMSIZ + 1]; @@ -215,7 +215,6 @@ struct static_route */ }; - /* The following for loop allows to iterate over the nexthop * structure of routes. * @@ -321,14 +320,14 @@ typedef enum RIB_UPDATE_OTHER } rib_update_event_t; -extern struct nexthop *rib_nexthop_ifindex_add (struct rib *, unsigned int); +extern struct nexthop *rib_nexthop_ifindex_add (struct rib *, ifindex_t); 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); + ifindex_t); extern void rib_nexthop_add (struct rib *rib, struct nexthop *nexthop); extern void rib_copy_nexthops (struct rib *rib, struct nexthop *nh); @@ -364,7 +363,7 @@ extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *, 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); + ifindex_t ifindex); extern int is_zebra_valid_kernel_table(u_int32_t table_id); extern int is_zebra_main_routing_table(u_int32_t table_id); @@ -375,13 +374,13 @@ extern int zebra_check_addr (struct prefix *p); * also implicitly withdraw equal prefix of same type. */ extern int rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, struct in_addr *gate, struct in_addr *src, - unsigned int ifindex, vrf_id_t vrf_id, u_int32_t table_id, + ifindex_t ifindex, vrf_id_t vrf_id, u_int32_t table_id, u_int32_t, u_char, safi_t); extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t); extern int rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, - struct in_addr *gate, unsigned int ifindex, + struct in_addr *gate, ifindex_t ifindex, vrf_id_t, u_int32_t, safi_t safi); extern struct rib *rib_match_ipv4 (struct in_addr, safi_t safi, vrf_id_t, @@ -406,22 +405,22 @@ extern void static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_route *si); extern int -static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, unsigned int ifindex, +static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex, const char *ifname, u_char flags, u_short tag, u_char distance, struct zebra_vrf *zvrf); extern int -static_delete_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, unsigned int ifindex, +static_delete_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex, u_short tag, u_char distance, struct zebra_vrf *zvrf); extern int rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, - struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id, + struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, u_int32_t table_id, u_int32_t metric, u_char distance, safi_t safi); extern int rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, - struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id, + struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, u_int32_t table_id, safi_t safi); extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t); @@ -432,16 +431,16 @@ extern struct route_table *rib_table_ipv6; extern int static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, - unsigned int ifindex, const char *ifname, u_char flags, + ifindex_t ifindex, const char *ifname, u_char flags, u_short tag, u_char distance, struct zebra_vrf *zvrf); extern int rib_add_ipv6_multipath (struct prefix *, struct rib *, safi_t, - unsigned long); + ifindex_t); extern int static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, - unsigned int ifindex, u_short tag, u_char distance, + ifindex_t ifindex, u_short tag, u_char distance, struct zebra_vrf *zvrf); extern int rib_gc_dest (struct route_node *rn); diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index bd1c923506..d93a530317 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -74,7 +74,7 @@ extern u_int32_t nl_rcvbufsize; /* Note: on netlink systems, there should be a 1-to-1 mapping between interface names and ifindex values. */ static void -set_ifindex(struct interface *ifp, unsigned int ifi_index) +set_ifindex(struct interface *ifp, ifindex_t ifi_index) { struct interface *oifp; struct zebra_ns *zns = zebra_ns_lookup (NS_DEFAULT); diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c index ffb0d088a7..24671829f0 100644 --- a/zebra/rt_socket.c +++ b/zebra/rt_socket.c @@ -76,7 +76,7 @@ kernel_rtm_ipv4 (int cmd, struct prefix *p, struct rib *rib, int family) struct nexthop *nexthop, *tnexthop; int recursing; int nexthop_num = 0; - unsigned int ifindex = 0; + ifindex_t ifindex = 0; int gate = 0; int error; char prefix_buf[PREFIX_STRLEN]; @@ -287,7 +287,7 @@ kernel_rtm_ipv6_multipath (int cmd, struct prefix *p, struct rib *rib, struct nexthop *nexthop, *tnexthop; int recursing; int nexthop_num = 0; - unsigned int ifindex = 0; + ifindex_t ifindex = 0; int gate = 0; int error; diff --git a/zebra/rtadv.c b/zebra/rtadv.c index f3f1cee14b..8333d2e08c 100644 --- a/zebra/rtadv.c +++ b/zebra/rtadv.c @@ -70,7 +70,7 @@ static int if_join_all_router (int, struct interface *); static int if_leave_all_router (int, struct interface *); static int -rtadv_increment_received(struct zebra_ns *zns, unsigned int *ifindex) +rtadv_increment_received(struct zebra_ns *zns, ifindex_t *ifindex) { int ret = -1; struct interface *iface; @@ -88,7 +88,7 @@ rtadv_increment_received(struct zebra_ns *zns, unsigned int *ifindex) static int rtadv_recv_packet (struct zebra_ns *zns, int sock, u_char *buf, int buflen, - struct sockaddr_in6 *from, unsigned int *ifindex, + struct sockaddr_in6 *from, ifindex_t *ifindex, int *hoplimit) { int ret; @@ -534,7 +534,7 @@ rtadv_process_advert (u_char *msg, unsigned int len, struct interface *ifp, static void -rtadv_process_packet (u_char *buf, unsigned int len, unsigned int ifindex, int hoplimit, +rtadv_process_packet (u_char *buf, unsigned int len, ifindex_t ifindex, int hoplimit, struct sockaddr_in6 *from, struct zebra_ns *zns) { struct icmp6_hdr *icmph; @@ -609,7 +609,7 @@ rtadv_read (struct thread *thread) int len; u_char buf[RTADV_MSG_SIZE]; struct sockaddr_in6 from; - unsigned int ifindex = 0; + ifindex_t ifindex = 0; int hoplimit = -1; struct zebra_ns *zns = THREAD_ARG (thread); diff --git a/zebra/test_main.c b/zebra/test_main.c index 902c675aef..95c56bb046 100644 --- a/zebra/test_main.c +++ b/zebra/test_main.c @@ -112,7 +112,7 @@ usage (char *progname, int status) exit (status); } -static unsigned int test_ifindex = 0; +static ifindex_t test_ifindex = 0; /* testrib commands */ DEFUN (test_interface_state, diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 3aa9356fe6..16f43f7312 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -21,12 +21,12 @@ #include +#include "if.h" #include "prefix.h" #include "table.h" #include "memory.h" #include "str.h" #include "command.h" -#include "if.h" #include "log.h" #include "sockunion.h" #include "linklist.h" @@ -210,7 +210,7 @@ rib_nexthop_delete (struct rib *rib, struct nexthop *nexthop) struct nexthop * -rib_nexthop_ifindex_add (struct rib *rib, unsigned int ifindex) +rib_nexthop_ifindex_add (struct rib *rib, ifindex_t ifindex) { struct nexthop *nexthop; @@ -241,7 +241,7 @@ rib_nexthop_ipv4_add (struct rib *rib, struct in_addr *ipv4, struct in_addr *src struct nexthop * rib_nexthop_ipv4_ifindex_add (struct rib *rib, struct in_addr *ipv4, - struct in_addr *src, unsigned int ifindex) + struct in_addr *src, ifindex_t ifindex) { struct nexthop *nexthop; struct interface *ifp; @@ -281,7 +281,7 @@ rib_nexthop_ipv6_add (struct rib *rib, struct in6_addr *ipv6) struct nexthop * rib_nexthop_ipv6_ifindex_add (struct rib *rib, struct in6_addr *ipv6, - unsigned int ifindex) + ifindex_t ifindex) { struct nexthop *nexthop; @@ -1199,8 +1199,8 @@ nexthop_active_update (struct route_node *rn, struct rib *rib, int set) { struct nexthop *nexthop; union g_addr prev_src; - unsigned int prev_active, prev_index, new_active, old_num_nh; - + unsigned int prev_active, new_active, old_num_nh; + ifindex_t prev_index; old_num_nh = rib->nexthop_active_num; rib->nexthop_active_num = 0; @@ -2413,7 +2413,7 @@ rib_delnode (struct route_node *rn, struct rib *rib) int rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, struct in_addr *gate, struct in_addr *src, - unsigned int ifindex, vrf_id_t vrf_id, u_int32_t table_id, + ifindex_t ifindex, vrf_id_t vrf_id, u_int32_t table_id, u_int32_t metric, u_char distance, safi_t safi) { struct rib *rib; @@ -2770,7 +2770,7 @@ rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib, safi_t safi) /* XXX factor with rib_delete_ipv6 */ int rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, - struct in_addr *gate, unsigned int ifindex, vrf_id_t vrf_id, + struct in_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, u_int32_t table_id, safi_t safi) { struct route_table *table; @@ -3182,7 +3182,7 @@ static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ } int -static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, unsigned int ifindex, +static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex, const char *ifname, u_char flags, u_short tag, u_char distance, struct zebra_vrf *zvrf) { @@ -3278,7 +3278,7 @@ static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, unsigned i } int -static_delete_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, unsigned int ifindex, +static_delete_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex, u_short tag, u_char distance, struct zebra_vrf *zvrf) { u_char type = 0; @@ -3341,7 +3341,7 @@ static_delete_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, unsigne int rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, - struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id, + struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, u_int32_t table_id, u_int32_t metric, u_char distance, safi_t safi) { struct rib *rib; @@ -3450,7 +3450,7 @@ rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, int rib_add_ipv6_multipath (struct prefix *p, struct rib *rib, safi_t safi, - unsigned long ifindex) + ifindex_t ifindex) { struct route_table *table; struct route_node *rn; @@ -3565,7 +3565,7 @@ rib_add_ipv6_multipath (struct prefix *p, struct rib *rib, safi_t safi, int rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, - struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id, + struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, u_int32_t table_id, safi_t safi) { struct route_table *table; @@ -3702,7 +3702,7 @@ rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, /* Add static route into static route configuration. */ int static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, - unsigned int ifindex, const char *ifname, u_char flags, + ifindex_t ifindex, const char *ifname, u_char flags, u_short tag, u_char distance, struct zebra_vrf *zvrf) { struct route_node *rn; @@ -3798,7 +3798,7 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, /* Delete static route from static route configuration. */ int static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, - unsigned int ifindex, u_short tag, u_char distance, + ifindex_t ifindex, u_short tag, u_char distance, struct zebra_vrf *zvrf) { struct route_node *rn; diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index db3e5eaba1..1417824d07 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -252,7 +252,7 @@ route_match_interface (void *rule, struct prefix *prefix, { struct nh_rmap_obj *nh_data; char *ifname = rule; - unsigned int ifindex; + ifindex_t ifindex; if (type == RMAP_ZEBRA) { diff --git a/zebra/zserv.c b/zebra/zserv.c index d625c02ff4..a1fe9bc188 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -1188,7 +1188,7 @@ zread_ipv4_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf) u_char nexthop_num; u_char nexthop_type; struct stream *s; - unsigned int ifindex; + ifindex_t ifindex; safi_t safi; int ret; -- cgit v1.2.3 From 2f97fa65ff6331e6dec751901ac2e4e450e2d66c Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Mon, 2 Nov 2015 16:50:05 +0200 Subject: zebra: make ZEBRA_FLAG_CHANGED internal status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This flag is used internally in zebra only. And it makes no sense to expose it over the zclient API, as having it set from client could corrupt the internal state. Signed-off-by: Timo Teräs Acked-by: Donald Sharp (cherry picked from commit 7eb6136b2732d4782360f9f376336c6d4f667ff0) --- lib/zebra.h | 1 - zebra/rib.h | 1 + zebra/zebra_rib.c | 46 +++++++++++++++++++++++----------------------- zebra/zebra_rnh.c | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) (limited to 'zebra/zebra_rib.c') diff --git a/lib/zebra.h b/lib/zebra.h index b3a814c0d2..e117e26bf6 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -489,7 +489,6 @@ extern const char *zserv_command_string (unsigned int command); #define ZEBRA_FLAG_BLACKHOLE 0x04 #define ZEBRA_FLAG_IBGP 0x08 #define ZEBRA_FLAG_SELECTED 0x10 -#define ZEBRA_FLAG_CHANGED 0x20 #define ZEBRA_FLAG_STATIC 0x40 #define ZEBRA_FLAG_REJECT 0x80 #define ZEBRA_FLAG_SCOPE_LINK 0x100 diff --git a/zebra/rib.h b/zebra/rib.h index 291ee0b714..a2109d8c17 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -81,6 +81,7 @@ struct rib #define RIB_ENTRY_REMOVED 0x1 /* to simplify NHT logic when NHs change, instead of doing a NH by NH cmp */ #define RIB_ENTRY_NEXTHOPS_CHANGED 0x2 +#define RIB_ENTRY_CHANGED 0x4 /* Nexthop information. */ u_char nexthop_num; diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 16f43f7312..c1bceee9e6 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -1188,7 +1188,7 @@ nexthop_active_check (struct route_node *rn, struct rib *rib, /* Iterate over all nexthops of the given RIB entry and refresh their * ACTIVE flag. rib->nexthop_active_num is updated accordingly. If any * nexthop is found to toggle the ACTIVE flag, the whole rib structure - * is flagged with ZEBRA_FLAG_CHANGED. The 4th 'set' argument is + * is flagged with RIB_ENTRY_CHANGED. The 4th 'set' argument is * transparently passed to nexthop_active_check(). * * Return value is the new number of active nexthops. @@ -1204,7 +1204,7 @@ nexthop_active_update (struct route_node *rn, struct rib *rib, int set) old_num_nh = rib->nexthop_active_num; rib->nexthop_active_num = 0; - UNSET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG (rib->status, RIB_ENTRY_CHANGED); for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) { @@ -1224,15 +1224,15 @@ nexthop_active_update (struct route_node *rn, struct rib *rib, int set) nexthop->type < NEXTHOP_TYPE_BLACKHOLE) && !(IPV6_ADDR_SAME (&prev_src.ipv6, &nexthop->rmap_src.ipv6)))) { - SET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED); + SET_FLAG (rib->flags, RIB_ENTRY_CHANGED); SET_FLAG (rib->status, RIB_ENTRY_NEXTHOPS_CHANGED); } } if (old_num_nh != rib->nexthop_active_num) - SET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED); + SET_FLAG (rib->flags, RIB_ENTRY_CHANGED); - if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_CHANGED)) + if (CHECK_FLAG (rib->flags, RIB_ENTRY_CHANGED)) { SET_FLAG (rib->status, RIB_ENTRY_NEXTHOPS_CHANGED); } @@ -1429,7 +1429,7 @@ rib_process_add_route (struct zebra_vrf *zvrf, struct route_node *rn, /* Update real nexthop. This may actually determine if nexthop is active or not. */ if (!nexthop_active_update (rn, select, 1)) { - UNSET_FLAG(select->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG(select->flags, RIB_ENTRY_CHANGED); return; } @@ -1455,7 +1455,7 @@ rib_process_add_route (struct zebra_vrf *zvrf, struct route_node *rn, /* Update for redistribution. */ if (installed) redistribute_update (&rn->p, select, NULL); - UNSET_FLAG(select->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG(select->flags, RIB_ENTRY_CHANGED); } static void @@ -1482,7 +1482,7 @@ rib_process_del_route (struct zebra_vrf *zvrf, struct route_node *rn, /* Update nexthop for route, reset changed flag. */ nexthop_active_update (rn, fib, 1); - UNSET_FLAG(fib->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG(fib->flags, RIB_ENTRY_CHANGED); } static void @@ -1503,7 +1503,7 @@ rib_process_update_route (struct zebra_vrf *zvrf, struct route_node *rn, * something has changed. */ if (select != fib || - CHECK_FLAG (select->flags, ZEBRA_FLAG_CHANGED)) + CHECK_FLAG (select->flags, RIB_ENTRY_CHANGED)) { zfpm_trigger_update (rn, "updating existing route"); @@ -1623,11 +1623,11 @@ rib_process_update_route (struct zebra_vrf *zvrf, struct route_node *rn, /* Set real nexthop. */ nexthop_active_update (rn, fib, 1); - UNSET_FLAG(fib->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG(fib->flags, RIB_ENTRY_CHANGED); } /* Clear changed flag. */ - UNSET_FLAG(select->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG(select->flags, RIB_ENTRY_CHANGED); } /* Core function for processing routing information base. */ @@ -1707,7 +1707,7 @@ rib_process (struct route_node *rn) * the nexthop_active_update() code. Thus, we might miss changes to * recursive NHs. */ - if (!CHECK_FLAG(rib->flags, ZEBRA_FLAG_CHANGED) && + if (!CHECK_FLAG(rib->flags, RIB_ENTRY_CHANGED) && ! nexthop_active_update (rn, rib, 0)) { if (rib->type == ZEBRA_ROUTE_TABLE) @@ -1735,7 +1735,7 @@ rib_process (struct route_node *rn) /* Infinite distance. */ if (rib->distance == DISTANCE_INFINITY) { - UNSET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG (rib->flags, RIB_ENTRY_CHANGED); continue; } @@ -1761,30 +1761,30 @@ rib_process (struct route_node *rn) if (select->type != ZEBRA_ROUTE_CONNECT || rib->metric <= select->metric) { - UNSET_FLAG (select->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG (select->flags, RIB_ENTRY_CHANGED); select = rib; } else - UNSET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG (rib->flags, RIB_ENTRY_CHANGED); continue; } else if (select->type == ZEBRA_ROUTE_CONNECT) { - UNSET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG (rib->flags, RIB_ENTRY_CHANGED); continue; } /* higher distance loses */ if (rib->distance > select->distance) { - UNSET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG (rib->flags, RIB_ENTRY_CHANGED); continue; } /* lower wins */ if (rib->distance < select->distance) { - UNSET_FLAG (select->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG (select->flags, RIB_ENTRY_CHANGED); select = rib; continue; } @@ -1792,7 +1792,7 @@ rib_process (struct route_node *rn) /* metric tie-breaks equal distance */ if (rib->metric <= select->metric) { - UNSET_FLAG (select->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG (select->flags, RIB_ENTRY_CHANGED); select = rib; } } /* RNODE_FOREACH_RIB_SAFE */ @@ -1823,7 +1823,7 @@ rib_process (struct route_node *rn) if (IS_ZEBRA_DEBUG_RIB) rnode_debug (rn, vrf_id, "Updating existing route, select %p, fib %p", (void *)select, (void *)fib); - if (CHECK_FLAG (select->flags, ZEBRA_FLAG_CHANGED)) + if (CHECK_FLAG (select->status, RIB_ENTRY_CHANGED)) { if (info->safi == SAFI_UNICAST) zfpm_trigger_update (rn, "updating existing route"); @@ -1865,7 +1865,7 @@ rib_process (struct route_node *rn) rib_uninstall_kernel (rn, select); UNSET_FLAG (select->flags, ZEBRA_FLAG_SELECTED); } - UNSET_FLAG (select->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG (select->flags, RIB_ENTRY_CHANGED); } else if (! RIB_SYSTEM_ROUTE (select)) { @@ -1918,7 +1918,7 @@ rib_process (struct route_node *rn) /* Set real nexthop. */ nexthop_active_update (rn, fib, 1); - UNSET_FLAG(fib->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG(fib->flags, RIB_ENTRY_CHANGED); } /* Regardless of some RIB entry being SELECTED or not before, now we can @@ -1988,7 +1988,7 @@ rib_process (struct route_node *rn) redistribute_delete(&rn->p, fib); } } - UNSET_FLAG(select->flags, ZEBRA_FLAG_CHANGED); + UNSET_FLAG(select->flags, RIB_ENTRY_CHANGED); } #endif diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index 03ae466997..b3cc6f44c0 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -593,7 +593,7 @@ zebra_rnh_process_static_routes (vrf_id_t vrfid, int family, vrfid, bufn, bufs); } - SET_FLAG(srib->flags, ZEBRA_FLAG_CHANGED); + SET_FLAG(srib->flags, RIB_ENTRY_CHANGED); SET_FLAG(srib->status, RIB_ENTRY_NEXTHOPS_CHANGED); rib_queue_add(static_rn); } -- cgit v1.2.3 From 2b50b6031ceb1c960337dd263c91095c4fd27696 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sun, 21 Aug 2016 12:59:48 -0400 Subject: zebra: Fix cherry-pick of ZEBRA_FLAG_CHANGED When cherrypicking I did not notice the move of the flag from flags -> status. Signed-off-by: Donald Sharp --- zebra/zebra_rib.c | 40 ++++++++++++++++++++-------------------- zebra/zebra_rnh.c | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) (limited to 'zebra/zebra_rib.c') diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index c1bceee9e6..0dc8086906 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -1224,15 +1224,15 @@ nexthop_active_update (struct route_node *rn, struct rib *rib, int set) nexthop->type < NEXTHOP_TYPE_BLACKHOLE) && !(IPV6_ADDR_SAME (&prev_src.ipv6, &nexthop->rmap_src.ipv6)))) { - SET_FLAG (rib->flags, RIB_ENTRY_CHANGED); + SET_FLAG (rib->status, RIB_ENTRY_CHANGED); SET_FLAG (rib->status, RIB_ENTRY_NEXTHOPS_CHANGED); } } if (old_num_nh != rib->nexthop_active_num) - SET_FLAG (rib->flags, RIB_ENTRY_CHANGED); + SET_FLAG (rib->status, RIB_ENTRY_CHANGED); - if (CHECK_FLAG (rib->flags, RIB_ENTRY_CHANGED)) + if (CHECK_FLAG (rib->status, RIB_ENTRY_CHANGED)) { SET_FLAG (rib->status, RIB_ENTRY_NEXTHOPS_CHANGED); } @@ -1429,7 +1429,7 @@ rib_process_add_route (struct zebra_vrf *zvrf, struct route_node *rn, /* Update real nexthop. This may actually determine if nexthop is active or not. */ if (!nexthop_active_update (rn, select, 1)) { - UNSET_FLAG(select->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG(select->status, RIB_ENTRY_CHANGED); return; } @@ -1455,7 +1455,7 @@ rib_process_add_route (struct zebra_vrf *zvrf, struct route_node *rn, /* Update for redistribution. */ if (installed) redistribute_update (&rn->p, select, NULL); - UNSET_FLAG(select->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG(select->status, RIB_ENTRY_CHANGED); } static void @@ -1482,7 +1482,7 @@ rib_process_del_route (struct zebra_vrf *zvrf, struct route_node *rn, /* Update nexthop for route, reset changed flag. */ nexthop_active_update (rn, fib, 1); - UNSET_FLAG(fib->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG(fib->status, RIB_ENTRY_CHANGED); } static void @@ -1503,7 +1503,7 @@ rib_process_update_route (struct zebra_vrf *zvrf, struct route_node *rn, * something has changed. */ if (select != fib || - CHECK_FLAG (select->flags, RIB_ENTRY_CHANGED)) + CHECK_FLAG (select->status, RIB_ENTRY_CHANGED)) { zfpm_trigger_update (rn, "updating existing route"); @@ -1623,11 +1623,11 @@ rib_process_update_route (struct zebra_vrf *zvrf, struct route_node *rn, /* Set real nexthop. */ nexthop_active_update (rn, fib, 1); - UNSET_FLAG(fib->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG(fib->status, RIB_ENTRY_CHANGED); } /* Clear changed flag. */ - UNSET_FLAG(select->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG(select->status, RIB_ENTRY_CHANGED); } /* Core function for processing routing information base. */ @@ -1707,7 +1707,7 @@ rib_process (struct route_node *rn) * the nexthop_active_update() code. Thus, we might miss changes to * recursive NHs. */ - if (!CHECK_FLAG(rib->flags, RIB_ENTRY_CHANGED) && + if (!CHECK_FLAG(rib->status, RIB_ENTRY_CHANGED) && ! nexthop_active_update (rn, rib, 0)) { if (rib->type == ZEBRA_ROUTE_TABLE) @@ -1735,7 +1735,7 @@ rib_process (struct route_node *rn) /* Infinite distance. */ if (rib->distance == DISTANCE_INFINITY) { - UNSET_FLAG (rib->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG (rib->status, RIB_ENTRY_CHANGED); continue; } @@ -1761,30 +1761,30 @@ rib_process (struct route_node *rn) if (select->type != ZEBRA_ROUTE_CONNECT || rib->metric <= select->metric) { - UNSET_FLAG (select->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG (select->status, RIB_ENTRY_CHANGED); select = rib; } else - UNSET_FLAG (rib->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG (rib->status, RIB_ENTRY_CHANGED); continue; } else if (select->type == ZEBRA_ROUTE_CONNECT) { - UNSET_FLAG (rib->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG (rib->status, RIB_ENTRY_CHANGED); continue; } /* higher distance loses */ if (rib->distance > select->distance) { - UNSET_FLAG (rib->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG (rib->status, RIB_ENTRY_CHANGED); continue; } /* lower wins */ if (rib->distance < select->distance) { - UNSET_FLAG (select->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG (select->status, RIB_ENTRY_CHANGED); select = rib; continue; } @@ -1792,7 +1792,7 @@ rib_process (struct route_node *rn) /* metric tie-breaks equal distance */ if (rib->metric <= select->metric) { - UNSET_FLAG (select->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG (select->status, RIB_ENTRY_CHANGED); select = rib; } } /* RNODE_FOREACH_RIB_SAFE */ @@ -1865,7 +1865,7 @@ rib_process (struct route_node *rn) rib_uninstall_kernel (rn, select); UNSET_FLAG (select->flags, ZEBRA_FLAG_SELECTED); } - UNSET_FLAG (select->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG (select->status, RIB_ENTRY_CHANGED); } else if (! RIB_SYSTEM_ROUTE (select)) { @@ -1918,7 +1918,7 @@ rib_process (struct route_node *rn) /* Set real nexthop. */ nexthop_active_update (rn, fib, 1); - UNSET_FLAG(fib->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG(fib->status, RIB_ENTRY_CHANGED); } /* Regardless of some RIB entry being SELECTED or not before, now we can @@ -1988,7 +1988,7 @@ rib_process (struct route_node *rn) redistribute_delete(&rn->p, fib); } } - UNSET_FLAG(select->flags, RIB_ENTRY_CHANGED); + UNSET_FLAG(select->status, RIB_ENTRY_CHANGED); } #endif diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index b3cc6f44c0..55c428067b 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -593,7 +593,7 @@ zebra_rnh_process_static_routes (vrf_id_t vrfid, int family, vrfid, bufn, bufs); } - SET_FLAG(srib->flags, RIB_ENTRY_CHANGED); + SET_FLAG(srib->status, RIB_ENTRY_CHANGED); SET_FLAG(srib->status, RIB_ENTRY_NEXTHOPS_CHANGED); rib_queue_add(static_rn); } -- cgit v1.2.3 From c50ca33acf29bb269e8f26be19a8ccd06ab41d3e Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Mon, 2 Nov 2015 16:50:07 +0200 Subject: zebra: implement per-route mtu handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commits allow overriding MTU using netlink attributes on per-route basis. This is useful for routing protocols that can advertice prefix specific MTUs between routers (e.g. NHRP). Signed-off-by: Timo Teräs (cherry picked from commit b11f3b54c842117e22e2f5cf1561ea34eee8dfcc) --- lib/zclient.c | 8 ++++++++ lib/zclient.h | 5 +++++ zebra/connected.c | 6 +++--- zebra/kernel_socket.c | 6 ++++-- zebra/redistribute.c | 3 ++- zebra/rib.h | 9 ++++++-- zebra/rt_netlink.c | 57 +++++++++++++++++++++++++++++++++++++++++++++------ zebra/zebra_rib.c | 14 ++++++++++--- zebra/zebra_vty.c | 2 ++ zebra/zserv.c | 17 +++++++++++++++ 10 files changed, 110 insertions(+), 17 deletions(-) (limited to 'zebra/zebra_rib.c') diff --git a/lib/zclient.c b/lib/zclient.c index a28db083cb..0259af5971 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -709,6 +709,8 @@ zclient_connect (struct thread *t) * * If ZAPI_MESSAGE_TAG is set, the tag value is written as a 2 byte value * + * If ZAPI_MESSAGE_MTU is set, the mtu value is written as a 4 byte value + * * XXX: No attention paid to alignment. */ int @@ -769,6 +771,8 @@ zapi_ipv4_route (u_char cmd, struct zclient *zclient, struct prefix_ipv4 *p, stream_putl (s, api->metric); if (CHECK_FLAG (api->message, ZAPI_MESSAGE_TAG)) stream_putw (s, api->tag); + if (CHECK_FLAG (api->message, ZAPI_MESSAGE_MTU)) + stream_putl (s, api->mtu); /* Put length at the first point of the stream. */ stream_putw_at (s, 0, stream_get_endp (s)); @@ -834,6 +838,8 @@ zapi_ipv4_route_ipv6_nexthop (u_char cmd, struct zclient *zclient, stream_putl (s, api->metric); if (CHECK_FLAG (api->message, ZAPI_MESSAGE_TAG)) stream_putw (s, api->tag); + if (CHECK_FLAG (api->message, ZAPI_MESSAGE_MTU)) + stream_putl (s, api->mtu); /* Put length at the first point of the stream. */ stream_putw_at (s, 0, stream_get_endp (s)); @@ -898,6 +904,8 @@ zapi_ipv6_route (u_char cmd, struct zclient *zclient, struct prefix_ipv6 *p, stream_putl (s, api->metric); if (CHECK_FLAG (api->message, ZAPI_MESSAGE_TAG)) stream_putw (s, api->tag); + if (CHECK_FLAG (api->message, ZAPI_MESSAGE_MTU)) + stream_putl (s, api->mtu); /* Put length at the first point of the stream. */ stream_putw_at (s, 0, stream_get_endp (s)); diff --git a/lib/zclient.h b/lib/zclient.h index 8926bbbe63..c42d8c9aa3 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -116,6 +116,7 @@ struct zclient #define ZAPI_MESSAGE_DISTANCE 0x04 #define ZAPI_MESSAGE_METRIC 0x08 #define ZAPI_MESSAGE_TAG 0x10 +#define ZAPI_MESSAGE_MTU 0x20 /* Zserv protocol message header */ struct zserv_header @@ -154,6 +155,8 @@ struct zapi_ipv4 u_short tag; + u_int32_t mtu; + vrf_id_t vrf_id; }; @@ -237,6 +240,8 @@ struct zapi_ipv6 u_short tag; + u_int32_t mtu; + vrf_id_t vrf_id; }; diff --git a/zebra/connected.c b/zebra/connected.c index 42b5a8ab9c..3077272221 100644 --- a/zebra/connected.c +++ b/zebra/connected.c @@ -201,10 +201,10 @@ connected_up_ipv4 (struct interface *ifp, struct connected *ifc) return; rib_add_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, NULL, ifp->ifindex, - ifp->vrf_id, RT_TABLE_MAIN, ifp->metric, 0, SAFI_UNICAST); + ifp->vrf_id, RT_TABLE_MAIN, ifp->metric, 0, 0, SAFI_UNICAST); rib_add_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, NULL, ifp->ifindex, - ifp->vrf_id, RT_TABLE_MAIN, ifp->metric, 0, SAFI_MULTICAST); + ifp->vrf_id, RT_TABLE_MAIN, ifp->metric, 0, 0, SAFI_MULTICAST); if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug ("%u: IF %s IPv4 address add/up, scheduling RIB processing", @@ -379,7 +379,7 @@ connected_up_ipv6 (struct interface *ifp, struct connected *ifc) #endif rib_add_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, ifp->vrf_id, - RT_TABLE_MAIN, ifp->metric, 0, SAFI_UNICAST); + RT_TABLE_MAIN, ifp->metric, 0, 0, SAFI_UNICAST); if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug ("%u: IF %s IPv6 address down, scheduling RIB processing", diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 638062d5d6..c5763dd46f 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -974,7 +974,8 @@ rtm_read (struct rt_msghdr *rtm) || rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_CHANGE) rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, - &p, &gate.sin.sin_addr, NULL, 0, VRF_DEFAULT, 0, 0, 0, SAFI_UNICAST); + &p, &gate.sin.sin_addr, NULL, 0, VRF_DEFAULT, + 0, 0, 0, 0, SAFI_UNICAST); else rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, &gate.sin.sin_addr, 0, VRF_DEFAULT, 0, SAFI_UNICAST); @@ -1016,7 +1017,8 @@ rtm_read (struct rt_msghdr *rtm) || rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_CHANGE) rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, - &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, 0, 0, 0, SAFI_UNICAST); + &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, + 0, 0, 0, 0, SAFI_UNICAST); else rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, 0, SAFI_UNICAST); diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 4238d8329e..892bc2af2b 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -578,7 +578,7 @@ zebra_add_import_table_entry (struct route_node *rn, struct rib *rib, const char rib_add_ipv4(ZEBRA_ROUTE_TABLE, rib->table, 0, &p4, gate, &nhop->src.ipv4, nhop->ifindex, rib->vrf_id, zebrad.rtm_table_default, - rib->metric, + rib->metric, rib->mtu, zebra_import_table_distance[AFI_IP][rib->table], SAFI_UNICAST); } @@ -589,6 +589,7 @@ zebra_add_import_table_entry (struct route_node *rn, struct rib *rib, const char newrib->distance = zebra_import_table_distance[AFI_IP][rib->table]; newrib->flags = rib->flags; newrib->metric = rib->metric; + newrib->mtu = rib->mtu; newrib->table = zebrad.rtm_table_default; newrib->nexthop_num = 0; newrib->uptime = time(NULL); diff --git a/zebra/rib.h b/zebra/rib.h index a2109d8c17..095b9c6f8f 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -64,6 +64,10 @@ struct rib /* Metric */ u_int32_t metric; + /* MTU */ + u_int32_t mtu; + u_int32_t nexthop_mtu; + /* Distance. */ u_char distance; @@ -376,7 +380,7 @@ extern int zebra_check_addr (struct prefix *p); extern int rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, struct in_addr *gate, struct in_addr *src, ifindex_t ifindex, vrf_id_t vrf_id, u_int32_t table_id, - u_int32_t, u_char, safi_t); + u_int32_t, u_int32_t, u_char, safi_t); extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t); @@ -417,7 +421,8 @@ static_delete_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex extern int rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, - u_int32_t table_id, u_int32_t metric, u_char distance, safi_t safi); + u_int32_t table_id, u_int32_t metric, u_int32_t mtu, + u_char distance, safi_t safi); extern int rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index d93a530317..49dcd1e6de 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -866,6 +866,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h, int index; int table; int metric; + u_int32_t mtu = 0; void *dest; void *gate; @@ -937,6 +938,18 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h, if (tb[RTA_PRIORITY]) metric = *(int *) RTA_DATA(tb[RTA_PRIORITY]); + if (tb[RTA_METRICS]) + { + struct rtattr *mxrta[RTAX_MAX+1]; + + memset (mxrta, 0, sizeof mxrta); + netlink_parse_rtattr (mxrta, RTAX_MAX, RTA_DATA(tb[RTA_METRICS]), + RTA_PAYLOAD(tb[RTA_METRICS])); + + if (mxrta[RTAX_MTU]) + mtu = *(u_int32_t *) RTA_DATA(mxrta[RTAX_MTU]); + } + if (rtm->rtm_family == AF_INET) { struct prefix_ipv4 p; @@ -946,7 +959,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h, if (!tb[RTA_MULTIPATH]) rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, flags, &p, gate, src, index, - vrf_id, table, metric, 0, SAFI_UNICAST); + vrf_id, table, metric, mtu, 0, SAFI_UNICAST); else { /* This is a multipath route */ @@ -962,6 +975,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h, rib->distance = 0; rib->flags = flags; rib->metric = metric; + rib->mtu = mtu; rib->vrf_id = vrf_id; rib->table = table; rib->nexthop_num = 0; @@ -1014,7 +1028,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h, p.prefixlen = rtm->rtm_dst_len; rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, flags, &p, gate, index, vrf_id, - table, metric, 0, SAFI_UNICAST); + table, metric, mtu, 0, SAFI_UNICAST); } #endif /* HAVE_IPV6 */ @@ -1051,6 +1065,7 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h, int index; int table; int metric; + u_int32_t mtu = 0; void *dest; void *gate; @@ -1142,8 +1157,23 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h, if (tb[RTA_PREFSRC]) src = RTA_DATA (tb[RTA_PREFSRC]); - if (h->nlmsg_type == RTM_NEWROUTE && tb[RTA_PRIORITY]) - metric = *(int *) RTA_DATA(tb[RTA_PRIORITY]); + if (h->nlmsg_type == RTM_NEWROUTE) + { + if (tb[RTA_PRIORITY]) + metric = *(int *) RTA_DATA(tb[RTA_PRIORITY]); + + if (tb[RTA_METRICS]) + { + struct rtattr *mxrta[RTAX_MAX+1]; + + memset (mxrta, 0, sizeof mxrta); + netlink_parse_rtattr (mxrta, RTAX_MAX, RTA_DATA(tb[RTA_METRICS]), + RTA_PAYLOAD(tb[RTA_METRICS])); + + if (mxrta[RTAX_MTU]) + mtu = *(u_int32_t *) RTA_DATA(mxrta[RTAX_MTU]); + } + } if (rtm->rtm_family == AF_INET) { @@ -1164,7 +1194,7 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h, { if (!tb[RTA_MULTIPATH]) rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, src, index, vrf_id, - table, metric, 0, SAFI_UNICAST); + table, metric, mtu, 0, SAFI_UNICAST); else { /* This is a multipath route */ @@ -1180,6 +1210,7 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h, rib->distance = 0; rib->flags = 0; rib->metric = metric; + rib->mtu = mtu; rib->vrf_id = vrf_id; rib->table = table; rib->nexthop_num = 0; @@ -1248,7 +1279,7 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h, if (h->nlmsg_type == RTM_NEWROUTE) rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, index, vrf_id, - table, metric, 0, SAFI_UNICAST); + table, metric, mtu, 0, SAFI_UNICAST); else rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, gate, index, vrf_id, table, SAFI_UNICAST); @@ -2079,6 +2110,20 @@ netlink_route_multipath (int cmd, struct prefix *p, struct rib *rib, addattr32(&req.n, sizeof req, RTA_TABLE, rib->table); } + if (rib->mtu || rib->nexthop_mtu) + { + char buf[NL_PKT_BUF_SIZE]; + struct rtattr *rta = (void *) buf; + u_int32_t mtu = rib->mtu; + if (!mtu || (rib->nexthop_mtu && rib->nexthop_mtu < mtu)) + mtu = rib->nexthop_mtu; + rta->rta_type = RTA_METRICS; + rta->rta_len = RTA_LENGTH(0); + rta_addattr_l (rta, NL_PKT_BUF_SIZE, RTAX_MTU, &mtu, sizeof mtu); + addattr_l (&req.n, NL_PKT_BUF_SIZE, RTA_METRICS, RTA_DATA (rta), + RTA_PAYLOAD (rta)); + } + if (discard) { if (cmd == RTM_NEWROUTE) diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 0dc8086906..195d3633e1 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -352,6 +352,7 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set, zebra_deregister_rnh_static_nexthops(rib->vrf_id, nexthop->resolved, top); nexthops_free(nexthop->resolved); nexthop->resolved = NULL; + rib->nexthop_mtu = 0; } /* Skip nexthops that have been filtered out due to route-map */ @@ -545,6 +546,8 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set, } resolved = 1; } + if (resolved && set) + rib->nexthop_mtu = match->mtu; return resolved; } else @@ -2414,7 +2417,7 @@ int rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, struct in_addr *gate, struct in_addr *src, ifindex_t ifindex, vrf_id_t vrf_id, u_int32_t table_id, - u_int32_t metric, u_char distance, safi_t safi) + u_int32_t metric, u_int32_t mtu, u_char distance, safi_t safi) { struct rib *rib; struct rib *same = NULL; @@ -2481,6 +2484,7 @@ rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, rib->distance = distance; rib->flags = flags; rib->metric = metric; + rib->mtu = mtu; rib->table = table_id; rib->vrf_id = vrf_id; rib->nexthop_num = 0; @@ -2554,9 +2558,10 @@ void _rib_dump (const char * func, ); zlog_debug ( - "%s: metric == %u, distance == %u, flags == %u, status == %u", + "%s: metric == %u, mtu == %u, distance == %u, flags == %u, status == %u", func, rib->metric, + rib->mtu, rib->distance, rib->flags, rib->status @@ -2992,6 +2997,7 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro rib->instance = 0; rib->distance = si->distance; rib->metric = 0; + rib->mtu = 0; rib->vrf_id = si->vrf_id; rib->table = si->vrf_id ? (zebra_vrf_lookup(si->vrf_id))->table_id : zebrad.rtm_table_default; rib->nexthop_num = 0; @@ -3342,7 +3348,8 @@ static_delete_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex int rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, - u_int32_t table_id, u_int32_t metric, u_char distance, safi_t safi) + u_int32_t table_id, u_int32_t metric, u_int32_t mtu, + u_char distance, safi_t safi) { struct rib *rib; struct rib *same = NULL; @@ -3401,6 +3408,7 @@ rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, rib->distance = distance; rib->flags = flags; rib->metric = metric; + rib->mtu = mtu; rib->table = table_id; rib->vrf_id = vrf_id; rib->nexthop_num = 0; diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index e9090cbed2..ff2f7c7bc4 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -1929,6 +1929,8 @@ vty_show_ip_route_detail (struct vty *vty, struct route_node *rn, int mcast) vty_out (vty, ", distance %u, metric %u", rib->distance, rib->metric); if (rib->tag) vty_out (vty, ", tag %d", rib->tag); + if (rib->mtu) + vty_out (vty, ", mtu %u", rib->mtu); if (rib->vrf_id != VRF_DEFAULT) { zvrf = vrf_info_lookup(rib->vrf_id); diff --git a/zebra/zserv.c b/zebra/zserv.c index a1fe9bc188..84881e14a4 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -695,6 +695,8 @@ zsend_redistribute_route (int cmd, struct zserv *client, struct prefix *p, SET_FLAG(zapi_flags, ZAPI_MESSAGE_TAG); stream_putw(s, rib->tag); } + SET_FLAG (zapi_flags, ZAPI_MESSAGE_MTU); + stream_putl (s, rib->mtu); } /* write real message flags value */ @@ -1264,6 +1266,11 @@ zread_ipv4_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf) else rib->tag = 0; + if (CHECK_FLAG (message, ZAPI_MESSAGE_MTU)) + rib->mtu = stream_getl (s); + else + rib->mtu = 0; + /* Table */ rib->table = zvrf->table_id; @@ -1518,6 +1525,11 @@ zread_ipv4_route_ipv6_nexthop_add (struct zserv *client, u_short length, struct else rib->tag = 0; + if (CHECK_FLAG (message, ZAPI_MESSAGE_MTU)) + rib->mtu = stream_getl (s); + else + rib->mtu = 0; + /* Table */ rib->table = zvrf->table_id; @@ -1636,6 +1648,11 @@ zread_ipv6_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf) else rib->tag = 0; + if (CHECK_FLAG (message, ZAPI_MESSAGE_MTU)) + rib->mtu = stream_getl (s); + else + rib->mtu = 0; + /* VRF ID */ rib->vrf_id = zvrf->vrf_id; rib->table = zvrf->table_id; -- cgit v1.2.3 From 28f6dde859dad5785aa40067a9ce611684e28fb4 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 1 Sep 2016 07:20:02 -0400 Subject: zebra: Create zebra_static.[ch] to isolate code Isolate the zebra static_XXX functions from zebra_rib.c This is the first in a series of changes to clean up the zebra code a bit more. Signed-off-by: Donald Sharp --- zebra/Makefile.am | 6 +- zebra/rib.h | 75 +------ zebra/zebra_rib.c | 593 +------------------------------------------------ zebra/zebra_static.c | 617 +++++++++++++++++++++++++++++++++++++++++++++++++++ zebra/zebra_static.h | 95 ++++++++ zebra/zebra_vrf.c | 1 + zebra/zebra_vty.c | 3 +- 7 files changed, 729 insertions(+), 661 deletions(-) create mode 100644 zebra/zebra_static.c create mode 100644 zebra/zebra_static.h (limited to 'zebra/zebra_rib.c') diff --git a/zebra/Makefile.am b/zebra/Makefile.am index 4492f9e6d4..0218af81b7 100644 --- a/zebra/Makefile.am +++ b/zebra/Makefile.am @@ -31,19 +31,19 @@ zebra_SOURCES = \ redistribute.c debug.c rtadv.c zebra_snmp.c zebra_vty.c \ irdp_main.c irdp_interface.c irdp_packet.c router-id.c zebra_fpm.c \ $(othersrc) zebra_ptm.c zebra_rnh.c zebra_ptm_redistribute.c \ - zebra_ns.c zebra_vrf.c + zebra_ns.c zebra_vrf.c zebra_static.c testzebra_SOURCES = test_main.c zebra_rib.c interface.c connected.c debug.c \ zebra_vty.c zebra_ptm.c zebra_routemap.c zebra_ns.c zebra_vrf.c \ kernel_null.c redistribute_null.c ioctl_null.c misc_null.c zebra_rnh_null.c \ - zebra_ptm_null.c rtadv_null.c if_null.c zserv_null.c + zebra_ptm_null.c rtadv_null.c if_null.c zserv_null.c zebra_static.c noinst_HEADERS = \ connected.h ioctl.h rib.h rt.h zserv.h redistribute.h debug.h rtadv.h \ interface.h ipforward.h irdp.h router-id.h kernel_socket.h \ rt_netlink.h zebra_fpm.h zebra_fpm_private.h zebra_rnh.h \ zebra_ptm_redistribute.h zebra_ptm.h zebra_routemap.h \ - zebra_ns.h zebra_vrf.h ioctl_solaris.h + zebra_ns.h zebra_vrf.h ioctl_solaris.h zebra_static.h zebra_LDADD = $(otherobj) ../lib/libzebra.la $(LIBCAP) diff --git a/zebra/rib.h b/zebra/rib.h index 095b9c6f8f..32f370f9ef 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -175,51 +175,6 @@ typedef struct rib_dest_t_ #define RNODE_FOREACH_RIB_SAFE(rn, rib, next) \ RIB_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode (rn), rib, next) -/* Static route information. */ -struct static_route -{ - /* For linked list. */ - struct static_route *prev; - struct static_route *next; - - /* VRF identifier. */ - vrf_id_t vrf_id; - - /* Administrative distance. */ - u_char distance; - - /* Tag */ - u_short tag; - - /* Flag for this static route's type. */ - u_char type; -#define STATIC_IFINDEX 1 -#define STATIC_IPV4_GATEWAY 2 -#define STATIC_IPV4_BLACKHOLE 3 -#define STATIC_IPV6_GATEWAY 4 -#define STATIC_IPV6_GATEWAY_IFINDEX 5 - - /* - * Nexthop value. - * - * Under IPv4 addr and ifindex are - * used independentyly. - * STATIC_IPV4_GATEWAY uses addr - * STATIC_IFINDEX uses ifindex - */ - union g_addr addr; - ifindex_t ifindex; - - char ifname[INTERFACE_NAMSIZ + 1]; - - /* bit flags */ - u_char flags; -/* - see ZEBRA_FLAG_REJECT - ZEBRA_FLAG_BLACKHOLE - */ -}; - /* The following for loop allows to iterate over the nexthop * structure of routes. * @@ -365,6 +320,7 @@ extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *, #define ZEBRA_RIB_FOUND_CONNECTED 2 #define ZEBRA_RIB_NOTFOUND 3 +extern void rib_nexthop_delete (struct rib *rib, struct nexthop *nexthop); 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, @@ -374,6 +330,11 @@ extern int is_zebra_valid_kernel_table(u_int32_t table_id); extern int is_zebra_main_routing_table(u_int32_t table_id); extern int zebra_check_addr (struct prefix *p); +extern void rib_addnode (struct route_node *rn, struct rib *rib, int process); +extern void rib_delnode (struct route_node *rn, struct rib *rib); +extern int rib_install_kernel (struct route_node *rn, struct rib *rib, int update); +extern int rib_uninstall_kernel (struct route_node *rn, struct rib *rib); + /* NOTE: * All rib_add_ipv[46]* functions will not just add prefix into RIB, but * also implicitly withdraw equal prefix of same type. */ @@ -404,20 +365,6 @@ extern void rib_init (void); extern unsigned long rib_score_proto (u_char proto, u_short instance); extern void rib_queue_add (struct route_node *rn); -extern void -static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_route *si); -extern void -static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_route *si); - -extern int -static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex, - const char *ifname, u_char flags, u_short tag, - u_char distance, struct zebra_vrf *zvrf); - -extern int -static_delete_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex, - u_short tag, u_char distance, struct zebra_vrf *zvrf); - extern int rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, @@ -435,20 +382,10 @@ extern struct rib *rib_match_ipv6 (struct in6_addr *, vrf_id_t); extern struct route_table *rib_table_ipv6; -extern int -static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, - ifindex_t ifindex, const char *ifname, u_char flags, - u_short tag, u_char distance, struct zebra_vrf *zvrf); - extern int rib_add_ipv6_multipath (struct prefix *, struct rib *, safi_t, ifindex_t); -extern int -static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, - ifindex_t ifindex, u_short tag, u_char distance, - struct zebra_vrf *zvrf); - extern int rib_gc_dest (struct route_node *rn); extern struct route_table *rib_tables_iter_next (rib_tables_iter_t *iter); diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 195d3633e1..0db1b0a689 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -195,7 +195,7 @@ rib_copy_nexthops (struct rib *rib, struct nexthop *nh) } /* Delete specified nexthop from the list. */ -static void +void rib_nexthop_delete (struct rib *rib, struct nexthop *nexthop) { if (nexthop->next) @@ -1248,7 +1248,7 @@ nexthop_active_update (struct route_node *rn, struct rib *rib, int set) /* Update flag indicates whether this is a "replace" or not. Currently, this * is only used for IPv4. */ -static int +int rib_install_kernel (struct route_node *rn, struct rib *rib, int update) { int ret = 0; @@ -1303,7 +1303,7 @@ rib_install_kernel (struct route_node *rn, struct rib *rib, int update) } /* Uninstall the route from kernel. */ -static int +int rib_uninstall_kernel (struct route_node *rn, struct rib *rib) { int ret = 0; @@ -1555,7 +1555,6 @@ rib_process_update_route (struct zebra_vrf *zvrf, struct route_node *rn, for (nexthop = fib->nexthop; nexthop; nexthop = nexthop->next) UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB); } - } /* Update for redistribution. */ @@ -2324,7 +2323,7 @@ rib_link (struct route_node *rn, struct rib *rib, int process) rib_queue_add (rn); } -static void +void rib_addnode (struct route_node *rn, struct rib *rib, int process) { /* RIB node has been un-removed before route-node is processed. @@ -2379,7 +2378,7 @@ rib_unlink (struct route_node *rn, struct rib *rib) } -static void +void rib_delnode (struct route_node *rn, struct rib *rib) { afi_t afi; @@ -2910,440 +2909,7 @@ rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, return 0; } -/* Install static route into rib. */ -void -static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_route *si) -{ - struct rib *rib; - struct route_node *rn; - struct route_table *table; - struct prefix nh_p; - - /* Lookup table. */ - table = zebra_vrf_table (afi, safi, si->vrf_id); - if (! table) - return; - - /* Lookup existing route */ - rn = route_node_get (table, p); - RNODE_FOREACH_RIB (rn, rib) - { - if (CHECK_FLAG (rib->status, RIB_ENTRY_REMOVED)) - continue; - - if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance) - break; - } - - if (rib) - { - /* if tag value changed , update old value in RIB */ - if (rib->tag != si->tag) - rib->tag = si->tag; - - /* Same distance static route is there. Update it with new - nexthop. */ - route_unlock_node (rn); - switch (si->type) - { - case STATIC_IPV4_GATEWAY: - 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(si->vrf_id, &nh_p, rn); - break; - case STATIC_IFINDEX: - rib_nexthop_ifindex_add (rib, si->ifindex); - break; - case STATIC_IPV4_BLACKHOLE: - rib_nexthop_blackhole_add (rib); - break; - case STATIC_IPV6_GATEWAY: - 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(si->vrf_id, &nh_p, rn); - break; - case STATIC_IPV6_GATEWAY_IFINDEX: - rib_nexthop_ipv6_ifindex_add (rib, &si->addr.ipv6, si->ifindex); - break; - } - - if (IS_ZEBRA_DEBUG_RIB) - { - char buf[INET6_ADDRSTRLEN]; - if (IS_ZEBRA_DEBUG_RIB) - { - inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN); - zlog_debug ("%u:%s/%d: Modifying route rn %p, rib %p (type %d)", - si->vrf_id, buf, p->prefixlen, rn, rib, rib->type); - } - } - /* Schedule route for processing or invoke NHT, as appropriate. */ - if (si->type == STATIC_IPV4_GATEWAY || - si->type == STATIC_IPV6_GATEWAY) - zebra_evaluate_rnh(si->vrf_id, nh_p.family, 1, RNH_NEXTHOP_TYPE, &nh_p); - else - rib_queue_add (rn); - } - else - { - /* This is new static route. */ - rib = XCALLOC (MTYPE_RIB, sizeof (struct rib)); - - rib->type = ZEBRA_ROUTE_STATIC; - rib->instance = 0; - rib->distance = si->distance; - rib->metric = 0; - rib->mtu = 0; - rib->vrf_id = si->vrf_id; - rib->table = si->vrf_id ? (zebra_vrf_lookup(si->vrf_id))->table_id : zebrad.rtm_table_default; - rib->nexthop_num = 0; - rib->tag = si->tag; - - switch (si->type) - { - case STATIC_IPV4_GATEWAY: - 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(si->vrf_id, &nh_p, rn); - break; - case STATIC_IFINDEX: - rib_nexthop_ifindex_add (rib, si->ifindex); - break; - case STATIC_IPV4_BLACKHOLE: - rib_nexthop_blackhole_add (rib); - break; - case STATIC_IPV6_GATEWAY: - 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(si->vrf_id, &nh_p, rn); - break; - case STATIC_IPV6_GATEWAY_IFINDEX: - rib_nexthop_ipv6_ifindex_add (rib, &si->addr.ipv6, si->ifindex); - break; - } - - /* Save the flags of this static routes (reject, blackhole) */ - rib->flags = si->flags; - - if (IS_ZEBRA_DEBUG_RIB) - { - char buf[INET6_ADDRSTRLEN]; - if (IS_ZEBRA_DEBUG_RIB) - { - inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN); - zlog_debug ("%u:%s/%d: Inserting route rn %p, rib %p (type %d)", - si->vrf_id, buf, p->prefixlen, rn, rib, rib->type); - } - } - /* Link this rib to the tree. Schedule for processing or invoke NHT, - * as appropriate. - */ - if (si->type == STATIC_IPV4_GATEWAY || - si->type == STATIC_IPV6_GATEWAY) - { - rib_addnode (rn, rib, 0); - zebra_evaluate_rnh(si->vrf_id, nh_p.family, 1, RNH_NEXTHOP_TYPE, &nh_p); - } - else - rib_addnode (rn, rib, 1); - } -} - -static int -static_nexthop_same (struct nexthop *nexthop, struct static_route *si) -{ - if (nexthop->type == NEXTHOP_TYPE_IPV4 - && si->type == STATIC_IPV4_GATEWAY - && IPV4_ADDR_SAME (&nexthop->gate.ipv4, &si->addr.ipv4)) - return 1; - if (nexthop->type == NEXTHOP_TYPE_IFINDEX - && si->type == STATIC_IFINDEX - && nexthop->ifindex == si->ifindex) - return 1; - if (nexthop->type == NEXTHOP_TYPE_BLACKHOLE - && si->type == STATIC_IPV4_BLACKHOLE) - return 1; - if (nexthop->type == NEXTHOP_TYPE_IPV6 - && si->type == STATIC_IPV6_GATEWAY - && IPV6_ADDR_SAME (&nexthop->gate.ipv6, &si->addr.ipv6)) - return 1; - if (nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX - && si->type == STATIC_IPV6_GATEWAY_IFINDEX - && IPV6_ADDR_SAME (&nexthop->gate.ipv6, &si->addr.ipv6) - && nexthop->ifindex == si->ifindex) - return 1; - return 0; -} - -/* Uninstall static route from RIB. */ -void -static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_route *si) -{ - struct route_node *rn; - struct rib *rib; - struct nexthop *nexthop; - struct route_table *table; - struct prefix nh_p; - - /* Lookup table. */ - table = zebra_vrf_table (afi, safi, si->vrf_id); - if (! table) - return; - - /* Lookup existing route with type and distance. */ - rn = route_node_lookup (table, p); - if (! rn) - return; - - RNODE_FOREACH_RIB (rn, rib) - { - if (CHECK_FLAG (rib->status, RIB_ENTRY_REMOVED)) - continue; - - if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance && - rib->tag == si->tag) - break; - } - - if (! rib) - { - route_unlock_node (rn); - return; - } - - /* Lookup nexthop. */ - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) - if (static_nexthop_same (nexthop, si)) - break; - - /* Can't find nexthop. */ - if (! nexthop) - { - route_unlock_node (rn); - return; - } - - /* Check nexthop. */ - if (rib->nexthop_num == 1) - rib_delnode (rn, rib); - else - { - /* Mark this nexthop as inactive and reinstall the route. Then, delete - * the nexthop. There is no need to re-evaluate the route for this - * scenario. - */ - if (IS_ZEBRA_DEBUG_RIB) - { - char buf[INET6_ADDRSTRLEN]; - if (IS_ZEBRA_DEBUG_RIB) - { - inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN); - zlog_debug ("%u:%s/%d: Modifying route rn %p, rib %p (type %d)", - si->vrf_id, buf, p->prefixlen, rn, rib, rib->type); - } - } - UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); - if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)) - { - /* If there are other active nexthops, do an update. */ - if (rib->nexthop_active_num > 1) - { - rib_install_kernel (rn, rib, 1); - redistribute_update (&rn->p, rib, NULL); - } - else - { - redistribute_delete (&rn->p, rib); - rib_uninstall_kernel (rn, rib); - } - } - - if (afi == AFI_IP) - { - /* Delete the nexthop and dereg from NHT */ - nh_p.family = AF_INET; - nh_p.prefixlen = IPV4_MAX_BITLEN; - nh_p.u.prefix4 = nexthop->gate.ipv4; - } - else - { - nh_p.family = AF_INET6; - nh_p.prefixlen = IPV6_MAX_BITLEN; - nh_p.u.prefix6 = nexthop->gate.ipv6; - } - rib_nexthop_delete (rib, nexthop); - zebra_deregister_rnh_static_nh(si->vrf_id, &nh_p, rn); - nexthop_free (nexthop); - } - /* Unlock node. */ - route_unlock_node (rn); -} - -int -static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex, - const char *ifname, u_char flags, u_short tag, - u_char distance, struct zebra_vrf *zvrf) -{ - u_char type = 0; - struct route_node *rn; - struct static_route *si; - struct static_route *pp; - struct static_route *cp; - struct static_route *update = NULL; - struct route_table *stable = zvrf->stable[AFI_IP][safi]; - - if (! stable) - return -1; - - /* Lookup static route prefix. */ - rn = route_node_get (stable, p); - - /* Make flags. */ - if (gate) - type = STATIC_IPV4_GATEWAY; - else if (ifindex) - type = STATIC_IFINDEX; - else - type = STATIC_IPV4_BLACKHOLE; - - /* Do nothing if there is a same static route. */ - for (si = rn->info; si; si = si->next) - { - if (type == si->type - && (! gate || IPV4_ADDR_SAME (gate, &si->addr.ipv4)) - && (! ifindex || ifindex == si->ifindex)) - { - if ((distance == si->distance) && (tag == si->tag)) - { - route_unlock_node (rn); - return 0; - } - else - update = si; - } - } - - /* Distance or tag changed. */ - if (update) - static_delete_ipv4 (safi, p, gate, ifindex, update->tag, update->distance, zvrf); - - /* Make new static route structure. */ - si = XCALLOC (MTYPE_STATIC_ROUTE, sizeof (struct static_route)); - si->type = type; - si->distance = distance; - si->flags = flags; - si->tag = tag; - si->vrf_id = zvrf->vrf_id; - si->ifindex = ifindex; - if (si->ifindex) - strcpy(si->ifname, ifname); - - if (gate) - si->addr.ipv4 = *gate; - - /* Add new static route information to the tree with sort by - distance value and gateway address. */ - for (pp = NULL, cp = rn->info; cp; pp = cp, cp = cp->next) - { - if (si->distance < cp->distance) - break; - if (si->distance > cp->distance) - continue; - if (si->type == STATIC_IPV4_GATEWAY && cp->type == STATIC_IPV4_GATEWAY) - { - if (ntohl (si->addr.ipv4.s_addr) < ntohl (cp->addr.ipv4.s_addr)) - break; - if (ntohl (si->addr.ipv4.s_addr) > ntohl (cp->addr.ipv4.s_addr)) - continue; - } - } - - /* Make linked list. */ - if (pp) - pp->next = si; - else - rn->info = si; - if (cp) - cp->prev = si; - si->prev = pp; - si->next = cp; - - /* Install into rib. */ - static_install_route (AFI_IP, safi, p, si); - - return 1; -} - -int -static_delete_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex, - u_short tag, u_char distance, struct zebra_vrf *zvrf) -{ - u_char type = 0; - struct route_node *rn; - struct static_route *si; - struct route_table *stable; - - /* Lookup table. */ - stable = zebra_vrf_static_table (AFI_IP, safi, zvrf); - if (! stable) - return -1; - - /* Lookup static route prefix. */ - rn = route_node_lookup (stable, p); - if (! rn) - return 0; - - /* Make flags. */ - if (gate) - type = STATIC_IPV4_GATEWAY; - else if (ifindex) - type = STATIC_IFINDEX; - else - type = STATIC_IPV4_BLACKHOLE; - - /* Find same static route is the tree */ - for (si = rn->info; si; si = si->next) - if (type == si->type - && (! gate || IPV4_ADDR_SAME (gate, &si->addr.ipv4)) - && (! ifindex || ifindex == si->ifindex) - && (! tag || (tag == si->tag))) - break; - - /* Can't find static route. */ - if (! si) - { - route_unlock_node (rn); - return 0; - } - - /* Install into rib. */ - static_uninstall_route (AFI_IP, safi, p, si); - - /* Unlink static route from linked list. */ - if (si->prev) - si->prev->next = si->next; - else - rn->info = si->next; - if (si->next) - si->next->prev = si->prev; - route_unlock_node (rn); - - /* Free static route configuration. */ - XFREE (MTYPE_STATIC_ROUTE, si); - - route_unlock_node (rn); - - return 1; -} int rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, @@ -3707,155 +3273,6 @@ rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, return 0; } -/* Add static route into static route configuration. */ -int -static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, - ifindex_t ifindex, const char *ifname, u_char flags, - u_short tag, u_char distance, struct zebra_vrf *zvrf) -{ - struct route_node *rn; - struct static_route *si; - struct static_route *pp; - struct static_route *cp; - struct static_route *update = NULL; - struct route_table *stable = zvrf->stable[AFI_IP6][SAFI_UNICAST]; - - if (! stable) - return -1; - - if (!gate && - (type == STATIC_IPV6_GATEWAY || type == STATIC_IPV6_GATEWAY_IFINDEX)) - return -1; - - if (!ifindex && - (type == STATIC_IPV6_GATEWAY_IFINDEX || type == STATIC_IFINDEX)) - return -1; - - /* Lookup static route prefix. */ - rn = route_node_get (stable, p); - - /* Do nothing if there is a same static route. */ - for (si = rn->info; si; si = si->next) - { - if (type == si->type - && (! gate || IPV6_ADDR_SAME (gate, &si->addr.ipv6)) - && (! ifindex || ifindex == si->ifindex)) - { - if ((distance == si->distance) && (tag == si->tag)) - { - route_unlock_node (rn); - return 0; - } - else - update = si; - } - } - - /* Distance or tag changed. */ - if (update) - static_delete_ipv6 (p, type, gate, ifindex, update->tag, update->distance, zvrf); - - /* Make new static route structure. */ - si = XCALLOC (MTYPE_STATIC_ROUTE, sizeof (struct static_route)); - - si->type = type; - si->distance = distance; - si->flags = flags; - si->tag = tag; - si->vrf_id = zvrf->vrf_id; - si->ifindex = ifindex; - if (si->ifindex) - strcpy (si->ifname, ifname); - - switch (type) - { - case STATIC_IPV6_GATEWAY: - si->addr.ipv6 = *gate; - break; - case STATIC_IPV6_GATEWAY_IFINDEX: - si->addr.ipv6 = *gate; - break; - } - - /* Add new static route information to the tree with sort by - distance value and gateway address. */ - for (pp = NULL, cp = rn->info; cp; pp = cp, cp = cp->next) - { - if (si->distance < cp->distance) - break; - if (si->distance > cp->distance) - continue; - } - - /* Make linked list. */ - if (pp) - pp->next = si; - else - rn->info = si; - if (cp) - cp->prev = si; - si->prev = pp; - si->next = cp; - - /* Install into rib. */ - static_install_route (AFI_IP6, SAFI_UNICAST, p, si); - - return 1; -} - -/* Delete static route from static route configuration. */ -int -static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, - ifindex_t ifindex, u_short tag, u_char distance, - struct zebra_vrf *zvrf) -{ - struct route_node *rn; - struct static_route *si; - struct route_table *stable; - - /* Lookup table. */ - stable = zebra_vrf_static_table (AFI_IP6, SAFI_UNICAST, zvrf); - if (! stable) - return -1; - - /* Lookup static route prefix. */ - rn = route_node_lookup (stable, p); - if (! rn) - return 0; - - /* Find same static route is the tree */ - for (si = rn->info; si; si = si->next) - if (distance == si->distance - && type == si->type - && (! gate || IPV6_ADDR_SAME (gate, &si->addr.ipv6)) - && (! ifindex || ifindex == si->ifindex) - && (! tag || (tag == si->tag))) - break; - - /* Can't find static route. */ - if (! si) - { - route_unlock_node (rn); - return 0; - } - - /* Install into rib. */ - static_uninstall_route (AFI_IP6, SAFI_UNICAST, p, si); - - /* Unlink static route from linked list. */ - if (si->prev) - si->prev->next = si->next; - else - rn->info = si->next; - if (si->next) - si->next->prev = si->prev; - - /* Free static route configuration. */ - XFREE (MTYPE_STATIC_ROUTE, si); - - return 1; -} - /* Schedule routes of a particular table (address-family) based on event. */ static void rib_update_table (struct route_table *table, rib_update_event_t event) diff --git a/zebra/zebra_static.c b/zebra/zebra_static.c new file mode 100644 index 0000000000..9d16f12679 --- /dev/null +++ b/zebra/zebra_static.c @@ -0,0 +1,617 @@ +/* + * Static Routing Information code + * Copyright (C) 2016 Cumulus Networks + * Donald Sharp + * + * This file is part of Quagga. + * + * 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. + * + * 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 Quagga; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#include + +#include +#include + +#include "zebra/debug.h" +#include "zebra/rib.h" +#include "zebra/zserv.h" +#include "zebra/zebra_vrf.h" +#include "zebra/zebra_static.h" +#include "zebra/zebra_rnh.h" +#include "zebra/redistribute.h" + +/* Install static route into rib. */ +void +static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_route *si) +{ + struct rib *rib; + struct route_node *rn; + struct route_table *table; + struct prefix nh_p; + + /* Lookup table. */ + table = zebra_vrf_table (afi, safi, si->vrf_id); + if (! table) + return; + + /* Lookup existing route */ + rn = route_node_get (table, p); + RNODE_FOREACH_RIB (rn, rib) + { + if (CHECK_FLAG (rib->status, RIB_ENTRY_REMOVED)) + continue; + + if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance) + break; + } + + if (rib) + { + /* if tag value changed , update old value in RIB */ + if (rib->tag != si->tag) + rib->tag = si->tag; + + /* Same distance static route is there. Update it with new + nexthop. */ + route_unlock_node (rn); + switch (si->type) + { + case STATIC_IPV4_GATEWAY: + 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(si->vrf_id, &nh_p, rn); + break; + case STATIC_IFINDEX: + rib_nexthop_ifindex_add (rib, si->ifindex); + break; + case STATIC_IPV4_BLACKHOLE: + rib_nexthop_blackhole_add (rib); + break; + case STATIC_IPV6_GATEWAY: + 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(si->vrf_id, &nh_p, rn); + break; + case STATIC_IPV6_GATEWAY_IFINDEX: + rib_nexthop_ipv6_ifindex_add (rib, &si->addr.ipv6, si->ifindex); + break; + } + + if (IS_ZEBRA_DEBUG_RIB) + { + char buf[INET6_ADDRSTRLEN]; + if (IS_ZEBRA_DEBUG_RIB) + { + inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN); + zlog_debug ("%u:%s/%d: Modifying route rn %p, rib %p (type %d)", + si->vrf_id, buf, p->prefixlen, rn, rib, rib->type); + } + } + /* Schedule route for processing or invoke NHT, as appropriate. */ + if (si->type == STATIC_IPV4_GATEWAY || + si->type == STATIC_IPV6_GATEWAY) + zebra_evaluate_rnh(si->vrf_id, nh_p.family, 1, RNH_NEXTHOP_TYPE, &nh_p); + else + rib_queue_add (rn); + } + else + { + /* This is new static route. */ + rib = XCALLOC (MTYPE_RIB, sizeof (struct rib)); + + rib->type = ZEBRA_ROUTE_STATIC; + rib->instance = 0; + rib->distance = si->distance; + rib->metric = 0; + rib->mtu = 0; + rib->vrf_id = si->vrf_id; + rib->table = si->vrf_id ? (zebra_vrf_lookup(si->vrf_id))->table_id : zebrad.rtm_table_default; + rib->nexthop_num = 0; + rib->tag = si->tag; + + switch (si->type) + { + case STATIC_IPV4_GATEWAY: + 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(si->vrf_id, &nh_p, rn); + break; + case STATIC_IFINDEX: + rib_nexthop_ifindex_add (rib, si->ifindex); + break; + case STATIC_IPV4_BLACKHOLE: + rib_nexthop_blackhole_add (rib); + break; + case STATIC_IPV6_GATEWAY: + 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(si->vrf_id, &nh_p, rn); + break; + case STATIC_IPV6_GATEWAY_IFINDEX: + rib_nexthop_ipv6_ifindex_add (rib, &si->addr.ipv6, si->ifindex); + break; + } + + /* Save the flags of this static routes (reject, blackhole) */ + rib->flags = si->flags; + + if (IS_ZEBRA_DEBUG_RIB) + { + char buf[INET6_ADDRSTRLEN]; + if (IS_ZEBRA_DEBUG_RIB) + { + inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN); + zlog_debug ("%u:%s/%d: Inserting route rn %p, rib %p (type %d)", + si->vrf_id, buf, p->prefixlen, rn, rib, rib->type); + } + } + /* Link this rib to the tree. Schedule for processing or invoke NHT, + * as appropriate. + */ + if (si->type == STATIC_IPV4_GATEWAY || + si->type == STATIC_IPV6_GATEWAY) + { + rib_addnode (rn, rib, 0); + zebra_evaluate_rnh(si->vrf_id, nh_p.family, 1, RNH_NEXTHOP_TYPE, &nh_p); + } + else + rib_addnode (rn, rib, 1); + } +} +static int +static_nexthop_same (struct nexthop *nexthop, struct static_route *si) +{ + if (nexthop->type == NEXTHOP_TYPE_IPV4 + && si->type == STATIC_IPV4_GATEWAY + && IPV4_ADDR_SAME (&nexthop->gate.ipv4, &si->addr.ipv4)) + return 1; + if (nexthop->type == NEXTHOP_TYPE_IFINDEX + && si->type == STATIC_IFINDEX + && nexthop->ifindex == si->ifindex) + return 1; + if (nexthop->type == NEXTHOP_TYPE_BLACKHOLE + && si->type == STATIC_IPV4_BLACKHOLE) + return 1; + if (nexthop->type == NEXTHOP_TYPE_IPV6 + && si->type == STATIC_IPV6_GATEWAY + && IPV6_ADDR_SAME (&nexthop->gate.ipv6, &si->addr.ipv6)) + return 1; + if (nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX + && si->type == STATIC_IPV6_GATEWAY_IFINDEX + && IPV6_ADDR_SAME (&nexthop->gate.ipv6, &si->addr.ipv6) + && nexthop->ifindex == si->ifindex) + return 1; + return 0; +} + +/* Uninstall static route from RIB. */ +void +static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_route *si) +{ + struct route_node *rn; + struct rib *rib; + struct nexthop *nexthop; + struct route_table *table; + struct prefix nh_p; + + /* Lookup table. */ + table = zebra_vrf_table (afi, safi, si->vrf_id); + if (! table) + return; + + /* Lookup existing route with type and distance. */ + rn = route_node_lookup (table, p); + if (! rn) + return; + + RNODE_FOREACH_RIB (rn, rib) + { + if (CHECK_FLAG (rib->status, RIB_ENTRY_REMOVED)) + continue; + + if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance && + rib->tag == si->tag) + break; + } + + if (! rib) + { + route_unlock_node (rn); + return; + } + + /* Lookup nexthop. */ + for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) + if (static_nexthop_same (nexthop, si)) + break; + + /* Can't find nexthop. */ + if (! nexthop) + { + route_unlock_node (rn); + return; + } + + /* Check nexthop. */ + if (rib->nexthop_num == 1) + rib_delnode (rn, rib); + else + { + /* Mark this nexthop as inactive and reinstall the route. Then, delete + * the nexthop. There is no need to re-evaluate the route for this + * scenario. + */ + if (IS_ZEBRA_DEBUG_RIB) + { + char buf[INET6_ADDRSTRLEN]; + if (IS_ZEBRA_DEBUG_RIB) + { + inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN); + zlog_debug ("%u:%s/%d: Modifying route rn %p, rib %p (type %d)", + si->vrf_id, buf, p->prefixlen, rn, rib, rib->type); + } + } + UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); + if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)) + { + /* If there are other active nexthops, do an update. */ + if (rib->nexthop_active_num > 1) + { + rib_install_kernel (rn, rib, 1); + redistribute_update (&rn->p, rib, NULL); + } + else + { + redistribute_delete (&rn->p, rib); + rib_uninstall_kernel (rn, rib); + } + } + + if (afi == AFI_IP) + { + /* Delete the nexthop and dereg from NHT */ + nh_p.family = AF_INET; + nh_p.prefixlen = IPV4_MAX_BITLEN; + nh_p.u.prefix4 = nexthop->gate.ipv4; + } + else + { + nh_p.family = AF_INET6; + nh_p.prefixlen = IPV6_MAX_BITLEN; + nh_p.u.prefix6 = nexthop->gate.ipv6; + } + rib_nexthop_delete (rib, nexthop); + zebra_deregister_rnh_static_nh(si->vrf_id, &nh_p, rn); + nexthop_free (nexthop); + } + /* Unlock node. */ + route_unlock_node (rn); +} + +int +static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex, + const char *ifname, u_char flags, u_short tag, + u_char distance, struct zebra_vrf *zvrf) +{ + u_char type = 0; + struct route_node *rn; + struct static_route *si; + struct static_route *pp; + struct static_route *cp; + struct static_route *update = NULL; + struct route_table *stable = zvrf->stable[AFI_IP][safi]; + + if (! stable) + return -1; + + /* Lookup static route prefix. */ + rn = route_node_get (stable, p); + + /* Make flags. */ + if (gate) + type = STATIC_IPV4_GATEWAY; + else if (ifindex) + type = STATIC_IFINDEX; + else + type = STATIC_IPV4_BLACKHOLE; + + /* Do nothing if there is a same static route. */ + for (si = rn->info; si; si = si->next) + { + if (type == si->type + && (! gate || IPV4_ADDR_SAME (gate, &si->addr.ipv4)) + && (! ifindex || ifindex == si->ifindex)) + { + if ((distance == si->distance) && (tag == si->tag)) + { + route_unlock_node (rn); + return 0; + } + else + update = si; + } + } + + /* Distance or tag changed. */ + if (update) + static_delete_ipv4 (safi, p, gate, ifindex, update->tag, update->distance, zvrf); + + /* Make new static route structure. */ + si = XCALLOC (MTYPE_STATIC_ROUTE, sizeof (struct static_route)); + + si->type = type; + si->distance = distance; + si->flags = flags; + si->tag = tag; + si->vrf_id = zvrf->vrf_id; + si->ifindex = ifindex; + if (si->ifindex) + strcpy(si->ifname, ifname); + + if (gate) + si->addr.ipv4 = *gate; + + /* Add new static route information to the tree with sort by + distance value and gateway address. */ + for (pp = NULL, cp = rn->info; cp; pp = cp, cp = cp->next) + { + if (si->distance < cp->distance) + break; + if (si->distance > cp->distance) + continue; + if (si->type == STATIC_IPV4_GATEWAY && cp->type == STATIC_IPV4_GATEWAY) + { + if (ntohl (si->addr.ipv4.s_addr) < ntohl (cp->addr.ipv4.s_addr)) + break; + if (ntohl (si->addr.ipv4.s_addr) > ntohl (cp->addr.ipv4.s_addr)) + continue; + } + } + + /* Make linked list. */ + if (pp) + pp->next = si; + else + rn->info = si; + if (cp) + cp->prev = si; + si->prev = pp; + si->next = cp; + + /* Install into rib. */ + static_install_route (AFI_IP, safi, p, si); + + return 1; +} + +int +static_delete_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex, + u_short tag, u_char distance, struct zebra_vrf *zvrf) +{ + u_char type = 0; + struct route_node *rn; + struct static_route *si; + struct route_table *stable; + + /* Lookup table. */ + stable = zebra_vrf_static_table (AFI_IP, safi, zvrf); + if (! stable) + return -1; + + /* Lookup static route prefix. */ + rn = route_node_lookup (stable, p); + if (! rn) + return 0; + + /* Make flags. */ + if (gate) + type = STATIC_IPV4_GATEWAY; + else if (ifindex) + type = STATIC_IFINDEX; + else + type = STATIC_IPV4_BLACKHOLE; + + /* Find same static route is the tree */ + for (si = rn->info; si; si = si->next) + if (type == si->type + && (! gate || IPV4_ADDR_SAME (gate, &si->addr.ipv4)) + && (! ifindex || ifindex == si->ifindex) + && (! tag || (tag == si->tag))) + break; + + /* Can't find static route. */ + if (! si) + { + route_unlock_node (rn); + return 0; + } + + /* Install into rib. */ + static_uninstall_route (AFI_IP, safi, p, si); + + /* Unlink static route from linked list. */ + if (si->prev) + si->prev->next = si->next; + else + rn->info = si->next; + if (si->next) + si->next->prev = si->prev; + route_unlock_node (rn); + + /* Free static route configuration. */ + XFREE (MTYPE_STATIC_ROUTE, si); + + route_unlock_node (rn); + + return 1; +} + +/* Add static route into static route configuration. */ +int +static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, + ifindex_t ifindex, const char *ifname, u_char flags, + u_short tag, u_char distance, struct zebra_vrf *zvrf) +{ + struct route_node *rn; + struct static_route *si; + struct static_route *pp; + struct static_route *cp; + struct static_route *update = NULL; + struct route_table *stable = zvrf->stable[AFI_IP6][SAFI_UNICAST]; + + if (! stable) + return -1; + + if (!gate && + (type == STATIC_IPV6_GATEWAY || type == STATIC_IPV6_GATEWAY_IFINDEX)) + return -1; + + if (!ifindex && + (type == STATIC_IPV6_GATEWAY_IFINDEX || type == STATIC_IFINDEX)) + return -1; + + /* Lookup static route prefix. */ + rn = route_node_get (stable, p); + + /* Do nothing if there is a same static route. */ + for (si = rn->info; si; si = si->next) + { + if (type == si->type + && (! gate || IPV6_ADDR_SAME (gate, &si->addr.ipv6)) + && (! ifindex || ifindex == si->ifindex)) + { + if ((distance == si->distance) && (tag == si->tag)) + { + route_unlock_node (rn); + return 0; + } + else + update = si; + } + } + + /* Distance or tag changed. */ + if (update) + static_delete_ipv6 (p, type, gate, ifindex, update->tag, update->distance, zvrf); + + /* Make new static route structure. */ + si = XCALLOC (MTYPE_STATIC_ROUTE, sizeof (struct static_route)); + + si->type = type; + si->distance = distance; + si->flags = flags; + si->tag = tag; + si->vrf_id = zvrf->vrf_id; + si->ifindex = ifindex; + if (si->ifindex) + strcpy (si->ifname, ifname); + + switch (type) + { + case STATIC_IPV6_GATEWAY: + si->addr.ipv6 = *gate; + break; + case STATIC_IPV6_GATEWAY_IFINDEX: + si->addr.ipv6 = *gate; + break; + } + + /* Add new static route information to the tree with sort by + distance value and gateway address. */ + for (pp = NULL, cp = rn->info; cp; pp = cp, cp = cp->next) + { + if (si->distance < cp->distance) + break; + if (si->distance > cp->distance) + continue; + } + + /* Make linked list. */ + if (pp) + pp->next = si; + else + rn->info = si; + if (cp) + cp->prev = si; + si->prev = pp; + si->next = cp; + + /* Install into rib. */ + static_install_route (AFI_IP6, SAFI_UNICAST, p, si); + + return 1; +} + +/* Delete static route from static route configuration. */ +int +static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, + ifindex_t ifindex, u_short tag, u_char distance, + struct zebra_vrf *zvrf) +{ + struct route_node *rn; + struct static_route *si; + struct route_table *stable; + + /* Lookup table. */ + stable = zebra_vrf_static_table (AFI_IP6, SAFI_UNICAST, zvrf); + if (! stable) + return -1; + + /* Lookup static route prefix. */ + rn = route_node_lookup (stable, p); + if (! rn) + return 0; + + /* Find same static route is the tree */ + for (si = rn->info; si; si = si->next) + if (distance == si->distance + && type == si->type + && (! gate || IPV6_ADDR_SAME (gate, &si->addr.ipv6)) + && (! ifindex || ifindex == si->ifindex) + && (! tag || (tag == si->tag))) + break; + + /* Can't find static route. */ + if (! si) + { + route_unlock_node (rn); + return 0; + } + + /* Install into rib. */ + static_uninstall_route (AFI_IP6, SAFI_UNICAST, p, si); + + /* Unlink static route from linked list. */ + if (si->prev) + si->prev->next = si->next; + else + rn->info = si->next; + if (si->next) + si->next->prev = si->prev; + + /* Free static route configuration. */ + XFREE (MTYPE_STATIC_ROUTE, si); + + return 1; +} diff --git a/zebra/zebra_static.h b/zebra/zebra_static.h new file mode 100644 index 0000000000..a3096725f7 --- /dev/null +++ b/zebra/zebra_static.h @@ -0,0 +1,95 @@ +/* + * Static Routing Information header + * Copyright (C) 2016 Cumulus Networks + * Donald Sharp + * + * This file is part of Quagga. + * + * 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. + * + * 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 Quagga; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#ifndef __ZEBRA_STATIC_H__ +#define __ZEBRA_STATIC_H__ + +/* Static route information. */ +struct static_route +{ + /* For linked list. */ + struct static_route *prev; + struct static_route *next; + + /* VRF identifier. */ + vrf_id_t vrf_id; + + /* Administrative distance. */ + u_char distance; + + /* Tag */ + u_short tag; + + /* Flag for this static route's type. */ + u_char type; +#define STATIC_IFINDEX 1 +#define STATIC_IPV4_GATEWAY 2 +#define STATIC_IPV4_BLACKHOLE 3 +#define STATIC_IPV6_GATEWAY 4 +#define STATIC_IPV6_GATEWAY_IFINDEX 5 + + /* + * Nexthop value. + * + * Under IPv4 addr and ifindex are + * used independentyly. + * STATIC_IPV4_GATEWAY uses addr + * STATIC_IFINDEX uses ifindex + */ + union g_addr addr; + ifindex_t ifindex; + + char ifname[INTERFACE_NAMSIZ + 1]; + + /* bit flags */ + u_char flags; +/* + see ZEBRA_FLAG_REJECT + ZEBRA_FLAG_BLACKHOLE + */ +}; + +extern void +static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_route *si); +extern void +static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_route *si); + +extern int +static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex, + const char *ifname, u_char flags, u_short tag, + u_char distance, struct zebra_vrf *zvrf); + +extern int +static_delete_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex, + u_short tag, u_char distance, struct zebra_vrf *zvrf); + +extern int +static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, + ifindex_t ifindex, const char *ifname, u_char flags, + u_short tag, u_char distance, struct zebra_vrf *zvrf); + +extern int +static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, + ifindex_t ifindex, u_short tag, u_char distance, + struct zebra_vrf *zvrf); + +#endif diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index 46dc29d102..d9bd919bfe 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -29,6 +29,7 @@ #include "zebra/rib.h" #include "zebra/zebra_vrf.h" #include "zebra/router-id.h" +#include "zebra/zebra_static.h" extern struct zebra_t zebrad; struct list *zvrf_list; diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 3c2626670b..716e74c0b0 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -29,13 +29,14 @@ #include "rib.h" #include "nexthop.h" #include "vrf.h" +#include "lib/json.h" #include "zebra/zserv.h" #include "zebra/zebra_vrf.h" #include "zebra/zebra_rnh.h" #include "zebra/redistribute.h" #include "zebra/zebra_routemap.h" -#include "lib/json.h" +#include "zebra/zebra_static.h" extern int allow_delete; -- cgit v1.2.3 From 14364a318097a49062f545a255e4e6a306e7b2fe Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 24 Aug 2016 00:48:37 -0400 Subject: zebra: Refactor rib_match_ipv[4|6] the rib_match_ipv4 and rib_match_ipv6 functions were the same. Refactor to 1 function. Signed-off-by: Donald Sharp --- zebra/rib.h | 6 ++-- zebra/zebra_rib.c | 98 ++++++++++++------------------------------------------- zebra/zserv.c | 6 ++-- 3 files changed, 26 insertions(+), 84 deletions(-) (limited to 'zebra/zebra_rib.c') diff --git a/zebra/rib.h b/zebra/rib.h index 32f370f9ef..7fd29dcd5a 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -349,8 +349,8 @@ extern int rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix struct in_addr *gate, ifindex_t ifindex, vrf_id_t, u_int32_t, safi_t safi); -extern struct rib *rib_match_ipv4 (struct in_addr, safi_t safi, vrf_id_t, - struct route_node **rn_out); +extern struct rib *rib_match (afi_t afi, safi_t safi, vrf_id_t, union g_addr *, + struct route_node **rn_out); extern struct rib *rib_match_ipv4_multicast (struct in_addr addr, struct route_node **rn_out); @@ -378,8 +378,6 @@ rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t); -extern struct rib *rib_match_ipv6 (struct in6_addr *, vrf_id_t); - extern struct route_table *rib_table_ipv6; extern int diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 0db1b0a689..3a160825d5 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -747,10 +747,10 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set, } struct rib * -rib_match_ipv4 (struct in_addr addr, safi_t safi, vrf_id_t vrf_id, - struct route_node **rn_out) +rib_match (afi_t afi, safi_t safi, vrf_id_t vrf_id, + union g_addr *addr, struct route_node **rn_out) { - struct prefix_ipv4 p; + struct prefix p; struct route_table *table; struct route_node *rn; struct rib *match; @@ -758,14 +758,18 @@ rib_match_ipv4 (struct in_addr addr, safi_t safi, vrf_id_t vrf_id, int recursing; /* Lookup table. */ - table = zebra_vrf_table (AFI_IP, safi, vrf_id); + table = zebra_vrf_table (afi, safi, vrf_id); if (! table) return 0; - memset (&p, 0, sizeof (struct prefix_ipv4)); - p.family = AF_INET; + memset (&p, 0, sizeof (struct prefix)); + p.family = afi; + p.u.prefix = *(u_char *)addr; p.prefixlen = IPV4_MAX_PREFIXLEN; - p.prefix = addr; + if (afi == AFI_IP) + p.prefixlen = IPV4_MAX_PREFIXLEN; + else + p.prefixlen = IPV6_MAX_PREFIXLEN; rn = route_node_match (table, (struct prefix *) &p); @@ -820,23 +824,23 @@ rib_match_ipv4_multicast (struct in_addr addr, struct route_node **rn_out) { struct rib *rib = NULL, *mrib = NULL, *urib = NULL; struct route_node *m_rn = NULL, *u_rn = NULL; - int skip_bgp = 0; /* bool */ + union g_addr gaddr = { .ipv4 = addr }; switch (ipv4_multicast_mode) { case MCAST_MRIB_ONLY: - return rib_match_ipv4 (addr, SAFI_MULTICAST, skip_bgp, rn_out); + return rib_match (AFI_IP, SAFI_MULTICAST, VRF_DEFAULT, &gaddr, rn_out); case MCAST_URIB_ONLY: - return rib_match_ipv4 (addr, SAFI_UNICAST, skip_bgp, rn_out); + return rib_match (AFI_IP, SAFI_UNICAST, VRF_DEFAULT, &gaddr, rn_out); case MCAST_NO_CONFIG: case MCAST_MIX_MRIB_FIRST: - rib = mrib = rib_match_ipv4 (addr, SAFI_MULTICAST, skip_bgp, &m_rn); + rib = mrib = rib_match (AFI_IP, SAFI_MULTICAST, VRF_DEFAULT, &gaddr, &m_rn); if (!mrib) - rib = urib = rib_match_ipv4 (addr, SAFI_UNICAST, skip_bgp, &u_rn); + rib = urib = rib_match (AFI_IP, SAFI_UNICAST, VRF_DEFAULT, &gaddr, &u_rn); break; case MCAST_MIX_DISTANCE: - mrib = rib_match_ipv4 (addr, SAFI_MULTICAST, skip_bgp, &m_rn); - urib = rib_match_ipv4 (addr, SAFI_UNICAST, skip_bgp, &u_rn); + mrib = rib_match (AFI_IP, SAFI_MULTICAST, VRF_DEFAULT, &gaddr, &m_rn); + urib = rib_match (AFI_IP, SAFI_UNICAST, VRF_DEFAULT, &gaddr, &u_rn); if (mrib && urib) rib = urib->distance < mrib->distance ? urib : mrib; else if (mrib) @@ -845,8 +849,8 @@ rib_match_ipv4_multicast (struct in_addr addr, struct route_node **rn_out) rib = urib; break; case MCAST_MIX_PFXLEN: - mrib = rib_match_ipv4 (addr, SAFI_MULTICAST, skip_bgp, &m_rn); - urib = rib_match_ipv4 (addr, SAFI_UNICAST, skip_bgp, &u_rn); + mrib = rib_match (AFI_IP, SAFI_MULTICAST, VRF_DEFAULT, &gaddr, &m_rn); + urib = rib_match (AFI_IP, SAFI_UNICAST, VRF_DEFAULT, &gaddr, &u_rn); if (mrib && urib) rib = u_rn->p.prefixlen > m_rn->p.prefixlen ? urib : mrib; else if (mrib) @@ -1009,68 +1013,6 @@ rib_lookup_ipv4_route (struct prefix_ipv4 *p, union sockunion * qgate, return ZEBRA_RIB_NOTFOUND; } -struct rib * -rib_match_ipv6 (struct in6_addr *addr, vrf_id_t vrf_id) -{ - struct prefix_ipv6 p; - struct route_table *table; - struct route_node *rn; - struct rib *match; - struct nexthop *newhop, *tnewhop; - int recursing; - - /* Lookup table. */ - table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id); - if (! table) - return 0; - - memset (&p, 0, sizeof (struct prefix_ipv6)); - p.family = AF_INET6; - p.prefixlen = IPV6_MAX_PREFIXLEN; - IPV6_ADDR_COPY (&p.prefix, addr); - - rn = route_node_match (table, (struct prefix *) &p); - - while (rn) - { - route_unlock_node (rn); - - /* Pick up selected route. */ - RNODE_FOREACH_RIB (rn, match) - { - if (CHECK_FLAG (match->status, RIB_ENTRY_REMOVED)) - continue; - if (CHECK_FLAG (match->flags, ZEBRA_FLAG_SELECTED)) - break; - } - - /* If there is no selected route or matched route is EGP, go up - tree. */ - if (! match) - { - do { - rn = rn->parent; - } while (rn && rn->info == NULL); - if (rn) - route_lock_node (rn); - } - else - { - if (match->type == ZEBRA_ROUTE_CONNECT) - /* Directly point connected route. */ - return match; - else - { - for (ALL_NEXTHOPS_RO(match->nexthop, newhop, tnewhop, recursing)) - if (CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_FIB)) - return match; - return NULL; - } - } - } - return NULL; -} - #define RIB_SYSTEM_ROUTE(R) \ ((R)->type == ZEBRA_ROUTE_KERNEL || (R)->type == ZEBRA_ROUTE_CONNECT) diff --git a/zebra/zserv.c b/zebra/zserv.c index 84881e14a4..73e84faca2 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -722,9 +722,10 @@ zsend_ipv6_nexthop_lookup (struct zserv *client, struct in6_addr *addr, unsigned long nump; u_char num; struct nexthop *nexthop; + union g_addr gaddr = { .ipv6 = *addr }; /* Lookup nexthop. */ - rib = rib_match_ipv6 (addr, vrf_id); + rib = rib_match (AFI_IP6, SAFI_UNICAST, vrf_id, &gaddr, NULL); /* Get output stream. */ s = client->obuf; @@ -788,9 +789,10 @@ zsend_ipv4_nexthop_lookup (struct zserv *client, struct in_addr addr, unsigned long nump; u_char num; struct nexthop *nexthop; + union g_addr gaddr = { .ipv4 = addr }; /* Lookup nexthop. */ - rib = rib_match_ipv4 (addr, SAFI_UNICAST, vrf_id, NULL); + rib = rib_match (AFI_IP, SAFI_UNICAST, vrf_id, &gaddr, NULL); /* Get output stream. */ s = client->obuf; -- cgit v1.2.3 From 616368ed1ea8165beb2b1ba137b474ee794046d5 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 24 Aug 2016 01:39:08 -0400 Subject: zebra: Refactor rib_delete_ipv[4|6] These two functions are essentially the same. Refactor. Signed-off-by: Donald Sharp --- zebra/connected.c | 24 ++++---- zebra/kernel_socket.c | 35 +++++------ zebra/redistribute.c | 13 ++-- zebra/rib.h | 12 ++-- zebra/rt_netlink.c | 26 ++++---- zebra/zebra_rib.c | 162 ++++---------------------------------------------- zebra/zserv.c | 29 +++++---- 7 files changed, 81 insertions(+), 220 deletions(-) (limited to 'zebra/zebra_rib.c') diff --git a/zebra/connected.c b/zebra/connected.c index 3077272221..e3cb12bcd0 100644 --- a/zebra/connected.c +++ b/zebra/connected.c @@ -303,7 +303,7 @@ connected_add_ipv4 (struct interface *ifp, int flags, struct in_addr *addr, void connected_down_ipv4 (struct interface *ifp, struct connected *ifc) { - struct prefix_ipv4 p; + struct prefix p; if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) return; @@ -311,19 +311,19 @@ connected_down_ipv4 (struct interface *ifp, struct connected *ifc) PREFIX_COPY_IPV4(&p, CONNECTED_PREFIX(ifc)); /* Apply mask to the network. */ - apply_mask_ipv4 (&p); + apply_mask (&p); /* In case of connected address is 0.0.0.0/0 we treat it tunnel address. */ - if (prefix_ipv4_any (&p)) + if (prefix_ipv4_any ((struct prefix_ipv4 *)&p)) return; /* Same logic as for connected_up_ipv4(): push the changes into the head. */ - rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, ifp->vrf_id, 0, - SAFI_UNICAST); + rib_delete (AFI_IP, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, + 0, 0, &p, NULL, ifp->ifindex, 0); - rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, ifp->vrf_id, 0, - SAFI_MULTICAST); + rib_delete (AFI_IP, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, + 0, 0, &p, NULL, ifp->ifindex, 0); if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug ("%u: IF %s IPv4 address down, scheduling RIB processing", @@ -456,20 +456,20 @@ connected_add_ipv6 (struct interface *ifp, int flags, struct in6_addr *addr, void connected_down_ipv6 (struct interface *ifp, struct connected *ifc) { - struct prefix_ipv6 p; + struct prefix p; if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) return; PREFIX_COPY_IPV6(&p, CONNECTED_PREFIX(ifc)); - apply_mask_ipv6 (&p); + apply_mask (&p); - if (IN6_IS_ADDR_UNSPECIFIED (&p.prefix)) + if (IN6_IS_ADDR_UNSPECIFIED (&p.u.prefix6)) return; - rib_delete_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, - ifp->vrf_id, 0, SAFI_UNICAST); + rib_delete (AFI_IP6, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, + 0, 0, &p, NULL, ifp->ifindex, 0); if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug ("%u: IF %s IPv6 address down, scheduling RIB processing", diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index c5763dd46f..ccc54ce81f 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -884,10 +884,10 @@ rtm_read (struct rt_msghdr *rtm) if (dest.sa.sa_family == AF_INET) { - struct prefix_ipv4 p; + struct prefix p; p.family = AF_INET; - p.prefix = dest.sin.sin_addr; + p.u.prefix4 = dest.sin.sin_addr; if (flags & RTF_HOST) p.prefixlen = IPV4_MAX_PREFIXLEN; else @@ -967,20 +967,20 @@ rtm_read (struct rt_msghdr *rtm) * to specify the route really */ if (rtm->rtm_type == RTM_CHANGE) - rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, - NULL, 0, VRF_DEFAULT, 0, SAFI_UNICAST); + rib_delete (AFI_IP, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL, + 0, zebra_flags, &p, NULL, 0, 0); + union g_addr ggate = { .ipv4 = gate.sin.sin_addr }; if (rtm->rtm_type == RTM_GET || rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_CHANGE) rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, - &p, &gate.sin.sin_addr, NULL, 0, VRF_DEFAULT, + (struct prefix_ipv4 *)&p, &gate.sin.sin_addr, NULL, 0, VRF_DEFAULT, 0, 0, 0, 0, SAFI_UNICAST); else - rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, - &p, &gate.sin.sin_addr, 0, VRF_DEFAULT, 0, SAFI_UNICAST); + rib_delete (AFI_IP, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL, + 0, zebra_flags, &p, &&ggate, 0, 0); } -#ifdef HAVE_IPV6 if (dest.sa.sa_family == AF_INET6) { /* One day we might have a debug section here like one in the @@ -988,11 +988,11 @@ rtm_read (struct rt_msghdr *rtm) */ if (rtm->rtm_type != RTM_GET && rtm->rtm_pid == pid) return; - struct prefix_ipv6 p; + struct prefix p; ifindex_t ifindex = 0; p.family = AF_INET6; - p.prefix = dest.sin6.sin6_addr; + p.u.prefix6 = dest.sin6.sin6_addr; if (flags & RTF_HOST) p.prefixlen = IPV6_MAX_PREFIXLEN; else @@ -1010,20 +1010,21 @@ rtm_read (struct rt_msghdr *rtm) * to specify the route really */ if (rtm->rtm_type == RTM_CHANGE) - rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, - NULL, 0, VRF_DEFAULT, 0, SAFI_UNICAST); - + rib_delete (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL, + 0, zebra_flags, &p, NULL, 0, 0); + + union g_addr ggate = { .ipv6 = gate.sin6.sin6_addr }; if (rtm->rtm_type == RTM_GET || rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_CHANGE) rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, - &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, + (struct prefix_ipv6 *)&p, &gate.sin6.sin6_addr, + ifindex, VRF_DEFAULT, 0, 0, 0, 0, SAFI_UNICAST); else - rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, - &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, 0, SAFI_UNICAST); + rib_delete (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL, + 0, zebra_flags, &p, &ggate, ifindex, 0); } -#endif /* HAVE_IPV6 */ } /* Interface function for the kernel routing table updates. Support diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 892bc2af2b..2eb4f257f5 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -614,16 +614,17 @@ zebra_add_import_table_entry (struct route_node *rn, struct rib *rib, const char int zebra_del_import_table_entry (struct route_node *rn, struct rib *rib) { - struct prefix_ipv4 p4; + struct prefix p; if (rn->p.family == AF_INET) { - p4.family = AF_INET; - p4.prefixlen = rn->p.prefixlen; - p4.prefix = rn->p.u.prefix4; + p.family = AF_INET; + p.prefixlen = rn->p.prefixlen; + p.u.prefix4 = rn->p.u.prefix4; - rib_delete_ipv4(ZEBRA_ROUTE_TABLE, rib->table, rib->flags, &p4, NULL, - 0, rib->vrf_id, zebrad.rtm_table_default, SAFI_UNICAST); + rib_delete (AFI_IP, SAFI_UNICAST, rib->vrf_id, ZEBRA_ROUTE_TABLE, + rib->table, rib->flags, &p, NULL, + 0, zebrad.rtm_table_default); } /* DD: Add IPv6 code */ diff --git a/zebra/rib.h b/zebra/rib.h index 7fd29dcd5a..8b70de7a03 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -345,9 +345,10 @@ extern int rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ip extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t); -extern int rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, - struct in_addr *gate, ifindex_t ifindex, - vrf_id_t, u_int32_t, safi_t safi); +extern int rib_delete (afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, + u_short instance, int flags, struct prefix *p, + union g_addr *gate, ifindex_t ifindex, + u_int32_t table_id); extern struct rib *rib_match (afi_t afi, safi_t safi, vrf_id_t, union g_addr *, struct route_node **rn_out); @@ -371,11 +372,6 @@ rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, u_int32_t table_id, u_int32_t metric, u_int32_t mtu, u_char distance, safi_t safi); -extern int -rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, - struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, - u_int32_t table_id, safi_t safi); - extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t); extern struct route_table *rib_table_ipv6; diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 49dcd1e6de..dc3aa2f6bb 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -1059,7 +1059,8 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h, struct rtmsg *rtm; struct rtattr *tb[RTA_MAX + 1]; u_char zebra_flags = 0; - + struct prefix p; + char anyaddr[16] = { 0 }; int index; @@ -1177,9 +1178,8 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h, if (rtm->rtm_family == AF_INET) { - struct prefix_ipv4 p; p.family = AF_INET; - memcpy (&p.prefix, dest, 4); + memcpy (&p.u.prefix4, dest, 4); p.prefixlen = rtm->rtm_dst_len; if (IS_ZEBRA_DEBUG_KERNEL) @@ -1193,7 +1193,7 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h, if (h->nlmsg_type == RTM_NEWROUTE) { if (!tb[RTA_MULTIPATH]) - rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, src, index, vrf_id, + rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, 0, (struct prefix_ipv4 *)&p, gate, src, index, vrf_id, table, metric, mtu, 0, SAFI_UNICAST); else { @@ -1252,21 +1252,20 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h, if (rib->nexthop_num == 0) XFREE (MTYPE_RIB, rib); else - rib_add_ipv4_multipath (&p, rib, SAFI_UNICAST); + rib_add_ipv4_multipath ((struct prefix_ipv4 *)&p, rib, SAFI_UNICAST); } } else - rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, gate, index, - vrf_id, table, SAFI_UNICAST); + rib_delete (AFI_IP, SAFI_UNICAST, vrf_id, ZEBRA_ROUTE_KERNEL, 0, zebra_flags, + &p, gate, index, table); } -#ifdef HAVE_IPV6 if (rtm->rtm_family == AF_INET6) { - struct prefix_ipv6 p; + struct prefix p; p.family = AF_INET6; - memcpy (&p.prefix, dest, 16); + memcpy (&p.u.prefix6, dest, 16); p.prefixlen = rtm->rtm_dst_len; if (IS_ZEBRA_DEBUG_KERNEL) @@ -1278,13 +1277,12 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h, } if (h->nlmsg_type == RTM_NEWROUTE) - rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, index, vrf_id, + rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, 0, (struct prefix_ipv6 *)&p, gate, index, vrf_id, table, metric, mtu, 0, SAFI_UNICAST); else - rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, gate, index, - vrf_id, table, SAFI_UNICAST); + rib_delete (AFI_IP6, SAFI_UNICAST, vrf_id, ZEBRA_ROUTE_KERNEL, + 0, zebra_flags, &p, gate, index, table); } -#endif /* HAVE_IPV6 */ return 0; } diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 3a160825d5..0dbbd47a45 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -2713,11 +2713,10 @@ rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib, safi_t safi) return ret; } -/* XXX factor with rib_delete_ipv6 */ int -rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, - struct in_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, - u_int32_t table_id, safi_t safi) +rib_delete (afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, u_short instance, + int flags, struct prefix *p, union g_addr *gate, ifindex_t ifindex, + u_int32_t table_id) { struct route_table *table; struct route_node *rn; @@ -2730,15 +2729,15 @@ rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, char buf2[INET6_ADDRSTRLEN]; /* Lookup table. */ - table = zebra_vrf_table_with_table_id (AFI_IP, safi, vrf_id, table_id); + table = zebra_vrf_table_with_table_id (afi, safi, vrf_id, table_id); if (! table) return 0; /* Apply mask. */ - apply_mask_ipv4 (p); + apply_mask (p); /* Lookup route node. */ - rn = route_node_lookup (table, (struct prefix *) p); + rn = route_node_lookup (table, p); if (! rn) { if (IS_ZEBRA_DEBUG_RIB) @@ -2784,7 +2783,8 @@ rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, break; } for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing)) - if (IPV4_ADDR_SAME (&nexthop->gate.ipv4, gate)) + if (IPV4_ADDR_SAME (&nexthop->gate.ipv4, gate) || + IPV6_ADDR_SAME (&nexthop->gate.ipv6, gate)) { same = rib; break; @@ -2802,10 +2802,10 @@ rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, { if (IS_ZEBRA_DEBUG_RIB) { - zlog_debug ("%u:%s/%d: rn %p, rib %p (type %d) was deleted " + zlog_debug ("%u:%s: rn %p, rib %p (type %d) was deleted " "from kernel, adding", - vrf_id, inet_ntop (p->family, &p->prefix, buf1, INET6_ADDRSTRLEN), - p->prefixlen, rn, fib, fib->type); + vrf_id, prefix2str(p, buf1, INET6_ADDRSTRLEN), + rn, fib, fib->type); } if (allow_delete) { @@ -2830,7 +2830,7 @@ rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, zlog_debug ("%u:%s: via %s ifindex %d type %d " "doesn't exist in rib", vrf_id, prefix2str (p, buf1, sizeof(buf1)), - inet_ntop (AF_INET, gate, buf2, INET_ADDRSTRLEN), + inet_ntop (family2afi(afi), gate, buf2, INET_ADDRSTRLEN), ifindex, type); else @@ -3077,144 +3077,6 @@ rib_add_ipv6_multipath (struct prefix *p, struct rib *rib, safi_t safi, return ret; } -/* XXX factor with rib_delete_ipv6 */ - -int -rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, - struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, - u_int32_t table_id, safi_t safi) -{ - struct route_table *table; - struct route_node *rn; - struct rib *rib; - struct rib *fib = NULL; - struct rib *same = NULL; - struct nexthop *nexthop, *tnexthop; - int recursing; - char buf1[PREFIX_STRLEN]; - char buf2[INET6_ADDRSTRLEN]; - - /* Apply mask. */ - apply_mask_ipv6 (p); - - /* Lookup table. */ - table = zebra_vrf_table_with_table_id (AFI_IP6, safi, vrf_id, table_id); - if (! table) - return 0; - - /* Lookup route node. */ - rn = route_node_lookup (table, (struct prefix *) p); - if (! rn) - { - if (IS_ZEBRA_DEBUG_RIB) - zlog_debug ("%u:%s: doesn't exist in rib", - vrf_id, prefix2str (p, buf1, sizeof(buf1))); - return ZEBRA_ERR_RTNOEXIST; - } - - /* Lookup same type route. */ - RNODE_FOREACH_RIB (rn, rib) - { - if (CHECK_FLAG(rib->status, RIB_ENTRY_REMOVED)) - continue; - - if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED)) - fib = rib; - - if (rib->type != type) - continue; - if (rib->instance != instance) - continue; - if (rib->type == ZEBRA_ROUTE_CONNECT && (nexthop = rib->nexthop) && - nexthop->type == NEXTHOP_TYPE_IFINDEX) - { - if (nexthop->ifindex != ifindex) - continue; - if (rib->refcnt) - { - rib->refcnt--; - route_unlock_node (rn); - route_unlock_node (rn); - return 0; - } - same = rib; - break; - } - /* Make sure that the route found has the same gateway. */ - else - { - if (gate == NULL) - { - same = rib; - break; - } - for (ALL_NEXTHOPS_RO(rib->nexthop, nexthop, tnexthop, recursing)) - if (IPV6_ADDR_SAME (&nexthop->gate.ipv6, gate)) - { - same = rib; - break; - } - if (same) - break; - } - } - - /* If same type of route can't be found and this message is from - kernel. */ - if (! same) - { - if (fib && type == ZEBRA_ROUTE_KERNEL && - CHECK_FLAG(flags, ZEBRA_FLAG_SELFROUTE)) - { - if (IS_ZEBRA_DEBUG_RIB) - zlog_debug ("%u:%s/%d: rn %p, rib %p (type %d) was deleted " - "from kernel, adding", - vrf_id, inet_ntop (p->family, &p->prefix, buf1, INET6_ADDRSTRLEN), - p->prefixlen, rn, fib, fib->type); - if (allow_delete) - { - /* Unset flags. */ - for (nexthop = fib->nexthop; nexthop; nexthop = nexthop->next) - UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB); - - UNSET_FLAG (fib->flags, ZEBRA_FLAG_SELECTED); - } - else - { - /* This means someone else, other than Zebra, has deleted a Zebra - * route from the kernel. We will add it back */ - rib_install_kernel(rn, fib, 0); - } - } - else - { - if (IS_ZEBRA_DEBUG_KERNEL) - { - if (gate) - zlog_debug ("%s: vrf %u via %s ifindex %d type %d " - "doesn't exist in rib", - prefix2str (p, buf1, sizeof(buf1)), vrf_id, - inet_ntop (AF_INET6, gate, buf2, INET6_ADDRSTRLEN), - ifindex, - type); - else - zlog_debug ("%s: vrf %u ifindex %d type %d doesn't exist in rib", - prefix2str (p, buf1, sizeof(buf1)), vrf_id, - ifindex, - type); - } - route_unlock_node (rn); - return ZEBRA_ERR_RTNOEXIST; - } - } - - if (same) - rib_delnode (rn, same); - - route_unlock_node (rn); - return 0; -} - /* Schedule routes of a particular table (address-family) based on event. */ static void rib_update_table (struct route_table *table, rib_update_event_t event) diff --git a/zebra/zserv.c b/zebra/zserv.c index 73e84faca2..09992870a7 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -1293,9 +1293,10 @@ zread_ipv4_delete (struct zserv *client, u_short length, struct zebra_vrf *zvrf) int i; struct stream *s; struct zapi_ipv4 api; - struct in_addr nexthop, *nexthop_p; + struct in_addr nexthop; + union g_addr *nexthop_p; unsigned long ifindex; - struct prefix_ipv4 p; + struct prefix p; u_char nexthop_num; u_char nexthop_type; u_int32_t table_id; @@ -1316,7 +1317,7 @@ zread_ipv4_delete (struct zserv *client, u_short length, struct zebra_vrf *zvrf) memset (&p, 0, sizeof (struct prefix_ipv4)); p.family = AF_INET; p.prefixlen = stream_getc (s); - stream_get (&p.prefix, s, PSIZE (p.prefixlen)); + stream_get (&p.u.prefix4, s, PSIZE (p.prefixlen)); /* Nexthop, ifindex, distance, metric. */ if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) @@ -1334,11 +1335,11 @@ zread_ipv4_delete (struct zserv *client, u_short length, struct zebra_vrf *zvrf) break; case ZEBRA_NEXTHOP_IPV4: nexthop.s_addr = stream_get_ipv4 (s); - nexthop_p = &nexthop; + nexthop_p = (union g_addr *)&nexthop; break; case ZEBRA_NEXTHOP_IPV4_IFINDEX: nexthop.s_addr = stream_get_ipv4 (s); - nexthop_p = &nexthop; + nexthop_p = (union g_addr *)&nexthop; ifindex = stream_getl (s); break; case ZEBRA_NEXTHOP_IPV6: @@ -1368,8 +1369,8 @@ zread_ipv4_delete (struct zserv *client, u_short length, struct zebra_vrf *zvrf) table_id = zvrf->table_id; - rib_delete_ipv4 (api.type, api.instance, api.flags, &p, nexthop_p, ifindex, - zvrf->vrf_id, table_id, api.safi); + rib_delete (AFI_IP, api.safi, zvrf->vrf_id, api.type, api.instance, + api.flags, &p, nexthop_p, ifindex, table_id); client->v4_route_del_cnt++; return 0; } @@ -1677,8 +1678,9 @@ zread_ipv6_delete (struct zserv *client, u_short length, struct zebra_vrf *zvrf) struct stream *s; struct zapi_ipv6 api; struct in6_addr nexthop; + union g_addr *pnexthop; unsigned long ifindex; - struct prefix_ipv6 p; + struct prefix p; s = client->ibuf; ifindex = 0; @@ -1695,7 +1697,7 @@ zread_ipv6_delete (struct zserv *client, u_short length, struct zebra_vrf *zvrf) memset (&p, 0, sizeof (struct prefix_ipv6)); p.family = AF_INET6; p.prefixlen = stream_getc (s); - stream_get (&p.prefix, s, PSIZE (p.prefixlen)); + stream_get (&p.u.prefix6, s, PSIZE (p.prefixlen)); /* Nexthop, ifindex, distance, metric. */ if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) @@ -1711,6 +1713,7 @@ zread_ipv6_delete (struct zserv *client, u_short length, struct zebra_vrf *zvrf) { case ZEBRA_NEXTHOP_IPV6: stream_get (&nexthop, s, 16); + pnexthop = (union g_addr *)&nexthop; break; case ZEBRA_NEXTHOP_IFINDEX: ifindex = stream_getl (s); @@ -1738,11 +1741,11 @@ zread_ipv6_delete (struct zserv *client, u_short length, struct zebra_vrf *zvrf) api.tag = 0; if (IN6_IS_ADDR_UNSPECIFIED (&nexthop)) - rib_delete_ipv6 (api.type, api.instance, api.flags, &p, NULL, ifindex, - zvrf->vrf_id, client->rtm_table, api.safi); + rib_delete (AFI_IP6, api.safi, zvrf->vrf_id, api.type, api.instance, + api.flags, &p, NULL, ifindex, client->rtm_table); else - rib_delete_ipv6 (api.type, api.instance, api.flags, &p, &nexthop, ifindex, - zvrf->vrf_id, client->rtm_table, api.safi); + rib_delete (AFI_IP6, api.safi, zvrf->vrf_id, api.type, api.instance, + api.flags, &p, pnexthop, ifindex, client->rtm_table); client->v6_route_del_cnt++; return 0; -- cgit v1.2.3 From 3b1098beed5c294746a9203b5de3c9da82c25d76 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 24 Aug 2016 02:20:47 -0400 Subject: zebra: Refactor rib_add_ipv[4|6] to a common function rib_add_ipv[4|6] both were essentially the same function combine and refactor everywhere. Signed-off-by: Donald Sharp --- zebra/connected.c | 33 +++++----- zebra/kernel_socket.c | 14 ++-- zebra/redistribute.c | 27 ++++---- zebra/rib.h | 9 +-- zebra/rt_netlink.c | 31 ++++----- zebra/rtread_getmsg.c | 32 ++++----- zebra/zebra_rib.c | 175 +++++++++++--------------------------------------- 7 files changed, 112 insertions(+), 209 deletions(-) (limited to 'zebra/zebra_rib.c') diff --git a/zebra/connected.c b/zebra/connected.c index e3cb12bcd0..2aa91ecd66 100644 --- a/zebra/connected.c +++ b/zebra/connected.c @@ -185,26 +185,28 @@ connected_update(struct interface *ifp, struct connected *ifc) void connected_up_ipv4 (struct interface *ifp, struct connected *ifc) { - struct prefix_ipv4 p; + struct prefix p; if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) return; - PREFIX_COPY_IPV4(&p, CONNECTED_PREFIX(ifc)); + PREFIX_COPY_IPV4((struct prefix_ipv4 *)&p, CONNECTED_PREFIX(ifc)); /* Apply mask to the network. */ - apply_mask_ipv4 (&p); + apply_mask (&p); /* In case of connected address is 0.0.0.0/0 we treat it tunnel address. */ - if (prefix_ipv4_any (&p)) + if (prefix_ipv4_any ((struct prefix_ipv4 *)&p)) return; - rib_add_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, NULL, ifp->ifindex, - ifp->vrf_id, RT_TABLE_MAIN, ifp->metric, 0, 0, SAFI_UNICAST); + rib_add (AFI_IP, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, + 0, 0, &p, NULL, NULL, ifp->ifindex, + RT_TABLE_MAIN, ifp->metric, 0, 0); - rib_add_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, NULL, ifp->ifindex, - ifp->vrf_id, RT_TABLE_MAIN, ifp->metric, 0, 0, SAFI_MULTICAST); + rib_add (AFI_IP, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, + 0, 0, &p, NULL, NULL, ifp->ifindex, + RT_TABLE_MAIN, ifp->metric, 0, 0); if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug ("%u: IF %s IPv4 address add/up, scheduling RIB processing", @@ -358,28 +360,28 @@ connected_delete_ipv4 (struct interface *ifp, int flags, struct in_addr *addr, rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE); } -#ifdef HAVE_IPV6 void connected_up_ipv6 (struct interface *ifp, struct connected *ifc) { - struct prefix_ipv6 p; + struct prefix p; if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) return; - PREFIX_COPY_IPV6(&p, CONNECTED_PREFIX(ifc)); + PREFIX_COPY_IPV6((struct prefix_ipv6 *)&p, CONNECTED_PREFIX(ifc)); /* Apply mask to the network. */ - apply_mask_ipv6 (&p); + apply_mask (&p); #ifndef LINUX /* XXX: It is already done by rib_bogus_ipv6 within rib_add_ipv6 */ - if (IN6_IS_ADDR_UNSPECIFIED (&p.prefix)) + if (IN6_IS_ADDR_UNSPECIFIED (&p.u.prefix6)) return; #endif - rib_add_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, ifp->vrf_id, - RT_TABLE_MAIN, ifp->metric, 0, 0, SAFI_UNICAST); + rib_add (AFI_IP6, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, + 0, 0, &p, NULL, NULL, ifp->ifindex, + RT_TABLE_MAIN, ifp->metric, 0, 0); if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug ("%u: IF %s IPv6 address down, scheduling RIB processing", @@ -502,7 +504,6 @@ connected_delete_ipv6 (struct interface *ifp, struct in6_addr *address, rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE); } -#endif /* HAVE_IPV6 */ int connected_is_unnumbered (struct interface *ifp) diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index ccc54ce81f..a500fabbfb 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -974,12 +974,11 @@ rtm_read (struct rt_msghdr *rtm) if (rtm->rtm_type == RTM_GET || rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_CHANGE) - rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, - (struct prefix_ipv4 *)&p, &gate.sin.sin_addr, NULL, 0, VRF_DEFAULT, - 0, 0, 0, 0, SAFI_UNICAST); + rib_add (AFI_IP, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL, 0, zebra_flags, + &p, &ggate, NULL, 0, 0, 0, 0, 0); else rib_delete (AFI_IP, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL, - 0, zebra_flags, &p, &&ggate, 0, 0); + 0, zebra_flags, &p, &ggate, 0, 0); } if (dest.sa.sa_family == AF_INET6) { @@ -1017,10 +1016,9 @@ rtm_read (struct rt_msghdr *rtm) if (rtm->rtm_type == RTM_GET || rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_CHANGE) - rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, - (struct prefix_ipv6 *)&p, &gate.sin6.sin6_addr, - ifindex, VRF_DEFAULT, - 0, 0, 0, 0, SAFI_UNICAST); + rib_add (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL, + 0, zebra_flags, &p, &ggate, NULL, ifindex, + 0, 0, 0, 0); else rib_delete (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, &ggate, ifindex, 0); diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 2eb4f257f5..776c3519be 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -550,9 +550,9 @@ int zebra_add_import_table_entry (struct route_node *rn, struct rib *rib, const char *rmap_name) { struct rib *newrib; - struct prefix_ipv4 p4; + struct prefix p; struct nexthop *nhop; - struct in_addr *gate; + union g_addr *gate; route_map_result_t ret = RMAP_MATCH; if (rmap_name) @@ -563,9 +563,9 @@ zebra_add_import_table_entry (struct route_node *rn, struct rib *rib, const char { if (rn->p.family == AF_INET) { - p4.family = AF_INET; - p4.prefixlen = rn->p.prefixlen; - p4.prefix = rn->p.u.prefix4; + p.family = AF_INET; + p.prefixlen = rn->p.prefixlen; + p.u.prefix4 = rn->p.u.prefix4; if (rib->nexthop_num == 1) { @@ -573,14 +573,13 @@ zebra_add_import_table_entry (struct route_node *rn, struct rib *rib, const char if (nhop->type == NEXTHOP_TYPE_IFINDEX) gate = NULL; else - gate = &nhop->gate.ipv4; - - rib_add_ipv4(ZEBRA_ROUTE_TABLE, rib->table, 0, &p4, - gate, &nhop->src.ipv4, - nhop->ifindex, rib->vrf_id, zebrad.rtm_table_default, - rib->metric, rib->mtu, - zebra_import_table_distance[AFI_IP][rib->table], - SAFI_UNICAST); + gate = (union g_addr *)&nhop->gate.ipv4; + + rib_add (AFI_IP, SAFI_UNICAST, rib->vrf_id, ZEBRA_ROUTE_TABLE, + rib->table, 0, &p, gate, (union g_addr *)&nhop->src.ipv4, + nhop->ifindex, zebrad.rtm_table_default, + rib->metric, rib->mtu, + zebra_import_table_distance[AFI_IP][rib->table]); } else if (rib->nexthop_num > 1) { @@ -599,7 +598,7 @@ zebra_add_import_table_entry (struct route_node *rn, struct rib *rib, const char for (nhop = rib->nexthop; nhop; nhop = nhop->next) rib_copy_nexthops(newrib, nhop); - rib_add_ipv4_multipath(&p4, newrib, SAFI_UNICAST); + rib_add_ipv4_multipath((struct prefix_ipv4 *)&p, newrib, SAFI_UNICAST); } } } diff --git a/zebra/rib.h b/zebra/rib.h index 8b70de7a03..e51e1277bf 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -338,10 +338,11 @@ extern int rib_uninstall_kernel (struct route_node *rn, struct rib *rib); /* NOTE: * All rib_add_ipv[46]* functions will not just add prefix into RIB, but * also implicitly withdraw equal prefix of same type. */ -extern int rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, - struct in_addr *gate, struct in_addr *src, - ifindex_t ifindex, vrf_id_t vrf_id, u_int32_t table_id, - u_int32_t, u_int32_t, u_char, safi_t); +extern int rib_add (afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, + u_short instance, int flags, struct prefix *p, + union g_addr *gate, union g_addr *src, + ifindex_t ifindex, u_int32_t table_id, + u_int32_t, u_int32_t, u_char); extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t); diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index dc3aa2f6bb..be291c0c9b 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -860,6 +860,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h, struct rtmsg *rtm; struct rtattr *tb[RTA_MAX + 1]; u_char flags = 0; + struct prefix p; char anyaddr[16] = { 0 }; @@ -952,14 +953,14 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h, if (rtm->rtm_family == AF_INET) { - struct prefix_ipv4 p; p.family = AF_INET; - memcpy (&p.prefix, dest, 4); + memcpy (&p.u.prefix4, dest, 4); p.prefixlen = rtm->rtm_dst_len; if (!tb[RTA_MULTIPATH]) - rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, flags, &p, gate, src, index, - vrf_id, table, metric, mtu, 0, SAFI_UNICAST); + rib_add (AFI_IP, SAFI_UNICAST, vrf_id, ZEBRA_ROUTE_KERNEL, + 0, flags, &p, gate, src, index, + table, metric, mtu, 0); else { /* This is a multipath route */ @@ -1016,21 +1017,19 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h, if (rib->nexthop_num == 0) XFREE (MTYPE_RIB, rib); else - rib_add_ipv4_multipath (&p, rib, SAFI_UNICAST); + rib_add_ipv4_multipath ((struct prefix_ipv4 *)&p, rib, SAFI_UNICAST); } } -#ifdef HAVE_IPV6 if (rtm->rtm_family == AF_INET6) { - struct prefix_ipv6 p; p.family = AF_INET6; - memcpy (&p.prefix, dest, 16); + memcpy (&p.u.prefix6, dest, 16); p.prefixlen = rtm->rtm_dst_len; - rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, flags, &p, gate, index, vrf_id, - table, metric, mtu, 0, SAFI_UNICAST); + rib_add (AFI_IP6, SAFI_UNICAST, vrf_id, ZEBRA_ROUTE_KERNEL, + 0, flags, &p, gate, src, index, + table, metric, mtu, 0); } -#endif /* HAVE_IPV6 */ return 0; } @@ -1193,8 +1192,9 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h, if (h->nlmsg_type == RTM_NEWROUTE) { if (!tb[RTA_MULTIPATH]) - rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, 0, (struct prefix_ipv4 *)&p, gate, src, index, vrf_id, - table, metric, mtu, 0, SAFI_UNICAST); + rib_add (AFI_IP, SAFI_UNICAST, vrf_id, ZEBRA_ROUTE_KERNEL, + 0, 0, &p, gate, src, index, + table, metric, mtu, 0); else { /* This is a multipath route */ @@ -1277,8 +1277,9 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h, } if (h->nlmsg_type == RTM_NEWROUTE) - rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, 0, (struct prefix_ipv6 *)&p, gate, index, vrf_id, - table, metric, mtu, 0, SAFI_UNICAST); + rib_add (AFI_IP6, SAFI_UNICAST, vrf_id, ZEBRA_ROUTE_KERNEL, + 0, 0, &p, gate, src, index, + table, metric, mtu, 0); else rib_delete (AFI_IP6, SAFI_UNICAST, vrf_id, ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, gate, index, table); diff --git a/zebra/rtread_getmsg.c b/zebra/rtread_getmsg.c index 9defa49bfd..0facc1a19f 100644 --- a/zebra/rtread_getmsg.c +++ b/zebra/rtread_getmsg.c @@ -70,28 +70,30 @@ static void handle_route_entry (mib2_ipRouteEntry_t *routeEntry) { - struct prefix_ipv4 prefix; - struct in_addr tmpaddr, gateway; - u_char zebra_flags = 0; + struct prefix prefix; + struct in_addr tmpaddr, gateway; + union g_addr *ggateway; + u_char zebra_flags = 0; - if (routeEntry->ipRouteInfo.re_ire_type & IRE_CACHETABLE) - return; + if (routeEntry->ipRouteInfo.re_ire_type & IRE_CACHETABLE) + return; - if (routeEntry->ipRouteInfo.re_ire_type & IRE_HOST_REDIRECT) - zebra_flags |= ZEBRA_FLAG_SELFROUTE; + if (routeEntry->ipRouteInfo.re_ire_type & IRE_HOST_REDIRECT) + zebra_flags |= ZEBRA_FLAG_SELFROUTE; - prefix.family = AF_INET; + prefix.family = AF_INET; - tmpaddr.s_addr = routeEntry->ipRouteDest; - prefix.prefix = tmpaddr; + tmpaddr.s_addr = routeEntry->ipRouteDest; + prefix.u.prefix4 = tmpaddr; - tmpaddr.s_addr = routeEntry->ipRouteMask; - prefix.prefixlen = ip_masklen (tmpaddr); + tmpaddr.s_addr = routeEntry->ipRouteMask; + prefix.prefixlen = ip_masklen (tmpaddr); - gateway.s_addr = routeEntry->ipRouteNextHop; + gateway.s_addr = routeEntry->ipRouteNextHop; + ggateway = (union g_addr *)&gateway; - rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &prefix, - &gateway, NULL, 0, VRF_DEFAULT, 0, 0, 0, 0, SAFI_UNICAST); + rib_add (AFI_IP, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL, 0, + zebra_flags, &prefix, ggateway, NULL, 0, 0, 0, 0, 0); } void diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 0dbbd47a45..17d59236f8 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -2354,124 +2354,6 @@ rib_delnode (struct route_node *rn, struct rib *rib) } } -int -rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, - struct in_addr *gate, struct in_addr *src, - ifindex_t ifindex, vrf_id_t vrf_id, u_int32_t table_id, - u_int32_t metric, u_int32_t mtu, u_char distance, safi_t safi) -{ - struct rib *rib; - struct rib *same = NULL; - struct route_table *table; - struct route_node *rn; - struct nexthop *nexthop; - - /* Lookup table. */ - table = zebra_vrf_table_with_table_id (AFI_IP, safi, vrf_id, table_id); - if (! table) - return 0; - - /* Make it sure prefixlen is applied to the prefix. */ - apply_mask_ipv4 (p); - - /* Set default distance by route type. */ - if (distance == 0) - { - if ((unsigned)type >= array_size(route_info)) - distance = 150; - else - distance = route_info[type].distance; - - /* iBGP distance is 200. */ - if (type == ZEBRA_ROUTE_BGP && CHECK_FLAG (flags, ZEBRA_FLAG_IBGP)) - distance = 200; - } - - /* Lookup route node.*/ - rn = route_node_get (table, (struct prefix *) p); - - /* If same type of route are installed, treat it as a implicit - withdraw. */ - RNODE_FOREACH_RIB (rn, rib) - { - if (CHECK_FLAG (rib->status, RIB_ENTRY_REMOVED)) - continue; - - if (rib->type != type) - continue; - if (rib->instance != instance) - continue; - - if (rib->type != ZEBRA_ROUTE_CONNECT) - { - same = rib; - break; - } - /* Duplicate connected route comes in. */ - else if ((nexthop = rib->nexthop) && - nexthop->type == NEXTHOP_TYPE_IFINDEX && - nexthop->ifindex == ifindex && - !CHECK_FLAG (rib->status, RIB_ENTRY_REMOVED)) - { - rib->refcnt++; - return 0 ; - } - } - - /* Allocate new rib structure. */ - rib = XCALLOC (MTYPE_RIB, sizeof (struct rib)); - rib->type = type; - rib->instance = instance; - rib->distance = distance; - rib->flags = flags; - rib->metric = metric; - rib->mtu = mtu; - rib->table = table_id; - rib->vrf_id = vrf_id; - rib->nexthop_num = 0; - rib->uptime = time (NULL); - - /* Nexthop settings. */ - if (gate) - { - if (ifindex) - rib_nexthop_ipv4_ifindex_add (rib, gate, src, ifindex); - else - rib_nexthop_ipv4_add (rib, gate, src); - } - else - 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) - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) - SET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB); - - /* Link new rib to node.*/ - if (IS_ZEBRA_DEBUG_RIB) - { - char buf[INET6_ADDRSTRLEN]; - if (IS_ZEBRA_DEBUG_RIB) - { - inet_ntop (p->family, &p->prefix, buf, INET6_ADDRSTRLEN); - zlog_debug ("%u:%s/%d: Inserting route rn %p, rib %p (type %d) " - "existing %p", - vrf_id, buf, p->prefixlen, (void *)rn, (void *)rib, rib->type, (void *)same); - } - - if (IS_ZEBRA_DEBUG_RIB_DETAILED) - rib_dump ((struct prefix *)p, rib); - } - rib_addnode (rn, rib, 1); - - /* Free implicit route.*/ - if (same) - rib_delnode (rn, same); - - route_unlock_node (rn); - return 0; -} - /* This function dumps the contents of a given RIB entry into * standard debug log. Calling function name and IP prefix in * question are passed as 1st and 2nd arguments. @@ -2854,10 +2736,11 @@ rib_delete (afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, u_short instance, int -rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, - struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, - u_int32_t table_id, u_int32_t metric, u_int32_t mtu, - u_char distance, safi_t safi) +rib_add (afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, + u_short instance, int flags, struct prefix *p, + union g_addr *gate, union g_addr *src, ifindex_t ifindex, + u_int32_t table_id, u_int32_t metric, u_int32_t mtu, + u_char distance) { struct rib *rib; struct rib *same = NULL; @@ -2866,22 +2749,28 @@ rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, struct nexthop *nexthop; /* Lookup table. */ - table = zebra_vrf_table_with_table_id (AFI_IP6, safi, vrf_id, table_id); + table = zebra_vrf_table_with_table_id (afi, safi, vrf_id, table_id); if (! table) return 0; /* Make sure mask is applied. */ - apply_mask_ipv6 (p); + apply_mask (p); /* Set default distance by route type. */ - if (!distance) - distance = route_info[type].distance; - - if (type == ZEBRA_ROUTE_BGP && CHECK_FLAG (flags, ZEBRA_FLAG_IBGP)) - distance = 200; + if (distance == 0) + { + if ((unsigned)type >= array_size(route_info)) + distance = 150; + else + distance = route_info[type].distance; + + /* iBGP distance is 200. */ + if (type == ZEBRA_ROUTE_BGP && CHECK_FLAG (flags, ZEBRA_FLAG_IBGP)) + distance = 200; + } /* Lookup route node.*/ - rn = route_node_get (table, (struct prefix *) p); + rn = route_node_get (table, p); /* If same type of route are installed, treat it as a implicit withdraw. */ @@ -2899,12 +2788,14 @@ rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, same = rib; break; } + /* Duplicate connected route comes in. */ else if ((nexthop = rib->nexthop) && nexthop->type == NEXTHOP_TYPE_IFINDEX && - nexthop->ifindex == ifindex) + nexthop->ifindex == ifindex && + !CHECK_FLAG (rib->status, RIB_ENTRY_REMOVED)) { rib->refcnt++; - return 0; + return 0 ; } } @@ -2925,10 +2816,20 @@ rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, /* Nexthop settings. */ if (gate) { - if (ifindex) - rib_nexthop_ipv6_ifindex_add (rib, gate, ifindex); + if (afi == AFI_IP6) + { + if (ifindex) + rib_nexthop_ipv6_ifindex_add (rib, &gate->ipv6, ifindex); + else + rib_nexthop_ipv6_add (rib, &gate->ipv6); + } else - rib_nexthop_ipv6_add (rib, gate); + { + if (ifindex) + rib_nexthop_ipv4_ifindex_add (rib, &gate->ipv4, &src->ipv4, ifindex); + else + rib_nexthop_ipv4_add (rib, &gate->ipv4, &src->ipv4); + } } else rib_nexthop_ifindex_add (rib, ifindex); @@ -2944,7 +2845,7 @@ rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, char buf[INET6_ADDRSTRLEN]; if (IS_ZEBRA_DEBUG_RIB) { - inet_ntop (p->family, &p->prefix, buf, INET6_ADDRSTRLEN); + inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN); zlog_debug ("%u:%s/%d: Inserting route rn %p, rib %p (type %d) " "existing %p", vrf_id, buf, p->prefixlen, (void *)rn, @@ -2952,7 +2853,7 @@ rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, } if (IS_ZEBRA_DEBUG_RIB_DETAILED) - rib_dump ((struct prefix *)p, rib); + rib_dump (p, rib); } rib_addnode (rn, rib, 1); -- cgit v1.2.3 From b4c034b0330e378b51a0e516d717b5fbfcfc083f Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 24 Aug 2016 04:01:20 -0400 Subject: zebra: refactor rib_add_ipv[4|6]_multipath The rib_add_ipv[4|6]_multipath functions are functionally equivalent. Refactor to 1 function. Signed-off-by: Donald Sharp --- zebra/connected.c | 2 +- zebra/redistribute.c | 2 +- zebra/rib.h | 15 ++---- zebra/rt_netlink.c | 4 +- zebra/zebra_rib.c | 135 ++++++--------------------------------------------- zebra/zserv.c | 22 ++++----- 6 files changed, 32 insertions(+), 148 deletions(-) (limited to 'zebra/zebra_rib.c') diff --git a/zebra/connected.c b/zebra/connected.c index 2aa91ecd66..6e82e6ec78 100644 --- a/zebra/connected.c +++ b/zebra/connected.c @@ -374,7 +374,7 @@ connected_up_ipv6 (struct interface *ifp, struct connected *ifc) apply_mask (&p); #ifndef LINUX - /* XXX: It is already done by rib_bogus_ipv6 within rib_add_ipv6 */ + /* XXX: It is already done by rib_bogus_ipv6 within rib_add */ if (IN6_IS_ADDR_UNSPECIFIED (&p.u.prefix6)) return; #endif diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 776c3519be..2864e0b8a5 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -598,7 +598,7 @@ zebra_add_import_table_entry (struct route_node *rn, struct rib *rib, const char for (nhop = rib->nexthop; nhop; nhop = nhop->next) rib_copy_nexthops(newrib, nhop); - rib_add_ipv4_multipath((struct prefix_ipv4 *)&p, newrib, SAFI_UNICAST); + rib_add_multipath(AFI_IP, SAFI_UNICAST, &p, newrib); } } } diff --git a/zebra/rib.h b/zebra/rib.h index e51e1277bf..0faa088d87 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -336,7 +336,7 @@ extern int rib_install_kernel (struct route_node *rn, struct rib *rib, int updat extern int rib_uninstall_kernel (struct route_node *rn, struct rib *rib); /* NOTE: - * All rib_add_ipv[46]* functions will not just add prefix into RIB, but + * All rib_add function will not just add prefix into RIB, but * also implicitly withdraw equal prefix of same type. */ extern int rib_add (afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, u_short instance, int flags, struct prefix *p, @@ -344,7 +344,8 @@ extern int rib_add (afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, ifindex_t ifindex, u_int32_t table_id, u_int32_t, u_int32_t, u_char); -extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t); +extern int rib_add_multipath (afi_t afi, safi_t safi, struct prefix *, + struct rib *); extern int rib_delete (afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, u_short instance, int flags, struct prefix *p, @@ -367,20 +368,10 @@ extern void rib_init (void); extern unsigned long rib_score_proto (u_char proto, u_short instance); extern void rib_queue_add (struct route_node *rn); -extern int -rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, - struct in6_addr *gate, ifindex_t ifindex, vrf_id_t vrf_id, - u_int32_t table_id, u_int32_t metric, u_int32_t mtu, - u_char distance, safi_t safi); - extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t); extern struct route_table *rib_table_ipv6; -extern int -rib_add_ipv6_multipath (struct prefix *, struct rib *, safi_t, - ifindex_t); - extern int rib_gc_dest (struct route_node *rn); extern struct route_table *rib_tables_iter_next (rib_tables_iter_t *iter); diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index be291c0c9b..826c59a729 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -1017,7 +1017,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h, if (rib->nexthop_num == 0) XFREE (MTYPE_RIB, rib); else - rib_add_ipv4_multipath ((struct prefix_ipv4 *)&p, rib, SAFI_UNICAST); + rib_add_multipath (AFI_IP, SAFI_UNICAST, &p, rib); } } if (rtm->rtm_family == AF_INET6) @@ -1252,7 +1252,7 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h, if (rib->nexthop_num == 0) XFREE (MTYPE_RIB, rib); else - rib_add_ipv4_multipath ((struct prefix_ipv4 *)&p, rib, SAFI_UNICAST); + rib_add_multipath (AFI_IP, SAFI_UNICAST, &p, rib); } } else diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 17d59236f8..23ec8dab9a 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -2517,21 +2517,31 @@ void rib_lookup_and_pushup (struct prefix_ipv4 * p, vrf_id_t vrf_id) } int -rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib, safi_t safi) +rib_add_multipath (afi_t afi, safi_t safi, struct prefix *p, + struct rib *rib) { struct route_table *table; struct route_node *rn; struct rib *same; struct nexthop *nexthop; int ret = 0; - + int family; + + if (!rib) + return 0; + + if (p->family == AF_INET) + family = AFI_IP; + else + family = AFI_IP6; + /* Lookup table. */ - table = zebra_vrf_table_with_table_id (AFI_IP, safi, rib->vrf_id, rib->table); + table = zebra_vrf_table_with_table_id (family, safi, rib->vrf_id, rib->table); if (! table) return 0; /* Make it sure prefixlen is applied to the prefix. */ - apply_mask_ipv4 (p); + apply_mask (p); /* Set default distance by route type. */ if (rib->distance == 0) @@ -2545,7 +2555,7 @@ rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib, safi_t safi) } /* Lookup route node.*/ - rn = route_node_get (table, (struct prefix *) p); + rn = route_node_get (table, p); /* If same type of route are installed, treat it as a implicit withdraw. */ @@ -2571,7 +2581,7 @@ rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib, safi_t safi) char buf[INET6_ADDRSTRLEN]; if (IS_ZEBRA_DEBUG_RIB) { - inet_ntop (p->family, &p->prefix, buf, INET6_ADDRSTRLEN); + inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN); zlog_debug ("%u:%s/%d: Inserting route rn %p, rib %p (type %d) " "existing %p", rib->vrf_id, buf, p->prefixlen, (void *)rn, @@ -2865,119 +2875,6 @@ rib_add (afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, return 0; } -int -rib_add_ipv6_multipath (struct prefix *p, struct rib *rib, safi_t safi, - ifindex_t ifindex) -{ - struct route_table *table; - struct route_node *rn; - struct rib *same = NULL; - struct nexthop *nexthop; - int ret = 0; - int family; - - if (!rib) - return 0; - - if (p->family == AF_INET) - family = AFI_IP; - else - family = AFI_IP6; - - /* Lookup table. */ - table = zebra_vrf_table_with_table_id (family, safi, rib->vrf_id, rib->table); - if (! table) - return 0; - - if (p->family == AF_INET) - { - /* Make it sure prefixlen is applied to the prefix. */ - apply_mask_ipv4 ((struct prefix_ipv4 *)p); - } - else - { - /* Make sure mask is applied. */ - apply_mask_ipv6 ((struct prefix_ipv6 *)p); - } - - /* Set default distance by route type. */ - if (rib->distance == 0) - { - rib->distance = route_info[rib->type].distance; - - /* iBGP distance is 200. */ - if (rib->type == ZEBRA_ROUTE_BGP - && CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP)) - rib->distance = 200; - } - - /* Lookup route node.*/ - rn = route_node_get (table, (struct prefix *) p); - - /* If same type of route are installed, treat it as a implicit - withdraw. */ - RNODE_FOREACH_RIB (rn, same) { - if (CHECK_FLAG (same->status, RIB_ENTRY_REMOVED)) { - continue; - } - if (same->type != rib->type) { - continue; - } - - if (same->instance != rib->instance) { - continue; - } - - if (same->table != rib->table) { - continue; - } - if (same->type != ZEBRA_ROUTE_CONNECT) { - break; - } - else if ((nexthop = same->nexthop) && - nexthop->type == NEXTHOP_TYPE_IFINDEX && - nexthop->ifindex == ifindex) { - same->refcnt++; - return 0; - } - } - - /* If this route is kernel route, set FIB flag to the route. */ - if (rib->type == ZEBRA_ROUTE_KERNEL || rib->type == ZEBRA_ROUTE_CONNECT) { - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) { - SET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB); - } - } - - /* Link new rib to node.*/ - if (IS_ZEBRA_DEBUG_RIB) - { - char buf[INET6_ADDRSTRLEN]; - if (IS_ZEBRA_DEBUG_RIB) - { - inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN); - zlog_debug ("%u:%s/%d: Inserting route rn %p, rib %p (type %d) " - "existing %p", - rib->vrf_id, buf, p->prefixlen, rn, rib, rib->type, same); - } - - if (IS_ZEBRA_DEBUG_RIB_DETAILED) - rib_dump ((struct prefix *)p, rib); - } - rib_addnode (rn, rib, 1); - ret = 1; - - /* Free implicit route.*/ - if (same) - { - rib_delnode (rn, same); - ret = -1; - } - - route_unlock_node (rn); - return ret; -} - /* Schedule routes of a particular table (address-family) based on event. */ static void rib_update_table (struct route_table *table, rib_update_event_t event) diff --git a/zebra/zserv.c b/zebra/zserv.c index 09992870a7..e72683afd1 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -1186,7 +1186,7 @@ zread_ipv4_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf) { int i; struct rib *rib; - struct prefix_ipv4 p; + struct prefix p; u_char message; struct in_addr nexthop; u_char nexthop_num; @@ -1214,7 +1214,7 @@ zread_ipv4_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf) memset (&p, 0, sizeof (struct prefix_ipv4)); p.family = AF_INET; p.prefixlen = stream_getc (s); - stream_get (&p.prefix, s, PSIZE (p.prefixlen)); + stream_get (&p.u.prefix4, s, PSIZE (p.prefixlen)); /* VRF ID */ rib->vrf_id = zvrf->vrf_id; @@ -1276,7 +1276,7 @@ zread_ipv4_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf) /* Table */ rib->table = zvrf->table_id; - ret = rib_add_ipv4_multipath (&p, rib, safi); + ret = rib_add_multipath (AFI_IP, safi, &p, rib); /* Stats */ if (ret > 0) @@ -1427,8 +1427,7 @@ zread_ipv4_route_ipv6_nexthop_add (struct zserv *client, u_short length, struct u_char message; u_char nexthop_num; u_char nexthop_type; - unsigned long ifindex; - struct prefix_ipv4 p; + struct prefix p; safi_t safi; static struct in6_addr nexthops[MULTIPATH_NUM]; static unsigned int ifindices[MULTIPATH_NUM]; @@ -1437,7 +1436,6 @@ zread_ipv4_route_ipv6_nexthop_add (struct zserv *client, u_short length, struct /* Get input stream. */ s = client->ibuf; - ifindex = 0; memset (&nexthop, 0, sizeof (struct in6_addr)); /* Allocate new rib. */ @@ -1455,7 +1453,7 @@ zread_ipv4_route_ipv6_nexthop_add (struct zserv *client, u_short length, struct memset (&p, 0, sizeof (struct prefix_ipv4)); p.family = AF_INET; p.prefixlen = stream_getc (s); - stream_get (&p.prefix, s, PSIZE (p.prefixlen)); + stream_get (&p.u.prefix4, s, PSIZE (p.prefixlen)); /* VRF ID */ rib->vrf_id = zvrf->vrf_id; @@ -1536,7 +1534,7 @@ zread_ipv4_route_ipv6_nexthop_add (struct zserv *client, u_short length, struct /* Table */ rib->table = zvrf->table_id; - ret = rib_add_ipv6_multipath ((struct prefix *)&p, rib, safi, ifindex); + ret = rib_add_multipath (AFI_IP6, safi, &p, rib); /* Stats */ if (ret > 0) client->v4_route_add_cnt++; @@ -1556,8 +1554,7 @@ zread_ipv6_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf) u_char message; u_char nexthop_num; u_char nexthop_type; - unsigned long ifindex; - struct prefix_ipv6 p; + struct prefix p; safi_t safi; static struct in6_addr nexthops[MULTIPATH_NUM]; static unsigned int ifindices[MULTIPATH_NUM]; @@ -1566,7 +1563,6 @@ zread_ipv6_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf) /* Get input stream. */ s = client->ibuf; - ifindex = 0; memset (&nexthop, 0, sizeof (struct in6_addr)); /* Allocate new rib. */ @@ -1584,7 +1580,7 @@ zread_ipv6_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf) memset (&p, 0, sizeof (struct prefix_ipv6)); p.family = AF_INET6; p.prefixlen = stream_getc (s); - stream_get (&p.prefix, s, PSIZE (p.prefixlen)); + stream_get (&p.u.prefix6, s, PSIZE (p.prefixlen)); /* We need to give nh-addr, nh-ifindex with the same next-hop object * to the rib to ensure that IPv6 multipathing works; need to coalesce @@ -1660,7 +1656,7 @@ zread_ipv6_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf) rib->vrf_id = zvrf->vrf_id; rib->table = zvrf->table_id; - ret = rib_add_ipv6_multipath ((struct prefix *)&p, rib, safi, ifindex); + ret = rib_add_multipath (AFI_IP, safi, &p, rib); /* Stats */ if (ret > 0) client->v6_route_add_cnt++; -- cgit v1.2.3 From bab85d4fcbc55577019bd746b9cc9073778721ce Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Wed, 24 Aug 2016 17:09:14 +0200 Subject: zebra: assorted parts of 0abf6796c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Author: Timo Teräs Date: Fri Jan 15 17:36:29 2016 +0200 zebra: atomic FIB updates This commit updates the kernel API so that route changes are atomically updated using change/replaces messages instead of first sending a withdraw followed with update. Same for zclient updates, changes are sent as single ADD instead of DELETE + ADD. Signed-off-by: Timo Teräs --- zebra/zebra_rib.c | 105 +++++++++++++++++++++++++----------------------------- 1 file changed, 49 insertions(+), 56 deletions(-) (limited to 'zebra/zebra_rib.c') diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 23ec8dab9a..3812101431 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -1574,6 +1574,48 @@ rib_process_update_route (struct zebra_vrf *zvrf, struct route_node *rn, UNSET_FLAG(select->status, RIB_ENTRY_CHANGED); } +/* Check if 'alternate' RIB entry is better than 'current'. */ +static struct rib * +rib_choose_best (struct rib *current, struct rib *alternate) +{ + if (current == NULL) + return alternate; + + /* filter route selection in following order: + * - connected beats other types + * - lower distance beats higher + * - lower metric beats higher for equal distance + * - last, hence oldest, route wins tie break. + */ + + /* Connected routes. Pick the last connected + * route of the set of lowest metric connected routes. + */ + if (alternate->type == ZEBRA_ROUTE_CONNECT) + { + if (current->type != ZEBRA_ROUTE_CONNECT + || alternate->metric <= current->metric) + return alternate; + + return current; + } + + if (current->type == ZEBRA_ROUTE_CONNECT) + return current; + + /* higher distance loses */ + if (alternate->distance < current->distance) + return alternate; + if (current->distance < alternate->distance) + return current; + + /* metric tie-breaks equal distance */ + if (alternate->metric <= current->metric) + return alternate; + + return current; +} + /* Core function for processing routing information base. */ static void rib_process (struct route_node *rn) @@ -1583,6 +1625,7 @@ rib_process (struct route_node *rn) struct rib *fib = NULL; struct rib *select = NULL; struct rib *del = NULL; + struct rib *best = NULL; char buf[INET6_ADDRSTRLEN]; rib_dest_t *dest; struct zebra_vrf *zvrf = NULL; @@ -1683,62 +1726,12 @@ rib_process (struct route_node *rn) continue; } - /* Newly selected rib, the common case. */ - if (!select) - { - select = rib; - continue; - } - - /* filter route selection in following order: - * - connected beats other types - * - lower distance beats higher - * - lower metric beats higher for equal distance - * - last, hence oldest, route wins tie break. - */ - - /* Connected routes. Pick the last connected - * route of the set of lowest metric connected routes. - */ - if (rib->type == ZEBRA_ROUTE_CONNECT) - { - if (select->type != ZEBRA_ROUTE_CONNECT - || rib->metric <= select->metric) - { - UNSET_FLAG (select->status, RIB_ENTRY_CHANGED); - select = rib; - } - else - UNSET_FLAG (rib->status, RIB_ENTRY_CHANGED); - continue; - } - else if (select->type == ZEBRA_ROUTE_CONNECT) - { - UNSET_FLAG (rib->status, RIB_ENTRY_CHANGED); - continue; - } - - /* higher distance loses */ - if (rib->distance > select->distance) - { - UNSET_FLAG (rib->status, RIB_ENTRY_CHANGED); - continue; - } - - /* lower wins */ - if (rib->distance < select->distance) - { - UNSET_FLAG (select->status, RIB_ENTRY_CHANGED); - select = rib; - continue; - } - - /* metric tie-breaks equal distance */ - if (rib->metric <= select->metric) - { - UNSET_FLAG (select->status, RIB_ENTRY_CHANGED); - select = rib; - } + best = rib_choose_best(select, rib); + if (select && best != select) + UNSET_FLAG (select->status, RIB_ENTRY_CHANGED); + if (best != rib) + UNSET_FLAG (rib->status, RIB_ENTRY_CHANGED); + select = best; } /* RNODE_FOREACH_RIB_SAFE */ /* After the cycle is finished, the following pointers will be set: -- cgit v1.2.3