tunnel: Add support for matching on OAM packets.
[cascardo/ovs.git] / lib / odp-util.c
index 8e95c9e..8f71c7c 100644 (file)
@@ -832,6 +832,7 @@ tunnel_key_attr_len(int type)
     case OVS_TUNNEL_KEY_ATTR_TTL: return 1;
     case OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT: return 0;
     case OVS_TUNNEL_KEY_ATTR_CSUM: return 0;
+    case OVS_TUNNEL_KEY_ATTR_OAM: return 0;
     case __OVS_TUNNEL_KEY_ATTR_MAX:
         return -1;
     }
@@ -879,6 +880,9 @@ odp_tun_key_from_attr(const struct nlattr *attr, struct flow_tnl *tun)
         case OVS_TUNNEL_KEY_ATTR_CSUM:
             tun->flags |= FLOW_TNL_F_CSUM;
             break;
+        case OVS_TUNNEL_KEY_ATTR_OAM:
+            tun->flags |= FLOW_TNL_F_OAM;
+            break;
         default:
             /* Allow this to show up as unexpected, if there are unknown
              * tunnel attribute, eventually resulting in ODP_FIT_TOO_MUCH. */
@@ -923,6 +927,9 @@ tun_key_to_attr(struct ofpbuf *a, const struct flow_tnl *tun_key)
     if (tun_key->flags & FLOW_TNL_F_CSUM) {
         nl_msg_put_flag(a, OVS_TUNNEL_KEY_ATTR_CSUM);
     }
+    if (tun_key->flags & FLOW_TNL_F_OAM) {
+        nl_msg_put_flag(a, OVS_TUNNEL_KEY_ATTR_OAM);
+    }
 
     nl_msg_end_nested(a, tun_key_ofs);
 }
