openflow: Support matching and modifying MPLS TTL field.
[cascardo/ovs.git] / lib / meta-flow.h
index 323da02..d6ffdfa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
+ * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -368,6 +368,41 @@ enum OVS_PACKED_ENUM mf_field_id {
      */
     MFF_TUN_DST,
 
+    /* "tun_ipv6_src".
+     *
+     * The IPv6 source address in the outer IP header of a tunneled packet.
+     *
+     * For non-tunneled packets, the value is 0.
+     *
+     * Type: be128.
+     * Maskable: bitwise.
+     * Formatting: IPv6.
+     * Prerequisites: none.
+     * Access: read/write.
+     * NXM: NXM_NX_TUN_IPV6_SRC(109) since v2.5.
+     * OXM: none.
+     * Prefix lookup member: tunnel.ipv6_src.
+     */
+    MFF_TUN_IPV6_SRC,
+
+    /* "tun_ipv6_dst".
+     *
+     * The IPv6 destination address in the outer IP header of a tunneled
+     * packet.
+     *
+     * For non-tunneled packets, the value is 0.
+     *
+     * Type: be128.
+     * Maskable: bitwise.
+     * Formatting: IPv6.
+     * Prerequisites: none.
+     * Access: read/write.
+     * NXM: NXM_NX_TUN_IPV6_DST(110) since v2.5.
+     * OXM: none.
+     * Prefix lookup member: tunnel.ipv6_dst.
+     */
+    MFF_TUN_IPV6_DST,
+
     /* "tun_flags".
      *
      * Flags representing aspects of tunnel behavior.
@@ -703,6 +738,109 @@ enum OVS_PACKED_ENUM mf_field_id {
      */
     MFF_PKT_MARK,
 
+    /* "ct_state".
+     *
+     * Connection tracking state.  The field is populated by the NXAST_CT
+     * action. The following bit values describe the state of the connection:
+     *
+     *   - New (0x01): This is the beginning of a new connection.
+     *   - Established (0x02): This is part of an already existing connection.
+     *   - Related (0x04): This is a separate connection that is related to an
+     *                     existing connection.
+     *   - Reply (0x08): This flow is in the reply direction, ie it did not
+     *                   initiate the connection.
+     *   - Invalid (0x10): This flow could not be associated with a connection.
+     *                     This could be set for a variety of reasons,
+     *                     including (but not limited to):
+     *                     - L3/L4 protocol handler is not loaded/unavailable.
+     *                     - L3/L4 protocol handler determines that the packet
+     *                       is malformed or invalid for the current FSM stage.
+     *                     - Packets are unexpected length for protocol.
+     *   - Tracked (0x20): Connection tracking has occurred.
+     *
+     * The "Tracked" bit corresponds to the packet_state as described in the
+     * description of NXAST_CT action. The remaining bits correspond to
+     * connection state. The "New" bit implies that the connection state
+     * is uncommitted, while "Established" implies that it has previously been
+     * committed.
+     *
+     * There are additional constraints on the ct_state bits, listed in order
+     * of precedence below:
+     *
+     *   - If "Tracked" is unset, no other bits may be set.
+     *   - If "Tracked" is set, one or more other bits may be set.
+     *   - If "Invalid" is set, only the "Tracked" bit is also set.
+     *   - The "New" and "Established" bits are mutually exclusive.
+     *   - The "New" and "Reply" bits are mutually exclusive.
+     *   - The "Related" bit may be set in conjunction with any other bits.
+     *     Connections that are identified as "Related" are separate
+     *     connections from the originating connection, so must be committed
+     *     separately. All packets for a related connection will have the
+     *     "Related" bit set (not just the initial packet).
+     *
+     * Type: be32.
+     * Maskable: bitwise.
+     * Formatting: ct state.
+     * Prerequisites: none.
+     * Access: read-only.
+     * NXM: NXM_NX_CT_STATE(105) since v2.5.
+     * OXM: none.
+     */
+    MFF_CT_STATE,
+
+    /* "ct_zone".
+     *
+     * Connection tracking zone.  The field is populated by the
+     * NXAST_CT action.
+     *
+     * Type: be16.
+     * Maskable: no.
+     * Formatting: hexadecimal.
+     * Prerequisites: none.
+     * Access: read-only.
+     * NXM: NXM_NX_CT_ZONE(106) since v2.5.
+     * OXM: none.
+     */
+    MFF_CT_ZONE,
+
+    /* "ct_mark".
+     *
+     * Connection tracking mark.  The mark is carried with the
+     * connection tracking state.  On Linux this corresponds to the
+     * nf_conn's "mark" member but the exact implementation is
+     * platform-dependent.
+     *
+     * Writable only from nested actions within the NXAST_CT action.
+     *
+     * Type: be32.
+     * Maskable: bitwise.
+     * Formatting: hexadecimal.
+     * Prerequisites: none.
+     * Access: read/write.
+     * NXM: NXM_NX_CT_MARK(107) since v2.5.
+     * OXM: none.
+     */
+    MFF_CT_MARK,
+
+    /* "ct_label".
+     *
+     * Connection tracking label.  The label is carried with the
+     * connection tracking state.  On Linux this is held in the
+     * conntrack label extension but the exact implementation is
+     * platform-dependent.
+     *
+     * Writable only from nested actions within the NXAST_CT action.
+     *
+     * Type: be128.
+     * Maskable: bitwise.
+     * Formatting: hexadecimal.
+     * Prerequisites: none.
+     * Access: read/write.
+     * NXM: NXM_NX_CT_LABEL(108) since v2.5.
+     * OXM: none.
+     */
+    MFF_CT_LABEL,
+
 #if FLOW_N_REGS == 8
     /* "reg<N>".
      *
@@ -1006,6 +1144,21 @@ enum OVS_PACKED_ENUM mf_field_id {
      */
     MFF_MPLS_BOS,
 
+    /* "mpls_ttl".
+     *
+     * The outermost MPLS label's time-to-live (TTL) field, or 0 if no MPLS
+     * labels are present.
+     *
+     * Type: u8.
+     * Maskable: no.
+     * Formatting: decimal.
+     * Prerequisites: MPLS.
+     * Access: read/write.
+     * NXM: NXM_NX_MPLS_TTL(30) since v2.6.
+     * OXM: none.
+     */
+    MFF_MPLS_TTL,
+
 /* ## ---- ## */
 /* ## IPv4 ## */
 /* ## ---- ## */
@@ -1059,7 +1212,7 @@ enum OVS_PACKED_ENUM mf_field_id {
      *
      * The source address in the IPv6 header.
      *
-     * Type: IPv6.
+     * Type: be128.
      * Maskable: bitwise.
      * Formatting: IPv6.
      * Prerequisites: IPv6.
@@ -1074,7 +1227,7 @@ enum OVS_PACKED_ENUM mf_field_id {
      *
      * The destination address in the IPv6 header.
      *
-     * Type: IPv6.
+     * Type: be128.
      * Maskable: bitwise.
      * Formatting: IPv6.
      * Prerequisites: IPv6.
@@ -1466,7 +1619,7 @@ enum OVS_PACKED_ENUM mf_field_id {
      * Maskable: no.
      * Formatting: decimal.
      * Prerequisites: ICMPv4.
-     * Access: read-only.
+     * Access: read/write.
      * NXM: NXM_OF_ICMP_TYPE(13) since v1.1.
      * OXM: OXM_OF_ICMPV4_TYPE(19) since OF1.2 and v1.7.
      * OF1.0: exact match.
@@ -1482,7 +1635,7 @@ enum OVS_PACKED_ENUM mf_field_id {
      * Maskable: no.
      * Formatting: decimal.
      * Prerequisites: ICMPv4.
-     * Access: read-only.
+     * Access: read/write.
      * NXM: NXM_OF_ICMP_CODE(14) since v1.1.
      * OXM: OXM_OF_ICMPV4_CODE(20) since OF1.2 and v1.7.
      * OF1.0: exact match.
@@ -1498,7 +1651,7 @@ enum OVS_PACKED_ENUM mf_field_id {
      * Maskable: no.
      * Formatting: decimal.
      * Prerequisites: ICMPv6.
-     * Access: read-only.
+     * Access: read/write.
      * NXM: NXM_NX_ICMPV6_TYPE(21) since v1.1.
      * OXM: OXM_OF_ICMPV6_TYPE(29) since OF1.2 and v1.7.
      */
@@ -1512,7 +1665,7 @@ enum OVS_PACKED_ENUM mf_field_id {
      * Maskable: no.
      * Formatting: decimal.
      * Prerequisites: ICMPv6.
-     * Access: read-only.
+     * Access: read/write.
      * NXM: NXM_NX_ICMPV6_CODE(22) since v1.1.
      * OXM: OXM_OF_ICMPV6_CODE(30) since OF1.2 and v1.7.
      */
@@ -1528,7 +1681,7 @@ enum OVS_PACKED_ENUM mf_field_id {
      *
      * Before Open vSwitch 1.8, only CIDR masks were supported.
      *
-     * Type: IPv6.
+     * Type: be128.
      * Maskable: bitwise.
      * Formatting: IPv6.
      * Prerequisites: ND.
@@ -1679,6 +1832,7 @@ enum OVS_PACKED_ENUM mf_string {
     MFS_HEXADECIMAL,
 
     /* Other formats. */
+    MFS_CT_STATE,               /* Connection tracking state */
     MFS_ETHERNET,
     MFS_IPV4,
     MFS_IPV6,
@@ -1741,14 +1895,15 @@ struct mf_field {
 union mf_value {
     uint8_t tun_metadata[128];
     struct in6_addr ipv6;
-    uint8_t mac[ETH_ADDR_LEN];
+    struct eth_addr mac;
+    ovs_be128 be128;
     ovs_be64 be64;
     ovs_be32 be32;
     ovs_be16 be16;
     uint8_t u8;
 };
 BUILD_ASSERT_DECL(sizeof(union mf_value) == 128);
-BUILD_ASSERT_DECL(sizeof(union mf_value) >= GENEVE_MAX_OPT_SIZE);
+BUILD_ASSERT_DECL(sizeof(union mf_value) >= TLV_MAX_OPT_SIZE);
 
 /* A const mf_value with all bits initialized to ones. */
 extern const union mf_value exact_match_mask;
@@ -1779,7 +1934,7 @@ union mf_subvalue {
     };
     struct {
         uint8_t dummy_mac[122];
-        uint8_t mac[6];
+        struct eth_addr mac;
     };
     struct {
         ovs_be32 dummy_ipv4[31];
@@ -1800,6 +1955,7 @@ bool mf_subvalue_intersect(const union mf_subvalue *a_value,
                            union mf_subvalue *dst_mask);
 int mf_subvalue_width(const union mf_subvalue *);
 void mf_subvalue_shift(union mf_subvalue *, int n);
+void mf_subvalue_format(const union mf_subvalue *, struct ds *);
 
 /* An array of fields with values */
 struct field_array {
@@ -1844,28 +2000,27 @@ bool mf_is_value_valid(const struct mf_field *, const union mf_value *value);
 void mf_get_value(const struct mf_field *, const struct flow *,
                   union mf_value *value);
 void mf_set_value(const struct mf_field *, const union mf_value *value,
-                  struct match *);
+                  struct match *, char **err_str);
 void mf_set_flow_value(const struct mf_field *, const union mf_value *value,
                        struct flow *);
 void mf_set_flow_value_masked(const struct mf_field *,
                               const union mf_value *value,
                               const union mf_value *mask,
                               struct flow *);
-bool mf_is_zero(const struct mf_field *, const struct flow *);
+bool mf_is_tun_metadata(const struct mf_field *);
+bool mf_is_set(const struct mf_field *, const struct flow *);
 void mf_mask_field(const struct mf_field *, struct flow *);
 int mf_field_len(const struct mf_field *, const union mf_value *value,
-                 const union mf_value *mask);
+                 const union mf_value *mask, bool *is_masked);
 
 void mf_get(const struct mf_field *, const struct match *,
             union mf_value *value, union mf_value *mask);
 
 /* Returns the set of usable protocols. */
-enum ofputil_protocol mf_set(const struct mf_field *,
-                             const union mf_value *value,
-                             const union mf_value *mask,
-                             struct match *);
+uint32_t mf_set(const struct mf_field *, const union mf_value *value,
+                const union mf_value *mask, struct match *, char **err_str);
 
-void mf_set_wild(const struct mf_field *, struct match *);
+void mf_set_wild(const struct mf_field *, struct match *, char **err_str);
 
 /* Subfields. */
 void mf_write_subfield_flow(const struct mf_subfield *,