#include "tunnel.h"
#include "vlan.h"
#include "vport.h"
-#include "vport-generic.h"
#include "vport-internal_dev.h"
#define PORT_TABLE_SIZE 1024
if (null_ports) {
lookup.daddr = 0;
lookup.saddr = 0;
+ lookup.in_key = 0;
lookup.tunnel_type = tunnel_type;
vport = port_table_lookup(&lookup, mutable);
if (vport)
if (OVS_CB(skb)->tun_key->ipv4_dst) {
df_inherit = false;
pmtud = false;
- frag_off = OVS_CB(skb)->tun_key->tun_flags & OVS_FLOW_TNL_F_DONT_FRAGMENT ?
+ frag_off = OVS_CB(skb)->tun_key->tun_flags & OVS_TNL_F_DONT_FRAGMENT ?
htons(IP_DF) : 0;
} else {
df_inherit = mutable->flags & TNL_F_DF_INHERIT;
return true;
}
-static struct rtable *find_route(const struct tnl_mutable_config *mutable,
- __be32 saddr, __be32 daddr, u8 ipproto,
- u8 tos)
+static struct rtable *find_route(struct net *net,
+ __be32 *saddr, __be32 daddr, u8 ipproto,
+ u8 tos)
{
+ struct rtable *rt;
/* Tunnel configuration keeps DSCP part of TOS bits, But Linux
* router expect RT_TOS bits only. */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)
struct flowi fl = { .nl_u = { .ip4_u = {
.daddr = daddr,
- .saddr = saddr,
+ .saddr = *saddr,
.tos = RT_TOS(tos) } },
.proto = ipproto };
- struct rtable *rt;
- if (unlikely(ip_route_output_key(port_key_get_net(&mutable->key), &rt, &fl)))
+ if (unlikely(ip_route_output_key(net, &rt, &fl)))
return ERR_PTR(-EADDRNOTAVAIL);
-
+ *saddr = fl.nl_u.ip4_u.saddr;
return rt;
#else
struct flowi4 fl = { .daddr = daddr,
- .saddr = saddr,
+ .saddr = *saddr,
.flowi4_tos = RT_TOS(tos),
.flowi4_proto = ipproto };
- return ip_route_output_key(port_key_get_net(&mutable->key), &fl);
+ rt = ip_route_output_key(net, &fl);
+ *saddr = fl.saddr;
+ return rt;
#endif
}
}
/* Route lookup */
- rt = find_route(mutable, saddr, daddr, tnl_vport->tnl_ops->ipproto, tos);
+ rt = find_route(port_key_get_net(&mutable->key), &saddr, daddr,
+ tnl_vport->tnl_ops->ipproto, tos);
if (IS_ERR(rt))
goto error_free;
iph->version = 4;
iph->ihl = sizeof(struct iphdr) >> 2;
iph->protocol = tnl_vport->tnl_ops->ipproto;
- iph->daddr = rt->rt_dst;
- iph->saddr = rt->rt_src;
+ iph->daddr = daddr;
+ iph->saddr = saddr;
iph->tos = tos;
iph->ttl = ttl;
iph->frag_off = frag_off;
[OVS_TUNNEL_ATTR_IN_KEY] = { .type = NLA_U64 },
[OVS_TUNNEL_ATTR_TOS] = { .type = NLA_U8 },
[OVS_TUNNEL_ATTR_TTL] = { .type = NLA_U8 },
+ [OVS_TUNNEL_ATTR_DST_PORT] = { .type = NLA_U16 },
};
/* Sets OVS_TUNNEL_ATTR_* fields in 'mutable', which must initially be
if (err)
return err;
- if (!a[OVS_TUNNEL_ATTR_FLAGS] || !a[OVS_TUNNEL_ATTR_DST_IPV4])
- return -EINVAL;
+ /* Process attributes possibly useful for null_ports first */
+ if (a[OVS_TUNNEL_ATTR_DST_PORT])
+ mutable->dst_port =
+ htons(nla_get_u16(a[OVS_TUNNEL_ATTR_DST_PORT]));
+
+ if (a[OVS_TUNNEL_ATTR_DST_IPV4])
+ mutable->key.daddr = nla_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
- 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]);
+ /* Skip the rest if configuring a null_port */
+ if (!mutable->key.daddr)
+ goto out;
+
+ 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))
if (ipv4_is_multicast(mutable->key.daddr)) {
struct net_device *dev;
struct rtable *rt;
+ __be32 saddr = mutable->key.saddr;
- rt = find_route(mutable, mutable->key.saddr, mutable->key.daddr,
- tnl_ops->ipproto, mutable->tos);
+ rt = find_route(port_key_get_net(&mutable->key),
+ &saddr, mutable->key.daddr,
+ tnl_ops->ipproto, mutable->tos);
if (IS_ERR(rt))
return -EADDRNOTAVAIL;
dev = rt_dst(rt).dev;
const struct tnl_vport *tnl_vport = tnl_vport_priv(vport);
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))
+ if (mutable->dst_port && nla_put_u16(skb, OVS_TUNNEL_ATTR_DST_PORT,
+ ntohs(mutable->dst_port)))
goto nla_put_failure;
+ /* 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))
+ 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;