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.111 retrieving revision 1.122 diff -u -p -r1.111 -r1.122 --- src/sys/netinet/udp_usrreq.c 2003/09/25 00:59:32 1.111 +++ src/sys/netinet/udp_usrreq.c 2004/05/25 04:34:00 1.122 @@ -1,4 +1,4 @@ -/* $NetBSD: udp_usrreq.c,v 1.111 2003/09/25 00:59:32 mycroft Exp $ */ +/* $NetBSD: udp_usrreq.c,v 1.122 2004/05/25 04:34:00 atatat Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.111 2003/09/25 00:59:32 mycroft Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.122 2004/05/25 04:34:00 atatat Exp $"); #include "opt_inet.h" #include "opt_ipsec.h" @@ -117,6 +117,7 @@ __KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c #ifdef FAST_IPSEC #include +#include /* XXX ipsecstat namespace */ #ifdef INET6 #include #endif @@ -145,19 +146,19 @@ struct inpcbtable udbtable; struct udpstat udpstat; #ifdef INET -static void udp4_sendup __P((struct mbuf *, int, struct sockaddr *, - struct socket *)); -static int udp4_realinput __P((struct sockaddr_in *, struct sockaddr_in *, - struct mbuf *, int)); +static void udp4_sendup (struct mbuf *, int, struct sockaddr *, + struct socket *); +static int udp4_realinput (struct sockaddr_in *, struct sockaddr_in *, + struct mbuf *, int); #endif #ifdef INET6 -static void udp6_sendup __P((struct mbuf *, int, struct sockaddr *, - struct socket *)); -static int udp6_realinput __P((int, struct sockaddr_in6 *, - struct sockaddr_in6 *, struct mbuf *, int)); +static void udp6_sendup (struct mbuf *, int, struct sockaddr *, + struct socket *); +static int udp6_realinput (int, struct sockaddr_in6 *, + struct sockaddr_in6 *, struct mbuf *, int); #endif #ifdef INET -static void udp_notify __P((struct inpcb *, int)); +static void udp_notify (struct inpcb *, int); #endif #ifndef UDBHASHSIZE @@ -185,6 +186,11 @@ struct evcnt udp_swcsum = EVCNT_INITIALI #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); + #else #define UDP_CSUM_COUNTER_INCR(ev) /* nothing */ @@ -192,18 +198,11 @@ struct evcnt udp_swcsum = EVCNT_INITIALI #endif /* UDP_CSUM_COUNTERS */ void -udp_init() +udp_init(void) { in_pcbinit(&udbtable, udbhashsize, udbhashsize); -#ifdef UDP_CSUM_COUNTERS - evcnt_attach_static(&udp_hwcsum_bad); - evcnt_attach_static(&udp_hwcsum_ok); - evcnt_attach_static(&udp_hwcsum_data); - evcnt_attach_static(&udp_swcsum); -#endif /* UDP_CSUM_COUNTERS */ - MOWNER_ATTACH(&udp_tx_mowner); MOWNER_ATTACH(&udp_rx_mowner); MOWNER_ATTACH(&udp_mowner); @@ -211,13 +210,7 @@ udp_init() #ifdef INET void -#if __STDC__ udp_input(struct mbuf *m, ...) -#else -udp_input(m, va_alist) - struct mbuf *m; - va_dcl -#endif { va_list ap; struct sockaddr_in src, dst; @@ -270,8 +263,8 @@ udp_input(m, va_alist) */ if (uh->uh_sum) { switch (m->m_pkthdr.csum_flags & - ((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_UDPv4) | - M_CSUM_TCP_UDP_BAD | M_CSUM_DATA)) { + ((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_UDPv4) | + M_CSUM_TCP_UDP_BAD | M_CSUM_DATA)) { case M_CSUM_UDPv4|M_CSUM_TCP_UDP_BAD: UDP_CSUM_COUNTER_INCR(&udp_hwcsum_bad); goto badcsum; @@ -280,8 +273,9 @@ udp_input(m, va_alist) u_int32_t hw_csum = m->m_pkthdr.csum_data; UDP_CSUM_COUNTER_INCR(&udp_hwcsum_data); if (m->m_pkthdr.csum_flags & M_CSUM_NO_PSEUDOHDR) - hw_csum = in_cksum_phdr(ip->ip_src.s_addr, ip->ip_dst.s_addr, - htonl(hw_csum + ntohs(ip->ip_len) + IPPROTO_UDP)); + hw_csum = in_cksum_phdr(ip->ip_src.s_addr, + ip->ip_dst.s_addr, + htons(hw_csum + len + IPPROTO_UDP)); if ((hw_csum ^ 0xffff) != 0) goto badcsum; break; @@ -371,9 +365,7 @@ badcsum: #ifdef INET6 int -udp6_input(mp, offp, proto) - struct mbuf **mp; - int *offp, proto; +udp6_input(struct mbuf **mp, int *offp, int proto) { struct mbuf *m = *mp; int off = *offp; @@ -429,9 +421,11 @@ udp6_input(mp, offp, proto) /* * Checksum extended UDP header and data. */ - if (uh->uh_sum == 0) + if (uh->uh_sum == 0) { udp6stat.udp6s_nosum++; - else if (in6_cksum(m, IPPROTO_UDP, off, ulen) != 0) { + goto bad; + } + if (in6_cksum(m, IPPROTO_UDP, off, ulen) != 0) { udp6stat.udp6s_badsum++; goto bad; } @@ -472,11 +466,8 @@ bad: #ifdef INET static void -udp4_sendup(m, off, src, so) - struct mbuf *m; - int off; /* offset of data portion */ - struct sockaddr *src; - struct socket *so; +udp4_sendup(struct mbuf *m, int off /* offset of data portion */, + struct sockaddr *src, struct socket *so) { struct mbuf *opts = NULL; struct mbuf *n; @@ -529,11 +520,8 @@ udp4_sendup(m, off, src, so) #ifdef INET6 static void -udp6_sendup(m, off, src, so) - struct mbuf *m; - int off; /* offset of data portion */ - struct sockaddr *src; - struct socket *so; +udp6_sendup(struct mbuf *m, int off /* offset of data portion */, + struct sockaddr *src, struct socket *so) { struct mbuf *opts = NULL; struct mbuf *n; @@ -577,11 +565,8 @@ udp6_sendup(m, off, src, so) #ifdef INET static int -udp4_realinput(src, dst, m, off) - struct sockaddr_in *src; - struct sockaddr_in *dst; - struct mbuf *m; - int off; /* offset of udphdr */ +udp4_realinput(struct sockaddr_in *src, struct sockaddr_in *dst, + struct mbuf *m, int off /* offset of udphdr */) { u_int16_t *sport, *dport; int rcvcnt; @@ -681,12 +666,8 @@ bad: #ifdef INET6 static int -udp6_realinput(af, src, dst, m, off) - int af; /* af on packet */ - struct sockaddr_in6 *src; - struct sockaddr_in6 *dst; - struct mbuf *m; - int off; /* offset of udphdr */ +udp6_realinput(int af, struct sockaddr_in6 *src, struct sockaddr_in6 *dst, + struct mbuf *m, int off) { u_int16_t sport, dport; int rcvcnt; @@ -803,25 +784,19 @@ bad: * just wake up so that he can collect error status. */ static void -udp_notify(inp, errno) - struct inpcb *inp; - int errno; +udp_notify(struct inpcb *inp, int errno) { - inp->inp_socket->so_error = errno; sorwakeup(inp->inp_socket); sowwakeup(inp->inp_socket); } void * -udp_ctlinput(cmd, sa, v) - int cmd; - struct sockaddr *sa; - void *v; +udp_ctlinput(int cmd, struct sockaddr *sa, void *v) { struct ip *ip = v; struct udphdr *uh; - void (*notify) __P((struct inpcb *, int)) = udp_notify; + void (*notify)(struct inpcb *, int) = udp_notify; int errno; if (sa->sa_family != AF_INET @@ -849,13 +824,7 @@ udp_ctlinput(cmd, sa, v) } int -#if __STDC__ udp_output(struct mbuf *m, ...) -#else -udp_output(m, va_alist) - struct mbuf *m; - va_dcl -#endif { struct inpcb *inp; struct udpiphdr *ui; @@ -934,11 +903,8 @@ int udp_recvspace = 40 * (1024 + sizeof( /*ARGSUSED*/ int -udp_usrreq(so, req, m, nam, control, p) - struct socket *so; - int req; - struct mbuf *m, *nam, *control; - struct proc *p; +udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, + struct mbuf *control, struct proc *p) { struct inpcb *inp; int s; @@ -1022,11 +988,6 @@ udp_usrreq(so, req, m, nam, control, p) so->so_state &= ~SS_ISCONNECTED; /* XXX */ in_pcbdisconnect(inp); inp->inp_laddr = zeroin_addr; /* XXX */ - if (inp->inp_ia != NULL) { - LIST_REMOVE(inp, inp_ialink); - IFAFREE(&inp->inp_ia->ia_ifa); - inp->inp_ia = NULL; - } in_pcbstate(inp, INP_BOUND); /* XXX */ break; @@ -1071,11 +1032,6 @@ udp_usrreq(so, req, m, nam, control, p) in_pcbstate(inp, INP_BOUND); /* XXX */ } die: - if (inp->inp_ia != NULL && in_nullhost(inp->inp_laddr)) { - LIST_REMOVE(inp, inp_ialink); - IFAFREE(&inp->inp_ia->ia_ifa); - inp->inp_ia = NULL; - } if (m) m_freem(m); } @@ -1118,31 +1074,46 @@ release: /* * Sysctl for udp variables. */ -int -udp_sysctl(name, namelen, oldp, oldlenp, newp, newlen) - int *name; - u_int namelen; - void *oldp; - size_t *oldlenp; - void *newp; - size_t newlen; +SYSCTL_SETUP(sysctl_net_inet_udp_setup, "sysctl net.inet.udp subtree setup") { - /* All sysctl names at this level are terminal. */ - if (namelen != 1) - return (ENOTDIR); - - switch (name[0]) { - case UDPCTL_CHECKSUM: - return (sysctl_int(oldp, oldlenp, newp, newlen, &udpcksum)); - case UDPCTL_SENDSPACE: - return (sysctl_int(oldp, oldlenp, newp, newlen, - &udp_sendspace)); - case UDPCTL_RECVSPACE: - return (sysctl_int(oldp, oldlenp, newp, newlen, - &udp_recvspace)); - default: - return (ENOPROTOOPT); - } - /* NOTREACHED */ + + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, "net", NULL, + NULL, 0, NULL, 0, + CTL_NET, CTL_EOL); + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, "inet", NULL, + NULL, 0, NULL, 0, + CTL_NET, PF_INET, CTL_EOL); + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, "udp", + SYSCTL_DESCR("UDPv4 related settings"), + NULL, 0, NULL, 0, + CTL_NET, PF_INET, IPPROTO_UDP, CTL_EOL); + + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "checksum", + SYSCTL_DESCR("Compute and check UDP checksums"), + NULL, 0, &udpcksum, 0, + CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_CHECKSUM, + CTL_EOL); + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "sendspace", + SYSCTL_DESCR("Default UDP send buffer size"), + NULL, 0, &udp_sendspace, 0, + CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_SENDSPACE, + CTL_EOL); + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "recvspace", + SYSCTL_DESCR("Default UDP receive buffer size"), + NULL, 0, &udp_recvspace, 0, + CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_RECVSPACE, + CTL_EOL); } #endif