]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: prepare dplane to deal with pbr rules
authorJakub Urbańczyk <xthaid@gmail.com>
Sun, 24 May 2020 16:44:36 +0000 (18:44 +0200)
committerJakub Urbańczyk <xthaid@gmail.com>
Wed, 10 Jun 2020 14:18:45 +0000 (16:18 +0200)
This commit is the first step to convert IP rule installation to
use dplane thread.
 * Add dataplane's internal representation of a pbr rule
 * Add dplane stats related to rules
 * Introduce a new type of dplane operation

Signed-off-by: Jakub Urbańczyk <xthaid@gmail.com>
zebra/zebra_dplane.c
zebra/zebra_dplane.h
zebra/zebra_nhg.c

index 568b3989249ac887f4c2550cdeee759092b47fbe..6c1bfaa98c4f58a73a5ce9b13ae0e5bd85abfcf2 100644 (file)
@@ -191,6 +191,36 @@ struct dplane_neigh_info {
        uint16_t state;
 };
 
+/*
+ * Policy based routing rule info for the dataplane
+ */
+struct dplane_ctx_rule {
+       uint32_t priority;
+
+       /* The route table pointed by this rule */
+       uint32_t table;
+
+       /* Filter criteria */
+       uint32_t filter_bm;
+       uint32_t fwmark;
+       struct prefix src_ip;
+       struct prefix dst_ip;
+};
+
+struct dplane_rule_info {
+       /*
+        * Originating zclient sock fd, so we can know who to send
+        * back to.
+        */
+       int sock;
+
+       int unique;
+       int seq;
+
+       struct dplane_ctx_rule new;
+       struct dplane_ctx_rule old;
+};
+
 /*
  * The context block used to exchange info about route updates across
  * the boundary between the zebra main context (and pthread) and the
@@ -238,6 +268,7 @@ struct zebra_dplane_ctx {
                struct dplane_intf_info intf;
                struct dplane_mac_info macinfo;
                struct dplane_neigh_info neigh;
+               struct dplane_rule_info rule;
        } u;
 
        /* Namespace info, used especially for netlink kernel communication */
@@ -361,6 +392,9 @@ static struct zebra_dplane_globals {
        _Atomic uint32_t dg_neighs_in;
        _Atomic uint32_t dg_neigh_errors;
 
+       _Atomic uint32_t dg_rules_in;
+       _Atomic uint32_t dg_rule_errors;
+
        _Atomic uint32_t dg_update_yields;
 
        /* Dataplane pthread */
@@ -564,6 +598,9 @@ static void dplane_ctx_free_internal(struct zebra_dplane_ctx *ctx)
        case DPLANE_OP_NEIGH_DELETE:
        case DPLANE_OP_VTEP_ADD:
        case DPLANE_OP_VTEP_DELETE:
+       case DPLANE_OP_RULE_ADD:
+       case DPLANE_OP_RULE_DELETE:
+       case DPLANE_OP_RULE_UPDATE:
        case DPLANE_OP_NONE:
                break;
        }
@@ -786,6 +823,16 @@ const char *dplane_op2str(enum dplane_op_e op)
        case DPLANE_OP_VTEP_DELETE:
                ret = "VTEP_DELETE";
                break;
+
+       case DPLANE_OP_RULE_ADD:
+               ret = "RULE_ADD";
+               break;
+       case DPLANE_OP_RULE_DELETE:
+               ret = "RULE_DELETE";
+               break;
+       case DPLANE_OP_RULE_UPDATE:
+               ret = "RULE_UPDATE";
+               break;
        }
 
        return ret;
@@ -1517,6 +1564,116 @@ uint16_t dplane_ctx_neigh_get_state(const struct zebra_dplane_ctx *ctx)
        return ctx->u.neigh.state;
 }
 
