]> git.proxmox.com Git - mirror_frr.git/commitdiff
zebra: pass PBR expanded actions to the dataplane
authorAnuradha Karuppiah <anuradhak@nvidia.com>
Sat, 18 Dec 2021 18:47:27 +0000 (10:47 -0800)
committerDonald Sharp <sharpd@nvidia.com>
Mon, 27 Jun 2022 11:56:55 +0000 (07:56 -0400)
These attributes are needed for dpdk dataplane programming

Signed-off-by: Anuradha Karuppiah <anuradhak@nvidia.com>
zebra/zebra_dplane.c
zebra/zebra_dplane.h
zebra/zebra_pbr.h

index 3a3bac6c74db9cbaa36032dc08f5d766ee335780..424cea467309ec4b9561d37927280d9554b11040 100644 (file)
@@ -36,6 +36,7 @@
 #include "zebra/rt.h"
 #include "zebra/debug.h"
 #include "zebra/zebra_pbr.h"
+#include "zebra/zebra_neigh.h"
 #include "printfrr.h"
 
 /* Memory types */
@@ -265,6 +266,8 @@ struct dplane_ctx_rule {
        struct prefix src_ip;
        struct prefix dst_ip;
        uint8_t ip_proto;
+       uint16_t src_port;
+       uint16_t dst_port;
 
        uint8_t action_pcp;
        uint16_t action_vlan_id;
@@ -273,6 +276,10 @@ struct dplane_ctx_rule {
        uint32_t action_queue_id;
 
        char ifname[INTERFACE_NAMSIZ + 1];
+       struct ethaddr smac;
+       struct ethaddr dmac;
+       int out_ifindex;
+       intptr_t dp_flow_ptr;
 };
 
 struct dplane_rule_info {
@@ -2144,6 +2151,34 @@ uint8_t dplane_ctx_rule_get_old_ipproto(const struct zebra_dplane_ctx *ctx)
        return ctx->u.rule.old.ip_proto;
 }
 
+uint16_t dplane_ctx_rule_get_src_port(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.new.src_port;
+}
+
+uint16_t dplane_ctx_rule_get_old_src_port(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.old.src_port;
+}
+
+uint16_t dplane_ctx_rule_get_dst_port(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.new.dst_port;
+}
+
+uint16_t dplane_ctx_rule_get_old_dst_port(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.old.dst_port;
+}
+
 uint8_t dplane_ctx_rule_get_dsfield(const struct zebra_dplane_ctx *ctx)
 {
        DPLANE_CTX_VALID(ctx);
@@ -2258,6 +2293,51 @@ void dplane_ctx_get_pbr_ipset_entry(const struct zebra_dplane_ctx *ctx,
        memcpy(entry, &ctx->u.ipset_entry.entry, sizeof(struct zebra_pbr_ipset_entry));
 }
 
+const struct ethaddr *
+dplane_ctx_rule_get_smac(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return &(ctx->u.rule.new.smac);
+}
+
+const struct ethaddr *
+dplane_ctx_rule_get_dmac(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return &(ctx->u.rule.new.dmac);
+}
+
+int dplane_ctx_rule_get_out_ifindex(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.new.out_ifindex;
+}
+
+intptr_t dplane_ctx_rule_get_old_dp_flow_ptr(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.old.dp_flow_ptr;
+}
+
+intptr_t dplane_ctx_rule_get_dp_flow_ptr(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.new.dp_flow_ptr;
+}
+
+void dplane_ctx_rule_set_dp_flow_ptr(struct zebra_dplane_ctx *ctx,
+                                    intptr_t dp_flow_ptr)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       ctx->u.rule.new.dp_flow_ptr = dp_flow_ptr;
+}
+
 /*
  * End of dplane context accessors
  */
@@ -2976,6 +3056,8 @@ done:
 static void dplane_ctx_rule_init_single(struct dplane_ctx_rule *dplane_rule,
                                        struct zebra_pbr_rule *rule)
 {
+       struct zebra_neigh_ent *n;
+
        dplane_rule->priority = rule->rule.priority;
        dplane_rule->table = rule->rule.action.table;
 
@@ -2983,6 +3065,8 @@ static void dplane_ctx_rule_init_single(struct dplane_ctx_rule *dplane_rule,
        dplane_rule->fwmark = rule->rule.filter.fwmark;
        dplane_rule->dsfield = rule->rule.filter.dsfield;
        dplane_rule->ip_proto = rule->rule.filter.ip_proto;
+       dplane_rule->src_port = rule->rule.filter.src_port;
+       dplane_rule->dst_port = rule->rule.filter.dst_port;
        prefix_copy(&(dplane_rule->dst_ip), &rule->rule.filter.dst_ip);
        prefix_copy(&(dplane_rule->src_ip), &rule->rule.filter.src_ip);
 
@@ -2992,6 +3076,19 @@ static void dplane_ctx_rule_init_single(struct dplane_ctx_rule *dplane_rule,
        dplane_rule->action_queue_id = rule->rule.action.queue_id;
 
        strlcpy(dplane_rule->ifname, rule->ifname, INTERFACE_NAMSIZ);
+       dplane_rule->dp_flow_ptr = rule->action.dp_flow_ptr;
+       n = rule->action.neigh;
+       if (n && (n->flags & ZEBRA_NEIGH_ENT_ACTIVE)) {
+               struct interface *ifp = if_lookup_by_index_per_ns(
+                       zebra_ns_lookup(NS_DEFAULT), n->ifindex);
+               if (ifp) {
+                       dplane_rule->out_ifindex = n->ifindex;
+                       memcpy(&dplane_rule->dmac, &n->mac, ETH_ALEN);
+                       memcpy(&dplane_rule->smac, ifp->hw_addr, ETH_ALEN);
+               } else {
+                       dplane_rule->out_ifindex = 0;
+               }
+       }
 }
 
 /**
@@ -3031,8 +3128,13 @@ static int dplane_ctx_rule_init(struct zebra_dplane_ctx *ctx,
        ctx->u.rule.seq = new_rule->rule.seq;
 
        dplane_ctx_rule_init_single(&ctx->u.rule.new, new_rule);
-       if (op == DPLANE_OP_RULE_UPDATE)
+       if (op == DPLANE_OP_RULE_UPDATE) {
                dplane_ctx_rule_init_single(&ctx->u.rule.old, old_rule);
+               /* clear the dp_flow_ptr in the old_rule - it is about to be
+                * deleted
+                */
+               old_rule->action.dp_flow_ptr = (intptr_t)NULL;
+       }
 
        return AOK;
 }
index d147a3e21c62909cce4866e449004670a98efdfb..d940bd9568e38f3481fe43125f75cf29ee059e7b 100644 (file)
@@ -547,6 +547,10 @@ uint8_t dplane_ctx_rule_get_dsfield(const struct zebra_dplane_ctx *ctx);
 uint8_t dplane_ctx_rule_get_old_dsfield(const struct zebra_dplane_ctx *ctx);
 uint8_t dplane_ctx_rule_get_ipproto(const struct zebra_dplane_ctx *ctx);
 uint8_t dplane_ctx_rule_get_old_ipproto(const struct zebra_dplane_ctx *ctx);
+uint16_t dplane_ctx_rule_get_src_port(const struct zebra_dplane_ctx *ctx);
+uint16_t dplane_ctx_rule_get_old_src_port(const struct zebra_dplane_ctx *ctx);
+uint16_t dplane_ctx_rule_get_dst_port(const struct zebra_dplane_ctx *ctx);
+uint16_t dplane_ctx_rule_get_old_dst_port(const struct zebra_dplane_ctx *ctx);
 const struct prefix *
 dplane_ctx_rule_get_src_ip(const struct zebra_dplane_ctx *ctx);
 const struct prefix *
@@ -555,6 +559,16 @@ const struct prefix *
 dplane_ctx_rule_get_dst_ip(const struct zebra_dplane_ctx *ctx);
 const struct prefix *
 dplane_ctx_rule_get_old_dst_ip(const struct zebra_dplane_ctx *ctx);
+const struct ethaddr *
+dplane_ctx_rule_get_smac(const struct zebra_dplane_ctx *ctx);
+const struct ethaddr *
+dplane_ctx_rule_get_dmac(const struct zebra_dplane_ctx *ctx);
+int dplane_ctx_rule_get_out_ifindex(const struct zebra_dplane_ctx *ctx);
+intptr_t dplane_ctx_rule_get_dp_flow_ptr(const struct zebra_dplane_ctx *ctx);
+intptr_t
+dplane_ctx_rule_get_old_dp_flow_ptr(const struct zebra_dplane_ctx *ctx);
+void dplane_ctx_rule_set_dp_flow_ptr(struct zebra_dplane_ctx *ctx,
+                                    intptr_t dp_flow_ptr);
 /* Accessors for policy based routing iptable information */
 struct zebra_pbr_iptable;
 void dplane_ctx_get_pbr_iptable(const struct zebra_dplane_ctx *ctx,
index c83ece61739d0da322d1f933324c71e767563ac9..baa8755fa5320e65934916ab41ff5d1c43c0e712 100644 (file)
@@ -45,6 +45,9 @@ struct zebra_pbr_action {
        /* dest-interface */
        ifindex_t ifindex;
 
+       /* dataplane info */
+       intptr_t dp_flow_ptr;
+
        /* neigh */
        struct zebra_neigh_ent *neigh;
        /* zebra_pbr_rule is linked to neigh via neigh_listnode */