提交 a11d206d 编写于 作者: Y YOSHIFUJI Hideaki 提交者: David S. Miller

[IPV6]: Per-interface statistics support.

For IP MIB (RFC4293).
Signed-off-by: NYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
上级 7a3025b1
...@@ -152,6 +152,7 @@ struct ifacaddr6 ...@@ -152,6 +152,7 @@ struct ifacaddr6
struct ipv6_devstat { struct ipv6_devstat {
struct proc_dir_entry *proc_dir_entry; struct proc_dir_entry *proc_dir_entry;
DEFINE_SNMP_STAT(struct ipstats_mib, ipv6);
DEFINE_SNMP_STAT(struct icmpv6_mib, icmpv6); DEFINE_SNMP_STAT(struct icmpv6_mib, icmpv6);
}; };
......
...@@ -113,9 +113,24 @@ extern int sysctl_mld_max_msf; ...@@ -113,9 +113,24 @@ extern int sysctl_mld_max_msf;
/* MIBs */ /* MIBs */
DECLARE_SNMP_STAT(struct ipstats_mib, ipv6_statistics); DECLARE_SNMP_STAT(struct ipstats_mib, ipv6_statistics);
#define IP6_INC_STATS(field) SNMP_INC_STATS(ipv6_statistics, field) #define IP6_INC_STATS(idev,field) ({ \
#define IP6_INC_STATS_BH(field) SNMP_INC_STATS_BH(ipv6_statistics, field) struct inet6_dev *_idev = (idev); \
#define IP6_INC_STATS_USER(field) SNMP_INC_STATS_USER(ipv6_statistics, field) if (likely(_idev != NULL)) \
SNMP_INC_STATS(_idev->stats.ipv6, field); \
SNMP_INC_STATS(ipv6_statistics, field); \
})
#define IP6_INC_STATS_BH(idev,field) ({ \
struct inet6_dev *_idev = (idev); \
if (likely(_idev != NULL)) \
SNMP_INC_STATS_BH(_idev->stats.ipv6, field); \
SNMP_INC_STATS_BH(ipv6_statistics, field); \
})
#define IP6_INC_STATS_USER(idev,field) ({ \
struct inet6_dev *_idev = (idev); \
if (likely(_idev != NULL)) \
SNMP_INC_STATS_USER(_idev->stats.ipv6, field); \
SNMP_INC_STATS_USER(ipv6_statistics, field); \
})
DECLARE_SNMP_STAT(struct icmpv6_mib, icmpv6_statistics); DECLARE_SNMP_STAT(struct icmpv6_mib, icmpv6_statistics);
#define ICMP6_INC_STATS(idev, field) ({ \ #define ICMP6_INC_STATS(idev, field) ({ \
struct inet6_dev *_idev = (idev); \ struct inet6_dev *_idev = (idev); \
......
...@@ -284,10 +284,12 @@ static int ipv6_destopt_rcv(struct sk_buff **skbp) ...@@ -284,10 +284,12 @@ static int ipv6_destopt_rcv(struct sk_buff **skbp)
#ifdef CONFIG_IPV6_MIP6 #ifdef CONFIG_IPV6_MIP6
__u16 dstbuf; __u16 dstbuf;
#endif #endif
struct dst_entry *dst;
if (!pskb_may_pull(skb, (skb->h.raw-skb->data)+8) || if (!pskb_may_pull(skb, (skb->h.raw-skb->data)+8) ||
!pskb_may_pull(skb, (skb->h.raw-skb->data)+((skb->h.raw[1]+1)<<3))) { !pskb_may_pull(skb, (skb->h.raw-skb->data)+((skb->h.raw[1]+1)<<3))) {
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INHDRERRORS);
kfree_skb(skb); kfree_skb(skb);
return -1; return -1;
} }
...@@ -298,7 +300,9 @@ static int ipv6_destopt_rcv(struct sk_buff **skbp) ...@@ -298,7 +300,9 @@ static int ipv6_destopt_rcv(struct sk_buff **skbp)
dstbuf = opt->dst1; dstbuf = opt->dst1;
#endif #endif
dst = dst_clone(skb->dst);
if (ip6_parse_tlv(tlvprocdestopt_lst, skbp)) { if (ip6_parse_tlv(tlvprocdestopt_lst, skbp)) {
dst_release(dst);
skb = *skbp; skb = *skbp;
skb->h.raw += ((skb->h.raw[1]+1)<<3); skb->h.raw += ((skb->h.raw[1]+1)<<3);
opt = IP6CB(skb); opt = IP6CB(skb);
...@@ -310,7 +314,8 @@ static int ipv6_destopt_rcv(struct sk_buff **skbp) ...@@ -310,7 +314,8 @@ static int ipv6_destopt_rcv(struct sk_buff **skbp)
return 1; return 1;
} }
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(dst), IPSTATS_MIB_INHDRERRORS);
dst_release(dst);
return -1; return -1;
} }
...@@ -365,7 +370,8 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp) ...@@ -365,7 +370,8 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp)
if (!pskb_may_pull(skb, (skb->h.raw-skb->data)+8) || if (!pskb_may_pull(skb, (skb->h.raw-skb->data)+8) ||
!pskb_may_pull(skb, (skb->h.raw-skb->data)+((skb->h.raw[1]+1)<<3))) { !pskb_may_pull(skb, (skb->h.raw-skb->data)+((skb->h.raw[1]+1)<<3))) {
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INHDRERRORS);
kfree_skb(skb); kfree_skb(skb);
return -1; return -1;
} }
...@@ -374,7 +380,8 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp) ...@@ -374,7 +380,8 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp)
if (ipv6_addr_is_multicast(&skb->nh.ipv6h->daddr) || if (ipv6_addr_is_multicast(&skb->nh.ipv6h->daddr) ||
skb->pkt_type != PACKET_HOST) { skb->pkt_type != PACKET_HOST) {
IP6_INC_STATS_BH(IPSTATS_MIB_INADDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INADDRERRORS);
kfree_skb(skb); kfree_skb(skb);
return -1; return -1;
} }
...@@ -388,7 +395,8 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp) ...@@ -388,7 +395,8 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp)
* processed by own * processed by own
*/ */
if (!addr) { if (!addr) {
IP6_INC_STATS_BH(IPSTATS_MIB_INADDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INADDRERRORS);
kfree_skb(skb); kfree_skb(skb);
return -1; return -1;
} }
...@@ -410,7 +418,8 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp) ...@@ -410,7 +418,8 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp)
switch (hdr->type) { switch (hdr->type) {
case IPV6_SRCRT_TYPE_0: case IPV6_SRCRT_TYPE_0:
if (hdr->hdrlen & 0x01) { if (hdr->hdrlen & 0x01) {
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INHDRERRORS);
icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, (&hdr->hdrlen) - skb->nh.raw); icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, (&hdr->hdrlen) - skb->nh.raw);
return -1; return -1;
} }
...@@ -419,14 +428,16 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp) ...@@ -419,14 +428,16 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp)
case IPV6_SRCRT_TYPE_2: case IPV6_SRCRT_TYPE_2:
/* Silently discard invalid RTH type 2 */ /* Silently discard invalid RTH type 2 */
if (hdr->hdrlen != 2 || hdr->segments_left != 1) { if (hdr->hdrlen != 2 || hdr->segments_left != 1) {
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INHDRERRORS);
kfree_skb(skb); kfree_skb(skb);
return -1; return -1;
} }
break; break;
#endif #endif
default: default:
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INHDRERRORS);
icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, (&hdr->type) - skb->nh.raw); icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, (&hdr->type) - skb->nh.raw);
return -1; return -1;
} }
...@@ -439,7 +450,8 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp) ...@@ -439,7 +450,8 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp)
n = hdr->hdrlen >> 1; n = hdr->hdrlen >> 1;
if (hdr->segments_left > n) { if (hdr->segments_left > n) {
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INHDRERRORS);
icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, (&hdr->segments_left) - skb->nh.raw); icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, (&hdr->segments_left) - skb->nh.raw);
return -1; return -1;
} }
...@@ -449,12 +461,14 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp) ...@@ -449,12 +461,14 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp)
*/ */
if (skb_cloned(skb)) { if (skb_cloned(skb)) {
struct sk_buff *skb2 = skb_copy(skb, GFP_ATOMIC); struct sk_buff *skb2 = skb_copy(skb, GFP_ATOMIC);
kfree_skb(skb);
/* the copy is a forwarded packet */ /* the copy is a forwarded packet */
if (skb2 == NULL) { if (skb2 == NULL) {
IP6_INC_STATS_BH(IPSTATS_MIB_OUTDISCARDS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_OUTDISCARDS);
kfree_skb(skb);
return -1; return -1;
} }
kfree_skb(skb);
*skbp = skb = skb2; *skbp = skb = skb2;
opt = IP6CB(skb2); opt = IP6CB(skb2);
hdr = (struct ipv6_rt_hdr *) skb2->h.raw; hdr = (struct ipv6_rt_hdr *) skb2->h.raw;
...@@ -475,12 +489,14 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp) ...@@ -475,12 +489,14 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp)
if (xfrm6_input_addr(skb, (xfrm_address_t *)addr, if (xfrm6_input_addr(skb, (xfrm_address_t *)addr,
(xfrm_address_t *)&skb->nh.ipv6h->saddr, (xfrm_address_t *)&skb->nh.ipv6h->saddr,
IPPROTO_ROUTING) < 0) { IPPROTO_ROUTING) < 0) {
IP6_INC_STATS_BH(IPSTATS_MIB_INADDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INADDRERRORS);
kfree_skb(skb); kfree_skb(skb);
return -1; return -1;
} }
if (!ipv6_chk_home_addr(addr)) { if (!ipv6_chk_home_addr(addr)) {
IP6_INC_STATS_BH(IPSTATS_MIB_INADDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INADDRERRORS);
kfree_skb(skb); kfree_skb(skb);
return -1; return -1;
} }
...@@ -491,7 +507,8 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp) ...@@ -491,7 +507,8 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp)
} }
if (ipv6_addr_is_multicast(addr)) { if (ipv6_addr_is_multicast(addr)) {
IP6_INC_STATS_BH(IPSTATS_MIB_INADDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INADDRERRORS);
kfree_skb(skb); kfree_skb(skb);
return -1; return -1;
} }
...@@ -510,7 +527,8 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp) ...@@ -510,7 +527,8 @@ static int ipv6_rthdr_rcv(struct sk_buff **skbp)
if (skb->dst->dev->flags&IFF_LOOPBACK) { if (skb->dst->dev->flags&IFF_LOOPBACK) {
if (skb->nh.ipv6h->hop_limit <= 1) { if (skb->nh.ipv6h->hop_limit <= 1) {
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INHDRERRORS);
icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT,
0, skb->dev); 0, skb->dev);
kfree_skb(skb); kfree_skb(skb);
...@@ -632,24 +650,25 @@ static int ipv6_hop_jumbo(struct sk_buff **skbp, int optoff) ...@@ -632,24 +650,25 @@ static int ipv6_hop_jumbo(struct sk_buff **skbp, int optoff)
if (skb->nh.raw[optoff+1] != 4 || (optoff&3) != 2) { if (skb->nh.raw[optoff+1] != 4 || (optoff&3) != 2) {
LIMIT_NETDEBUG(KERN_DEBUG "ipv6_hop_jumbo: wrong jumbo opt length/alignment %d\n", LIMIT_NETDEBUG(KERN_DEBUG "ipv6_hop_jumbo: wrong jumbo opt length/alignment %d\n",
skb->nh.raw[optoff+1]); skb->nh.raw[optoff+1]);
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INHDRERRORS);
goto drop; goto drop;
} }
pkt_len = ntohl(*(u32*)(skb->nh.raw+optoff+2)); pkt_len = ntohl(*(u32*)(skb->nh.raw+optoff+2));
if (pkt_len <= IPV6_MAXPLEN) { if (pkt_len <= IPV6_MAXPLEN) {
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_INHDRERRORS);
icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, optoff+2); icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, optoff+2);
return 0; return 0;
} }
if (skb->nh.ipv6h->payload_len) { if (skb->nh.ipv6h->payload_len) {
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_INHDRERRORS);
icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, optoff); icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, optoff);
return 0; return 0;
} }
if (pkt_len > skb->len - sizeof(struct ipv6hdr)) { if (pkt_len > skb->len - sizeof(struct ipv6hdr)) {
IP6_INC_STATS_BH(IPSTATS_MIB_INTRUNCATEDPKTS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_INTRUNCATEDPKTS);
goto drop; goto drop;
} }
......
...@@ -177,7 +177,8 @@ static inline int icmpv6_xrlim_allow(struct sock *sk, int type, ...@@ -177,7 +177,8 @@ static inline int icmpv6_xrlim_allow(struct sock *sk, int type,
*/ */
dst = ip6_route_output(sk, fl); dst = ip6_route_output(sk, fl);
if (dst->error) { if (dst->error) {
IP6_INC_STATS(IPSTATS_MIB_OUTNOROUTES); IP6_INC_STATS(ip6_dst_idev(dst),
IPSTATS_MIB_OUTNOROUTES);
} else if (dst->dev && (dst->dev->flags&IFF_LOOPBACK)) { } else if (dst->dev && (dst->dev->flags&IFF_LOOPBACK)) {
res = 1; res = 1;
} else { } else {
......
...@@ -60,14 +60,22 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt ...@@ -60,14 +60,22 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
{ {
struct ipv6hdr *hdr; struct ipv6hdr *hdr;
u32 pkt_len; u32 pkt_len;
struct inet6_dev *idev;
if (skb->pkt_type == PACKET_OTHERHOST) if (skb->pkt_type == PACKET_OTHERHOST) {
goto drop; kfree_skb(skb);
return 0;
}
rcu_read_lock();
IP6_INC_STATS_BH(IPSTATS_MIB_INRECEIVES); idev = __in6_dev_get(skb->dev);
IP6_INC_STATS_BH(idev, IPSTATS_MIB_INRECEIVES);
if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) { if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
IP6_INC_STATS_BH(IPSTATS_MIB_INDISCARDS); IP6_INC_STATS_BH(idev, IPSTATS_MIB_INDISCARDS);
rcu_read_unlock();
goto out; goto out;
} }
...@@ -104,7 +112,7 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt ...@@ -104,7 +112,7 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
if (pkt_len + sizeof(struct ipv6hdr) > skb->len) if (pkt_len + sizeof(struct ipv6hdr) > skb->len)
goto truncated; goto truncated;
if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr))) { if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr))) {
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(idev, IPSTATS_MIB_INHDRERRORS);
goto drop; goto drop;
} }
hdr = skb->nh.ipv6h; hdr = skb->nh.ipv6h;
...@@ -112,17 +120,21 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt ...@@ -112,17 +120,21 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
if (hdr->nexthdr == NEXTHDR_HOP) { if (hdr->nexthdr == NEXTHDR_HOP) {
if (ipv6_parse_hopopts(&skb) < 0) { if (ipv6_parse_hopopts(&skb) < 0) {
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(idev, IPSTATS_MIB_INHDRERRORS);
rcu_read_unlock();
return 0; return 0;
} }
} }
rcu_read_unlock();
return NF_HOOK(PF_INET6,NF_IP6_PRE_ROUTING, skb, dev, NULL, ip6_rcv_finish); return NF_HOOK(PF_INET6,NF_IP6_PRE_ROUTING, skb, dev, NULL, ip6_rcv_finish);
truncated: truncated:
IP6_INC_STATS_BH(IPSTATS_MIB_INTRUNCATEDPKTS); IP6_INC_STATS_BH(idev, IPSTATS_MIB_INTRUNCATEDPKTS);
err: err:
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(idev, IPSTATS_MIB_INHDRERRORS);
drop: drop:
rcu_read_unlock();
kfree_skb(skb); kfree_skb(skb);
out: out:
return 0; return 0;
...@@ -140,6 +152,7 @@ static inline int ip6_input_finish(struct sk_buff *skb) ...@@ -140,6 +152,7 @@ static inline int ip6_input_finish(struct sk_buff *skb)
unsigned int nhoff; unsigned int nhoff;
int nexthdr; int nexthdr;
u8 hash; u8 hash;
struct inet6_dev *idev;
/* /*
* Parse extension headers * Parse extension headers
...@@ -147,6 +160,7 @@ static inline int ip6_input_finish(struct sk_buff *skb) ...@@ -147,6 +160,7 @@ static inline int ip6_input_finish(struct sk_buff *skb)
rcu_read_lock(); rcu_read_lock();
resubmit: resubmit:
idev = ip6_dst_idev(skb->dst);
if (!pskb_pull(skb, skb->h.raw - skb->data)) if (!pskb_pull(skb, skb->h.raw - skb->data))
goto discard; goto discard;
nhoff = IP6CB(skb)->nhoff; nhoff = IP6CB(skb)->nhoff;
...@@ -185,24 +199,24 @@ static inline int ip6_input_finish(struct sk_buff *skb) ...@@ -185,24 +199,24 @@ static inline int ip6_input_finish(struct sk_buff *skb)
if (ret > 0) if (ret > 0)
goto resubmit; goto resubmit;
else if (ret == 0) else if (ret == 0)
IP6_INC_STATS_BH(IPSTATS_MIB_INDELIVERS); IP6_INC_STATS_BH(idev, IPSTATS_MIB_INDELIVERS);
} else { } else {
if (!raw_sk) { if (!raw_sk) {
if (xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) { if (xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) {
IP6_INC_STATS_BH(IPSTATS_MIB_INUNKNOWNPROTOS); IP6_INC_STATS_BH(idev, IPSTATS_MIB_INUNKNOWNPROTOS);
icmpv6_send(skb, ICMPV6_PARAMPROB, icmpv6_send(skb, ICMPV6_PARAMPROB,
ICMPV6_UNK_NEXTHDR, nhoff, ICMPV6_UNK_NEXTHDR, nhoff,
skb->dev); skb->dev);
} }
} else } else
IP6_INC_STATS_BH(IPSTATS_MIB_INDELIVERS); IP6_INC_STATS_BH(idev, IPSTATS_MIB_INDELIVERS);
kfree_skb(skb); kfree_skb(skb);
} }
rcu_read_unlock(); rcu_read_unlock();
return 0; return 0;
discard: discard:
IP6_INC_STATS_BH(IPSTATS_MIB_INDISCARDS); IP6_INC_STATS_BH(idev, IPSTATS_MIB_INDISCARDS);
rcu_read_unlock(); rcu_read_unlock();
kfree_skb(skb); kfree_skb(skb);
return 0; return 0;
...@@ -219,7 +233,7 @@ int ip6_mc_input(struct sk_buff *skb) ...@@ -219,7 +233,7 @@ int ip6_mc_input(struct sk_buff *skb)
struct ipv6hdr *hdr; struct ipv6hdr *hdr;
int deliver; int deliver;
IP6_INC_STATS_BH(IPSTATS_MIB_INMCASTPKTS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_INMCASTPKTS);
hdr = skb->nh.ipv6h; hdr = skb->nh.ipv6h;
deliver = likely(!(skb->dev->flags & (IFF_PROMISC|IFF_ALLMULTI))) || deliver = likely(!(skb->dev->flags & (IFF_PROMISC|IFF_ALLMULTI))) ||
......
...@@ -88,7 +88,7 @@ static inline int ip6_output_finish(struct sk_buff *skb) ...@@ -88,7 +88,7 @@ static inline int ip6_output_finish(struct sk_buff *skb)
} else if (dst->neighbour) } else if (dst->neighbour)
return dst->neighbour->output(skb); return dst->neighbour->output(skb);
IP6_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES); IP6_INC_STATS_BH(ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES);
kfree_skb(skb); kfree_skb(skb);
return -EINVAL; return -EINVAL;
...@@ -118,6 +118,7 @@ static int ip6_output2(struct sk_buff *skb) ...@@ -118,6 +118,7 @@ static int ip6_output2(struct sk_buff *skb)
if (ipv6_addr_is_multicast(&skb->nh.ipv6h->daddr)) { if (ipv6_addr_is_multicast(&skb->nh.ipv6h->daddr)) {
struct ipv6_pinfo* np = skb->sk ? inet6_sk(skb->sk) : NULL; struct ipv6_pinfo* np = skb->sk ? inet6_sk(skb->sk) : NULL;
struct inet6_dev *idev = ip6_dst_idev(skb->dst);
if (!(dev->flags & IFF_LOOPBACK) && (!np || np->mc_loop) && if (!(dev->flags & IFF_LOOPBACK) && (!np || np->mc_loop) &&
ipv6_chk_mcast_addr(dev, &skb->nh.ipv6h->daddr, ipv6_chk_mcast_addr(dev, &skb->nh.ipv6h->daddr,
...@@ -133,13 +134,13 @@ static int ip6_output2(struct sk_buff *skb) ...@@ -133,13 +134,13 @@ static int ip6_output2(struct sk_buff *skb)
ip6_dev_loopback_xmit); ip6_dev_loopback_xmit);
if (skb->nh.ipv6h->hop_limit == 0) { if (skb->nh.ipv6h->hop_limit == 0) {
IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS); IP6_INC_STATS(idev, IPSTATS_MIB_OUTDISCARDS);
kfree_skb(skb); kfree_skb(skb);
return 0; return 0;
} }
} }
IP6_INC_STATS(IPSTATS_MIB_OUTMCASTPKTS); IP6_INC_STATS(idev, IPSTATS_MIB_OUTMCASTPKTS);
} }
return NF_HOOK(PF_INET6, NF_IP6_POST_ROUTING, skb,NULL, skb->dev,ip6_output_finish); return NF_HOOK(PF_INET6, NF_IP6_POST_ROUTING, skb,NULL, skb->dev,ip6_output_finish);
...@@ -182,12 +183,14 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl, ...@@ -182,12 +183,14 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
if (skb_headroom(skb) < head_room) { if (skb_headroom(skb) < head_room) {
struct sk_buff *skb2 = skb_realloc_headroom(skb, head_room); struct sk_buff *skb2 = skb_realloc_headroom(skb, head_room);
kfree_skb(skb); if (skb2 == NULL) {
skb = skb2; IP6_INC_STATS(ip6_dst_idev(skb->dst),
if (skb == NULL) { IPSTATS_MIB_OUTDISCARDS);
IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS); kfree_skb(skb);
return -ENOBUFS; return -ENOBUFS;
} }
kfree_skb(skb);
skb = skb2;
if (sk) if (sk)
skb_set_owner_w(skb, sk); skb_set_owner_w(skb, sk);
} }
...@@ -230,7 +233,8 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl, ...@@ -230,7 +233,8 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
mtu = dst_mtu(dst); mtu = dst_mtu(dst);
if ((skb->len <= mtu) || ipfragok || skb_is_gso(skb)) { if ((skb->len <= mtu) || ipfragok || skb_is_gso(skb)) {
IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS); IP6_INC_STATS(ip6_dst_idev(skb->dst),
IPSTATS_MIB_OUTREQUESTS);
return NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, dst->dev, return NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, dst->dev,
dst_output); dst_output);
} }
...@@ -239,7 +243,7 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl, ...@@ -239,7 +243,7 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
printk(KERN_DEBUG "IPv6: sending pkt_too_big to self\n"); printk(KERN_DEBUG "IPv6: sending pkt_too_big to self\n");
skb->dev = dst->dev; skb->dev = dst->dev;
icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev); icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev);
IP6_INC_STATS(IPSTATS_MIB_FRAGFAILS); IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_FRAGFAILS);
kfree_skb(skb); kfree_skb(skb);
return -EMSGSIZE; return -EMSGSIZE;
} }
...@@ -373,7 +377,7 @@ int ip6_forward(struct sk_buff *skb) ...@@ -373,7 +377,7 @@ int ip6_forward(struct sk_buff *skb)
goto error; goto error;
if (!xfrm6_policy_check(NULL, XFRM_POLICY_FWD, skb)) { if (!xfrm6_policy_check(NULL, XFRM_POLICY_FWD, skb)) {
IP6_INC_STATS(IPSTATS_MIB_INDISCARDS); IP6_INC_STATS(ip6_dst_idev(dst), IPSTATS_MIB_INDISCARDS);
goto drop; goto drop;
} }
...@@ -406,7 +410,7 @@ int ip6_forward(struct sk_buff *skb) ...@@ -406,7 +410,7 @@ int ip6_forward(struct sk_buff *skb)
skb->dev = dst->dev; skb->dev = dst->dev;
icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT,
0, skb->dev); 0, skb->dev);
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(dst), IPSTATS_MIB_INHDRERRORS);
kfree_skb(skb); kfree_skb(skb);
return -ETIMEDOUT; return -ETIMEDOUT;
...@@ -419,13 +423,13 @@ int ip6_forward(struct sk_buff *skb) ...@@ -419,13 +423,13 @@ int ip6_forward(struct sk_buff *skb)
if (proxied > 0) if (proxied > 0)
return ip6_input(skb); return ip6_input(skb);
else if (proxied < 0) { else if (proxied < 0) {
IP6_INC_STATS(IPSTATS_MIB_INDISCARDS); IP6_INC_STATS(ip6_dst_idev(dst), IPSTATS_MIB_INDISCARDS);
goto drop; goto drop;
} }
} }
if (!xfrm6_route_forward(skb)) { if (!xfrm6_route_forward(skb)) {
IP6_INC_STATS(IPSTATS_MIB_INDISCARDS); IP6_INC_STATS(ip6_dst_idev(dst), IPSTATS_MIB_INDISCARDS);
goto drop; goto drop;
} }
dst = skb->dst; dst = skb->dst;
...@@ -464,14 +468,14 @@ int ip6_forward(struct sk_buff *skb) ...@@ -464,14 +468,14 @@ int ip6_forward(struct sk_buff *skb)
/* Again, force OUTPUT device used as source address */ /* Again, force OUTPUT device used as source address */
skb->dev = dst->dev; skb->dev = dst->dev;
icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, dst_mtu(dst), skb->dev); icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, dst_mtu(dst), skb->dev);
IP6_INC_STATS_BH(IPSTATS_MIB_INTOOBIGERRORS); IP6_INC_STATS_BH(ip6_dst_idev(dst), IPSTATS_MIB_INTOOBIGERRORS);
IP6_INC_STATS_BH(IPSTATS_MIB_FRAGFAILS); IP6_INC_STATS_BH(ip6_dst_idev(dst), IPSTATS_MIB_FRAGFAILS);
kfree_skb(skb); kfree_skb(skb);
return -EMSGSIZE; return -EMSGSIZE;
} }
if (skb_cow(skb, dst->dev->hard_header_len)) { if (skb_cow(skb, dst->dev->hard_header_len)) {
IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS); IP6_INC_STATS(ip6_dst_idev(dst), IPSTATS_MIB_OUTDISCARDS);
goto drop; goto drop;
} }
...@@ -481,11 +485,11 @@ int ip6_forward(struct sk_buff *skb) ...@@ -481,11 +485,11 @@ int ip6_forward(struct sk_buff *skb)
hdr->hop_limit--; hdr->hop_limit--;
IP6_INC_STATS_BH(IPSTATS_MIB_OUTFORWDATAGRAMS); IP6_INC_STATS_BH(ip6_dst_idev(dst), IPSTATS_MIB_OUTFORWDATAGRAMS);
return NF_HOOK(PF_INET6,NF_IP6_FORWARD, skb, skb->dev, dst->dev, ip6_forward_finish); return NF_HOOK(PF_INET6,NF_IP6_FORWARD, skb, skb->dev, dst->dev, ip6_forward_finish);
error: error:
IP6_INC_STATS_BH(IPSTATS_MIB_INADDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(dst), IPSTATS_MIB_INADDRERRORS);
drop: drop:
kfree_skb(skb); kfree_skb(skb);
return -EINVAL; return -EINVAL;
...@@ -622,7 +626,7 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) ...@@ -622,7 +626,7 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
tmp_hdr = kmalloc(hlen, GFP_ATOMIC); tmp_hdr = kmalloc(hlen, GFP_ATOMIC);
if (!tmp_hdr) { if (!tmp_hdr) {
IP6_INC_STATS(IPSTATS_MIB_FRAGFAILS); IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_FRAGFAILS);
return -ENOMEM; return -ENOMEM;
} }
...@@ -643,7 +647,8 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) ...@@ -643,7 +647,8 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
skb->data_len = first_len - skb_headlen(skb); skb->data_len = first_len - skb_headlen(skb);
skb->len = first_len; skb->len = first_len;
skb->nh.ipv6h->payload_len = htons(first_len - sizeof(struct ipv6hdr)); skb->nh.ipv6h->payload_len = htons(first_len - sizeof(struct ipv6hdr));
dst_hold(&rt->u.dst);
for (;;) { for (;;) {
/* Prepare header of the next frame, /* Prepare header of the next frame,
...@@ -667,7 +672,7 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) ...@@ -667,7 +672,7 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
err = output(skb); err = output(skb);
if(!err) if(!err)
IP6_INC_STATS(IPSTATS_MIB_FRAGCREATES); IP6_INC_STATS(ip6_dst_idev(&rt->u.dst), IPSTATS_MIB_FRAGCREATES);
if (err || !frag) if (err || !frag)
break; break;
...@@ -680,7 +685,8 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) ...@@ -680,7 +685,8 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
kfree(tmp_hdr); kfree(tmp_hdr);
if (err == 0) { if (err == 0) {
IP6_INC_STATS(IPSTATS_MIB_FRAGOKS); IP6_INC_STATS(ip6_dst_idev(&rt->u.dst), IPSTATS_MIB_FRAGOKS);
dst_release(&rt->u.dst);
return 0; return 0;
} }
...@@ -690,7 +696,8 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) ...@@ -690,7 +696,8 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
frag = skb; frag = skb;
} }
IP6_INC_STATS(IPSTATS_MIB_FRAGFAILS); IP6_INC_STATS(ip6_dst_idev(&rt->u.dst), IPSTATS_MIB_FRAGFAILS);
dst_release(&rt->u.dst);
return err; return err;
} }
...@@ -723,7 +730,8 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) ...@@ -723,7 +730,8 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
if ((frag = alloc_skb(len+hlen+sizeof(struct frag_hdr)+LL_RESERVED_SPACE(rt->u.dst.dev), GFP_ATOMIC)) == NULL) { if ((frag = alloc_skb(len+hlen+sizeof(struct frag_hdr)+LL_RESERVED_SPACE(rt->u.dst.dev), GFP_ATOMIC)) == NULL) {
NETDEBUG(KERN_INFO "IPv6: frag: no memory for new fragment!\n"); NETDEBUG(KERN_INFO "IPv6: frag: no memory for new fragment!\n");
IP6_INC_STATS(IPSTATS_MIB_FRAGFAILS); IP6_INC_STATS(ip6_dst_idev(skb->dst),
IPSTATS_MIB_FRAGFAILS);
err = -ENOMEM; err = -ENOMEM;
goto fail; goto fail;
} }
...@@ -784,15 +792,17 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)) ...@@ -784,15 +792,17 @@ static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
if (err) if (err)
goto fail; goto fail;
IP6_INC_STATS(IPSTATS_MIB_FRAGCREATES); IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_FRAGCREATES);
} }
IP6_INC_STATS(ip6_dst_idev(skb->dst),
IPSTATS_MIB_FRAGOKS);
kfree_skb(skb); kfree_skb(skb);
IP6_INC_STATS(IPSTATS_MIB_FRAGOKS);
return err; return err;
fail: fail:
IP6_INC_STATS(ip6_dst_idev(skb->dst),
IPSTATS_MIB_FRAGFAILS);
kfree_skb(skb); kfree_skb(skb);
IP6_INC_STATS(IPSTATS_MIB_FRAGFAILS);
return err; return err;
} }
...@@ -1265,7 +1275,7 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to, ...@@ -1265,7 +1275,7 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
return 0; return 0;
error: error:
inet->cork.length -= length; inet->cork.length -= length;
IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS); IP6_INC_STATS(rt->rt6i_idev, IPSTATS_MIB_OUTDISCARDS);
return err; return err;
} }
...@@ -1326,7 +1336,7 @@ int ip6_push_pending_frames(struct sock *sk) ...@@ -1326,7 +1336,7 @@ int ip6_push_pending_frames(struct sock *sk)
skb->priority = sk->sk_priority; skb->priority = sk->sk_priority;
skb->dst = dst_clone(&rt->u.dst); skb->dst = dst_clone(&rt->u.dst);
IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS); IP6_INC_STATS(rt->rt6i_idev, IPSTATS_MIB_OUTREQUESTS);
err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, skb->dst->dev, dst_output); err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, skb->dst->dev, dst_output);
if (err) { if (err) {
if (err > 0) if (err > 0)
...@@ -1357,7 +1367,8 @@ void ip6_flush_pending_frames(struct sock *sk) ...@@ -1357,7 +1367,8 @@ void ip6_flush_pending_frames(struct sock *sk)
struct sk_buff *skb; struct sk_buff *skb;
while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL) { while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL) {
IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS); IP6_INC_STATS(ip6_dst_idev(skb->dst),
IPSTATS_MIB_OUTDISCARDS);
kfree_skb(skb); kfree_skb(skb);
} }
......
...@@ -1465,7 +1465,7 @@ static void mld_sendpack(struct sk_buff *skb) ...@@ -1465,7 +1465,7 @@ static void mld_sendpack(struct sk_buff *skb)
struct inet6_dev *idev = in6_dev_get(skb->dev); struct inet6_dev *idev = in6_dev_get(skb->dev);
int err; int err;
IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS); IP6_INC_STATS(idev, IPSTATS_MIB_OUTREQUESTS);
payload_len = skb->tail - (unsigned char *)skb->nh.ipv6h - payload_len = skb->tail - (unsigned char *)skb->nh.ipv6h -
sizeof(struct ipv6hdr); sizeof(struct ipv6hdr);
mldlen = skb->tail - skb->h.raw; mldlen = skb->tail - skb->h.raw;
...@@ -1477,9 +1477,9 @@ static void mld_sendpack(struct sk_buff *skb) ...@@ -1477,9 +1477,9 @@ static void mld_sendpack(struct sk_buff *skb)
mld_dev_queue_xmit); mld_dev_queue_xmit);
if (!err) { if (!err) {
ICMP6_INC_STATS(idev,ICMP6_MIB_OUTMSGS); ICMP6_INC_STATS(idev,ICMP6_MIB_OUTMSGS);
IP6_INC_STATS(IPSTATS_MIB_OUTMCASTPKTS); IP6_INC_STATS(idev, IPSTATS_MIB_OUTMCASTPKTS);
} else } else
IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS); IP6_INC_STATS(idev, IPSTATS_MIB_OUTDISCARDS);
if (likely(idev != NULL)) if (likely(idev != NULL))
in6_dev_put(idev); in6_dev_put(idev);
...@@ -1763,7 +1763,10 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type) ...@@ -1763,7 +1763,10 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
IPV6_TLV_ROUTERALERT, 2, 0, 0, IPV6_TLV_ROUTERALERT, 2, 0, 0,
IPV6_TLV_PADN, 0 }; IPV6_TLV_PADN, 0 };
IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS); rcu_read_lock();
IP6_INC_STATS(__in6_dev_get(dev),
IPSTATS_MIB_OUTREQUESTS);
rcu_read_unlock();
snd_addr = addr; snd_addr = addr;
if (type == ICMPV6_MGM_REDUCTION) { if (type == ICMPV6_MGM_REDUCTION) {
snd_addr = &all_routers; snd_addr = &all_routers;
...@@ -1777,7 +1780,10 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type) ...@@ -1777,7 +1780,10 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
skb = sock_alloc_send_skb(sk, LL_RESERVED_SPACE(dev) + full_len, 1, &err); skb = sock_alloc_send_skb(sk, LL_RESERVED_SPACE(dev) + full_len, 1, &err);
if (skb == NULL) { if (skb == NULL) {
IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS); rcu_read_lock();
IP6_INC_STATS(__in6_dev_get(dev),
IPSTATS_MIB_OUTDISCARDS);
rcu_read_unlock();
return; return;
} }
...@@ -1816,9 +1822,9 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type) ...@@ -1816,9 +1822,9 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
else else
ICMP6_INC_STATS(idev, ICMP6_MIB_OUTGROUPMEMBRESPONSES); ICMP6_INC_STATS(idev, ICMP6_MIB_OUTGROUPMEMBRESPONSES);
ICMP6_INC_STATS(idev, ICMP6_MIB_OUTMSGS); ICMP6_INC_STATS(idev, ICMP6_MIB_OUTMSGS);
IP6_INC_STATS(IPSTATS_MIB_OUTMCASTPKTS); IP6_INC_STATS(idev, IPSTATS_MIB_OUTMCASTPKTS);
} else } else
IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS); IP6_INC_STATS(idev, IPSTATS_MIB_OUTDISCARDS);
if (likely(idev != NULL)) if (likely(idev != NULL))
in6_dev_put(idev); in6_dev_put(idev);
......
...@@ -515,7 +515,7 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh, ...@@ -515,7 +515,7 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh,
skb->dst = dst; skb->dst = dst;
idev = in6_dev_get(dst->dev); idev = in6_dev_get(dst->dev);
IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS); IP6_INC_STATS(idev, IPSTATS_MIB_OUTREQUESTS);
err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, dst->dev, dst_output); err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, dst->dev, dst_output);
if (!err) { if (!err) {
ICMP6_INC_STATS(idev, ICMP6_MIB_OUTNEIGHBORADVERTISEMENTS); ICMP6_INC_STATS(idev, ICMP6_MIB_OUTNEIGHBORADVERTISEMENTS);
...@@ -601,7 +601,7 @@ void ndisc_send_ns(struct net_device *dev, struct neighbour *neigh, ...@@ -601,7 +601,7 @@ void ndisc_send_ns(struct net_device *dev, struct neighbour *neigh,
/* send it! */ /* send it! */
skb->dst = dst; skb->dst = dst;
idev = in6_dev_get(dst->dev); idev = in6_dev_get(dst->dev);
IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS); IP6_INC_STATS(idev, IPSTATS_MIB_OUTREQUESTS);
err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, dst->dev, dst_output); err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, dst->dev, dst_output);
if (!err) { if (!err) {
ICMP6_INC_STATS(idev, ICMP6_MIB_OUTNEIGHBORSOLICITS); ICMP6_INC_STATS(idev, ICMP6_MIB_OUTNEIGHBORSOLICITS);
...@@ -676,7 +676,7 @@ void ndisc_send_rs(struct net_device *dev, struct in6_addr *saddr, ...@@ -676,7 +676,7 @@ void ndisc_send_rs(struct net_device *dev, struct in6_addr *saddr,
/* send it! */ /* send it! */
skb->dst = dst; skb->dst = dst;
idev = in6_dev_get(dst->dev); idev = in6_dev_get(dst->dev);
IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS); IP6_INC_STATS(idev, IPSTATS_MIB_OUTREQUESTS);
err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, dst->dev, dst_output); err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, dst->dev, dst_output);
if (!err) { if (!err) {
ICMP6_INC_STATS(idev, ICMP6_MIB_OUTROUTERSOLICITS); ICMP6_INC_STATS(idev, ICMP6_MIB_OUTROUTERSOLICITS);
...@@ -1512,7 +1512,7 @@ void ndisc_send_redirect(struct sk_buff *skb, struct neighbour *neigh, ...@@ -1512,7 +1512,7 @@ void ndisc_send_redirect(struct sk_buff *skb, struct neighbour *neigh,
buff->dst = dst; buff->dst = dst;
idev = in6_dev_get(dst->dev); idev = in6_dev_get(dst->dev);
IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS); IP6_INC_STATS(idev, IPSTATS_MIB_OUTREQUESTS);
err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, buff, NULL, dst->dev, dst_output); err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, buff, NULL, dst->dev, dst_output);
if (!err) { if (!err) {
ICMP6_INC_STATS(idev, ICMP6_MIB_OUTREDIRECTS); ICMP6_INC_STATS(idev, ICMP6_MIB_OUTREDIRECTS);
......
...@@ -31,7 +31,7 @@ int ip6_route_me_harder(struct sk_buff *skb) ...@@ -31,7 +31,7 @@ int ip6_route_me_harder(struct sk_buff *skb)
#endif #endif
if (dst->error) { if (dst->error) {
IP6_INC_STATS(IPSTATS_MIB_OUTNOROUTES); IP6_INC_STATS(ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES);
LIMIT_NETDEBUG(KERN_DEBUG "ip6_route_me_harder: No more route.\n"); LIMIT_NETDEBUG(KERN_DEBUG "ip6_route_me_harder: No more route.\n");
dst_release(dst); dst_release(dst);
return -EINVAL; return -EINVAL;
......
...@@ -161,6 +161,7 @@ static int snmp6_seq_show(struct seq_file *seq, void *v) ...@@ -161,6 +161,7 @@ static int snmp6_seq_show(struct seq_file *seq, void *v)
if (idev) { if (idev) {
seq_printf(seq, "%-32s\t%u\n", "ifIndex", idev->dev->ifindex); seq_printf(seq, "%-32s\t%u\n", "ifIndex", idev->dev->ifindex);
snmp6_seq_show_item(seq, (void **)idev->stats.ipv6, snmp6_ipstats_list);
snmp6_seq_show_item(seq, (void **)idev->stats.icmpv6, snmp6_icmp6_list); snmp6_seq_show_item(seq, (void **)idev->stats.icmpv6, snmp6_icmp6_list);
} else { } else {
snmp6_seq_show_item(seq, (void **)ipv6_statistics, snmp6_ipstats_list); snmp6_seq_show_item(seq, (void **)ipv6_statistics, snmp6_ipstats_list);
...@@ -281,6 +282,9 @@ int snmp6_alloc_dev(struct inet6_dev *idev) ...@@ -281,6 +282,9 @@ int snmp6_alloc_dev(struct inet6_dev *idev)
if (!idev || !idev->dev) if (!idev || !idev->dev)
return -EINVAL; return -EINVAL;
if (snmp6_mib_init((void **)idev->stats.ipv6, sizeof(struct ipstats_mib),
__alignof__(struct ipstats_mib)) < 0)
goto err_ip;
if (snmp6_mib_init((void **)idev->stats.icmpv6, sizeof(struct icmpv6_mib), if (snmp6_mib_init((void **)idev->stats.icmpv6, sizeof(struct icmpv6_mib),
__alignof__(struct icmpv6_mib)) < 0) __alignof__(struct icmpv6_mib)) < 0)
goto err_icmp; goto err_icmp;
...@@ -288,12 +292,15 @@ int snmp6_alloc_dev(struct inet6_dev *idev) ...@@ -288,12 +292,15 @@ int snmp6_alloc_dev(struct inet6_dev *idev)
return 0; return 0;
err_icmp: err_icmp:
snmp6_mib_free((void **)idev->stats.ipv6);
err_ip:
return err; return err;
} }
int snmp6_free_dev(struct inet6_dev *idev) int snmp6_free_dev(struct inet6_dev *idev)
{ {
snmp6_mib_free((void **)idev->stats.icmpv6); snmp6_mib_free((void **)idev->stats.icmpv6);
snmp6_mib_free((void **)idev->stats.ipv6);
return 0; return 0;
} }
......
...@@ -586,7 +586,7 @@ static int rawv6_send_hdrinc(struct sock *sk, void *from, int length, ...@@ -586,7 +586,7 @@ static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
if (err) if (err)
goto error_fault; goto error_fault;
IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS); IP6_INC_STATS(rt->rt6i_idev, IPSTATS_MIB_OUTREQUESTS);
err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, rt->u.dst.dev, err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
dst_output); dst_output);
if (err > 0) if (err > 0)
...@@ -600,7 +600,7 @@ static int rawv6_send_hdrinc(struct sock *sk, void *from, int length, ...@@ -600,7 +600,7 @@ static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
err = -EFAULT; err = -EFAULT;
kfree_skb(skb); kfree_skb(skb);
error: error:
IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS); IP6_INC_STATS(rt->rt6i_idev, IPSTATS_MIB_OUTDISCARDS);
return err; return err;
} }
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include <net/snmp.h> #include <net/snmp.h>
#include <net/ipv6.h> #include <net/ipv6.h>
#include <net/ip6_route.h>
#include <net/protocol.h> #include <net/protocol.h>
#include <net/transp_v6.h> #include <net/transp_v6.h>
#include <net/rawv6.h> #include <net/rawv6.h>
...@@ -257,7 +258,7 @@ static __inline__ void fq_kill(struct frag_queue *fq) ...@@ -257,7 +258,7 @@ static __inline__ void fq_kill(struct frag_queue *fq)
} }
} }
static void ip6_evictor(void) static void ip6_evictor(struct inet6_dev *idev)
{ {
struct frag_queue *fq; struct frag_queue *fq;
struct list_head *tmp; struct list_head *tmp;
...@@ -284,14 +285,14 @@ static void ip6_evictor(void) ...@@ -284,14 +285,14 @@ static void ip6_evictor(void)
spin_unlock(&fq->lock); spin_unlock(&fq->lock);
fq_put(fq, &work); fq_put(fq, &work);
IP6_INC_STATS_BH(IPSTATS_MIB_REASMFAILS); IP6_INC_STATS_BH(idev, IPSTATS_MIB_REASMFAILS);
} }
} }
static void ip6_frag_expire(unsigned long data) static void ip6_frag_expire(unsigned long data)
{ {
struct frag_queue *fq = (struct frag_queue *) data; struct frag_queue *fq = (struct frag_queue *) data;
struct net_device *dev; struct net_device *dev = NULL;
spin_lock(&fq->lock); spin_lock(&fq->lock);
...@@ -300,17 +301,19 @@ static void ip6_frag_expire(unsigned long data) ...@@ -300,17 +301,19 @@ static void ip6_frag_expire(unsigned long data)
fq_kill(fq); fq_kill(fq);
IP6_INC_STATS_BH(IPSTATS_MIB_REASMTIMEOUT); dev = dev_get_by_index(fq->iif);
IP6_INC_STATS_BH(IPSTATS_MIB_REASMFAILS); if (!dev)
goto out;
rcu_read_lock();
IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMTIMEOUT);
IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMFAILS);
rcu_read_unlock();
/* Don't send error if the first segment did not arrive. */ /* Don't send error if the first segment did not arrive. */
if (!(fq->last_in&FIRST_IN) || !fq->fragments) if (!(fq->last_in&FIRST_IN) || !fq->fragments)
goto out; goto out;
dev = dev_get_by_index(fq->iif);
if (!dev)
goto out;
/* /*
But use as source device on which LAST ARRIVED But use as source device on which LAST ARRIVED
segment was received. And do not use fq->dev segment was received. And do not use fq->dev
...@@ -318,8 +321,9 @@ static void ip6_frag_expire(unsigned long data) ...@@ -318,8 +321,9 @@ static void ip6_frag_expire(unsigned long data)
*/ */
fq->fragments->dev = dev; fq->fragments->dev = dev;
icmpv6_send(fq->fragments, ICMPV6_TIME_EXCEED, ICMPV6_EXC_FRAGTIME, 0, dev); icmpv6_send(fq->fragments, ICMPV6_TIME_EXCEED, ICMPV6_EXC_FRAGTIME, 0, dev);
dev_put(dev);
out: out:
if (dev)
dev_put(dev);
spin_unlock(&fq->lock); spin_unlock(&fq->lock);
fq_put(fq, NULL); fq_put(fq, NULL);
} }
...@@ -366,7 +370,8 @@ static struct frag_queue *ip6_frag_intern(struct frag_queue *fq_in) ...@@ -366,7 +370,8 @@ static struct frag_queue *ip6_frag_intern(struct frag_queue *fq_in)
static struct frag_queue * static struct frag_queue *
ip6_frag_create(u32 id, struct in6_addr *src, struct in6_addr *dst) ip6_frag_create(u32 id, struct in6_addr *src, struct in6_addr *dst,
struct inet6_dev *idev)
{ {
struct frag_queue *fq; struct frag_queue *fq;
...@@ -386,12 +391,13 @@ ip6_frag_create(u32 id, struct in6_addr *src, struct in6_addr *dst) ...@@ -386,12 +391,13 @@ ip6_frag_create(u32 id, struct in6_addr *src, struct in6_addr *dst)
return ip6_frag_intern(fq); return ip6_frag_intern(fq);
oom: oom:
IP6_INC_STATS_BH(IPSTATS_MIB_REASMFAILS); IP6_INC_STATS_BH(idev, IPSTATS_MIB_REASMFAILS);
return NULL; return NULL;
} }
static __inline__ struct frag_queue * static __inline__ struct frag_queue *
fq_find(u32 id, struct in6_addr *src, struct in6_addr *dst) fq_find(u32 id, struct in6_addr *src, struct in6_addr *dst,
struct inet6_dev *idev)
{ {
struct frag_queue *fq; struct frag_queue *fq;
struct hlist_node *n; struct hlist_node *n;
...@@ -410,7 +416,7 @@ fq_find(u32 id, struct in6_addr *src, struct in6_addr *dst) ...@@ -410,7 +416,7 @@ fq_find(u32 id, struct in6_addr *src, struct in6_addr *dst)
} }
read_unlock(&ip6_frag_lock); read_unlock(&ip6_frag_lock);
return ip6_frag_create(id, src, dst); return ip6_frag_create(id, src, dst, idev);
} }
...@@ -428,7 +434,8 @@ static void ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, ...@@ -428,7 +434,8 @@ static void ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
((u8 *) (fhdr + 1) - (u8 *) (skb->nh.ipv6h + 1))); ((u8 *) (fhdr + 1) - (u8 *) (skb->nh.ipv6h + 1)));
if ((unsigned int)end > IPV6_MAXPLEN) { if ((unsigned int)end > IPV6_MAXPLEN) {
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INHDRERRORS);
icmpv6_param_prob(skb,ICMPV6_HDR_FIELD, (u8*)&fhdr->frag_off - skb->nh.raw); icmpv6_param_prob(skb,ICMPV6_HDR_FIELD, (u8*)&fhdr->frag_off - skb->nh.raw);
return; return;
} }
...@@ -455,7 +462,8 @@ static void ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, ...@@ -455,7 +462,8 @@ static void ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
/* RFC2460 says always send parameter problem in /* RFC2460 says always send parameter problem in
* this case. -DaveM * this case. -DaveM
*/ */
IP6_INC_STATS_BH(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst),
IPSTATS_MIB_INHDRERRORS);
icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, icmpv6_param_prob(skb, ICMPV6_HDR_FIELD,
offsetof(struct ipv6hdr, payload_len)); offsetof(struct ipv6hdr, payload_len));
return; return;
...@@ -571,7 +579,7 @@ static void ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, ...@@ -571,7 +579,7 @@ static void ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,
return; return;
err: err:
IP6_INC_STATS(IPSTATS_MIB_REASMFAILS); IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMFAILS);
kfree_skb(skb); kfree_skb(skb);
} }
...@@ -665,7 +673,9 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff **skb_in, ...@@ -665,7 +673,9 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff **skb_in,
if (head->ip_summed == CHECKSUM_COMPLETE) if (head->ip_summed == CHECKSUM_COMPLETE)
head->csum = csum_partial(head->nh.raw, head->h.raw-head->nh.raw, head->csum); head->csum = csum_partial(head->nh.raw, head->h.raw-head->nh.raw, head->csum);
IP6_INC_STATS_BH(IPSTATS_MIB_REASMOKS); rcu_read_lock();
IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMOKS);
rcu_read_unlock();
fq->fragments = NULL; fq->fragments = NULL;
return 1; return 1;
...@@ -677,7 +687,9 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff **skb_in, ...@@ -677,7 +687,9 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff **skb_in,
if (net_ratelimit()) if (net_ratelimit())
printk(KERN_DEBUG "ip6_frag_reasm: no memory for reassembly\n"); printk(KERN_DEBUG "ip6_frag_reasm: no memory for reassembly\n");
out_fail: out_fail:
IP6_INC_STATS_BH(IPSTATS_MIB_REASMFAILS); rcu_read_lock();
IP6_INC_STATS_BH(__in6_dev_get(dev), IPSTATS_MIB_REASMFAILS);
rcu_read_unlock();
return -1; return -1;
} }
...@@ -691,16 +703,16 @@ static int ipv6_frag_rcv(struct sk_buff **skbp) ...@@ -691,16 +703,16 @@ static int ipv6_frag_rcv(struct sk_buff **skbp)
hdr = skb->nh.ipv6h; hdr = skb->nh.ipv6h;
IP6_INC_STATS_BH(IPSTATS_MIB_REASMREQDS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMREQDS);
/* Jumbo payload inhibits frag. header */ /* Jumbo payload inhibits frag. header */
if (hdr->payload_len==0) { if (hdr->payload_len==0) {
IP6_INC_STATS(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_INHDRERRORS);
icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, skb->h.raw-skb->nh.raw); icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, skb->h.raw-skb->nh.raw);
return -1; return -1;
} }
if (!pskb_may_pull(skb, (skb->h.raw-skb->data)+sizeof(struct frag_hdr))) { if (!pskb_may_pull(skb, (skb->h.raw-skb->data)+sizeof(struct frag_hdr))) {
IP6_INC_STATS(IPSTATS_MIB_INHDRERRORS); IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_INHDRERRORS);
icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, skb->h.raw-skb->nh.raw); icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, skb->h.raw-skb->nh.raw);
return -1; return -1;
} }
...@@ -711,16 +723,17 @@ static int ipv6_frag_rcv(struct sk_buff **skbp) ...@@ -711,16 +723,17 @@ static int ipv6_frag_rcv(struct sk_buff **skbp)
if (!(fhdr->frag_off & htons(0xFFF9))) { if (!(fhdr->frag_off & htons(0xFFF9))) {
/* It is not a fragmented frame */ /* It is not a fragmented frame */
skb->h.raw += sizeof(struct frag_hdr); skb->h.raw += sizeof(struct frag_hdr);
IP6_INC_STATS_BH(IPSTATS_MIB_REASMOKS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMOKS);
IP6CB(skb)->nhoff = (u8*)fhdr - skb->nh.raw; IP6CB(skb)->nhoff = (u8*)fhdr - skb->nh.raw;
return 1; return 1;
} }
if (atomic_read(&ip6_frag_mem) > sysctl_ip6frag_high_thresh) if (atomic_read(&ip6_frag_mem) > sysctl_ip6frag_high_thresh)
ip6_evictor(); ip6_evictor(ip6_dst_idev(skb->dst));
if ((fq = fq_find(fhdr->identification, &hdr->saddr, &hdr->daddr)) != NULL) { if ((fq = fq_find(fhdr->identification, &hdr->saddr, &hdr->daddr,
ip6_dst_idev(skb->dst))) != NULL) {
int ret = -1; int ret = -1;
spin_lock(&fq->lock); spin_lock(&fq->lock);
...@@ -736,7 +749,7 @@ static int ipv6_frag_rcv(struct sk_buff **skbp) ...@@ -736,7 +749,7 @@ static int ipv6_frag_rcv(struct sk_buff **skbp)
return ret; return ret;
} }
IP6_INC_STATS_BH(IPSTATS_MIB_REASMFAILS); IP6_INC_STATS_BH(ip6_dst_idev(skb->dst), IPSTATS_MIB_REASMFAILS);
kfree_skb(skb); kfree_skb(skb);
return -1; return -1;
} }
......
...@@ -1749,9 +1749,9 @@ static inline int ip6_pkt_drop(struct sk_buff *skb, int code) ...@@ -1749,9 +1749,9 @@ static inline int ip6_pkt_drop(struct sk_buff *skb, int code)
{ {
int type = ipv6_addr_type(&skb->nh.ipv6h->daddr); int type = ipv6_addr_type(&skb->nh.ipv6h->daddr);
if (type == IPV6_ADDR_ANY || type == IPV6_ADDR_RESERVED) if (type == IPV6_ADDR_ANY || type == IPV6_ADDR_RESERVED)
IP6_INC_STATS(IPSTATS_MIB_INADDRERRORS); IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_INADDRERRORS);
IP6_INC_STATS(IPSTATS_MIB_OUTNOROUTES); IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_OUTNOROUTES);
icmpv6_send(skb, ICMPV6_DEST_UNREACH, code, 0, skb->dev); icmpv6_send(skb, ICMPV6_DEST_UNREACH, code, 0, skb->dev);
kfree_skb(skb); kfree_skb(skb);
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册