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: Fri, 27 Apr 2018 10:49:35 -0600 Message-ID: References: <20180425183449.25134-1-dsahern@gmail.com> <20180425183449.25134-9-dsahern@gmail.com> <20180427164303.qxodjc63i6pf75q6@kafai-mbp> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: netdev@vger.kernel.org, borkmann@iogearbox.net, ast@kernel.org, shm@cumulusnetworks.com, roopa@cumulusnetworks.com, brouer@redhat.com, toke@toke.dk, john.fastabend@gmail.com To: Martin KaFai Lau Return-path: Received: from mail-pf0-f195.google.com ([209.85.192.195]:43173 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758554AbeD0Qti (ORCPT ); Fri, 27 Apr 2018 12:49:38 -0400 Received: by mail-pf0-f195.google.com with SMTP id j11so1881881pff.10 for ; Fri, 27 Apr 2018 09:49:38 -0700 (PDT) In-Reply-To: <20180427164303.qxodjc63i6pf75q6@kafai-mbp> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 4/27/18 10:43 AM, Martin KaFai Lau wrote: >> +#if IS_ENABLED(CONFIG_IPV6) >> +static int bpf_ipv6_fib_lookup(struct xdp_buff *ctx, >> + struct bpf_fib_lookup *params, u32 flags) >> +{ >> + struct net *net = dev_net(ctx->rxq->dev); >> + struct neighbour *neigh; >> + struct net_device *dev; >> + struct fib6_info *f6i; >> + struct flowi6 fl6; >> + int strict = 0; >> + int oif; >> + >> + /* link local addresses are never forwarded */ >> + if (rt6_need_strict(¶ms->ipv6_dst) || >> + rt6_need_strict(¶ms->ipv6_src)) >> + return 0; >> + >> + dev = dev_get_by_index_rcu(net, params->ifindex); >> + if (unlikely(!dev)) >> + return -ENODEV; >> + >> + if (flags & BPF_FIB_LOOKUP_OUTPUT) { >> + fl6.flowi6_iif = 1; > 1 is for LOOPBACK_IFINDEX? yes. The intention is to mirror the flow struct created by full stack so that routing in bpf == routing in IPv6 stack. ip6_route_output_flags sets flowi6_iif to 1, so I repeated it here. > >> + oif = fl6.flowi6_oif = params->ifindex; >> + } else { >> + oif = fl6.flowi6_iif = params->ifindex; >> + fl6.flowi6_oif = 0; >> + strict = RT6_LOOKUP_F_HAS_SADDR; >> + }