[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.86 and 1.97

version 1.86, 2001/10/24 06:04:08 version 1.97, 2003/01/20 00:05:46
Line 3 
Line 3 
 /*  /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.   * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  * All rights reserved.   * All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions   * modification, are permitted provided that the following conditions
  * are met:   * are met:
Line 15 
Line 15 
  * 3. Neither the name of the project nor the names of its contributors   * 3. Neither the name of the project nor the names of its contributors
  *    may be used to endorse or promote products derived from this software   *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.   *    without specific prior written permission.
  *   *
  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND   * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Line 64 
Line 64 
  *      @(#)udp_usrreq.c        8.6 (Berkeley) 5/23/95   *      @(#)udp_usrreq.c        8.6 (Berkeley) 5/23/95
  */   */
   
   #include <sys/cdefs.h>
   __KERNEL_RCSID(0, "$NetBSD$");
   
 #include "opt_inet.h"  #include "opt_inet.h"
 #include "opt_ipsec.h"  #include "opt_ipsec.h"
 #include "opt_inet_csum.h"  #include "opt_inet_csum.h"
Line 80 
Line 83 
 #include <sys/systm.h>  #include <sys/systm.h>
 #include <sys/proc.h>  #include <sys/proc.h>
 #include <sys/domain.h>  #include <sys/domain.h>
   
 #include <uvm/uvm_extern.h>  
 #include <sys/sysctl.h>  #include <sys/sysctl.h>
   
 #include <net/if.h>  #include <net/if.h>
Line 138  int udpcksum = 1;
Line 139  int udpcksum = 1;
 int     udpcksum = 0;           /* XXX */  int     udpcksum = 0;           /* XXX */
 #endif  #endif
   
   struct  inpcbtable udbtable;
   struct  udpstat udpstat;
   
 #ifdef INET  #ifdef INET
 static void udp4_sendup __P((struct mbuf *, int, struct sockaddr *,  static void udp4_sendup __P((struct mbuf *, int, struct sockaddr *,
         struct socket *));          struct socket *));
Line 147  static int udp4_realinput __P((struct so
Line 151  static int udp4_realinput __P((struct so
 #ifdef INET6  #ifdef INET6
 static void udp6_sendup __P((struct mbuf *, int, struct sockaddr *,  static void udp6_sendup __P((struct mbuf *, int, struct sockaddr *,
         struct socket *));          struct socket *));
 static  int in6_mcmatch __P((struct in6pcb *, struct in6_addr *,  
         struct ifnet *));  
 static int udp6_realinput __P((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
Line 211  udp_input(m, va_alist)
Line 213  udp_input(m, va_alist)
         struct sockaddr_in src, dst;          struct sockaddr_in src, dst;
         struct ip *ip;          struct ip *ip;
         struct udphdr *uh;          struct udphdr *uh;
         int iphlen, proto;          int iphlen;
         int len;          int len;
         int n;          int n;
           u_int16_t ip_len;
   
         va_start(ap, m);          va_start(ap, m);
         iphlen = va_arg(ap, int);          iphlen = va_arg(ap, int);
         proto = va_arg(ap, int);          (void)va_arg(ap, int);          /* ignore value, advance ap */
         va_end(ap);          va_end(ap);
   
         udpstat.udps_ipackets++;          udpstat.udps_ipackets++;
Line 260  udp_input(m, va_alist)
Line 263  udp_input(m, va_alist)
                 return;                  return;
         }          }
 #endif  #endif
           KASSERT(UDP_HDR_ALIGNED_P(uh));
   
         /* destination port of 0 is illegal, based on RFC768. */          /* destination port of 0 is illegal, based on RFC768. */
         if (uh->uh_dport == 0)          if (uh->uh_dport == 0)
Line 269  udp_input(m, va_alist)
Line 273  udp_input(m, va_alist)
          * Make mbuf data length reflect UDP length.           * Make mbuf data length reflect UDP length.
          * If not enough data to reflect UDP length, drop.           * If not enough data to reflect UDP length, drop.
          */           */
           ip_len = ntohs(ip->ip_len);
         len = ntohs((u_int16_t)uh->uh_ulen);          len = ntohs((u_int16_t)uh->uh_ulen);
         if (ip->ip_len != iphlen + len) {          if (ip_len != iphlen + len) {
                 if (ip->ip_len < iphlen + len || len < sizeof(struct udphdr)) {                  if (ip_len < iphlen + len || len < sizeof(struct udphdr)) {
                         udpstat.udps_badlen++;                          udpstat.udps_badlen++;
                         goto bad;                          goto bad;
                 }                  }
                 m_adj(m, iphlen + len - ip->ip_len);                  m_adj(m, iphlen + len - ip_len);
         }          }
   
         /*          /*
Line 416  udp6_input(mp, offp, proto)
Line 421  udp6_input(mp, offp, proto)
                 return IPPROTO_DONE;                  return IPPROTO_DONE;
         }          }
 #endif  #endif
           KASSERT(UDP_HDR_ALIGNED_P(uh));
         ulen = ntohs((u_short)uh->uh_ulen);          ulen = ntohs((u_short)uh->uh_ulen);
         /*          /*
          * RFC2675 section 4: jumbograms will have 0 in the UDP header field,           * RFC2675 section 4: jumbograms will have 0 in the UDP header field,
Line 495  udp4_sendup(m, off, src, so)
Line 501  udp4_sendup(m, off, src, so)
         struct mbuf *opts = NULL;          struct mbuf *opts = NULL;
         struct mbuf *n;          struct mbuf *n;
         struct inpcb *inp = NULL;          struct inpcb *inp = NULL;
 #ifdef INET6  
         struct in6pcb *in6p = NULL;  
 #endif  
   
         if (!so)          if (!so)
                 return;                  return;
Line 507  udp4_sendup(m, off, src, so)
Line 510  udp4_sendup(m, off, src, so)
                 break;                  break;
 #ifdef INET6  #ifdef INET6
         case AF_INET6:          case AF_INET6:
                 in6p = sotoin6pcb(so);  
                 break;                  break;
 #endif  #endif
         default:          default:
Line 613  udp4_realinput(src, dst, m, off)
Line 615  udp4_realinput(src, dst, m, off)
   
         if (IN_MULTICAST(dst4->s_addr) ||          if (IN_MULTICAST(dst4->s_addr) ||
             in_broadcast(*dst4, m->m_pkthdr.rcvif)) {              in_broadcast(*dst4, m->m_pkthdr.rcvif)) {
                 struct inpcb *last;  
                 /*                  /*
                  * Deliver a multicast or broadcast datagram to *all* sockets                   * Deliver a multicast or broadcast datagram to *all* sockets
                  * for which the local and remote addresses and ports match                   * for which the local and remote addresses and ports match
Line 631  udp4_realinput(src, dst, m, off)
Line 632  udp4_realinput(src, dst, m, off)
                  */                   */
   
                 /*                  /*
                  * KAME note: usually we drop udpiphdr from mbuf here.                   * KAME note: traditionally we dropped udpiphdr from mbuf here.
                  * we need udpiphdr for IPsec processing so we do that later.                   * we need udpiphdr for IPsec processing so we do that later.
                  */                   */
                 /*                  /*
                  * Locate pcb(s) for datagram.                   * Locate pcb(s) for datagram.
                  */                   */
                 for (inp = udbtable.inpt_queue.cqh_first;                  CIRCLEQ_FOREACH(inp, &udbtable.inpt_queue, inp_queue) {
                     inp != (struct inpcb *)&udbtable.inpt_queue;  
                     inp = inp->inp_queue.cqe_next) {  
                         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 652  udp4_realinput(src, dst, m, off)
Line 651  udp4_realinput(src, dst, m, off)
                                         continue;                                          continue;
                         }                          }
   
                         last = inp;  
                         udp4_sendup(m, off, (struct sockaddr *)src,                          udp4_sendup(m, off, (struct sockaddr *)src,
                                 inp->inp_socket);                                  inp->inp_socket);
                         rcvcnt++;                          rcvcnt++;
Line 692  bad:
Line 690  bad:
   
 #ifdef INET6  #ifdef INET6
 static int  static int
 in6_mcmatch(in6p, ia6, ifp)  
         struct in6pcb *in6p;  
         struct in6_addr *ia6;  
         struct ifnet *ifp;  
 {  
         struct ip6_moptions *im6o = in6p->in6p_moptions;  
         struct in6_multi_mship *imm;  
   
         if (im6o == NULL)  
                 return 0;  
   
         for (imm = im6o->im6o_memberships.lh_first; imm != NULL;  
              imm = imm->i6mm_chain.le_next) {  
                 if ((ifp == NULL ||  
                      imm->i6mm_maddr->in6m_ifp == ifp) &&  
                     IN6_ARE_ADDR_EQUAL(&imm->i6mm_maddr->in6m_addr,  
                                        ia6))  
                         return 1;  
         }  
         return 0;  
 }  
   
 static int  
 udp6_realinput(af, src, dst, m, off)  udp6_realinput(af, src, dst, m, off)
         int af;         /* af on packet */          int af;         /* af on packet */
         struct sockaddr_in6 *src;          struct sockaddr_in6 *src;
Line 740  udp6_realinput(af, src, dst, m, off)
Line 715  udp6_realinput(af, src, dst, m, off)
         sport = src->sin6_port;          sport = src->sin6_port;
         in6_embedscope(&dst6, dst, NULL, NULL);          in6_embedscope(&dst6, dst, NULL, NULL);
         dport = dst->sin6_port;          dport = dst->sin6_port;
         dst4 = (struct in_addr *)&dst->sin6_addr.s6_addr32[12];          dst4 = (struct in_addr *)&dst->sin6_addr.s6_addr[12];
   
         if (IN6_IS_ADDR_MULTICAST(&dst6) ||          if (IN6_IS_ADDR_MULTICAST(&dst6) ||
             (af == AF_INET && IN_MULTICAST(dst4->s_addr))) {              (af == AF_INET && IN_MULTICAST(dst4->s_addr))) {
                 struct in6pcb *last;  
                 /*                  /*
                  * Deliver a multicast or broadcast datagram to *all* sockets                   * Deliver a multicast or broadcast datagram to *all* sockets
                  * for which the local and remote addresses and ports match                   * for which the local and remote addresses and ports match
Line 762  udp6_realinput(af, src, dst, m, off)
Line 736  udp6_realinput(af, src, dst, m, off)
                  */                   */
   
                 /*                  /*
                  * KAME note: usually we drop udpiphdr from mbuf here.                   * KAME note: traditionally we dropped udpiphdr from mbuf here.
                  * we need udpiphdr for IPsec processing so we do that later.                   * we need udpiphdr for IPsec processing so we do that later.
                  */                   */
                 /*                  /*
Line 773  udp6_realinput(af, src, dst, m, off)
Line 747  udp6_realinput(af, src, dst, m, off)
                         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)) {
                                 if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, &dst6) &&                                  if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, &dst6))
                                     !in6_mcmatch(in6p, &dst6, m->m_pkthdr.rcvif))  
                                         continue;                                          continue;
                         }                          } else {
                         else {  
                                 if (IN6_IS_ADDR_V4MAPPED(&dst6) &&                                  if (IN6_IS_ADDR_V4MAPPED(&dst6) &&
                                     (in6p->in6p_flags & IN6P_IPV6_V6ONLY))                                      (in6p->in6p_flags & IN6P_IPV6_V6ONLY))
                                         continue;                                          continue;
Line 786  udp6_realinput(af, src, dst, m, off)
Line 758  udp6_realinput(af, src, dst, m, off)
                                 if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_faddr,                                  if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_faddr,
                                     &src6) || in6p->in6p_fport != sport)                                      &src6) || in6p->in6p_fport != sport)
                                         continue;                                          continue;
                         }                          } else {
                         else {  
                                 if (IN6_IS_ADDR_V4MAPPED(&src6) &&                                  if (IN6_IS_ADDR_V4MAPPED(&src6) &&
                                     (in6p->in6p_flags & IN6P_IPV6_V6ONLY))                                      (in6p->in6p_flags & IN6P_IPV6_V6ONLY))
                                         continue;                                          continue;
                         }                          }
   
                         last = in6p;  
                         udp6_sendup(m, off, (struct sockaddr *)src,                          udp6_sendup(m, off, (struct sockaddr *)src,
                                 in6p->in6p_socket);                                  in6p->in6p_socket);
                         rcvcnt++;                          rcvcnt++;
Line 916  udp_output(m, va_alist)
Line 886  udp_output(m, va_alist)
          * Compute the packet length of the IP header, and           * Compute the packet length of the IP header, and
          * punt if the length looks bogus.           * punt if the length looks bogus.
          */           */
         if ((len + sizeof(struct udpiphdr)) > IP_MAXPACKET) {          if (len + sizeof(struct udpiphdr) > IP_MAXPACKET) {
                 error = EMSGSIZE;                  error = EMSGSIZE;
                 goto release;                  goto release;
         }          }
Line 948  udp_output(m, va_alist)
Line 918  udp_output(m, va_alist)
                 m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum);                  m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum);
         } else          } else
                 ui->ui_sum = 0;                  ui->ui_sum = 0;
         ((struct ip *)ui)->ip_len = sizeof (struct udpiphdr) + len;          ((struct ip *)ui)->ip_len = htons(sizeof (struct udpiphdr) + len);
         ((struct ip *)ui)->ip_ttl = inp->inp_ip.ip_ttl; /* XXX */          ((struct ip *)ui)->ip_ttl = inp->inp_ip.ip_ttl; /* XXX */
         ((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++;
Line 1163  udp_sysctl(name, namelen, oldp, oldlenp,
Line 1133  udp_sysctl(name, namelen, oldp, oldlenp,
                 return (sysctl_int(oldp, oldlenp, newp, newlen,                  return (sysctl_int(oldp, oldlenp, newp, newlen,
                     &udp_sendspace));                      &udp_sendspace));
         case UDPCTL_RECVSPACE:          case UDPCTL_RECVSPACE:
                 return (sysctl_int(oldp, oldlenp, newp, newlen,                  return (sysctl_int(oldp, oldlenp, newp, newlen,
                     &udp_recvspace));                      &udp_recvspace));
         default:          default:
                 return (ENOPROTOOPT);                  return (ENOPROTOOPT);

Legend:
Removed from v.1.86  
changed lines
  Added in v.1.97

CVSweb <webmaster@jp.NetBSD.org>