datapath: Fix few mpls issues.
[cascardo/ovs.git] / datapath / flow_netlink.c
index 6c74841..0649d2c 100644 (file)
@@ -18,9 +18,6 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-#include "flow.h"
-#include "datapath.h"
-#include "mpls.h"
 #include <linux/uaccess.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/rculist.h>
 #include <net/geneve.h>
 #include <net/ip.h>
-#include <net/ip_tunnels.h>
 #include <net/ipv6.h>
 #include <net/ndisc.h>
+#include <net/mpls.h>
 
+#include "datapath.h"
+#include "flow.h"
 #include "flow_netlink.h"
 
 static void update_range(struct sw_flow_match *match,
@@ -112,13 +111,14 @@ static void update_range(struct sw_flow_match *match,
        } while (0)
 
 static bool match_validate(const struct sw_flow_match *match,
-                          u64 key_attrs, u64 mask_attrs)
+                          u64 key_attrs, u64 mask_attrs, bool log)
 {
        u64 key_expected = 1ULL << OVS_KEY_ATTR_ETHERNET;
        u64 mask_allowed = key_attrs;  /* At most allow all key attributes */
 
        /* The following mask attributes allowed only if they
-        * pass the validation tests. */
+        * pass the validation tests.
+        */
        mask_allowed &= ~((1ULL << OVS_KEY_ATTR_IPV4)
                        | (1ULL << OVS_KEY_ATTR_IPV6)
                        | (1ULL << OVS_KEY_ATTR_TCP)
@@ -231,15 +231,19 @@ static bool match_validate(const struct sw_flow_match *match,
 
        if ((key_attrs & key_expected) != key_expected) {
                /* Key attributes check failed. */
-               OVS_NLERR("Missing expected key attributes (key_attrs=%llx, expected=%llx).\n",
-                               (unsigned long long)key_attrs, (unsigned long long)key_expected);
+               OVS_NLERR(log,
+                         "Missing expected key attributes (key_attrs=%llx, expected=%llx).",
+                         (unsigned long long)key_attrs,
+                         (unsigned long long)key_expected);
                return false;
        }
 
        if ((mask_attrs & mask_allowed) != mask_attrs) {
                /* Mask attributes check failed. */
-               OVS_NLERR("Contain more than allowed mask fields (mask_attrs=%llx, mask_allowed=%llx).\n",
-                               (unsigned long long)mask_attrs, (unsigned long long)mask_allowed);
+               OVS_NLERR(log,
+                         "Contain more than allowed mask fields (mask_attrs=%llx, mask_allowed=%llx).",
+                         (unsigned long long)mask_attrs,
+                         (unsigned long long)mask_allowed);
                return false;
        }
 
@@ -249,7 +253,8 @@ static bool match_validate(const struct sw_flow_match *match,
 size_t ovs_tun_key_attr_size(void)
 {
        /* Whenever adding new OVS_TUNNEL_KEY_ FIELDS, we should consider
-        * updating this function.  */
+        * updating this function.
+        */
        return    nla_total_size(8)    /* OVS_TUNNEL_KEY_ATTR_ID */
                + nla_total_size(4)    /* OVS_TUNNEL_KEY_ATTR_IPV4_SRC */
                + nla_total_size(4)    /* OVS_TUNNEL_KEY_ATTR_IPV4_DST */
@@ -266,7 +271,8 @@ size_t ovs_tun_key_attr_size(void)
 size_t ovs_key_attr_size(void)
 {
        /* Whenever adding new OVS_KEY_ FIELDS, we should consider
-        * updating this function.  */
+        * updating this function.
+        */
        BUILD_BUG_ON(OVS_KEY_ATTR_TUNNEL_INFO != 22);
 
        return    nla_total_size(4)   /* OVS_KEY_ATTR_PRIORITY */
@@ -327,7 +333,7 @@ static bool is_all_zero(const u8 *fp, size_t size)
 
 static int __parse_flow_nlattrs(const struct nlattr *attr,
                                const struct nlattr *a[],
-                               u64 *attrsp, bool nz)
+                               u64 *attrsp, bool log, bool nz)
 {
        const struct nlattr *nla;
        u64 attrs;
@@ -339,20 +345,22 @@ static int __parse_flow_nlattrs(const struct nlattr *attr,
                int expected_len;
 
                if (type > OVS_KEY_ATTR_MAX) {
-                       OVS_NLERR("Unknown key attribute (type=%d, max=%d).\n",
+                       OVS_NLERR(log,
+                                 "Unknown key attribute (type=%d, max=%d).",
                                  type, OVS_KEY_ATTR_MAX);
                        return -EINVAL;
                }
 
                if (attrs & (1ULL << type)) {
-                       OVS_NLERR("Duplicate key attribute (type %d).\n", type);
+                       OVS_NLERR(log, "Duplicate key attribute (type %d).",
+                                 type);
                        return -EINVAL;
                }
 
                expected_len = ovs_key_lens[type];
                if (nla_len(nla) != expected_len && expected_len != -1) {
-                       OVS_NLERR("Key attribute has unexpected length (type=%d"
-                                 ", length=%d, expected=%d).\n", type,
+                       OVS_NLERR(log, "Key attribute has unexpected length "
+                                 "(type=%d, length=%d, expected=%d).", type,
                                  nla_len(nla), expected_len);
                        return -EINVAL;
                }
@@ -363,7 +371,7 @@ static int __parse_flow_nlattrs(const struct nlattr *attr,
                }
        }
        if (rem) {
-               OVS_NLERR("Message has %d unknown bytes.\n", rem);
+               OVS_NLERR(log, "Message has %d unknown bytes.", rem);
                return -EINVAL;
        }
 
@@ -372,19 +380,22 @@ static int __parse_flow_nlattrs(const struct nlattr *attr,
 }
 
 static int parse_flow_mask_nlattrs(const struct nlattr *attr,
-                                  const struct nlattr *a[], u64 *attrsp)
+                                  const struct nlattr *a[], u64 *attrsp,
+                                  bool log)
 {
-       return __parse_flow_nlattrs(attr, a, attrsp, true);
+       return __parse_flow_nlattrs(attr, a, attrsp, log, true);
 }
 
 static int parse_flow_nlattrs(const struct nlattr *attr,
-                             const struct nlattr *a[], u64 *attrsp)
+                             const struct nlattr *a[], u64 *attrsp,
+                             bool log)
 {
-       return __parse_flow_nlattrs(attr, a, attrsp, false);
+       return __parse_flow_nlattrs(attr, a, attrsp, log, false);
 }
 
 static int ipv4_tun_from_nlattr(const struct nlattr *attr,
-                               struct sw_flow_match *match, bool is_mask)
+                               struct sw_flow_match *match, bool is_mask,
+                               bool log)
 {
        struct nlattr *a;
        int rem;
@@ -408,16 +419,19 @@ static int ipv4_tun_from_nlattr(const struct nlattr *attr,
                };
 
                if (type > OVS_TUNNEL_KEY_ATTR_MAX) {
-                       OVS_NLERR("Unknown IPv4 tunnel attribute (type=%d, max=%d).\n",
-                       type, OVS_TUNNEL_KEY_ATTR_MAX);
+                       OVS_NLERR(log,
+                                 "Unknown tunnel attribute (type=%d, max=%d).",
+                                 type, OVS_TUNNEL_KEY_ATTR_MAX);
                        return -EINVAL;
                }
 
                if (ovs_tunnel_key_lens[type] != nla_len(a) &&
                    ovs_tunnel_key_lens[type] != -1) {
-                       OVS_NLERR("IPv4 tunnel attribute type has unexpected "
-                                 " length (type=%d, length=%d, expected=%d).\n",
-                                 type, nla_len(a), ovs_tunnel_key_lens[type]);
+                       OVS_NLERR(log,
+                                 "Tunnel attribute has unexpected length "
+                                 "(type=%d, length=%d, expected=%d).",
+                                 type, nla_len(a),
+                                 ovs_tunnel_key_lens[type]);
                        return -EINVAL;
                }
 
@@ -464,16 +478,16 @@ static int ipv4_tun_from_nlattr(const struct nlattr *attr,
                case OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS:
                        tun_flags |= TUNNEL_OPTIONS_PRESENT;
                        if (nla_len(a) > sizeof(match->key->tun_opts)) {
-                               OVS_NLERR("Geneve option length exceeds "
-                                         "maximum size (len %d, max %zu).\n",
+                               OVS_NLERR(log, "Geneve option too long "
+                                         "(len %d, max %zu).",
                                          nla_len(a),
                                          sizeof(match->key->tun_opts));
                                return -EINVAL;
                        }
 
                        if (nla_len(a) % 4 != 0) {
-                               OVS_NLERR("Geneve option length is not "
-                                         "a multiple of 4 (len %d).\n",
+                               OVS_NLERR(log, "Geneve option length is not "
+                                         "a multiple of 4 (len %d).",
                                          nla_len(a));
                                return -EINVAL;
                        }
@@ -497,9 +511,11 @@ static int ipv4_tun_from_nlattr(const struct nlattr *attr,
                                 * information later.
                                 */
                                if (match->key->tun_opts_len != nla_len(a)) {
-                                       OVS_NLERR("Geneve option key length (%d)"
-                                          " is different from mask length (%d).",
-                                          match->key->tun_opts_len, nla_len(a));
+                                       OVS_NLERR(log,
+                                                 "Geneve option key length (%d)"
+                                                 " is different from mask length (%d).",
+                                                 match->key->tun_opts_len,
+                                                 nla_len(a));
                                        return -EINVAL;
                                }
 
@@ -513,7 +529,8 @@ static int ipv4_tun_from_nlattr(const struct nlattr *attr,
                                nla_data(a), nla_len(a), is_mask);
                        break;
                default:
-                       OVS_NLERR("Unknown IPv4 tunnel attribute (%d).\n", type);
+                       OVS_NLERR(log, "Unknown IPv4 tunnel attribute (%d).",
+                                 type);
                        return -EINVAL;
                }
        }
@@ -521,18 +538,20 @@ static int ipv4_tun_from_nlattr(const struct nlattr *attr,
        SW_FLOW_KEY_PUT(match, tun_key.tun_flags, tun_flags, is_mask);
 
        if (rem > 0) {
-               OVS_NLERR("IPv4 tunnel attribute has %d unknown bytes.\n", rem);
+               OVS_NLERR(log, "IPv4 tunnel attribute has %d unknown bytes.",
+                         rem);
                return -EINVAL;
        }
 
        if (!is_mask) {
                if (!match->key->tun_key.ipv4_dst) {
-                       OVS_NLERR("IPv4 tunnel destination address is zero.\n");
+                       OVS_NLERR(log,
+                                 "IPv4 tunnel destination address is zero.");
                        return -EINVAL;
                }
 
                if (!ttl) {
-                       OVS_NLERR("IPv4 tunnel TTL not specified.\n");
+                       OVS_NLERR(log, "IPv4 tunnel TTL not specified.");
                        return -EINVAL;
                }
        }
@@ -612,7 +631,8 @@ int ovs_nla_put_egress_tunnel_key(struct sk_buff *skb,
 }
 
 static int metadata_from_nlattrs(struct sw_flow_match *match,  u64 *attrs,
-                                const struct nlattr **a, bool is_mask)
+                                const struct nlattr **a, bool is_mask,
+                                bool log)
 {
        if (*attrs & (1ULL << OVS_KEY_ATTR_DP_HASH)) {
                u32 hash_val = nla_get_u32(a[OVS_KEY_ATTR_DP_HASH]);
@@ -640,7 +660,8 @@ static int metadata_from_nlattrs(struct sw_flow_match *match,  u64 *attrs,
                if (is_mask) {
                        in_port = 0xffffffff; /* Always exact match in_port. */
                } else if (in_port >= DP_MAX_PORTS) {
-                       OVS_NLERR("Input port (%d) exceeds maximum allowable (%d).\n",
+                       OVS_NLERR(log,
+                                 "Input port (%d) exceeds maximum allowable (%d).",
                                  in_port, DP_MAX_PORTS);
                        return -EINVAL;
                }
@@ -659,7 +680,7 @@ static int metadata_from_nlattrs(struct sw_flow_match *match,  u64 *attrs,
        }
        if (*attrs & (1ULL << OVS_KEY_ATTR_TUNNEL)) {
                if (ipv4_tun_from_nlattr(a[OVS_KEY_ATTR_TUNNEL], match,
-                                        is_mask))
+                                        is_mask, log))
                        return -EINVAL;
                *attrs &= ~(1ULL << OVS_KEY_ATTR_TUNNEL);
        }
@@ -667,11 +688,12 @@ static int metadata_from_nlattrs(struct sw_flow_match *match,  u64 *attrs,
 }
 
 static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
-                               const struct nlattr **a, bool is_mask)
+                               const struct nlattr **a, bool is_mask,
+                               bool log)
 {
        int err;
 
-       err = metadata_from_nlattrs(match, &attrs, a, is_mask);
+       err = metadata_from_nlattrs(match, &attrs, a, is_mask, log);
        if (err)
                return err;
 
@@ -692,9 +714,11 @@ static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
                tci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
                if (!(tci & htons(VLAN_TAG_PRESENT))) {
                        if (is_mask)
-                               OVS_NLERR("VLAN TCI mask does not have exact match for VLAN_TAG_PRESENT bit.\n");
+                               OVS_NLERR(log,
+                                         "VLAN TCI mask does not have exact match for VLAN_TAG_PRESENT bit.");
                        else
-                               OVS_NLERR("VLAN TCI does not have VLAN_TAG_PRESENT bit set.\n");
+                               OVS_NLERR(log,
+                                         "VLAN TCI does not have VLAN_TAG_PRESENT bit set.");
 
                        return -EINVAL;
                }
@@ -711,8 +735,9 @@ static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
                        /* Always exact match EtherType. */
                        eth_type = htons(0xffff);
                } else if (ntohs(eth_type) < ETH_P_802_3_MIN) {
-                       OVS_NLERR("EtherType is less than minimum (type=%x, min=%x).\n",
-                                       ntohs(eth_type), ETH_P_802_3_MIN);
+                       OVS_NLERR(log,
+                                 "EtherType is less than minimum (type=%x, min=%x).",
+                                 ntohs(eth_type), ETH_P_802_3_MIN);
                        return -EINVAL;
                }
 
@@ -727,8 +752,9 @@ static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
 
                ipv4_key = nla_data(a[OVS_KEY_ATTR_IPV4]);
                if (!is_mask && ipv4_key->ipv4_frag > OVS_FRAG_TYPE_MAX) {
-                       OVS_NLERR("Unknown IPv4 fragment type (value=%d, max=%d).\n",
-                               ipv4_key->ipv4_frag, OVS_FRAG_TYPE_MAX);
+                       OVS_NLERR(log,
+                                 "Unknown IPv4 fragment type (value=%d, max=%d).",
+                                 ipv4_key->ipv4_frag, OVS_FRAG_TYPE_MAX);
                        return -EINVAL;
                }
                SW_FLOW_KEY_PUT(match, ip.proto,
@@ -751,12 +777,14 @@ static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
 
                ipv6_key = nla_data(a[OVS_KEY_ATTR_IPV6]);
                if (!is_mask && ipv6_key->ipv6_frag > OVS_FRAG_TYPE_MAX) {
-                       OVS_NLERR("Unknown IPv6 fragment type (value=%d, max=%d).\n",
-                               ipv6_key->ipv6_frag, OVS_FRAG_TYPE_MAX);
+                       OVS_NLERR(log,
+                                 "Unknown IPv6 fragment type (value=%d, max=%d).",
+                                 ipv6_key->ipv6_frag, OVS_FRAG_TYPE_MAX);
                        return -EINVAL;
                }
                if (ipv6_key->ipv6_label & htonl(0xFFF00000)) {
-                       OVS_NLERR("Invalid IPv6 flow label value (value=%x, max=%x).\n",
+                       OVS_NLERR(log,
+                                 "Invalid IPv6 flow label value (value=%x, max=%x).",
                                  ntohl(ipv6_key->ipv6_label), (1 << 20) - 1);
                        return -EINVAL;
                }
@@ -787,7 +815,7 @@ static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
 
                arp_key = nla_data(a[OVS_KEY_ATTR_ARP]);
                if (!is_mask && (arp_key->arp_op & htons(0xff00))) {
-                       OVS_NLERR("Unknown ARP opcode (opcode=%d).\n",
+                       OVS_NLERR(log, "Unknown ARP opcode (opcode=%d).",
                                  arp_key->arp_op);
                        return -EINVAL;
                }
@@ -888,7 +916,7 @@ static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
        }
 
        if (attrs != 0) {
-               OVS_NLERR("Unknown key attributes (%llx).\n",
+               OVS_NLERR(log, "Unknown key attributes (%llx).",
                          (unsigned long long)attrs);
                return -EINVAL;
        }
@@ -929,10 +957,14 @@ static void mask_set_nlattr(struct nlattr *attr, u8 val)
  * of this flow.
  * @mask: Optional. Netlink attribute holding nested %OVS_KEY_ATTR_* Netlink
  * attribute specifies the mask field of the wildcarded flow.
+ * @log: Boolean to allow kernel error logging.  Normally true, but when
+ * probing for feature compatibility this should be passed in as false to
+ * suppress unnecessary error logging.
  */
 int ovs_nla_get_match(struct sw_flow_match *match,
                      const struct nlattr *nla_key,
-                     const struct nlattr *nla_mask)
+                     const struct nlattr *nla_mask,
+                     bool log)
 {
        const struct nlattr *a[OVS_KEY_ATTR_MAX + 1];
        const struct nlattr *encap;
@@ -942,7 +974,7 @@ int ovs_nla_get_match(struct sw_flow_match *match,
        bool encap_valid = false;
        int err;
 
-       err = parse_flow_nlattrs(nla_key, a, &key_attrs);
+       err = parse_flow_nlattrs(nla_key, a, &key_attrs, log);
        if (err)
                return err;
 
@@ -953,7 +985,7 @@ int ovs_nla_get_match(struct sw_flow_match *match,
 
                if (!((key_attrs & (1ULL << OVS_KEY_ATTR_VLAN)) &&
                      (key_attrs & (1ULL << OVS_KEY_ATTR_ENCAP)))) {
-                       OVS_NLERR("Invalid Vlan frame.\n");
+                       OVS_NLERR(log, "Invalid Vlan frame.");
                        return -EINVAL;
                }
 
@@ -964,22 +996,24 @@ int ovs_nla_get_match(struct sw_flow_match *match,
                encap_valid = true;
 
                if (tci & htons(VLAN_TAG_PRESENT)) {
-                       err = parse_flow_nlattrs(encap, a, &key_attrs);
+                       err = parse_flow_nlattrs(encap, a, &key_attrs, log);
                        if (err)
                                return err;
                } else if (!tci) {
                        /* Corner case for truncated 802.1Q header. */
                        if (nla_len(encap)) {
-                               OVS_NLERR("Truncated 802.1Q header has non-zero encap attribute.\n");
+                               OVS_NLERR(log,
+                                         "Truncated 802.1Q header has non-zero encap attribute.");
                                return -EINVAL;
                        }
                } else {
-                       OVS_NLERR("Encap attribute is set for a non-VLAN frame.\n");
+                       OVS_NLERR(log,
+                                 "Encap attribute is set for a non-VLAN frame.");
                        return  -EINVAL;
                }
        }
 
-       err = ovs_key_from_nlattrs(match, key_attrs, a, false);
+       err = ovs_key_from_nlattrs(match, key_attrs, a, false, log);
        if (err)
                return err;
 
@@ -1014,7 +1048,7 @@ int ovs_nla_get_match(struct sw_flow_match *match,
                        nla_mask = newmask;
                }
 
-               err = parse_flow_mask_nlattrs(nla_mask, a, &mask_attrs);
+               err = parse_flow_mask_nlattrs(nla_mask, a, &mask_attrs, log);
                if (err)
                        goto free_newmask;
 
@@ -1026,7 +1060,8 @@ int ovs_nla_get_match(struct sw_flow_match *match,
                        __be16 tci = 0;
 
                        if (!encap_valid) {
-                               OVS_NLERR("Encap mask attribute is set for non-VLAN frame.\n");
+                               OVS_NLERR(log,
+                                         "Encap mask attribute is set for non-VLAN frame.");
                                err = -EINVAL;
                                goto free_newmask;
                        }
@@ -1038,12 +1073,14 @@ int ovs_nla_get_match(struct sw_flow_match *match,
                        if (eth_type == htons(0xffff)) {
                                mask_attrs &= ~(1ULL << OVS_KEY_ATTR_ETHERTYPE);
                                encap = a[OVS_KEY_ATTR_ENCAP];
-                               err = parse_flow_mask_nlattrs(encap, a, &mask_attrs);
+                               err = parse_flow_mask_nlattrs(encap, a,
+                                                             &mask_attrs, log);
                                if (err)
                                        goto free_newmask;
                        } else {
-                               OVS_NLERR("VLAN frames must have an exact match on the TPID (mask=%x).\n",
-                                               ntohs(eth_type));
+                               OVS_NLERR(log,
+                                         "VLAN frames must have an exact match on the TPID (mask=%x).",
+                                         ntohs(eth_type));
                                err = -EINVAL;
                                goto free_newmask;
                        }
@@ -1052,18 +1089,20 @@ int ovs_nla_get_match(struct sw_flow_match *match,
                                tci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
 
                        if (!(tci & htons(VLAN_TAG_PRESENT))) {
-                               OVS_NLERR("VLAN tag present bit must have an exact match (tci_mask=%x).\n", ntohs(tci));
+                               OVS_NLERR(log,
+                                         "VLAN tag present bit must have an exact match (tci_mask=%x).",
+                                         ntohs(tci));
                                err = -EINVAL;
                                goto free_newmask;
                        }
                }
 
-               err = ovs_key_from_nlattrs(match, mask_attrs, a, true);
+               err = ovs_key_from_nlattrs(match, mask_attrs, a, true, log);
                if (err)
                        goto free_newmask;
        }
 
-       if (!match_validate(match, key_attrs, mask_attrs))
+       if (!match_validate(match, key_attrs, mask_attrs, log))
                err = -EINVAL;
 
 free_newmask:
@@ -1076,6 +1115,9 @@ free_newmask:
  * @key: Receives extracted in_port, priority, tun_key and skb_mark.
  * @attr: Netlink attribute holding nested %OVS_KEY_ATTR_* Netlink attribute
  * sequence.
+ * @log: Boolean to allow kernel error logging.  Normally true, but when
+ * probing for feature compatibility this should be passed in as false to
+ * suppress unnecessary error logging.
  *
  * This parses a series of Netlink attributes that form a flow key, which must
  * take the same form accepted by flow_from_nlattrs(), but only enough of it to
@@ -1083,14 +1125,15 @@ free_newmask:
  * extracted from the packet itself.
  */
 int ovs_nla_get_flow_metadata(const struct nlattr *attr,
-                             struct sw_flow_key *key)
+                             struct sw_flow_key *key,
+                             bool log)
 {
        const struct nlattr *a[OVS_KEY_ATTR_MAX + 1];
        struct sw_flow_match match;
        u64 attrs = 0;
        int err;
 
-       err = parse_flow_nlattrs(attr, a, &attrs);
+       err = parse_flow_nlattrs(attr, a, &attrs, log);
        if (err)
                return -EINVAL;
 
@@ -1100,7 +1143,7 @@ int ovs_nla_get_flow_metadata(const struct nlattr *attr,
        memset(key, 0, OVS_SW_FLOW_KEY_METADATA_SIZE);
        key->phy.in_port = DP_MAX_PORTS;
 
-       return metadata_from_nlattrs(&match, &attrs, a, false);
+       return metadata_from_nlattrs(&match, &attrs, a, false, log);
 }
 
 int ovs_nla_put_flow(const struct sw_flow_key *swkey,
@@ -1320,13 +1363,13 @@ nla_put_failure:
 
 #define MAX_ACTIONS_BUFSIZE    (32 * 1024)
 
-static struct sw_flow_actions *nla_alloc_flow_actions(int size)
+static struct sw_flow_actions *nla_alloc_flow_actions(int size, bool log)
 {
        struct sw_flow_actions *sfa;
 
        if (size > MAX_ACTIONS_BUFSIZE) {
-               OVS_NLERR("Flow action size (%u bytes) exceeds maximum "
-                         "(%u bytes)\n", size, MAX_ACTIONS_BUFSIZE);
+               OVS_NLERR(log, "Flow action size (%u bytes) exceeds maximum "
+                         "(%u bytes)", size, MAX_ACTIONS_BUFSIZE);
                return ERR_PTR(-EINVAL);
        }
 
@@ -1347,14 +1390,15 @@ static void rcu_free_acts_callback(struct rcu_head *rcu)
 }
 
 /* Schedules 'sf_acts' to be freed after the next RCU grace period.
- * The caller must hold rcu_read_lock for this to be sensible. */
+ * The caller must hold rcu_read_lock for this to be sensible.
+ */
 void ovs_nla_free_flow_actions(struct sw_flow_actions *sf_acts)
 {
        call_rcu(&sf_acts->rcu, rcu_free_acts_callback);
 }
 
 static struct nlattr *reserve_sfa_size(struct sw_flow_actions **sfa,
-                                      int attr_len)
+                                      int attr_len, bool log)
 {
 
        struct sw_flow_actions *acts;
@@ -1374,7 +1418,7 @@ static struct nlattr *reserve_sfa_size(struct sw_flow_actions **sfa,
                new_acts_size = MAX_ACTIONS_BUFSIZE;
        }
 
-       acts = nla_alloc_flow_actions(new_acts_size);
+       acts = nla_alloc_flow_actions(new_acts_size, log);
        if (IS_ERR(acts))
                return (void *)acts;
 
@@ -1389,11 +1433,11 @@ out:
 }
 
 static struct nlattr *__add_action(struct sw_flow_actions **sfa, int attrtype,
-                                  void *data, int len)
+                                  void *data, int len, bool log)
 {
        struct nlattr *a;
 
-       a = reserve_sfa_size(sfa, nla_attr_size(len));
+       a = reserve_sfa_size(sfa, nla_attr_size(len), log);
        if (IS_ERR(a))
                return a;
 
@@ -1408,11 +1452,11 @@ static struct nlattr *__add_action(struct sw_flow_actions **sfa, int attrtype,
 }
 
 static int add_action(struct sw_flow_actions **sfa, int attrtype,
-                     void *data, int len)
+                     void *data, int len, bool log)
 {
        struct nlattr *a;
 
-       a = __add_action(sfa, attrtype, data, len);
+       a = __add_action(sfa, attrtype, data, len, log);
        if (IS_ERR(a))
                return PTR_ERR(a);
 
@@ -1420,12 +1464,12 @@ static int add_action(struct sw_flow_actions **sfa, int attrtype,
 }
 
 static inline int add_nested_action_start(struct sw_flow_actions **sfa,
-                                         int attrtype)
+                                         int attrtype, bool log)
 {
        int used = (*sfa)->actions_len;
        int err;
 
-       err = add_action(sfa, attrtype, NULL, 0);
+       err = add_action(sfa, attrtype, NULL, 0, log);
        if (err)
                return err;
 
@@ -1444,12 +1488,12 @@ static inline void add_nested_action_end(struct sw_flow_actions *sfa,
 static int __ovs_nla_copy_actions(const struct nlattr *attr,
                                  const struct sw_flow_key *key,
                                  int depth, struct sw_flow_actions **sfa,
-                                 __be16 eth_type, __be16 vlan_tci);
+                                 __be16 eth_type, __be16 vlan_tci, bool log);
 
 static int validate_and_copy_sample(const struct nlattr *attr,
                                    const struct sw_flow_key *key, int depth,
                                    struct sw_flow_actions **sfa,
-                                   __be16 eth_type, __be16 vlan_tci)
+                                   __be16 eth_type, __be16 vlan_tci, bool log)
 {
        const struct nlattr *attrs[OVS_SAMPLE_ATTR_MAX + 1];
        const struct nlattr *probability, *actions;
@@ -1475,19 +1519,19 @@ static int validate_and_copy_sample(const struct nlattr *attr,
                return -EINVAL;
 
        /* validation done, copy sample action. */
-       start = add_nested_action_start(sfa, OVS_ACTION_ATTR_SAMPLE);
+       start = add_nested_action_start(sfa, OVS_ACTION_ATTR_SAMPLE, log);
        if (start < 0)
                return start;
        err = add_action(sfa, OVS_SAMPLE_ATTR_PROBABILITY,
-                        nla_data(probability), sizeof(u32));
+                        nla_data(probability), sizeof(u32), log);
        if (err)
                return err;
-       st_acts = add_nested_action_start(sfa, OVS_SAMPLE_ATTR_ACTIONS);
+       st_acts = add_nested_action_start(sfa, OVS_SAMPLE_ATTR_ACTIONS, log);
        if (st_acts < 0)
                return st_acts;
 
        err = __ovs_nla_copy_actions(actions, key, depth + 1, sfa,
-                                    eth_type, vlan_tci);
+                                    eth_type, vlan_tci, log);
        if (err)
                return err;
 
@@ -1524,7 +1568,7 @@ void ovs_match_init(struct sw_flow_match *match,
 }
 
 static int validate_and_copy_set_tun(const struct nlattr *attr,
-                                    struct sw_flow_actions **sfa)
+                                    struct sw_flow_actions **sfa, bool log)
 {
        struct sw_flow_match match;
        struct sw_flow_key key;
@@ -1533,7 +1577,7 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
        int err, start;
 
        ovs_match_init(&match, &key, NULL);
-       err = ipv4_tun_from_nlattr(nla_data(attr), &match, false);
+       err = ipv4_tun_from_nlattr(nla_data(attr), &match, false, log);
        if (err)
                return err;
 
@@ -1562,12 +1606,12 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
                key.tun_key.tun_flags |= crit_opt ? TUNNEL_CRIT_OPT : 0;
        };
 
-       start = add_nested_action_start(sfa, OVS_ACTION_ATTR_SET);
+       start = add_nested_action_start(sfa, OVS_ACTION_ATTR_SET, log);
        if (start < 0)
                return start;
 
        a = __add_action(sfa, OVS_KEY_ATTR_TUNNEL_INFO, NULL,
-                       sizeof(*tun_info) + key.tun_opts_len);
+                        sizeof(*tun_info) + key.tun_opts_len, log);
        if (IS_ERR(a))
                return PTR_ERR(a);
 
@@ -1580,9 +1624,9 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
                 * everything else will go away after flow setup. We can append
                 * it to tun_info and then point there.
                 */
-               tun_info->options = (struct geneve_opt *)(tun_info + 1);
-               memcpy(tun_info->options, GENEVE_OPTS(&key, key.tun_opts_len),
+               memcpy((tun_info + 1), GENEVE_OPTS(&key, key.tun_opts_len),
                        key.tun_opts_len);
+               tun_info->options = (struct geneve_opt *)(tun_info + 1);
        } else {
                tun_info->options = NULL;
        }
@@ -1595,7 +1639,7 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
 static int validate_set(const struct nlattr *a,
                        const struct sw_flow_key *flow_key,
                        struct sw_flow_actions **sfa,
-                       bool *set_tun, __be16 eth_type)
+                       bool *set_tun, __be16 eth_type, bool log)
 {
        const struct nlattr *ovs_key = nla_data(a);
        int key_type = nla_type(ovs_key);
@@ -1620,8 +1664,11 @@ static int validate_set(const struct nlattr *a,
                break;
 
        case OVS_KEY_ATTR_TUNNEL:
+               if (eth_p_mpls(eth_type))
+                       return -EINVAL;
+
                *set_tun = true;
-               err = validate_and_copy_set_tun(a, sfa);
+               err = validate_and_copy_set_tun(a, sfa, log);
                if (err)
                        return err;
                break;
@@ -1714,12 +1761,12 @@ static int validate_userspace(const struct nlattr *attr)
 }
 
 static int copy_action(const struct nlattr *from,
-                      struct sw_flow_actions **sfa)
+                      struct sw_flow_actions **sfa, bool log)
 {
        int totlen = NLA_ALIGN(from->nla_len);
        struct nlattr *to;
 
-       to = reserve_sfa_size(sfa, from->nla_len);
+       to = reserve_sfa_size(sfa, from->nla_len, log);
        if (IS_ERR(to))
                return PTR_ERR(to);
 
@@ -1730,9 +1777,10 @@ static int copy_action(const struct nlattr *from,
 static int __ovs_nla_copy_actions(const struct nlattr *attr,
                                  const struct sw_flow_key *key,
                                  int depth, struct sw_flow_actions **sfa,
-                                 __be16 eth_type, __be16 vlan_tci)
+                                 __be16 eth_type, __be16 vlan_tci, bool log)
 {
        const struct nlattr *a;
+       bool out_tnl_port = false;
        int rem, err;
 
        if (depth >= SAMPLE_ACTION_DEPTH)
@@ -1775,6 +1823,7 @@ static int __ovs_nla_copy_actions(const struct nlattr *attr,
                case OVS_ACTION_ATTR_OUTPUT:
                        if (nla_get_u32(a) >= DP_MAX_PORTS)
                                return -EINVAL;
+                       out_tnl_port = false;
                        break;
 
                case OVS_ACTION_ATTR_HASH: {
@@ -1809,6 +1858,12 @@ static int __ovs_nla_copy_actions(const struct nlattr *attr,
                case OVS_ACTION_ATTR_PUSH_MPLS: {
                        const struct ovs_action_push_mpls *mpls = nla_data(a);
 
+                       /* Networking stack do not allow simultaneous Tunnel
+                        * and MPLS GSO.
+                        */
+                       if (out_tnl_port)
+                               return -EINVAL;
+
                        if (!eth_p_mpls(mpls->mpls_ethertype))
                                return -EINVAL;
                        /* Prohibit push MPLS other than to a white list
@@ -1843,14 +1898,16 @@ static int __ovs_nla_copy_actions(const struct nlattr *attr,
                        break;
 
                case OVS_ACTION_ATTR_SET:
-                       err = validate_set(a, key, sfa, &skip_copy, eth_type);
+                       err = validate_set(a, key, sfa,
+                                          &out_tnl_port, eth_type, log);
                        if (err)
                                return err;
+                       skip_copy = out_tnl_port;
                        break;
 
                case OVS_ACTION_ATTR_SAMPLE:
                        err = validate_and_copy_sample(a, key, depth, sfa,
-                                                      eth_type, vlan_tci);
+                                                      eth_type, vlan_tci, log);
                        if (err)
                                return err;
                        skip_copy = true;
@@ -1860,7 +1917,7 @@ static int __ovs_nla_copy_actions(const struct nlattr *attr,
                        return -EINVAL;
                }
                if (!skip_copy) {
-                       err = copy_action(a, sfa);
+                       err = copy_action(a, sfa, log);
                        if (err)
                                return err;
                }
@@ -1874,16 +1931,16 @@ static int __ovs_nla_copy_actions(const struct nlattr *attr,
 
 int ovs_nla_copy_actions(const struct nlattr *attr,
                         const struct sw_flow_key *key,
-                        struct sw_flow_actions **sfa)
+                        struct sw_flow_actions **sfa, bool log)
 {
        int err;
 
-       *sfa = nla_alloc_flow_actions(nla_len(attr));
+       *sfa = nla_alloc_flow_actions(nla_len(attr), log);
        if (IS_ERR(*sfa))
                return PTR_ERR(*sfa);
 
        err = __ovs_nla_copy_actions(attr, key, 0, sfa, key->eth.type,
-                                    key->eth.tci);
+                                    key->eth.tci, log);
        if (err)
                kfree(*sfa);