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>
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>
27 gnet_stats_copy(struct gnet_dump *d, int type, void *buf, int size)
29 RTA_PUT(d->skb, type, size, buf);
33 spin_unlock_bh(d->lock);
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)
43 d->tail = (struct rtattr *) skb->tail;
45 d->compat_tc_stats = tc_stats_type;
46 d->compat_xstats = xstats_type;
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);
56 gnet_stats_start_copy(struct sk_buff *skb, int type, spinlock_t *lock,
59 return gnet_stats_start_copy_compat(skb, type, 0, 0, lock, d);
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));
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));
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));
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)
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)
122 spin_unlock_bh(d->lock);
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);