[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.22 and 1.28

version 1.22, 1995/06/18 20:01:19 version 1.28, 1996/03/16 23:54:03
Line 43 
Line 43 
 #include <sys/socketvar.h>  #include <sys/socketvar.h>
 #include <sys/errno.h>  #include <sys/errno.h>
 #include <sys/stat.h>  #include <sys/stat.h>
   #include <sys/systm.h>
   #include <sys/proc.h>
   
   #include <vm/vm.h>
   #include <sys/sysctl.h>
   
 #include <net/if.h>  #include <net/if.h>
 #include <net/route.h>  #include <net/route.h>
Line 57 
Line 62 
 #include <netinet/udp.h>  #include <netinet/udp.h>
 #include <netinet/udp_var.h>  #include <netinet/udp_var.h>
   
   #include <machine/stdarg.h>
   
 /*  /*
  * UDP protocol implementation.   * UDP protocol implementation.
  * Per RFC 768, August, 1980.   * Per RFC 768, August, 1980.
Line 68  int udpcksum = 0;  /* XXX */
Line 75  int udpcksum = 0;  /* XXX */
 #endif  #endif
   
 struct  sockaddr_in udp_in = { sizeof(udp_in), AF_INET };  struct  sockaddr_in udp_in = { sizeof(udp_in), AF_INET };
 struct  inpcb *udp_last_inpcb = 0;  
   
 static  void udp_detach __P((struct inpcb *));  static  void udp_detach __P((struct inpcb *));
 static  void udp_notify __P((struct inpcb *, int));  static  void udp_notify __P((struct inpcb *, int));
 static  struct mbuf *udp_saveopt __P((caddr_t, int, int));  static  struct mbuf *udp_saveopt __P((caddr_t, int, int));
   
   #ifndef UDBHASHSIZE
   #define UDBHASHSIZE     128
   #endif
   int     udbhashsize = UDBHASHSIZE;
   
 void  void
 udp_init()  udp_init()
 {  {
   
         in_pcbinit(&udbtable);          in_pcbinit(&udbtable, udbhashsize);
 }  }
   
 void  void
 udp_input(m, iphlen)  #if __STDC__
         register struct mbuf *m;  udp_input(struct mbuf *m, ...)
         int iphlen;  #else
   udp_input(m, va_alist)
           struct mbuf *m;
           va_dcl
   #endif
 {  {
         register struct ip *ip;          register struct ip *ip;
         register struct udphdr *uh;          register struct udphdr *uh;
Line 92  udp_input(m, iphlen)
Line 107  udp_input(m, iphlen)
         struct mbuf *opts = 0;          struct mbuf *opts = 0;
         int len;          int len;
         struct ip save_ip;          struct ip save_ip;
           int iphlen;
           va_list ap;
   
           va_start(ap, m);
           iphlen = va_arg(ap, int);
           va_end(ap);
   
         udpstat.udps_ipackets++;          udpstat.udps_ipackets++;
   
Line 142  udp_input(m, iphlen)
Line 163  udp_input(m, iphlen)
          * Checksum extended UDP header and data.           * Checksum extended UDP header and data.
          */           */
         if (udpcksum && uh->uh_sum) {          if (udpcksum && uh->uh_sum) {
                 ((struct ipovly *)ip)->ih_next = 0;                  bzero(((struct ipovly *)ip)->ih_x1,
                 ((struct ipovly *)ip)->ih_prev = 0;                      sizeof ((struct ipovly *)ip)->ih_x1);
                 ((struct ipovly *)ip)->ih_x1 = 0;  
                 ((struct ipovly *)ip)->ih_len = uh->uh_ulen;                  ((struct ipovly *)ip)->ih_len = uh->uh_ulen;
                 if (uh->uh_sum = in_cksum(m, len + sizeof (struct ip))) {                  if ((uh->uh_sum = in_cksum(m, len + sizeof (struct ip))) != 0) {
                         udpstat.udps_badsum++;                          udpstat.udps_badsum++;
                         m_freem(m);                          m_freem(m);
                         return;                          return;
Line 223  udp_input(m, iphlen)
Line 243  udp_input(m, iphlen)
                          * port.  It * assumes that an application will never                           * port.  It * assumes that an application will never
                          * clear these options after setting them.                           * clear these options after setting them.
                          */                           */
                         if ((last->so_options&(SO_REUSEPORT|SO_REUSEADDR) == 0))                          if ((last->so_options&(SO_REUSEPORT|SO_REUSEADDR)) == 0)
                                 break;                                  break;
                 }                  }
   
Line 247  udp_input(m, iphlen)
Line 267  udp_input(m, iphlen)
         /*          /*
          * Locate pcb for datagram.           * Locate pcb for datagram.
          */           */
         inp = udp_last_inpcb;          inp = in_pcbhashlookup(&udbtable, ip->ip_src, uh->uh_sport,
         if (inp == 0 ||              ip->ip_dst, uh->uh_dport);
             inp->inp_lport != uh->uh_dport ||          if (inp == 0) {
             inp->inp_fport != uh->uh_sport ||                  ++udpstat.udps_pcbhashmiss;
             inp->inp_faddr.s_addr != ip->ip_src.s_addr ||  
             inp->inp_laddr.s_addr != ip->ip_dst.s_addr) {  
                 udpstat.udpps_pcbcachemiss++;  
                 inp = in_pcblookup(&udbtable, ip->ip_src, uh->uh_sport,                  inp = in_pcblookup(&udbtable, ip->ip_src, uh->uh_sport,
                     ip->ip_dst, uh->uh_dport, INPLOOKUP_WILDCARD);                      ip->ip_dst, uh->uh_dport, INPLOOKUP_WILDCARD);
                 if (inp == 0) {                  if (inp == 0) {
Line 267  udp_input(m, iphlen)
Line 284  udp_input(m, iphlen)
                         icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0);                          icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0);
                         return;                          return;
                 }                  }
                 udp_last_inpcb = inp;  
         }          }
   
         /*          /*
Line 358  udp_notify(inp, errno)
Line 374  udp_notify(inp, errno)
         sowwakeup(inp->inp_socket);          sowwakeup(inp->inp_socket);
 }  }
   
 void  void *
 udp_ctlinput(cmd, sa, ip)  udp_ctlinput(cmd, sa, v)
         int cmd;          int cmd;
         struct sockaddr *sa;          struct sockaddr *sa;
         register struct ip *ip;          void *v;
 {  {
           register struct ip *ip = v;
         register struct udphdr *uh;          register struct udphdr *uh;
         extern struct in_addr zeroin_addr;  
         extern int inetctlerrmap[];          extern int inetctlerrmap[];
         void (*notify) __P((struct inpcb *, int)) = udp_notify;          void (*notify) __P((struct inpcb *, int)) = udp_notify;
         int errno;          int errno;
   
         if ((unsigned)cmd >= PRC_NCMDS)          if ((unsigned)cmd >= PRC_NCMDS)
                 return;                  return NULL;
         errno = inetctlerrmap[cmd];          errno = inetctlerrmap[cmd];
         if (PRC_IS_REDIRECT(cmd))          if (PRC_IS_REDIRECT(cmd))
                 notify = in_rtchange, ip = 0;                  notify = in_rtchange, ip = 0;
         else if (cmd == PRC_HOSTDEAD)          else if (cmd == PRC_HOSTDEAD)
                 ip = 0;                  ip = 0;
         else if (errno = 0)          else if (errno == 0)
                 return;                  return NULL;
         if (ip) {          if (ip) {
                 uh = (struct udphdr *)((caddr_t)ip + (ip->ip_hl << 2));                  uh = (struct udphdr *)((caddr_t)ip + (ip->ip_hl << 2));
                 in_pcbnotify(&udbtable, sa, uh->uh_dport, ip->ip_src,                  in_pcbnotify(&udbtable, sa, uh->uh_dport, ip->ip_src,
                     uh->uh_sport, errno, notify);                      uh->uh_sport, errno, notify);
         } else          } else
                 in_pcbnotifyall(&udbtable, sa, errno, notify);                  in_pcbnotifyall(&udbtable, sa, errno, notify);
           return NULL;
 }  }
   
 int  int
 udp_output(inp, m, addr, control)  #if __STDC__
   udp_output(struct mbuf *m, ...)
   #else
   udp_output(m, va_alist)
           struct mbuf *m;
           va_dcl
   #endif
   {
         register struct inpcb *inp;          register struct inpcb *inp;
         register struct mbuf *m;  
         struct mbuf *addr, *control;          struct mbuf *addr, *control;
 {  
         register struct udpiphdr *ui;          register struct udpiphdr *ui;
         register int len = m->m_pkthdr.len;          register int len = m->m_pkthdr.len;
         struct in_addr laddr;          struct in_addr laddr;
         int s, error = 0;          int s = 0, error = 0;
           va_list ap;
   
           va_start(ap, m);
           inp = va_arg(ap, struct inpcb *);
           addr = va_arg(ap, struct mbuf *);
           control = va_arg(ap, struct mbuf *);
           va_end(ap);
   
         if (control)          if (control)
                 m_freem(control);               /* XXX */                  m_freem(control);               /* XXX */
Line 410  udp_output(inp, m, addr, control)
Line 439  udp_output(inp, m, addr, control)
                 /*                  /*
                  * Must block input while temporarily connected.                   * Must block input while temporarily connected.
                  */                   */
                 s = splnet();                  s = splsoftnet();
                 error = in_pcbconnect(inp, addr);                  error = in_pcbconnect(inp, addr);
                 if (error) {                  if (error) {
                         splx(s);                          splx(s);
Line 437  udp_output(inp, m, addr, control)
Line 466  udp_output(inp, m, addr, control)
          * and addresses and length put into network format.           * and addresses and length put into network format.
          */           */
         ui = mtod(m, struct udpiphdr *);          ui = mtod(m, struct udpiphdr *);
         ui->ui_next = ui->ui_prev = 0;          bzero(ui->ui_x1, sizeof ui->ui_x1);
         ui->ui_x1 = 0;  
         ui->ui_pr = IPPROTO_UDP;          ui->ui_pr = IPPROTO_UDP;
         ui->ui_len = htons((u_int16_t)len + sizeof (struct udphdr));          ui->ui_len = htons((u_int16_t)len + sizeof (struct udphdr));
         ui->ui_src = inp->inp_laddr;          ui->ui_src = inp->inp_laddr;
Line 508  udp_usrreq(so, req, m, addr, control)
Line 536  udp_usrreq(so, req, m, addr, control)
                         error = EINVAL;                          error = EINVAL;
                         break;                          break;
                 }                  }
                 s = splnet();                  s = splsoftnet();
                 error = in_pcballoc(so, &udbtable);                  error = in_pcballoc(so, &udbtable);
                 splx(s);                  splx(s);
                 if (error)                  if (error)
Line 524  udp_usrreq(so, req, m, addr, control)
Line 552  udp_usrreq(so, req, m, addr, control)
                 break;                  break;
   
         case PRU_BIND:          case PRU_BIND:
                 s = splnet();                  s = splsoftnet();
                 error = in_pcbbind(inp, addr);                  error = in_pcbbind(inp, addr);
                 splx(s);                  splx(s);
                 break;                  break;
Line 538  udp_usrreq(so, req, m, addr, control)
Line 566  udp_usrreq(so, req, m, addr, control)
                         error = EISCONN;                          error = EISCONN;
                         break;                          break;
                 }                  }
                 s = splnet();                  s = splsoftnet();
                 error = in_pcbconnect(inp, addr);                  error = in_pcbconnect(inp, addr);
                 splx(s);                  splx(s);
                 if (error == 0)                  if (error == 0)
Line 558  udp_usrreq(so, req, m, addr, control)
Line 586  udp_usrreq(so, req, m, addr, control)
                         error = ENOTCONN;                          error = ENOTCONN;
                         break;                          break;
                 }                  }
                 s = splnet();                  s = splsoftnet();
                 in_pcbdisconnect(inp);                  in_pcbdisconnect(inp);
                 inp->inp_laddr.s_addr = INADDR_ANY;                  inp->inp_laddr.s_addr = INADDR_ANY;
                 splx(s);                  splx(s);
