Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zebra route-leaking for static routes #1618

Merged
merged 18 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions zebra/connected.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,12 @@ void connected_up(struct interface *ifp, struct connected *ifc)
break;
}

rib_add(afi, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0,
rib_add(afi, SAFI_UNICAST, ifp->vrf_id, ifp->vrf_id,
ZEBRA_ROUTE_CONNECT, 0, 0,
&p, NULL, &nh, RT_TABLE_MAIN, ifp->metric, 0, 0, 0);

rib_add(afi, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0,
rib_add(afi, SAFI_MULTICAST, ifp->vrf_id, ifp->vrf_id,
ZEBRA_ROUTE_CONNECT, 0, 0,
&p, NULL, &nh, RT_TABLE_MAIN, ifp->metric, 0, 0, 0);

if (IS_ZEBRA_DEBUG_RIB_DETAILED) {
Expand Down
4 changes: 2 additions & 2 deletions zebra/kernel_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ void rtm_read(struct rt_msghdr *rtm)

if (rtm->rtm_type == RTM_GET || rtm->rtm_type == RTM_ADD
|| rtm->rtm_type == RTM_CHANGE)
rib_add(AFI_IP, SAFI_UNICAST, VRF_DEFAULT,
rib_add(AFI_IP, SAFI_UNICAST, VRF_DEFAULT, VRF_DEFAULT,
ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, NULL,
&nh, 0, 0, 0, 0, 0);
else
Expand Down Expand Up @@ -1096,7 +1096,7 @@ void rtm_read(struct rt_msghdr *rtm)

if (rtm->rtm_type == RTM_GET || rtm->rtm_type == RTM_ADD
|| rtm->rtm_type == RTM_CHANGE)
rib_add(AFI_IP6, SAFI_UNICAST, VRF_DEFAULT,
rib_add(AFI_IP6, SAFI_UNICAST, VRF_DEFAULT, VRF_DEFAULT,
ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, NULL,
&nh, 0, 0, 0, 0, 0);
else
Expand Down
4 changes: 2 additions & 2 deletions zebra/rib.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ extern void rib_uninstall_kernel(struct route_node *rn, struct route_entry *re);
/* NOTE:
* All rib_add function will not just add prefix into RIB, but
* also implicitly withdraw equal prefix of same type. */
extern int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type,
u_short instance, int flags, struct prefix *p,
extern int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, vrf_id_t nh_vrf_id,
int type, u_short instance, int flags, struct prefix *p,
struct prefix_ipv6 *src_p, const struct nexthop *nh,
u_int32_t table_id, u_int32_t metric, u_int32_t mtu,
uint8_t distance, route_tag_t tag);
Expand Down
24 changes: 23 additions & 1 deletion zebra/rt_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl,
afi = AFI_IP6;

if (h->nlmsg_type == RTM_NEWROUTE) {
struct interface *ifp;
vrf_id_t nh_vrf_id = vrf_id;

if (!tb[RTA_MULTIPATH]) {
struct nexthop nh;
size_t sz = (afi == AFI_IP) ? 4 : 16;
Expand Down Expand Up @@ -434,7 +437,14 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl,
if (gate)
memcpy(&nh.gate, gate, sz);

rib_add(afi, SAFI_UNICAST, vrf_id, proto,
if (index) {
ifp = if_lookup_by_index(index,
VRF_UNKNOWN);
if (ifp)
nh_vrf_id = ifp->vrf_id;
}

rib_add(afi, SAFI_UNICAST, vrf_id, nh_vrf_id, proto,
0, flags, &p, NULL, &nh, table, metric,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my understanding is that vrf route leak mechanism is not yet available on netns.
so I think that lookup mechanism should be put in place only for vrf with backend vrf lite.

at least what I will do is : if (!(vrf_id has backend netns) && index)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest that you stop route leaking before we get to this point and just leave this code alone. It should not care about the underlying mechanism

Copy link
Member

@pguibert6WIND pguibert6WIND Jan 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some other code in #1633 where I will have to know the kind of backend.
mainly because you can have the same interface name and interface index name for different vrfs.
so when you say "stop route leaking before", I need to ack with you that I will have that case very quickly.

mtu, distance, tag);
} else {
Expand Down Expand Up @@ -465,6 +475,18 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl,
break;

index = rtnh->rtnh_ifindex;
if (index) {
/*
* Yes we are looking this up
* for every nexthop and just
* using the last one looked
* up right now
*/
ifp = if_lookup_by_index(index,
VRF_UNKNOWN);
if (ifp)
re->nh_vrf_id = ifp->vrf_id;
}
gate = 0;
if (rtnh->rtnh_len > sizeof(*rtnh)) {
memset(tb, 0, sizeof(tb));
Expand Down
5 changes: 3 additions & 2 deletions zebra/rtread_getmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ static void handle_route_entry(mib2_ipRouteEntry_t *routeEntry)
nh.type = NEXTHOP_TYPE_IPV4;
nh.gate.ipv4.s_addr = routeEntry->ipRouteNextHop;

rib_add(AFI_IP, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL, 0,
zebra_flags, &prefix, NULL, &nh, 0, 0, 0, 0, 0);
rib_add(AFI_IP, SAFI_UNICAST, VRF_DEFAULT, VRF_DEFAULT,
ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &prefix, NULL,
&nh, 0, 0, 0, 0, 0);
}

void route_read(struct zebra_ns *zns)
Expand Down
9 changes: 5 additions & 4 deletions zebra/zebra_rib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2497,9 +2497,10 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type,
}


int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, u_short instance,
int flags, struct prefix *p, struct prefix_ipv6 *src_p,
const struct nexthop *nh, u_int32_t table_id, u_int32_t metric,
int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, vrf_id_t nh_vrf_id,
int type, u_short instance, int flags, struct prefix *p,
struct prefix_ipv6 *src_p, const struct nexthop *nh,
u_int32_t table_id, u_int32_t metric,
u_int32_t mtu, uint8_t distance, route_tag_t tag)
{
struct route_entry *re;
Expand All @@ -2515,7 +2516,7 @@ int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, u_short instance,
re->mtu = mtu;
re->table = table_id;
re->vrf_id = vrf_id;
re->nh_vrf_id = vrf_id;
re->nh_vrf_id = nh_vrf_id;
re->nexthop_num = 0;
re->uptime = time(NULL);
re->tag = tag;
Expand Down