From: Daniel Borkmann <daniel@iogearbox.net>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>, David Miller <davem@davemloft.net>,
netdev@vger.kernel.org, tklauser@distanz.ch
Subject: Re: AF_PACKET mmap() v4...
Date: Thu, 05 Nov 2015 23:56:37 +0100 [thread overview]
Message-ID: <563BDEA5.9080907@iogearbox.net> (raw)
In-Reply-To: <1446740279.4184.40.camel@edumazet-glaptop2.roam.corp.google.com>
On 11/05/2015 05:17 PM, Eric Dumazet wrote:
> On Thu, 2015-11-05 at 13:56 +0100, Daniel Borkmann wrote:
>> On 11/05/2015 12:38 PM, Eric Dumazet wrote:
>
>>> If I am not mistaken, af_packet also lacks the ability to properly set
>>> skb->protocol
>>>
>>> I noticed this using trafgen on a bonding device, when I did my SYNFLOOD
>>> tests for TCP listener rewrite.
>>>
>>> The bonding hash function might uses flow dissector, but as this flow
>>> dissection depends on skb->protocol, all the traffic is directed on a
>>> single slave.
>>
>> Right, if I see this correctly, when you trigger the flushing of TX_RING
>> via sendmsg(), one can hand over a sockaddr_ll, where we infer sll_protocol
>> and tag every skb's skb->protocol with that in tpacket_fill_skb() for the
>> current flushing run. Otherwise, we use the po->num specified at socket
>> creation / bind time for everything (trafgen case).
>>
>> If needed on a per skb basis, perhaps we could map some tpacket_hdr{,2}
>> member that is not used from TX_RING side (perhaps union on tp_snaplen)?
>
> If po->num is 0 (as in trafgen case), we could also get the proto from
> Ethernet header provided by the user.
>
> The skb_probe_transport_header() call from tpacket_fill_skb() is useless
> in the current kernel.
>
> Let say an application wants to mix IPv6 and IPv4 packets, using a
> single TX ring....
Sorry for the late answer.
For the skb->protocol issue, perhaps something like this. Also noticed that
we should rather do the vlan check when we have the actual linear data from
the ring slot, the current way seems buggy if I see this correctly. Both
patches squashed below.
Thanks,
Daniel
net/packet/af_packet.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 691660b..8415ebd 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2399,8 +2399,22 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
} else {
data = ph.raw + po->tp_hdrlen - sizeof(struct sockaddr_ll);
}
+
to_write = tp_len;
+ /* If skb->protocol is still 0, try to infer it. */
+ if (!skb->protocol && tp_len >= sizeof(struct ethhdr))
+ skb->protocol = ((struct ethhdr *)data)->h_proto;
+ if (tp_len > dev->mtu + dev->hard_header_len) {
+ /* Earlier code assumed this would be a VLAN pkt,
+ * double-check this now that we have the actual
+ * (linear) packet data at hand.
+ */
+ if (unlikely(((struct ethhdr *)data)->h_proto !=
+ htons(ETH_P_8021Q)))
+ return -EMSGSIZE;
+ }
+
if (sock->type == SOCK_DGRAM) {
err = dev_hard_header(skb, dev, ntohs(proto), addr,
NULL, tp_len);
@@ -2524,19 +2538,6 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
}
tp_len = tpacket_fill_skb(po, skb, ph, dev, size_max, proto,
addr, hlen);
- if (likely(tp_len >= 0) &&
- 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.9.3
next prev parent reply other threads:[~2015-11-05 22:56 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-05 5:04 AF_PACKET mmap() v4 David Miller
2015-11-05 6:53 ` Richard Cochran
2015-11-05 8:14 ` Guy Harris
2015-11-05 15:32 ` David Miller
2015-11-05 9:07 ` Arnd Bergmann
2015-11-05 9:39 ` Daniel Borkmann
2015-11-05 11:38 ` Eric Dumazet
2015-11-05 12:56 ` Daniel Borkmann
2015-11-05 16:17 ` Eric Dumazet
2015-11-05 22:56 ` Daniel Borkmann [this message]
2015-11-06 11:34 ` Daniel Borkmann
2015-11-08 2:19 ` Alexei Starovoitov
2015-11-08 4:27 ` John Fastabend
2015-11-09 10:54 ` Daniel Borkmann
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=563BDEA5.9080907@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=tklauser@distanz.ch \
/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).