@@ -949,7 +956,8 @@ odp_mask_attr_is_exact(const struct nlattr *ma)
         odp_tun_key_from_attr(ma, &tun_mask);
         if (tun_mask.flags == (FLOW_TNL_F_KEY
                                | FLOW_TNL_F_DONT_FRAGMENT
-                               | FLOW_TNL_F_CSUM)) {
+                               | FLOW_TNL_F_CSUM
+                               | FLOW_TNL_F_OAM)) {
             /* The flags are exact match, check the remaining fields. */
             tun_mask.flags = 0xffff;
             is_exact = is_all_ones((uint8_t *)&tun_mask,
@@ -1319,7 +1327,7 @@ format_odp_key_attr(const struct nlattr *a, const struct nlattr *ma,
         } else {
             const struct ovs_key_sctp *sctp_key = nl_attr_get(a);
 
-            ds_put_format(ds, "(src=%"PRIu16",dst=%"PRIu16")",
+            ds_put_format(ds, "src=%"PRIu16",dst=%"PRIu16,
                           ntohs(sctp_key->sctp_src), ntohs(sctp_key->sctp_dst));
         }
         break;
@@ -2483,7 +2491,7 @@ ovs_to_odp_frag_mask(uint8_t nw_frag_mask)
 static void
 odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *flow,
                          const struct flow *mask, odp_port_t odp_in_port,
-                         size_t max_mpls_depth, bool export_mask)
+                         size_t max_mpls_depth, bool recirc, bool export_mask)
 {
     struct ovs_key_ethernet *eth_key;
     size_t encap;
@@ -2497,11 +2505,8 @@ odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *flow,
 
     nl_msg_put_u32(buf, OVS_KEY_ATTR_SKB_MARK, data->pkt_mark);
 
-    if (data->recirc_id || (mask && mask->recirc_id)) {
+    if (recirc) {
         nl_msg_put_u32(buf, OVS_KEY_ATTR_RECIRC_ID, data->recirc_id);
-    }
-
-    if (data->dp_hash || (mask && mask->dp_hash)) {
         nl_msg_put_u32(buf, OVS_KEY_ATTR_DP_HASH, data->dp_hash);
     }
 
@@ -2643,11 +2648,11 @@ odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *flow,
             icmpv6_key->icmpv6_type = ntohs(data->tp_src);
             icmpv6_key->icmpv6_code = ntohs(data->tp_dst);
 
-            if (flow->tp_dst == htons(0) &&
-                (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT) ||
-                 flow->tp_src == htons(ND_NEIGHBOR_ADVERT)) &&
-                (!export_mask || (data->tp_src == htons(0xffff) &&
-                              data->tp_dst == htons(0xffff)))) {
+            if (flow->tp_dst == htons(0)
+                && (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT)
+                    || flow->tp_src == htons(ND_NEIGHBOR_ADVERT))
+                && (!export_mask || (data->tp_src == htons(0xffff)
+                                     && data->tp_dst == htons(0xffff)))) {
 
                 struct ovs_key_nd *nd_key;
 
@@ -2674,12 +2679,17 @@ unencap:
  * port.
  *
  * 'buf' must have at least ODPUTIL_FLOW_KEY_BYTES bytes of space, or be
- * capable of being expanded to allow for that much space. */
+ * capable of being expanded to allow for that much space.
+ *
+ * 'recirc' indicates support for recirculation fields. If this is true, then
+ * these fields will always be serialised. */
 void
 odp_flow_key_from_flow(struct ofpbuf *buf, const struct flow *flow,
-                       const struct flow *mask, odp_port_t odp_in_port)
+                       const struct flow *mask, odp_port_t odp_in_port,
+                       bool recirc)
 {
-    odp_flow_key_from_flow__(buf, flow, mask, odp_in_port, SIZE_MAX, false);
+    odp_flow_key_from_flow__(buf, flow, mask, odp_in_port, SIZE_MAX, recirc,
+                             false);
 }
 
 /* Appends a representation of 'mask' as OVS_KEY_ATTR_* attributes to
@@ -2689,14 +2699,17 @@ odp_flow_key_from_flow(struct ofpbuf *buf, const struct flow *flow,
  * ARP, IPv4, IPv6, etc.
  *
  * 'buf' must have at least ODPUTIL_FLOW_KEY_BYTES bytes of space, or be
- * capable of being expanded to allow for that much space. */
+ * capable of being expanded to allow for that much space.
+ *
+ * 'recirc' indicates support for recirculation fields. If this is true, then
+ * these fields will always be serialised. */
 void
 odp_flow_key_from_mask(struct ofpbuf *buf, const struct flow *mask,
                        const struct flow *flow, uint32_t odp_in_port_mask,
-                       size_t max_mpls_depth)
+                       size_t max_mpls_depth, bool recirc)
 {
-    odp_flow_key_from_flow__(buf, flow, mask,
-                             u32_to_odp(odp_in_port_mask), max_mpls_depth, true);
+    odp_flow_key_from_flow__(buf, flow, mask, u32_to_odp(odp_in_port_mask),
+                             max_mpls_depth, recirc, true);
 }
 
 /* Generate ODP flow key from the given packet metadata */
@@ -3313,7 +3326,7 @@ odp_flow_key_to_flow__(const struct nlattr *key, size_t key_len,
         flow->recirc_id = nl_attr_get_u32(attrs[OVS_KEY_ATTR_RECIRC_ID]);
         expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_RECIRC_ID;
     } else if (is_mask) {
-        /* Always exact match recirc_id when datapath does not sepcify it. */
+        /* Always exact match recirc_id if it is not specified. */
         flow->recirc_id = UINT32_MAX;
     }
 
@@ -3785,6 +3798,11 @@ static void
 commit_set_port_action(const struct flow *flow, struct flow *base,
                        struct ofpbuf *odp_actions, struct flow_wildcards *wc)
 {
+    /* Check if 'flow' really has an L3 header. */
+    if (!flow->nw_proto) {
+        return;
+    }
+
     if (!is_ip_any(base) || (!base->tp_src && !base->tp_dst)) {
         return;
     }