Change UDP stats from a structure to an array of uint64_t's.
Note: This is ABI-compatible with the old icmpstat structure; old netstat binaries will continue to work properly.
This commit is contained in:
parent
67b7abb1ce
commit
738aabaf82
6
sys/dist/pf/net/pf.c
vendored
6
sys/dist/pf/net/pf.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pf.c,v 1.45 2008/04/06 19:04:48 thorpej Exp $ */
|
||||
/* $NetBSD: pf.c,v 1.46 2008/04/06 20:17:27 thorpej Exp $ */
|
||||
/* $OpenBSD: pf.c,v 1.487 2005/04/22 09:53:18 dhartmei Exp $ */
|
||||
|
||||
/*
|
||||
@ -37,7 +37,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: pf.c,v 1.45 2008/04/06 19:04:48 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: pf.c,v 1.46 2008/04/06 20:17:27 thorpej Exp $");
|
||||
|
||||
#include "bpfilter.h"
|
||||
#include "pflog.h"
|
||||
@ -5832,7 +5832,7 @@ pf_check_proto_cksum(struct mbuf *m, int off, int len, u_int8_t p,
|
||||
tcpstat.tcps_rcvbadsum++;
|
||||
break;
|
||||
case IPPROTO_UDP:
|
||||
udpstat.udps_badsum++;
|
||||
udpstat[UDP_STAT_BADSUM]++;
|
||||
break;
|
||||
case IPPROTO_ICMP:
|
||||
icmpstat[ICMP_STAT_CHECKSUM]++;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: udp_usrreq.c,v 1.163 2007/11/27 22:45:30 christos Exp $ */
|
||||
/* $NetBSD: udp_usrreq.c,v 1.164 2008/04/06 20:17:27 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
@ -61,7 +61,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.163 2007/11/27 22:45:30 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.164 2008/04/06 20:17:27 thorpej Exp $");
|
||||
|
||||
#include "opt_inet.h"
|
||||
#include "opt_ipsec.h"
|
||||
@ -143,7 +143,8 @@ int udpcksum = 1;
|
||||
int udp_do_loopback_cksum = 0;
|
||||
|
||||
struct inpcbtable udbtable;
|
||||
struct udpstat udpstat;
|
||||
|
||||
uint64_t udpstat[UDP_NSTATS];
|
||||
|
||||
#ifdef INET
|
||||
#ifdef IPSEC_NAT_T
|
||||
@ -324,7 +325,7 @@ udp4_input_checksum(struct mbuf *m, const struct udphdr *uh,
|
||||
return 0;
|
||||
|
||||
badcsum:
|
||||
udpstat.udps_badsum++;
|
||||
udpstat[UDP_STAT_BADSUM]++;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -346,7 +347,7 @@ udp_input(struct mbuf *m, ...)
|
||||
va_end(ap);
|
||||
|
||||
MCLAIM(m, &udp_rx_mowner);
|
||||
udpstat.udps_ipackets++;
|
||||
udpstat[UDP_STAT_IPACKETS]++;
|
||||
|
||||
/*
|
||||
* Get IP and UDP header together in first mbuf.
|
||||
@ -354,7 +355,7 @@ udp_input(struct mbuf *m, ...)
|
||||
ip = mtod(m, struct ip *);
|
||||
IP6_EXTHDR_GET(uh, struct udphdr *, m, iphlen, sizeof(struct udphdr));
|
||||
if (uh == NULL) {
|
||||
udpstat.udps_hdrops++;
|
||||
udpstat[UDP_STAT_HDROPS]++;
|
||||
return;
|
||||
}
|
||||
KASSERT(UDP_HDR_ALIGNED_P(uh));
|
||||
@ -371,7 +372,7 @@ udp_input(struct mbuf *m, ...)
|
||||
len = ntohs((u_int16_t)uh->uh_ulen);
|
||||
if (ip_len != iphlen + len) {
|
||||
if (ip_len < iphlen + len || len < sizeof(struct udphdr)) {
|
||||
udpstat.udps_badlen++;
|
||||
udpstat[UDP_STAT_BADLEN]++;
|
||||
goto bad;
|
||||
}
|
||||
m_adj(m, iphlen + len - ip_len);
|
||||
@ -388,7 +389,7 @@ udp_input(struct mbuf *m, ...)
|
||||
sockaddr_in_init(&dst, &ip->ip_dst, uh->uh_dport);
|
||||
|
||||
if ((n = udp4_realinput(&src, &dst, &m, iphlen)) == -1) {
|
||||
udpstat.udps_hdrops++;
|
||||
udpstat[UDP_STAT_HDROPS]++;
|
||||
return;
|
||||
}
|
||||
#ifdef INET6
|
||||
@ -416,10 +417,10 @@ udp_input(struct mbuf *m, ...)
|
||||
|
||||
if (n == 0) {
|
||||
if (m->m_flags & (M_BCAST | M_MCAST)) {
|
||||
udpstat.udps_noportbcast++;
|
||||
udpstat[UDP_STAT_NOPORTBCAST]++;
|
||||
goto bad;
|
||||
}
|
||||
udpstat.udps_noport++;
|
||||
udpstat[UDP_STAT_NOPORT]++;
|
||||
#ifdef IPKDB
|
||||
if (checkipkdb(&ip->ip_src, uh->uh_sport, uh->uh_dport,
|
||||
m, iphlen + sizeof(struct udphdr),
|
||||
@ -638,7 +639,7 @@ udp4_sendup(struct mbuf *m, int off /* offset of data portion */,
|
||||
if (opts)
|
||||
m_freem(opts);
|
||||
so->so_rcv.sb_overflowed++;
|
||||
udpstat.udps_fullsock++;
|
||||
udpstat[UDP_STAT_FULLSOCK]++;
|
||||
} else
|
||||
sorwakeup(so);
|
||||
}
|
||||
@ -778,7 +779,7 @@ udp4_realinput(struct sockaddr_in *src, struct sockaddr_in *dst,
|
||||
*/
|
||||
inp = in_pcblookup_connect(&udbtable, *src4, *sport, *dst4, *dport);
|
||||
if (inp == 0) {
|
||||
++udpstat.udps_pcbhashmiss;
|
||||
udpstat[UDP_STAT_PCBHASHMISS]++;
|
||||
inp = in_pcblookup_bind(&udbtable, *dst4, *dport);
|
||||
if (inp == 0)
|
||||
return rcvcnt;
|
||||
@ -926,7 +927,7 @@ udp6_realinput(int af, struct sockaddr_in6 *src, struct sockaddr_in6 *dst,
|
||||
in6p = in6_pcblookup_connect(&udbtable, &src6, sport, dst6,
|
||||
dport, 0);
|
||||
if (in6p == 0) {
|
||||
++udpstat.udps_pcbhashmiss;
|
||||
udpstat[UDP_STAT_PCBHASHMISS]++;
|
||||
in6p = in6_pcblookup_bind(&udbtable, dst6, dport, 0);
|
||||
if (in6p == 0)
|
||||
return rcvcnt;
|
||||
@ -1142,7 +1143,7 @@ udp_output(struct mbuf *m, ...)
|
||||
((struct ip *)ui)->ip_len = htons(sizeof (struct udpiphdr) + len);
|
||||
((struct ip *)ui)->ip_ttl = inp->inp_ip.ip_ttl; /* XXX */
|
||||
((struct ip *)ui)->ip_tos = inp->inp_ip.ip_tos; /* XXX */
|
||||
udpstat.udps_opackets++;
|
||||
udpstat[UDP_STAT_OPACKETS]++;
|
||||
|
||||
return (ip_output(m, inp->inp_options, ro,
|
||||
inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST),
|
||||
@ -1391,7 +1392,7 @@ SYSCTL_SETUP(sysctl_net_inet_udp_setup, "sysctl net.inet.udp subtree setup")
|
||||
CTLFLAG_PERMANENT,
|
||||
CTLTYPE_STRUCT, "stats",
|
||||
SYSCTL_DESCR("UDP statistics"),
|
||||
NULL, 0, &udpstat, sizeof(udpstat),
|
||||
NULL, 0, udpstat, sizeof(udpstat),
|
||||
CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_STATS,
|
||||
CTL_EOL);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: udp_var.h,v 1.33 2007/12/25 18:33:47 perry Exp $ */
|
||||
/* $NetBSD: udp_var.h,v 1.34 2008/04/06 20:17:27 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1989, 1993
|
||||
@ -51,19 +51,21 @@ struct udpiphdr {
|
||||
#define ui_ulen ui_u.uh_ulen
|
||||
#define ui_sum ui_u.uh_sum
|
||||
|
||||
struct udpstat {
|
||||
/* input statistics: */
|
||||
u_quad_t udps_ipackets; /* total input packets */
|
||||
u_quad_t udps_hdrops; /* packet shorter than header */
|
||||
u_quad_t udps_badsum; /* checksum error */
|
||||
u_quad_t udps_badlen; /* data length larger than packet */
|
||||
u_quad_t udps_noport; /* no socket on port */
|
||||
u_quad_t udps_noportbcast; /* of above, arrived as broadcast */
|
||||
u_quad_t udps_fullsock; /* not delivered, input socket full */
|
||||
u_quad_t udps_pcbhashmiss; /* input packets missing pcb hash */
|
||||
/* output statistics: */
|
||||
u_quad_t udps_opackets; /* total output packets */
|
||||
};
|
||||
/*
|
||||
* UDP statistics.
|
||||
* Each counter is an unsigned 64-bit value.
|
||||
*/
|
||||
#define UDP_STAT_IPACKETS 0 /* total input packets */
|
||||
#define UDP_STAT_HDROPS 1 /* packet shorter than header */
|
||||
#define UDP_STAT_BADSUM 2 /* checksum error */
|
||||
#define UDP_STAT_BADLEN 3 /* data length larger than packet */
|
||||
#define UDP_STAT_NOPORT 4 /* no socket on port */
|
||||
#define UDP_STAT_NOPORTBCAST 5 /* of above, arrived as broadcast */
|
||||
#define UDP_STAT_FULLSOCK 6 /* not delivered, input socket full */
|
||||
#define UDP_STAT_PCBHASHMISS 7 /* input packets missing PCB hash */
|
||||
#define UDP_STAT_OPACKETS 8 /* total output packets */
|
||||
|
||||
#define UDP_NSTATS 9
|
||||
|
||||
/*
|
||||
* Names for UDP sysctl objects
|
||||
@ -86,7 +88,7 @@ struct udpstat {
|
||||
|
||||
#ifdef _KERNEL
|
||||
extern struct inpcbtable udbtable;
|
||||
extern struct udpstat udpstat;
|
||||
extern uint64_t udpstat[UDP_NSTATS];
|
||||
|
||||
#ifdef __NO_STRICT_ALIGNMENT
|
||||
#define UDP_HDR_ALIGNED_P(uh) 1
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: inet.c,v 1.79 2008/04/06 19:04:50 thorpej Exp $ */
|
||||
/* $NetBSD: inet.c,v 1.80 2008/04/06 20:17:27 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1988, 1993
|
||||
@ -34,7 +34,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: inet.c,v 1.79 2008/04/06 19:04:50 thorpej Exp $");
|
||||
__RCSID("$NetBSD: inet.c,v 1.80 2008/04/06 20:17:27 thorpej Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -407,52 +407,51 @@ tcp_stats(off, name)
|
||||
* Dump UDP statistics structure.
|
||||
*/
|
||||
void
|
||||
udp_stats(off, name)
|
||||
u_long off;
|
||||
char *name;
|
||||
udp_stats(u_long off, char *name)
|
||||
{
|
||||
struct udpstat udpstat;
|
||||
uint64_t udpstat[UDP_NSTATS];
|
||||
u_quad_t delivered;
|
||||
|
||||
if (use_sysctl) {
|
||||
size_t size = sizeof(udpstat);
|
||||
|
||||
if (sysctlbyname("net.inet.udp.stats", &udpstat, &size,
|
||||
if (sysctlbyname("net.inet.udp.stats", udpstat, &size,
|
||||
NULL, 0) == -1)
|
||||
err(1, "net.inet.udp.stats");
|
||||
} else {
|
||||
if (off == 0)
|
||||
return;
|
||||
kread(off, (char *)&udpstat, sizeof (udpstat));
|
||||
kread(off, (char *)udpstat, sizeof (udpstat));
|
||||
}
|
||||
|
||||
printf ("%s:\n", name);
|
||||
|
||||
#define ps(f, m) if (udpstat.f || sflag <= 1) \
|
||||
printf(m, (unsigned long long)udpstat.f)
|
||||
#define p(f, m) if (udpstat.f || sflag <= 1) \
|
||||
printf(m, (unsigned long long)udpstat.f, plural(udpstat.f))
|
||||
#define p3(f, m) if (udpstat.f || sflag <= 1) \
|
||||
printf(m, (unsigned long long)udpstat.f, plurales(udpstat.f))
|
||||
#define ps(f, m) if (udpstat[f] || sflag <= 1) \
|
||||
printf(m, (unsigned long long)udpstat[f])
|
||||
#define p(f, m) if (udpstat[f] || sflag <= 1) \
|
||||
printf(m, (unsigned long long)udpstat[f], plural(udpstat[f]))
|
||||
#define p3(f, m) if (udpstat[f] || sflag <= 1) \
|
||||
printf(m, (unsigned long long)udpstat[f], plurales(udpstat[f]))
|
||||
|
||||
p(udps_ipackets, "\t%llu datagram%s received\n");
|
||||
ps(udps_hdrops, "\t%llu with incomplete header\n");
|
||||
ps(udps_badlen, "\t%llu with bad data length field\n");
|
||||
ps(udps_badsum, "\t%llu with bad checksum\n");
|
||||
ps(udps_noport, "\t%llu dropped due to no socket\n");
|
||||
p(udps_noportbcast, "\t%llu broadcast/multicast datagram%s dropped due to no socket\n");
|
||||
ps(udps_fullsock, "\t%llu dropped due to full socket buffers\n");
|
||||
delivered = udpstat.udps_ipackets -
|
||||
udpstat.udps_hdrops -
|
||||
udpstat.udps_badlen -
|
||||
udpstat.udps_badsum -
|
||||
udpstat.udps_noport -
|
||||
udpstat.udps_noportbcast -
|
||||
udpstat.udps_fullsock;
|
||||
p(UDP_STAT_IPACKETS, "\t%llu datagram%s received\n");
|
||||
ps(UDP_STAT_HDROPS, "\t%llu with incomplete header\n");
|
||||
ps(UDP_STAT_BADLEN, "\t%llu with bad data length field\n");
|
||||
ps(UDP_STAT_BADSUM, "\t%llu with bad checksum\n");
|
||||
ps(UDP_STAT_NOPORT, "\t%llu dropped due to no socket\n");
|
||||
p(UDP_STAT_NOPORTBCAST,
|
||||
"\t%llu broadcast/multicast datagram%s dropped due to no socket\n");
|
||||
ps(UDP_STAT_FULLSOCK, "\t%llu dropped due to full socket buffers\n");
|
||||
delivered = udpstat[UDP_STAT_IPACKETS] -
|
||||
udpstat[UDP_STAT_HDROPS] -
|
||||
udpstat[UDP_STAT_BADLEN] -
|
||||
udpstat[UDP_STAT_BADSUM] -
|
||||
udpstat[UDP_STAT_NOPORT] -
|
||||
udpstat[UDP_STAT_NOPORTBCAST] -
|
||||
udpstat[UDP_STAT_FULLSOCK];
|
||||
if (delivered || sflag <= 1)
|
||||
printf("\t%llu delivered\n", (unsigned long long)delivered);
|
||||
p3(udps_pcbhashmiss, "\t%llu PCB hash miss%s\n");
|
||||
p(udps_opackets, "\t%llu datagram%s output\n");
|
||||
p3(UDP_STAT_PCBHASHMISS, "\t%llu PCB hash miss%s\n");
|
||||
p(UDP_STAT_OPACKETS, "\t%llu datagram%s output\n");
|
||||
|
||||
#undef ps
|
||||
#undef p
|
||||
|
Loading…
x
Reference in New Issue
Block a user