Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Remove unnecessary NULL checks for inp_socket and in6p_s...
details: https://anonhg.NetBSD.org/src/rev/415bc047d032
branches: trunk
changeset: 353099:415bc047d032
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Thu Apr 20 08:46:07 2017 +0000
description:
Remove unnecessary NULL checks for inp_socket and in6p_socket
They cannot be NULL except for programming errors.
diffstat:
sys/netinet/raw_ip.c | 8 ++++----
sys/netinet/sctp_input.c | 6 +++---
sys/netinet/tcp_input.c | 12 +++++++-----
sys/netinet/udp_usrreq.c | 9 ++++-----
sys/netinet6/sctp6_usrreq.c | 6 +++---
sys/netinet6/udp6_usrreq.c | 6 +++---
sys/netipsec/ipsec.c | 20 ++++++++++----------
sys/netipsec/ipsec.h | 7 +------
sys/netipsec/ipsec6.h | 7 +------
9 files changed, 36 insertions(+), 45 deletions(-)
diffs (296 lines):
diff -r 4c4bf9e9939c -r 415bc047d032 sys/netinet/raw_ip.c
--- a/sys/netinet/raw_ip.c Thu Apr 20 08:45:25 2017 +0000
+++ b/sys/netinet/raw_ip.c Thu Apr 20 08:46:07 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: raw_ip.c,v 1.163 2017/03/03 07:13:06 ozaki-r Exp $ */
+/* $NetBSD: raw_ip.c,v 1.164 2017/04/20 08:46:07 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.163 2017/03/03 07:13:06 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.164 2017/04/20 08:46:07 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -213,7 +213,7 @@
#if defined(IPSEC)
/* check AH/ESP integrity. */
else if (ipsec_used &&
- ipsec4_in_reject_so(m, last->inp_socket)) {
+ ipsec4_in_reject(m, last)) {
IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);
/* do not inject data to pcb */
}
@@ -228,7 +228,7 @@
#if defined(IPSEC)
/* check AH/ESP integrity. */
if (ipsec_used && last != NULL
- && ipsec4_in_reject_so(m, last->inp_socket)) {
+ && ipsec4_in_reject(m, last)) {
m_freem(m);
IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);
IP_STATDEC(IP_STAT_DELIVERED);
diff -r 4c4bf9e9939c -r 415bc047d032 sys/netinet/sctp_input.c
--- a/sys/netinet/sctp_input.c Thu Apr 20 08:45:25 2017 +0000
+++ b/sys/netinet/sctp_input.c Thu Apr 20 08:46:07 2017 +0000
@@ -1,5 +1,5 @@
/* $KAME: sctp_input.c,v 1.28 2005/04/21 18:36:21 nishida Exp $ */
-/* $NetBSD: sctp_input.c,v 1.3 2016/06/10 13:31:44 ozaki-r Exp $ */
+/* $NetBSD: sctp_input.c,v 1.4 2017/04/20 08:46:07 ozaki-r Exp $ */
/*
* Copyright (C) 2002, 2003, 2004 Cisco Systems Inc,
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sctp_input.c,v 1.3 2016/06/10 13:31:44 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_input.c,v 1.4 2017/04/20 08:46:07 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_ipsec.h"
@@ -4237,7 +4237,7 @@
* I very much doubt any of the IPSEC stuff will work but I have
* no idea, so I will leave it in place.
*/
- if (ipsec_used && ipsec4_in_reject_so(m, inp->ip_inp.inp.inp_socket)) {
+ if (ipsec_used && ipsec4_in_reject(m, inp)) {
#if 0
ipsecstat.in_polvio++;
#endif
diff -r 4c4bf9e9939c -r 415bc047d032 sys/netinet/tcp_input.c
--- a/sys/netinet/tcp_input.c Thu Apr 20 08:45:25 2017 +0000
+++ b/sys/netinet/tcp_input.c Thu Apr 20 08:46:07 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tcp_input.c,v 1.356 2017/03/31 06:49:44 ozaki-r Exp $ */
+/* $NetBSD: tcp_input.c,v 1.357 2017/04/20 08:46:07 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.356 2017/03/31 06:49:44 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.357 2017/04/20 08:46:07 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -1484,7 +1484,7 @@
#ifdef INET6
else if (in6p &&
(in6p->in6p_socket->so_options & SO_ACCEPTCONN) == 0
- && ipsec6_in_reject_so(m, in6p->in6p_socket)) {
+ && ipsec6_in_reject(m, in6p)) {
IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);
goto drop;
}
@@ -1835,7 +1835,8 @@
switch (af) {
#ifdef INET
case AF_INET:
- if (!ipsec4_in_reject_so(m, so))
+ KASSERT(sotoinpcb(so) == inp);
+ if (!ipsec4_in_reject(m, inp))
break;
IPSEC_STATINC(
IPSEC_STAT_IN_POLVIO);
@@ -1844,7 +1845,8 @@
#endif
#ifdef INET6
case AF_INET6:
- if (!ipsec6_in_reject_so(m, so))
+ KASSERT(sotoin6pcb(so) == in6p);
+ if (!ipsec6_in_reject(m, in6p))
break;
IPSEC6_STATINC(
IPSEC_STAT_IN_POLVIO);
diff -r 4c4bf9e9939c -r 415bc047d032 sys/netinet/udp_usrreq.c
--- a/sys/netinet/udp_usrreq.c Thu Apr 20 08:45:25 2017 +0000
+++ b/sys/netinet/udp_usrreq.c Thu Apr 20 08:46:07 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: udp_usrreq.c,v 1.232 2017/04/20 08:45:09 ozaki-r Exp $ */
+/* $NetBSD: udp_usrreq.c,v 1.233 2017/04/20 08:46:07 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.232 2017/04/20 08:45:09 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.233 2017/04/20 08:46:07 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -470,15 +470,14 @@
struct mbuf *n;
struct inpcb *inp;
- if (!so)
- return;
+ KASSERT(so != NULL);
KASSERT(so->so_proto->pr_domain->dom_family == AF_INET);
inp = sotoinpcb(so);
KASSERT(inp != NULL);
#if defined(IPSEC)
/* check AH/ESP integrity. */
- if (ipsec_used && so != NULL && ipsec4_in_reject_so(m, so)) {
+ if (ipsec_used && ipsec4_in_reject(m, inp)) {
IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);
if ((n = m_copypacket(m, M_DONTWAIT)) != NULL)
icmp_error(n, ICMP_UNREACH, ICMP_UNREACH_ADMIN_PROHIBIT,
diff -r 4c4bf9e9939c -r 415bc047d032 sys/netinet6/sctp6_usrreq.c
--- a/sys/netinet6/sctp6_usrreq.c Thu Apr 20 08:45:25 2017 +0000
+++ b/sys/netinet6/sctp6_usrreq.c Thu Apr 20 08:46:07 2017 +0000
@@ -1,5 +1,5 @@
/* $KAME: sctp6_usrreq.c,v 1.38 2005/08/24 08:08:56 suz Exp $ */
-/* $NetBSD: sctp6_usrreq.c,v 1.11 2016/12/13 08:29:03 ozaki-r Exp $ */
+/* $NetBSD: sctp6_usrreq.c,v 1.12 2017/04/20 08:46:07 ozaki-r Exp $ */
/*
* Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
@@ -33,7 +33,7 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sctp6_usrreq.c,v 1.11 2016/12/13 08:29:03 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp6_usrreq.c,v 1.12 2017/04/20 08:46:07 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -235,7 +235,7 @@
/*
* Check AH/ESP integrity.
*/
- if (ipsec_used && ipsec6_in_reject_so(m, in6p->sctp_socket)) {
+ if (ipsec_used && ipsec6_in_reject(m, in6p)) {
/* XXX */
#if 0
/* FIX ME: need to find right stat */
diff -r 4c4bf9e9939c -r 415bc047d032 sys/netinet6/udp6_usrreq.c
--- a/sys/netinet6/udp6_usrreq.c Thu Apr 20 08:45:25 2017 +0000
+++ b/sys/netinet6/udp6_usrreq.c Thu Apr 20 08:46:07 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: udp6_usrreq.c,v 1.128 2017/04/20 08:45:09 ozaki-r Exp $ */
+/* $NetBSD: udp6_usrreq.c,v 1.129 2017/04/20 08:46:07 ozaki-r Exp $ */
/* $KAME: udp6_usrreq.c,v 1.86 2001/05/27 17:33:00 itojun Exp $ */
/*
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.128 2017/04/20 08:45:09 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.129 2017/04/20 08:46:07 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -352,7 +352,7 @@
#if defined(IPSEC)
/* check AH/ESP integrity. */
- if (ipsec_used && ipsec6_in_reject_so(m, so)) {
+ if (ipsec_used && ipsec6_in_reject(m, in6p)) {
IPSEC6_STATINC(IPSEC_STAT_IN_POLVIO);
if ((n = m_copypacket(m, M_DONTWAIT)) != NULL)
icmp6_error(n, ICMP6_DST_UNREACH,
diff -r 4c4bf9e9939c -r 415bc047d032 sys/netipsec/ipsec.c
--- a/sys/netipsec/ipsec.c Thu Apr 20 08:45:25 2017 +0000
+++ b/sys/netipsec/ipsec.c Thu Apr 20 08:46:07 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ipsec.c,v 1.81 2017/04/20 03:41:47 ozaki-r Exp $ */
+/* $NetBSD: ipsec.c,v 1.82 2017/04/20 08:46:07 ozaki-r Exp $ */
/* $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/netipsec/ipsec.c,v 1.2.2.2 2003/07/01 01:38:13 sam Exp $ */
/* $KAME: ipsec.c,v 1.103 2001/05/24 07:14:18 sakane Exp $ */
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.81 2017/04/20 03:41:47 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.82 2017/04/20 08:46:07 ozaki-r Exp $");
/*
* IPsec controller part.
@@ -608,12 +608,12 @@
*error = 0;
-
- /* XXX KAME IPv6 calls us with non-null inp but bogus inp_socket? */
- if (inp == NULL || inp->inp_socket == NULL) {
+ if (inp == NULL) {
sp = ipsec_getpolicybyaddr(m, dir, flag, error);
- } else
+ } else {
+ KASSERT(inp->inp_socket != NULL);
sp = ipsec_getpolicybysock(m, dir, (struct inpcb_hdr *)inp, error);
+ }
if (sp == NULL) {
KASSERTMSG(*error != 0, "getpolicy failed w/o error");
IPSEC_STATINC(IPSEC_STAT_OUT_INVAL);
@@ -853,12 +853,12 @@
*error = 0;
-
- /* XXX KAME IPv6 calls us with non-null inp but bogus inp_socket? */
- if (in6p == NULL || in6p->in6p_socket == NULL) {
+ if (in6p == NULL) {
sp = ipsec_getpolicybyaddr(m, dir, flag, error);
- } else
+ } else {
+ KASSERT(in6p->in6p_socket != NULL);
sp = ipsec_getpolicybysock(m, dir, (struct inpcb_hdr *)in6p, error);
+ }
if (sp == NULL) {
KASSERTMSG(*error != 0, "getpolicy failed w/o error");
IPSEC_STATINC(IPSEC_STAT_OUT_INVAL);
diff -r 4c4bf9e9939c -r 415bc047d032 sys/netipsec/ipsec.h
--- a/sys/netipsec/ipsec.h Thu Apr 20 08:45:25 2017 +0000
+++ b/sys/netipsec/ipsec.h Thu Apr 20 08:46:07 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ipsec.h,v 1.42 2017/04/20 03:41:47 ozaki-r Exp $ */
+/* $NetBSD: ipsec.h,v 1.43 2017/04/20 08:46:07 ozaki-r Exp $ */
/* $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/netipsec/ipsec.h,v 1.2.4.2 2004/02/14 22:23:23 bms Exp $ */
/* $KAME: ipsec.h,v 1.53 2001/11/20 08:32:38 itojun Exp $ */
@@ -294,11 +294,6 @@
int ipsec4_get_policy (struct inpcb *, const void *, size_t, struct mbuf **);
int ipsec4_delete_pcbpolicy (struct inpcb *);
int ipsec4_in_reject (struct mbuf *, struct inpcb *);
-/*
- * KAME ipsec4_in_reject_so(struct mbuf*, struct so) compatibility shim
- */
-#define ipsec4_in_reject_so(m, _so) \
- ipsec4_in_reject(m, ((_so) == NULL? NULL : sotoinpcb(_so)))
struct secas;
diff -r 4c4bf9e9939c -r 415bc047d032 sys/netipsec/ipsec6.h
--- a/sys/netipsec/ipsec6.h Thu Apr 20 08:45:25 2017 +0000
+++ b/sys/netipsec/ipsec6.h Thu Apr 20 08:46:07 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ipsec6.h,v 1.16 2017/04/18 05:25:32 ozaki-r Exp $ */
+/* $NetBSD: ipsec6.h,v 1.17 2017/04/20 08:46:07 ozaki-r Exp $ */
/* $FreeBSD: src/sys/netipsec/ipsec6.h,v 1.1.4.1 2003/01/24 05:11:35 sam Exp $ */
/* $KAME: ipsec.h,v 1.44 2001/03/23 08:08:47 itojun Exp $ */
@@ -67,11 +67,6 @@
struct secpolicy * ipsec6_check_policy(struct mbuf *,
struct in6pcb *, int, int*,int*);
int ipsec6_in_reject (struct mbuf *, struct in6pcb *);
-/*
- * KAME ipsec6_in_reject_so(struct mbuf*, struct so) compatibility shim
- */
-#define ipsec6_in_reject_so(m, _so) \
- ipsec6_in_reject(m, ((_so) == NULL? NULL : sotoin6pcb(_so)))
struct tcp6cb;
Home |
Main Index |
Thread Index |
Old Index