Skip to content

Commit b01a240

Browse files
ebiedermdavem330
authored andcommitted
sctp: Make the mib per network namespace
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Acked-by: Vlad Yasevich <vyasevich@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent bb2db45 commit b01a240

13 files changed

Lines changed: 158 additions & 119 deletions

File tree

‎include/net/netns/sctp.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
struct sock;
55
struct proc_dir_entry;
6+
struct sctp_mib;
67

78
struct netns_sctp {
9+
DEFINE_SNMP_STAT(struct sctp_mib, sctp_statistics);
10+
811
#ifdef CONFIG_PROC_FS
912
struct proc_dir_entry *proc_net_sctp;
1013
#endif

‎include/net/sctp/sctp.h‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,10 @@ extern struct kmem_cache *sctp_bucket_cachep __read_mostly;
221221
#define sctp_bh_unlock_sock(sk) bh_unlock_sock(sk)
222222

223223
/* SCTP SNMP MIB stats handlers */
224-
DECLARE_SNMP_STAT(struct sctp_mib, sctp_statistics);
225-
#define SCTP_INC_STATS(field) SNMP_INC_STATS(sctp_statistics, field)
226-
#define SCTP_INC_STATS_BH(field) SNMP_INC_STATS_BH(sctp_statistics, field)
227-
#define SCTP_INC_STATS_USER(field) SNMP_INC_STATS_USER(sctp_statistics, field)
228-
#define SCTP_DEC_STATS(field) SNMP_DEC_STATS(sctp_statistics, field)
224+
#define SCTP_INC_STATS(net, field) SNMP_INC_STATS((net)->sctp.sctp_statistics, field)
225+
#define SCTP_INC_STATS_BH(net, field) SNMP_INC_STATS_BH((net)->sctp.sctp_statistics, field)
226+
#define SCTP_INC_STATS_USER(net, field) SNMP_INC_STATS_USER((net)->sctp.sctp_statistics, field)
227+
#define SCTP_DEC_STATS(net, field) SNMP_DEC_STATS((net)->sctp.sctp_statistics, field)
229228

230229
#endif /* !TEST_FRAME */
231230

‎net/sctp/associola.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ static void sctp_assoc_bh_rcv(struct work_struct *work)
11501150
if (sctp_chunk_is_data(chunk))
11511151
asoc->peer.last_data_from = chunk->transport;
11521152
else
1153-
SCTP_INC_STATS(SCTP_MIB_INCTRLCHUNKS);
1153+
SCTP_INC_STATS(sock_net(asoc->base.sk), SCTP_MIB_INCTRLCHUNKS);
11541154

11551155
if (chunk->transport)
11561156
chunk->transport->last_time_heard = jiffies;

‎net/sctp/chunk.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
257257
offset = 0;
258258

259259
if ((whole > 1) || (whole && over))
260-
SCTP_INC_STATS_USER(SCTP_MIB_FRAGUSRMSGS);
260+
SCTP_INC_STATS_USER(sock_net(asoc->base.sk), SCTP_MIB_FRAGUSRMSGS);
261261

262262
/* Create chunks for all the full sized DATA chunks. */
263263
for (i=0, len=first_len; i < whole; i++) {

‎net/sctp/endpointola.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ static void sctp_endpoint_bh_rcv(struct work_struct *work)
478478
if (asoc && sctp_chunk_is_data(chunk))
479479
asoc->peer.last_data_from = chunk->transport;
480480
else
481-
SCTP_INC_STATS(SCTP_MIB_INCTRLCHUNKS);
481+
SCTP_INC_STATS(sock_net(ep->base.sk), SCTP_MIB_INCTRLCHUNKS);
482482

483483
if (chunk->transport)
484484
chunk->transport->last_time_heard = jiffies;

‎net/sctp/input.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static int sctp_add_backlog(struct sock *sk, struct sk_buff *skb);
8383

8484

8585
/* Calculate the SCTP checksum of an SCTP packet. */
86-
static inline int sctp_rcv_checksum(struct sk_buff *skb)
86+
static inline int sctp_rcv_checksum(struct net *net, struct sk_buff *skb)
8787
{
8888
struct sctphdr *sh = sctp_hdr(skb);
8989
__le32 cmp = sh->checksum;
@@ -99,7 +99,7 @@ static inline int sctp_rcv_checksum(struct sk_buff *skb)
9999

100100
if (val != cmp) {
101101
/* CRC failure, dump it. */
102-
SCTP_INC_STATS_BH(SCTP_MIB_CHECKSUMERRORS);
102+
SCTP_INC_STATS_BH(net, SCTP_MIB_CHECKSUMERRORS);
103103
return -1;
104104
}
105105
return 0;
@@ -137,7 +137,7 @@ int sctp_rcv(struct sk_buff *skb)
137137
if (skb->pkt_type!=PACKET_HOST)
138138
goto discard_it;
139139

140-
SCTP_INC_STATS_BH(SCTP_MIB_INSCTPPACKS);
140+
SCTP_INC_STATS_BH(net, SCTP_MIB_INSCTPPACKS);
141141

142142
if (skb_linearize(skb))
143143
goto discard_it;
@@ -149,7 +149,7 @@ int sctp_rcv(struct sk_buff *skb)
149149
if (skb->len < sizeof(struct sctphdr))
150150
goto discard_it;
151151
if (!sctp_checksum_disable && !skb_csum_unnecessary(skb) &&
152-
sctp_rcv_checksum(skb) < 0)
152+
sctp_rcv_checksum(net, skb) < 0)
153153
goto discard_it;
154154

155155
skb_pull(skb, sizeof(struct sctphdr));
@@ -220,7 +220,7 @@ int sctp_rcv(struct sk_buff *skb)
220220
*/
221221
if (!asoc) {
222222
if (sctp_rcv_ootb(skb)) {
223-
SCTP_INC_STATS_BH(SCTP_MIB_OUTOFBLUES);
223+
SCTP_INC_STATS_BH(net, SCTP_MIB_OUTOFBLUES);
224224
goto discard_release;
225225
}
226226
}
@@ -276,9 +276,9 @@ int sctp_rcv(struct sk_buff *skb)
276276
skb = NULL; /* sctp_chunk_free already freed the skb */
277277
goto discard_release;
278278
}
279-
SCTP_INC_STATS_BH(SCTP_MIB_IN_PKT_BACKLOG);
279+
SCTP_INC_STATS_BH(net, SCTP_MIB_IN_PKT_BACKLOG);
280280
} else {
281-
SCTP_INC_STATS_BH(SCTP_MIB_IN_PKT_SOFTIRQ);
281+
SCTP_INC_STATS_BH(net, SCTP_MIB_IN_PKT_SOFTIRQ);
282282
sctp_inq_push(&chunk->rcvr->inqueue, chunk);
283283
}
284284

