Skip to content

Commit df6ce47

Browse files
committed
Merge branch 'vlan_action'
Jiri Pirko says: ==================== sched: introduce vlan action Please see the individual patches for info ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents fe15912 + c7e2b96 commit df6ce47

File tree

22 files changed

+522
-214
lines changed

22 files changed

+522
-214
lines changed

drivers/net/bonding/bond_alb.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,8 @@ static void rlb_update_client(struct rlb_client_info *client_info)
475475
skb->dev = client_info->slave->dev;
476476

477477
if (client_info->vlan_id) {
478-
skb = vlan_put_tag(skb, htons(ETH_P_8021Q), client_info->vlan_id);
479-
if (!skb) {
480-
netdev_err(client_info->slave->bond->dev,
481-
"failed to insert VLAN tag\n");
482-
continue;
483-
}
478+
__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
479+
client_info->vlan_id);
484480
}
485481

486482
arp_xmit(skb);
@@ -951,13 +947,8 @@ static void alb_send_lp_vid(struct slave *slave, u8 mac_addr[],
951947
skb->priority = TC_PRIO_CONTROL;
952948
skb->dev = slave->dev;
953949

954-
if (vid) {
955-
skb = vlan_put_tag(skb, vlan_proto, vid);
956-
if (!skb) {
957-
netdev_err(slave->bond->dev, "failed to insert VLAN tag\n");
958-
return;
959-
}
960-
}
950+
if (vid)
951+
__vlan_hwaccel_put_tag(skb, vlan_proto, vid);
961952

962953
dev_queue_xmit(skb);
963954
}

drivers/net/bonding/bond_main.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,8 +2146,8 @@ static void bond_arp_send(struct net_device *slave_dev, int arp_op,
21462146

21472147
netdev_dbg(slave_dev, "inner tag: proto %X vid %X\n",
21482148
ntohs(outer_tag->vlan_proto), tags->vlan_id);
2149-
skb = __vlan_put_tag(skb, tags->vlan_proto,
2150-
tags->vlan_id);
2149+
skb = vlan_insert_tag_set_proto(skb, tags->vlan_proto,
2150+
tags->vlan_id);
21512151
if (!skb) {
21522152
net_err_ratelimited("failed to insert inner VLAN tag\n");
21532153
return;
@@ -2159,12 +2159,8 @@ static void bond_arp_send(struct net_device *slave_dev, int arp_op,
21592159
if (outer_tag->vlan_id) {
21602160
netdev_dbg(slave_dev, "outer tag: proto %X vid %X\n",
21612161
ntohs(outer_tag->vlan_proto), outer_tag->vlan_id);
2162-
skb = vlan_put_tag(skb, outer_tag->vlan_proto,
2163-
outer_tag->vlan_id);
2164-
if (!skb) {
2165-
net_err_ratelimited("failed to insert outer VLAN tag\n");
2166-
return;
2167-
}
2162+
__vlan_hwaccel_put_tag(skb, outer_tag->vlan_proto,
2163+
outer_tag->vlan_id);
21682164
}
21692165

21702166
xmit:

drivers/net/ethernet/emulex/benet/be_main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,8 @@ static struct sk_buff *be_insert_vlan_in_pkt(struct be_adapter *adapter,
887887
}
888888

889889
if (vlan_tag) {
890-
skb = __vlan_put_tag(skb, htons(ETH_P_8021Q), vlan_tag);
890+
skb = vlan_insert_tag_set_proto(skb, htons(ETH_P_8021Q),
891+
vlan_tag);
891892
if (unlikely(!skb))
892893
return skb;
893894
skb->vlan_tci = 0;
@@ -896,7 +897,8 @@ static struct sk_buff *be_insert_vlan_in_pkt(struct be_adapter *adapter,
896897
/* Insert the outer VLAN, if any */
897898
if (adapter->qnq_vid) {
898899
vlan_tag = adapter->qnq_vid;
899-
skb = __vlan_put_tag(skb, htons(ETH_P_8021Q), vlan_tag);
900+
skb = vlan_insert_tag_set_proto(skb, htons(ETH_P_8021Q),
901+
vlan_tag);
900902
if (unlikely(!skb))
901903
return skb;
902904
if (skip_hw_vlan)

drivers/net/usb/cdc_mbim.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ static struct sk_buff *cdc_mbim_process_dgram(struct usbnet *dev, u8 *buf, size_
402402

403403
/* map MBIM session to VLAN */
404404
if (tci)
405-
vlan_put_tag(skb, htons(ETH_P_8021Q), tci);
405+
__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tci);
406406
err:
407407
return skb;
408408
}

drivers/net/vxlan.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,14 +1599,9 @@ static int vxlan6_xmit_skb(struct vxlan_sock *vs,
15991599
if (unlikely(err))
16001600
return err;
16011601

1602-
if (vlan_tx_tag_present(skb)) {
1603-
if (WARN_ON(!__vlan_put_tag(skb,
1604-
skb->vlan_proto,
1605-
vlan_tx_tag_get(skb))))
1606-
return -ENOMEM;
1607-
1608-
skb->vlan_tci = 0;
1609-
}
1602+
skb = vlan_hwaccel_push_inside(skb);
1603+
if (WARN_ON(!skb))
1604+
return -ENOMEM;
16101605

16111606
vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh));
16121607
vxh->vx_flags = htonl(VXLAN_FLAGS);
@@ -1643,14 +1638,9 @@ int vxlan_xmit_skb(struct vxlan_sock *vs,
16431638
if (unlikely(err))
16441639
return err;
16451640

1646-
if (vlan_tx_tag_present(skb)) {
1647-
if (WARN_ON(!__vlan_put_tag(skb,
1648-
skb->vlan_proto,
1649-
vlan_tx_tag_get(skb))))
1650-
return -ENOMEM;
1651-
1652-
skb->vlan_tci = 0;
1653-
}
1641+
skb = vlan_hwaccel_push_inside(skb);
1642+
if (WARN_ON(!skb))
1643+
return -ENOMEM;
16541644

16551645
vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh));
16561646
vxh->vx_flags = htonl(VXLAN_FLAGS);

drivers/scsi/fcoe/fcoe.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,10 +1669,8 @@ static int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp)
16691669
fcoe->realdev->features & NETIF_F_HW_VLAN_CTAG_TX) {
16701670
/* must set skb->dev before calling vlan_put_tag */
16711671
skb->dev = fcoe->realdev;
1672-
skb = __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
1673-
vlan_dev_vlan_id(fcoe->netdev));
1674-
if (!skb)
1675-
return -ENOMEM;
1672+
__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
1673+
vlan_dev_vlan_id(fcoe->netdev));
16761674
} else
16771675
skb->dev = fcoe->netdev;
16781676

