MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / net / core / gen_stats.c
blob2b2ba6570b8b62b4ece51269c7d4d5df6bb8e9ee
1 /*
2 * net/core/gen_stats.c
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Thomas Graf <tgraf@suug.ch>
10 * Jamal Hadi Salim
11 * Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
13 * See Documentation/networking/gen_stats.txt
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/interrupt.h>
20 #include <linux/socket.h>
21 #include <linux/rtnetlink.h>
22 #include <linux/gen_stats.h>
23 #include <net/gen_stats.h>
26 static inline int
27 gnet_stats_copy(struct gnet_dump *d, int type, void *buf, int size)
29 RTA_PUT(d->skb, type, size, buf);
30 return 0;
32 rtattr_failure:
33 spin_unlock_bh(d->lock);
34 return -1;
37 int
38 gnet_stats_start_copy_compat(struct sk_buff *skb, int type, int tc_stats_type,
39 int xstats_type, spinlock_t *lock, struct gnet_dump *d)
41 spin_lock_bh(lock);
42 d->lock = lock;
43 d->tail = (struct rtattr *) skb->tail;
44 d->skb = skb;
45 d->compat_tc_stats = tc_stats_type;
46 d->compat_xstats = xstats_type;
47 d->xstats = NULL;
49 if (d->compat_tc_stats)
50 memset(&d->tc_stats, 0, sizeof(d->tc_stats));
52 return gnet_stats_copy(d, type, NULL, 0);
55 int
56 gnet_stats_start_copy(struct sk_buff *skb, int type, spinlock_t *lock,
57 struct gnet_dump *d)
59 return gnet_stats_start_copy_compat(skb, type, 0, 0, lock, d);
63 int
64 gnet_stats_copy_basic(struct gnet_dump *d, struct gnet_stats_basic *b)
66 if (d->compat_tc_stats) {
67 d->tc_stats.bytes = b->bytes;
68 d->tc_stats.packets = b->packets;
71 return gnet_stats_copy(d, TCA_STATS_BASIC, b, sizeof(*b));
74 int
75 gnet_stats_copy_rate_est(struct gnet_dump *d, struct gnet_stats_rate_est *r)
77 if (d->compat_tc_stats) {
78 d->tc_stats.bps = r->bps;
79 d->tc_stats.pps = r->pps;
82 return gnet_stats_copy(d, TCA_STATS_RATE_EST, r, sizeof(*r));
85 int
86 gnet_stats_copy_queue(struct gnet_dump *d, struct gnet_stats_queue *q)
88 if (d->compat_tc_stats) {
89 d->tc_stats.drops = q->drops;
90 d->tc_stats.qlen = q->qlen;
91 d->tc_stats.backlog = q->backlog;
92 d->tc_stats.overlimits = q->overlimits;
95 return gnet_stats_copy(d, TCA_STATS_QUEUE, q, sizeof(*q));
98 int
99 gnet_stats_copy_app(struct gnet_dump *d, void *st, int len)
101 if (d->compat_xstats)
102 d->xstats = (struct rtattr *) d->skb->tail;
103 return gnet_stats_copy(d, TCA_STATS_APP, st, len);
107 gnet_stats_finish_copy(struct gnet_dump *d)
109 d->tail->rta_len = d->skb->tail - (u8 *) d->tail;
111 if (d->compat_tc_stats)
112 if (gnet_stats_copy(d, d->compat_tc_stats, &d->tc_stats,
113 sizeof(d->tc_stats)) < 0)
114 return -1;
116 if (d->compat_xstats && d->xstats) {
117 if (gnet_stats_copy(d, d->compat_xstats, RTA_DATA(d->xstats),
118 RTA_PAYLOAD(d->xstats)) < 0)
119 return -1;
122 spin_unlock_bh(d->lock);
123 return 0;
127 EXPORT_SYMBOL(gnet_stats_start_copy);
128 EXPORT_SYMBOL(gnet_stats_copy_basic);
129 EXPORT_SYMBOL(gnet_stats_copy_rate_est);
130 EXPORT_SYMBOL(gnet_stats_copy_queue);
131 EXPORT_SYMBOL(gnet_stats_copy_app);
132 EXPORT_SYMBOL(gnet_stats_finish_copy);