This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / net / core / gen_stats.c
1 /*
2  * net/core/gen_stats.c
3  *
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.
8  *
9  * Authors:  Thomas Graf <tgraf@suug.ch>
10  *           Jamal Hadi Salim
11  *           Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
12  *
13  * See Documentation/networking/gen_stats.txt
14  */
15
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>
24
25
26 static inline int
27 gnet_stats_copy(struct gnet_dump *d, int type, void *buf, int size)
28 {
29         RTA_PUT(d->skb, type, size, buf);
30         return 0;
31
32 rtattr_failure:
33         spin_unlock_bh(d->lock);
34         return -1;
35 }
36
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)
40 {
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;
48
49         if (d->compat_tc_stats)
50                 memset(&d->tc_stats, 0, sizeof(d->tc_stats));
51
52         return gnet_stats_copy(d, type, NULL, 0);
53 }
54
55 int
56 gnet_stats_start_copy(struct sk_buff *skb, int type, spinlock_t *lock,
57         struct gnet_dump *d)
58 {
59         return gnet_stats_start_copy_compat(skb, type, 0, 0, lock, d);
60 }
61
62
63 int
64 gnet_stats_copy_basic(struct gnet_dump *d, struct gnet_stats_basic *b)
65 {
66         if (d->compat_tc_stats) {
67                 d->tc_stats.bytes = b->bytes;
68                 d->tc_stats.packets = b->packets;
69         }
70         
71         return gnet_stats_copy(d, TCA_STATS_BASIC, b, sizeof(*b));
72 }
73
74 int
75 gnet_stats_copy_rate_est(struct gnet_dump *d, struct gnet_stats_rate_est *r)
76 {
77         if (d->compat_tc_stats) {
78                 d->tc_stats.bps = r->bps;
79                 d->tc_stats.pps = r->pps;
80         }
81
82         return gnet_stats_copy(d, TCA_STATS_RATE_EST, r, sizeof(*r));
83 }
84
85 int
86 gnet_stats_copy_queue(struct gnet_dump *d, struct gnet_stats_queue *q)
87 {
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;
93         }
94                 
95         return gnet_stats_copy(d, TCA_STATS_QUEUE, q, sizeof(*q));
96 }
97
98 int
99 gnet_stats_copy_app(struct gnet_dump *d, void *st, int len)
100 {
101         if (d->compat_xstats)
102                 d->xstats = (struct rtattr *) d->skb->tail;
103         return gnet_stats_copy(d, TCA_STATS_APP, st, len);
104 }
105
106 int
107 gnet_stats_finish_copy(struct gnet_dump *d)
108 {
109         d->tail->rta_len = d->skb->tail - (u8 *) d->tail;
110
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;
115
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;
120         }
121
122         spin_unlock_bh(d->lock);
123         return 0;
124 }
125
126
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);