[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.147 and 1.170

version 1.147, 2015/04/03 20:01:07 version 1.170, 2018/02/28 11:10:22
Line 67 
Line 67 
 #include <sys/cdefs.h>  #include <sys/cdefs.h>
 __KERNEL_RCSID(0, "$NetBSD$");  __KERNEL_RCSID(0, "$NetBSD$");
   
   #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
   
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/sysctl.h>  #include <sys/sysctl.h>
Line 84  __KERNEL_RCSID(0, "$NetBSD$");
Line 86  __KERNEL_RCSID(0, "$NetBSD$");
 #include <sys/kauth.h>  #include <sys/kauth.h>
   
 #include <net/if.h>  #include <net/if.h>
 #include <net/route.h>  
   
 #include <netinet/in.h>  #include <netinet/in.h>
 #include <netinet/in_systm.h>  #include <netinet/in_systm.h>
Line 103  __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,
     struct in_addr, int, int, void (*)(struct inpcb *, int));      struct in_addr, int, int, void (*)(struct inpcb *, int));
 int      rip_connect_pcb(struct inpcb *, struct mbuf *);  static int       rip_connect_pcb(struct inpcb *, struct sockaddr_in *);
 static void      rip_disconnect1(struct inpcb *);  static void      rip_disconnect1(struct inpcb *);
   
 static void sysctl_net_inet_raw_setup(struct sysctllog **);  static void sysctl_net_inet_raw_setup(struct sysctllog **);
Line 147  rip_sbappendaddr(struct inpcb *last, str
Line 144  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
 #ifdef SO_OTIMESTAMP              || SOOPT_TIMESTAMP(last->inp_socket->so_options))
             || 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 210  rip_input(struct mbuf *m, ...)
Line 204  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 && ipsec_in_reject(m, last)) {
                     ipsec4_in_reject_so(m, last->inp_socket)) {  
                         IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);  
                         /* do not inject data to pcb */                          /* do not inject data to pcb */
                 }                  }
 #endif /*IPSEC*/  #endif /*IPSEC*/
Line 225  rip_input(struct mbuf *m, ...)
Line 217  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 && ipsec_in_reject(m, last)) {
             && ipsec4_in_reject_so(m, last->inp_socket)) {  
                 m_freem(m);                  m_freem(m);
                 IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);  
                 IP_STATDEC(IP_STAT_DELIVERED);                  IP_STATDEC(IP_STAT_DELIVERED);
                 /* do not inject data to pcb */                  /* do not inject data to pcb */
         } else          } else
Line 309  rip_ctlinput(int cmd, const struct socka
Line 299  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, ...)  rip_output(struct mbuf *m, struct inpcb *inp, struct mbuf *control,
       struct lwp *l)
 {  {
         struct inpcb *inp;  
         struct ip *ip;          struct ip *ip;
         struct mbuf *opts;          struct mbuf *opts;
         int flags;          struct ip_pktopts pktopts;
         va_list ap;          kauth_cred_t cred;
           int error, flags;
         va_start(ap, m);  
         inp = va_arg(ap, struct inpcb *);          flags = (inp->inp_socket->so_options & SO_DONTROUTE) |
         va_end(ap);              IP_ALLOWBROADCAST | IP_RETURNMTU;
   
         flags =          if (l == NULL)
             (inp->inp_socket->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST                  cred = NULL;
             | IP_RETURNMTU;          else
                   cred = l->l_cred;
   
           /* Setup IP outgoing packet options */
           memset(&pktopts, 0, sizeof(pktopts));
           error = ip_setpktopts(control, &pktopts, &flags, inp, cred);
           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 331  rip_output(struct mbuf *m, ...)
Line 330  rip_output(struct mbuf *m, ...)
          */           */
         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) {
                         m_freem(m);                          error = EMSGSIZE;
                         return (EMSGSIZE);                          goto release;
                 }                  }
                 M_PREPEND(m, sizeof(struct ip), M_DONTWAIT);                  M_PREPEND(m, sizeof(struct ip), M_DONTWAIT);
                 if (!m)                  if (!m) {
                         return (ENOBUFS);                          error = 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 = inp->inp_laddr;                  ip->ip_src = pktopts.ippo_laddr.sin_addr;
                 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) {
                         m_freem(m);                          error = EMSGSIZE;
                         return (EMSGSIZE);                          goto release;
                 }                  }
                 ip = mtod(m, struct ip *);                  ip = mtod(m, struct ip *);
   
Line 362  rip_output(struct mbuf *m, ...)
Line 363  rip_output(struct mbuf *m, ...)
                         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) {
                                 return (ENOMEM);        /* XXX */                                  error = 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) {
                         m_freem(m);                          error = EINVAL;
                         return (EINVAL);                          goto release;
                 }                  }
                 HTONS(ip->ip_len);                  HTONS(ip->ip_len);
                 HTONS(ip->ip_off);                  HTONS(ip->ip_off);
