2 * wprobe-core.c: Wireless probe interface core
3 * Copyright (C) 2008-2009 Felix Fietkau <nbd@openwrt.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/kernel.h>
17 #include <linux/version.h>
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/spinlock.h>
21 #include <linux/rcupdate.h>
22 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
23 #include <linux/rculist.h>
25 #include <linux/list.h>
27 #include <linux/skbuff.h>
28 #include <linux/wprobe.h>
29 #include <linux/math64.h>
33 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
34 #define list_for_each_rcu __list_for_each_rcu
37 #define WPROBE_MIN_INTERVAL 100 /* minimum measurement interval in msecs */
38 #define WPROBE_MAX_FILTER_SIZE 1024
39 #define WPROBE_MAX_FRAME_SIZE 1900
41 static struct list_head wprobe_if;
42 static spinlock_t wprobe_lock;
44 static struct genl_family wprobe_fam = {
45 .id = GENL_ID_GENERATE,
49 /* only the first set of attributes is used for queries */
50 .maxattr = WPROBE_ATTR_LAST,
53 /* fake radiotap header */
54 struct wprobe_rtap_hdr {
61 static void wprobe_update_stats(struct wprobe_iface *dev, struct wprobe_link *l);
62 static int wprobe_sync_data(struct wprobe_iface *dev, struct wprobe_link *l, bool query);
63 static void wprobe_free_filter(struct wprobe_filter *f);
66 wprobe_add_link(struct wprobe_iface *s, struct wprobe_link *l, const char *addr)
70 INIT_LIST_HEAD(&l->list);
71 l->val = kzalloc(sizeof(struct wprobe_value) * s->n_link_items, GFP_ATOMIC);
76 memcpy(&l->addr, addr, ETH_ALEN);
77 spin_lock_irqsave(&wprobe_lock, flags);
78 list_add_tail_rcu(&l->list, &s->links);
79 spin_unlock_irqrestore(&wprobe_lock, flags);
83 EXPORT_SYMBOL(wprobe_add_link);
86 wprobe_remove_link(struct wprobe_iface *s, struct wprobe_link *l)
90 spin_lock_irqsave(&wprobe_lock, flags);
91 list_del_rcu(&l->list);
92 spin_unlock_irqrestore(&wprobe_lock, flags);
96 EXPORT_SYMBOL(wprobe_remove_link);
99 wprobe_measure_timer(unsigned long data)
101 struct wprobe_iface *dev = (struct wprobe_iface *) data;
103 /* set next measurement interval */
104 mod_timer(&dev->measure_timer, jiffies +
105 msecs_to_jiffies(dev->measure_interval));
107 /* perform measurement */
108 wprobe_sync_data(dev, NULL, false);
112 wprobe_add_iface(struct wprobe_iface *s)
117 /* reset only wprobe private area */
118 memset(&s->list, 0, sizeof(struct wprobe_iface) - offsetof(struct wprobe_iface, list));
121 INIT_LIST_HEAD(&s->list);
122 INIT_LIST_HEAD(&s->links);
123 setup_timer(&s->measure_timer, wprobe_measure_timer, (unsigned long) s);
125 s->val = kzalloc(sizeof(struct wprobe_value) * s->n_global_items, GFP_ATOMIC);
129 vsize = max(s->n_link_items, s->n_global_items);
130 s->query_val = kzalloc(sizeof(struct wprobe_value) * vsize, GFP_ATOMIC);
134 /* initialize defaults to be able to handle overflow,
135 * user space will need to handle this if it keeps an
136 * internal histogram */
138 s->scale_max = (1 << 31);
143 spin_lock_irqsave(&wprobe_lock, flags);
144 list_add_rcu(&s->list, &wprobe_if);
145 spin_unlock_irqrestore(&wprobe_lock, flags);
154 EXPORT_SYMBOL(wprobe_add_iface);
157 wprobe_remove_iface(struct wprobe_iface *s)
161 BUG_ON(!list_empty(&s->links));
163 del_timer_sync(&s->measure_timer);
164 spin_lock_irqsave(&wprobe_lock, flags);
165 list_del_rcu(&s->list);
166 spin_unlock_irqrestore(&wprobe_lock, flags);
168 /* wait for all queries to finish before freeing the
169 * temporary value storage buffer */
174 if (s->active_filter)
175 wprobe_free_filter(s->active_filter);
177 EXPORT_SYMBOL(wprobe_remove_iface);
179 static struct wprobe_iface *
180 wprobe_get_dev(struct nlattr *attr)
182 struct wprobe_iface *dev = NULL;
183 struct wprobe_iface *p;
190 name = nla_data(attr);
191 list_for_each_entry_rcu(p, &wprobe_if, list) {
193 if (strcmp(name, p->name) != 0)
204 wprobe_add_frame(struct wprobe_iface *dev, const struct wprobe_wlan_hdr *hdr, void *data, int len)
206 struct wprobe_filter *f;
212 f = rcu_dereference(dev->active_filter);
216 spin_lock_irqsave(&f->lock, flags);
219 skb->len = sizeof(struct wprobe_rtap_hdr);
220 skb->tail = skb->data + skb->len;
221 if (len + skb->len > WPROBE_MAX_FRAME_SIZE)
222 len = WPROBE_MAX_FRAME_SIZE - skb->len;
224 memcpy(skb_put(skb, f->hdrlen), hdr, sizeof(struct wprobe_wlan_hdr));
225 memcpy(skb_put(skb, len), data, len);
227 for(i = 0; i < f->n_groups; i++) {
228 struct wprobe_filter_group *fg = &f->groups[i];
232 for (j = 0; j < fg->n_items; j++) {
233 struct wprobe_filter_item *fi = fg->items[j];
235 if (!fi->hdr.n_items) {
239 if (sk_run_filter(skb, fi->filter, fi->hdr.n_items) == 0)
245 if (!found && def >= 0) {
250 struct wprobe_filter_counter *c = &fg->counters[j];
252 if (hdr->type >= WPROBE_PKT_TX)
259 spin_unlock_irqrestore(&f->lock, flags);
264 EXPORT_SYMBOL(wprobe_add_frame);
267 wprobe_sync_data(struct wprobe_iface *dev, struct wprobe_link *l, bool query)
269 struct wprobe_value *val;
274 n = dev->n_link_items;
277 n = dev->n_global_items;
281 spin_lock_irqsave(&dev->lock, flags);
282 err = dev->sync_data(dev, l, val, !query);
287 memcpy(dev->query_val, val, sizeof(struct wprobe_value) * n);
289 wprobe_update_stats(dev, l);
291 spin_unlock_irqrestore(&dev->lock, flags);
294 EXPORT_SYMBOL(wprobe_sync_data);
297 wprobe_scale_stats(struct wprobe_iface *dev, const struct wprobe_item *item,
298 struct wprobe_value *val, int n)
300 u64 scale_ts = jiffies_64;
303 for (i = 0; i < n; i++) {
304 if (!(item[i].flags & WPROBE_F_KEEPSTAT))
307 if (val[i].n <= dev->scale_min)
310 /* FIXME: div_s64 seems to be very imprecise here, even when
311 * the values are scaled up */
312 val[i].s *= dev->scale_m;
313 val[i].s = div_s64(val[i].s, dev->scale_d);
315 val[i].ss *= dev->scale_m;
316 val[i].ss = div_s64(val[i].ss, dev->scale_d);
318 val[i].n = (val[i].n * dev->scale_m) / dev->scale_d;
319 val[i].scale_timestamp = scale_ts;
325 wprobe_update_stats(struct wprobe_iface *dev, struct wprobe_link *l)
327 const struct wprobe_item *item;
328 struct wprobe_value *val;
329 bool scale_stats = false;
333 n = dev->n_link_items;
334 item = dev->link_items;
337 n = dev->n_global_items;
338 item = dev->global_items;
342 /* process statistics */
343 for (i = 0; i < n; i++) {
350 if ((item[i].flags & WPROBE_F_KEEPSTAT) &&
351 (dev->scale_max > 0) && (val[i].n > dev->scale_max)) {
355 switch(item[i].type) {
386 val[i].pending = false;
389 wprobe_scale_stats(dev, item, val, n);
391 EXPORT_SYMBOL(wprobe_update_stats);
393 static const struct nla_policy wprobe_policy[WPROBE_ATTR_LAST+1] = {
394 [WPROBE_ATTR_INTERFACE] = { .type = NLA_NUL_STRING },
395 [WPROBE_ATTR_MAC] = { .type = NLA_STRING },
396 [WPROBE_ATTR_FLAGS] = { .type = NLA_U32 },
399 [WPROBE_ATTR_INTERVAL] = { .type = NLA_MSECS },
400 [WPROBE_ATTR_SAMPLES_MIN] = { .type = NLA_U32 },
401 [WPROBE_ATTR_SAMPLES_MAX] = { .type = NLA_U32 },
402 [WPROBE_ATTR_SAMPLES_SCALE_M] = { .type = NLA_U32 },
403 [WPROBE_ATTR_SAMPLES_SCALE_D] = { .type = NLA_U32 },
404 [WPROBE_ATTR_FILTER] = { .type = NLA_BINARY, .len = 32768 },
408 wprobe_check_ptr(struct list_head *list, struct list_head *ptr)
412 list_for_each_rcu(p, list) {
420 wprobe_send_item_value(struct sk_buff *msg, struct netlink_callback *cb,
421 struct wprobe_iface *dev, struct wprobe_link *l,
422 const struct wprobe_item *item,
425 struct genlmsghdr *hdr;
426 struct wprobe_value *val = dev->query_val;
427 u64 time = val[i].last - val[i].first;
429 hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq,
430 &wprobe_fam, NLM_F_MULTI, WPROBE_CMD_GET_INFO);
432 NLA_PUT_U32(msg, WPROBE_ATTR_ID, i);
433 NLA_PUT_U32(msg, WPROBE_ATTR_FLAGS, flags);
434 NLA_PUT_U8(msg, WPROBE_ATTR_TYPE, item[i].type);
435 NLA_PUT_U64(msg, WPROBE_ATTR_DURATION, time);
437 switch(item[i].type) {
440 NLA_PUT_U8(msg, item[i].type, val[i].U8);
444 NLA_PUT_U16(msg, item[i].type, val[i].U16);
448 NLA_PUT_U32(msg, item[i].type, val[i].U32);
452 NLA_PUT_U64(msg, item[i].type, val[i].U64);
454 case WPROBE_VAL_STRING:
456 NLA_PUT_STRING(msg, item[i].type, val[i].STRING);
458 NLA_PUT_STRING(msg, item[i].type, "");
459 /* bypass avg/stdev */
462 /* skip unknown values */
465 if (item[i].flags & WPROBE_F_KEEPSTAT) {
466 NLA_PUT_U64(msg, WPROBE_VAL_SUM, val[i].s);
467 NLA_PUT_U64(msg, WPROBE_VAL_SUM_SQ, val[i].ss);
468 NLA_PUT_U32(msg, WPROBE_VAL_SAMPLES, (u32) val[i].n);
469 NLA_PUT_MSECS(msg, WPROBE_VAL_SCALE_TIME, val[i].scale_timestamp);
472 genlmsg_end(msg, hdr);
476 genlmsg_cancel(msg, hdr);
481 wprobe_send_item_info(struct sk_buff *msg, struct netlink_callback *cb,
482 struct wprobe_iface *dev,
483 const struct wprobe_item *item, int i)
485 struct genlmsghdr *hdr;
487 hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq,
488 &wprobe_fam, NLM_F_MULTI, WPROBE_CMD_GET_LIST);
490 if ((i == 0) && (dev->addr != NULL))
491 NLA_PUT(msg, WPROBE_ATTR_MAC, 6, dev->addr);
492 NLA_PUT_U32(msg, WPROBE_ATTR_ID, (u32) i);
493 NLA_PUT_STRING(msg, WPROBE_ATTR_NAME, item[i].name);
494 NLA_PUT_U8(msg, WPROBE_ATTR_TYPE, item[i].type);
495 NLA_PUT_U32(msg, WPROBE_ATTR_FLAGS, item[i].flags);
496 genlmsg_end(msg, hdr);
500 genlmsg_cancel(msg, hdr);
505 static struct wprobe_link *
506 wprobe_find_link(struct wprobe_iface *dev, const char *mac)
508 struct wprobe_link *l;
510 list_for_each_entry_rcu(l, &dev->links, list) {
511 if (!memcmp(l->addr, mac, 6))
518 wprobe_dump_filter_group(struct sk_buff *msg, struct wprobe_filter_group *fg, struct netlink_callback *cb)
520 struct genlmsghdr *hdr;
521 struct nlattr *group, *item;
524 hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq,
525 &wprobe_fam, NLM_F_MULTI, WPROBE_CMD_GET_FILTER);
529 NLA_PUT_STRING(msg, WPROBE_ATTR_NAME, fg->name);
530 group = nla_nest_start(msg, WPROBE_ATTR_FILTER_GROUP);
531 for (i = 0; i < fg->n_items; i++) {
532 struct wprobe_filter_item *fi = fg->items[i];
533 struct wprobe_filter_counter *fc = &fg->counters[i];
535 item = nla_nest_start(msg, WPROBE_ATTR_FILTER_GROUP);
536 NLA_PUT_STRING(msg, WPROBE_ATTR_NAME, fi->hdr.name);
537 NLA_PUT_U64(msg, WPROBE_ATTR_RXCOUNT, fc->rx);
538 NLA_PUT_U64(msg, WPROBE_ATTR_TXCOUNT, fc->tx);
539 nla_nest_end(msg, item);
542 nla_nest_end(msg, group);
543 genlmsg_end(msg, hdr);
547 genlmsg_cancel(msg, hdr);
552 wprobe_dump_filters(struct sk_buff *skb, struct netlink_callback *cb)
554 struct wprobe_iface *dev = (struct wprobe_iface *)cb->args[0];
555 struct wprobe_filter *f;
560 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + wprobe_fam.hdrsize,
561 wprobe_fam.attrbuf, wprobe_fam.maxattr, wprobe_policy);
565 dev = wprobe_get_dev(wprobe_fam.attrbuf[WPROBE_ATTR_INTERFACE]);
571 cb->args[0] = (long) dev;
574 if (!wprobe_check_ptr(&wprobe_if, &dev->list)) {
581 f = rcu_dereference(dev->active_filter);
585 for (i = cb->args[1]; i < f->n_groups; i++) {
586 if (unlikely(!wprobe_dump_filter_group(skb, &f->groups[i], cb)))
598 wprobe_dump_link(struct sk_buff *msg, struct wprobe_link *l, struct netlink_callback *cb)
600 struct genlmsghdr *hdr;
602 hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq,
603 &wprobe_fam, NLM_F_MULTI, WPROBE_CMD_GET_LINKS);
607 NLA_PUT(msg, WPROBE_ATTR_MAC, 6, l->addr);
608 genlmsg_end(msg, hdr);
612 genlmsg_cancel(msg, hdr);
617 wprobe_dump_links(struct sk_buff *skb, struct netlink_callback *cb)
619 struct wprobe_iface *dev = (struct wprobe_iface *)cb->args[0];
620 struct wprobe_link *l;
625 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + wprobe_fam.hdrsize,
626 wprobe_fam.attrbuf, wprobe_fam.maxattr, wprobe_policy);
630 dev = wprobe_get_dev(wprobe_fam.attrbuf[WPROBE_ATTR_INTERFACE]);
636 cb->args[0] = (long) dev;
638 if (!wprobe_check_ptr(&wprobe_if, &dev->list)) {
645 list_for_each_entry_rcu(l, &dev->links, list) {
649 if (unlikely(!wprobe_dump_link(skb, l, cb)))
661 #define WPROBE_F_LINK (1 << 31) /* for internal use */
663 wprobe_dump_info(struct sk_buff *skb, struct netlink_callback *cb)
665 struct wprobe_iface *dev = (struct wprobe_iface *)cb->args[0];
666 struct wprobe_link *l = (struct wprobe_link *)cb->args[1];
667 struct wprobe_value *val;
668 const struct wprobe_item *item;
669 struct genlmsghdr *hdr;
671 int cmd, n, i = cb->args[3];
672 u32 vflags = cb->args[2];
675 hdr = (struct genlmsghdr *)nlmsg_data(cb->nlh);
678 /* since the attribute value list might be too big for a single netlink
679 * message, the device, link and offset get stored in the netlink callback.
680 * if this is the first request, we need to do the full lookup for the device.
682 * access to the device and link structure is synchronized through rcu.
686 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + wprobe_fam.hdrsize,
687 wprobe_fam.attrbuf, wprobe_fam.maxattr, wprobe_policy);
692 dev = wprobe_get_dev(wprobe_fam.attrbuf[WPROBE_ATTR_INTERFACE]);
696 if (cmd == WPROBE_CMD_GET_INFO) {
697 if (wprobe_fam.attrbuf[WPROBE_ATTR_MAC]) {
698 l = wprobe_find_link(dev, nla_data(wprobe_fam.attrbuf[WPROBE_ATTR_MAC]));
706 item = dev->link_items;
707 n = dev->n_link_items;
710 item = dev->global_items;
711 n = dev->n_global_items;
715 /* sync data and move to temp storage for the query */
716 spin_lock_irqsave(&dev->lock, flags);
717 err = wprobe_sync_data(dev, l, true);
719 memcpy(dev->query_val, val, n * sizeof(struct wprobe_value));
720 spin_unlock_irqrestore(&dev->lock, flags);
726 if (wprobe_fam.attrbuf[WPROBE_ATTR_FLAGS])
727 vflags |= nla_get_u32(wprobe_fam.attrbuf[WPROBE_ATTR_FLAGS]);
729 if (wprobe_fam.attrbuf[WPROBE_ATTR_MAC])
730 vflags |= WPROBE_F_LINK;
732 cb->args[0] = (long) dev;
733 cb->args[1] = (long) l;
734 cb->args[2] = vflags;
737 /* when pulling pointers from the callback, validate them
738 * against the list using rcu to make sure that we won't
739 * dereference pointers to free'd memory after the last
742 if (!wprobe_check_ptr(&wprobe_if, &dev->list))
745 if (l && !wprobe_check_ptr(&dev->links, &l->list))
749 if (vflags & WPROBE_F_LINK) {
750 item = dev->link_items;
751 n = dev->n_link_items;
753 item = dev->global_items;
754 n = dev->n_global_items;
759 case WPROBE_CMD_GET_INFO:
761 if (!wprobe_send_item_value(skb, cb, dev, l, item, i, vflags))
766 case WPROBE_CMD_GET_LIST:
768 if (!wprobe_send_item_info(skb, cb, dev, item, i))
787 wprobe_update_auto_measurement(struct wprobe_iface *dev, u32 interval)
789 if (interval && (interval < WPROBE_MIN_INTERVAL))
792 if (!interval && dev->measure_interval)
793 del_timer_sync(&dev->measure_timer);
795 dev->measure_interval = interval;
799 /* kick of a new measurement immediately */
800 mod_timer(&dev->measure_timer, jiffies + 1);
806 wprobe_measure(struct sk_buff *skb, struct genl_info *info)
808 struct wprobe_iface *dev;
809 struct wprobe_link *l = NULL;
813 dev = wprobe_get_dev(info->attrs[WPROBE_ATTR_INTERFACE]);
817 if (info->attrs[WPROBE_ATTR_MAC]) {
818 l = wprobe_find_link(dev, nla_data(wprobe_fam.attrbuf[WPROBE_ATTR_MAC]));
823 err = wprobe_sync_data(dev, l, false);
831 wprobe_check_filter(void *data, int datalen, int gs)
833 struct wprobe_filter_item_hdr *hdr;
834 void *orig_data = data;
835 void *end = data + datalen;
836 int i, j, k, is, cur_is;
838 for (i = j = is = 0; i < gs; i++) {
840 data += sizeof(*hdr);
846 cur_is = be32_to_cpu(hdr->n_items);
847 hdr->n_items = cur_is;
849 for (j = 0; j < cur_is; j++) {
850 struct sock_filter *sf;
854 data += sizeof(*hdr);
859 n_items = be32_to_cpu(hdr->n_items);
860 hdr->n_items = n_items;
867 for (k = 0; k < n_items; k++) {
868 sf->code = be16_to_cpu(sf->code);
869 sf->k = be32_to_cpu(sf->k);
872 if (sk_chk_filter(data, n_items) != 0) {
873 printk("%s: filter check failed at group %d, item %d\n", __func__, i, j);
877 data += n_items * sizeof(struct sock_filter);
883 printk(KERN_ERR "%s: overrun during filter check at group %d, item %d, offset=%d, len=%d\n", __func__, i, j, (data - orig_data), datalen);
888 wprobe_free_filter(struct wprobe_filter *f)
903 wprobe_set_filter(struct wprobe_iface *dev, void *data, int len)
905 struct wprobe_filter_hdr *fhdr;
906 struct wprobe_rtap_hdr *rtap;
907 struct wprobe_filter *f;
908 int i, j, cur_is, is, gs;
910 if (len < sizeof(*fhdr))
914 data += sizeof(*fhdr);
915 len -= sizeof(*fhdr);
917 if (memcmp(fhdr->magic, "WPFF", 4) != 0) {
918 printk(KERN_ERR "%s: filter rejected (invalid magic)\n", __func__);
922 gs = be16_to_cpu(fhdr->n_groups);
923 is = wprobe_check_filter(data, len, gs);
927 f = kzalloc(sizeof(struct wprobe_filter) +
928 gs * sizeof(struct wprobe_filter_group), GFP_ATOMIC);
932 f->skb = alloc_skb(WPROBE_MAX_FRAME_SIZE, GFP_ATOMIC);
936 f->data = kmalloc(len, GFP_ATOMIC);
940 f->items = kzalloc(sizeof(struct wprobe_filter_item *) * is, GFP_ATOMIC);
944 f->counters = kzalloc(sizeof(struct wprobe_filter_counter) * is, GFP_ATOMIC);
948 spin_lock_init(&f->lock);
949 memcpy(f->data, data, len);
952 if (f->hdrlen < sizeof(struct wprobe_wlan_hdr))
953 f->hdrlen = sizeof(struct wprobe_wlan_hdr);
955 rtap = (struct wprobe_rtap_hdr *)skb_put(f->skb, sizeof(*rtap));
956 memset(rtap, 0, sizeof(*rtap));
957 rtap->len = cpu_to_le16(sizeof(struct wprobe_rtap_hdr) + f->hdrlen);
961 for (i = 0; i < gs; i++) {
962 struct wprobe_filter_item_hdr *hdr = data;
963 struct wprobe_filter_group *g = &f->groups[i];
965 data += sizeof(*hdr);
967 g->items = &f->items[cur_is];
968 g->counters = &f->counters[cur_is];
969 g->n_items = hdr->n_items;
971 for (j = 0; j < g->n_items; j++) {
973 f->items[cur_is++] = data;
974 data += sizeof(*hdr) + hdr->n_items * sizeof(struct sock_filter);
977 rcu_assign_pointer(dev->active_filter, f);
981 wprobe_free_filter(f);
986 wprobe_set_config(struct sk_buff *skb, struct genl_info *info)
988 struct wprobe_iface *dev;
991 u32 scale_min, scale_max;
992 u32 scale_m, scale_d;
994 struct wprobe_filter *filter_free = NULL;
997 dev = wprobe_get_dev(info->attrs[WPROBE_ATTR_INTERFACE]);
1002 spin_lock_irqsave(&dev->lock, flags);
1003 if (info->attrs[WPROBE_ATTR_MAC]) {
1004 /* not supported yet */
1008 if (info->attrs[WPROBE_ATTR_FLAGS]) {
1009 u32 flags = nla_get_u32(info->attrs[WPROBE_ATTR_FLAGS]);
1011 if (flags & BIT(WPROBE_F_RESET)) {
1012 struct wprobe_link *l;
1014 memset(dev->val, 0, sizeof(struct wprobe_value) * dev->n_global_items);
1015 list_for_each_entry_rcu(l, &dev->links, list) {
1016 memset(l->val, 0, sizeof(struct wprobe_value) * dev->n_link_items);
1021 if (info->attrs[WPROBE_ATTR_SAMPLES_MIN] ||
1022 info->attrs[WPROBE_ATTR_SAMPLES_MAX]) {
1023 if ((attr = info->attrs[WPROBE_ATTR_SAMPLES_MIN]))
1024 scale_min = nla_get_u32(attr);
1026 scale_min = dev->scale_min;
1028 if ((attr = info->attrs[WPROBE_ATTR_SAMPLES_MAX]))
1029 scale_max = nla_get_u32(attr);
1031 scale_max = dev->scale_max;
1033 if ((!scale_min && !scale_max) ||
1034 (scale_min && scale_max && (scale_min < scale_max))) {
1035 dev->scale_min = scale_min;
1036 dev->scale_max = scale_max;
1042 if (info->attrs[WPROBE_ATTR_SAMPLES_SCALE_M] &&
1043 info->attrs[WPROBE_ATTR_SAMPLES_SCALE_D]) {
1045 scale_m = nla_get_u32(info->attrs[WPROBE_ATTR_SAMPLES_SCALE_M]);
1046 scale_d = nla_get_u32(info->attrs[WPROBE_ATTR_SAMPLES_SCALE_D]);
1048 if (!scale_d || (scale_m > scale_d))
1051 dev->scale_m = scale_m;
1052 dev->scale_d = scale_d;
1055 if ((attr = info->attrs[WPROBE_ATTR_FILTER])) {
1056 filter_free = rcu_dereference(dev->active_filter);
1057 rcu_assign_pointer(dev->active_filter, NULL);
1058 if (nla_len(attr) > 0)
1059 wprobe_set_filter(dev, nla_data(attr), nla_len(attr));
1063 if (info->attrs[WPROBE_ATTR_INTERVAL]) {
1064 /* change of measurement interval requested */
1065 err = wprobe_update_auto_measurement(dev,
1066 (u32) nla_get_u64(info->attrs[WPROBE_ATTR_INTERVAL]));
1070 spin_unlock_irqrestore(&dev->lock, flags);
1075 wprobe_free_filter(filter_free);
1080 static struct genl_ops wprobe_ops[] = {
1082 .cmd = WPROBE_CMD_GET_INFO,
1083 .dumpit = wprobe_dump_info,
1084 .policy = wprobe_policy,
1087 .cmd = WPROBE_CMD_GET_LIST,
1088 .dumpit = wprobe_dump_info,
1089 .policy = wprobe_policy,
1092 .cmd = WPROBE_CMD_MEASURE,
1093 .doit = wprobe_measure,
1094 .policy = wprobe_policy,
1097 .cmd = WPROBE_CMD_GET_LINKS,
1098 .dumpit = wprobe_dump_links,
1099 .policy = wprobe_policy,
1102 .cmd = WPROBE_CMD_CONFIG,
1103 .doit = wprobe_set_config,
1104 .policy = wprobe_policy,
1107 .cmd = WPROBE_CMD_GET_FILTER,
1108 .dumpit = wprobe_dump_filters,
1109 .policy = wprobe_policy,
1116 BUG_ON(!list_empty(&wprobe_if));
1117 genl_unregister_family(&wprobe_fam);
1126 spin_lock_init(&wprobe_lock);
1127 INIT_LIST_HEAD(&wprobe_if);
1129 err = genl_register_family(&wprobe_fam);
1133 for (i = 0; i < ARRAY_SIZE(wprobe_ops); i++) {
1134 err = genl_register_ops(&wprobe_fam, &wprobe_ops[i]);
1142 genl_unregister_family(&wprobe_fam);
1146 module_init(wprobe_init);
1147 module_exit(wprobe_exit);
1148 MODULE_LICENSE("GPL");