diff options
Diffstat (limited to 'zebra')
55 files changed, 1798 insertions, 1156 deletions
diff --git a/zebra/connected.c b/zebra/connected.c index e28ec8d09b..94b56c8971 100644 --- a/zebra/connected.c +++ b/zebra/connected.c @@ -73,7 +73,8 @@ static void connected_announce(struct interface *ifp, struct connected *ifc) if (!ifc) return; - if (!if_is_loopback(ifp) && ifc->address->family == AF_INET) { + if (!if_is_loopback(ifp) && ifc->address->family == AF_INET && + !IS_ZEBRA_IF_VRF(ifp)) { if (ifc->address->prefixlen == 32) SET_FLAG(ifc->flags, ZEBRA_IFA_UNNUMBERED); else @@ -249,9 +250,10 @@ void connected_up(struct interface *ifp, struct connected *ifc) if (IS_ZEBRA_DEBUG_RIB_DETAILED) { char buf[PREFIX_STRLEN]; - zlog_debug("%u: IF %s address %s add/up, scheduling RIB processing", - ifp->vrf_id, ifp->name, - prefix2str(&p, buf, sizeof(buf))); + zlog_debug( + "%u: IF %s address %s add/up, scheduling RIB processing", + ifp->vrf_id, ifp->name, + prefix2str(&p, buf, sizeof(buf))); } rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE); @@ -260,9 +262,10 @@ void connected_up(struct interface *ifp, struct connected *ifc) if (IS_ZEBRA_DEBUG_MPLS) { char buf[PREFIX_STRLEN]; - zlog_debug("%u: IF %s IP %s address add/up, scheduling MPLS processing", - ifp->vrf_id, ifp->name, - prefix2str(&p, buf, sizeof(buf))); + zlog_debug( + "%u: IF %s IP %s address add/up, scheduling MPLS processing", + ifp->vrf_id, ifp->name, + prefix2str(&p, buf, sizeof(buf))); } mpls_mark_lsps_for_processing(vrf_info_lookup(ifp->vrf_id)); } @@ -402,15 +405,16 @@ void connected_down(struct interface *ifp, struct connected *ifc) rib_delete(afi, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, &nh, 0, 0, false, NULL); - rib_delete(afi, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, - 0, &p, NULL, &nh, 0, 0, false, NULL); + rib_delete(afi, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0, + &p, NULL, &nh, 0, 0, false, NULL); if (IS_ZEBRA_DEBUG_RIB_DETAILED) { char buf[PREFIX_STRLEN]; - zlog_debug("%u: IF %s IP %s address down, scheduling RIB processing", - ifp->vrf_id, ifp->name, - prefix2str(&p, buf, sizeof(buf))); + zlog_debug( + "%u: IF %s IP %s address down, scheduling RIB processing", + ifp->vrf_id, ifp->name, + prefix2str(&p, buf, sizeof(buf))); } rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE); @@ -420,9 +424,10 @@ void connected_down(struct interface *ifp, struct connected *ifc) if (IS_ZEBRA_DEBUG_MPLS) { char buf[PREFIX_STRLEN]; - zlog_debug("%u: IF %s IP %s address down, scheduling MPLS processing", - ifp->vrf_id, ifp->name, - prefix2str(&p, buf, sizeof(buf))); + zlog_debug( + "%u: IF %s IP %s address down, scheduling MPLS processing", + ifp->vrf_id, ifp->name, + prefix2str(&p, buf, sizeof(buf))); } mpls_mark_lsps_for_processing(vrf_info_lookup(ifp->vrf_id)); } @@ -441,9 +446,10 @@ static void connected_delete_helper(struct connected *ifc, struct prefix *p) if (IS_ZEBRA_DEBUG_RIB_DETAILED) { char buf[PREFIX_STRLEN]; - zlog_debug("%u: IF %s IP %s address del, scheduling RIB processing", - ifp->vrf_id, ifp->name, - prefix2str(p, buf, sizeof(buf))); + zlog_debug( + "%u: IF %s IP %s address del, scheduling RIB processing", + ifp->vrf_id, ifp->name, + prefix2str(p, buf, sizeof(buf))); } rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE); @@ -452,9 +458,10 @@ static void connected_delete_helper(struct connected *ifc, struct prefix *p) if (IS_ZEBRA_DEBUG_MPLS) { char buf[PREFIX_STRLEN]; - zlog_debug("%u: IF %s IP %s address delete, scheduling MPLS processing", - ifp->vrf_id, ifp->name, - prefix2str(p, buf, sizeof(buf))); + zlog_debug( + "%u: IF %s IP %s address delete, scheduling MPLS processing", + ifp->vrf_id, ifp->name, + prefix2str(p, buf, sizeof(buf))); } mpls_mark_lsps_for_processing(vrf_info_lookup(ifp->vrf_id)); } diff --git a/zebra/debug.c b/zebra/debug.c index 1df547a023..14b36cb5fb 100644 --- a/zebra/debug.c +++ b/zebra/debug.c @@ -212,13 +212,15 @@ DEFUN (debug_zebra_kernel_msgdump, SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV); if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND) - UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND); + UNSET_FLAG(zebra_debug_kernel, + ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND); } else if (argv_find(argv, argc, "send", &idx)) { SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND); if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV) - UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV); + UNSET_FLAG(zebra_debug_kernel, + ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV); } else { SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV); @@ -400,7 +402,8 @@ static int config_write_debug(struct vty *vty) } if (IS_ZEBRA_DEBUG_KERNEL) { - if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND && IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV) { + if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND + && IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV) { vty_out(vty, "debug zebra kernel msgdump\n"); write++; } else if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV) { diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index 639f70a6b4..bb0a0e052e 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -367,8 +367,8 @@ static int get_iflink_speed(struct interface *interface) /* use ioctl to get IP address of an interface */ if (zserv_privs.change(ZPRIVS_RAISE)) zlog_err("Can't raise privileges"); - sd = vrf_socket(PF_INET, SOCK_DGRAM, IPPROTO_IP, - interface->vrf_id, NULL); + sd = vrf_socket(PF_INET, SOCK_DGRAM, IPPROTO_IP, interface->vrf_id, + NULL); if (sd < 0) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("Failure to read interface %s speed: %d %s", @@ -649,8 +649,6 @@ static int netlink_interface(struct sockaddr_nl *snl, struct nlmsghdr *h, ifp = if_get_by_name(name, vrf_id, 0); set_ifindex(ifp, ifi->ifi_index, zns); ifp->flags = ifi->ifi_flags & 0x0000fffff; - if (IS_ZEBRA_IF_VRF(ifp)) - SET_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK); ifp->mtu6 = ifp->mtu = *(uint32_t *)RTA_DATA(tb[IFLA_MTU]); ifp->metric = 0; ifp->speed = get_iflink_speed(ifp); @@ -661,6 +659,8 @@ static int netlink_interface(struct sockaddr_nl *snl, struct nlmsghdr *h, /* Set zebra interface type */ zebra_if_set_ziftype(ifp, zif_type, zif_slave_type); + if (IS_ZEBRA_IF_VRF(ifp)) + SET_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK); /* Update link. */ zebra_if_update_link(ifp, link_ifindex); @@ -856,14 +856,14 @@ int kernel_address_delete_ipv4(struct interface *ifp, struct connected *ifc) return netlink_address(RTM_DELADDR, AF_INET, ifp, ifc); } -int kernel_address_add_ipv6 (struct interface *ifp, struct connected *ifc) +int kernel_address_add_ipv6(struct interface *ifp, struct connected *ifc) { - return netlink_address (RTM_NEWADDR, AF_INET6, ifp, ifc); + return netlink_address(RTM_NEWADDR, AF_INET6, ifp, ifc); } -int kernel_address_delete_ipv6 (struct interface *ifp, struct connected *ifc) +int kernel_address_delete_ipv6(struct interface *ifp, struct connected *ifc) { - return netlink_address (RTM_DELADDR, AF_INET6, ifp, ifc); + return netlink_address(RTM_DELADDR, AF_INET6, ifp, ifc); } int netlink_interface_addr(struct sockaddr_nl *snl, struct nlmsghdr *h, @@ -1143,15 +1143,15 @@ int netlink_link_change(struct sockaddr_nl *snl, struct nlmsghdr *h, /* Update interface information. */ set_ifindex(ifp, ifi->ifi_index, zns); ifp->flags = ifi->ifi_flags & 0x0000fffff; - if (IS_ZEBRA_IF_VRF(ifp)) - SET_FLAG(ifp->status, - ZEBRA_INTERFACE_VRF_LOOPBACK); ifp->mtu6 = ifp->mtu = *(int *)RTA_DATA(tb[IFLA_MTU]); ifp->metric = 0; ifp->ptm_status = ZEBRA_PTM_STATUS_UNKNOWN; /* Set interface type */ zebra_if_set_ziftype(ifp, zif_type, zif_slave_type); + if (IS_ZEBRA_IF_VRF(ifp)) + SET_FLAG(ifp->status, + ZEBRA_INTERFACE_VRF_LOOPBACK); /* Update link. */ zebra_if_update_link(ifp, link_ifindex); diff --git a/zebra/interface.c b/zebra/interface.c index 7229b8818d..01283f9122 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -52,10 +52,10 @@ #define ZEBRA_PTM_SUPPORT -DEFINE_HOOK(zebra_if_extra_info, (struct vty *vty, struct interface *ifp), - (vty, ifp)) -DEFINE_HOOK(zebra_if_config_wr, (struct vty *vty, struct interface *ifp), - (vty, ifp)) +DEFINE_HOOK(zebra_if_extra_info, (struct vty * vty, struct interface *ifp), + (vty, ifp)) +DEFINE_HOOK(zebra_if_config_wr, (struct vty * vty, struct interface *ifp), + (vty, ifp)) static void if_down_del_nbr_connected(struct interface *ifp); @@ -71,8 +71,8 @@ static int if_zebra_speed_update(struct thread *thread) new_speed = kernel_get_speed(ifp); if (new_speed != ifp->speed) { zlog_info("%s: %s old speed: %u new speed: %u", - __PRETTY_FUNCTION__, ifp->name, - ifp->speed, new_speed); + __PRETTY_FUNCTION__, ifp->name, ifp->speed, + new_speed); ifp->speed = new_speed; if_add_update(ifp); } @@ -148,8 +148,8 @@ static int if_zebra_new_hook(struct interface *ifp) * of seconds and ask again. Hopefully it's all settled * down upon startup. */ - thread_add_timer(zebrad.master, if_zebra_speed_update, - ifp, 15, &zebra_if->speed_update); + thread_add_timer(zebrad.master, if_zebra_speed_update, ifp, 15, + &zebra_if->speed_update); return 0; } @@ -608,16 +608,14 @@ static void if_delete_connected(struct interface *ifp) if (!ifp->connected) return; - while ((node = (last ? last->next - : listhead(ifp->connected)))) { + while ((node = (last ? last->next : listhead(ifp->connected)))) { ifc = listgetdata(node); cp = *CONNECTED_PREFIX(ifc); apply_mask(&cp); if (cp.family == AF_INET - && (rn = route_node_lookup(zebra_if->ipv4_subnets, - &cp))) { + && (rn = route_node_lookup(zebra_if->ipv4_subnets, &cp))) { struct listnode *anode; struct listnode *next; struct listnode *first; @@ -1529,7 +1527,7 @@ DEFUN (show_interface_desc_vrf_all, struct vrf *vrf; RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) - if (!RB_EMPTY (if_name_head, &vrf->ifaces_by_name)) { + if (!RB_EMPTY(if_name_head, &vrf->ifaces_by_name)) { vty_out(vty, "\n\tVRF %u\n\n", vrf->vrf_id); if_show_description(vty, vrf->vrf_id); } diff --git a/zebra/interface.h b/zebra/interface.h index e13721448c..9f109fc05f 100644 --- a/zebra/interface.h +++ b/zebra/interface.h @@ -60,8 +60,6 @@ struct rtadvconf { Default: 0.33 * MaxRtrAdvInterval */ int MinRtrAdvInterval; /* This field is currently unused. */ - /* $FRR indent$ */ - /* clang-format off */ #define RTADV_MIN_RTR_ADV_INTERVAL (0.33 * RTADV_MAX_RTR_ADV_INTERVAL) /* Unsolicited Router Advertisements' interval timer. */ @@ -176,9 +174,8 @@ struct rtadvconf { #define BGP_RA_CONFIGURED (1<<0) /* BGP configured RA? */ #define VTY_RA_CONFIGURED (1<<1) /* Operator configured RA? */ #define VTY_RA_INTERVAL_CONFIGURED (1<<2) /* Operator configured RA interval */ - int - NumFastReXmitsRemain; /* Loaded first with number of fast - rexmits to do */ + int NumFastReXmitsRemain; /* Loaded first with number of fast + rexmits to do */ #define RTADV_FAST_REXMIT_PERIOD 1 /* 1 sec */ #define RTADV_NUM_FAST_REXMITS 4 /* Fast Rexmit RA 4 times on certain events */ @@ -277,10 +274,10 @@ struct zebra_if { struct thread *speed_update; }; -DECLARE_HOOK(zebra_if_extra_info, (struct vty *vty, struct interface *ifp), - (vty, ifp)) -DECLARE_HOOK(zebra_if_config_wr, (struct vty *vty, struct interface *ifp), - (vty, ifp)) +DECLARE_HOOK(zebra_if_extra_info, (struct vty * vty, struct interface *ifp), + (vty, ifp)) +DECLARE_HOOK(zebra_if_config_wr, (struct vty * vty, struct interface *ifp), + (vty, ifp)) static inline void zebra_if_set_ziftype(struct interface *ifp, zebra_iftype_t zif_type, diff --git a/zebra/ioctl.c b/zebra/ioctl.c index d07d37056e..a95d5d4e1b 100644 --- a/zebra/ioctl.c +++ b/zebra/ioctl.c @@ -501,14 +501,14 @@ struct in6_ifreq { int if_prefix_add_ipv6(struct interface *ifp, struct connected *ifc) { #ifdef HAVE_NETLINK - return kernel_address_add_ipv6 (ifp, ifc); + return kernel_address_add_ipv6(ifp, ifc); #endif /* HAVE_NETLINK */ } int if_prefix_delete_ipv6(struct interface *ifp, struct connected *ifc) { #ifdef HAVE_NETLINK - return kernel_address_delete_ipv6 (ifp, ifc); + return kernel_address_delete_ipv6(ifp, ifc); #endif /* HAVE_NETLINK */ } #else /* LINUX_IPV6 */ diff --git a/zebra/irdp_interface.c b/zebra/irdp_interface.c index 8234ed6bdd..2c10ce86a0 100644 --- a/zebra/irdp_interface.c +++ b/zebra/irdp_interface.c @@ -63,14 +63,14 @@ extern int irdp_sock; DEFINE_MTYPE_STATIC(ZEBRA, IRDP_IF, "IRDP interface data") -#define IRDP_CONFIGED \ - do { \ - if (!irdp) { \ - vty_out(vty, "Please Configure IRDP before using this command\n"); \ - return CMD_WARNING_CONFIG_FAILED; \ - } \ - } \ - while (0) +#define IRDP_CONFIGED \ + do { \ + if (!irdp) { \ + vty_out(vty, \ + "Please Configure IRDP before using this command\n"); \ + return CMD_WARNING_CONFIG_FAILED; \ + } \ + } while (0) static struct irdp_interface *irdp_if_get(struct interface *ifp) { diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c index 5567d53c3f..39e04480c6 100644 --- a/zebra/irdp_main.c +++ b/zebra/irdp_main.c @@ -353,9 +353,5 @@ static int irdp_module_init(void) return 0; } -FRR_MODULE_SETUP( - .name = "zebra_irdp", - .version = FRR_VERSION, - .description = "zebra IRDP module", - .init = irdp_module_init, -) +FRR_MODULE_SETUP(.name = "zebra_irdp", .version = FRR_VERSION, + .description = "zebra IRDP module", .init = irdp_module_init, ) diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index 0b3b6eed45..52b2692090 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -45,6 +45,7 @@ #include "zebra/kernel_netlink.h" #include "zebra/rt_netlink.h" #include "zebra/if_netlink.h" +#include "zebra/rule_netlink.h" #ifndef SO_RCVBUFFORCE #define SO_RCVBUFFORCE (33) @@ -85,6 +86,9 @@ static const struct message nlmsg_str[] = {{RTM_NEWROUTE, "RTM_NEWROUTE"}, {RTM_NEWNEIGH, "RTM_NEWNEIGH"}, {RTM_DELNEIGH, "RTM_DELNEIGH"}, {RTM_GETNEIGH, "RTM_GETNEIGH"}, + {RTM_NEWRULE, "RTM_NEWRULE"}, + {RTM_DELRULE, "RTM_DELRULE"}, + {RTM_GETRULE, "RTM_GETRULE"}, {0}}; static const struct message rtproto_str[] = { @@ -240,28 +244,24 @@ static int netlink_information_fetch(struct sockaddr_nl *snl, switch (h->nlmsg_type) { case RTM_NEWROUTE: return netlink_route_change(snl, h, ns_id, startup); - break; case RTM_DELROUTE: return netlink_route_change(snl, h, ns_id, startup); - break; case RTM_NEWLINK: return netlink_link_change(snl, h, ns_id, startup); - break; case RTM_DELLINK: return netlink_link_change(snl, h, ns_id, startup); - break; case RTM_NEWADDR: return netlink_interface_addr(snl, h, ns_id, startup); - break; case RTM_DELADDR: return netlink_interface_addr(snl, h, ns_id, startup); - break; case RTM_NEWNEIGH: return netlink_neigh_change(snl, h, ns_id); - break; case RTM_DELNEIGH: return netlink_neigh_change(snl, h, ns_id); - break; + case RTM_NEWRULE: + return netlink_rule_change(snl, h, ns_id, startup); + case RTM_DELRULE: + return netlink_rule_change(snl, h, ns_id, startup); default: if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("Unknown netlink nlmsg_type %d vrf %u\n", @@ -788,7 +788,8 @@ void kernel_init(struct zebra_ns *zns) /* Initialize netlink sockets */ groups = RTMGRP_LINK | RTMGRP_IPV4_ROUTE | RTMGRP_IPV4_IFADDR | RTMGRP_IPV6_ROUTE | RTMGRP_IPV6_IFADDR | RTMGRP_IPV4_MROUTE - | RTMGRP_NEIGH; + | RTMGRP_NEIGH + | RTNLGRP_IPV4_RULE | RTNLGRP_IPV6_RULE; snprintf(zns->netlink.name, sizeof(zns->netlink.name), "netlink-listen (NS %u)", zns->ns_id); diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 3b28a9b242..eba4270efe 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -1384,8 +1384,8 @@ static void routing_socket(struct zebra_ns *zns) if (zserv_privs.change(ZPRIVS_RAISE)) zlog_err("routing_socket: Can't raise privileges"); - routing_sock = ns_socket(AF_ROUTE, SOCK_RAW, - 0, (ns_id_t)zns->ns->ns_id); + routing_sock = + ns_socket(AF_ROUTE, SOCK_RAW, 0, (ns_id_t)zns->ns->ns_id); if (routing_sock < 0) { if (zserv_privs.change(ZPRIVS_LOWER)) diff --git a/zebra/main.c b/zebra/main.c index 749d509a86..00d853ea26 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -140,7 +140,7 @@ static void sigint(void) SET_FLAG(zvrf->flags, ZEBRA_VRF_RETAIN); } if (zebrad.lsp_process_q) - work_queue_free(zebrad.lsp_process_q); + work_queue_free_and_null(&zebrad.lsp_process_q); vrf_terminate(); ns_walk_func(zebra_ns_disabled); @@ -151,7 +151,7 @@ static void sigint(void) route_map_finish(); list_delete_and_null(&zebrad.client_list); - work_queue_free(zebrad.ribq); + work_queue_free_and_null(&zebrad.ribq); meta_queue_free(zebrad.mq); frr_fini(); @@ -208,8 +208,7 @@ int main(int argc, char **argv) #endif vrf_configure_backend(VRF_BACKEND_VRF_LITE); - logicalrouter_configure_backend( - LOGICALROUTER_BACKEND_NETNS); + logicalrouter_configure_backend(LOGICALROUTER_BACKEND_NETNS); frr_preinit(&zebra_di, argc, argv); @@ -289,7 +288,7 @@ int main(int argc, char **argv) case 'n': vrf_configure_backend(VRF_BACKEND_NETNS); logicalrouter_configure_backend( - LOGICALROUTER_BACKEND_OFF); + LOGICALROUTER_BACKEND_OFF); break; #endif /* HAVE_NETLINK */ #if defined(HANDLE_ZAPI_FUZZING) @@ -333,8 +332,8 @@ int main(int argc, char **argv) zebra_mpls_vty_init(); zebra_pw_vty_init(); - /* For debug purpose. */ - /* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */ +/* For debug purpose. */ +/* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */ #if defined(HANDLE_ZAPI_FUZZING) if (fuzzing) { diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 3c6a2a7daf..a7b2361ac6 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -519,7 +519,7 @@ int zebra_add_import_table_entry(struct route_node *rn, struct route_entry *re, afi = family2afi(rn->p.family); if (rmap_name) ret = zebra_import_table_route_map_check( - afi, re->type, &rn->p, re->nexthop, re->vrf_id, + afi, re->type, &rn->p, re->ng.nexthop, re->vrf_id, re->tag, rmap_name); if (ret != RMAP_MATCH) { @@ -533,8 +533,7 @@ int zebra_add_import_table_entry(struct route_node *rn, struct route_entry *re, if (CHECK_FLAG(same->status, ROUTE_ENTRY_REMOVED)) continue; - if (same->type == re->type - && same->instance == re->instance + if (same->type == re->type && same->instance == re->instance && same->table == re->table && same->type != ZEBRA_ROUTE_CONNECT) break; @@ -543,7 +542,7 @@ int zebra_add_import_table_entry(struct route_node *rn, struct route_entry *re, if (same) zebra_del_import_table_entry(rn, same); - newre = XCALLOC(MTYPE_RE,sizeof(struct route_entry)); + newre = XCALLOC(MTYPE_RE, sizeof(struct route_entry)); newre->type = ZEBRA_ROUTE_TABLE; newre->distance = zebra_import_table_distance[afi][re->table]; newre->flags = re->flags; @@ -553,7 +552,7 @@ int zebra_add_import_table_entry(struct route_node *rn, struct route_entry *re, newre->nexthop_num = 0; newre->uptime = time(NULL); newre->instance = re->table; - route_entry_copy_nexthops(newre, re->nexthop); + route_entry_copy_nexthops(newre, re->ng.nexthop); rib_add_multipath(afi, SAFI_UNICAST, &p, NULL, newre); @@ -568,8 +567,8 @@ int zebra_del_import_table_entry(struct route_node *rn, struct route_entry *re) afi = family2afi(rn->p.family); prefix_copy(&p, &rn->p); - rib_delete(afi, SAFI_UNICAST, re->vrf_id, ZEBRA_ROUTE_TABLE, - re->table, re->flags, &p, NULL, re->nexthop, + rib_delete(afi, SAFI_UNICAST, re->vrf_id, ZEBRA_ROUTE_TABLE, re->table, + re->flags, &p, NULL, re->ng.nexthop, zebrad.rtm_table_default, re->metric, false, NULL); return 0; @@ -664,19 +663,17 @@ int zebra_import_table_config(struct vty *vty) if (zebra_import_table_distance[afi][i] != ZEBRA_TABLE_DISTANCE_DEFAULT) { - vty_out(vty, - "%s import-table %d distance %d", + vty_out(vty, "%s import-table %d distance %d", afi_str[afi], i, zebra_import_table_distance[afi][i]); } else { - vty_out(vty, "%s import-table %d", - afi_str[afi], i); + vty_out(vty, "%s import-table %d", afi_str[afi], + i); } rmap_name = zebra_get_import_table_route_map(afi, i); if (rmap_name) - vty_out(vty, " route-map %s", - rmap_name); + vty_out(vty, " route-map %s", rmap_name); vty_out(vty, "\n"); write = 1; @@ -704,11 +701,9 @@ void zebra_import_table_rm_update() if (!rmap_name) return; - table = zebra_vrf_other_route_table(afi, - i, + table = zebra_vrf_other_route_table(afi, i, VRF_DEFAULT); - for (rn = route_top(table); rn; - rn = route_next(rn)) { + for (rn = route_top(table); rn; rn = route_next(rn)) { /* For each entry in the non-default * routing table, * add the entry in the main table @@ -730,8 +725,8 @@ void zebra_import_table_rm_update() && (rn->p.family == AF_INET)) || ((afi == AFI_IP6) && (rn->p.family == AF_INET6))) - zebra_add_import_table_entry( - rn, re, rmap_name); + zebra_add_import_table_entry(rn, re, + rmap_name); } } } diff --git a/zebra/rib.h b/zebra/rib.h index 9a5d88ed15..5dd444dce0 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -29,6 +29,7 @@ #include "table.h" #include "queue.h" #include "nexthop.h" +#include "nexthop_group.h" #include "vrf.h" #include "if.h" #include "mpls.h" @@ -43,7 +44,7 @@ struct route_entry { struct route_entry *prev; /* Nexthop structure */ - struct nexthop *nexthop; + struct nexthop_group ng; /* Tag */ route_tag_t tag; @@ -170,10 +171,10 @@ typedef struct rib_dest_t_ { (re) && ((next) = (re)->next, 1); (re) = (next)) #define RNODE_FOREACH_RE(rn, re) \ - RE_DEST_FOREACH_ROUTE(rib_dest_from_rnode(rn), re) + RE_DEST_FOREACH_ROUTE (rib_dest_from_rnode(rn), re) #define RNODE_FOREACH_RE_SAFE(rn, re, next) \ - RE_DEST_FOREACH_ROUTE_SAFE(rib_dest_from_rnode(rn), re, next) + RE_DEST_FOREACH_ROUTE_SAFE (rib_dest_from_rnode(rn), re, next) #if defined(HAVE_RTADV) /* Structure which hold status of router advertisement. */ @@ -444,8 +445,8 @@ DECLARE_HOOK(rib_update, (struct route_node * rn, const char *reason), extern void zebra_vty_init(void); -extern int static_config(struct vty *vty, struct zebra_vrf *zvrf, - afi_t afi, safi_t safi, const char *cmd); +extern int static_config(struct vty *vty, struct zebra_vrf *zvrf, afi_t afi, + safi_t safi, const char *cmd); extern pid_t pid; #endif /*_ZEBRA_RIB_H */ diff --git a/zebra/rt.h b/zebra/rt.h index 472f2d7a97..399f6e8453 100644 --- a/zebra/rt.h +++ b/zebra/rt.h @@ -69,17 +69,16 @@ extern void kernel_route_rib(struct route_node *rn, struct prefix *p, * so let's separate it out and allow the result to * be passed back up. */ -extern void kernel_route_rib_pass_fail(struct route_node *rn, - struct prefix *p, +extern void kernel_route_rib_pass_fail(struct route_node *rn, struct prefix *p, struct route_entry *re, enum southbound_results res); extern int kernel_address_add_ipv4(struct interface *, struct connected *); extern int kernel_address_delete_ipv4(struct interface *, struct connected *); -extern int kernel_address_add_ipv6 (struct interface *, struct connected *); -extern int kernel_address_delete_ipv6 (struct interface *, struct connected *); -extern int kernel_neigh_update(int cmd, int ifindex, uint32_t addr, - char *lla, int llalen, ns_id_t ns_id); +extern int kernel_address_add_ipv6(struct interface *, struct connected *); +extern int kernel_address_delete_ipv6(struct interface *, struct connected *); +extern int kernel_neigh_update(int cmd, int ifindex, uint32_t addr, char *lla, + int llalen, ns_id_t ns_id); extern int kernel_interface_set_master(struct interface *master, struct interface *slave); @@ -96,8 +95,7 @@ extern void kernel_del_lsp(zebra_lsp_t *lsp); * the install/failure to set/unset flags and to notify * as needed. */ -extern void kernel_lsp_pass_fail(zebra_lsp_t *lsp, - enum southbound_results res); +extern void kernel_lsp_pass_fail(zebra_lsp_t *lsp, enum southbound_results res); extern int mpls_kernel_init(void); diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index e26109badf..2b758c58d8 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -160,8 +160,8 @@ static inline int proto2zebra(int proto, int family) proto = ZEBRA_ROUTE_BGP; break; case RTPROT_OSPF: - proto = (family == AFI_IP) ? - ZEBRA_ROUTE_OSPF : ZEBRA_ROUTE_OSPF6; + proto = (family == AFI_IP) ? ZEBRA_ROUTE_OSPF + : ZEBRA_ROUTE_OSPF6; break; case RTPROT_ISIS: proto = ZEBRA_ROUTE_ISIS; @@ -340,8 +340,7 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, struct rtattr *mxrta[RTAX_MAX + 1]; memset(mxrta, 0, sizeof mxrta); - netlink_parse_rtattr(mxrta, RTAX_MAX, - RTA_DATA(tb[RTA_METRICS]), + netlink_parse_rtattr(mxrta, RTAX_MAX, RTA_DATA(tb[RTA_METRICS]), RTA_PAYLOAD(tb[RTA_METRICS])); if (mxrta[RTAX_MTU]) @@ -392,19 +391,20 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, */ if (proto == ZEBRA_ROUTE_KERNEL) { distance = (metric >> 24) & 0xFF; - metric = (metric & 0x00FFFFFF); + metric = (metric & 0x00FFFFFF); } if (IS_ZEBRA_DEBUG_KERNEL) { char buf[PREFIX_STRLEN]; char buf2[PREFIX_STRLEN]; - zlog_debug( - "%s %s%s%s vrf %u metric: %d Admin Distance: %d", nl_msg_type_to_str(h->nlmsg_type), - prefix2str(&p, buf, sizeof(buf)), - src_p.prefixlen ? " from " : "", - src_p.prefixlen ? prefix2str(&src_p, buf2, sizeof(buf2)) - : "", - vrf_id, metric, distance); + zlog_debug("%s %s%s%s vrf %u metric: %d Admin Distance: %d", + nl_msg_type_to_str(h->nlmsg_type), + prefix2str(&p, buf, sizeof(buf)), + src_p.prefixlen ? " from " : "", + src_p.prefixlen + ? prefix2str(&src_p, buf2, sizeof(buf2)) + : "", + vrf_id, metric, distance); } afi_t afi = AFI_IP; @@ -425,9 +425,10 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, if (index && !gate) nh.type = NEXTHOP_TYPE_IFINDEX; else if (index && gate) - nh.type = (afi == AFI_IP) - ? NEXTHOP_TYPE_IPV4_IFINDEX - : NEXTHOP_TYPE_IPV6_IFINDEX; + nh.type = + (afi == AFI_IP) + ? NEXTHOP_TYPE_IPV4_IFINDEX + : NEXTHOP_TYPE_IPV6_IFINDEX; else if (!index && gate) nh.type = (afi == AFI_IP) ? NEXTHOP_TYPE_IPV4 @@ -447,8 +448,7 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, memcpy(&nh.gate, gate, sz); if (index) { - ifp = if_lookup_by_index(index, - VRF_UNKNOWN); + ifp = if_lookup_by_index(index, VRF_UNKNOWN); if (ifp) nh_vrf_id = ifp->vrf_id; } @@ -553,8 +553,8 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, if (re->nexthop_num == 0) XFREE(MTYPE_RE, re); else - rib_add_multipath(afi, SAFI_UNICAST, &p, - NULL, re); + rib_add_multipath(afi, SAFI_UNICAST, &p, NULL, + re); } } else { if (!tb[RTA_MULTIPATH]) { @@ -585,15 +585,13 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, nh.ifindex = index; if (gate) memcpy(&nh.gate, gate, sz); - rib_delete(afi, SAFI_UNICAST, vrf_id, - proto, 0, flags, &p, NULL, &nh, - table, metric, true, NULL); + rib_delete(afi, SAFI_UNICAST, vrf_id, proto, 0, flags, + &p, NULL, &nh, table, metric, true, NULL); } else { /* XXX: need to compare the entire list of nexthops * here for NLM_F_APPEND stupidity */ - rib_delete(afi, SAFI_UNICAST, vrf_id, - proto, 0, flags, &p, NULL, NULL, - table, metric, true, NULL); + rib_delete(afi, SAFI_UNICAST, vrf_id, proto, 0, flags, + &p, NULL, NULL, table, metric, true, NULL); } } @@ -1400,11 +1398,10 @@ static int netlink_route_multipath(int cmd, struct prefix *p, /* Count overall nexthops so we can decide whether to use singlepath * or multipath case. */ nexthop_num = 0; - for (ALL_NEXTHOPS(re->nexthop, nexthop)) { + for (ALL_NEXTHOPS(re->ng, nexthop)) { if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) continue; - if (cmd == RTM_NEWROUTE - && !NEXTHOP_IS_ACTIVE(nexthop->flags)) + if (cmd == RTM_NEWROUTE && !NEXTHOP_IS_ACTIVE(nexthop->flags)) continue; if (cmd == RTM_DELROUTE && !CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)) @@ -1416,7 +1413,7 @@ static int netlink_route_multipath(int cmd, struct prefix *p, /* Singlepath case. */ if (nexthop_num == 1 || multipath_num == 1) { nexthop_num = 0; - for (ALL_NEXTHOPS(re->nexthop, nexthop)) { + for (ALL_NEXTHOPS(re->ng, nexthop)) { /* * So we want to cover 2 types of blackhole * routes here: @@ -1516,7 +1513,7 @@ static int netlink_route_multipath(int cmd, struct prefix *p, rtnh = RTA_DATA(rta); nexthop_num = 0; - for (ALL_NEXTHOPS(re->nexthop, nexthop)) { + for (ALL_NEXTHOPS(re->ng, nexthop)) { if (nexthop_num >= multipath_num) break; @@ -1687,15 +1684,14 @@ void kernel_route_rib(struct route_node *rn, struct prefix *p, * screwed. */ if (old) - netlink_route_multipath(RTM_DELROUTE, p, - src_p, old, 0); - ret = netlink_route_multipath(RTM_NEWROUTE, p, - src_p, new, 0); + netlink_route_multipath(RTM_DELROUTE, p, src_p, + old, 0); + ret = netlink_route_multipath(RTM_NEWROUTE, p, src_p, + new, 0); } kernel_route_rib_pass_fail(rn, p, new, - (!ret) ? - SOUTHBOUND_INSTALL_SUCCESS : - SOUTHBOUND_INSTALL_FAILURE); + (!ret) ? SOUTHBOUND_INSTALL_SUCCESS + : SOUTHBOUND_INSTALL_FAILURE); return; } @@ -1703,9 +1699,8 @@ void kernel_route_rib(struct route_node *rn, struct prefix *p, ret = netlink_route_multipath(RTM_DELROUTE, p, src_p, old, 0); kernel_route_rib_pass_fail(rn, p, old, - (!ret) ? - SOUTHBOUND_DELETE_SUCCESS : - SOUTHBOUND_DELETE_FAILURE); + (!ret) ? SOUTHBOUND_DELETE_SUCCESS + : SOUTHBOUND_DELETE_FAILURE); } } @@ -2176,7 +2171,8 @@ static int netlink_ipneigh_change(struct sockaddr_nl *snl, struct nlmsghdr *h, nl_msg_type_to_str(h->nlmsg_type), nl_family_to_str(ndm->ndm_family), ifp->name, ndm->ndm_ifindex, - (unsigned long)RTA_PAYLOAD(tb[NDA_LLADDR])); + (unsigned long)RTA_PAYLOAD( + tb[NDA_LLADDR])); return 0; } diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c index b2baee5728..433faf789a 100644 --- a/zebra/rt_socket.c +++ b/zebra/rt_socket.c @@ -123,7 +123,7 @@ static int kernel_rtm_ipv4(int cmd, struct prefix *p, struct route_entry *re) #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ /* Make gateway. */ - for (ALL_NEXTHOPS(re->nexthop, nexthop)) { + for (ALL_NEXTHOPS(re->ng, nexthop)) { if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) continue; @@ -135,8 +135,7 @@ static int kernel_rtm_ipv4(int cmd, struct prefix *p, struct route_entry *re) * but this if statement seems overly cautious - what about * other than ADD and DELETE? */ - if ((cmd == RTM_ADD - && NEXTHOP_IS_ACTIVE(nexthop->flags)) + if ((cmd == RTM_ADD && NEXTHOP_IS_ACTIVE(nexthop->flags)) || (cmd == RTM_DELETE && CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB))) { if (nexthop->type == NEXTHOP_TYPE_IPV4 @@ -304,14 +303,13 @@ static int kernel_rtm_ipv6(int cmd, struct prefix *p, struct route_entry *re) #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ /* Make gateway. */ - for (ALL_NEXTHOPS(re->nexthop, nexthop)) { + for (ALL_NEXTHOPS(re->ng, nexthop)) { if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) continue; gate = 0; - if ((cmd == RTM_ADD - && NEXTHOP_IS_ACTIVE(nexthop->flags)) + if ((cmd == RTM_ADD && NEXTHOP_IS_ACTIVE(nexthop->flags)) || (cmd == RTM_DELETE)) { if (nexthop->type == NEXTHOP_TYPE_IPV6 || nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) { @@ -411,15 +409,15 @@ void kernel_route_rib(struct route_node *rn, struct prefix *p, zlog_err("Can't lower privileges"); if (new) { - kernel_route_rib_pass_fail(rn, p, new, - (!route) ? - SOUTHBOUND_INSTALL_SUCCESS : - SOUTHBOUND_INSTALL_FAILURE); + kernel_route_rib_pass_fail( + rn, p, new, + (!route) ? SOUTHBOUND_INSTALL_SUCCESS + : SOUTHBOUND_INSTALL_FAILURE); } else { kernel_route_rib_pass_fail(rn, p, old, - (!route) ? - SOUTHBOUND_DELETE_SUCCESS : - SOUTHBOUND_DELETE_FAILURE); + (!route) + ? SOUTHBOUND_DELETE_SUCCESS + : SOUTHBOUND_DELETE_FAILURE); } } diff --git a/zebra/rtadv.c b/zebra/rtadv.c index 860e8710d6..5eebca163b 100644 --- a/zebra/rtadv.c +++ b/zebra/rtadv.c @@ -842,9 +842,9 @@ void zebra_interface_radv_set(struct zserv *client, u_short length, SET_FLAG(zif->rtadv.ra_configured, BGP_RA_CONFIGURED); ipv6_nd_suppress_ra_set(ifp, RA_ENABLE); if (ra_interval - && (ra_interval * 1000) < zif->rtadv.MaxRtrAdvInterval - && !CHECK_FLAG(zif->rtadv.ra_configured, - VTY_RA_INTERVAL_CONFIGURED)) + && (ra_interval * 1000) < zif->rtadv.MaxRtrAdvInterval + && !CHECK_FLAG(zif->rtadv.ra_configured, + VTY_RA_INTERVAL_CONFIGURED)) zif->rtadv.MaxRtrAdvInterval = ra_interval * 1000; } else { UNSET_FLAG(zif->rtadv.ra_configured, BGP_RA_CONFIGURED); diff --git a/zebra/rtadv.h b/zebra/rtadv.h index 9ec1bffa8d..2cae6d06f9 100644 --- a/zebra/rtadv.h +++ b/zebra/rtadv.h @@ -103,8 +103,7 @@ typedef enum { extern void rtadv_init(struct zebra_ns *); extern void rtadv_terminate(struct zebra_ns *); extern void rtadv_cmd_init(void); -extern void zebra_interface_radv_set(struct zserv *client, - u_short length, struct zebra_vrf *zvrf, - int enable); +extern void zebra_interface_radv_set(struct zserv *client, u_short length, + struct zebra_vrf *zvrf, int enable); #endif /* _ZEBRA_RTADV_H */ diff --git a/zebra/rtread_getmsg.c b/zebra/rtread_getmsg.c index 95bc8db1c9..38321bc416 100644 --- a/zebra/rtread_getmsg.c +++ b/zebra/rtread_getmsg.c @@ -263,4 +263,8 @@ void neigh_read_for_vlan(struct zebra_ns *zns, struct interface *vlan_if) { } +void kernel_read_pbr_rules(struct zebra_ns *zns) +{ +} + #endif /* SUNOS_5 */ diff --git a/zebra/rtread_netlink.c b/zebra/rtread_netlink.c index ec29d1820e..e992046078 100644 --- a/zebra/rtread_netlink.c +++ b/zebra/rtread_netlink.c @@ -25,7 +25,9 @@ #include "vty.h" #include "zebra/rt.h" +#include "zebra/zebra_pbr.h" #include "zebra/rt_netlink.h" +#include "zebra/rule_netlink.h" void route_read(struct zebra_ns *zns) { @@ -53,4 +55,9 @@ void neigh_read_for_vlan(struct zebra_ns *zns, struct interface *vlan_if) netlink_neigh_read_for_vlan(zns, vlan_if); } +void kernel_read_pbr_rules(struct zebra_ns *zns) +{ + netlink_rules_read(zns); +} + #endif /* GNU_LINUX */ diff --git a/zebra/rtread_sysctl.c b/zebra/rtread_sysctl.c index 4f5a80612e..fba67e3d0c 100644 --- a/zebra/rtread_sysctl.c +++ b/zebra/rtread_sysctl.c @@ -30,6 +30,7 @@ #include "zebra/rt.h" #include "zebra/kernel_socket.h" +#include "zebra/zebra_pbr.h" /* Kernel routing table read up by sysctl function. */ void route_read(struct zebra_ns *zns) @@ -92,4 +93,8 @@ void neigh_read_for_vlan(struct zebra_ns *zns, struct interface *vlan_if) { } +void kernel_read_pbr_rules(struct zebra_ns *zns) +{ +} + #endif /* !defined(GNU_LINUX) && !defined(SUNOS_5) */ diff --git a/zebra/rule_netlink.c b/zebra/rule_netlink.c new file mode 100644 index 0000000000..2122f9f5fa --- /dev/null +++ b/zebra/rule_netlink.c @@ -0,0 +1,267 @@ +/* + * Zebra Policy Based Routing (PBR) interaction with the kernel using + * netlink. + * Copyright (C) 2018 Cumulus Networks, Inc. + * + * This file is part of FRR. + * + * FRR 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. + * + * FRR 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 FRR; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include <zebra.h> + +#ifdef HAVE_NETLINK + +#include "if.h" +#include "prefix.h" +#include "vrf.h" + +#include <linux/fib_rules.h> +#include "zebra/zserv.h" +#include "zebra/zebra_ns.h" +#include "zebra/zebra_vrf.h" +#include "zebra/rt.h" +#include "zebra/interface.h" +#include "zebra/debug.h" +#include "zebra/rtadv.h" +#include "zebra/kernel_netlink.h" +#include "zebra/rule_netlink.h" +#include "zebra/zebra_pbr.h" + +/* definitions */ + +/* static function declarations */ + +/* Private functions */ + +/* Install or uninstall specified rule for a specific interface. + * Form netlink message and ship it. Currently, notify status after + * waiting for netlink status. + */ +static int netlink_rule_update(int cmd, struct zebra_pbr_rule *rule) +{ + int family; + int bytelen; + struct { + struct nlmsghdr n; + struct fib_rule_hdr frh; + char buf[NL_PKT_BUF_SIZE]; + } req; + struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT); + struct sockaddr_nl snl; + char buf1[PREFIX_STRLEN]; + char buf2[PREFIX_STRLEN]; + + memset(&req, 0, sizeof(req) - NL_PKT_BUF_SIZE); + family = PREFIX_FAMILY(&rule->filter.src_ip); + bytelen = (family == AF_INET ? 4 : 16); + + req.n.nlmsg_type = cmd; + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); + req.n.nlmsg_flags = NLM_F_REQUEST; + req.n.nlmsg_pid = zns->netlink_cmd.snl.nl_pid; + + req.frh.family = family; + req.frh.action = FR_ACT_TO_TBL; + + if (cmd == RTM_NEWRULE) + req.n.nlmsg_flags |= NLM_F_CREATE | NLM_F_EXCL; + + /* rule's pref # */ + addattr32(&req.n, sizeof(req), FRA_PRIORITY, rule->priority); + + /* interface on which applied */ + if (rule->ifp) + addattr_l(&req.n, sizeof(req), FRA_IFNAME, rule->ifp->name, + strlen(rule->ifp->name) + 1); + + /* source IP, if specified */ + if (IS_RULE_FILTERING_ON_SRC_IP(rule)) { + req.frh.src_len = rule->filter.src_ip.prefixlen; + addattr_l(&req.n, sizeof(req), FRA_SRC, + &rule->filter.src_ip.u.prefix, bytelen); + } + /* destination IP, if specified */ + if (IS_RULE_FILTERING_ON_DST_IP(rule)) { + req.frh.dst_len = rule->filter.dst_ip.prefixlen; + addattr_l(&req.n, sizeof(req), FRA_DST, + &rule->filter.dst_ip.u.prefix, bytelen); + } + + /* Route table to use to forward, if filter criteria matches. */ + if (rule->action.table < 256) + req.frh.table = rule->action.table; + else { + req.frh.table = RT_TABLE_UNSPEC; + addattr32(&req.n, sizeof(req), FRA_TABLE, + rule->action.table); + } + + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "Tx %s family %s IF %s(%u) Pref %u Src %s Dst %s Table %u", + nl_msg_type_to_str(cmd), nl_family_to_str(family), + rule->ifp ? rule->ifp->name : "Unknown", + rule->ifp ? rule->ifp->ifindex : 0, rule->priority, + prefix2str(&rule->filter.src_ip, buf1, sizeof(buf1)), + prefix2str(&rule->filter.dst_ip, buf2, sizeof(buf2)), + rule->action.table); + + /* Ship off the message. + * Note: Currently, netlink_talk() is a blocking call which returns + * back the status. + */ + memset(&snl, 0, sizeof(snl)); + snl.nl_family = AF_NETLINK; + return netlink_talk(netlink_talk_filter, &req.n, + &zns->netlink_cmd, zns, 0); +} + + +/* Public functions */ +/* + * Install specified rule for a specific interface. The preference is what + * goes in the rule to denote relative ordering; it may or may not be the + * same as the rule's user-defined sequence number. + */ +void kernel_add_pbr_rule(struct zebra_pbr_rule *rule) +{ + int ret = 0; + + ret = netlink_rule_update(RTM_NEWRULE, rule); + kernel_pbr_rule_add_del_status(rule, + (!ret) ? SOUTHBOUND_INSTALL_SUCCESS + : SOUTHBOUND_INSTALL_FAILURE); +} + +/* + * Uninstall specified rule for a specific interface. + */ +void kernel_del_pbr_rule(struct zebra_pbr_rule *rule) +{ + int ret = 0; + + ret = netlink_rule_update(RTM_DELRULE, rule); + kernel_pbr_rule_add_del_status(rule, + (!ret) ? SOUTHBOUND_DELETE_SUCCESS + : SOUTHBOUND_DELETE_FAILURE); +} + +/* + * Handle netlink notification informing a rule add or delete. + * Handling of an ADD is TBD. + * DELs are notified up, if other attributes indicate it may be a + * notification of interest. The expectation is that if this corresponds + * to a PBR rule added by FRR, it will be readded. + */ +int netlink_rule_change(struct sockaddr_nl *snl, struct nlmsghdr *h, + ns_id_t ns_id, int startup) +{ + struct zebra_ns *zns; + struct fib_rule_hdr *frh; + struct rtattr *tb[FRA_MAX + 1]; + int len; + char *ifname; + struct zebra_pbr_rule rule; + char buf1[PREFIX_STRLEN]; + char buf2[PREFIX_STRLEN]; + + /* Basic validation followed by extracting attributes. */ + if (h->nlmsg_type != RTM_NEWRULE && h->nlmsg_type != RTM_DELRULE) + return 0; + + /* TBD */ + if (h->nlmsg_type == RTM_NEWRULE) + return 0; + + len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct fib_rule_hdr)); + if (len < 0) + return -1; + + frh = NLMSG_DATA(h); + if (frh->family != AF_INET && frh->family != AF_INET6) + return 0; + if (frh->action != FR_ACT_TO_TBL) + return 0; + + memset(tb, 0, sizeof(tb)); + netlink_parse_rtattr(tb, FRA_MAX, RTM_RTA(frh), len); + + /* TBD: We don't care about rules not specifying an IIF. */ + if (tb[FRA_IFNAME] == NULL) + return 0; + + /* If we don't know the interface, we don't care. */ + ifname = (char *)RTA_DATA(tb[FRA_IFNAME]); + zns = zebra_ns_lookup(ns_id); + rule.ifp = if_lookup_by_name_per_ns(zns, ifname); + if (!rule.ifp) + return 0; + + memset(&rule, 0, sizeof(rule)); + if (tb[FRA_PRIORITY]) + rule.priority = *(uint32_t *)RTA_DATA(tb[FRA_PRIORITY]); + + if (tb[FRA_SRC]) { + if (frh->family == AF_INET) + memcpy(&rule.filter.src_ip.u.prefix4, + RTA_DATA(tb[FRA_SRC]), 4); + else + memcpy(&rule.filter.src_ip.u.prefix6, + RTA_DATA(tb[FRA_SRC]), 16); + rule.filter.src_ip.prefixlen = frh->src_len; + rule.filter.filter_bm |= PBR_FILTER_SRC_IP; + } + + if (tb[FRA_DST]) { + if (frh->family == AF_INET) + memcpy(&rule.filter.dst_ip.u.prefix4, + RTA_DATA(tb[FRA_DST]), 4); + else + memcpy(&rule.filter.dst_ip.u.prefix6, + RTA_DATA(tb[FRA_DST]), 16); + rule.filter.dst_ip.prefixlen = frh->dst_len; + rule.filter.filter_bm |= PBR_FILTER_DST_IP; + } + + if (tb[FRA_TABLE]) + rule.action.table = *(uint32_t *)RTA_DATA(tb[FRA_TABLE]); + else + rule.action.table = frh->table; + + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "Rx %s family %s IF %s(%u) Pref %u Src %s Dst %s Table %u", + nl_msg_type_to_str(h->nlmsg_type), + nl_family_to_str(frh->family), rule.ifp->name, + rule.ifp->ifindex, rule.priority, + prefix2str(&rule.filter.src_ip, buf1, sizeof(buf1)), + prefix2str(&rule.filter.dst_ip, buf2, sizeof(buf2)), + rule.action.table); + + return kernel_pbr_rule_del(&rule); +} + +/* + * Get to know existing PBR rules in the kernel - typically called at startup. + * TBD. + */ +int netlink_rules_read(struct zebra_ns *zns) +{ + return 0; +} + +#endif /* HAVE_NETLINK */ diff --git a/zebra/rule_netlink.h b/zebra/rule_netlink.h new file mode 100644 index 0000000000..3a9b51309e --- /dev/null +++ b/zebra/rule_netlink.h @@ -0,0 +1,42 @@ +/* + * Zebra Policy Based Routing (PBR) interaction with the kernel using + * netlink - public definitions and function declarations. + * Copyright (C) 2018 Cumulus Networks, Inc. + * + * This file is part of FRR. + * + * FRR 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. + * + * FRR 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 FRR; 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_RULE_NETLINK_H +#define _ZEBRA_RULE_NETLINK_H + +#ifdef HAVE_NETLINK + +/* + * Handle netlink notification informing a rule add or delete. + */ +extern int netlink_rule_change(struct sockaddr_nl *snl, struct nlmsghdr *h, + ns_id_t ns_id, int startup); + +/* + * Get to know existing PBR rules in the kernel - typically called at startup. + */ +extern int netlink_rules_read(struct zebra_ns *zns); + +#endif /* HAVE_NETLINK */ + +#endif /* _ZEBRA_RULE_NETLINK_H */ diff --git a/zebra/rule_socket.c b/zebra/rule_socket.c new file mode 100644 index 0000000000..46c53f9e02 --- /dev/null +++ b/zebra/rule_socket.c @@ -0,0 +1,51 @@ +/* + * Zebra Policy Based Routing (PBR) interaction with the kernel using + * netlink. + * Copyright (C) 2018 Cumulus Networks, Inc. + * Donald Sharp + * + * This file is part of FRR. + * + * FRR 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. + * + * FRR 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 FRR; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include <zebra.h> + +#ifndef HAVE_NETLINK + +#include "if.h" +#include "prefix.h" +#include "vrf.h" + +#include "zebra/zserv.h" +#include "zebra/zebra_ns.h" +#include "zebra/zebra_vrf.h" +#include "zebra/rt.h" +#include "zebra/interface.h" +#include "zebra/debug.h" +#include "zebra/rtadv.h" +#include "zebra/kernel_netlink.h" +#include "zebra/rule_netlink.h" +#include "zebra/zebra_pbr.h" + +void kernel_add_pbr_rule(struct zebra_pbr_rule *rule) +{ +} +void kernel_del_pbr_rule(struct zebra_pbr_rule *rule) +{ +} + +#endif diff --git a/zebra/subdir.am b/zebra/subdir.am index bb7439c0f6..ef157b7539 100644 --- a/zebra/subdir.am +++ b/zebra/subdir.am @@ -45,6 +45,8 @@ zebra_zebra_SOURCES = \ zebra/rtread_getmsg.c \ zebra/rtread_netlink.c \ zebra/rtread_sysctl.c \ + zebra/rule_netlink.c \ + zebra/rule_socket.c \ zebra/zebra_l2.c \ zebra/zebra_memory.c \ zebra/zebra_mpls.c \ @@ -54,6 +56,7 @@ zebra_zebra_SOURCES = \ zebra/zebra_mpls_vty.c \ zebra/zebra_mroute.c \ zebra/zebra_ns.c \ + zebra/zebra_pbr.c \ zebra/zebra_ptm.c \ zebra/zebra_ptm_redistribute.c \ zebra/zebra_pw.c \ @@ -90,12 +93,14 @@ noinst_HEADERS += \ zebra/rt.h \ zebra/rt_netlink.h \ zebra/rtadv.h \ + zebra/rule_netlink.h \ zebra/zebra_fpm_private.h \ zebra/zebra_l2.h \ zebra/zebra_memory.h \ zebra/zebra_mpls.h \ zebra/zebra_mroute.h \ zebra/zebra_ns.h \ + zebra/zebra_pbr.h \ zebra/zebra_ptm.h \ zebra/zebra_ptm_redistribute.h \ zebra/zebra_pw.h \ diff --git a/zebra/zebra_fpm.c b/zebra/zebra_fpm.c index a6e0882ff8..9d3133f55b 100644 --- a/zebra/zebra_fpm.c +++ b/zebra/zebra_fpm.c @@ -719,8 +719,7 @@ static int zfpm_read_cb(struct thread *thread) sprintf(buffer, "closed socket in read(%d): %s", errno, safe_strerror(errno)); zfpm_connection_down(buffer); - } - else + } else zfpm_connection_down("closed socket in read"); return 0; } @@ -757,8 +756,7 @@ static int zfpm_read_cb(struct thread *thread) sprintf(buffer, "failed to read message(%d) %s", errno, safe_strerror(errno)); zfpm_connection_down(buffer); - } - else + } else zfpm_connection_down("failed to read message"); return 0; } @@ -1554,9 +1552,8 @@ static int fpm_remote_srv_write(struct vty *vty) in.s_addr = zfpm_g->fpm_server; if ((zfpm_g->fpm_server != FPM_DEFAULT_IP - && zfpm_g->fpm_server != INADDR_ANY) - || (zfpm_g->fpm_port != FPM_DEFAULT_PORT - && zfpm_g->fpm_port != 0)) + && zfpm_g->fpm_server != INADDR_ANY) + || (zfpm_g->fpm_port != FPM_DEFAULT_PORT && zfpm_g->fpm_port != 0)) vty_out(vty, "fpm connection ip %s port %d\n", inet_ntoa(in), zfpm_g->fpm_port); diff --git a/zebra/zebra_fpm_netlink.c b/zebra/zebra_fpm_netlink.c index 27c7891372..97a0e142fb 100644 --- a/zebra/zebra_fpm_netlink.c +++ b/zebra/zebra_fpm_netlink.c @@ -249,7 +249,7 @@ static int netlink_route_info_fill(netlink_route_info_t *ri, int cmd, ri->rtm_type = RTN_UNICAST; ri->metric = &re->metric; - for (ALL_NEXTHOPS(re->nexthop, nexthop)) { + for (ALL_NEXTHOPS(re->ng, nexthop)) { if (ri->num_nhs >= multipath_num) break; diff --git a/zebra/zebra_fpm_protobuf.c b/zebra/zebra_fpm_protobuf.c index b850f1fb1e..e661b6efc7 100644 --- a/zebra/zebra_fpm_protobuf.c +++ b/zebra/zebra_fpm_protobuf.c @@ -170,7 +170,7 @@ static Fpm__AddRoute *create_add_route_message(qpb_allocator_t *allocator, * Figure out the set of nexthops to be added to the message. */ num_nhs = 0; - for (ALL_NEXTHOPS(re->nexthop, nexthop)) { + for (ALL_NEXTHOPS(re->ng, nexthop)) { if (num_nhs >= multipath_num) break; diff --git a/zebra/zebra_l2.h b/zebra/zebra_l2.h index d9bbcfed6f..0d0c5aaf22 100644 --- a/zebra/zebra_l2.h +++ b/zebra/zebra_l2.h @@ -67,7 +67,6 @@ union zebra_l2if_info { #define IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif) ((zif)->l2info.br.vlan_aware == 1) - extern void zebra_l2_map_slave_to_bridge(struct zebra_l2info_brslave *br_slave); extern void zebra_l2_unmap_slave_from_bridge(struct zebra_l2info_brslave *br_slave); diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index ec80081a46..0af06806d3 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -182,7 +182,7 @@ static int lsp_install(struct zebra_vrf *zvrf, mpls_label_t label, * the label advertised by the recursive nexthop (plus we don't have the * logic yet to push multiple labels). */ - for (nexthop = re->nexthop; nexthop; nexthop = nexthop->next) { + for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) { /* Skip inactive and recursive entries. */ if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) continue; @@ -411,8 +411,8 @@ static int fec_change_update_lsp(struct zebra_vrf *zvrf, zebra_fec_t *fec, afi_t afi; /* Uninstall label forwarding entry, if previously installed. */ - if (old_label != MPLS_INVALID_LABEL && - old_label != MPLS_LABEL_IMPLICIT_NULL) + if (old_label != MPLS_INVALID_LABEL + && old_label != MPLS_LABEL_IMPLICIT_NULL) lsp_uninstall(zvrf, old_label); /* Install label forwarding entry corr. to new label, if needed. */ @@ -637,7 +637,7 @@ static int nhlfe_nexthop_active_ipv4(zebra_nhlfe_t *nhlfe, || !CHECK_FLAG(match->flags, ZEBRA_FLAG_SELECTED)) continue; - for (match_nh = match->nexthop; match_nh; + for (match_nh = match->ng.nexthop; match_nh; match_nh = match_nh->next) { if (match->type == ZEBRA_ROUTE_CONNECT || nexthop->ifindex == match_nh->ifindex) { @@ -688,10 +688,10 @@ static int nhlfe_nexthop_active_ipv6(zebra_nhlfe_t *nhlfe, break; } - if (!match || !match->nexthop) + if (!match || !match->ng.nexthop) return 0; - nexthop->ifindex = match->nexthop->ifindex; + nexthop->ifindex = match->ng.nexthop->ifindex; return 1; } @@ -937,16 +937,16 @@ static wq_item_status lsp_process(struct work_queue *wq, void *data) * Any NHLFE that was installed but is not * selected now needs to have its flags updated. */ - for (nhlfe = lsp->nhlfe_list; - nhlfe; nhlfe = nhlfe->next) { + for (nhlfe = lsp->nhlfe_list; nhlfe; + nhlfe = nhlfe->next) { nexthop = nhlfe->nexthop; if (!nexthop) continue; if (CHECK_FLAG(nhlfe->flags, - NHLFE_FLAG_INSTALLED) && - !CHECK_FLAG(nhlfe->flags, - NHLFE_FLAG_SELECTED)) { + NHLFE_FLAG_INSTALLED) + && !CHECK_FLAG(nhlfe->flags, + NHLFE_FLAG_SELECTED)) { UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED); UNSET_FLAG(nexthop->flags, @@ -1398,9 +1398,9 @@ static void nhlfe_print(zebra_nhlfe_t *nhlfe, struct vty *vty) default: break; } - vty_out(vty, "%s", CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED) - ? " (installed)" - : ""); + vty_out(vty, "%s", + CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED) ? " (installed)" + : ""); vty_out(vty, "\n"); } @@ -1688,8 +1688,7 @@ static int mpls_processq_init(struct zebra_t *zebra) /* Public functions */ -void kernel_lsp_pass_fail(zebra_lsp_t *lsp, - enum southbound_results res) +void kernel_lsp_pass_fail(zebra_lsp_t *lsp, enum southbound_results res) { struct nexthop *nexthop; zebra_nhlfe_t *nhlfe; @@ -2287,7 +2286,7 @@ int mpls_ftn_update(int add, struct zebra_vrf *zvrf, enum lsp_types_t type, if (re == NULL) return -1; - for (nexthop = re->nexthop; nexthop; nexthop = nexthop->next) { + for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) { switch (nexthop->type) { case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4_IFINDEX: @@ -2505,7 +2504,7 @@ void mpls_ldp_ftn_uninstall_all(struct zebra_vrf *zvrf, int afi) for (rn = route_top(table); rn; rn = route_next(rn)) { update = 0; RNODE_FOREACH_RE (rn, re) { - for (nexthop = re->nexthop; nexthop; + for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) { if (nexthop->nh_label_type != ZEBRA_LSP_LDP) continue; @@ -2793,8 +2792,7 @@ void zebra_mpls_print_lsp_table(struct vty *vty, struct zebra_vrf *zvrf, nexthop = nhlfe->nexthop; switch (nexthop->type) { - case NEXTHOP_TYPE_IFINDEX: - { + case NEXTHOP_TYPE_IFINDEX: { struct interface *ifp; ifp = if_lookup_by_index( @@ -2955,12 +2953,9 @@ void zebra_mpls_init_tables(struct zebra_vrf *zvrf) { if (!zvrf) return; - zvrf->slsp_table = hash_create(label_hash, - label_cmp, - "ZEBRA SLSP table"); - zvrf->lsp_table = hash_create(label_hash, - label_cmp, - "ZEBRA LSP table"); + zvrf->slsp_table = + hash_create(label_hash, label_cmp, "ZEBRA SLSP table"); + zvrf->lsp_table = hash_create(label_hash, label_cmp, "ZEBRA LSP table"); zvrf->fec_table[AFI_IP] = route_table_init(); zvrf->fec_table[AFI_IP6] = route_table_init(); zvrf->mpls_flags = 0; diff --git a/zebra/zebra_mpls_netlink.c b/zebra/zebra_mpls_netlink.c index 3c8d25189e..d7c231c37e 100644 --- a/zebra/zebra_mpls_netlink.c +++ b/zebra/zebra_mpls_netlink.c @@ -41,9 +41,8 @@ void kernel_add_lsp(zebra_lsp_t *lsp) ret = netlink_mpls_multipath(RTM_NEWROUTE, lsp); kernel_lsp_pass_fail(lsp, - (!ret) ? - SOUTHBOUND_INSTALL_SUCCESS : - SOUTHBOUND_INSTALL_FAILURE); + (!ret) ? SOUTHBOUND_INSTALL_SUCCESS + : SOUTHBOUND_INSTALL_FAILURE); } /* @@ -69,9 +68,8 @@ void kernel_upd_lsp(zebra_lsp_t *lsp) ret = netlink_mpls_multipath(RTM_NEWROUTE, lsp); kernel_lsp_pass_fail(lsp, - (!ret) ? - SOUTHBOUND_INSTALL_SUCCESS : - SOUTHBOUND_INSTALL_FAILURE); + (!ret) ? SOUTHBOUND_INSTALL_SUCCESS + : SOUTHBOUND_INSTALL_FAILURE); } /* @@ -82,23 +80,20 @@ void kernel_del_lsp(zebra_lsp_t *lsp) int ret; if (!lsp) { // unexpected - kernel_lsp_pass_fail(lsp, - SOUTHBOUND_DELETE_FAILURE); + kernel_lsp_pass_fail(lsp, SOUTHBOUND_DELETE_FAILURE); return; } if (!CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED)) { - kernel_lsp_pass_fail(lsp, - SOUTHBOUND_DELETE_FAILURE); + kernel_lsp_pass_fail(lsp, SOUTHBOUND_DELETE_FAILURE); return; } ret = netlink_mpls_multipath(RTM_DELROUTE, lsp); kernel_lsp_pass_fail(lsp, - (!ret) ? - SOUTHBOUND_DELETE_SUCCESS : - SOUTHBOUND_DELETE_FAILURE); + (!ret) ? SOUTHBOUND_DELETE_SUCCESS + : SOUTHBOUND_DELETE_FAILURE); } int mpls_kernel_init(void) diff --git a/zebra/zebra_mpls_openbsd.c b/zebra/zebra_mpls_openbsd.c index 2fc93893fa..2c7fe577ef 100644 --- a/zebra/zebra_mpls_openbsd.c +++ b/zebra/zebra_mpls_openbsd.c @@ -297,9 +297,8 @@ void kernel_add_lsp(zebra_lsp_t *lsp) ret = kernel_lsp_cmd(RTM_ADD, lsp); kernel_lsp_pass_fail(lsp, - (!ret) ? - SOUTHBOUND_INSTALL_SUCCESS : - SOUTHBOUND_INSTALL_FAILURE); + (!ret) ? SOUTHBOUND_INSTALL_SUCCESS + : SOUTHBOUND_INSTALL_FAILURE); } void kernel_upd_lsp(zebra_lsp_t *lsp) @@ -314,9 +313,8 @@ void kernel_upd_lsp(zebra_lsp_t *lsp) ret = kernel_lsp_cmd(RTM_CHANGE, lsp); kernel_lsp_pass_fail(lsp, - (!ret) ? - SOUTHBOUND_INSTALL_SUCCESS : - SOUTHBOUND_INSTALL_FAILURE); + (!ret) ? SOUTHBOUND_INSTALL_SUCCESS + : SOUTHBOUND_INSTALL_FAILURE); return; } @@ -325,23 +323,20 @@ void kernel_del_lsp(zebra_lsp_t *lsp) int ret; if (!lsp) { // unexpected - kernel_lsp_pass_fail(lsp, - SOUTHBOUND_DELETE_FAILURE); + kernel_lsp_pass_fail(lsp, SOUTHBOUND_DELETE_FAILURE); return; } if (!CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED)) { - kernel_lsp_pass_fail(lsp, - SOUTHBOUND_DELETE_FAILURE); + kernel_lsp_pass_fail(lsp, SOUTHBOUND_DELETE_FAILURE); return; } ret = kernel_lsp_cmd(RTM_DELETE, lsp); kernel_lsp_pass_fail(lsp, - (!ret) ? - SOUTHBOUND_DELETE_SUCCESS : - SOUTHBOUND_DELETE_FAILURE); + (!ret) ? SOUTHBOUND_DELETE_SUCCESS + : SOUTHBOUND_DELETE_FAILURE); } static int kmpw_install(struct zebra_pw *pw) diff --git a/zebra/zebra_netns_id.c b/zebra/zebra_netns_id.c index 966d6ed0d2..a81413f5a9 100644 --- a/zebra/zebra_netns_id.c +++ b/zebra/zebra_netns_id.c @@ -47,8 +47,8 @@ #define NETLINK_SOCKET_BUFFER_SIZE 512 #define NETLINK_ALIGNTO 4 -#define NETLINK_ALIGN(len) (((len)+NETLINK_ALIGNTO-1) \ - & ~(NETLINK_ALIGNTO-1)) +#define NETLINK_ALIGN(len) \ + (((len) + NETLINK_ALIGNTO - 1) & ~(NETLINK_ALIGNTO - 1)) #define NETLINK_NLATTR_LEN(_a, _b) (unsigned int)((char *)_a - (char *)_b) #endif /* defined(HAVE_NETLINK) */ @@ -77,36 +77,33 @@ static struct nlmsghdr *initiate_nlh(char *buf, unsigned int *seq, int type) return nlh; } -static int send_receive(int sock, struct nlmsghdr *nlh, - unsigned int seq, char *buf) +static int send_receive(int sock, struct nlmsghdr *nlh, unsigned int seq, + char *buf) { int ret; - static const struct sockaddr_nl snl = { - .nl_family = AF_NETLINK - }; + static const struct sockaddr_nl snl = {.nl_family = AF_NETLINK}; ret = sendto(sock, (const void *)nlh, (size_t)nlh->nlmsg_len, 0, - (struct sockaddr *) &snl, (socklen_t)sizeof(snl)); + (struct sockaddr *)&snl, (socklen_t)sizeof(snl)); if (ret < 0) { - zlog_err("netlink( %u) sendmsg() error: %s", - sock, safe_strerror(errno)); + zlog_err("netlink( %u) sendmsg() error: %s", sock, + safe_strerror(errno)); return -1; } /* reception */ struct sockaddr_nl addr; struct iovec iov = { - .iov_base = buf, - .iov_len = NETLINK_SOCKET_BUFFER_SIZE, + .iov_base = buf, .iov_len = NETLINK_SOCKET_BUFFER_SIZE, }; struct msghdr msg = { - .msg_name = &addr, - .msg_namelen = sizeof(struct sockaddr_nl), - .msg_iov = &iov, - .msg_iovlen = 1, - .msg_control = NULL, + .msg_name = &addr, + .msg_namelen = sizeof(struct sockaddr_nl), + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_control = NULL, .msg_controllen = 0, - .msg_flags = 0, + .msg_flags = 0, }; ret = recvmsg(sock, &msg, 0); if (ret < 0) { @@ -119,8 +116,9 @@ static int send_receive(int sock, struct nlmsghdr *nlh, } /* nlh already points to buf */ if (nlh->nlmsg_seq != seq) { - zlog_err("netlink recvmsg: bad sequence number %x (expected %x)", - seq, nlh->nlmsg_seq); + zlog_err( + "netlink recvmsg: bad sequence number %x (expected %x)", + seq, nlh->nlmsg_seq); return -1; } return ret; @@ -132,16 +130,16 @@ static int send_receive(int sock, struct nlmsghdr *nlh, static ns_id_t extract_nsid(struct nlmsghdr *nlh, char *buf) { ns_id_t ns_id = NS_UNKNOWN; - int offset = NETLINK_ALIGN(sizeof(struct nlmsghdr)) + - NETLINK_ALIGN(sizeof(struct rtgenmsg)); + int offset = NETLINK_ALIGN(sizeof(struct nlmsghdr)) + + NETLINK_ALIGN(sizeof(struct rtgenmsg)); int curr_length = offset; void *tail = (void *)((char *)nlh + NETLINK_ALIGN(nlh->nlmsg_len)); struct nlattr *attr; for (attr = (struct nlattr *)((char *)buf + offset); - NETLINK_NLATTR_LEN(tail, attr) >= sizeof(struct nlattr) && - attr->nla_len >= sizeof(struct nlattr) && - attr->nla_len <= NETLINK_NLATTR_LEN(tail, attr); + NETLINK_NLATTR_LEN(tail, attr) >= sizeof(struct nlattr) + && attr->nla_len >= sizeof(struct nlattr) + && attr->nla_len <= NETLINK_NLATTR_LEN(tail, attr); attr += NETLINK_ALIGN(attr->nla_len)) { curr_length += attr->nla_len; if ((attr->nla_type & NLA_TYPE_MASK) == NETNSA_NSID) { @@ -172,8 +170,8 @@ ns_id_t zebra_ns_id_get(const char *netnspath) /* netlink socket */ sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock < 0) { - zlog_err("netlink( %u) socket() error: %s", - sock, safe_strerror(errno)); + zlog_err("netlink( %u) socket() error: %s", sock, + safe_strerror(errno)); return NS_UNKNOWN; } memset(&snl, 0, sizeof(snl)); @@ -182,8 +180,8 @@ ns_id_t zebra_ns_id_get(const char *netnspath) snl.nl_pid = 0; /* AUTO PID */ ret = bind(sock, (struct sockaddr *)&snl, sizeof(snl)); if (ret < 0) { - zlog_err("netlink( %u) socket() bind error: %s", - sock, safe_strerror(errno)); + zlog_err("netlink( %u) socket() bind error: %s", sock, + safe_strerror(errno)); close(sock); close(fd); return NS_UNKNOWN; @@ -222,10 +220,12 @@ ns_id_t zebra_ns_id_get(const char *netnspath) break; } else { if (nlh->nlmsg_type == NLMSG_ERROR) { - struct nlmsgerr *err = (struct nlmsgerr *) - ((char *)nlh + - NETLINK_ALIGN(sizeof( - struct nlmsghdr))); + struct nlmsgerr *err = + (struct nlmsgerr + *)((char *)nlh + + NETLINK_ALIGN(sizeof( + struct + nlmsghdr))); ret = -1; if (err->error < 0) @@ -248,14 +248,15 @@ ns_id_t zebra_ns_id_get(const char *netnspath) } } len = len - NETLINK_ALIGN(nlh->nlmsg_len); - nlh = (struct nlmsghdr *)((char *)nlh + - NETLINK_ALIGN(nlh->nlmsg_len)); + nlh = (struct nlmsghdr *)((char *)nlh + + NETLINK_ALIGN(nlh->nlmsg_len)); } while (len != 0 && return_nsid != NS_UNKNOWN && ret == 0); if (ret <= 0) { if (errno != EEXIST && ret != 0) { - zlog_err("netlink( %u) recvfrom() error 2 when reading: %s", - fd, safe_strerror(errno)); + zlog_err( + "netlink( %u) recvfrom() error 2 when reading: %s", + fd, safe_strerror(errno)); close(sock); close(fd); if (errno == ENOTSUP) { @@ -289,10 +290,12 @@ ns_id_t zebra_ns_id_get(const char *netnspath) if (return_nsid != NS_UNKNOWN) break; } else if (nlh->nlmsg_type == NLMSG_ERROR) { - struct nlmsgerr *err = (struct nlmsgerr *) - ((char *)nlh + - NETLINK_ALIGN(sizeof( - struct nlmsghdr))); + struct nlmsgerr *err = + (struct nlmsgerr + *)((char *)nlh + + NETLINK_ALIGN(sizeof( + struct + nlmsghdr))); if (err->error < 0) errno = -err->error; else @@ -300,8 +303,9 @@ ns_id_t zebra_ns_id_get(const char *netnspath) break; } len = len - NETLINK_ALIGN(nlh->nlmsg_len); - nlh = (struct nlmsghdr *)((char *)nlh + - NETLINK_ALIGN(nlh->nlmsg_len)); + nlh = (struct nlmsghdr *)((char *)nlh + + NETLINK_ALIGN( + nlh->nlmsg_len)); } while (len != 0 && return_nsid != NS_UNKNOWN && ret == 0); } @@ -348,8 +352,7 @@ ns_id_t zebra_ns_id_get_default(void) return NS_DEFAULT_INTERNAL; close(fd); return zebra_ns_id_get((char *)NS_DEFAULT_NAME); -#else /* HAVE_NETNS */ +#else /* HAVE_NETNS */ return NS_DEFAULT_INTERNAL; #endif /* !HAVE_NETNS */ } - diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c index b98d6ed703..4f55be45b6 100644 --- a/zebra/zebra_netns_notify.c +++ b/zebra/zebra_netns_notify.c @@ -83,8 +83,9 @@ static void zebra_ns_notify_create_context_from_entry_name(const char *name) /* if VRF with NS ID already present */ vrf = vrf_lookup_by_id((vrf_id_t)ns_id); if (vrf) { - zlog_warn("NS notify : same NSID used by VRF %s. Ignore NS %s creation", - vrf->name, netnspath); + zlog_warn( + "NS notify : same NSID used by VRF %s. Ignore NS %s creation", + vrf->name, netnspath); return; } if (vrf_handler_create(NULL, name, &vrf) != CMD_SUCCESS) { @@ -96,8 +97,7 @@ static void zebra_ns_notify_create_context_from_entry_name(const char *name) zlog_warn("NS notify : failed to create NS %s", netnspath); return; } - zlog_info("NS notify : created VRF %s NS %s", - name, netnspath); + zlog_info("NS notify : created VRF %s NS %s", name, netnspath); } static int zebra_ns_continue_read(struct zebra_netns_info *zns_info, @@ -111,8 +111,8 @@ static int zebra_ns_continue_read(struct zebra_netns_info *zns_info, return 0; } thread_add_timer_msec(zebrad.master, zebra_ns_ready_read, - (void *)zns_info, - ZEBRA_NS_POLLING_INTERVAL_MSEC, NULL); + (void *)zns_info, ZEBRA_NS_POLLING_INTERVAL_MSEC, + NULL); return 0; } @@ -160,19 +160,17 @@ static int zebra_ns_notify_read(struct thread *t) char buf[BUFSIZ]; ssize_t len; - zebra_netns_notify_current = thread_add_read(zebrad.master, - zebra_ns_notify_read, - NULL, fd_monitor, NULL); + zebra_netns_notify_current = thread_add_read( + zebrad.master, zebra_ns_notify_read, NULL, fd_monitor, NULL); len = read(fd_monitor, buf, sizeof(buf)); if (len < 0) { zlog_warn("NS notify read: failed to read (%s)", safe_strerror(errno)); return 0; } - for (event = (struct inotify_event *)buf; - (char *)event < &buf[len]; - event = (struct inotify_event *)((char *)event + - sizeof(*event) + event->len)) { + for (event = (struct inotify_event *)buf; (char *)event < &buf[len]; + event = (struct inotify_event *)((char *)event + sizeof(*event) + + event->len)) { char *netnspath; struct zebra_netns_info *netnsinfo; @@ -187,7 +185,7 @@ static int zebra_ns_notify_read(struct thread *t) netnsinfo->retries = ZEBRA_NS_POLLING_MAX_RETRIES; netnsinfo->netnspath = netnspath; thread_add_timer_msec(zebrad.master, zebra_ns_ready_read, - (void *)netnsinfo, 0, NULL); + (void *)netnsinfo, 0, NULL); } return 0; } @@ -205,7 +203,7 @@ void zebra_ns_notify_parse(void) struct stat st; if (strcmp(dent->d_name, ".") == 0 - || strcmp(dent->d_name, "..") == 0) + || strcmp(dent->d_name, "..") == 0) continue; if (fstatat(dirfd(srcdir), dent->d_name, &st, 0) < 0) { zlog_warn("NS parsing init: failed to parse entry %s", @@ -236,9 +234,8 @@ void zebra_ns_notify_init(void) zlog_warn("NS notify watch: failed to add watch (%s)", safe_strerror(errno)); } - zebra_netns_notify_current = thread_add_read(zebrad.master, - zebra_ns_notify_read, - NULL, fd_monitor, NULL); + zebra_netns_notify_current = thread_add_read( + zebrad.master, zebra_ns_notify_read, NULL, fd_monitor, NULL); } void zebra_ns_notify_close(void) diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c index cb302985c8..192e8ad413 100644 --- a/zebra/zebra_ns.c +++ b/zebra/zebra_ns.c @@ -36,23 +36,22 @@ #include "debug.h" #include "zebra_netns_notify.h" #include "zebra_netns_id.h" +#include "zebra_pbr.h" extern struct zebra_privs_t zserv_privs; DEFINE_MTYPE(ZEBRA, ZEBRA_NS, "Zebra Name Space") -static inline int -zebra_ns_table_entry_compare(const struct zebra_ns_table *e1, - const struct zebra_ns_table *e2); +static inline int zebra_ns_table_entry_compare(const struct zebra_ns_table *e1, + const struct zebra_ns_table *e2); RB_GENERATE(zebra_ns_table_head, zebra_ns_table, zebra_ns_table_entry, zebra_ns_table_entry_compare); static struct zebra_ns *dzns; -static inline int -zebra_ns_table_entry_compare(const struct zebra_ns_table *e1, - const struct zebra_ns_table *e2) +static inline int zebra_ns_table_entry_compare(const struct zebra_ns_table *e1, + const struct zebra_ns_table *e2) { if (e1->tableid == e2->tableid) return (e1->afi - e2->afi); @@ -96,7 +95,7 @@ static int zebra_ns_new(struct ns *ns) static int zebra_ns_delete(struct ns *ns) { - struct zebra_ns *zns = (struct zebra_ns *) ns->info; + struct zebra_ns *zns = (struct zebra_ns *)ns->info; if (IS_ZEBRA_DEBUG_EVENT) zlog_info("ZNS %s with id %u (deleted)", ns->name, ns->ns_id); @@ -146,8 +145,8 @@ int zebra_ns_enable(ns_id_t ns_id, void **info) return 0; } -struct route_table *zebra_ns_find_table(struct zebra_ns *zns, - uint32_t tableid, afi_t afi) +struct route_table *zebra_ns_find_table(struct zebra_ns *zns, uint32_t tableid, + afi_t afi) { struct zebra_ns_table finder; struct zebra_ns_table *znst; @@ -213,12 +212,15 @@ int zebra_ns_disable(ns_id_t ns_id, void **info) struct zebra_ns_table *znst; struct zebra_ns *zns = (struct zebra_ns *)(*info); + hash_clean(zns->rules_hash, zebra_pbr_rules_free); + hash_free(zns->rules_hash); while (!RB_EMPTY(zebra_ns_table_head, &zns->ns_tables)) { znst = RB_ROOT(zebra_ns_table_head, &zns->ns_tables); RB_REMOVE(zebra_ns_table_head, &zns->ns_tables, znst); zebra_ns_free_table(znst); } + route_table_finish(zns->if_table); zebra_vxlan_ns_disable(zns); #if defined(HAVE_RTADV) @@ -259,6 +261,9 @@ int zebra_ns_init(void) /* Default NS is activated */ zebra_ns_enable(ns_id, (void **)&dzns); + dzns->rules_hash = + hash_create_size(8, zebra_pbr_rules_hash_key, + zebra_pbr_rules_hash_equal, "Rules Hash"); if (vrf_is_backend_netns()) { ns_add_hook(NS_NEW_HOOK, zebra_ns_new); ns_add_hook(NS_ENABLE_HOOK, zebra_ns_enabled); @@ -275,7 +280,7 @@ static int logicalrouter_config_write(struct vty *vty) struct ns *ns; int write = 0; - RB_FOREACH(ns, ns_head, &ns_tree) { + RB_FOREACH (ns, ns_head, &ns_tree) { if (ns->ns_id == NS_DEFAULT || ns->name == NULL) continue; vty_out(vty, "logical-router %u netns %s\n", ns->ns_id, diff --git a/zebra/zebra_ns.h b/zebra/zebra_ns.h index 3a998a49ff..19ecba1f0e 100644 --- a/zebra/zebra_ns.h +++ b/zebra/zebra_ns.h @@ -23,6 +23,7 @@ #define __ZEBRA_NS_H__ #include <lib/ns.h> +#include <lib/vrf.h> #ifdef HAVE_NETLINK /* Socket interface to kernel */ @@ -70,6 +71,8 @@ struct zebra_ns { struct zebra_ns_table_head ns_tables; + struct hash *rules_hash; + /* Back pointer */ struct ns *ns; }; diff --git a/zebra/zebra_pbr.c b/zebra/zebra_pbr.c new file mode 100644 index 0000000000..4da09dc538 --- /dev/null +++ b/zebra/zebra_pbr.c @@ -0,0 +1,162 @@ +/* Zebra Policy Based Routing (PBR) main handling. + * Copyright (C) 2018 Cumulus Networks, Inc. + * + * This file is part of FRR. + * + * FRR 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. + * + * FRR 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 FRR; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include <zebra.h> + +#include <jhash.h> +#include <hash.h> + +#include "zebra/zebra_pbr.h" +#include "zebra/rt.h" + +/* definitions */ + +/* static function declarations */ + +/* Private functions */ + +/* Public functions */ +void zebra_pbr_rules_free(void *arg) +{ + struct zebra_pbr_rule *rule; + + rule = (struct zebra_pbr_rule *)arg; + + kernel_del_pbr_rule(rule); + XFREE(MTYPE_TMP, rule); +} + +uint32_t zebra_pbr_rules_hash_key(void *arg) +{ + struct zebra_pbr_rule *rule; + uint32_t key; + + rule = (struct zebra_pbr_rule *)arg; + key = jhash_3words(rule->seq, rule->priority, rule->action.table, + prefix_hash_key(&rule->filter.src_ip)); + if (rule->ifp) + key = jhash_1word(rule->ifp->ifindex, key); + else + key = jhash_1word(0, key); + + return jhash_3words(rule->filter.src_port, rule->filter.dst_port, + prefix_hash_key(&rule->filter.dst_ip), + jhash_1word(rule->unique, key)); +} + +int zebra_pbr_rules_hash_equal(const void *arg1, const void *arg2) +{ + const struct zebra_pbr_rule *r1, *r2; + + r1 = (const struct zebra_pbr_rule *)arg1; + r2 = (const struct zebra_pbr_rule *)arg2; + + if (r1->seq != r2->seq) + return 0; + + if (r1->priority != r2->priority) + return 0; + + if (r1->unique != r2->unique) + return 0; + + if (r1->action.table != r2->action.table) + return 0; + + if (r1->filter.src_port != r2->filter.src_port) + return 0; + + if (r1->filter.dst_port != r2->filter.dst_port) + return 0; + + if (!prefix_same(&r1->filter.src_ip, &r2->filter.src_ip)) + return 0; + + if (!prefix_same(&r1->filter.dst_ip, &r2->filter.dst_ip)) + return 0; + + if (r1->ifp != r2->ifp) + return 0; + + return 1; +} + +static void *pbr_rule_alloc_intern(void *arg) +{ + struct zebra_pbr_rule *zpr; + struct zebra_pbr_rule *new; + + zpr = (struct zebra_pbr_rule *)arg; + + new = XCALLOC(MTYPE_TMP, sizeof(*new)); + + memcpy(new, zpr, sizeof(*zpr)); + + return new; +} + +void zebra_pbr_add_rule(struct zebra_ns *zns, struct zebra_pbr_rule *rule) +{ + (void)hash_get(zns->rules_hash, rule, pbr_rule_alloc_intern); + kernel_add_pbr_rule(rule); +} + +void zebra_pbr_del_rule(struct zebra_ns *zns, struct zebra_pbr_rule *rule) +{ + struct zebra_pbr_rule *lookup; + + lookup = hash_lookup(zns->rules_hash, rule); + kernel_del_pbr_rule(rule); + + if (lookup) + XFREE(MTYPE_TMP, lookup); + else + zlog_warn("%s: Rule being deleted we know nothing about", + __PRETTY_FUNCTION__); +} + +/* + * Handle success or failure of rule (un)install in the kernel. + */ +void kernel_pbr_rule_add_del_status(struct zebra_pbr_rule *rule, + enum southbound_results res) +{ + switch (res) { + case SOUTHBOUND_INSTALL_SUCCESS: + zsend_rule_notify_owner(rule, ZAPI_RULE_INSTALLED); + break; + case SOUTHBOUND_INSTALL_FAILURE: + zsend_rule_notify_owner(rule, ZAPI_RULE_FAIL_INSTALL); + break; + case SOUTHBOUND_DELETE_SUCCESS: + break; + case SOUTHBOUND_DELETE_FAILURE: + break; + } +} + +/* + * Handle rule delete notification from kernel. + */ +int kernel_pbr_rule_del(struct zebra_pbr_rule *rule) +{ + return 0; +} diff --git a/zebra/zebra_pbr.h b/zebra/zebra_pbr.h new file mode 100644 index 0000000000..4b28b6ec35 --- /dev/null +++ b/zebra/zebra_pbr.h @@ -0,0 +1,138 @@ +/* + * Zebra Policy Based Routing (PBR) Data structures and definitions + * These are public definitions referenced by multiple files. + * Copyright (C) 2018 Cumulus Networks, Inc. + * + * This file is part of FRR. + * + * FRR 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. + * + * FRR 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 FRR; 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_PBR_H +#define _ZEBRA_PBR_H + +#include <zebra.h> + +#include "prefix.h" +#include "if.h" + +#include "rt.h" + +/* + * A PBR filter + * + * The filter or match criteria in a PBR rule. + * For simplicity, all supported filters are grouped into a structure rather + * than delineating further. A bitmask denotes which filters are actually + * specified. + */ +struct zebra_pbr_filter { + uint32_t filter_bm; +#define PBR_FILTER_SRC_IP (1 << 0) +#define PBR_FILTER_DST_IP (1 << 1) +#define PBR_FILTER_SRC_PORT (1 << 2) +#define PBR_FILTER_DST_PORT (1 << 3) + + /* Source and Destination IP address with masks. */ + struct prefix src_ip; + struct prefix dst_ip; + + /* Source and Destination higher-layer (TCP/UDP) port numbers. */ + uint16_t src_port; + uint16_t dst_port; +}; + +#define IS_RULE_FILTERING_ON_SRC_IP(r) \ + (r->filter.filter_bm & PBR_FILTER_SRC_IP) +#define IS_RULE_FILTERING_ON_DST_IP(r) \ + (r->filter.filter_bm & PBR_FILTER_DST_IP) +#define IS_RULE_FILTERING_ON_SRC_PORT(r) \ + (r->filter.filter_bm & PBR_FILTER_SRC_PORT) +#define IS_RULE_FILTERING_ON_DST_PORT(r) \ + (r->filter.filter_bm & PBR_FILTER_DST_PORT) + +/* + * A PBR action + * + * The action corresponding to a PBR rule. + * While the user specifies the action in a particular way, the forwarding + * plane implementation (Linux only) requires that to be encoded into a + * route table and the rule then point to that route table; in some cases, + * the user criteria may directly point to a table too. + */ +struct zebra_pbr_action { + uint32_t table; +}; + +/* + * A PBR rule + * + * This is a combination of the filter criteria and corresponding action. + * Rules also have a user-defined sequence number which defines the relative + * order amongst rules. + */ +struct zebra_pbr_rule { + /* + * Originating zclient sock fd, so we can know who to send + * back to. + */ + int sock; + + uint32_t seq; + uint32_t priority; + struct interface *ifp; + uint32_t unique; + struct zebra_pbr_filter filter; + struct zebra_pbr_action action; +}; + +void zebra_pbr_add_rule(struct zebra_ns *zns, struct zebra_pbr_rule *rule); +void zebra_pbr_del_rule(struct zebra_ns *zns, struct zebra_pbr_rule *rule); + +/* + * Install specified rule for a specific interface. + * It is possible that the user-defined sequence number and the one in the + * forwarding plane may not coincide, hence the API requires a separate + * rule priority - maps to preference/FRA_PRIORITY on Linux. + */ +extern void kernel_add_pbr_rule(struct zebra_pbr_rule *rule); + +/* + * Uninstall specified rule for a specific interface. + */ +extern void kernel_del_pbr_rule(struct zebra_pbr_rule *rule); + +/* + * Get to know existing PBR rules in the kernel - typically called at startup. + */ +extern void kernel_read_pbr_rules(struct zebra_ns *zns); + +enum southbound_results; +/* + * Handle success or failure of rule (un)install in the kernel. + */ +extern void kernel_pbr_rule_add_del_status(struct zebra_pbr_rule *rule, + enum southbound_results res); + +/* + * Handle rule delete notification from kernel. + */ +extern int kernel_pbr_rule_del(struct zebra_pbr_rule *rule); + +extern void zebra_pbr_rules_free(void *arg); +extern uint32_t zebra_pbr_rules_hash_key(void *arg); +extern int zebra_pbr_rules_hash_equal(const void *arg1, const void *arg2); +#endif /* _ZEBRA_PBR_H */ diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index 187c2594ad..f6775fa0b1 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -956,8 +956,7 @@ stream_failure: } /* BFD client register */ -int zebra_ptm_bfd_client_register(struct zserv *client, - u_short length) +int zebra_ptm_bfd_client_register(struct zserv *client, u_short length) { struct stream *s; unsigned int pid; diff --git a/zebra/zebra_ptm.h b/zebra/zebra_ptm.h index 664221eff7..392853b599 100644 --- a/zebra/zebra_ptm.h +++ b/zebra/zebra_ptm.h @@ -67,8 +67,7 @@ int zebra_ptm_bfd_dst_register(struct zserv *client, u_short length, int zebra_ptm_bfd_dst_deregister(struct zserv *client, u_short length, struct zebra_vrf *zvrf); void zebra_ptm_show_status(struct vty *vty, struct interface *ifp); -int zebra_ptm_bfd_client_register(struct zserv *client, - u_short length); +int zebra_ptm_bfd_client_register(struct zserv *client, u_short length); void zebra_ptm_if_init(struct zebra_if *zebra_ifp); void zebra_ptm_if_set_ptm_state(struct interface *ifp, struct zebra_if *zebra_ifp); diff --git a/zebra/zebra_pw.c b/zebra/zebra_pw.c index 96bee36be6..68ad69397f 100644 --- a/zebra/zebra_pw.c +++ b/zebra/zebra_pw.c @@ -256,7 +256,7 @@ static int zebra_pw_check_reachability(struct zebra_pw *pw) * Need to ensure that there's a label binding for all nexthops. * Otherwise, ECMP for this route could render the pseudowire unusable. */ - for (ALL_NEXTHOPS(re->nexthop, nexthop)) { + for (ALL_NEXTHOPS(re->ng, nexthop)) { if (!nexthop->nh_label) { if (IS_ZEBRA_DEBUG_PW) zlog_warn("%s: unlabeled route for %s", diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 10e5f55e05..72dbfb12fc 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -183,7 +183,7 @@ int zebra_check_addr(struct prefix *p) /* Add nexthop to the end of a rib node's nexthop list */ void route_entry_nexthop_add(struct route_entry *re, struct nexthop *nexthop) { - nexthop_add(&re->nexthop, nexthop); + nexthop_add(&re->ng.nexthop, nexthop); re->nexthop_num++; } @@ -193,8 +193,8 @@ void route_entry_nexthop_add(struct route_entry *re, struct nexthop *nexthop) */ void route_entry_copy_nexthops(struct route_entry *re, struct nexthop *nh) { - assert(!re->nexthop); - copy_nexthops(&re->nexthop, nh, NULL); + assert(!re->ng.nexthop); + copy_nexthops(&re->ng.nexthop, nh, NULL); for (struct nexthop *nexthop = nh; nexthop; nexthop = nexthop->next) re->nexthop_num++; } @@ -207,7 +207,7 @@ void route_entry_nexthop_delete(struct route_entry *re, struct nexthop *nexthop) if (nexthop->prev) nexthop->prev->next = nexthop->next; else - re->nexthop = nexthop->next; + re->ng.nexthop = nexthop->next; re->nexthop_num--; } @@ -267,8 +267,8 @@ struct nexthop *route_entry_nexthop_ipv4_ifindex_add(struct route_entry *re, /*Pending: need to think if null ifp here is ok during bootup? There was a crash because ifp here was coming to be NULL */ if (ifp) - if (connected_is_unnumbered(ifp) || - CHECK_FLAG(re->flags, ZEBRA_FLAG_EVPN_ROUTE)) { + if (connected_is_unnumbered(ifp) + || CHECK_FLAG(re->flags, ZEBRA_FLAG_EVPN_ROUTE)) { SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK); } @@ -481,8 +481,8 @@ static int nexthop_active(afi_t afi, struct route_entry *re, * host route. */ if (top && rn == top) - if (((afi == AFI_IP) && (rn->p.prefixlen != 32)) || - ((afi == AFI_IP6) && (rn->p.prefixlen != 128))) + if (((afi == AFI_IP) && (rn->p.prefixlen != 32)) + || ((afi == AFI_IP6) && (rn->p.prefixlen != 128))) return 0; /* Pick up selected route. */ @@ -493,10 +493,10 @@ static int nexthop_active(afi_t afi, struct route_entry *re, return 0; dest = rib_dest_from_rnode(rn); - if (dest && dest->selected_fib && - !CHECK_FLAG(dest->selected_fib->status, - ROUTE_ENTRY_REMOVED) && - dest->selected_fib->type != ZEBRA_ROUTE_TABLE) + if (dest && dest->selected_fib + && !CHECK_FLAG(dest->selected_fib->status, + ROUTE_ENTRY_REMOVED) + && dest->selected_fib->type != ZEBRA_ROUTE_TABLE) match = dest->selected_fib; /* If there is no selected route or matched route is EGP, go up @@ -513,7 +513,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re, if (match->type == ZEBRA_ROUTE_CONNECT) { /* Directly point connected route. */ - newhop = match->nexthop; + newhop = match->ng.nexthop; if (newhop) { if (nexthop->type == NEXTHOP_TYPE_IPV4 || nexthop->type == NEXTHOP_TYPE_IPV6) @@ -522,7 +522,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re, return 1; } else if (CHECK_FLAG(re->flags, ZEBRA_FLAG_ALLOW_RECURSION)) { resolved = 0; - for (ALL_NEXTHOPS(match->nexthop, newhop)) { + for (ALL_NEXTHOPS(match->ng, newhop)) { if (!CHECK_FLAG(newhop->flags, NEXTHOP_FLAG_FIB)) continue; @@ -545,7 +545,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re, return resolved; } else if (re->type == ZEBRA_ROUTE_STATIC) { resolved = 0; - for (ALL_NEXTHOPS(match->nexthop, newhop)) { + for (ALL_NEXTHOPS(match->ng, newhop)) { if (!CHECK_FLAG(newhop->flags, NEXTHOP_FLAG_FIB)) continue; @@ -600,8 +600,9 @@ struct route_entry *rib_match(afi_t afi, safi_t safi, vrf_id_t vrf_id, route_unlock_node(rn); dest = rib_dest_from_rnode(rn); - if (dest && dest->selected_fib && - !CHECK_FLAG(dest->selected_fib->status, ROUTE_ENTRY_REMOVED)) + if (dest && dest->selected_fib + && !CHECK_FLAG(dest->selected_fib->status, + ROUTE_ENTRY_REMOVED)) match = dest->selected_fib; /* If there is no selected route or matched route is EGP, go up @@ -615,7 +616,7 @@ struct route_entry *rib_match(afi_t afi, safi_t safi, vrf_id_t vrf_id, } else { if (match->type != ZEBRA_ROUTE_CONNECT) { int found = 0; - for (ALL_NEXTHOPS(match->nexthop, newhop)) + for (ALL_NEXTHOPS(match->ng, newhop)) if (CHECK_FLAG(newhop->flags, NEXTHOP_FLAG_FIB)) { found = 1; @@ -728,8 +729,8 @@ struct route_entry *rib_lookup_ipv4(struct prefix_ipv4 *p, vrf_id_t vrf_id) route_unlock_node(rn); dest = rib_dest_from_rnode(rn); - if (dest && dest->selected_fib && - !CHECK_FLAG(dest->selected_fib->status, ROUTE_ENTRY_REMOVED)) + if (dest && dest->selected_fib + && !CHECK_FLAG(dest->selected_fib->status, ROUTE_ENTRY_REMOVED)) match = dest->selected_fib; if (!match) @@ -738,7 +739,7 @@ struct route_entry *rib_lookup_ipv4(struct prefix_ipv4 *p, vrf_id_t vrf_id) if (match->type == ZEBRA_ROUTE_CONNECT) return match; - for (ALL_NEXTHOPS(match->nexthop, nexthop)) + for (ALL_NEXTHOPS(match->ng, nexthop)) if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)) return match; @@ -785,8 +786,8 @@ int rib_lookup_ipv4_route(struct prefix_ipv4 *p, union sockunion *qgate, /* Find out if a "selected" RR for the discovered RIB entry exists ever. */ - if (dest && dest->selected_fib && - !CHECK_FLAG(dest->selected_fib->status, ROUTE_ENTRY_REMOVED)) + if (dest && dest->selected_fib + && !CHECK_FLAG(dest->selected_fib->status, ROUTE_ENTRY_REMOVED)) match = dest->selected_fib; /* None such found :( */ @@ -798,7 +799,7 @@ int rib_lookup_ipv4_route(struct prefix_ipv4 *p, union sockunion *qgate, /* Ok, we have a cood candidate, let's check it's nexthop list... */ nexthops_active = 0; - for (ALL_NEXTHOPS(match->nexthop, nexthop)) + for (ALL_NEXTHOPS(match->ng, nexthop)) if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)) { nexthops_active = 1; if (nexthop->gate.ipv4.s_addr == sockunion2ip(qgate)) @@ -962,7 +963,7 @@ static int nexthop_active_update(struct route_node *rn, struct route_entry *re, re->nexthop_active_num = 0; UNSET_FLAG(re->status, ROUTE_ENTRY_CHANGED); - for (nexthop = re->nexthop; nexthop; nexthop = nexthop->next) { + for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) { /* No protocol daemon provides src and so we're skipping * tracking it */ prev_src = nexthop->rmap_src; @@ -1006,7 +1007,7 @@ int zebra_rib_labeled_unicast(struct route_entry *re) if (re->type != ZEBRA_ROUTE_BGP) return 0; - for (ALL_NEXTHOPS(re->nexthop, nexthop)) + for (ALL_NEXTHOPS(re->ng, nexthop)) if (!nexthop->nh_label || !nexthop->nh_label->num_labels) return 0; @@ -1026,7 +1027,7 @@ void kernel_route_rib_pass_fail(struct route_node *rn, struct prefix *p, switch (res) { case SOUTHBOUND_INSTALL_SUCCESS: dest->selected_fib = re; - for (ALL_NEXTHOPS(re->nexthop, nexthop)) { + for (ALL_NEXTHOPS(re->ng, nexthop)) { if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) continue; @@ -1059,8 +1060,10 @@ void kernel_route_rib_pass_fail(struct route_node *rn, struct prefix *p, */ if (dest->selected_fib == re) dest->selected_fib = NULL; - for (ALL_NEXTHOPS(re->nexthop, nexthop)) + for (ALL_NEXTHOPS(re->ng, nexthop)) UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); + + zsend_route_notify_owner(re, p, ZAPI_ROUTE_REMOVED); break; case SOUTHBOUND_DELETE_FAILURE: /* @@ -1070,6 +1073,8 @@ void kernel_route_rib_pass_fail(struct route_node *rn, struct prefix *p, dest->selected_fib = NULL; zlog_warn("%u:%s: Route Deletion failure", re->vrf_id, prefix2str(p, buf, sizeof(buf))); + + zsend_route_notify_owner(re, p, ZAPI_ROUTE_REMOVE_FAIL); break; } } @@ -1088,20 +1093,20 @@ void rib_install_kernel(struct route_node *rn, struct route_entry *re, srcdest_rnode_prefixes(rn, &p, &src_p); if (info->safi != SAFI_UNICAST) { - for (ALL_NEXTHOPS(re->nexthop, nexthop)) + for (ALL_NEXTHOPS(re->ng, nexthop)) SET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); return; } else { struct nexthop *prev; - for (ALL_NEXTHOPS(re->nexthop, nexthop)) { + for (ALL_NEXTHOPS(re->ng, nexthop)) { UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_DUPLICATE); - for (ALL_NEXTHOPS(re->nexthop, prev)) { + for (ALL_NEXTHOPS(re->ng, prev)) { if (prev == nexthop) break; - if (nexthop_same_firsthop (nexthop, prev)) - { - SET_FLAG (nexthop->flags, NEXTHOP_FLAG_DUPLICATE); + if (nexthop_same_firsthop(nexthop, prev)) { + SET_FLAG(nexthop->flags, + NEXTHOP_FLAG_DUPLICATE); break; } } @@ -1137,7 +1142,7 @@ void rib_uninstall_kernel(struct route_node *rn, struct route_entry *re) srcdest_rnode_prefixes(rn, &p, &src_p); if (info->safi != SAFI_UNICAST) { - for (ALL_NEXTHOPS(re->nexthop, nexthop)) + for (ALL_NEXTHOPS(re->ng, nexthop)) UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); return; } @@ -1387,7 +1392,7 @@ static void rib_process_update_fib(struct zebra_vrf *zvrf, if (!RIB_SYSTEM_ROUTE(old)) rib_uninstall_kernel(rn, old); } else { - for (nexthop = old->nexthop; nexthop; + for (nexthop = old->ng.nexthop; nexthop; nexthop = nexthop->next) UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); @@ -1443,7 +1448,7 @@ static void rib_process_update_fib(struct zebra_vrf *zvrf, if (!RIB_SYSTEM_ROUTE(new)) { bool in_fib = false; - for (ALL_NEXTHOPS(new->nexthop, nexthop)) + for (ALL_NEXTHOPS(new->ng, nexthop)) if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)) { in_fib = true; @@ -1675,13 +1680,16 @@ static void rib_process(struct route_node *rn) /* Redistribute SELECTED entry */ if (old_selected != new_selected || selected_changed) { - struct nexthop *nexthop; + struct nexthop *nexthop = NULL; /* Check if we have a FIB route for the destination, otherwise, * don't redistribute it */ - for (ALL_NEXTHOPS(new_fib ? new_fib->nexthop : NULL, nexthop)) { - if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)) { - break; + if (new_fib) { + for (ALL_NEXTHOPS(new_fib->ng, nexthop)) { + if (CHECK_FLAG(nexthop->flags, + NEXTHOP_FLAG_FIB)) { + break; + } } } if (!nexthop) @@ -2115,9 +2123,9 @@ void rib_unlink(struct route_node *rn, struct route_entry *re) /* free RE and nexthops */ if (re->type == ZEBRA_ROUTE_STATIC) - zebra_deregister_rnh_static_nexthops(re->vrf_id, - re->nexthop, rn); - nexthops_free(re->nexthop); + zebra_deregister_rnh_static_nexthops(re->vrf_id, re->ng.nexthop, + rn); + nexthops_free(re->ng.nexthop); XFREE(MTYPE_RE, re); } @@ -2181,7 +2189,7 @@ void _route_entry_dump(const char *func, union prefixconstptr pp, zlog_debug("%s: nexthop_num == %u, nexthop_active_num == %u", func, re->nexthop_num, re->nexthop_active_num); - for (ALL_NEXTHOPS(re->nexthop, nexthop)) { + for (ALL_NEXTHOPS(re->ng, nexthop)) { inet_ntop(p->family, &nexthop->gate, straddr, INET6_ADDRSTRLEN); zlog_debug("%s: %s %s[%u] with flags %s%s%s", func, (nexthop->rparent ? " NH" : "NH"), straddr, @@ -2343,8 +2351,8 @@ int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p, continue; if (same->instance != re->instance) continue; - if (same->type == ZEBRA_ROUTE_KERNEL && - same->metric != re->metric) + if (same->type == ZEBRA_ROUTE_KERNEL + && same->metric != re->metric) continue; /* * We should allow duplicate connected routes because of @@ -2356,7 +2364,7 @@ int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p, /* If this route is kernel route, set FIB flag to the route. */ if (RIB_SYSTEM_ROUTE(re)) - for (nexthop = re->nexthop; nexthop; nexthop = nexthop->next) + for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) SET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); /* Link new re to node.*/ @@ -2440,10 +2448,9 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, continue; if (re->instance != instance) continue; - if (re->type == ZEBRA_ROUTE_KERNEL && - re->metric != metric) + if (re->type == ZEBRA_ROUTE_KERNEL && re->metric != metric) continue; - if (re->type == ZEBRA_ROUTE_CONNECT && (rtnh = re->nexthop) + if (re->type == ZEBRA_ROUTE_CONNECT && (rtnh = re->ng.nexthop) && rtnh->type == NEXTHOP_TYPE_IFINDEX && nh) { if (rtnh->ifindex != nh->ifindex) continue; @@ -2456,7 +2463,7 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, same = re; break; } - for (ALL_NEXTHOPS(re->nexthop, rtnh)) + for (ALL_NEXTHOPS(re->ng, rtnh)) if (nexthop_same_no_recurse(rtnh, nh)) { same = re; break; @@ -2493,7 +2500,7 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, } if (allow_delete) { /* Unset flags. */ - for (rtnh = fib->nexthop; rtnh; + for (rtnh = fib->ng.nexthop; rtnh; rtnh = rtnh->next) UNSET_FLAG(rtnh->flags, NEXTHOP_FLAG_FIB); @@ -2536,9 +2543,8 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, } if (same) { - if (fromkernel && - CHECK_FLAG(flags, ZEBRA_FLAG_SELFROUTE) && - !allow_delete) { + if (fromkernel && CHECK_FLAG(flags, ZEBRA_FLAG_SELFROUTE) + && !allow_delete) { rib_install_kernel(rn, same, NULL); route_unlock_node(rn); @@ -2548,7 +2554,7 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, if (CHECK_FLAG(flags, ZEBRA_FLAG_EVPN_ROUTE)) { struct nexthop *tmp_nh; - for (ALL_NEXTHOPS(re->nexthop, tmp_nh)) { + for (ALL_NEXTHOPS(re->ng, tmp_nh)) { struct ipaddr vtep_ip; memset(&vtep_ip, 0, sizeof(struct ipaddr)); @@ -2621,9 +2627,8 @@ static void rib_update_table(struct route_table *table, * has already been queued we don't * need to queue it up again */ - if (rn->info - && CHECK_FLAG(rib_dest_from_rnode(rn)->flags, - RIB_ROUTE_ANY_QUEUED)) + if (rn->info && CHECK_FLAG(rib_dest_from_rnode(rn)->flags, + RIB_ROUTE_ANY_QUEUED)) continue; switch (event) { case RIB_UPDATE_IF_CHANGE: @@ -2640,10 +2645,10 @@ static void rib_update_table(struct route_table *table, RNODE_FOREACH_RE_SAFE (rn, re, next) { struct nexthop *nh; - if (re->type != ZEBRA_ROUTE_SYSTEM && - re->type != ZEBRA_ROUTE_KERNEL && - re->type != ZEBRA_ROUTE_CONNECT && - re->type != ZEBRA_ROUTE_STATIC) + if (re->type != ZEBRA_ROUTE_SYSTEM + && re->type != ZEBRA_ROUTE_KERNEL + && re->type != ZEBRA_ROUTE_CONNECT + && re->type != ZEBRA_ROUTE_STATIC) continue; if (re->type != ZEBRA_ROUTE_STATIC) { @@ -2651,7 +2656,7 @@ static void rib_update_table(struct route_table *table, continue; } - for (nh = re->nexthop; nh; nh = nh->next) + for (nh = re->ng.nexthop; nh; nh = nh->next) if (!(nh->type == NEXTHOP_TYPE_IPV4 || nh->type == NEXTHOP_TYPE_IPV6)) break; @@ -2768,7 +2773,7 @@ static void rib_sweep_table(struct route_table *table) * to a different spot (ie startup ) * this decision needs to be revisited */ - for (ALL_NEXTHOPS(re->nexthop, nexthop)) + for (ALL_NEXTHOPS(re->ng, nexthop)) SET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); rib_uninstall_kernel(rn, re); diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index d960dbd937..dd3fe17702 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -355,7 +355,8 @@ static int zebra_rnh_apply_nht_rmap(int family, struct route_node *prn, rmap_family = (family == AF_INET) ? AFI_IP : AFI_IP6; if (prn && re) { - for (nexthop = re->nexthop; nexthop; nexthop = nexthop->next) { + for (nexthop = re->ng.nexthop; nexthop; + nexthop = nexthop->next) { ret = zebra_nht_route_map_check(rmap_family, proto, &prn->p, re, nexthop); if (ret != RMAP_DENYMATCH) { @@ -373,12 +374,10 @@ static int zebra_rnh_apply_nht_rmap(int family, struct route_node *prn, * Determine appropriate route (RE entry) resolving a tracked BGP route * for BGP route for import. */ -static -struct route_entry *zebra_rnh_resolve_import_entry(vrf_id_t vrfid, - int family, - struct route_node *nrn, - struct rnh *rnh, - struct route_node **prn) +static struct route_entry * +zebra_rnh_resolve_import_entry(vrf_id_t vrfid, int family, + struct route_node *nrn, struct rnh *rnh, + struct route_node **prn) { struct route_table *route_table; struct route_node *rn; @@ -397,15 +396,15 @@ struct route_entry *zebra_rnh_resolve_import_entry(vrf_id_t vrfid, /* Unlock route node - we don't need to lock when walking the tree. */ route_unlock_node(rn); - if (CHECK_FLAG(rnh->flags, ZEBRA_NHT_EXACT_MATCH) && - !prefix_same(&nrn->p, &rn->p)) + if (CHECK_FLAG(rnh->flags, ZEBRA_NHT_EXACT_MATCH) + && !prefix_same(&nrn->p, &rn->p)) return NULL; /* Identify appropriate route entry. */ - RNODE_FOREACH_RE(rn, re) { - if (!CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED) && - CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED) && - (re->type != ZEBRA_ROUTE_BGP)) + RNODE_FOREACH_RE (rn, re) { + if (!CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED) + && CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED) + && (re->type != ZEBRA_ROUTE_BGP)) break; } @@ -430,7 +429,7 @@ static void zebra_rnh_eval_import_check_entry(vrf_id_t vrfid, int family, struct nexthop *nexthop; if (re && (rnh->state == NULL)) { - for (ALL_NEXTHOPS(re->nexthop, nexthop)) + for (ALL_NEXTHOPS(re->ng, nexthop)) if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)) { state_changed = 1; break; @@ -561,7 +560,7 @@ static void zebra_rnh_process_static_routes(vrf_id_t vrfid, int family, * be having multiple. We care here only about * registered nexthops. */ - for (nexthop = sre->nexthop; nexthop; + for (nexthop = sre->ng.nexthop; nexthop; nexthop = nexthop->next) { switch (nexthop->type) { case NEXTHOP_TYPE_IPV4: @@ -628,11 +627,10 @@ static void zebra_rnh_process_static_routes(vrf_id_t vrfid, int family, * Determine appropriate route (route entry) resolving a tracked * nexthop. */ -static struct route_entry *zebra_rnh_resolve_nexthop_entry(vrf_id_t vrfid, - int family, - struct route_node *nrn, - struct rnh *rnh, - struct route_node **prn) +static struct route_entry * +zebra_rnh_resolve_nexthop_entry(vrf_id_t vrfid, int family, + struct route_node *nrn, struct rnh *rnh, + struct route_node **prn) { struct route_table *route_table; struct route_node *rn; @@ -658,12 +656,12 @@ static struct route_entry *zebra_rnh_resolve_nexthop_entry(vrf_id_t vrfid, /* Do not resolve over default route unless allowed && * match route to be exact if so specified */ - if (is_default_prefix(&rn->p) && - !rnh_resolve_via_default(rn->p.family)) + if (is_default_prefix(&rn->p) + && !rnh_resolve_via_default(rn->p.family)) return NULL; /* Identify appropriate route entry. */ - RNODE_FOREACH_RE(rn, re) { + RNODE_FOREACH_RE (rn, re) { if (CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED)) continue; if (!CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED)) @@ -676,11 +674,10 @@ static struct route_entry *zebra_rnh_resolve_nexthop_entry(vrf_id_t vrfid, if (re->type == ZEBRA_ROUTE_NHRP) { struct nexthop *nexthop; - for (nexthop = re->nexthop; - nexthop; + for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) if (nexthop->type - == NEXTHOP_TYPE_IFINDEX) + == NEXTHOP_TYPE_IFINDEX) break; if (nexthop) break; @@ -779,8 +776,8 @@ static void zebra_rnh_evaluate_entry(vrf_id_t vrfid, int family, int force, /* Identify route entry (RE) resolving this tracked entry. */ if (type == RNH_IMPORT_CHECK_TYPE) - re = zebra_rnh_resolve_import_entry(vrfid, family, nrn, - rnh, &prn); + re = zebra_rnh_resolve_import_entry(vrfid, family, nrn, rnh, + &prn); else re = zebra_rnh_resolve_nexthop_entry(vrfid, family, nrn, rnh, &prn); @@ -820,8 +817,8 @@ static void zebra_rnh_clear_nhc_flag(vrf_id_t vrfid, int family, /* Identify route entry (RIB) resolving this tracked entry. */ if (type == RNH_IMPORT_CHECK_TYPE) - re = zebra_rnh_resolve_import_entry(vrfid, family, nrn, - rnh, &prn); + re = zebra_rnh_resolve_import_entry(vrfid, family, nrn, rnh, + &prn); else re = zebra_rnh_resolve_nexthop_entry(vrfid, family, nrn, rnh, &prn); @@ -929,8 +926,8 @@ static void free_state(vrf_id_t vrf_id, struct route_entry *re, return; /* free RE and nexthops */ - zebra_deregister_rnh_static_nexthops(vrf_id, re->nexthop, rn); - nexthops_free(re->nexthop); + zebra_deregister_rnh_static_nexthops(vrf_id, re->ng.nexthop, rn); + nexthops_free(re->ng.nexthop); XFREE(MTYPE_RE, re); } @@ -953,7 +950,7 @@ static void copy_state(struct rnh *rnh, struct route_entry *re, state->metric = re->metric; state->vrf_id = re->vrf_id; - route_entry_copy_nexthops(state, re->nexthop); + route_entry_copy_nexthops(state, re->ng.nexthop); rnh->state = state; } @@ -1026,7 +1023,7 @@ static int send_client(struct rnh *rnh, struct zserv *client, rnh_type_t type, num = 0; nump = stream_get_endp(s); stream_putc(s, 0); - for (nexthop = re->nexthop; nexthop; nexthop = nexthop->next) + for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) if ((CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB) || CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) @@ -1119,7 +1116,7 @@ static void print_rnh(struct route_node *rn, struct vty *vty) if (rnh->state) { vty_out(vty, " resolved via %s\n", zebra_route_string(rnh->state->type)); - for (nexthop = rnh->state->nexthop; nexthop; + for (nexthop = rnh->state->ng.nexthop; nexthop; nexthop = nexthop->next) print_nh(nexthop, vty); } else diff --git a/zebra/zebra_rnh.h b/zebra/zebra_rnh.h index bd121ec83c..7af1dbeaf1 100644 --- a/zebra/zebra_rnh.h +++ b/zebra/zebra_rnh.h @@ -39,9 +39,9 @@ struct rnh { struct route_entry *state; struct prefix resolved_route; struct list *client_list; - struct list * - zebra_static_route_list; /* static routes dependent on this NH - */ + struct list + *zebra_static_route_list; /* static routes dependent on this NH + */ struct list *zebra_pseudowire_list; /* pseudowires dependent on this NH */ struct route_node *node; diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 882a03f844..64c38635fb 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -238,8 +238,8 @@ DEFUN (match_ipv6_address_prefix_len, "Match prefix length of ipv6 address\n" "Prefix length\n") { - return zebra_route_match_add(vty, "ipv6 address prefix-len", argv[4]->arg, - RMAP_EVENT_MATCH_ADDED); + return zebra_route_match_add(vty, "ipv6 address prefix-len", + argv[4]->arg, RMAP_EVENT_MATCH_ADDED); } DEFUN (no_match_ipv6_address_prefix_len, diff --git a/zebra/zebra_snmp.c b/zebra/zebra_snmp.c index 48218effd1..3ab208d30b 100644 --- a/zebra/zebra_snmp.c +++ b/zebra/zebra_snmp.c @@ -285,8 +285,8 @@ static void check_replace(struct route_node *np2, struct route_entry *re2, return; } - if (in_addr_cmp((u_char *)&(*re)->nexthop->gate.ipv4, - (u_char *)&re2->nexthop->gate.ipv4) + if (in_addr_cmp((u_char *)&(*re)->ng.nexthop->gate.ipv4, + (u_char *)&re2->ng.nexthop->gate.ipv4) <= 0) return; @@ -370,9 +370,9 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], for (*np = route_top(table); *np; *np = route_next(*np)) { if (!in_addr_cmp(&(*np)->p.u.prefix, (u_char *)&dest)) { RNODE_FOREACH_RE (*np, *re) { - if (!in_addr_cmp((u_char *)&(*re) - ->nexthop->gate - .ipv4, + if (!in_addr_cmp( + (u_char *)&(*re) + ->ng.nexthop->gate.ipv4, (u_char *)&nexthop)) if (proto == proto_trans((*re)->type)) @@ -404,9 +404,10 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], if ((policy < policy2) || ((policy == policy2) && (proto < proto2)) || ((policy == policy2) && (proto == proto2) - && (in_addr_cmp((u_char *)&re2->nexthop - ->gate.ipv4, - (u_char *)&nexthop) + && (in_addr_cmp( + (u_char *)&re2->ng.nexthop + ->gate.ipv4, + (u_char *)&nexthop) >= 0))) check_replace(np2, re2, np, re); } @@ -430,7 +431,7 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], { struct nexthop *nexthop; - nexthop = (*re)->nexthop; + nexthop = (*re)->ng.nexthop; if (nexthop) { pnt = (u_char *)&nexthop->gate.ipv4; for (i = 0; i < 4; i++) @@ -459,7 +460,7 @@ static u_char *ipFwTable(struct variable *v, oid objid[], size_t *objid_len, if (!np) return NULL; - nexthop = re->nexthop; + nexthop = re->ng.nexthop; if (!nexthop) return NULL; diff --git a/zebra/zebra_static.c b/zebra/zebra_static.c index b42bd818af..f3921790a6 100644 --- a/zebra/zebra_static.c +++ b/zebra/zebra_static.c @@ -103,8 +103,8 @@ void static_install_route(afi_t afi, safi_t safi, struct prefix *p, re, si->ifindex, si->nh_vrf_id); break; case STATIC_BLACKHOLE: - nexthop = route_entry_nexthop_blackhole_add( - re, bh_type); + nexthop = + route_entry_nexthop_blackhole_add(re, bh_type); break; case STATIC_IPV6_GATEWAY: nexthop = route_entry_nexthop_ipv6_add( @@ -182,8 +182,8 @@ void static_install_route(afi_t afi, safi_t safi, struct prefix *p, re, si->ifindex, si->nh_vrf_id); break; case STATIC_BLACKHOLE: - nexthop = route_entry_nexthop_blackhole_add( - re, bh_type); + nexthop = + route_entry_nexthop_blackhole_add(re, bh_type); break; case STATIC_IPV6_GATEWAY: nexthop = route_entry_nexthop_ipv6_add( @@ -300,7 +300,7 @@ void static_uninstall_route(afi_t afi, safi_t safi, struct prefix *p, } /* Lookup nexthop. */ - for (nexthop = re->nexthop; nexthop; nexthop = nexthop->next) + for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) if (static_nexthop_same(nexthop, si)) break; @@ -393,16 +393,14 @@ int static_add_route(afi_t afi, safi_t safi, u_char type, struct prefix *p, if (!stable) return -1; - if (!gate - && (type == STATIC_IPV4_GATEWAY - || type == STATIC_IPV4_GATEWAY_IFNAME - || type == STATIC_IPV6_GATEWAY - || type == STATIC_IPV6_GATEWAY_IFNAME)) + if (!gate && (type == STATIC_IPV4_GATEWAY + || type == STATIC_IPV4_GATEWAY_IFNAME + || type == STATIC_IPV6_GATEWAY + || type == STATIC_IPV6_GATEWAY_IFNAME)) return -1; if (!ifname - && (type == STATIC_IFNAME - || type == STATIC_IPV4_GATEWAY_IFNAME + && (type == STATIC_IFNAME || type == STATIC_IPV4_GATEWAY_IFNAME || type == STATIC_IPV6_GATEWAY_IFNAME)) return -1; @@ -412,11 +410,12 @@ int static_add_route(afi_t afi, safi_t safi, u_char type, struct prefix *p, /* Do nothing if there is a same static route. */ for (si = rn->info; si; si = si->next) { if (type == si->type - && (!gate || ((afi == AFI_IP - && IPV4_ADDR_SAME(&gate->ipv4, &si->addr.ipv4)) - || (afi == AFI_IP6 - && IPV6_ADDR_SAME(gate, &si->addr.ipv6)))) - && (!strcmp (ifname ? ifname : "", si->ifname))) { + && (!gate + || ((afi == AFI_IP + && IPV4_ADDR_SAME(&gate->ipv4, &si->addr.ipv4)) + || (afi == AFI_IP6 + && IPV6_ADDR_SAME(gate, &si->addr.ipv6)))) + && (!strcmp(ifname ? ifname : "", si->ifname))) { if ((distance == si->distance) && (tag == si->tag) && !memcmp(&si->snh_label, snh_label, sizeof(struct static_nh_label)) @@ -531,10 +530,11 @@ int static_delete_route(afi_t afi, safi_t safi, u_char type, struct prefix *p, /* Find same static route is the tree */ for (si = rn->info; si; si = si->next) if (type == si->type - && (!gate || ((afi == AFI_IP - && IPV4_ADDR_SAME(&gate->ipv4, &si->addr.ipv4)) - || (afi == AFI_IP6 - && IPV6_ADDR_SAME(gate, &si->addr.ipv6)))) + && (!gate + || ((afi == AFI_IP + && IPV4_ADDR_SAME(&gate->ipv4, &si->addr.ipv4)) + || (afi == AFI_IP6 + && IPV6_ADDR_SAME(gate, &si->addr.ipv6)))) && (!strcmp(ifname ? ifname : "", si->ifname)) && (!tag || (tag == si->tag)) && (!snh_label->num_labels @@ -569,8 +569,8 @@ int static_delete_route(afi_t afi, safi_t safi, u_char type, struct prefix *p, return 1; } -static void static_ifindex_update_af(struct interface *ifp, bool up, - afi_t afi, safi_t safi) +static void static_ifindex_update_af(struct interface *ifp, bool up, afi_t afi, + safi_t safi) { struct route_table *stable; struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id); @@ -598,8 +598,7 @@ static void static_ifindex_update_af(struct interface *ifp, bool up, } else { if (si->ifindex != ifp->ifindex) continue; - static_uninstall_route(afi, safi, p, src_p, - si); + static_uninstall_route(afi, safi, p, src_p, si); si->ifindex = IFINDEX_INTERNAL; } } diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index bb15fd04f3..9e13f4ed6e 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -111,8 +111,8 @@ static int zebra_vrf_enable(struct vrf *vrf) assert(zvrf); if (IS_ZEBRA_DEBUG_EVENT) - zlog_debug("VRF %s id %u is now active", - zvrf_name(zvrf), zvrf_id(zvrf)); + zlog_debug("VRF %s id %u is now active", zvrf_name(zvrf), + zvrf_id(zvrf)); if (vrf_is_backend_netns()) zvrf->zns = zebra_ns_lookup((ns_id_t)vrf->vrf_id); @@ -182,8 +182,8 @@ static int zebra_vrf_disable(struct vrf *vrf) assert(zvrf); if (IS_ZEBRA_DEBUG_EVENT) - zlog_debug("VRF %s id %u is now inactive", - zvrf_name(zvrf), zvrf_id(zvrf)); + zlog_debug("VRF %s id %u is now inactive", zvrf_name(zvrf), + zvrf_id(zvrf)); /* Uninstall any static routes configured for this VRF. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) @@ -221,7 +221,8 @@ static int zebra_vrf_disable(struct vrf *vrf) zebra_mpls_cleanup_tables(zvrf); zebra_pw_exit(zvrf); - /* Remove link-local IPv4 addresses created for BGP unnumbered peering. */ + /* Remove link-local IPv4 addresses created for BGP unnumbered peering. + */ FOR_ALL_INTERFACES (vrf, ifp) if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp); @@ -231,8 +232,8 @@ static int zebra_vrf_disable(struct vrf *vrf) struct route_node *rnode; rib_dest_t *dest; - for (ALL_LIST_ELEMENTS(zebrad.mq->subq[i], - lnode, nnode, rnode)) { + for (ALL_LIST_ELEMENTS(zebrad.mq->subq[i], lnode, nnode, + rnode)) { dest = rib_dest_from_rnode(rnode); if (dest && rib_dest_vrf(dest) == zvrf) { route_unlock_node(rnode); @@ -273,8 +274,8 @@ static int zebra_vrf_delete(struct vrf *vrf) assert(zvrf); if (IS_ZEBRA_DEBUG_EVENT) - zlog_debug("VRF %s id %u deleted", - zvrf_name(zvrf), zvrf_id(zvrf)); + zlog_debug("VRF %s id %u deleted", zvrf_name(zvrf), + zvrf_id(zvrf)); /* clean-up work queues */ for (i = 0; i < MQ_SIZE; i++) { @@ -282,7 +283,8 @@ static int zebra_vrf_delete(struct vrf *vrf) struct route_node *rnode; rib_dest_t *dest; - for (ALL_LIST_ELEMENTS(zebrad.mq->subq[i], lnode, nnode, rnode)) { + for (ALL_LIST_ELEMENTS(zebrad.mq->subq[i], lnode, nnode, + rnode)) { dest = rib_dest_from_rnode(rnode); if (dest && rib_dest_vrf(dest) == zvrf) { route_unlock_node(rnode); @@ -560,10 +562,11 @@ static int vrf_config_write(struct vty *vty) if (vrf_is_user_cfged(vrf)) { vty_out(vty, "vrf %s\n", zvrf_name(zvrf)); if (zvrf->l3vni) - vty_out(vty, " vni %u%s\n", - zvrf->l3vni, - is_l3vni_for_prefix_routes_only(zvrf->l3vni) ? - " prefix-routes-only" :""); + vty_out(vty, " vni %u%s\n", zvrf->l3vni, + is_l3vni_for_prefix_routes_only( + zvrf->l3vni) + ? " prefix-routes-only" + : ""); zebra_ns_config_write(vty, (struct ns *)vrf->ns_ctxt); vty_out(vty, "!\n"); } @@ -581,8 +584,8 @@ static int vrf_config_write(struct vty *vty) /* Zebra VRF initialization. */ void zebra_vrf_init(void) { - vrf_init(zebra_vrf_new, zebra_vrf_enable, - zebra_vrf_disable, zebra_vrf_delete); + vrf_init(zebra_vrf_new, zebra_vrf_enable, zebra_vrf_disable, + zebra_vrf_delete); vrf_cmd_init(vrf_config_write); } diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 4824c09f3d..9fe3c707bb 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -69,25 +69,20 @@ static void vty_show_ip_route_summary_prefix(struct vty *vty, /* * special macro to allow us to get the correct zebra_vrf */ -#define ZEBRA_DECLVAR_CONTEXT(A, B) \ - struct vrf *A = VTY_GET_CONTEXT(vrf); \ - struct zebra_vrf *B = \ - (vrf) ? vrf->info : NULL; \ +#define ZEBRA_DECLVAR_CONTEXT(A, B) \ + struct vrf *A = VTY_GET_CONTEXT(vrf); \ + struct zebra_vrf *B = (vrf) ? vrf->info : NULL; /* VNI range as per RFC 7432 */ #define CMD_VNI_RANGE "(1-16777215)" /* General function for static route. */ -static int zebra_static_route_leak(struct vty *vty, - struct zebra_vrf *zvrf, - struct zebra_vrf *nh_zvrf, - afi_t afi, safi_t safi, - const char *negate, const char *dest_str, - const char *mask_str, const char *src_str, - const char *gate_str, const char *ifname, - const char *flag_str, const char *tag_str, - const char *distance_str, - const char *label_str) +static int zebra_static_route_leak( + struct vty *vty, struct zebra_vrf *zvrf, struct zebra_vrf *nh_zvrf, + afi_t afi, safi_t safi, const char *negate, const char *dest_str, + const char *mask_str, const char *src_str, const char *gate_str, + const char *ifname, const char *flag_str, const char *tag_str, + const char *distance_str, const char *label_str) { int ret; u_char distance; @@ -180,10 +175,11 @@ static int zebra_static_route_leak(struct vty *vty, /* Null0 static route. */ if (ifname != NULL) { - if (strncasecmp(ifname, "Null0", strlen(ifname)) == 0 || - strncasecmp(ifname, "reject", strlen(ifname)) == 0 || - strncasecmp(ifname, "blackhole", strlen(ifname)) == 0) { - vty_out(vty, "%% Nexthop interface cannot be Null0, reject or blackhole\n"); + if (strncasecmp(ifname, "Null0", strlen(ifname)) == 0 + || strncasecmp(ifname, "reject", strlen(ifname)) == 0 + || strncasecmp(ifname, "blackhole", strlen(ifname)) == 0) { + vty_out(vty, + "%% Nexthop interface cannot be Null0, reject or blackhole\n"); return CMD_WARNING_CONFIG_FAILED; } } @@ -249,12 +245,12 @@ static int zebra_static_route_leak(struct vty *vty, } static int zebra_static_route(struct vty *vty, afi_t afi, safi_t safi, - const char *negate, const char *dest_str, - const char *mask_str, const char *src_str, - const char *gate_str, const char *ifname, - const char *flag_str, const char *tag_str, - const char *distance_str, const char *vrf_name, - const char *label_str) + const char *negate, const char *dest_str, + const char *mask_str, const char *src_str, + const char *gate_str, const char *ifname, + const char *flag_str, const char *tag_str, + const char *distance_str, const char *vrf_name, + const char *label_str) { struct zebra_vrf *zvrf; struct vrf *vrf; @@ -286,10 +282,9 @@ static int zebra_static_route(struct vty *vty, afi_t afi, safi_t safi, /* Mark as having FRR configuration */ vrf_set_user_cfged(vrf); } - return zebra_static_route_leak(vty, zvrf, zvrf, afi, safi, - negate, dest_str, mask_str, src_str, - gate_str, ifname, flag_str, tag_str, - distance_str, label_str); + return zebra_static_route_leak( + vty, zvrf, zvrf, afi, safi, negate, dest_str, mask_str, src_str, + gate_str, ifname, flag_str, tag_str, distance_str, label_str); } @@ -429,8 +424,8 @@ DEFPY(ip_route_blackhole, MPLS_LABEL_HELPSTR) { return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, no, prefix, - mask_str, NULL, NULL, NULL, flag, - tag_str, distance_str, vrf, label); + mask_str, NULL, NULL, NULL, flag, tag_str, + distance_str, vrf, label); } DEFPY(ip_route_blackhole_vrf, @@ -464,10 +459,9 @@ DEFPY(ip_route_blackhole_vrf, * valid. Add an assert to make it happy */ assert(prefix); - return zebra_static_route_leak(vty, zvrf, zvrf, - AFI_IP, SAFI_UNICAST, no, prefix, - mask_str, NULL, NULL, NULL, flag, - tag_str, distance_str, label); + return zebra_static_route_leak(vty, zvrf, zvrf, AFI_IP, SAFI_UNICAST, + no, prefix, mask_str, NULL, NULL, NULL, + flag, tag_str, distance_str, label); } DEFPY(ip_route_address_interface, @@ -509,8 +503,7 @@ DEFPY(ip_route_address_interface, zvrf = zebra_vrf_lookup_by_name(vrf); if (!zvrf) { - vty_out(vty, "%% vrf %s is not defined\n", - vrf); + vty_out(vty, "%% vrf %s is not defined\n", vrf); return CMD_WARNING_CONFIG_FAILED; } @@ -520,15 +513,13 @@ DEFPY(ip_route_address_interface, nh_zvrf = zvrf; if (!nh_zvrf) { - vty_out(vty, "%% nexthop vrf %s is not defined\n", - nexthop_vrf); + vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf); return CMD_WARNING_CONFIG_FAILED; } - return zebra_static_route_leak(vty, zvrf, nh_zvrf, - AFI_IP, SAFI_UNICAST, no, prefix, - mask_str, NULL, gate_str, ifname, flag, - tag_str, distance_str, label); + return zebra_static_route_leak( + vty, zvrf, nh_zvrf, AFI_IP, SAFI_UNICAST, no, prefix, mask_str, + NULL, gate_str, ifname, flag, tag_str, distance_str, label); } DEFPY(ip_route_address_interface_vrf, @@ -573,15 +564,13 @@ DEFPY(ip_route_address_interface_vrf, nh_zvrf = zvrf; if (!nh_zvrf) { - vty_out(vty, "%% nexthop vrf %s is not defined\n", - nexthop_vrf); + vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf); return CMD_WARNING_CONFIG_FAILED; } - return zebra_static_route_leak(vty, zvrf, nh_zvrf, - AFI_IP, SAFI_UNICAST, no, prefix, - mask_str, NULL, gate_str, ifname, flag, - tag_str, distance_str, label); + return zebra_static_route_leak( + vty, zvrf, nh_zvrf, AFI_IP, SAFI_UNICAST, no, prefix, mask_str, + NULL, gate_str, ifname, flag, tag_str, distance_str, label); } DEFPY(ip_route, @@ -621,8 +610,7 @@ DEFPY(ip_route, zvrf = zebra_vrf_lookup_by_name(vrf); if (!zvrf) { - vty_out(vty, "%% vrf %s is not defined\n", - vrf); + vty_out(vty, "%% vrf %s is not defined\n", vrf); return CMD_WARNING_CONFIG_FAILED; } @@ -632,16 +620,14 @@ DEFPY(ip_route, nh_zvrf = zvrf; if (!nh_zvrf) { - vty_out(vty, "%% nexthop vrf %s is not defined\n", - nexthop_vrf); + vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf); return CMD_WARNING_CONFIG_FAILED; } - return zebra_static_route_leak(vty, zvrf, nh_zvrf, - AFI_IP, SAFI_UNICAST, no, prefix, - mask_str, NULL, gate_str, ifname, flag, - tag_str, distance_str, label); + return zebra_static_route_leak( + vty, zvrf, nh_zvrf, AFI_IP, SAFI_UNICAST, no, prefix, mask_str, + NULL, gate_str, ifname, flag, tag_str, distance_str, label); } DEFPY(ip_route_vrf, @@ -684,15 +670,13 @@ DEFPY(ip_route_vrf, nh_zvrf = zvrf; if (!nh_zvrf) { - vty_out(vty, "%% nexthop vrf %s is not defined\n", - nexthop_vrf); + vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf); return CMD_WARNING_CONFIG_FAILED; } - return zebra_static_route_leak(vty, zvrf, nh_zvrf, - AFI_IP, SAFI_UNICAST, no, prefix, - mask_str, NULL, gate_str, ifname, flag, - tag_str, distance_str, label); + return zebra_static_route_leak( + vty, zvrf, nh_zvrf, AFI_IP, SAFI_UNICAST, no, prefix, mask_str, + NULL, gate_str, ifname, flag, tag_str, distance_str, label); } /* New RIB. Detailed information for IPv4 route. */ @@ -748,24 +732,26 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, vty_out(vty, " Last update "); if (uptime < ONE_DAY_SECOND) - vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, - tm->tm_min, tm->tm_sec); + vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, + tm->tm_sec); else if (uptime < ONE_WEEK_SECOND) - vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, - tm->tm_hour, tm->tm_min); + vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, + tm->tm_min); else vty_out(vty, "%02dw%dd%02dh", tm->tm_yday / 7, tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour); vty_out(vty, " ago\n"); - for (ALL_NEXTHOPS(re->nexthop, nexthop)) { + for (ALL_NEXTHOPS(re->ng, nexthop)) { char addrstr[32]; vty_out(vty, " %c%s", CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB) - ? CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE) - ? ' ' : '*' + ? CHECK_FLAG(nexthop->flags, + NEXTHOP_FLAG_DUPLICATE) + ? ' ' + : '*' : ' ', nexthop->rparent ? " " : ""); @@ -924,11 +910,11 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, } if (uptime < ONE_DAY_SECOND) - sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, - tm->tm_min, tm->tm_sec); + sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, + tm->tm_sec); else if (uptime < ONE_WEEK_SECOND) - sprintf(buf, "%dd%02dh%02dm", tm->tm_yday, - tm->tm_hour, tm->tm_min); + sprintf(buf, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, + tm->tm_min); else sprintf(buf, "%02dw%dd%02dh", tm->tm_yday / 7, tm->tm_yday - ((tm->tm_yday / 7) * 7), @@ -936,7 +922,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, json_object_string_add(json_route, "uptime", buf); - for (ALL_NEXTHOPS(re->nexthop, nexthop)) { + for (ALL_NEXTHOPS(re->ng, nexthop)) { json_nexthop = json_object_new_object(); if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE)) @@ -1028,8 +1014,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, struct vrf *vrf = vrf_lookup_by_id(nexthop->vrf_id); - json_object_string_add(json_nexthop, - "vrf", + json_object_string_add(json_nexthop, "vrf", vrf->name); } if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE)) @@ -1103,8 +1088,8 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, } /* Nexthop information. */ - for (ALL_NEXTHOPS(re->nexthop, nexthop)) { - if (nexthop == re->nexthop) { + for (ALL_NEXTHOPS(re->ng, nexthop)) { + if (nexthop == re->ng.nexthop) { /* Prefix information. */ len = vty_out(vty, "%c", zebra_route_char(re->type)); if (re->instance) @@ -1126,8 +1111,10 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, } else { vty_out(vty, " %c%*c", CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB) - ? CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE) - ? ' ' : '*' + ? CHECK_FLAG(nexthop->flags, + NEXTHOP_FLAG_DUPLICATE) + ? ' ' + : '*' : ' ', len - 3 + (2 * nexthop_level(nexthop)), ' '); } @@ -1259,8 +1246,7 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, dest = rib_dest_from_rnode(rn); RNODE_FOREACH_RE (rn, re) { - if (use_fib - && re != dest->selected_fib) + if (use_fib && re != dest->selected_fib) continue; if (tag && re->tag != tag) @@ -1663,7 +1649,7 @@ DEFPY (show_route_detail, struct vrf *vrf; struct zebra_vrf *zvrf; - RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) { + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { if ((zvrf = vrf->info) == NULL || (table = zvrf->table[afi][SAFI_UNICAST]) == NULL) continue; @@ -1737,7 +1723,7 @@ DEFPY (show_route_summary, struct vrf *vrf; struct zebra_vrf *zvrf; - RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) { + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { if ((zvrf = vrf->info) == NULL || (table = zvrf->table[afi][SAFI_UNICAST]) == NULL) continue; @@ -1856,7 +1842,7 @@ static void vty_show_ip_route_summary_prefix(struct vty *vty, * In case of ECMP, count only once. */ cnt = 0; - for (nexthop = re->nexthop; (!cnt && nexthop); + for (nexthop = re->ng.nexthop; (!cnt && nexthop); nexthop = nexthop->next) { cnt++; rib_cnt[ZEBRA_ROUTE_TOTAL]++; @@ -1905,8 +1891,8 @@ static void vty_show_ip_route_summary_prefix(struct vty *vty, } /* Write static route configuration. */ -int static_config(struct vty *vty, struct zebra_vrf *zvrf, - afi_t afi, safi_t safi, const char *cmd) +int static_config(struct vty *vty, struct zebra_vrf *zvrf, afi_t afi, + safi_t safi, const char *cmd) { char spacing[100]; struct route_node *rn; @@ -1918,8 +1904,7 @@ int static_config(struct vty *vty, struct zebra_vrf *zvrf, if ((stable = zvrf->stable[afi][safi]) == NULL) return write; - sprintf(spacing, "%s%s", - (zvrf->vrf->vrf_id == VRF_DEFAULT) ? "" : " ", + sprintf(spacing, "%s%s", (zvrf->vrf->vrf_id == VRF_DEFAULT) ? "" : " ", cmd); for (rn = route_top(stable); rn; rn = srcdest_route_next(rn)) @@ -1929,13 +1914,11 @@ int static_config(struct vty *vty, struct zebra_vrf *zvrf, switch (si->type) { case STATIC_IPV4_GATEWAY: - vty_out(vty, " %s", - inet_ntoa(si->addr.ipv4)); + vty_out(vty, " %s", inet_ntoa(si->addr.ipv4)); break; case STATIC_IPV6_GATEWAY: vty_out(vty, " %s", - inet_ntop(AF_INET6, - &si->addr.ipv6, buf, + inet_ntop(AF_INET6, &si->addr.ipv6, buf, sizeof buf)); break; case STATIC_IFNAME: @@ -1956,26 +1939,22 @@ int static_config(struct vty *vty, struct zebra_vrf *zvrf, break; case STATIC_IPV4_GATEWAY_IFNAME: vty_out(vty, " %s %s", - inet_ntop(AF_INET, - &si->addr.ipv4, buf, + inet_ntop(AF_INET, &si->addr.ipv4, buf, sizeof buf), si->ifname); break; case STATIC_IPV6_GATEWAY_IFNAME: vty_out(vty, " %s %s", - inet_ntop(AF_INET6, - &si->addr.ipv6, buf, + inet_ntop(AF_INET6, &si->addr.ipv6, buf, sizeof buf), si->ifname); break; } if (si->tag) - vty_out(vty, " tag %" ROUTE_TAG_PRI, - si->tag); + vty_out(vty, " tag %" ROUTE_TAG_PRI, si->tag); - if (si->distance - != ZEBRA_STATIC_DISTANCE_DEFAULT) + if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT) vty_out(vty, " %d", si->distance); if (si->nh_vrf_id != si->vrf_id) { @@ -1990,8 +1969,8 @@ int static_config(struct vty *vty, struct zebra_vrf *zvrf, if (si->snh_label.num_labels) vty_out(vty, " label %s", mpls_label2str(si->snh_label.num_labels, - si->snh_label.label, - buf, sizeof buf, 0)); + si->snh_label.label, buf, + sizeof buf, 0)); vty_out(vty, "\n"); @@ -2026,8 +2005,8 @@ DEFPY(ipv6_route_blackhole, MPLS_LABEL_HELPSTR) { return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, no, prefix_str, - NULL, from_str, NULL, NULL, flag, - tag_str, distance_str, vrf, label); + NULL, from_str, NULL, NULL, flag, tag_str, + distance_str, vrf, label); } DEFPY(ipv6_route_blackhole_vrf, @@ -2062,10 +2041,9 @@ DEFPY(ipv6_route_blackhole_vrf, * valid. Add an assert to make it happy */ assert(prefix); - return zebra_static_route_leak(vty, zvrf, zvrf, - AFI_IP6, SAFI_UNICAST, no, prefix_str, - NULL, from_str, NULL, NULL, flag, - tag_str, distance_str, label); + return zebra_static_route_leak( + vty, zvrf, zvrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL, + from_str, NULL, NULL, flag, tag_str, distance_str, label); } DEFPY(ipv6_route_address_interface, @@ -2100,8 +2078,7 @@ DEFPY(ipv6_route_address_interface, zvrf = zebra_vrf_lookup_by_name(vrf); if (!zvrf) { - vty_out(vty, "%% vrf %s is not defined\n", - vrf); + vty_out(vty, "%% vrf %s is not defined\n", vrf); return CMD_WARNING_CONFIG_FAILED; } @@ -2111,15 +2088,13 @@ DEFPY(ipv6_route_address_interface, nh_zvrf = zvrf; if (!nh_zvrf) { - vty_out(vty, "%% nexthop vrf %s is not defined\n", - nexthop_vrf); + vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf); return CMD_WARNING_CONFIG_FAILED; } - return zebra_static_route_leak(vty, zvrf, nh_zvrf, - AFI_IP6, SAFI_UNICAST, no, prefix_str, - NULL, from_str, gate_str, ifname, NULL, - tag_str, distance_str, label); + return zebra_static_route_leak( + vty, zvrf, nh_zvrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL, + from_str, gate_str, ifname, NULL, tag_str, distance_str, label); } DEFPY(ipv6_route_address_interface_vrf, @@ -2157,15 +2132,13 @@ DEFPY(ipv6_route_address_interface_vrf, nh_zvrf = zvrf; if (!nh_zvrf) { - vty_out(vty, "%% nexthop vrf %s is not defined\n", - nexthop_vrf); + vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf); return CMD_WARNING_CONFIG_FAILED; } - return zebra_static_route_leak(vty, zvrf, nh_zvrf, - AFI_IP6, SAFI_UNICAST, no, prefix_str, - NULL, from_str, gate_str, ifname, NULL, - tag_str, distance_str, label); + return zebra_static_route_leak( + vty, zvrf, nh_zvrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL, + from_str, gate_str, ifname, NULL, tag_str, distance_str, label); } DEFPY(ipv6_route, @@ -2199,8 +2172,7 @@ DEFPY(ipv6_route, zvrf = zebra_vrf_lookup_by_name(vrf); if (!zvrf) { - vty_out(vty, "%% vrf %s is not defined\n", - vrf); + vty_out(vty, "%% vrf %s is not defined\n", vrf); return CMD_WARNING_CONFIG_FAILED; } @@ -2210,15 +2182,13 @@ DEFPY(ipv6_route, nh_zvrf = zvrf; if (!nh_zvrf) { - vty_out(vty, "%% nexthop vrf %s is not defined\n", - nexthop_vrf); + vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf); return CMD_WARNING_CONFIG_FAILED; } - return zebra_static_route_leak(vty, zvrf, nh_zvrf, - AFI_IP6, SAFI_UNICAST, no, prefix_str, - NULL, from_str, gate_str, ifname, NULL, - tag_str, distance_str, label); + return zebra_static_route_leak( + vty, zvrf, nh_zvrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL, + from_str, gate_str, ifname, NULL, tag_str, distance_str, label); } DEFPY(ipv6_route_vrf, @@ -2255,15 +2225,13 @@ DEFPY(ipv6_route_vrf, nh_zvrf = zvrf; if (!nh_zvrf) { - vty_out(vty, "%% nexthop vrf %s is not defined\n", - nexthop_vrf); + vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf); return CMD_WARNING_CONFIG_FAILED; } - return zebra_static_route_leak(vty, zvrf, nh_zvrf, - AFI_IP6, SAFI_UNICAST, no, prefix_str, - NULL, from_str, gate_str, ifname, NULL, - tag_str, distance_str, label); + return zebra_static_route_leak( + vty, zvrf, nh_zvrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL, + from_str, gate_str, ifname, NULL, tag_str, distance_str, label); } /* @@ -2374,12 +2342,11 @@ DEFUN (show_vrf, continue; vty_out(vty, "vrf %s ", zvrf_name(zvrf)); - if (zvrf_id(zvrf) == VRF_UNKNOWN - || !zvrf_is_active(zvrf)) + if (zvrf_id(zvrf) == VRF_UNKNOWN || !zvrf_is_active(zvrf)) vty_out(vty, "inactive"); else if (zvrf_ns_name(zvrf)) - vty_out(vty, "id %u netns %s", - zvrf_id(zvrf), zvrf_ns_name(zvrf)); + vty_out(vty, "id %u netns %s", zvrf_id(zvrf), + zvrf_ns_name(zvrf)); else vty_out(vty, "id %u table %u", zvrf_id(zvrf), zvrf->table_id); @@ -2528,10 +2495,10 @@ DEFUN (show_vrf_vni, } if (!uj) - vty_out(vty, "%-37s %-10s %-20s %-20s %-5s %-18s\n", - "VRF", "VNI", "VxLAN IF", "L3-SVI", "State", "Rmac"); + vty_out(vty, "%-37s %-10s %-20s %-20s %-5s %-18s\n", "VRF", + "VNI", "VxLAN IF", "L3-SVI", "State", "Rmac"); - RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) { + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { zvrf = vrf->info; if (!zvrf) continue; @@ -3029,10 +2996,10 @@ DEFUN_HIDDEN (zebra_workqueue_timer, "Work Queue\n" "Time in milliseconds\n") { - uint32_t timer = strtoul(argv[2]->arg, NULL, 10); - zebrad.ribq->spec.hold = timer; + uint32_t timer = strtoul(argv[2]->arg, NULL, 10); + zebrad.ribq->spec.hold = timer; - return CMD_SUCCESS; + return CMD_SUCCESS; } DEFUN_HIDDEN (no_zebra_workqueue_timer, @@ -3043,9 +3010,9 @@ DEFUN_HIDDEN (no_zebra_workqueue_timer, "Work Queue\n" "Time in milliseconds\n") { - zebrad.ribq->spec.hold = ZEBRA_RIB_PROCESS_HOLD_TIME; + zebrad.ribq->spec.hold = ZEBRA_RIB_PROCESS_HOLD_TIME; - return CMD_SUCCESS; + return CMD_SUCCESS; } DEFUN (no_ip_zebra_import_table, @@ -3097,8 +3064,8 @@ static int config_write_protocol(struct vty *vty) vty_out(vty, "zebra work-queue %u\n", zebrad.ribq->spec.hold); if (zebrad.packets_to_process != ZEBRA_ZAPI_PACKETS_TO_PROCESS) - vty_out(vty, - "zebra zapi-packets %u\n", zebrad.packets_to_process); + vty_out(vty, "zebra zapi-packets %u\n", + zebrad.packets_to_process); enum multicast_mode ipv4_multicast_mode = multicast_mode_ipv4_get(); @@ -3168,7 +3135,7 @@ DEFUN (show_zebra, vty_out(vty, "VRF Installs Removals Updates Installs Removals\n"); - RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) { + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { struct zebra_vrf *zvrf = vrf->info; vty_out(vty, "%-25s %10" PRIu64 " %10" PRIu64 " %10" PRIu64 @@ -3442,5 +3409,4 @@ void zebra_vty_init(void) install_element(CONFIG_NODE, &no_default_vrf_vni_mapping_cmd); install_element(VRF_NODE, &vrf_vni_mapping_cmd); install_element(VRF_NODE, &no_vrf_vni_mapping_cmd); - } diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index e07dc6059f..d3ede66fb0 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -58,9 +58,8 @@ DEFINE_MTYPE_STATIC(ZEBRA, NEIGH, "VNI Neighbor"); /* static function declarations */ -static int ip_prefix_send_to_client(vrf_id_t vrf_id, - struct prefix *p, - uint16_t cmd); +static int ip_prefix_send_to_client(vrf_id_t vrf_id, struct prefix *p, + uint16_t cmd); static void zvni_print_neigh(zebra_neigh_t *n, void *ctxt, json_object *json); static void zvni_print_neigh_hash(struct hash_backet *backet, void *ctxt); static void zvni_print_neigh_hash_all_vni(struct hash_backet *backet, @@ -75,8 +74,7 @@ static void zvni_print_mac_hash_all_vni(struct hash_backet *backet, void *ctxt); static void zvni_print(zebra_vni_t *zvni, void **ctxt); static void zvni_print_hash(struct hash_backet *backet, void *ctxt[]); -static int zvni_macip_send_msg_to_client(vni_t vni, - struct ethaddr *macaddr, +static int zvni_macip_send_msg_to_client(vni_t vni, struct ethaddr *macaddr, struct ipaddr *ip, u_char flags, u_int16_t cmd); static unsigned int neigh_hash_keymake(void *p); @@ -88,21 +86,18 @@ static int zvni_neigh_del(zebra_vni_t *zvni, zebra_neigh_t *n); static int zvni_neigh_del_hash_entry(struct hash_backet *backet, void *arg); static void zvni_neigh_del_from_vtep(zebra_vni_t *zvni, int uninstall, struct in_addr *r_vtep_ip); -static void zvni_neigh_del_all(zebra_vni_t *zvni, - int uninstall, int upd_client, u_int32_t flags); +static void zvni_neigh_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, + u_int32_t flags); static zebra_neigh_t *zvni_neigh_lookup(zebra_vni_t *zvni, struct ipaddr *ip); -static int zvni_neigh_send_add_to_client(vni_t vni, - struct ipaddr *ip, +static int zvni_neigh_send_add_to_client(vni_t vni, struct ipaddr *ip, struct ethaddr *macaddr, u_char flags); -static int zvni_neigh_send_del_to_client(vni_t vni, - struct ipaddr *ip, +static int zvni_neigh_send_del_to_client(vni_t vni, struct ipaddr *ip, struct ethaddr *macaddr, u_char flags); static int zvni_neigh_install(zebra_vni_t *zvni, zebra_neigh_t *n); static int zvni_neigh_uninstall(zebra_vni_t *zvni, zebra_neigh_t *n); static zebra_vni_t *zvni_from_svi(struct interface *ifp, - struct interface *br_if); -static struct interface *zvni_map_to_svi(vlanid_t vid, - struct interface *br_if); + struct interface *br_if); +static struct interface *zvni_map_to_svi(vlanid_t vid, struct interface *br_if); /* l3-vni next-hop neigh related APIs */ static zebra_neigh_t *zl3vni_nh_lookup(zebra_l3vni_t *zl3vni, @@ -124,8 +119,7 @@ static zebra_mac_t *zl3vni_rmac_add(zebra_l3vni_t *zl3vni, struct ethaddr *rmac); static int zl3vni_rmac_del(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac); static int zl3vni_rmac_install(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac); -static int zl3vni_rmac_uninstall(zebra_l3vni_t *zl3vni, - zebra_mac_t *zrmac); +static int zl3vni_rmac_uninstall(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac); /* l3-vni related APIs*/ static zebra_l3vni_t *zl3vni_lookup(vni_t vni); @@ -146,13 +140,13 @@ static int zvni_mac_del(zebra_vni_t *zvni, zebra_mac_t *mac); static int zvni_mac_del_hash_entry(struct hash_backet *backet, void *arg); static void zvni_mac_del_from_vtep(zebra_vni_t *zvni, int uninstall, struct in_addr *r_vtep_ip); -static void zvni_mac_del_all(zebra_vni_t *zvni, - int uninstall, int upd_client, u_int32_t flags); +static void zvni_mac_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, + u_int32_t flags); static zebra_mac_t *zvni_mac_lookup(zebra_vni_t *zvni, struct ethaddr *macaddr); -static int zvni_mac_send_add_to_client(vni_t vni, - struct ethaddr *macaddr, u_char flags); -static int zvni_mac_send_del_to_client(vni_t vni, - struct ethaddr *macaddr, u_char flags); +static int zvni_mac_send_add_to_client(vni_t vni, struct ethaddr *macaddr, + u_char flags); +static int zvni_mac_send_del_to_client(vni_t vni, struct ethaddr *macaddr, + u_char flags); static zebra_vni_t *zvni_map_vlan(struct interface *ifp, struct interface *br_if, vlanid_t vid); static int zvni_mac_install(zebra_vni_t *zvni, zebra_mac_t *mac); @@ -434,8 +428,7 @@ static void zvni_print_neigh_hash_all_vni(struct hash_backet *backet, } /* print a specific next hop for an l3vni */ -static void zl3vni_print_nh(zebra_neigh_t *n, - struct vty *vty, +static void zl3vni_print_nh(zebra_neigh_t *n, struct vty *vty, json_object *json) { char buf1[ETHER_ADDR_STRLEN]; @@ -448,7 +441,7 @@ static void zl3vni_print_nh(zebra_neigh_t *n, vty_out(vty, "Ip: %s\n", ipaddr2str(&n->ip, buf2, sizeof(buf2))); vty_out(vty, " RMAC: %s\n", - prefix_mac2str(&n->emac, buf1, sizeof(buf1))); + prefix_mac2str(&n->emac, buf1, sizeof(buf1))); vty_out(vty, " Refcount: %d\n", listcount(n->host_list)); vty_out(vty, " Prefixes:\n"); for (ALL_LIST_ELEMENTS_RO(n->host_list, node, p)) @@ -456,25 +449,22 @@ static void zl3vni_print_nh(zebra_neigh_t *n, prefix2str(p, buf2, sizeof(buf2))); } else { json_hosts = json_object_new_array(); - json_object_string_add(json, "ip", - ipaddr2str(&(n->ip), buf2, - sizeof(buf2))); - json_object_string_add(json, "routerMac", - prefix_mac2str(&n->emac, buf2, - sizeof(buf2))); + json_object_string_add( + json, "ip", ipaddr2str(&(n->ip), buf2, sizeof(buf2))); + json_object_string_add( + json, "routerMac", + prefix_mac2str(&n->emac, buf2, sizeof(buf2))); json_object_int_add(json, "refCount", listcount(n->host_list)); for (ALL_LIST_ELEMENTS_RO(n->host_list, node, p)) json_object_array_add(json_hosts, - json_object_new_string( - prefix2str(p, buf2, - sizeof(buf2)))); + json_object_new_string(prefix2str( + p, buf2, sizeof(buf2)))); json_object_object_add(json, "prefixList", json_hosts); } } /* Print a specific RMAC entry */ -static void zl3vni_print_rmac(zebra_mac_t *zrmac, - struct vty *vty, +static void zl3vni_print_rmac(zebra_mac_t *zrmac, struct vty *vty, json_object *json) { char buf1[ETHER_ADDR_STRLEN]; @@ -495,19 +485,17 @@ static void zl3vni_print_rmac(zebra_mac_t *zrmac, prefix2str(p, buf2, sizeof(buf2))); } else { json_hosts = json_object_new_array(); - json_object_string_add(json, "routerMac", - prefix_mac2str(&zrmac->macaddr, - buf1, - sizeof(buf1))); + json_object_string_add( + json, "routerMac", + prefix_mac2str(&zrmac->macaddr, buf1, sizeof(buf1))); json_object_string_add(json, "vtepIp", inet_ntoa(zrmac->fwd_info.r_vtep_ip)); json_object_int_add(json, "refCount", listcount(zrmac->host_list)); for (ALL_LIST_ELEMENTS_RO(zrmac->host_list, node, p)) json_object_array_add(json_hosts, - json_object_new_string( - prefix2str(p, buf2, - sizeof(buf2)))); + json_object_new_string(prefix2str( + p, buf2, sizeof(buf2)))); json_object_object_add(json, "prefixList", json_hosts); } } @@ -736,8 +724,7 @@ static void zvni_print_mac_hash_all_vni(struct hash_backet *backet, void *ctxt) } } -static void zl3vni_print_nh_hash(struct hash_backet *backet, - void *ctx) +static void zl3vni_print_nh_hash(struct hash_backet *backet, void *ctx) { struct nh_walk_ctx *wctx = NULL; struct vty *vty = NULL; @@ -763,9 +750,9 @@ static void zl3vni_print_nh_hash(struct hash_backet *backet, } else { json_object_string_add(json_nh, "nexthopIp", ipaddr2str(&n->ip, buf2, sizeof(buf2))); - json_object_string_add(json_nh, "routerMac", - prefix_mac2str(&n->emac, buf1, - sizeof(buf1))); + json_object_string_add( + json_nh, "routerMac", + prefix_mac2str(&n->emac, buf1, sizeof(buf1))); json_object_object_add(json_vni, ipaddr2str(&(n->ip), buf2, sizeof(buf2)), json_nh); @@ -803,8 +790,7 @@ static void zl3vni_print_nh_hash_all_vni(struct hash_backet *backet, } if (json == NULL) { - vty_out(vty, "\nVNI %u #Next-Hops %u\n\n", - zl3vni->vni, num_nh); + vty_out(vty, "\nVNI %u #Next-Hops %u\n\n", zl3vni->vni, num_nh); vty_out(vty, "%-15s %-17s\n", "IP", "RMAC"); } else json_object_int_add(json_vni, "numNextHops", num_nh); @@ -848,8 +834,7 @@ static void zl3vni_print_rmac_hash_all_vni(struct hash_backet *backet, } if (json == NULL) { - vty_out(vty, "\nVNI %u #RMACs %u\n\n", - zl3vni->vni, num_rmacs); + vty_out(vty, "\nVNI %u #RMACs %u\n\n", zl3vni->vni, num_rmacs); vty_out(vty, "%-17s %-21s\n", "RMAC", "Remote VTEP"); } else json_object_int_add(json_vni, "numRmacs", num_rmacs); @@ -866,8 +851,7 @@ static void zl3vni_print_rmac_hash_all_vni(struct hash_backet *backet, json_object_object_add(json, vni_str, json_vni); } -static void zl3vni_print_rmac_hash(struct hash_backet *backet, - void *ctx) +static void zl3vni_print_rmac_hash(struct hash_backet *backet, void *ctx) { zebra_mac_t *zrmac = NULL; struct rmac_walk_ctx *wctx = NULL; @@ -888,17 +872,16 @@ static void zl3vni_print_rmac_hash(struct hash_backet *backet, if (!json) { vty_out(vty, "%-17s %-21s\n", prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf)), - inet_ntoa(zrmac->fwd_info.r_vtep_ip)); + inet_ntoa(zrmac->fwd_info.r_vtep_ip)); } else { - json_object_string_add(json_rmac, "routerMac", - prefix_mac2str(&zrmac->macaddr, buf, - sizeof(buf))); + json_object_string_add( + json_rmac, "routerMac", + prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf))); json_object_string_add(json_rmac, "vtepIp", inet_ntoa(zrmac->fwd_info.r_vtep_ip)); - json_object_object_add(json, - prefix_mac2str(&zrmac->macaddr, buf, - sizeof(buf)), - json_rmac); + json_object_object_add( + json, prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf)), + json_rmac); } } @@ -918,19 +901,17 @@ static void zl3vni_print(zebra_l3vni_t *zl3vni, void **ctx) if (!json) { vty_out(vty, "VNI: %u\n", zl3vni->vni); vty_out(vty, " Type: %s\n", "L3"); - vty_out(vty, " Tenant VRF: %s\n", - zl3vni_vrf_name(zl3vni)); + vty_out(vty, " Tenant VRF: %s\n", zl3vni_vrf_name(zl3vni)); vty_out(vty, " Local Vtep Ip: %s\n", inet_ntoa(zl3vni->local_vtep_ip)); vty_out(vty, " Vxlan-Intf: %s\n", zl3vni_vxlan_if_name(zl3vni)); - vty_out(vty, " SVI-If: %s\n", - zl3vni_svi_if_name(zl3vni)); - vty_out(vty, " State: %s\n", - zl3vni_state2str(zl3vni)); + vty_out(vty, " SVI-If: %s\n", zl3vni_svi_if_name(zl3vni)); + vty_out(vty, " State: %s\n", zl3vni_state2str(zl3vni)); vty_out(vty, " VNI Filter: %s\n", - CHECK_FLAG(zl3vni->filter, PREFIX_ROUTES_ONLY) ? - "prefix-routes-only" : "none"); + CHECK_FLAG(zl3vni->filter, PREFIX_ROUTES_ONLY) + ? "prefix-routes-only" + : "none"); vty_out(vty, " Router MAC: %s\n", zl3vni_rmac2str(zl3vni, buf, sizeof(buf))); vty_out(vty, " L2 VNIs: "); @@ -947,17 +928,16 @@ static void zl3vni_print(zebra_l3vni_t *zl3vni, void **ctx) zl3vni_vxlan_if_name(zl3vni)); json_object_string_add(json, "sviIntf", zl3vni_svi_if_name(zl3vni)); - json_object_string_add(json, "state", - zl3vni_state2str(zl3vni)); - json_object_string_add(json, "vrf", - zl3vni_vrf_name(zl3vni)); - json_object_string_add(json, "routerMac", - zl3vni_rmac2str(zl3vni, buf, - sizeof(buf))); - json_object_string_add(json, "vniFilter", - CHECK_FLAG(zl3vni->filter, - PREFIX_ROUTES_ONLY) ? - "prefix-routes-only" : "none"); + json_object_string_add(json, "state", zl3vni_state2str(zl3vni)); + json_object_string_add(json, "vrf", zl3vni_vrf_name(zl3vni)); + json_object_string_add( + json, "routerMac", + zl3vni_rmac2str(zl3vni, buf, sizeof(buf))); + json_object_string_add( + json, "vniFilter", + CHECK_FLAG(zl3vni->filter, PREFIX_ROUTES_ONLY) + ? "prefix-routes-only" + : "none"); for (ALL_LIST_ELEMENTS(zl3vni->l2vnis, node, nnode, zvni)) { json_object_array_add(json_vni_list, json_object_new_int(zvni->vni)); @@ -1001,10 +981,9 @@ static void zvni_print(zebra_vni_t *zvni, void **ctxt) num_macs = num_valid_macs(zvni); num_neigh = hashcount(zvni->neigh_table); if (json == NULL) { - vty_out(vty, " VxLAN interface: %s\n", - zvni->vxlan_if->name); + vty_out(vty, " VxLAN interface: %s\n", zvni->vxlan_if->name); vty_out(vty, " VxLAN ifIndex: %u\n", zvni->vxlan_if->ifindex); - vty_out(vty," Local VTEP IP: %s\n", + vty_out(vty, " Local VTEP IP: %s\n", inet_ntoa(zvni->local_vtep_ip)); } else { json_object_string_add(json, "vxlanInterface", @@ -1054,8 +1033,7 @@ static void zvni_print(zebra_vni_t *zvni, void **ctxt) } /* print a L3 VNI hash entry */ -static void zl3vni_print_hash(struct hash_backet *backet, - void *ctx[]) +static void zl3vni_print_hash(struct hash_backet *backet, void *ctx[]) { struct vty *vty = NULL; json_object *json = NULL; @@ -1070,13 +1048,10 @@ static void zl3vni_print_hash(struct hash_backet *backet, return; if (!json) { - vty_out(vty, - "%-10u %-4s %-21s %-8lu %-8lu %-15s %-37s\n", - zl3vni->vni, "L3", - zl3vni_vxlan_if_name(zl3vni), + vty_out(vty, "%-10u %-4s %-21s %-8lu %-8lu %-15s %-37s\n", + zl3vni->vni, "L3", zl3vni_vxlan_if_name(zl3vni), hashcount(zl3vni->rmac_table), - hashcount(zl3vni->nh_table), - "n/a", + hashcount(zl3vni->nh_table), "n/a", zl3vni_vrf_name(zl3vni)); } else { char vni_str[VNI_STR_LEN]; @@ -1096,7 +1071,6 @@ static void zl3vni_print_hash(struct hash_backet *backet, zl3vni_vrf_name(zl3vni)); json_object_object_add(json, vni_str, json_vni); } - } /* @@ -1131,12 +1105,10 @@ static void zvni_print_hash(struct hash_backet *backet, void *ctxt[]) num_macs = num_valid_macs(zvni); num_neigh = hashcount(zvni->neigh_table); if (json == NULL) - vty_out(vty, - "%-10u %-4s %-21s %-8u %-8u %-15u %-37s\n", + vty_out(vty, "%-10u %-4s %-21s %-8u %-8u %-15u %-37s\n", zvni->vni, "L2", zvni->vxlan_if ? zvni->vxlan_if->name : "unknown", - num_macs, num_neigh, - num_vteps, + num_macs, num_neigh, num_vteps, vrf_id_to_name(zvni->vrf_id)); else { char vni_str[VNI_STR_LEN]; @@ -1170,8 +1142,7 @@ static void zvni_print_hash(struct hash_backet *backet, void *ctxt[]) /* * Inform BGP about local MACIP. */ -static int zvni_macip_send_msg_to_client(vni_t vni, - struct ethaddr *macaddr, +static int zvni_macip_send_msg_to_client(vni_t vni, struct ethaddr *macaddr, struct ipaddr *ip, u_char flags, u_int16_t cmd) { @@ -1214,8 +1185,8 @@ static int zvni_macip_send_msg_to_client(vni_t vni, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( "Send MACIP %s flags 0x%x MAC %s IP %s L2-VNI %u to %s", - (cmd == ZEBRA_MACIP_ADD) ? "Add" : "Del", - flags, prefix_mac2str(macaddr, buf, sizeof(buf)), + (cmd == ZEBRA_MACIP_ADD) ? "Add" : "Del", flags, + prefix_mac2str(macaddr, buf, sizeof(buf)), ipaddr2str(ip, buf2, sizeof(buf2)), vni, zebra_route_string(client->proto)); @@ -1372,8 +1343,8 @@ static void zvni_neigh_del_from_vtep(zebra_vni_t *zvni, int uninstall, /* * Delete all neighbor entries for this VNI. */ -static void zvni_neigh_del_all(zebra_vni_t *zvni, - int uninstall, int upd_client, u_int32_t flags) +static void zvni_neigh_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, + u_int32_t flags) { struct neigh_walk_ctx wctx; @@ -1471,8 +1442,8 @@ static void zvni_process_neigh_on_local_mac_del(zebra_vni_t *zvni, zvni->vni); ZEBRA_NEIGH_SET_INACTIVE(n); - zvni_neigh_send_del_to_client( - zvni->vni, &n->ip, &n->emac, 0); + zvni_neigh_send_del_to_client(zvni->vni, &n->ip, + &n->emac, 0); } } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) { if (IS_ZEBRA_DEBUG_VXLAN) @@ -1508,8 +1479,8 @@ static void zvni_process_neigh_on_remote_mac_add(zebra_vni_t *zvni, zvni->vni); ZEBRA_NEIGH_SET_INACTIVE(n); - zvni_neigh_send_del_to_client( - zvni->vni, &n->ip, &n->emac, 0); + zvni_neigh_send_del_to_client(zvni->vni, &n->ip, + &n->emac, 0); } } } @@ -1540,12 +1511,11 @@ static void zvni_process_neigh_on_remote_mac_del(zebra_vni_t *zvni, /* * Inform BGP about local neighbor addition. */ -static int zvni_neigh_send_add_to_client(vni_t vni, - struct ipaddr *ip, +static int zvni_neigh_send_add_to_client(vni_t vni, struct ipaddr *ip, struct ethaddr *macaddr, u_char neigh_flags) { - u_char flags = 0; + u_char flags = 0; if (CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_DEF_GW)) SET_FLAG(flags, ZEBRA_MACIP_TYPE_GW); @@ -1557,8 +1527,7 @@ static int zvni_neigh_send_add_to_client(vni_t vni, /* * Inform BGP about local neighbor deletion. */ -static int zvni_neigh_send_del_to_client(vni_t vni, - struct ipaddr *ip, +static int zvni_neigh_send_del_to_client(vni_t vni, struct ipaddr *ip, struct ethaddr *macaddr, u_char flags) { return zvni_macip_send_msg_to_client(vni, macaddr, ip, flags, @@ -1725,8 +1694,7 @@ static int zvni_add_macip_for_intf(struct interface *ifp, zebra_vni_t *zvni) } -static int zvni_advertise_subnet(zebra_vni_t *zvni, - struct interface *ifp, +static int zvni_advertise_subnet(zebra_vni_t *zvni, struct interface *ifp, int advertise) { struct listnode *cnode = NULL, *cnnode = NULL; @@ -1747,7 +1715,7 @@ static int zvni_advertise_subnet(zebra_vni_t *zvni, apply_mask(&p); if (advertise) ip_prefix_send_to_client(ifp->vrf_id, &p, - ZEBRA_IP_PREFIX_ROUTE_ADD); + ZEBRA_IP_PREFIX_ROUTE_ADD); else ip_prefix_send_to_client(ifp->vrf_id, &p, ZEBRA_IP_PREFIX_ROUTE_DEL); @@ -1823,8 +1791,7 @@ static int zvni_gw_macip_add(struct interface *ifp, zebra_vni_t *zvni, prefix_mac2str(macaddr, buf, sizeof(buf)), ipaddr2str(ip, buf2, sizeof(buf2))); - zvni_neigh_send_add_to_client(zvni->vni, ip, macaddr, - n->flags); + zvni_neigh_send_add_to_client(zvni->vni, ip, macaddr, n->flags); return 0; } @@ -1860,13 +1827,11 @@ static int zvni_gw_macip_del(struct interface *ifp, zebra_vni_t *zvni, /* only need to delete the entry from bgp if we sent it before */ if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:SVI %s(%u) VNI %u, sending GW MAC %s IP %s del to BGP", - ifp->vrf_id, ifp->name, - ifp->ifindex, zvni->vni, - prefix_mac2str(&(n->emac), - NULL, - ETHER_ADDR_STRLEN), - ipaddr2str(ip, buf2, sizeof(buf2))); + zlog_debug( + "%u:SVI %s(%u) VNI %u, sending GW MAC %s IP %s del to BGP", + ifp->vrf_id, ifp->name, ifp->ifindex, zvni->vni, + prefix_mac2str(&(n->emac), NULL, ETHER_ADDR_STRLEN), + ipaddr2str(ip, buf2, sizeof(buf2))); /* Remove neighbor from BGP. */ zvni_neigh_send_del_to_client(zvni->vni, &n->ip, &n->emac, @@ -1908,7 +1873,8 @@ static void zvni_gw_macip_del_for_vni_hash(struct hash_backet *backet, zl2_info = zif->l2info.vxl; - vlan_if = zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if); + vlan_if = + zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if); if (!vlan_if) return; @@ -1947,8 +1913,8 @@ static void zvni_gw_macip_add_for_vni_hash(struct hash_backet *backet, return; zl2_info = zif->l2info.vxl; - vlan_if = zvni_map_to_svi(zl2_info.access_vlan, - zif->brslave_info.br_if); + vlan_if = + zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if); if (!vlan_if) return; @@ -1988,8 +1954,7 @@ static int mac_cmp(const void *p1, const void *p2) if (pmac1 == NULL || pmac2 == NULL) return 0; - return (memcmp(pmac1->macaddr.octet, pmac2->macaddr.octet, - ETH_ALEN) + return (memcmp(pmac1->macaddr.octet, pmac2->macaddr.octet, ETH_ALEN) == 0); } @@ -2059,9 +2024,8 @@ static int zvni_mac_del_hash_entry(struct hash_backet *backet, void *arg) && IPV4_ADDR_SAME(&mac->fwd_info.r_vtep_ip, &wctx->r_vtep_ip))) { if (wctx->upd_client && (mac->flags & ZEBRA_MAC_LOCAL)) { - zvni_mac_send_del_to_client( - wctx->zvni->vni, &mac->macaddr, - mac->flags); + zvni_mac_send_del_to_client(wctx->zvni->vni, + &mac->macaddr, mac->flags); } if (wctx->uninstall) @@ -2098,8 +2062,8 @@ static void zvni_mac_del_from_vtep(zebra_vni_t *zvni, int uninstall, /* * Delete all MAC entries for this VNI. */ -static void zvni_mac_del_all(zebra_vni_t *zvni, - int uninstall, int upd_client, u_int32_t flags) +static void zvni_mac_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, + u_int32_t flags) { struct mac_walk_ctx wctx; @@ -2135,11 +2099,10 @@ static zebra_mac_t *zvni_mac_lookup(zebra_vni_t *zvni, struct ethaddr *mac) /* * Inform BGP about local MAC addition. */ -static int zvni_mac_send_add_to_client(vni_t vni, - struct ethaddr *macaddr, +static int zvni_mac_send_add_to_client(vni_t vni, struct ethaddr *macaddr, u_char mac_flags) { - u_char flags = 0; + u_char flags = 0; if (CHECK_FLAG(mac_flags, ZEBRA_MAC_STICKY)) SET_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY); @@ -2153,11 +2116,10 @@ static int zvni_mac_send_add_to_client(vni_t vni, /* * Inform BGP about local MAC deletion. */ -static int zvni_mac_send_del_to_client(vni_t vni, - struct ethaddr *macaddr, +static int zvni_mac_send_del_to_client(vni_t vni, struct ethaddr *macaddr, u_char mac_flags) { - u_char flags = 0; + u_char flags = 0; if (CHECK_FLAG(mac_flags, ZEBRA_MAC_STICKY)) SET_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY); @@ -2448,8 +2410,7 @@ static void zvni_deref_ip2mac(zebra_vni_t *zvni, zebra_mac_t *mac, /* * Read and populate local MACs and neighbors corresponding to this VNI. */ -static void zvni_read_mac_neigh(zebra_vni_t *zvni, - struct interface *ifp) +static void zvni_read_mac_neigh(zebra_vni_t *zvni, struct interface *ifp) { struct zebra_ns *zns; struct zebra_if *zif; @@ -2616,8 +2577,8 @@ static int zvni_send_add_to_client(zebra_vni_t *zvni) stream_putw_at(s, 0, stream_get_endp(s)); if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Send VNI_ADD %u %s tenant vrf %s to %s", - zvni->vni, inet_ntoa(zvni->local_vtep_ip), + zlog_debug("Send VNI_ADD %u %s tenant vrf %s to %s", zvni->vni, + inet_ntoa(zvni->local_vtep_ip), vrf_id_to_name(zvni->vrf_id), zebra_route_string(client->proto)); @@ -2689,8 +2650,9 @@ static void zvni_build_hash_table() if (zl3vni) { if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("create L3-VNI hash for Intf %s(%u) L3-VNI %u", - ifp->name, ifp->ifindex, vni); + zlog_debug( + "create L3-VNI hash for Intf %s(%u) L3-VNI %u", + ifp->name, ifp->ifindex, vni); /* associate with vxlan_if */ zl3vni->local_vtep_ip = vxl->vtep_ip; @@ -2892,8 +2854,7 @@ static void zvni_cleanup_all(struct hash_backet *backet, void *arg) } /* cleanup L3VNI */ -static void zl3vni_cleanup_all(struct hash_backet *backet, - void *args) +static void zl3vni_cleanup_all(struct hash_backet *backet, void *args) { zebra_l3vni_t *zl3vni = NULL; @@ -2904,8 +2865,7 @@ static void zl3vni_cleanup_all(struct hash_backet *backet, zebra_vxlan_process_l3vni_oper_down(zl3vni); } -static int is_host_present_in_host_list(struct list *list, - struct prefix *host) +static int is_host_present_in_host_list(struct list *list, struct prefix *host) { struct listnode *node = NULL; struct prefix *p = NULL; @@ -2917,8 +2877,7 @@ static int is_host_present_in_host_list(struct list *list, return 0; } -static void host_list_add_host(struct list *list, - struct prefix *host) +static void host_list_add_host(struct list *list, struct prefix *host) { struct prefix *p = NULL; @@ -2928,8 +2887,7 @@ static void host_list_add_host(struct list *list, listnode_add_sort(list, p); } -static void host_list_delete_host(struct list *list, - struct prefix *host) +static void host_list_delete_host(struct list *list, struct prefix *host) { struct listnode *node = NULL, *nnode = NULL, *node_to_del = NULL; struct prefix *p = NULL; @@ -2978,8 +2936,7 @@ static void *zl3vni_rmac_alloc(void *p) /* * Add RMAC entry to l3-vni */ -static zebra_mac_t *zl3vni_rmac_add(zebra_l3vni_t *zl3vni, - struct ethaddr *rmac) +static zebra_mac_t *zl3vni_rmac_add(zebra_l3vni_t *zl3vni, struct ethaddr *rmac) { zebra_mac_t tmp_rmac; zebra_mac_t *zrmac = NULL; @@ -3001,8 +2958,7 @@ static zebra_mac_t *zl3vni_rmac_add(zebra_l3vni_t *zl3vni, /* * Delete MAC entry. */ -static int zl3vni_rmac_del(zebra_l3vni_t *zl3vni, - zebra_mac_t *zrmac) +static int zl3vni_rmac_del(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac) { zebra_mac_t *tmp_rmac; @@ -3020,14 +2976,13 @@ static int zl3vni_rmac_del(zebra_l3vni_t *zl3vni, /* * Install remote RMAC into the kernel. */ -static int zl3vni_rmac_install(zebra_l3vni_t *zl3vni, - zebra_mac_t *zrmac) +static int zl3vni_rmac_install(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac) { struct zebra_if *zif = NULL; struct zebra_l2info_vxlan *vxl = NULL; - if (!(CHECK_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE)) || - !(CHECK_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE_RMAC))) + if (!(CHECK_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE)) + || !(CHECK_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE_RMAC))) return 0; zif = zl3vni->vxlan_if->info; @@ -3037,29 +2992,27 @@ static int zl3vni_rmac_install(zebra_l3vni_t *zl3vni, vxl = &zif->l2info.vxl; return kernel_add_mac(zl3vni->vxlan_if, vxl->access_vlan, - &zrmac->macaddr, - zrmac->fwd_info.r_vtep_ip, 0); + &zrmac->macaddr, zrmac->fwd_info.r_vtep_ip, 0); } /* * Uninstall remote RMAC from the kernel. */ -static int zl3vni_rmac_uninstall(zebra_l3vni_t *zl3vni, - zebra_mac_t *zrmac) +static int zl3vni_rmac_uninstall(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac) { char buf[ETHER_ADDR_STRLEN]; struct zebra_if *zif = NULL; struct zebra_l2info_vxlan *vxl = NULL; - if (!(CHECK_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE)) || - !(CHECK_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE_RMAC))) + if (!(CHECK_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE)) + || !(CHECK_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE_RMAC))) return 0; if (!zl3vni->vxlan_if) { zlog_err( - "RMAC %s on L3-VNI %u hash %p couldn't be uninstalled - no vxlan_if", - prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf)), - zl3vni->vni, zl3vni); + "RMAC %s on L3-VNI %u hash %p couldn't be uninstalled - no vxlan_if", + prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf)), + zl3vni->vni, zl3vni); return -1; } @@ -3074,8 +3027,7 @@ static int zl3vni_rmac_uninstall(zebra_l3vni_t *zl3vni, } /* handle rmac add */ -static int zl3vni_remote_rmac_add(zebra_l3vni_t *zl3vni, - struct ethaddr *rmac, +static int zl3vni_remote_rmac_add(zebra_l3vni_t *zl3vni, struct ethaddr *rmac, struct ipaddr *vtep_ip, struct prefix *host_prefix) { @@ -3090,10 +3042,9 @@ static int zl3vni_remote_rmac_add(zebra_l3vni_t *zl3vni, if (!zrmac) { zlog_warn( "Failed to add RMAC %s L3VNI %u Remote VTEP %s", - prefix_mac2str(rmac, buf, - sizeof(buf)), - zl3vni->vni, ipaddr2str(vtep_ip, buf1, - sizeof(buf1))); + prefix_mac2str(rmac, buf, sizeof(buf)), + zl3vni->vni, + ipaddr2str(vtep_ip, buf1, sizeof(buf1))); return -1; } memset(&zrmac->fwd_info, 0, sizeof(zrmac->fwd_info)); @@ -3110,8 +3061,7 @@ static int zl3vni_remote_rmac_add(zebra_l3vni_t *zl3vni, /* handle rmac delete */ -static int zl3vni_remote_rmac_del(zebra_l3vni_t *zl3vni, - struct ethaddr *rmac, +static int zl3vni_remote_rmac_del(zebra_l3vni_t *zl3vni, struct ethaddr *rmac, struct prefix *host_prefix) { zebra_mac_t *zrmac = NULL; @@ -3135,8 +3085,7 @@ static int zl3vni_remote_rmac_del(zebra_l3vni_t *zl3vni, /* * Look up nh hash entry on a l3-vni. */ -static zebra_neigh_t *zl3vni_nh_lookup(zebra_l3vni_t *zl3vni, - struct ipaddr *ip) +static zebra_neigh_t *zl3vni_nh_lookup(zebra_l3vni_t *zl3vni, struct ipaddr *ip) { zebra_neigh_t tmp; zebra_neigh_t *n; @@ -3166,8 +3115,7 @@ static void *zl3vni_nh_alloc(void *p) /* * Add neighbor entry. */ -static zebra_neigh_t *zl3vni_nh_add(zebra_l3vni_t *zl3vni, - struct ipaddr *ip, +static zebra_neigh_t *zl3vni_nh_add(zebra_l3vni_t *zl3vni, struct ipaddr *ip, struct ethaddr *mac) { zebra_neigh_t tmp_n; @@ -3191,8 +3139,7 @@ static zebra_neigh_t *zl3vni_nh_add(zebra_l3vni_t *zl3vni, /* * Delete neighbor entry. */ -static int zl3vni_nh_del(zebra_l3vni_t *zl3vni, - zebra_neigh_t *n) +static int zl3vni_nh_del(zebra_l3vni_t *zl3vni, zebra_neigh_t *n) { zebra_neigh_t *tmp_n; @@ -3210,14 +3157,13 @@ static int zl3vni_nh_del(zebra_l3vni_t *zl3vni, /* * Install remote nh as neigh into the kernel. */ -static int zl3vni_nh_install(zebra_l3vni_t *zl3vni, - zebra_neigh_t *n) +static int zl3vni_nh_install(zebra_l3vni_t *zl3vni, zebra_neigh_t *n) { if (!is_l3vni_oper_up(zl3vni)) return -1; - if (!(n->flags & ZEBRA_NEIGH_REMOTE) || - !(n->flags & ZEBRA_NEIGH_REMOTE_NH)) + if (!(n->flags & ZEBRA_NEIGH_REMOTE) + || !(n->flags & ZEBRA_NEIGH_REMOTE_NH)) return 0; return kernel_add_neigh(zl3vni->svi_if, &n->ip, &n->emac); @@ -3226,11 +3172,10 @@ static int zl3vni_nh_install(zebra_l3vni_t *zl3vni, /* * Uninstall remote nh from the kernel. */ -static int zl3vni_nh_uninstall(zebra_l3vni_t *zl3vni, - zebra_neigh_t *n) +static int zl3vni_nh_uninstall(zebra_l3vni_t *zl3vni, zebra_neigh_t *n) { - if (!(n->flags & ZEBRA_NEIGH_REMOTE) || - !(n->flags & ZEBRA_NEIGH_REMOTE_NH)) + if (!(n->flags & ZEBRA_NEIGH_REMOTE) + || !(n->flags & ZEBRA_NEIGH_REMOTE_NH)) return 0; if (!zl3vni->svi_if || !if_is_operative(zl3vni->svi_if)) @@ -3240,8 +3185,7 @@ static int zl3vni_nh_uninstall(zebra_l3vni_t *zl3vni, } /* add remote vtep as a neigh entry */ -static int zl3vni_remote_nh_add(zebra_l3vni_t *zl3vni, - struct ipaddr *vtep_ip, +static int zl3vni_remote_nh_add(zebra_l3vni_t *zl3vni, struct ipaddr *vtep_ip, struct ethaddr *rmac, struct prefix *host_prefix) { @@ -3256,10 +3200,8 @@ static int zl3vni_remote_nh_add(zebra_l3vni_t *zl3vni, zlog_warn( "Failed to add NH as Neigh (IP %s MAC %s L3-VNI %u)", - ipaddr2str(vtep_ip, buf1, - sizeof(buf1)), - prefix_mac2str(rmac, buf, - sizeof(buf)), + ipaddr2str(vtep_ip, buf1, sizeof(buf1)), + prefix_mac2str(rmac, buf, sizeof(buf)), zl3vni->vni); return -1; } @@ -3275,8 +3217,7 @@ static int zl3vni_remote_nh_add(zebra_l3vni_t *zl3vni, } /* handle nh neigh delete */ -static int zl3vni_remote_nh_del(zebra_l3vni_t *zl3vni, - struct ipaddr *vtep_ip, +static int zl3vni_remote_nh_del(zebra_l3vni_t *zl3vni, struct ipaddr *vtep_ip, struct prefix *host_prefix) { zebra_neigh_t *nh = NULL; @@ -3301,8 +3242,8 @@ static int zl3vni_remote_nh_del(zebra_l3vni_t *zl3vni, /* handle neigh update from kernel - the only thing of interest is to * readd stale entries. */ -static int zl3vni_local_nh_add_update(zebra_l3vni_t *zl3vni, - struct ipaddr *ip, u_int16_t state) +static int zl3vni_local_nh_add_update(zebra_l3vni_t *zl3vni, struct ipaddr *ip, + u_int16_t state) { #ifdef GNU_LINUX zebra_neigh_t *n = NULL; @@ -3321,8 +3262,7 @@ static int zl3vni_local_nh_add_update(zebra_l3vni_t *zl3vni, } /* handle neigh delete from kernel */ -static int zl3vni_local_nh_del(zebra_l3vni_t *zl3vni, - struct ipaddr *ip) +static int zl3vni_local_nh_del(zebra_l3vni_t *zl3vni, struct ipaddr *ip) { zebra_neigh_t *n = NULL; @@ -3416,13 +3356,12 @@ static zebra_l3vni_t *zl3vni_add(vni_t vni, vrf_id_t vrf_id) zl3vni->l2vnis->cmp = (int (*)(void *, void *))vni_hash_cmp; /* Create hash table for remote RMAC */ - zl3vni->rmac_table = - hash_create(mac_hash_keymake, mac_cmp, - "Zebra L3-VNI RMAC-Table"); + zl3vni->rmac_table = hash_create(mac_hash_keymake, mac_cmp, + "Zebra L3-VNI RMAC-Table"); /* Create hash table for neighbors */ zl3vni->nh_table = hash_create(neigh_hash_keymake, neigh_cmp, - "Zebra L3-VNI next-hop table"); + "Zebra L3-VNI next-hop table"); return zl3vni; } @@ -3491,7 +3430,7 @@ static struct interface *zl3vni_map_to_vxlan_if(zebra_l3vni_t *zl3vni) static struct interface *zl3vni_map_to_svi_if(zebra_l3vni_t *zl3vni) { - struct zebra_if *zif = NULL; /* zebra_if for vxlan_if */ + struct zebra_if *zif = NULL; /* zebra_if for vxlan_if */ struct zebra_l2info_vxlan *vxl = NULL; /* l2 info for vxlan_if */ if (!zl3vni) @@ -3614,8 +3553,7 @@ static int zl3vni_send_add_to_client(zebra_l3vni_t *zl3vni) s = client->obuf; stream_reset(s); - zclient_create_header(s, ZEBRA_L3VNI_ADD, - zl3vni_vrf_id(zl3vni)); + zclient_create_header(s, ZEBRA_L3VNI_ADD, zl3vni_vrf_id(zl3vni)); stream_putl(s, zl3vni->vni); stream_put(s, &rmac, sizeof(struct ethaddr)); stream_put_in_addr(s, &zl3vni->local_vtep_ip); @@ -3626,13 +3564,14 @@ static int zl3vni_send_add_to_client(zebra_l3vni_t *zl3vni) if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "Send L3_VNI_ADD %u VRF %s RMAC %s local-ip %s filter %s to %s", - zl3vni->vni, vrf_id_to_name(zl3vni_vrf_id(zl3vni)), - prefix_mac2str(&rmac, buf, sizeof(buf)), - inet_ntoa(zl3vni->local_vtep_ip), - CHECK_FLAG(zl3vni->filter, PREFIX_ROUTES_ONLY) ? - "prefix-routes-only" : "none", - zebra_route_string(client->proto)); + "Send L3_VNI_ADD %u VRF %s RMAC %s local-ip %s filter %s to %s", + zl3vni->vni, vrf_id_to_name(zl3vni_vrf_id(zl3vni)), + prefix_mac2str(&rmac, buf, sizeof(buf)), + inet_ntoa(zl3vni->local_vtep_ip), + CHECK_FLAG(zl3vni->filter, PREFIX_ROUTES_ONLY) + ? "prefix-routes-only" + : "none", + zebra_route_string(client->proto)); client->l3vniadd_cnt++; return zebra_server_send_message(client); @@ -3654,16 +3593,14 @@ static int zl3vni_send_del_to_client(zebra_l3vni_t *zl3vni) s = client->obuf; stream_reset(s); - zclient_create_header(s, ZEBRA_L3VNI_DEL, - zl3vni_vrf_id(zl3vni)); + zclient_create_header(s, ZEBRA_L3VNI_DEL, zl3vni_vrf_id(zl3vni)); stream_putl(s, zl3vni->vni); /* Write packet size. */ stream_putw_at(s, 0, stream_get_endp(s)); if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Send L3_VNI_DEL %u VRF %s to %s", - zl3vni->vni, + zlog_debug("Send L3_VNI_DEL %u VRF %s to %s", zl3vni->vni, vrf_id_to_name(zl3vni_vrf_id(zl3vni)), zebra_route_string(client->proto)); @@ -3689,11 +3626,10 @@ static void zebra_vxlan_process_l3vni_oper_down(zebra_l3vni_t *zl3vni) zl3vni_send_del_to_client(zl3vni); } -static void zvni_add_to_l3vni_list(struct hash_backet *backet, - void *ctxt) +static void zvni_add_to_l3vni_list(struct hash_backet *backet, void *ctxt) { - zebra_vni_t *zvni = (zebra_vni_t *) backet->data; - zebra_l3vni_t *zl3vni = (zebra_l3vni_t *) ctxt; + zebra_vni_t *zvni = (zebra_vni_t *)backet->data; + zebra_l3vni_t *zl3vni = (zebra_l3vni_t *)ctxt; if (zvni->vrf_id == zl3vni_vrf_id(zl3vni)) listnode_add_sort(zl3vni->l2vnis, zvni); @@ -3702,8 +3638,8 @@ static void zvni_add_to_l3vni_list(struct hash_backet *backet, /* * handle transition of vni from l2 to l3 and vice versa */ -static int zebra_vxlan_handle_vni_transition(struct zebra_vrf *zvrf, - vni_t vni, int add) +static int zebra_vxlan_handle_vni_transition(struct zebra_vrf *zvrf, vni_t vni, + int add) { zebra_vni_t *zvni = NULL; @@ -3722,8 +3658,7 @@ static int zebra_vxlan_handle_vni_transition(struct zebra_vrf *zvrf, return 0; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Del L2-VNI %u - transition to L3-VNI", - vni); + zlog_debug("Del L2-VNI %u - transition to L3-VNI", vni); /* Delete VNI from BGP. */ zvni_send_del_to_client(zvni->vni); @@ -3737,8 +3672,8 @@ static int zebra_vxlan_handle_vni_transition(struct zebra_vrf *zvrf, /* Delete the hash entry. */ if (zvni_del(zvni)) { - zlog_err("Failed to del VNI hash %p, VNI %u", - zvni, zvni->vni); + zlog_err("Failed to del VNI hash %p, VNI %u", zvni, + zvni->vni); return -1; } } else { @@ -3753,8 +3688,7 @@ static int zebra_vxlan_handle_vni_transition(struct zebra_vrf *zvrf, } /* delete and uninstall rmac hash entry */ -static void zl3vni_del_rmac_hash_entry(struct hash_backet *backet, - void *ctx) +static void zl3vni_del_rmac_hash_entry(struct hash_backet *backet, void *ctx) { zebra_mac_t *zrmac = NULL; zebra_l3vni_t *zl3vni = NULL; @@ -3766,8 +3700,7 @@ static void zl3vni_del_rmac_hash_entry(struct hash_backet *backet, } /* delete and uninstall nh hash entry */ -static void zl3vni_del_nh_hash_entry(struct hash_backet *backet, - void *ctx) +static void zl3vni_del_nh_hash_entry(struct hash_backet *backet, void *ctx) { zebra_neigh_t *n = NULL; zebra_l3vni_t *zl3vni = NULL; @@ -3778,9 +3711,8 @@ static void zl3vni_del_nh_hash_entry(struct hash_backet *backet, zl3vni_nh_del(zl3vni, n); } -static int ip_prefix_send_to_client(vrf_id_t vrf_id, - struct prefix *p, - uint16_t cmd) +static int ip_prefix_send_to_client(vrf_id_t vrf_id, struct prefix *p, + uint16_t cmd) { struct zserv *client = NULL; struct stream *s = NULL; @@ -3801,8 +3733,7 @@ static int ip_prefix_send_to_client(vrf_id_t vrf_id, stream_putw_at(s, 0, stream_get_endp(s)); if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug( - "Send ip prefix %s %s on vrf %s", + zlog_debug("Send ip prefix %s %s on vrf %s", prefix2str(p, buf, sizeof(buf)), (cmd == ZEBRA_IP_PREFIX_ROUTE_ADD) ? "ADD" : "DEL", vrf_id_to_name(vrf_id)); @@ -3817,7 +3748,7 @@ static int ip_prefix_send_to_client(vrf_id_t vrf_id, /* re-add remote rmac if needed */ static int zebra_vxlan_readd_remote_rmac(zebra_l3vni_t *zl3vni, - struct ethaddr *rmac) + struct ethaddr *rmac) { char buf[ETHER_ADDR_STRLEN]; zebra_mac_t *zrmac = NULL; @@ -3828,8 +3759,7 @@ static int zebra_vxlan_readd_remote_rmac(zebra_l3vni_t *zl3vni, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug("Del remote RMAC %s L3VNI %u - readd", - prefix_mac2str(rmac, buf, sizeof(buf)), - zl3vni->vni); + prefix_mac2str(rmac, buf, sizeof(buf)), zl3vni->vni); zl3vni_rmac_install(zl3vni, zrmac); return 0; @@ -3849,10 +3779,9 @@ int is_l3vni_for_prefix_routes_only(vni_t vni) } /* handle evpn route in vrf table */ -void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id, - struct ethaddr *rmac, - struct ipaddr *vtep_ip, - struct prefix *host_prefix) +void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id, struct ethaddr *rmac, + struct ipaddr *vtep_ip, + struct prefix *host_prefix) { zebra_l3vni_t *zl3vni = NULL; @@ -3868,10 +3797,9 @@ void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id, } /* handle evpn vrf route delete */ -void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id, - struct ethaddr *rmac, - struct ipaddr *vtep_ip, - struct prefix *host_prefix) +void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id, struct ethaddr *rmac, + struct ipaddr *vtep_ip, + struct prefix *host_prefix) { zebra_l3vni_t *zl3vni = NULL; @@ -3886,8 +3814,7 @@ void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id, zl3vni_remote_rmac_del(zl3vni, rmac, host_prefix); } -void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, - vni_t l3vni, +void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni, struct ethaddr *rmac, u_char use_json) { @@ -3909,8 +3836,7 @@ void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, if (use_json) vty_out(vty, "{}\n"); else - vty_out(vty, "%% L3-VNI %u doesnt exist\n", - l3vni); + vty_out(vty, "%% L3-VNI %u doesnt exist\n", l3vni); return; } @@ -3934,8 +3860,7 @@ void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, } } -void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, - vni_t l3vni, +void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t l3vni, u_char use_json) { zebra_l3vni_t *zl3vni; @@ -3965,8 +3890,7 @@ void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, wctx.vty = vty; wctx.json = json; if (!use_json) { - vty_out(vty, - "Number of Remote RMACs known for this VNI: %u\n", + vty_out(vty, "Number of Remote RMACs known for this VNI: %u\n", num_rmacs); vty_out(vty, "%-17s %-21s\n", "MAC", "Remote VTEP"); } else @@ -3981,8 +3905,7 @@ void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, } } -void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, - u_char use_json) +void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, u_char use_json) { struct zebra_ns *zns = NULL; json_object *json = NULL; @@ -4018,10 +3941,8 @@ void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, } } -void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, - vni_t l3vni, - struct ipaddr *ip, - u_char use_json) +void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, vni_t l3vni, + struct ipaddr *ip, u_char use_json) { zebra_l3vni_t *zl3vni = NULL; zebra_neigh_t *n = NULL; @@ -4065,9 +3986,7 @@ void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, } } -void zebra_vxlan_print_nh_l3vni(struct vty *vty, - vni_t l3vni, - u_char use_json) +void zebra_vxlan_print_nh_l3vni(struct vty *vty, vni_t l3vni, u_char use_json) { u_int32_t num_nh; struct nh_walk_ctx wctx; @@ -4096,8 +4015,7 @@ void zebra_vxlan_print_nh_l3vni(struct vty *vty, wctx.vty = vty; wctx.json = json; if (!use_json) { - vty_out(vty, - "Number of NH Neighbors known for this VNI: %u\n", + vty_out(vty, "Number of NH Neighbors known for this VNI: %u\n", num_nh); vty_out(vty, "%-15s %-17s\n", "IP", "RMAC"); } else @@ -4112,8 +4030,7 @@ void zebra_vxlan_print_nh_l3vni(struct vty *vty, } } -void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, - u_char use_json) +void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, u_char use_json) { struct zebra_ns *zns = NULL; json_object *json = NULL; @@ -4197,17 +4114,14 @@ void zebra_vxlan_print_vrf_vni(struct vty *vty, struct zebra_vrf *zvrf, if (!json_vrfs) { vty_out(vty, "%-37s %-10u %-20s %-20s %-5s %-18s\n", - zvrf_name(zvrf), - zl3vni->vni, + zvrf_name(zvrf), zl3vni->vni, zl3vni_vxlan_if_name(zl3vni), - zl3vni_svi_if_name(zl3vni), - zl3vni_state2str(zl3vni), + zl3vni_svi_if_name(zl3vni), zl3vni_state2str(zl3vni), zl3vni_rmac2str(zl3vni, buf, sizeof(buf))); } else { json_object *json_vrf = NULL; json_vrf = json_object_new_object(); - json_object_string_add(json_vrf, "vrf", - zvrf_name(zvrf)); + json_object_string_add(json_vrf, "vrf", zvrf_name(zvrf)); json_object_int_add(json_vrf, "vni", zl3vni->vni); json_object_string_add(json_vrf, "vxlanIntf", zl3vni_vxlan_if_name(zl3vni)); @@ -4215,9 +4129,9 @@ void zebra_vxlan_print_vrf_vni(struct vty *vty, struct zebra_vrf *zvrf, zl3vni_svi_if_name(zl3vni)); json_object_string_add(json_vrf, "state", zl3vni_state2str(zl3vni)); - json_object_string_add(json_vrf, "routerMac", - zl3vni_rmac2str(zl3vni, buf, - sizeof(buf))); + json_object_string_add( + json_vrf, "routerMac", + zl3vni_rmac2str(zl3vni, buf, sizeof(buf))); json_object_array_add(json_vrfs, json_vrf); } } @@ -4690,10 +4604,9 @@ void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf, if (use_json) json = json_object_new_object(); else - vty_out(vty, - "%-10s %-4s %-21s %-8s %-8s %-15s %-37s\n", - "VNI", "Type", "VxLAN IF", "# MACs", - "# ARPs", "# Remote VTEPs", "Tenant VRF"); + vty_out(vty, "%-10s %-4s %-21s %-8s %-8s %-15s %-37s\n", "VNI", + "Type", "VxLAN IF", "# MACs", "# ARPs", + "# Remote VTEPs", "Tenant VRF"); args[0] = vty; args[1] = json; @@ -4754,8 +4667,8 @@ int zebra_vxlan_local_neigh_del(struct interface *ifp, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug("Del neighbor %s intf %s(%u) -> L2-VNI %u", - ipaddr2str(ip, buf, sizeof(buf)), - ifp->name, ifp->ifindex, zvni->vni); + ipaddr2str(ip, buf, sizeof(buf)), ifp->name, + ifp->ifindex, zvni->vni); /* If entry doesn't exist, nothing to do. */ n = zvni_neigh_lookup(zvni, ip); @@ -4784,8 +4697,7 @@ int zebra_vxlan_local_neigh_del(struct interface *ifp, /* Remove neighbor from BGP. */ if (IS_ZEBRA_NEIGH_ACTIVE(n)) - zvni_neigh_send_del_to_client(zvni->vni, &n->ip, &n->emac, - 0); + zvni_neigh_send_del_to_client(zvni->vni, &n->ip, &n->emac, 0); /* Delete this neighbor entry. */ zvni_neigh_del(zvni, n); @@ -4841,10 +4753,10 @@ int zebra_vxlan_local_neigh_add_update(struct interface *ifp, zmac = zvni_mac_lookup(zvni, macaddr); if (!zmac) { if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug( - "AUTO MAC %s created for neigh %s on VNI %u", - prefix_mac2str(macaddr, buf, sizeof(buf)), - ipaddr2str(ip, buf2, sizeof(buf2)), zvni->vni); + zlog_debug("AUTO MAC %s created for neigh %s on VNI %u", + prefix_mac2str(macaddr, buf, sizeof(buf)), + ipaddr2str(ip, buf2, sizeof(buf2)), + zvni->vni); zmac = zvni_mac_add(zvni, macaddr); if (!zmac) { @@ -4865,8 +4777,7 @@ int zebra_vxlan_local_neigh_add_update(struct interface *ifp, n = zvni_neigh_lookup(zvni, ip); if (n) { if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { - if (memcmp(n->emac.octet, macaddr->octet, - ETH_ALEN) + if (memcmp(n->emac.octet, macaddr->octet, ETH_ALEN) == 0) { /* Update any params and return - client doesn't * care about a purely local change. @@ -5042,10 +4953,9 @@ int zebra_vxlan_remote_macip_del(struct zserv *client, u_short length, n = zvni_neigh_lookup(zvni, &ip); if (n && !mac) { - zlog_err( - "Failed to locate MAC %s for neigh %s VNI %u", - prefix_mac2str(&macaddr, buf, sizeof(buf)), - ipaddr2str(&ip, buf1, sizeof(buf1)), vni); + zlog_err("Failed to locate MAC %s for neigh %s VNI %u", + prefix_mac2str(&macaddr, buf, sizeof(buf)), + ipaddr2str(&ip, buf1, sizeof(buf1)), vni); continue; } @@ -5057,13 +4967,13 @@ int zebra_vxlan_remote_macip_del(struct zserv *client, u_short length, continue; /* Ignore the delete if this mac is a gateway mac-ip */ - if (mac && CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL) && - CHECK_FLAG(mac->flags, ZEBRA_MAC_DEF_GW)) { - zlog_err("%u: Ignore Del for MAC %s neigh %s on VNI %u as it is configured as a default gateway", - zvrf_id(zvrf), - prefix_mac2str(&macaddr, buf, sizeof(buf)), - ipaddr2str(&ip, buf1, sizeof(buf1)), - vni); + if (mac && CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL) + && CHECK_FLAG(mac->flags, ZEBRA_MAC_DEF_GW)) { + zlog_err( + "%u: Ignore Del for MAC %s neigh %s on VNI %u as it is configured as a default gateway", + zvrf_id(zvrf), + prefix_mac2str(&macaddr, buf, sizeof(buf)), + ipaddr2str(&ip, buf1, sizeof(buf1)), vni); continue; } @@ -5078,8 +4988,7 @@ int zebra_vxlan_remote_macip_del(struct zserv *client, u_short length, * if the MAC matches. */ if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE) - && (memcmp(n->emac.octet, macaddr.octet, - ETH_ALEN) + && (memcmp(n->emac.octet, macaddr.octet, ETH_ALEN) == 0)) { zvni_neigh_uninstall(zvni, n); zvni_neigh_del(zvni, n); @@ -5087,8 +4996,7 @@ int zebra_vxlan_remote_macip_del(struct zserv *client, u_short length, } } else { if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) { - zvni_process_neigh_on_remote_mac_del(zvni, - mac); + zvni_process_neigh_on_remote_mac_del(zvni, mac); if (list_isempty(mac->neigh_list)) { zvni_mac_uninstall(zvni, mac, 0); @@ -5134,8 +5042,9 @@ int zebra_vxlan_remote_macip_add(struct zserv *client, u_short length, memset(&vtep_ip, 0, sizeof(struct in_addr)); if (!EVPN_ENABLED(zvrf)) { - zlog_warn("%s: EVPN Not turned on yet we have received a remote_macip add zapi callback", - __PRETTY_FUNCTION__); + zlog_warn( + "%s: EVPN Not turned on yet we have received a remote_macip add zapi callback", + __PRETTY_FUNCTION__); return -1; } @@ -5218,15 +5127,16 @@ int zebra_vxlan_remote_macip_add(struct zserv *client, u_short length, /* Ignore the update if the mac is already present as a gateway mac */ - if (mac && CHECK_FLAG(mac->flags, ZEBRA_MAC_DEF_GW) && - CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_GW)) { + if (mac && CHECK_FLAG(mac->flags, ZEBRA_MAC_DEF_GW) + && CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_GW)) { if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:Ignore MAC %s IP %s on VNI %u as MAC is already configured as gateway mac", - zvrf_id(zvrf), - prefix_mac2str(&macaddr, - buf, sizeof(buf)), - ipaddr2str(&ip, buf1, - sizeof(buf1)), vni); + zlog_debug( + "%u:Ignore MAC %s IP %s on VNI %u as MAC is already configured as gateway mac", + zvrf_id(zvrf), + prefix_mac2str(&macaddr, buf, + sizeof(buf)), + ipaddr2str(&ip, buf1, sizeof(buf1)), + vni); continue; } @@ -5375,8 +5285,8 @@ int zebra_vxlan_check_del_local_mac(struct interface *ifp, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( "Add/update remote MAC %s intf %s(%u) VNI %u - del local", - prefix_mac2str(macaddr, buf, sizeof(buf)), - ifp->name, ifp->ifindex, vni); + prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, + ifp->ifindex, vni); /* Remove MAC from BGP. */ zvni_mac_send_del_to_client(zvni->vni, macaddr, mac->flags); @@ -5540,11 +5450,10 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp, } if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug( - "Add/Update %sMAC %s intf %s(%u) VID %u -> VNI %u", - sticky ? "sticky " : "", - prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, - ifp->ifindex, vid, zvni->vni); + zlog_debug("Add/Update %sMAC %s intf %s(%u) VID %u -> VNI %u", + sticky ? "sticky " : "", + prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, + ifp->ifindex, vid, zvni->vni); /* If same entry already exists, nothing to do. */ mac = zvni_mac_lookup(zvni, macaddr); @@ -5647,8 +5556,9 @@ int zebra_vxlan_remote_vtep_del(struct zserv *client, u_short length, struct zebra_if *zif; if (!is_evpn_enabled()) { - zlog_warn("%s: EVPN is not enabled yet we have received a vtep del command", - __PRETTY_FUNCTION__); + zlog_warn( + "%s: EVPN is not enabled yet we have received a vtep del command", + __PRETTY_FUNCTION__); return -1; } @@ -5731,8 +5641,9 @@ int zebra_vxlan_remote_vtep_add(struct zserv *client, u_short length, struct zebra_if *zif; if (!is_evpn_enabled()) { - zlog_warn("%s: EVPN not enabled yet we received a vtep_add zapi call", - __PRETTY_FUNCTION__); + zlog_warn( + "%s: EVPN not enabled yet we received a vtep_add zapi call", + __PRETTY_FUNCTION__); return -1; } @@ -5785,9 +5696,8 @@ int zebra_vxlan_remote_vtep_add(struct zserv *client, u_short length, continue; if (zvni_vtep_add(zvni, &vtep_ip) == NULL) { - zlog_err( - "Failed to add remote VTEP, VNI %u zvni %p", - vni, zvni); + zlog_err("Failed to add remote VTEP, VNI %u zvni %p", + vni, zvni); continue; } @@ -5986,9 +5896,10 @@ int zebra_vxlan_svi_up(struct interface *ifp, struct interface *link_if) } if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("SVI %s(%u) VNI %u VRF %s is UP, installing neighbors", - ifp->name, ifp->ifindex, zvni->vni, - vrf_id_to_name(ifp->vrf_id)); + zlog_debug( + "SVI %s(%u) VNI %u VRF %s is UP, installing neighbors", + ifp->name, ifp->ifindex, zvni->vni, + vrf_id_to_name(ifp->vrf_id)); /* update the vrf information for l2-vni and inform bgp */ zvni->vrf_id = ifp->vrf_id; @@ -5997,8 +5908,7 @@ int zebra_vxlan_svi_up(struct interface *ifp, struct interface *link_if) /* Install any remote neighbors for this VNI. */ memset(&n_wctx, 0, sizeof(struct neigh_walk_ctx)); n_wctx.zvni = zvni; - hash_iterate(zvni->neigh_table, - zvni_install_neigh_hash, + hash_iterate(zvni->neigh_table, zvni_install_neigh_hash, &n_wctx); } @@ -6029,15 +5939,15 @@ int zebra_vxlan_if_down(struct interface *ifp) if (zl3vni) { /* process-if-down for l3-vni */ if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Intf %s(%u) L3-VNI %u is DOWN", - ifp->name, ifp->ifindex, vni); + zlog_debug("Intf %s(%u) L3-VNI %u is DOWN", ifp->name, + ifp->ifindex, vni); zebra_vxlan_process_l3vni_oper_down(zl3vni); } else { /* process if-down for l2-vni */ if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Intf %s(%u) L2-VNI %u is DOWN", - ifp->name, ifp->ifindex, vni); + zlog_debug("Intf %s(%u) L2-VNI %u is DOWN", ifp->name, + ifp->ifindex, vni); /* Locate hash entry; it is expected to exist. */ zvni = zvni_lookup(vni); @@ -6087,8 +5997,8 @@ int zebra_vxlan_if_up(struct interface *ifp) if (zl3vni) { if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Intf %s(%u) L3-VNI %u is UP", - ifp->name, ifp->ifindex, vni); + zlog_debug("Intf %s(%u) L3-VNI %u is UP", ifp->name, + ifp->ifindex, vni); /* we need to associate with SVI, if any, we can associate with * svi-if only after association with vxlan-intf is complete @@ -6102,8 +6012,8 @@ int zebra_vxlan_if_up(struct interface *ifp) struct interface *vlan_if = NULL; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Intf %s(%u) L2-VNI %u is UP", - ifp->name, ifp->ifindex, vni); + zlog_debug("Intf %s(%u) L2-VNI %u is UP", ifp->name, + ifp->ifindex, vni); /* Locate hash entry; it is expected to exist. */ zvni = zvni_lookup(vni); @@ -6160,8 +6070,8 @@ int zebra_vxlan_if_del(struct interface *ifp) if (zl3vni) { if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Del L3-VNI %u intf %s(%u)", - vni, ifp->name, ifp->ifindex); + zlog_debug("Del L3-VNI %u intf %s(%u)", vni, ifp->name, + ifp->ifindex); /* process oper-down for l3-vni */ zebra_vxlan_process_l3vni_oper_down(zl3vni); @@ -6173,8 +6083,8 @@ int zebra_vxlan_if_del(struct interface *ifp) /* process if-del for l2-vni*/ if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Del L2-VNI %u intf %s(%u)", - vni, ifp->name, ifp->ifindex); + zlog_debug("Del L2-VNI %u intf %s(%u)", vni, ifp->name, + ifp->ifindex); /* Locate hash entry; it is expected to exist. */ zvni = zvni_lookup(vni); @@ -6236,8 +6146,8 @@ int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags) if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( "Update L3-VNI %u intf %s(%u) VLAN %u local IP %s master %u chg 0x%x", - vni, ifp->name, ifp->ifindex, - vxl->access_vlan, inet_ntoa(vxl->vtep_ip), + vni, ifp->name, ifp->ifindex, vxl->access_vlan, + inet_ntoa(vxl->vtep_ip), zif->brslave_info.bridge_ifindex, chgflags); /* Removed from bridge? Cleanup and return */ @@ -6258,7 +6168,7 @@ int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags) zl3vni->local_vtep_ip = vxl->vtep_ip; if (is_l3vni_oper_up(zl3vni)) zebra_vxlan_process_l3vni_oper_up( - zl3vni); + zl3vni); } } @@ -6272,7 +6182,7 @@ int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags) zl3vni->local_vtep_ip = vxl->vtep_ip; if (is_l3vni_oper_up(zl3vni)) zebra_vxlan_process_l3vni_oper_up( - zl3vni); + zl3vni); } } @@ -6298,8 +6208,8 @@ int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags) if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( "Update L2-VNI %u intf %s(%u) VLAN %u local IP %s master %u chg 0x%x", - vni, ifp->name, ifp->ifindex, - vxl->access_vlan, inet_ntoa(vxl->vtep_ip), + vni, ifp->name, ifp->ifindex, vxl->access_vlan, + inet_ntoa(vxl->vtep_ip), zif->brslave_info.bridge_ifindex, chgflags); /* Removed from bridge? Cleanup and return */ @@ -6353,8 +6263,7 @@ int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags) memset(&m_wctx, 0, sizeof(struct mac_walk_ctx)); m_wctx.zvni = zvni; - hash_iterate(zvni->mac_table, - zvni_install_mac_hash, + hash_iterate(zvni->mac_table, zvni_install_mac_hash, &m_wctx); memset(&n_wctx, 0, sizeof(struct neigh_walk_ctx)); @@ -6394,8 +6303,8 @@ int zebra_vxlan_if_add(struct interface *ifp) if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( "Add L3-VNI %u intf %s(%u) VLAN %u local IP %s master %u", - vni, ifp->name, ifp->ifindex, - vxl->access_vlan, inet_ntoa(vxl->vtep_ip), + vni, ifp->name, ifp->ifindex, vxl->access_vlan, + inet_ntoa(vxl->vtep_ip), zif->brslave_info.bridge_ifindex); /* associate with vxlan_if */ @@ -6440,10 +6349,10 @@ int zebra_vxlan_if_add(struct interface *ifp) zlog_debug( "Add L2-VNI %u VRF %s intf %s(%u) VLAN %u local IP %s master %u", vni, - vlan_if ? vrf_id_to_name(vlan_if->vrf_id) : - "Default", - ifp->name, ifp->ifindex, - vxl->access_vlan, inet_ntoa(vxl->vtep_ip), + vlan_if ? vrf_id_to_name(vlan_if->vrf_id) + : "Default", + ifp->name, ifp->ifindex, vxl->access_vlan, + inet_ntoa(vxl->vtep_ip), zif->brslave_info.bridge_ifindex); /* If down or not mapped to a bridge, we're done. */ @@ -6460,10 +6369,9 @@ int zebra_vxlan_if_add(struct interface *ifp) return 0; } -int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf *zvrf, - vni_t vni, - char *err, int err_str_sz, - int filter, int add) +int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf *zvrf, vni_t vni, + char *err, int err_str_sz, int filter, + int add) { zebra_l3vni_t *zl3vni = NULL; struct zebra_vrf *zvrf_default = NULL; @@ -6473,9 +6381,7 @@ int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf *zvrf, return -1; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("vrf %s vni %u %s", - zvrf_name(zvrf), - vni, + zlog_debug("vrf %s vni %u %s", zvrf_name(zvrf), vni, add ? "ADD" : "DEL"); if (add) { @@ -6500,8 +6406,7 @@ int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf *zvrf, /* add the L3-VNI to the global table */ zl3vni = zl3vni_add(vni, zvrf_id(zvrf)); if (!zl3vni) { - snprintf(err, err_str_sz, - "Could not add L3-VNI"); + snprintf(err, err_str_sz, "Could not add L3-VNI"); return -1; } @@ -6526,8 +6431,8 @@ int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf *zvrf, zl3vni->svi_if = zl3vni_map_to_svi_if(zl3vni); /* formulate l2vni list */ - hash_iterate(zvrf_default->vni_table, - zvni_add_to_l3vni_list, zl3vni); + hash_iterate(zvrf_default->vni_table, zvni_add_to_l3vni_list, + zl3vni); if (is_l3vni_oper_up(zl3vni)) zebra_vxlan_process_l3vni_oper_up(zl3vni); @@ -6542,13 +6447,11 @@ int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf *zvrf, zebra_vxlan_process_l3vni_oper_down(zl3vni); /* delete and uninstall all rmacs */ - hash_iterate(zl3vni->rmac_table, - zl3vni_del_rmac_hash_entry, + hash_iterate(zl3vni->rmac_table, zl3vni_del_rmac_hash_entry, zl3vni); /* delete and uninstall all next-hops */ - hash_iterate(zl3vni->nh_table, - zl3vni_del_nh_hash_entry, + hash_iterate(zl3vni->nh_table, zl3vni_del_nh_hash_entry, zl3vni); zvrf->l3vni = 0; @@ -6639,10 +6542,9 @@ int zebra_vxlan_advertise_subnet(struct zserv *client, u_short length, return 0; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug( - "EVPN subnet Adv %s on VNI %d , currently %s", - advertise ? "enabled" : "disabled", vni, - zvni->advertise_subnet ? "enabled" : "disabled"); + zlog_debug("EVPN subnet Adv %s on VNI %d , currently %s", + advertise ? "enabled" : "disabled", vni, + zvni->advertise_subnet ? "enabled" : "disabled"); zvni->advertise_subnet = advertise; @@ -6659,8 +6561,8 @@ int zebra_vxlan_advertise_subnet(struct zserv *client, u_short length, zl2_info = zif->l2info.vxl; - vlan_if = zvni_map_to_svi(zl2_info.access_vlan, - zif->brslave_info.br_if); + vlan_if = + zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if); if (!vlan_if) return 0; @@ -6729,9 +6631,8 @@ int zebra_vxlan_advertise_gw_macip(struct zserv *client, u_short length, zlog_debug( "EVPN gateway macip Adv %s on VNI %d , currently %s", advertise ? "enabled" : "disabled", vni, - advertise_gw_macip_enabled(zvni) - ? "enabled" - : "disabled"); + advertise_gw_macip_enabled(zvni) ? "enabled" + : "disabled"); if (zvni->advertise_gw_macip == advertise) return 0; @@ -6785,16 +6686,15 @@ stream_failure: * when disabled, the entries should be deleted and remote VTEPs and MACs * uninstalled from the kernel. */ -int zebra_vxlan_advertise_all_vni(struct zserv *client, - u_short length, struct zebra_vrf *zvrf) +int zebra_vxlan_advertise_all_vni(struct zserv *client, u_short length, + struct zebra_vrf *zvrf) { struct stream *s = NULL; int advertise = 0; struct zebra_ns *zns = NULL; if (zvrf_id(zvrf) != VRF_DEFAULT) { - zlog_err("EVPN VNI Adv for non-default VRF %u", - zvrf_id(zvrf)); + zlog_err("EVPN VNI Adv for non-default VRF %u", zvrf_id(zvrf)); return -1; } diff --git a/zebra/zebra_vxlan.h b/zebra/zebra_vxlan.h index df9b07db60..7abf0050fc 100644 --- a/zebra/zebra_vxlan.h +++ b/zebra/zebra_vxlan.h @@ -36,8 +36,7 @@ /* Is EVPN enabled? */ #define EVPN_ENABLED(zvrf) (zvrf)->advertise_all_vni -static inline int -is_evpn_enabled() +static inline int is_evpn_enabled() { struct zebra_vrf *zvrf = NULL; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); @@ -97,11 +96,11 @@ extern void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni, u_char use_json); extern void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf, u_char use_json); -extern void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t vni, u_char - use_json); +extern void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t vni, + u_char use_json); extern void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, u_char use_json); -extern void zebra_vxlan_print_nh_l3vni(struct vty *vty, vni_t vni, u_char - use_json); +extern void zebra_vxlan_print_nh_l3vni(struct vty *vty, vni_t vni, + u_char use_json); extern void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, u_char use_json); extern void zebra_vxlan_print_l3vni(struct vty *vty, vni_t vni, u_char use_json); @@ -118,10 +117,10 @@ extern int zebra_vxlan_local_neigh_add_update( extern int zebra_vxlan_local_neigh_del(struct interface *ifp, struct interface *link_if, struct ipaddr *ip); -extern int zebra_vxlan_remote_macip_add(struct zserv *client, - u_short length, struct zebra_vrf *zvrf); -extern int zebra_vxlan_remote_macip_del(struct zserv *client, - u_short length, struct zebra_vrf *zvrf); +extern int zebra_vxlan_remote_macip_add(struct zserv *client, u_short length, + struct zebra_vrf *zvrf); +extern int zebra_vxlan_remote_macip_del(struct zserv *client, u_short length, + struct zebra_vrf *zvrf); extern int zebra_vxlan_local_mac_add_update(struct interface *ifp, struct interface *br_if, struct ethaddr *mac, vlanid_t vid, @@ -141,21 +140,19 @@ extern int zebra_vxlan_if_down(struct interface *ifp); extern int zebra_vxlan_if_add(struct interface *ifp); extern int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags); extern int zebra_vxlan_if_del(struct interface *ifp); -extern int zebra_vxlan_remote_vtep_add(struct zserv *client, - u_short length, struct zebra_vrf *zvrf); -extern int zebra_vxlan_remote_vtep_del(struct zserv *client, - u_short length, struct zebra_vrf *zvrf); +extern int zebra_vxlan_remote_vtep_add(struct zserv *client, u_short length, + struct zebra_vrf *zvrf); +extern int zebra_vxlan_remote_vtep_del(struct zserv *client, u_short length, + struct zebra_vrf *zvrf); extern int zebra_vxlan_advertise_subnet(struct zserv *client, u_short length, struct zebra_vrf *zvrf); -extern int zebra_vxlan_advertise_gw_macip(struct zserv *client, - u_short length, +extern int zebra_vxlan_advertise_gw_macip(struct zserv *client, u_short length, struct zebra_vrf *zvrf); -extern int zebra_vxlan_advertise_all_vni(struct zserv *client, - u_short length, +extern int zebra_vxlan_advertise_all_vni(struct zserv *client, u_short length, struct zebra_vrf *zvrf); extern int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf *zvrf, vni_t vni, - char *err, - int err_str_sz, int filter, int add); + char *err, int err_str_sz, + int filter, int add); extern void zebra_vxlan_init_tables(struct zebra_vrf *zvrf); extern void zebra_vxlan_close_tables(struct zebra_vrf *); extern void zebra_vxlan_cleanup_tables(struct zebra_vrf *); diff --git a/zebra/zebra_vxlan_null.c b/zebra/zebra_vxlan_null.c index 0eb880e848..1bac2cafb6 100644 --- a/zebra/zebra_vxlan_null.c +++ b/zebra/zebra_vxlan_null.c @@ -87,19 +87,19 @@ void zebra_vxlan_print_evpn(struct vty *vty, u_char uj) { } -void zebra_vxlan_print_rmacs_l3vni(struct vty*, vni_t, u_char) +void zebra_vxlan_print_rmacs_l3vni(struct vty *, vni_t, u_char) { } -void zebra_vxlan_print_rmacs_all_l3vni(struct vty*, u_char) +void zebra_vxlan_print_rmacs_all_l3vni(struct vty *, u_char) { } -void zebra_vxlan_print_nh_l3vni(struct vty*, vni_t, u_char) +void zebra_vxlan_print_nh_l3vni(struct vty *, vni_t, u_char) { } -void zebra_vxlan_print_nh_all_l3vni(struct vty*, u_char) +void zebra_vxlan_print_nh_all_l3vni(struct vty *, u_char) { } diff --git a/zebra/zebra_vxlan_private.h b/zebra/zebra_vxlan_private.h index e8de25cefd..6174c6a56d 100644 --- a/zebra/zebra_vxlan_private.h +++ b/zebra/zebra_vxlan_private.h @@ -180,10 +180,9 @@ static inline const char *zl3vni_rmac2str(zebra_l3vni_t *zl3vni, char *buf, */ static inline int is_l3vni_oper_up(zebra_l3vni_t *zl3vni) { - return (is_evpn_enabled() && zl3vni && - (zl3vni->vrf_id != VRF_UNKNOWN) && - zl3vni->vxlan_if && if_is_operative(zl3vni->vxlan_if) && - zl3vni->svi_if && if_is_operative(zl3vni->svi_if)); + return (is_evpn_enabled() && zl3vni && (zl3vni->vrf_id != VRF_UNKNOWN) + && zl3vni->vxlan_if && if_is_operative(zl3vni->vxlan_if) + && zl3vni->svi_if && if_is_operative(zl3vni->svi_if)); } static inline const char *zl3vni_state2str(zebra_l3vni_t *zl3vni) @@ -204,8 +203,7 @@ static inline vrf_id_t zl3vni_vrf_id(zebra_l3vni_t *zl3vni) return zl3vni->vrf_id; } -static inline void zl3vni_get_rmac(zebra_l3vni_t *zl3vni, - struct ethaddr *rmac) +static inline void zl3vni_get_rmac(zebra_l3vni_t *zl3vni, struct ethaddr *rmac) { if (!zl3vni) return; diff --git a/zebra/zserv.c b/zebra/zserv.c index 07258cdb72..9afffbda1e 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -60,6 +60,7 @@ #include "zebra/label_manager.h" #include "zebra/zebra_vxlan.h" #include "zebra/rt.h" +#include "zebra/zebra_pbr.h" /* Event list of zebra. */ enum event { ZEBRA_SERV, ZEBRA_READ, ZEBRA_WRITE }; @@ -189,8 +190,8 @@ static void zserv_encode_vrf(struct stream *s, struct zebra_vrf *zvrf) data.l.table_id = zvrf->table_id; if (netns_name) - strlcpy(data.l.netns_name, - basename((char *)netns_name), NS_NAMSIZ); + strlcpy(data.l.netns_name, basename((char *)netns_name), + NS_NAMSIZ); else memset(data.l.netns_name, 0, NS_NAMSIZ); /* Pass the tableid and the netns NAME */ @@ -616,7 +617,7 @@ int zsend_redistribute_route(int cmd, struct zserv *client, struct prefix *p, SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); api.nexthop_num = re->nexthop_active_num; } - for (nexthop = re->nexthop; nexthop; nexthop = nexthop->next) { + for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) { if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) continue; @@ -718,16 +719,18 @@ static int zserv_rnh_register(struct zserv *client, u_short length, l += 4; if (p.family == AF_INET) { if (p.prefixlen > IPV4_MAX_BITLEN) { - zlog_warn("%s: Specified prefix length %d is too large for a v4 address", - __PRETTY_FUNCTION__, p.prefixlen); + zlog_warn( + "%s: Specified prefix length %d is too large for a v4 address", + __PRETTY_FUNCTION__, p.prefixlen); return -1; } STREAM_GET(&p.u.prefix4.s_addr, s, IPV4_MAX_BYTELEN); l += IPV4_MAX_BYTELEN; } else if (p.family == AF_INET6) { if (p.prefixlen > IPV6_MAX_BITLEN) { - zlog_warn("%s: Specified prefix length %d is to large for a v6 address", - __PRETTY_FUNCTION__, p.prefixlen); + zlog_warn( + "%s: Specified prefix length %d is to large for a v6 address", + __PRETTY_FUNCTION__, p.prefixlen); return -1; } STREAM_GET(&p.u.prefix6, s, IPV6_MAX_BYTELEN); @@ -791,16 +794,18 @@ static int zserv_rnh_unregister(struct zserv *client, u_short length, l += 4; if (p.family == AF_INET) { if (p.prefixlen > IPV4_MAX_BITLEN) { - zlog_warn("%s: Specified prefix length %d is to large for a v4 address", - __PRETTY_FUNCTION__, p.prefixlen); + zlog_warn( + "%s: Specified prefix length %d is to large for a v4 address", + __PRETTY_FUNCTION__, p.prefixlen); return -1; } STREAM_GET(&p.u.prefix4.s_addr, s, IPV4_MAX_BYTELEN); l += IPV4_MAX_BYTELEN; } else if (p.family == AF_INET6) { if (p.prefixlen > IPV6_MAX_BITLEN) { - zlog_warn("%s: Specified prefix length %d is to large for a v6 address", - __PRETTY_FUNCTION__, p.prefixlen); + zlog_warn( + "%s: Specified prefix length %d is to large for a v6 address", + __PRETTY_FUNCTION__, p.prefixlen); return -1; } STREAM_GET(&p.u.prefix6, s, IPV6_MAX_BYTELEN); @@ -860,10 +865,12 @@ static int zserv_fec_register(struct zserv *client, u_short length) return -1; } STREAM_GETC(s, p.prefixlen); - if ((p.family == AF_INET && p.prefixlen > IPV4_MAX_BITLEN) || - (p.family == AF_INET6 && p.prefixlen > IPV6_MAX_BITLEN)) { - zlog_warn("%s: Specified prefix length: %d is to long for %d", - __PRETTY_FUNCTION__, p.prefixlen, p.family); + if ((p.family == AF_INET && p.prefixlen > IPV4_MAX_BITLEN) + || (p.family == AF_INET6 + && p.prefixlen > IPV6_MAX_BITLEN)) { + zlog_warn( + "%s: Specified prefix length: %d is to long for %d", + __PRETTY_FUNCTION__, p.prefixlen, p.family); return -1; } l += 5; @@ -920,10 +927,12 @@ static int zserv_fec_unregister(struct zserv *client, u_short length) return -1; } STREAM_GETC(s, p.prefixlen); - if ((p.family == AF_INET && p.prefixlen > IPV4_MAX_BITLEN) || - (p.family == AF_INET6 && p.prefixlen > IPV6_MAX_BITLEN)) { - zlog_warn("%s: Received prefix length %d which is greater than %d can support", - __PRETTY_FUNCTION__, p.prefixlen, p.family); + if ((p.family == AF_INET && p.prefixlen > IPV4_MAX_BITLEN) + || (p.family == AF_INET6 + && p.prefixlen > IPV6_MAX_BITLEN)) { + zlog_warn( + "%s: Received prefix length %d which is greater than %d can support", + __PRETTY_FUNCTION__, p.prefixlen, p.family); return -1; } l += 5; @@ -970,7 +979,7 @@ static int zsend_ipv4_nexthop_lookup_mrib(struct zserv *client, * we * are looking up. Therefore, we will just iterate over the top * chain of nexthops. */ - for (nexthop = re->nexthop; nexthop; nexthop = nexthop->next) + for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) num += zsend_write_nexthop(s, nexthop); @@ -1034,6 +1043,44 @@ int zsend_route_notify_owner(struct route_entry *re, struct prefix *p, return zebra_server_send_message(client); } +void zsend_rule_notify_owner(struct zebra_pbr_rule *rule, + enum zapi_rule_notify_owner note) +{ + struct listnode *node; + struct zserv *client; + struct stream *s; + + if (IS_ZEBRA_DEBUG_PACKET) { + zlog_debug("%s: Notifying %u", + __PRETTY_FUNCTION__, rule->unique); + } + + for (ALL_LIST_ELEMENTS_RO(zebrad.client_list, node, client)) { + if (rule->sock == client->sock) + break; + } + + if (!client) + return; + + s = client->obuf; + stream_reset(s); + + zclient_create_header(s, ZEBRA_RULE_NOTIFY_OWNER, VRF_DEFAULT); + stream_put(s, ¬e, sizeof(note)); + stream_putl(s, rule->seq); + stream_putl(s, rule->priority); + stream_putl(s, rule->unique); + if (rule->ifp) + stream_putl(s, rule->ifp->ifindex); + else + stream_putl(s, 0); + + stream_putw_at(s, 0, stream_get_endp(s)); + + zebra_server_send_message(client); +} + /* Router-id is updated. Send ZEBRA_ROUTER_ID_ADD to client. */ int zsend_router_id_update(struct zserv *client, struct prefix *p, vrf_id_t vrf_id) @@ -1157,7 +1204,10 @@ static int zread_route_add(struct zserv *client, u_short length, re->flags = api.flags; re->uptime = time(NULL); re->vrf_id = vrf_id; - re->table = zvrf->table_id; + if (api.tableid && vrf_id == VRF_DEFAULT) + re->table = api.tableid; + else + re->table = zvrf->table_id; if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP)) { for (i = 0; i < api.nexthop_num; i++) { @@ -1179,8 +1229,7 @@ static int zread_route_add(struct zserv *client, u_short length, memset(&vtep_ip, 0, sizeof(struct ipaddr)); if (CHECK_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE)) { - ifindex = - get_l3vni_svi_ifindex(vrf_id); + ifindex = get_l3vni_svi_ifindex(vrf_id); } else { ifindex = api_nh->ifindex; } @@ -1201,10 +1250,8 @@ static int zread_route_add(struct zserv *client, u_short length, &(api_nh->gate.ipv4), sizeof(struct in_addr)); zebra_vxlan_evpn_vrf_route_add( - vrf_id, - &api.rmac, - &vtep_ip, - &api.prefix); + vrf_id, &api.rmac, &vtep_ip, + &api.prefix); } break; case NEXTHOP_TYPE_IPV6: @@ -1250,9 +1297,10 @@ static int zread_route_add(struct zserv *client, u_short length, } if (!nexthop) { - zlog_warn("%s: Nexthops Specified: %d but we failed to properly create one", - __PRETTY_FUNCTION__, api.nexthop_num); - nexthops_free(re->nexthop); + zlog_warn( + "%s: Nexthops Specified: %d but we failed to properly create one", + __PRETTY_FUNCTION__, api.nexthop_num); + nexthops_free(re->ng.nexthop); XFREE(MTYPE_RE, re); return -1; } @@ -1284,7 +1332,7 @@ static int zread_route_add(struct zserv *client, u_short length, if (afi != AFI_IP6 && CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) { zlog_warn("%s: Received SRC Prefix but afi is not v6", __PRETTY_FUNCTION__); - nexthops_free(re->nexthop); + nexthops_free(re->ng.nexthop); XFREE(MTYPE_RE, re); return -1; } @@ -1399,8 +1447,9 @@ static int zread_ipv4_add(struct zserv *client, u_short length, p.family = AF_INET; STREAM_GETC(s, p.prefixlen); if (p.prefixlen > IPV4_MAX_BITLEN) { - zlog_warn("%s: Specified prefix length %d is greater than what v4 can be", - __PRETTY_FUNCTION__, p.prefixlen); + zlog_warn( + "%s: Specified prefix length %d is greater than what v4 can be", + __PRETTY_FUNCTION__, p.prefixlen); XFREE(MTYPE_RE, re); return -1; } @@ -1449,9 +1498,10 @@ static int zread_ipv4_add(struct zserv *client, u_short length, re->vrf_id); break; case NEXTHOP_TYPE_IPV6: - zlog_warn("%s: Please use ZEBRA_ROUTE_ADD if you want to pass v6 nexthops", - __PRETTY_FUNCTION__); - nexthops_free(re->nexthop); + zlog_warn( + "%s: Please use ZEBRA_ROUTE_ADD if you want to pass v6 nexthops", + __PRETTY_FUNCTION__); + nexthops_free(re->ng.nexthop); XFREE(MTYPE_RE, re); return -1; break; @@ -1459,9 +1509,10 @@ static int zread_ipv4_add(struct zserv *client, u_short length, route_entry_nexthop_blackhole_add(re, bh_type); break; default: - zlog_warn("%s: Specified nexthop type: %d does not exist", - __PRETTY_FUNCTION__, nexthop_type); - nexthops_free(re->nexthop); + zlog_warn( + "%s: Specified nexthop type: %d does not exist", + __PRETTY_FUNCTION__, nexthop_type); + nexthops_free(re->ng.nexthop); XFREE(MTYPE_RE, re); return -1; } @@ -1501,7 +1552,7 @@ static int zread_ipv4_add(struct zserv *client, u_short length, return 0; stream_failure: - nexthops_free(re->nexthop); + nexthops_free(re->ng.nexthop); XFREE(MTYPE_RE, re); return -1; } @@ -1610,8 +1661,9 @@ static int zread_ipv4_route_ipv6_nexthop_add(struct zserv *client, p.family = AF_INET; STREAM_GETC(s, p.prefixlen); if (p.prefixlen > IPV4_MAX_BITLEN) { - zlog_warn("%s: Prefix Length %d is greater than what a v4 address can use", - __PRETTY_FUNCTION__, p.prefixlen); + zlog_warn( + "%s: Prefix Length %d is greater than what a v4 address can use", + __PRETTY_FUNCTION__, p.prefixlen); XFREE(MTYPE_RE, re); return -1; } @@ -1663,9 +1715,10 @@ static int zread_ipv4_route_ipv6_nexthop_add(struct zserv *client, route_entry_nexthop_blackhole_add(re, bh_type); break; default: - zlog_warn("%s: Please use ZEBRA_ROUTE_ADD if you want to pass non v6 nexthops", - __PRETTY_FUNCTION__); - nexthops_free(re->nexthop); + zlog_warn( + "%s: Please use ZEBRA_ROUTE_ADD if you want to pass non v6 nexthops", + __PRETTY_FUNCTION__); + nexthops_free(re->ng.nexthop); XFREE(MTYPE_RE, re); return -1; } @@ -1728,7 +1781,7 @@ static int zread_ipv4_route_ipv6_nexthop_add(struct zserv *client, return 0; stream_failure: - nexthops_free(re->nexthop); + nexthops_free(re->ng.nexthop); XFREE(MTYPE_RE, re); return -1; } @@ -1783,8 +1836,9 @@ static int zread_ipv6_add(struct zserv *client, u_short length, p.family = AF_INET6; STREAM_GETC(s, p.prefixlen); if (p.prefixlen > IPV6_MAX_BITLEN) { - zlog_warn("%s: Specified prefix length %d is to large for v6 prefix", - __PRETTY_FUNCTION__, p.prefixlen); + zlog_warn( + "%s: Specified prefix length %d is to large for v6 prefix", + __PRETTY_FUNCTION__, p.prefixlen); XFREE(MTYPE_RE, re); return -1; } @@ -1795,8 +1849,9 @@ static int zread_ipv6_add(struct zserv *client, u_short length, src_p.family = AF_INET6; STREAM_GETC(s, src_p.prefixlen); if (src_p.prefixlen > IPV6_MAX_BITLEN) { - zlog_warn("%s: Specified src prefix length %d is to large for v6 prefix", - __PRETTY_FUNCTION__, src_p.prefixlen); + zlog_warn( + "%s: Specified src prefix length %d is to large for v6 prefix", + __PRETTY_FUNCTION__, src_p.prefixlen); XFREE(MTYPE_RE, re); return -1; } @@ -1856,9 +1911,10 @@ static int zread_ipv6_add(struct zserv *client, u_short length, route_entry_nexthop_blackhole_add(re, bh_type); break; default: - zlog_warn("%s: Please use ZEBRA_ROUTE_ADD if you want to pass non v6 nexthops", - __PRETTY_FUNCTION__); - nexthops_free(re->nexthop); + zlog_warn( + "%s: Please use ZEBRA_ROUTE_ADD if you want to pass non v6 nexthops", + __PRETTY_FUNCTION__); + nexthops_free(re->ng.nexthop); XFREE(MTYPE_RE, re); return -1; } @@ -1919,7 +1975,7 @@ static int zread_ipv6_add(struct zserv *client, u_short length, return 0; stream_failure: - nexthops_free(re->nexthop); + nexthops_free(re->ng.nexthop); XFREE(MTYPE_RE, re); return -1; @@ -2060,9 +2116,9 @@ static void zread_mpls_labels(int command, struct zserv *client, u_short length, STREAM_GET(&prefix.u.prefix4.s_addr, s, IPV4_MAX_BYTELEN); STREAM_GETC(s, prefix.prefixlen); if (prefix.prefixlen > IPV4_MAX_BITLEN) { - zlog_warn("%s: Specified prefix length %d is greater than a v4 address can support", - __PRETTY_FUNCTION__, - prefix.prefixlen); + zlog_warn( + "%s: Specified prefix length %d is greater than a v4 address can support", + __PRETTY_FUNCTION__, prefix.prefixlen); return; } STREAM_GET(&gate.ipv4.s_addr, s, IPV4_MAX_BYTELEN); @@ -2071,9 +2127,9 @@ static void zread_mpls_labels(int command, struct zserv *client, u_short length, STREAM_GET(&prefix.u.prefix6, s, 16); STREAM_GETC(s, prefix.prefixlen); if (prefix.prefixlen > IPV6_MAX_BITLEN) { - zlog_warn("%s: Specified prefix length %d is greater than a v6 address can support", - __PRETTY_FUNCTION__, - prefix.prefixlen); + zlog_warn( + "%s: Specified prefix length %d is greater than a v6 address can support", + __PRETTY_FUNCTION__, prefix.prefixlen); return; } STREAM_GET(&gate.ipv6, s, 16); @@ -2262,13 +2318,11 @@ static void zread_label_manager_request(int cmd, struct zserv *client, /* external label manager */ if (lm_is_external) - zread_relay_label_manager_request(cmd, client, - zvrf_id(zvrf)); + zread_relay_label_manager_request(cmd, client, zvrf_id(zvrf)); /* this is a label manager */ else { if (cmd == ZEBRA_LABEL_MANAGER_CONNECT) - zread_label_manager_connect(client, - zvrf_id(zvrf)); + zread_label_manager_connect(client, zvrf_id(zvrf)); else { /* Sanity: don't allow 'unidentified' requests */ if (!client->proto) { @@ -2277,8 +2331,7 @@ static void zread_label_manager_request(int cmd, struct zserv *client, return; } if (cmd == ZEBRA_GET_LABEL_CHUNK) - zread_get_label_chunk(client, - zvrf_id(zvrf)); + zread_get_label_chunk(client, zvrf_id(zvrf)); else if (cmd == ZEBRA_RELEASE_LABEL_CHUNK) zread_release_label_chunk(client); } @@ -2504,8 +2557,7 @@ static void zebra_client_create(int sock) zebra_vrf_update_all(client); } -static int zread_interface_set_master(struct zserv *client, - u_short length) +static int zread_interface_set_master(struct zserv *client, u_short length) { struct interface *master; struct interface *slave; @@ -2531,8 +2583,7 @@ stream_failure: } -static void zread_vrf_label(struct zserv *client, - struct zebra_vrf *zvrf) +static void zread_vrf_label(struct zserv *client, struct zebra_vrf *zvrf) { struct interface *ifp; mpls_label_t nlabel; @@ -2571,7 +2622,7 @@ static void zread_vrf_label(struct zserv *client, bool really_remove; really_remove = true; - for (scrubber = AFI_IP; scrubber < AFI_MAX ; scrubber++) { + for (scrubber = AFI_IP; scrubber < AFI_MAX; scrubber++) { if (scrubber == afi) continue; @@ -2591,16 +2642,75 @@ static void zread_vrf_label(struct zserv *client, } if (nlabel != MPLS_LABEL_NONE) - mpls_lsp_install(def_zvrf, ltype, nlabel, MPLS_LABEL_IMPLICIT_NULL, - NEXTHOP_TYPE_IFINDEX, NULL, ifp->ifindex); + mpls_lsp_install(def_zvrf, ltype, nlabel, + MPLS_LABEL_IMPLICIT_NULL, NEXTHOP_TYPE_IFINDEX, + NULL, ifp->ifindex); zvrf->label[afi] = nlabel; stream_failure: return; } -static inline void zserv_handle_commands(struct zserv *client, - uint16_t command, +static inline void zread_rule(uint16_t command, struct zserv *client, + uint16_t length, struct zebra_vrf *zvrf) +{ + struct zebra_pbr_rule zpr; + struct stream *s; + uint32_t total, i; + ifindex_t ifindex; + + s = client->ibuf; + STREAM_GETL(s, total); + + for (i = 0; i < total; i++) { + memset(&zpr, 0, sizeof(zpr)); + + zpr.sock = client->sock; + STREAM_GETL(s, zpr.seq); + STREAM_GETL(s, zpr.priority); + STREAM_GETL(s, zpr.unique); + STREAM_GETC(s, zpr.filter.src_ip.family); + STREAM_GETC(s, zpr.filter.src_ip.prefixlen); + STREAM_GET(&zpr.filter.src_ip.u.prefix, s, + prefix_blen(&zpr.filter.src_ip)); + STREAM_GETW(s, zpr.filter.src_port); + STREAM_GETC(s, zpr.filter.dst_ip.family); + STREAM_GETC(s, zpr.filter.dst_ip.prefixlen); + STREAM_GET(&zpr.filter.dst_ip.u.prefix, s, + prefix_blen(&zpr.filter.dst_ip)); + STREAM_GETW(s, zpr.filter.dst_port); + STREAM_GETL(s, zpr.action.table); + STREAM_GETL(s, ifindex); + + zpr.ifp = if_lookup_by_index(ifindex, VRF_UNKNOWN); + if (!zpr.ifp) { + zlog_debug("FAiled to lookup ifindex: %u", ifindex); + return; + } + + if (!is_default_prefix(&zpr.filter.src_ip)) + zpr.filter.filter_bm |= PBR_FILTER_SRC_IP; + + if (!is_default_prefix(&zpr.filter.dst_ip)) + zpr.filter.filter_bm |= PBR_FILTER_DST_IP; + + if (zpr.filter.src_port) + zpr.filter.filter_bm |= PBR_FILTER_SRC_PORT; + + if (zpr.filter.dst_port) + zpr.filter.filter_bm |= PBR_FILTER_DST_PORT; + + if (command == ZEBRA_RULE_ADD) + zebra_pbr_add_rule(zvrf->zns, &zpr); + else + zebra_pbr_del_rule(zvrf->zns, &zpr); + } + +stream_failure: + return; +} + +static inline void zserv_handle_commands(struct zserv *client, uint16_t command, uint16_t length, struct zebra_vrf *zvrf) { @@ -2658,20 +2768,17 @@ static inline void zserv_handle_commands(struct zserv *client, zread_hello(client); break; case ZEBRA_NEXTHOP_REGISTER: - zserv_rnh_register(client, length, RNH_NEXTHOP_TYPE, - zvrf); + zserv_rnh_register(client, length, RNH_NEXTHOP_TYPE, zvrf); break; case ZEBRA_NEXTHOP_UNREGISTER: - zserv_rnh_unregister(client, length, RNH_NEXTHOP_TYPE, - zvrf); + zserv_rnh_unregister(client, length, RNH_NEXTHOP_TYPE, zvrf); break; case ZEBRA_IMPORT_ROUTE_REGISTER: - zserv_rnh_register(client, length, RNH_IMPORT_CHECK_TYPE, - zvrf); + zserv_rnh_register(client, length, RNH_IMPORT_CHECK_TYPE, zvrf); break; case ZEBRA_IMPORT_ROUTE_UNREGISTER: - zserv_rnh_unregister(client, length, - RNH_IMPORT_CHECK_TYPE, zvrf); + zserv_rnh_unregister(client, length, RNH_IMPORT_CHECK_TYPE, + zvrf); break; case ZEBRA_BFD_DEST_UPDATE: case ZEBRA_BFD_DEST_REGISTER: @@ -2747,6 +2854,10 @@ static inline void zserv_handle_commands(struct zserv *client, case ZEBRA_PW_UNSET: zread_pseudowire(command, client, length, zvrf); break; + case ZEBRA_RULE_ADD: + case ZEBRA_RULE_DELETE: + zread_rule(command, client, length, zvrf); + break; default: zlog_info("Zebra received unknown command %d", command); break; @@ -2804,14 +2915,15 @@ static int zebra_client_read(struct thread *thread) if ((already = stream_get_endp(client->ibuf)) < ZEBRA_HEADER_SIZE) { ssize_t nbyte; - if (((nbyte = - stream_read_try(client->ibuf, sock, - ZEBRA_HEADER_SIZE - already)) + if (((nbyte = stream_read_try(client->ibuf, sock, + ZEBRA_HEADER_SIZE + - already)) == 0) || (nbyte == -1)) { if (IS_ZEBRA_DEBUG_EVENT) - zlog_debug("connection closed socket [%d]", - sock); + zlog_debug( + "connection closed socket [%d]", + sock); zebra_client_close(client); return -1; } @@ -2884,11 +2996,13 @@ static int zebra_client_read(struct thread *thread) /* Debug packet information. */ if (IS_ZEBRA_DEBUG_EVENT) - zlog_debug("zebra message comes from socket [%d]", sock); + zlog_debug("zebra message comes from socket [%d]", + sock); if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV) zlog_debug("zebra message received [%s] %d in VRF %u", - zserv_command_string(command), length, vrf_id); + zserv_command_string(command), length, + vrf_id); client->last_read_time = monotime(NULL); client->last_read_cmd = command; @@ -2896,14 +3010,16 @@ static int zebra_client_read(struct thread *thread) zvrf = zebra_vrf_lookup_by_id(vrf_id); if (!zvrf) { if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV) - zlog_debug("zebra received unknown VRF[%u]", vrf_id); + zlog_debug("zebra received unknown VRF[%u]", + vrf_id); goto zclient_read_out; } zserv_handle_commands(client, command, length, zvrf); if (client->t_suicide) { - /* No need to wait for thread callback, just kill immediately. + /* No need to wait for thread callback, just kill + * immediately. */ zebra_client_close(client); return -1; @@ -3161,8 +3277,7 @@ struct zserv *zebra_find_client(u_char proto, u_short instance) struct zserv *client; for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client)) { - if (client->proto == proto && - client->instance == instance) + if (client->proto == proto && client->instance == instance) return client; } @@ -3221,7 +3336,7 @@ void zserv_read_file(char *input) client = zebrad.client_list->head->data; t.arg = client; - fd = open(input, O_RDONLY|O_NONBLOCK); + fd = open(input, O_RDONLY | O_NONBLOCK); t.u.fd = fd; zebra_client_read(&t); diff --git a/zebra/zserv.h b/zebra/zserv.h index 2044816227..8519693726 100644 --- a/zebra/zserv.h +++ b/zebra/zserv.h @@ -31,6 +31,7 @@ #include "zebra/zebra_ns.h" #include "zebra/zebra_pw.h" +//#include "zebra/zebra_pbr.h" /* Default port information. */ #define ZEBRA_VTY_PORT 2601 @@ -137,15 +138,15 @@ struct zebra_t { /* default table */ u_int32_t rtm_table_default; - /* rib work queue */ - #define ZEBRA_RIB_PROCESS_HOLD_TIME 10 +/* rib work queue */ +#define ZEBRA_RIB_PROCESS_HOLD_TIME 10 struct work_queue *ribq; struct meta_queue *mq; /* LSP work queue */ struct work_queue *lsp_process_q; - #define ZEBRA_ZAPI_PACKETS_TO_PROCESS 10 +#define ZEBRA_ZAPI_PACKETS_TO_PROCESS 10 u_int32_t packets_to_process; }; extern struct zebra_t zebrad; @@ -178,6 +179,10 @@ extern int zsend_pw_update(struct zserv *, struct zebra_pw *); extern int zsend_route_notify_owner(struct route_entry *re, struct prefix *p, enum zapi_route_notify_owner note); +struct zebra_pbr_rule; +extern void zsend_rule_notify_owner(struct zebra_pbr_rule *rule, + enum zapi_rule_notify_owner note); + extern void zserv_nexthop_num_warn(const char *, const struct prefix *, const unsigned int); extern int zebra_server_send_message(struct zserv *client); |
