Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2020 Facebook */
0003 #include "bpf_iter.h"
0004 #include "bpf_tracing_net.h"
0005 #include <bpf/bpf_helpers.h>
0006 
0007 char _license[] SEC("license") = "GPL";
0008 
0009 extern bool CONFIG_IPV6_SUBTREES __kconfig __weak;
0010 
0011 SEC("iter/ipv6_route")
0012 int dump_ipv6_route(struct bpf_iter__ipv6_route *ctx)
0013 {
0014     struct seq_file *seq = ctx->meta->seq;
0015     struct fib6_info *rt = ctx->rt;
0016     const struct net_device *dev;
0017     struct fib6_nh *fib6_nh;
0018     unsigned int flags;
0019     struct nexthop *nh;
0020 
0021     if (rt == (void *)0)
0022         return 0;
0023 
0024     fib6_nh = &rt->fib6_nh[0];
0025     flags = rt->fib6_flags;
0026 
0027     /* FIXME: nexthop_is_multipath is not handled here. */
0028     nh = rt->nh;
0029     if (rt->nh)
0030         fib6_nh = &nh->nh_info->fib6_nh;
0031 
0032     BPF_SEQ_PRINTF(seq, "%pi6 %02x ", &rt->fib6_dst.addr, rt->fib6_dst.plen);
0033 
0034     if (CONFIG_IPV6_SUBTREES)
0035         BPF_SEQ_PRINTF(seq, "%pi6 %02x ", &rt->fib6_src.addr,
0036                    rt->fib6_src.plen);
0037     else
0038         BPF_SEQ_PRINTF(seq, "00000000000000000000000000000000 00 ");
0039 
0040     if (fib6_nh->fib_nh_gw_family) {
0041         flags |= RTF_GATEWAY;
0042         BPF_SEQ_PRINTF(seq, "%pi6 ", &fib6_nh->fib_nh_gw6);
0043     } else {
0044         BPF_SEQ_PRINTF(seq, "00000000000000000000000000000000 ");
0045     }
0046 
0047     dev = fib6_nh->fib_nh_dev;
0048     if (dev)
0049         BPF_SEQ_PRINTF(seq, "%08x %08x %08x %08x %8s\n", rt->fib6_metric,
0050                    rt->fib6_ref.refs.counter, 0, flags, dev->name);
0051     else
0052         BPF_SEQ_PRINTF(seq, "%08x %08x %08x %08x\n", rt->fib6_metric,
0053                    rt->fib6_ref.refs.counter, 0, flags);
0054 
0055     return 0;
0056 }