#include "zebra/rt.h"
#include "zebra/debug.h"
#include "zebra/zebra_pbr.h"
+#include "zebra/zebra_neigh.h"
#include "printfrr.h"
/* Memory types */
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;
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 {
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);
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
*/
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;
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);
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;
+ }
+ }
}
/**
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;
}
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 *
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,