Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <idosch@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Ido Schimmel and committed by
David S. Miller
edd3d007 cac1174f

+62
+1
MAINTAINERS
··· 11156 11156 W: https://fedorahosted.org/dropwatch/ 11157 11157 F: net/core/drop_monitor.c 11158 11158 F: include/uapi/linux/net_dropmon.h 11159 + F: include/net/drop_monitor.h 11159 11160 11160 11161 NETWORKING DRIVERS 11161 11162 M: "David S. Miller" <davem@davemloft.net>
+33
include/net/drop_monitor.h
··· 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_ */
+28
net/core/drop_monitor.c
··· 26 26 #include <linux/bitops.h> 27 27 #include <linux/slab.h> 28 28 #include <linux/module.h> 29 + #include <net/drop_monitor.h> 29 30 #include <net/genetlink.h> 30 31 #include <net/netevent.h> 31 32 ··· 44 43 * netlink alerts 45 44 */ 46 45 static int trace_state = TRACE_OFF; 46 + static bool monitor_hw; 47 47 48 48 /* net_dm_mutex 49 49 * ··· 95 93 void (*napi_poll_probe)(void *ignore, struct napi_struct *napi, 96 94 int work, int budget); 97 95 void (*work_item_func)(struct work_struct *work); 96 + void (*hw_probe)(struct sk_buff *skb, 97 + const struct net_dm_hw_metadata *hw_metadata); 98 98 }; 99 99 100 100 struct net_dm_skb_cb { ··· 271 267 rcu_read_unlock(); 272 268 } 273 269 270 + static void 271 + net_dm_hw_summary_probe(struct sk_buff *skb, 272 + const struct net_dm_hw_metadata *hw_metadata) 273 + { 274 + } 275 + 274 276 static const struct net_dm_alert_ops net_dm_alert_summary_ops = { 275 277 .kfree_skb_probe = trace_kfree_skb_hit, 276 278 .napi_poll_probe = trace_napi_poll_hit, 277 279 .work_item_func = send_dm_alert, 280 + .hw_probe = net_dm_hw_summary_probe, 278 281 }; 279 282 280 283 static void net_dm_packet_trace_kfree_skb_hit(void *ignore, ··· 493 482 net_dm_packet_report(skb); 494 483 } 495 484 485 + static void 486 + net_dm_hw_packet_probe(struct sk_buff *skb, 487 + const struct net_dm_hw_metadata *hw_metadata) 488 + { 489 + } 490 + 496 491 static const struct net_dm_alert_ops net_dm_alert_packet_ops = { 497 492 .kfree_skb_probe = net_dm_packet_trace_kfree_skb_hit, 498 493 .napi_poll_probe = net_dm_packet_trace_napi_poll_hit, 499 494 .work_item_func = net_dm_packet_work, 495 + .hw_probe = net_dm_hw_packet_probe, 500 496 }; 501 497 502 498 static const struct net_dm_alert_ops *net_dm_alert_ops_arr[] = { 503 499 [NET_DM_ALERT_MODE_SUMMARY] = &net_dm_alert_summary_ops, 504 500 [NET_DM_ALERT_MODE_PACKET] = &net_dm_alert_packet_ops, 505 501 }; 502 + 503 + void net_dm_hw_report(struct sk_buff *skb, 504 + const struct net_dm_hw_metadata *hw_metadata) 505 + { 506 + if (!monitor_hw) 507 + return; 508 + 509 + net_dm_alert_ops_arr[net_dm_alert_mode]->hw_probe(skb, hw_metadata); 510 + } 511 + EXPORT_SYMBOL_GPL(net_dm_hw_report); 506 512 507 513 static int net_dm_trace_on_set(struct netlink_ext_ack *extack) 508 514 {