Skip to content

Commit 3bd653c

Browse files
dlunevdavem330
authored andcommitted
netns: add net parameter to IP6_INC_STATS
Signed-off-by: Denis V. Lunev <den@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 98b3377 commit 3bd653c

9 files changed

Lines changed: 57 additions & 40 deletions

File tree

‎include/net/ipv6.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ extern struct ctl_path net_ipv6_ctl_path[];
129129
/* MIBs */
130130
DECLARE_SNMP_STAT(struct ipstats_mib, ipv6_statistics);
131131

132-
#define IP6_INC_STATS(idev,field) _DEVINC(ipv6, , idev, field)
132+
#define IP6_INC_STATS(net, idev,field) ({ (void)(net); \
133+
_DEVINC(ipv6, , idev, field); })
133134
#define IP6_INC_STATS_BH(idev,field) _DEVINC(ipv6, _BH, idev, field)
134135
#define IP6_ADD_STATS_BH(idev,field,val) _DEVADD(ipv6, _BH, idev, field, val)
135136

‎net/ipv6/icmp.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static inline int icmpv6_xrlim_allow(struct sock *sk, int type,
183183
*/
184184
dst = ip6_route_output(net, sk, fl);
185185
if (dst->error) {
186-
IP6_INC_STATS(ip6_dst_idev(dst),
186+
IP6_INC_STATS(net, ip6_dst_idev(dst),
187187
IPSTATS_MIB_OUTNOROUTES);
188188
} else if (dst->dev && (dst->dev->flags&IFF_LOOPBACK)) {
189189
res = 1;

‎net/ipv6/ip6_output.c‎

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,14 @@ static int ip6_output2(struct sk_buff *skb)
150150
ip6_dev_loopback_xmit);
151151

152152
if (ipv6_hdr(skb)->hop_limit == 0) {
153-
IP6_INC_STATS(idev, IPSTATS_MIB_OUTDISCARDS);
153+
IP6_INC_STATS(dev_net(dev), idev,
154+
IPSTATS_MIB_OUTDISCARDS);
154155
kfree_skb(skb);
155156
return 0;
156157
}
157158
}
158159

159-
IP6_INC_STATS(idev, IPSTATS_MIB_OUTMCASTPKTS);
160+
IP6_INC_STATS(dev_net(dev), idev, IPSTATS_MIB_OUTMCASTPKTS);
160161
}
161162

