From ba1849ef8c8560cff44008e06c5668b8261b033e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 9 Feb 2018 18:38:02 -0500 Subject: [PATCH] lib, zebra: Allow zapi to send down the tableid Allow the calling daemon to pass down what table-id we want to use to install the route. Useful for PBR. The vrf id passed must be the VRF_DEFAULT else this value is ignored. Signed-off-by: Donald Sharp --- lib/zclient.c | 4 ++++ lib/zclient.h | 8 ++++++++ zebra/zserv.c | 5 ++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/zclient.c b/lib/zclient.c index f853824bb..3f2021a5b 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1058,6 +1058,8 @@ int zapi_route_encode(u_char cmd, struct stream *s, struct zapi_route *api) stream_putl(s, api->tag); if (CHECK_FLAG(api->message, ZAPI_MESSAGE_MTU)) stream_putl(s, api->mtu); + if (CHECK_FLAG(api->message, ZAPI_MESSAGE_TABLEID)) + stream_putl(s, api->tableid); /* Put length at the first point of the stream. */ stream_putw_at(s, 0, stream_get_endp(s)); @@ -1207,6 +1209,8 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) STREAM_GETL(s, api->tag); if (CHECK_FLAG(api->message, ZAPI_MESSAGE_MTU)) STREAM_GETL(s, api->mtu); + if (CHECK_FLAG(api->message, ZAPI_MESSAGE_TABLEID)) + STREAM_GETL(s, api->tableid); stream_failure: return 0; diff --git a/lib/zclient.h b/lib/zclient.h index 1848440db..39566b173 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -225,6 +225,12 @@ struct zclient { #define ZAPI_MESSAGE_MTU 0x10 #define ZAPI_MESSAGE_SRCPFX 0x20 #define ZAPI_MESSAGE_LABEL 0x40 +/* + * This should only be used by a DAEMON that needs to communicate + * the table being used is not in the VRF. You must pass the + * default vrf, else this will be ignored. + */ +#define ZAPI_MESSAGE_TABLEID 0x80 /* Zserv protocol message header */ struct zserv_header { @@ -289,6 +295,8 @@ struct zapi_route { vrf_id_t vrf_id; + uint32_t tableid; + struct ethaddr rmac; }; diff --git a/zebra/zserv.c b/zebra/zserv.c index 8275ee1a3..d245e0972 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -1164,7 +1164,10 @@ static int zread_route_add(struct zserv *client, u_short length, re->flags = api.flags; re->uptime = time(NULL); re->vrf_id = vrf_id; - re->table = zvrf->table_id; + if (api.tableid && vrf_id == VRF_DEFAULT) + re->table = api.tableid; + else + re->table = zvrf->table_id; if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP)) { for (i = 0; i < api.nexthop_num; i++) { -- 2.39.5