[BACK]Return to udp_usrreq.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / netinet

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/netinet/udp_usrreq.c between version 1.103.2.3 and 1.107

version 1.103.2.3, 2004/09/18 14:54:54 version 1.107, 2003/08/22 21:53:06
Line 117  __KERNEL_RCSID(0, "$NetBSD$");
Line 117  __KERNEL_RCSID(0, "$NetBSD$");
   
 #ifdef FAST_IPSEC  #ifdef FAST_IPSEC
 #include <netipsec/ipsec.h>  #include <netipsec/ipsec.h>
 #include <netipsec/ipsec_var.h>                 /* XXX ipsecstat namespace */  
 #ifdef INET6  #ifdef INET6
 #include <netipsec/ipsec6.h>  #include <netipsec/ipsec6.h>
 #endif  #endif
Line 146  struct inpcbtable udbtable;
Line 145  struct inpcbtable udbtable;
 struct  udpstat udpstat;  struct  udpstat udpstat;
   
 #ifdef INET  #ifdef INET
 static void udp4_sendup (struct mbuf *, int, struct sockaddr *,  static void udp4_sendup __P((struct mbuf *, int, struct sockaddr *,
         struct socket *);          struct socket *));
 static int udp4_realinput (struct sockaddr_in *, struct sockaddr_in *,  static int udp4_realinput __P((struct sockaddr_in *, struct sockaddr_in *,
         struct mbuf *, int);          struct mbuf *, int));
 #endif  #endif
 #ifdef INET6  #ifdef INET6
 static void udp6_sendup (struct mbuf *, int, struct sockaddr *,  static void udp6_sendup __P((struct mbuf *, int, struct sockaddr *,
         struct socket *);          struct socket *));
 static int udp6_realinput (int, struct sockaddr_in6 *,  static int udp6_realinput __P((int, struct sockaddr_in6 *,
         struct sockaddr_in6 *, struct mbuf *, int);          struct sockaddr_in6 *, struct mbuf *, int));
 #endif  #endif
 #ifdef INET  #ifdef INET
 static  void udp_notify (struct inpcb *, int);  static  void udp_notify __P((struct inpcb *, int));
 #endif  #endif
   
 #ifndef UDBHASHSIZE  #ifndef UDBHASHSIZE
Line 186  struct evcnt udp_swcsum = EVCNT_INITIALI
Line 185  struct evcnt udp_swcsum = EVCNT_INITIALI
   
 #define UDP_CSUM_COUNTER_INCR(ev)       (ev)->ev_count++  #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  #else
   
 #define UDP_CSUM_COUNTER_INCR(ev)       /* nothing */  #define UDP_CSUM_COUNTER_INCR(ev)       /* nothing */