include/linux/if_vlan.h

Lines changed: 73 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -282,28 +282,24 @@ static inline bool vlan_hw_offload_capable(netdev_features_t features,
282282
}
283283

284284
/**
285-
* vlan_insert_tag - regular VLAN tag inserting
285+
* __vlan_insert_tag - regular VLAN tag inserting
286286
* @skb: skbuff to tag
287287
* @vlan_proto: VLAN encapsulation protocol
288288
* @vlan_tci: VLAN TCI to insert
289289
*
290290
* Inserts the VLAN tag into @skb as part of the payload
291-
* Returns a VLAN tagged skb. If a new skb is created, @skb is freed.
292-
*
293-
* Following the skb_unshare() example, in case of error, the calling function
294-
* doesn't have to worry about freeing the original skb.
291+
* Returns error if skb_cow_head failes.
295292
*
296293
* Does not change skb->protocol so this function can be used during receive.
297294
*/
298-
static inline struct sk_buff *vlan_insert_tag(struct sk_buff *skb,
299-
__be16 vlan_proto, u16 vlan_tci)
295+
static inline int __vlan_insert_tag(struct sk_buff *skb,
296+
__be16 vlan_proto, u16 vlan_tci)
300297
{
301298
struct vlan_ethhdr *veth;
302299

303-
if (skb_cow_head(skb, VLAN_HLEN) < 0) {
304-
dev_kfree_skb_any(skb);
305-
return NULL;
306-
}
300+
if (skb_cow_head(skb, VLAN_HLEN) < 0)
301+
return -ENOMEM;
302+
307303
veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
308304

309305
/* Move the mac addresses to the beginning of the new header. */
@@ -316,12 +312,40 @@ static inline struct sk_buff *vlan_insert_tag(struct sk_buff *skb,
316312
/* now, the TCI */
317313
veth->h_vlan_TCI = htons(vlan_tci);
318314

315+
return 0;
316+
}
317+
318+
/**
319+
* vlan_insert_tag - regular VLAN tag inserting
320+
* @skb: skbuff to tag
321+
* @vlan_proto: VLAN encapsulation protocol
322+
* @vlan_tci: VLAN TCI to insert
323+
*
324+
* Inserts the VLAN tag into @skb as part of the payload
325+
* Returns a VLAN tagged skb. If a new skb is created, @skb is freed.
326+
*
327+
* Following the skb_unshare() example, in case of error, the calling function
328+
* doesn't have to worry about freeing the original skb.
329+
*
330+
* Does not change skb->protocol so this function can be used during receive.
331+
*/
332+
static inline struct sk_buff *vlan_insert_tag(struct sk_buff *skb,
333+
__be16 vlan_proto, u16 vlan_tci)
334+
{
335+
int err;
336+
337+
err = __vlan_insert_tag(skb, vlan_proto, vlan_tci);
338+
if (err) {
339+
dev_kfree_skb_any(skb);
340+
return NULL;
341+
}
319342
return skb;
320343
}
321344

322345
/**
323-
* __vlan_put_tag - regular VLAN tag inserting
346+
* vlan_insert_tag_set_proto - regular VLAN tag inserting
324347
* @skb: skbuff to tag
348+
* @vlan_proto: VLAN encapsulation protocol
325349
* @vlan_tci: VLAN TCI to insert
326350
*
327351
* Inserts the VLAN tag into @skb as part of the payload
@@ -330,48 +354,63 @@ static inline struct sk_buff *vlan_insert_tag(struct sk_buff *skb,
330354
* Following the skb_unshare() example, in case of error, the calling function
331355
* doesn't have to worry about freeing the original skb.
332356
*/
333-
static inline struct sk_buff *__vlan_put_tag(struct sk_buff *skb,
334-
__be16 vlan_proto, u16 vlan_tci)
357+
static inline struct sk_buff *vlan_insert_tag_set_proto(struct sk_buff *skb,
358+
__be16 vlan_proto,
359+
u16 vlan_tci)
335360
{
336361
skb = vlan_insert_tag(skb, vlan_proto, vlan_tci);
337362
if (skb)
338363
skb->protocol = vlan_proto;
339364
return skb;
340365
}
341366

342-
/**
343-
* __vlan_hwaccel_put_tag - hardware accelerated VLAN inserting
367+
/*
368+
* __vlan_hwaccel_push_inside - pushes vlan tag to the payload
344369
* @skb: skbuff to tag
345-
* @vlan_proto: VLAN encapsulation protocol
346-
* @vlan_tci: VLAN TCI to insert
347370
*
348-
* Puts the VLAN TCI in @skb->vlan_tci and lets the device do the rest
371+
* Pushes the VLAN tag from @skb->vlan_tci inside to the payload.
372+
*
373+
* Following the skb_unshare() example, in case of error, the calling function
374+
* doesn't have to worry about freeing the original skb.
349375
*/
350-
static inline struct sk_buff *__vlan_hwaccel_put_tag(struct sk_buff *skb,
351-
__be16 vlan_proto,
352-
u16 vlan_tci)
376+
static inline struct sk_buff *__vlan_hwaccel_push_inside(struct sk_buff *skb)
353377
{
354-
skb->vlan_proto = vlan_proto;
355-
skb->vlan_tci = VLAN_TAG_PRESENT | vlan_tci;
378+
skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
379+
vlan_tx_tag_get(skb));
380+
if (likely(skb))
381+
skb->vlan_tci = 0;
382+
return skb;
383+
}
384+
/*
385+
* vlan_hwaccel_push_inside - pushes vlan tag to the payload
386+
* @skb: skbuff to tag
387+
*
388+
* Checks is tag is present in @skb->vlan_tci and if it is, it pushes the
389+
* VLAN tag from @skb->vlan_tci inside to the payload.
390+
*
391+
* Following the skb_unshare() example, in case of error, the calling function
392+
* doesn't have to worry about freeing the original skb.
393+
*/
394+
static inline struct sk_buff *vlan_hwaccel_push_inside(struct sk_buff *skb)
395+
{
396+
if (vlan_tx_tag_present(skb))
397+
skb = __vlan_hwaccel_push_inside(skb);
356398
return skb;
357399
}
358400

