Skip to content

Commit

Permalink
From 349e3f758860be0077b69919c39764d3486ec44a Mon Sep 17 00:00:00 200…
Browse files Browse the repository at this point in the history
…1 Subject: [PATCH] use vrf id instead of table id

Signed-off-by: Stepan Blyschak <[email protected]>
  • Loading branch information
stepanblyschak authored and cscarpitta committed Sep 15, 2024
1 parent 13c154a commit 2cc0781
Showing 1 changed file with 61 additions and 13 deletions.
74 changes: 61 additions & 13 deletions zebra/rt_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,30 @@ vrf_id_t vrf_lookup_by_table(uint32_t table_id, ns_id_t ns_id)
return VRF_DEFAULT;
}

static uint32_t table_lookup_by_vrf(vrf_id_t vrf_id, ns_id_t ns_id)
{
struct vrf *vrf;
struct zebra_vrf *zvrf;

RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
zvrf = vrf->info;
if (zvrf == NULL)
continue;
/* case vrf with netns : match the netnsid */
if (vrf_is_backend_netns()) {
if (ns_id == zvrf_id(zvrf))
return zvrf->table_id;
} else {
/* VRF is VRF_BACKEND_VRF_LITE */
if (zvrf_id(zvrf) != vrf_id)
continue;
return zvrf->table_id;
}
}

return RT_TABLE_UNSPEC;
}

/**
* @parse_encap_mpls() - Parses encapsulated mpls attributes
* @tb: Pointer to rtattr to look for nested items in.
Expand Down Expand Up @@ -782,14 +806,26 @@ int netlink_route_change_read_unicast_internal(struct nlmsghdr *h,
if (rtm->rtm_family == AF_MPLS)
return 0;

/* Table corresponding to route. */
if (tb[RTA_TABLE])
table = *(int *)RTA_DATA(tb[RTA_TABLE]);
else
table = rtm->rtm_table;
if (!ctx) {
/* Table corresponding to route. */
if (tb[RTA_TABLE])
table = *(int *)RTA_DATA(tb[RTA_TABLE]);
else
table = rtm->rtm_table;

/* Map to VRF */
vrf_id = vrf_lookup_by_table(table, ns_id);
} else {
/* With FPM, rtm_table contains vrf id, see netlink_route_multipath_msg_encode */
if (tb[RTA_TABLE])
vrf_id = *(int *)RTA_DATA(tb[RTA_TABLE]);
else
vrf_id = rtm->rtm_table;

/* Map to table */
table = table_lookup_by_vrf(vrf_id, ns_id);
}

/* Map to VRF */
vrf_id = vrf_lookup_by_table(table, ns_id);
if (vrf_id == VRF_DEFAULT) {
if (!is_zebra_valid_kernel_table(table)
&& !is_zebra_main_routing_table(table))
Expand Down Expand Up @@ -2089,12 +2125,24 @@ ssize_t netlink_route_multipath_msg_encode(int cmd,

/* Table corresponding to this route. */
table_id = dplane_ctx_get_table(ctx);
if (table_id < 256)
req->r.rtm_table = table_id;
else {
req->r.rtm_table = RT_TABLE_UNSPEC;
if (!nl_attr_put32(&req->n, datalen, RTA_TABLE, table_id))
return 0;
if (!fpm) {
if (table_id < 256)
req->r.rtm_table = table_id;
else {
req->r.rtm_table = RT_TABLE_UNSPEC;
if (!nl_attr_put32(&req->n, datalen, RTA_TABLE, table_id))
return 0;
}
} else {
/* Put vrf if_index instead of table id */
vrf_id_t vrf = dplane_ctx_get_vrf(ctx);
if (vrf < 256)
req->r.rtm_table = vrf;
else {
req->r.rtm_table = RT_TABLE_UNSPEC;
if (!nl_attr_put32(&req->n, datalen, RTA_TABLE, vrf))
return 0;
}
}

if (IS_ZEBRA_DEBUG_KERNEL)
Expand Down

0 comments on commit 2cc0781

Please sign in to comment.