tunnel: Hide 'struct tnl_port' internally.
[sliver-openvswitch.git] / ofproto / ofproto-dpif-xlate.c
index 36f54ee..0e7b9a0 100644 (file)
@@ -26,6 +26,7 @@
 #include "coverage.h"
 #include "dpif.h"
 #include "dynamic-string.h"
+#include "in-band.h"
 #include "lacp.h"
 #include "learn.h"
 #include "mac-learning.h"
@@ -547,8 +548,6 @@ xlate_normal(struct xlate_ctx *ctx)
 
     ctx->xout->has_normal = true;
 
-    /* Check the dl_type, since we may check for gratuituous ARP. */
-    memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
     memset(&wc->masks.dl_src, 0xff, sizeof wc->masks.dl_src);
     memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
     wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
@@ -813,7 +812,6 @@ process_special(struct xlate_ctx *ctx, const struct flow *flow,
         return SLOW_BFD;
     } else if (ofport->bundle && ofport->bundle->lacp
                && flow->dl_type == htons(ETH_TYPE_LACP)) {
-        memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
         if (packet) {
             lacp_process_packet(ofport->bundle->lacp, ofport, packet);
         }
@@ -906,13 +904,13 @@ compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port,
         flow->nw_tos |= dscp;
     }
 
