All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] packet: allow to transmit +4 byte in TX_RING slot for VLAN case
@ 2014-02-28  1:22 Daniel Borkmann
  2014-02-28 11:26 ` Kretschmer, Mathias
  2014-02-28 21:52 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel Borkmann @ 2014-02-28  1:22 UTC (permalink / raw)
  To: davem; +Cc: netdev, mathias.kretschmer, Ben Greear, Phil Sutter

Commit 57f89bfa2140 ("network: Allow af_packet to transmit +4 bytes
for VLAN packets.") added the possibility for non-mmaped frames to
send extra 4 byte for VLAN header so the MTU increases from 1500 to
1504 byte, for example.

Commit cbd89acb9eb2 ("af_packet: fix for sending VLAN frames via
packet_mmap") attempted to fix that for the mmap part but was
reverted as it caused regressions while using eth_type_trans()
on output path.

Lets just act analogous to 57f89bfa2140 and add a similar logic
to TX_RING. We presume size_max as overcharged with +4 bytes and
later on after skb has been built by tpacket_fill_skb() check
for ETH_P_8021Q header on packets larger than normal MTU. Can
be easily reproduced with a slightly modified trafgen in mmap(2)
mode, test cases:

 { fill(0xff, 12) const16(0x8100) fill(0xff, <1504|1505>) }
 { fill(0xff, 12) const16(0x0806) fill(0xff, <1500|1501>) }

Note that we need to do the test right after tpacket_fill_skb()
as sockets can have PACKET_LOSS set where we would not fail but
instead just continue to traverse the ring.

Reported-by: Mathias Kretschmer <mathias.kretschmer@fokus.fraunhofer.de>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Cc: Ben Greear <greearb@candelatech.com>
Cc: Phil Sutter <phil@nwl.cc>
---
 net/packet/af_packet.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 48a6a93..2923044 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2257,8 +2257,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
 	if (unlikely(!(dev->flags & IFF_UP)))
 		goto out_put;
 
-	reserve = dev->hard_header_len;
-
+	reserve = dev->hard_header_len + VLAN_HLEN;
 	size_max = po->tx_ring.frame_size
 		- (po->tp_hdrlen - sizeof(struct sockaddr_ll));
 
@@ -2285,8 +2284,19 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
 			goto out_status;
 
 		tp_len = tpacket_fill_skb(po, skb, ph, dev, size_max, proto,
-				addr, hlen);
+					  addr, hlen);
+		if (tp_len > dev->mtu + dev->hard_header_len) {
+			struct ethhdr *ehdr;
+			/* Earlier code assumed this would be a VLAN pkt,
+			 * double-check this now that we have the actual
+			 * packet in hand.
+			 */
 
+			skb_reset_mac_header(skb);
+			ehdr = eth_hdr(skb);
+			if (ehdr->h_proto != htons(ETH_P_8021Q))
+				tp_len = -EMSGSIZE;
+		}
 		if (unlikely(tp_len < 0)) {
 			if (po->tp_loss) {
 				__packet_set_status(po, ph,
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH net-next] packet: allow to transmit +4 byte in TX_RING slot for VLAN case
  2014-02-28  1:22 [PATCH net-next] packet: allow to transmit +4 byte in TX_RING slot for VLAN case Daniel Borkmann
@ 2014-02-28 11:26 ` Kretschmer, Mathias
  2014-02-28 21:52 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Kretschmer, Mathias @ 2014-02-28 11:26 UTC (permalink / raw)
  To: Daniel Borkmann, davem; +Cc: netdev, Ben Greear, Phil Sutter

Tested-by: Mathias Kretschmer <mathias.kretschmer@fokus.fraunhofer.de>

