diff options
40 files changed, 1269 insertions, 1446 deletions
diff --git a/bfdd/ptm_adapter.c b/bfdd/ptm_adapter.c index d3d54c1780..90e2df2367 100644 --- a/bfdd/ptm_adapter.c +++ b/bfdd/ptm_adapter.c @@ -84,10 +84,11 @@ static void bfdd_client_deregister(struct stream *msg); static void debug_printbpc(const struct bfd_peer_cfg *bpc, const char *fmt, ...) { char timers[3][128] = {}; + char minttl_str[32] = {}; char addr[3][128] = {}; char profile[128] = {}; char cbit_str[32]; - char msgbuf[256]; + char msgbuf[512]; va_list vl; /* Avoid debug calculations if it's disabled. */ @@ -120,6 +121,10 @@ static void debug_printbpc(const struct bfd_peer_cfg *bpc, const char *fmt, ...) snprintf(cbit_str, sizeof(cbit_str), " cbit:0x%02x", bpc->bpc_cbit); + if (bpc->bpc_has_minimum_ttl) + snprintf(minttl_str, sizeof(minttl_str), " minimum-ttl:%d", + bpc->bpc_minimum_ttl); + if (bpc->bpc_has_profile) snprintf(profile, sizeof(profile), " profile:%s", bpc->bpc_profile); @@ -128,9 +133,10 @@ static void debug_printbpc(const struct bfd_peer_cfg *bpc, const char *fmt, ...) vsnprintf(msgbuf, sizeof(msgbuf), fmt, vl); va_end(vl); - zlog_debug("%s [mhop:%s %s%s%s%s%s%s%s%s]", msgbuf, + zlog_debug("%s [mhop:%s %s%s%s%s%s%s%s%s%s]", msgbuf, bpc->bpc_mhop ? "yes" : "no", addr[0], addr[1], addr[2], - timers[0], timers[1], timers[2], cbit_str, profile); + timers[0], timers[1], timers[2], cbit_str, minttl_str, + profile); } static void _ptm_bfd_session_del(struct bfd_session *bs, uint8_t diag) @@ -307,6 +313,8 @@ static int _ptm_msg_read(struct stream *msg, int command, vrf_id_t vrf_id, /* * Register/Deregister/Update Message format: + * + * Old format (being used by PTM BFD). * - header: Command, VRF * - l: pid * - w: family @@ -322,16 +330,37 @@ static int _ptm_msg_read(struct stream *msg, int command, vrf_id_t vrf_id, * - multihop: * - w: family * - AF_INET: - * - l: destination ipv4 + * - l: source IPv4 address * - AF_INET6: - * - 16 bytes: destination IPv6 + * - 16 bytes: source IPv6 address * - c: ttl * - no multihop * - AF_INET6: * - w: family - * - 16 bytes: ipv6 address + * - 16 bytes: source IPv6 address * - c: ifname length * - X bytes: interface name + * + * New format: + * - header: Command, VRF + * - l: pid + * - w: family + * - AF_INET: + * - l: destination IPv4 address + * - AF_INET6: + * - 16 bytes: destination IPv6 address + * - l: min_rx + * - l: min_tx + * - c: detect multiplier + * - c: is_multihop? + * - w: family + * - AF_INET: + * - l: source IPv4 address + * - AF_INET6: + * - 16 bytes: source IPv6 address + * - c: ttl + * - c: ifname length + * - X bytes: interface name * - c: bfd_cbit * - c: profile name length. * - X bytes: profile name. @@ -355,58 +384,50 @@ static int _ptm_msg_read(struct stream *msg, int command, vrf_id_t vrf_id, bpc->bpc_ipv4 = (bpc->bpc_peer.sa_sin.sin_family == AF_INET); /* Get peer configuration. */ - if (command != ZEBRA_BFD_DEST_DEREGISTER) { - STREAM_GETL(msg, bpc->bpc_recvinterval); - bpc->bpc_has_recvinterval = - (bpc->bpc_recvinterval != BPC_DEF_RECEIVEINTERVAL); - - STREAM_GETL(msg, bpc->bpc_txinterval); - bpc->bpc_has_txinterval = - (bpc->bpc_txinterval != BPC_DEF_TRANSMITINTERVAL); - - STREAM_GETC(msg, bpc->bpc_detectmultiplier); - bpc->bpc_has_detectmultiplier = - (bpc->bpc_detectmultiplier != BPC_DEF_DETECTMULTIPLIER); - } + STREAM_GETL(msg, bpc->bpc_recvinterval); + bpc->bpc_has_recvinterval = + (bpc->bpc_recvinterval != BPC_DEF_RECEIVEINTERVAL); + + STREAM_GETL(msg, bpc->bpc_txinterval); + bpc->bpc_has_txinterval = + (bpc->bpc_txinterval != BPC_DEF_TRANSMITINTERVAL); + + STREAM_GETC(msg, bpc->bpc_detectmultiplier); + bpc->bpc_has_detectmultiplier = + (bpc->bpc_detectmultiplier != BPC_DEF_DETECTMULTIPLIER); /* Read (single|multi)hop and its options. */ STREAM_GETC(msg, bpc->bpc_mhop); - if (bpc->bpc_mhop) { - /* Read multihop source address and TTL. */ - _ptm_msg_read_address(msg, &bpc->bpc_local); - STREAM_GETC(msg, bpc->bpc_minimum_ttl); - if (bpc->bpc_minimum_ttl >= BFD_TTL_VAL - || bpc->bpc_minimum_ttl == 0) { - zlog_warn("%s: received invalid TTL configuration %d", - __func__, bpc->bpc_has_minimum_ttl); - bpc->bpc_minimum_ttl = BFD_DEF_MHOP_TTL; - bpc->bpc_has_minimum_ttl = false; - } else { - bpc->bpc_minimum_ttl = - (BFD_TTL_VAL + 1) - bpc->bpc_minimum_ttl; - bpc->bpc_has_minimum_ttl = true; - } + + /* Read multihop source address and TTL. */ + _ptm_msg_read_address(msg, &bpc->bpc_local); + + /* Read the minimum TTL (0 means unset or invalid). */ + STREAM_GETC(msg, bpc->bpc_minimum_ttl); + if (bpc->bpc_minimum_ttl == 0) { + bpc->bpc_minimum_ttl = BFD_DEF_MHOP_TTL; + bpc->bpc_has_minimum_ttl = false; } else { - /* If target is IPv6, then we must obtain local address. */ - if (bpc->bpc_ipv4 == false) - _ptm_msg_read_address(msg, &bpc->bpc_local); + bpc->bpc_minimum_ttl = (BFD_TTL_VAL + 1) - bpc->bpc_minimum_ttl; + bpc->bpc_has_minimum_ttl = true; + } - /* - * Read interface name and make sure it fits our data - * structure, otherwise fail. - */ - STREAM_GETC(msg, ifnamelen); - if (ifnamelen >= sizeof(bpc->bpc_localif)) { - zlog_err("ptm-read: interface name is too big"); - return -1; - } + /* + * Read interface name and make sure it fits our data + * structure, otherwise fail. + */ + STREAM_GETC(msg, ifnamelen); + if (ifnamelen >= sizeof(bpc->bpc_localif)) { + zlog_err("ptm-read: interface name is too big"); + return -1; + } - bpc->bpc_has_localif = ifnamelen > 0; - if (bpc->bpc_has_localif) { - STREAM_GET(bpc->bpc_localif, msg, ifnamelen); - bpc->bpc_localif[ifnamelen] = 0; - } + bpc->bpc_has_localif = ifnamelen > 0; + if (bpc->bpc_has_localif) { + STREAM_GET(bpc->bpc_localif, msg, ifnamelen); + bpc->bpc_localif[ifnamelen] = 0; } + if (vrf_id != VRF_DEFAULT) { struct vrf *vrf; @@ -424,6 +445,7 @@ static int _ptm_msg_read(struct stream *msg, int command, vrf_id_t vrf_id, strlcpy(bpc->bpc_vrfname, VRF_DEFAULT_NAME, sizeof(bpc->bpc_vrfname)); } + /* Read control plane independant configuration. */ STREAM_GETC(msg, bpc->bpc_cbit); /* Handle profile names. */ diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index fb9f3a1b38..ce22e8404d 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -1028,8 +1028,7 @@ struct attr *bgp_attr_aggregate_intern( SET_FLAG(bgp->peer_self->rmap_type, PEER_RMAP_TYPE_AGGREGATE); - ret = route_map_apply(aggregate->rmap.map, p, RMAP_BGP, - &rmap_path); + ret = route_map_apply(aggregate->rmap.map, p, &rmap_path); bgp->peer_self->rmap_type = 0; diff --git a/bgpd/bgp_conditional_adv.c b/bgpd/bgp_conditional_adv.c index ca67d49c8a..b5cd1b52b7 100644 --- a/bgpd/bgp_conditional_adv.c +++ b/bgpd/bgp_conditional_adv.c @@ -47,7 +47,7 @@ bgp_check_rmap_prefixes_in_bgp_table(struct bgp_table *table, RESET_FLAG(dummy_attr.rmap_change_flags); - ret = route_map_apply(rmap, dest_p, RMAP_BGP, &path); + ret = route_map_apply(rmap, dest_p, &path); if (ret != RMAP_PERMITMATCH) bgp_attr_flush(&dummy_attr); else { @@ -113,7 +113,7 @@ static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi, RESET_FLAG(dummy_attr.rmap_change_flags); - if (route_map_apply(rmap, dest_p, RMAP_BGP, &path) + if (route_map_apply(rmap, dest_p, &path) != RMAP_PERMITMATCH) { bgp_attr_flush(&dummy_attr); continue; diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index 84e8960ee3..890f7963e6 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -4210,7 +4210,7 @@ void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, afi_t afi, bgp_vrf->adv_cmd_rmap[afi][safi] .map, bgp_dest_get_prefix(dest), - RMAP_BGP, &tmp_pi); + &tmp_pi); if (ret == RMAP_DENYMATCH) { bgp_attr_flush(&tmp_attr); continue; diff --git a/bgpd/bgp_flowspec_vty.c b/bgpd/bgp_flowspec_vty.c index 0789581df1..57f212b05d 100644 --- a/bgpd/bgp_flowspec_vty.c +++ b/bgpd/bgp_flowspec_vty.c @@ -268,7 +268,7 @@ void route_vty_out_flowspec(struct vty *vty, const struct prefix *p, json_object *json_ecom_path = NULL; json_object *json_time_path = NULL; char timebuf[BGP_UPTIME_LEN]; - struct ecommunity *ipv6_ecomm; + struct ecommunity *ipv6_ecomm = NULL; if (p == NULL || p->family != AF_FLOWSPEC) return; @@ -300,7 +300,9 @@ void route_vty_out_flowspec(struct vty *vty, const struct prefix *p, if (!path) return; - ipv6_ecomm = bgp_attr_get_ipv6_ecommunity(path->attr); + if (path->attr) + ipv6_ecomm = bgp_attr_get_ipv6_ecommunity(path->attr); + if (path->attr && (path->attr->ecommunity || ipv6_ecomm)) { /* Print attribute */ attr = path->attr; diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 5877390377..662c5da414 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -744,7 +744,7 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */ info.attr = &static_attr; ret = route_map_apply( bgp_vrf->vpn_policy[afi].rmap[BGP_VPN_POLICY_DIR_TOVPN], - p, RMAP_BGP, &info); + p, &info); if (RMAP_DENYMATCH == ret) { bgp_attr_flush(&static_attr); /* free any added parts */ if (debug) @@ -1190,7 +1190,7 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */ info.extra = path_vpn->extra; /* Used for source-vrf filter */ ret = route_map_apply(bgp_vrf->vpn_policy[afi] .rmap[BGP_VPN_POLICY_DIR_FROMVPN], - p, RMAP_BGP, &info); + p, &info); if (RMAP_DENYMATCH == ret) { bgp_attr_flush(&static_attr); /* free any added parts */ if (debug) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index b6ae6dc064..8d87f2cd04 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -1504,7 +1504,7 @@ static int bgp_input_modifier(struct peer *peer, const struct prefix *p, SET_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN); /* Apply BGP route map to the attribute. */ - ret = route_map_apply(rmap, p, RMAP_BGP, &rmap_path); + ret = route_map_apply(rmap, p, &rmap_path); peer->rmap_type = 0; @@ -1555,7 +1555,7 @@ static int bgp_output_modifier(struct peer *peer, const struct prefix *p, SET_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT); /* Apply BGP route map to the attribute. */ - ret = route_map_apply(rmap, p, RMAP_BGP, &rmap_path); + ret = route_map_apply(rmap, p, &rmap_path); peer->rmap_type = rmap_type; @@ -2051,10 +2051,10 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, if (bgp_path_suppressed(pi)) ret = route_map_apply(UNSUPPRESS_MAP(filter), p, - RMAP_BGP, &rmap_path); + &rmap_path); else ret = route_map_apply(ROUTE_MAP_OUT(filter), p, - RMAP_BGP, &rmap_path); + &rmap_path); peer->rmap_type = 0; @@ -2637,7 +2637,7 @@ static void bgp_process_evpn_route_injection(struct bgp *bgp, afi_t afi, RESET_FLAG(dummy_attr.rmap_change_flags); ret = route_map_apply(bgp->adv_cmd_rmap[afi][safi].map, - p, RMAP_BGP, &rmap_path); + p, &rmap_path); if (ret == RMAP_DENYMATCH) { bgp_attr_flush(&dummy_attr); @@ -5228,8 +5228,7 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p, SET_FLAG(bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK); - ret = route_map_apply(bgp_static->rmap.map, p, RMAP_BGP, - &rmap_path); + ret = route_map_apply(bgp_static->rmap.map, p, &rmap_path); bgp->peer_self->rmap_type = 0; @@ -5548,8 +5547,7 @@ static void bgp_static_update_safi(struct bgp *bgp, const struct prefix *p, SET_FLAG(bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK); - ret = route_map_apply(bgp_static->rmap.map, p, RMAP_BGP, - &rmap_path); + ret = route_map_apply(bgp_static->rmap.map, p, &rmap_path); bgp->peer_self->rmap_type = 0; @@ -6400,7 +6398,7 @@ static bool aggr_suppress_map_test(struct bgp *bgp, rmap_path.attr = &attr; SET_FLAG(bgp->peer_self->rmap_type, PEER_RMAP_TYPE_AGGREGATE); - rmr = route_map_apply(aggregate->suppress_map, p, RMAP_BGP, &rmap_path); + rmr = route_map_apply(aggregate->suppress_map, p, &rmap_path); bgp->peer_self->rmap_type = 0; bgp_attr_flush(&attr); @@ -7858,8 +7856,7 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p, SET_FLAG(bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE); - ret = route_map_apply(red->rmap.map, p, RMAP_BGP, - &rmap_path); + ret = route_map_apply(red->rmap.map, p, &rmap_path); bgp->peer_self->rmap_type = 0; @@ -10403,8 +10400,7 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, path.peer = pi->peer; path.attr = &dummy_attr; - ret = route_map_apply(rmap, dest_p, RMAP_BGP, - &path); + ret = route_map_apply(rmap, dest_p, &path); if (ret == RMAP_DENYMATCH) continue; } diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index e4a9c29000..637eaca397 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -244,8 +244,7 @@ struct bgp_match_peer_compiled { received in bgp_path_info->peer. If it is the same, or if the peer structure received is a peer_group containing it, returns RMAP_MATCH. */ static enum route_map_cmd_result_t -route_match_peer(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_peer(void *rule, const struct prefix *prefix, void *object) { struct bgp_match_peer_compiled *pc; union sockunion *su; @@ -255,56 +254,51 @@ route_match_peer(void *rule, const struct prefix *prefix, struct peer *peer; struct listnode *node, *nnode; - if (type == RMAP_BGP) { - pc = rule; - su = &pc->su; - peer = ((struct bgp_path_info *)object)->peer; + pc = rule; + su = &pc->su; + peer = ((struct bgp_path_info *)object)->peer; - if (pc->interface) { - if (!peer->conf_if) - return RMAP_NOMATCH; + if (pc->interface) { + if (!peer->conf_if) + return RMAP_NOMATCH; - if (strcmp(peer->conf_if, pc->interface) == 0) - return RMAP_MATCH; + if (strcmp(peer->conf_if, pc->interface) == 0) + return RMAP_MATCH; - return RMAP_NOMATCH; - } + return RMAP_NOMATCH; + } - /* If su='0.0.0.0' (command 'match peer local'), and it's a - NETWORK, - REDISTRIBUTE, AGGREGATE-ADDRESS or DEFAULT_GENERATED route - => return RMAP_MATCH - */ - if (sockunion_same(su, &su_def)) { - int ret; - if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_NETWORK) - || CHECK_FLAG(peer->rmap_type, - PEER_RMAP_TYPE_REDISTRIBUTE) - || CHECK_FLAG(peer->rmap_type, - PEER_RMAP_TYPE_AGGREGATE) - || CHECK_FLAG(peer->rmap_type, - PEER_RMAP_TYPE_DEFAULT)) - ret = RMAP_MATCH; - else - ret = RMAP_NOMATCH; - return ret; - } + /* If su='0.0.0.0' (command 'match peer local'), and it's a + NETWORK, + REDISTRIBUTE, AGGREGATE-ADDRESS or DEFAULT_GENERATED route + => return RMAP_MATCH + */ + if (sockunion_same(su, &su_def)) { + int ret; + if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_NETWORK) + || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE) + || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_AGGREGATE) + || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_DEFAULT)) + ret = RMAP_MATCH; + else + ret = RMAP_NOMATCH; + return ret; + } + + if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { + if (sockunion_same(su, &peer->su)) + return RMAP_MATCH; - if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { + return RMAP_NOMATCH; + } else { + group = peer->group; + for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) { if (sockunion_same(su, &peer->su)) return RMAP_MATCH; - - return RMAP_NOMATCH; - } else { - group = peer->group; - for (ALL_LIST_ELEMENTS(group->peer, node, nnode, - peer)) { - if (sockunion_same(su, &peer->su)) - return RMAP_MATCH; - } - return RMAP_NOMATCH; } + return RMAP_NOMATCH; } + return RMAP_NOMATCH; } @@ -345,8 +339,7 @@ static const struct route_map_rule_cmd route_match_peer_cmd = { #if defined(HAVE_LUA) static enum route_map_cmd_result_t -route_match_command(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_command(void *rule, const struct prefix *prefix, void *object) { int status = RMAP_NOMATCH; u_int32_t locpref = 0; @@ -443,12 +436,11 @@ static const struct route_map_rule_cmd route_match_command_cmd = { /* Match function should return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_ip_address(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_address(void *rule, const struct prefix *prefix, void *object) { struct access_list *alist; - if (type == RMAP_BGP && prefix->family == AF_INET) { + if (prefix->family == AF_INET) { alist = access_list_lookup(AFI_IP, (char *)rule); if (alist == NULL) return RMAP_NOMATCH; @@ -485,14 +477,13 @@ static const struct route_map_rule_cmd route_match_ip_address_cmd = { /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_ip_next_hop(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_next_hop(void *rule, const struct prefix *prefix, void *object) { struct access_list *alist; struct bgp_path_info *path; struct prefix_ipv4 p; - if (type == RMAP_BGP && prefix->family == AF_INET) { + if (prefix->family == AF_INET) { path = object; p.family = AF_INET; p.prefix = path->attr->nexthop; @@ -534,15 +525,14 @@ static const struct route_map_rule_cmd route_match_ip_next_hop_cmd = { /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_ip_route_source(void *rule, const struct prefix *pfx, - route_map_object_t type, void *object) +route_match_ip_route_source(void *rule, const struct prefix *pfx, void *object) { struct access_list *alist; struct bgp_path_info *path; struct peer *peer; struct prefix_ipv4 p; - if (type == RMAP_BGP && pfx->family == AF_INET) { + if (pfx->family == AF_INET) { path = object; peer = path->peer; @@ -624,14 +614,10 @@ route_match_prefix_list_flowspec(afi_t afi, struct prefix_list *plist, static enum route_map_cmd_result_t route_match_address_prefix_list(void *rule, afi_t afi, - const struct prefix *prefix, - route_map_object_t type, void *object) + const struct prefix *prefix, void *object) { struct prefix_list *plist; - if (type != RMAP_BGP) - return RMAP_NOMATCH; - plist = prefix_list_lookup(afi, (char *)rule); if (plist == NULL) return RMAP_NOMATCH; @@ -645,10 +631,9 @@ route_match_address_prefix_list(void *rule, afi_t afi, static enum route_map_cmd_result_t route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { - return route_match_address_prefix_list(rule, AFI_IP, prefix, type, - object); + return route_match_address_prefix_list(rule, AFI_IP, prefix, object); } static void *route_match_ip_address_prefix_list_compile(const char *arg) @@ -673,13 +658,13 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct prefix_list *plist; struct bgp_path_info *path; struct prefix_ipv4 p; - if (type == RMAP_BGP && prefix->family == AF_INET) { + if (prefix->family == AF_INET) { path = object; p.family = AF_INET; p.prefix = path->attr->nexthop; @@ -718,11 +703,11 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_ip_next_hop_type(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct bgp_path_info *path; - if (type == RMAP_BGP && prefix->family == AF_INET) { + if (prefix->family == AF_INET) { path = (struct bgp_path_info *)object; if (!path) return RMAP_NOMATCH; @@ -759,16 +744,15 @@ static const struct route_map_rule_cmd /* `match ip route-source prefix-list PREFIX_LIST' */ static enum route_map_cmd_result_t -route_match_ip_route_source_prefix_list(void *rule, - const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_route_source_prefix_list(void *rule, const struct prefix *prefix, + void *object) { struct prefix_list *plist; struct bgp_path_info *path; struct peer *peer; struct prefix_ipv4 p; - if (type == RMAP_BGP && prefix->family == AF_INET) { + if (prefix->family == AF_INET) { path = object; peer = path->peer; @@ -812,10 +796,9 @@ static const struct route_map_rule_cmd /* Match function should return 1 if match is success else 0 */ static enum route_map_cmd_result_t -route_match_evpn_default_route(void *rule, const struct prefix *p, - route_map_object_t type, void *object) +route_match_evpn_default_route(void *rule, const struct prefix *p, void *object) { - if (type == RMAP_BGP && is_evpn_prefix_default(p)) + if (is_evpn_prefix_default(p)) return RMAP_MATCH; return RMAP_NOMATCH; @@ -835,30 +818,24 @@ static const struct route_map_rule_cmd /* Match function should return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_mac_address(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_mac_address(void *rule, const struct prefix *prefix, void *object) { struct access_list *alist; struct prefix p; - if (type == RMAP_BGP) { - alist = access_list_lookup(AFI_L2VPN, (char *)rule); - if (alist == NULL) - return RMAP_NOMATCH; - - if (prefix->u.prefix_evpn.route_type != BGP_EVPN_MAC_IP_ROUTE) - return RMAP_NOMATCH; + alist = access_list_lookup(AFI_L2VPN, (char *)rule); + if (alist == NULL) + return RMAP_NOMATCH; - p.family = AF_ETHERNET; - p.prefixlen = ETH_ALEN * 8; - p.u.prefix_eth = prefix->u.prefix_evpn.macip_addr.mac; + if (prefix->u.prefix_evpn.route_type != BGP_EVPN_MAC_IP_ROUTE) + return RMAP_NOMATCH; - return (access_list_apply(alist, &p) == FILTER_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); - } + p.family = AF_ETHERNET; + p.prefixlen = ETH_ALEN * 8; + p.u.prefix_eth = prefix->u.prefix_evpn.macip_addr.mac; - return RMAP_NOMATCH; + return (access_list_apply(alist, &p) == FILTER_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } /* Route map `mac address' match statement. `arg' should be @@ -889,43 +866,42 @@ static const struct route_map_rule_cmd route_match_mac_address_cmd = { * ...RMAP_NOOP to ignore this match check. */ static enum route_map_cmd_result_t -route_match_vni(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_vni(void *rule, const struct prefix *prefix, void *object) { vni_t vni = 0; unsigned int label_cnt = 0; struct bgp_path_info *path = NULL; struct prefix_evpn *evp = (struct prefix_evpn *) prefix; - if (type == RMAP_BGP) { - vni = *((vni_t *)rule); - path = (struct bgp_path_info *)object; + vni = *((vni_t *)rule); + path = (struct bgp_path_info *)object; - /* - * This rmap filter is valid for vxlan tunnel type only. - * For any other tunnel type, return noop to ignore - * this check. - */ - if (path->attr->encap_tunneltype != BGP_ENCAP_TYPE_VXLAN) - return RMAP_NOOP; + /* + * This rmap filter is valid for vxlan tunnel type only. + * For any other tunnel type, return noop to ignore + * this check. + */ + if (path->attr->encap_tunneltype != BGP_ENCAP_TYPE_VXLAN) + return RMAP_NOOP; - /* - * Apply filter to type 1, 2, 5 routes only. - * Other route types do not have vni label. - */ - if (evp && (evp->prefix.route_type != BGP_EVPN_AD_ROUTE && - evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE && - evp->prefix.route_type != BGP_EVPN_IP_PREFIX_ROUTE)) - return RMAP_NOOP; + /* + * Apply filter to type 1, 2, 5 routes only. + * Other route types do not have vni label. + */ + if (evp + && (evp->prefix.route_type != BGP_EVPN_AD_ROUTE + && evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE + && evp->prefix.route_type != BGP_EVPN_IP_PREFIX_ROUTE)) + return RMAP_NOOP; - if (path->extra == NULL) - return RMAP_NOMATCH; + if (path->extra == NULL) + return RMAP_NOMATCH; - for ( ; label_cnt < BGP_MAX_LABELS && - label_cnt < path->extra->num_labels; label_cnt++) { - if (vni == label2vni(&path->extra->label[label_cnt])) - return RMAP_MATCH; - } + for (; + label_cnt < BGP_MAX_LABELS && label_cnt < path->extra->num_labels; + label_cnt++) { + if (vni == label2vni(&path->extra->label[label_cnt])) + return RMAP_MATCH; } return RMAP_NOMATCH; @@ -967,17 +943,14 @@ static const struct route_map_rule_cmd route_match_evpn_vni_cmd = { /* Match function should return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_evpn_route_type(void *rule, const struct prefix *pfx, - route_map_object_t type, void *object) +route_match_evpn_route_type(void *rule, const struct prefix *pfx, void *object) { uint8_t route_type = 0; - if (type == RMAP_BGP) { - route_type = *((uint8_t *)rule); + route_type = *((uint8_t *)rule); - if (route_type == pfx->u.prefix_evpn.route_type) - return RMAP_MATCH; - } + if (route_type == pfx->u.prefix_evpn.route_type) + return RMAP_MATCH; return RMAP_NOMATCH; } @@ -1017,28 +990,24 @@ static const struct route_map_rule_cmd route_match_evpn_route_type_cmd = { /* Match function should return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_rd(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_rd(void *rule, const struct prefix *prefix, void *object) { struct prefix_rd *prd_rule = NULL; const struct prefix_rd *prd_route = NULL; struct bgp_path_info *path = NULL; - if (type == RMAP_BGP) { - if (prefix->family != AF_EVPN) - return RMAP_NOMATCH; + if (prefix->family != AF_EVPN) + return RMAP_NOMATCH; - prd_rule = (struct prefix_rd *)rule; - path = (struct bgp_path_info *)object; + prd_rule = (struct prefix_rd *)rule; + path = (struct bgp_path_info *)object; - if (path->net == NULL || path->net->pdest == NULL) - return RMAP_NOMATCH; + if (path->net == NULL || path->net->pdest == NULL) + return RMAP_NOMATCH; - prd_route = (struct prefix_rd *)bgp_dest_get_prefix( - path->net->pdest); - if (memcmp(prd_route->val, prd_rule->val, ECOMMUNITY_SIZE) == 0) - return RMAP_MATCH; - } + prd_route = (struct prefix_rd *)bgp_dest_get_prefix(path->net->pdest); + if (memcmp(prd_route->val, prd_rule->val, ECOMMUNITY_SIZE) == 0) + return RMAP_MATCH; return RMAP_NOMATCH; } @@ -1077,26 +1046,24 @@ static const struct route_map_rule_cmd route_match_evpn_rd_cmd = { /* Route map commands for VRF route leak with source vrf matching */ static enum route_map_cmd_result_t route_match_vrl_source_vrf(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct bgp_path_info *path; char *vrf_name; - if (type == RMAP_BGP) { - vrf_name = rule; - path = (struct bgp_path_info *)object; + vrf_name = rule; + path = (struct bgp_path_info *)object; - if (strncmp(vrf_name, "n/a", VRF_NAMSIZ) == 0) - return RMAP_NOMATCH; + if (strncmp(vrf_name, "n/a", VRF_NAMSIZ) == 0) + return RMAP_NOMATCH; - if (path->extra == NULL) - return RMAP_NOMATCH; + if (path->extra == NULL) + return RMAP_NOMATCH; - if (strncmp(vrf_name, vrf_id_to_name( - path->extra->bgp_orig->vrf_id), VRF_NAMSIZ) - == 0) - return RMAP_MATCH; - } + if (strncmp(vrf_name, vrf_id_to_name(path->extra->bgp_orig->vrf_id), + VRF_NAMSIZ) + == 0) + return RMAP_MATCH; return RMAP_NOMATCH; } @@ -1127,22 +1094,18 @@ static const struct route_map_rule_cmd route_match_vrl_source_vrf_cmd = { /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_local_pref(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_local_pref(void *rule, const struct prefix *prefix, void *object) { uint32_t *local_pref; struct bgp_path_info *path; - if (type == RMAP_BGP) { - local_pref = rule; - path = object; + local_pref = rule; + path = object; - if (path->attr->local_pref == *local_pref) - return RMAP_MATCH; - else - return RMAP_NOMATCH; - } - return RMAP_NOMATCH; + if (path->attr->local_pref == *local_pref) + return RMAP_MATCH; + else + return RMAP_NOMATCH; } /* @@ -1188,18 +1151,14 @@ static const struct route_map_rule_cmd route_match_local_pref_cmd = { /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_metric(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_metric(void *rule, const struct prefix *prefix, void *object) { struct rmap_value *rv; struct bgp_path_info *path; - if (type == RMAP_BGP) { - rv = rule; - path = object; - return route_value_match(rv, path->attr->med); - } - return RMAP_NOMATCH; + rv = rule; + path = object; + return route_value_match(rv, path->attr->med); } /* Route map commands for metric matching. */ @@ -1214,27 +1173,22 @@ static const struct route_map_rule_cmd route_match_metric_cmd = { /* Match function for as-path match. I assume given object is */ static enum route_map_cmd_result_t -route_match_aspath(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_aspath(void *rule, const struct prefix *prefix, void *object) { struct as_list *as_list; struct bgp_path_info *path; - if (type == RMAP_BGP) { - as_list = as_list_lookup((char *)rule); - if (as_list == NULL) - return RMAP_NOMATCH; + as_list = as_list_lookup((char *)rule); + if (as_list == NULL) + return RMAP_NOMATCH; - path = object; + path = object; - /* Perform match. */ - return ((as_list_apply(as_list, path->attr->aspath) - == AS_FILTER_DENY) - ? RMAP_NOMATCH - : RMAP_MATCH); - } - return RMAP_NOMATCH; + /* Perform match. */ + return ((as_list_apply(as_list, path->attr->aspath) == AS_FILTER_DENY) + ? RMAP_NOMATCH + : RMAP_MATCH); } /* Compile function for as-path match. */ @@ -1266,32 +1220,28 @@ struct rmap_community { /* Match function for community match. */ static enum route_map_cmd_result_t -route_match_community(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_community(void *rule, const struct prefix *prefix, void *object) { struct community_list *list; struct bgp_path_info *path; struct rmap_community *rcom = rule; - if (type == RMAP_BGP) { - path = object; - rcom = rule; + path = object; + rcom = rule; - list = community_list_lookup(bgp_clist, rcom->name, - rcom->name_hash, - COMMUNITY_LIST_MASTER); - if (!list) - return RMAP_NOMATCH; + list = community_list_lookup(bgp_clist, rcom->name, rcom->name_hash, + COMMUNITY_LIST_MASTER); + if (!list) + return RMAP_NOMATCH; - if (rcom->exact) { - if (community_list_exact_match(path->attr->community, - list)) - return RMAP_MATCH; - } else { - if (community_list_match(path->attr->community, list)) - return RMAP_MATCH; - } + if (rcom->exact) { + if (community_list_exact_match(path->attr->community, list)) + return RMAP_MATCH; + } else { + if (community_list_match(path->attr->community, list)) + return RMAP_MATCH; } + return RMAP_NOMATCH; } @@ -1355,34 +1305,27 @@ static const struct route_map_rule_cmd route_match_community_cmd = { /* Match function for lcommunity match. */ static enum route_map_cmd_result_t -route_match_lcommunity(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_lcommunity(void *rule, const struct prefix *prefix, void *object) { struct community_list *list; struct bgp_path_info *path; struct rmap_community *rcom = rule; - if (type == RMAP_BGP) { - path = object; + path = object; - list = community_list_lookup(bgp_clist, rcom->name, - rcom->name_hash, - LARGE_COMMUNITY_LIST_MASTER); - if (!list) - return RMAP_NOMATCH; + list = community_list_lookup(bgp_clist, rcom->name, rcom->name_hash, + LARGE_COMMUNITY_LIST_MASTER); + if (!list) + return RMAP_NOMATCH; - if (rcom->exact) { - if (lcommunity_list_exact_match( - path->attr->lcommunity, - list)) - return RMAP_MATCH; - } else { - if (lcommunity_list_match( - path->attr->lcommunity, - list)) - return RMAP_MATCH; - } + if (rcom->exact) { + if (lcommunity_list_exact_match(path->attr->lcommunity, list)) + return RMAP_MATCH; + } else { + if (lcommunity_list_match(path->attr->lcommunity, list)) + return RMAP_MATCH; } + return RMAP_NOMATCH; } @@ -1431,25 +1374,22 @@ static const struct route_map_rule_cmd route_match_lcommunity_cmd = { /* Match function for extcommunity match. */ static enum route_map_cmd_result_t -route_match_ecommunity(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ecommunity(void *rule, const struct prefix *prefix, void *object) { struct community_list *list; struct bgp_path_info *path; struct rmap_community *rcom = rule; - if (type == RMAP_BGP) { - path = object; + path = object; - list = community_list_lookup(bgp_clist, rcom->name, - rcom->name_hash, - EXTCOMMUNITY_LIST_MASTER); - if (!list) - return RMAP_NOMATCH; + list = community_list_lookup(bgp_clist, rcom->name, rcom->name_hash, + EXTCOMMUNITY_LIST_MASTER); + if (!list) + return RMAP_NOMATCH; + + if (ecommunity_list_match(path->attr->ecommunity, list)) + return RMAP_MATCH; - if (ecommunity_list_match(path->attr->ecommunity, list)) - return RMAP_MATCH; - } return RMAP_NOMATCH; } @@ -1487,19 +1427,16 @@ static const struct route_map_rule_cmd route_match_ecommunity_cmd = { /* `match origin' */ static enum route_map_cmd_result_t -route_match_origin(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_origin(void *rule, const struct prefix *prefix, void *object) { uint8_t *origin; struct bgp_path_info *path; - if (type == RMAP_BGP) { - origin = rule; - path = object; + origin = rule; + path = object; - if (path->attr->origin == *origin) - return RMAP_MATCH; - } + if (path->attr->origin == *origin) + return RMAP_MATCH; return RMAP_NOMATCH; } @@ -1537,8 +1474,7 @@ static const struct route_map_rule_cmd route_match_origin_cmd = { /* match probability { */ static enum route_map_cmd_result_t -route_match_probability(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_probability(void *rule, const struct prefix *prefix, void *object) { long r = frr_weak_random(); @@ -1594,26 +1530,22 @@ static const struct route_map_rule_cmd route_match_probability_cmd = { /* Match function should return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_interface(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_interface(void *rule, const struct prefix *prefix, void *object) { struct interface *ifp; struct bgp_path_info *path; - if (type == RMAP_BGP) { - path = object; + path = object; - if (!path) - return RMAP_NOMATCH; + if (!path) + return RMAP_NOMATCH; - ifp = if_lookup_by_name_all_vrf((char *)rule); + ifp = if_lookup_by_name_all_vrf((char *)rule); - if (ifp == NULL || ifp->ifindex != path->attr->nh_ifindex) - return RMAP_NOMATCH; + if (ifp == NULL || ifp->ifindex != path->attr->nh_ifindex) + return RMAP_NOMATCH; - return RMAP_MATCH; - } - return RMAP_NOMATCH; + return RMAP_MATCH; } /* Route map `interface' match statement. `arg' should be @@ -1643,20 +1575,15 @@ static const struct route_map_rule_cmd route_match_interface_cmd = { /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_tag(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_tag(void *rule, const struct prefix *prefix, void *object) { route_tag_t *tag; struct bgp_path_info *path; - if (type == RMAP_BGP) { - tag = rule; - path = object; - - return ((path->attr->tag == *tag) ? RMAP_MATCH : RMAP_NOMATCH); - } + tag = rule; + path = object; - return RMAP_NOMATCH; + return ((path->attr->tag == *tag) ? RMAP_MATCH : RMAP_NOMATCH); } @@ -1669,15 +1596,11 @@ static const struct route_map_rule_cmd route_match_tag_cmd = { }; static enum route_map_cmd_result_t -route_set_srte_color(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_srte_color(void *rule, const struct prefix *prefix, void *object) { uint32_t *srte_color = rule; struct bgp_path_info *path; - if (type != RMAP_BGP) - return RMAP_OKAY; - path = object; path->attr->srte_color = *srte_color; @@ -1716,16 +1639,12 @@ struct rmap_ip_nexthop_set { }; static enum route_map_cmd_result_t -route_set_ip_nexthop(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_ip_nexthop(void *rule, const struct prefix *prefix, void *object) { struct rmap_ip_nexthop_set *rins = rule; struct bgp_path_info *path; struct peer *peer; - if (type != RMAP_BGP) - return RMAP_OKAY; - if (prefix->family == AF_INET6) return RMAP_OKAY; @@ -1824,26 +1743,22 @@ static const struct route_map_rule_cmd route_set_ip_nexthop_cmd = { /* Set local preference. */ static enum route_map_cmd_result_t -route_set_local_pref(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_local_pref(void *rule, const struct prefix *prefix, void *object) { struct rmap_value *rv; struct bgp_path_info *path; uint32_t locpref = 0; - if (type == RMAP_BGP) { - /* Fetch routemap's rule information. */ - rv = rule; - path = object; + /* Fetch routemap's rule information. */ + rv = rule; + path = object; - /* Set local preference value. */ - if (path->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) - locpref = path->attr->local_pref; + /* Set local preference value. */ + if (path->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) + locpref = path->attr->local_pref; - path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF); - path->attr->local_pref = - route_value_adjust(rv, locpref, path->peer); - } + path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF); + path->attr->local_pref = route_value_adjust(rv, locpref, path->peer); return RMAP_OKAY; } @@ -1860,20 +1775,17 @@ static const struct route_map_rule_cmd route_set_local_pref_cmd = { /* Set weight. */ static enum route_map_cmd_result_t -route_set_weight(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_weight(void *rule, const struct prefix *prefix, void *object) { struct rmap_value *rv; struct bgp_path_info *path; - if (type == RMAP_BGP) { - /* Fetch routemap's rule information. */ - rv = rule; - path = object; + /* Fetch routemap's rule information. */ + rv = rule; + path = object; - /* Set weight value. */ - path->attr->weight = route_value_adjust(rv, 0, path->peer); - } + /* Set weight value. */ + path->attr->weight = route_value_adjust(rv, 0, path->peer); return RMAP_OKAY; } @@ -1888,15 +1800,11 @@ static const struct route_map_rule_cmd route_set_weight_cmd = { /* `set distance DISTANCE */ static enum route_map_cmd_result_t -route_set_distance(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_distance(void *rule, const struct prefix *prefix, void *object) { struct bgp_path_info *path = object; struct rmap_value *rv = rule; - if (type != RMAP_BGP) - return RMAP_OKAY; - path->attr->distance = rv->value; return RMAP_OKAY; @@ -1914,24 +1822,22 @@ static const struct route_map_rule_cmd route_set_distance_cmd = { /* Set metric to attribute. */ static enum route_map_cmd_result_t -route_set_metric(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_metric(void *rule, const struct prefix *prefix, void *object) { struct rmap_value *rv; struct bgp_path_info *path; uint32_t med = 0; - if (type == RMAP_BGP) { - /* Fetch routemap's rule information. */ - rv = rule; - path = object; + /* Fetch routemap's rule information. */ + rv = rule; + path = object; - if (path->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) - med = path->attr->med; + if (path->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) + med = path->attr->med; + + path->attr->med = route_value_adjust(rv, med, path->peer); + path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC); - path->attr->med = route_value_adjust(rv, med, path->peer); - path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC); - } return RMAP_OKAY; } @@ -1945,21 +1851,20 @@ static const struct route_map_rule_cmd route_set_metric_cmd = { /* `set table (1-4294967295)' */ -static enum route_map_cmd_result_t route_set_table_id(void *rule, - const struct prefix *prefix, - route_map_object_t type, - void *object) +static enum route_map_cmd_result_t +route_set_table_id(void *rule, const struct prefix *prefix, + + void *object) { struct rmap_value *rv; struct bgp_path_info *path; - if (type == RMAP_BGP) { - /* Fetch routemap's rule information. */ - rv = rule; - path = object; + /* Fetch routemap's rule information. */ + rv = rule; + path = object; + + path->attr->rmap_table_id = rv->value; - path->attr->rmap_table_id = rv->value; - } return RMAP_OKAY; } @@ -1975,34 +1880,31 @@ static const struct route_map_rule_cmd route_set_table_id_cmd = { /* For AS path prepend mechanism. */ static enum route_map_cmd_result_t -route_set_aspath_prepend(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_aspath_prepend(void *rule, const struct prefix *prefix, void *object) { struct aspath *aspath; struct aspath *new; struct bgp_path_info *path; - if (type == RMAP_BGP) { - path = object; - - if (path->attr->aspath->refcnt) - new = aspath_dup(path->attr->aspath); - else - new = path->attr->aspath; + path = object; - if ((uintptr_t)rule > 10) { - aspath = rule; - aspath_prepend(aspath, new); - } else { - as_t as = aspath_leftmost(new); - if (!as) - as = path->peer->as; - new = aspath_add_seq_n(new, as, (uintptr_t)rule); - } + if (path->attr->aspath->refcnt) + new = aspath_dup(path->attr->aspath); + else + new = path->attr->aspath; - path->attr->aspath = new; + if ((uintptr_t)rule > 10) { + aspath = rule; + aspath_prepend(aspath, new); + } else { + as_t as = aspath_leftmost(new); + if (!as) + as = path->peer->as; + new = aspath_add_seq_n(new, as, (uintptr_t)rule); } + path->attr->aspath = new; + return RMAP_OKAY; } @@ -2039,22 +1941,19 @@ static const struct route_map_rule_cmd route_set_aspath_prepend_cmd = { * Make a deep copy of existing AS_PATH, but for the first ASn only. */ static enum route_map_cmd_result_t -route_set_aspath_exclude(void *rule, const struct prefix *dummy, - route_map_object_t type, void *object) +route_set_aspath_exclude(void *rule, const struct prefix *dummy, void *object) { struct aspath *new_path, *exclude_path; struct bgp_path_info *path; - if (type == RMAP_BGP) { - exclude_path = rule; - path = object; - if (path->attr->aspath->refcnt) - new_path = aspath_dup(path->attr->aspath); - else - new_path = path->attr->aspath; - path->attr->aspath = - aspath_filter_exclude(new_path, exclude_path); - } + exclude_path = rule; + path = object; + if (path->attr->aspath->refcnt) + new_path = aspath_dup(path->attr->aspath); + else + new_path = path->attr->aspath; + path->attr->aspath = aspath_filter_exclude(new_path, exclude_path); + return RMAP_OKAY; } @@ -2075,8 +1974,7 @@ struct rmap_com_set { /* For community set mechanism. */ static enum route_map_cmd_result_t -route_set_community(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_community(void *rule, const struct prefix *prefix, void *object) { struct rmap_com_set *rcs; struct bgp_path_info *path; @@ -2085,44 +1983,42 @@ route_set_community(void *rule, const struct prefix *prefix, struct community *old; struct community *merge; - if (type == RMAP_BGP) { - rcs = rule; - path = object; - attr = path->attr; - old = attr->community; - - /* "none" case. */ - if (rcs->none) { - attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)); - attr->community = NULL; - /* See the longer comment down below. */ - if (old && old->refcnt == 0) - community_free(&old); - return RMAP_OKAY; - } + rcs = rule; + path = object; + attr = path->attr; + old = attr->community; + + /* "none" case. */ + if (rcs->none) { + attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)); + attr->community = NULL; + /* See the longer comment down below. */ + if (old && old->refcnt == 0) + community_free(&old); + return RMAP_OKAY; + } - /* "additive" case. */ - if (rcs->additive && old) { - merge = community_merge(community_dup(old), rcs->com); + /* "additive" case. */ + if (rcs->additive && old) { + merge = community_merge(community_dup(old), rcs->com); - new = community_uniq_sort(merge); - community_free(&merge); - } else - new = community_dup(rcs->com); + new = community_uniq_sort(merge); + community_free(&merge); + } else + new = community_dup(rcs->com); - /* HACK: if the old community is not intern'd, - * we should free it here, or all reference to it may be - * lost. - * Really need to cleanup attribute caching sometime. - */ - if (old && old->refcnt == 0) - community_free(&old); + /* HACK: if the old community is not intern'd, + * we should free it here, or all reference to it may be + * lost. + * Really need to cleanup attribute caching sometime. + */ + if (old && old->refcnt == 0) + community_free(&old); - /* will be interned by caller if required */ - attr->community = new; + /* will be interned by caller if required */ + attr->community = new; - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); - } + attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); return RMAP_OKAY; } @@ -2192,8 +2088,7 @@ struct rmap_lcom_set { /* For lcommunity set mechanism. */ static enum route_map_cmd_result_t -route_set_lcommunity(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_lcommunity(void *rule, const struct prefix *prefix, void *object) { struct rmap_lcom_set *rcs; struct bgp_path_info *path; @@ -2202,46 +2097,42 @@ route_set_lcommunity(void *rule, const struct prefix *prefix, struct lcommunity *old; struct lcommunity *merge; - if (type == RMAP_BGP) { - rcs = rule; - path = object; - attr = path->attr; - old = attr->lcommunity; - - /* "none" case. */ - if (rcs->none) { - attr->flag &= - ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)); - attr->lcommunity = NULL; - - /* See the longer comment down below. */ - if (old && old->refcnt == 0) - lcommunity_free(&old); - return RMAP_OKAY; - } - - if (rcs->additive && old) { - merge = lcommunity_merge(lcommunity_dup(old), - rcs->lcom); + rcs = rule; + path = object; + attr = path->attr; + old = attr->lcommunity; - new = lcommunity_uniq_sort(merge); - lcommunity_free(&merge); - } else - new = lcommunity_dup(rcs->lcom); + /* "none" case. */ + if (rcs->none) { + attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)); + attr->lcommunity = NULL; - /* HACK: if the old large-community is not intern'd, - * we should free it here, or all reference to it may be - * lost. - * Really need to cleanup attribute caching sometime. - */ + /* See the longer comment down below. */ if (old && old->refcnt == 0) lcommunity_free(&old); + return RMAP_OKAY; + } - /* will be intern()'d or attr_flush()'d by bgp_update_main() */ - attr->lcommunity = new; + if (rcs->additive && old) { + merge = lcommunity_merge(lcommunity_dup(old), rcs->lcom); - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES); - } + new = lcommunity_uniq_sort(merge); + lcommunity_free(&merge); + } else + new = lcommunity_dup(rcs->lcom); + + /* HACK: if the old large-community is not intern'd, + * we should free it here, or all reference to it may be + * lost. + * Really need to cleanup attribute caching sometime. + */ + if (old && old->refcnt == 0) + lcommunity_free(&old); + + /* will be intern()'d or attr_flush()'d by bgp_update_main() */ + attr->lcommunity = new; + + attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES); return RMAP_OKAY; } @@ -2306,8 +2197,7 @@ static const struct route_map_rule_cmd route_set_lcommunity_cmd = { /* For large community set mechanism. */ static enum route_map_cmd_result_t -route_set_lcommunity_delete(void *rule, const struct prefix *pfx, - route_map_object_t type, void *object) +route_set_lcommunity_delete(void *rule, const struct prefix *pfx, void *object) { struct community_list *list; struct lcommunity *merge; @@ -2316,40 +2206,36 @@ route_set_lcommunity_delete(void *rule, const struct prefix *pfx, struct bgp_path_info *path; struct rmap_community *rcom = rule; - if (type == RMAP_BGP) { - if (!rcom) - return RMAP_OKAY; + if (!rcom) + return RMAP_OKAY; - path = object; - list = community_list_lookup(bgp_clist, rcom->name, - rcom->name_hash, - LARGE_COMMUNITY_LIST_MASTER); - old = path->attr->lcommunity; - - if (list && old) { - merge = lcommunity_list_match_delete( - lcommunity_dup(old), list); - new = lcommunity_uniq_sort(merge); - lcommunity_free(&merge); - - /* HACK: if the old community is not intern'd, - * we should free it here, or all reference to it may be - * lost. - * Really need to cleanup attribute caching sometime. - */ - if (old->refcnt == 0) - lcommunity_free(&old); - - if (new->size == 0) { - path->attr->lcommunity = NULL; - path->attr->flag &= ~ATTR_FLAG_BIT( - BGP_ATTR_LARGE_COMMUNITIES); - lcommunity_free(&new); - } else { - path->attr->lcommunity = new; - path->attr->flag |= ATTR_FLAG_BIT( - BGP_ATTR_LARGE_COMMUNITIES); - } + path = object; + list = community_list_lookup(bgp_clist, rcom->name, rcom->name_hash, + LARGE_COMMUNITY_LIST_MASTER); + old = path->attr->lcommunity; + + if (list && old) { + merge = lcommunity_list_match_delete(lcommunity_dup(old), list); + new = lcommunity_uniq_sort(merge); + lcommunity_free(&merge); + + /* HACK: if the old community is not intern'd, + * we should free it here, or all reference to it may be + * lost. + * Really need to cleanup attribute caching sometime. + */ + if (old->refcnt == 0) + lcommunity_free(&old); + + if (new->size == 0) { + path->attr->lcommunity = NULL; + path->attr->flag &= + ~ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES); + lcommunity_free(&new); + } else { + path->attr->lcommunity = new; + path->attr->flag |= + ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES); } } @@ -2399,7 +2285,7 @@ static const struct route_map_rule_cmd route_set_lcommunity_delete_cmd = { /* For community set mechanism. */ static enum route_map_cmd_result_t route_set_community_delete(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct community_list *list; struct community *merge; @@ -2408,40 +2294,35 @@ route_set_community_delete(void *rule, const struct prefix *prefix, struct bgp_path_info *path; struct rmap_community *rcom = rule; - if (type == RMAP_BGP) { - if (!rcom) - return RMAP_OKAY; + if (!rcom) + return RMAP_OKAY; - path = object; - list = community_list_lookup(bgp_clist, rcom->name, - rcom->name_hash, - COMMUNITY_LIST_MASTER); - old = path->attr->community; - - if (list && old) { - merge = community_list_match_delete(community_dup(old), - list); - new = community_uniq_sort(merge); - community_free(&merge); - - /* HACK: if the old community is not intern'd, - * we should free it here, or all reference to it may be - * lost. - * Really need to cleanup attribute caching sometime. - */ - if (old->refcnt == 0) - community_free(&old); - - if (new->size == 0) { - path->attr->community = NULL; - path->attr->flag &= - ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); - community_free(&new); - } else { - path->attr->community = new; - path->attr->flag |= - ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); - } + path = object; + list = community_list_lookup(bgp_clist, rcom->name, rcom->name_hash, + COMMUNITY_LIST_MASTER); + old = path->attr->community; + + if (list && old) { + merge = community_list_match_delete(community_dup(old), list); + new = community_uniq_sort(merge); + community_free(&merge); + + /* HACK: if the old community is not intern'd, + * we should free it here, or all reference to it may be + * lost. + * Really need to cleanup attribute caching sometime. + */ + if (old->refcnt == 0) + community_free(&old); + + if (new->size == 0) { + path->attr->community = NULL; + path->attr->flag &= + ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); + community_free(&new); + } else { + path->attr->community = new; + path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } } @@ -2489,42 +2370,39 @@ static const struct route_map_rule_cmd route_set_community_delete_cmd = { /* For community set mechanism. Used by _rt and _soo. */ static enum route_map_cmd_result_t -route_set_ecommunity(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_ecommunity(void *rule, const struct prefix *prefix, void *object) { struct ecommunity *ecom; struct ecommunity *new_ecom; struct ecommunity *old_ecom; struct bgp_path_info *path; - if (type == RMAP_BGP) { - ecom = rule; - path = object; + ecom = rule; + path = object; - if (!ecom) - return RMAP_OKAY; + if (!ecom) + return RMAP_OKAY; - /* We assume additive for Extended Community. */ - old_ecom = path->attr->ecommunity; + /* We assume additive for Extended Community. */ + old_ecom = path->attr->ecommunity; - if (old_ecom) { - new_ecom = ecommunity_merge(ecommunity_dup(old_ecom), - ecom); + if (old_ecom) { + new_ecom = ecommunity_merge(ecommunity_dup(old_ecom), ecom); - /* old_ecom->refcnt = 1 => owned elsewhere, e.g. - * bgp_update_receive() - * ->refcnt = 0 => set by a previous route-map - * statement */ - if (!old_ecom->refcnt) - ecommunity_free(&old_ecom); - } else - new_ecom = ecommunity_dup(ecom); + /* old_ecom->refcnt = 1 => owned elsewhere, e.g. + * bgp_update_receive() + * ->refcnt = 0 => set by a previous route-map + * statement */ + if (!old_ecom->refcnt) + ecommunity_free(&old_ecom); + } else + new_ecom = ecommunity_dup(ecom); - /* will be intern()'d or attr_flush()'d by bgp_update_main() */ - path->attr->ecommunity = new_ecom; + /* will be intern()'d or attr_flush()'d by bgp_update_main() */ + path->attr->ecommunity = new_ecom; + + path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); - path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); - } return RMAP_OKAY; } @@ -2588,8 +2466,7 @@ struct rmap_ecomm_lb_set { }; static enum route_map_cmd_result_t -route_set_ecommunity_lb(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_ecommunity_lb(void *rule, const struct prefix *prefix, void *object) { struct rmap_ecomm_lb_set *rels = rule; struct bgp_path_info *path; @@ -2602,9 +2479,6 @@ route_set_ecommunity_lb(void *rule, const struct prefix *prefix, struct ecommunity *old_ecom; as_t as; - if (type != RMAP_BGP) - return RMAP_OKAY; - path = object; peer = path->peer; if (!peer || !peer->bgp) @@ -2721,18 +2595,15 @@ struct route_map_rule_cmd route_set_ecommunity_lb_cmd = { /* For origin set. */ static enum route_map_cmd_result_t -route_set_origin(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_origin(void *rule, const struct prefix *prefix, void *object) { uint8_t *origin; struct bgp_path_info *path; - if (type == RMAP_BGP) { - origin = rule; - path = object; + origin = rule; + path = object; - path->attr->origin = *origin; - } + path->attr->origin = *origin; return RMAP_OKAY; } @@ -2772,15 +2643,12 @@ static const struct route_map_rule_cmd route_set_origin_cmd = { /* For atomic aggregate set. */ static enum route_map_cmd_result_t -route_set_atomic_aggregate(void *rule, const struct prefix *pfx, - route_map_object_t type, void *object) +route_set_atomic_aggregate(void *rule, const struct prefix *pfx, void *object) { struct bgp_path_info *path; - if (type == RMAP_BGP) { - path = object; - path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE); - } + path = object; + path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE); return RMAP_OKAY; } @@ -2812,20 +2680,17 @@ struct aggregator { }; static enum route_map_cmd_result_t -route_set_aggregator_as(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_aggregator_as(void *rule, const struct prefix *prefix, void *object) { struct bgp_path_info *path; struct aggregator *aggregator; - if (type == RMAP_BGP) { - path = object; - aggregator = rule; + path = object; + aggregator = rule; - path->attr->aggregator_as = aggregator->as; - path->attr->aggregator_addr = aggregator->address; - path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR); - } + path->attr->aggregator_as = aggregator->as; + path->attr->aggregator_addr = aggregator->address; + path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR); return RMAP_OKAY; } @@ -2867,19 +2732,16 @@ static const struct route_map_rule_cmd route_set_aggregator_as_cmd = { /* Set tag to object. object must be pointer to struct bgp_path_info */ static enum route_map_cmd_result_t -route_set_tag(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_tag(void *rule, const struct prefix *prefix, void *object) { route_tag_t *tag; struct bgp_path_info *path; - if (type == RMAP_BGP) { - tag = rule; - path = object; + tag = rule; + path = object; - /* Set tag value */ - path->attr->tag = *tag; - } + /* Set tag value */ + path->attr->tag = *tag; return RMAP_OKAY; } @@ -2894,24 +2756,21 @@ static const struct route_map_rule_cmd route_set_tag_cmd = { /* Set label-index to object. object must be pointer to struct bgp_path_info */ static enum route_map_cmd_result_t -route_set_label_index(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_label_index(void *rule, const struct prefix *prefix, void *object) { struct rmap_value *rv; struct bgp_path_info *path; uint32_t label_index; - if (type == RMAP_BGP) { - /* Fetch routemap's rule information. */ - rv = rule; - path = object; + /* Fetch routemap's rule information. */ + rv = rule; + path = object; - /* Set label-index value. */ - label_index = rv->value; - if (label_index) { - path->attr->label_index = label_index; - path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID); - } + /* Set label-index value. */ + label_index = rv->value; + if (label_index) { + path->attr->label_index = label_index; + path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID); } return RMAP_OKAY; @@ -2928,12 +2787,11 @@ static const struct route_map_rule_cmd route_set_label_index_cmd = { /* `match ipv6 address IP_ACCESS_LIST' */ static enum route_map_cmd_result_t -route_match_ipv6_address(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ipv6_address(void *rule, const struct prefix *prefix, void *object) { struct access_list *alist; - if (type == RMAP_BGP && prefix->family == AF_INET6) { + if (prefix->family == AF_INET6) { alist = access_list_lookup(AFI_IP6, (char *)rule); if (alist == NULL) return RMAP_NOMATCH; @@ -2966,25 +2824,19 @@ static const struct route_map_rule_cmd route_match_ipv6_address_cmd = { /* `match ipv6 next-hop IP_ADDRESS' */ static enum route_map_cmd_result_t -route_match_ipv6_next_hop(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ipv6_next_hop(void *rule, const struct prefix *prefix, void *object) { struct in6_addr *addr = rule; struct bgp_path_info *path; - if (type == RMAP_BGP) { - path = object; - - if (IPV6_ADDR_SAME(&path->attr->mp_nexthop_global, addr)) - return RMAP_MATCH; + path = object; - if (path->attr->mp_nexthop_len - == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL - && IPV6_ADDR_SAME(&path->attr->mp_nexthop_local, rule)) - return RMAP_MATCH; + if (IPV6_ADDR_SAME(&path->attr->mp_nexthop_global, addr)) + return RMAP_MATCH; - return RMAP_NOMATCH; - } + if (path->attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL + && IPV6_ADDR_SAME(&path->attr->mp_nexthop_local, rule)) + return RMAP_MATCH; return RMAP_NOMATCH; } @@ -3020,22 +2872,17 @@ static const struct route_map_rule_cmd route_match_ipv6_next_hop_cmd = { /* `match ip next-hop IP_ADDRESS' */ static enum route_map_cmd_result_t -route_match_ipv4_next_hop(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ipv4_next_hop(void *rule, const struct prefix *prefix, void *object) { struct in_addr *addr = rule; struct bgp_path_info *path; - if (type == RMAP_BGP) { - path = object; - - if (path->attr->nexthop.s_addr == addr->s_addr || - (path->attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4 && - IPV4_ADDR_SAME(&path->attr->mp_nexthop_global_in, addr))) - return RMAP_MATCH; + path = object; - return RMAP_NOMATCH; - } + if (path->attr->nexthop.s_addr == addr->s_addr + || (path->attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4 + && IPV4_ADDR_SAME(&path->attr->mp_nexthop_global_in, addr))) + return RMAP_MATCH; return RMAP_NOMATCH; } @@ -3072,10 +2919,9 @@ static const struct route_map_rule_cmd route_match_ipv4_next_hop_cmd = { static enum route_map_cmd_result_t route_match_ipv6_address_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { - return route_match_address_prefix_list(rule, AFI_IP6, prefix, type, - object); + return route_match_address_prefix_list(rule, AFI_IP6, prefix, object); } static void *route_match_ipv6_address_prefix_list_compile(const char *arg) @@ -3100,12 +2946,12 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_ipv6_next_hop_type(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct bgp_path_info *path; struct in6_addr *addr = rule; - if (type == RMAP_BGP && prefix->family == AF_INET6) { + if (prefix->family == AF_INET6) { path = (struct bgp_path_info *)object; if (!path) return RMAP_NOMATCH; @@ -3114,6 +2960,7 @@ route_match_ipv6_next_hop_type(void *rule, const struct prefix *prefix, && !path->attr->nh_ifindex) return RMAP_MATCH; } + return RMAP_NOMATCH; } @@ -3150,27 +2997,24 @@ static const struct route_map_rule_cmd /* Set nexthop to object. ojbect must be pointer to struct attr. */ static enum route_map_cmd_result_t -route_set_ipv6_nexthop_global(void *rule, const struct prefix *p, - route_map_object_t type, void *object) +route_set_ipv6_nexthop_global(void *rule, const struct prefix *p, void *object) { struct in6_addr *address; struct bgp_path_info *path; - if (type == RMAP_BGP) { - /* Fetch routemap's rule information. */ - address = rule; - path = object; + /* Fetch routemap's rule information. */ + address = rule; + path = object; - /* Set next hop value. */ - path->attr->mp_nexthop_global = *address; + /* Set next hop value. */ + path->attr->mp_nexthop_global = *address; - /* Set nexthop length. */ - if (path->attr->mp_nexthop_len == 0) - path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL; + /* Set nexthop length. */ + if (path->attr->mp_nexthop_len == 0) + path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL; - SET_FLAG(path->attr->rmap_change_flags, - BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED); - } + SET_FLAG(path->attr->rmap_change_flags, + BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED); return RMAP_OKAY; } @@ -3212,28 +3056,27 @@ static const struct route_map_rule_cmd /* Set next-hop preference value. */ static enum route_map_cmd_result_t route_set_ipv6_nexthop_prefer_global(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct bgp_path_info *path; struct peer *peer; - if (type == RMAP_BGP) { - /* Fetch routemap's rule information. */ - path = object; - peer = path->peer; + /* Fetch routemap's rule information. */ + path = object; + peer = path->peer; - if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN) - || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) { - /* Set next hop preference to global */ - path->attr->mp_nexthop_prefer_global = true; - SET_FLAG(path->attr->rmap_change_flags, - BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED); - } else { - path->attr->mp_nexthop_prefer_global = false; - SET_FLAG(path->attr->rmap_change_flags, - BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED); - } + if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN) + || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) { + /* Set next hop preference to global */ + path->attr->mp_nexthop_prefer_global = true; + SET_FLAG(path->attr->rmap_change_flags, + BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED); + } else { + path->attr->mp_nexthop_prefer_global = false; + SET_FLAG(path->attr->rmap_change_flags, + BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED); } + return RMAP_OKAY; } @@ -3266,29 +3109,24 @@ static const struct route_map_rule_cmd /* Set nexthop to object. ojbect must be pointer to struct attr. */ static enum route_map_cmd_result_t -route_set_ipv6_nexthop_local(void *rule, const struct prefix *p, - route_map_object_t type, void *object) +route_set_ipv6_nexthop_local(void *rule, const struct prefix *p, void *object) { struct in6_addr *address; struct bgp_path_info *path; - if (type == RMAP_BGP) { - /* Fetch routemap's rule information. */ - address = rule; - path = object; + /* Fetch routemap's rule information. */ + address = rule; + path = object; - /* Set next hop value. */ - path->attr->mp_nexthop_local = *address; + /* Set next hop value. */ + path->attr->mp_nexthop_local = *address; - /* Set nexthop length. */ - if (path->attr->mp_nexthop_len - != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) - path->attr->mp_nexthop_len = - BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL; + /* Set nexthop length. */ + if (path->attr->mp_nexthop_len != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) + path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL; - SET_FLAG(path->attr->rmap_change_flags, - BATTR_RMAP_IPV6_LL_NHOP_CHANGED); - } + SET_FLAG(path->attr->rmap_change_flags, + BATTR_RMAP_IPV6_LL_NHOP_CHANGED); return RMAP_OKAY; } @@ -3331,55 +3169,52 @@ static const struct route_map_rule_cmd /* Set nexthop to object. ojbect must be pointer to struct attr. */ static enum route_map_cmd_result_t -route_set_ipv6_nexthop_peer(void *rule, const struct prefix *pfx, - route_map_object_t type, void *object) +route_set_ipv6_nexthop_peer(void *rule, const struct prefix *pfx, void *object) { struct in6_addr peer_address; struct bgp_path_info *path; struct peer *peer; - if (type == RMAP_BGP) { - /* Fetch routemap's rule information. */ - path = object; - peer = path->peer; - - if ((CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN) - || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) - && peer->su_remote - && sockunion_family(peer->su_remote) == AF_INET6) { - peer_address = peer->su_remote->sin6.sin6_addr; - /* Set next hop value and length in attribute. */ - if (IN6_IS_ADDR_LINKLOCAL(&peer_address)) { - path->attr->mp_nexthop_local = peer_address; - if (path->attr->mp_nexthop_len - != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) - path->attr->mp_nexthop_len = - BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL; - } else { - path->attr->mp_nexthop_global = peer_address; - if (path->attr->mp_nexthop_len == 0) - path->attr->mp_nexthop_len = - BGP_ATTR_NHLEN_IPV6_GLOBAL; - } + /* Fetch routemap's rule information. */ + path = object; + peer = path->peer; - } else if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT)) { - /* The next hop value will be set as part of packet - * rewrite. - * Set the flags here to indicate that rewrite needs to - * be done. - * Also, clear the value - we clear both global and - * link-local - * nexthops, whether we send one or both is determined - * elsewhere. - */ - SET_FLAG(path->attr->rmap_change_flags, - BATTR_RMAP_NEXTHOP_PEER_ADDRESS); - /* clear next hop value. */ - memset(&(path->attr->mp_nexthop_global), 0, - sizeof(struct in6_addr)); - memset(&(path->attr->mp_nexthop_local), 0, - sizeof(struct in6_addr)); + if ((CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN) + || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) + && peer->su_remote + && sockunion_family(peer->su_remote) == AF_INET6) { + peer_address = peer->su_remote->sin6.sin6_addr; + /* Set next hop value and length in attribute. */ + if (IN6_IS_ADDR_LINKLOCAL(&peer_address)) { + path->attr->mp_nexthop_local = peer_address; + if (path->attr->mp_nexthop_len + != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) + path->attr->mp_nexthop_len = + BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL; + } else { + path->attr->mp_nexthop_global = peer_address; + if (path->attr->mp_nexthop_len == 0) + path->attr->mp_nexthop_len = + BGP_ATTR_NHLEN_IPV6_GLOBAL; } + + } else if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT)) { + /* The next hop value will be set as part of packet + * rewrite. + * Set the flags here to indicate that rewrite needs to + * be done. + * Also, clear the value - we clear both global and + * link-local + * nexthops, whether we send one or both is determined + * elsewhere. + */ + SET_FLAG(path->attr->rmap_change_flags, + BATTR_RMAP_NEXTHOP_PEER_ADDRESS); + /* clear next hop value. */ + memset(&(path->attr->mp_nexthop_global), 0, + sizeof(struct in6_addr)); + memset(&(path->attr->mp_nexthop_local), 0, + sizeof(struct in6_addr)); } return RMAP_OKAY; @@ -3414,21 +3249,18 @@ static const struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd = { /* `set ipv4 vpn next-hop A.B.C.D' */ static enum route_map_cmd_result_t -route_set_vpnv4_nexthop(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_vpnv4_nexthop(void *rule, const struct prefix *prefix, void *object) { struct in_addr *address; struct bgp_path_info *path; - if (type == RMAP_BGP) { - /* Fetch routemap's rule information. */ - address = rule; - path = object; + /* Fetch routemap's rule information. */ + address = rule; + path = object; - /* Set next hop value. */ - path->attr->mp_nexthop_global_in = *address; - path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_IPV4; - } + /* Set next hop value. */ + path->attr->mp_nexthop_global_in = *address; + path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_IPV4; return RMAP_OKAY; } @@ -3453,22 +3285,19 @@ static void *route_set_vpnv4_nexthop_compile(const char *arg) /* `set ipv6 vpn next-hop A.B.C.D' */ static enum route_map_cmd_result_t -route_set_vpnv6_nexthop(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_vpnv6_nexthop(void *rule, const struct prefix *prefix, void *object) { struct in6_addr *address; struct bgp_path_info *path; - if (type == RMAP_BGP) { - /* Fetch routemap's rule information. */ - address = rule; - path = object; + /* Fetch routemap's rule information. */ + address = rule; + path = object; - /* Set next hop value. */ - memcpy(&path->attr->mp_nexthop_global, address, - sizeof(struct in6_addr)); - path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_VPNV6_GLOBAL; - } + /* Set next hop value. */ + memcpy(&path->attr->mp_nexthop_global, address, + sizeof(struct in6_addr)); + path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_VPNV6_GLOBAL; return RMAP_OKAY; } @@ -3514,19 +3343,16 @@ static const struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd = { /* For origin set. */ static enum route_map_cmd_result_t -route_set_originator_id(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_originator_id(void *rule, const struct prefix *prefix, void *object) { struct in_addr *address; struct bgp_path_info *path; - if (type == RMAP_BGP) { - address = rule; - path = object; + address = rule; + path = object; - path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID); - path->attr->originator_id = *address; - } + path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID); + path->attr->originator_id = *address; return RMAP_OKAY; } diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c index 0f0aff7eaa..24ee99bddb 100644 --- a/bgpd/bgp_rpki.c +++ b/bgpd/bgp_rpki.c @@ -124,7 +124,7 @@ static int is_running(void); static void route_match_free(void *rule); static enum route_map_cmd_result_t route_match(void *rule, const struct prefix *prefix, - route_map_object_t type, + void *object); static void *route_match_compile(const char *arg); static void revalidate_bgp_node(struct bgp_dest *dest, afi_t afi, safi_t safi); @@ -213,20 +213,18 @@ static void ipv6_addr_to_host_byte_order(const uint32_t *src, uint32_t *dest) static enum route_map_cmd_result_t route_match(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) { int *rpki_status = rule; struct bgp_path_info *path; - if (type == RMAP_BGP) { - path = object; + path = object; - if (rpki_validate_prefix(path->peer, path->attr, prefix) - == *rpki_status) { - return RMAP_MATCH; - } + if (rpki_validate_prefix(path->peer, path->attr, prefix) + == *rpki_status) { + return RMAP_MATCH; } + return RMAP_NOMATCH; } diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c index 6793fa1ca3..da9e1f28ae 100644 --- a/bgpd/bgp_updgrp_adv.c +++ b/bgpd/bgp_updgrp_adv.c @@ -823,8 +823,7 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw) ret = route_map_apply( peer->default_rmap[afi][safi].map, - bgp_dest_get_prefix(dest), RMAP_BGP, - &tmp_pi); + bgp_dest_get_prefix(dest), &tmp_pi); if (ret == RMAP_DENYMATCH) { bgp_attr_flush(&tmp_attr); diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 0f8168c89e..73f03f6a9d 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -918,7 +918,7 @@ static bool bgp_table_map_apply(struct route_map *map, const struct prefix *p, { route_map_result_t ret; - ret = route_map_apply(map, p, RMAP_BGP, path); + ret = route_map_apply(map, p, path); bgp_attr_flush(path->attr); if (ret != RMAP_DENYMATCH) diff --git a/bgpd/rfapi/vnc_export_bgp.c b/bgpd/rfapi/vnc_export_bgp.c index 11f39b2b82..762cd2596f 100644 --- a/bgpd/rfapi/vnc_export_bgp.c +++ b/bgpd/rfapi/vnc_export_bgp.c @@ -290,7 +290,7 @@ void vnc_direct_bgp_add_route_ce(struct bgp *bgp, struct agg_node *rn, info.peer = peer; info.attr = &hattr; ret = route_map_apply(bgp->rfapi_cfg->routemap_export_bgp, - prefix, RMAP_BGP, &info); + prefix, &info); if (ret == RMAP_DENYMATCH) { bgp_attr_flush(&hattr); return; @@ -1033,7 +1033,7 @@ void vnc_direct_bgp_add_nve(struct bgp *bgp, struct rfapi_descriptor *rfd) ret = route_map_apply( rfgn->rfg ->routemap_export_bgp, - p, RMAP_BGP, &info); + p, &info); if (ret == RMAP_DENYMATCH) { bgp_attr_flush(&hattr); continue; @@ -1242,8 +1242,7 @@ static void vnc_direct_add_rn_group_rd(struct bgp *bgp, info.peer = irfd->peer; info.attr = &hattr; - ret = route_map_apply(rfg->routemap_export_bgp, p, RMAP_BGP, - &info); + ret = route_map_apply(rfg->routemap_export_bgp, p, &info); if (ret == RMAP_DENYMATCH) { bgp_attr_flush(&hattr); vnc_zlog_debug_verbose( @@ -1691,8 +1690,7 @@ void vnc_direct_bgp_rh_add_route(struct bgp *bgp, afi_t afi, memset(&info, 0, sizeof(info)); info.peer = peer; info.attr = &hattr; - ret = route_map_apply(hc->routemap_export_bgp, prefix, RMAP_BGP, - &info); + ret = route_map_apply(hc->routemap_export_bgp, prefix, &info); if (ret == RMAP_DENYMATCH) { bgp_attr_flush(&hattr); return; @@ -1917,8 +1915,7 @@ void vnc_direct_bgp_rh_vpn_enable(struct bgp *bgp, afi_t afi) info.attr = &hattr; ret = route_map_apply( hc->routemap_export_bgp, - dest_p, RMAP_BGP, - &info); + dest_p, &info); if (ret == RMAP_DENYMATCH) { bgp_attr_flush(&hattr); vnc_zlog_debug_verbose( diff --git a/bgpd/rfapi/vnc_import_bgp.c b/bgpd/rfapi/vnc_import_bgp.c index 5a65eef466..b23c1eda76 100644 --- a/bgpd/rfapi/vnc_import_bgp.c +++ b/bgpd/rfapi/vnc_import_bgp.c @@ -357,7 +357,7 @@ static int process_unicast_route(struct bgp *bgp, /* in */ memset(&info, 0, sizeof(info)); info.peer = peer; info.attr = &hattr; - ret = route_map_apply(rmap, prefix, RMAP_BGP, &info); + ret = route_map_apply(rmap, prefix, &info); if (ret == RMAP_DENYMATCH) { bgp_attr_flush(&hattr); vnc_zlog_debug_verbose( @@ -784,7 +784,7 @@ static void vnc_import_bgp_add_route_mode_plain(struct bgp *bgp, memset(&info, 0, sizeof(info)); info.peer = peer; info.attr = &hattr; - ret = route_map_apply(rmap, prefix, RMAP_BGP, &info); + ret = route_map_apply(rmap, prefix, &info); if (ret == RMAP_DENYMATCH) { bgp_attr_flush(&hattr); vnc_zlog_debug_verbose( @@ -977,7 +977,7 @@ static void vnc_import_bgp_add_route_mode_nvegroup( memset(&path, 0, sizeof(path)); path.peer = peer; path.attr = &hattr; - ret = route_map_apply(rmap, prefix, RMAP_BGP, &path); + ret = route_map_apply(rmap, prefix, &path); if (ret == RMAP_DENYMATCH) { bgp_attr_flush(&hattr); vnc_zlog_debug_verbose( diff --git a/doc/user/bgp.rst b/doc/user/bgp.rst index 5ae001daf2..0a562e1edf 100644 --- a/doc/user/bgp.rst +++ b/doc/user/bgp.rst @@ -1353,10 +1353,10 @@ Configuring Peers Optionally you can specify a shutdown message `MSG`. - Also, you can specify optionally _rtt_ in milliseconds to automatically + Also, you can specify optionally ``rtt`` in milliseconds to automatically shutdown the peer if round-trip-time becomes higher than defined. - Additional _count_ parameter is the number of keepalive messages to count + Additional ``count`` parameter is the number of keepalive messages to count before shutdown the peer if round-trip-time becomes higher than defined. .. index:: [no] neighbor PEER disable-connected-check @@ -1470,7 +1470,7 @@ Configuring Peers granular and offers much smarter matching criterion than number of received prefixes, making it more suited to implementing policy. - If _force_ is set, then ALL prefixes are counted for maximum instead of + If ``force`` is set, then ALL prefixes are counted for maximum instead of accepted only. This is useful for cases where an inbound filter is applied, but you want maximum-prefix to act on ALL (including filtered) prefixes. This option requires `soft-reconfiguration inbound` to be enabled for the peer. @@ -3172,16 +3172,16 @@ displays IPv6 routing table. Total number of prefixes 1 - If _wide_ option is specified, then the prefix table's width is increased + If ``wide`` option is specified, then the prefix table's width is increased to fully display the prefix and the nexthop. This is especially handy dealing with IPv6 prefixes and if :clicmd:`[no] bgp default show-nexthop-hostname` is enabled. - If _all_ option is specified, _ip_ keyword is ignored, show bgp all and + If ``all`` option is specified, ``ip`` keyword is ignored, show bgp all and show ip bgp all commands display routes for all AFIs and SAFIs. - If _json_ option is specified, output is displayed in JSON format. + If ``json`` option is specified, output is displayed in JSON format. Some other commands provide additional options for filtering the output. @@ -3275,18 +3275,18 @@ structure is extended with :clicmd:`show bgp [afi] [safi]`. from neighbor or filtered routes received from neighbor based on the option specified. - If _wide_ option is specified, then the prefix table's width is increased + If ``wide`` option is specified, then the prefix table's width is increased to fully display the prefix and the nexthop. This is especially handy dealing with IPv6 prefixes and if :clicmd:`[no] bgp default show-nexthop-hostname` is enabled. - If _all_ option is specified, _ip_ keyword is ignored and, + If ``all`` option is specified, ``ip`` keyword is ignored and, routes displayed for all AFIs and SAFIs. - if afi is specified, with _all_ option, routes will be displayed for + if afi is specified, with ``all`` option, routes will be displayed for each SAFI in the selcted AFI - If _json_ option is specified, output is displayed in JSON format. + If ``json`` option is specified, output is displayed in JSON format. .. _bgp-display-routes-by-community: @@ -3320,18 +3320,18 @@ attribute. match the specified community list. When `exact-match` is specified, it displays only routes that have an exact match. - If _wide_ option is specified, then the prefix table's width is increased + If ``wide`` option is specified, then the prefix table's width is increased to fully display the prefix and the nexthop. This is especially handy dealing with IPv6 prefixes and if :clicmd:`[no] bgp default show-nexthop-hostname` is enabled. - If _all_ option is specified, _ip_ keyword is ignored and, + If ``all`` option is specified, ``ip`` keyword is ignored and, routes displayed for all AFIs and SAFIs. - if afi is specified, with _all_ option, routes will be displayed for + if afi is specified, with ``all`` option, routes will be displayed for each SAFI in the selcted AFI - If _json_ option is specified, output is displayed in JSON format. + If ``json`` option is specified, output is displayed in JSON format. .. _bgp-display-routes-by-lcommunity: diff --git a/doc/user/zebra.rst b/doc/user/zebra.rst index 624e3cfe1a..5c7f4ac773 100644 --- a/doc/user/zebra.rst +++ b/doc/user/zebra.rst @@ -72,6 +72,19 @@ Besides the common invocation options (:ref:`common-invocation-options`), the option and we will use Route Replace Semantics instead of delete than add. +.. option:: --asic-offload [notify_on_offload|notify_on_ack] + + The linux kernel has the ability to use asic-offload ( see switchdev + development ). When the operator knows that FRR will be working in + this way, allow them to specify this with FRR. At this point this + code only supports asynchronous notification of the offload state. + In other words the initial ACK received for linux kernel installation + does not give zebra any data about what the state of the offload + is. This option takes the optional paramegers notify_on_offload + or notify_on_ack. This signals to zebra to notify upper level + protocols about route installation/update on ack received from + the linux kernel or from offload notification. + .. _interface-commands: Configuration Addresses behaviour diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index 9b814c92de..74a0d795ab 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -319,6 +319,7 @@ enum rt_scope_t { #define RTM_F_FIB_MATCH 0x2000 /* return full fib lookup match */ #define RTM_F_OFFLOAD 0x4000 /* route is offloaded */ #define RTM_F_TRAP 0x8000 /* route is trapping packets */ +#define RTM_F_OFFLOAD_FAILED 0x10000 /* route offload failed */ /* Reserved table identifiers */ diff --git a/isisd/isis_redist.c b/isisd/isis_redist.c index 5714fa872a..240be27cf3 100644 --- a/isisd/isis_redist.c +++ b/isisd/isis_redist.c @@ -167,8 +167,7 @@ static void isis_redist_update_ext_reach(struct isis_area *area, int level, area_info.metric = redist->metric; if (redist->map_name) { - map_ret = - route_map_apply(redist->map, p, RMAP_ISIS, &area_info); + map_ret = route_map_apply(redist->map, p, &area_info); if (map_ret == RMAP_DENYMATCH) area_info.distance = 255; } diff --git a/isisd/isis_routemap.c b/isisd/isis_routemap.c index 902528e1bb..db0f2fd8be 100644 --- a/isisd/isis_routemap.c +++ b/isisd/isis_routemap.c @@ -49,14 +49,10 @@ #include "isis_routemap.h" static enum route_map_cmd_result_t -route_match_ip_address(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_address(void *rule, const struct prefix *prefix, void *object) { struct access_list *alist; - if (type != RMAP_ISIS) - return RMAP_NOMATCH; - alist = access_list_lookup(AFI_IP, (char *)rule); if (access_list_apply(alist, prefix) != FILTER_DENY) return RMAP_MATCH; @@ -85,13 +81,10 @@ static const struct route_map_rule_cmd route_match_ip_address_cmd = { static enum route_map_cmd_result_t route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct prefix_list *plist; - if (type != RMAP_ISIS) - return RMAP_NOMATCH; - plist = prefix_list_lookup(AFI_IP, (char *)rule); if (prefix_list_apply(plist, prefix) != PREFIX_DENY) return RMAP_MATCH; @@ -120,14 +113,10 @@ static const struct route_map_rule_cmd /* ------------------------------------------------------------*/ static enum route_map_cmd_result_t -route_match_ipv6_address(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ipv6_address(void *rule, const struct prefix *prefix, void *object) { struct access_list *alist; - if (type != RMAP_ISIS) - return RMAP_NOMATCH; - alist = access_list_lookup(AFI_IP6, (char *)rule); if (access_list_apply(alist, prefix) != FILTER_DENY) return RMAP_MATCH; @@ -156,13 +145,10 @@ static const struct route_map_rule_cmd route_match_ipv6_address_cmd = { static enum route_map_cmd_result_t route_match_ipv6_address_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct prefix_list *plist; - if (type != RMAP_ISIS) - return RMAP_NOMATCH; - plist = prefix_list_lookup(AFI_IP6, (char *)rule); if (prefix_list_apply(plist, prefix) != PREFIX_DENY) return RMAP_MATCH; @@ -191,18 +177,16 @@ static const struct route_map_rule_cmd /* ------------------------------------------------------------*/ static enum route_map_cmd_result_t -route_set_metric(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_metric(void *rule, const struct prefix *prefix, void *object) { uint32_t *metric; struct isis_ext_info *info; - if (type == RMAP_ISIS) { - metric = rule; - info = object; + metric = rule; + info = object; + + info->metric = *metric; - info->metric = *metric; - } return RMAP_OKAY; } @@ -104,7 +104,10 @@ void bfd_set_param(struct bfd_info **bfd_info, uint32_t min_rx, uint32_t min_tx, if (((*bfd_info)->required_min_rx != min_rx) || ((*bfd_info)->desired_min_tx != min_tx) || ((*bfd_info)->detect_mult != detect_mult) - || (profile && strcmp((*bfd_info)->profile, profile))) + || ((*bfd_info)->profile[0] == 0 && profile) + || ((*bfd_info)->profile[0] && profile == NULL) + || (profile && (*bfd_info)->profile[0] + && strcmp((*bfd_info)->profile, profile))) *command = ZEBRA_BFD_DEST_UPDATE; } @@ -468,6 +471,39 @@ int zclient_bfd_command(struct zclient *zc, struct bfd_session_arg *args) : sizeof(struct in6_addr); stream_put(s, &args->dst, addrlen); + /* + * For more BFD integration protocol details, see function + * `_ptm_msg_read` in `bfdd/ptm_adapter.c`. + */ +#if HAVE_BFDD > 0 + /* Session timers. */ + stream_putl(s, args->min_rx); + stream_putl(s, args->min_tx); + stream_putc(s, args->detection_multiplier); + + /* Is multi hop? */ + stream_putc(s, args->mhop != 0); + + /* Source address. */ + stream_putw(s, args->family); + stream_put(s, &args->src, addrlen); + + /* Send the expected TTL. */ + stream_putc(s, args->ttl); + + /* Send interface name if any. */ + stream_putc(s, args->ifnamelen); + if (args->ifnamelen) + stream_put(s, args->ifname, args->ifnamelen); + + /* Send the C bit indicator. */ + stream_putc(s, args->cbit); + + /* Send profile name if any. */ + stream_putc(s, args->profilelen); + if (args->profilelen) + stream_put(s, args->profile, args->profilelen); +#else /* PTM BFD */ /* Encode timers if this is a registration message. */ if (args->command != ZEBRA_BFD_DEST_DEREGISTER) { stream_putl(s, args->min_rx); @@ -500,16 +536,6 @@ int zclient_bfd_command(struct zclient *zc, struct bfd_session_arg *args) if (args->ifnamelen) stream_put(s, args->ifname, args->ifnamelen); } - - /* Send the C bit indicator. */ - stream_putc(s, args->cbit); - - /* `ptm-bfd` doesn't support profiles yet. */ -#if HAVE_BFDD > 0 - /* Send profile name if any. */ - stream_putc(s, args->profilelen); - if (args->profilelen) - stream_put(s, args->profile, args->profilelen); #endif /* HAVE_BFDD */ /* Finish the message by writing the size. */ diff --git a/lib/routemap.c b/lib/routemap.c index 0eb54a4794..004beb3628 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -1530,8 +1530,7 @@ enum rmap_compile_rets route_map_delete_set(struct route_map_index *index, static enum route_map_cmd_result_t route_map_apply_match(struct route_map_rule_list *match_list, - const struct prefix *prefix, route_map_object_t type, - void *object) + const struct prefix *prefix, void *object) { enum route_map_cmd_result_t ret = RMAP_NOMATCH; struct route_map_rule *match; @@ -1555,7 +1554,7 @@ route_map_apply_match(struct route_map_rule_list *match_list, * If all result in NOOP, end-result is NOOP. */ ret = (*match->cmd->func_apply)(match->value, prefix, - type, object); + object); /* * If the consolidated result of func_apply is: @@ -1647,9 +1646,10 @@ static struct list *route_map_get_index_list(struct route_node **rn, /* * This function returns the route-map index that best matches the prefix. */ -static struct route_map_index * -route_map_get_index(struct route_map *map, const struct prefix *prefix, - route_map_object_t type, void *object, uint8_t *match_ret) +static struct route_map_index *route_map_get_index(struct route_map *map, + const struct prefix *prefix, + void *object, + uint8_t *match_ret) { int ret = 0; struct list *candidate_rmap_list = NULL; @@ -1695,7 +1695,7 @@ route_map_get_index(struct route_map *map, const struct prefix *prefix, break; ret = route_map_apply_match(&index->match_list, prefix, - type, object); + object); if (ret == RMAP_MATCH) { *match_ret = ret; @@ -2369,8 +2369,7 @@ void route_map_notify_pentry_dependencies(const char *affected_name, We need to make sure our route-map processing matches the above */ route_map_result_t route_map_apply(struct route_map *map, - const struct prefix *prefix, - route_map_object_t type, void *object) + const struct prefix *prefix, void *object) { static int recursion = 0; enum route_map_cmd_result_t match_ret = RMAP_NOMATCH; @@ -2397,7 +2396,7 @@ route_map_result_t route_map_apply(struct route_map *map, if ((!map->optimization_disabled) && (map->ipv4_prefix_table || map->ipv6_prefix_table)) { - index = route_map_get_index(map, prefix, type, object, + index = route_map_get_index(map, prefix, object, (uint8_t *)&match_ret); if (index) { if (rmap_debug) @@ -2431,7 +2430,7 @@ route_map_result_t route_map_apply(struct route_map *map, index->applied++; /* Apply this index. */ match_ret = route_map_apply_match(&index->match_list, - prefix, type, object); + prefix, object); if (rmap_debug) { zlog_debug( "Route-map: %s, sequence: %d, prefix: %pFX, result: %s", @@ -2489,9 +2488,8 @@ route_map_result_t route_map_apply(struct route_map *map, * set succeeded or not. So, ignore * return code. */ - (void) (*set->cmd->func_apply)( - set->value, prefix, type, - object); + (void)(*set->cmd->func_apply)( + set->value, prefix, object); /* Call another route-map if available */ if (index->nextrm) { @@ -2504,8 +2502,7 @@ route_map_result_t route_map_apply(struct route_map *map, { recursion++; ret = route_map_apply( - nextrm, prefix, type, - object); + nextrm, prefix, object); recursion--; } diff --git a/lib/routemap.h b/lib/routemap.h index 64da4b87ef..3e208c8cb5 100644 --- a/lib/routemap.h +++ b/lib/routemap.h @@ -68,17 +68,6 @@ enum route_map_cmd_result_t { RMAP_ERROR }; - -typedef enum { - RMAP_RIP, - RMAP_RIPNG, - RMAP_OSPF, - RMAP_OSPF6, - RMAP_BGP, - RMAP_ZEBRA, - RMAP_ISIS, -} route_map_object_t; - typedef enum { RMAP_EXIT, RMAP_GOTO, RMAP_NEXT } route_map_end_t; typedef enum { @@ -117,7 +106,6 @@ struct route_map_rule_cmd { /* Function for value set or match. */ enum route_map_cmd_result_t (*func_apply)(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object); /* Compile argument and return result as void *. */ @@ -299,7 +287,6 @@ struct route_map *route_map_lookup_warn_noexist(struct vty *vty, const char *nam /* Apply route map to the object. */ extern route_map_result_t route_map_apply(struct route_map *map, const struct prefix *prefix, - route_map_object_t object_type, void *object); extern void route_map_add_hook(void (*func)(const char *)); diff --git a/lib/zclient.h b/lib/zclient.h index 231fdad09b..3c80ba7efa 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -514,6 +514,13 @@ struct zapi_route { * offload situation. */ #define ZEBRA_FLAG_OFFLOADED 0x100 +/* + * This flag tells everyone that the route has + * failed offloading. + * This flag makes no sense unless you are in an asic + * offload situation. + */ +#define ZEBRA_FLAG_OFFLOAD_FAILED 0x200 /* The older XXX_MESSAGE flags live here */ uint32_t message; diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index c053716f26..1d222d5568 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -1095,8 +1095,7 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex, tinfo.ifindex = ifindex; tinfo.tag = tag; - ret = route_map_apply(ospf6->rmap[type].map, prefix, RMAP_OSPF6, - &troute); + ret = route_map_apply(ospf6->rmap[type].map, prefix, &troute); if (ret == RMAP_DENYMATCH) { if (IS_OSPF6_DEBUG_ASBR) zlog_debug("Denied by route-map \"%s\"", @@ -1400,14 +1399,11 @@ static void ospf6_redistribute_show_config(struct vty *vty, struct ospf6 *ospf6) static enum route_map_cmd_result_t ospf6_routemap_rule_match_address_prefixlist(void *rule, const struct prefix *prefix, - route_map_object_t type, + void *object) { struct prefix_list *plist; - if (type != RMAP_OSPF6) - return RMAP_NOMATCH; - plist = prefix_list_lookup(AFI_IP6, (char *)rule); if (plist == NULL) return RMAP_NOMATCH; @@ -1440,18 +1436,16 @@ static const struct route_map_rule_cmd zero. */ static enum route_map_cmd_result_t ospf6_routemap_rule_match_interface(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct interface *ifp; struct ospf6_external_info *ei; - if (type == RMAP_OSPF6) { - ei = ((struct ospf6_route *)object)->route_option; - ifp = if_lookup_by_name_all_vrf((char *)rule); + ei = ((struct ospf6_route *)object)->route_option; + ifp = if_lookup_by_name_all_vrf((char *)rule); - if (ifp != NULL && ei->ifindex == ifp->ifindex) - return RMAP_MATCH; - } + if (ifp != NULL && ei->ifindex == ifp->ifindex) + return RMAP_MATCH; return RMAP_NOMATCH; } @@ -1480,14 +1474,13 @@ static const struct route_map_rule_cmd /* Match function for matching route tags */ static enum route_map_cmd_result_t -ospf6_routemap_rule_match_tag(void *rule, const struct prefix *p, - route_map_object_t type, void *object) +ospf6_routemap_rule_match_tag(void *rule, const struct prefix *p, void *object) { route_tag_t *tag = rule; struct ospf6_route *route = object; struct ospf6_external_info *info = route->route_option; - if (type == RMAP_OSPF6 && info->tag == *tag) + if (info->tag == *tag) return RMAP_MATCH; return RMAP_NOMATCH; @@ -1503,14 +1496,11 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t ospf6_routemap_rule_set_metric_type(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { char *metric_type = rule; struct ospf6_route *route = object; - if (type != RMAP_OSPF6) - return RMAP_OKAY; - if (strcmp(metric_type, "type-2") == 0) route->path.metric_type = 2; else @@ -1541,14 +1531,11 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t ospf6_routemap_rule_set_metric(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { char *metric = rule; struct ospf6_route *route = object; - if (type != RMAP_OSPF6) - return RMAP_OKAY; - route->path.cost = atoi(metric); return RMAP_OKAY; } @@ -1578,15 +1565,12 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t ospf6_routemap_rule_set_forwarding(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { char *forwarding = rule; struct ospf6_route *route = object; struct ospf6_external_info *info = route->route_option; - if (type != RMAP_OSPF6) - return RMAP_OKAY; - if (inet_pton(AF_INET6, forwarding, &info->forwarding) != 1) { memset(&info->forwarding, 0, sizeof(struct in6_addr)); return RMAP_ERROR; @@ -1617,16 +1601,12 @@ static const struct route_map_rule_cmd }; static enum route_map_cmd_result_t -ospf6_routemap_rule_set_tag(void *rule, const struct prefix *p, - route_map_object_t type, void *object) +ospf6_routemap_rule_set_tag(void *rule, const struct prefix *p, void *object) { route_tag_t *tag = rule; struct ospf6_route *route = object; struct ospf6_external_info *info = route->route_option; - if (type != RMAP_OSPF6) - return RMAP_OKAY; - info->tag = *tag; return RMAP_OKAY; } diff --git a/ospfd/ospf_opaque.c b/ospfd/ospf_opaque.c index eb0c4a949a..3939b5479f 100644 --- a/ospfd/ospf_opaque.c +++ b/ospfd/ospf_opaque.c @@ -126,6 +126,8 @@ void ospf_opaque_term(void) void ospf_opaque_finish(void) { + ospf_mpls_te_finish(); + ospf_router_info_finish(); ospf_ext_finish(); diff --git a/ospfd/ospf_routemap.c b/ospfd/ospf_routemap.c index c89fd3597f..f9e11541fc 100644 --- a/ospfd/ospf_routemap.c +++ b/ospfd/ospf_routemap.c @@ -127,27 +127,22 @@ static void ospf_route_map_event(const char *name) /* `match ip netxthop ' */ /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_ip_nexthop(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_nexthop(void *rule, const struct prefix *prefix, void *object) { struct access_list *alist; struct external_info *ei = object; struct prefix_ipv4 p; - if (type == RMAP_OSPF) { - p.family = AF_INET; - p.prefix = ei->nexthop; - p.prefixlen = IPV4_MAX_BITLEN; + p.family = AF_INET; + p.prefix = ei->nexthop; + p.prefixlen = IPV4_MAX_BITLEN; - alist = access_list_lookup(AFI_IP, (char *)rule); - if (alist == NULL) - return RMAP_NOMATCH; + alist = access_list_lookup(AFI_IP, (char *)rule); + if (alist == NULL) + return RMAP_NOMATCH; - return (access_list_apply(alist, &p) == FILTER_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (access_list_apply(alist, &p) == FILTER_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } /* Route map `ip next-hop' match statement. `arg' should be @@ -175,26 +170,22 @@ static const struct route_map_rule_cmd route_match_ip_nexthop_cmd = { static enum route_map_cmd_result_t route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct prefix_list *plist; struct external_info *ei = object; struct prefix_ipv4 p; - if (type == RMAP_OSPF) { - p.family = AF_INET; - p.prefix = ei->nexthop; - p.prefixlen = IPV4_MAX_BITLEN; + p.family = AF_INET; + p.prefix = ei->nexthop; + p.prefixlen = IPV4_MAX_BITLEN; - plist = prefix_list_lookup(AFI_IP, (char *)rule); - if (plist == NULL) - return RMAP_NOMATCH; + plist = prefix_list_lookup(AFI_IP, (char *)rule); + if (plist == NULL) + return RMAP_NOMATCH; - return (prefix_list_apply(plist, &p) == PREFIX_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (prefix_list_apply(plist, &p) == PREFIX_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } static void *route_match_ip_next_hop_prefix_list_compile(const char *arg) @@ -219,11 +210,11 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_ip_next_hop_type(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct external_info *ei = object; - if (type == RMAP_OSPF && prefix->family == AF_INET) { + if (prefix->family == AF_INET) { ei = (struct external_info *)object; if (!ei) return RMAP_NOMATCH; @@ -256,22 +247,17 @@ static const struct route_map_rule_cmd /* Match function should return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_ip_address(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_address(void *rule, const struct prefix *prefix, void *object) { struct access_list *alist; /* struct prefix_ipv4 match; */ - if (type == RMAP_OSPF) { - alist = access_list_lookup(AFI_IP, (char *)rule); - if (alist == NULL) - return RMAP_NOMATCH; + alist = access_list_lookup(AFI_IP, (char *)rule); + if (alist == NULL) + return RMAP_NOMATCH; - return (access_list_apply(alist, prefix) == FILTER_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (access_list_apply(alist, prefix) == FILTER_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } /* Route map `ip address' match statement. `arg' should be @@ -298,20 +284,16 @@ static const struct route_map_rule_cmd route_match_ip_address_cmd = { /* `match ip address prefix-list PREFIX_LIST' */ static enum route_map_cmd_result_t route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct prefix_list *plist; - if (type == RMAP_OSPF) { - plist = prefix_list_lookup(AFI_IP, (char *)rule); - if (plist == NULL) - return RMAP_NOMATCH; + plist = prefix_list_lookup(AFI_IP, (char *)rule); + if (plist == NULL) + return RMAP_NOMATCH; - return (prefix_list_apply(plist, prefix) == PREFIX_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (prefix_list_apply(plist, prefix) == PREFIX_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } static void *route_match_ip_address_prefix_list_compile(const char *arg) @@ -336,22 +318,18 @@ static const struct route_map_rule_cmd /* Match function should return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_interface(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_interface(void *rule, const struct prefix *prefix, void *object) { struct interface *ifp; struct external_info *ei; - if (type == RMAP_OSPF) { - ei = object; - ifp = if_lookup_by_name_all_vrf((char *)rule); + ei = object; + ifp = if_lookup_by_name_all_vrf((char *)rule); - if (ifp == NULL || ifp->ifindex != ei->ifindex) - return RMAP_NOMATCH; + if (ifp == NULL || ifp->ifindex != ei->ifindex) + return RMAP_NOMATCH; - return RMAP_MATCH; - } - return RMAP_NOMATCH; + return RMAP_MATCH; } /* Route map `interface' match statement. `arg' should be @@ -377,20 +355,15 @@ static const struct route_map_rule_cmd route_match_interface_cmd = { /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_tag(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_tag(void *rule, const struct prefix *prefix, void *object) { route_tag_t *tag; struct external_info *ei; - if (type == RMAP_OSPF) { - tag = rule; - ei = object; + tag = rule; + ei = object; - return ((ei->tag == *tag) ? RMAP_MATCH : RMAP_NOMATCH); - } - - return RMAP_NOMATCH; + return ((ei->tag == *tag) ? RMAP_MATCH : RMAP_NOMATCH); } /* Route map commands for tag matching. */ @@ -410,33 +383,31 @@ struct ospf_metric { /* `set metric METRIC' */ /* Set metric to attribute. */ static enum route_map_cmd_result_t -route_set_metric(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_metric(void *rule, const struct prefix *prefix, void *object) { struct ospf_metric *metric; struct external_info *ei; - if (type == RMAP_OSPF) { - /* Fetch routemap's rule information. */ - metric = rule; - ei = object; + /* Fetch routemap's rule information. */ + metric = rule; + ei = object; - /* Set metric out value. */ - if (!metric->used) - return RMAP_OKAY; + /* Set metric out value. */ + if (!metric->used) + return RMAP_OKAY; - ei->route_map_set.metric = DEFAULT_DEFAULT_METRIC; + ei->route_map_set.metric = DEFAULT_DEFAULT_METRIC; - if (metric->type == metric_increment) - ei->route_map_set.metric += metric->metric; - else if (metric->type == metric_decrement) - ei->route_map_set.metric -= metric->metric; - else if (metric->type == metric_absolute) - ei->route_map_set.metric = metric->metric; + if (metric->type == metric_increment) + ei->route_map_set.metric += metric->metric; + else if (metric->type == metric_decrement) + ei->route_map_set.metric -= metric->metric; + else if (metric->type == metric_absolute) + ei->route_map_set.metric = metric->metric; + + if (ei->route_map_set.metric > OSPF_LS_INFINITY) + ei->route_map_set.metric = OSPF_LS_INFINITY; - if (ei->route_map_set.metric > OSPF_LS_INFINITY) - ei->route_map_set.metric = OSPF_LS_INFINITY; - } return RMAP_OKAY; } @@ -492,20 +463,18 @@ static const struct route_map_rule_cmd route_set_metric_cmd = { /* `set metric-type TYPE' */ /* Set metric-type to attribute. */ static enum route_map_cmd_result_t -route_set_metric_type(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_metric_type(void *rule, const struct prefix *prefix, void *object) { uint32_t *metric_type; struct external_info *ei; - if (type == RMAP_OSPF) { - /* Fetch routemap's rule information. */ - metric_type = rule; - ei = object; + /* Fetch routemap's rule information. */ + metric_type = rule; + ei = object; + + /* Set metric out value. */ + ei->route_map_set.metric_type = *metric_type; - /* Set metric out value. */ - ei->route_map_set.metric_type = *metric_type; - } return RMAP_OKAY; } @@ -543,19 +512,16 @@ static const struct route_map_rule_cmd route_set_metric_type_cmd = { }; static enum route_map_cmd_result_t -route_set_tag(void *rule, const struct prefix *prefix, route_map_object_t type, - void *object) +route_set_tag(void *rule, const struct prefix *prefix, void *object) { route_tag_t *tag; struct external_info *ei; - if (type == RMAP_OSPF) { - tag = rule; - ei = object; + tag = rule; + ei = object; - /* Set tag value */ - ei->tag = *tag; - } + /* Set tag value */ + ei->tag = *tag; return RMAP_OKAY; } diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index e3c554c530..17ff9a1a46 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -187,6 +187,7 @@ void ospf_mpls_te_finish(void) // list_delete_all_node(OspfMplsTE.iflist); OspfMplsTE.enabled = false; + ospf_mpls_te_unregister(); OspfMplsTE.inter_as = Off; } @@ -2229,6 +2230,17 @@ DEFUN (no_ospf_mpls_te, if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA); + /* + * This resets the OspfMplsTE.inter_as to its initial state. + * This is to avoid having an inter-as value different from + * Off when mpls-te gets restarted (after being removed) + */ + if (OspfMplsTE.inter_as != Off) { + /* Deregister the Callbacks for Inter-AS support */ + ospf_mpls_te_unregister(); + OspfMplsTE.inter_as = Off; + } + return CMD_SUCCESS; } diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index fd965e8f21..d449f9d2fa 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -902,8 +902,7 @@ int ospf_external_info_apply_default_routemap(struct ospf *ospf, if (red && ROUTEMAP_NAME(red)) { route_map_result_t ret; - ret = route_map_apply(ROUTEMAP(red), (struct prefix *)p, - RMAP_OSPF, ei); + ret = route_map_apply(ROUTEMAP(red), (struct prefix *)p, ei); if (ret == RMAP_DENYMATCH) { ei->route_map_set = save_values; @@ -1056,8 +1055,7 @@ int ospf_redistribute_check(struct ospf *ospf, struct external_info *ei, if (red && ROUTEMAP_NAME(red)) { route_map_result_t ret; - ret = route_map_apply(ROUTEMAP(red), (struct prefix *)p, - RMAP_OSPF, ei); + ret = route_map_apply(ROUTEMAP(red), (struct prefix *)p, ei); if (ret == RMAP_DENYMATCH) { ei->route_map_set = save_values; diff --git a/ripd/rip_routemap.c b/ripd/rip_routemap.c index 77c2db8ceb..061cefec30 100644 --- a/ripd/rip_routemap.c +++ b/ripd/rip_routemap.c @@ -43,27 +43,23 @@ struct rip_metric_modifier { /* `match metric METRIC' */ /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_metric(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_metric(void *rule, const struct prefix *prefix, void *object) { uint32_t *metric; uint32_t check; struct rip_info *rinfo; - if (type == RMAP_RIP) { - metric = rule; - rinfo = object; - - /* If external metric is available, the route-map should - work on this one (for redistribute purpose) */ - check = (rinfo->external_metric) ? rinfo->external_metric - : rinfo->metric; - if (check == *metric) - return RMAP_MATCH; - else - return RMAP_NOMATCH; - } - return RMAP_NOMATCH; + metric = rule; + rinfo = object; + + /* If external metric is available, the route-map should + work on this one (for redistribute purpose) */ + check = (rinfo->external_metric) ? rinfo->external_metric + : rinfo->metric; + if (check == *metric) + return RMAP_MATCH; + else + return RMAP_NOMATCH; } /* Route map `match metric' match statement. `arg' is METRIC value */ @@ -98,29 +94,25 @@ static const struct route_map_rule_cmd route_match_metric_cmd = { /* `match interface IFNAME' */ /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_interface(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_interface(void *rule, const struct prefix *prefix, void *object) { struct rip_info *rinfo; struct interface *ifp; char *ifname; - if (type == RMAP_RIP) { - ifname = rule; - ifp = if_lookup_by_name(ifname, VRF_DEFAULT); + ifname = rule; + ifp = if_lookup_by_name(ifname, VRF_DEFAULT); - if (!ifp) - return RMAP_NOMATCH; + if (!ifp) + return RMAP_NOMATCH; - rinfo = object; + rinfo = object; - if (rinfo->ifindex_out == ifp->ifindex - || rinfo->nh.ifindex == ifp->ifindex) - return RMAP_MATCH; - else - return RMAP_NOMATCH; - } - return RMAP_NOMATCH; + if (rinfo->ifindex_out == ifp->ifindex + || rinfo->nh.ifindex == ifp->ifindex) + return RMAP_MATCH; + else + return RMAP_NOMATCH; } /* Route map `match interface' match statement. `arg' is IFNAME value */ @@ -148,30 +140,25 @@ static const struct route_map_rule_cmd route_match_interface_cmd = { /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_ip_next_hop(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_next_hop(void *rule, const struct prefix *prefix, void *object) { struct access_list *alist; struct rip_info *rinfo; struct prefix_ipv4 p; - if (type == RMAP_RIP) { - rinfo = object; - p.family = AF_INET; - p.prefix = (rinfo->nh.gate.ipv4.s_addr != INADDR_ANY) - ? rinfo->nh.gate.ipv4 - : rinfo->from; - p.prefixlen = IPV4_MAX_BITLEN; + rinfo = object; + p.family = AF_INET; + p.prefix = (rinfo->nh.gate.ipv4.s_addr != INADDR_ANY) + ? rinfo->nh.gate.ipv4 + : rinfo->from; + p.prefixlen = IPV4_MAX_BITLEN; - alist = access_list_lookup(AFI_IP, (char *)rule); - if (alist == NULL) - return RMAP_NOMATCH; + alist = access_list_lookup(AFI_IP, (char *)rule); + if (alist == NULL) + return RMAP_NOMATCH; - return (access_list_apply(alist, &p) == FILTER_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (access_list_apply(alist, &p) == FILTER_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } /* Route map `ip next-hop' match statement. `arg' should be @@ -199,29 +186,25 @@ static const struct route_map_rule_cmd route_match_ip_next_hop_cmd = { static enum route_map_cmd_result_t route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct prefix_list *plist; struct rip_info *rinfo; struct prefix_ipv4 p; - if (type == RMAP_RIP) { - rinfo = object; - p.family = AF_INET; - p.prefix = (rinfo->nh.gate.ipv4.s_addr != INADDR_ANY) - ? rinfo->nh.gate.ipv4 - : rinfo->from; - p.prefixlen = IPV4_MAX_BITLEN; + rinfo = object; + p.family = AF_INET; + p.prefix = (rinfo->nh.gate.ipv4.s_addr != INADDR_ANY) + ? rinfo->nh.gate.ipv4 + : rinfo->from; + p.prefixlen = IPV4_MAX_BITLEN; - plist = prefix_list_lookup(AFI_IP, (char *)rule); - if (plist == NULL) - return RMAP_NOMATCH; + plist = prefix_list_lookup(AFI_IP, (char *)rule); + if (plist == NULL) + return RMAP_NOMATCH; - return (prefix_list_apply(plist, &p) == PREFIX_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (prefix_list_apply(plist, &p) == PREFIX_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } static void *route_match_ip_next_hop_prefix_list_compile(const char *arg) @@ -246,11 +229,11 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_ip_next_hop_type(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct rip_info *rinfo; - if (type == RMAP_RIP && prefix->family == AF_INET) { + if (prefix->family == AF_INET) { rinfo = (struct rip_info *)object; if (!rinfo) return RMAP_NOMATCH; @@ -284,21 +267,16 @@ static const struct route_map_rule_cmd /* Match function should return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_ip_address(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_address(void *rule, const struct prefix *prefix, void *object) { struct access_list *alist; - if (type == RMAP_RIP) { - alist = access_list_lookup(AFI_IP, (char *)rule); - if (alist == NULL) - return RMAP_NOMATCH; + alist = access_list_lookup(AFI_IP, (char *)rule); + if (alist == NULL) + return RMAP_NOMATCH; - return (access_list_apply(alist, prefix) == FILTER_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (access_list_apply(alist, prefix) == FILTER_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } /* Route map `ip address' match statement. `arg' should be @@ -326,20 +304,16 @@ static const struct route_map_rule_cmd route_match_ip_address_cmd = { static enum route_map_cmd_result_t route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct prefix_list *plist; - if (type == RMAP_RIP) { - plist = prefix_list_lookup(AFI_IP, (char *)rule); - if (plist == NULL) - return RMAP_NOMATCH; + plist = prefix_list_lookup(AFI_IP, (char *)rule); + if (plist == NULL) + return RMAP_NOMATCH; - return (prefix_list_apply(plist, prefix) == PREFIX_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (prefix_list_apply(plist, prefix) == PREFIX_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } static void *route_match_ip_address_prefix_list_compile(const char *arg) @@ -363,25 +337,21 @@ static const struct route_map_rule_cmd /* `match tag TAG' */ /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_tag(void *rule, const struct prefix *p, route_map_object_t type, - void *object) +route_match_tag(void *rule, const struct prefix *p, void *object) { route_tag_t *tag; struct rip_info *rinfo; route_tag_t rinfo_tag; - if (type == RMAP_RIP) { - tag = rule; - rinfo = object; + tag = rule; + rinfo = object; - /* The information stored by rinfo is host ordered. */ - rinfo_tag = rinfo->tag; - if (rinfo_tag == *tag) - return RMAP_MATCH; - else - return RMAP_NOMATCH; - } - return RMAP_NOMATCH; + /* The information stored by rinfo is host ordered. */ + rinfo_tag = rinfo->tag; + if (rinfo_tag == *tag) + return RMAP_MATCH; + else + return RMAP_NOMATCH; } /* Route map commands for tag matching. */ @@ -396,33 +366,30 @@ static const struct route_map_rule_cmd route_match_tag_cmd = { /* Set metric to attribute. */ static enum route_map_cmd_result_t -route_set_metric(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_metric(void *rule, const struct prefix *prefix, void *object) { - if (type == RMAP_RIP) { - struct rip_metric_modifier *mod; - struct rip_info *rinfo; + struct rip_metric_modifier *mod; + struct rip_info *rinfo; - mod = rule; - rinfo = object; + mod = rule; + rinfo = object; - if (!mod->used) - return RMAP_OKAY; + if (!mod->used) + return RMAP_OKAY; - if (mod->type == metric_increment) - rinfo->metric_out += mod->metric; - else if (mod->type == metric_decrement) - rinfo->metric_out -= mod->metric; - else if (mod->type == metric_absolute) - rinfo->metric_out = mod->metric; + if (mod->type == metric_increment) + rinfo->metric_out += mod->metric; + else if (mod->type == metric_decrement) + rinfo->metric_out -= mod->metric; + else if (mod->type == metric_absolute) + rinfo->metric_out = mod->metric; - if ((signed int)rinfo->metric_out < 1) - rinfo->metric_out = 1; - if (rinfo->metric_out > RIP_METRIC_INFINITY) - rinfo->metric_out = RIP_METRIC_INFINITY; + if ((signed int)rinfo->metric_out < 1) + rinfo->metric_out = 1; + if (rinfo->metric_out > RIP_METRIC_INFINITY) + rinfo->metric_out = RIP_METRIC_INFINITY; - rinfo->metric_set = 1; - } + rinfo->metric_set = 1; return RMAP_OKAY; } @@ -495,22 +462,20 @@ static const struct route_map_rule_cmd route_set_metric_cmd = { /* `set ip next-hop IP_ADDRESS' */ /* Set nexthop to object. ojbect must be pointer to struct attr. */ -static enum route_map_cmd_result_t route_set_ip_nexthop(void *rule, - const struct prefix *prefix, - route_map_object_t type, - void *object) +static enum route_map_cmd_result_t +route_set_ip_nexthop(void *rule, const struct prefix *prefix, + + void *object) { struct in_addr *address; struct rip_info *rinfo; - if (type == RMAP_RIP) { - /* Fetch routemap's rule information. */ - address = rule; - rinfo = object; + /* Fetch routemap's rule information. */ + address = rule; + rinfo = object; - /* Set next hop value. */ - rinfo->nexthop_out = *address; - } + /* Set next hop value. */ + rinfo->nexthop_out = *address; return RMAP_OKAY; } @@ -552,20 +517,17 @@ static const struct route_map_rule_cmd route_set_ip_nexthop_cmd = { /* Set tag to object. ojbect must be pointer to struct attr. */ static enum route_map_cmd_result_t -route_set_tag(void *rule, const struct prefix *prefix, route_map_object_t type, - void *object) +route_set_tag(void *rule, const struct prefix *prefix, void *object) { route_tag_t *tag; struct rip_info *rinfo; - if (type == RMAP_RIP) { - /* Fetch routemap's rule information. */ - tag = rule; - rinfo = object; + /* Fetch routemap's rule information. */ + tag = rule; + rinfo = object; - /* Set next hop value. */ - rinfo->tag_out = *tag; - } + /* Set next hop value. */ + rinfo->tag_out = *tag; return RMAP_OKAY; } diff --git a/ripd/ripd.c b/ripd/ripd.c index 059a0e2efd..0cec847f05 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -462,7 +462,7 @@ static void rip_rte_process(struct rte *rte, struct sockaddr_in *from, if (ri->routemap[RIP_FILTER_IN]) { /* The object should be of the type of rip_info */ ret = route_map_apply(ri->routemap[RIP_FILTER_IN], - (struct prefix *)&p, RMAP_RIP, &newinfo); + (struct prefix *)&p, &newinfo); if (ret == RMAP_DENYMATCH) { if (IS_RIP_DEBUG_PACKET) @@ -2251,7 +2251,7 @@ void rip_output_process(struct connected *ifc, struct sockaddr_in *to, if (ri->routemap[RIP_FILTER_OUT]) { ret = route_map_apply( ri->routemap[RIP_FILTER_OUT], - (struct prefix *)p, RMAP_RIP, rinfo); + (struct prefix *)p, rinfo); if (ret == RMAP_DENYMATCH) { if (IS_RIP_DEBUG_PACKET) @@ -2267,7 +2267,7 @@ void rip_output_process(struct connected *ifc, struct sockaddr_in *to, && rinfo->sub_type != RIP_ROUTE_INTERFACE) { ret = route_map_apply( rip->redist[rinfo->type].route_map.map, - (struct prefix *)p, RMAP_RIP, rinfo); + (struct prefix *)p, rinfo); if (ret == RMAP_DENYMATCH) { if (IS_RIP_DEBUG_PACKET) diff --git a/ripngd/ripng_routemap.c b/ripngd/ripng_routemap.c index b5f80d2ab0..9aed8d6963 100644 --- a/ripngd/ripng_routemap.c +++ b/ripngd/ripng_routemap.c @@ -39,21 +39,19 @@ struct rip_metric_modifier { /* `match metric METRIC' */ /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_metric(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_metric(void *rule, const struct prefix *prefix, void *object) { uint32_t *metric; struct ripng_info *rinfo; - if (type == RMAP_RIPNG) { - metric = rule; - rinfo = object; + metric = rule; + rinfo = object; + + if (rinfo->metric == *metric) + return RMAP_MATCH; + else + return RMAP_NOMATCH; - if (rinfo->metric == *metric) - return RMAP_MATCH; - else - return RMAP_NOMATCH; - } return RMAP_NOMATCH; } @@ -89,27 +87,25 @@ static const struct route_map_rule_cmd route_match_metric_cmd = { /* `match interface IFNAME' */ /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_interface(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_interface(void *rule, const struct prefix *prefix, void *object) { struct ripng_info *rinfo; struct interface *ifp; char *ifname; - if (type == RMAP_RIPNG) { - ifname = rule; - ifp = if_lookup_by_name(ifname, VRF_DEFAULT); + ifname = rule; + ifp = if_lookup_by_name(ifname, VRF_DEFAULT); - if (!ifp) - return RMAP_NOMATCH; + if (!ifp) + return RMAP_NOMATCH; - rinfo = object; + rinfo = object; + + if (rinfo->ifindex == ifp->ifindex) + return RMAP_MATCH; + else + return RMAP_NOMATCH; - if (rinfo->ifindex == ifp->ifindex) - return RMAP_MATCH; - else - return RMAP_NOMATCH; - } return RMAP_NOMATCH; } @@ -135,27 +131,24 @@ static const struct route_map_rule_cmd route_match_interface_cmd = { /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t route_match_tag(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) { route_tag_t *tag; struct ripng_info *rinfo; route_tag_t rinfo_tag; - if (type == RMAP_RIPNG) { - tag = rule; - rinfo = object; + tag = rule; + rinfo = object; - /* The information stored by rinfo is host ordered. */ - rinfo_tag = rinfo->tag; - if (rinfo_tag == *tag) - return RMAP_MATCH; - else - return RMAP_NOMATCH; - } - return RMAP_NOMATCH; + /* The information stored by rinfo is host ordered. */ + rinfo_tag = rinfo->tag; + if (rinfo_tag == *tag) + return RMAP_MATCH; + else + return RMAP_NOMATCH; } + static const struct route_map_rule_cmd route_match_tag_cmd = { "tag", route_match_tag, @@ -167,33 +160,31 @@ static const struct route_map_rule_cmd route_match_tag_cmd = { /* Set metric to attribute. */ static enum route_map_cmd_result_t -route_set_metric(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_set_metric(void *rule, const struct prefix *prefix, void *object) { - if (type == RMAP_RIPNG) { - struct rip_metric_modifier *mod; - struct ripng_info *rinfo; + struct rip_metric_modifier *mod; + struct ripng_info *rinfo; - mod = rule; - rinfo = object; + mod = rule; + rinfo = object; - if (!mod->used) - return RMAP_OKAY; + if (!mod->used) + return RMAP_OKAY; - if (mod->type == metric_increment) - rinfo->metric_out += mod->metric; - else if (mod->type == metric_decrement) - rinfo->metric_out -= mod->metric; - else if (mod->type == metric_absolute) - rinfo->metric_out = mod->metric; + if (mod->type == metric_increment) + rinfo->metric_out += mod->metric; + else if (mod->type == metric_decrement) + rinfo->metric_out -= mod->metric; + else if (mod->type == metric_absolute) + rinfo->metric_out = mod->metric; - if (rinfo->metric_out < 1) - rinfo->metric_out = 1; - if (rinfo->metric_out > RIPNG_METRIC_INFINITY) - rinfo->metric_out = RIPNG_METRIC_INFINITY; + if (rinfo->metric_out < 1) + rinfo->metric_out = 1; + if (rinfo->metric_out > RIPNG_METRIC_INFINITY) + rinfo->metric_out = RIPNG_METRIC_INFINITY; + + rinfo->metric_set = 1; - rinfo->metric_set = 1; - } return RMAP_OKAY; } @@ -265,20 +256,17 @@ static const struct route_map_rule_cmd route_set_metric_cmd = { /* Set nexthop to object. ojbect must be pointer to struct attr. */ static enum route_map_cmd_result_t -route_set_ipv6_nexthop_local(void *rule, const struct prefix *p, - route_map_object_t type, void *object) +route_set_ipv6_nexthop_local(void *rule, const struct prefix *p, void *object) { struct in6_addr *address; struct ripng_info *rinfo; - if (type == RMAP_RIPNG) { - /* Fetch routemap's rule information. */ - address = rule; - rinfo = object; + /* Fetch routemap's rule information. */ + address = rule; + rinfo = object; - /* Set next hop value. */ - rinfo->nexthop_out = *address; - } + /* Set next hop value. */ + rinfo->nexthop_out = *address; return RMAP_OKAY; } @@ -321,20 +309,17 @@ static const struct route_map_rule_cmd /* Set tag to object. ojbect must be pointer to struct attr. */ static enum route_map_cmd_result_t -route_set_tag(void *rule, const struct prefix *prefix, route_map_object_t type, - void *object) +route_set_tag(void *rule, const struct prefix *prefix, void *object) { route_tag_t *tag; struct ripng_info *rinfo; - if (type == RMAP_RIPNG) { - /* Fetch routemap's rule information. */ - tag = rule; - rinfo = object; + /* Fetch routemap's rule information. */ + tag = rule; + rinfo = object; - /* Set next hop value. */ - rinfo->tag_out = *tag; - } + /* Set next hop value. */ + rinfo->tag_out = *tag; return RMAP_OKAY; } diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 8d9249e4ae..1ebdae43fb 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -748,8 +748,7 @@ static void ripng_route_process(struct rte *rte, struct sockaddr_in6 *from, /* Modify entry. */ if (ri->routemap[RIPNG_FILTER_IN]) { ret = route_map_apply(ri->routemap[RIPNG_FILTER_IN], - (struct prefix *)&p, RMAP_RIPNG, - &newinfo); + (struct prefix *)&p, &newinfo); if (ret == RMAP_DENYMATCH) { if (IS_RIPNG_DEBUG_PACKET) @@ -1661,7 +1660,7 @@ void ripng_output_process(struct interface *ifp, struct sockaddr_in6 *to, if (ri->routemap[RIPNG_FILTER_OUT]) { ret = route_map_apply( ri->routemap[RIPNG_FILTER_OUT], - (struct prefix *)p, RMAP_RIPNG, rinfo); + (struct prefix *)p, rinfo); if (ret == RMAP_DENYMATCH) { if (IS_RIPNG_DEBUG_PACKET) @@ -1677,7 +1676,7 @@ void ripng_output_process(struct interface *ifp, struct sockaddr_in6 *to, ret = route_map_apply(ripng->redist[rinfo->type] .route_map.map, (struct prefix *)p, - RMAP_RIPNG, rinfo); + rinfo); if (ret == RMAP_DENYMATCH) { if (IS_RIPNG_DEBUG_PACKET) @@ -1773,8 +1772,7 @@ void ripng_output_process(struct interface *ifp, struct sockaddr_in6 *to, ret = route_map_apply( ri->routemap[RIPNG_FILTER_OUT], - (struct prefix *)p, RMAP_RIPNG, - &newinfo); + (struct prefix *)p, &newinfo); if (ret == RMAP_DENYMATCH) { if (IS_RIPNG_DEBUG_PACKET) diff --git a/zebra/connected.c b/zebra/connected.c index 6a1efc3e65..70ea2e3805 100644 --- a/zebra/connected.c +++ b/zebra/connected.c @@ -41,6 +41,7 @@ #include "zebra/zebra_mpls.h" #include "zebra/debug.h" #include "zebra/zebra_errors.h" +#include "zebra/zebra_router.h" /* communicate the withdrawal of a connected address */ static void connected_withdraw(struct connected *ifc) @@ -207,6 +208,7 @@ void connected_up(struct interface *ifp, struct connected *ifc) }; struct zebra_vrf *zvrf; uint32_t metric; + uint32_t flags = 0; zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id); if (!zvrf) { @@ -251,11 +253,22 @@ void connected_up(struct interface *ifp, struct connected *ifc) metric = (ifc->metric < (uint32_t)METRIC_MAX) ? ifc->metric : ifp->metric; - rib_add(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, - 0, 0, &p, NULL, &nh, 0, zvrf->table_id, metric, 0, 0, 0); - rib_add(afi, SAFI_MULTICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, - 0, 0, &p, NULL, &nh, 0, zvrf->table_id, metric, 0, 0, 0); + /* + * Since we are hand creating the connected routes + * in our main routing table, *if* we are working + * in an offloaded environment then we need to + * pretend like the route is offloaded so everything + * else will work + */ + if (zrouter.asic_offloaded) + flags |= ZEBRA_FLAG_OFFLOADED; + + rib_add(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, 0, + flags, &p, NULL, &nh, 0, zvrf->table_id, metric, 0, 0, 0); + + rib_add(afi, SAFI_MULTICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, 0, + flags, &p, NULL, &nh, 0, zvrf->table_id, metric, 0, 0, 0); /* Schedule LSP forwarding entries for processing, if appropriate. */ if (zvrf->vrf->vrf_id == VRF_DEFAULT) { diff --git a/zebra/main.c b/zebra/main.c index ced29e1a25..55fd3244cb 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -83,6 +83,8 @@ uint32_t nl_rcvbufsize = 4194304; #endif /* HAVE_NETLINK */ #define OPTION_V6_RR_SEMANTICS 2000 +#define OPTION_ASIC_OFFLOAD 2001 + /* Command line options. */ const struct option longopts[] = { {"batch", no_argument, NULL, 'b'}, @@ -92,6 +94,7 @@ const struct option longopts[] = { {"retain", no_argument, NULL, 'r'}, {"vrfdefaultname", required_argument, NULL, 'o'}, {"graceful_restart", required_argument, NULL, 'K'}, + {"asic-offload", optional_argument, NULL, OPTION_ASIC_OFFLOAD}, #ifdef HAVE_NETLINK {"vrfwnetns", no_argument, NULL, 'n'}, {"nl-bufsize", required_argument, NULL, 's'}, @@ -281,6 +284,8 @@ int main(int argc, char **argv) char *vrf_default_name_configured = NULL; struct sockaddr_storage dummy; socklen_t dummylen; + bool asic_offload = false; + bool notify_on_ack = true; graceful_restart = 0; vrf_configure_backend(VRF_BACKEND_VRF_LITE); @@ -301,6 +306,7 @@ int main(int argc, char **argv) " -r, --retain When program terminates, retain added route by zebra.\n" " -o, --vrfdefaultname Set default VRF name.\n" " -K, --graceful_restart Graceful restart at the kernel level, timer in seconds for expiration\n" + " -A, --asic-offload FRR is interacting with an asic underneath the linux kernel\n" #ifdef HAVE_NETLINK " -n, --vrfwnetns Use NetNS as VRF backend\n" " -s, --nl-bufsize Set netlink receive buffer size\n" @@ -366,6 +372,13 @@ int main(int argc, char **argv) case OPTION_V6_RR_SEMANTICS: v6_rr_semantics = true; break; + case OPTION_ASIC_OFFLOAD: + if (!strcmp(optarg, "notify_on_offload")) + notify_on_ack = false; + if (!strcmp(optarg, "notify_on_ack")) + notify_on_ack = true; + asic_offload = true; + break; #endif /* HAVE_NETLINK */ default: frr_help_exit(1); @@ -376,7 +389,7 @@ int main(int argc, char **argv) zrouter.master = frr_init(); /* Zebra related initialize. */ - zebra_router_init(); + zebra_router_init(asic_offload, notify_on_ack); zserv_init(); rib_init(); zebra_if_init(); diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 4dc8c2a6eb..3402edf467 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -642,7 +642,9 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, selfroute = is_selfroute(rtm->rtm_protocol); - if (!startup && selfroute && h->nlmsg_type == RTM_NEWROUTE) { + if (!startup && selfroute + && h->nlmsg_type == RTM_NEWROUTE + && !zrouter.asic_offloaded) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("Route type: %d Received that we think we have originated, ignoring", rtm->rtm_protocol); @@ -672,6 +674,8 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, flags |= ZEBRA_FLAG_TRAPPED; if (rtm->rtm_flags & RTM_F_OFFLOAD) flags |= ZEBRA_FLAG_OFFLOADED; + if (rtm->rtm_flags & RTM_F_OFFLOAD_FAILED) + flags |= ZEBRA_FLAG_OFFLOAD_FAILED; /* Route which inserted by Zebra. */ if (selfroute) { diff --git a/zebra/zebra_nb_config.c b/zebra/zebra_nb_config.c index df95770307..ea2e20ed3b 100644 --- a/zebra/zebra_nb_config.c +++ b/zebra/zebra_nb_config.c @@ -1550,12 +1550,14 @@ int lib_route_map_entry_set_action_source_v4_modify( if (pif != NULL) break; } - if (pif == NULL) { - snprintf(args->errmsg, args->errmsg_len, - "is not a local address: %s", - yang_dnode_get_string(args->dnode, NULL)); - return NB_ERR_VALIDATION; - } + /* + * On startup the local address *may* not have come up + * yet. We need to allow startup configuration of + * set src or we are fudged. Log it for future fun + */ + if (pif == NULL) + zlog_warn("set src %pI4 is not a local address", + &p.u.prefix4); return NB_OK; case NB_EV_PREPARE: case NB_EV_ABORT: @@ -1618,12 +1620,14 @@ int lib_route_map_entry_set_action_source_v6_modify( if (pif != NULL) break; } - if (pif == NULL) { - snprintf(args->errmsg, args->errmsg_len, - "is not a local adddress: %s", - yang_dnode_get_string(args->dnode, NULL)); - return NB_ERR_VALIDATION; - } + /* + * On startup the local address *may* not have come up + * yet. We need to allow startup configuration of + * set src or we are fudged. Log it for future fun + */ + if (pif == NULL) + zlog_warn("set src %pI6 is not a local address", + &p.u.prefix6); return NB_OK; case NB_EV_PREPARE: case NB_EV_ABORT: diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index b688704962..569b23573c 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -1821,8 +1821,12 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) "%s(%u):%pFX Stale dplane result for re %p", VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), dest_pfx, re); - } else - UNSET_FLAG(re->status, ROUTE_ENTRY_QUEUED); + } else { + if (!zrouter.asic_offloaded || + (CHECK_FLAG(re->flags, ZEBRA_FLAG_OFFLOADED) || + CHECK_FLAG(re->flags, ZEBRA_FLAG_OFFLOAD_FAILED))) + UNSET_FLAG(re->status, ROUTE_ENTRY_QUEUED); + } } if (old_re) { @@ -1899,8 +1903,23 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) zvrf->installs++; /* Notify route owner */ - zsend_route_notify_owner_ctx(ctx, ZAPI_ROUTE_INSTALLED); - + if (zebra_router_notify_on_ack()) + zsend_route_notify_owner_ctx(ctx, ZAPI_ROUTE_INSTALLED); + else { + if (re) { + if (CHECK_FLAG(re->flags, + ZEBRA_FLAG_OFFLOADED)) + zsend_route_notify_owner_ctx( + ctx, + ZAPI_ROUTE_INSTALLED); + if (CHECK_FLAG( + re->flags, + ZEBRA_FLAG_OFFLOAD_FAILED)) + zsend_route_notify_owner_ctx( + ctx, + ZAPI_ROUTE_FAIL_INSTALL); + } + } } else { if (re) { SET_FLAG(re->status, ROUTE_ENTRY_FAILED); @@ -2067,7 +2086,8 @@ static void rib_process_dplane_notify(struct zebra_dplane_ctx *ctx) } /* Ensure we clear the QUEUED flag */ - UNSET_FLAG(re->status, ROUTE_ENTRY_QUEUED); + if (!zrouter.asic_offloaded) + UNSET_FLAG(re->status, ROUTE_ENTRY_QUEUED); /* Is this a notification that ... matters? We mostly care about * the route that is currently selected for installation; we may also diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 294f2c17ff..7b0a1e3d9c 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -64,19 +64,17 @@ static void zebra_route_map_set_delay_timer(uint32_t value); * Match function return 1 if match is success else return 0 */ static enum route_map_cmd_result_t -route_match_tag(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_tag(void *rule, const struct prefix *prefix, void *object) { route_tag_t *tag; struct nh_rmap_obj *nh_data; - if (type == RMAP_ZEBRA) { - tag = rule; - nh_data = object; + tag = rule; + nh_data = object; + + if (nh_data->tag == *tag) + return RMAP_MATCH; - if (nh_data->tag == *tag) - return RMAP_MATCH; - } return RMAP_NOMATCH; } @@ -92,25 +90,23 @@ static const struct route_map_rule_cmd route_match_tag_cmd = { /* `match interface IFNAME' */ /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_interface(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_interface(void *rule, const struct prefix *prefix, void *object) { struct nh_rmap_obj *nh_data; char *ifname = rule; ifindex_t ifindex; - if (type == RMAP_ZEBRA) { - if (strcasecmp(ifname, "any") == 0) - return RMAP_MATCH; - nh_data = object; - if (!nh_data || !nh_data->nexthop) - return RMAP_NOMATCH; - ifindex = ifname2ifindex(ifname, nh_data->vrf_id); - if (ifindex == 0) - return RMAP_NOMATCH; - if (nh_data->nexthop->ifindex == ifindex) - return RMAP_MATCH; - } + if (strcasecmp(ifname, "any") == 0) + return RMAP_MATCH; + nh_data = object; + if (!nh_data || !nh_data->nexthop) + return RMAP_NOMATCH; + ifindex = ifname2ifindex(ifname, nh_data->vrf_id); + if (ifindex == 0) + return RMAP_NOMATCH; + if (nh_data->nexthop->ifindex == ifindex) + return RMAP_MATCH; + return RMAP_NOMATCH; } @@ -938,40 +934,35 @@ DEFPY_YANG (show_ipv6_protocol_nht, /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_ip_next_hop(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_next_hop(void *rule, const struct prefix *prefix, void *object) { struct access_list *alist; struct nh_rmap_obj *nh_data; struct prefix_ipv4 p; - if (type == RMAP_ZEBRA) { - nh_data = object; - if (!nh_data) - return RMAP_NOMATCH; - - switch (nh_data->nexthop->type) { - case NEXTHOP_TYPE_IFINDEX: - /* Interface routes can't match ip next-hop */ - return RMAP_NOMATCH; - case NEXTHOP_TYPE_IPV4_IFINDEX: - case NEXTHOP_TYPE_IPV4: - p.family = AF_INET; - p.prefix = nh_data->nexthop->gate.ipv4; - p.prefixlen = IPV4_MAX_BITLEN; - break; - default: - return RMAP_NOMATCH; - } - alist = access_list_lookup(AFI_IP, (char *)rule); - if (alist == NULL) - return RMAP_NOMATCH; + nh_data = object; + if (!nh_data) + return RMAP_NOMATCH; - return (access_list_apply(alist, &p) == FILTER_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); + switch (nh_data->nexthop->type) { + case NEXTHOP_TYPE_IFINDEX: + /* Interface routes can't match ip next-hop */ + return RMAP_NOMATCH; + case NEXTHOP_TYPE_IPV4_IFINDEX: + case NEXTHOP_TYPE_IPV4: + p.family = AF_INET; + p.prefix = nh_data->nexthop->gate.ipv4; + p.prefixlen = IPV4_MAX_BITLEN; + break; + default: + return RMAP_NOMATCH; } - return RMAP_NOMATCH; + alist = access_list_lookup(AFI_IP, (char *)rule); + if (alist == NULL) + return RMAP_NOMATCH; + + return (access_list_apply(alist, &p) == FILTER_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } /* Route map `ip next-hop' match statement. `arg' should be @@ -999,39 +990,35 @@ static const struct route_map_rule_cmd route_match_ip_next_hop_cmd = { static enum route_map_cmd_result_t route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct prefix_list *plist; struct nh_rmap_obj *nh_data; struct prefix_ipv4 p; - if (type == RMAP_ZEBRA) { - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data) - return RMAP_NOMATCH; - - switch (nh_data->nexthop->type) { - case NEXTHOP_TYPE_IFINDEX: - /* Interface routes can't match ip next-hop */ - return RMAP_NOMATCH; - case NEXTHOP_TYPE_IPV4_IFINDEX: - case NEXTHOP_TYPE_IPV4: - p.family = AF_INET; - p.prefix = nh_data->nexthop->gate.ipv4; - p.prefixlen = IPV4_MAX_BITLEN; - break; - default: - return RMAP_NOMATCH; - } - plist = prefix_list_lookup(AFI_IP, (char *)rule); - if (plist == NULL) - return RMAP_NOMATCH; + nh_data = (struct nh_rmap_obj *)object; + if (!nh_data) + return RMAP_NOMATCH; - return (prefix_list_apply(plist, &p) == PREFIX_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); + switch (nh_data->nexthop->type) { + case NEXTHOP_TYPE_IFINDEX: + /* Interface routes can't match ip next-hop */ + return RMAP_NOMATCH; + case NEXTHOP_TYPE_IPV4_IFINDEX: + case NEXTHOP_TYPE_IPV4: + p.family = AF_INET; + p.prefix = nh_data->nexthop->gate.ipv4; + p.prefixlen = IPV4_MAX_BITLEN; + break; + default: + return RMAP_NOMATCH; } - return RMAP_NOMATCH; + plist = prefix_list_lookup(AFI_IP, (char *)rule); + if (plist == NULL) + return RMAP_NOMATCH; + + return (prefix_list_apply(plist, &p) == PREFIX_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } static void *route_match_ip_next_hop_prefix_list_compile(const char *arg) @@ -1058,34 +1045,28 @@ static const struct route_map_rule_cmd zero. */ static enum route_map_cmd_result_t route_match_address(afi_t afi, void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct access_list *alist; - if (type == RMAP_ZEBRA) { - alist = access_list_lookup(afi, (char *)rule); - if (alist == NULL) - return RMAP_NOMATCH; + alist = access_list_lookup(afi, (char *)rule); + if (alist == NULL) + return RMAP_NOMATCH; - return (access_list_apply(alist, prefix) == FILTER_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (access_list_apply(alist, prefix) == FILTER_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } static enum route_map_cmd_result_t -route_match_ip_address(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_address(void *rule, const struct prefix *prefix, void *object) { - return route_match_address(AFI_IP, rule, prefix, type, object); + return route_match_address(AFI_IP, rule, prefix, object); } static enum route_map_cmd_result_t -route_match_ipv6_address(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ipv6_address(void *rule, const struct prefix *prefix, void *object) { - return route_match_address(AFI_IP6, rule, prefix, type, object); + return route_match_address(AFI_IP6, rule, prefix, object); } /* Route map `ip address' match statement. `arg' should be @@ -1121,28 +1102,23 @@ static const struct route_map_rule_cmd route_match_ipv6_address_cmd = { static enum route_map_cmd_result_t route_match_address_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object, afi_t afi) + void *object, afi_t afi) { struct prefix_list *plist; - if (type == RMAP_ZEBRA) { - plist = prefix_list_lookup(afi, (char *)rule); - if (plist == NULL) - return RMAP_NOMATCH; + plist = prefix_list_lookup(afi, (char *)rule); + if (plist == NULL) + return RMAP_NOMATCH; - return (prefix_list_apply(plist, prefix) == PREFIX_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (prefix_list_apply(plist, prefix) == PREFIX_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } static enum route_map_cmd_result_t route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { - return (route_match_address_prefix_list(rule, prefix, type, object, - AFI_IP)); + return (route_match_address_prefix_list(rule, prefix, object, AFI_IP)); } static void *route_match_address_prefix_list_compile(const char *arg) @@ -1165,10 +1141,9 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_ipv6_address_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { - return (route_match_address_prefix_list(rule, prefix, type, object, - AFI_IP6)); + return (route_match_address_prefix_list(rule, prefix, object, AFI_IP6)); } static const struct route_map_rule_cmd @@ -1183,11 +1158,11 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_ipv6_next_hop_type(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct nh_rmap_obj *nh_data; - if (type == RMAP_ZEBRA && prefix->family == AF_INET6) { + if (prefix->family == AF_INET6) { nh_data = (struct nh_rmap_obj *)object; if (!nh_data) return RMAP_NOMATCH; @@ -1195,6 +1170,7 @@ route_match_ipv6_next_hop_type(void *rule, const struct prefix *prefix, if (nh_data->nexthop->type == NEXTHOP_TYPE_BLACKHOLE) return RMAP_MATCH; } + return RMAP_NOMATCH; } @@ -1220,15 +1196,11 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_address_prefix_len(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { uint32_t *prefixlen = (uint32_t *)rule; - if (type == RMAP_ZEBRA) { - return ((prefix->prefixlen == *prefixlen) ? RMAP_MATCH - : RMAP_NOMATCH); - } - return RMAP_NOMATCH; + return ((prefix->prefixlen == *prefixlen) ? RMAP_MATCH : RMAP_NOMATCH); } static void *route_match_address_prefix_len_compile(const char *arg) @@ -1277,34 +1249,30 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_ip_nexthop_prefix_len(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { uint32_t *prefixlen = (uint32_t *)rule; struct nh_rmap_obj *nh_data; struct prefix_ipv4 p; - if (type == RMAP_ZEBRA) { - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data || !nh_data->nexthop) - return RMAP_NOMATCH; + nh_data = (struct nh_rmap_obj *)object; + if (!nh_data || !nh_data->nexthop) + return RMAP_NOMATCH; - switch (nh_data->nexthop->type) { - case NEXTHOP_TYPE_IFINDEX: - /* Interface routes can't match ip next-hop */ - return RMAP_NOMATCH; - case NEXTHOP_TYPE_IPV4_IFINDEX: - case NEXTHOP_TYPE_IPV4: - p.family = AF_INET; - p.prefix = nh_data->nexthop->gate.ipv4; - p.prefixlen = IPV4_MAX_BITLEN; - break; - default: - return RMAP_NOMATCH; - } - return ((p.prefixlen == *prefixlen) ? RMAP_MATCH - : RMAP_NOMATCH); + switch (nh_data->nexthop->type) { + case NEXTHOP_TYPE_IFINDEX: + /* Interface routes can't match ip next-hop */ + return RMAP_NOMATCH; + case NEXTHOP_TYPE_IPV4_IFINDEX: + case NEXTHOP_TYPE_IPV4: + p.family = AF_INET; + p.prefix = nh_data->nexthop->gate.ipv4; + p.prefixlen = IPV4_MAX_BITLEN; + break; + default: + return RMAP_NOMATCH; } - return RMAP_NOMATCH; + return ((p.prefixlen == *prefixlen) ? RMAP_MATCH : RMAP_NOMATCH); } static const struct route_map_rule_cmd @@ -1319,11 +1287,11 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_ip_next_hop_type(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct nh_rmap_obj *nh_data; - if (type == RMAP_ZEBRA && prefix->family == AF_INET) { + if (prefix->family == AF_INET) { nh_data = (struct nh_rmap_obj *)object; if (!nh_data) return RMAP_NOMATCH; @@ -1331,6 +1299,7 @@ route_match_ip_next_hop_type(void *rule, const struct prefix *prefix, if (nh_data->nexthop->type == NEXTHOP_TYPE_BLACKHOLE) return RMAP_MATCH; } + return RMAP_NOMATCH; } @@ -1355,21 +1324,17 @@ static const struct route_map_rule_cmd /* `match source-protocol PROTOCOL' */ static enum route_map_cmd_result_t -route_match_source_protocol(void *rule, const struct prefix *p, - route_map_object_t type, void *object) +route_match_source_protocol(void *rule, const struct prefix *p, void *object) { uint32_t *rib_type = (uint32_t *)rule; struct nh_rmap_obj *nh_data; - if (type == RMAP_ZEBRA) { - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data) - return RMAP_NOMATCH; + nh_data = (struct nh_rmap_obj *)object; + if (!nh_data) + return RMAP_NOMATCH; - return ((nh_data->source_protocol == *rib_type) ? RMAP_MATCH - : RMAP_NOMATCH); - } - return RMAP_NOMATCH; + return ((nh_data->source_protocol == *rib_type) ? RMAP_MATCH + : RMAP_NOMATCH); } static void *route_match_source_protocol_compile(const char *arg) @@ -1399,15 +1364,11 @@ static const struct route_map_rule_cmd route_match_source_protocol_cmd = { /* `source-instance` */ static enum route_map_cmd_result_t -route_match_source_instance(void *rule, const struct prefix *p, - route_map_object_t type, void *object) +route_match_source_instance(void *rule, const struct prefix *p, void *object) { uint8_t *instance = (uint8_t *)rule; struct nh_rmap_obj *nh_data; - if (type != RMAP_ZEBRA) - return RMAP_NOMATCH; - nh_data = (struct nh_rmap_obj *)object; if (!nh_data) return RMAP_NOMATCH; @@ -1444,15 +1405,13 @@ static const struct route_map_rule_cmd route_match_source_instance_cmd = { /* Set src. */ static enum route_map_cmd_result_t -route_set_src(void *rule, const struct prefix *prefix, route_map_object_t type, - void *object) +route_set_src(void *rule, const struct prefix *prefix, void *object) { struct nh_rmap_obj *nh_data; - if (type == RMAP_ZEBRA) { - nh_data = (struct nh_rmap_obj *)object; - nh_data->nexthop->rmap_src = *(union g_addr *)rule; - } + nh_data = (struct nh_rmap_obj *)object; + nh_data->nexthop->rmap_src = *(union g_addr *)rule; + return RMAP_OKAY; } @@ -1738,7 +1697,7 @@ zebra_route_map_check(int family, int rib_type, uint8_t instance, if (!rmap && PROTO_RM_NAME(zvrf, family, ZEBRA_ROUTE_MAX)) rmap = PROTO_RM_MAP(zvrf, family, ZEBRA_ROUTE_MAX); if (rmap) { - ret = route_map_apply(rmap, p, RMAP_ZEBRA, &nh_obj); + ret = route_map_apply(rmap, p, &nh_obj); } return (ret); @@ -1782,7 +1741,7 @@ zebra_import_table_route_map_check(int family, int re_type, uint8_t instance, if (re_type >= 0 && re_type < ZEBRA_ROUTE_MAX) rmap = route_map_lookup_by_name(rmap_name); if (rmap) { - ret = route_map_apply(rmap, p, RMAP_ZEBRA, &nh_obj); + ret = route_map_apply(rmap, p, &nh_obj); } return (ret); @@ -1810,7 +1769,7 @@ route_map_result_t zebra_nht_route_map_check(afi_t afi, int client_proto, if (!rmap && NHT_RM_MAP(zvrf, afi, ZEBRA_ROUTE_MAX)) rmap = NHT_RM_MAP(zvrf, afi, ZEBRA_ROUTE_MAX); if (rmap) - ret = route_map_apply(rmap, p, RMAP_ZEBRA, &nh_obj); + ret = route_map_apply(rmap, p, &nh_obj); return ret; } diff --git a/zebra/zebra_router.c b/zebra/zebra_router.c index fc4390f7f8..249ec38a69 100644 --- a/zebra/zebra_router.c +++ b/zebra/zebra_router.c @@ -257,7 +257,12 @@ void zebra_router_terminate(void) hash_free(zrouter.iptable_hash); } -void zebra_router_init(void) +bool zebra_router_notify_on_ack(void) +{ + return !zrouter.asic_offloaded || zrouter.notify_on_ack; +} + +void zebra_router_init(bool asic_offload, bool notify_on_ack) { zrouter.sequence_num = 0; @@ -291,5 +296,6 @@ void zebra_router_init(void) hash_create_size(8, zebra_nhg_id_key, zebra_nhg_hash_id_equal, "Zebra Router Nexthop Groups ID index"); - zrouter.asic_offloaded = false; + zrouter.asic_offloaded = asic_offload; + zrouter.notify_on_ack = notify_on_ack; } diff --git a/zebra/zebra_router.h b/zebra/zebra_router.h index 8651a01e9f..08c5fcaf8d 100644 --- a/zebra/zebra_router.h +++ b/zebra/zebra_router.h @@ -210,13 +210,14 @@ struct zebra_router { * Does the underlying system provide an asic offload */ bool asic_offloaded; + bool notify_on_ack; }; #define GRACEFUL_RESTART_TIME 60 extern struct zebra_router zrouter; -extern void zebra_router_init(void); +extern void zebra_router_init(bool asic_offload, bool notify_on_ack); extern void zebra_router_cleanup(void); extern void zebra_router_terminate(void); @@ -255,6 +256,8 @@ extern void multicast_mode_ipv4_set(enum multicast_mode mode); extern enum multicast_mode multicast_mode_ipv4_get(void); +extern bool zebra_router_notify_on_ack(void); + /* zebra_northbound.c */ extern const struct frr_yang_module_info frr_zebra_info; diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index ab7d2845e7..ea7baa2565 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -204,12 +204,16 @@ static char re_status_output_char(const struct route_entry *re, star_p = true; } + if (zrouter.asic_offloaded && + CHECK_FLAG(re->status, ROUTE_ENTRY_QUEUED)) + return 'q'; + if (zrouter.asic_offloaded && CHECK_FLAG(re->flags, ZEBRA_FLAG_TRAPPED)) return 't'; if (zrouter.asic_offloaded - && !CHECK_FLAG(re->flags, ZEBRA_FLAG_OFFLOADED)) + && CHECK_FLAG(re->flags, ZEBRA_FLAG_OFFLOAD_FAILED)) return 'o'; if (star_p) @@ -870,6 +874,9 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, if (CHECK_FLAG(re->flags, ZEBRA_FLAG_OFFLOADED)) json_object_boolean_true_add(json_route, "offloaded"); + if (CHECK_FLAG(re->flags, ZEBRA_FLAG_OFFLOAD_FAILED)) + json_object_boolean_false_add(json_route, "offloaded"); + if (re->tag) json_object_int_add(json_route, "tag", re->tag); @@ -2005,6 +2012,8 @@ static void vty_show_ip_route_summary(struct vty *vty, #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1) uint32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1]; uint32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1]; + uint32_t offload_cnt[ZEBRA_ROUTE_TOTAL + 1]; + uint32_t trap_cnt[ZEBRA_ROUTE_TOTAL + 1]; uint32_t i; uint32_t is_ibgp; json_object *json_route_summary = NULL; @@ -2012,6 +2021,8 @@ static void vty_show_ip_route_summary(struct vty *vty, memset(&rib_cnt, 0, sizeof(rib_cnt)); memset(&fib_cnt, 0, sizeof(fib_cnt)); + memset(&offload_cnt, 0, sizeof(offload_cnt)); + memset(&trap_cnt, 0, sizeof(trap_cnt)); if (use_json) { json_route_summary = json_object_new_object(); @@ -2039,6 +2050,20 @@ static void vty_show_ip_route_summary(struct vty *vty, else fib_cnt[re->type]++; } + + if (CHECK_FLAG(re->flags, ZEBRA_FLAG_TRAPPED)) { + if (is_ibgp) + trap_cnt[ZEBRA_ROUTE_IBGP]++; + else + trap_cnt[re->type]++; + } + + if (CHECK_FLAG(re->flags, ZEBRA_FLAG_OFFLOADED)) { + if (is_ibgp) + offload_cnt[ZEBRA_ROUTE_IBGP]++; + else + offload_cnt[re->type]++; + } } if (!use_json) @@ -2062,6 +2087,13 @@ static void vty_show_ip_route_summary(struct vty *vty, json_object_int_add( json_route_ebgp, "rib", rib_cnt[ZEBRA_ROUTE_BGP]); + json_object_int_add( + json_route_ebgp, "fibOffLoaded", + offload_cnt[ZEBRA_ROUTE_BGP]); + json_object_int_add( + json_route_ebgp, "fibTrapped", + trap_cnt[ZEBRA_ROUTE_BGP]); + json_object_string_add(json_route_ebgp, "type", "ebgp"); json_object_array_add(json_route_routes, @@ -2076,6 +2108,12 @@ static void vty_show_ip_route_summary(struct vty *vty, json_object_int_add( json_route_ibgp, "rib", rib_cnt[ZEBRA_ROUTE_IBGP]); + json_object_int_add( + json_route_ibgp, "fibOffLoaded", + offload_cnt[ZEBRA_ROUTE_IBGP]); + json_object_int_add( + json_route_ibgp, "fibTrapped", + trap_cnt[ZEBRA_ROUTE_IBGP]); json_object_string_add(json_route_ibgp, "type", "ibgp"); json_object_array_add(json_route_routes, @@ -2099,6 +2137,13 @@ static void vty_show_ip_route_summary(struct vty *vty, "fib", fib_cnt[i]); json_object_int_add(json_route_type, "rib", rib_cnt[i]); + + json_object_int_add(json_route_type, + "fibOffLoaded", + offload_cnt[i]); + json_object_int_add(json_route_type, + "fibTrapped", + trap_cnt[i]); json_object_string_add( json_route_type, "type", zebra_route_string(i)); |
