From d5b2119cb418c47a70eb931a4ccdb6e6f078619f Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 8 Jan 2018 11:17:02 -0500 Subject: *: Send/receive the nexthop vrf_id Modify the code to send and receive to/from zebra the nexthops vrf_id. Signed-off-by: Donald Sharp --- lib/zclient.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/zclient.c') diff --git a/lib/zclient.c b/lib/zclient.c index 4177ce1a71..8f9536f5a2 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -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]; @@ -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]; -- cgit v1.2.3 From a9ff90c41b0a95195d19d451ee83eb460e1599d0 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Thu, 14 Dec 2017 16:01:36 +0100 Subject: lib: increase vrf_id from 16 bit to 32 bit identifier This is a preparatory work for configuring vrf/frr over netns vrf structure is being changed to 32 bit, and the VRF will have the possibility to have a backend made up of NETNS. Let's put some history. Initially the 32 bit was because one wanted to map on vrf_id both the VRFLITE and the NSID. Initially, one would have liked to make zebra configure at the same time both vrf lite and vrf from netns in a flat way. From the show running perspective, one would have had both kind of vrfs, thatone would configure on the same way. however, it leads to inconsistencies in concepts, because it mixes vrf vrf with vrf, and vrf is not always mapped with netns. For instance, logical-router could also be used with netns. In that case, it would not be possible to map vrf with netns. There was an other reason why 32 bit is proposed. this is because some systems handle NSID to 32 bits. As vrf lite exists only on Linux, there are other systems that would like to use an other vrf backend than vrf lite. The netns backend for vrf will be used for that too. for instance, for windows or freebsd, some similar netns concept exists; so it will be easier to reuse netns backend for vrf, than reusing vrflite backend for vrf. This commit is here to extend vrf_id to 32 bits. Following commits in a second step will help in enable a VRF backend. Signed-off-by: Philippe Guibert --- lib/vrf.c | 6 +++--- lib/vrf.h | 3 +-- lib/zclient.c | 12 ++++++------ lib/zclient.h | 4 ++-- lib/zebra.h | 2 +- zebra/zebra_ptm.c | 2 +- zebra/zserv.c | 10 +++++----- 7 files changed, 19 insertions(+), 20 deletions(-) (limited to 'lib/zclient.c') diff --git a/lib/vrf.c b/lib/vrf.c index 3c34b95262..b4ed24cbff 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -94,7 +94,7 @@ struct vrf *vrf_get(vrf_id_t vrf_id, const char *name) int new = 0; if (debug_vrf) - zlog_debug("VRF_GET: %s(%d)", name, vrf_id); + zlog_debug("VRF_GET: %s(%u)", name, vrf_id); /* Nothing to see, move along here */ if (!name && vrf_id == VRF_UNKNOWN) @@ -268,7 +268,7 @@ void *vrf_info_lookup(vrf_id_t vrf_id) */ #define VRF_BITMAP_NUM_OF_GROUPS 8 -#define VRF_BITMAP_NUM_OF_BITS_IN_GROUP (UINT16_MAX / VRF_BITMAP_NUM_OF_GROUPS) +#define VRF_BITMAP_NUM_OF_BITS_IN_GROUP (UINT32_MAX / VRF_BITMAP_NUM_OF_GROUPS) #define VRF_BITMAP_NUM_OF_BYTES_IN_GROUP \ (VRF_BITMAP_NUM_OF_BITS_IN_GROUP / CHAR_BIT + 1) /* +1 for ensure */ @@ -355,7 +355,7 @@ static void vrf_autocomplete(vector comps, struct cmd_token *token) struct vrf *vrf = NULL; RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (vrf->vrf_id != 0) + if (vrf->vrf_id != VRF_DEFAULT) vector_set(comps, XSTRDUP(MTYPE_COMPLETION, vrf->name)); } } diff --git a/lib/vrf.h b/lib/vrf.h index 9afca4c6fb..7e625769e7 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -32,8 +32,7 @@ /* The default VRF ID */ #define VRF_DEFAULT 0 -#define VRF_UNKNOWN UINT16_MAX -#define VRF_ALL UINT16_MAX - 1 +#define VRF_UNKNOWN UINT32_MAX /* Pending: May need to refine this. */ #ifndef IFLA_VRF_MAX diff --git a/lib/zclient.c b/lib/zclient.c index 4177ce1a71..d4a7b45b97 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -291,7 +291,7 @@ void zclient_create_header(struct stream *s, uint16_t command, vrf_id_t vrf_id) stream_putw(s, ZEBRA_HEADER_SIZE); stream_putc(s, ZEBRA_HEADER_MARKER); stream_putc(s, ZSERV_VERSION); - stream_putw(s, vrf_id); + stream_putl(s, vrf_id); stream_putw(s, command); } @@ -306,7 +306,7 @@ int zclient_read_header(struct stream *s, int sock, u_int16_t *size, *size -= ZEBRA_HEADER_SIZE; STREAM_GETC(s, *marker); STREAM_GETC(s, *version); - STREAM_GETW(s, *vrf_id); + STREAM_GETL(s, *vrf_id); STREAM_GETW(s, *cmd); if (*version != ZSERV_VERSION || *marker != ZEBRA_HEADER_MARKER) { @@ -1677,7 +1677,7 @@ struct interface *zebra_interface_vrf_update_read(struct stream *s, { unsigned int ifindex; struct interface *ifp; - vrf_id_t new_id = VRF_DEFAULT; + vrf_id_t new_id; /* Get interface index. */ ifindex = stream_getl(s); @@ -2043,7 +2043,7 @@ static int zclient_read(struct thread *thread) length = stream_getw(zclient->ibuf); marker = stream_getc(zclient->ibuf); version = stream_getc(zclient->ibuf); - vrf_id = stream_getw(zclient->ibuf); + vrf_id = stream_getl(zclient->ibuf); command = stream_getw(zclient->ibuf); if (marker != ZEBRA_HEADER_MARKER || version != ZSERV_VERSION) { @@ -2346,9 +2346,9 @@ void zclient_interface_set_master(struct zclient *client, zclient_create_header(s, ZEBRA_INTERFACE_SET_MASTER, master->vrf_id); - stream_putw(s, master->vrf_id); + stream_putl(s, master->vrf_id); stream_putl(s, master->ifindex); - stream_putw(s, slave->vrf_id); + stream_putl(s, slave->vrf_id); stream_putl(s, slave->ifindex); stream_putw_at(s, 0, stream_get_endp(s)); diff --git a/lib/zclient.h b/lib/zclient.h index cc34fd9d2c..00ad692718 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -40,7 +40,7 @@ #define ZEBRA_MAX_PACKET_SIZ 4096 /* Zebra header size. */ -#define ZEBRA_HEADER_SIZE 8 +#define ZEBRA_HEADER_SIZE 10 /* special socket path name to use TCP * @ is used as first character because that's abstract socket names on Linux @@ -227,7 +227,7 @@ struct zserv_header { * always set to 255 in new zserv. */ uint8_t version; -#define ZSERV_VERSION 4 +#define ZSERV_VERSION 5 vrf_id_t vrf_id; uint16_t command; }; diff --git a/lib/zebra.h b/lib/zebra.h index 1eb0c56252..b9a795d160 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -486,7 +486,7 @@ typedef u_int16_t zebra_size_t; typedef u_int16_t zebra_command_t; /* VRF ID type. */ -typedef u_int16_t vrf_id_t; +typedef uint32_t vrf_id_t; typedef uint32_t route_tag_t; #define ROUTE_TAG_MAX UINT32_MAX diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index 769d2f5666..953f74ecec 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -432,7 +432,7 @@ static void if_bfd_session_update(struct interface *ifp, struct prefix *dp, } else { zlog_debug( "MESSAGE: ZEBRA_INTERFACE_BFD_DEST_UPDATE %s/%d " - "with src %s/%d and vrf %d %s event", + "with src %s/%d and vrf %u %s event", inet_ntop(dp->family, &dp->u.prefix, buf[0], INET6_ADDRSTRLEN), dp->prefixlen, diff --git a/zebra/zserv.c b/zebra/zserv.c index 7eded89f6d..6241a16389 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -155,7 +155,7 @@ void zserv_create_header(struct stream *s, uint16_t cmd, vrf_id_t vrf_id) stream_putw(s, ZEBRA_HEADER_SIZE); stream_putc(s, ZEBRA_HEADER_MARKER); stream_putc(s, ZSERV_VERSION); - stream_putw(s, vrf_id); + stream_putl(s, vrf_id); stream_putw(s, cmd); } @@ -508,7 +508,7 @@ int zsend_interface_vrf_update(struct zserv *client, struct interface *ifp, /* Fill in the ifIndex of the interface and its new VRF (id) */ stream_putl(s, ifp->ifindex); - stream_putw(s, vrf_id); + stream_putl(s, vrf_id); /* Write packet size. */ stream_putw_at(s, 0, stream_get_endp(s)); @@ -2472,11 +2472,11 @@ static int zread_interface_set_master(struct zserv *client, int ifindex; vrf_id_t vrf_id; - STREAM_GETW(s, vrf_id); + STREAM_GETL(s, vrf_id); STREAM_GETL(s, ifindex); master = if_lookup_by_index(ifindex, vrf_id); - STREAM_GETW(s, vrf_id); + STREAM_GETL(s, vrf_id); STREAM_GETL(s, ifindex); slave = if_lookup_by_index(ifindex, vrf_id); @@ -2714,7 +2714,7 @@ static int zebra_client_read(struct thread *thread) STREAM_GETW(client->ibuf, length); STREAM_GETC(client->ibuf, marker); STREAM_GETC(client->ibuf, version); - STREAM_GETW(client->ibuf, vrf_id); + STREAM_GETL(client->ibuf, vrf_id); STREAM_GETW(client->ibuf, command); if (marker != ZEBRA_HEADER_MARKER || version != ZSERV_VERSION) { -- cgit v1.2.3 From 0d9e7f455e0c5cb4bfac9d0b955adcc529d56431 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 22 Jan 2018 18:16:59 -0500 Subject: lib: Cleanup some zclient clutter. The zclient code can be cleaned up a tiny bit and hopefully improve it's indentation some. Signed-off-by: Donald Sharp --- lib/zclient.c | 82 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 38 deletions(-) (limited to 'lib/zclient.c') diff --git a/lib/zclient.c b/lib/zclient.c index d4a7b45b97..b5372a32ee 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -389,25 +389,28 @@ void zclient_send_reg_requests(struct zclient *zclient, vrf_id_t vrf_id) vrf_id); /* Flush all redistribute request. */ - if (vrf_id == VRF_DEFAULT) - for (afi = AFI_IP; afi < AFI_MAX; afi++) - for (i = 0; i < ZEBRA_ROUTE_MAX; i++) - if (zclient->mi_redist[afi][i].enabled) { - struct listnode *node; - u_short *id; - - for (ALL_LIST_ELEMENTS_RO( - zclient->mi_redist[afi][i] - .instances, - node, id)) - if (!(i == zclient->redist_default - && *id == zclient->instance)) - zebra_redistribute_send( - ZEBRA_REDISTRIBUTE_ADD, - zclient, afi, i, - *id, - VRF_DEFAULT); - } + if (vrf_id == VRF_DEFAULT) { + for (afi = AFI_IP; afi < AFI_MAX; afi++) { + for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { + if (!zclient->mi_redist[afi][i].enabled) + continue; + + struct listnode *node; + u_short *id; + + for (ALL_LIST_ELEMENTS_RO( + zclient->mi_redist[afi][i] + .instances, node, id)) + if (!(i == zclient->redist_default + && *id == zclient->instance)) + zebra_redistribute_send( + ZEBRA_REDISTRIBUTE_ADD, + zclient, afi, i, + *id, + VRF_DEFAULT); + } + } + } /* Flush all redistribute request. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) @@ -451,25 +454,28 @@ void zclient_send_dereg_requests(struct zclient *zclient, vrf_id_t vrf_id) vrf_id); /* Flush all redistribute request. */ - if (vrf_id == VRF_DEFAULT) - for (afi = AFI_IP; afi < AFI_MAX; afi++) - for (i = 0; i < ZEBRA_ROUTE_MAX; i++) - if (zclient->mi_redist[afi][i].enabled) { - struct listnode *node; - u_short *id; - - for (ALL_LIST_ELEMENTS_RO( - zclient->mi_redist[afi][i] - .instances, - node, id)) - if (!(i == zclient->redist_default - && *id == zclient->instance)) - zebra_redistribute_send( - ZEBRA_REDISTRIBUTE_DELETE, - zclient, afi, i, - *id, - VRF_DEFAULT); - } + if (vrf_id == VRF_DEFAULT) { + for (afi = AFI_IP; afi < AFI_MAX; afi++) { + for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { + if (!zclient->mi_redist[afi][i].enabled) + continue; + + struct listnode *node; + u_short *id; + + for (ALL_LIST_ELEMENTS_RO( + zclient->mi_redist[afi][i] + .instances, node, id)) + if (!(i == zclient->redist_default + && *id == zclient->instance)) + zebra_redistribute_send( + ZEBRA_REDISTRIBUTE_DELETE, + zclient, afi, i, + *id, + VRF_DEFAULT); + } + } + } /* Flush all redistribute request. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) -- cgit v1.2.3 From 09eef679fb19ef0a731f4a72009eed071847da19 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 22 Jan 2018 18:18:38 -0500 Subject: lib: Unset bitmap when not using it The zclient->redist bitmap for vrf's was being set again for the zclient_send_dereg_requests function. This should be a unset on tear down. Signed-off-by: Donald Sharp --- lib/zclient.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/zclient.c') diff --git a/lib/zclient.c b/lib/zclient.c index b5372a32ee..9045b5b6ce 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -450,8 +450,8 @@ void zclient_send_dereg_requests(struct zclient *zclient, vrf_id_t vrf_id) /* Set unwanted redistribute route. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) - vrf_bitmap_set(zclient->redist[afi][zclient->redist_default], - vrf_id); + vrf_bitmap_unset(zclient->redist[afi][zclient->redist_default], + vrf_id); /* Flush all redistribute request. */ if (vrf_id == VRF_DEFAULT) { -- cgit v1.2.3 From 3c1925406846d0e2d981086ea4d3c9fb09dc8b4a Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 22 Jan 2018 18:36:03 -0500 Subject: bgpd, lib, pimd: Abstract commands for nexthop tracking Abstract the code that sends the zapi message into zebra for the turn on/off of nexthop tracking for a prefix. Signed-off-by: Donald Sharp --- bgpd/bgp_nht.c | 29 +++++------------------------ lib/zclient.c | 27 +++++++++++++++++++++++++++ lib/zclient.h | 3 +++ pimd/pim_nht.c | 28 +--------------------------- 4 files changed, 36 insertions(+), 51 deletions(-) (limited to 'lib/zclient.c') diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index 247884d294..a963838f5f 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -572,12 +572,11 @@ static int make_prefix(int afi, struct bgp_info *ri, struct prefix *p) */ static void sendmsg_zebra_rnh(struct bgp_nexthop_cache *bnc, int command) { - struct stream *s; struct prefix *p; + bool exact_match = false; int ret; - /* Check socket. */ - if (!zclient || zclient->sock < 0) + if (!zclient) return; /* Don't try to register if Zebra doesn't know of this instance. */ @@ -585,32 +584,14 @@ static void sendmsg_zebra_rnh(struct bgp_nexthop_cache *bnc, int command) return; p = &(bnc->node->p); - s = zclient->obuf; - stream_reset(s); - zclient_create_header(s, command, bnc->bgp->vrf_id); if ((command == ZEBRA_NEXTHOP_REGISTER || command == ZEBRA_IMPORT_ROUTE_REGISTER) && (CHECK_FLAG(bnc->flags, BGP_NEXTHOP_CONNECTED) || CHECK_FLAG(bnc->flags, BGP_STATIC_ROUTE_EXACT_MATCH))) - stream_putc(s, 1); - else - stream_putc(s, 0); - - stream_putw(s, PREFIX_FAMILY(p)); - stream_putc(s, p->prefixlen); - switch (PREFIX_FAMILY(p)) { - case AF_INET: - stream_put_in_addr(s, &p->u.prefix4); - break; - case AF_INET6: - stream_put(s, &(p->u.prefix6), 16); - break; - default: - break; - } - stream_putw_at(s, 0, stream_get_endp(s)); + exact_match = true; - ret = zclient_send_message(zclient); + ret = zclient_send_rnh(zclient, command, p, + exact_match, bnc->bgp->vrf_id); /* TBD: handle the failure */ if (ret < 0) zlog_warn("sendmsg_nexthop: zclient_send_message() failed"); diff --git a/lib/zclient.c b/lib/zclient.c index 9045b5b6ce..9d863a3b26 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -614,6 +614,33 @@ static int zclient_connect(struct thread *t) return zclient_start(zclient); } +int zclient_send_rnh(struct zclient *zclient, int command, struct prefix *p, + bool exact_match, vrf_id_t vrf_id) +{ + struct stream *s; + + s = zclient->obuf; + stream_reset(s); + zclient_create_header(s, command, vrf_id); + stream_putc(s, (exact_match) ? 1 : 0); + + stream_putw(s, PREFIX_FAMILY(p)); + stream_putc(s, p->prefixlen); + switch (PREFIX_FAMILY(p)) { + case AF_INET: + stream_put_in_addr(s, &p->u.prefix4); + break; + case AF_INET6: + stream_put(s, &(p->u.prefix6), 16); + break; + default: + break; + } + stream_putw_at(s, 0, stream_get_endp(s)); + + return zclient_send_message(zclient); +} + /* * "xdr_encode"-like interface that allows daemon (client) to send * a message to zebra server for a route that needs to be diff --git a/lib/zclient.h b/lib/zclient.h index 00ad692718..847c2904d0 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -478,6 +478,9 @@ extern int zapi_ipv4_route_ipv6_nexthop(u_char, struct zclient *, struct zapi_ipv6 *) __attribute__((deprecated)); extern int zclient_route_send(u_char, struct zclient *, struct zapi_route *); +extern int zclient_send_rnh(struct zclient *zclient, int command, + struct prefix *p, bool exact_match, + vrf_id_t vrf_id); extern int zapi_route_encode(u_char, struct stream *, struct zapi_route *); extern int zapi_route_decode(struct stream *, struct zapi_route *); bool zapi_route_notify_decode(struct stream *s, struct prefix *p, diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index 089639c77e..ccef796724 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -47,40 +47,14 @@ void pim_sendmsg_zebra_rnh(struct pim_instance *pim, struct zclient *zclient, struct pim_nexthop_cache *pnc, int command) { - struct stream *s; struct prefix *p; int ret; - /* Check socket. */ - if (!zclient || zclient->sock < 0) - return; - p = &(pnc->rpf.rpf_addr); - s = zclient->obuf; - stream_reset(s); - zclient_create_header(s, command, pim->vrf_id); - /* get update for all routes for a prefix */ - stream_putc(s, 0); - - stream_putw(s, PREFIX_FAMILY(p)); - stream_putc(s, p->prefixlen); - switch (PREFIX_FAMILY(p)) { - case AF_INET: - stream_put_in_addr(s, &p->u.prefix4); - break; - case AF_INET6: - stream_put(s, &(p->u.prefix6), 16); - break; - default: - break; - } - stream_putw_at(s, 0, stream_get_endp(s)); - - ret = zclient_send_message(zclient); + ret = zclient_send_rnh(zclient, command, p, false, pim->vrf_id); if (ret < 0) zlog_warn("sendmsg_nexthop: zclient_send_message() failed"); - if (PIM_DEBUG_PIM_NHT) { char buf[PREFIX2STR_BUFFER]; prefix2str(p, buf, sizeof(buf)); -- cgit v1.2.3