From: Daniel Borkmann <dborkman@redhat.com>
To: Ronny Meeus <ronny.meeus@gmail.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>, netdev <netdev@vger.kernel.org>
Subject: Re: How do I receive vlan tags on an AF_PACKET socket in 3.4 kernel?
Date: Wed, 31 Jul 2013 16:42:55 +0200 [thread overview]
Message-ID: <51F9226F.30202@redhat.com> (raw)
In-Reply-To: <CAMJ=MEeLRQTROpj4LBJ2b--dqyxBUKPcW7F=q9qdqxm_4kHL7g@mail.gmail.com>
On 07/31/2013 04:36 PM, Ronny Meeus wrote:
> On Wed, Jul 31, 2013 at 4:16 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
>> On Wed, 2013-07-31 at 14:51 +0200, Ronny Meeus wrote:
>>
>>> Thanks for the feedback. High level it is almost clear.
>>>
>>> At implementation level I do not understand how it is supposed to work.
>>> If I use tcpdump to generate a filter for example on vlan 4094 I see
>>> no reference at all to the newly added instructions to get the VLAN.
>>>
>>> ~ # tcpdump -i eth-ntb vlan 4094 -d
>>> tcpdump: WARNING: eth-ntb: no IPv4 address assigned
>>> (000) ldh [12]
>>> (001) jeq #0x8100 jt 3 jf 2
>>> (002) jeq #0x9100 jt 3 jf 7
>>> (003) ldh [14]
>>> (004) and #0xfff
>>> (005) jeq #0xffe jt 6 jf 7
>>> (006) ret #65535
>>> (007) ret #0
>>>
>>> To me it looks like to code above is just checking the bytes in the
>>> raw Ethernet packet at offset 12 and 14.
>>> Since the command above seems to work it looks to me that the
>>> filtering is done in the tcpdump application instead of in the kernel.
>>>
>>> If I use the strace command while starting tcpdump I see that the
>>> SO_ATTACH_FILTER sockopt is passed to the kernel:
>>>
>>> <snip>
>>> setsockopt(3, SOL_SOCKET, SO_ATTACH_FILTER, "\0\1\0\0\20\f\366\340", 8) = 0
>>> fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
>>> fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
>>> recvfrom(3, 0x7f6f6630, 1, 32, 0, 0) = -1 EAGAIN (Resource
>>> temporarily unavailable)
>>> fcntl64(3, F_SETFL, O_RDWR) = 0
>>> setsockopt(3, SOL_SOCKET, SO_ATTACH_FILTER, "\0\10\0\0\20>\210@", 8) = 0
>>> <snip>
>>>
>>> So I'm confused. I would expect to see some commands to read access
>>> the VLAN field in the additional data and compare it to the VLAN
>>> (4094) I want to filter.
>>
>> I assumed from you initial mail you were using a BPF filter, not
>> libpcap, which presumably doesnt use these new 'instructions'
>
> I used the tcpdump tool to generate the filter I need to use in my application.
>
>> Adapting the BPF filter generated by libpcap is a matter of adding 3 or
>> 4 instructions. In your case 2 instructions actually
>>
>> One to load tag id into A
>> One to compare A against immediate value 4094 and conditional jump.
>
> Can you give an real example of a filter that passes all packets that
> have a VLAN 4094 attached and drops all others?
You can use bpfc (git://github.com/borkmann/netsniff-ng.git), it also has
an extensive man page. That should probably do it:
$ cat foo
ld vlant
jneq #4094, drop
ret #-1
drop: ret #0
$ bpfc foo
{ 0x20, 0, 0, 0xfffff02c },
{ 0x15, 0, 1, 0x00000ffe },
{ 0x6, 0, 0, 0xffffffff },
{ 0x6, 0, 0, 0x00000000 },
next prev parent reply other threads:[~2013-07-31 14:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-30 13:07 How do I receive vlan tags on an AF_PACKET socket in 3.4 kernel? Ronny Meeus
2013-07-30 14:09 ` Eric Dumazet
2013-07-31 12:51 ` Ronny Meeus
2013-07-31 12:54 ` Daniel Borkmann
2013-07-31 14:16 ` Eric Dumazet
2013-07-31 14:36 ` Ronny Meeus
2013-07-31 14:42 ` Daniel Borkmann [this message]
2013-07-31 15:09 ` Eric Dumazet
2013-07-31 20:01 ` Ronny Meeus
2013-07-31 20:47 ` Eric Dumazet
2013-08-01 9:24 ` Ronny Meeus
2013-08-02 8:15 ` Daniel Borkmann
2013-08-02 9:03 ` Ronny Meeus
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=51F9226F.30202@redhat.com \
--to=dborkman@redhat.com \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=ronny.meeus@gmail.com \
/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).