Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/netinet/raw_ip.c,v retrieving revision 1.103.6.2 retrieving revision 1.104 diff -u -p -r1.103.6.2 -r1.104 --- src/sys/netinet/raw_ip.c 2008/09/28 10:40:58 1.103.6.2 +++ src/sys/netinet/raw_ip.c 2008/04/07 06:31:28 1.104 @@ -1,4 +1,4 @@ -/* $NetBSD: raw_ip.c,v 1.103.6.2 2008/09/28 10:40:58 mjf Exp $ */ +/* $NetBSD: raw_ip.c,v 1.104 2008/04/07 06:31:28 thorpej Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.103.6.2 2008/09/28 10:40:58 mjf Exp $"); +__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.104 2008/04/07 06:31:28 thorpej Exp $"); #include "opt_inet.h" #include "opt_ipsec.h" @@ -86,7 +86,6 @@ __KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1 #include #include #include -#include #include #include #include @@ -97,14 +96,12 @@ __KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1 #ifdef IPSEC #include -#include -#endif /* IPSEC */ +#endif /*IPSEC*/ #ifdef FAST_IPSEC #include -#include -#include -#endif /* FAST_IPSEC */ +#include /* XXX ipsecstat namespace */ +#endif /* FAST_IPSEC*/ struct inpcbtable rawcbtable; @@ -202,7 +199,7 @@ rip_input(struct mbuf *m, ...) #if defined(IPSEC) || defined(FAST_IPSEC) /* check AH/ESP integrity. */ else if (ipsec4_in_reject_so(m, last->inp_socket)) { - IPSEC_STATINC(IPSEC_STAT_IN_POLVIO); + ipsecstat.in_polvio++; /* do not inject data to pcb */ } #endif /*IPSEC*/ @@ -217,22 +214,18 @@ rip_input(struct mbuf *m, ...) /* check AH/ESP integrity. */ if (last != NULL && ipsec4_in_reject_so(m, last->inp_socket)) { m_freem(m); - IPSEC_STATINC(IPSEC_STAT_IN_POLVIO); - IP_STATDEC(IP_STAT_DELIVERED); + ipsecstat.in_polvio++; + ipstat[IP_STAT_DELIVERED]--; /* do not inject data to pcb */ } else #endif /*IPSEC*/ if (last != NULL) rip_sbappendaddr(last, ip, sintosa(&ripsrc), hlen, opts, m); else if (inetsw[ip_protox[ip->ip_p]].pr_input == rip_input) { - uint64_t *ips; - icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PROTOCOL, 0, 0); - ips = IP_STAT_GETREF(); - ips[IP_STAT_NOPROTO]++; - ips[IP_STAT_DELIVERED]--; - IP_STAT_PUTREF(); + ipstat[IP_STAT_NOPROTO]++; + ipstat[IP_STAT_DELIVERED]--; } else m_freem(m); return; @@ -370,7 +363,7 @@ rip_output(struct mbuf *m, ...) opts = NULL; /* XXX prevent ip_output from overwriting header fields */ flags |= IP_RAWOUTPUT; - IP_STATINC(IP_STAT_RAWOUT); + ipstat[IP_STAT_RAWOUT]++; } return (ip_output(m, opts, &inp->inp_route, flags, inp->inp_moptions, inp->inp_socket, &inp->inp_errormtu)); @@ -380,43 +373,40 @@ rip_output(struct mbuf *m, ...) * Raw IP socket option processing. */ int -rip_ctloutput(int op, struct socket *so, struct sockopt *sopt) +rip_ctloutput(int op, struct socket *so, int level, int optname, + struct mbuf **m) { struct inpcb *inp = sotoinpcb(so); int error = 0; - int optval; - if (sopt->sopt_level == SOL_SOCKET && sopt->sopt_name == SO_NOHEADER) { + if (level == SOL_SOCKET && optname == SO_NOHEADER) { if (op == PRCO_GETOPT) { - optval = (inp->inp_flags & INP_NOHEADER) ? 1 : 0; - error = sockopt_set(sopt, &optval, sizeof(optval)); - } else if (op == PRCO_SETOPT) { - error = sockopt_getint(sopt, &optval); - if (error) - goto out; - if (optval) { - inp->inp_flags &= ~INP_HDRINCL; - inp->inp_flags |= INP_NOHEADER; - } else - inp->inp_flags &= ~INP_NOHEADER; - } - goto out; - } else if (sopt->sopt_level != IPPROTO_IP) - return ip_ctloutput(op, so, sopt); + *m = m_intopt(so, + (inp->inp_flags & INP_NOHEADER) ? 1 : 0); + return 0; + } else if (*m == NULL || (*m)->m_len != sizeof(int)) + error = EINVAL; + else if (*mtod(*m, int *)) { + inp->inp_flags &= ~INP_HDRINCL; + inp->inp_flags |= INP_NOHEADER; + } else + inp->inp_flags &= ~INP_NOHEADER; + goto free_m; + } else if (level != IPPROTO_IP) + return ip_ctloutput(op, so, level, optname, m); switch (op) { case PRCO_SETOPT: - switch (sopt->sopt_name) { + switch (optname) { case IP_HDRINCL: - error = sockopt_getint(sopt, &optval); - if (error) - break; - if (optval) + if (*m == NULL || (*m)->m_len != sizeof(int)) + error = EINVAL; + else if (*mtod(*m, int *)) inp->inp_flags |= INP_HDRINCL; else inp->inp_flags &= ~INP_HDRINCL; - break; + goto free_m; #ifdef MROUTING case MRT_INIT: @@ -429,21 +419,20 @@ rip_ctloutput(int op, struct socket *so, case MRT_API_CONFIG: case MRT_ADD_BW_UPCALL: case MRT_DEL_BW_UPCALL: - error = ip_mrouter_set(so, sopt); + error = ip_mrouter_set(so, optname, m); break; #endif default: - error = ip_ctloutput(op, so, sopt); + error = ip_ctloutput(op, so, level, optname, m); break; } break; case PRCO_GETOPT: - switch (sopt->sopt_name) { + switch (optname) { case IP_HDRINCL: - optval = inp->inp_flags & INP_HDRINCL; - error = sockopt_set(sopt, &optval, sizeof(optval)); + *m = m_intopt(so, inp->inp_flags & INP_HDRINCL ? 1 : 0); break; #ifdef MROUTING @@ -451,17 +440,20 @@ rip_ctloutput(int op, struct socket *so, case MRT_ASSERT: case MRT_API_SUPPORT: case MRT_API_CONFIG: - error = ip_mrouter_get(so, sopt); + error = ip_mrouter_get(so, optname, m); break; #endif default: - error = ip_ctloutput(op, so, sopt); + error = ip_ctloutput(op, so, level, optname, m); break; } break; } - out: + return error; +free_m: + if (op == PRCO_SETOPT && *m != NULL) + (void)m_free(*m); return error; } @@ -529,11 +521,9 @@ rip_usrreq(struct socket *so, int req, s = splsoftnet(); if (req == PRU_PURGEIF) { - mutex_enter(softnet_lock); in_pcbpurgeif0(&rawcbtable, (struct ifnet *)control); in_purgeif((struct ifnet *)control); in_pcbpurgeif(&rawcbtable, (struct ifnet *)control); - mutex_exit(softnet_lock); splx(s); return (0); } @@ -551,7 +541,6 @@ rip_usrreq(struct socket *so, int req, switch (req) { case PRU_ATTACH: - sosetlock(so); if (inp != 0) { error = EISCONN; break;