From ec89fc6ff8367c446da811bbf74626c5bf6c2b30 Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Thu, 25 Jul 2013 17:20:53 -0700 Subject: [PATCH] ofproto-dpif: Hide rule_dpif_miss_rule(). It's simpler to hide it than to make it thread safe and ensure it stays that way in the long term. Signed-off-by: Ethan Jackson Acked-by: Ben Pfaff --- ofproto/ofproto-dpif-xlate.c | 22 +++++++++++++++++----- ofproto/ofproto-dpif-xlate.h | 12 +++++++----- ofproto/ofproto-dpif.c | 32 ++++++++++++++++---------------- ofproto/ofproto-dpif.h | 8 +++++--- 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 86d8222bc..ef45b544e 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -70,6 +70,10 @@ struct xbridge { struct dpif_ipfix *ipfix; /* Ipfix handle, or null. */ struct stp *stp; /* STP or null if disabled. */ + /* Special rules installed by ofproto-dpif. */ + struct rule_dpif *miss_rule; + struct rule_dpif *no_packet_in_rule; + enum ofp_config_flags frag; /* Fragmentation handling. */ bool has_netflow; /* Bridge runs netflow? */ bool has_in_band; /* Bridge has in band control? */ @@ -209,8 +213,10 @@ static bool dscp_from_skb_priority(const struct xport *, uint32_t skb_priority, void xlate_ofproto_set(struct ofproto_dpif *ofproto, const char *name, - struct dpif *dpif, const struct mac_learning *ml, - struct stp *stp, const struct mbridge *mbridge, + struct dpif *dpif, struct rule_dpif *miss_rule, + struct rule_dpif *no_packet_in_rule, + const struct mac_learning *ml, struct stp *stp, + const struct mbridge *mbridge, const struct dpif_sflow *sflow, const struct dpif_ipfix *ipfix, enum ofp_config_flags frag, bool forward_bpdu, bool has_in_band, bool has_netflow) @@ -259,6 +265,8 @@ xlate_ofproto_set(struct ofproto_dpif *ofproto, const char *name, xbridge->has_in_band = has_in_band; xbridge->has_netflow = has_netflow; xbridge->frag = frag; + xbridge->miss_rule = miss_rule; + xbridge->no_packet_in_rule = no_packet_in_rule; } void @@ -1586,14 +1594,18 @@ ctx_rule_hooks(struct xlate_ctx *ctx, struct rule_dpif *rule, ctx->xin->resubmit_hook(ctx->xin, rule, ctx->recurse); } if (rule == NULL && may_packet_in) { + struct xport *xport; + /* XXX * check if table configuration flags * OFPTC_TABLE_MISS_CONTROLLER, default. * OFPTC_TABLE_MISS_CONTINUE, * OFPTC_TABLE_MISS_DROP - * When OF1.0, OFPTC_TABLE_MISS_CONTINUE is used. What to do? - */ - rule = rule_dpif_miss_rule(ctx->xbridge->ofproto, &ctx->xin->flow); + * When OF1.0, OFPTC_TABLE_MISS_CONTINUE is used. What to do? */ + xport = get_ofp_port(ctx->xbridge, ctx->xin->flow.in_port.ofp_port); + rule = choose_miss_rule(xport ? xport->config : 0, + ctx->xbridge->miss_rule, + ctx->xbridge->no_packet_in_rule); } if (rule && ctx->xin->resubmit_stats) { rule_credit_stats(rule, ctx->xin->resubmit_stats); diff --git a/ofproto/ofproto-dpif-xlate.h b/ofproto/ofproto-dpif-xlate.h index 9f8ff44a6..881823b70 100644 --- a/ofproto/ofproto-dpif-xlate.h +++ b/ofproto/ofproto-dpif-xlate.h @@ -111,11 +111,13 @@ struct xlate_in { }; void xlate_ofproto_set(struct ofproto_dpif *, const char *name, - struct dpif *, const struct mac_learning *, - struct stp *, const struct mbridge *, - const struct dpif_sflow *, const struct dpif_ipfix *, - enum ofp_config_flags, bool forward_bpdu, - bool has_in_band, bool has_netflow); + struct dpif *, struct rule_dpif *miss_rule, + struct rule_dpif *no_packet_in_rule, + const struct mac_learning *, struct stp *, + const struct mbridge *, const struct dpif_sflow *, + const struct dpif_ipfix *, enum ofp_config_flags, + bool forward_bpdu, bool has_in_band, bool has_netflow); + void xlate_remove_ofproto(struct ofproto_dpif *); void xlate_bundle_set(struct ofproto_dpif *, struct ofbundle *, diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 1a3567db8..6ef2eb834 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -799,7 +799,8 @@ type_run(const char *type) } xlate_ofproto_set(ofproto, ofproto->up.name, - ofproto->backer->dpif, ofproto->ml, + ofproto->backer->dpif, ofproto->miss_rule, + ofproto->no_packet_in_rule, ofproto->ml, ofproto->stp, ofproto->mbridge, ofproto->sflow, ofproto->ipfix, ofproto->up.frag_handling, @@ -5105,14 +5106,21 @@ static struct rule_dpif * rule_dpif_lookup(struct ofproto_dpif *ofproto, const struct flow *flow, struct flow_wildcards *wc) { + struct ofport_dpif *port; struct rule_dpif *rule; rule = rule_dpif_lookup_in_table(ofproto, flow, wc, 0); if (rule) { return rule; } + port = get_ofp_port(ofproto, flow->in_port.ofp_port); + if (!port) { + VLOG_WARN_RL(&rl, "packet-in on unknown OpenFlow port %"PRIu16, + flow->in_port.ofp_port); + } - return rule_dpif_miss_rule(ofproto, flow); + return choose_miss_rule(port ? port->up.pp.config : 0, ofproto->miss_rule, + ofproto->no_packet_in_rule); } struct rule_dpif * @@ -5152,22 +5160,14 @@ rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto, return rule_dpif_cast(rule_from_cls_rule(cls_rule)); } +/* Given a port configuration (specified as zero if there's no port), chooses + * which of 'miss_rule' and 'no_packet_in_rule' should be used in case of a + * flow table miss. */ struct rule_dpif * -rule_dpif_miss_rule(struct ofproto_dpif *ofproto, const struct flow *flow) +choose_miss_rule(enum ofputil_port_config config, struct rule_dpif *miss_rule, + struct rule_dpif *no_packet_in_rule) { - struct ofport_dpif *port; - - port = get_ofp_port(ofproto, flow->in_port.ofp_port); - if (!port) { - VLOG_WARN_RL(&rl, "packet-in on unknown OpenFlow port %"PRIu16, - flow->in_port.ofp_port); - return ofproto->miss_rule; - } - - if (port->up.pp.config & OFPUTIL_PC_NO_PACKET_IN) { - return ofproto->no_packet_in_rule; - } - return ofproto->miss_rule; + return config & OFPUTIL_PC_NO_PACKET_IN ? no_packet_in_rule : miss_rule; } static void diff --git a/ofproto/ofproto-dpif.h b/ofproto/ofproto-dpif.h index 88593ce3d..a74146b80 100644 --- a/ofproto/ofproto-dpif.h +++ b/ofproto/ofproto-dpif.h @@ -22,6 +22,7 @@ #include "ovs-thread.h" #include "timer.h" #include "util.h" +#include "ovs-thread.h" union user_action_cookie; struct ofproto_dpif; @@ -59,11 +60,12 @@ struct rule_dpif *rule_dpif_lookup_in_table(struct ofproto_dpif *, struct flow_wildcards *, uint8_t table_id); -struct rule_dpif *rule_dpif_miss_rule(struct ofproto_dpif *ofproto, - const struct flow *); - void rule_credit_stats(struct rule_dpif *, const struct dpif_flow_stats *); +struct rule_dpif *choose_miss_rule(enum ofputil_port_config, + struct rule_dpif *miss_rule, + struct rule_dpif *no_packet_in_rule); + bool ofproto_has_vlan_splinters(const struct ofproto_dpif *); ofp_port_t vsp_realdev_to_vlandev(const struct ofproto_dpif *, ofp_port_t realdev_ofp_port, -- 2.20.1