@@ -293,7 +293,7 @@ int sctp_rcv(struct sk_buff *skb)
293293
return 0;
294294

295295
discard_it:
296-
SCTP_INC_STATS_BH(SCTP_MIB_IN_PKT_DISCARDS);
296+
SCTP_INC_STATS_BH(net, SCTP_MIB_IN_PKT_DISCARDS);
297297
kfree_skb(skb);
298298
return 0;
299299

@@ -543,7 +543,7 @@ struct sock *sctp_err_lookup(struct net *net, int family, struct sk_buff *skb,
543543
* servers this needs to be solved differently.
544544
*/
545545
if (sock_owned_by_user(sk))
546-
NET_INC_STATS_BH(&init_net, LINUX_MIB_LOCKDROPPEDICMPS);
546+
NET_INC_STATS_BH(net, LINUX_MIB_LOCKDROPPEDICMPS);
547547

548548
*app = asoc;
549549
*tpp = transport;
@@ -593,7 +593,7 @@ void sctp_v4_err(struct sk_buff *skb, __u32 info)
593593
struct net *net = dev_net(skb->dev);
594594

595595
if (skb->len < ihlen + 8) {
596-
ICMP_INC_STATS_BH(&init_net, ICMP_MIB_INERRORS);
596+
ICMP_INC_STATS_BH(net, ICMP_MIB_INERRORS);
597597
return;
598598
}
599599

@@ -607,7 +607,7 @@ void sctp_v4_err(struct sk_buff *skb, __u32 info)
607607
skb->network_header = saveip;
608608
skb->transport_header = savesctp;
609609
if (!sk) {
610-
ICMP_INC_STATS_BH(&init_net, ICMP_MIB_INERRORS);
610+
ICMP_INC_STATS_BH(net, ICMP_MIB_INERRORS);
611611
return;
612612
}
613613
/* Warning: The sock lock is held. Remember to call

‎net/sctp/ipv6.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ SCTP_STATIC void sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
169169
skb->network_header = saveip;
170170
skb->transport_header = savesctp;
171171
if (!sk) {
172-
ICMP6_INC_STATS_BH(dev_net(skb->dev), idev, ICMP6_MIB_INERRORS);
172+
ICMP6_INC_STATS_BH(net, idev, ICMP6_MIB_INERRORS);
173173
goto out;
174174
}
175175

@@ -243,7 +243,7 @@ static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport)
243243
__func__, skb, skb->len,
244244
&fl6.saddr, &fl6.daddr);
245245

246-
SCTP_INC_STATS(SCTP_MIB_OUTSCTPPACKS);
246+
SCTP_INC_STATS(sock_net(sk), SCTP_MIB_OUTSCTPPACKS);
247247

248248
if (!(transport->param_flags & SPP_PMTUD_ENABLE))
249249
skb->local_df = 1;

‎net/sctp/output.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ int sctp_packet_transmit(struct sctp_packet *packet)
597597
return err;
598598
no_route:
599599
kfree_skb(nskb);
600-
IP_INC_STATS_BH(&init_net, IPSTATS_MIB_OUTNOROUTES);
600+
IP_INC_STATS_BH(sock_net(asoc->base.sk), IPSTATS_MIB_OUTNOROUTES);
601601

602602
/* FIXME: Returning the 'err' will effect all the associations
603603
* associated with a socket, although only one of the paths of the

‎net/sctp/outqueue.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ void sctp_outq_free(struct sctp_outq *q)
299299
/* Put a new chunk in an sctp_outq. */
300300
int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk)
301301
{
302+
struct net *net = sock_net(q->asoc->base.sk);
302303
int error = 0;
303304

304305
SCTP_DEBUG_PRINTK("sctp_outq_tail(%p, %p[%s])\n",
@@ -337,15 +338,15 @@ int sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk)
337338

338339
sctp_outq_tail_data(q, chunk);
339340
if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
340-
SCTP_INC_STATS(SCTP_MIB_OUTUNORDERCHUNKS);
341+
SCTP_INC_STATS(net, SCTP_MIB_OUTUNORDERCHUNKS);
341342
else
342-
SCTP_INC_STATS(SCTP_MIB_OUTORDERCHUNKS);
343+
SCTP_INC_STATS(net, SCTP_MIB_OUTORDERCHUNKS);
343344
q->empty = 0;
344345
break;
345346
}
346347
} else {
347348
list_add_tail(&chunk->list, &q->control_chunk_list);
348-
SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
349+
SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
349350
}
350351

