[BACK]Return to raw_ip.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/raw_ip.c between version 1.114.2.4 and 1.157

version 1.114.2.4, 2017/12/03 11:39:04 version 1.157, 2016/04/26 08:44:44
Line 69  __KERNEL_RCSID(0, "$NetBSD$");
Line 69  __KERNEL_RCSID(0, "$NetBSD$");
   
 #ifdef _KERNEL_OPT  #ifdef _KERNEL_OPT
 #include "opt_inet.h"  #include "opt_inet.h"
   #include "opt_compat_netbsd.h"
 #include "opt_ipsec.h"  #include "opt_ipsec.h"
 #include "opt_mrouting.h"  #include "opt_mrouting.h"
 #include "opt_net_mpsafe.h"  
 #endif  #endif
   
 #include <sys/param.h>  #include <sys/param.h>
Line 104  __KERNEL_RCSID(0, "$NetBSD$");
Line 104  __KERNEL_RCSID(0, "$NetBSD$");
 #include <netipsec/ipsec_private.h>  #include <netipsec/ipsec_private.h>
 #endif  /* IPSEC */  #endif  /* IPSEC */
   
   #ifdef COMPAT_50
   #include <compat/sys/socket.h>
   #endif
   
 struct inpcbtable rawcbtable;  struct inpcbtable rawcbtable;
   
 int      rip_pcbnotify(struct inpcbtable *, struct in_addr,  int      rip_pcbnotify(struct inpcbtable *, struct in_addr,
Line 144  rip_sbappendaddr(struct inpcb *last, str
Line 148  rip_sbappendaddr(struct inpcb *last, str
         if (last->inp_flags & INP_NOHEADER)          if (last->inp_flags & INP_NOHEADER)
                 m_adj(n, hlen);                  m_adj(n, hlen);
         if (last->inp_flags & INP_CONTROLOPTS          if (last->inp_flags & INP_CONTROLOPTS
             || SOOPT_TIMESTAMP(last->inp_socket->so_options))  #ifdef SO_OTIMESTAMP
               || last->inp_socket->so_options & SO_OTIMESTAMP
   #endif
               || last->inp_socket->so_options & SO_TIMESTAMP)
                 ip_savecontrol(last, &opts, ip, n);                  ip_savecontrol(last, &opts, ip, n);
         if (sbappendaddr(&last->inp_socket->so_rcv, sa, n, opts) == 0) {          if (sbappendaddr(&last->inp_socket->so_rcv, sa, n, opts) == 0) {
                 /* should notify about lost packet */                  /* should notify about lost packet */
Line 205  rip_input(struct mbuf *m, ...)
Line 212  rip_input(struct mbuf *m, ...)
 #if defined(IPSEC)  #if defined(IPSEC)
                 /* check AH/ESP integrity. */                  /* check AH/ESP integrity. */
                 else if (ipsec_used &&                  else if (ipsec_used &&
                     ipsec4_in_reject(m, last)) {                      ipsec4_in_reject_so(m, last->inp_socket)) {
                         IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);                          IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);
                         /* do not inject data to pcb */                          /* do not inject data to pcb */
                 }                  }
Line 220  rip_input(struct mbuf *m, ...)
Line 227  rip_input(struct mbuf *m, ...)
 #if defined(IPSEC)  #if defined(IPSEC)
         /* check AH/ESP integrity. */          /* check AH/ESP integrity. */
         if (ipsec_used && last != NULL          if (ipsec_used && last != NULL
             && ipsec4_in_reject(m, last)) {              && ipsec4_in_reject_so(m, last->inp_socket)) {
                 m_freem(m);                  m_freem(m);
                 IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);                  IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);
                 IP_STATDEC(IP_STAT_DELIVERED);                  IP_STATDEC(IP_STAT_DELIVERED);
Line 303  rip_ctlinput(int cmd, const struct socka
Line 310  rip_ctlinput(int cmd, const struct socka
  * Tack on options user may have setup with control call.   * Tack on options user may have setup with control call.
  */   */
 int  int
 rip_output(struct mbuf *m, struct inpcb *inp, struct mbuf *control,  rip_output(struct mbuf *m, struct inpcb *inp)
     struct lwp *l)  
 {  {
         struct ip *ip;          struct ip *ip;
         struct mbuf *opts;          struct mbuf *opts;
         struct ip_pktopts pktopts;          int flags;
         kauth_cred_t cred;  
         int error, flags;          flags =
               (inp->inp_socket->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST
         flags = (inp->inp_socket->so_options & SO_DONTROUTE) |              | IP_RETURNMTU;
             IP_ALLOWBROADCAST | IP_RETURNMTU;  
   
         if (l == NULL)  
                 cred = NULL;  
         else  
                 cred = l->l_cred;  
   
         /* Setup IP outgoing packet options */  
         memset(&pktopts, 0, sizeof(pktopts));  
         error = ip_setpktopts(control, &pktopts, &flags, inp, cred,  
             IPPROTO_RAW);  
         if (control != NULL)  
                 m_freem(control);  
         if (error != 0)  
                 goto release;  
   
         /*          /*
          * If the user handed us a complete IP packet, use it.           * If the user handed us a complete IP packet, use it.
Line 335  rip_output(struct mbuf *m, struct inpcb 
Line 326  rip_output(struct mbuf *m, struct inpcb 
          */           */
         if ((inp->inp_flags & INP_HDRINCL) == 0) {          if ((inp->inp_flags & INP_HDRINCL) == 0) {
                 if ((m->m_pkthdr.len + sizeof(struct ip)) > IP_MAXPACKET) {                  if ((m->m_pkthdr.len + sizeof(struct ip)) > IP_MAXPACKET) {
                         error = EMSGSIZE;                          m_freem(m);
                         goto release;                          return (EMSGSIZE);
                 }                  }
                 M_PREPEND(m, sizeof(struct ip), M_DONTWAIT);                  M_PREPEND(m, sizeof(struct ip), M_DONTWAIT);
                 if (!m) {                  if (!m)
                         error = ENOBUFS;                          return (ENOBUFS);
                         goto release;  
                 }  
                 ip = mtod(m, struct ip *);                  ip = mtod(m, struct ip *);
                 ip->ip_tos = 0;                  ip->ip_tos = 0;
                 ip->ip_off = htons(0);                  ip->ip_off = htons(0);
                 ip->ip_p = inp->inp_ip.ip_p;                  ip->ip_p = inp->inp_ip.ip_p;
                 ip->ip_len = htons(m->m_pkthdr.len);                  ip->ip_len = htons(m->m_pkthdr.len);
                 ip->ip_src = pktopts.ippo_laddr.sin_addr;                  ip->ip_src = inp->inp_laddr;
                 ip->ip_dst = inp->inp_faddr;                  ip->ip_dst = inp->inp_faddr;
                 ip->ip_ttl = MAXTTL;                  ip->ip_ttl = MAXTTL;
                 opts = inp->inp_options;                  opts = inp->inp_options;
         } else {          } else {
                 if (m->m_pkthdr.len > IP_MAXPACKET) {                  if (m->m_pkthdr.len > IP_MAXPACKET) {
                         error = EMSGSIZE;                          m_freem(m);
                         goto release;                          return (EMSGSIZE);
                 }                  }
                 ip = mtod(m, struct ip *);                  ip = mtod(m, struct ip *);
   
Line 368  rip_output(struct mbuf *m, struct inpcb 
Line 357  rip_output(struct mbuf *m, struct inpcb 
                         int hlen = ip->ip_hl << 2;                          int hlen = ip->ip_hl << 2;
   
                         m = m_copyup(m, hlen, (max_linkhdr + 3) & ~3);                          m = m_copyup(m, hlen, (max_linkhdr + 3) & ~3);
                         if (m == NULL) {                          if (m == NULL)
                                 error = ENOMEM; /* XXX */                                  return (ENOMEM);        /* XXX */
                                 goto release;  
                         }  
                         ip = mtod(m, struct ip *);                          ip = mtod(m, struct ip *);
                 }                  }
   
                 /* XXX userland passes ip_len and ip_off in host order */                  /* XXX userland passes ip_len and ip_off in host order */
                 if (m->m_pkthdr.len != ip->ip_len) {                  if (m->m_pkthdr.len != ip->ip_len) {
                         error = EINVAL;                          m_freem(m);
                         goto release;                          return (EINVAL);
                 }                  }
                 HTONS(ip->ip_len);                  HTONS(ip->ip_len);
                 HTONS(ip->ip_off);                  HTONS(ip->ip_off);
Line 394  rip_output(struct mbuf *m, struct inpcb 
Line 381  rip_output(struct mbuf *m, struct inpcb 
          * IP output.  Note: if IP_RETURNMTU flag is set, the MTU size           * IP output.  Note: if IP_RETURNMTU flag is set, the MTU size
          * will be stored in inp_errormtu.           * will be stored in inp_errormtu.
          */           */
         return ip_output(m, opts, &inp->inp_route, flags, pktopts.ippo_imo,          return ip_output(m, opts, &inp->inp_route, flags, inp->inp_moptions,
             inp);               inp->inp_socket);
   
  release:  
         if (m != NULL)  
                 m_freem(m);  
         return error;  
 }  }
   
 /*  /*
Line 496  int
Line 478  int
 rip_connect_pcb(struct inpcb *inp, struct sockaddr_in *addr)  rip_connect_pcb(struct inpcb *inp, struct sockaddr_in *addr)
 {  {
   
         if (IFNET_READER_EMPTY())          if (IFNET_EMPTY())
                 return (EADDRNOTAVAIL);                  return (EADDRNOTAVAIL);
         if (addr->sin_family != AF_INET)          if (addr->sin_family != AF_INET)
                 return (EAFNOSUPPORT);                  return (EAFNOSUPPORT);
Line 572  rip_bind(struct socket *so, struct socka
Line 554  rip_bind(struct socket *so, struct socka
         struct inpcb *inp = sotoinpcb(so);          struct inpcb *inp = sotoinpcb(so);
         struct sockaddr_in *addr = (struct sockaddr_in *)nam;          struct sockaddr_in *addr = (struct sockaddr_in *)nam;
         int error = 0;          int error = 0;
         int s, ss;          int s;
         struct ifaddr *ifa;          struct ifaddr *ia;
   
         KASSERT(solocked(so));          KASSERT(solocked(so));
         KASSERT(inp != NULL);          KASSERT(inp != NULL);
Line 583  rip_bind(struct socket *so, struct socka
Line 565  rip_bind(struct socket *so, struct socka
                 return EINVAL;                  return EINVAL;
   
         s = splsoftnet();          s = splsoftnet();
         if (IFNET_READER_EMPTY()) {          if (IFNET_EMPTY()) {
                 error = EADDRNOTAVAIL;                  error = EADDRNOTAVAIL;
                 goto release;                  goto release;
         }          }
Line 591  rip_bind(struct socket *so, struct socka
Line 573  rip_bind(struct socket *so, struct socka
                 error = EAFNOSUPPORT;                  error = EAFNOSUPPORT;
                 goto release;                  goto release;
         }          }
         ss = pserialize_read_enter();          if ((ia = ifa_ifwithaddr(sintosa(addr))) == 0 &&
         if ((ifa = ifa_ifwithaddr(sintosa(addr))) == NULL &&  
             !in_nullhost(addr->sin_addr))              !in_nullhost(addr->sin_addr))
         {          {
                 pserialize_read_exit(ss);  
                 error = EADDRNOTAVAIL;                  error = EADDRNOTAVAIL;
                 goto release;                  goto release;
         }          }
         if (ifa && (ifatoia(ifa))->ia4_flags & IN6_IFF_DUPLICATED) {          if (ia && ((struct in_ifaddr *)ia)->ia4_flags &
                 pserialize_read_exit(ss);                      (IN6_IFF_NOTREADY | IN_IFF_DETACHED))
           {
                 error = EADDRNOTAVAIL;                  error = EADDRNOTAVAIL;
                 goto release;                  goto release;
         }          }
         pserialize_read_exit(ss);  
   
         inp->inp_laddr = addr->sin_addr;          inp->inp_laddr = addr->sin_addr;
   
Line 772  rip_send(struct socket *so, struct mbuf 
Line 752  rip_send(struct socket *so, struct mbuf 
          * Ship a packet out.  The appropriate raw output           * Ship a packet out.  The appropriate raw output
          * routine handles any massaging necessary.           * routine handles any massaging necessary.
          */           */
           if (control && control->m_len) {
                   m_freem(control);
                   m_freem(m);
                   return EINVAL;
           }
   
         s = splsoftnet();          s = splsoftnet();
         if (nam) {          if (nam) {
                 if ((so->so_state & SS_ISCONNECTED) != 0) {                  if ((so->so_state & SS_ISCONNECTED) != 0) {
Line 779  rip_send(struct socket *so, struct mbuf 
Line 765  rip_send(struct socket *so, struct mbuf 
                         goto die;                          goto die;
                 }                  }
                 error = rip_connect_pcb(inp, (struct sockaddr_in *)nam);                  error = rip_connect_pcb(inp, (struct sockaddr_in *)nam);
                 if (error)                  if (error) {
                         goto die;                  die:
                           m_freem(m);
                           splx(s);
                           return error;
                   }
         } else {          } else {
                 if ((so->so_state & SS_ISCONNECTED) == 0) {                  if ((so->so_state & SS_ISCONNECTED) == 0) {
                         error = ENOTCONN;                          error = ENOTCONN;
                         goto die;                          goto die;
                 }                  }
         }          }
         error = rip_output(m, inp, control, l);          error = rip_output(m, inp);
         m = NULL;  
         control = NULL;  
         if (nam)          if (nam)
                 rip_disconnect1(inp);                  rip_disconnect1(inp);
  die:  
         if (m != NULL)  
                 m_freem(m);  
         if (control != NULL)  
                 m_freem(control);  
   
         splx(s);          splx(s);
         return error;          return error;
Line 821  rip_purgeif(struct socket *so, struct if
Line 804  rip_purgeif(struct socket *so, struct if
         s = splsoftnet();          s = splsoftnet();
         mutex_enter(softnet_lock);          mutex_enter(softnet_lock);
         in_pcbpurgeif0(&rawcbtable, ifp);          in_pcbpurgeif0(&rawcbtable, ifp);
 #ifdef NET_MPSAFE  
         mutex_exit(softnet_lock);  
 #endif  
         in_purgeif(ifp);          in_purgeif(ifp);
 #ifdef NET_MPSAFE  
         mutex_enter(softnet_lock);  
 #endif  
         in_pcbpurgeif(&rawcbtable, ifp);          in_pcbpurgeif(&rawcbtable, ifp);
         mutex_exit(softnet_lock);          mutex_exit(softnet_lock);
         splx(s);          splx(s);

Legend:
Removed from v.1.114.2.4  
changed lines
  Added in v.1.157

CVSweb <webmaster@jp.NetBSD.org>