]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: collect gre information and push it when needed
authorPhilippe Guibert <philippe.guibert@6wind.com>
Fri, 12 Mar 2021 13:32:53 +0000 (14:32 +0100)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Fri, 30 Apr 2021 08:33:18 +0000 (10:33 +0200)
- 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>
zebra/if_netlink.c
zebra/zapi_msg.c
zebra/zebra_dplane.c
zebra/zebra_dplane.h

index 1886f7a54214fc1303916cfe71a0d6a134fb2d40..b1e0f21f68767af5df6821deafbd5b5b74c30fa2 100644 (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);
 
index 75e2f59b98626a13c5c218bae3065a1719777166..55f8edd2729b3e675d02a4e44643b9c8ccd009f4 100644 (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;
index b54973a9417f33884d746a8d16059fca21888a9d..a8df0c56ceb369405e4c20083dfbe8c8852be84b 100644 (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;
index 5405a7cb85760054ed8d2d9aa914e2308bc5dd1e..3a8536dda50b81e7e3114c676cd7181ee8f25bad 100644 (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;