+/* Accessors for PBR rule information */
+int dplane_ctx_rule_get_sock(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.sock;
+}
+
+int dplane_ctx_rule_get_unique(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.unique;
+}
+
+int dplane_ctx_rule_get_seq(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.seq;
+}
+
+uint32_t dplane_ctx_rule_get_priority(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.new.priority;
+}
+
+uint32_t dplane_ctx_rule_get_old_priority(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.old.priority;
+}
+
+uint32_t dplane_ctx_rule_get_table(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.new.table;
+}
+
+uint32_t dplane_ctx_rule_get_old_table(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.old.table;
+}
+
+uint32_t dplane_ctx_rule_get_filter_bm(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.new.filter_bm;
+}
+
+uint32_t dplane_ctx_rule_get_old_filter_bm(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.old.filter_bm;
+}
+
+uint32_t dplane_ctx_rule_get_fwmark(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.new.fwmark;
+}
+
+uint32_t dplane_ctx_rule_get_old_fwmark(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return ctx->u.rule.old.fwmark;
+}
+
+const struct prefix *
+dplane_ctx_rule_get_src_ip(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return &(ctx->u.rule.new.src_ip);
+}
+
+const struct prefix *
+dplane_ctx_rule_get_old_src_ip(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return &(ctx->u.rule.old.src_ip);
+}
+
+const struct prefix *
+dplane_ctx_rule_get_dst_ip(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return &(ctx->u.rule.new.dst_ip);
+}
+
+const struct prefix *
+dplane_ctx_rule_get_old_dst_ip(const struct zebra_dplane_ctx *ctx)
+{
+       DPLANE_CTX_VALID(ctx);
+
+       return &(ctx->u.rule.old.dst_ip);
+}
+
 /*
  * End of dplane context accessors
  */
@@ -2909,6 +3066,13 @@ int dplane_show_helper(struct vty *vty, bool detailed)
        vty_out(vty, "EVPN neigh updates:       %"PRIu64"\n", incoming);
        vty_out(vty, "EVPN neigh errors:        %"PRIu64"\n", errs);
 
+       incoming = atomic_load_explicit(&zdplane_info.dg_rules_in,
+                                       memory_order_relaxed);
+       errs = atomic_load_explicit(&zdplane_info.dg_rule_errors,
+                                   memory_order_relaxed);
+       vty_out(vty, "Rule updates:             %" PRIu64 "\n", incoming);
+       vty_out(vty, "Rule errors:              %" PRIu64 "\n", errs);
+
        return CMD_SUCCESS;
 }
 
index 7f8049b767c2990736f74a2ab725264d941c92d4..164fce75bc02dbc2170cee95d392c3ffef5fa56e 100644 (file)
@@ -144,6 +144,11 @@ enum dplane_op_e {
        /* EVPN VTEP updates */
        DPLANE_OP_VTEP_ADD,
        DPLANE_OP_VTEP_DELETE,
+
+       /* Policy based routing rule update */
+       DPLANE_OP_RULE_ADD,
+       DPLANE_OP_RULE_DELETE,
+       DPLANE_OP_RULE_UPDATE,
 };
 
 /*
@@ -384,6 +389,27 @@ const struct ethaddr *dplane_ctx_neigh_get_mac(
 uint32_t dplane_ctx_neigh_get_flags(const struct zebra_dplane_ctx *ctx);
 uint16_t dplane_ctx_neigh_get_state(const struct zebra_dplane_ctx *ctx);
 
+/* Accessors for policy based routing rule information */
+int dplane_ctx_rule_get_sock(const struct zebra_dplane_ctx *ctx);
+int dplane_ctx_rule_get_unique(const struct zebra_dplane_ctx *ctx);
+int dplane_ctx_rule_get_seq(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_rule_get_priority(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_rule_get_old_priority(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_rule_get_table(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_rule_get_old_table(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_rule_get_filter_bm(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_rule_get_old_filter_bm(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_rule_get_fwmark(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_rule_get_old_fwmark(const struct zebra_dplane_ctx *ctx);
+const struct prefix *
+dplane_ctx_rule_get_src_ip(const struct zebra_dplane_ctx *ctx);
+const struct prefix *
+dplane_ctx_rule_get_old_src_ip(const struct zebra_dplane_ctx *ctx);
+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);
+
 /* Namespace info - esp. for netlink communication */
 const struct zebra_dplane_info *dplane_ctx_get_ns(
        const struct zebra_dplane_ctx *ctx);
index d07ceb652ccea216b3cd12c8b70dc4f2f6030077..8723bd8d3086c488f6e8b044ea8103789ea3ec9e 100644 (file)
@@ -2563,6 +2563,9 @@ void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx)
        case DPLANE_OP_NEIGH_DELETE:
        case DPLANE_OP_VTEP_ADD:
        case DPLANE_OP_VTEP_DELETE:
+       case DPLANE_OP_RULE_ADD:
+       case DPLANE_OP_RULE_DELETE:
+       case DPLANE_OP_RULE_UPDATE:
        case DPLANE_OP_NONE:
                break;
        }