-    if (ofport->tnl_port) {
+    if (ofport->is_tunnel) {
          /* Save tunnel metadata so that changes made due to
           * the Logical (tunnel) Port are not visible for any further
           * matches, while explicit set actions on tunnel metadata are.
           */
         struct flow_tnl flow_tnl = flow->tunnel;
-        odp_port = tnl_port_send(ofport->tnl_port, flow, &ctx->xout->wc);
+        odp_port = tnl_port_send(ofport, flow, &ctx->xout->wc);
         if (odp_port == ODPP_NONE) {
             xlate_report(ctx, "Tunneling decided against output");
             goto out; /* restore flow_nw_tos */
@@ -970,24 +968,6 @@ compose_output_action(struct xlate_ctx *ctx, ofp_port_t ofp_port)
     compose_output_action__(ctx, ofp_port, true);
 }
 
-static void
-tag_the_flow(struct xlate_ctx *ctx, struct rule_dpif *rule)
-{
-    struct ofproto_dpif *ofproto = ctx->ofproto;
-    uint8_t table_id = ctx->table_id;
-
-    if (table_id > 0 && table_id < N_TABLES) {
-        struct table_dpif *table = &ofproto->tables[table_id];
-        if (table->other_table) {
-            ctx->xout->tags |= (rule && rule->tag
-                                ? rule->tag
-                                : rule_calculate_tag(&ctx->xin->flow,
-                                                     &table->other_table->mask,
-                                                     table->basis));
-        }
-    }
-}
-
 /* Common rule processing in one place to avoid duplicating code. */
 static struct rule_dpif *
 ctx_rule_hooks(struct xlate_ctx *ctx, struct rule_dpif *rule,
@@ -1028,7 +1008,8 @@ xlate_table_action(struct xlate_ctx *ctx,
         rule = rule_dpif_lookup_in_table(ctx->ofproto, &ctx->xin->flow,
                                          &ctx->xout->wc, table_id);
 
-        tag_the_flow(ctx, rule);
+        ctx->xout->tags |= calculate_flow_tag(ctx->ofproto, &ctx->xin->flow,
+                                              ctx->table_id, rule);
 
         /* Restore the original input port.  Otherwise OFPP_NORMAL and
          * OFPP_IN_PORT will have surprising behavior. */
@@ -1147,7 +1128,6 @@ compose_mpls_push_action(struct xlate_ctx *ctx, ovs_be16 eth_type)
 
     ovs_assert(eth_type_mpls(eth_type));
 
-    memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
     memset(&wc->masks.mpls_lse, 0xff, sizeof wc->masks.mpls_lse);
     memset(&wc->masks.mpls_depth, 0xff, sizeof wc->masks.mpls_depth);
 
@@ -1182,7 +1162,6 @@ compose_mpls_pop_action(struct xlate_ctx *ctx, ovs_be16 eth_type)
     ovs_assert(eth_type_mpls(ctx->xin->flow.dl_type));
     ovs_assert(!eth_type_mpls(eth_type));
 
-    memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
     memset(&wc->masks.mpls_lse, 0xff, sizeof wc->masks.mpls_lse);
     memset(&wc->masks.mpls_depth, 0xff, sizeof wc->masks.mpls_depth);
 
@@ -1239,7 +1218,6 @@ compose_dec_mpls_ttl_action(struct xlate_ctx *ctx)
     uint8_t ttl = mpls_lse_to_ttl(flow->mpls_lse);
     struct flow_wildcards *wc = &ctx->xout->wc;
 
-    memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
     memset(&wc->masks.mpls_lse, 0xff, sizeof wc->masks.mpls_lse);
 
     if (!eth_type_mpls(flow->dl_type)) {
@@ -1594,14 +1572,12 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
             break;
 
         case OFPACT_SET_IPV4_SRC:
-            memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
             if (flow->dl_type == htons(ETH_TYPE_IP)) {
                 flow->nw_src = ofpact_get_SET_IPV4_SRC(a)->ipv4;
             }
             break;
 
         case OFPACT_SET_IPV4_DST:
-            memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
             if (flow->dl_type == htons(ETH_TYPE_IP)) {
                 flow->nw_dst = ofpact_get_SET_IPV4_DST(a)->ipv4;
             }
@@ -1609,7 +1585,6 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
 
         case OFPACT_SET_IPV4_DSCP:
             /* OpenFlow 1.0 only supports IPv4. */
-            memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
             if (flow->dl_type == htons(ETH_TYPE_IP)) {
                 flow->nw_tos &= ~IP_DSCP_MASK;
                 flow->nw_tos |= ofpact_get_SET_IPV4_DSCP(a)->dscp;
@@ -1617,7 +1592,6 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
             break;
 
         case OFPACT_SET_L4_SRC_PORT:
-            memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
             memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
             if (is_ip_any(flow)) {
                 flow->tp_src = htons(ofpact_get_SET_L4_SRC_PORT(a)->port);
@@ -1625,7 +1599,6 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
             break;
 
         case OFPACT_SET_L4_DST_PORT:
-            memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
             memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
             if (is_ip_any(flow)) {
                 flow->tp_dst = htons(ofpact_get_SET_L4_DST_PORT(a)->port);
@@ -1687,7 +1660,6 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
             break;
 
         case OFPACT_DEC_TTL:
-            memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
             if (compose_dec_ttl(ctx, ofpact_get_DEC_TTL(a))) {
                 goto out;
             }
@@ -1702,7 +1674,6 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
             break;
 
         case OFPACT_BUNDLE:
-            ctx->ofproto->has_bundle_action = true;
             xlate_bundle_action(ctx, ofpact_get_BUNDLE(a));
             break;
 
@@ -1719,7 +1690,6 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
             break;
 
         case OFPACT_FIN_TIMEOUT:
-            memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
             memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
             ctx->xout->has_fin_timeout = true;
             xlate_fin_timeout(ctx, ofpact_get_FIN_TIMEOUT(a));
@@ -1756,7 +1726,8 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
             rule = rule_dpif_lookup_in_table(ctx->ofproto, flow, wc,
                                              ctx->table_id);
 
-            tag_the_flow(ctx, rule);
+            ctx->xout->tags = calculate_flow_tag(ctx->ofproto, &ctx->xin->flow,
+                                                 ctx->table_id, rule);
 
             rule = ctx_rule_hooks(ctx, rule, true);
 
@@ -1851,6 +1822,22 @@ xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src)
                src->odp_actions.size);
 }
 \f
+static bool
+actions_output_to_local_port(const struct xlate_ctx *ctx)
+{
+    odp_port_t local_odp_port = ofp_port_to_odp_port(ctx->ofproto, OFPP_LOCAL);
+    const struct nlattr *a;
+    unsigned int left;
+
+    NL_ATTR_FOR_EACH_UNSAFE (a, left, ctx->xout->odp_actions.data,
+                             ctx->xout->odp_actions.size) {
+        if (nl_attr_type(a) == OVS_ACTION_ATTR_OUTPUT
+            && nl_attr_get_odp_port(a) == local_odp_port) {
+            return true;
+        }
+    }
+    return false;
+}
 
 /* Translates the 'ofpacts_len' bytes of "struct ofpacts" starting at 'ofpacts'
  * into datapath actions in 'odp_actions', using 'ctx'. */
@@ -1908,13 +1895,14 @@ xlate_actions(struct xlate_in *xin, struct xlate_out *xout)
     flow_wildcards_init_catchall(wc);
     memset(&wc->masks.in_port, 0xff, sizeof wc->masks.in_port);
     memset(&wc->masks.skb_priority, 0xff, sizeof wc->masks.skb_priority);
+    memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
     wc->masks.nw_frag |= FLOW_NW_FRAG_MASK;
 
     if (tnl_port_should_receive(&ctx.xin->flow)) {
         memset(&wc->masks.tunnel, 0xff, sizeof wc->masks.tunnel);
     }
     if (xin->ofproto->netflow) {
-        netflow_mask_wc(wc);
+        netflow_mask_wc(flow, wc);
     }
 
     ctx.xout->tags = 0;
@@ -1983,7 +1971,6 @@ xlate_actions(struct xlate_in *xin, struct xlate_out *xout)
     } else {
         static struct vlog_rate_limit trace_rl = VLOG_RATE_LIMIT_INIT(1, 1);
         size_t sample_actions_len;
-        odp_port_t local_odp_port;
 
         if (flow->in_port.ofp_port
             != vsp_realdev_to_vlandev(ctx.ofproto, flow->in_port.ofp_port,
@@ -2020,11 +2007,9 @@ xlate_actions(struct xlate_in *xin, struct xlate_out *xout)
             }
         }
 
-        local_odp_port = ofp_port_to_odp_port(ctx.ofproto, OFPP_LOCAL);
-        if (!connmgr_must_output_local(ctx.ofproto->up.connmgr, flow,
-                                       local_odp_port,
-                                       ctx.xout->odp_actions.data,
-                                       ctx.xout->odp_actions.size)) {
+        if (connmgr_has_in_band(ctx.ofproto->up.connmgr)
+            && in_band_must_output_to_local_port(flow)
+            && !actions_output_to_local_port(&ctx)) {
             compose_output_action(&ctx, OFPP_LOCAL);
         }
         if (ctx.ofproto->has_mirrors) {