Make OVS_TUNNEL_ATTR_DST_IPV4 optional to allow configuration of null_ports.
[cascardo/ovs.git] / datapath / tunnel.c
index 0a9bb37..470461a 100644 (file)
@@ -1066,11 +1066,16 @@ static int tnl_set_config(struct net *net, struct nlattr *options,
        if (err)
                return err;
 
-       if (!a[OVS_TUNNEL_ATTR_FLAGS] || !a[OVS_TUNNEL_ATTR_DST_IPV4])
-               return -EINVAL;
+       if (a[OVS_TUNNEL_ATTR_DST_IPV4])
+               mutable->key.daddr = nla_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
+
+       /* Skip the rest if configuring a null_port */
+       if (!mutable->key.daddr)
+               goto out;
 
-       mutable->flags = nla_get_u32(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_PUBLIC;
-       mutable->key.daddr = nla_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
+       if (a[OVS_TUNNEL_ATTR_FLAGS])
+               mutable->flags = nla_get_u32(a[OVS_TUNNEL_ATTR_FLAGS])
+                       & TNL_F_PUBLIC;
 
        if (a[OVS_TUNNEL_ATTR_SRC_IPV4]) {
                if (ipv4_is_multicast(mutable->key.daddr))
@@ -1225,11 +1230,15 @@ int ovs_tnl_get_options(const struct vport *vport, struct sk_buff *skb)
        const struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
        const struct tnl_mutable_config *mutable = rcu_dereference_rtnl(tnl_vport->mutable);
 
+       /* Skip the rest for null_ports */
+       if (!mutable->key.daddr)
+               return 0;
+
+       if (nla_put_be32(skb, OVS_TUNNEL_ATTR_DST_IPV4, mutable->key.daddr))
+               goto nla_put_failure;
        if (nla_put_u32(skb, OVS_TUNNEL_ATTR_FLAGS,
-                     mutable->flags & TNL_F_PUBLIC) ||
-           nla_put_be32(skb, OVS_TUNNEL_ATTR_DST_IPV4, mutable->key.daddr))
+                       mutable->flags & TNL_F_PUBLIC))
                goto nla_put_failure;
-
        if (!(mutable->flags & TNL_F_IN_KEY_MATCH) &&
            nla_put_be64(skb, OVS_TUNNEL_ATTR_IN_KEY, mutable->key.in_key))
                goto nla_put_failure;