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

version 1.88.10.2, 2006/03/10 15:20:54 version 1.97, 2007/05/12 02:10:25
Line 77  __KERNEL_RCSID(0, "$NetBSD$");
Line 77  __KERNEL_RCSID(0, "$NetBSD$");
 #include <sys/errno.h>  #include <sys/errno.h>
 #include <sys/systm.h>  #include <sys/systm.h>
 #include <sys/proc.h>  #include <sys/proc.h>
   #include <sys/kauth.h>
   
 #include <net/if.h>  #include <net/if.h>
 #include <net/route.h>  #include <net/route.h>
Line 142  rip_input(struct mbuf *m, ...)
Line 143  rip_input(struct mbuf *m, ...)
         struct ip *ip = mtod(m, struct ip *);          struct ip *ip = mtod(m, struct ip *);
         struct inpcb_hdr *inph;          struct inpcb_hdr *inph;
         struct inpcb *inp;          struct inpcb *inp;
         struct inpcb *last = 0;          struct inpcb *last = NULL;
         struct mbuf *opts = 0;          struct mbuf *n, *opts = NULL;
         struct sockaddr_in ripsrc;          struct sockaddr_in ripsrc;
         va_list ap;          va_list ap;
   
Line 152  rip_input(struct mbuf *m, ...)
Line 153  rip_input(struct mbuf *m, ...)
         proto = va_arg(ap, int);          proto = va_arg(ap, int);
         va_end(ap);          va_end(ap);
   
         ripsrc.sin_family = AF_INET;          sockaddr_in_init(&ripsrc, &ip->ip_src, 0);
         ripsrc.sin_len = sizeof(struct sockaddr_in);  
         ripsrc.sin_addr = ip->ip_src;  
         ripsrc.sin_port = 0;  
         bzero((caddr_t)ripsrc.sin_zero, sizeof(ripsrc.sin_zero));  
   
         /*          /*
          * XXX Compatibility: programs using raw IP expect ip_len           * XXX Compatibility: programs using raw IP expect ip_len
Line 178  rip_input(struct mbuf *m, ...)
Line 175  rip_input(struct mbuf *m, ...)
                 if (!in_nullhost(inp->inp_faddr) &&                  if (!in_nullhost(inp->inp_faddr) &&
                     !in_hosteq(inp->inp_faddr, ip->ip_src))                      !in_hosteq(inp->inp_faddr, ip->ip_src))
                         continue;                          continue;
                 if (last) {                  if (last == NULL)
                         struct mbuf *n;                          ;
   
 #if defined(IPSEC) || defined(FAST_IPSEC)  #if defined(IPSEC) || defined(FAST_IPSEC)
                         /* check AH/ESP integrity. */                  /* check AH/ESP integrity. */
                         if (ipsec4_in_reject_so(m, last->inp_socket)) {                  else if (ipsec4_in_reject_so(m, last->inp_socket)) {
                                 ipsecstat.in_polvio++;                          ipsecstat.in_polvio++;
                                 /* do not inject data to pcb */                          /* do not inject data to pcb */
                         } else                  }
 #endif /*IPSEC*/  #endif /*IPSEC*/
                         if ((n = m_copy(m, 0, (int)M_COPYALL)) != NULL) {                  else if ((n = m_copy(m, 0, M_COPYALL)) != NULL) {
                                 if (last->inp_flags & INP_CONTROLOPTS ||                          if (last->inp_flags & INP_CONTROLOPTS ||
                                     last->inp_socket->so_options & SO_TIMESTAMP)                              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,                          if (sbappendaddr(&last->inp_socket->so_rcv,
                                     sintosa(&ripsrc), n, opts) == 0) {                              sintosa(&ripsrc), n, opts) == 0) {
                                         /* should notify about lost packet */                                  /* should notify about lost packet */
                                         m_freem(n);                                  m_freem(n);
                                         if (opts)                                  if (opts)
                                                 m_freem(opts);                                          m_freem(opts);
                                 } else                          } else
                                         sorwakeup(last->inp_socket);                                  sorwakeup(last->inp_socket);
                                 opts = NULL;                          opts = NULL;
                         }  
                 }                  }
                 last = inp;                  last = inp;
         }          }
 #if defined(IPSEC) || defined(FAST_IPSEC)  #if defined(IPSEC) || defined(FAST_IPSEC)
         /* check AH/ESP integrity. */          /* check AH/ESP integrity. */
         if (last && ipsec4_in_reject_so(m, last->inp_socket)) {          if (last != NULL && ipsec4_in_reject_so(m, last->inp_socket)) {
                 m_freem(m);                  m_freem(m);
                 ipsecstat.in_polvio++;                  ipsecstat.in_polvio++;
                 ipstat.ips_delivered--;                  ipstat.ips_delivered--;
                 /* do not inject data to pcb */                  /* do not inject data to pcb */
         } else          } else
 #endif /*IPSEC*/  #endif /*IPSEC*/
         if (last) {          if (last != NULL) {
                 if (last->inp_flags & INP_CONTROLOPTS ||                  if (last->inp_flags & INP_CONTROLOPTS ||
                     last->inp_socket->so_options & SO_TIMESTAMP)                      last->inp_socket->so_options & SO_TIMESTAMP)
                         ip_savecontrol(last, &opts, ip, m);                          ip_savecontrol(last, &opts, ip, m);
Line 225  rip_input(struct mbuf *m, ...)
Line 220  rip_input(struct mbuf *m, ...)
                                 m_freem(opts);                                  m_freem(opts);
                 } else                  } else
                         sorwakeup(last->inp_socket);                          sorwakeup(last->inp_socket);
         } else {          } else if (inetsw[ip_protox[ip->ip_p]].pr_input == rip_input) {
                 if (inetsw[ip_protox[ip->ip_p]].pr_input == rip_input) {                  icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PROTOCOL,
                         icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PROTOCOL,                      0, 0);
                             0, 0);                  ipstat.ips_noproto++;
                         ipstat.ips_noproto++;                  ipstat.ips_delivered--;
                         ipstat.ips_delivered--;          } else
                 } else                  m_freem(m);
                         m_freem(m);  
         }  
         return;          return;
 }  }
   
