Skip to content

Commit edd3d00

Browse files
idoschdavem330
authored andcommitted
drop_monitor: Add basic infrastructure for hardware drops
Export a function that can be invoked in order to report packets that were dropped by the underlying hardware along with metadata. Subsequent patches will add support for the different alert modes. Signed-off-by: Ido Schimmel <[email protected]> Acked-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cac1174 commit edd3d00

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11156,6 +11156,7 @@ S: Maintained
1115611156
W: https://fedorahosted.org/dropwatch/
1115711157
F: net/core/drop_monitor.c
1115811158
F: include/uapi/linux/net_dropmon.h
11159+
F: include/net/drop_monitor.h
1115911160

1116011161
NETWORKING DRIVERS
1116111162
M: "David S. Miller" <[email protected]>

include/net/drop_monitor.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
3+
#ifndef _NET_DROP_MONITOR_H_
4+
#define _NET_DROP_MONITOR_H_
5+
6+
#include <linux/ktime.h>
7+
#include <linux/netdevice.h>
8+
#include <linux/skbuff.h>
9+
10+
/**
11+
* struct net_dm_hw_metadata - Hardware-supplied packet metadata.
12+
* @trap_group_name: Hardware trap group name.
13+
* @trap_name: Hardware trap name.
14+
* @input_dev: Input netdevice.
15+
*/
16+
struct net_dm_hw_metadata {
17+
const char *trap_group_name;
18+
const char *trap_name;
19+
struct net_device *input_dev;
20+
};
21+
22+
#if IS_ENABLED(CONFIG_NET_DROP_MONITOR)
23+
void net_dm_hw_report(struct sk_buff *skb,
24+
const struct net_dm_hw_metadata *hw_metadata);
25+
#else
26+
static inline void
27+
net_dm_hw_report(struct sk_buff *skb,
28+
const struct net_dm_hw_metadata *hw_metadata)
29+
{
30+
}
31+
#endif
32+
33+
#endif /* _NET_DROP_MONITOR_H_ */

net/core/drop_monitor.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/bitops.h>
2727
#include <linux/slab.h>
2828
#include <linux/module.h>
29+
#include <net/drop_monitor.h>
2930
#include <net/genetlink.h>
3031
#include <net/netevent.h>
3132

@@ -43,6 +44,7 @@
4344
* netlink alerts
4445
*/
4546
static int trace_state = TRACE_OFF;
47+
static bool monitor_hw;
4648

4749
/* net_dm_mutex
4850
*
@@ -93,6 +95,8 @@ struct net_dm_alert_ops {
9395
void (*napi_poll_probe)(void *ignore, struct napi_struct *napi,
9496
int work, int budget);
9597
void (*work_item_func)(struct work_struct *work);
98+
void (*hw_probe)(struct sk_buff *skb,
99+
const struct net_dm_hw_metadata *hw_metadata);
96100
};
97101

98102
struct net_dm_skb_cb {
@@ -267,10 +271,17 @@ static void trace_napi_poll_hit(void *ignore, struct napi_struct *napi,
267271
rcu_read_unlock();
268272
}
269273

274+
static void
275+
net_dm_hw_summary_probe(struct sk_buff *skb,
276+
const struct net_dm_hw_metadata *hw_metadata)
277+
{
278+
}
279+
270280
static const struct net_dm_alert_ops net_dm_alert_summary_ops = {
271281
.kfree_skb_probe = trace_kfree_skb_hit,
272282
.napi_poll_probe = trace_napi_poll_hit,
273283
.work_item_func = send_dm_alert,
284+
.hw_probe = net_dm_hw_summary_probe,
274285
};
275286

276287
static void net_dm_packet_trace_kfree_skb_hit(void *ignore,
@@ -482,17 +493,34 @@ static void net_dm_packet_work(struct work_struct *work)
482493
net_dm_packet_report(skb);
483494
}
484495

496+
static void
497+
net_dm_hw_packet_probe(struct sk_buff *skb,
498+
const struct net_dm_hw_metadata *hw_metadata)
499+
{
500+
}
501+
485502
static const struct net_dm_alert_ops net_dm_alert_packet_ops = {
486503
.kfree_skb_probe = net_dm_packet_trace_kfree_skb_hit,
487504
.napi_poll_probe = net_dm_packet_trace_napi_poll_hit,
488505
.work_item_func = net_dm_packet_work,
506+
.hw_probe = net_dm_hw_packet_probe,
489507
};
490508

491509
static const struct net_dm_alert_ops *net_dm_alert_ops_arr[] = {
492510
[NET_DM_ALERT_MODE_SUMMARY] = &net_dm_alert_summary_ops,
493511
[NET_DM_ALERT_MODE_PACKET] = &net_dm_alert_packet_ops,
494512
};
495513

514+
void net_dm_hw_report(struct sk_buff *skb,
515+
const struct net_dm_hw_metadata *hw_metadata)
516+
{
517+
if (!monitor_hw)
518+
return;
519+
520+
net_dm_alert_ops_arr[net_dm_alert_mode]->hw_probe(skb, hw_metadata);
521+
}
522+
EXPORT_SYMBOL_GPL(net_dm_hw_report);
523+
496524
static int net_dm_trace_on_set(struct netlink_ext_ack *extack)
497525
{
498526
const struct net_dm_alert_ops *ops;

0 commit comments

Comments
 (0)