zebra: collect gre information and push it when needed

- gre keys are collected and stored locally.
- when gre source set is requested, and the link interface
configured is different, the gre information collected is
pushed in the query, namely source ip or gre keys if present.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
This commit is contained in:
Philippe Guibert 2021-03-12 14:32:53 +01:00
parent db51f0cd10
commit e3d3fa06f7
4 changed files with 48 additions and 5 deletions

View File

@ -73,6 +73,7 @@
#include "zebra/zebra_errors.h"
#include "zebra/zebra_vxlan.h"
#include "zebra/zebra_evpn_mh.h"
#include "zebra/zebra_l2.h"
extern struct zebra_privs_t zserv_privs;
@ -475,6 +476,7 @@ netlink_gre_set_msg_encoder(struct zebra_dplane_ctx *ctx, void *buf,
uint32_t link_idx;
unsigned int mtu;
struct rtattr *rta_info, *rta_data;
const struct zebra_l2info_gre *gre_info;
if (buflen < sizeof(*req))
return 0;
@ -485,6 +487,11 @@ netlink_gre_set_msg_encoder(struct zebra_dplane_ctx *ctx, void *buf,
req->n.nlmsg_flags = NLM_F_REQUEST;
req->ifi.ifi_index = dplane_ctx_get_ifindex(ctx);
gre_info = dplane_ctx_gre_get_info(ctx);
if (!gre_info)
return 0;
req->ifi.ifi_change = 0xFFFFFFFF;
link_idx = dplane_ctx_gre_get_link_ifindex(ctx);
mtu = dplane_ctx_gre_get_mtu(ctx);
@ -495,13 +502,36 @@ netlink_gre_set_msg_encoder(struct zebra_dplane_ctx *ctx, void *buf,
rta_info = nl_attr_nest(&req->n, buflen, IFLA_LINKINFO);
if (!rta_info)
return 0;
if (!nl_attr_put(&req->n, buflen, IFLA_INFO_KIND, "gre", 3))
return 0;
rta_data = nl_attr_nest(&req->n, buflen, IFLA_INFO_DATA);
if (!rta_info)
if (!rta_data)
return 0;
if (!nl_attr_put32(&req->n, buflen, IFLA_GRE_LINK, link_idx))
return 0;
if (gre_info->vtep_ip.s_addr &&
!nl_attr_put32(&req->n, buflen, IFLA_GRE_LOCAL,
gre_info->vtep_ip.s_addr))
return 0;
if (gre_info->vtep_ip_remote.s_addr &&
!nl_attr_put32(&req->n, buflen, IFLA_GRE_REMOTE,
gre_info->vtep_ip_remote.s_addr))
return 0;
if (gre_info->ikey &&
!nl_attr_put32(&req->n, buflen, IFLA_GRE_IKEY,
gre_info->ikey))
return 0;
if (gre_info->okey &&
!nl_attr_put32(&req->n, buflen, IFLA_GRE_IKEY,
gre_info->okey))
return 0;
nl_attr_nest_end(&req->n, rta_data);
nl_attr_nest_end(&req->n, rta_info);

View File

@ -3473,7 +3473,7 @@ static inline void zebra_gre_source_set(ZAPI_HANDLER_ARGS)
if (gre_zif->link && gre_zif->link == ifp_link && mtu == ifp->mtu)
return;
dplane_gre_set(ifp, ifp_link, mtu);
dplane_gre_set(ifp, ifp_link, mtu, gre_info);
stream_failure:
return;

View File

@ -274,6 +274,7 @@ struct dplane_rule_info {
struct dplane_gre_ctx {
uint32_t link_ifindex;
unsigned int mtu;
struct zebra_l2info_gre info;
};
/*
* The context block used to exchange info about route updates across
@ -1804,6 +1805,14 @@ dplane_ctx_gre_get_mtu(const struct zebra_dplane_ctx *ctx)
return ctx->u.gre.mtu;
}
const struct zebra_l2info_gre *
dplane_ctx_gre_get_info(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return &ctx->u.gre.info;
}
/* Accessors for PBR rule information */
int dplane_ctx_rule_get_sock(const struct zebra_dplane_ctx *ctx)
{
@ -4161,7 +4170,8 @@ dplane_pbr_ipset_entry_delete(struct zebra_pbr_ipset_entry *ipset)
* Common helper api for GRE set
*/
enum zebra_dplane_result
dplane_gre_set(struct interface *ifp, struct interface *ifp_link, unsigned int mtu)
dplane_gre_set(struct interface *ifp, struct interface *ifp_link,
unsigned int mtu, const struct zebra_l2info_gre *gre_info)
{
enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE;
struct zebra_dplane_ctx *ctx;
@ -4195,7 +4205,8 @@ dplane_gre_set(struct interface *ifp, struct interface *ifp_link, unsigned int m
ctx->u.gre.link_ifindex = ifp_link->ifindex;
else
ctx->u.gre.link_ifindex = 0;
if (gre_info)
memcpy(&ctx->u.gre.info, gre_info, sizeof(ctx->u.gre.info));
ctx->u.gre.mtu = mtu;
ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS;

View File

@ -533,6 +533,8 @@ uint32_t
dplane_ctx_gre_get_link_ifindex(const struct zebra_dplane_ctx *ctx);
unsigned int
dplane_ctx_gre_get_mtu(const struct zebra_dplane_ctx *ctx);
const struct zebra_l2info_gre *
dplane_ctx_gre_get_info(const struct zebra_dplane_ctx *ctx);
/* Namespace info - esp. for netlink communication */
const struct zebra_dplane_info *dplane_ctx_get_ns(
@ -707,7 +709,7 @@ enum zebra_dplane_result dplane_neigh_table_update(const struct interface *ifp,
*/
enum zebra_dplane_result
dplane_gre_set(struct interface *ifp, struct interface *ifp_link,
unsigned int mtu);
unsigned int mtu, const struct zebra_l2info_gre *gre_info);
/* Forward ref of zebra_pbr_rule */
struct zebra_pbr_rule;