Line 265  rip_pcbnotify(struct inpcbtable *table,
Line 258  rip_pcbnotify(struct inpcbtable *table,
 }  }
   
 void *  void *
 rip_ctlinput(int cmd, struct sockaddr *sa, void *v)  rip_ctlinput(int cmd, const struct sockaddr *sa, void *v)
 {  {
         struct ip *ip = v;          struct ip *ip = v;
         void (*notify)(struct inpcb *, int) = in_rtchange;          void (*notify)(struct inpcb *, int) = in_rtchange;
Line 284  rip_ctlinput(int cmd, struct sockaddr *s
Line 277  rip_ctlinput(int cmd, struct sockaddr *s
         else if (errno == 0)          else if (errno == 0)
                 return NULL;                  return NULL;
         if (ip) {          if (ip) {
                 rip_pcbnotify(&rawcbtable, satosin(sa)->sin_addr,                  rip_pcbnotify(&rawcbtable, satocsin(sa)->sin_addr,
                     ip->ip_src, ip->ip_p, errno, notify);                      ip->ip_src, ip->ip_p, errno, notify);
   
                 /* XXX mapped address case */                  /* XXX mapped address case */
         } else          } else
                 in_pcbnotifyall(&rawcbtable, satosin(sa)->sin_addr, errno,                  in_pcbnotifyall(&rawcbtable, satocsin(sa)->sin_addr, errno,
                     notify);                      notify);
         return NULL;          return NULL;
 }  }
Line 505  rip_usrreq(struct socket *so, int req,
Line 498  rip_usrreq(struct socket *so, int req,
     struct mbuf *m, struct mbuf *nam, struct mbuf *control, struct lwp *l)      struct mbuf *m, struct mbuf *nam, struct mbuf *control, struct lwp *l)
 {  {
         struct inpcb *inp;          struct inpcb *inp;
         struct proc *p;  
         int s;          int s;
         int error = 0;          int error = 0;
 #ifdef MROUTING  #ifdef MROUTING
         extern struct socket *ip_mrouter;          extern struct socket *ip_mrouter;
 #endif  #endif
   
         p = l ? l->l_proc : NULL;  
         if (req == PRU_CONTROL)          if (req == PRU_CONTROL)
                 return (in_control(so, (long)m, (caddr_t)nam,                  return (in_control(so, (long)m, (void *)nam,
                     (struct ifnet *)control, p));                      (struct ifnet *)control, l));
   
           s = splsoftnet();
   
         if (req == PRU_PURGEIF) {          if (req == PRU_PURGEIF) {
                 in_pcbpurgeif0(&rawcbtable, (struct ifnet *)control);                  in_pcbpurgeif0(&rawcbtable, (struct ifnet *)control);
                 in_purgeif((struct ifnet *)control);                  in_purgeif((struct ifnet *)control);
                 in_pcbpurgeif(&rawcbtable, (struct ifnet *)control);                  in_pcbpurgeif(&rawcbtable, (struct ifnet *)control);
                   splx(s);
                 return (0);                  return (0);
         }          }
   
         s = splsoftnet();  
         inp = sotoinpcb(so);          inp = sotoinpcb(so);
 #ifdef DIAGNOSTIC  #ifdef DIAGNOSTIC
         if (req != PRU_SEND && req != PRU_SENDOOB && control)          if (req != PRU_SEND && req != PRU_SENDOOB && control)
Line 542  rip_usrreq(struct socket *so, int req,
Line 535  rip_usrreq(struct socket *so, int req,
                         error = EISCONN;                          error = EISCONN;
                         break;                          break;
                 }                  }
                 if (p == 0 || (error = kauth_authorize_generic(p->p_cred,  
                                                 KAUTH_GENERIC_ISSUSER, &p->p_acflag))) {                  if (l == NULL) {
                         error = EACCES;                          error = EACCES;
                         break;                          break;
                 }                  }
   
                   /* XXX: raw socket permissions are checked in socreate() */
   
                 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {                  if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
                         error = soreserve(so, rip_sendspace, rip_recvspace);                          error = soreserve(so, rip_sendspace, rip_recvspace);
                         if (error)                          if (error)

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

CVSweb <webmaster@jp.NetBSD.org>