Line 570  udp_usrreq(so, req, m, addr, control)
Line 598  udp_usrreq(so, req, m, addr, control)
                 break;                  break;
   
         case PRU_SEND:          case PRU_SEND:
                 return (udp_output(inp, m, addr, control));                  return (udp_output(m, inp, addr, control));
   
         case PRU_ABORT:          case PRU_ABORT:
                 soisdisconnected(so);                  soisdisconnected(so);
Line 621  static void
Line 649  static void
 udp_detach(inp)  udp_detach(inp)
         struct inpcb *inp;          struct inpcb *inp;
 {  {
         int s = splnet();          int s = splsoftnet();
   
         if (inp == udp_last_inpcb)  
                 udp_last_inpcb = 0;  
         in_pcbdetach(inp);          in_pcbdetach(inp);
         splx(s);          splx(s);
 }  }
Line 632  udp_detach(inp)
Line 658  udp_detach(inp)
 /*  /*
  * Sysctl for udp variables.   * Sysctl for udp variables.
  */   */
   int
 udp_sysctl(name, namelen, oldp, oldlenp, newp, newlen)  udp_sysctl(name, namelen, oldp, oldlenp, newp, newlen)
         int *name;          int *name;
         u_int namelen;          u_int namelen;

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.28

CVSweb <webmaster@jp.NetBSD.org>