162163
return NF_HOOK(PF_INET6, NF_INET_POST_ROUTING, skb, NULL, skb->dev,
@@ -175,7 +176,8 @@ int ip6_output(struct sk_buff *skb)
175176
{
176177
struct inet6_dev *idev = ip6_dst_idev(skb->dst);
177178
if (unlikely(idev->cnf.disable_ipv6)) {
178-
IP6_INC_STATS(idev, IPSTATS_MIB_OUTDISCARDS);
179+
IP6_INC_STATS(dev_net(skb->dst->dev), idev,
180+
IPSTATS_MIB_OUTDISCARDS);
179181
kfree_skb(skb);
180182
return 0;
181183
}
@@ -194,6 +196,7 @@ int ip6_output(struct sk_buff *skb)
194196
int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
195197
struct ipv6_txoptions *opt, int ipfragok)
196198
{
199+
struct net *net = sock_net(sk);
197200
struct ipv6_pinfo *np = inet6_sk(sk);
198201
struct in6_addr *first_hop = &fl->fl6_dst;
199202
struct dst_entry *dst = skb->dst;
@@ -216,7 +219,7 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
216219
if (skb_headroom(skb) < head_room) {
217220
struct sk_buff *skb2 = skb_realloc_headroom(skb, head_room);
218221
if (skb2 == NULL) {
219-
IP6_INC_STATS(ip6_dst_idev(skb->dst),
222+
IP6_INC_STATS(net, ip6_dst_idev(skb->dst),
220223
IPSTATS_MIB_OUTDISCARDS);
221224
kfree_skb(skb);
222225
return -ENOBUFS;
@@ -270,7 +273,7 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
270273

271274
mtu = dst_mtu(dst);
272275
if ((skb->len <= mtu) || skb->local_df || skb_is_gso(skb)) {
273-
IP6_INC_STATS(ip6_dst_idev(skb->dst),
276+
IP6_INC_STATS(net, ip6_dst_idev(skb->dst),
274277
IPSTATS_MIB_OUTREQUESTS);
275278
return NF_HOOK(PF_INET6, NF_INET_LOCAL_OUT, skb, NULL, dst->dev,
276279
dst_output);
@@ -280,7 +283,7 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
280283
printk(KERN_DEBUG "IPv6: sending pkt_too_big to self\n");
281284
skb->dev = dst->dev;
282285
icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev);
283-
IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_FRAGFAILS);
286+
IP6_INC_STATS(net, ip6_dst_idev(skb->dst), IPSTATS_MIB_FRAGFAILS);
284287
kfree_skb(skb);
285288
return -EMSGSIZE;
286289
}
@@ -422,7 +425,7 @@ int ip6_forward(struct sk_buff *skb)
422425
goto drop;
423426

424427
if (!xfrm6_policy_check(NULL, XFRM_POLICY_FWD, skb)) {
425-
IP6_INC_STATS(ip6_dst_idev(dst), IPSTATS_MIB_INDISCARDS);
428+
IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_INDISCARDS);
426429
goto drop;
427430
}
428431

@@ -468,13 +471,14 @@ int ip6_forward(struct sk_buff *skb)
468471
if (proxied > 0)
469472
return ip6_input(skb);
470473
else if (proxied < 0) {
471-
IP6_INC_STATS(ip6_dst_idev(dst), IPSTATS_MIB_INDISCARDS);
474+
IP6_INC_STATS(net, ip6_dst_idev(dst),
475+
IPSTATS_MIB_INDISCARDS);
472476
goto drop;
473477
}
474478
}
475479

476480
if (!xfrm6_route_forward(skb)) {
477-
IP6_INC_STATS(ip6_dst_idev(dst), IPSTATS_MIB_INDISCARDS);
481+
IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_INDISCARDS);
478482
goto drop;
479483
}
480484
dst = skb->dst;
@@ -530,7 +534,7 @@ int ip6_forward(struct sk_buff *skb)
530534
}
531535

532536
if (skb_cow(skb, dst->dev->hard_header_len)) {
533-
IP6_INC_STATS(ip6_dst_idev(dst), IPSTATS_MIB_OUTDISCARDS);
537+
IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTDISCARDS);
534538
goto drop;
535539
}
536540

@@ -622,6 +626,7 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
622626
__be32 frag_id = 0;
623627
int ptr, offset = 0, err=0;
624628
u8 *prevhdr, nexthdr = 0;
629+
struct net *net = dev_net(skb->dst->dev);
625630

626631
hlen = ip6_find_1stfragopt(skb, &prevhdr);
627632
nexthdr = *prevhdr;
@@ -635,7 +640,8 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
635640
if (!skb->local_df) {
636641
skb->dev = skb->dst->dev;
637642
icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev);
638-
IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_FRAGFAILS);
643+
IP6_INC_STATS(net, ip6_dst_idev(skb->dst),
644+
IPSTATS_MIB_FRAGFAILS);
639645
kfree_skb(skb);
640646
return -EMSGSIZE;
641647
}
@@ -684,7 +690,8 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
684690
*prevhdr = NEXTHDR_FRAGMENT;
685691
tmp_hdr = kmemdup(skb_network_header(skb), hlen, GFP_ATOMIC);
686692
if (!tmp_hdr) {
687-
IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_FRAGFAILS);
693+
IP6_INC_STATS(net, ip6_dst_idev(skb->dst),
694+
IPSTATS_MIB_FRAGFAILS);
688695
return -ENOMEM;
689696
}
690697

@@ -735,7 +742,8 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
735742

