1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
3 #include "bpf_iter.h"
4 #include "bpf_tracing_net.h"
5 #include <bpf/bpf_helpers.h>
6 #include <bpf/bpf_tracing.h>
7
8 char _license[] SEC("license") = "GPL";
9
10 extern bool CONFIG_IPV6_SUBTREES __kconfig __weak;
11
12 SEC("iter/ipv6_route")
dump_ipv6_route(struct bpf_iter__ipv6_route * ctx)13 int dump_ipv6_route(struct bpf_iter__ipv6_route *ctx)
14 {
15 struct seq_file *seq = ctx->meta->seq;
16 struct fib6_info *rt = ctx->rt;
17 const struct net_device *dev;
18 struct fib6_nh *fib6_nh;
19 unsigned int flags;
20 struct nexthop *nh;
21
22 if (rt == (void *)0)
23 return 0;
24
25 fib6_nh = &rt->fib6_nh[0];
26 flags = rt->fib6_flags;
27
28 /* FIXME: nexthop_is_multipath is not handled here. */
29 nh = rt->nh;
30 if (rt->nh)
31 fib6_nh = &nh->nh_info->fib6_nh;
32
33 BPF_SEQ_PRINTF(seq, "%pi6 %02x ", &rt->fib6_dst.addr, rt->fib6_dst.plen);
34
35 if (CONFIG_IPV6_SUBTREES)
36 BPF_SEQ_PRINTF(seq, "%pi6 %02x ", &rt->fib6_src.addr,
37 rt->fib6_src.plen);
38 else
39 BPF_SEQ_PRINTF(seq, "00000000000000000000000000000000 00 ");
40
41 if (fib6_nh->fib_nh_gw_family) {
42 flags |= RTF_GATEWAY;
43 BPF_SEQ_PRINTF(seq, "%pi6 ", &fib6_nh->fib_nh_gw6);
44 } else {
45 BPF_SEQ_PRINTF(seq, "00000000000000000000000000000000 ");
46 }
47
48 dev = fib6_nh->fib_nh_dev;
49 if (dev)
50 BPF_SEQ_PRINTF(seq, "%08x %08x %08x %08x %8s\n", rt->fib6_metric,
51 rt->fib6_ref.refs.counter, 0, flags, dev->name);
52 else
53 BPF_SEQ_PRINTF(seq, "%08x %08x %08x %08x\n", rt->fib6_metric,
54 rt->fib6_ref.refs.counter, 0, flags);
55
56 return 0;
57 }
58