Skip to content

Commit 018c1dd

Browse files
Eric Garverdavem330
authored andcommitted
openvswitch: 802.1AD Flow handling, actions, vlan parsing, netlink attributes
Add support for 802.1ad including the ability to push and pop double tagged vlans. Add support for 802.1ad to netlink parsing and flow conversion. Uses double nested encap attributes to represent double tagged vlan. Inner TPID encoded along with ctci in nested attributes. This is based on Thomas F Herbert's original v20 patch. I made some small clean ups and bug fixes. Signed-off-by: Thomas F Herbert <thomasfherbert@gmail.com> Signed-off-by: Eric Garver <e@erig.me> Acked-by: Pravin B Shelar <pshelar@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fe19c4f commit 018c1dd

5 files changed

Lines changed: 282 additions & 124 deletions

File tree

‎net/openvswitch/actions.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,20 +246,24 @@ static int pop_vlan(struct sk_buff *skb, struct sw_flow_key *key)
246246
int err;
247247

248248
err = skb_vlan_pop(skb);
249-
if (skb_vlan_tag_present(skb))
249+
if (skb_vlan_tag_present(skb)) {
250250
invalidate_flow_key(key);
251-
else
252-
key->eth.tci = 0;
251+
} else {
252+
key->eth.vlan.tci = 0;
253+
key->eth.vlan.tpid = 0;
254+
}
253255
return err;
254256
}
255257

256258
static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key,
257259
const struct ovs_action_push_vlan *vlan)
258260
{
259-
if (skb_vlan_tag_present(skb))
261+
if (skb_vlan_tag_present(skb)) {
260262
invalidate_flow_key(key);
261-
else
262-
key->eth.tci = vlan->vlan_tci;
263+
} else {
264+
key->eth.vlan.tci = vlan->vlan_tci;
265+
key->eth.vlan.tpid = vlan->vlan_tpid;
266+
}
263267
return skb_vlan_push(skb, vlan->vlan_tpid,
264268
ntohs(vlan->vlan_tci) & ~VLAN_TAG_PRESENT);
265269
}

‎net/openvswitch/flow.c‎

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -302,24 +302,57 @@ static bool icmp6hdr_ok(struct sk_buff *skb)
302302
sizeof(struct icmp6hdr));
303303
}
304304

305-
static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
305+
/**
306+
* Parse vlan tag from vlan header.
307+
* Returns ERROR on memory error.
308+
* Returns 0 if it encounters a non-vlan or incomplete packet.
309+
* Returns 1 after successfully parsing vlan tag.
310+
*/
311+
static int parse_vlan_tag(struct sk_buff *skb, struct vlan_head *key_vh)
306312
{
307-
struct qtag_prefix {
308-
__be16 eth_type; /* ETH_P_8021Q */
309-
__be16 tci;
310-
};
311-
struct qtag_prefix *qp;
313+
struct vlan_head *vh = (struct vlan_head *)skb->data;
312314

313-
if (unlikely(skb->len < sizeof(struct qtag_prefix) + sizeof(__be16)))
315+
if (likely(!eth_type_vlan(vh->tpid)))
314316
return 0;
315317

316-
if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
317-
sizeof(__be16))))
318+
if (unlikely(skb->len < sizeof(struct vlan_head) + sizeof(__be16)))
319+
return 0;
320+
321+
if (unlikely(!pskb_may_pull(skb, sizeof(struct vlan_head) +
322+
sizeof(__be16))))
318323
return -ENOMEM;
319324

320-
qp = (struct qtag_prefix *) skb->data;
321-
key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
322-
__skb_pull(skb, sizeof(struct qtag_prefix));
325+
vh = (struct vlan_head *)skb->data;
326+
key_vh->tci = vh->tci | htons(VLAN_TAG_PRESENT);
327+
key_vh->tpid = vh->tpid;
328+
329+
__skb_pull(skb, sizeof(struct vlan_head));
330+
return 1;
331+
}
332+
333+
static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
334+
{
335+
int res;
336+
337+
key->eth.vlan.tci = 0;
338+
key->eth.vlan.tpid = 0;
339+
key->eth.cvlan.tci = 0;
340+
key->eth.cvlan.tpid = 0;
341+
342+
if (likely(skb_vlan_tag_present(skb))) {
343+
key->eth.vlan.tci = htons(skb->vlan_tci);
344+
key->eth.vlan.tpid = skb->vlan_proto;
345+
} else {
346+
/* Parse outer vlan tag in the non-accelerated case. */
347+
res = parse_vlan_tag(skb, &key->eth.vlan);
348+
if (res <= 0)
349+
return res;
350+
}
351+
352+
/* Parse inner vlan tag. */
353+
res = parse_vlan_tag(skb, &key->eth.cvlan);
354+
if (res <= 0)
355+
return res;
323356

324357
return 0;
325358
}
@@ -480,12 +513,8 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
480513
* update skb->csum here.
481514
*/
482515

483-
key->eth.tci = 0;
484-
if (skb_vlan_tag_present(skb))
485-
key->eth.tci = htons(skb->vlan_tci);
486-
else if (eth->h_proto == htons(ETH_P_8021Q))
487-
if (unlikely(parse_vlan(skb, key)))
488-
return -ENOMEM;
516+
if (unlikely(parse_vlan(skb, key)))
517+
return -ENOMEM;
489518

490519
key->eth.type = parse_ethertype(skb);
491520
if (unlikely(key->eth.type == htons(0)))

‎net/openvswitch/flow.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ struct ovs_tunnel_info {
5050
struct metadata_dst *tun_dst;
5151
};
5252

53+
struct vlan_head {
54+
__be16 tpid; /* Vlan type. Generally 802.1q or 802.1ad.*/
55+
__be16 tci; /* 0 if no VLAN, VLAN_TAG_PRESENT set otherwise. */
56+
};
57+
5358
#define OVS_SW_FLOW_KEY_METADATA_SIZE \
5459
(offsetof(struct sw_flow_key, recirc_id) + \
5560
FIELD_SIZEOF(struct sw_flow_key, recirc_id))
@@ -69,7 +74,8 @@ struct sw_flow_key {
6974
struct {
7075
u8 src[ETH_ALEN]; /* Ethernet source address. */
7176
u8 dst[ETH_ALEN]; /* Ethernet destination address. */
72-
__be16 tci; /* 0 if no VLAN, VLAN_TAG_PRESENT set otherwise. */
77+
struct vlan_head vlan;
78+
struct vlan_head cvlan;
7379
__be16 type; /* Ethernet frame type. */
7480
} eth;
7581
union {

0 commit comments

Comments
 (0)