Line 198  EVCNT_ATTACH_STATIC(udp_swcsum);
Line 192  EVCNT_ATTACH_STATIC(udp_swcsum);
 #endif /* UDP_CSUM_COUNTERS */  #endif /* UDP_CSUM_COUNTERS */
   
 void  void
 udp_init(void)  udp_init()
 {  {
   
   #ifdef INET
         in_pcbinit(&udbtable, udbhashsize, udbhashsize);          in_pcbinit(&udbtable, udbhashsize, udbhashsize);
   #endif
   
   #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_tx_mowner);
         MOWNER_ATTACH(&udp_rx_mowner);          MOWNER_ATTACH(&udp_rx_mowner);
Line 210  udp_init(void)
Line 213  udp_init(void)
   
 #ifdef INET  #ifdef INET
 void  void
   #if __STDC__
 udp_input(struct mbuf *m, ...)  udp_input(struct mbuf *m, ...)
   #else
   udp_input(m, va_alist)
           struct mbuf *m;
           va_dcl
   #endif
 {  {
         va_list ap;          va_list ap;
         struct sockaddr_in src, dst;          struct sockaddr_in src, dst;
Line 263  udp_input(struct mbuf *m, ...)
Line 272  udp_input(struct mbuf *m, ...)
          */           */
         if (uh->uh_sum) {          if (uh->uh_sum) {
                 switch (m->m_pkthdr.csum_flags &                  switch (m->m_pkthdr.csum_flags &
                     ((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_UDPv4) |                          ((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_UDPv4) |
                     M_CSUM_TCP_UDP_BAD | M_CSUM_DATA)) {                           M_CSUM_TCP_UDP_BAD | M_CSUM_DATA)) {
                 case M_CSUM_UDPv4|M_CSUM_TCP_UDP_BAD:                  case M_CSUM_UDPv4|M_CSUM_TCP_UDP_BAD:
                         UDP_CSUM_COUNTER_INCR(&udp_hwcsum_bad);                          UDP_CSUM_COUNTER_INCR(&udp_hwcsum_bad);
                         goto badcsum;                          goto badcsum;
Line 273  udp_input(struct mbuf *m, ...)
Line 282  udp_input(struct mbuf *m, ...)
                         u_int32_t hw_csum = m->m_pkthdr.csum_data;                          u_int32_t hw_csum = m->m_pkthdr.csum_data;
                         UDP_CSUM_COUNTER_INCR(&udp_hwcsum_data);                          UDP_CSUM_COUNTER_INCR(&udp_hwcsum_data);
                         if (m->m_pkthdr.csum_flags & M_CSUM_NO_PSEUDOHDR)                          if (m->m_pkthdr.csum_flags & M_CSUM_NO_PSEUDOHDR)
                                 hw_csum = in_cksum_phdr(ip->ip_src.s_addr,                            hw_csum = in_cksum_phdr(ip->ip_src.s_addr, ip->ip_dst.s_addr,
                                     ip->ip_dst.s_addr,                                  htonl(hw_csum + ntohs(ip->ip_len) + IPPROTO_UDP));
                                     htons(hw_csum + len + IPPROTO_UDP));  
                         if ((hw_csum ^ 0xffff) != 0)                          if ((hw_csum ^ 0xffff) != 0)
                                 goto badcsum;                                  goto badcsum;
                         break;                          break;
Line 365  badcsum:
Line 373  badcsum:
   
 #ifdef INET6  #ifdef INET6
 int  int
 udp6_input(struct mbuf **mp, int *offp, int proto)  udp6_input(mp, offp, proto)
           struct mbuf **mp;
           int *offp, proto;
 {  {
         struct mbuf *m = *mp;          struct mbuf *m = *mp;
         int off = *offp;          int off = *offp;
Line 421  udp6_input(struct mbuf **mp, int *offp, 
Line 431  udp6_input(struct mbuf **mp, int *offp, 
         /*          /*
          * Checksum extended UDP header and data.           * Checksum extended UDP header and data.
          */           */
         if (uh->uh_sum == 0) {          if (uh->uh_sum == 0)
                 udp6stat.udp6s_nosum++;                  udp6stat.udp6s_nosum++;
                 goto bad;          else if (in6_cksum(m, IPPROTO_UDP, off, ulen) != 0) {
         }  
         if (in6_cksum(m, IPPROTO_UDP, off, ulen) != 0) {  
                 udp6stat.udp6s_badsum++;                  udp6stat.udp6s_badsum++;
                 goto bad;                  goto bad;
         }          }
Line 466  bad:
Line 474  bad:
   
 #ifdef INET  #ifdef INET
 static void  static void
 udp4_sendup(struct mbuf *m, int off /* offset of data portion */,  udp4_sendup(m, off, src, so)
         struct sockaddr *src, struct socket *so)          struct mbuf *m;
           int off;        /* offset of data portion */
           struct sockaddr *src;
           struct socket *so;
 {  {
         struct mbuf *opts = NULL;          struct mbuf *opts = NULL;
         struct mbuf *n;          struct mbuf *n;
Line 491  udp4_sendup(struct mbuf *m, int off /* o
Line 502  udp4_sendup(struct mbuf *m, int off /* o
         /* check AH/ESP integrity. */          /* check AH/ESP integrity. */
         if (so != NULL && ipsec4_in_reject_so(m, so)) {          if (so != NULL && ipsec4_in_reject_so(m, so)) {
                 ipsecstat.in_polvio++;                  ipsecstat.in_polvio++;
                 if ((n = m_copy(m, 0, M_COPYALL)) != NULL)  
                         icmp_error(n, ICMP_UNREACH, ICMP_UNREACH_ADMIN_PROHIBIT,  
                             0, 0);  
                 return;                  return;
         }          }
 #endif /*IPSEC*/  #endif /*IPSEC*/
Line 511  udp4_sendup(struct mbuf *m, int off /* o
Line 519  udp4_sendup(struct mbuf *m, int off /* o
                         m_freem(n);                          m_freem(n);
                         if (opts)                          if (opts)
                                 m_freem(opts);                                  m_freem(opts);
                         so->so_rcv.sb_overflowed++;  
                         udpstat.udps_fullsock++;                          udpstat.udps_fullsock++;
                 } else                  } else
                         sorwakeup(so);                          sorwakeup(so);
Line 521  udp4_sendup(struct mbuf *m, int off /* o
Line 528  udp4_sendup(struct mbuf *m, int off /* o
   
 #ifdef INET6  #ifdef INET6
 static void  static void
 udp6_sendup(struct mbuf *m, int off /* offset of data portion */,  udp6_sendup(m, off, src, so)
         struct sockaddr *src, struct socket *so)          struct mbuf *m;
           int off;        /* offset of data portion */
           struct sockaddr *src;
           struct socket *so;
 {  {
         struct mbuf *opts = NULL;          struct mbuf *opts = NULL;
         struct mbuf *n;          struct mbuf *n;
Line 538  udp6_sendup(struct mbuf *m, int off /* o
Line 548  udp6_sendup(struct mbuf *m, int off /* o
         /* check AH/ESP integrity. */          /* check AH/ESP integrity. */
         if (so != NULL && ipsec6_in_reject_so(m, so)) {          if (so != NULL && ipsec6_in_reject_so(m, so)) {
                 ipsec6stat.in_polvio++;                  ipsec6stat.in_polvio++;
                 if ((n = m_copy(m, 0, M_COPYALL)) != NULL)  
                         icmp6_error(n, ICMP6_DST_UNREACH,  
                             ICMP6_DST_UNREACH_ADMIN, 0);  
                 return;                  return;
         }          }
 #endif /*IPSEC*/  #endif /*IPSEC*/
Line 557  udp6_sendup(struct mbuf *m, int off /* o
Line 564  udp6_sendup(struct mbuf *m, int off /* o
                         m_freem(n);                          m_freem(n);
                         if (opts)                          if (opts)
                                 m_freem(opts);                                  m_freem(opts);
                         so->so_rcv.sb_overflowed++;  
                         udp6stat.udp6s_fullsock++;                          udp6stat.udp6s_fullsock++;
                 } else                  } else
                         sorwakeup(so);                          sorwakeup(so);
Line 567  udp6_sendup(struct mbuf *m, int off /* o
Line 573  udp6_sendup(struct mbuf *m, int off /* o
   
 #ifdef INET  #ifdef INET
 static int  static int
 udp4_realinput(struct sockaddr_in *src, struct sockaddr_in *dst,  udp4_realinput(src, dst, m, off)
         struct mbuf *m, int off /* offset of udphdr */)          struct sockaddr_in *src;
           struct sockaddr_in *dst;
           struct mbuf *m;
           int off;        /* offset of udphdr */
 {  {
         u_int16_t *sport, *dport;          u_int16_t *sport, *dport;
         int rcvcnt;          int rcvcnt;
         struct in_addr *src4, *dst4;          struct in_addr *src4, *dst4;
         struct inpcb_hdr *inph;  
         struct inpcb *inp;          struct inpcb *inp;
   
         rcvcnt = 0;          rcvcnt = 0;
Line 612  udp4_realinput(struct sockaddr_in *src, 
Line 620  udp4_realinput(struct sockaddr_in *src, 
                 /*                  /*
                  * Locate pcb(s) for datagram.                   * Locate pcb(s) for datagram.
                  */                   */
                 CIRCLEQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) {                  CIRCLEQ_FOREACH(inp, &udbtable.inpt_queue, inp_queue) {
                         inp = (struct inpcb *)inph;  
                         if (inp->inp_af != AF_INET)  
                                 continue;  
   
                         if (inp->inp_lport != *dport)                          if (inp->inp_lport != *dport)
                                 continue;                                  continue;
                         if (!in_nullhost(inp->inp_laddr)) {                          if (!in_nullhost(inp->inp_laddr)) {
Line 668  bad:
Line 672  bad:
   
 #ifdef INET6  #ifdef INET6
 static int  static int
 udp6_realinput(int af, struct sockaddr_in6 *src, struct sockaddr_in6 *dst,  udp6_realinput(af, src, dst, m, off)
         struct mbuf *m, int off)          int af;         /* af on packet */
           struct sockaddr_in6 *src;
           struct sockaddr_in6 *dst;
           struct mbuf *m;
           int off;        /* offset of udphdr */
 {  {
         u_int16_t sport, dport;          u_int16_t sport, dport;
         int rcvcnt;          int rcvcnt;
         struct in6_addr src6, dst6;          struct in6_addr src6, dst6;
         const struct in_addr *dst4;          const struct in_addr *dst4;
         struct inpcb_hdr *inph;  
         struct in6pcb *in6p;          struct in6pcb *in6p;
   
         rcvcnt = 0;          rcvcnt = 0;
Line 717  udp6_realinput(int af, struct sockaddr_i
Line 724  udp6_realinput(int af, struct sockaddr_i
                 /*                  /*
                  * Locate pcb(s) for datagram.                   * Locate pcb(s) for datagram.
                  */                   */
                 CIRCLEQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) {                  for (in6p = udb6.in6p_next; in6p != &udb6;
                         in6p = (struct in6pcb *)inph;                       in6p = in6p->in6p_next) {
                         if (in6p->in6p_af != AF_INET6)  
                                 continue;  
   
                         if (in6p->in6p_lport != dport)                          if (in6p->in6p_lport != dport)
                                 continue;                                  continue;
                         if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) {                          if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) {
Line 762  udp6_realinput(int af, struct sockaddr_i
Line 766  udp6_realinput(int af, struct sockaddr_i
                 /*                  /*
                  * Locate pcb for datagram.                   * Locate pcb for datagram.
                  */                   */
                 in6p = in6_pcblookup_connect(&udbtable, &src6, sport,                  in6p = in6_pcblookup_connect(&udb6, &src6, sport,
                     &dst6, dport, 0);                      &dst6, dport, 0);
                 if (in6p == 0) {                  if (in6p == 0) {
                         ++udpstat.udps_pcbhashmiss;                          ++udpstat.udps_pcbhashmiss;
                         in6p = in6_pcblookup_bind(&udbtable, &dst6, dport, 0);                          in6p = in6_pcblookup_bind(&udb6, &dst6, dport, 0);
                         if (in6p == 0)                          if (in6p == 0)
                                 return rcvcnt;                                  return rcvcnt;
                 }                  }
Line 786  bad:
Line 790  bad:
  * just wake up so that he can collect error status.   * just wake up so that he can collect error status.
  */   */
 static void  static void
 udp_notify(struct inpcb *inp, int errno)  udp_notify(inp, errno)
           struct inpcb *inp;
           int errno;
 {  {
   
         inp->inp_socket->so_error = errno;          inp->inp_socket->so_error = errno;
         sorwakeup(inp->inp_socket);          sorwakeup(inp->inp_socket);
         sowwakeup(inp->inp_socket);          sowwakeup(inp->inp_socket);
 }  }
   
 void *  void *
 udp_ctlinput(int cmd, struct sockaddr *sa, void *v)  udp_ctlinput(cmd, sa, v)
           int cmd;
           struct sockaddr *sa;
           void *v;
 {  {
         struct ip *ip = v;          struct ip *ip = v;
         struct udphdr *uh;          struct udphdr *uh;
         void (*notify)(struct inpcb *, int) = udp_notify;          void (*notify) __P((struct inpcb *, int)) = udp_notify;
         int errno;          int errno;
   
         if (sa->sa_family != AF_INET          if (sa->sa_family != AF_INET
Line 826  udp_ctlinput(int cmd, struct sockaddr *s
Line 836  udp_ctlinput(int cmd, struct sockaddr *s
 }  }
   
 int  int
   #if __STDC__
 udp_output(struct mbuf *m, ...)  udp_output(struct mbuf *m, ...)
   #else
   udp_output(m, va_alist)
           struct mbuf *m;
           va_dcl
   #endif
 {  {
         struct inpcb *inp;          struct inpcb *inp;
         struct udpiphdr *ui;          struct udpiphdr *ui;
Line 890  udp_output(struct mbuf *m, ...)
Line 906  udp_output(struct mbuf *m, ...)
         ((struct ip *)ui)->ip_tos = inp->inp_ip.ip_tos; /* XXX */          ((struct ip *)ui)->ip_tos = inp->inp_ip.ip_tos; /* XXX */
         udpstat.udps_opackets++;          udpstat.udps_opackets++;
   
   #ifdef IPSEC
           if (ipsec_setsocket(m, inp->inp_socket) != 0) {
                   error = ENOBUFS;
                   goto release;
           }
   #endif /*IPSEC*/
   
         return (ip_output(m, inp->inp_options, &inp->inp_route,          return (ip_output(m, inp->inp_options, &inp->inp_route,
             inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST),              inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST),
             inp->inp_moptions, inp->inp_socket));              inp->inp_moptions, inp->inp_socket));
Line 905  int udp_recvspace = 40 * (1024 + sizeof(
Line 928  int udp_recvspace = 40 * (1024 + sizeof(
   
 /*ARGSUSED*/  /*ARGSUSED*/
 int  int
 udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,  udp_usrreq(so, req, m, nam, control, p)
         struct mbuf *control, struct proc *p)          struct socket *so;
           int req;
           struct mbuf *m, *nam, *control;
           struct proc *p;
 {  {
         struct inpcb *inp;          struct inpcb *inp;
         int s;          int s;
Line 990  udp_usrreq(struct socket *so, int req, s
Line 1016  udp_usrreq(struct socket *so, int req, s
                 so->so_state &= ~SS_ISCONNECTED;        /* XXX */                  so->so_state &= ~SS_ISCONNECTED;        /* XXX */
                 in_pcbdisconnect(inp);                  in_pcbdisconnect(inp);
                 inp->inp_laddr = zeroin_addr;           /* XXX */                  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 */                  in_pcbstate(inp, INP_BOUND);            /* XXX */
                 break;                  break;
   
Line 1034  udp_usrreq(struct socket *so, int req, s
Line 1065  udp_usrreq(struct socket *so, int req, s
                         in_pcbstate(inp, INP_BOUND);    /* XXX */                          in_pcbstate(inp, INP_BOUND);    /* XXX */
                 }                  }
           die:            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)                  if (m)
                         m_freem(m);                          m_freem(m);
         }          }
Line 1076  release:
Line 1112  release:
 /*  /*
  * Sysctl for udp variables.   * Sysctl for udp variables.
  */   */
 SYSCTL_SETUP(sysctl_net_inet_udp_setup, "sysctl net.inet.udp subtree setup")  int
   udp_sysctl(name, namelen, oldp, oldlenp, newp, newlen)
           int *name;
           u_int namelen;
           void *oldp;
           size_t *oldlenp;
           void *newp;
           size_t newlen;
 {  {
           /* All sysctl names at this level are terminal. */
         sysctl_createv(clog, 0, NULL, NULL,          if (namelen != 1)
                        CTLFLAG_PERMANENT,                  return (ENOTDIR);
                        CTLTYPE_NODE, "net", NULL,  
                        NULL, 0, NULL, 0,          switch (name[0]) {
                        CTL_NET, CTL_EOL);          case UDPCTL_CHECKSUM:
         sysctl_createv(clog, 0, NULL, NULL,                  return (sysctl_int(oldp, oldlenp, newp, newlen, &udpcksum));
                        CTLFLAG_PERMANENT,          case UDPCTL_SENDSPACE:
                        CTLTYPE_NODE, "inet", NULL,                  return (sysctl_int(oldp, oldlenp, newp, newlen,
                        NULL, 0, NULL, 0,                      &udp_sendspace));
                        CTL_NET, PF_INET, CTL_EOL);          case UDPCTL_RECVSPACE:
         sysctl_createv(clog, 0, NULL, NULL,                  return (sysctl_int(oldp, oldlenp, newp, newlen,
                        CTLFLAG_PERMANENT,                      &udp_recvspace));
                        CTLTYPE_NODE, "udp",          default:
                        SYSCTL_DESCR("UDPv4 related settings"),                  return (ENOPROTOOPT);
                        NULL, 0, NULL, 0,          }
                        CTL_NET, PF_INET, IPPROTO_UDP, CTL_EOL);          /* NOTREACHED */
   
         sysctl_createv(clog, 0, NULL, NULL,  
                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,  
                        CTLTYPE_INT, "checksum",  
                        SYSCTL_DESCR("Compute 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  #endif

Legend:
Removed from v.1.103.2.3  
changed lines
  Added in v.1.107

CVSweb <webmaster@jp.NetBSD.org>