1 // SPDX-License-Identifier: GPL-2.0-only
3 * Monitoring code for network dropped packet alerts
5 * Copyright (C) 2009 Neil Horman <nhorman@tuxdriver.com>
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/netdevice.h>
11 #include <linux/etherdevice.h>
12 #include <linux/string.h>
13 #include <linux/if_arp.h>
14 #include <linux/inetdevice.h>
15 #include <linux/inet.h>
16 #include <linux/interrupt.h>
17 #include <linux/netpoll.h>
18 #include <linux/sched.h>
19 #include <linux/delay.h>
20 #include <linux/types.h>
21 #include <linux/workqueue.h>
22 #include <linux/netlink.h>
23 #include <linux/net_dropmon.h>
24 #include <linux/percpu.h>
25 #include <linux/timer.h>
26 #include <linux/bitops.h>
27 #include <linux/slab.h>
28 #include <linux/module.h>
29 #include <net/genetlink.h>
30 #include <net/netevent.h>
31 #include <net/flow_offload.h>
32 #include <net/devlink.h>
34 #include <trace/events/skb.h>
35 #include <trace/events/napi.h>
36 #include <trace/events/devlink.h>
38 #include <asm/unaligned.h>
44 * Globals, our netlink socket pointer
45 * and the work handle that will send up
48 static int trace_state = TRACE_OFF;
49 static bool monitor_hw;
53 * An overall lock guarding every operation coming from userspace.
54 * It also guards the global 'hw_stats_list' list.
56 static DEFINE_MUTEX(net_dm_mutex);
60 struct u64_stats_sync syncp;
63 #define NET_DM_MAX_HW_TRAP_NAME_LEN 40
65 struct net_dm_hw_entry {
66 char trap_name[NET_DM_MAX_HW_TRAP_NAME_LEN];
70 struct net_dm_hw_entries {
72 struct net_dm_hw_entry entries[];
75 struct per_cpu_dm_data {
76 spinlock_t lock; /* Protects 'skb', 'hw_entries' and
81 struct net_dm_hw_entries *hw_entries;
83 struct sk_buff_head drop_queue;
84 struct work_struct dm_alert_work;
85 struct timer_list send_timer;
86 struct net_dm_stats stats;
89 struct dm_hw_stat_delta {
90 struct net_device *dev;
91 unsigned long last_rx;
92 struct list_head list;
94 unsigned long last_drop_val;
97 static struct genl_family net_drop_monitor_family;
99 static DEFINE_PER_CPU(struct per_cpu_dm_data, dm_cpu_data);
100 static DEFINE_PER_CPU(struct per_cpu_dm_data, dm_hw_cpu_data);
102 static int dm_hit_limit = 64;
103 static int dm_delay = 1;
104 static unsigned long dm_hw_check_delta = 2*HZ;
105 static LIST_HEAD(hw_stats_list);
107 static enum net_dm_alert_mode net_dm_alert_mode = NET_DM_ALERT_MODE_SUMMARY;
108 static u32 net_dm_trunc_len;
109 static u32 net_dm_queue_len = 1000;
111 struct net_dm_alert_ops {
112 void (*kfree_skb_probe)(void *ignore, struct sk_buff *skb,
114 enum skb_drop_reason reason);
115 void (*napi_poll_probe)(void *ignore, struct napi_struct *napi,
116 int work, int budget);
117 void (*work_item_func)(struct work_struct *work);
118 void (*hw_work_item_func)(struct work_struct *work);
119 void (*hw_trap_probe)(void *ignore, const struct devlink *devlink,
121 const struct devlink_trap_metadata *metadata);
124 struct net_dm_skb_cb {
126 struct devlink_trap_metadata *hw_metadata;
131 #define NET_DM_SKB_CB(__skb) ((struct net_dm_skb_cb *)&((__skb)->cb[0]))
133 static struct sk_buff *reset_per_cpu_data(struct per_cpu_dm_data *data)
136 struct net_dm_alert_msg *msg;
142 al = sizeof(struct net_dm_alert_msg);
143 al += dm_hit_limit * sizeof(struct net_dm_drop_point);
144 al += sizeof(struct nlattr);
146 skb = genlmsg_new(al, GFP_KERNEL);
151 msg_header = genlmsg_put(skb, 0, 0, &net_drop_monitor_family,
152 0, NET_DM_CMD_ALERT);
158 nla = nla_reserve(skb, NLA_UNSPEC,
159 sizeof(struct net_dm_alert_msg));
170 mod_timer(&data->send_timer, jiffies + HZ / 10);
172 spin_lock_irqsave(&data->lock, flags);
173 swap(data->skb, skb);
174 spin_unlock_irqrestore(&data->lock, flags);
177 struct nlmsghdr *nlh = (struct nlmsghdr *)skb->data;
178 struct genlmsghdr *gnlh = (struct genlmsghdr *)nlmsg_data(nlh);
180 genlmsg_end(skb, genlmsg_data(gnlh));
186 static const struct genl_multicast_group dropmon_mcgrps[] = {
187 { .name = "events", },
190 static void send_dm_alert(struct work_struct *work)
193 struct per_cpu_dm_data *data;
195 data = container_of(work, struct per_cpu_dm_data, dm_alert_work);
197 skb = reset_per_cpu_data(data);
200 genlmsg_multicast(&net_drop_monitor_family, skb, 0,
205 * This is the timer function to delay the sending of an alert
206 * in the event that more drops will arrive during the
209 static void sched_send_work(struct timer_list *t)
211 struct per_cpu_dm_data *data = from_timer(data, t, send_timer);
213 schedule_work(&data->dm_alert_work);
216 static void trace_drop_common(struct sk_buff *skb, void *location)
218 struct net_dm_alert_msg *msg;
219 struct net_dm_drop_point *point;
220 struct nlmsghdr *nlh;
223 struct sk_buff *dskb;
224 struct per_cpu_dm_data *data;
227 local_irq_save(flags);
228 data = this_cpu_ptr(&dm_cpu_data);
229 spin_lock(&data->lock);
235 nlh = (struct nlmsghdr *)dskb->data;
236 nla = genlmsg_data(nlmsg_data(nlh));
239 for (i = 0; i < msg->entries; i++) {
240 if (!memcmp(&location, &point->pc, sizeof(void *))) {
246 if (msg->entries == dm_hit_limit)
249 * We need to create a new entry
251 __nla_reserve_nohdr(dskb, sizeof(struct net_dm_drop_point));
252 nla->nla_len += NLA_ALIGN(sizeof(struct net_dm_drop_point));
253 memcpy(point->pc, &location, sizeof(void *));
257 if (!timer_pending(&data->send_timer)) {
258 data->send_timer.expires = jiffies + dm_delay * HZ;
259 add_timer(&data->send_timer);
263 spin_unlock_irqrestore(&data->lock, flags);
266 static void trace_kfree_skb_hit(void *ignore, struct sk_buff *skb,
268 enum skb_drop_reason reason)
270 trace_drop_common(skb, location);
273 static void trace_napi_poll_hit(void *ignore, struct napi_struct *napi,
274 int work, int budget)
276 struct dm_hw_stat_delta *new_stat;
279 * Don't check napi structures with no associated device
285 list_for_each_entry_rcu(new_stat, &hw_stats_list, list) {
286 struct net_device *dev;
289 * only add a note to our monitor buffer if:
290 * 1) this is the dev we received on
291 * 2) its after the last_rx delta
292 * 3) our rx_dropped count has gone up
294 /* Paired with WRITE_ONCE() in dropmon_net_event() */
295 dev = READ_ONCE(new_stat->dev);
296 if ((dev == napi->dev) &&
297 (time_after(jiffies, new_stat->last_rx + dm_hw_check_delta)) &&
298 (napi->dev->stats.rx_dropped != new_stat->last_drop_val)) {
299 trace_drop_common(NULL, NULL);
300 new_stat->last_drop_val = napi->dev->stats.rx_dropped;
301 new_stat->last_rx = jiffies;
308 static struct net_dm_hw_entries *
309 net_dm_hw_reset_per_cpu_data(struct per_cpu_dm_data *hw_data)
311 struct net_dm_hw_entries *hw_entries;
314 hw_entries = kzalloc(struct_size(hw_entries, entries, dm_hit_limit),
317 /* If the memory allocation failed, we try to perform another
318 * allocation in 1/10 second. Otherwise, the probe function
319 * will constantly bail out.
321 mod_timer(&hw_data->send_timer, jiffies + HZ / 10);
324 spin_lock_irqsave(&hw_data->lock, flags);
325 swap(hw_data->hw_entries, hw_entries);
326 spin_unlock_irqrestore(&hw_data->lock, flags);
331 static int net_dm_hw_entry_put(struct sk_buff *msg,
332 const struct net_dm_hw_entry *hw_entry)
336 attr = nla_nest_start(msg, NET_DM_ATTR_HW_ENTRY);
340 if (nla_put_string(msg, NET_DM_ATTR_HW_TRAP_NAME, hw_entry->trap_name))
341 goto nla_put_failure;
343 if (nla_put_u32(msg, NET_DM_ATTR_HW_TRAP_COUNT, hw_entry->count))
344 goto nla_put_failure;
346 nla_nest_end(msg, attr);
351 nla_nest_cancel(msg, attr);
355 static int net_dm_hw_entries_put(struct sk_buff *msg,
356 const struct net_dm_hw_entries *hw_entries)
361 attr = nla_nest_start(msg, NET_DM_ATTR_HW_ENTRIES);
365 for (i = 0; i < hw_entries->num_entries; i++) {
368 rc = net_dm_hw_entry_put(msg, &hw_entries->entries[i]);
370 goto nla_put_failure;
373 nla_nest_end(msg, attr);
378 nla_nest_cancel(msg, attr);
383 net_dm_hw_summary_report_fill(struct sk_buff *msg,
384 const struct net_dm_hw_entries *hw_entries)
386 struct net_dm_alert_msg anc_hdr = { 0 };
390 hdr = genlmsg_put(msg, 0, 0, &net_drop_monitor_family, 0,
395 /* We need to put the ancillary header in order not to break user
398 if (nla_put(msg, NLA_UNSPEC, sizeof(anc_hdr), &anc_hdr))
399 goto nla_put_failure;
401 rc = net_dm_hw_entries_put(msg, hw_entries);
403 goto nla_put_failure;
405 genlmsg_end(msg, hdr);
410 genlmsg_cancel(msg, hdr);
414 static void net_dm_hw_summary_work(struct work_struct *work)
416 struct net_dm_hw_entries *hw_entries;
417 struct per_cpu_dm_data *hw_data;
421 hw_data = container_of(work, struct per_cpu_dm_data, dm_alert_work);
423 hw_entries = net_dm_hw_reset_per_cpu_data(hw_data);
427 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
431 rc = net_dm_hw_summary_report_fill(msg, hw_entries);
437 genlmsg_multicast(&net_drop_monitor_family, msg, 0, 0, GFP_KERNEL);
444 net_dm_hw_trap_summary_probe(void *ignore, const struct devlink *devlink,
446 const struct devlink_trap_metadata *metadata)
448 struct net_dm_hw_entries *hw_entries;
449 struct net_dm_hw_entry *hw_entry;
450 struct per_cpu_dm_data *hw_data;
454 if (metadata->trap_type == DEVLINK_TRAP_TYPE_CONTROL)
457 hw_data = this_cpu_ptr(&dm_hw_cpu_data);
458 spin_lock_irqsave(&hw_data->lock, flags);
459 hw_entries = hw_data->hw_entries;
464 for (i = 0; i < hw_entries->num_entries; i++) {
465 hw_entry = &hw_entries->entries[i];
466 if (!strncmp(hw_entry->trap_name, metadata->trap_name,
467 NET_DM_MAX_HW_TRAP_NAME_LEN - 1)) {
472 if (WARN_ON_ONCE(hw_entries->num_entries == dm_hit_limit))
475 hw_entry = &hw_entries->entries[hw_entries->num_entries];
476 strscpy(hw_entry->trap_name, metadata->trap_name,
477 NET_DM_MAX_HW_TRAP_NAME_LEN - 1);
479 hw_entries->num_entries++;
481 if (!timer_pending(&hw_data->send_timer)) {
482 hw_data->send_timer.expires = jiffies + dm_delay * HZ;
483 add_timer(&hw_data->send_timer);
487 spin_unlock_irqrestore(&hw_data->lock, flags);
490 static const struct net_dm_alert_ops net_dm_alert_summary_ops = {
491 .kfree_skb_probe = trace_kfree_skb_hit,
492 .napi_poll_probe = trace_napi_poll_hit,
493 .work_item_func = send_dm_alert,
494 .hw_work_item_func = net_dm_hw_summary_work,
495 .hw_trap_probe = net_dm_hw_trap_summary_probe,
498 static void net_dm_packet_trace_kfree_skb_hit(void *ignore,
501 enum skb_drop_reason reason)
503 ktime_t tstamp = ktime_get_real();
504 struct per_cpu_dm_data *data;
505 struct sk_buff *nskb;
508 if (!skb_mac_header_was_set(skb))
511 nskb = skb_clone(skb, GFP_ATOMIC);
515 NET_DM_SKB_CB(nskb)->pc = location;
516 /* Override the timestamp because we care about the time when the
517 * packet was dropped.
519 nskb->tstamp = tstamp;
521 data = this_cpu_ptr(&dm_cpu_data);
523 spin_lock_irqsave(&data->drop_queue.lock, flags);
524 if (skb_queue_len(&data->drop_queue) < net_dm_queue_len)
525 __skb_queue_tail(&data->drop_queue, nskb);
528 spin_unlock_irqrestore(&data->drop_queue.lock, flags);
530 schedule_work(&data->dm_alert_work);
535 spin_unlock_irqrestore(&data->drop_queue.lock, flags);
536 u64_stats_update_begin(&data->stats.syncp);
537 data->stats.dropped++;
538 u64_stats_update_end(&data->stats.syncp);
542 static void net_dm_packet_trace_napi_poll_hit(void *ignore,
543 struct napi_struct *napi,
544 int work, int budget)
548 static size_t net_dm_in_port_size(void)
550 /* NET_DM_ATTR_IN_PORT nest */
551 return nla_total_size(0) +
552 /* NET_DM_ATTR_PORT_NETDEV_IFINDEX */
553 nla_total_size(sizeof(u32)) +
554 /* NET_DM_ATTR_PORT_NETDEV_NAME */
555 nla_total_size(IFNAMSIZ + 1);
558 #define NET_DM_MAX_SYMBOL_LEN 40
560 static size_t net_dm_packet_report_size(size_t payload_len)
564 size = nlmsg_msg_size(GENL_HDRLEN + net_drop_monitor_family.hdrsize);
566 return NLMSG_ALIGN(size) +
567 /* NET_DM_ATTR_ORIGIN */
568 nla_total_size(sizeof(u16)) +
570 nla_total_size(sizeof(u64)) +
571 /* NET_DM_ATTR_SYMBOL */
572 nla_total_size(NET_DM_MAX_SYMBOL_LEN + 1) +
573 /* NET_DM_ATTR_IN_PORT */
574 net_dm_in_port_size() +
575 /* NET_DM_ATTR_TIMESTAMP */
576 nla_total_size(sizeof(u64)) +
577 /* NET_DM_ATTR_ORIG_LEN */
578 nla_total_size(sizeof(u32)) +
579 /* NET_DM_ATTR_PROTO */
580 nla_total_size(sizeof(u16)) +
581 /* NET_DM_ATTR_PAYLOAD */
582 nla_total_size(payload_len);
585 static int net_dm_packet_report_in_port_put(struct sk_buff *msg, int ifindex,
590 attr = nla_nest_start(msg, NET_DM_ATTR_IN_PORT);
595 nla_put_u32(msg, NET_DM_ATTR_PORT_NETDEV_IFINDEX, ifindex))
596 goto nla_put_failure;
598 if (name && nla_put_string(msg, NET_DM_ATTR_PORT_NETDEV_NAME, name))
599 goto nla_put_failure;
601 nla_nest_end(msg, attr);
606 nla_nest_cancel(msg, attr);
610 static int net_dm_packet_report_fill(struct sk_buff *msg, struct sk_buff *skb,
613 u64 pc = (u64)(uintptr_t) NET_DM_SKB_CB(skb)->pc;
614 char buf[NET_DM_MAX_SYMBOL_LEN];
619 hdr = genlmsg_put(msg, 0, 0, &net_drop_monitor_family, 0,
620 NET_DM_CMD_PACKET_ALERT);
624 if (nla_put_u16(msg, NET_DM_ATTR_ORIGIN, NET_DM_ORIGIN_SW))
625 goto nla_put_failure;
627 if (nla_put_u64_64bit(msg, NET_DM_ATTR_PC, pc, NET_DM_ATTR_PAD))
628 goto nla_put_failure;
630 snprintf(buf, sizeof(buf), "%pS", NET_DM_SKB_CB(skb)->pc);
631 if (nla_put_string(msg, NET_DM_ATTR_SYMBOL, buf))
632 goto nla_put_failure;
634 rc = net_dm_packet_report_in_port_put(msg, skb->skb_iif, NULL);
636 goto nla_put_failure;
638 if (nla_put_u64_64bit(msg, NET_DM_ATTR_TIMESTAMP,
639 ktime_to_ns(skb->tstamp), NET_DM_ATTR_PAD))
640 goto nla_put_failure;
642 if (nla_put_u32(msg, NET_DM_ATTR_ORIG_LEN, skb->len))
643 goto nla_put_failure;
648 if (nla_put_u16(msg, NET_DM_ATTR_PROTO, be16_to_cpu(skb->protocol)))
649 goto nla_put_failure;
651 attr = skb_put(msg, nla_total_size(payload_len));
652 attr->nla_type = NET_DM_ATTR_PAYLOAD;
653 attr->nla_len = nla_attr_size(payload_len);
654 if (skb_copy_bits(skb, 0, nla_data(attr), payload_len))
655 goto nla_put_failure;
658 genlmsg_end(msg, hdr);
663 genlmsg_cancel(msg, hdr);
667 #define NET_DM_MAX_PACKET_SIZE (0xffff - NLA_HDRLEN - NLA_ALIGNTO)
669 static void net_dm_packet_report(struct sk_buff *skb)
675 /* Make sure we start copying the packet from the MAC header */
676 if (skb->data > skb_mac_header(skb))
677 skb_push(skb, skb->data - skb_mac_header(skb));
679 skb_pull(skb, skb_mac_header(skb) - skb->data);
681 /* Ensure packet fits inside a single netlink attribute */
682 payload_len = min_t(size_t, skb->len, NET_DM_MAX_PACKET_SIZE);
683 if (net_dm_trunc_len)
684 payload_len = min_t(size_t, net_dm_trunc_len, payload_len);
686 msg = nlmsg_new(net_dm_packet_report_size(payload_len), GFP_KERNEL);
690 rc = net_dm_packet_report_fill(msg, skb, payload_len);
696 genlmsg_multicast(&net_drop_monitor_family, msg, 0, 0, GFP_KERNEL);
702 static void net_dm_packet_work(struct work_struct *work)
704 struct per_cpu_dm_data *data;
705 struct sk_buff_head list;
709 data = container_of(work, struct per_cpu_dm_data, dm_alert_work);
711 __skb_queue_head_init(&list);
713 spin_lock_irqsave(&data->drop_queue.lock, flags);
714 skb_queue_splice_tail_init(&data->drop_queue, &list);
715 spin_unlock_irqrestore(&data->drop_queue.lock, flags);
717 while ((skb = __skb_dequeue(&list)))
718 net_dm_packet_report(skb);
722 net_dm_flow_action_cookie_size(const struct devlink_trap_metadata *hw_metadata)
724 return hw_metadata->fa_cookie ?
725 nla_total_size(hw_metadata->fa_cookie->cookie_len) : 0;
729 net_dm_hw_packet_report_size(size_t payload_len,
730 const struct devlink_trap_metadata *hw_metadata)
734 size = nlmsg_msg_size(GENL_HDRLEN + net_drop_monitor_family.hdrsize);
736 return NLMSG_ALIGN(size) +
737 /* NET_DM_ATTR_ORIGIN */
738 nla_total_size(sizeof(u16)) +
739 /* NET_DM_ATTR_HW_TRAP_GROUP_NAME */
740 nla_total_size(strlen(hw_metadata->trap_group_name) + 1) +
741 /* NET_DM_ATTR_HW_TRAP_NAME */
742 nla_total_size(strlen(hw_metadata->trap_name) + 1) +
743 /* NET_DM_ATTR_IN_PORT */
744 net_dm_in_port_size() +
745 /* NET_DM_ATTR_FLOW_ACTION_COOKIE */
746 net_dm_flow_action_cookie_size(hw_metadata) +
747 /* NET_DM_ATTR_TIMESTAMP */
748 nla_total_size(sizeof(u64)) +
749 /* NET_DM_ATTR_ORIG_LEN */
750 nla_total_size(sizeof(u32)) +
751 /* NET_DM_ATTR_PROTO */
752 nla_total_size(sizeof(u16)) +
753 /* NET_DM_ATTR_PAYLOAD */
754 nla_total_size(payload_len);
757 static int net_dm_hw_packet_report_fill(struct sk_buff *msg,
758 struct sk_buff *skb, size_t payload_len)
760 struct devlink_trap_metadata *hw_metadata;
764 hw_metadata = NET_DM_SKB_CB(skb)->hw_metadata;
766 hdr = genlmsg_put(msg, 0, 0, &net_drop_monitor_family, 0,
767 NET_DM_CMD_PACKET_ALERT);
771 if (nla_put_u16(msg, NET_DM_ATTR_ORIGIN, NET_DM_ORIGIN_HW))
772 goto nla_put_failure;
774 if (nla_put_string(msg, NET_DM_ATTR_HW_TRAP_GROUP_NAME,
775 hw_metadata->trap_group_name))
776 goto nla_put_failure;
778 if (nla_put_string(msg, NET_DM_ATTR_HW_TRAP_NAME,
779 hw_metadata->trap_name))
780 goto nla_put_failure;
782 if (hw_metadata->input_dev) {
783 struct net_device *dev = hw_metadata->input_dev;
786 rc = net_dm_packet_report_in_port_put(msg, dev->ifindex,
789 goto nla_put_failure;
792 if (hw_metadata->fa_cookie &&
793 nla_put(msg, NET_DM_ATTR_FLOW_ACTION_COOKIE,
794 hw_metadata->fa_cookie->cookie_len,
795 hw_metadata->fa_cookie->cookie))
796 goto nla_put_failure;
798 if (nla_put_u64_64bit(msg, NET_DM_ATTR_TIMESTAMP,
799 ktime_to_ns(skb->tstamp), NET_DM_ATTR_PAD))
800 goto nla_put_failure;
802 if (nla_put_u32(msg, NET_DM_ATTR_ORIG_LEN, skb->len))
803 goto nla_put_failure;
808 if (nla_put_u16(msg, NET_DM_ATTR_PROTO, be16_to_cpu(skb->protocol)))
809 goto nla_put_failure;
811 attr = skb_put(msg, nla_total_size(payload_len));
812 attr->nla_type = NET_DM_ATTR_PAYLOAD;
813 attr->nla_len = nla_attr_size(payload_len);
814 if (skb_copy_bits(skb, 0, nla_data(attr), payload_len))
815 goto nla_put_failure;
818 genlmsg_end(msg, hdr);
823 genlmsg_cancel(msg, hdr);
827 static struct devlink_trap_metadata *
828 net_dm_hw_metadata_copy(const struct devlink_trap_metadata *metadata)
830 const struct flow_action_cookie *fa_cookie;
831 struct devlink_trap_metadata *hw_metadata;
832 const char *trap_group_name;
833 const char *trap_name;
835 hw_metadata = kzalloc(sizeof(*hw_metadata), GFP_ATOMIC);
839 trap_group_name = kstrdup(metadata->trap_group_name, GFP_ATOMIC);
840 if (!trap_group_name)
841 goto free_hw_metadata;
842 hw_metadata->trap_group_name = trap_group_name;
844 trap_name = kstrdup(metadata->trap_name, GFP_ATOMIC);
846 goto free_trap_group;
847 hw_metadata->trap_name = trap_name;
849 if (metadata->fa_cookie) {
850 size_t cookie_size = sizeof(*fa_cookie) +
851 metadata->fa_cookie->cookie_len;
853 fa_cookie = kmemdup(metadata->fa_cookie, cookie_size,
857 hw_metadata->fa_cookie = fa_cookie;
860 hw_metadata->input_dev = metadata->input_dev;
861 dev_hold(hw_metadata->input_dev);
868 kfree(trap_group_name);
875 net_dm_hw_metadata_free(const struct devlink_trap_metadata *hw_metadata)
877 dev_put(hw_metadata->input_dev);
878 kfree(hw_metadata->fa_cookie);
879 kfree(hw_metadata->trap_name);
880 kfree(hw_metadata->trap_group_name);
884 static void net_dm_hw_packet_report(struct sk_buff *skb)
886 struct devlink_trap_metadata *hw_metadata;
891 if (skb->data > skb_mac_header(skb))
892 skb_push(skb, skb->data - skb_mac_header(skb));
894 skb_pull(skb, skb_mac_header(skb) - skb->data);
896 payload_len = min_t(size_t, skb->len, NET_DM_MAX_PACKET_SIZE);
897 if (net_dm_trunc_len)
898 payload_len = min_t(size_t, net_dm_trunc_len, payload_len);
900 hw_metadata = NET_DM_SKB_CB(skb)->hw_metadata;
901 msg = nlmsg_new(net_dm_hw_packet_report_size(payload_len, hw_metadata),
906 rc = net_dm_hw_packet_report_fill(msg, skb, payload_len);
912 genlmsg_multicast(&net_drop_monitor_family, msg, 0, 0, GFP_KERNEL);
915 net_dm_hw_metadata_free(NET_DM_SKB_CB(skb)->hw_metadata);
919 static void net_dm_hw_packet_work(struct work_struct *work)
921 struct per_cpu_dm_data *hw_data;
922 struct sk_buff_head list;
926 hw_data = container_of(work, struct per_cpu_dm_data, dm_alert_work);
928 __skb_queue_head_init(&list);
930 spin_lock_irqsave(&hw_data->drop_queue.lock, flags);
931 skb_queue_splice_tail_init(&hw_data->drop_queue, &list);
932 spin_unlock_irqrestore(&hw_data->drop_queue.lock, flags);
934 while ((skb = __skb_dequeue(&list)))
935 net_dm_hw_packet_report(skb);
939 net_dm_hw_trap_packet_probe(void *ignore, const struct devlink *devlink,
941 const struct devlink_trap_metadata *metadata)
943 struct devlink_trap_metadata *n_hw_metadata;
944 ktime_t tstamp = ktime_get_real();
945 struct per_cpu_dm_data *hw_data;
946 struct sk_buff *nskb;
949 if (metadata->trap_type == DEVLINK_TRAP_TYPE_CONTROL)
952 if (!skb_mac_header_was_set(skb))
955 nskb = skb_clone(skb, GFP_ATOMIC);
959 n_hw_metadata = net_dm_hw_metadata_copy(metadata);
963 NET_DM_SKB_CB(nskb)->hw_metadata = n_hw_metadata;
964 nskb->tstamp = tstamp;
966 hw_data = this_cpu_ptr(&dm_hw_cpu_data);
968 spin_lock_irqsave(&hw_data->drop_queue.lock, flags);
969 if (skb_queue_len(&hw_data->drop_queue) < net_dm_queue_len)
970 __skb_queue_tail(&hw_data->drop_queue, nskb);
973 spin_unlock_irqrestore(&hw_data->drop_queue.lock, flags);
975 schedule_work(&hw_data->dm_alert_work);
980 spin_unlock_irqrestore(&hw_data->drop_queue.lock, flags);
981 u64_stats_update_begin(&hw_data->stats.syncp);
982 hw_data->stats.dropped++;
983 u64_stats_update_end(&hw_data->stats.syncp);
984 net_dm_hw_metadata_free(n_hw_metadata);
989 static const struct net_dm_alert_ops net_dm_alert_packet_ops = {
990 .kfree_skb_probe = net_dm_packet_trace_kfree_skb_hit,
991 .napi_poll_probe = net_dm_packet_trace_napi_poll_hit,
992 .work_item_func = net_dm_packet_work,
993 .hw_work_item_func = net_dm_hw_packet_work,
994 .hw_trap_probe = net_dm_hw_trap_packet_probe,
997 static const struct net_dm_alert_ops *net_dm_alert_ops_arr[] = {
998 [NET_DM_ALERT_MODE_SUMMARY] = &net_dm_alert_summary_ops,
999 [NET_DM_ALERT_MODE_PACKET] = &net_dm_alert_packet_ops,
1002 #if IS_ENABLED(CONFIG_NET_DEVLINK)
1003 static int net_dm_hw_probe_register(const struct net_dm_alert_ops *ops)
1005 return register_trace_devlink_trap_report(ops->hw_trap_probe, NULL);
1008 static void net_dm_hw_probe_unregister(const struct net_dm_alert_ops *ops)
1010 unregister_trace_devlink_trap_report(ops->hw_trap_probe, NULL);
1011 tracepoint_synchronize_unregister();
1014 static int net_dm_hw_probe_register(const struct net_dm_alert_ops *ops)
1019 static void net_dm_hw_probe_unregister(const struct net_dm_alert_ops *ops)
1024 static int net_dm_hw_monitor_start(struct netlink_ext_ack *extack)
1026 const struct net_dm_alert_ops *ops;
1030 NL_SET_ERR_MSG_MOD(extack, "Hardware monitoring already enabled");
1034 ops = net_dm_alert_ops_arr[net_dm_alert_mode];
1036 if (!try_module_get(THIS_MODULE)) {
1037 NL_SET_ERR_MSG_MOD(extack, "Failed to take reference on module");
1041 for_each_possible_cpu(cpu) {
1042 struct per_cpu_dm_data *hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1043 struct net_dm_hw_entries *hw_entries;
1045 INIT_WORK(&hw_data->dm_alert_work, ops->hw_work_item_func);
1046 timer_setup(&hw_data->send_timer, sched_send_work, 0);
1047 hw_entries = net_dm_hw_reset_per_cpu_data(hw_data);
1051 rc = net_dm_hw_probe_register(ops);
1053 NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to devlink_trap_probe() tracepoint");
1054 goto err_module_put;
1062 for_each_possible_cpu(cpu) {
1063 struct per_cpu_dm_data *hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1064 struct sk_buff *skb;
1066 del_timer_sync(&hw_data->send_timer);
1067 cancel_work_sync(&hw_data->dm_alert_work);
1068 while ((skb = __skb_dequeue(&hw_data->drop_queue))) {
1069 struct devlink_trap_metadata *hw_metadata;
1071 hw_metadata = NET_DM_SKB_CB(skb)->hw_metadata;
1072 net_dm_hw_metadata_free(hw_metadata);
1076 module_put(THIS_MODULE);
1080 static void net_dm_hw_monitor_stop(struct netlink_ext_ack *extack)
1082 const struct net_dm_alert_ops *ops;
1086 NL_SET_ERR_MSG_MOD(extack, "Hardware monitoring already disabled");
1090 ops = net_dm_alert_ops_arr[net_dm_alert_mode];
1094 net_dm_hw_probe_unregister(ops);
1096 for_each_possible_cpu(cpu) {
1097 struct per_cpu_dm_data *hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1098 struct sk_buff *skb;
1100 del_timer_sync(&hw_data->send_timer);
1101 cancel_work_sync(&hw_data->dm_alert_work);
1102 while ((skb = __skb_dequeue(&hw_data->drop_queue))) {
1103 struct devlink_trap_metadata *hw_metadata;
1105 hw_metadata = NET_DM_SKB_CB(skb)->hw_metadata;
1106 net_dm_hw_metadata_free(hw_metadata);
1111 module_put(THIS_MODULE);
1114 static int net_dm_trace_on_set(struct netlink_ext_ack *extack)
1116 const struct net_dm_alert_ops *ops;
1119 ops = net_dm_alert_ops_arr[net_dm_alert_mode];
1121 if (!try_module_get(THIS_MODULE)) {
1122 NL_SET_ERR_MSG_MOD(extack, "Failed to take reference on module");
1126 for_each_possible_cpu(cpu) {
1127 struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);
1128 struct sk_buff *skb;
1130 INIT_WORK(&data->dm_alert_work, ops->work_item_func);
1131 timer_setup(&data->send_timer, sched_send_work, 0);
1132 /* Allocate a new per-CPU skb for the summary alert message and
1133 * free the old one which might contain stale data from
1136 skb = reset_per_cpu_data(data);
1140 rc = register_trace_kfree_skb(ops->kfree_skb_probe, NULL);
1142 NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to kfree_skb() tracepoint");
1143 goto err_module_put;
1146 rc = register_trace_napi_poll(ops->napi_poll_probe, NULL);
1148 NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to napi_poll() tracepoint");
1149 goto err_unregister_trace;
1154 err_unregister_trace:
1155 unregister_trace_kfree_skb(ops->kfree_skb_probe, NULL);
1157 for_each_possible_cpu(cpu) {
1158 struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);
1159 struct sk_buff *skb;
1161 del_timer_sync(&data->send_timer);
1162 cancel_work_sync(&data->dm_alert_work);
1163 while ((skb = __skb_dequeue(&data->drop_queue)))
1166 module_put(THIS_MODULE);
1170 static void net_dm_trace_off_set(void)
1172 struct dm_hw_stat_delta *new_stat, *temp;
1173 const struct net_dm_alert_ops *ops;
1176 ops = net_dm_alert_ops_arr[net_dm_alert_mode];
1178 unregister_trace_napi_poll(ops->napi_poll_probe, NULL);
1179 unregister_trace_kfree_skb(ops->kfree_skb_probe, NULL);
1181 tracepoint_synchronize_unregister();
1183 /* Make sure we do not send notifications to user space after request
1184 * to stop tracing returns.
1186 for_each_possible_cpu(cpu) {
1187 struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);
1188 struct sk_buff *skb;
1190 del_timer_sync(&data->send_timer);
1191 cancel_work_sync(&data->dm_alert_work);
1192 while ((skb = __skb_dequeue(&data->drop_queue)))
1196 list_for_each_entry_safe(new_stat, temp, &hw_stats_list, list) {
1197 if (new_stat->dev == NULL) {
1198 list_del_rcu(&new_stat->list);
1199 kfree_rcu(new_stat, rcu);
1203 module_put(THIS_MODULE);
1206 static int set_all_monitor_traces(int state, struct netlink_ext_ack *extack)
1210 if (state == trace_state) {
1211 NL_SET_ERR_MSG_MOD(extack, "Trace state already set to requested state");
1217 rc = net_dm_trace_on_set(extack);
1220 net_dm_trace_off_set();
1228 trace_state = state;
1235 static bool net_dm_is_monitoring(void)
1237 return trace_state == TRACE_ON || monitor_hw;
1240 static int net_dm_alert_mode_get_from_info(struct genl_info *info,
1241 enum net_dm_alert_mode *p_alert_mode)
1245 val = nla_get_u8(info->attrs[NET_DM_ATTR_ALERT_MODE]);
1248 case NET_DM_ALERT_MODE_SUMMARY:
1249 case NET_DM_ALERT_MODE_PACKET:
1250 *p_alert_mode = val;
1259 static int net_dm_alert_mode_set(struct genl_info *info)
1261 struct netlink_ext_ack *extack = info->extack;
1262 enum net_dm_alert_mode alert_mode;
1265 if (!info->attrs[NET_DM_ATTR_ALERT_MODE])
1268 rc = net_dm_alert_mode_get_from_info(info, &alert_mode);
1270 NL_SET_ERR_MSG_MOD(extack, "Invalid alert mode");
1274 net_dm_alert_mode = alert_mode;
1279 static void net_dm_trunc_len_set(struct genl_info *info)
1281 if (!info->attrs[NET_DM_ATTR_TRUNC_LEN])
1284 net_dm_trunc_len = nla_get_u32(info->attrs[NET_DM_ATTR_TRUNC_LEN]);
1287 static void net_dm_queue_len_set(struct genl_info *info)
1289 if (!info->attrs[NET_DM_ATTR_QUEUE_LEN])
1292 net_dm_queue_len = nla_get_u32(info->attrs[NET_DM_ATTR_QUEUE_LEN]);
1295 static int net_dm_cmd_config(struct sk_buff *skb,
1296 struct genl_info *info)
1298 struct netlink_ext_ack *extack = info->extack;
1301 if (net_dm_is_monitoring()) {
1302 NL_SET_ERR_MSG_MOD(extack, "Cannot configure drop monitor during monitoring");
1306 rc = net_dm_alert_mode_set(info);
1310 net_dm_trunc_len_set(info);
1312 net_dm_queue_len_set(info);
1317 static int net_dm_monitor_start(bool set_sw, bool set_hw,
1318 struct netlink_ext_ack *extack)
1320 bool sw_set = false;
1324 rc = set_all_monitor_traces(TRACE_ON, extack);
1331 rc = net_dm_hw_monitor_start(extack);
1333 goto err_monitor_hw;
1340 set_all_monitor_traces(TRACE_OFF, extack);
1344 static void net_dm_monitor_stop(bool set_sw, bool set_hw,
1345 struct netlink_ext_ack *extack)
1348 net_dm_hw_monitor_stop(extack);
1350 set_all_monitor_traces(TRACE_OFF, extack);
1353 static int net_dm_cmd_trace(struct sk_buff *skb,
1354 struct genl_info *info)
1356 bool set_sw = !!info->attrs[NET_DM_ATTR_SW_DROPS];
1357 bool set_hw = !!info->attrs[NET_DM_ATTR_HW_DROPS];
1358 struct netlink_ext_ack *extack = info->extack;
1360 /* To maintain backward compatibility, we start / stop monitoring of
1361 * software drops if no flag is specified.
1363 if (!set_sw && !set_hw)
1366 switch (info->genlhdr->cmd) {
1367 case NET_DM_CMD_START:
1368 return net_dm_monitor_start(set_sw, set_hw, extack);
1369 case NET_DM_CMD_STOP:
1370 net_dm_monitor_stop(set_sw, set_hw, extack);
1377 static int net_dm_config_fill(struct sk_buff *msg, struct genl_info *info)
1381 hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq,
1382 &net_drop_monitor_family, 0, NET_DM_CMD_CONFIG_NEW);
1386 if (nla_put_u8(msg, NET_DM_ATTR_ALERT_MODE, net_dm_alert_mode))
1387 goto nla_put_failure;
1389 if (nla_put_u32(msg, NET_DM_ATTR_TRUNC_LEN, net_dm_trunc_len))
1390 goto nla_put_failure;
1392 if (nla_put_u32(msg, NET_DM_ATTR_QUEUE_LEN, net_dm_queue_len))
1393 goto nla_put_failure;
1395 genlmsg_end(msg, hdr);
1400 genlmsg_cancel(msg, hdr);
1404 static int net_dm_cmd_config_get(struct sk_buff *skb, struct genl_info *info)
1406 struct sk_buff *msg;
1409 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1413 rc = net_dm_config_fill(msg, info);
1417 return genlmsg_reply(msg, info);
1424 static void net_dm_stats_read(struct net_dm_stats *stats)
1428 memset(stats, 0, sizeof(*stats));
1429 for_each_possible_cpu(cpu) {
1430 struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);
1431 struct net_dm_stats *cpu_stats = &data->stats;
1436 start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
1437 dropped = cpu_stats->dropped;
1438 } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
1440 stats->dropped += dropped;
1444 static int net_dm_stats_put(struct sk_buff *msg)
1446 struct net_dm_stats stats;
1447 struct nlattr *attr;
1449 net_dm_stats_read(&stats);
1451 attr = nla_nest_start(msg, NET_DM_ATTR_STATS);
1455 if (nla_put_u64_64bit(msg, NET_DM_ATTR_STATS_DROPPED,
1456 stats.dropped, NET_DM_ATTR_PAD))
1457 goto nla_put_failure;
1459 nla_nest_end(msg, attr);
1464 nla_nest_cancel(msg, attr);
1468 static void net_dm_hw_stats_read(struct net_dm_stats *stats)
1472 memset(stats, 0, sizeof(*stats));
1473 for_each_possible_cpu(cpu) {
1474 struct per_cpu_dm_data *hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1475 struct net_dm_stats *cpu_stats = &hw_data->stats;
1480 start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
1481 dropped = cpu_stats->dropped;
1482 } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
1484 stats->dropped += dropped;
1488 static int net_dm_hw_stats_put(struct sk_buff *msg)
1490 struct net_dm_stats stats;
1491 struct nlattr *attr;
1493 net_dm_hw_stats_read(&stats);
1495 attr = nla_nest_start(msg, NET_DM_ATTR_HW_STATS);
1499 if (nla_put_u64_64bit(msg, NET_DM_ATTR_STATS_DROPPED,
1500 stats.dropped, NET_DM_ATTR_PAD))
1501 goto nla_put_failure;
1503 nla_nest_end(msg, attr);
1508 nla_nest_cancel(msg, attr);
1512 static int net_dm_stats_fill(struct sk_buff *msg, struct genl_info *info)
1517 hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq,
1518 &net_drop_monitor_family, 0, NET_DM_CMD_STATS_NEW);
1522 rc = net_dm_stats_put(msg);
1524 goto nla_put_failure;
1526 rc = net_dm_hw_stats_put(msg);
1528 goto nla_put_failure;
1530 genlmsg_end(msg, hdr);
1535 genlmsg_cancel(msg, hdr);
1539 static int net_dm_cmd_stats_get(struct sk_buff *skb, struct genl_info *info)
1541 struct sk_buff *msg;
1544 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1548 rc = net_dm_stats_fill(msg, info);
1552 return genlmsg_reply(msg, info);
1559 static int dropmon_net_event(struct notifier_block *ev_block,
1560 unsigned long event, void *ptr)
1562 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
1563 struct dm_hw_stat_delta *new_stat = NULL;
1564 struct dm_hw_stat_delta *tmp;
1567 case NETDEV_REGISTER:
1568 new_stat = kzalloc(sizeof(struct dm_hw_stat_delta), GFP_KERNEL);
1573 new_stat->dev = dev;
1574 new_stat->last_rx = jiffies;
1575 mutex_lock(&net_dm_mutex);
1576 list_add_rcu(&new_stat->list, &hw_stats_list);
1577 mutex_unlock(&net_dm_mutex);
1579 case NETDEV_UNREGISTER:
1580 mutex_lock(&net_dm_mutex);
1581 list_for_each_entry_safe(new_stat, tmp, &hw_stats_list, list) {
1582 if (new_stat->dev == dev) {
1584 /* Paired with READ_ONCE() in trace_napi_poll_hit() */
1585 WRITE_ONCE(new_stat->dev, NULL);
1587 if (trace_state == TRACE_OFF) {
1588 list_del_rcu(&new_stat->list);
1589 kfree_rcu(new_stat, rcu);
1594 mutex_unlock(&net_dm_mutex);
1601 static const struct nla_policy net_dm_nl_policy[NET_DM_ATTR_MAX + 1] = {
1602 [NET_DM_ATTR_UNSPEC] = { .strict_start_type = NET_DM_ATTR_UNSPEC + 1 },
1603 [NET_DM_ATTR_ALERT_MODE] = { .type = NLA_U8 },
1604 [NET_DM_ATTR_TRUNC_LEN] = { .type = NLA_U32 },
1605 [NET_DM_ATTR_QUEUE_LEN] = { .type = NLA_U32 },
1606 [NET_DM_ATTR_SW_DROPS] = {. type = NLA_FLAG },
1607 [NET_DM_ATTR_HW_DROPS] = {. type = NLA_FLAG },
1610 static const struct genl_small_ops dropmon_ops[] = {
1612 .cmd = NET_DM_CMD_CONFIG,
1613 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1614 .doit = net_dm_cmd_config,
1615 .flags = GENL_ADMIN_PERM,
1618 .cmd = NET_DM_CMD_START,
1619 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1620 .doit = net_dm_cmd_trace,
1623 .cmd = NET_DM_CMD_STOP,
1624 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1625 .doit = net_dm_cmd_trace,
1628 .cmd = NET_DM_CMD_CONFIG_GET,
1629 .doit = net_dm_cmd_config_get,
1632 .cmd = NET_DM_CMD_STATS_GET,
1633 .doit = net_dm_cmd_stats_get,
1637 static int net_dm_nl_pre_doit(const struct genl_ops *ops,
1638 struct sk_buff *skb, struct genl_info *info)
1640 mutex_lock(&net_dm_mutex);
1645 static void net_dm_nl_post_doit(const struct genl_ops *ops,
1646 struct sk_buff *skb, struct genl_info *info)
1648 mutex_unlock(&net_dm_mutex);
1651 static struct genl_family net_drop_monitor_family __ro_after_init = {
1655 .maxattr = NET_DM_ATTR_MAX,
1656 .policy = net_dm_nl_policy,
1657 .pre_doit = net_dm_nl_pre_doit,
1658 .post_doit = net_dm_nl_post_doit,
1659 .module = THIS_MODULE,
1660 .small_ops = dropmon_ops,
1661 .n_small_ops = ARRAY_SIZE(dropmon_ops),
1662 .mcgrps = dropmon_mcgrps,
1663 .n_mcgrps = ARRAY_SIZE(dropmon_mcgrps),
1666 static struct notifier_block dropmon_net_notifier = {
1667 .notifier_call = dropmon_net_event
1670 static void __net_dm_cpu_data_init(struct per_cpu_dm_data *data)
1672 spin_lock_init(&data->lock);
1673 skb_queue_head_init(&data->drop_queue);
1674 u64_stats_init(&data->stats.syncp);
1677 static void __net_dm_cpu_data_fini(struct per_cpu_dm_data *data)
1679 WARN_ON(!skb_queue_empty(&data->drop_queue));
1682 static void net_dm_cpu_data_init(int cpu)
1684 struct per_cpu_dm_data *data;
1686 data = &per_cpu(dm_cpu_data, cpu);
1687 __net_dm_cpu_data_init(data);
1690 static void net_dm_cpu_data_fini(int cpu)
1692 struct per_cpu_dm_data *data;
1694 data = &per_cpu(dm_cpu_data, cpu);
1695 /* At this point, we should have exclusive access
1696 * to this struct and can free the skb inside it.
1698 consume_skb(data->skb);
1699 __net_dm_cpu_data_fini(data);
1702 static void net_dm_hw_cpu_data_init(int cpu)
1704 struct per_cpu_dm_data *hw_data;
1706 hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1707 __net_dm_cpu_data_init(hw_data);
1710 static void net_dm_hw_cpu_data_fini(int cpu)
1712 struct per_cpu_dm_data *hw_data;
1714 hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1715 kfree(hw_data->hw_entries);
1716 __net_dm_cpu_data_fini(hw_data);
1719 static int __init init_net_drop_monitor(void)
1723 pr_info("Initializing network drop monitor service\n");
1725 if (sizeof(void *) > 8) {
1726 pr_err("Unable to store program counters on this arch, Drop monitor failed\n");
1730 rc = genl_register_family(&net_drop_monitor_family);
1732 pr_err("Could not create drop monitor netlink family\n");
1735 WARN_ON(net_drop_monitor_family.mcgrp_offset != NET_DM_GRP_ALERT);
1737 rc = register_netdevice_notifier(&dropmon_net_notifier);
1739 pr_crit("Failed to register netdevice notifier\n");
1745 for_each_possible_cpu(cpu) {
1746 net_dm_cpu_data_init(cpu);
1747 net_dm_hw_cpu_data_init(cpu);
1753 genl_unregister_family(&net_drop_monitor_family);
1758 static void exit_net_drop_monitor(void)
1762 BUG_ON(unregister_netdevice_notifier(&dropmon_net_notifier));
1765 * Because of the module_get/put we do in the trace state change path
1766 * we are guaranteed not to have any current users when we get here
1769 for_each_possible_cpu(cpu) {
1770 net_dm_hw_cpu_data_fini(cpu);
1771 net_dm_cpu_data_fini(cpu);
1774 BUG_ON(genl_unregister_family(&net_drop_monitor_family));
1777 module_init(init_net_drop_monitor);
1778 module_exit(exit_net_drop_monitor);
1780 MODULE_LICENSE("GPL v2");
1781 MODULE_AUTHOR("Neil Horman <nhorman@tuxdriver.com>");
1782 MODULE_ALIAS_GENL_FAMILY("NET_DM");
1783 MODULE_DESCRIPTION("Monitoring code for network dropped packet alerts");