Line 386  rip_output(struct mbuf *m, ...)
Line 389  rip_output(struct mbuf *m, ...)
          * 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, inp->inp_moptions,          return ip_output(m, opts, &inp->inp_route, flags, pktopts.ippo_imo,
              inp->inp_socket);              inp);
   
    release:
           if (m != NULL)
                   m_freem(m);
           return error;
 }  }
   
 /*  /*
Line 480  rip_ctloutput(int op, struct socket *so,
Line 488  rip_ctloutput(int op, struct socket *so,
 }  }
   
 int  int
 rip_connect_pcb(struct inpcb *inp, struct mbuf *nam)  rip_connect_pcb(struct inpcb *inp, struct sockaddr_in *addr)
 {  {
         struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *);  
   
         if (nam->m_len != sizeof(*addr))          if (IFNET_READER_EMPTY())
                 return (EINVAL);  
         if (IFNET_EMPTY())  
                 return (EADDRNOTAVAIL);                  return (EADDRNOTAVAIL);
         if (addr->sin_family != AF_INET)          if (addr->sin_family != AF_INET)
                 return (EAFNOSUPPORT);                  return (EAFNOSUPPORT);
Line 547  rip_detach(struct socket *so)
Line 552  rip_detach(struct socket *so)
 }  }
   
 static int  static int
 rip_accept(struct socket *so, struct mbuf *nam)  rip_accept(struct socket *so, struct sockaddr *nam)
 {  {
         KASSERT(solocked(so));          KASSERT(solocked(so));
   
Line 562  rip_bind(struct socket *so, struct socka
Line 567  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;          int s, ss;
           struct ifaddr *ifa;
   
         KASSERT(solocked(so));          KASSERT(solocked(so));
         KASSERT(inp != NULL);          KASSERT(inp != NULL);
Line 572  rip_bind(struct socket *so, struct socka
Line 578  rip_bind(struct socket *so, struct socka
                 return EINVAL;                  return EINVAL;
   
         s = splsoftnet();          s = splsoftnet();
         if (IFNET_EMPTY()) {          if (IFNET_READER_EMPTY()) {
                 error = EADDRNOTAVAIL;                  error = EADDRNOTAVAIL;
                 goto release;                  goto release;
         }          }
Line 580  rip_bind(struct socket *so, struct socka
Line 586  rip_bind(struct socket *so, struct socka
                 error = EAFNOSUPPORT;                  error = EAFNOSUPPORT;
                 goto release;                  goto release;
         }          }
         if (!in_nullhost(addr->sin_addr) &&          ss = pserialize_read_enter();
             ifa_ifwithaddr(sintosa(addr)) == 0) {          if ((ifa = ifa_ifwithaddr(sintosa(addr))) == NULL &&
               !in_nullhost(addr->sin_addr))
           {
                   pserialize_read_exit(ss);
                   error = EADDRNOTAVAIL;
                   goto release;
           }
           if (ifa && (ifatoia(ifa))->ia4_flags & IN6_IFF_DUPLICATED) {
                   pserialize_read_exit(ss);
                 error = EADDRNOTAVAIL;                  error = EADDRNOTAVAIL;
                 goto release;                  goto release;
         }          }
           pserialize_read_exit(ss);
   
         inp->inp_laddr = addr->sin_addr;          inp->inp_laddr = addr->sin_addr;
   
 release:  release:
Line 601  rip_listen(struct socket *so, struct lwp
Line 617  rip_listen(struct socket *so, struct lwp
 }  }
   
 static int  static int
 rip_connect(struct socket *so, struct mbuf *nam, struct lwp *l)  rip_connect(struct socket *so, struct sockaddr *nam, struct lwp *l)
 {  {
         struct inpcb *inp = sotoinpcb(so);          struct inpcb *inp = sotoinpcb(so);
         int error = 0;          int error = 0;
Line 612  rip_connect(struct socket *so, struct mb
Line 628  rip_connect(struct socket *so, struct mb
         KASSERT(nam != NULL);          KASSERT(nam != NULL);
   
         s = splsoftnet();          s = splsoftnet();
         error = rip_connect_pcb(inp, nam);          error = rip_connect_pcb(inp, (struct sockaddr_in *)nam);
         if (! error)          if (! error)
                 soisconnected(so);                  soisconnected(so);
         splx(s);          splx(s);
Line 688  rip_stat(struct socket *so, struct stat 
Line 704  rip_stat(struct socket *so, struct stat 
 }  }
   
 static int  static int
 rip_peeraddr(struct socket *so, struct mbuf *nam)  rip_peeraddr(struct socket *so, struct sockaddr *nam)
 {  {
         int s;          int s;
   
Line 697  rip_peeraddr(struct socket *so, struct m
Line 713  rip_peeraddr(struct socket *so, struct m
         KASSERT(nam != NULL);          KASSERT(nam != NULL);
   
         s = splsoftnet();          s = splsoftnet();
         in_setpeeraddr(sotoinpcb(so), nam);          in_setpeeraddr(sotoinpcb(so), (struct sockaddr_in *)nam);
         splx(s);          splx(s);
   
         return 0;          return 0;
 }  }
   
 static int  static int
 rip_sockaddr(struct socket *so, struct mbuf *nam)  rip_sockaddr(struct socket *so, struct sockaddr *nam)
 {  {
         int s;          int s;
   
Line 713  rip_sockaddr(struct socket *so, struct m
Line 729  rip_sockaddr(struct socket *so, struct m
         KASSERT(nam != NULL);          KASSERT(nam != NULL);
   
         s = splsoftnet();          s = splsoftnet();
         in_setsockaddr(sotoinpcb(so), nam);          in_setsockaddr(sotoinpcb(so), (struct sockaddr_in *)nam);
         splx(s);          splx(s);
   
         return 0;          return 0;
Line 736  rip_recvoob(struct socket *so, struct mb
Line 752  rip_recvoob(struct socket *so, struct mb
 }  }
   
 static int  static int
 rip_send(struct socket *so, struct mbuf *m, struct mbuf *nam,  rip_send(struct socket *so, struct mbuf *m, struct sockaddr *nam,
     struct mbuf *control, struct lwp *l)      struct mbuf *control, struct lwp *l)
 {  {
         struct inpcb *inp = sotoinpcb(so);          struct inpcb *inp = sotoinpcb(so);
Line 751  rip_send(struct socket *so, struct mbuf 
Line 767  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) {
                         error = EISCONN;                          error = EISCONN;
                         goto die;                          goto die;
                 }                  }
                 error = rip_connect_pcb(inp, nam);                  error = rip_connect_pcb(inp, (struct sockaddr_in *)nam);
                 if (error) {                  if (error)
                 die:                          goto 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);          error = rip_output(m, inp, control, l);
           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 803  rip_purgeif(struct socket *so, struct if
Line 816  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);
Line 811  rip_purgeif(struct socket *so, struct if
Line 830  rip_purgeif(struct socket *so, struct if
         return 0;          return 0;
 }  }
   
 int  
 rip_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,  
     struct mbuf *control, struct lwp *l)  
 {  
         KASSERT(req != PRU_ATTACH);  
         KASSERT(req != PRU_DETACH);  
         KASSERT(req != PRU_ACCEPT);  
         KASSERT(req != PRU_BIND);  
         KASSERT(req != PRU_LISTEN);  
         KASSERT(req != PRU_CONNECT);  
         KASSERT(req != PRU_CONNECT2);  
         KASSERT(req != PRU_DISCONNECT);  
         KASSERT(req != PRU_SHUTDOWN);  
         KASSERT(req != PRU_ABORT);  
         KASSERT(req != PRU_CONTROL);  
         KASSERT(req != PRU_SENSE);  
         KASSERT(req != PRU_PEERADDR);  
         KASSERT(req != PRU_SOCKADDR);  
         KASSERT(req != PRU_RCVD);  
         KASSERT(req != PRU_RCVOOB);  
         KASSERT(req != PRU_SEND);  
         KASSERT(req != PRU_SENDOOB);  
         KASSERT(req != PRU_PURGEIF);  
   
         KASSERT(solocked(so));  
   
         if (sotoinpcb(so) == NULL)  
                 return EINVAL;  
   
         panic("rip_usrreq");  
   
         return 0;  
 }  
   
 PR_WRAP_USRREQS(rip)  PR_WRAP_USRREQS(rip)
 #define rip_attach      rip_attach_wrapper  #define rip_attach      rip_attach_wrapper
 #define rip_detach      rip_detach_wrapper  #define rip_detach      rip_detach_wrapper
Line 865  PR_WRAP_USRREQS(rip)
Line 850  PR_WRAP_USRREQS(rip)
 #define rip_send        rip_send_wrapper  #define rip_send        rip_send_wrapper
 #define rip_sendoob     rip_sendoob_wrapper  #define rip_sendoob     rip_sendoob_wrapper
 #define rip_purgeif     rip_purgeif_wrapper  #define rip_purgeif     rip_purgeif_wrapper
 #define rip_usrreq      rip_usrreq_wrapper  
   
 const struct pr_usrreqs rip_usrreqs = {  const struct pr_usrreqs rip_usrreqs = {
         .pr_attach      = rip_attach,          .pr_attach      = rip_attach,
Line 887  const struct pr_usrreqs rip_usrreqs = {
Line 871  const struct pr_usrreqs rip_usrreqs = {
         .pr_send        = rip_send,          .pr_send        = rip_send,
         .pr_sendoob     = rip_sendoob,          .pr_sendoob     = rip_sendoob,
         .pr_purgeif     = rip_purgeif,          .pr_purgeif     = rip_purgeif,
         .pr_generic     = rip_usrreq,  
 };  };
   
 static void  static void

Legend:
Removed from v.1.147  
changed lines
  Added in v.1.170

CVSweb <webmaster@jp.NetBSD.org>