Make OVS_TUNNEL_ATTR_DST_IPV4 and OVS_TUNNEL_ATTR_FLAGS optional to allow configuration of null_ports.
Existing code in userspace still always sets the flags, as they are needed internally. Signed-off-by: Jarno Rajahalme <jarno.rajaha...@nsn.com> --- datapath/tunnel.c | 18 ++++++++++++------ include/openvswitch/tunnel.h | 7 ++++--- lib/netdev-vport.c | 26 ++++++++++++-------------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/datapath/tunnel.c b/datapath/tunnel.c index 1db60d2..66ed9e5 100644 --- a/datapath/tunnel.c +++ b/datapath/tunnel.c @@ -1066,11 +1066,15 @@ 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_FLAGS]) + mutable->flags = nla_get_u32(a[OVS_TUNNEL_ATTR_FLAGS]) + & TNL_F_PUBLIC; + else + mutable->flags = 0; - 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_DST_IPV4]) { + mutable->key.daddr = nla_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]); + } if (a[OVS_TUNNEL_ATTR_SRC_IPV4]) { if (ipv4_is_multicast(mutable->key.daddr)) @@ -1230,8 +1234,7 @@ int ovs_tnl_get_options(const struct vport *vport, struct sk_buff *skb) const struct tnl_mutable_config *mutable = rcu_dereference_rtnl(tnl_vport->mutable); 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) && @@ -1240,6 +1243,9 @@ int ovs_tnl_get_options(const struct vport *vport, struct sk_buff *skb) if (!(mutable->flags & TNL_F_OUT_KEY_ACTION) && nla_put_be64(skb, OVS_TUNNEL_ATTR_OUT_KEY, mutable->out_key)) goto nla_put_failure; + if (mutable->key.daddr && + nla_put_be32(skb, OVS_TUNNEL_ATTR_DST_IPV4, mutable->key.daddr)) + goto nla_put_failure; if (mutable->key.saddr && nla_put_be32(skb, OVS_TUNNEL_ATTR_SRC_IPV4, mutable->key.saddr)) goto nla_put_failure; diff --git a/include/openvswitch/tunnel.h b/include/openvswitch/tunnel.h index 23d8ba7..fd8fd08 100644 --- a/include/openvswitch/tunnel.h +++ b/include/openvswitch/tunnel.h @@ -45,14 +45,15 @@ /* OVS_VPORT_ATTR_OPTIONS attributes for tunnels. * - * OVS_TUNNEL_ATTR_FLAGS and OVS_TUNNEL_ATTR_DST_IPV4 are required. All other + * OVS_TUNNEL_ATTR_FLAGS and OVS_TUNNEL_ATTR_DST_IPV4 are required for + * kernel tunnel ports, but not for flow-based tunnels. All other * attributes are optional. */ enum { OVS_TUNNEL_ATTR_UNSPEC, OVS_TUNNEL_ATTR_FLAGS, /* 32-bit TNL_F_*. */ - OVS_TUNNEL_ATTR_DST_IPV4, /* IPv4 destination address. */ - OVS_TUNNEL_ATTR_SRC_IPV4, /* IPv4 source address. */ + OVS_TUNNEL_ATTR_DST_IPV4, /* remote IPv4 address. */ + OVS_TUNNEL_ATTR_SRC_IPV4, /* local IPv4 address. */ OVS_TUNNEL_ATTR_OUT_KEY, /* __be64 key to use on output. */ OVS_TUNNEL_ATTR_IN_KEY, /* __be64 key to match on input. */ OVS_TUNNEL_ATTR_TOS, /* 8-bit TOS value. */ diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c index 032cd3d..bb7346f 100644 --- a/lib/netdev-vport.c +++ b/lib/netdev-vport.c @@ -547,12 +547,13 @@ netdev_vport_get_tnl_iface(const struct netdev *netdev) a)) { return NULL; } - route = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]); + if (a[OVS_TUNNEL_ATTR_DST_IPV4]) { + route = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]); - if (route_table_get_name(route, name)) { - return name; + if (route_table_get_name(route, name)) { + return name; + } } - return NULL; } @@ -752,12 +753,9 @@ parse_tunnel_config(const char *name, const char *type, set_key(args, "in_key", OVS_TUNNEL_ATTR_IN_KEY, options); set_key(args, "out_key", OVS_TUNNEL_ATTR_OUT_KEY, options); - if (!daddr) { - VLOG_ERR("%s: %s type requires valid 'remote_ip' argument", - name, type); - return EINVAL; + if (daddr) { + nl_msg_put_be32(options, OVS_TUNNEL_ATTR_DST_IPV4, daddr); } - nl_msg_put_be32(options, OVS_TUNNEL_ATTR_DST_IPV4, daddr); if (saddr) { if (ip_is_multicast(daddr)) { @@ -778,7 +776,7 @@ tnl_port_config_from_nlattr(const struct nlattr *options, size_t options_len, { static const struct nl_policy ovs_tunnel_policy[] = { [OVS_TUNNEL_ATTR_FLAGS] = { .type = NL_A_U32 }, - [OVS_TUNNEL_ATTR_DST_IPV4] = { .type = NL_A_BE32 }, + [OVS_TUNNEL_ATTR_DST_IPV4] = { .type = NL_A_BE32, .optional = true }, [OVS_TUNNEL_ATTR_SRC_IPV4] = { .type = NL_A_BE32, .optional = true }, [OVS_TUNNEL_ATTR_IN_KEY] = { .type = NL_A_BE64, .optional = true }, [OVS_TUNNEL_ATTR_OUT_KEY] = { .type = NL_A_BE64, .optional = true }, @@ -808,7 +806,6 @@ unparse_tunnel_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED, struct smap *args) { struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1]; - ovs_be32 daddr; uint32_t flags; int error; @@ -817,9 +814,10 @@ unparse_tunnel_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED, return error; } - - daddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]); - smap_add_format(args, "remote_ip", IP_FMT, IP_ARGS(&daddr)); + if (a[OVS_TUNNEL_ATTR_DST_IPV4]) { + ovs_be32 daddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]); + smap_add_format(args, "remote_ip", IP_FMT, IP_ARGS(&daddr)); + } if (a[OVS_TUNNEL_ATTR_SRC_IPV4]) { ovs_be32 saddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_SRC_IPV4]); -- 1.7.10.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev