From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Ahern Subject: Re: [RFC bpf-next 8/9] bpf: Provide helper to do lookups in kernel FIB table Date: Wed, 25 Apr 2018 17:24:45 -0600 Message-ID: References: <20180425183449.25134-1-dsahern@gmail.com> <20180425183449.25134-9-dsahern@gmail.com> <9488a57d-5559-b69f-631e-71cada1c1d2d@iogearbox.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: shm@cumulusnetworks.com, roopa@cumulusnetworks.com, brouer@redhat.com, toke@toke.dk, john.fastabend@gmail.com To: Daniel Borkmann , netdev@vger.kernel.org, ast@kernel.org Return-path: Received: from mail-pf0-f175.google.com ([209.85.192.175]:44997 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753652AbeDYXYt (ORCPT ); Wed, 25 Apr 2018 19:24:49 -0400 Received: by mail-pf0-f175.google.com with SMTP id q22so1599361pff.11 for ; Wed, 25 Apr 2018 16:24:48 -0700 (PDT) In-Reply-To: <9488a57d-5559-b69f-631e-71cada1c1d2d@iogearbox.net> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 4/25/18 1:55 PM, Daniel Borkmann wrote: >> @@ -3861,6 +4090,8 @@ sk_filter_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) >> return &bpf_get_socket_cookie_proto; >> case BPF_FUNC_get_socket_uid: >> return &bpf_get_socket_uid_proto; >> + case BPF_FUNC_fib_lookup: >> + return &bpf_fib_lookup_proto; > This part doesn't belong to sk_filter_func_proto(), but to the > tc_cls_act_func_proto() instead. oops, somewhere in all of the re-basing it got added to the wrong function. Will fix. > >> default: >> return bpf_base_func_proto(func_id); >> } >> @@ -3957,6 +4188,8 @@ xdp_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) >> return &bpf_xdp_redirect_map_proto; >> case BPF_FUNC_xdp_adjust_tail: >> return &bpf_xdp_adjust_tail_proto; >> + case BPF_FUNC_fib_lookup: >> + return &bpf_fib_lookup_proto; > Basically, you're using the very same bpf_fib_lookup_proto for > both XDP and skb. In the skb case, you're reusing the two functions > bpf_ipv{4,6}_fib_lookup(), so when you get the netdev pointer for > retrieving the netns, you'll crash at dev_net(ctx->rxq->dev) since > this is XDP only and not skb meta data. > > Therefore, as mentioned, pass the netdev to bpf_ipv{4,6}_fib_lookup() > to have it generic and have bpf_xdp_fib_lookup_proto and > bpf_skb_fib_lookup_proto where both are under the case BPF_FUNC_fib_lookup > in the respective *func_proto(), but using the proper prototypes according > to their correct context. Meaning, both reuse bpf_ipv{4,6}_fib_lookup() > from each of their BPF_CALL_4() helper implementation. ok. I have been focused on the xdp program and not the tc path. Will fix.