1 #include <linux/skbuff.h>
2 #include <linux/netdevice.h>
3 #include <linux/if_vlan.h>
4 #include <linux/netpoll.h>
7 /* VLAN rx hw acceleration helper. This acts like netif_{rx,receive_skb}(). */
8 int __vlan_hwaccel_rx(struct sk_buff
*skb
, struct vlan_group
*grp
,
9 u16 vlan_tci
, int polling
)
11 struct net_device
*vlan_dev
;
17 if (skb_bond_should_drop(skb
, ACCESS_ONCE(skb
->dev
->master
)))
18 skb
->deliver_no_wcard
= 1;
20 skb
->skb_iif
= skb
->dev
->ifindex
;
21 __vlan_hwaccel_put_tag(skb
, vlan_tci
);
22 vlan_id
= vlan_tci
& VLAN_VID_MASK
;
23 vlan_dev
= vlan_group_get_device(grp
, vlan_id
);
28 if (!(skb
->dev
->flags
& IFF_PROMISC
))
30 skb
->pkt_type
= PACKET_OTHERHOST
;
33 return (polling
? netif_receive_skb(skb
) : netif_rx(skb
));
36 dev_kfree_skb_any(skb
);
39 EXPORT_SYMBOL(__vlan_hwaccel_rx
);
41 int vlan_hwaccel_do_receive(struct sk_buff
*skb
)
43 struct net_device
*dev
= skb
->dev
;
44 struct vlan_rx_stats
*rx_stats
;
46 skb
->dev
= vlan_dev_info(dev
)->real_dev
;
47 netif_nit_deliver(skb
);
50 skb
->priority
= vlan_get_ingress_priority(dev
, skb
->vlan_tci
);
53 rx_stats
= this_cpu_ptr(vlan_dev_info(dev
)->vlan_rx_stats
);
55 u64_stats_update_begin(&rx_stats
->syncp
);
56 rx_stats
->rx_packets
++;
57 rx_stats
->rx_bytes
+= skb
->len
;
59 switch (skb
->pkt_type
) {
60 case PACKET_BROADCAST
:
62 case PACKET_MULTICAST
:
63 rx_stats
->rx_multicast
++;
65 case PACKET_OTHERHOST
:
66 /* Our lower layer thinks this is not local, let's make sure.
67 * This allows the VLAN to have a different MAC than the
68 * underlying device, and still route correctly. */
69 if (!compare_ether_addr(eth_hdr(skb
)->h_dest
,
71 skb
->pkt_type
= PACKET_HOST
;
74 u64_stats_update_end(&rx_stats
->syncp
);
78 struct net_device
*vlan_dev_real_dev(const struct net_device
*dev
)
80 return vlan_dev_info(dev
)->real_dev
;
82 EXPORT_SYMBOL(vlan_dev_real_dev
);
84 u16
vlan_dev_vlan_id(const struct net_device
*dev
)
86 return vlan_dev_info(dev
)->vlan_id
;
88 EXPORT_SYMBOL(vlan_dev_vlan_id
);
91 vlan_gro_common(struct napi_struct
*napi
, struct vlan_group
*grp
,
92 unsigned int vlan_tci
, struct sk_buff
*skb
)
95 struct net_device
*vlan_dev
;
98 if (skb_bond_should_drop(skb
, ACCESS_ONCE(skb
->dev
->master
)))
99 skb
->deliver_no_wcard
= 1;
101 skb
->skb_iif
= skb
->dev
->ifindex
;
102 __vlan_hwaccel_put_tag(skb
, vlan_tci
);
103 vlan_id
= vlan_tci
& VLAN_VID_MASK
;
104 vlan_dev
= vlan_group_get_device(grp
, vlan_id
);
109 if (!(skb
->dev
->flags
& IFF_PROMISC
))
111 skb
->pkt_type
= PACKET_OTHERHOST
;
114 for (p
= napi
->gro_list
; p
; p
= p
->next
) {
115 NAPI_GRO_CB(p
)->same_flow
=
116 p
->dev
== skb
->dev
&& !compare_ether_header(
117 skb_mac_header(p
), skb_gro_mac_header(skb
));
118 NAPI_GRO_CB(p
)->flush
= 0;
121 return dev_gro_receive(napi
, skb
);
127 gro_result_t
vlan_gro_receive(struct napi_struct
*napi
, struct vlan_group
*grp
,
128 unsigned int vlan_tci
, struct sk_buff
*skb
)
130 if (netpoll_rx_on(skb
))
131 return vlan_hwaccel_receive_skb(skb
, grp
, vlan_tci
)
132 ? GRO_DROP
: GRO_NORMAL
;
134 skb_gro_reset_offset(skb
);
136 return napi_skb_finish(vlan_gro_common(napi
, grp
, vlan_tci
, skb
), skb
);
138 EXPORT_SYMBOL(vlan_gro_receive
);
140 gro_result_t
vlan_gro_frags(struct napi_struct
*napi
, struct vlan_group
*grp
,
141 unsigned int vlan_tci
)
143 struct sk_buff
*skb
= napi_frags_skb(napi
);
148 if (netpoll_rx_on(skb
)) {
149 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
150 return vlan_hwaccel_receive_skb(skb
, grp
, vlan_tci
)
151 ? GRO_DROP
: GRO_NORMAL
;
154 return napi_frags_finish(napi
, skb
,
155 vlan_gro_common(napi
, grp
, vlan_tci
, skb
));
157 EXPORT_SYMBOL(vlan_gro_frags
);