359401
/**
360-
* vlan_put_tag - inserts VLAN tag according to device features
402+
* __vlan_hwaccel_put_tag - hardware accelerated VLAN inserting
361403
* @skb: skbuff to tag
404+
* @vlan_proto: VLAN encapsulation protocol
362405
* @vlan_tci: VLAN TCI to insert
363406
*
364-
* Assumes skb->dev is the target that will xmit this frame.
365-
* Returns a VLAN tagged skb.
407+
* Puts the VLAN TCI in @skb->vlan_tci and lets the device do the rest
366408
*/
367-
static inline struct sk_buff *vlan_put_tag(struct sk_buff *skb,
368-
__be16 vlan_proto, u16 vlan_tci)
409+
static inline void __vlan_hwaccel_put_tag(struct sk_buff *skb,
410+
__be16 vlan_proto, u16 vlan_tci)
369411
{
370-
if (vlan_hw_offload_capable(skb->dev->features, vlan_proto)) {
371-
return __vlan_hwaccel_put_tag(skb, vlan_proto, vlan_tci);
372-
} else {
373-
return __vlan_put_tag(skb, vlan_proto, vlan_tci);
374-
}
412+
skb->vlan_proto = vlan_proto;
413+
skb->vlan_tci = VLAN_TAG_PRESENT | vlan_tci;
375414
}
376415

377416
/**

include/linux/skbuff.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,6 +2678,9 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet);
26782678
unsigned int skb_gso_transport_seglen(const struct sk_buff *skb);
26792679
struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features);
26802680
struct sk_buff *skb_vlan_untag(struct sk_buff *skb);
2681+
int skb_ensure_writable(struct sk_buff *skb, int write_len);
2682+
int skb_vlan_pop(struct sk_buff *skb);
2683+
int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci);
26812684

26822685
struct skb_checksum_ops {
26832686
__wsum (*update)(const void *mem, int len, __wsum wsum);

include/net/tc_act/tc_vlan.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2014 Jiri Pirko <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*/
9+
10+
#ifndef __NET_TC_VLAN_H
11+
#define __NET_TC_VLAN_H
12+
13+
#include <net/act_api.h>
14+
15+
#define VLAN_F_POP 0x1
16+
#define VLAN_F_PUSH 0x2
17+
18+
struct tcf_vlan {
19+
struct tcf_common common;
20+
int tcfv_action;
21+
__be16 tcfv_push_vid;
22+
__be16 tcfv_push_proto;
23+
};
24+
#define to_vlan(a) \
25+
container_of(a->priv, struct tcf_vlan, common)
26+
27+
#endif /* __NET_TC_VLAN_H */

include/uapi/linux/tc_act/tc_vlan.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2014 Jiri Pirko <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*/
9+
10+
#ifndef __LINUX_TC_VLAN_H
11+
#define __LINUX_TC_VLAN_H
12+
13+
#include <linux/pkt_cls.h>
14+
15+
#define TCA_ACT_VLAN 12
16+
17+
#define TCA_VLAN_ACT_POP 1
18+
#define TCA_VLAN_ACT_PUSH 2
19+
20+
struct tc_vlan {
21+
tc_gen;
22+
int v_action;
23+
};
24+
25+
enum {
26+
TCA_VLAN_UNSPEC,
27+
TCA_VLAN_TM,
28+
TCA_VLAN_PARMS,
29+
TCA_VLAN_PUSH_VLAN_ID,
30+
TCA_VLAN_PUSH_VLAN_PROTOCOL,
31+
__TCA_VLAN_MAX,
32+
};
33+
#define TCA_VLAN_MAX (__TCA_VLAN_MAX - 1)
34+
35+
#endif

net/8021q/vlan_dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static netdev_tx_t vlan_dev_hard_start_xmit(struct sk_buff *skb,
150150
u16 vlan_tci;
151151
vlan_tci = vlan->vlan_id;
152152
vlan_tci |= vlan_dev_get_egress_qos_mask(dev, skb->priority);
153-
skb = __vlan_hwaccel_put_tag(skb, vlan->vlan_proto, vlan_tci);
153+
__vlan_hwaccel_put_tag(skb, vlan->vlan_proto, vlan_tci);
154154
}
155155

156156
skb->dev = vlan->real_dev;

net/bridge/br_vlan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
199199
if (skb->vlan_proto != proto) {
200200
/* Protocol-mismatch, empty out vlan_tci for new tag */
201201
skb_push(skb, ETH_HLEN);
202-
skb = __vlan_put_tag(skb, skb->vlan_proto,
203-
vlan_tx_tag_get(skb));
202+
skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
203+
vlan_tx_tag_get(skb));
204204
if (unlikely(!skb))
205205
return false;
206206

0 commit comments

Comments
 (0)