351352
if (error < 0)
@@ -478,11 +479,12 @@ void sctp_retransmit_mark(struct sctp_outq *q,
478479
void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
479480
sctp_retransmit_reason_t reason)
480481
{
482+
struct net *net = sock_net(q->asoc->base.sk);
481483
int error = 0;
482484

483485
switch(reason) {
484486
case SCTP_RTXR_T3_RTX:
485-
SCTP_INC_STATS(SCTP_MIB_T3_RETRANSMITS);
487+
SCTP_INC_STATS(net, SCTP_MIB_T3_RETRANSMITS);
486488
sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_T3_RTX);
487489
/* Update the retran path if the T3-rtx timer has expired for
488490
* the current retran path.
@@ -493,15 +495,15 @@ void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
493495
transport->asoc->unack_data;
494496
break;
495497
case SCTP_RTXR_FAST_RTX:
496-
SCTP_INC_STATS(SCTP_MIB_FAST_RETRANSMITS);
498+
SCTP_INC_STATS(net, SCTP_MIB_FAST_RETRANSMITS);
497499
sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_FAST_RTX);
498500
q->fast_rtx = 1;
499501
break;
500502
case SCTP_RTXR_PMTUD:
501-
SCTP_INC_STATS(SCTP_MIB_PMTUD_RETRANSMITS);
503+
SCTP_INC_STATS(net, SCTP_MIB_PMTUD_RETRANSMITS);
502504
break;
503505
case SCTP_RTXR_T1_RTX:
504-
SCTP_INC_STATS(SCTP_MIB_T1_RETRANSMITS);
506+
SCTP_INC_STATS(net, SCTP_MIB_T1_RETRANSMITS);
505507
transport->asoc->init_retries++;
506508
break;
507509
default:
@@ -1914,6 +1916,6 @@ static void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn)
19141916

19151917
if (ftsn_chunk) {
19161918
list_add_tail(&ftsn_chunk->list, &q->control_chunk_list);
1917-
SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1919+
SCTP_INC_STATS(sock_net(asoc->base.sk), SCTP_MIB_OUTCTRLCHUNKS);
19181920
}
19191921
}

‎net/sctp/proc.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,9 @@ static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
8383
struct net *net = seq->private;
8484
int i;
8585

86-
if (!net_eq(net, &init_net))
87-
return 0;
88-
8986
for (i = 0; sctp_snmp_list[i].name != NULL; i++)
9087
seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i].name,
91-
snmp_fold_field((void __percpu **)sctp_statistics,
88+
snmp_fold_field((void __percpu **)net->sctp.sctp_statistics,
9289
sctp_snmp_list[i].entry));
9390

9491
return 0;

0 commit comments

Comments
 (0)