aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/net/ip.h20
-rw-r--r--include/net/ipv6.h12
-rw-r--r--include/net/snmp.h75
-rw-r--r--net/ipv4/af_inet.c36
-rw-r--r--net/ipv4/proc.c15
-rw-r--r--net/ipv6/addrconf.c18
-rw-r--r--net/ipv6/proc.c17
7 files changed, 167 insertions, 26 deletions
diff --git a/include/net/ip.h b/include/net/ip.h
index 3b524df7dddb..890f9725d681 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -165,12 +165,12 @@ struct ipv4_config {
165}; 165};
166 166
167extern struct ipv4_config ipv4_config; 167extern struct ipv4_config ipv4_config;
168#define IP_INC_STATS(net, field) SNMP_INC_STATS((net)->mib.ip_statistics, field) 168#define IP_INC_STATS(net, field) SNMP_INC_STATS64((net)->mib.ip_statistics, field)
169#define IP_INC_STATS_BH(net, field) SNMP_INC_STATS_BH((net)->mib.ip_statistics, field) 169#define IP_INC_STATS_BH(net, field) SNMP_INC_STATS64_BH((net)->mib.ip_statistics, field)
170#define IP_ADD_STATS(net, field, val) SNMP_ADD_STATS((net)->mib.ip_statistics, field, val) 170#define IP_ADD_STATS(net, field, val) SNMP_ADD_STATS64((net)->mib.ip_statistics, field, val)
171#define IP_ADD_STATS_BH(net, field, val) SNMP_ADD_STATS_BH((net)->mib.ip_statistics, field, val) 171#define IP_ADD_STATS_BH(net, field, val) SNMP_ADD_STATS64_BH((net)->mib.ip_statistics, field, val)
172#define IP_UPD_PO_STATS(net, field, val) SNMP_UPD_PO_STATS((net)->mib.ip_statistics, field, val) 172#define IP_UPD_PO_STATS(net, field, val) SNMP_UPD_PO_STATS64((net)->mib.ip_statistics, field, val)
173#define IP_UPD_PO_STATS_BH(net, field, val) SNMP_UPD_PO_STATS_BH((net)->mib.ip_statistics, field, val) 173#define IP_UPD_PO_STATS_BH(net, field, val) SNMP_UPD_PO_STATS64_BH((net)->mib.ip_statistics, field, val)
174#define NET_INC_STATS(net, field) SNMP_INC_STATS((net)->mib.net_statistics, field) 174#define NET_INC_STATS(net, field) SNMP_INC_STATS((net)->mib.net_statistics, field)
175#define NET_INC_STATS_BH(net, field) SNMP_INC_STATS_BH((net)->mib.net_statistics, field) 175#define NET_INC_STATS_BH(net, field) SNMP_INC_STATS_BH((net)->mib.net_statistics, field)
176#define NET_INC_STATS_USER(net, field) SNMP_INC_STATS_USER((net)->mib.net_statistics, field) 176#define NET_INC_STATS_USER(net, field) SNMP_INC_STATS_USER((net)->mib.net_statistics, field)
@@ -178,6 +178,14 @@ extern struct ipv4_config ipv4_config;
178#define NET_ADD_STATS_USER(net, field, adnd) SNMP_ADD_STATS_USER((net)->mib.net_statistics, field, adnd) 178#define NET_ADD_STATS_USER(net, field, adnd) SNMP_ADD_STATS_USER((net)->mib.net_statistics, field, adnd)
179 179
180extern unsigned long snmp_fold_field(void __percpu *mib[], int offt); 180extern unsigned long snmp_fold_field(void __percpu *mib[], int offt);
181#if BITS_PER_LONG==32
182extern u64 snmp_fold_field64(void __percpu *mib[], int offt, size_t sync_off);
183#else
184static inline u64 snmp_fold_field64(void __percpu *mib[], int offt, size_t syncp_off)
185{
186 return snmp_fold_field(mib, offt);
187}
188#endif
181extern int snmp_mib_init(void __percpu *ptr[2], size_t mibsize, size_t align); 189extern int snmp_mib_init(void __percpu *ptr[2], size_t mibsize, size_t align);
182extern void snmp_mib_free(void __percpu *ptr[2]); 190extern void snmp_mib_free(void __percpu *ptr[2]);
183 191
diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index f5808d596aab..1f8412410998 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -136,17 +136,17 @@ extern struct ctl_path net_ipv6_ctl_path[];
136/* MIBs */ 136/* MIBs */
137 137
138#define IP6_INC_STATS(net, idev,field) \ 138#define IP6_INC_STATS(net, idev,field) \
139 _DEVINC(net, ipv6, , idev, field) 139 _DEVINC(net, ipv6, 64, idev, field)
140#define IP6_INC_STATS_BH(net, idev,field) \ 140#define IP6_INC_STATS_BH(net, idev,field) \
141 _DEVINC(net, ipv6, _BH, idev, field) 141 _DEVINC(net, ipv6, 64_BH, idev, field)
142#define IP6_ADD_STATS(net, idev,field,val) \ 142#define IP6_ADD_STATS(net, idev,field,val) \
143 _DEVADD(net, ipv6, , idev, field, val) 143 _DEVADD(net, ipv6, 64, idev, field, val)
144#define IP6_ADD_STATS_BH(net, idev,field,val) \ 144#define IP6_ADD_STATS_BH(net, idev,field,val) \
145 _DEVADD(net, ipv6, _BH, idev, field, val) 145 _DEVADD(net, ipv6, 64_BH, idev, field, val)
146#define IP6_UPD_PO_STATS(net, idev,field,val) \ 146#define IP6_UPD_PO_STATS(net, idev,field,val) \
147 _DEVUPD(net, ipv6, , idev, field, val) 147 _DEVUPD(net, ipv6, 64, idev, field, val)
148#define IP6_UPD_PO_STATS_BH(net, idev,field,val) \ 148#define IP6_UPD_PO_STATS_BH(net, idev,field,val) \
149 _DEVUPD(net, ipv6, _BH, idev, field, val) 149 _DEVUPD(net, ipv6, 64_BH, idev, field, val)
150#define ICMP6_INC_STATS(net, idev, field) \ 150#define ICMP6_INC_STATS(net, idev, field) \
151 _DEVINC(net, icmpv6, , idev, field) 151 _DEVINC(net, icmpv6, , idev, field)
152#define ICMP6_INC_STATS_BH(net, idev, field) \ 152#define ICMP6_INC_STATS_BH(net, idev, field) \
diff --git a/include/net/snmp.h b/include/net/snmp.h
index 899003d18db9..a0e61806d480 100644
--- a/include/net/snmp.h
+++ b/include/net/snmp.h
@@ -47,15 +47,16 @@ struct snmp_mib {
47} 47}
48 48
49/* 49/*
50 * We use all unsigned longs. Linux will soon be so reliable that even 50 * We use unsigned longs for most mibs but u64 for ipstats.
51 * these will rapidly get too small 8-). Seriously consider the IpInReceives
52 * count on the 20Gb/s + networks people expect in a few years time!
53 */ 51 */
52#include <linux/u64_stats_sync.h>
54 53
55/* IPstats */ 54/* IPstats */
56#define IPSTATS_MIB_MAX __IPSTATS_MIB_MAX 55#define IPSTATS_MIB_MAX __IPSTATS_MIB_MAX
57struct ipstats_mib { 56struct ipstats_mib {
58 unsigned long mibs[IPSTATS_MIB_MAX]; 57 /* mibs[] must be first field of struct ipstats_mib */
58 u64 mibs[IPSTATS_MIB_MAX];
59 struct u64_stats_sync syncp;
59}; 60};
60 61
61/* ICMP */ 62/* ICMP */
@@ -155,4 +156,70 @@ struct linux_xfrm_mib {
155 ptr->mibs[basefield##PKTS]++; \ 156 ptr->mibs[basefield##PKTS]++; \
156 ptr->mibs[basefield##OCTETS] += addend;\ 157 ptr->mibs[basefield##OCTETS] += addend;\
157 } while (0) 158 } while (0)
159
160
161#if BITS_PER_LONG==32
162
163#define SNMP_ADD_STATS64_BH(mib, field, addend) \
164 do { \
165 __typeof__(*mib[0]) *ptr = __this_cpu_ptr((mib)[0]); \
166 u64_stats_update_begin(&ptr->syncp); \
167 ptr->mibs[field] += addend; \
168 u64_stats_update_end(&ptr->syncp); \
169 } while (0)
170#define SNMP_ADD_STATS64_USER(mib, field, addend) \
171 do { \
172 __typeof__(*mib[0]) *ptr; \
173 preempt_disable(); \
174 ptr = __this_cpu_ptr((mib)[1]); \
175 u64_stats_update_begin(&ptr->syncp); \
176 ptr->mibs[field] += addend; \
177 u64_stats_update_end(&ptr->syncp); \
178 preempt_enable(); \
179 } while (0)
180#define SNMP_ADD_STATS64(mib, field, addend) \
181 do { \
182 __typeof__(*mib[0]) *ptr; \
183 preempt_disable(); \
184 ptr = __this_cpu_ptr((mib)[!in_softirq()]); \
185 u64_stats_update_begin(&ptr->syncp); \
186 ptr->mibs[field] += addend; \
187 u64_stats_update_end(&ptr->syncp); \
188 preempt_enable(); \
189 } while (0)
190#define SNMP_INC_STATS64_BH(mib, field) SNMP_ADD_STATS64_BH(mib, field, 1)
191#define SNMP_INC_STATS64_USER(mib, field) SNMP_ADD_STATS64_USER(mib, field, 1)
192#define SNMP_INC_STATS64(mib, field) SNMP_ADD_STATS64(mib, field, 1)
193#define SNMP_UPD_PO_STATS64(mib, basefield, addend) \
194 do { \
195 __typeof__(*mib[0]) *ptr; \
196 preempt_disable(); \
197 ptr = __this_cpu_ptr((mib)[!in_softirq()]); \
198 u64_stats_update_begin(&ptr->syncp); \
199 ptr->mibs[basefield##PKTS]++; \
200 ptr->mibs[basefield##OCTETS] += addend; \
201 u64_stats_update_end(&ptr->syncp); \
202 preempt_enable(); \
203 } while (0)
204#define SNMP_UPD_PO_STATS64_BH(mib, basefield, addend) \
205 do { \
206 __typeof__(*mib[0]) *ptr; \
207 ptr = __this_cpu_ptr((mib)[!in_softirq()]); \
208 u64_stats_update_begin(&ptr->syncp); \
209 ptr->mibs[basefield##PKTS]++; \
210 ptr->mibs[basefield##OCTETS] += addend; \
211 u64_stats_update_end(&ptr->syncp); \
212 } while (0)
213#else
214#define SNMP_INC_STATS64_BH(mib, field) SNMP_INC_STATS_BH(mib, field)
215#define SNMP_INC_STATS64_USER(mib, field) SNMP_INC_STATS_USER(mib, field)
216#define SNMP_INC_STATS64(mib, field) SNMP_INC_STATS(mib, field)
217#define SNMP_DEC_STATS64(mib, field) SNMP_DEC_STATS(mib, field)
218#define SNMP_ADD_STATS64_BH(mib, field, addend) SNMP_ADD_STATS_BH(mib, field, addend)
219#define SNMP_ADD_STATS64_USER(mib, field, addend) SNMP_ADD_STATS_USER(mib, field, addend)
220#define SNMP_ADD_STATS64(mib, field, addend) SNMP_ADD_STATS(mib, field, addend)
221#define SNMP_UPD_PO_STATS64(mib, basefield, addend) SNMP_UPD_PO_STATS(mib, basefield, addend)
222#define SNMP_UPD_PO_STATS64_BH(mib, basefield, addend) SNMP_UPD_PO_STATS_BH(mib, basefield, addend)
223#endif
224
158#endif 225#endif
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 640db9b90330..3ceb025b16f2 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1427,6 +1427,42 @@ unsigned long snmp_fold_field(void __percpu *mib[], int offt)
1427} 1427}
1428EXPORT_SYMBOL_GPL(snmp_fold_field); 1428EXPORT_SYMBOL_GPL(snmp_fold_field);
1429 1429
1430#if BITS_PER_LONG==32
1431
1432u64 snmp_fold_field64(void __percpu *mib[], int offt, size_t syncp_offset)
1433{
1434 u64 res = 0;
1435 int cpu;
1436
1437 for_each_possible_cpu(cpu) {
1438 void *bhptr, *userptr;
1439 struct u64_stats_sync *syncp;
1440 u64 v_bh, v_user;
1441 unsigned int start;
1442
1443 /* first mib used by softirq context, we must use _bh() accessors */
1444 bhptr = per_cpu_ptr(SNMP_STAT_BHPTR(mib), cpu);
1445 syncp = (struct u64_stats_sync *)(bhptr + syncp_offset);
1446 do {
1447 start = u64_stats_fetch_begin_bh(syncp);
1448 v_bh = *(((u64 *) bhptr) + offt);
1449 } while (u64_stats_fetch_retry_bh(syncp, start));
1450
1451 /* second mib used in USER context */
1452 userptr = per_cpu_ptr(SNMP_STAT_USRPTR(mib), cpu);
1453 syncp = (struct u64_stats_sync *)(userptr + syncp_offset);
1454 do {
1455 start = u64_stats_fetch_begin(syncp);
1456 v_user = *(((u64 *) userptr) + offt);
1457 } while (u64_stats_fetch_retry(syncp, start));
1458
1459 res += v_bh + v_user;
1460 }
1461 return res;
1462}
1463EXPORT_SYMBOL_GPL(snmp_fold_field64);
1464#endif
1465
1430int snmp_mib_init(void __percpu *ptr[2], size_t mibsize, size_t align) 1466int snmp_mib_init(void __percpu *ptr[2], size_t mibsize, size_t align)
1431{ 1467{
1432 BUG_ON(ptr == NULL); 1468 BUG_ON(ptr == NULL);
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index e320ca6b3ef3..4ae1f203f7cb 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -343,10 +343,12 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
343 IPV4_DEVCONF_ALL(net, FORWARDING) ? 1 : 2, 343 IPV4_DEVCONF_ALL(net, FORWARDING) ? 1 : 2,
344 sysctl_ip_default_ttl); 344 sysctl_ip_default_ttl);
345 345
346 BUILD_BUG_ON(offsetof(struct ipstats_mib, mibs) != 0);
346 for (i = 0; snmp4_ipstats_list[i].name != NULL; i++) 347 for (i = 0; snmp4_ipstats_list[i].name != NULL; i++)
347 seq_printf(seq, " %lu", 348 seq_printf(seq, " %llu",
348 snmp_fold_field((void __percpu **)net->mib.ip_statistics, 349 snmp_fold_field64((void __percpu **)net->mib.ip_statistics,
349 snmp4_ipstats_list[i].entry)); 350 snmp4_ipstats_list[i].entry,
351 offsetof(struct ipstats_mib, syncp)));
350 352
351 icmp_put(seq); /* RFC 2011 compatibility */ 353 icmp_put(seq); /* RFC 2011 compatibility */
352 icmpmsg_put(seq); 354 icmpmsg_put(seq);
@@ -432,9 +434,10 @@ static int netstat_seq_show(struct seq_file *seq, void *v)
432 434
433 seq_puts(seq, "\nIpExt:"); 435 seq_puts(seq, "\nIpExt:");
434 for (i = 0; snmp4_ipextstats_list[i].name != NULL; i++) 436 for (i = 0; snmp4_ipextstats_list[i].name != NULL; i++)
435 seq_printf(seq, " %lu", 437 seq_printf(seq, " %llu",
436 snmp_fold_field((void __percpu **)net->mib.ip_statistics, 438 snmp_fold_field64((void __percpu **)net->mib.ip_statistics,
437 snmp4_ipextstats_list[i].entry)); 439 snmp4_ipextstats_list[i].entry,
440 offsetof(struct ipstats_mib, syncp)));
438 441
439 seq_putc(seq, '\n'); 442 seq_putc(seq, '\n');
440 return 0; 443 return 0;
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 2514adf5251e..e81155d2f251 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -3862,12 +3862,28 @@ static inline void __snmp6_fill_stats(u64 *stats, void __percpu **mib,
3862 memset(&stats[items], 0, pad); 3862 memset(&stats[items], 0, pad);
3863} 3863}
3864 3864
3865static inline void __snmp6_fill_stats64(u64 *stats, void __percpu **mib,
3866 int items, int bytes, size_t syncpoff)
3867{
3868 int i;
3869 int pad = bytes - sizeof(u64) * items;
3870 BUG_ON(pad < 0);
3871
3872 /* Use put_unaligned() because stats may not be aligned for u64. */
3873 put_unaligned(items, &stats[0]);
3874 for (i = 1; i < items; i++)
3875 put_unaligned(snmp_fold_field64(mib, i, syncpoff), &stats[i]);
3876
3877 memset(&stats[items], 0, pad);
3878}
3879
3865static void snmp6_fill_stats(u64 *stats, struct inet6_dev *idev, int attrtype, 3880static void snmp6_fill_stats(u64 *stats, struct inet6_dev *idev, int attrtype,
3866 int bytes) 3881 int bytes)
3867{ 3882{
3868 switch (attrtype) { 3883 switch (attrtype) {
3869 case IFLA_INET6_STATS: 3884 case IFLA_INET6_STATS:
3870 __snmp6_fill_stats(stats, (void __percpu **)idev->stats.ipv6, IPSTATS_MIB_MAX, bytes); 3885 __snmp6_fill_stats64(stats, (void __percpu **)idev->stats.ipv6,
3886 IPSTATS_MIB_MAX, bytes, offsetof(struct ipstats_mib, syncp));
3871 break; 3887 break;
3872 case IFLA_INET6_ICMP6STATS: 3888 case IFLA_INET6_ICMP6STATS:
3873 __snmp6_fill_stats(stats, (void __percpu **)idev->stats.icmpv6, ICMP6_MIB_MAX, bytes); 3889 __snmp6_fill_stats(stats, (void __percpu **)idev->stats.icmpv6, ICMP6_MIB_MAX, bytes);
diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
index 566798d69f37..d082eaeefa25 100644
--- a/net/ipv6/proc.c
+++ b/net/ipv6/proc.c
@@ -174,17 +174,28 @@ static void snmp6_seq_show_item(struct seq_file *seq, void __percpu **mib,
174 const struct snmp_mib *itemlist) 174 const struct snmp_mib *itemlist)
175{ 175{
176 int i; 176 int i;
177 for (i=0; itemlist[i].name; i++) 177
178 for (i = 0; itemlist[i].name; i++)
178 seq_printf(seq, "%-32s\t%lu\n", itemlist[i].name, 179 seq_printf(seq, "%-32s\t%lu\n", itemlist[i].name,
179 snmp_fold_field(mib, itemlist[i].entry)); 180 snmp_fold_field(mib, itemlist[i].entry));
180} 181}
181 182
183static void snmp6_seq_show_item64(struct seq_file *seq, void __percpu **mib,
184 const struct snmp_mib *itemlist, size_t syncpoff)
185{
186 int i;
187
188 for (i = 0; itemlist[i].name; i++)
189 seq_printf(seq, "%-32s\t%llu\n", itemlist[i].name,
190 snmp_fold_field64(mib, itemlist[i].entry, syncpoff));
191}
192
182static int snmp6_seq_show(struct seq_file *seq, void *v) 193static int snmp6_seq_show(struct seq_file *seq, void *v)
183{ 194{
184 struct net *net = (struct net *)seq->private; 195 struct net *net = (struct net *)seq->private;
185 196
186 snmp6_seq_show_item(seq, (void __percpu **)net->mib.ipv6_statistics, 197 snmp6_seq_show_item64(seq, (void __percpu **)net->mib.ipv6_statistics,
187 snmp6_ipstats_list); 198 snmp6_ipstats_list, offsetof(struct ipstats_mib, syncp));
188 snmp6_seq_show_item(seq, (void __percpu **)net->mib.icmpv6_statistics, 199 snmp6_seq_show_item(seq, (void __percpu **)net->mib.icmpv6_statistics,
189 snmp6_icmp6_list); 200 snmp6_icmp6_list);
190 snmp6_seq_show_icmpv6msg(seq, 201 snmp6_seq_show_icmpv6msg(seq,