Subject: Re: [PATCH net-next v2] filter: introduce SKF_AD_VLAN_TPID BPF extension

From: Alexei Starovoitov <[email-masked]>
Date: Thu, 19 Mar 2015 09:08:35 -0700

On 3/19/15 4:10 AM, Michal Sekletar wrote:
> If vlan offloading takes place then vlan header is removed from frame
> and its contents, both vlan_tci and vlan_proto, is available to userspace via
> TPACKET interface. However, only vlan_tci can be used in BPF filters.
>
> This commit introduces new BPF extension. It makes possible to load value of
> vlan_proto (vlan TPID) to register A.

Agree with the idea, though we need to decide whether to do ntohs on
vlan_proto or not. Since right now your patch makes it consistent
on different architectures.

For arch where extended BPF jit is available the following:
 > +	case SKF_AD_OFF + SKF_AD_VLAN_TPID:
...
 > +		/* A = ntohs(A) [emitting a nop or swap16] */
 > +		*insn = BPF_ENDIAN(BPF_FROM_BE, BPF_REG_A, 16);

will make sure that it's doing ntohs,
whereas arm JIT is doing normal 16-bit load.
ppc can be both big and little, so PPC_LHZ_OFFS is incorrect.

Since it's a new field, I think it makes sense not to do ntohs at all.
Let bpf programs do htons(PROTO_CONSTANT), since it can be done at
compile time instead of run-time.