[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAADnVQKNHL7iY=VHp4bs5k2hSDf8jy7H-0H0SgYjb81S25XB9Q@mail.gmail.com>
Date: Wed, 3 Sep 2014 16:14:31 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Daniel Borkmann <dborkman@...hat.com>,
Eric Dumazet <edumazet@...gle.com>
Cc: Denis Kirjanov <kda@...ux-powerpc.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
Markos Chandras <markos.chandras@...tec.com>,
Martin Schwidefsky <schwidefsky@...ibm.com>
Subject: Re: [PATCH v2 net-next] net: filter: export pkt_type_offset() helper
On Wed, Sep 3, 2014 at 3:01 PM, Daniel Borkmann <dborkman@...hat.com> wrote:
> On 09/03/2014 11:08 PM, Denis Kirjanov wrote:
>>
>
>> +static int __init init_pkt_type_offset(void)
>> {
>> struct sk_buff skb_probe = { .pkt_type = ~0, };
>> u8 *ct = (u8 *) &skb_probe;
>> unsigned int off;
>>
>> + pkt_type_offset = -1;
>> for (off = 0; off < sizeof(struct sk_buff); off++) {
>> - if (ct[off] == PKT_TYPE_MAX)
>> + if (ct[off] == PKT_TYPE_MAX) {
>> + pkt_type_offset = off;
>> return off;
>> + }
>> }
>
>
> Why not BUG_ON() when pkt_type_offset could not be found?
>
> That way we would know that something is broken and you can
> spare the checks for negative offsets everywhere ...
also such BUG_ON will be right in the face, since the kernel
won't even boot :)
I guess we can only hit it if compiler changes and starts
doing crazing things with bitfields.
Eric, you're the original author of this function, thoughts?
>> case SKF_AD_OFF + SKF_AD_PKTTYPE:
>> + if (pkt_type_offset < 0)
>> + return false;
with BUG_ON we wouldn't need this check.
>> *insn = BPF_LDX_MEM(BPF_B, BPF_REG_A, BPF_REG_CTX,
>> - pkt_type_offset());
>> + pkt_type_offset);
>> if (insn->off < 0)
>> return false;
and this one too.
and other checks in arch/*/jit
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists