Skip to content

Commit 9f32397

Browse files
dsaherndavem330
authored andcommitted
net/ipv4: Udate fib_table_lookup tracepoint
Commit 4a2d73a ("ipv4: fib_rules: support match on sport, dport and ip proto") added support for protocol and ports to FIB rules. Update the FIB lookup tracepoint to dump the parameters. In addition, make the IPv4 tracepoint similar to the IPv6 one where the lookup parameters and result are dumped in 1 event. It is much easier to use and understand the outcome of the lookup. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent aaa908f commit 9f32397

File tree

2 files changed

+52
-34
lines changed

2 files changed

+52
-34
lines changed

include/trace/events/fib.h

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,34 @@
1212

1313
TRACE_EVENT(fib_table_lookup,
1414

15-
TP_PROTO(u32 tb_id, const struct flowi4 *flp),
15+
TP_PROTO(u32 tb_id, const struct flowi4 *flp,
16+
const struct fib_nh *nh, int err),
1617

17-
TP_ARGS(tb_id, flp),
18+
TP_ARGS(tb_id, flp, nh, err),
1819

1920
TP_STRUCT__entry(
2021
__field( u32, tb_id )
22+
__field( int, err )
2123
__field( int, oif )
2224
__field( int, iif )
2325
__field( __u8, tos )
2426
__field( __u8, scope )
2527
__field( __u8, flags )
2628
__array( __u8, src, 4 )
2729
__array( __u8, dst, 4 )
30+
__array( __u8, gw, 4 )
31+
__array( __u8, saddr, 4 )
32+
__field( u16, sport )
33+
__field( u16, dport )
34+
__field( u8, proto )
35+
__dynamic_array(char, name, IFNAMSIZ )
2836
),
2937

3038
TP_fast_assign(
3139
__be32 *p32;
3240

3341
__entry->tb_id = tb_id;
42+
__entry->err = err;
3443
__entry->oif = flp->flowi4_oif;
3544
__entry->iif = flp->flowi4_iif;
3645
__entry->tos = flp->flowi4_tos;
@@ -42,36 +51,41 @@ TRACE_EVENT(fib_table_lookup,
4251

4352
p32 = (__be32 *) __entry->dst;
4453
*p32 = flp->daddr;
45-
),
46-
47-
TP_printk("table %u oif %d iif %d src %pI4 dst %pI4 tos %d scope %d flags %x",
48-
__entry->tb_id, __entry->oif, __entry->iif,
49-
__entry->src, __entry->dst, __entry->tos, __entry->scope,
50-
__entry->flags)
51-
);
52-
53-
TRACE_EVENT(fib_table_lookup_nh,
54-
55-
TP_PROTO(const struct fib_nh *nh),
56-
57-
TP_ARGS(nh),
58-
59-
TP_STRUCT__entry(
60-
__string( name, nh->nh_dev->name)
61-
__field( int, oif )
62-
__array( __u8, src, 4 )
63-
),
64-
65-
TP_fast_assign(
66-
__be32 *p32 = (__be32 *) __entry->src;
6754

68-
__assign_str(name, nh->nh_dev ? nh->nh_dev->name : "not set");
69-
__entry->oif = nh->nh_oif;
70-
*p32 = nh->nh_saddr;
55+
__entry->proto = flp->flowi4_proto;
56+
if (__entry->proto == IPPROTO_TCP ||
57+
__entry->proto == IPPROTO_UDP) {
58+
__entry->sport = ntohs(flp->fl4_sport);
59+
__entry->dport = ntohs(flp->fl4_dport);
60+
} else {
61+
__entry->sport = 0;
62+
__entry->dport = 0;
63+
}
64+
65+
if (nh) {
66+
p32 = (__be32 *) __entry->saddr;
67+
*p32 = nh->nh_saddr;
68+
69+
p32 = (__be32 *) __entry->gw;
70+
*p32 = nh->nh_gw;
71+
72+
__assign_str(name, nh->nh_dev ? nh->nh_dev->name : "-");
73+
} else {
74+
p32 = (__be32 *) __entry->saddr;
75+
*p32 = 0;
76+
77+
p32 = (__be32 *) __entry->gw;
78+
*p32 = 0;
79+
80+
__assign_str(name, "-");
81+
}
7182
),
7283

73-
TP_printk("nexthop dev %s oif %d src %pI4",
74-
__get_str(name), __entry->oif, __entry->src)
84+
TP_printk("table %u oif %d iif %d proto %u %pI4/%u -> %pI4/%u tos %d scope %d flags %x ==> dev %s gw %pI4 src %pI4 err %d",
85+
__entry->tb_id, __entry->oif, __entry->iif, __entry->proto,
86+
__entry->src, __entry->sport, __entry->dst, __entry->dport,
87+
__entry->tos, __entry->scope, __entry->flags,
88+
__get_str(name), __entry->gw, __entry->saddr, __entry->err)
7589
);
7690

7791
TRACE_EVENT(fib_validate_source,

net/ipv4/fib_trie.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,14 +1326,14 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
13261326
unsigned long index;
13271327
t_key cindex;
13281328

1329-
trace_fib_table_lookup(tb->tb_id, flp);
1330-
13311329
pn = t->kv;
13321330
cindex = 0;
13331331

13341332
n = get_child_rcu(pn, cindex);
1335-
if (!n)
1333+
if (!n) {
1334+
trace_fib_table_lookup(tb->tb_id, flp, NULL, -EAGAIN);
13361335
return -EAGAIN;
1336+
}
13371337

13381338
#ifdef CONFIG_IP_FIB_TRIE_STATS
13391339
this_cpu_inc(stats->gets);
@@ -1416,8 +1416,11 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
14161416
* nothing for us to do as we do not have any
14171417
* further nodes to parse.
14181418
*/
1419-
if (IS_TRIE(pn))
1419+
if (IS_TRIE(pn)) {
1420+
trace_fib_table_lookup(tb->tb_id, flp,
1421+
NULL, -EAGAIN);
14201422
return -EAGAIN;
1423+
}
14211424
#ifdef CONFIG_IP_FIB_TRIE_STATS
14221425
this_cpu_inc(stats->backtrack);
14231426
#endif
@@ -1459,6 +1462,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
14591462
#ifdef CONFIG_IP_FIB_TRIE_STATS
14601463
this_cpu_inc(stats->semantic_match_passed);
14611464
#endif
1465+
trace_fib_table_lookup(tb->tb_id, flp, NULL, err);
14621466
return err;
14631467
}
14641468
if (fi->fib_flags & RTNH_F_DEAD)
@@ -1494,7 +1498,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
14941498
#ifdef CONFIG_IP_FIB_TRIE_STATS
14951499
this_cpu_inc(stats->semantic_match_passed);
14961500
#endif
1497-
trace_fib_table_lookup_nh(nh);
1501+
trace_fib_table_lookup(tb->tb_id, flp, nh, err);
14981502

14991503
return err;
15001504
}

0 commit comments

Comments
 (0)