> -----Original Message-----
> From: Daniel Borkmann [mailto:dborkman@redhat.com]
> Sent: Friday, February 28, 2014 02:22
> To: davem@davemloft.net
> Cc: netdev@vger.kernel.org; Kretschmer, Mathias; Ben Greear; Phil Sutter
> Subject: [PATCH net-next] packet: allow to transmit +4 byte in TX_RING slot
> for VLAN case
> 
> Commit 57f89bfa2140 ("network: Allow af_packet to transmit +4 bytes for
> VLAN packets.") added the possibility for non-mmaped frames to send extra
> 4 byte for VLAN header so the MTU increases from 1500 to
> 1504 byte, for example.
> 
> Commit cbd89acb9eb2 ("af_packet: fix for sending VLAN frames via
> packet_mmap") attempted to fix that for the mmap part but was reverted as
> it caused regressions while using eth_type_trans() on output path.
> 
> Lets just act analogous to 57f89bfa2140 and add a similar logic to TX_RING.
> We presume size_max as overcharged with +4 bytes and later on after skb
> has been built by tpacket_fill_skb() check for ETH_P_8021Q header on
> packets larger than normal MTU. Can be easily reproduced with a slightly
> modified trafgen in mmap(2) mode, test cases:
> 
>  { fill(0xff, 12) const16(0x8100) fill(0xff, <1504|1505>) }  { fill(0xff, 12)
> const16(0x0806) fill(0xff, <1500|1501>) }
> 
> Note that we need to do the test right after tpacket_fill_skb() as sockets can
> have PACKET_LOSS set where we would not fail but instead just continue to
> traverse the ring.
> 
> Reported-by: Mathias Kretschmer
> <mathias.kretschmer@fokus.fraunhofer.de>
> Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
> Cc: Ben Greear <greearb@candelatech.com>
> Cc: Phil Sutter <phil@nwl.cc>
> ---
>  net/packet/af_packet.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index
> 48a6a93..2923044 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -2257,8 +2257,7 @@ static int tpacket_snd(struct packet_sock *po,
> struct msghdr *msg)
>  	if (unlikely(!(dev->flags & IFF_UP)))
>  		goto out_put;
> 
> -	reserve = dev->hard_header_len;
> -
> +	reserve = dev->hard_header_len + VLAN_HLEN;
>  	size_max = po->tx_ring.frame_size
>  		- (po->tp_hdrlen - sizeof(struct sockaddr_ll));
> 
> @@ -2285,8 +2284,19 @@ static int tpacket_snd(struct packet_sock *po,
> struct msghdr *msg)
>  			goto out_status;
> 
>  		tp_len = tpacket_fill_skb(po, skb, ph, dev, size_max, proto,
> -				addr, hlen);
> +					  addr, hlen);
> +		if (tp_len > dev->mtu + dev->hard_header_len) {
> +			struct ethhdr *ehdr;
> +			/* Earlier code assumed this would be a VLAN pkt,
> +			 * double-check this now that we have the actual
> +			 * packet in hand.
> +			 */
> 
> +			skb_reset_mac_header(skb);
> +			ehdr = eth_hdr(skb);
> +			if (ehdr->h_proto != htons(ETH_P_8021Q))
> +				tp_len = -EMSGSIZE;
> +		}
>  		if (unlikely(tp_len < 0)) {
>  			if (po->tp_loss) {
>  				__packet_set_status(po, ph,
> --
> 1.7.11.7

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] packet: allow to transmit +4 byte in TX_RING slot for VLAN case
  2014-02-28  1:22 [PATCH net-next] packet: allow to transmit +4 byte in TX_RING slot for VLAN case Daniel Borkmann
  2014-02-28 11:26 ` Kretschmer, Mathias
@ 2014-02-28 21:52 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2014-02-28 21:52 UTC (permalink / raw)
  To: dborkman; +Cc: netdev, mathias.kretschmer, greearb, phil

From: Daniel Borkmann <dborkman@redhat.com>
Date: Fri, 28 Feb 2014 02:22:06 +0100

> Commit 57f89bfa2140 ("network: Allow af_packet to transmit +4 bytes
> for VLAN packets.") added the possibility for non-mmaped frames to
> send extra 4 byte for VLAN header so the MTU increases from 1500 to
> 1504 byte, for example.
> 
> Commit cbd89acb9eb2 ("af_packet: fix for sending VLAN frames via
> packet_mmap") attempted to fix that for the mmap part but was
> reverted as it caused regressions while using eth_type_trans()
> on output path.
> 
> Lets just act analogous to 57f89bfa2140 and add a similar logic
> to TX_RING. We presume size_max as overcharged with +4 bytes and
> later on after skb has been built by tpacket_fill_skb() check
> for ETH_P_8021Q header on packets larger than normal MTU. Can
> be easily reproduced with a slightly modified trafgen in mmap(2)
> mode, test cases:
> 
>  { fill(0xff, 12) const16(0x8100) fill(0xff, <1504|1505>) }
>  { fill(0xff, 12) const16(0x0806) fill(0xff, <1500|1501>) }
> 
> Note that we need to do the test right after tpacket_fill_skb()
> as sockets can have PACKET_LOSS set where we would not fail but
> instead just continue to traverse the ring.
> 
> Reported-by: Mathias Kretschmer <mathias.kretschmer@fokus.fraunhofer.de>
> Signed-off-by: Daniel Borkmann <dborkman@redhat.com>

Looks good, applied, thanks Daniel.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-02-28 21:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-28  1:22 [PATCH net-next] packet: allow to transmit +4 byte in TX_RING slot for VLAN case Daniel Borkmann
2014-02-28 11:26 ` Kretschmer, Mathias
2014-02-28 21:52 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.