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(&params->ipv6_dst) ||
>> +        rt6_need_strict(&params->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;
>> +    }

Reply via email to