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.
55 static DEFINE_MUTEX(net_dm_mutex);
59 struct u64_stats_sync syncp;
62 #define NET_DM_MAX_HW_TRAP_NAME_LEN 40
64 struct net_dm_hw_entry {
65 char trap_name[NET_DM_MAX_HW_TRAP_NAME_LEN];
69 struct net_dm_hw_entries {
71 struct net_dm_hw_entry entries[];
74 struct per_cpu_dm_data {
75 spinlock_t lock; /* Protects 'skb', 'hw_entries' and
80 struct net_dm_hw_entries *hw_entries;
82 struct sk_buff_head drop_queue;
83 struct work_struct dm_alert_work;
84 struct timer_list send_timer;
85 struct net_dm_stats stats;
88 struct dm_hw_stat_delta {
89 unsigned long last_rx;
90 unsigned long last_drop_val;
94 static struct genl_family net_drop_monitor_family;
96 static DEFINE_PER_CPU(struct per_cpu_dm_data, dm_cpu_data);
97 static DEFINE_PER_CPU(struct per_cpu_dm_data, dm_hw_cpu_data);
99 static int dm_hit_limit = 64;
100 static int dm_delay = 1;
101 static unsigned long dm_hw_check_delta = 2*HZ;
103 static enum net_dm_alert_mode net_dm_alert_mode = NET_DM_ALERT_MODE_SUMMARY;
104 static u32 net_dm_trunc_len;
105 static u32 net_dm_queue_len = 1000;
107 struct net_dm_alert_ops {
108 void (*kfree_skb_probe)(void *ignore, struct sk_buff *skb,
110 enum skb_drop_reason reason);
111 void (*napi_poll_probe)(void *ignore, struct napi_struct *napi,
112 int work, int budget);
113 void (*work_item_func)(struct work_struct *work);
114 void (*hw_work_item_func)(struct work_struct *work);
115 void (*hw_trap_probe)(void *ignore, const struct devlink *devlink,
117 const struct devlink_trap_metadata *metadata);
120 struct net_dm_skb_cb {
122 struct devlink_trap_metadata *hw_metadata;
125 enum skb_drop_reason reason;
128 #define NET_DM_SKB_CB(__skb) ((struct net_dm_skb_cb *)&((__skb)->cb[0]))
130 static struct sk_buff *reset_per_cpu_data(struct per_cpu_dm_data *data)
133 struct net_dm_alert_msg *msg;
139 al = sizeof(struct net_dm_alert_msg);
140 al += dm_hit_limit * sizeof(struct net_dm_drop_point);
141 al += sizeof(struct nlattr);
143 skb = genlmsg_new(al, GFP_KERNEL);
148 msg_header = genlmsg_put(skb, 0, 0, &net_drop_monitor_family,
149 0, NET_DM_CMD_ALERT);
155 nla = nla_reserve(skb, NLA_UNSPEC,
156 sizeof(struct net_dm_alert_msg));
167 mod_timer(&data->send_timer, jiffies + HZ / 10);
169 spin_lock_irqsave(&data->lock, flags);
170 swap(data->skb, skb);
171 spin_unlock_irqrestore(&data->lock, flags);
174 struct nlmsghdr *nlh = (struct nlmsghdr *)skb->data;
175 struct genlmsghdr *gnlh = (struct genlmsghdr *)nlmsg_data(nlh);
177 genlmsg_end(skb, genlmsg_data(gnlh));
183 static const struct genl_multicast_group dropmon_mcgrps[] = {
184 { .name = "events", },
187 static void send_dm_alert(struct work_struct *work)
190 struct per_cpu_dm_data *data;
192 data = container_of(work, struct per_cpu_dm_data, dm_alert_work);
194 skb = reset_per_cpu_data(data);
197 genlmsg_multicast(&net_drop_monitor_family, skb, 0,
202 * This is the timer function to delay the sending of an alert
203 * in the event that more drops will arrive during the
206 static void sched_send_work(struct timer_list *t)
208 struct per_cpu_dm_data *data = from_timer(data, t, send_timer);
210 schedule_work(&data->dm_alert_work);
213 static void trace_drop_common(struct sk_buff *skb, void *location)
215 struct net_dm_alert_msg *msg;
216 struct net_dm_drop_point *point;
217 struct nlmsghdr *nlh;
220 struct sk_buff *dskb;
221 struct per_cpu_dm_data *data;
224 local_irq_save(flags);
225 data = this_cpu_ptr(&dm_cpu_data);
226 spin_lock(&data->lock);
232 nlh = (struct nlmsghdr *)dskb->data;
233 nla = genlmsg_data(nlmsg_data(nlh));
236 for (i = 0; i < msg->entries; i++) {
237 if (!memcmp(&location, &point->pc, sizeof(void *))) {
243 if (msg->entries == dm_hit_limit)
246 * We need to create a new entry
248 __nla_reserve_nohdr(dskb, sizeof(struct net_dm_drop_point));
249 nla->nla_len += NLA_ALIGN(sizeof(struct net_dm_drop_point));
250 memcpy(point->pc, &location, sizeof(void *));
254 if (!timer_pending(&data->send_timer)) {
255 data->send_timer.expires = jiffies + dm_delay * HZ;
256 add_timer(&data->send_timer);
260 spin_unlock_irqrestore(&data->lock, flags);
263 static void trace_kfree_skb_hit(void *ignore, struct sk_buff *skb,
265 enum skb_drop_reason reason)
267 trace_drop_common(skb, location);
270 static void trace_napi_poll_hit(void *ignore, struct napi_struct *napi,
271 int work, int budget)
273 struct net_device *dev = napi->dev;
274 struct dm_hw_stat_delta *stat;
276 * Don't check napi structures with no associated device
282 stat = rcu_dereference(dev->dm_private);
285 * only add a note to our monitor buffer if:
286 * 1) its after the last_rx delta
287 * 2) our rx_dropped count has gone up
289 if (time_after(jiffies, stat->last_rx + dm_hw_check_delta) &&
290 (dev->stats.rx_dropped != stat->last_drop_val)) {
291 trace_drop_common(NULL, NULL);
292 stat->last_drop_val = dev->stats.rx_dropped;
293 stat->last_rx = jiffies;
299 static struct net_dm_hw_entries *
300 net_dm_hw_reset_per_cpu_data(struct per_cpu_dm_data *hw_data)
302 struct net_dm_hw_entries *hw_entries;
305 hw_entries = kzalloc(struct_size(hw_entries, entries, dm_hit_limit),
308 /* If the memory allocation failed, we try to perform another
309 * allocation in 1/10 second. Otherwise, the probe function
310 * will constantly bail out.
312 mod_timer(&hw_data->send_timer, jiffies + HZ / 10);
315 spin_lock_irqsave(&hw_data->lock, flags);
316 swap(hw_data->hw_entries, hw_entries);
317 spin_unlock_irqrestore(&hw_data->lock, flags);
322 static int net_dm_hw_entry_put(struct sk_buff *msg,
323 const struct net_dm_hw_entry *hw_entry)
327 attr = nla_nest_start(msg, NET_DM_ATTR_HW_ENTRY);
331 if (nla_put_string(msg, NET_DM_ATTR_HW_TRAP_NAME, hw_entry->trap_name))
332 goto nla_put_failure;
334 if (nla_put_u32(msg, NET_DM_ATTR_HW_TRAP_COUNT, hw_entry->count))
335 goto nla_put_failure;
337 nla_nest_end(msg, attr);
342 nla_nest_cancel(msg, attr);
346 static int net_dm_hw_entries_put(struct sk_buff *msg,
347 const struct net_dm_hw_entries *hw_entries)
352 attr = nla_nest_start(msg, NET_DM_ATTR_HW_ENTRIES);
356 for (i = 0; i < hw_entries->num_entries; i++) {
359 rc = net_dm_hw_entry_put(msg, &hw_entries->entries[i]);
361 goto nla_put_failure;
364 nla_nest_end(msg, attr);
369 nla_nest_cancel(msg, attr);
374 net_dm_hw_summary_report_fill(struct sk_buff *msg,
375 const struct net_dm_hw_entries *hw_entries)
377 struct net_dm_alert_msg anc_hdr = { 0 };
381 hdr = genlmsg_put(msg, 0, 0, &net_drop_monitor_family, 0,
386 /* We need to put the ancillary header in order not to break user
389 if (nla_put(msg, NLA_UNSPEC, sizeof(anc_hdr), &anc_hdr))
390 goto nla_put_failure;
392 rc = net_dm_hw_entries_put(msg, hw_entries);
394 goto nla_put_failure;
396 genlmsg_end(msg, hdr);
401 genlmsg_cancel(msg, hdr);
405 static void net_dm_hw_summary_work(struct work_struct *work)
407 struct net_dm_hw_entries *hw_entries;
408 struct per_cpu_dm_data *hw_data;
412 hw_data = container_of(work, struct per_cpu_dm_data, dm_alert_work);
414 hw_entries = net_dm_hw_reset_per_cpu_data(hw_data);
418 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
422 rc = net_dm_hw_summary_report_fill(msg, hw_entries);
428 genlmsg_multicast(&net_drop_monitor_family, msg, 0, 0, GFP_KERNEL);
435 net_dm_hw_trap_summary_probe(void *ignore, const struct devlink *devlink,
437 const struct devlink_trap_metadata *metadata)
439 struct net_dm_hw_entries *hw_entries;
440 struct net_dm_hw_entry *hw_entry;
441 struct per_cpu_dm_data *hw_data;
445 if (metadata->trap_type == DEVLINK_TRAP_TYPE_CONTROL)
448 hw_data = this_cpu_ptr(&dm_hw_cpu_data);
449 spin_lock_irqsave(&hw_data->lock, flags);
450 hw_entries = hw_data->hw_entries;
455 for (i = 0; i < hw_entries->num_entries; i++) {
456 hw_entry = &hw_entries->entries[i];
457 if (!strncmp(hw_entry->trap_name, metadata->trap_name,
458 NET_DM_MAX_HW_TRAP_NAME_LEN - 1)) {
463 if (WARN_ON_ONCE(hw_entries->num_entries == dm_hit_limit))
466 hw_entry = &hw_entries->entries[hw_entries->num_entries];
467 strscpy(hw_entry->trap_name, metadata->trap_name,
468 NET_DM_MAX_HW_TRAP_NAME_LEN - 1);
470 hw_entries->num_entries++;
472 if (!timer_pending(&hw_data->send_timer)) {
473 hw_data->send_timer.expires = jiffies + dm_delay * HZ;
474 add_timer(&hw_data->send_timer);
478 spin_unlock_irqrestore(&hw_data->lock, flags);
481 static const struct net_dm_alert_ops net_dm_alert_summary_ops = {
482 .kfree_skb_probe = trace_kfree_skb_hit,
483 .napi_poll_probe = trace_napi_poll_hit,
484 .work_item_func = send_dm_alert,
485 .hw_work_item_func = net_dm_hw_summary_work,
486 .hw_trap_probe = net_dm_hw_trap_summary_probe,
489 static void net_dm_packet_trace_kfree_skb_hit(void *ignore,
492 enum skb_drop_reason reason)
494 ktime_t tstamp = ktime_get_real();
495 struct per_cpu_dm_data *data;
496 struct net_dm_skb_cb *cb;
497 struct sk_buff *nskb;
500 if (!skb_mac_header_was_set(skb))
503 nskb = skb_clone(skb, GFP_ATOMIC);
507 if (unlikely(reason >= SKB_DROP_REASON_MAX || reason <= 0))
508 reason = SKB_DROP_REASON_NOT_SPECIFIED;
509 cb = NET_DM_SKB_CB(nskb);
512 /* Override the timestamp because we care about the time when the
513 * packet was dropped.
515 nskb->tstamp = tstamp;
517 data = this_cpu_ptr(&dm_cpu_data);
519 spin_lock_irqsave(&data->drop_queue.lock, flags);
520 if (skb_queue_len(&data->drop_queue) < net_dm_queue_len)
521 __skb_queue_tail(&data->drop_queue, nskb);
524 spin_unlock_irqrestore(&data->drop_queue.lock, flags);
526 schedule_work(&data->dm_alert_work);
531 spin_unlock_irqrestore(&data->drop_queue.lock, flags);
532 u64_stats_update_begin(&data->stats.syncp);
533 u64_stats_inc(&data->stats.dropped);
534 u64_stats_update_end(&data->stats.syncp);
538 static void net_dm_packet_trace_napi_poll_hit(void *ignore,
539 struct napi_struct *napi,
540 int work, int budget)
544 static size_t net_dm_in_port_size(void)
546 /* NET_DM_ATTR_IN_PORT nest */
547 return nla_total_size(0) +
548 /* NET_DM_ATTR_PORT_NETDEV_IFINDEX */
549 nla_total_size(sizeof(u32)) +
550 /* NET_DM_ATTR_PORT_NETDEV_NAME */
551 nla_total_size(IFNAMSIZ + 1);
554 #define NET_DM_MAX_SYMBOL_LEN 40
556 static size_t net_dm_packet_report_size(size_t payload_len,
557 enum skb_drop_reason reason)
561 size = nlmsg_msg_size(GENL_HDRLEN + net_drop_monitor_family.hdrsize);
563 return NLMSG_ALIGN(size) +
564 /* NET_DM_ATTR_ORIGIN */
565 nla_total_size(sizeof(u16)) +
567 nla_total_size(sizeof(u64)) +
568 /* NET_DM_ATTR_SYMBOL */
569 nla_total_size(NET_DM_MAX_SYMBOL_LEN + 1) +
570 /* NET_DM_ATTR_IN_PORT */
571 net_dm_in_port_size() +
572 /* NET_DM_ATTR_TIMESTAMP */
573 nla_total_size(sizeof(u64)) +
574 /* NET_DM_ATTR_ORIG_LEN */
575 nla_total_size(sizeof(u32)) +
576 /* NET_DM_ATTR_PROTO */
577 nla_total_size(sizeof(u16)) +
578 /* NET_DM_ATTR_REASON */
579 nla_total_size(strlen(drop_reasons[reason]) + 1) +
580 /* NET_DM_ATTR_PAYLOAD */
581 nla_total_size(payload_len);
584 static int net_dm_packet_report_in_port_put(struct sk_buff *msg, int ifindex,
589 attr = nla_nest_start(msg, NET_DM_ATTR_IN_PORT);
594 nla_put_u32(msg, NET_DM_ATTR_PORT_NETDEV_IFINDEX, ifindex))
595 goto nla_put_failure;
597 if (name && nla_put_string(msg, NET_DM_ATTR_PORT_NETDEV_NAME, name))
598 goto nla_put_failure;
600 nla_nest_end(msg, attr);
605 nla_nest_cancel(msg, attr);
609 static int net_dm_packet_report_fill(struct sk_buff *msg, struct sk_buff *skb,
612 struct net_dm_skb_cb *cb = NET_DM_SKB_CB(skb);
613 char buf[NET_DM_MAX_SYMBOL_LEN];
618 hdr = genlmsg_put(msg, 0, 0, &net_drop_monitor_family, 0,
619 NET_DM_CMD_PACKET_ALERT);
623 if (nla_put_u16(msg, NET_DM_ATTR_ORIGIN, NET_DM_ORIGIN_SW))
624 goto nla_put_failure;
626 if (nla_put_u64_64bit(msg, NET_DM_ATTR_PC, (u64)(uintptr_t)cb->pc,
628 goto nla_put_failure;
630 if (nla_put_string(msg, NET_DM_ATTR_REASON,
631 drop_reasons[cb->reason]))
632 goto nla_put_failure;
634 snprintf(buf, sizeof(buf), "%pS", cb->pc);
635 if (nla_put_string(msg, NET_DM_ATTR_SYMBOL, buf))
636 goto nla_put_failure;
638 rc = net_dm_packet_report_in_port_put(msg, skb->skb_iif, NULL);
640 goto nla_put_failure;
642 if (nla_put_u64_64bit(msg, NET_DM_ATTR_TIMESTAMP,
643 ktime_to_ns(skb->tstamp), NET_DM_ATTR_PAD))
644 goto nla_put_failure;
646 if (nla_put_u32(msg, NET_DM_ATTR_ORIG_LEN, skb->len))
647 goto nla_put_failure;
652 if (nla_put_u16(msg, NET_DM_ATTR_PROTO, be16_to_cpu(skb->protocol)))
653 goto nla_put_failure;
655 attr = skb_put(msg, nla_total_size(payload_len));
656 attr->nla_type = NET_DM_ATTR_PAYLOAD;
657 attr->nla_len = nla_attr_size(payload_len);
658 if (skb_copy_bits(skb, 0, nla_data(attr), payload_len))
659 goto nla_put_failure;
662 genlmsg_end(msg, hdr);
667 genlmsg_cancel(msg, hdr);
671 #define NET_DM_MAX_PACKET_SIZE (0xffff - NLA_HDRLEN - NLA_ALIGNTO)
673 static void net_dm_packet_report(struct sk_buff *skb)
679 /* Make sure we start copying the packet from the MAC header */
680 if (skb->data > skb_mac_header(skb))
681 skb_push(skb, skb->data - skb_mac_header(skb));
683 skb_pull(skb, skb_mac_header(skb) - skb->data);
685 /* Ensure packet fits inside a single netlink attribute */
686 payload_len = min_t(size_t, skb->len, NET_DM_MAX_PACKET_SIZE);
687 if (net_dm_trunc_len)
688 payload_len = min_t(size_t, net_dm_trunc_len, payload_len);
690 msg = nlmsg_new(net_dm_packet_report_size(payload_len,
691 NET_DM_SKB_CB(skb)->reason),
696 rc = net_dm_packet_report_fill(msg, skb, payload_len);
702 genlmsg_multicast(&net_drop_monitor_family, msg, 0, 0, GFP_KERNEL);
708 static void net_dm_packet_work(struct work_struct *work)
710 struct per_cpu_dm_data *data;
711 struct sk_buff_head list;
715 data = container_of(work, struct per_cpu_dm_data, dm_alert_work);
717 __skb_queue_head_init(&list);
719 spin_lock_irqsave(&data->drop_queue.lock, flags);
720 skb_queue_splice_tail_init(&data->drop_queue, &list);
721 spin_unlock_irqrestore(&data->drop_queue.lock, flags);
723 while ((skb = __skb_dequeue(&list)))
724 net_dm_packet_report(skb);
728 net_dm_flow_action_cookie_size(const struct devlink_trap_metadata *hw_metadata)
730 return hw_metadata->fa_cookie ?
731 nla_total_size(hw_metadata->fa_cookie->cookie_len) : 0;
735 net_dm_hw_packet_report_size(size_t payload_len,
736 const struct devlink_trap_metadata *hw_metadata)
740 size = nlmsg_msg_size(GENL_HDRLEN + net_drop_monitor_family.hdrsize);
742 return NLMSG_ALIGN(size) +
743 /* NET_DM_ATTR_ORIGIN */
744 nla_total_size(sizeof(u16)) +
745 /* NET_DM_ATTR_HW_TRAP_GROUP_NAME */
746 nla_total_size(strlen(hw_metadata->trap_group_name) + 1) +
747 /* NET_DM_ATTR_HW_TRAP_NAME */
748 nla_total_size(strlen(hw_metadata->trap_name) + 1) +
749 /* NET_DM_ATTR_IN_PORT */
750 net_dm_in_port_size() +
751 /* NET_DM_ATTR_FLOW_ACTION_COOKIE */
752 net_dm_flow_action_cookie_size(hw_metadata) +
753 /* NET_DM_ATTR_TIMESTAMP */
754 nla_total_size(sizeof(u64)) +
755 /* NET_DM_ATTR_ORIG_LEN */
756 nla_total_size(sizeof(u32)) +
757 /* NET_DM_ATTR_PROTO */
758 nla_total_size(sizeof(u16)) +
759 /* NET_DM_ATTR_PAYLOAD */
760 nla_total_size(payload_len);
763 static int net_dm_hw_packet_report_fill(struct sk_buff *msg,
764 struct sk_buff *skb, size_t payload_len)
766 struct devlink_trap_metadata *hw_metadata;
770 hw_metadata = NET_DM_SKB_CB(skb)->hw_metadata;
772 hdr = genlmsg_put(msg, 0, 0, &net_drop_monitor_family, 0,
773 NET_DM_CMD_PACKET_ALERT);
777 if (nla_put_u16(msg, NET_DM_ATTR_ORIGIN, NET_DM_ORIGIN_HW))
778 goto nla_put_failure;
780 if (nla_put_string(msg, NET_DM_ATTR_HW_TRAP_GROUP_NAME,
781 hw_metadata->trap_group_name))
782 goto nla_put_failure;
784 if (nla_put_string(msg, NET_DM_ATTR_HW_TRAP_NAME,
785 hw_metadata->trap_name))
786 goto nla_put_failure;
788 if (hw_metadata->input_dev) {
789 struct net_device *dev = hw_metadata->input_dev;
792 rc = net_dm_packet_report_in_port_put(msg, dev->ifindex,
795 goto nla_put_failure;
798 if (hw_metadata->fa_cookie &&
799 nla_put(msg, NET_DM_ATTR_FLOW_ACTION_COOKIE,
800 hw_metadata->fa_cookie->cookie_len,
801 hw_metadata->fa_cookie->cookie))
802 goto nla_put_failure;
804 if (nla_put_u64_64bit(msg, NET_DM_ATTR_TIMESTAMP,
805 ktime_to_ns(skb->tstamp), NET_DM_ATTR_PAD))
806 goto nla_put_failure;
808 if (nla_put_u32(msg, NET_DM_ATTR_ORIG_LEN, skb->len))
809 goto nla_put_failure;
814 if (nla_put_u16(msg, NET_DM_ATTR_PROTO, be16_to_cpu(skb->protocol)))
815 goto nla_put_failure;
817 attr = skb_put(msg, nla_total_size(payload_len));
818 attr->nla_type = NET_DM_ATTR_PAYLOAD;
819 attr->nla_len = nla_attr_size(payload_len);
820 if (skb_copy_bits(skb, 0, nla_data(attr), payload_len))
821 goto nla_put_failure;
824 genlmsg_end(msg, hdr);
829 genlmsg_cancel(msg, hdr);
833 static struct devlink_trap_metadata *
834 net_dm_hw_metadata_copy(const struct devlink_trap_metadata *metadata)
836 const struct flow_action_cookie *fa_cookie;
837 struct devlink_trap_metadata *hw_metadata;
838 const char *trap_group_name;
839 const char *trap_name;
841 hw_metadata = kzalloc(sizeof(*hw_metadata), GFP_ATOMIC);
845 trap_group_name = kstrdup(metadata->trap_group_name, GFP_ATOMIC);
846 if (!trap_group_name)
847 goto free_hw_metadata;
848 hw_metadata->trap_group_name = trap_group_name;
850 trap_name = kstrdup(metadata->trap_name, GFP_ATOMIC);
852 goto free_trap_group;
853 hw_metadata->trap_name = trap_name;
855 if (metadata->fa_cookie) {
856 size_t cookie_size = sizeof(*fa_cookie) +
857 metadata->fa_cookie->cookie_len;
859 fa_cookie = kmemdup(metadata->fa_cookie, cookie_size,
863 hw_metadata->fa_cookie = fa_cookie;
866 hw_metadata->input_dev = metadata->input_dev;
867 netdev_hold(hw_metadata->input_dev, &hw_metadata->dev_tracker,
875 kfree(trap_group_name);
882 net_dm_hw_metadata_free(struct devlink_trap_metadata *hw_metadata)
884 netdev_put(hw_metadata->input_dev, &hw_metadata->dev_tracker);
885 kfree(hw_metadata->fa_cookie);
886 kfree(hw_metadata->trap_name);
887 kfree(hw_metadata->trap_group_name);
891 static void net_dm_hw_packet_report(struct sk_buff *skb)
893 struct devlink_trap_metadata *hw_metadata;
898 if (skb->data > skb_mac_header(skb))
899 skb_push(skb, skb->data - skb_mac_header(skb));
901 skb_pull(skb, skb_mac_header(skb) - skb->data);
903 payload_len = min_t(size_t, skb->len, NET_DM_MAX_PACKET_SIZE);
904 if (net_dm_trunc_len)
905 payload_len = min_t(size_t, net_dm_trunc_len, payload_len);
907 hw_metadata = NET_DM_SKB_CB(skb)->hw_metadata;
908 msg = nlmsg_new(net_dm_hw_packet_report_size(payload_len, hw_metadata),
913 rc = net_dm_hw_packet_report_fill(msg, skb, payload_len);
919 genlmsg_multicast(&net_drop_monitor_family, msg, 0, 0, GFP_KERNEL);
922 net_dm_hw_metadata_free(NET_DM_SKB_CB(skb)->hw_metadata);
926 static void net_dm_hw_packet_work(struct work_struct *work)
928 struct per_cpu_dm_data *hw_data;
929 struct sk_buff_head list;
933 hw_data = container_of(work, struct per_cpu_dm_data, dm_alert_work);
935 __skb_queue_head_init(&list);
937 spin_lock_irqsave(&hw_data->drop_queue.lock, flags);
938 skb_queue_splice_tail_init(&hw_data->drop_queue, &list);
939 spin_unlock_irqrestore(&hw_data->drop_queue.lock, flags);
941 while ((skb = __skb_dequeue(&list)))
942 net_dm_hw_packet_report(skb);
946 net_dm_hw_trap_packet_probe(void *ignore, const struct devlink *devlink,
948 const struct devlink_trap_metadata *metadata)
950 struct devlink_trap_metadata *n_hw_metadata;
951 ktime_t tstamp = ktime_get_real();
952 struct per_cpu_dm_data *hw_data;
953 struct sk_buff *nskb;
956 if (metadata->trap_type == DEVLINK_TRAP_TYPE_CONTROL)
959 if (!skb_mac_header_was_set(skb))
962 nskb = skb_clone(skb, GFP_ATOMIC);
966 n_hw_metadata = net_dm_hw_metadata_copy(metadata);
970 NET_DM_SKB_CB(nskb)->hw_metadata = n_hw_metadata;
971 nskb->tstamp = tstamp;
973 hw_data = this_cpu_ptr(&dm_hw_cpu_data);
975 spin_lock_irqsave(&hw_data->drop_queue.lock, flags);
976 if (skb_queue_len(&hw_data->drop_queue) < net_dm_queue_len)
977 __skb_queue_tail(&hw_data->drop_queue, nskb);
980 spin_unlock_irqrestore(&hw_data->drop_queue.lock, flags);
982 schedule_work(&hw_data->dm_alert_work);
987 spin_unlock_irqrestore(&hw_data->drop_queue.lock, flags);
988 u64_stats_update_begin(&hw_data->stats.syncp);
989 u64_stats_inc(&hw_data->stats.dropped);
990 u64_stats_update_end(&hw_data->stats.syncp);
991 net_dm_hw_metadata_free(n_hw_metadata);
996 static const struct net_dm_alert_ops net_dm_alert_packet_ops = {
997 .kfree_skb_probe = net_dm_packet_trace_kfree_skb_hit,
998 .napi_poll_probe = net_dm_packet_trace_napi_poll_hit,
999 .work_item_func = net_dm_packet_work,
1000 .hw_work_item_func = net_dm_hw_packet_work,
1001 .hw_trap_probe = net_dm_hw_trap_packet_probe,
1004 static const struct net_dm_alert_ops *net_dm_alert_ops_arr[] = {
1005 [NET_DM_ALERT_MODE_SUMMARY] = &net_dm_alert_summary_ops,
1006 [NET_DM_ALERT_MODE_PACKET] = &net_dm_alert_packet_ops,
1009 #if IS_ENABLED(CONFIG_NET_DEVLINK)
1010 static int net_dm_hw_probe_register(const struct net_dm_alert_ops *ops)
1012 return register_trace_devlink_trap_report(ops->hw_trap_probe, NULL);
1015 static void net_dm_hw_probe_unregister(const struct net_dm_alert_ops *ops)
1017 unregister_trace_devlink_trap_report(ops->hw_trap_probe, NULL);
1018 tracepoint_synchronize_unregister();
1021 static int net_dm_hw_probe_register(const struct net_dm_alert_ops *ops)
1026 static void net_dm_hw_probe_unregister(const struct net_dm_alert_ops *ops)
1031 static int net_dm_hw_monitor_start(struct netlink_ext_ack *extack)
1033 const struct net_dm_alert_ops *ops;
1037 NL_SET_ERR_MSG_MOD(extack, "Hardware monitoring already enabled");
1041 ops = net_dm_alert_ops_arr[net_dm_alert_mode];
1043 if (!try_module_get(THIS_MODULE)) {
1044 NL_SET_ERR_MSG_MOD(extack, "Failed to take reference on module");
1048 for_each_possible_cpu(cpu) {
1049 struct per_cpu_dm_data *hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1050 struct net_dm_hw_entries *hw_entries;
1052 INIT_WORK(&hw_data->dm_alert_work, ops->hw_work_item_func);
1053 timer_setup(&hw_data->send_timer, sched_send_work, 0);
1054 hw_entries = net_dm_hw_reset_per_cpu_data(hw_data);
1058 rc = net_dm_hw_probe_register(ops);
1060 NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to devlink_trap_probe() tracepoint");
1061 goto err_module_put;
1069 for_each_possible_cpu(cpu) {
1070 struct per_cpu_dm_data *hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1071 struct sk_buff *skb;
1073 del_timer_sync(&hw_data->send_timer);
1074 cancel_work_sync(&hw_data->dm_alert_work);
1075 while ((skb = __skb_dequeue(&hw_data->drop_queue))) {
1076 struct devlink_trap_metadata *hw_metadata;
1078 hw_metadata = NET_DM_SKB_CB(skb)->hw_metadata;
1079 net_dm_hw_metadata_free(hw_metadata);
1083 module_put(THIS_MODULE);
1087 static void net_dm_hw_monitor_stop(struct netlink_ext_ack *extack)
1089 const struct net_dm_alert_ops *ops;
1093 NL_SET_ERR_MSG_MOD(extack, "Hardware monitoring already disabled");
1097 ops = net_dm_alert_ops_arr[net_dm_alert_mode];
1101 net_dm_hw_probe_unregister(ops);
1103 for_each_possible_cpu(cpu) {
1104 struct per_cpu_dm_data *hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1105 struct sk_buff *skb;
1107 del_timer_sync(&hw_data->send_timer);
1108 cancel_work_sync(&hw_data->dm_alert_work);
1109 while ((skb = __skb_dequeue(&hw_data->drop_queue))) {
1110 struct devlink_trap_metadata *hw_metadata;
1112 hw_metadata = NET_DM_SKB_CB(skb)->hw_metadata;
1113 net_dm_hw_metadata_free(hw_metadata);
1118 module_put(THIS_MODULE);
1121 static int net_dm_trace_on_set(struct netlink_ext_ack *extack)
1123 const struct net_dm_alert_ops *ops;
1126 ops = net_dm_alert_ops_arr[net_dm_alert_mode];
1128 if (!try_module_get(THIS_MODULE)) {
1129 NL_SET_ERR_MSG_MOD(extack, "Failed to take reference on module");
1133 for_each_possible_cpu(cpu) {
1134 struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);
1135 struct sk_buff *skb;
1137 INIT_WORK(&data->dm_alert_work, ops->work_item_func);
1138 timer_setup(&data->send_timer, sched_send_work, 0);
1139 /* Allocate a new per-CPU skb for the summary alert message and
1140 * free the old one which might contain stale data from
1143 skb = reset_per_cpu_data(data);
1147 rc = register_trace_kfree_skb(ops->kfree_skb_probe, NULL);
1149 NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to kfree_skb() tracepoint");
1150 goto err_module_put;
1153 rc = register_trace_napi_poll(ops->napi_poll_probe, NULL);
1155 NL_SET_ERR_MSG_MOD(extack, "Failed to connect probe to napi_poll() tracepoint");
1156 goto err_unregister_trace;
1161 err_unregister_trace:
1162 unregister_trace_kfree_skb(ops->kfree_skb_probe, NULL);
1164 for_each_possible_cpu(cpu) {
1165 struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);
1166 struct sk_buff *skb;
1168 del_timer_sync(&data->send_timer);
1169 cancel_work_sync(&data->dm_alert_work);
1170 while ((skb = __skb_dequeue(&data->drop_queue)))
1173 module_put(THIS_MODULE);
1177 static void net_dm_trace_off_set(void)
1179 const struct net_dm_alert_ops *ops;
1182 ops = net_dm_alert_ops_arr[net_dm_alert_mode];
1184 unregister_trace_napi_poll(ops->napi_poll_probe, NULL);
1185 unregister_trace_kfree_skb(ops->kfree_skb_probe, NULL);
1187 tracepoint_synchronize_unregister();
1189 /* Make sure we do not send notifications to user space after request
1190 * to stop tracing returns.
1192 for_each_possible_cpu(cpu) {
1193 struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);
1194 struct sk_buff *skb;
1196 del_timer_sync(&data->send_timer);
1197 cancel_work_sync(&data->dm_alert_work);
1198 while ((skb = __skb_dequeue(&data->drop_queue)))
1202 module_put(THIS_MODULE);
1205 static int set_all_monitor_traces(int state, struct netlink_ext_ack *extack)
1209 if (state == trace_state) {
1210 NL_SET_ERR_MSG_MOD(extack, "Trace state already set to requested state");
1216 rc = net_dm_trace_on_set(extack);
1219 net_dm_trace_off_set();
1227 trace_state = state;
1234 static bool net_dm_is_monitoring(void)
1236 return trace_state == TRACE_ON || monitor_hw;
1239 static int net_dm_alert_mode_get_from_info(struct genl_info *info,
1240 enum net_dm_alert_mode *p_alert_mode)
1244 val = nla_get_u8(info->attrs[NET_DM_ATTR_ALERT_MODE]);
1247 case NET_DM_ALERT_MODE_SUMMARY:
1248 case NET_DM_ALERT_MODE_PACKET:
1249 *p_alert_mode = val;
1258 static int net_dm_alert_mode_set(struct genl_info *info)
1260 struct netlink_ext_ack *extack = info->extack;
1261 enum net_dm_alert_mode alert_mode;
1264 if (!info->attrs[NET_DM_ATTR_ALERT_MODE])
1267 rc = net_dm_alert_mode_get_from_info(info, &alert_mode);
1269 NL_SET_ERR_MSG_MOD(extack, "Invalid alert mode");
1273 net_dm_alert_mode = alert_mode;
1278 static void net_dm_trunc_len_set(struct genl_info *info)
1280 if (!info->attrs[NET_DM_ATTR_TRUNC_LEN])
1283 net_dm_trunc_len = nla_get_u32(info->attrs[NET_DM_ATTR_TRUNC_LEN]);
1286 static void net_dm_queue_len_set(struct genl_info *info)
1288 if (!info->attrs[NET_DM_ATTR_QUEUE_LEN])
1291 net_dm_queue_len = nla_get_u32(info->attrs[NET_DM_ATTR_QUEUE_LEN]);
1294 static int net_dm_cmd_config(struct sk_buff *skb,
1295 struct genl_info *info)
1297 struct netlink_ext_ack *extack = info->extack;
1300 if (net_dm_is_monitoring()) {
1301 NL_SET_ERR_MSG_MOD(extack, "Cannot configure drop monitor during monitoring");
1305 rc = net_dm_alert_mode_set(info);
1309 net_dm_trunc_len_set(info);
1311 net_dm_queue_len_set(info);
1316 static int net_dm_monitor_start(bool set_sw, bool set_hw,
1317 struct netlink_ext_ack *extack)
1319 bool sw_set = false;
1323 rc = set_all_monitor_traces(TRACE_ON, extack);
1330 rc = net_dm_hw_monitor_start(extack);
1332 goto err_monitor_hw;
1339 set_all_monitor_traces(TRACE_OFF, extack);
1343 static void net_dm_monitor_stop(bool set_sw, bool set_hw,
1344 struct netlink_ext_ack *extack)
1347 net_dm_hw_monitor_stop(extack);
1349 set_all_monitor_traces(TRACE_OFF, extack);
1352 static int net_dm_cmd_trace(struct sk_buff *skb,
1353 struct genl_info *info)
1355 bool set_sw = !!info->attrs[NET_DM_ATTR_SW_DROPS];
1356 bool set_hw = !!info->attrs[NET_DM_ATTR_HW_DROPS];
1357 struct netlink_ext_ack *extack = info->extack;
1359 /* To maintain backward compatibility, we start / stop monitoring of
1360 * software drops if no flag is specified.
1362 if (!set_sw && !set_hw)
1365 switch (info->genlhdr->cmd) {
1366 case NET_DM_CMD_START:
1367 return net_dm_monitor_start(set_sw, set_hw, extack);
1368 case NET_DM_CMD_STOP:
1369 net_dm_monitor_stop(set_sw, set_hw, extack);
1376 static int net_dm_config_fill(struct sk_buff *msg, struct genl_info *info)
1380 hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq,
1381 &net_drop_monitor_family, 0, NET_DM_CMD_CONFIG_NEW);
1385 if (nla_put_u8(msg, NET_DM_ATTR_ALERT_MODE, net_dm_alert_mode))
1386 goto nla_put_failure;
1388 if (nla_put_u32(msg, NET_DM_ATTR_TRUNC_LEN, net_dm_trunc_len))
1389 goto nla_put_failure;
1391 if (nla_put_u32(msg, NET_DM_ATTR_QUEUE_LEN, net_dm_queue_len))
1392 goto nla_put_failure;
1394 genlmsg_end(msg, hdr);
1399 genlmsg_cancel(msg, hdr);
1403 static int net_dm_cmd_config_get(struct sk_buff *skb, struct genl_info *info)
1405 struct sk_buff *msg;
1408 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1412 rc = net_dm_config_fill(msg, info);
1416 return genlmsg_reply(msg, info);
1423 static void net_dm_stats_read(struct net_dm_stats *stats)
1427 memset(stats, 0, sizeof(*stats));
1428 for_each_possible_cpu(cpu) {
1429 struct per_cpu_dm_data *data = &per_cpu(dm_cpu_data, cpu);
1430 struct net_dm_stats *cpu_stats = &data->stats;
1435 start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
1436 dropped = u64_stats_read(&cpu_stats->dropped);
1437 } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
1439 u64_stats_add(&stats->dropped, dropped);
1443 static int net_dm_stats_put(struct sk_buff *msg)
1445 struct net_dm_stats stats;
1446 struct nlattr *attr;
1448 net_dm_stats_read(&stats);
1450 attr = nla_nest_start(msg, NET_DM_ATTR_STATS);
1454 if (nla_put_u64_64bit(msg, NET_DM_ATTR_STATS_DROPPED,
1455 u64_stats_read(&stats.dropped), NET_DM_ATTR_PAD))
1456 goto nla_put_failure;
1458 nla_nest_end(msg, attr);
1463 nla_nest_cancel(msg, attr);
1467 static void net_dm_hw_stats_read(struct net_dm_stats *stats)
1471 memset(stats, 0, sizeof(*stats));
1472 for_each_possible_cpu(cpu) {
1473 struct per_cpu_dm_data *hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1474 struct net_dm_stats *cpu_stats = &hw_data->stats;
1479 start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
1480 dropped = u64_stats_read(&cpu_stats->dropped);
1481 } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
1483 u64_stats_add(&stats->dropped, dropped);
1487 static int net_dm_hw_stats_put(struct sk_buff *msg)
1489 struct net_dm_stats stats;
1490 struct nlattr *attr;
1492 net_dm_hw_stats_read(&stats);
1494 attr = nla_nest_start(msg, NET_DM_ATTR_HW_STATS);
1498 if (nla_put_u64_64bit(msg, NET_DM_ATTR_STATS_DROPPED,
1499 u64_stats_read(&stats.dropped), NET_DM_ATTR_PAD))
1500 goto nla_put_failure;
1502 nla_nest_end(msg, attr);
1507 nla_nest_cancel(msg, attr);
1511 static int net_dm_stats_fill(struct sk_buff *msg, struct genl_info *info)
1516 hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq,
1517 &net_drop_monitor_family, 0, NET_DM_CMD_STATS_NEW);
1521 rc = net_dm_stats_put(msg);
1523 goto nla_put_failure;
1525 rc = net_dm_hw_stats_put(msg);
1527 goto nla_put_failure;
1529 genlmsg_end(msg, hdr);
1534 genlmsg_cancel(msg, hdr);
1538 static int net_dm_cmd_stats_get(struct sk_buff *skb, struct genl_info *info)
1540 struct sk_buff *msg;
1543 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1547 rc = net_dm_stats_fill(msg, info);
1551 return genlmsg_reply(msg, info);
1558 static int dropmon_net_event(struct notifier_block *ev_block,
1559 unsigned long event, void *ptr)
1561 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
1562 struct dm_hw_stat_delta *stat;
1565 case NETDEV_REGISTER:
1566 if (WARN_ON_ONCE(rtnl_dereference(dev->dm_private)))
1568 stat = kzalloc(sizeof(*stat), GFP_KERNEL);
1572 stat->last_rx = jiffies;
1573 rcu_assign_pointer(dev->dm_private, stat);
1576 case NETDEV_UNREGISTER:
1577 stat = rtnl_dereference(dev->dm_private);
1579 rcu_assign_pointer(dev->dm_private, NULL);
1580 kfree_rcu(stat, rcu);
1587 static const struct nla_policy net_dm_nl_policy[NET_DM_ATTR_MAX + 1] = {
1588 [NET_DM_ATTR_UNSPEC] = { .strict_start_type = NET_DM_ATTR_UNSPEC + 1 },
1589 [NET_DM_ATTR_ALERT_MODE] = { .type = NLA_U8 },
1590 [NET_DM_ATTR_TRUNC_LEN] = { .type = NLA_U32 },
1591 [NET_DM_ATTR_QUEUE_LEN] = { .type = NLA_U32 },
1592 [NET_DM_ATTR_SW_DROPS] = {. type = NLA_FLAG },
1593 [NET_DM_ATTR_HW_DROPS] = {. type = NLA_FLAG },
1596 static const struct genl_small_ops dropmon_ops[] = {
1598 .cmd = NET_DM_CMD_CONFIG,
1599 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1600 .doit = net_dm_cmd_config,
1601 .flags = GENL_ADMIN_PERM,
1604 .cmd = NET_DM_CMD_START,
1605 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1606 .doit = net_dm_cmd_trace,
1609 .cmd = NET_DM_CMD_STOP,
1610 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
1611 .doit = net_dm_cmd_trace,
1614 .cmd = NET_DM_CMD_CONFIG_GET,
1615 .doit = net_dm_cmd_config_get,
1618 .cmd = NET_DM_CMD_STATS_GET,
1619 .doit = net_dm_cmd_stats_get,
1623 static int net_dm_nl_pre_doit(const struct genl_ops *ops,
1624 struct sk_buff *skb, struct genl_info *info)
1626 mutex_lock(&net_dm_mutex);
1631 static void net_dm_nl_post_doit(const struct genl_ops *ops,
1632 struct sk_buff *skb, struct genl_info *info)
1634 mutex_unlock(&net_dm_mutex);
1637 static struct genl_family net_drop_monitor_family __ro_after_init = {
1641 .maxattr = NET_DM_ATTR_MAX,
1642 .policy = net_dm_nl_policy,
1643 .pre_doit = net_dm_nl_pre_doit,
1644 .post_doit = net_dm_nl_post_doit,
1645 .module = THIS_MODULE,
1646 .small_ops = dropmon_ops,
1647 .n_small_ops = ARRAY_SIZE(dropmon_ops),
1648 .resv_start_op = NET_DM_CMD_STATS_GET + 1,
1649 .mcgrps = dropmon_mcgrps,
1650 .n_mcgrps = ARRAY_SIZE(dropmon_mcgrps),
1653 static struct notifier_block dropmon_net_notifier = {
1654 .notifier_call = dropmon_net_event
1657 static void __net_dm_cpu_data_init(struct per_cpu_dm_data *data)
1659 spin_lock_init(&data->lock);
1660 skb_queue_head_init(&data->drop_queue);
1661 u64_stats_init(&data->stats.syncp);
1664 static void __net_dm_cpu_data_fini(struct per_cpu_dm_data *data)
1666 WARN_ON(!skb_queue_empty(&data->drop_queue));
1669 static void net_dm_cpu_data_init(int cpu)
1671 struct per_cpu_dm_data *data;
1673 data = &per_cpu(dm_cpu_data, cpu);
1674 __net_dm_cpu_data_init(data);
1677 static void net_dm_cpu_data_fini(int cpu)
1679 struct per_cpu_dm_data *data;
1681 data = &per_cpu(dm_cpu_data, cpu);
1682 /* At this point, we should have exclusive access
1683 * to this struct and can free the skb inside it.
1685 consume_skb(data->skb);
1686 __net_dm_cpu_data_fini(data);
1689 static void net_dm_hw_cpu_data_init(int cpu)
1691 struct per_cpu_dm_data *hw_data;
1693 hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1694 __net_dm_cpu_data_init(hw_data);
1697 static void net_dm_hw_cpu_data_fini(int cpu)
1699 struct per_cpu_dm_data *hw_data;
1701 hw_data = &per_cpu(dm_hw_cpu_data, cpu);
1702 kfree(hw_data->hw_entries);
1703 __net_dm_cpu_data_fini(hw_data);
1706 static int __init init_net_drop_monitor(void)
1710 pr_info("Initializing network drop monitor service\n");
1712 if (sizeof(void *) > 8) {
1713 pr_err("Unable to store program counters on this arch, Drop monitor failed\n");
1717 rc = genl_register_family(&net_drop_monitor_family);
1719 pr_err("Could not create drop monitor netlink family\n");
1722 WARN_ON(net_drop_monitor_family.mcgrp_offset != NET_DM_GRP_ALERT);
1724 rc = register_netdevice_notifier(&dropmon_net_notifier);
1726 pr_crit("Failed to register netdevice notifier\n");
1732 for_each_possible_cpu(cpu) {
1733 net_dm_cpu_data_init(cpu);
1734 net_dm_hw_cpu_data_init(cpu);
1740 genl_unregister_family(&net_drop_monitor_family);
1745 static void exit_net_drop_monitor(void)
1749 BUG_ON(unregister_netdevice_notifier(&dropmon_net_notifier));
1752 * Because of the module_get/put we do in the trace state change path
1753 * we are guaranteed not to have any current users when we get here
1756 for_each_possible_cpu(cpu) {
1757 net_dm_hw_cpu_data_fini(cpu);
1758 net_dm_cpu_data_fini(cpu);
1761 BUG_ON(genl_unregister_family(&net_drop_monitor_family));
1764 module_init(init_net_drop_monitor);
1765 module_exit(exit_net_drop_monitor);
1767 MODULE_LICENSE("GPL v2");
1768 MODULE_AUTHOR("Neil Horman <nhorman@tuxdriver.com>");
1769 MODULE_ALIAS_GENL_FAMILY("NET_DM");
1770 MODULE_DESCRIPTION("Monitoring code for network dropped packet alerts");