netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <dborkman@redhat.com>
To: Mathias Kretschmer <mathias.kretschmer@fokus.fraunhofer.de>
Cc: jbrouer@redhat.com, netdev@vger.kernel.org
Subject: Re: TX_RING and VLAN : (packet size is too long 1518 > 1514)
Date: Sun, 23 Feb 2014 14:58:13 +0100	[thread overview]
Message-ID: <5309FE75.8030802@redhat.com> (raw)
In-Reply-To: <5309D59A.1020304@fokus.fraunhofer.de>

On 02/23/2014 12:03 PM, Mathias Kretschmer wrote:
> Hi Daniel, all
>
> we're running into the above error when sending full-sized VLAN-tagged frames via TX_RING (Kernel 3.10.31, but same code seems to be present in 3.14).
>
> For the regular send() calls, there seems to be code in place to handle VLAN-tagged frames, but in tpacket_fill_skb() there is no such check.
>
> I came up with fix for this, but can only verify this tomorrow.
> If it works, I'd send you a patch, but someone with more insights into the networking code should probably fix this properly ;-)

Looks like the logic was added only to packet_snd() path when there was no TX_RING
implementation available yet.

Does that patch work for you?

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 48a6a93..9deb991 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,7 @@ 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 (unlikely(tp_len < 0)) {
  			if (po->tp_loss) {
  				__packet_set_status(po, ph,
@@ -2300,6 +2298,21 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
  				goto out_status;
  			}
  		}
+		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)) {
+				status = TP_STATUS_WRONG_FORMAT;
+				err = -EMSGSIZE;
+				goto out_status;
+			}
+		}

  		packet_pick_tx_queue(dev, skb);

  reply	other threads:[~2014-02-23 13:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-23 11:03 TX_RING and VLAN : (packet size is too long 1518 > 1514) Mathias Kretschmer
2014-02-23 13:58 ` Daniel Borkmann [this message]
2014-02-24  9:03   ` Mathias Kretschmer
2014-02-24 22:33     ` Daniel Borkmann
2014-02-26  7:28       ` Mathias Kretschmer
2014-02-26 10:33         ` Daniel Borkmann
2014-02-24 21:40   ` Setting skb->protocol efficiently for AF_PACKETs via TX_RING Mathias Kretschmer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5309FE75.8030802@redhat.com \
    --to=dborkman@redhat.com \
    --cc=jbrouer@redhat.com \
    --cc=mathias.kretschmer@fokus.fraunhofer.de \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).