736743
err = output(skb);
737744
if(!err)
738-
IP6_INC_STATS(ip6_dst_idev(&rt->u.dst), IPSTATS_MIB_FRAGCREATES);
745+
IP6_INC_STATS(net, ip6_dst_idev(&rt->u.dst),
746+
IPSTATS_MIB_FRAGCREATES);
739747

740748
if (err || !frag)
741749
break;
@@ -748,7 +756,8 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
748756
kfree(tmp_hdr);
749757

750758
if (err == 0) {
751-
IP6_INC_STATS(ip6_dst_idev(&rt->u.dst), IPSTATS_MIB_FRAGOKS);
759+
IP6_INC_STATS(net, ip6_dst_idev(&rt->u.dst),
760+
IPSTATS_MIB_FRAGOKS);
752761
dst_release(&rt->u.dst);
753762
return 0;
754763
}
@@ -759,7 +768,8 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
759768
frag = skb;
760769
}
761770

762-
IP6_INC_STATS(ip6_dst_idev(&rt->u.dst), IPSTATS_MIB_FRAGFAILS);
771+
IP6_INC_STATS(net, ip6_dst_idev(&rt->u.dst),
772+
IPSTATS_MIB_FRAGFAILS);
763773
dst_release(&rt->u.dst);
764774
return err;
765775
}
@@ -793,7 +803,7 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
793803

