From 1db8a26af865333c8ab9a0a846da3c1ef42b9c06 Mon Sep 17 00:00:00 2001 From: Hideaki Yoshifuji Date: Wed, 2 Jun 2004 12:05:31 +0900 Subject: [PATCH] [IPV4] use ip-independent ipstats_mib to store IPv4 statistics. --- include/net/ip.h | 2 +- include/net/snmp.h | 24 -------------------- net/ipv4/af_inet.c | 4 ++-- net/ipv4/ip_forward.c | 2 +- net/ipv4/ip_fragment.c | 14 ++++++------ net/ipv4/ip_input.c | 18 +++++++-------- net/ipv4/ip_output.c | 22 +++++++++---------- net/ipv4/ipmr.c | 4 ++-- net/ipv4/proc.c | 50 ++++++++++++++++++++++++++++++++---------- net/ipv4/raw.c | 2 +- net/ipv4/tcp_ipv4.c | 4 ++-- net/sctp/output.c | 2 +- 12 files changed, 76 insertions(+), 72 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index 0caf7bc577baa..94ea1eda3b3dc 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -150,7 +150,7 @@ struct ipv4_config }; extern struct ipv4_config ipv4_config; -DECLARE_SNMP_STAT(struct ip_mib, ip_statistics); +DECLARE_SNMP_STAT(struct ipstats_mib, ip_statistics); #define IP_INC_STATS(field) SNMP_INC_STATS(ip_statistics, field) #define IP_INC_STATS_BH(field) SNMP_INC_STATS_BH(ip_statistics, field) #define IP_INC_STATS_USER(field) SNMP_INC_STATS_USER(ip_statistics, field) diff --git a/include/net/snmp.h b/include/net/snmp.h index 6278d79d8afee..c702dda23a4ba 100644 --- a/include/net/snmp.h +++ b/include/net/snmp.h @@ -60,30 +60,6 @@ struct snmp_item { * RFC 1213: MIB-II * RFC 2011 (updates 1213): SNMPv2-MIB-IP * RFC 2863: Interfaces Group MIB - */ -struct ip_mib -{ - unsigned long IpInReceives; - unsigned long IpInHdrErrors; - unsigned long IpInAddrErrors; - unsigned long IpForwDatagrams; - unsigned long IpInUnknownProtos; - unsigned long IpInDiscards; - unsigned long IpInDelivers; - unsigned long IpOutRequests; - unsigned long IpOutDiscards; - unsigned long IpOutNoRoutes; - unsigned long IpReasmTimeout; - unsigned long IpReasmReqds; - unsigned long IpReasmOKs; - unsigned long IpReasmFails; - unsigned long IpFragOKs; - unsigned long IpFragFails; - unsigned long IpFragCreates; - unsigned long __pad[0]; -}; - -/* * RFC 2465: IPv6 MIB: General Group * draft-ietf-ipv6-rfc2011-update-10.txt: MIB for IP: IP Statistics Tables */ diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index db0931a9a75f4..8b14637aa8a2d 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1066,8 +1066,8 @@ static int __init init_ipv4_mibs(void) { net_statistics[0] = alloc_percpu(struct linux_mib); net_statistics[1] = alloc_percpu(struct linux_mib); - ip_statistics[0] = alloc_percpu(struct ip_mib); - ip_statistics[1] = alloc_percpu(struct ip_mib); + ip_statistics[0] = alloc_percpu(struct ipstats_mib); + ip_statistics[1] = alloc_percpu(struct ipstats_mib); icmp_statistics[0] = alloc_percpu(struct icmp_mib); icmp_statistics[1] = alloc_percpu(struct icmp_mib); tcp_statistics[0] = alloc_percpu(struct tcp_mib); diff --git a/net/ipv4/ip_forward.c b/net/ipv4/ip_forward.c index f26d67ca69eb2..be1e87c11a2cb 100644 --- a/net/ipv4/ip_forward.c +++ b/net/ipv4/ip_forward.c @@ -46,7 +46,7 @@ static inline int ip_forward_finish(struct sk_buff *skb) { struct ip_options * opt = &(IPCB(skb)->opt); - IP_INC_STATS_BH(IpForwDatagrams); + IP_INC_STATS_BH(OutForwDatagrams); if (unlikely(opt->optlen)) ip_forward_options(skb); diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c index 375caffe0c194..1f007c67b5e74 100644 --- a/net/ipv4/ip_fragment.c +++ b/net/ipv4/ip_fragment.c @@ -263,7 +263,7 @@ static void ip_evictor(void) spin_unlock(&qp->lock); ipq_put(qp); - IP_INC_STATS_BH(IpReasmFails); + IP_INC_STATS_BH(ReasmFails); } } @@ -281,8 +281,8 @@ static void ip_expire(unsigned long arg) ipq_kill(qp); - IP_INC_STATS_BH(IpReasmTimeout); - IP_INC_STATS_BH(IpReasmFails); + IP_INC_STATS_BH(ReasmTimeout); + IP_INC_STATS_BH(ReasmFails); if ((qp->last_in&FIRST_IN) && qp->fragments != NULL) { struct sk_buff *head = qp->fragments; @@ -609,7 +609,7 @@ static struct sk_buff *ip_frag_reasm(struct ipq *qp, struct net_device *dev) iph = head->nh.iph; iph->frag_off = 0; iph->tot_len = htons(len); - IP_INC_STATS_BH(IpReasmOKs); + IP_INC_STATS_BH(ReasmOKs); qp->fragments = NULL; return head; @@ -625,7 +625,7 @@ out_oversize: "Oversized IP packet from %d.%d.%d.%d.\n", NIPQUAD(qp->saddr)); out_fail: - IP_INC_STATS_BH(IpReasmFails); + IP_INC_STATS_BH(ReasmFails); return NULL; } @@ -636,7 +636,7 @@ struct sk_buff *ip_defrag(struct sk_buff *skb) struct ipq *qp; struct net_device *dev; - IP_INC_STATS_BH(IpReasmReqds); + IP_INC_STATS_BH(ReasmReqds); /* Start by cleaning up the memory. */ if (atomic_read(&ip_frag_mem) > sysctl_ipfrag_high_thresh) @@ -661,7 +661,7 @@ struct sk_buff *ip_defrag(struct sk_buff *skb) return ret; } - IP_INC_STATS_BH(IpReasmFails); + IP_INC_STATS_BH(ReasmFails); kfree_skb(skb); return NULL; } diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index 904f20aba8ce8..2f71ed5cfcc9e 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -150,7 +150,7 @@ * SNMP management statistics */ -DEFINE_SNMP_STAT(struct ip_mib, ip_statistics); +DEFINE_SNMP_STAT(struct ipstats_mib, ip_statistics); /* * Process Router Attention IP option @@ -249,16 +249,16 @@ static inline int ip_local_deliver_finish(struct sk_buff *skb) protocol = -ret; goto resubmit; } - IP_INC_STATS_BH(IpInDelivers); + IP_INC_STATS_BH(InDelivers); } else { if (!raw_sk) { if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) { - IP_INC_STATS_BH(IpInUnknownProtos); + IP_INC_STATS_BH(InUnknownProtos); icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PROT_UNREACH, 0); } } else - IP_INC_STATS_BH(IpInDelivers); + IP_INC_STATS_BH(InDelivers); kfree_skb(skb); } } @@ -324,7 +324,7 @@ static inline int ip_rcv_finish(struct sk_buff *skb) */ if (skb_cow(skb, skb_headroom(skb))) { - IP_INC_STATS_BH(IpInDiscards); + IP_INC_STATS_BH(InDiscards); goto drop; } iph = skb->nh.iph; @@ -353,7 +353,7 @@ static inline int ip_rcv_finish(struct sk_buff *skb) return dst_input(skb); inhdr_error: - IP_INC_STATS_BH(IpInHdrErrors); + IP_INC_STATS_BH(InHdrErrors); drop: kfree_skb(skb); return NET_RX_DROP; @@ -372,10 +372,10 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt) if (skb->pkt_type == PACKET_OTHERHOST) goto drop; - IP_INC_STATS_BH(IpInReceives); + IP_INC_STATS_BH(InReceives); if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) { - IP_INC_STATS_BH(IpInDiscards); + IP_INC_STATS_BH(InDiscards); goto out; } @@ -426,7 +426,7 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt) ip_rcv_finish); inhdr_error: - IP_INC_STATS_BH(IpInHdrErrors); + IP_INC_STATS_BH(InHdrErrors); drop: kfree_skb(skb); out: diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 543dfba0be74d..e9b7d78c8e1cd 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -232,7 +232,7 @@ int ip_mc_output(struct sk_buff *skb) /* * If the indicated interface is up and running, send the packet. */ - IP_INC_STATS(IpOutRequests); + IP_INC_STATS(OutRequests); skb->dev = dev; skb->protocol = htons(ETH_P_IP); @@ -285,7 +285,7 @@ int ip_mc_output(struct sk_buff *skb) int ip_output(struct sk_buff *skb) { - IP_INC_STATS(IpOutRequests); + IP_INC_STATS(OutRequests); if ((skb->len > dst_pmtu(skb->dst) || skb_shinfo(skb)->frag_list) && !skb_shinfo(skb)->tso_size) @@ -390,7 +390,7 @@ packet_routed: dst_output); no_route: - IP_INC_STATS(IpOutNoRoutes); + IP_INC_STATS(OutNoRoutes); kfree_skb(skb); return -EHOSTUNREACH; } @@ -547,7 +547,7 @@ int ip_fragment(struct sk_buff *skb, int (*output)(struct sk_buff*)) } if (err == 0) { - IP_INC_STATS(IpFragOKs); + IP_INC_STATS(FragOKs); return 0; } @@ -556,7 +556,7 @@ int ip_fragment(struct sk_buff *skb, int (*output)(struct sk_buff*)) kfree_skb(frag); frag = skb; } - IP_INC_STATS(IpFragFails); + IP_INC_STATS(FragFails); return err; } @@ -662,7 +662,7 @@ slow_path: * Put this fragment into the sending queue. */ - IP_INC_STATS(IpFragCreates); + IP_INC_STATS(FragCreates); iph->tot_len = htons(len + hlen); @@ -673,12 +673,12 @@ slow_path: goto fail; } kfree_skb(skb); - IP_INC_STATS(IpFragOKs); + IP_INC_STATS(FragOKs); return err; fail: kfree_skb(skb); - IP_INC_STATS(IpFragFails); + IP_INC_STATS(FragFails); return err; } @@ -975,7 +975,7 @@ alloc_new_skb: error: inet->cork.length -= length; - IP_INC_STATS(IpOutDiscards); + IP_INC_STATS(OutDiscards); return err; } @@ -1088,7 +1088,7 @@ ssize_t ip_append_page(struct sock *sk, struct page *page, error: inet->cork.length -= size; - IP_INC_STATS(IpOutDiscards); + IP_INC_STATS(OutDiscards); return err; } @@ -1198,7 +1198,7 @@ out: return err; error: - IP_INC_STATS(IpOutDiscards); + IP_INC_STATS(OutDiscards); goto out; } diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 46f36a5c6118f..64ccce5256455 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -1115,7 +1115,7 @@ static inline int ipmr_forward_finish(struct sk_buff *skb) { struct ip_options * opt = &(IPCB(skb)->opt); - IP_INC_STATS_BH(IpForwDatagrams); + IP_INC_STATS_BH(OutForwDatagrams); if (unlikely(opt->optlen)) ip_forward_options(skb); @@ -1178,7 +1178,7 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi) to blackhole. */ - IP_INC_STATS_BH(IpFragFails); + IP_INC_STATS_BH(FragFails); ip_rt_put(rt); goto out_free; } diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c index 416e2e5529a01..be47cbec57be5 100644 --- a/net/ipv4/proc.c +++ b/net/ipv4/proc.c @@ -88,7 +88,7 @@ static struct file_operations sockstat_seq_fops = { }; static unsigned long -fold_field(void *mib[], int nr) +__fold_field(void *mib[], int offt) { unsigned long res = 0; int i; @@ -98,14 +98,41 @@ fold_field(void *mib[], int nr) continue; res += *((unsigned long *) (((void *) per_cpu_ptr(mib[0], i)) + - sizeof (unsigned long) * nr)); + offt)); res += *((unsigned long *) (((void *) per_cpu_ptr(mib[1], i)) + - sizeof (unsigned long) * nr)); + offt)); } return res; } +#define fold_field(_mib, _nr) __fold_field(_mib, (sizeof(unsigned long) * (_nr))) + +/* snmp items */ +static struct snmp_item snmp4_ipstats_list[] = { +#define __SNMP_GEN(x,y) SNMP_ITEM(struct ipstats_mib, x, y) +#define SNMP_GEN(x) __SNMP_GEN(x, #x) + SNMP_GEN(InReceives), + SNMP_GEN(InHdrErrors), + SNMP_GEN(InAddrErrors), + __SNMP_GEN(OutForwDatagrams,"ForwDatagrams"), /* for backward compatibility */ + SNMP_GEN(InUnknownProtos), + SNMP_GEN(InDiscards), + SNMP_GEN(InDelivers), + SNMP_GEN(OutRequests), + SNMP_GEN(OutDiscards), + SNMP_GEN(OutNoRoutes), + SNMP_GEN(ReasmTimeout), + SNMP_GEN(ReasmReqds), + SNMP_GEN(ReasmOKs), + SNMP_GEN(ReasmFails), + SNMP_GEN(FragOKs), + SNMP_GEN(FragFails), + SNMP_GEN(FragCreates), + SNMP_ITEM_SENTINEL +#undef SNMP_GEN +}; + /* * Called from the PROCfs module. This outputs /proc/net/snmp. */ @@ -113,17 +140,18 @@ static int snmp_seq_show(struct seq_file *seq, void *v) { int i; - seq_printf(seq, "Ip: Forwarding DefaultTTL InReceives InHdrErrors " - "InAddrErrors ForwDatagrams InUnknownProtos " - "InDiscards InDelivers OutRequests OutDiscards " - "OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs " - "ReasmFails FragOKs FragFails FragCreates\nIp: %d %d", + seq_printf(seq, "Ip: Forwarding DefaultTTL"); + + for (i = 0; snmp4_ipstats_list[i].name != NULL; i++) + seq_printf(seq, " %s", snmp4_ipstats_list[i].name); + + seq_printf(seq, "\nIp: %d %d", ipv4_devconf.forwarding ? 1 : 2, sysctl_ip_default_ttl); - for (i = 0; - i < offsetof(struct ip_mib, __pad) / sizeof(unsigned long); i++) + for (i = 0; snmp4_ipstats_list[i].name != NULL; i++) seq_printf(seq, " %lu", - fold_field((void **) ip_statistics, i)); + __fold_field((void **) ip_statistics, + snmp4_ipstats_list[i].offset)); seq_printf(seq, "\nIcmp: InMsgs InErrors InDestUnreachs InTimeExcds " "InParmProbs InSrcQuenchs InRedirects InEchos " diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 755d53aae52d1..8bae6ee8a6963 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -319,7 +319,7 @@ error_fault: err = -EFAULT; kfree_skb(skb); error: - IP_INC_STATS(IpOutDiscards); + IP_INC_STATS(OutDiscards); return err; } diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 87b73c85f18e9..5eeae6dc0ce2c 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1290,12 +1290,12 @@ static struct dst_entry* tcp_v4_route_req(struct sock *sk, .dport = req->rmt_port } } }; if (ip_route_output_flow(&rt, &fl, sk, 0)) { - IP_INC_STATS_BH(IpOutNoRoutes); + IP_INC_STATS_BH(OutNoRoutes); return NULL; } if (opt && opt->is_strictroute && rt->rt_dst != rt->rt_gateway) { ip_rt_put(rt); - IP_INC_STATS_BH(IpOutNoRoutes); + IP_INC_STATS_BH(OutNoRoutes); return NULL; } return &rt->u.dst; diff --git a/net/sctp/output.c b/net/sctp/output.c index 6d45e05c1f1a6..d54f915aee1db 100644 --- a/net/sctp/output.c +++ b/net/sctp/output.c @@ -496,7 +496,7 @@ out: return err; no_route: kfree_skb(nskb); - IP_INC_STATS_BH(IpOutNoRoutes); + IP_INC_STATS_BH(OutNoRoutes); /* FIXME: Returning the 'err' will effect all the associations * associated with a socket, although only one of the paths of the -- 2.53.0