bpfc: constants in input file

17 views
Skip to first unread message

John Lange

unread,
May 21, 2013, 4:41:03 PM5/21/13
to netsn...@googlegroups.com
Hello,

I've been using the bpfc tool lately, and it's very useful!  I was wondering whether the input file format might support constant value definitions that could be used elsewhere within the file.  For example, something like:

$VLAN_TAG #8100  
jeq    $VLAN_TAG, Keep, Drop

Thanks!
John

Daniel Borkmann

unread,
May 21, 2013, 4:46:29 PM5/21/13
to netsn...@googlegroups.com
Hi John,

On 05/21/2013 10:41 PM, John Lange wrote:
> I've been using the bpfc tool lately, and it's very useful! I was wondering whether the input file format might support constant value definitions that could be used elsewhere within the file. For example, something like:

Thanks for using bpfc! :-)

> $VLAN_TAG #8100
> �
> jeq $VLAN_TAG, Keep, Drop
> �

Currently it is not supported. What we could do here
would be a similar approach as in trafgen if you need
it, where we would pass the source file first to the
C preprocessor doing textual replacements and then to
bpfc. What do you say?

Cheers,

Daniel

jla...@trendium.com

unread,
May 22, 2013, 10:32:52 AM5/22/13
to netsn...@googlegroups.com

> Currently it is not supported. What we could do here
>
> would be a similar approach as in trafgen if you need
>
> it, where we would pass the source file first to the
>
> C preprocessor doing textual replacements and then to
>
> bpfc. What do you say?

Hi Daniel,
That would be great!
Thanks,
John

Daniel Borkmann

unread,
May 23, 2013, 5:15:45 AM5/23/13
to netsn...@googlegroups.com, jla...@trendium.com
Done, please pull from the repo to get this commit:

commit 4584b955420cd8d2fcae767c86b853fde4bccc6e
Author: Daniel Borkmann <dbor...@redhat.com>
Date: Thu May 23 11:08:03 2013 +0200

bpfc: allow bpf programs to be passed to cpp

This patch allows bpf programs to be passed to the C preprocessor
before handing over to bpfc. Example:

#define ETH_P_IP 0x800

ldh [12]
jne #ETH_P_IP, drop
ldb [23]
jneq #6, drop
ldh [20]
jset #0x1fff, drop
ldxb 4 * ([14] & 0xf)
ldh [x + 14]
jeq #0x16, pass
ldh [x + 16]
jne #0x16, drop
pass: ret #-1
drop: ret #0

Compile with: bpfc -i foo -p

Suggested-by: John Lange <JLa...@trendium.com>
Signed-off-by: Daniel Borkmann <dbor...@redhat.com>
Reply all
Reply to author
Forward
0 new messages