794804
if ((frag = alloc_skb(len+hlen+sizeof(struct frag_hdr)+LL_ALLOCATED_SPACE(rt->u.dst.dev), GFP_ATOMIC)) == NULL) {
795805
NETDEBUG(KERN_INFO "IPv6: frag: no memory for new fragment!\n");
796-
IP6_INC_STATS(ip6_dst_idev(skb->dst),
806+
IP6_INC_STATS(net, ip6_dst_idev(skb->dst),
797807
IPSTATS_MIB_FRAGFAILS);
798808
err = -ENOMEM;
799809
goto fail;
@@ -857,15 +867,16 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
857867
if (err)
858868
goto fail;
859869

860-
IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_FRAGCREATES);
870+
IP6_INC_STATS(net, ip6_dst_idev(skb->dst),
871+
IPSTATS_MIB_FRAGCREATES);
861872
}
862-
IP6_INC_STATS(ip6_dst_idev(skb->dst),
873+
IP6_INC_STATS(net, ip6_dst_idev(skb->dst),
863874
IPSTATS_MIB_FRAGOKS);
864875
kfree_skb(skb);
865876
return err;
866877

867878
fail:
868-
IP6_INC_STATS(ip6_dst_idev(skb->dst),
879+
IP6_INC_STATS(net, ip6_dst_idev(skb->dst),
869880
IPSTATS_MIB_FRAGFAILS);
870881
kfree_skb(skb);
871882
return err;
@@ -1385,7 +1396,7 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
13851396
return 0;
13861397
error:
13871398
inet->cork.length -= length;
1388-
IP6_INC_STATS(rt->rt6i_idev, IPSTATS_MIB_OUTDISCARDS);
1399+
IP6_INC_STATS(sock_net(sk), rt->rt6i_idev, IPSTATS_MIB_OUTDISCARDS);
13891400
return err;
13901401
}
13911402

@@ -1409,6 +1420,7 @@ int ip6_push_pending_frames(struct sock *sk)
14091420
struct in6_addr final_dst_buf, *final_dst = &final_dst_buf;
14101421
struct inet_sock *inet = inet_sk(sk);
14111422
struct ipv6_pinfo *np = inet6_sk(sk);
1423+
struct net *net = sock_net(sk);
14121424
struct ipv6hdr *hdr;
14131425
struct ipv6_txoptions *opt = np->cork.opt;
14141426
struct rt6_info *rt = (struct rt6_info *)inet->cork.dst;
@@ -1462,7 +1474,7 @@ int ip6_push_pending_frames(struct sock *sk)
14621474
skb->mark = sk->sk_mark;
14631475

14641476
skb->dst = dst_clone(&rt->u.dst);
1465-
IP6_INC_STATS(rt->rt6i_idev, IPSTATS_MIB_OUTREQUESTS);
1477+
IP6_INC_STATS(net, rt->rt6i_idev, IPSTATS_MIB_OUTREQUESTS);
14661478
if (proto == IPPROTO_ICMPV6) {
14671479
struct inet6_dev *idev = ip6_dst_idev(skb->dst);
14681480

@@ -1491,7 +1503,7 @@ void ip6_flush_pending_frames(struct sock *sk)
14911503

14921504
while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL) {
14931505
if (skb->dst)
1494-
IP6_INC_STATS(ip6_dst_idev(skb->dst),
1506+
IP6_INC_STATS(sock_net(sk), ip6_dst_idev(skb->dst),
14951507
IPSTATS_MIB_OUTDISCARDS);
14961508
kfree_skb(skb);
14971509
}

‎net/ipv6/mcast.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ static void mld_sendpack(struct sk_buff *skb)
14461446
int err;
14471447
struct flowi fl;
14481448

1449-
IP6_INC_STATS(idev, IPSTATS_MIB_OUTREQUESTS);
1449+
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTREQUESTS);
14501450
payload_len = (skb->tail - skb->network_header) - sizeof(*pip6);
14511451
mldlen = skb->tail - skb->transport_header;
14521452
pip6->payload_len = htons(payload_len);
@@ -1771,7 +1771,7 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
17711771
struct flowi fl;
17721772

17731773
rcu_read_lock();
1774-
IP6_INC_STATS(__in6_dev_get(dev),
1774+
IP6_INC_STATS(net, __in6_dev_get(dev),
17751775
IPSTATS_MIB_OUTREQUESTS);
17761776
rcu_read_unlock();
17771777
if (type == ICMPV6_MGM_REDUCTION)
@@ -1787,7 +1787,7 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
17871787

17881788
if (skb == NULL) {
17891789
rcu_read_lock();
1790-
IP6_INC_STATS(__in6_dev_get(dev),
1790+
IP6_INC_STATS(net, __in6_dev_get(dev),
17911791
IPSTATS_MIB_OUTDISCARDS);
17921792
rcu_read_unlock();
17931793
return;
@@ -1841,9 +1841,9 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
18411841
if (!err) {
18421842
ICMP6MSGOUT_INC_STATS(idev, type);
18431843
ICMP6_INC_STATS(idev, ICMP6_MIB_OUTMSGS);
1844-
IP6_INC_STATS(idev, IPSTATS_MIB_OUTMCASTPKTS);
1844+
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTMCASTPKTS);
18451845
} else
1846-
IP6_INC_STATS(idev, IPSTATS_MIB_OUTDISCARDS);
1846+
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS);
18471847

18481848
if (likely(idev != NULL))
18491849
in6_dev_put(idev);

‎net/ipv6/ndisc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ static void __ndisc_send(struct net_device *dev,
516516
skb->dst = dst;
517517

518518
idev = in6_dev_get(dst->dev);
519-
IP6_INC_STATS(idev, IPSTATS_MIB_OUTREQUESTS);
519+
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTREQUESTS);
520520

521521
err = NF_HOOK(PF_INET6, NF_INET_LOCAL_OUT, skb, NULL, dst->dev,
522522
dst_output);
@@ -1581,7 +1581,7 @@ void ndisc_send_redirect(struct sk_buff *skb, struct neighbour *neigh,
15811581

15821582
buff->dst = dst;
15831583
idev = in6_dev_get(dst->dev);
1584-
IP6_INC_STATS(idev, IPSTATS_MIB_OUTREQUESTS);
1584+
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTREQUESTS);
15851585
err = NF_HOOK(PF_INET6, NF_INET_LOCAL_OUT, buff, NULL, dst->dev,
15861586
dst_output);
15871587
if (!err) {

‎net/ipv6/netfilter.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ int ip6_route_me_harder(struct sk_buff *skb)
3333
#endif
3434

3535
if (dst->error) {
36-
IP6_INC_STATS(ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES);
36+
IP6_INC_STATS(&init_net, ip6_dst_idev(dst),
37+
IPSTATS_MIB_OUTNOROUTES);
3738
LIMIT_NETDEBUG(KERN_DEBUG "ip6_route_me_harder: No more route.\n");
3839
dst_release(dst);
3940
return -EINVAL;

‎net/ipv6/raw.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
638638
if (err)
639639
goto error_fault;
640640

641-
IP6_INC_STATS(rt->rt6i_idev, IPSTATS_MIB_OUTREQUESTS);
641+
IP6_INC_STATS(sock_net(sk), rt->rt6i_idev, IPSTATS_MIB_OUTREQUESTS);
642642
err = NF_HOOK(PF_INET6, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
643643
dst_output);
644644
if (err > 0)
@@ -652,7 +652,7 @@ static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
652652
err = -EFAULT;
653653
kfree_skb(skb);
654654
error:
655-
IP6_INC_STATS(rt->rt6i_idev, IPSTATS_MIB_OUTDISCARDS);
655+
IP6_INC_STATS(sock_net(sk), rt->rt6i_idev, IPSTATS_MIB_OUTDISCARDS);
656656
return err;
657657
}
658658

‎net/ipv6/reassembly.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
433433
return -1;
434434

435435
err:
436-
IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMFAILS);
436+
IP6_INC_STATS(dev_net(skb->dst->dev), ip6_dst_idev(skb->dst),
437+
IPSTATS_MIB_REASMFAILS);
437438
kfree_skb(skb);
438439
return -1;
439440
}
@@ -573,7 +574,7 @@ static int ipv6_frag_rcv(struct sk_buff *skb)
573574
struct frag_hdr *fhdr;
574575
struct frag_queue *fq;
575576
struct ipv6hdr *hdr = ipv6_hdr(skb);
576-
struct net *net;
577+
struct net *net = dev_net(skb->dst->dev);
577578

578579
IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMREQDS);
579580

