Skip to content

Commit

Permalink
Merge pull request #1618 from donaldsharp/zebra_startup_ordering
Browse files Browse the repository at this point in the history
zebra route-leaking for static routes
  • Loading branch information
pguibert6WIND authored Jan 23, 2018
2 parents 5c65809 + 6140853 commit d6fed38
Show file tree
Hide file tree
Showing 29 changed files with 652 additions and 168 deletions.
1 change: 1 addition & 0 deletions babeld/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ zebra_route(int add, int family, const unsigned char *pref, unsigned short plen,
api.type = ZEBRA_ROUTE_BABEL;
api.safi = SAFI_UNICAST;
api.vrf_id = VRF_DEFAULT;
api.nh_vrf_id = VRF_DEFAULT;
api.prefix = quagga_prefix;

if(metric >= KERNEL_INFINITY) {
Expand Down
2 changes: 2 additions & 0 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ void bgp_zebra_announce(struct bgp_node *rn, struct prefix *p,
memset(&api, 0, sizeof(api));
memcpy(&api.rmac, &(info->attr->rmac), sizeof(struct ethaddr));
api.vrf_id = bgp->vrf_id;
api.nh_vrf_id = bgp->vrf_id;
api.type = ZEBRA_ROUTE_BGP;
api.safi = safi;
api.prefix = *p;
Expand Down Expand Up @@ -1253,6 +1254,7 @@ void bgp_zebra_withdraw(struct prefix *p, struct bgp_info *info, safi_t safi)
memset(&api, 0, sizeof(api));
memcpy(&api.rmac, &(info->attr->rmac), sizeof(struct ethaddr));
api.vrf_id = peer->bgp->vrf_id;
api.nh_vrf_id = peer->bgp->vrf_id;
api.type = ZEBRA_ROUTE_BGP;
api.safi = safi;
api.prefix = *p;
Expand Down
1 change: 1 addition & 0 deletions bgpd/rfapi/vnc_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ static void vnc_zebra_route_msg(struct prefix *p, unsigned int nhp_count,

memset(&api, 0, sizeof(api));
api.vrf_id = VRF_DEFAULT;
api.nh_vrf_id = VRF_DEFAULT;
api.type = ZEBRA_ROUTE_VNC;
api.safi = SAFI_UNICAST;
api.prefix = *p;
Expand Down
2 changes: 2 additions & 0 deletions eigrpd/eigrp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ void eigrp_zebra_route_add(struct prefix *p, struct list *successors)

memset(&api, 0, sizeof(api));
api.vrf_id = VRF_DEFAULT;
api.nh_vrf_id = VRF_DEFAULT;
api.type = ZEBRA_ROUTE_EIGRP;
api.safi = SAFI_UNICAST;
memcpy(&api.prefix, p, sizeof(*p));
Expand Down Expand Up @@ -407,6 +408,7 @@ void eigrp_zebra_route_delete(struct prefix *p)

memset(&api, 0, sizeof(api));
api.vrf_id = VRF_DEFAULT;
api.nh_vrf_id = VRF_DEFAULT;
api.type = ZEBRA_ROUTE_EIGRP;
api.safi = SAFI_UNICAST;
memcpy(&api.prefix, p, sizeof(*p));
Expand Down
2 changes: 2 additions & 0 deletions isisd/isis_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ static void isis_zebra_route_add_route(struct prefix *prefix,

memset(&api, 0, sizeof(api));
api.vrf_id = VRF_DEFAULT;
api.nh_vrf_id = VRF_DEFAULT;
api.type = ZEBRA_ROUTE_ISIS;
api.safi = SAFI_UNICAST;
api.prefix = *prefix;
Expand Down Expand Up @@ -329,6 +330,7 @@ static void isis_zebra_route_del_route(struct prefix *prefix,

memset(&api, 0, sizeof(api));
api.vrf_id = VRF_DEFAULT;
api.nh_vrf_id = VRF_DEFAULT;
api.type = ZEBRA_ROUTE_ISIS;
api.safi = SAFI_UNICAST;
api.prefix = *prefix;
Expand Down
12 changes: 12 additions & 0 deletions lib/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ struct interface *if_lookup_by_index(ifindex_t ifindex, vrf_id_t vrf_id)
struct vrf *vrf;
struct interface if_tmp;

if (vrf_id == VRF_UNKNOWN) {
struct interface *ifp;

RB_FOREACH(vrf, vrf_id_head, &vrfs_by_id) {
ifp = if_lookup_by_index(ifindex, vrf->vrf_id);
if (ifp)
return ifp;
}

return NULL;
}

vrf = vrf_lookup_by_id(vrf_id);
if (!vrf)
return NULL;
Expand Down
7 changes: 7 additions & 0 deletions lib/if.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,13 @@ struct nbr_connected {
/* Prototypes. */
extern int if_cmp_name_func(char *, char *);

/*
* Passing in VRF_UNKNOWN is a valid thing to do, unless we
* are creating a new interface.
*
* This is useful for vrf route-leaking. So more than anything
* else think before you use VRF_UNKNOWN
*/
extern void if_update_to_new_vrf(struct interface *, vrf_id_t vrf_id);
extern struct interface *if_create(const char *name, vrf_id_t vrf_id);
extern struct interface *if_lookup_by_index(ifindex_t, vrf_id_t vrf_id);
Expand Down
5 changes: 5 additions & 0 deletions lib/zclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,8 @@ int zapi_route_encode(u_char cmd, struct stream *s, struct zapi_route *api)
}

stream_putw(s, api->nexthop_num);
if (api->nexthop_num)
stream_putw(s, api->nh_vrf_id);

for (i = 0; i < api->nexthop_num; i++) {
api_nh = &api->nexthops[i];
Expand Down Expand Up @@ -1091,6 +1093,9 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api)
return -1;
}

if (api->nexthop_num)
STREAM_GETW(s, api->nh_vrf_id);

for (i = 0; i < api->nexthop_num; i++) {
api_nh = &api->nexthops[i];

Expand Down
6 changes: 6 additions & 0 deletions lib/zclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ struct zapi_route {
u_int32_t mtu;

vrf_id_t vrf_id;
vrf_id_t nh_vrf_id;

struct ethaddr rmac;
};
Expand Down Expand Up @@ -420,6 +421,11 @@ extern struct interface *zebra_interface_vrf_update_read(struct stream *s,
vrf_id_t *new_vrf_id);
extern void zebra_interface_if_set_value(struct stream *, struct interface *);
extern void zebra_router_id_update_read(struct stream *s, struct prefix *rid);

#if CONFDATE > 20180823
CPP_NOTICE("zapi_ipv4_route, zapi_ipv6_route, zapi_ipv4_route_ipv6_nexthop as well as the zapi_ipv4 and zapi_ipv6 data structures should be removed now");
#endif

extern int zapi_ipv4_route(u_char, struct zclient *, struct prefix_ipv4 *,
struct zapi_ipv4 *) __attribute__((deprecated));

Expand Down
2 changes: 2 additions & 0 deletions nhrpd/nhrp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ void nhrp_route_announce(int add, enum nhrp_cache_type type, const struct prefix
memset(&api, 0, sizeof(api));
api.type = ZEBRA_ROUTE_NHRP;
api.safi = SAFI_UNICAST;
api.vrf_id = VRF_DEFAULT;
api.nh_vrf_id = VRF_DEFAULT;
api.prefix = *p;

switch (type) {
Expand Down
3 changes: 3 additions & 0 deletions ospf6d/ospf6_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ static void ospf6_zebra_route_update(int type, struct ospf6_route *request)

memset(&api, 0, sizeof(api));
api.vrf_id = VRF_DEFAULT;
api.nh_vrf_id = VRF_DEFAULT;
api.type = ZEBRA_ROUTE_OSPF6;
api.safi = SAFI_UNICAST;
api.prefix = *dest;
Expand Down Expand Up @@ -387,6 +388,7 @@ void ospf6_zebra_add_discard(struct ospf6_route *request)
if (!CHECK_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) {
memset(&api, 0, sizeof(api));
api.vrf_id = VRF_DEFAULT;
api.nh_vrf_id = VRF_DEFAULT;
api.type = ZEBRA_ROUTE_OSPF6;
api.safi = SAFI_UNICAST;
api.prefix = *dest;
Expand Down Expand Up @@ -420,6 +422,7 @@ void ospf6_zebra_delete_discard(struct ospf6_route *request)
if (CHECK_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) {
memset(&api, 0, sizeof(api));
api.vrf_id = VRF_DEFAULT;
api.nh_vrf_id = VRF_DEFAULT;
api.type = ZEBRA_ROUTE_OSPF6;
api.safi = SAFI_UNICAST;
api.prefix = *dest;
Expand Down
4 changes: 4 additions & 0 deletions ospfd/ospf_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ void ospf_zebra_add(struct ospf *ospf, struct prefix_ipv4 *p,

memset(&api, 0, sizeof(api));
api.vrf_id = ospf->vrf_id;
api.nh_vrf_id = ospf->vrf_id;
api.type = ZEBRA_ROUTE_OSPF;
api.instance = ospf->instance;
api.safi = SAFI_UNICAST;
Expand Down Expand Up @@ -466,6 +467,7 @@ void ospf_zebra_delete(struct ospf *ospf, struct prefix_ipv4 *p,

memset(&api, 0, sizeof(api));
api.vrf_id = ospf->vrf_id;
api.nh_vrf_id = ospf->vrf_id;
api.type = ZEBRA_ROUTE_OSPF;
api.instance = ospf->instance;
api.safi = SAFI_UNICAST;
Expand All @@ -487,6 +489,7 @@ void ospf_zebra_add_discard(struct ospf *ospf, struct prefix_ipv4 *p)

memset(&api, 0, sizeof(api));
api.vrf_id = ospf->vrf_id;
api.nh_vrf_id = ospf->vrf_id;
api.type = ZEBRA_ROUTE_OSPF;
api.instance = ospf->instance;
api.safi = SAFI_UNICAST;
Expand All @@ -506,6 +509,7 @@ void ospf_zebra_delete_discard(struct ospf *ospf, struct prefix_ipv4 *p)

memset(&api, 0, sizeof(api));
api.vrf_id = ospf->vrf_id;
api.nh_vrf_id = ospf->vrf_id;
api.type = ZEBRA_ROUTE_OSPF;
api.instance = ospf->instance;
api.safi = SAFI_UNICAST;
Expand Down
1 change: 1 addition & 0 deletions ripd/rip_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static void rip_zebra_ipv4_send(struct route_node *rp, u_char cmd)

memset(&api, 0, sizeof(api));
api.vrf_id = VRF_DEFAULT;
api.nh_vrf_id = VRF_DEFAULT;
api.type = ZEBRA_ROUTE_RIP;
api.safi = SAFI_UNICAST;

Expand Down
1 change: 1 addition & 0 deletions ripngd/ripng_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static void ripng_zebra_ipv6_send(struct route_node *rp, u_char cmd)

memset(&api, 0, sizeof(api));
api.vrf_id = VRF_DEFAULT;
api.nh_vrf_id = VRF_DEFAULT;
api.type = ZEBRA_ROUTE_RIPNG;
api.safi = SAFI_UNICAST;
api.prefix = rp->p;
Expand Down
2 changes: 2 additions & 0 deletions sharpd/sharp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void route_add(struct prefix *p, struct nexthop *nh)

memset(&api, 0, sizeof(api));
api.vrf_id = VRF_DEFAULT;
api.nh_vrf_id = VRF_DEFAULT;
api.type = ZEBRA_ROUTE_SHARP;
api.safi = SAFI_UNICAST;
memcpy(&api.prefix, p, sizeof(*p));
Expand All @@ -180,6 +181,7 @@ void route_delete(struct prefix *p)

memset(&api, 0, sizeof(api));
api.vrf_id = VRF_DEFAULT;
api.nh_vrf_id = VRF_DEFAULT;
api.type = ZEBRA_ROUTE_SHARP;
api.safi = SAFI_UNICAST;
memcpy(&api.prefix, p, sizeof(*p));
Expand Down
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
17 changes: 7 additions & 10 deletions zebra/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ int main(int argc, char **argv)
zebra_if_init();
zebra_debug_init();
router_id_cmd_init();

/*
* Initialize NS( and implicitly the VRF module), and make kernel
* routing socket. */
zebra_ns_init();

zebra_vty_init();
access_list_init();
prefix_list_init();
#if defined(HAVE_RTADV)
Expand All @@ -317,16 +324,6 @@ int main(int argc, char **argv)
/* For debug purpose. */
/* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */

/* Initialize NS( and implicitly the VRF module), and make kernel
* routing socket. */
zebra_ns_init();

/*
* Initialize show/config command after the vrf initialization is
* complete
*/
zebra_vty_init();

#if defined(HANDLE_ZAPI_FUZZING)
if (fuzzing) {
zserv_read_file(fuzzing);
Expand Down
7 changes: 5 additions & 2 deletions zebra/rib.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct route_entry {

/* VRF identifier. */
vrf_id_t vrf_id;
vrf_id_t nh_vrf_id;

/* Which routing table */
uint32_t table;
Expand Down Expand Up @@ -293,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 Expand Up @@ -439,6 +440,8 @@ DECLARE_HOOK(rib_update, (struct route_node * rn, const char *reason),


extern void zebra_vty_init(void);
extern int static_config(struct vty *vty, struct zebra_vrf *zvrf,
afi_t afi, safi_t safi, const char *cmd);
extern pid_t pid;

#endif /*_ZEBRA_RIB_H */
Loading

0 comments on commit d6fed38

Please sign in to comment.