Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/netinet/udp_usrreq.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/netinet/udp_usrreq.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.139 retrieving revision 1.143 diff -u -p -r1.139 -r1.143 --- src/sys/netinet/udp_usrreq.c 2005/08/05 09:21:26 1.139 +++ src/sys/netinet/udp_usrreq.c 2005/11/15 18:39:46 1.143 @@ -1,4 +1,4 @@ -/* $NetBSD: udp_usrreq.c,v 1.139 2005/08/05 09:21:26 elad Exp $ */ +/* $NetBSD: udp_usrreq.c,v 1.143 2005/11/15 18:39:46 dsl Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.139 2005/08/05 09:21:26 elad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.143 2005/11/15 18:39:46 dsl Exp $"); #include "opt_inet.h" #include "opt_ipsec.h" @@ -146,6 +146,7 @@ int udpcksum = 1; #else int udpcksum = 0; /* XXX */ #endif +int udp_do_loopback_cksum = 0; struct inpcbtable udbtable; struct udpstat udpstat; @@ -186,6 +187,7 @@ struct mowner udp_tx_mowner = { "udp", " #ifdef UDP_CSUM_COUNTERS #include +#if defined(INET) struct evcnt udp_hwcsum_bad = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "udp", "hwcsum bad"); struct evcnt udp_hwcsum_ok = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, @@ -195,12 +197,29 @@ struct evcnt udp_hwcsum_data = EVCNT_INI struct evcnt udp_swcsum = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "udp", "swcsum"); -#define UDP_CSUM_COUNTER_INCR(ev) (ev)->ev_count++ - EVCNT_ATTACH_STATIC(udp_hwcsum_bad); EVCNT_ATTACH_STATIC(udp_hwcsum_ok); EVCNT_ATTACH_STATIC(udp_hwcsum_data); EVCNT_ATTACH_STATIC(udp_swcsum); +#endif /* defined(INET) */ + +#if defined(INET6) +struct evcnt udp6_hwcsum_bad = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, + NULL, "udp6", "hwcsum bad"); +struct evcnt udp6_hwcsum_ok = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, + NULL, "udp6", "hwcsum ok"); +struct evcnt udp6_hwcsum_data = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, + NULL, "udp6", "hwcsum data"); +struct evcnt udp6_swcsum = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, + NULL, "udp6", "swcsum"); + +EVCNT_ATTACH_STATIC(udp6_hwcsum_bad); +EVCNT_ATTACH_STATIC(udp6_hwcsum_ok); +EVCNT_ATTACH_STATIC(udp6_hwcsum_data); +EVCNT_ATTACH_STATIC(udp6_swcsum); +#endif /* defined(INET6) */ + +#define UDP_CSUM_COUNTER_INCR(ev) (ev)->ev_count++ #else @@ -442,6 +461,11 @@ static int udp6_input_checksum(struct mbuf *m, const struct udphdr *uh, int off, int len) { + /* + * XXX it's better to record and check if this mbuf is + * already checked. + */ + if (__predict_false((m->m_flags & M_LOOP) && !udp_do_loopback_cksum)) { goto good; } @@ -449,9 +473,34 @@ udp6_input_checksum(struct mbuf *m, cons udp6stat.udp6s_nosum++; goto bad; } - if (in6_cksum(m, IPPROTO_UDP, off, len) != 0) { + + switch (m->m_pkthdr.csum_flags & + ((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_UDPv6) | + M_CSUM_TCP_UDP_BAD | M_CSUM_DATA)) { + case M_CSUM_UDPv6|M_CSUM_TCP_UDP_BAD: + UDP_CSUM_COUNTER_INCR(&udp6_hwcsum_bad); udp6stat.udp6s_badsum++; goto bad; + +#if 0 /* notyet */ + case M_CSUM_UDPv6|M_CSUM_DATA: +#endif + + case M_CSUM_UDPv6: + /* Checksum was okay. */ + UDP_CSUM_COUNTER_INCR(&udp6_hwcsum_ok); + break; + + default: + /* + * Need to compute it ourselves. Maybe skip checksum + * on loopback interfaces. + */ + UDP_CSUM_COUNTER_INCR(&udp6_swcsum); + if (in6_cksum(m, IPPROTO_UDP, off, len) != 0) { + udp6stat.udp6s_badsum++; + goto bad; + } } good: @@ -1177,7 +1226,7 @@ udp_usrreq(struct socket *so, int req, s break; case PRU_CONNECT: - error = in_pcbconnect(inp, nam); + error = in_pcbconnect(inp, nam, p); if (error) break; soisconnected(so); @@ -1219,7 +1268,7 @@ udp_usrreq(struct socket *so, int req, s error = EISCONN; goto die; } - error = in_pcbconnect(inp, nam); + error = in_pcbconnect(inp, nam, p); if (error) goto die; } else { @@ -1407,10 +1456,10 @@ udp4_espinudp(m, off, src, so) } if (inp->inp_flags & INP_ESPINUDP_NON_IKE) { - u_int64_t *st = (u_int64_t *)data; + u_int32_t *st = (u_int32_t *)data; if ((len <= sizeof(u_int64_t) + sizeof(struct esp)) - || (*st != 0)) + || ((st[0] | st[1]) != 0)) return 0; /* Normal UDP processing */ skip = sizeof(struct udphdr) + sizeof(u_int64_t);