@@ -597,7 +598,6 @@ static int ipv6_frag_rcv(struct sk_buff *skb)
597598
return 1;
598599
}
599600

600-
net = dev_net(skb->dev);
601601
if (atomic_read(&net->ipv6.frags.mem) > net->ipv6.frags.high_thresh)
602602
ip6_evictor(net, ip6_dst_idev(skb->dst));
603603

@@ -619,7 +619,7 @@ static int ipv6_frag_rcv(struct sk_buff *skb)
619619
return -1;
620620

621621
fail_hdr:
622-
IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_INHDRERRORS);
622+
IP6_INC_STATS(net, ip6_dst_idev(skb->dst), IPSTATS_MIB_INHDRERRORS);
623623
icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, skb_network_header_len(skb));
624624
return -1;
625625
}

‎net/ipv6/route.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,16 +1833,19 @@ int ipv6_route_ioctl(struct net *net, unsigned int cmd, void __user *arg)
18331833
static int ip6_pkt_drop(struct sk_buff *skb, int code, int ipstats_mib_noroutes)
18341834
{
18351835
int type;
1836+
struct dst_entry *dst = skb->dst;
18361837
switch (ipstats_mib_noroutes) {
18371838
case IPSTATS_MIB_INNOROUTES:
18381839
type = ipv6_addr_type(&ipv6_hdr(skb)->daddr);
18391840
if (type == IPV6_ADDR_ANY || type == IPV6_ADDR_RESERVED) {
1840-
IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_INADDRERRORS);
1841+
IP6_INC_STATS(dev_net(dst->dev), ip6_dst_idev(dst),
1842+
IPSTATS_MIB_INADDRERRORS);
18411843
break;
18421844
}
18431845
/* FALLTHROUGH */
18441846
case IPSTATS_MIB_OUTNOROUTES:
1845-
IP6_INC_STATS(ip6_dst_idev(skb->dst), ipstats_mib_noroutes);
1847+
IP6_INC_STATS(dev_net(dst->dev), ip6_dst_idev(dst),
1848+
ipstats_mib_noroutes);
18461849
break;
18471850
}
18481851
icmpv6_send(skb, ICMPV6_DEST_UNREACH, code, 0, skb->dev);

0 commit comments

Comments
 (0)