diff options
Diffstat (limited to 'zebra/zapi_msg.c')
| -rw-r--r-- | zebra/zapi_msg.c | 81 |
1 files changed, 46 insertions, 35 deletions
diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index d6ade783cf..1dbe41f462 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -559,13 +559,15 @@ int zsend_redistribute_route(int cmd, struct zserv *client, memcpy(&api.src_prefix, src_p, sizeof(api.src_prefix)); } - for (nexthop = re->ng->nexthop; nexthop; nexthop = nexthop->next) { + for (nexthop = re->nhe->nhg->nexthop; + nexthop; nexthop = nexthop->next) { if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) continue; api_nh = &api.nexthops[count]; api_nh->vrf_id = nexthop->vrf_id; api_nh->type = nexthop->type; + api_nh->weight = nexthop->weight; switch (nexthop->type) { case NEXTHOP_TYPE_BLACKHOLE: api_nh->bh_type = nexthop->bh_type; @@ -666,7 +668,7 @@ static int zsend_ipv4_nexthop_lookup_mrib(struct zserv *client, * nexthop we are looking up. Therefore, we will just iterate * over the top chain of nexthops. */ - for (nexthop = re->ng->nexthop; nexthop; + for (nexthop = re->nhe->nhg->nexthop; nexthop; nexthop = nexthop->next) if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) num += zserv_encode_nexthop(s, nexthop); @@ -1022,7 +1024,7 @@ static int zsend_table_manager_connect_response(struct zserv *client, /* Inbound message handling ------------------------------------------------ */ -int cmd2type[] = { +const int cmd2type[] = { [ZEBRA_NEXTHOP_REGISTER] = RNH_NEXTHOP_TYPE, [ZEBRA_NEXTHOP_UNREGISTER] = RNH_NEXTHOP_TYPE, [ZEBRA_IMPORT_ROUTE_REGISTER] = RNH_IMPORT_CHECK_TYPE, @@ -1393,6 +1395,7 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) struct prefix_ipv6 *src_p = NULL; struct route_entry *re; struct nexthop *nexthop = NULL; + struct nexthop_group *ng = NULL; int i, ret; vrf_id_t vrf_id = 0; struct ipaddr vtep_ip; @@ -1409,11 +1412,8 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) char buf_prefix[PREFIX_STRLEN]; prefix2str(&api.prefix, buf_prefix, sizeof(buf_prefix)); - zlog_debug("%s: p=%s, ZAPI_MESSAGE_LABEL: %sset, flags=0x%x", - __func__, buf_prefix, - (CHECK_FLAG(api.message, ZAPI_MESSAGE_LABEL) ? "" - : "un"), - api.flags); + zlog_debug("%s: p=%s, flags=0x%x", + __func__, buf_prefix, api.flags); } /* Allocate new route. */ @@ -1424,7 +1424,6 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) re->flags = api.flags; re->uptime = monotime(NULL); re->vrf_id = vrf_id; - re->ng = nexthop_group_new(); if (api.tableid) re->table = api.tableid; @@ -1438,11 +1437,13 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) __func__, &api.prefix, zebra_route_string(client->proto)); - nexthop_group_delete(&re->ng); XFREE(MTYPE_RE, re); return; } + /* Use temporary list of nexthops */ + ng = nexthop_group_new(); + /* * TBD should _all_ of the nexthop add operations use * api_nh->vrf_id instead of re->vrf_id ? I only changed @@ -1457,8 +1458,8 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) switch (api_nh->type) { case NEXTHOP_TYPE_IFINDEX: - nexthop = route_entry_nexthop_ifindex_add( - re, api_nh->ifindex, api_nh->vrf_id); + nexthop = nexthop_from_ifindex(api_nh->ifindex, + api_nh->vrf_id); break; case NEXTHOP_TYPE_IPV4: if (IS_ZEBRA_DEBUG_RECV) { @@ -1469,8 +1470,8 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) zlog_debug("%s: nh=%s, vrf_id=%d", __func__, nhbuf, api_nh->vrf_id); } - nexthop = route_entry_nexthop_ipv4_add( - re, &api_nh->gate.ipv4, NULL, api_nh->vrf_id); + nexthop = nexthop_from_ipv4(&api_nh->gate.ipv4, + NULL, api_nh->vrf_id); break; case NEXTHOP_TYPE_IPV4_IFINDEX: @@ -1486,8 +1487,8 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) __func__, nhbuf, api_nh->vrf_id, re->vrf_id, ifindex); } - nexthop = route_entry_nexthop_ipv4_ifindex_add( - re, &api_nh->gate.ipv4, NULL, ifindex, + nexthop = nexthop_from_ipv4_ifindex( + &api_nh->gate.ipv4, NULL, ifindex, api_nh->vrf_id); /* Special handling for IPv4 routes sourced from EVPN: @@ -1504,15 +1505,15 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) } break; case NEXTHOP_TYPE_IPV6: - nexthop = route_entry_nexthop_ipv6_add( - re, &api_nh->gate.ipv6, api_nh->vrf_id); + nexthop = nexthop_from_ipv6(&api_nh->gate.ipv6, + api_nh->vrf_id); break; case NEXTHOP_TYPE_IPV6_IFINDEX: memset(&vtep_ip, 0, sizeof(struct ipaddr)); ifindex = api_nh->ifindex; - nexthop = route_entry_nexthop_ipv6_ifindex_add( - re, &api_nh->gate.ipv6, ifindex, - api_nh->vrf_id); + nexthop = nexthop_from_ipv6_ifindex(&api_nh->gate.ipv6, + ifindex, + api_nh->vrf_id); /* Special handling for IPv6 routes sourced from EVPN: * the nexthop and associated MAC need to be installed. @@ -1527,8 +1528,7 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) } break; case NEXTHOP_TYPE_BLACKHOLE: - nexthop = route_entry_nexthop_blackhole_add( - re, api_nh->bh_type); + nexthop = nexthop_from_blackhole(api_nh->bh_type); break; } @@ -1537,15 +1537,19 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) EC_ZEBRA_NEXTHOP_CREATION_FAILED, "%s: Nexthops Specified: %d but we failed to properly create one", __PRETTY_FUNCTION__, api.nexthop_num); - nexthop_group_delete(&re->ng); + nexthop_group_delete(&ng); XFREE(MTYPE_RE, re); return; } - if (api_nh->onlink) + + if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_ONLINK)) SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK); + if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_WEIGHT)) + nexthop->weight = api_nh->weight; + /* MPLS labels for BGP-LU or Segment Routing */ - if (CHECK_FLAG(api.message, ZAPI_MESSAGE_LABEL) + if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_LABEL) && api_nh->type != NEXTHOP_TYPE_IFINDEX && api_nh->type != NEXTHOP_TYPE_BLACKHOLE) { enum lsp_types_t label_type; @@ -1563,6 +1567,9 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) api_nh->label_num, &api_nh->labels[0]); } + + /* Add new nexthop to temporary list */ + nexthop_group_add_sorted(ng, nexthop); } if (CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE)) @@ -1579,14 +1586,14 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) flog_warn(EC_ZEBRA_RX_SRCDEST_WRONG_AFI, "%s: Received SRC Prefix but afi is not v6", __PRETTY_FUNCTION__); - nexthop_group_delete(&re->ng); + nexthop_group_delete(&ng); XFREE(MTYPE_RE, re); return; } if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) src_p = &api.src_prefix; - ret = rib_add_multipath(afi, api.safi, &api.prefix, src_p, re); + ret = rib_add_multipath(afi, api.safi, &api.prefix, src_p, re, ng); /* Stats */ switch (api.prefix.family) { @@ -1782,7 +1789,7 @@ static void zread_mpls_labels_add(ZAPI_HANDLER_ARGS) struct zapi_nexthop_label *znh; znh = &zl.nexthops[i]; - mpls_lsp_install(zvrf, zl.type, zl.local_label, znh->label, + mpls_lsp_install(zvrf, zl.type, zl.local_label, 1, &znh->label, znh->type, &znh->address, znh->ifindex); if (CHECK_FLAG(zl.message, ZAPI_LABELS_FTN)) @@ -1883,7 +1890,7 @@ static void zread_mpls_labels_replace(ZAPI_HANDLER_ARGS) struct zapi_nexthop_label *znh; znh = &zl.nexthops[i]; - mpls_lsp_install(zvrf, zl.type, zl.local_label, znh->label, + mpls_lsp_install(zvrf, zl.type, zl.local_label, 1, &znh->label, znh->type, &znh->address, znh->ifindex); if (CHECK_FLAG(zl.message, ZAPI_LABELS_FTN)) { @@ -2282,10 +2289,11 @@ static void zread_vrf_label(ZAPI_HANDLER_ARGS) ifp->ifindex); } - if (nlabel != MPLS_LABEL_NONE) - mpls_lsp_install(def_zvrf, ltype, nlabel, - MPLS_LABEL_IMPLICIT_NULL, NEXTHOP_TYPE_IFINDEX, - NULL, ifp->ifindex); + if (nlabel != MPLS_LABEL_NONE) { + mpls_label_t out_label = MPLS_LABEL_IMPLICIT_NULL; + mpls_lsp_install(def_zvrf, ltype, nlabel, 1, &out_label, + NEXTHOP_TYPE_IFINDEX, NULL, ifp->ifindex); + } zvrf->label[afi] = nlabel; stream_failure: @@ -2485,7 +2493,7 @@ stream_failure: return; } -void (*zserv_handlers[])(ZAPI_HANDLER_ARGS) = { +void (*const zserv_handlers[])(ZAPI_HANDLER_ARGS) = { [ZEBRA_ROUTER_ID_ADD] = zread_router_id_add, [ZEBRA_ROUTER_ID_DELETE] = zread_router_id_delete, [ZEBRA_INTERFACE_ADD] = zread_interface_add, @@ -2556,6 +2564,9 @@ void (*zserv_handlers[])(ZAPI_HANDLER_ARGS) = { [ZEBRA_IPTABLE_DELETE] = zread_iptable, [ZEBRA_VXLAN_FLOOD_CONTROL] = zebra_vxlan_flood_control, [ZEBRA_VXLAN_SG_REPLAY] = zebra_vxlan_sg_replay, + [ZEBRA_MLAG_CLIENT_REGISTER] = zebra_mlag_client_register, + [ZEBRA_MLAG_CLIENT_UNREGISTER] = zebra_mlag_client_unregister, + [ZEBRA_MLAG_FORWARD_MSG] = zebra_mlag_forward_client_msg, }; #if defined(HANDLE_ZAPI_FUZZING) |
