diff options
author | rwatson <rwatson@FreeBSD.org> | 2009-08-02 19:43:32 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2009-08-02 19:43:32 +0000 |
commit | 5c6699ad3da677119a855665cf574faa86b982fc (patch) | |
tree | a40bf95a151eb088ca45c32ee899b724ba74dcea /sys | |
parent | b08de52c2d9909520082a33aafe53c6ee39df7d7 (diff) | |
download | FreeBSD-src-5c6699ad3da677119a855665cf574faa86b982fc.zip FreeBSD-src-5c6699ad3da677119a855665cf574faa86b982fc.tar.gz |
Many network stack subsystems use a single global data structure to hold
all pertinent statatistics for the subsystem. These structures are
sometimes "borrowed" by kernel modules that require a place to store
statistics for similar events.
Add KPI accessor functions for statistics structures referenced by kernel
modules so that they no longer encode certain specifics of how the data
structures are named and stored. This change is intended to make it
easier to move to per-CPU network stats following 8.0-RELEASE.
The following modules are affected by this change:
if_bridge
if_cxgb
if_gif
ip_mroute
ipdivert
pf
In practice, most of these statistics consumers should, in fact, maintain
their own statistics data structures rather than borrowing structures
from the base network stack. However, that change is too agressive for
this point in the release cycle.
Reviewed by: bz
Approved by: re (kib)
Diffstat (limited to 'sys')
-rw-r--r-- | sys/contrib/pf/net/pf.c | 28 | ||||
-rw-r--r-- | sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c | 2 | ||||
-rw-r--r-- | sys/net/if_bridge.c | 18 | ||||
-rw-r--r-- | sys/netinet/icmp6.h | 11 | ||||
-rw-r--r-- | sys/netinet/icmp_var.h | 11 | ||||
-rw-r--r-- | sys/netinet/in_gif.c | 6 | ||||
-rw-r--r-- | sys/netinet/ip_divert.c | 10 | ||||
-rw-r--r-- | sys/netinet/ip_icmp.c | 14 | ||||
-rw-r--r-- | sys/netinet/ip_input.c | 21 | ||||
-rw-r--r-- | sys/netinet/ip_var.h | 14 | ||||
-rw-r--r-- | sys/netinet/tcp_input.c | 14 | ||||
-rw-r--r-- | sys/netinet/tcp_var.h | 11 | ||||
-rw-r--r-- | sys/netinet/udp_usrreq.c | 14 | ||||
-rw-r--r-- | sys/netinet/udp_var.h | 11 | ||||
-rw-r--r-- | sys/netinet6/icmp6.c | 14 |
15 files changed, 167 insertions, 32 deletions
diff --git a/sys/contrib/pf/net/pf.c b/sys/contrib/pf/net/pf.c index 79cef36..591ea36 100644 --- a/sys/contrib/pf/net/pf.c +++ b/sys/contrib/pf/net/pf.c @@ -6141,7 +6141,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp, if (r->rt == PF_FASTROUTE) { in_rtalloc(ro, 0); if (ro->ro_rt == 0) { - IPSTAT_INC(ips_noroute); + KMOD_IPSTAT_INC(ips_noroute); goto bad; } @@ -6272,16 +6272,16 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp, if ((ifp->if_capabilities & IFCAP_CSUM_IPv4) && ifp->if_bridge == NULL) { m0->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT; - IPSTAT_INC(ips_outhwcsum); + KMOD_IPSTAT_INC(ips_outhwcsum); } else { ip->ip_sum = 0; ip->ip_sum = in_cksum(m0, ip->ip_hl << 2); } /* Update relevant hardware checksum stats for TCP/UDP */ if (m0->m_pkthdr.csum_flags & M_TCPV4_CSUM_OUT) - TCPSTAT_INC(tcpstat.tcps_outhwcsum); + KMOD_TCPSTAT_INC(tcps_outhwcsum); else if (m0->m_pkthdr.csum_flags & M_UDPV4_CSUM_OUT) - UDPSTAT_INC(udps_outhwcsum); + KMOD_UDPSTAT_INC(udps_outhwcsum); error = (*ifp->if_output)(ifp, m0, sintosa(dst), NULL); goto done; } @@ -6291,7 +6291,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp, * Must be able to put at least 8 bytes per fragment. */ if (ip->ip_off & htons(IP_DF)) { - IPSTAT_INC(ips_cantfrag); + KMOD_IPSTAT_INC(ips_cantfrag); if (r->rt != PF_DUPTO) { #ifdef __FreeBSD__ /* icmp_error() expects host byte ordering */ @@ -6348,7 +6348,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp, } if (error == 0) - IPSTAT_INC(ips_fragmented); + KMOD_IPSTAT_INC(ips_fragmented); done: if (r->rt != PF_DUPTO) @@ -6622,23 +6622,23 @@ pf_check_proto_cksum(struct mbuf *m, int off, int len, u_int8_t p, sa_family_t a switch (p) { case IPPROTO_TCP: { - TCPSTAT_INC(tcps_rcvbadsum); + KMOD_TCPSTAT_INC(tcps_rcvbadsum); break; } case IPPROTO_UDP: { - UDPSTAT_INC(udps_badsum); + KMOD_UDPSTAT_INC(udps_badsum); break; } case IPPROTO_ICMP: { - ICMPSTAT_INC(icps_checksum); + KMOD_ICMPSTAT_INC(icps_checksum); break; } #ifdef INET6 case IPPROTO_ICMPV6: { - ICMP6STAT_INC(icp6s_checksum); + KMOD_ICMP6STAT_INC(icp6s_checksum); break; } #endif /* INET6 */ @@ -6725,17 +6725,17 @@ pf_check_proto_cksum(struct mbuf *m, int off, int len, u_int8_t p, m->m_pkthdr.csum_flags |= flag_bad; switch (p) { case IPPROTO_TCP: - TCPSTAT_INC(tcps_rcvbadsum); + KMOD_TCPSTAT_INC(tcps_rcvbadsum); break; case IPPROTO_UDP: - UDPSTAT_INC(udps_badsum); + KMOD_UDPSTAT_INC(udps_badsum); break; case IPPROTO_ICMP: - ICMPSTAT_INC(icps_checksum); + KMOD_ICMPSTAT_INC(icps_checksum); break; #ifdef INET6 case IPPROTO_ICMPV6: - ICMP6STAT_INC(icp6s_checksum); + KMOD_ICMP6STAT_INC(icp6s_checksum); break; #endif /* INET6 */ } diff --git a/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c b/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c index d528b30..e019c61 100644 --- a/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c +++ b/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c @@ -3821,7 +3821,7 @@ socket_act_establish(struct socket *so, struct mbuf *m) #endif toep->tp_state = tp->t_state; - TCPSTAT_INC(tcps_connects); + KMOD_TCPSTAT_INC(tcps_connects); } diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index ced953a..f1a79cb 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -3244,12 +3244,12 @@ bridge_ip_checkbasic(struct mbuf **mp) if ((m = m_copyup(m, sizeof(struct ip), (max_linkhdr + 3) & ~3)) == NULL) { /* XXXJRT new stat, please */ - IPSTAT_INC(ips_toosmall); + KMOD_IPSTAT_INC(ips_toosmall); goto bad; } } else if (__predict_false(m->m_len < sizeof (struct ip))) { if ((m = m_pullup(m, sizeof (struct ip))) == NULL) { - IPSTAT_INC(ips_toosmall); + KMOD_IPSTAT_INC(ips_toosmall); goto bad; } } @@ -3257,17 +3257,17 @@ bridge_ip_checkbasic(struct mbuf **mp) if (ip == NULL) goto bad; if (ip->ip_v != IPVERSION) { - IPSTAT_INC(ips_badvers); + KMOD_IPSTAT_INC(ips_badvers); goto bad; } hlen = ip->ip_hl << 2; if (hlen < sizeof(struct ip)) { /* minimum header length */ - IPSTAT_INC(ips_badhlen); + KMOD_IPSTAT_INC(ips_badhlen); goto bad; } if (hlen > m->m_len) { if ((m = m_pullup(m, hlen)) == 0) { - IPSTAT_INC(ips_badhlen); + KMOD_IPSTAT_INC(ips_badhlen); goto bad; } ip = mtod(m, struct ip *); @@ -3284,7 +3284,7 @@ bridge_ip_checkbasic(struct mbuf **mp) } } if (sum) { - IPSTAT_INC(ips_badsum); + KMOD_IPSTAT_INC(ips_badsum); goto bad; } @@ -3295,7 +3295,7 @@ bridge_ip_checkbasic(struct mbuf **mp) * Check for additional length bogosity */ if (len < hlen) { - IPSTAT_INC(ips_badlen); + KMOD_IPSTAT_INC(ips_badlen); goto bad; } @@ -3305,7 +3305,7 @@ bridge_ip_checkbasic(struct mbuf **mp) * Drop packet if shorter than we expect. */ if (m->m_pkthdr.len < len) { - IPSTAT_INC(ips_tooshort); + KMOD_IPSTAT_INC(ips_tooshort); goto bad; } @@ -3418,7 +3418,7 @@ bridge_fragment(struct ifnet *ifp, struct mbuf *m, struct ether_header *eh, } if (error == 0) - IPSTAT_INC(ips_fragmented); + KMOD_IPSTAT_INC(ips_fragmented); return (error); diff --git a/sys/netinet/icmp6.h b/sys/netinet/icmp6.h index 7dc22e5..c3a8ac7 100644 --- a/sys/netinet/icmp6.h +++ b/sys/netinet/icmp6.h @@ -600,8 +600,19 @@ struct icmp6stat { }; #ifdef _KERNEL +/* + * In-kernel consumers can use these accessor macros directly to update + * stats. + */ #define ICMP6STAT_ADD(name, val) V_icmp6stat.name += (val) #define ICMP6STAT_INC(name) ICMP6STAT_ADD(name, 1) + +/* + * Kernel module consumers must use this accessor macro. + */ +void kmod_icmp6stat_inc(int statnum); +#define KMOD_ICMP6STAT_INC(name) \ + kmod_icmp6stat_inc(offsetof(struct icmp6stat, name) / sizeof(u_quad_t)) #endif /* diff --git a/sys/netinet/icmp_var.h b/sys/netinet/icmp_var.h index 4d70ada..30da6a2 100644 --- a/sys/netinet/icmp_var.h +++ b/sys/netinet/icmp_var.h @@ -58,8 +58,19 @@ struct icmpstat { }; #ifdef _KERNEL +/* + * In-kernel consumers can use these accessor macros directly to update + * stats. + */ #define ICMPSTAT_ADD(name, val) V_icmpstat.name += (val) #define ICMPSTAT_INC(name) ICMPSTAT_ADD(name, 1) + +/* + * Kernel module consumers must use this accessor macro. + */ +void kmod_icmpstat_inc(int statnum); +#define KMOD_ICMPSTAT_INC(name) \ + kmod_icmpstat_inc(offsetof(struct icmpstat, name) / sizeof(u_long)) #endif /* diff --git a/sys/netinet/in_gif.c b/sys/netinet/in_gif.c index 3872dde..44b9961 100644 --- a/sys/netinet/in_gif.c +++ b/sys/netinet/in_gif.c @@ -281,14 +281,14 @@ in_gif_input(struct mbuf *m, int off) sc = (struct gif_softc *)encap_getarg(m); if (sc == NULL) { m_freem(m); - IPSTAT_INC(ips_nogif); + KMOD_IPSTAT_INC(ips_nogif); return; } gifp = GIF2IFP(sc); if (gifp == NULL || (gifp->if_flags & IFF_UP) == 0) { m_freem(m); - IPSTAT_INC(ips_nogif); + KMOD_IPSTAT_INC(ips_nogif); return; } @@ -348,7 +348,7 @@ in_gif_input(struct mbuf *m, int off) break; default: - IPSTAT_INC(ips_nogif); + KMOD_IPSTAT_INC(ips_nogif); m_freem(m); return; } diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 6910310..31059e9 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -186,7 +186,7 @@ void div_input(struct mbuf *m, int off) { - IPSTAT_INC(ips_noproto); + KMOD_IPSTAT_INC(ips_noproto); m_freem(m); } @@ -310,8 +310,8 @@ divert_packet(struct mbuf *m, int incoming) INP_INFO_RUNLOCK(&V_divcbinfo); if (sa == NULL) { m_freem(m); - IPSTAT_INC(ips_noproto); - IPSTAT_DEC(ips_delivered); + KMOD_IPSTAT_INC(ips_noproto); + KMOD_IPSTAT_DEC(ips_delivered); } } @@ -396,7 +396,7 @@ div_output(struct socket *so, struct mbuf *m, struct sockaddr_in *sin, ip->ip_off = ntohs(ip->ip_off); /* Send packet to output processing */ - IPSTAT_INC(ips_rawout); /* XXX */ + KMOD_IPSTAT_INC(ips_rawout); /* XXX */ #ifdef MAC mac_inpcb_create_mbuf(inp, m); @@ -567,7 +567,7 @@ div_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, /* Packet must have a header (but that's about it) */ if (m->m_len < sizeof (struct ip) && (m = m_pullup(m, sizeof (struct ip))) == 0) { - IPSTAT_INC(ips_toosmall); + KMOD_IPSTAT_INC(ips_toosmall); m_freem(m); return EINVAL; } diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index b7906e3..fcb9ca6 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -172,6 +172,20 @@ icmp_init(void) } /* + * Kernel module interface for updating icmpstat. The argument is an index + * into icmpstat treated as an array of u_long. While this encodes the + * general layout of icmpstat into the caller, it doesn't encode its + * location, so that future changes to add, for example, per-CPU stats + * support won't cause binary compatibility problems for kernel modules. + */ +void +kmod_icmpstat_inc(int statnum) +{ + + (*((u_long *)&V_icmpstat + statnum))++; +} + +/* * Generate an error packet of type error * in response to bad packet ip. */ diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 05de6d8..7886fa7 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -235,6 +235,27 @@ VNET_DEFINE(int, fw_one_pass) = 1; static void ip_freef(struct ipqhead *, struct ipq *); +/* + * Kernel module interface for updating ipstat. The argument is an index + * into ipstat treated as an array of u_long. While this encodes the general + * layout of ipstat into the caller, it doesn't encode its location, so that + * future changes to add, for example, per-CPU stats support won't cause + * binary compatibility problems for kernel modules. + */ +void +kmod_ipstat_inc(int statnum) +{ + + (*((u_long *)&V_ipstat + statnum))++; +} + +void +kmod_ipstat_dec(int statnum) +{ + + (*((u_long *)&V_ipstat + statnum))--; +} + static int sysctl_netinet_intr_queue_maxlen(SYSCTL_HANDLER_ARGS) { diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index 74aecb1..448ba3d 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -131,11 +131,25 @@ struct ipstat { #include <net/vnet.h> +/* + * In-kernel consumers can use these accessor macros directly to update + * stats. + */ #define IPSTAT_ADD(name, val) V_ipstat.name += (val) #define IPSTAT_SUB(name, val) V_ipstat.name -= (val) #define IPSTAT_INC(name) IPSTAT_ADD(name, 1) #define IPSTAT_DEC(name) IPSTAT_SUB(name, 1) +/* + * Kernel module consumers must use this accessor macro. + */ +void kmod_ipstat_inc(int statnum); +#define KMOD_IPSTAT_INC(name) \ + kmod_ipstat_inc(offsetof(struct ipstat, name) / sizeof(u_long)) +void kmod_ipstat_dec(int statnum); +#define KMOD_IPSTAT_DEC(name) \ + kmod_ipstat_dec(offsetof(struct ipstat, name) / sizeof(u_long)) + /* flags passed to ip_output as last parameter */ #define IP_FORWARDING 0x1 /* most of ip header exists */ #define IP_RAWOUTPUT 0x2 /* raw ip header exists */ diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 22ee3d7..470d782 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -217,6 +217,20 @@ static void tcp_newreno_partial_ack(struct tcpcb *, struct tcphdr *); static void inline tcp_congestion_exp(struct tcpcb *); +/* + * Kernel module interface for updating tcpstat. The argument is an index + * into tcpstat treated as an array of u_long. While this encodes the + * general layout of tcpstat into the caller, it doesn't encode its location, + * so that future changes to add, for example, per-CPU stats support won't + * cause binary compatibility problems for kernel modules. + */ +void +kmod_tcpstat_inc(int statnum) +{ + + (*((u_long *)&V_tcpstat + statnum))++; +} + static void inline tcp_congestion_exp(struct tcpcb *tp) { diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 8845769..96353f3 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -474,8 +474,19 @@ struct tcpstat { }; #ifdef _KERNEL +/* + * In-kernel consumers can use these accessor macros directly to update + * stats. + */ #define TCPSTAT_ADD(name, val) V_tcpstat.name += (val) #define TCPSTAT_INC(name) TCPSTAT_ADD(name, 1) + +/* + * Kernel module consumers must use this accessor macro. + */ +void kmod_tcpstat_inc(int statnum); +#define KMOD_TCPSTAT_INC(name) \ + kmod_tcpstat_inc(offsetof(struct tcpstat, name) / sizeof(u_long)) #endif /* diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 520fc94..019ceb3 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -203,6 +203,20 @@ udp_init(void) EVENTHANDLER_PRI_ANY); } +/* + * Kernel module interface for updating udpstat. The argument is an index + * into udpstat treated as an array of u_long. While this encodes the + * general layout of udpstat into the caller, it doesn't encode its location, + * so that future changes to add, for example, per-CPU stats support won't + * cause binary compatibility problems for kernel modules. + */ +void +kmod_udpstat_inc(int statnum) +{ + + (*((u_long *)&V_udpstat + statnum))++; +} + int udp_newudpcb(struct inpcb *inp) { diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h index 8031670..b8d994c 100644 --- a/sys/netinet/udp_var.h +++ b/sys/netinet/udp_var.h @@ -91,8 +91,19 @@ struct udpstat { }; #ifdef _KERNEL +/* + * In-kernel consumers can use these accessor macros directly to update + * stats. + */ #define UDPSTAT_ADD(name, val) V_udpstat.name += (val) #define UDPSTAT_INC(name) UDPSTAT_ADD(name, 1) + +/* + * Kernel module consumers must use this accessor macro. + */ +void kmod_udpstat_inc(int statnum); +#define KMOD_UDPSTAT_INC(name) \ + kmod_udpstat_inc(offsetof(struct udpstat, name) / sizeof(u_long)) #endif /* diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index bdf7786..7fe63b6 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -152,6 +152,20 @@ icmp6_init(void) V_icmp6errpps_count = 0; } +/* + * Kernel module interface for updating icmp6stat. The argument is an index + * into icmp6stat treated as an array of u_quad_t. While this encodes the + * general layout of icmp6stat into the caller, it doesn't encode its + * location, so that future changes to add, for example, per-CPU stats + * support won't cause binary compatibility problems for kernel modules. + */ +void +kmod_icmp6stat_inc(int statnum) +{ + + (*((u_quad_t *)&V_icmp6stat + statnum))++; +} + static void icmp6_errcount(struct icmp6errstat *stat, int type, int code) { |