2009-07-08 13:19:16 -07:00
|
|
|
/*
|
|
|
|
* Distributed under the terms of the GNU GPL version 2.
|
2011-01-12 10:44:43 -08:00
|
|
|
* Copyright (c) 2007, 2008, 2009, 2010, 2011 Nicira Networks.
|
2009-06-15 15:11:30 -07:00
|
|
|
*
|
|
|
|
* Significant portions of this file may be copied from parts of the Linux
|
|
|
|
* kernel, by Linus Torvalds and others.
|
2009-07-08 13:19:16 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "flow.h"
|
2010-03-04 17:55:44 -05:00
|
|
|
#include "datapath.h"
|
2011-01-23 18:44:44 -08:00
|
|
|
#include <asm/uaccess.h>
|
2009-07-08 13:19:16 -07:00
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/if_ether.h>
|
|
|
|
#include <linux/if_vlan.h>
|
|
|
|
#include <net/llc_pdu.h>
|
|
|
|
#include <linux/kernel.h>
|
2010-04-02 16:46:18 -04:00
|
|
|
#include <linux/jhash.h>
|
2009-07-08 13:19:16 -07:00
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/llc.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/rcupdate.h>
|
2009-07-16 12:58:28 -07:00
|
|
|
#include <linux/if_arp.h>
|
2009-07-08 13:19:16 -07:00
|
|
|
#include <linux/if_ether.h>
|
|
|
|
#include <linux/ip.h>
|
2010-12-29 19:03:46 -08:00
|
|
|
#include <linux/ipv6.h>
|
2009-07-08 13:19:16 -07:00
|
|
|
#include <linux/tcp.h>
|
|
|
|
#include <linux/udp.h>
|
|
|
|
#include <linux/icmp.h>
|
2010-12-29 19:03:46 -08:00
|
|
|
#include <linux/icmpv6.h>
|
2011-09-09 19:09:47 -07:00
|
|
|
#include <linux/rculist.h>
|
2010-03-12 16:05:25 -05:00
|
|
|
#include <net/inet_ecn.h>
|
2009-07-08 13:19:16 -07:00
|
|
|
#include <net/ip.h>
|
2010-12-29 19:03:46 -08:00
|
|
|
#include <net/ipv6.h>
|
2011-02-01 22:54:11 -08:00
|
|
|
#include <net/ndisc.h>
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2010-12-29 22:13:15 -08:00
|
|
|
#include "vlan.h"
|
|
|
|
|
2010-12-04 13:52:25 -08:00
|
|
|
static struct kmem_cache *flow_cache;
|
2010-11-23 16:34:22 -08:00
|
|
|
static unsigned int hash_seed __read_mostly;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2011-05-10 11:48:36 -07:00
|
|
|
static int check_header(struct sk_buff *skb, int len)
|
|
|
|
{
|
|
|
|
if (unlikely(skb->len < len))
|
|
|
|
return -EINVAL;
|
|
|
|
if (unlikely(!pskb_may_pull(skb, len)))
|
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-13 10:18:28 -07:00
|
|
|
static inline bool arphdr_ok(struct sk_buff *skb)
|
2009-07-16 12:58:28 -07:00
|
|
|
{
|
2011-05-10 11:48:36 -07:00
|
|
|
return pskb_may_pull(skb, skb_network_offset(skb) +
|
|
|
|
sizeof(struct arp_eth_header));
|
2009-07-16 12:58:28 -07:00
|
|
|
}
|
|
|
|
|
2010-08-27 12:32:05 -07:00
|
|
|
static inline int check_iphdr(struct sk_buff *skb)
|
2009-07-08 13:19:16 -07:00
|
|
|
{
|
2010-08-27 12:32:05 -07:00
|
|
|
unsigned int nh_ofs = skb_network_offset(skb);
|
|
|
|
unsigned int ip_len;
|
2011-05-10 11:48:36 -07:00
|
|
|
int err;
|
2010-08-27 12:32:05 -07:00
|
|
|
|
2011-05-10 11:48:36 -07:00
|
|
|
err = check_header(skb, nh_ofs + sizeof(struct iphdr));
|
|
|
|
if (unlikely(err))
|
|
|
|
return err;
|
2010-08-27 12:32:05 -07:00
|
|
|
|
|
|
|
ip_len = ip_hdrlen(skb);
|
2011-05-10 11:48:36 -07:00
|
|
|
if (unlikely(ip_len < sizeof(struct iphdr) ||
|
|
|
|
skb->len < nh_ofs + ip_len))
|
2010-08-27 12:32:05 -07:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
skb_set_transport_header(skb, nh_ofs + ip_len);
|
|
|
|
return 0;
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
|
2010-08-13 10:18:28 -07:00
|
|
|
static inline bool tcphdr_ok(struct sk_buff *skb)
|
2009-07-08 13:19:16 -07:00
|
|
|
{
|
|
|
|
int th_ofs = skb_transport_offset(skb);
|
2011-05-10 11:48:36 -07:00
|
|
|
int tcp_len;
|
|
|
|
|
|
|
|
if (unlikely(!pskb_may_pull(skb, th_ofs + sizeof(struct tcphdr))))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
tcp_len = tcp_hdrlen(skb);
|
|
|
|
if (unlikely(tcp_len < sizeof(struct tcphdr) ||
|
|
|
|
skb->len < th_ofs + tcp_len))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
|
2010-08-13 10:18:28 -07:00
|
|
|
static inline bool udphdr_ok(struct sk_buff *skb)
|
2009-07-08 13:19:16 -07:00
|
|
|
{
|
2011-05-10 11:48:36 -07:00
|
|
|
return pskb_may_pull(skb, skb_transport_offset(skb) +
|
|
|
|
sizeof(struct udphdr));
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
|
2010-08-13 10:18:28 -07:00
|
|
|
static inline bool icmphdr_ok(struct sk_buff *skb)
|
2009-07-08 13:19:16 -07:00
|
|
|
{
|
2011-05-10 11:48:36 -07:00
|
|
|
return pskb_may_pull(skb, skb_transport_offset(skb) +
|
|
|
|
sizeof(struct icmphdr));
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
|
2011-01-29 14:11:23 -08:00
|
|
|
u64 flow_used_time(unsigned long flow_jiffies)
|
|
|
|
{
|
|
|
|
struct timespec cur_ts;
|
|
|
|
u64 cur_ms, idle_ms;
|
|
|
|
|
|
|
|
ktime_get_ts(&cur_ts);
|
|
|
|
idle_ms = jiffies_to_msecs(jiffies - flow_jiffies);
|
|
|
|
cur_ms = (u64)cur_ts.tv_sec * MSEC_PER_SEC +
|
|
|
|
cur_ts.tv_nsec / NSEC_PER_MSEC;
|
|
|
|
|
|
|
|
return cur_ms - idle_ms;
|
|
|
|
}
|
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
#define SW_FLOW_KEY_OFFSET(field) \
|
|
|
|
offsetof(struct sw_flow_key, field) + \
|
|
|
|
FIELD_SIZEOF(struct sw_flow_key, field)
|
|
|
|
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
/**
|
|
|
|
* skip_exthdr - skip any IPv6 extension headers
|
|
|
|
* @skb: skbuff to parse
|
|
|
|
* @start: offset of first extension header
|
|
|
|
* @nexthdrp: Initially, points to the type of the extension header at @start.
|
|
|
|
* This function updates it to point to the extension header at the final
|
|
|
|
* offset.
|
|
|
|
* @tos_frag: Points to the @tos_frag member in a &struct sw_flow_key. This
|
|
|
|
* function sets an appropriate %OVS_FRAG_TYPE_* value.
|
|
|
|
*
|
|
|
|
* This is based on ipv6_skip_exthdr() but adds the updates to *@tos_frag.
|
|
|
|
*
|
|
|
|
* When there is more than one fragment header, this version reports whether
|
|
|
|
* the final fragment header that it examines is a first fragment.
|
|
|
|
*
|
|
|
|
* Returns the final payload offset, or -1 on error.
|
|
|
|
*/
|
|
|
|
static int skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp,
|
|
|
|
u8 *tos_frag)
|
|
|
|
{
|
|
|
|
u8 nexthdr = *nexthdrp;
|
|
|
|
|
|
|
|
while (ipv6_ext_hdr(nexthdr)) {
|
|
|
|
struct ipv6_opt_hdr _hdr, *hp;
|
|
|
|
int hdrlen;
|
|
|
|
|
|
|
|
if (nexthdr == NEXTHDR_NONE)
|
|
|
|
return -1;
|
|
|
|
hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr);
|
|
|
|
if (hp == NULL)
|
|
|
|
return -1;
|
|
|
|
if (nexthdr == NEXTHDR_FRAGMENT) {
|
|
|
|
__be16 _frag_off, *fp;
|
|
|
|
fp = skb_header_pointer(skb,
|
|
|
|
start+offsetof(struct frag_hdr,
|
|
|
|
frag_off),
|
|
|
|
sizeof(_frag_off),
|
|
|
|
&_frag_off);
|
|
|
|
if (fp == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*tos_frag &= ~OVS_FRAG_TYPE_MASK;
|
|
|
|
if (ntohs(*fp) & ~0x7) {
|
|
|
|
*tos_frag |= OVS_FRAG_TYPE_LATER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*tos_frag |= OVS_FRAG_TYPE_FIRST;
|
|
|
|
hdrlen = 8;
|
|
|
|
} else if (nexthdr == NEXTHDR_AUTH)
|
|
|
|
hdrlen = (hp->hdrlen+2)<<2;
|
|
|
|
else
|
|
|
|
hdrlen = ipv6_optlen(hp);
|
|
|
|
|
|
|
|
nexthdr = hp->nexthdr;
|
|
|
|
start += hdrlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
*nexthdrp = nexthdr;
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
static int parse_ipv6hdr(struct sk_buff *skb, struct sw_flow_key *key,
|
|
|
|
int *key_lenp)
|
2010-12-29 19:03:46 -08:00
|
|
|
{
|
|
|
|
unsigned int nh_ofs = skb_network_offset(skb);
|
|
|
|
unsigned int nh_len;
|
|
|
|
int payload_ofs;
|
|
|
|
struct ipv6hdr *nh;
|
|
|
|
uint8_t nexthdr;
|
2011-05-10 11:48:36 -07:00
|
|
|
int err;
|
2010-12-29 19:03:46 -08:00
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
*key_lenp = SW_FLOW_KEY_OFFSET(ipv6.addr);
|
|
|
|
|
2011-05-10 11:48:36 -07:00
|
|
|
err = check_header(skb, nh_ofs + sizeof(*nh));
|
|
|
|
if (unlikely(err))
|
|
|
|
return err;
|
2010-12-29 19:03:46 -08:00
|
|
|
|
|
|
|
nh = ipv6_hdr(skb);
|
|
|
|
nexthdr = nh->nexthdr;
|
|
|
|
payload_ofs = (u8 *)(nh + 1) - skb->data;
|
|
|
|
|
2011-06-08 12:28:57 -07:00
|
|
|
key->ip.proto = NEXTHDR_NONE;
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
key->ip.tos_frag = ipv6_get_dsfield(nh) & ~INET_ECN_MASK;
|
2011-05-18 11:30:07 -07:00
|
|
|
ipv6_addr_copy(&key->ipv6.addr.src, &nh->saddr);
|
|
|
|
ipv6_addr_copy(&key->ipv6.addr.dst, &nh->daddr);
|
2010-12-29 19:03:46 -08:00
|
|
|
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
payload_ofs = skip_exthdr(skb, payload_ofs, &nexthdr, &key->ip.tos_frag);
|
2011-02-25 16:46:19 -08:00
|
|
|
if (unlikely(payload_ofs < 0))
|
2010-12-29 19:03:46 -08:00
|
|
|
return -EINVAL;
|
2011-02-25 16:46:19 -08:00
|
|
|
|
2010-12-29 19:03:46 -08:00
|
|
|
nh_len = payload_ofs - nh_ofs;
|
|
|
|
skb_set_transport_header(skb, nh_ofs + nh_len);
|
2011-06-08 12:28:57 -07:00
|
|
|
key->ip.proto = nexthdr;
|
2010-12-29 19:03:46 -08:00
|
|
|
return nh_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool icmp6hdr_ok(struct sk_buff *skb)
|
|
|
|
{
|
2011-05-10 11:48:36 -07:00
|
|
|
return pskb_may_pull(skb, skb_transport_offset(skb) +
|
|
|
|
sizeof(struct icmp6hdr));
|
2010-12-29 19:03:46 -08:00
|
|
|
}
|
2011-01-29 14:11:23 -08:00
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
#define TCP_FLAGS_OFFSET 13
|
|
|
|
#define TCP_FLAG_MASK 0x3f
|
|
|
|
|
|
|
|
void flow_used(struct sw_flow *flow, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
u8 tcp_flags = 0;
|
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
if (flow->key.eth.type == htons(ETH_P_IP) &&
|
2011-06-08 12:28:57 -07:00
|
|
|
flow->key.ip.proto == IPPROTO_TCP) {
|
2010-07-27 10:02:07 -07:00
|
|
|
u8 *tcp = (u8 *)tcp_hdr(skb);
|
|
|
|
tcp_flags = *(tcp + TCP_FLAGS_OFFSET) & TCP_FLAG_MASK;
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
|
2011-10-06 21:52:39 -07:00
|
|
|
spin_lock(&flow->lock);
|
2010-07-15 19:22:07 -07:00
|
|
|
flow->used = jiffies;
|
2009-07-08 13:19:16 -07:00
|
|
|
flow->packet_count++;
|
|
|
|
flow->byte_count += skb->len;
|
|
|
|
flow->tcp_flags |= tcp_flags;
|
2011-10-06 21:52:39 -07:00
|
|
|
spin_unlock(&flow->lock);
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
|
2011-01-28 14:00:51 -08:00
|
|
|
struct sw_flow_actions *flow_actions_alloc(const struct nlattr *actions)
|
2009-07-08 13:19:16 -07:00
|
|
|
{
|
2011-01-28 14:00:51 -08:00
|
|
|
int actions_len = nla_len(actions);
|
2009-07-08 13:19:16 -07:00
|
|
|
struct sw_flow_actions *sfa;
|
|
|
|
|
2010-09-14 13:32:36 -07:00
|
|
|
/* At least DP_MAX_PORTS actions are required to be able to flood a
|
|
|
|
* packet to every port. Factor of 2 allows for setting VLAN tags,
|
|
|
|
* etc. */
|
2010-12-10 10:40:58 -08:00
|
|
|
if (actions_len > 2 * DP_MAX_PORTS * nla_total_size(4))
|
2009-07-08 13:19:16 -07:00
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
2011-01-17 14:34:55 -08:00
|
|
|
sfa = kmalloc(sizeof(*sfa) + actions_len, GFP_KERNEL);
|
2009-07-08 13:19:16 -07:00
|
|
|
if (!sfa)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2010-12-10 10:40:58 -08:00
|
|
|
sfa->actions_len = actions_len;
|
2011-01-28 14:00:51 -08:00
|
|
|
memcpy(sfa->actions, nla_data(actions), actions_len);
|
2009-07-08 13:19:16 -07:00
|
|
|
return sfa;
|
|
|
|
}
|
|
|
|
|
2010-07-26 18:46:27 -07:00
|
|
|
struct sw_flow *flow_alloc(void)
|
|
|
|
{
|
|
|
|
struct sw_flow *flow;
|
|
|
|
|
|
|
|
flow = kmem_cache_alloc(flow_cache, GFP_KERNEL);
|
|
|
|
if (!flow)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
spin_lock_init(&flow->lock);
|
2010-08-29 09:49:51 -07:00
|
|
|
atomic_set(&flow->refcnt, 1);
|
2011-04-28 16:34:56 -07:00
|
|
|
flow->sf_acts = NULL;
|
2010-08-29 09:49:51 -07:00
|
|
|
flow->dead = false;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2010-07-26 18:46:27 -07:00
|
|
|
return flow;
|
|
|
|
}
|
|
|
|
|
2011-09-09 19:09:47 -07:00
|
|
|
static struct hlist_head __rcu *find_bucket(struct flow_table * table, u32 hash)
|
2010-04-02 16:46:18 -04:00
|
|
|
{
|
2011-09-09 19:09:47 -07:00
|
|
|
return flex_array_get(table->buckets,
|
|
|
|
(hash & (table->n_buckets - 1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct flex_array __rcu *alloc_buckets(unsigned int n_buckets)
|
|
|
|
{
|
|
|
|
struct flex_array __rcu * buckets;
|
|
|
|
int i, err;
|
|
|
|
|
|
|
|
buckets = flex_array_alloc(sizeof(struct hlist_head *),
|
|
|
|
n_buckets, GFP_KERNEL);
|
|
|
|
if (!buckets)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
err = flex_array_prealloc(buckets, 0, n_buckets, GFP_KERNEL);
|
|
|
|
if (err) {
|
|
|
|
flex_array_free(buckets);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n_buckets; i++)
|
|
|
|
INIT_HLIST_HEAD((struct hlist_head *)
|
|
|
|
flex_array_get(buckets, i));
|
|
|
|
|
|
|
|
return buckets;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_buckets(struct flex_array * buckets)
|
|
|
|
{
|
|
|
|
flex_array_free(buckets);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct flow_table *flow_tbl_alloc(int new_size)
|
|
|
|
{
|
|
|
|
struct flow_table *table = kmalloc(sizeof(*table), GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
table->buckets = alloc_buckets(new_size);
|
|
|
|
|
|
|
|
if (!table->buckets) {
|
|
|
|
kfree(table);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
table->n_buckets = new_size;
|
|
|
|
table->count = 0;
|
|
|
|
|
|
|
|
return table;
|
|
|
|
}
|
2010-08-29 09:49:51 -07:00
|
|
|
|
2011-09-09 19:09:47 -07:00
|
|
|
static void flow_free(struct sw_flow *flow)
|
|
|
|
{
|
2010-08-29 09:49:51 -07:00
|
|
|
flow->dead = true;
|
|
|
|
flow_put(flow);
|
2010-04-02 16:46:18 -04:00
|
|
|
}
|
|
|
|
|
2011-09-09 19:09:47 -07:00
|
|
|
void flow_tbl_destroy(struct flow_table *table)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < table->n_buckets; i++) {
|
|
|
|
struct sw_flow *flow;
|
|
|
|
struct hlist_head *head = flex_array_get(table->buckets, i);
|
|
|
|
struct hlist_node *node, *n;
|
|
|
|
|
|
|
|
hlist_for_each_entry_safe(flow, node, n, head, hash_node) {
|
|
|
|
hlist_del_init_rcu(&flow->hash_node);
|
|
|
|
flow_free(flow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free_buckets(table->buckets);
|
|
|
|
kfree(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flow_tbl_destroy_rcu_cb(struct rcu_head *rcu)
|
|
|
|
{
|
|
|
|
struct flow_table *table = container_of(rcu, struct flow_table, rcu);
|
|
|
|
|
|
|
|
flow_tbl_destroy(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
void flow_tbl_deferred_destroy(struct flow_table *table)
|
|
|
|
{
|
|
|
|
if (!table)
|
|
|
|
return;
|
|
|
|
|
|
|
|
call_rcu(&table->rcu, flow_tbl_destroy_rcu_cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sw_flow *flow_tbl_next(struct flow_table *table, u32 *bucket, u32 *last)
|
|
|
|
{
|
|
|
|
struct sw_flow *flow;
|
|
|
|
struct hlist_head *head;
|
|
|
|
struct hlist_node *n;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
while (*bucket < table->n_buckets) {
|
|
|
|
i = 0;
|
|
|
|
head = flex_array_get(table->buckets, *bucket);
|
|
|
|
hlist_for_each_entry_rcu(flow, n, head, hash_node) {
|
|
|
|
if (i < *last) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*last = i + 1;
|
|
|
|
return flow;
|
|
|
|
}
|
|
|
|
(*bucket)++;
|
|
|
|
*last = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct flow_table *flow_tbl_expand(struct flow_table *table)
|
|
|
|
{
|
|
|
|
struct flow_table *new_table;
|
|
|
|
int n_buckets = table->n_buckets * 2;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
new_table = flow_tbl_alloc(n_buckets);
|
|
|
|
if (!new_table)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
for (i = 0; i < table->n_buckets; i++) {
|
|
|
|
struct sw_flow *flow;
|
|
|
|
struct hlist_head *head;
|
|
|
|
struct hlist_node *n, *pos;
|
|
|
|
|
|
|
|
head = flex_array_get(table->buckets, i);
|
|
|
|
|
|
|
|
hlist_for_each_entry_safe(flow, n, pos, head, hash_node) {
|
|
|
|
hlist_del_init_rcu(&flow->hash_node);
|
|
|
|
flow_tbl_insert(new_table, flow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_table;
|
|
|
|
}
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
/* RCU callback used by flow_deferred_free. */
|
|
|
|
static void rcu_free_flow_callback(struct rcu_head *rcu)
|
|
|
|
{
|
|
|
|
struct sw_flow *flow = container_of(rcu, struct sw_flow, rcu);
|
2010-08-29 09:49:51 -07:00
|
|
|
|
|
|
|
flow->dead = true;
|
|
|
|
flow_put(flow);
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Schedules 'flow' to be freed after the next RCU grace period.
|
|
|
|
* The caller must hold rcu_read_lock for this to be sensible. */
|
|
|
|
void flow_deferred_free(struct sw_flow *flow)
|
|
|
|
{
|
|
|
|
call_rcu(&flow->rcu, rcu_free_flow_callback);
|
|
|
|
}
|
|
|
|
|
2010-08-29 09:49:51 -07:00
|
|
|
void flow_hold(struct sw_flow *flow)
|
|
|
|
{
|
|
|
|
atomic_inc(&flow->refcnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void flow_put(struct sw_flow *flow)
|
|
|
|
{
|
|
|
|
if (unlikely(!flow))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (atomic_dec_and_test(&flow->refcnt)) {
|
2010-12-23 16:44:22 -08:00
|
|
|
kfree((struct sf_flow_acts __force *)flow->sf_acts);
|
2010-08-29 09:49:51 -07:00
|
|
|
kmem_cache_free(flow_cache, flow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
/* RCU callback used by flow_deferred_free_acts. */
|
|
|
|
static void rcu_free_acts_callback(struct rcu_head *rcu)
|
|
|
|
{
|
2010-08-30 00:24:53 -07:00
|
|
|
struct sw_flow_actions *sf_acts = container_of(rcu,
|
2009-07-08 13:19:16 -07:00
|
|
|
struct sw_flow_actions, rcu);
|
|
|
|
kfree(sf_acts);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Schedules 'sf_acts' to be freed after the next RCU grace period.
|
|
|
|
* The caller must hold rcu_read_lock for this to be sensible. */
|
|
|
|
void flow_deferred_free_acts(struct sw_flow_actions *sf_acts)
|
|
|
|
{
|
|
|
|
call_rcu(&sf_acts->rcu, rcu_free_acts_callback);
|
|
|
|
}
|
|
|
|
|
2011-05-10 11:48:36 -07:00
|
|
|
static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
|
2009-07-08 13:19:16 -07:00
|
|
|
{
|
datapath: Fix handling of 802.1Q and SNAP headers.
The kernel and user datapaths have code that assumes that 802.1Q headers
are used only inside Ethernet II frames, not inside SNAP-encapsulated
frames. But the kernel and user flow_extract() implementations would
interpret 802.1Q headers inside SNAP headers as being valid VLANs. This
would cause packet corruption if any VLAN-related actions were to be taken,
so change the two flow_extract() implementations only to accept 802.1Q as
an Ethernet II frame type, not as a SNAP-encoded frame type.
802.1Q-2005 says that this is correct anyhow:
Where the ISS instance used to transmit and receive tagged frames is
provided by a media access control method that can support Ethernet
Type encoding directly (e.g., is an IEEE 802.3 or IEEE 802.11 MAC) or
is media access method independent (e.g., 6.6), the TPID is Ethernet
Type encoded, i.e., is two octets in length and comprises solely the
assigned Ethernet Type value.
Where the ISS instance is provided by a media access method that
cannot directly support Ethernet Type encoding (e.g., is an IEEE
802.5 or FDDI MAC), the TPID is encoded according to the rule for
a Subnetwork Access Protocol (Clause 10 of IEEE Std 802) that
encapsulates Ethernet frames over LLC, and comprises the SNAP
header (AA-AA-03) followed by the SNAP PID (00-00-00) followed by
the two octets of the assigned Ethernet Type value.
All of the media that OVS handles supports Ethernet Type fields, so to me
that means that we don't have to handle 802.1Q-inside-SNAP.
On the other hand, we *do* have to handle SNAP-inside-802.1Q, because this
is actually allowed by the standards. So this commit also adds that
support.
I verified that, with this change, both SNAP and Ethernet packets are
properly recognized both with and without 802.1Q encapsulation.
I was a bit surprised to find out that Linux does not accept
SNAP-encapsulated IP frames on Ethernet.
Here's a summary of how frames are handled before and after this commit:
Common cases
------------
Ethernet
+------------+
1. |dst|src|TYPE|
+------------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
2. |dst|src| len| |aa|aa|03| |000000|TYPE|
+------------+ +--------+ +-----------+
Ethernet 802.1Q
+------------+ +---------+
3. |dst|src|8100| |VLAN|TYPE|
+------------+ +---------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
4. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |000000|TYPE|
+------------+ +---------+ +--------+ +-----------+
Unusual cases
-------------
Ethernet LLC SNAP 802.1Q
+------------+ +--------+ +-----------+ +---------+
5. |dst|src| len| |aa|aa|03| |000000|8100| |VLAN|TYPE|
+------------+ +--------+ +-----------+ +---------+
Ethernet LLC
+------------+ +--------+
6. |dst|src| len| |xx|xx|xx|
+------------+ +--------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
7. |dst|src| len| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +--------+ +-----------+
Ethernet 802.1Q LLC
+------------+ +---------+ +--------+
8. |dst|src|8100| |VLAN| LEN| |xx|xx|xx|
+------------+ +---------+ +--------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
9. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +---------+ +--------+ +-----------+
Behavior
--------
--------------- --------------- -------------------------------------
Before After
this commit this commit
dl_type dl_vlan dl_type dl_vlan Notes
------- ------- ------- ------- -------------------------------------
1. TYPE ffff TYPE ffff no change
2. TYPE ffff TYPE ffff no change
3. TYPE VLAN TYPE VLAN no change
4. LEN VLAN TYPE VLAN proposal fixes behavior
5. TYPE VLAN 8100 ffff 802.1Q says this is invalid framing
6. 05ff ffff 05ff ffff no change
7. 05ff ffff 05ff ffff no change
8. LEN VLAN 05ff VLAN proposal fixes behavior
9. LEN VLAN 05ff VLAN proposal fixes behavior
Signed-off-by: Ben Pfaff <blp@nicira.com>
2010-08-10 11:35:46 -07:00
|
|
|
struct qtag_prefix {
|
|
|
|
__be16 eth_type; /* ETH_P_8021Q */
|
|
|
|
__be16 tci;
|
|
|
|
};
|
|
|
|
struct qtag_prefix *qp;
|
|
|
|
|
2011-05-10 11:48:36 -07:00
|
|
|
if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
|
|
|
|
sizeof(__be16))))
|
|
|
|
return -ENOMEM;
|
datapath: Fix handling of 802.1Q and SNAP headers.
The kernel and user datapaths have code that assumes that 802.1Q headers
are used only inside Ethernet II frames, not inside SNAP-encapsulated
frames. But the kernel and user flow_extract() implementations would
interpret 802.1Q headers inside SNAP headers as being valid VLANs. This
would cause packet corruption if any VLAN-related actions were to be taken,
so change the two flow_extract() implementations only to accept 802.1Q as
an Ethernet II frame type, not as a SNAP-encoded frame type.
802.1Q-2005 says that this is correct anyhow:
Where the ISS instance used to transmit and receive tagged frames is
provided by a media access control method that can support Ethernet
Type encoding directly (e.g., is an IEEE 802.3 or IEEE 802.11 MAC) or
is media access method independent (e.g., 6.6), the TPID is Ethernet
Type encoded, i.e., is two octets in length and comprises solely the
assigned Ethernet Type value.
Where the ISS instance is provided by a media access method that
cannot directly support Ethernet Type encoding (e.g., is an IEEE
802.5 or FDDI MAC), the TPID is encoded according to the rule for
a Subnetwork Access Protocol (Clause 10 of IEEE Std 802) that
encapsulates Ethernet frames over LLC, and comprises the SNAP
header (AA-AA-03) followed by the SNAP PID (00-00-00) followed by
the two octets of the assigned Ethernet Type value.
All of the media that OVS handles supports Ethernet Type fields, so to me
that means that we don't have to handle 802.1Q-inside-SNAP.
On the other hand, we *do* have to handle SNAP-inside-802.1Q, because this
is actually allowed by the standards. So this commit also adds that
support.
I verified that, with this change, both SNAP and Ethernet packets are
properly recognized both with and without 802.1Q encapsulation.
I was a bit surprised to find out that Linux does not accept
SNAP-encapsulated IP frames on Ethernet.
Here's a summary of how frames are handled before and after this commit:
Common cases
------------
Ethernet
+------------+
1. |dst|src|TYPE|
+------------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
2. |dst|src| len| |aa|aa|03| |000000|TYPE|
+------------+ +--------+ +-----------+
Ethernet 802.1Q
+------------+ +---------+
3. |dst|src|8100| |VLAN|TYPE|
+------------+ +---------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
4. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |000000|TYPE|
+------------+ +---------+ +--------+ +-----------+
Unusual cases
-------------
Ethernet LLC SNAP 802.1Q
+------------+ +--------+ +-----------+ +---------+
5. |dst|src| len| |aa|aa|03| |000000|8100| |VLAN|TYPE|
+------------+ +--------+ +-----------+ +---------+
Ethernet LLC
+------------+ +--------+
6. |dst|src| len| |xx|xx|xx|
+------------+ +--------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
7. |dst|src| len| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +--------+ +-----------+
Ethernet 802.1Q LLC
+------------+ +---------+ +--------+
8. |dst|src|8100| |VLAN| LEN| |xx|xx|xx|
+------------+ +---------+ +--------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
9. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +---------+ +--------+ +-----------+
Behavior
--------
--------------- --------------- -------------------------------------
Before After
this commit this commit
dl_type dl_vlan dl_type dl_vlan Notes
------- ------- ------- ------- -------------------------------------
1. TYPE ffff TYPE ffff no change
2. TYPE ffff TYPE ffff no change
3. TYPE VLAN TYPE VLAN no change
4. LEN VLAN TYPE VLAN proposal fixes behavior
5. TYPE VLAN 8100 ffff 802.1Q says this is invalid framing
6. 05ff ffff 05ff ffff no change
7. 05ff ffff 05ff ffff no change
8. LEN VLAN 05ff VLAN proposal fixes behavior
9. LEN VLAN 05ff VLAN proposal fixes behavior
Signed-off-by: Ben Pfaff <blp@nicira.com>
2010-08-10 11:35:46 -07:00
|
|
|
|
|
|
|
qp = (struct qtag_prefix *) skb->data;
|
2011-05-18 11:30:07 -07:00
|
|
|
key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
|
datapath: Fix handling of 802.1Q and SNAP headers.
The kernel and user datapaths have code that assumes that 802.1Q headers
are used only inside Ethernet II frames, not inside SNAP-encapsulated
frames. But the kernel and user flow_extract() implementations would
interpret 802.1Q headers inside SNAP headers as being valid VLANs. This
would cause packet corruption if any VLAN-related actions were to be taken,
so change the two flow_extract() implementations only to accept 802.1Q as
an Ethernet II frame type, not as a SNAP-encoded frame type.
802.1Q-2005 says that this is correct anyhow:
Where the ISS instance used to transmit and receive tagged frames is
provided by a media access control method that can support Ethernet
Type encoding directly (e.g., is an IEEE 802.3 or IEEE 802.11 MAC) or
is media access method independent (e.g., 6.6), the TPID is Ethernet
Type encoded, i.e., is two octets in length and comprises solely the
assigned Ethernet Type value.
Where the ISS instance is provided by a media access method that
cannot directly support Ethernet Type encoding (e.g., is an IEEE
802.5 or FDDI MAC), the TPID is encoded according to the rule for
a Subnetwork Access Protocol (Clause 10 of IEEE Std 802) that
encapsulates Ethernet frames over LLC, and comprises the SNAP
header (AA-AA-03) followed by the SNAP PID (00-00-00) followed by
the two octets of the assigned Ethernet Type value.
All of the media that OVS handles supports Ethernet Type fields, so to me
that means that we don't have to handle 802.1Q-inside-SNAP.
On the other hand, we *do* have to handle SNAP-inside-802.1Q, because this
is actually allowed by the standards. So this commit also adds that
support.
I verified that, with this change, both SNAP and Ethernet packets are
properly recognized both with and without 802.1Q encapsulation.
I was a bit surprised to find out that Linux does not accept
SNAP-encapsulated IP frames on Ethernet.
Here's a summary of how frames are handled before and after this commit:
Common cases
------------
Ethernet
+------------+
1. |dst|src|TYPE|
+------------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
2. |dst|src| len| |aa|aa|03| |000000|TYPE|
+------------+ +--------+ +-----------+
Ethernet 802.1Q
+------------+ +---------+
3. |dst|src|8100| |VLAN|TYPE|
+------------+ +---------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
4. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |000000|TYPE|
+------------+ +---------+ +--------+ +-----------+
Unusual cases
-------------
Ethernet LLC SNAP 802.1Q
+------------+ +--------+ +-----------+ +---------+
5. |dst|src| len| |aa|aa|03| |000000|8100| |VLAN|TYPE|
+------------+ +--------+ +-----------+ +---------+
Ethernet LLC
+------------+ +--------+
6. |dst|src| len| |xx|xx|xx|
+------------+ +--------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
7. |dst|src| len| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +--------+ +-----------+
Ethernet 802.1Q LLC
+------------+ +---------+ +--------+
8. |dst|src|8100| |VLAN| LEN| |xx|xx|xx|
+------------+ +---------+ +--------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
9. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +---------+ +--------+ +-----------+
Behavior
--------
--------------- --------------- -------------------------------------
Before After
this commit this commit
dl_type dl_vlan dl_type dl_vlan Notes
------- ------- ------- ------- -------------------------------------
1. TYPE ffff TYPE ffff no change
2. TYPE ffff TYPE ffff no change
3. TYPE VLAN TYPE VLAN no change
4. LEN VLAN TYPE VLAN proposal fixes behavior
5. TYPE VLAN 8100 ffff 802.1Q says this is invalid framing
6. 05ff ffff 05ff ffff no change
7. 05ff ffff 05ff ffff no change
8. LEN VLAN 05ff VLAN proposal fixes behavior
9. LEN VLAN 05ff VLAN proposal fixes behavior
Signed-off-by: Ben Pfaff <blp@nicira.com>
2010-08-10 11:35:46 -07:00
|
|
|
__skb_pull(skb, sizeof(struct qtag_prefix));
|
2011-05-10 11:48:36 -07:00
|
|
|
|
|
|
|
return 0;
|
datapath: Fix handling of 802.1Q and SNAP headers.
The kernel and user datapaths have code that assumes that 802.1Q headers
are used only inside Ethernet II frames, not inside SNAP-encapsulated
frames. But the kernel and user flow_extract() implementations would
interpret 802.1Q headers inside SNAP headers as being valid VLANs. This
would cause packet corruption if any VLAN-related actions were to be taken,
so change the two flow_extract() implementations only to accept 802.1Q as
an Ethernet II frame type, not as a SNAP-encoded frame type.
802.1Q-2005 says that this is correct anyhow:
Where the ISS instance used to transmit and receive tagged frames is
provided by a media access control method that can support Ethernet
Type encoding directly (e.g., is an IEEE 802.3 or IEEE 802.11 MAC) or
is media access method independent (e.g., 6.6), the TPID is Ethernet
Type encoded, i.e., is two octets in length and comprises solely the
assigned Ethernet Type value.
Where the ISS instance is provided by a media access method that
cannot directly support Ethernet Type encoding (e.g., is an IEEE
802.5 or FDDI MAC), the TPID is encoded according to the rule for
a Subnetwork Access Protocol (Clause 10 of IEEE Std 802) that
encapsulates Ethernet frames over LLC, and comprises the SNAP
header (AA-AA-03) followed by the SNAP PID (00-00-00) followed by
the two octets of the assigned Ethernet Type value.
All of the media that OVS handles supports Ethernet Type fields, so to me
that means that we don't have to handle 802.1Q-inside-SNAP.
On the other hand, we *do* have to handle SNAP-inside-802.1Q, because this
is actually allowed by the standards. So this commit also adds that
support.
I verified that, with this change, both SNAP and Ethernet packets are
properly recognized both with and without 802.1Q encapsulation.
I was a bit surprised to find out that Linux does not accept
SNAP-encapsulated IP frames on Ethernet.
Here's a summary of how frames are handled before and after this commit:
Common cases
------------
Ethernet
+------------+
1. |dst|src|TYPE|
+------------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
2. |dst|src| len| |aa|aa|03| |000000|TYPE|
+------------+ +--------+ +-----------+
Ethernet 802.1Q
+------------+ +---------+
3. |dst|src|8100| |VLAN|TYPE|
+------------+ +---------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
4. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |000000|TYPE|
+------------+ +---------+ +--------+ +-----------+
Unusual cases
-------------
Ethernet LLC SNAP 802.1Q
+------------+ +--------+ +-----------+ +---------+
5. |dst|src| len| |aa|aa|03| |000000|8100| |VLAN|TYPE|
+------------+ +--------+ +-----------+ +---------+
Ethernet LLC
+------------+ +--------+
6. |dst|src| len| |xx|xx|xx|
+------------+ +--------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
7. |dst|src| len| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +--------+ +-----------+
Ethernet 802.1Q LLC
+------------+ +---------+ +--------+
8. |dst|src|8100| |VLAN| LEN| |xx|xx|xx|
+------------+ +---------+ +--------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
9. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +---------+ +--------+ +-----------+
Behavior
--------
--------------- --------------- -------------------------------------
Before After
this commit this commit
dl_type dl_vlan dl_type dl_vlan Notes
------- ------- ------- ------- -------------------------------------
1. TYPE ffff TYPE ffff no change
2. TYPE ffff TYPE ffff no change
3. TYPE VLAN TYPE VLAN no change
4. LEN VLAN TYPE VLAN proposal fixes behavior
5. TYPE VLAN 8100 ffff 802.1Q says this is invalid framing
6. 05ff ffff 05ff ffff no change
7. 05ff ffff 05ff ffff no change
8. LEN VLAN 05ff VLAN proposal fixes behavior
9. LEN VLAN 05ff VLAN proposal fixes behavior
Signed-off-by: Ben Pfaff <blp@nicira.com>
2010-08-10 11:35:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static __be16 parse_ethertype(struct sk_buff *skb)
|
2009-07-08 13:19:16 -07:00
|
|
|
{
|
datapath: Fix handling of 802.1Q and SNAP headers.
The kernel and user datapaths have code that assumes that 802.1Q headers
are used only inside Ethernet II frames, not inside SNAP-encapsulated
frames. But the kernel and user flow_extract() implementations would
interpret 802.1Q headers inside SNAP headers as being valid VLANs. This
would cause packet corruption if any VLAN-related actions were to be taken,
so change the two flow_extract() implementations only to accept 802.1Q as
an Ethernet II frame type, not as a SNAP-encoded frame type.
802.1Q-2005 says that this is correct anyhow:
Where the ISS instance used to transmit and receive tagged frames is
provided by a media access control method that can support Ethernet
Type encoding directly (e.g., is an IEEE 802.3 or IEEE 802.11 MAC) or
is media access method independent (e.g., 6.6), the TPID is Ethernet
Type encoded, i.e., is two octets in length and comprises solely the
assigned Ethernet Type value.
Where the ISS instance is provided by a media access method that
cannot directly support Ethernet Type encoding (e.g., is an IEEE
802.5 or FDDI MAC), the TPID is encoded according to the rule for
a Subnetwork Access Protocol (Clause 10 of IEEE Std 802) that
encapsulates Ethernet frames over LLC, and comprises the SNAP
header (AA-AA-03) followed by the SNAP PID (00-00-00) followed by
the two octets of the assigned Ethernet Type value.
All of the media that OVS handles supports Ethernet Type fields, so to me
that means that we don't have to handle 802.1Q-inside-SNAP.
On the other hand, we *do* have to handle SNAP-inside-802.1Q, because this
is actually allowed by the standards. So this commit also adds that
support.
I verified that, with this change, both SNAP and Ethernet packets are
properly recognized both with and without 802.1Q encapsulation.
I was a bit surprised to find out that Linux does not accept
SNAP-encapsulated IP frames on Ethernet.
Here's a summary of how frames are handled before and after this commit:
Common cases
------------
Ethernet
+------------+
1. |dst|src|TYPE|
+------------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
2. |dst|src| len| |aa|aa|03| |000000|TYPE|
+------------+ +--------+ +-----------+
Ethernet 802.1Q
+------------+ +---------+
3. |dst|src|8100| |VLAN|TYPE|
+------------+ +---------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
4. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |000000|TYPE|
+------------+ +---------+ +--------+ +-----------+
Unusual cases
-------------
Ethernet LLC SNAP 802.1Q
+------------+ +--------+ +-----------+ +---------+
5. |dst|src| len| |aa|aa|03| |000000|8100| |VLAN|TYPE|
+------------+ +--------+ +-----------+ +---------+
Ethernet LLC
+------------+ +--------+
6. |dst|src| len| |xx|xx|xx|
+------------+ +--------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
7. |dst|src| len| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +--------+ +-----------+
Ethernet 802.1Q LLC
+------------+ +---------+ +--------+
8. |dst|src|8100| |VLAN| LEN| |xx|xx|xx|
+------------+ +---------+ +--------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
9. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +---------+ +--------+ +-----------+
Behavior
--------
--------------- --------------- -------------------------------------
Before After
this commit this commit
dl_type dl_vlan dl_type dl_vlan Notes
------- ------- ------- ------- -------------------------------------
1. TYPE ffff TYPE ffff no change
2. TYPE ffff TYPE ffff no change
3. TYPE VLAN TYPE VLAN no change
4. LEN VLAN TYPE VLAN proposal fixes behavior
5. TYPE VLAN 8100 ffff 802.1Q says this is invalid framing
6. 05ff ffff 05ff ffff no change
7. 05ff ffff 05ff ffff no change
8. LEN VLAN 05ff VLAN proposal fixes behavior
9. LEN VLAN 05ff VLAN proposal fixes behavior
Signed-off-by: Ben Pfaff <blp@nicira.com>
2010-08-10 11:35:46 -07:00
|
|
|
struct llc_snap_hdr {
|
|
|
|
u8 dsap; /* Always 0xAA */
|
|
|
|
u8 ssap; /* Always 0xAA */
|
|
|
|
u8 ctrl;
|
|
|
|
u8 oui[3];
|
2010-12-04 12:04:39 -08:00
|
|
|
__be16 ethertype;
|
datapath: Fix handling of 802.1Q and SNAP headers.
The kernel and user datapaths have code that assumes that 802.1Q headers
are used only inside Ethernet II frames, not inside SNAP-encapsulated
frames. But the kernel and user flow_extract() implementations would
interpret 802.1Q headers inside SNAP headers as being valid VLANs. This
would cause packet corruption if any VLAN-related actions were to be taken,
so change the two flow_extract() implementations only to accept 802.1Q as
an Ethernet II frame type, not as a SNAP-encoded frame type.
802.1Q-2005 says that this is correct anyhow:
Where the ISS instance used to transmit and receive tagged frames is
provided by a media access control method that can support Ethernet
Type encoding directly (e.g., is an IEEE 802.3 or IEEE 802.11 MAC) or
is media access method independent (e.g., 6.6), the TPID is Ethernet
Type encoded, i.e., is two octets in length and comprises solely the
assigned Ethernet Type value.
Where the ISS instance is provided by a media access method that
cannot directly support Ethernet Type encoding (e.g., is an IEEE
802.5 or FDDI MAC), the TPID is encoded according to the rule for
a Subnetwork Access Protocol (Clause 10 of IEEE Std 802) that
encapsulates Ethernet frames over LLC, and comprises the SNAP
header (AA-AA-03) followed by the SNAP PID (00-00-00) followed by
the two octets of the assigned Ethernet Type value.
All of the media that OVS handles supports Ethernet Type fields, so to me
that means that we don't have to handle 802.1Q-inside-SNAP.
On the other hand, we *do* have to handle SNAP-inside-802.1Q, because this
is actually allowed by the standards. So this commit also adds that
support.
I verified that, with this change, both SNAP and Ethernet packets are
properly recognized both with and without 802.1Q encapsulation.
I was a bit surprised to find out that Linux does not accept
SNAP-encapsulated IP frames on Ethernet.
Here's a summary of how frames are handled before and after this commit:
Common cases
------------
Ethernet
+------------+
1. |dst|src|TYPE|
+------------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
2. |dst|src| len| |aa|aa|03| |000000|TYPE|
+------------+ +--------+ +-----------+
Ethernet 802.1Q
+------------+ +---------+
3. |dst|src|8100| |VLAN|TYPE|
+------------+ +---------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
4. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |000000|TYPE|
+------------+ +---------+ +--------+ +-----------+
Unusual cases
-------------
Ethernet LLC SNAP 802.1Q
+------------+ +--------+ +-----------+ +---------+
5. |dst|src| len| |aa|aa|03| |000000|8100| |VLAN|TYPE|
+------------+ +--------+ +-----------+ +---------+
Ethernet LLC
+------------+ +--------+
6. |dst|src| len| |xx|xx|xx|
+------------+ +--------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
7. |dst|src| len| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +--------+ +-----------+
Ethernet 802.1Q LLC
+------------+ +---------+ +--------+
8. |dst|src|8100| |VLAN| LEN| |xx|xx|xx|
+------------+ +---------+ +--------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
9. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +---------+ +--------+ +-----------+
Behavior
--------
--------------- --------------- -------------------------------------
Before After
this commit this commit
dl_type dl_vlan dl_type dl_vlan Notes
------- ------- ------- ------- -------------------------------------
1. TYPE ffff TYPE ffff no change
2. TYPE ffff TYPE ffff no change
3. TYPE VLAN TYPE VLAN no change
4. LEN VLAN TYPE VLAN proposal fixes behavior
5. TYPE VLAN 8100 ffff 802.1Q says this is invalid framing
6. 05ff ffff 05ff ffff no change
7. 05ff ffff 05ff ffff no change
8. LEN VLAN 05ff VLAN proposal fixes behavior
9. LEN VLAN 05ff VLAN proposal fixes behavior
Signed-off-by: Ben Pfaff <blp@nicira.com>
2010-08-10 11:35:46 -07:00
|
|
|
};
|
|
|
|
struct llc_snap_hdr *llc;
|
|
|
|
__be16 proto;
|
|
|
|
|
|
|
|
proto = *(__be16 *) skb->data;
|
|
|
|
__skb_pull(skb, sizeof(__be16));
|
|
|
|
|
2011-01-23 18:44:44 -08:00
|
|
|
if (ntohs(proto) >= 1536)
|
datapath: Fix handling of 802.1Q and SNAP headers.
The kernel and user datapaths have code that assumes that 802.1Q headers
are used only inside Ethernet II frames, not inside SNAP-encapsulated
frames. But the kernel and user flow_extract() implementations would
interpret 802.1Q headers inside SNAP headers as being valid VLANs. This
would cause packet corruption if any VLAN-related actions were to be taken,
so change the two flow_extract() implementations only to accept 802.1Q as
an Ethernet II frame type, not as a SNAP-encoded frame type.
802.1Q-2005 says that this is correct anyhow:
Where the ISS instance used to transmit and receive tagged frames is
provided by a media access control method that can support Ethernet
Type encoding directly (e.g., is an IEEE 802.3 or IEEE 802.11 MAC) or
is media access method independent (e.g., 6.6), the TPID is Ethernet
Type encoded, i.e., is two octets in length and comprises solely the
assigned Ethernet Type value.
Where the ISS instance is provided by a media access method that
cannot directly support Ethernet Type encoding (e.g., is an IEEE
802.5 or FDDI MAC), the TPID is encoded according to the rule for
a Subnetwork Access Protocol (Clause 10 of IEEE Std 802) that
encapsulates Ethernet frames over LLC, and comprises the SNAP
header (AA-AA-03) followed by the SNAP PID (00-00-00) followed by
the two octets of the assigned Ethernet Type value.
All of the media that OVS handles supports Ethernet Type fields, so to me
that means that we don't have to handle 802.1Q-inside-SNAP.
On the other hand, we *do* have to handle SNAP-inside-802.1Q, because this
is actually allowed by the standards. So this commit also adds that
support.
I verified that, with this change, both SNAP and Ethernet packets are
properly recognized both with and without 802.1Q encapsulation.
I was a bit surprised to find out that Linux does not accept
SNAP-encapsulated IP frames on Ethernet.
Here's a summary of how frames are handled before and after this commit:
Common cases
------------
Ethernet
+------------+
1. |dst|src|TYPE|
+------------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
2. |dst|src| len| |aa|aa|03| |000000|TYPE|
+------------+ +--------+ +-----------+
Ethernet 802.1Q
+------------+ +---------+
3. |dst|src|8100| |VLAN|TYPE|
+------------+ +---------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
4. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |000000|TYPE|
+------------+ +---------+ +--------+ +-----------+
Unusual cases
-------------
Ethernet LLC SNAP 802.1Q
+------------+ +--------+ +-----------+ +---------+
5. |dst|src| len| |aa|aa|03| |000000|8100| |VLAN|TYPE|
+------------+ +--------+ +-----------+ +---------+
Ethernet LLC
+------------+ +--------+
6. |dst|src| len| |xx|xx|xx|
+------------+ +--------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
7. |dst|src| len| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +--------+ +-----------+
Ethernet 802.1Q LLC
+------------+ +---------+ +--------+
8. |dst|src|8100| |VLAN| LEN| |xx|xx|xx|
+------------+ +---------+ +--------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
9. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +---------+ +--------+ +-----------+
Behavior
--------
--------------- --------------- -------------------------------------
Before After
this commit this commit
dl_type dl_vlan dl_type dl_vlan Notes
------- ------- ------- ------- -------------------------------------
1. TYPE ffff TYPE ffff no change
2. TYPE ffff TYPE ffff no change
3. TYPE VLAN TYPE VLAN no change
4. LEN VLAN TYPE VLAN proposal fixes behavior
5. TYPE VLAN 8100 ffff 802.1Q says this is invalid framing
6. 05ff ffff 05ff ffff no change
7. 05ff ffff 05ff ffff no change
8. LEN VLAN 05ff VLAN proposal fixes behavior
9. LEN VLAN 05ff VLAN proposal fixes behavior
Signed-off-by: Ben Pfaff <blp@nicira.com>
2010-08-10 11:35:46 -07:00
|
|
|
return proto;
|
|
|
|
|
2011-05-10 11:48:36 -07:00
|
|
|
if (skb->len < sizeof(struct llc_snap_hdr))
|
2011-01-23 18:44:44 -08:00
|
|
|
return htons(ETH_P_802_2);
|
datapath: Fix handling of 802.1Q and SNAP headers.
The kernel and user datapaths have code that assumes that 802.1Q headers
are used only inside Ethernet II frames, not inside SNAP-encapsulated
frames. But the kernel and user flow_extract() implementations would
interpret 802.1Q headers inside SNAP headers as being valid VLANs. This
would cause packet corruption if any VLAN-related actions were to be taken,
so change the two flow_extract() implementations only to accept 802.1Q as
an Ethernet II frame type, not as a SNAP-encoded frame type.
802.1Q-2005 says that this is correct anyhow:
Where the ISS instance used to transmit and receive tagged frames is
provided by a media access control method that can support Ethernet
Type encoding directly (e.g., is an IEEE 802.3 or IEEE 802.11 MAC) or
is media access method independent (e.g., 6.6), the TPID is Ethernet
Type encoded, i.e., is two octets in length and comprises solely the
assigned Ethernet Type value.
Where the ISS instance is provided by a media access method that
cannot directly support Ethernet Type encoding (e.g., is an IEEE
802.5 or FDDI MAC), the TPID is encoded according to the rule for
a Subnetwork Access Protocol (Clause 10 of IEEE Std 802) that
encapsulates Ethernet frames over LLC, and comprises the SNAP
header (AA-AA-03) followed by the SNAP PID (00-00-00) followed by
the two octets of the assigned Ethernet Type value.
All of the media that OVS handles supports Ethernet Type fields, so to me
that means that we don't have to handle 802.1Q-inside-SNAP.
On the other hand, we *do* have to handle SNAP-inside-802.1Q, because this
is actually allowed by the standards. So this commit also adds that
support.
I verified that, with this change, both SNAP and Ethernet packets are
properly recognized both with and without 802.1Q encapsulation.
I was a bit surprised to find out that Linux does not accept
SNAP-encapsulated IP frames on Ethernet.
Here's a summary of how frames are handled before and after this commit:
Common cases
------------
Ethernet
+------------+
1. |dst|src|TYPE|
+------------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
2. |dst|src| len| |aa|aa|03| |000000|TYPE|
+------------+ +--------+ +-----------+
Ethernet 802.1Q
+------------+ +---------+
3. |dst|src|8100| |VLAN|TYPE|
+------------+ +---------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
4. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |000000|TYPE|
+------------+ +---------+ +--------+ +-----------+
Unusual cases
-------------
Ethernet LLC SNAP 802.1Q
+------------+ +--------+ +-----------+ +---------+
5. |dst|src| len| |aa|aa|03| |000000|8100| |VLAN|TYPE|
+------------+ +--------+ +-----------+ +---------+
Ethernet LLC
+------------+ +--------+
6. |dst|src| len| |xx|xx|xx|
+------------+ +--------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
7. |dst|src| len| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +--------+ +-----------+
Ethernet 802.1Q LLC
+------------+ +---------+ +--------+
8. |dst|src|8100| |VLAN| LEN| |xx|xx|xx|
+------------+ +---------+ +--------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
9. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +---------+ +--------+ +-----------+
Behavior
--------
--------------- --------------- -------------------------------------
Before After
this commit this commit
dl_type dl_vlan dl_type dl_vlan Notes
------- ------- ------- ------- -------------------------------------
1. TYPE ffff TYPE ffff no change
2. TYPE ffff TYPE ffff no change
3. TYPE VLAN TYPE VLAN no change
4. LEN VLAN TYPE VLAN proposal fixes behavior
5. TYPE VLAN 8100 ffff 802.1Q says this is invalid framing
6. 05ff ffff 05ff ffff no change
7. 05ff ffff 05ff ffff no change
8. LEN VLAN 05ff VLAN proposal fixes behavior
9. LEN VLAN 05ff VLAN proposal fixes behavior
Signed-off-by: Ben Pfaff <blp@nicira.com>
2010-08-10 11:35:46 -07:00
|
|
|
|
2011-05-10 11:48:36 -07:00
|
|
|
if (unlikely(!pskb_may_pull(skb, sizeof(struct llc_snap_hdr))))
|
|
|
|
return htons(0);
|
|
|
|
|
datapath: Fix handling of 802.1Q and SNAP headers.
The kernel and user datapaths have code that assumes that 802.1Q headers
are used only inside Ethernet II frames, not inside SNAP-encapsulated
frames. But the kernel and user flow_extract() implementations would
interpret 802.1Q headers inside SNAP headers as being valid VLANs. This
would cause packet corruption if any VLAN-related actions were to be taken,
so change the two flow_extract() implementations only to accept 802.1Q as
an Ethernet II frame type, not as a SNAP-encoded frame type.
802.1Q-2005 says that this is correct anyhow:
Where the ISS instance used to transmit and receive tagged frames is
provided by a media access control method that can support Ethernet
Type encoding directly (e.g., is an IEEE 802.3 or IEEE 802.11 MAC) or
is media access method independent (e.g., 6.6), the TPID is Ethernet
Type encoded, i.e., is two octets in length and comprises solely the
assigned Ethernet Type value.
Where the ISS instance is provided by a media access method that
cannot directly support Ethernet Type encoding (e.g., is an IEEE
802.5 or FDDI MAC), the TPID is encoded according to the rule for
a Subnetwork Access Protocol (Clause 10 of IEEE Std 802) that
encapsulates Ethernet frames over LLC, and comprises the SNAP
header (AA-AA-03) followed by the SNAP PID (00-00-00) followed by
the two octets of the assigned Ethernet Type value.
All of the media that OVS handles supports Ethernet Type fields, so to me
that means that we don't have to handle 802.1Q-inside-SNAP.
On the other hand, we *do* have to handle SNAP-inside-802.1Q, because this
is actually allowed by the standards. So this commit also adds that
support.
I verified that, with this change, both SNAP and Ethernet packets are
properly recognized both with and without 802.1Q encapsulation.
I was a bit surprised to find out that Linux does not accept
SNAP-encapsulated IP frames on Ethernet.
Here's a summary of how frames are handled before and after this commit:
Common cases
------------
Ethernet
+------------+
1. |dst|src|TYPE|
+------------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
2. |dst|src| len| |aa|aa|03| |000000|TYPE|
+------------+ +--------+ +-----------+
Ethernet 802.1Q
+------------+ +---------+
3. |dst|src|8100| |VLAN|TYPE|
+------------+ +---------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
4. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |000000|TYPE|
+------------+ +---------+ +--------+ +-----------+
Unusual cases
-------------
Ethernet LLC SNAP 802.1Q
+------------+ +--------+ +-----------+ +---------+
5. |dst|src| len| |aa|aa|03| |000000|8100| |VLAN|TYPE|
+------------+ +--------+ +-----------+ +---------+
Ethernet LLC
+------------+ +--------+
6. |dst|src| len| |xx|xx|xx|
+------------+ +--------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
7. |dst|src| len| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +--------+ +-----------+
Ethernet 802.1Q LLC
+------------+ +---------+ +--------+
8. |dst|src|8100| |VLAN| LEN| |xx|xx|xx|
+------------+ +---------+ +--------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
9. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +---------+ +--------+ +-----------+
Behavior
--------
--------------- --------------- -------------------------------------
Before After
this commit this commit
dl_type dl_vlan dl_type dl_vlan Notes
------- ------- ------- ------- -------------------------------------
1. TYPE ffff TYPE ffff no change
2. TYPE ffff TYPE ffff no change
3. TYPE VLAN TYPE VLAN no change
4. LEN VLAN TYPE VLAN proposal fixes behavior
5. TYPE VLAN 8100 ffff 802.1Q says this is invalid framing
6. 05ff ffff 05ff ffff no change
7. 05ff ffff 05ff ffff no change
8. LEN VLAN 05ff VLAN proposal fixes behavior
9. LEN VLAN 05ff VLAN proposal fixes behavior
Signed-off-by: Ben Pfaff <blp@nicira.com>
2010-08-10 11:35:46 -07:00
|
|
|
llc = (struct llc_snap_hdr *) skb->data;
|
|
|
|
if (llc->dsap != LLC_SAP_SNAP ||
|
|
|
|
llc->ssap != LLC_SAP_SNAP ||
|
|
|
|
(llc->oui[0] | llc->oui[1] | llc->oui[2]) != 0)
|
2011-01-23 18:44:44 -08:00
|
|
|
return htons(ETH_P_802_2);
|
datapath: Fix handling of 802.1Q and SNAP headers.
The kernel and user datapaths have code that assumes that 802.1Q headers
are used only inside Ethernet II frames, not inside SNAP-encapsulated
frames. But the kernel and user flow_extract() implementations would
interpret 802.1Q headers inside SNAP headers as being valid VLANs. This
would cause packet corruption if any VLAN-related actions were to be taken,
so change the two flow_extract() implementations only to accept 802.1Q as
an Ethernet II frame type, not as a SNAP-encoded frame type.
802.1Q-2005 says that this is correct anyhow:
Where the ISS instance used to transmit and receive tagged frames is
provided by a media access control method that can support Ethernet
Type encoding directly (e.g., is an IEEE 802.3 or IEEE 802.11 MAC) or
is media access method independent (e.g., 6.6), the TPID is Ethernet
Type encoded, i.e., is two octets in length and comprises solely the
assigned Ethernet Type value.
Where the ISS instance is provided by a media access method that
cannot directly support Ethernet Type encoding (e.g., is an IEEE
802.5 or FDDI MAC), the TPID is encoded according to the rule for
a Subnetwork Access Protocol (Clause 10 of IEEE Std 802) that
encapsulates Ethernet frames over LLC, and comprises the SNAP
header (AA-AA-03) followed by the SNAP PID (00-00-00) followed by
the two octets of the assigned Ethernet Type value.
All of the media that OVS handles supports Ethernet Type fields, so to me
that means that we don't have to handle 802.1Q-inside-SNAP.
On the other hand, we *do* have to handle SNAP-inside-802.1Q, because this
is actually allowed by the standards. So this commit also adds that
support.
I verified that, with this change, both SNAP and Ethernet packets are
properly recognized both with and without 802.1Q encapsulation.
I was a bit surprised to find out that Linux does not accept
SNAP-encapsulated IP frames on Ethernet.
Here's a summary of how frames are handled before and after this commit:
Common cases
------------
Ethernet
+------------+
1. |dst|src|TYPE|
+------------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
2. |dst|src| len| |aa|aa|03| |000000|TYPE|
+------------+ +--------+ +-----------+
Ethernet 802.1Q
+------------+ +---------+
3. |dst|src|8100| |VLAN|TYPE|
+------------+ +---------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
4. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |000000|TYPE|
+------------+ +---------+ +--------+ +-----------+
Unusual cases
-------------
Ethernet LLC SNAP 802.1Q
+------------+ +--------+ +-----------+ +---------+
5. |dst|src| len| |aa|aa|03| |000000|8100| |VLAN|TYPE|
+------------+ +--------+ +-----------+ +---------+
Ethernet LLC
+------------+ +--------+
6. |dst|src| len| |xx|xx|xx|
+------------+ +--------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
7. |dst|src| len| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +--------+ +-----------+
Ethernet 802.1Q LLC
+------------+ +---------+ +--------+
8. |dst|src|8100| |VLAN| LEN| |xx|xx|xx|
+------------+ +---------+ +--------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
9. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +---------+ +--------+ +-----------+
Behavior
--------
--------------- --------------- -------------------------------------
Before After
this commit this commit
dl_type dl_vlan dl_type dl_vlan Notes
------- ------- ------- ------- -------------------------------------
1. TYPE ffff TYPE ffff no change
2. TYPE ffff TYPE ffff no change
3. TYPE VLAN TYPE VLAN no change
4. LEN VLAN TYPE VLAN proposal fixes behavior
5. TYPE VLAN 8100 ffff 802.1Q says this is invalid framing
6. 05ff ffff 05ff ffff no change
7. 05ff ffff 05ff ffff no change
8. LEN VLAN 05ff VLAN proposal fixes behavior
9. LEN VLAN 05ff VLAN proposal fixes behavior
Signed-off-by: Ben Pfaff <blp@nicira.com>
2010-08-10 11:35:46 -07:00
|
|
|
|
|
|
|
__skb_pull(skb, sizeof(struct llc_snap_hdr));
|
|
|
|
return llc->ethertype;
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
|
2011-02-01 22:54:11 -08:00
|
|
|
static int parse_icmpv6(struct sk_buff *skb, struct sw_flow_key *key,
|
2011-05-18 11:30:07 -07:00
|
|
|
int *key_lenp, int nh_len)
|
2011-02-01 22:54:11 -08:00
|
|
|
{
|
|
|
|
struct icmp6hdr *icmp = icmp6_hdr(skb);
|
2011-05-18 11:30:07 -07:00
|
|
|
int error = 0;
|
|
|
|
int key_len;
|
2011-02-01 22:54:11 -08:00
|
|
|
|
|
|
|
/* The ICMPv6 type and code fields use the 16-bit transport port
|
2011-02-25 16:46:19 -08:00
|
|
|
* fields, so we need to store them in 16-bit network byte order.
|
|
|
|
*/
|
2011-05-18 11:30:07 -07:00
|
|
|
key->ipv6.tp.src = htons(icmp->icmp6_type);
|
|
|
|
key->ipv6.tp.dst = htons(icmp->icmp6_code);
|
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
|
2011-02-01 22:54:11 -08:00
|
|
|
|
2011-02-25 16:46:19 -08:00
|
|
|
if (icmp->icmp6_code == 0 &&
|
|
|
|
(icmp->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION ||
|
|
|
|
icmp->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT)) {
|
2011-03-02 14:51:31 -08:00
|
|
|
int icmp_len = skb->len - skb_transport_offset(skb);
|
2011-02-01 22:54:11 -08:00
|
|
|
struct nd_msg *nd;
|
|
|
|
int offset;
|
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv6.nd);
|
|
|
|
|
2011-02-01 22:54:11 -08:00
|
|
|
/* In order to process neighbor discovery options, we need the
|
2011-02-25 16:46:19 -08:00
|
|
|
* entire packet.
|
|
|
|
*/
|
|
|
|
if (unlikely(icmp_len < sizeof(*nd)))
|
2011-05-18 11:30:07 -07:00
|
|
|
goto out;
|
|
|
|
if (unlikely(skb_linearize(skb))) {
|
|
|
|
error = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-02-01 22:54:11 -08:00
|
|
|
|
|
|
|
nd = (struct nd_msg *)skb_transport_header(skb);
|
2011-05-18 11:30:07 -07:00
|
|
|
ipv6_addr_copy(&key->ipv6.nd.target, &nd->target);
|
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv6.nd);
|
2011-02-01 22:54:11 -08:00
|
|
|
|
|
|
|
icmp_len -= sizeof(*nd);
|
|
|
|
offset = 0;
|
|
|
|
while (icmp_len >= 8) {
|
|
|
|
struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)(nd->opt + offset);
|
|
|
|
int opt_len = nd_opt->nd_opt_len * 8;
|
|
|
|
|
2011-02-25 16:46:19 -08:00
|
|
|
if (unlikely(!opt_len || opt_len > icmp_len))
|
2011-02-01 22:54:11 -08:00
|
|
|
goto invalid;
|
|
|
|
|
2011-02-25 16:46:19 -08:00
|
|
|
/* Store the link layer address if the appropriate
|
|
|
|
* option is provided. It is considered an error if
|
|
|
|
* the same link layer option is specified twice.
|
|
|
|
*/
|
2011-02-01 22:54:11 -08:00
|
|
|
if (nd_opt->nd_opt_type == ND_OPT_SOURCE_LL_ADDR
|
2011-02-25 16:46:19 -08:00
|
|
|
&& opt_len == 8) {
|
2011-05-18 11:30:07 -07:00
|
|
|
if (unlikely(!is_zero_ether_addr(key->ipv6.nd.sll)))
|
2011-02-01 22:54:11 -08:00
|
|
|
goto invalid;
|
2011-05-18 11:30:07 -07:00
|
|
|
memcpy(key->ipv6.nd.sll,
|
2011-02-25 16:46:19 -08:00
|
|
|
&nd->opt[offset+sizeof(*nd_opt)], ETH_ALEN);
|
2011-02-01 22:54:11 -08:00
|
|
|
} else if (nd_opt->nd_opt_type == ND_OPT_TARGET_LL_ADDR
|
2011-02-25 16:46:19 -08:00
|
|
|
&& opt_len == 8) {
|
2011-05-18 11:30:07 -07:00
|
|
|
if (unlikely(!is_zero_ether_addr(key->ipv6.nd.tll)))
|
2011-02-01 22:54:11 -08:00
|
|
|
goto invalid;
|
2011-05-18 11:30:07 -07:00
|
|
|
memcpy(key->ipv6.nd.tll,
|
2011-02-25 16:46:19 -08:00
|
|
|
&nd->opt[offset+sizeof(*nd_opt)], ETH_ALEN);
|
2011-02-01 22:54:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
icmp_len -= opt_len;
|
|
|
|
offset += opt_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
goto out;
|
2011-02-01 22:54:11 -08:00
|
|
|
|
|
|
|
invalid:
|
2011-05-18 11:30:07 -07:00
|
|
|
memset(&key->ipv6.nd.target, 0, sizeof(key->ipv6.nd.target));
|
|
|
|
memset(key->ipv6.nd.sll, 0, sizeof(key->ipv6.nd.sll));
|
|
|
|
memset(key->ipv6.nd.tll, 0, sizeof(key->ipv6.nd.tll));
|
2011-02-01 22:54:11 -08:00
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
out:
|
|
|
|
*key_lenp = key_len;
|
|
|
|
return error;
|
2011-02-01 22:54:11 -08:00
|
|
|
}
|
|
|
|
|
2010-08-13 10:47:44 -07:00
|
|
|
/**
|
|
|
|
* flow_extract - extracts a flow key from an Ethernet frame.
|
|
|
|
* @skb: sk_buff that contains the frame, with skb->data pointing to the
|
|
|
|
* Ethernet header
|
|
|
|
* @in_port: port number on which @skb was received.
|
|
|
|
* @key: output flow key
|
2011-05-18 11:30:07 -07:00
|
|
|
* @key_lenp: length of output flow key
|
2010-08-13 10:47:44 -07:00
|
|
|
*
|
|
|
|
* The caller must ensure that skb->len >= ETH_HLEN.
|
|
|
|
*
|
2010-08-27 12:32:05 -07:00
|
|
|
* Returns 0 if successful, otherwise a negative errno value.
|
|
|
|
*
|
2010-08-27 12:41:00 -07:00
|
|
|
* Initializes @skb header pointers as follows:
|
|
|
|
*
|
|
|
|
* - skb->mac_header: the Ethernet header.
|
|
|
|
*
|
|
|
|
* - skb->network_header: just past the Ethernet header, or just past the
|
|
|
|
* VLAN header, to the first byte of the Ethernet payload.
|
|
|
|
*
|
2010-12-29 19:03:46 -08:00
|
|
|
* - skb->transport_header: If key->dl_type is ETH_P_IP or ETH_P_IPV6
|
|
|
|
* on output, then just past the IP header, if one is present and
|
|
|
|
* of a correct length, otherwise the same as skb->network_header.
|
|
|
|
* For other key->dl_type values it is left untouched.
|
2010-08-13 10:47:44 -07:00
|
|
|
*/
|
2011-01-23 18:44:44 -08:00
|
|
|
int flow_extract(struct sk_buff *skb, u16 in_port, struct sw_flow_key *key,
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
int *key_lenp)
|
2009-07-08 13:19:16 -07:00
|
|
|
{
|
2011-05-18 11:30:07 -07:00
|
|
|
int error = 0;
|
|
|
|
int key_len = SW_FLOW_KEY_OFFSET(eth);
|
2009-07-08 13:19:16 -07:00
|
|
|
struct ethhdr *eth;
|
|
|
|
|
2011-01-17 14:34:55 -08:00
|
|
|
memset(key, 0, sizeof(*key));
|
2011-05-18 11:30:07 -07:00
|
|
|
key->eth.tun_id = OVS_CB(skb)->tun_id;
|
|
|
|
key->eth.in_port = in_port;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
skb_reset_mac_header(skb);
|
|
|
|
|
2011-05-10 11:48:36 -07:00
|
|
|
/* Link layer. We are guaranteed to have at least the 14 byte Ethernet
|
|
|
|
* header in the linear data area.
|
|
|
|
*/
|
datapath: Fix handling of 802.1Q and SNAP headers.
The kernel and user datapaths have code that assumes that 802.1Q headers
are used only inside Ethernet II frames, not inside SNAP-encapsulated
frames. But the kernel and user flow_extract() implementations would
interpret 802.1Q headers inside SNAP headers as being valid VLANs. This
would cause packet corruption if any VLAN-related actions were to be taken,
so change the two flow_extract() implementations only to accept 802.1Q as
an Ethernet II frame type, not as a SNAP-encoded frame type.
802.1Q-2005 says that this is correct anyhow:
Where the ISS instance used to transmit and receive tagged frames is
provided by a media access control method that can support Ethernet
Type encoding directly (e.g., is an IEEE 802.3 or IEEE 802.11 MAC) or
is media access method independent (e.g., 6.6), the TPID is Ethernet
Type encoded, i.e., is two octets in length and comprises solely the
assigned Ethernet Type value.
Where the ISS instance is provided by a media access method that
cannot directly support Ethernet Type encoding (e.g., is an IEEE
802.5 or FDDI MAC), the TPID is encoded according to the rule for
a Subnetwork Access Protocol (Clause 10 of IEEE Std 802) that
encapsulates Ethernet frames over LLC, and comprises the SNAP
header (AA-AA-03) followed by the SNAP PID (00-00-00) followed by
the two octets of the assigned Ethernet Type value.
All of the media that OVS handles supports Ethernet Type fields, so to me
that means that we don't have to handle 802.1Q-inside-SNAP.
On the other hand, we *do* have to handle SNAP-inside-802.1Q, because this
is actually allowed by the standards. So this commit also adds that
support.
I verified that, with this change, both SNAP and Ethernet packets are
properly recognized both with and without 802.1Q encapsulation.
I was a bit surprised to find out that Linux does not accept
SNAP-encapsulated IP frames on Ethernet.
Here's a summary of how frames are handled before and after this commit:
Common cases
------------
Ethernet
+------------+
1. |dst|src|TYPE|
+------------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
2. |dst|src| len| |aa|aa|03| |000000|TYPE|
+------------+ +--------+ +-----------+
Ethernet 802.1Q
+------------+ +---------+
3. |dst|src|8100| |VLAN|TYPE|
+------------+ +---------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
4. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |000000|TYPE|
+------------+ +---------+ +--------+ +-----------+
Unusual cases
-------------
Ethernet LLC SNAP 802.1Q
+------------+ +--------+ +-----------+ +---------+
5. |dst|src| len| |aa|aa|03| |000000|8100| |VLAN|TYPE|
+------------+ +--------+ +-----------+ +---------+
Ethernet LLC
+------------+ +--------+
6. |dst|src| len| |xx|xx|xx|
+------------+ +--------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
7. |dst|src| len| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +--------+ +-----------+
Ethernet 802.1Q LLC
+------------+ +---------+ +--------+
8. |dst|src|8100| |VLAN| LEN| |xx|xx|xx|
+------------+ +---------+ +--------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
9. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +---------+ +--------+ +-----------+
Behavior
--------
--------------- --------------- -------------------------------------
Before After
this commit this commit
dl_type dl_vlan dl_type dl_vlan Notes
------- ------- ------- ------- -------------------------------------
1. TYPE ffff TYPE ffff no change
2. TYPE ffff TYPE ffff no change
3. TYPE VLAN TYPE VLAN no change
4. LEN VLAN TYPE VLAN proposal fixes behavior
5. TYPE VLAN 8100 ffff 802.1Q says this is invalid framing
6. 05ff ffff 05ff ffff no change
7. 05ff ffff 05ff ffff no change
8. LEN VLAN 05ff VLAN proposal fixes behavior
9. LEN VLAN 05ff VLAN proposal fixes behavior
Signed-off-by: Ben Pfaff <blp@nicira.com>
2010-08-10 11:35:46 -07:00
|
|
|
eth = eth_hdr(skb);
|
2011-05-18 11:30:07 -07:00
|
|
|
memcpy(key->eth.src, eth->h_source, ETH_ALEN);
|
|
|
|
memcpy(key->eth.dst, eth->h_dest, ETH_ALEN);
|
|
|
|
|
datapath: Fix handling of 802.1Q and SNAP headers.
The kernel and user datapaths have code that assumes that 802.1Q headers
are used only inside Ethernet II frames, not inside SNAP-encapsulated
frames. But the kernel and user flow_extract() implementations would
interpret 802.1Q headers inside SNAP headers as being valid VLANs. This
would cause packet corruption if any VLAN-related actions were to be taken,
so change the two flow_extract() implementations only to accept 802.1Q as
an Ethernet II frame type, not as a SNAP-encoded frame type.
802.1Q-2005 says that this is correct anyhow:
Where the ISS instance used to transmit and receive tagged frames is
provided by a media access control method that can support Ethernet
Type encoding directly (e.g., is an IEEE 802.3 or IEEE 802.11 MAC) or
is media access method independent (e.g., 6.6), the TPID is Ethernet
Type encoded, i.e., is two octets in length and comprises solely the
assigned Ethernet Type value.
Where the ISS instance is provided by a media access method that
cannot directly support Ethernet Type encoding (e.g., is an IEEE
802.5 or FDDI MAC), the TPID is encoded according to the rule for
a Subnetwork Access Protocol (Clause 10 of IEEE Std 802) that
encapsulates Ethernet frames over LLC, and comprises the SNAP
header (AA-AA-03) followed by the SNAP PID (00-00-00) followed by
the two octets of the assigned Ethernet Type value.
All of the media that OVS handles supports Ethernet Type fields, so to me
that means that we don't have to handle 802.1Q-inside-SNAP.
On the other hand, we *do* have to handle SNAP-inside-802.1Q, because this
is actually allowed by the standards. So this commit also adds that
support.
I verified that, with this change, both SNAP and Ethernet packets are
properly recognized both with and without 802.1Q encapsulation.
I was a bit surprised to find out that Linux does not accept
SNAP-encapsulated IP frames on Ethernet.
Here's a summary of how frames are handled before and after this commit:
Common cases
------------
Ethernet
+------------+
1. |dst|src|TYPE|
+------------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
2. |dst|src| len| |aa|aa|03| |000000|TYPE|
+------------+ +--------+ +-----------+
Ethernet 802.1Q
+------------+ +---------+
3. |dst|src|8100| |VLAN|TYPE|
+------------+ +---------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
4. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |000000|TYPE|
+------------+ +---------+ +--------+ +-----------+
Unusual cases
-------------
Ethernet LLC SNAP 802.1Q
+------------+ +--------+ +-----------+ +---------+
5. |dst|src| len| |aa|aa|03| |000000|8100| |VLAN|TYPE|
+------------+ +--------+ +-----------+ +---------+
Ethernet LLC
+------------+ +--------+
6. |dst|src| len| |xx|xx|xx|
+------------+ +--------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
7. |dst|src| len| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +--------+ +-----------+
Ethernet 802.1Q LLC
+------------+ +---------+ +--------+
8. |dst|src|8100| |VLAN| LEN| |xx|xx|xx|
+------------+ +---------+ +--------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
9. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +---------+ +--------+ +-----------+
Behavior
--------
--------------- --------------- -------------------------------------
Before After
this commit this commit
dl_type dl_vlan dl_type dl_vlan Notes
------- ------- ------- ------- -------------------------------------
1. TYPE ffff TYPE ffff no change
2. TYPE ffff TYPE ffff no change
3. TYPE VLAN TYPE VLAN no change
4. LEN VLAN TYPE VLAN proposal fixes behavior
5. TYPE VLAN 8100 ffff 802.1Q says this is invalid framing
6. 05ff ffff 05ff ffff no change
7. 05ff ffff 05ff ffff no change
8. LEN VLAN 05ff VLAN proposal fixes behavior
9. LEN VLAN 05ff VLAN proposal fixes behavior
Signed-off-by: Ben Pfaff <blp@nicira.com>
2010-08-10 11:35:46 -07:00
|
|
|
__skb_pull(skb, 2 * ETH_ALEN);
|
2010-12-29 22:13:15 -08:00
|
|
|
|
|
|
|
if (vlan_tx_tag_present(skb))
|
2011-05-18 11:30:07 -07:00
|
|
|
key->eth.tci = htons(vlan_get_tci(skb));
|
2010-12-29 22:13:15 -08:00
|
|
|
else if (eth->h_proto == htons(ETH_P_8021Q))
|
2011-05-10 11:48:36 -07:00
|
|
|
if (unlikely(parse_vlan(skb, key)))
|
|
|
|
return -ENOMEM;
|
2010-12-29 22:13:15 -08:00
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
key->eth.type = parse_ethertype(skb);
|
|
|
|
if (unlikely(key->eth.type == htons(0)))
|
2011-05-10 11:48:36 -07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
datapath: Fix handling of 802.1Q and SNAP headers.
The kernel and user datapaths have code that assumes that 802.1Q headers
are used only inside Ethernet II frames, not inside SNAP-encapsulated
frames. But the kernel and user flow_extract() implementations would
interpret 802.1Q headers inside SNAP headers as being valid VLANs. This
would cause packet corruption if any VLAN-related actions were to be taken,
so change the two flow_extract() implementations only to accept 802.1Q as
an Ethernet II frame type, not as a SNAP-encoded frame type.
802.1Q-2005 says that this is correct anyhow:
Where the ISS instance used to transmit and receive tagged frames is
provided by a media access control method that can support Ethernet
Type encoding directly (e.g., is an IEEE 802.3 or IEEE 802.11 MAC) or
is media access method independent (e.g., 6.6), the TPID is Ethernet
Type encoded, i.e., is two octets in length and comprises solely the
assigned Ethernet Type value.
Where the ISS instance is provided by a media access method that
cannot directly support Ethernet Type encoding (e.g., is an IEEE
802.5 or FDDI MAC), the TPID is encoded according to the rule for
a Subnetwork Access Protocol (Clause 10 of IEEE Std 802) that
encapsulates Ethernet frames over LLC, and comprises the SNAP
header (AA-AA-03) followed by the SNAP PID (00-00-00) followed by
the two octets of the assigned Ethernet Type value.
All of the media that OVS handles supports Ethernet Type fields, so to me
that means that we don't have to handle 802.1Q-inside-SNAP.
On the other hand, we *do* have to handle SNAP-inside-802.1Q, because this
is actually allowed by the standards. So this commit also adds that
support.
I verified that, with this change, both SNAP and Ethernet packets are
properly recognized both with and without 802.1Q encapsulation.
I was a bit surprised to find out that Linux does not accept
SNAP-encapsulated IP frames on Ethernet.
Here's a summary of how frames are handled before and after this commit:
Common cases
------------
Ethernet
+------------+
1. |dst|src|TYPE|
+------------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
2. |dst|src| len| |aa|aa|03| |000000|TYPE|
+------------+ +--------+ +-----------+
Ethernet 802.1Q
+------------+ +---------+
3. |dst|src|8100| |VLAN|TYPE|
+------------+ +---------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
4. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |000000|TYPE|
+------------+ +---------+ +--------+ +-----------+
Unusual cases
-------------
Ethernet LLC SNAP 802.1Q
+------------+ +--------+ +-----------+ +---------+
5. |dst|src| len| |aa|aa|03| |000000|8100| |VLAN|TYPE|
+------------+ +--------+ +-----------+ +---------+
Ethernet LLC
+------------+ +--------+
6. |dst|src| len| |xx|xx|xx|
+------------+ +--------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
7. |dst|src| len| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +--------+ +-----------+
Ethernet 802.1Q LLC
+------------+ +---------+ +--------+
8. |dst|src|8100| |VLAN| LEN| |xx|xx|xx|
+------------+ +---------+ +--------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
9. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +---------+ +--------+ +-----------+
Behavior
--------
--------------- --------------- -------------------------------------
Before After
this commit this commit
dl_type dl_vlan dl_type dl_vlan Notes
------- ------- ------- ------- -------------------------------------
1. TYPE ffff TYPE ffff no change
2. TYPE ffff TYPE ffff no change
3. TYPE VLAN TYPE VLAN no change
4. LEN VLAN TYPE VLAN proposal fixes behavior
5. TYPE VLAN 8100 ffff 802.1Q says this is invalid framing
6. 05ff ffff 05ff ffff no change
7. 05ff ffff 05ff ffff no change
8. LEN VLAN 05ff VLAN proposal fixes behavior
9. LEN VLAN 05ff VLAN proposal fixes behavior
Signed-off-by: Ben Pfaff <blp@nicira.com>
2010-08-10 11:35:46 -07:00
|
|
|
skb_reset_network_header(skb);
|
2011-05-10 11:48:36 -07:00
|
|
|
__skb_push(skb, skb->data - skb_mac_header(skb));
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
/* Network layer. */
|
2011-05-18 11:30:07 -07:00
|
|
|
if (key->eth.type == htons(ETH_P_IP)) {
|
2010-08-27 12:32:05 -07:00
|
|
|
struct iphdr *nh;
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
__be16 offset;
|
2011-05-18 11:30:07 -07:00
|
|
|
|
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv4.addr);
|
2010-08-27 12:32:05 -07:00
|
|
|
|
|
|
|
error = check_iphdr(skb);
|
|
|
|
if (unlikely(error)) {
|
|
|
|
if (error == -EINVAL) {
|
|
|
|
skb->transport_header = skb->network_header;
|
2011-05-18 11:30:07 -07:00
|
|
|
error = 0;
|
2010-08-27 12:32:05 -07:00
|
|
|
}
|
2011-05-18 11:30:07 -07:00
|
|
|
goto out;
|
2010-08-27 12:32:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nh = ip_hdr(skb);
|
2011-05-18 11:30:07 -07:00
|
|
|
key->ipv4.addr.src = nh->saddr;
|
|
|
|
key->ipv4.addr.dst = nh->daddr;
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
|
2011-06-08 12:28:57 -07:00
|
|
|
key->ip.proto = nh->protocol;
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
key->ip.tos_frag = nh->tos & ~INET_ECN_MASK;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
offset = nh->frag_off & htons(IP_OFFSET);
|
|
|
|
if (offset) {
|
|
|
|
key->ip.tos_frag |= OVS_FRAG_TYPE_LATER;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (nh->frag_off & htons(IP_MF) ||
|
|
|
|
skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
|
|
|
|
key->ip.tos_frag |= OVS_FRAG_TYPE_FIRST;
|
2010-08-29 14:28:58 -07:00
|
|
|
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
/* Transport layer. */
|
2011-06-08 12:28:57 -07:00
|
|
|
if (key->ip.proto == IPPROTO_TCP) {
|
2011-06-08 12:23:05 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
if (tcphdr_ok(skb)) {
|
2011-06-08 12:23:05 -07:00
|
|
|
struct tcphdr *tcp = tcp_hdr(skb);
|
|
|
|
key->ipv4.tp.src = tcp->source;
|
|
|
|
key->ipv4.tp.dst = tcp->dest;
|
|
|
|
}
|
2011-06-08 12:28:57 -07:00
|
|
|
} else if (key->ip.proto == IPPROTO_UDP) {
|
2011-06-08 12:23:05 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
if (udphdr_ok(skb)) {
|
2011-06-08 12:23:05 -07:00
|
|
|
struct udphdr *udp = udp_hdr(skb);
|
|
|
|
key->ipv4.tp.src = udp->source;
|
|
|
|
key->ipv4.tp.dst = udp->dest;
|
|
|
|
}
|
2011-06-08 12:28:57 -07:00
|
|
|
} else if (key->ip.proto == IPPROTO_ICMP) {
|
2011-06-08 12:23:05 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
if (icmphdr_ok(skb)) {
|
2011-06-08 12:23:05 -07:00
|
|
|
struct icmphdr *icmp = icmp_hdr(skb);
|
|
|
|
/* The ICMP type and code fields use the 16-bit
|
|
|
|
* transport port fields, so we need to store them
|
|
|
|
* in 16-bit network byte order. */
|
|
|
|
key->ipv4.tp.src = htons(icmp->type);
|
|
|
|
key->ipv4.tp.dst = htons(icmp->code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
} else if (key->eth.type == htons(ETH_P_ARP) && arphdr_ok(skb)) {
|
2009-07-16 12:58:28 -07:00
|
|
|
struct arp_eth_header *arp;
|
|
|
|
|
|
|
|
arp = (struct arp_eth_header *)skb_network_header(skb);
|
|
|
|
|
2010-03-04 17:55:44 -05:00
|
|
|
if (arp->ar_hrd == htons(ARPHRD_ETHER)
|
2009-11-16 15:24:35 -08:00
|
|
|
&& arp->ar_pro == htons(ETH_P_IP)
|
|
|
|
&& arp->ar_hln == ETH_ALEN
|
|
|
|
&& arp->ar_pln == 4) {
|
|
|
|
|
|
|
|
/* We only match on the lower 8 bits of the opcode. */
|
2010-08-29 14:28:58 -07:00
|
|
|
if (ntohs(arp->ar_op) <= 0xff)
|
2011-06-08 12:28:57 -07:00
|
|
|
key->ip.proto = ntohs(arp->ar_op);
|
2011-05-18 11:30:07 -07:00
|
|
|
|
2011-06-08 12:28:57 -07:00
|
|
|
if (key->ip.proto == ARPOP_REQUEST
|
|
|
|
|| key->ip.proto == ARPOP_REPLY) {
|
2011-05-18 11:30:07 -07:00
|
|
|
memcpy(&key->ipv4.addr.src, arp->ar_sip, sizeof(key->ipv4.addr.src));
|
|
|
|
memcpy(&key->ipv4.addr.dst, arp->ar_tip, sizeof(key->ipv4.addr.dst));
|
|
|
|
memcpy(key->ipv4.arp.sha, arp->ar_sha, ETH_ALEN);
|
|
|
|
memcpy(key->ipv4.arp.tha, arp->ar_tha, ETH_ALEN);
|
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv4.arp);
|
2009-11-16 15:24:35 -08:00
|
|
|
}
|
|
|
|
}
|
2011-05-18 11:30:07 -07:00
|
|
|
} else if (key->eth.type == htons(ETH_P_IPV6)) {
|
2010-12-29 19:03:46 -08:00
|
|
|
int nh_len; /* IPv6 Header + Extensions */
|
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
nh_len = parse_ipv6hdr(skb, key, &key_len);
|
2010-12-29 19:03:46 -08:00
|
|
|
if (unlikely(nh_len < 0)) {
|
2011-05-18 11:30:07 -07:00
|
|
|
if (nh_len == -EINVAL)
|
2010-12-29 19:03:46 -08:00
|
|
|
skb->transport_header = skb->network_header;
|
2011-05-18 11:30:07 -07:00
|
|
|
else
|
|
|
|
error = nh_len;
|
|
|
|
goto out;
|
2010-12-29 19:03:46 -08:00
|
|
|
}
|
|
|
|
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
if ((key->ip.tos_frag & OVS_FRAG_TYPE_MASK) == OVS_FRAG_TYPE_LATER)
|
|
|
|
goto out;
|
|
|
|
if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
|
|
|
|
key->ip.tos_frag |= OVS_FRAG_TYPE_FIRST;
|
|
|
|
|
2010-12-29 19:03:46 -08:00
|
|
|
/* Transport layer. */
|
2011-06-08 12:28:57 -07:00
|
|
|
if (key->ip.proto == NEXTHDR_TCP) {
|
2011-05-18 11:30:07 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
|
2010-12-29 19:03:46 -08:00
|
|
|
if (tcphdr_ok(skb)) {
|
|
|
|
struct tcphdr *tcp = tcp_hdr(skb);
|
2011-05-18 11:30:07 -07:00
|
|
|
key->ipv6.tp.src = tcp->source;
|
|
|
|
key->ipv6.tp.dst = tcp->dest;
|
2010-12-29 19:03:46 -08:00
|
|
|
}
|
2011-06-08 12:28:57 -07:00
|
|
|
} else if (key->ip.proto == NEXTHDR_UDP) {
|
2011-05-18 11:30:07 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
|
2010-12-29 19:03:46 -08:00
|
|
|
if (udphdr_ok(skb)) {
|
|
|
|
struct udphdr *udp = udp_hdr(skb);
|
2011-05-18 11:30:07 -07:00
|
|
|
key->ipv6.tp.src = udp->source;
|
|
|
|
key->ipv6.tp.dst = udp->dest;
|
2010-12-29 19:03:46 -08:00
|
|
|
}
|
2011-06-08 12:28:57 -07:00
|
|
|
} else if (key->ip.proto == NEXTHDR_ICMP) {
|
2011-05-18 11:30:07 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
|
2010-12-29 19:03:46 -08:00
|
|
|
if (icmp6hdr_ok(skb)) {
|
2011-05-18 11:30:07 -07:00
|
|
|
error = parse_icmpv6(skb, key, &key_len, nh_len);
|
2011-02-01 22:54:11 -08:00
|
|
|
if (error < 0)
|
2011-05-18 11:30:07 -07:00
|
|
|
goto out;
|
2010-12-29 19:03:46 -08:00
|
|
|
}
|
|
|
|
}
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
2011-05-18 11:30:07 -07:00
|
|
|
|
|
|
|
out:
|
|
|
|
*key_lenp = key_len;
|
|
|
|
return error;
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
u32 flow_hash(const struct sw_flow_key *key, int key_len)
|
2010-04-02 16:46:18 -04:00
|
|
|
{
|
2011-05-18 11:30:07 -07:00
|
|
|
return jhash2((u32*)key, DIV_ROUND_UP(key_len, sizeof(u32)), hash_seed);
|
2010-04-02 16:46:18 -04:00
|
|
|
}
|
|
|
|
|
2011-09-09 19:09:47 -07:00
|
|
|
struct sw_flow * flow_tbl_lookup(struct flow_table *table,
|
|
|
|
struct sw_flow_key *key, int key_len)
|
2010-04-02 16:46:18 -04:00
|
|
|
{
|
2011-09-09 19:09:47 -07:00
|
|
|
struct sw_flow *flow;
|
|
|
|
struct hlist_node *n;
|
|
|
|
struct hlist_head *head;
|
|
|
|
u32 hash;
|
2010-04-02 16:46:18 -04:00
|
|
|
|
2011-09-09 19:09:47 -07:00
|
|
|
hash = flow_hash(key, key_len);
|
|
|
|
|
|
|
|
head = find_bucket(table, hash);
|
|
|
|
hlist_for_each_entry_rcu(flow, n, head, hash_node) {
|
|
|
|
|
|
|
|
if (flow->hash == hash &&
|
|
|
|
!memcmp(&flow->key, key, key_len)) {
|
|
|
|
return flow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void flow_tbl_insert(struct flow_table *table, struct sw_flow *flow)
|
|
|
|
{
|
|
|
|
struct hlist_head *head;
|
|
|
|
|
|
|
|
head = find_bucket(table, flow->hash);
|
|
|
|
hlist_add_head_rcu(&flow->hash_node, head);
|
|
|
|
table->count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void flow_tbl_remove(struct flow_table *table, struct sw_flow *flow)
|
|
|
|
{
|
|
|
|
if (!hlist_unhashed(&flow->hash_node)) {
|
|
|
|
hlist_del_init_rcu(&flow->hash_node);
|
|
|
|
table->count--;
|
|
|
|
BUG_ON(table->count < 0);
|
|
|
|
}
|
2011-01-23 18:44:44 -08:00
|
|
|
}
|
|
|
|
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
static int parse_tos_frag(struct sw_flow_key *swkey, u8 tos, u8 frag)
|
|
|
|
{
|
|
|
|
if (tos & INET_ECN_MASK || frag > OVS_FRAG_TYPE_MAX)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
swkey->ip.tos_frag = tos | frag;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
/* The size of the argument for each %OVS_KEY_ATTR_* Netlink attribute. */
|
2011-10-21 14:38:54 -07:00
|
|
|
const u32 ovs_key_lens[OVS_KEY_ATTR_MAX + 1] = {
|
2011-08-18 10:35:40 -07:00
|
|
|
[OVS_KEY_ATTR_TUN_ID] = 8,
|
|
|
|
[OVS_KEY_ATTR_IN_PORT] = 4,
|
|
|
|
[OVS_KEY_ATTR_ETHERNET] = sizeof(struct ovs_key_ethernet),
|
|
|
|
[OVS_KEY_ATTR_8021Q] = sizeof(struct ovs_key_8021q),
|
|
|
|
[OVS_KEY_ATTR_ETHERTYPE] = 2,
|
|
|
|
[OVS_KEY_ATTR_IPV4] = sizeof(struct ovs_key_ipv4),
|
|
|
|
[OVS_KEY_ATTR_IPV6] = sizeof(struct ovs_key_ipv6),
|
|
|
|
[OVS_KEY_ATTR_TCP] = sizeof(struct ovs_key_tcp),
|
|
|
|
[OVS_KEY_ATTR_UDP] = sizeof(struct ovs_key_udp),
|
|
|
|
[OVS_KEY_ATTR_ICMP] = sizeof(struct ovs_key_icmp),
|
|
|
|
[OVS_KEY_ATTR_ICMPV6] = sizeof(struct ovs_key_icmpv6),
|
|
|
|
[OVS_KEY_ATTR_ARP] = sizeof(struct ovs_key_arp),
|
|
|
|
[OVS_KEY_ATTR_ND] = sizeof(struct ovs_key_nd),
|
2011-06-01 13:39:51 -07:00
|
|
|
};
|
|
|
|
|
2011-01-23 18:44:44 -08:00
|
|
|
/**
|
|
|
|
* flow_from_nlattrs - parses Netlink attributes into a flow key.
|
|
|
|
* @swkey: receives the extracted flow key.
|
2011-05-18 11:30:07 -07:00
|
|
|
* @key_lenp: number of bytes used in @swkey.
|
2011-08-18 10:35:40 -07:00
|
|
|
* @attr: Netlink attribute holding nested %OVS_KEY_ATTR_* Netlink attribute
|
2011-01-26 15:42:00 -08:00
|
|
|
* sequence.
|
2011-01-23 18:44:44 -08:00
|
|
|
*
|
|
|
|
* This state machine accepts the following forms, with [] for optional
|
|
|
|
* elements and | for alternatives:
|
|
|
|
*
|
2011-09-08 16:30:20 -07:00
|
|
|
* [tun_id] [in_port] ethernet [8021q] [ethertype \
|
2011-02-01 22:54:11 -08:00
|
|
|
* [IPv4 [TCP|UDP|ICMP] | IPv6 [TCP|UDP|ICMPv6 [ND]] | ARP]]
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
*
|
|
|
|
* except that IPv4 or IPv6 terminates the sequence if its @ipv4_frag or
|
|
|
|
* @ipv6_frag member, respectively, equals %OVS_FRAG_TYPE_LATER.
|
2011-01-23 18:44:44 -08:00
|
|
|
*/
|
2011-05-18 11:30:07 -07:00
|
|
|
int flow_from_nlattrs(struct sw_flow_key *swkey, int *key_lenp,
|
|
|
|
const struct nlattr *attr)
|
2011-01-23 18:44:44 -08:00
|
|
|
{
|
2011-05-18 11:30:07 -07:00
|
|
|
int error = 0;
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
enum ovs_frag_type frag_type;
|
2011-01-23 18:44:44 -08:00
|
|
|
const struct nlattr *nla;
|
|
|
|
u16 prev_type;
|
|
|
|
int rem;
|
2011-05-18 11:30:07 -07:00
|
|
|
int key_len;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
|
|
|
memset(swkey, 0, sizeof(*swkey));
|
2011-09-08 16:30:20 -07:00
|
|
|
swkey->eth.in_port = USHRT_MAX;
|
2011-05-18 11:30:07 -07:00
|
|
|
swkey->eth.type = htons(ETH_P_802_2);
|
|
|
|
key_len = SW_FLOW_KEY_OFFSET(eth);
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
prev_type = OVS_KEY_ATTR_UNSPEC;
|
2011-01-26 15:42:00 -08:00
|
|
|
nla_for_each_nested(nla, attr, rem) {
|
2011-08-18 10:35:40 -07:00
|
|
|
const struct ovs_key_ethernet *eth_key;
|
|
|
|
const struct ovs_key_8021q *q_key;
|
|
|
|
const struct ovs_key_ipv4 *ipv4_key;
|
|
|
|
const struct ovs_key_ipv6 *ipv6_key;
|
|
|
|
const struct ovs_key_tcp *tcp_key;
|
|
|
|
const struct ovs_key_udp *udp_key;
|
|
|
|
const struct ovs_key_icmp *icmp_key;
|
|
|
|
const struct ovs_key_icmpv6 *icmpv6_key;
|
|
|
|
const struct ovs_key_arp *arp_key;
|
|
|
|
const struct ovs_key_nd *nd_key;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
|
|
|
int type = nla_type(nla);
|
|
|
|
|
2011-10-21 14:38:54 -07:00
|
|
|
if (type > OVS_KEY_ATTR_MAX || nla_len(nla) != ovs_key_lens[type])
|
|
|
|
goto invalid;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
|
|
|
#define TRANSITION(PREV_TYPE, TYPE) (((PREV_TYPE) << 16) | (TYPE))
|
|
|
|
switch (TRANSITION(prev_type, type)) {
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_UNSPEC, OVS_KEY_ATTR_TUN_ID):
|
2011-05-18 11:30:07 -07:00
|
|
|
swkey->eth.tun_id = nla_get_be64(nla);
|
2011-01-23 18:44:44 -08:00
|
|
|
break;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_UNSPEC, OVS_KEY_ATTR_IN_PORT):
|
|
|
|
case TRANSITION(OVS_KEY_ATTR_TUN_ID, OVS_KEY_ATTR_IN_PORT):
|
2011-01-23 18:44:44 -08:00
|
|
|
if (nla_get_u32(nla) >= DP_MAX_PORTS)
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
|
|
|
swkey->eth.in_port = nla_get_u32(nla);
|
2011-01-23 18:44:44 -08:00
|
|
|
break;
|
|
|
|
|
2011-09-08 16:30:20 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_UNSPEC, OVS_KEY_ATTR_ETHERNET):
|
|
|
|
case TRANSITION(OVS_KEY_ATTR_TUN_ID, OVS_KEY_ATTR_ETHERNET):
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_IN_PORT, OVS_KEY_ATTR_ETHERNET):
|
2011-01-23 18:44:44 -08:00
|
|
|
eth_key = nla_data(nla);
|
2011-05-18 11:30:07 -07:00
|
|
|
memcpy(swkey->eth.src, eth_key->eth_src, ETH_ALEN);
|
|
|
|
memcpy(swkey->eth.dst, eth_key->eth_dst, ETH_ALEN);
|
2011-01-23 18:44:44 -08:00
|
|
|
break;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_ETHERNET, OVS_KEY_ATTR_8021Q):
|
2011-01-23 18:44:44 -08:00
|
|
|
q_key = nla_data(nla);
|
|
|
|
/* Only standard 0x8100 VLANs currently supported. */
|
|
|
|
if (q_key->q_tpid != htons(ETH_P_8021Q))
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
2011-01-23 18:44:44 -08:00
|
|
|
if (q_key->q_tci & htons(VLAN_TAG_PRESENT))
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
|
|
|
swkey->eth.tci = q_key->q_tci | htons(VLAN_TAG_PRESENT);
|
2011-01-23 18:44:44 -08:00
|
|
|
break;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_8021Q, OVS_KEY_ATTR_ETHERTYPE):
|
|
|
|
case TRANSITION(OVS_KEY_ATTR_ETHERNET, OVS_KEY_ATTR_ETHERTYPE):
|
2011-05-18 11:30:07 -07:00
|
|
|
swkey->eth.type = nla_get_be16(nla);
|
|
|
|
if (ntohs(swkey->eth.type) < 1536)
|
|
|
|
goto invalid;
|
2011-01-23 18:44:44 -08:00
|
|
|
break;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_ETHERTYPE, OVS_KEY_ATTR_IPV4):
|
2011-05-18 11:30:07 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv4.addr);
|
|
|
|
if (swkey->eth.type != htons(ETH_P_IP))
|
|
|
|
goto invalid;
|
2011-01-23 18:44:44 -08:00
|
|
|
ipv4_key = nla_data(nla);
|
2011-06-08 12:28:57 -07:00
|
|
|
swkey->ip.proto = ipv4_key->ipv4_proto;
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
if (parse_tos_frag(swkey, ipv4_key->ipv4_tos,
|
|
|
|
ipv4_key->ipv4_frag))
|
|
|
|
goto invalid;
|
2011-05-18 11:30:07 -07:00
|
|
|
swkey->ipv4.addr.src = ipv4_key->ipv4_src;
|
|
|
|
swkey->ipv4.addr.dst = ipv4_key->ipv4_dst;
|
2011-01-23 18:44:44 -08:00
|
|
|
break;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_ETHERTYPE, OVS_KEY_ATTR_IPV6):
|
2011-05-18 11:30:07 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv6.addr);
|
|
|
|
if (swkey->eth.type != htons(ETH_P_IPV6))
|
|
|
|
goto invalid;
|
2010-12-29 19:03:46 -08:00
|
|
|
ipv6_key = nla_data(nla);
|
2011-06-08 12:28:57 -07:00
|
|
|
swkey->ip.proto = ipv6_key->ipv6_proto;
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
if (parse_tos_frag(swkey, ipv6_key->ipv6_tos,
|
|
|
|
ipv6_key->ipv6_frag))
|
|
|
|
goto invalid;
|
2011-05-18 11:30:07 -07:00
|
|
|
memcpy(&swkey->ipv6.addr.src, ipv6_key->ipv6_src,
|
|
|
|
sizeof(swkey->ipv6.addr.src));
|
|
|
|
memcpy(&swkey->ipv6.addr.dst, ipv6_key->ipv6_dst,
|
|
|
|
sizeof(swkey->ipv6.addr.dst));
|
2010-12-29 19:03:46 -08:00
|
|
|
break;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_IPV4, OVS_KEY_ATTR_TCP):
|
2011-05-18 11:30:07 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
|
2011-06-08 12:28:57 -07:00
|
|
|
if (swkey->ip.proto != IPPROTO_TCP)
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
|
|
|
tcp_key = nla_data(nla);
|
|
|
|
swkey->ipv4.tp.src = tcp_key->tcp_src;
|
|
|
|
swkey->ipv4.tp.dst = tcp_key->tcp_dst;
|
|
|
|
break;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_IPV6, OVS_KEY_ATTR_TCP):
|
2011-05-18 11:30:07 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
|
2011-06-08 12:28:57 -07:00
|
|
|
if (swkey->ip.proto != IPPROTO_TCP)
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
2011-01-23 18:44:44 -08:00
|
|
|
tcp_key = nla_data(nla);
|
2011-05-18 11:30:07 -07:00
|
|
|
swkey->ipv6.tp.src = tcp_key->tcp_src;
|
|
|
|
swkey->ipv6.tp.dst = tcp_key->tcp_dst;
|
2011-01-23 18:44:44 -08:00
|
|
|
break;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_IPV4, OVS_KEY_ATTR_UDP):
|
2011-05-18 11:30:07 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
|
2011-06-08 12:28:57 -07:00
|
|
|
if (swkey->ip.proto != IPPROTO_UDP)
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
|
|
|
udp_key = nla_data(nla);
|
|
|
|
swkey->ipv4.tp.src = udp_key->udp_src;
|
|
|
|
swkey->ipv4.tp.dst = udp_key->udp_dst;
|
|
|
|
break;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_IPV6, OVS_KEY_ATTR_UDP):
|
2011-05-18 11:30:07 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
|
2011-06-08 12:28:57 -07:00
|
|
|
if (swkey->ip.proto != IPPROTO_UDP)
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
2011-01-23 18:44:44 -08:00
|
|
|
udp_key = nla_data(nla);
|
2011-05-18 11:30:07 -07:00
|
|
|
swkey->ipv6.tp.src = udp_key->udp_src;
|
|
|
|
swkey->ipv6.tp.dst = udp_key->udp_dst;
|
2011-01-23 18:44:44 -08:00
|
|
|
break;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_IPV4, OVS_KEY_ATTR_ICMP):
|
2011-05-18 11:30:07 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
|
2011-06-08 12:28:57 -07:00
|
|
|
if (swkey->ip.proto != IPPROTO_ICMP)
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
2011-01-23 18:44:44 -08:00
|
|
|
icmp_key = nla_data(nla);
|
2011-05-18 11:30:07 -07:00
|
|
|
swkey->ipv4.tp.src = htons(icmp_key->icmp_type);
|
|
|
|
swkey->ipv4.tp.dst = htons(icmp_key->icmp_code);
|
2011-01-23 18:44:44 -08:00
|
|
|
break;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_IPV6, OVS_KEY_ATTR_ICMPV6):
|
2011-05-18 11:30:07 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
|
2011-06-08 12:28:57 -07:00
|
|
|
if (swkey->ip.proto != IPPROTO_ICMPV6)
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
2010-12-29 19:03:46 -08:00
|
|
|
icmpv6_key = nla_data(nla);
|
2011-05-18 11:30:07 -07:00
|
|
|
swkey->ipv6.tp.src = htons(icmpv6_key->icmpv6_type);
|
|
|
|
swkey->ipv6.tp.dst = htons(icmpv6_key->icmpv6_code);
|
2010-12-29 19:03:46 -08:00
|
|
|
break;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_ETHERTYPE, OVS_KEY_ATTR_ARP):
|
2011-05-18 11:30:07 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv4.arp);
|
|
|
|
if (swkey->eth.type != htons(ETH_P_ARP))
|
|
|
|
goto invalid;
|
2011-01-23 18:44:44 -08:00
|
|
|
arp_key = nla_data(nla);
|
2011-05-18 11:30:07 -07:00
|
|
|
swkey->ipv4.addr.src = arp_key->arp_sip;
|
|
|
|
swkey->ipv4.addr.dst = arp_key->arp_tip;
|
2011-01-23 18:44:44 -08:00
|
|
|
if (arp_key->arp_op & htons(0xff00))
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
2011-06-08 12:28:57 -07:00
|
|
|
swkey->ip.proto = ntohs(arp_key->arp_op);
|
2011-05-18 11:30:07 -07:00
|
|
|
memcpy(swkey->ipv4.arp.sha, arp_key->arp_sha, ETH_ALEN);
|
|
|
|
memcpy(swkey->ipv4.arp.tha, arp_key->arp_tha, ETH_ALEN);
|
2011-01-23 18:44:44 -08:00
|
|
|
break;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_ICMPV6, OVS_KEY_ATTR_ND):
|
2011-05-18 11:30:07 -07:00
|
|
|
key_len = SW_FLOW_KEY_OFFSET(ipv6.nd);
|
|
|
|
if (swkey->ipv6.tp.src != htons(NDISC_NEIGHBOUR_SOLICITATION)
|
|
|
|
&& swkey->ipv6.tp.src != htons(NDISC_NEIGHBOUR_ADVERTISEMENT))
|
|
|
|
goto invalid;
|
2011-02-01 22:54:11 -08:00
|
|
|
nd_key = nla_data(nla);
|
2011-05-18 11:30:07 -07:00
|
|
|
memcpy(&swkey->ipv6.nd.target, nd_key->nd_target,
|
|
|
|
sizeof(swkey->ipv6.nd.target));
|
|
|
|
memcpy(swkey->ipv6.nd.sll, nd_key->nd_sll, ETH_ALEN);
|
|
|
|
memcpy(swkey->ipv6.nd.tll, nd_key->nd_tll, ETH_ALEN);
|
2011-02-01 22:54:11 -08:00
|
|
|
break;
|
|
|
|
|
2011-01-23 18:44:44 -08:00
|
|
|
default:
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
2011-01-23 18:44:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
prev_type = type;
|
|
|
|
}
|
|
|
|
if (rem)
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
frag_type = swkey->ip.tos_frag & OVS_FRAG_TYPE_MASK;
|
2011-01-23 18:44:44 -08:00
|
|
|
switch (prev_type) {
|
2011-08-18 10:35:40 -07:00
|
|
|
case OVS_KEY_ATTR_UNSPEC:
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case OVS_KEY_ATTR_TUN_ID:
|
|
|
|
case OVS_KEY_ATTR_IN_PORT:
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case OVS_KEY_ATTR_ETHERNET:
|
|
|
|
case OVS_KEY_ATTR_8021Q:
|
2011-05-18 11:30:07 -07:00
|
|
|
goto ok;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case OVS_KEY_ATTR_ETHERTYPE:
|
2011-05-18 11:30:07 -07:00
|
|
|
if (swkey->eth.type == htons(ETH_P_IP) ||
|
|
|
|
swkey->eth.type == htons(ETH_P_ARP))
|
|
|
|
goto invalid;
|
|
|
|
goto ok;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case OVS_KEY_ATTR_IPV4:
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
if (frag_type == OVS_FRAG_TYPE_LATER)
|
|
|
|
goto ok;
|
2011-06-08 12:28:57 -07:00
|
|
|
if (swkey->ip.proto == IPPROTO_TCP ||
|
|
|
|
swkey->ip.proto == IPPROTO_UDP ||
|
|
|
|
swkey->ip.proto == IPPROTO_ICMP)
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
|
|
|
goto ok;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case OVS_KEY_ATTR_IPV6:
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
if (frag_type == OVS_FRAG_TYPE_LATER)
|
|
|
|
goto ok;
|
2011-06-08 12:28:57 -07:00
|
|
|
if (swkey->ip.proto == IPPROTO_TCP ||
|
|
|
|
swkey->ip.proto == IPPROTO_UDP ||
|
|
|
|
swkey->ip.proto == IPPROTO_ICMPV6)
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
|
|
|
goto ok;
|
2010-12-29 19:03:46 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case OVS_KEY_ATTR_ICMPV6:
|
2011-05-18 11:30:07 -07:00
|
|
|
if (swkey->ipv6.tp.src == htons(NDISC_NEIGHBOUR_SOLICITATION) ||
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
swkey->ipv6.tp.src == htons(NDISC_NEIGHBOUR_ADVERTISEMENT) ||
|
|
|
|
frag_type == OVS_FRAG_TYPE_LATER)
|
2011-05-18 11:30:07 -07:00
|
|
|
goto invalid;
|
|
|
|
goto ok;
|
2011-02-01 22:54:11 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case OVS_KEY_ATTR_TCP:
|
|
|
|
case OVS_KEY_ATTR_UDP:
|
|
|
|
case OVS_KEY_ATTR_ICMP:
|
|
|
|
case OVS_KEY_ATTR_ND:
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
if (frag_type == OVS_FRAG_TYPE_LATER)
|
|
|
|
goto invalid;
|
|
|
|
goto ok;
|
|
|
|
|
|
|
|
case OVS_KEY_ATTR_ARP:
|
2011-05-18 11:30:07 -07:00
|
|
|
goto ok;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WARN_ON_ONCE(1);
|
2011-01-23 18:44:44 -08:00
|
|
|
}
|
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
invalid:
|
|
|
|
error = -EINVAL;
|
|
|
|
|
|
|
|
ok:
|
|
|
|
WARN_ON_ONCE(!key_len && !error);
|
|
|
|
*key_lenp = key_len;
|
|
|
|
return error;
|
2011-01-23 18:44:44 -08:00
|
|
|
}
|
|
|
|
|
2011-06-01 13:39:51 -07:00
|
|
|
/**
|
|
|
|
* flow_metadata_from_nlattrs - parses Netlink attributes into a flow key.
|
|
|
|
* @in_port: receives the extracted input port.
|
|
|
|
* @tun_id: receives the extracted tunnel ID.
|
2011-08-18 10:35:40 -07:00
|
|
|
* @key: Netlink attribute holding nested %OVS_KEY_ATTR_* Netlink attribute
|
2011-06-01 13:39:51 -07:00
|
|
|
* sequence.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* get the metadata, that is, the parts of the flow key that cannot be
|
|
|
|
* extracted from the packet itself.
|
|
|
|
*/
|
|
|
|
int flow_metadata_from_nlattrs(u16 *in_port, __be64 *tun_id,
|
|
|
|
const struct nlattr *attr)
|
|
|
|
{
|
|
|
|
const struct nlattr *nla;
|
|
|
|
u16 prev_type;
|
|
|
|
int rem;
|
|
|
|
|
2011-09-08 16:30:20 -07:00
|
|
|
*in_port = USHRT_MAX;
|
2011-06-01 13:39:51 -07:00
|
|
|
*tun_id = 0;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
prev_type = OVS_KEY_ATTR_UNSPEC;
|
2011-06-01 13:39:51 -07:00
|
|
|
nla_for_each_nested(nla, attr, rem) {
|
|
|
|
int type = nla_type(nla);
|
|
|
|
|
2011-10-21 14:38:54 -07:00
|
|
|
if (type > OVS_KEY_ATTR_MAX || nla_len(nla) != ovs_key_lens[type])
|
|
|
|
return -EINVAL;
|
2011-06-01 13:39:51 -07:00
|
|
|
|
|
|
|
switch (TRANSITION(prev_type, type)) {
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_UNSPEC, OVS_KEY_ATTR_TUN_ID):
|
2011-06-01 13:39:51 -07:00
|
|
|
*tun_id = nla_get_be64(nla);
|
|
|
|
break;
|
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
case TRANSITION(OVS_KEY_ATTR_UNSPEC, OVS_KEY_ATTR_IN_PORT):
|
|
|
|
case TRANSITION(OVS_KEY_ATTR_TUN_ID, OVS_KEY_ATTR_IN_PORT):
|
2011-06-01 13:39:51 -07:00
|
|
|
if (nla_get_u32(nla) >= DP_MAX_PORTS)
|
|
|
|
return -EINVAL;
|
|
|
|
*in_port = nla_get_u32(nla);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-09-08 16:30:20 -07:00
|
|
|
return 0;
|
2011-06-01 13:39:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
prev_type = type;
|
|
|
|
}
|
|
|
|
if (rem)
|
|
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-26 15:42:00 -08:00
|
|
|
int flow_to_nlattrs(const struct sw_flow_key *swkey, struct sk_buff *skb)
|
2011-01-23 18:44:44 -08:00
|
|
|
{
|
2011-08-18 10:35:40 -07:00
|
|
|
struct ovs_key_ethernet *eth_key;
|
2011-01-26 15:42:00 -08:00
|
|
|
struct nlattr *nla;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-02-06 22:46:27 -08:00
|
|
|
/* This is an imperfect sanity-check that FLOW_BUFSIZE doesn't need
|
2011-08-18 10:35:40 -07:00
|
|
|
* to be updated, but will at least raise awareness when new
|
|
|
|
* datapath key types are added. */
|
|
|
|
BUILD_BUG_ON(__OVS_KEY_ATTR_MAX != 14);
|
2011-02-06 22:46:27 -08:00
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
if (swkey->eth.tun_id != cpu_to_be64(0))
|
2011-08-18 10:35:40 -07:00
|
|
|
NLA_PUT_BE64(skb, OVS_KEY_ATTR_TUN_ID, swkey->eth.tun_id);
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-09-08 16:30:20 -07:00
|
|
|
if (swkey->eth.in_port != USHRT_MAX)
|
|
|
|
NLA_PUT_U32(skb, OVS_KEY_ATTR_IN_PORT, swkey->eth.in_port);
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
nla = nla_reserve(skb, OVS_KEY_ATTR_ETHERNET, sizeof(*eth_key));
|
2011-01-26 15:42:00 -08:00
|
|
|
if (!nla)
|
|
|
|
goto nla_put_failure;
|
|
|
|
eth_key = nla_data(nla);
|
2011-05-18 11:30:07 -07:00
|
|
|
memcpy(eth_key->eth_src, swkey->eth.src, ETH_ALEN);
|
|
|
|
memcpy(eth_key->eth_dst, swkey->eth.dst, ETH_ALEN);
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
if (swkey->eth.tci != htons(0)) {
|
2011-08-18 10:35:40 -07:00
|
|
|
struct ovs_key_8021q q_key;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-01-26 15:42:00 -08:00
|
|
|
q_key.q_tpid = htons(ETH_P_8021Q);
|
2011-05-18 11:30:07 -07:00
|
|
|
q_key.q_tci = swkey->eth.tci & ~htons(VLAN_TAG_PRESENT);
|
2011-08-18 10:35:40 -07:00
|
|
|
NLA_PUT(skb, OVS_KEY_ATTR_8021Q, sizeof(q_key), &q_key);
|
2011-01-23 18:44:44 -08:00
|
|
|
}
|
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
if (swkey->eth.type == htons(ETH_P_802_2))
|
2011-01-26 15:42:00 -08:00
|
|
|
return 0;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
NLA_PUT_BE16(skb, OVS_KEY_ATTR_ETHERTYPE, swkey->eth.type);
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-05-18 11:30:07 -07:00
|
|
|
if (swkey->eth.type == htons(ETH_P_IP)) {
|
2011-08-18 10:35:40 -07:00
|
|
|
struct ovs_key_ipv4 *ipv4_key;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
nla = nla_reserve(skb, OVS_KEY_ATTR_IPV4, sizeof(*ipv4_key));
|
2011-01-26 15:42:00 -08:00
|
|
|
if (!nla)
|
|
|
|
goto nla_put_failure;
|
|
|
|
ipv4_key = nla_data(nla);
|
2011-08-18 10:35:40 -07:00
|
|
|
memset(ipv4_key, 0, sizeof(struct ovs_key_ipv4));
|
2011-05-18 11:30:07 -07:00
|
|
|
ipv4_key->ipv4_src = swkey->ipv4.addr.src;
|
|
|
|
ipv4_key->ipv4_dst = swkey->ipv4.addr.dst;
|
2011-06-08 12:28:57 -07:00
|
|
|
ipv4_key->ipv4_proto = swkey->ip.proto;
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
ipv4_key->ipv4_tos = swkey->ip.tos_frag & ~INET_ECN_MASK;
|
|
|
|
ipv4_key->ipv4_frag = swkey->ip.tos_frag & OVS_FRAG_TYPE_MASK;
|
2011-05-18 11:30:07 -07:00
|
|
|
} else if (swkey->eth.type == htons(ETH_P_IPV6)) {
|
2011-08-18 10:35:40 -07:00
|
|
|
struct ovs_key_ipv6 *ipv6_key;
|
2010-12-29 19:03:46 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
nla = nla_reserve(skb, OVS_KEY_ATTR_IPV6, sizeof(*ipv6_key));
|
2010-12-29 19:03:46 -08:00
|
|
|
if (!nla)
|
|
|
|
goto nla_put_failure;
|
|
|
|
ipv6_key = nla_data(nla);
|
2011-08-18 10:35:40 -07:00
|
|
|
memset(ipv6_key, 0, sizeof(struct ovs_key_ipv6));
|
2011-05-18 11:30:07 -07:00
|
|
|
memcpy(ipv6_key->ipv6_src, &swkey->ipv6.addr.src,
|
2010-12-29 19:03:46 -08:00
|
|
|
sizeof(ipv6_key->ipv6_src));
|
2011-05-18 11:30:07 -07:00
|
|
|
memcpy(ipv6_key->ipv6_dst, &swkey->ipv6.addr.dst,
|
2010-12-29 19:03:46 -08:00
|
|
|
sizeof(ipv6_key->ipv6_dst));
|
2011-06-08 12:28:57 -07:00
|
|
|
ipv6_key->ipv6_proto = swkey->ip.proto;
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
ipv6_key->ipv6_tos = swkey->ip.tos_frag & ~INET_ECN_MASK;
|
|
|
|
ipv6_key->ipv6_frag = swkey->ip.tos_frag & OVS_FRAG_TYPE_MASK;
|
2011-05-18 11:30:07 -07:00
|
|
|
} else if (swkey->eth.type == htons(ETH_P_ARP)) {
|
2011-08-18 10:35:40 -07:00
|
|
|
struct ovs_key_arp *arp_key;
|
2010-12-29 19:03:46 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
nla = nla_reserve(skb, OVS_KEY_ATTR_ARP, sizeof(*arp_key));
|
2010-12-29 19:03:46 -08:00
|
|
|
if (!nla)
|
|
|
|
goto nla_put_failure;
|
|
|
|
arp_key = nla_data(nla);
|
2011-08-18 10:35:40 -07:00
|
|
|
memset(arp_key, 0, sizeof(struct ovs_key_arp));
|
2011-05-18 11:30:07 -07:00
|
|
|
arp_key->arp_sip = swkey->ipv4.addr.src;
|
|
|
|
arp_key->arp_tip = swkey->ipv4.addr.dst;
|
2011-06-08 12:28:57 -07:00
|
|
|
arp_key->arp_op = htons(swkey->ip.proto);
|
2011-05-18 11:30:07 -07:00
|
|
|
memcpy(arp_key->arp_sha, swkey->ipv4.arp.sha, ETH_ALEN);
|
|
|
|
memcpy(arp_key->arp_tha, swkey->ipv4.arp.tha, ETH_ALEN);
|
2010-12-29 19:03:46 -08:00
|
|
|
}
|
|
|
|
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
if ((swkey->eth.type == htons(ETH_P_IP) ||
|
|
|
|
swkey->eth.type == htons(ETH_P_IPV6)) &&
|
|
|
|
(swkey->ip.tos_frag & OVS_FRAG_TYPE_MASK) != OVS_FRAG_TYPE_LATER) {
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-06-08 12:28:57 -07:00
|
|
|
if (swkey->ip.proto == IPPROTO_TCP) {
|
2011-08-18 10:35:40 -07:00
|
|
|
struct ovs_key_tcp *tcp_key;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
nla = nla_reserve(skb, OVS_KEY_ATTR_TCP, sizeof(*tcp_key));
|
2011-01-26 15:42:00 -08:00
|
|
|
if (!nla)
|
|
|
|
goto nla_put_failure;
|
|
|
|
tcp_key = nla_data(nla);
|
2011-05-18 11:30:07 -07:00
|
|
|
if (swkey->eth.type == htons(ETH_P_IP)) {
|
|
|
|
tcp_key->tcp_src = swkey->ipv4.tp.src;
|
|
|
|
tcp_key->tcp_dst = swkey->ipv4.tp.dst;
|
|
|
|
} else if (swkey->eth.type == htons(ETH_P_IPV6)) {
|
|
|
|
tcp_key->tcp_src = swkey->ipv6.tp.src;
|
|
|
|
tcp_key->tcp_dst = swkey->ipv6.tp.dst;
|
|
|
|
}
|
2011-06-08 12:28:57 -07:00
|
|
|
} else if (swkey->ip.proto == IPPROTO_UDP) {
|
2011-08-18 10:35:40 -07:00
|
|
|
struct ovs_key_udp *udp_key;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
nla = nla_reserve(skb, OVS_KEY_ATTR_UDP, sizeof(*udp_key));
|
2011-01-26 15:42:00 -08:00
|
|
|
if (!nla)
|
|
|
|
goto nla_put_failure;
|
|
|
|
udp_key = nla_data(nla);
|
2011-05-18 11:30:07 -07:00
|
|
|
if (swkey->eth.type == htons(ETH_P_IP)) {
|
|
|
|
udp_key->udp_src = swkey->ipv4.tp.src;
|
|
|
|
udp_key->udp_dst = swkey->ipv4.tp.dst;
|
|
|
|
} else if (swkey->eth.type == htons(ETH_P_IPV6)) {
|
|
|
|
udp_key->udp_src = swkey->ipv6.tp.src;
|
|
|
|
udp_key->udp_dst = swkey->ipv6.tp.dst;
|
|
|
|
}
|
|
|
|
} else if (swkey->eth.type == htons(ETH_P_IP) &&
|
2011-06-08 12:28:57 -07:00
|
|
|
swkey->ip.proto == IPPROTO_ICMP) {
|
2011-08-18 10:35:40 -07:00
|
|
|
struct ovs_key_icmp *icmp_key;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
nla = nla_reserve(skb, OVS_KEY_ATTR_ICMP, sizeof(*icmp_key));
|
2011-01-26 15:42:00 -08:00
|
|
|
if (!nla)
|
|
|
|
goto nla_put_failure;
|
|
|
|
icmp_key = nla_data(nla);
|
2011-05-18 11:30:07 -07:00
|
|
|
icmp_key->icmp_type = ntohs(swkey->ipv4.tp.src);
|
|
|
|
icmp_key->icmp_code = ntohs(swkey->ipv4.tp.dst);
|
|
|
|
} else if (swkey->eth.type == htons(ETH_P_IPV6) &&
|
2011-06-08 12:28:57 -07:00
|
|
|
swkey->ip.proto == IPPROTO_ICMPV6) {
|
2011-08-18 10:35:40 -07:00
|
|
|
struct ovs_key_icmpv6 *icmpv6_key;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
nla = nla_reserve(skb, OVS_KEY_ATTR_ICMPV6,
|
2011-02-25 16:46:19 -08:00
|
|
|
sizeof(*icmpv6_key));
|
2010-12-29 19:03:46 -08:00
|
|
|
if (!nla)
|
|
|
|
goto nla_put_failure;
|
|
|
|
icmpv6_key = nla_data(nla);
|
2011-05-18 11:30:07 -07:00
|
|
|
icmpv6_key->icmpv6_type = ntohs(swkey->ipv6.tp.src);
|
|
|
|
icmpv6_key->icmpv6_code = ntohs(swkey->ipv6.tp.dst);
|
2011-02-01 22:54:11 -08:00
|
|
|
|
2011-02-25 16:46:19 -08:00
|
|
|
if (icmpv6_key->icmpv6_type == NDISC_NEIGHBOUR_SOLICITATION ||
|
|
|
|
icmpv6_key->icmpv6_type == NDISC_NEIGHBOUR_ADVERTISEMENT) {
|
2011-08-18 10:35:40 -07:00
|
|
|
struct ovs_key_nd *nd_key;
|
2011-02-01 22:54:11 -08:00
|
|
|
|
2011-08-18 10:35:40 -07:00
|
|
|
nla = nla_reserve(skb, OVS_KEY_ATTR_ND, sizeof(*nd_key));
|
2011-02-01 22:54:11 -08:00
|
|
|
if (!nla)
|
|
|
|
goto nla_put_failure;
|
|
|
|
nd_key = nla_data(nla);
|
2011-05-18 11:30:07 -07:00
|
|
|
memcpy(nd_key->nd_target, &swkey->ipv6.nd.target,
|
2011-02-01 22:54:11 -08:00
|
|
|
sizeof(nd_key->nd_target));
|
2011-05-18 11:30:07 -07:00
|
|
|
memcpy(nd_key->nd_sll, swkey->ipv6.nd.sll, ETH_ALEN);
|
|
|
|
memcpy(nd_key->nd_tll, swkey->ipv6.nd.tll, ETH_ALEN);
|
2011-02-01 22:54:11 -08:00
|
|
|
}
|
2010-12-29 19:03:46 -08:00
|
|
|
}
|
2011-01-23 18:44:44 -08:00
|
|
|
}
|
|
|
|
|
2011-01-26 15:42:00 -08:00
|
|
|
return 0;
|
2011-01-23 18:44:44 -08:00
|
|
|
|
2011-01-26 15:42:00 -08:00
|
|
|
nla_put_failure:
|
|
|
|
return -EMSGSIZE;
|
2010-04-02 16:46:18 -04:00
|
|
|
}
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
/* Initializes the flow module.
|
|
|
|
* Returns zero if successful or a negative error code. */
|
|
|
|
int flow_init(void)
|
|
|
|
{
|
|
|
|
flow_cache = kmem_cache_create("sw_flow", sizeof(struct sw_flow), 0,
|
|
|
|
0, NULL);
|
|
|
|
if (flow_cache == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-01-17 14:34:55 -08:00
|
|
|
get_random_bytes(&hash_seed, sizeof(hash_seed));
|
2010-04-02 16:46:18 -04:00
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Uninitializes the flow module. */
|
|
|
|
void flow_exit(void)
|
|
|
|
{
|
|
|
|
kmem_cache_destroy(flow_cache);
|
|
|
|
}
|