Module Name:    src
Committed By:   ozaki-r
Date:           Fri Oct 28 05:25:36 UTC 2022

Modified Files:
        src/sys/netinet: in_pcb.c in_pcb.h ip_output.c portalgo.c raw_ip.c
            tcp_input.c tcp_output.c tcp_subr.c tcp_syncache.c tcp_timer.c
            tcp_usrreq.c tcp_vtw.c udp_usrreq.c
        src/sys/netinet6: icmp6.c in6_pcb.c in6_src.c ip6_output.c raw_ip6.c
            udp6_usrreq.c

Log Message:
inpcb: separate inpcb again to reduce the size of PCB for IPv4

The data size of PCB for IPv4 increased because of the merge of
struct in6pcb.  The change decreases the size to the original size by
separating struct inpcb (again).  struct in4pcb and in6pcb that embed
struct inpcb are introduced.

Even after the separation, users don't need to realize the separation
and only have to use some macros to access dedicated data.  For example,
inp->inp_laddr is now accessed through in4p_laddr(inp).


To generate a diff of this commit:
cvs rdiff -u -r1.192 -r1.193 src/sys/netinet/in_pcb.c
cvs rdiff -u -r1.72 -r1.73 src/sys/netinet/in_pcb.h
cvs rdiff -u -r1.321 -r1.322 src/sys/netinet/ip_output.c
cvs rdiff -u -r1.12 -r1.13 src/sys/netinet/portalgo.c
cvs rdiff -u -r1.182 -r1.183 src/sys/netinet/raw_ip.c
cvs rdiff -u -r1.435 -r1.436 src/sys/netinet/tcp_input.c
cvs rdiff -u -r1.215 -r1.216 src/sys/netinet/tcp_output.c
cvs rdiff -u -r1.292 -r1.293 src/sys/netinet/tcp_subr.c
cvs rdiff -u -r1.3 -r1.4 src/sys/netinet/tcp_syncache.c
cvs rdiff -u -r1.97 -r1.98 src/sys/netinet/tcp_timer.c
cvs rdiff -u -r1.233 -r1.234 src/sys/netinet/tcp_usrreq.c
cvs rdiff -u -r1.22 -r1.23 src/sys/netinet/tcp_vtw.c
cvs rdiff -u -r1.262 -r1.263 src/sys/netinet/udp_usrreq.c
cvs rdiff -u -r1.253 -r1.254 src/sys/netinet6/icmp6.c
cvs rdiff -u -r1.172 -r1.173 src/sys/netinet6/in6_pcb.c
cvs rdiff -u -r1.89 -r1.90 src/sys/netinet6/in6_src.c
cvs rdiff -u -r1.230 -r1.231 src/sys/netinet6/ip6_output.c
cvs rdiff -u -r1.179 -r1.180 src/sys/netinet6/raw_ip6.c
cvs rdiff -u -r1.151 -r1.152 src/sys/netinet6/udp6_usrreq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netinet/in_pcb.c
diff -u src/sys/netinet/in_pcb.c:1.192 src/sys/netinet/in_pcb.c:1.193
--- src/sys/netinet/in_pcb.c:1.192	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet/in_pcb.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_pcb.c,v 1.192 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: in_pcb.c,v 1.193 2022/10/28 05:25:36 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.192 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.193 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -156,13 +156,16 @@ int	anonportmax = IPPORT_ANONMAX;
 int	lowportmin  = IPPORT_RESERVEDMIN;
 int	lowportmax  = IPPORT_RESERVEDMAX;
 
-static struct pool inpcb_pool;
+static struct pool in4pcb_pool;
+static struct pool in6pcb_pool;
 
 static int
 inpcb_poolinit(void)
 {
 
-	pool_init(&inpcb_pool, sizeof(struct inpcb), 0, 0, 0, "inpcbpl", NULL,
+	pool_init(&in4pcb_pool, sizeof(struct in4pcb), 0, 0, 0, "in4pcbpl", NULL,
+	    IPL_NET);
+	pool_init(&in6pcb_pool, sizeof(struct in6pcb), 0, 0, 0, "in6pcbpl", NULL,
 	    IPL_NET);
 	return 0;
 }
@@ -194,30 +197,39 @@ in_pcballoc(struct socket *so, void *v)
 
 	KASSERT(soaf(so) == AF_INET || soaf(so) == AF_INET6);
 
-	inp = pool_get(&inpcb_pool, PR_NOWAIT);
+	if (soaf(so) == AF_INET)
+		inp = pool_get(&in4pcb_pool, PR_NOWAIT|PR_ZERO);
+	else
+		inp = pool_get(&in6pcb_pool, PR_NOWAIT|PR_ZERO);
 	if (inp == NULL)
 		return (ENOBUFS);
-	memset(inp, 0, sizeof(*inp));
 	inp->inp_af = soaf(so);
 	inp->inp_table = table;
 	inp->inp_socket = so;
-	inp->inp_errormtu = -1;
 	inp->inp_portalgo = PORTALGO_DEFAULT;
 	inp->inp_bindportonsend = false;
-	inp->inp_prefsrcip.s_addr = INADDR_ANY;
 	inp->inp_overudp_cb = NULL;
 	inp->inp_overudp_arg = NULL;
+
+	if (inp->inp_af == AF_INET) {
+		in4p_errormtu(inp) = -1;
+		in4p_prefsrcip(inp).s_addr = INADDR_ANY;
+	}
 #ifdef INET6
-	inp->inp_hops6 = -1;	/* use kernel default */
-	inp->inp_icmp6filt = NULL;
-	if (inp->inp_af == AF_INET6 && ip6_v6only)
-		inp->inp_flags |= IN6P_IPV6_V6ONLY;
+	else {
+		in6p_hops6(inp) = -1;	/* use kernel default */
+		if (ip6_v6only)
+			inp->inp_flags |= IN6P_IPV6_V6ONLY;
+	}
 #endif
 #if defined(IPSEC)
 	if (ipsec_enabled) {
 		int error = ipsec_init_pcbpolicy(so, &inp->inp_sp);
 		if (error != 0) {
-			pool_put(&inpcb_pool, inp);
+			if (inp->inp_af == AF_INET)
+				pool_put(&in4pcb_pool, inp);
+			else
+				pool_put(&in6pcb_pool, inp);
 			return error;
 		}
 		inp->inp_sp->sp_inp = inp;
@@ -325,7 +337,7 @@ in_pcbbind_addr(struct inpcb *inp, struc
 
 	error = in_pcbbindableaddr(inp, sin, cred);
 	if (error == 0)
-		inp->inp_laddr = sin->sin_addr;
+		in4p_laddr(inp) = sin->sin_addr;
 	return error;
 }
 
@@ -399,7 +411,7 @@ in_pcbbind_port(struct inpcb *inp, struc
 			 */
 			if (t &&
 			    (!in_nullhost(sin->sin_addr) ||
-			     !in_nullhost(t->inp_laddr) ||
+			     !in_nullhost(in4p_laddr(t)) ||
 			     (t->inp_socket->so_options & SO_REUSEPORT) == 0)
 			    && (so->so_uidinfo->ui_uid != t->inp_socket->so_uidinfo->ui_uid)) {
 				return (EADDRINUSE);
@@ -442,7 +454,7 @@ in_pcbbind(void *v, struct sockaddr_in *
 	if (inp->inp_af != AF_INET)
 		return (EINVAL);
 
-	if (inp->inp_lport || !in_nullhost(inp->inp_laddr))
+	if (inp->inp_lport || !in_nullhost(in4p_laddr(inp)))
 		return (EINVAL);
 
 	if (NULL != sin) {
@@ -462,7 +474,7 @@ in_pcbbind(void *v, struct sockaddr_in *
 	/* Bind port. */
 	error = in_pcbbind_port(inp, sin, l->l_cred);
 	if (error) {
-		inp->inp_laddr.s_addr = INADDR_ANY;
+		in4p_laddr(inp).s_addr = INADDR_ANY;
 
 		return (error);
 	}
@@ -536,7 +548,7 @@ in_pcbconnect(void *v, struct sockaddr_i
 	 * chose a port number once, even if sending to multiple
 	 * destinations.
 	 */
-	if (in_nullhost(inp->inp_laddr)) {
+	if (in_nullhost(in4p_laddr(inp))) {
 		int xerror;
 		struct in_ifaddr *ia, *_ia;
 		int s;
@@ -566,13 +578,13 @@ in_pcbconnect(void *v, struct sockaddr_i
 		ia4_release(ia, &psref);
 		curlwp_bindx(bound);
 	} else
-		laddr = inp->inp_laddr;
+		laddr = in4p_laddr(inp);
 	if (in_pcblookup_connect(inp->inp_table, sin->sin_addr, sin->sin_port,
 	                         laddr, inp->inp_lport, &vestige) != NULL ||
 	    vestige.valid) {
 		return (EADDRINUSE);
 	}
-	if (in_nullhost(inp->inp_laddr)) {
+	if (in_nullhost(in4p_laddr(inp))) {
 		if (inp->inp_lport == 0) {
 			error = in_pcbbind(inp, NULL, l);
 			/*
@@ -584,16 +596,16 @@ in_pcbconnect(void *v, struct sockaddr_i
 			if (error != 0)
 				return (error);
 		}
-		inp->inp_laddr = laddr;
+		in4p_laddr(inp) = laddr;
 	}
-	inp->inp_faddr = sin->sin_addr;
+	in4p_faddr(inp) = sin->sin_addr;
 	inp->inp_fport = sin->sin_port;
 
         /* Late bind, if needed */
 	if (inp->inp_bindportonsend) {
                struct sockaddr_in lsin = *((const struct sockaddr_in *)
 		    inp->inp_socket->so_proto->pr_domain->dom_sa_any);
-		lsin.sin_addr = inp->inp_laddr;
+		lsin.sin_addr = in4p_laddr(inp);
 		lsin.sin_port = 0;
 
 		if ((error = in_pcbbind_port(inp, &lsin, l->l_cred)) != 0)
@@ -616,7 +628,7 @@ in_pcbdisconnect(void *v)
 	if (inp->inp_af != AF_INET)
 		return;
 
-	inp->inp_faddr = zeroin_addr;
+	in4p_faddr(inp) = zeroin_addr;
 	inp->inp_fport = 0;
 	in_pcbstate(inp, INP_BOUND);
 #if defined(IPSEC)
@@ -651,16 +663,21 @@ in_pcbdetach(void *v)
 	if (inp->inp_options) {
 		m_free(inp->inp_options);
 	}
-	if (inp->inp_outputopts6 != NULL) {
-		ip6_clearpktopts(inp->inp_outputopts6, -1);
-		free(inp->inp_outputopts6, M_IP6OPT);
-	}
 	rtcache_free(&inp->inp_route);
-	ip6_freemoptions(inp->inp_moptions6);
 	ip_freemoptions(inp->inp_moptions);
+	if (inp->inp_af == AF_INET6) {
+		if (in6p_outputopts(inp) != NULL) {
+			ip6_clearpktopts(in6p_outputopts(inp), -1);
+			free(in6p_outputopts(inp), M_IP6OPT);
+		}
+		ip6_freemoptions(in6p_moptions(inp));
+	}
 	sofree(so);			/* drops the socket's lock */
 
-	pool_put(&inpcb_pool, inp);
+	if (inp->inp_af == AF_INET)
+		pool_put(&in4pcb_pool, inp);
+	else
+		pool_put(&in6pcb_pool, inp);
 	mutex_enter(softnet_lock);	/* reacquire the softnet_lock */
 }
 
@@ -671,7 +688,7 @@ in_setsockaddr(struct inpcb *inp, struct
 	if (inp->inp_af != AF_INET)
 		return;
 
-	sockaddr_in_init(sin, &inp->inp_laddr, inp->inp_lport);
+	sockaddr_in_init(sin, &in4p_laddr(inp), inp->inp_lport);
 }
 
 void
@@ -681,7 +698,7 @@ in_setpeeraddr(struct inpcb *inp, struct
 	if (inp->inp_af != AF_INET)
 		return;
 
-	sockaddr_in_init(sin, &inp->inp_faddr, inp->inp_fport);
+	sockaddr_in_init(sin, &in4p_faddr(inp), inp->inp_fport);
 }
 
 /*
@@ -714,10 +731,10 @@ in_pcbnotify(struct inpcbtable *table, s
 		if (inp->inp_af != AF_INET)
 			continue;
 
-		if (in_hosteq(inp->inp_faddr, faddr) &&
+		if (in_hosteq(in4p_faddr(inp), faddr) &&
 		    inp->inp_fport == fport &&
 		    inp->inp_lport == lport &&
-		    in_hosteq(inp->inp_laddr, laddr)) {
+		    in_hosteq(in4p_laddr(inp), laddr)) {
 			(*notify)(inp, errno);
 			nmatch++;
 		}
@@ -737,7 +754,7 @@ in_pcbnotifyall(struct inpcbtable *table
 	TAILQ_FOREACH(inp, &table->inpt_queue, inp_queue) {
 		if (inp->inp_af != AF_INET)
 			continue;
-		if (in_hosteq(inp->inp_faddr, faddr))
+		if (in_hosteq(in4p_faddr(inp), faddr))
 			(*notify)(inp, errno);
 	}
 }
@@ -907,16 +924,16 @@ in_pcblookup_port(struct inpcbtable *tab
 		 *	A	A	match
 		 */
 		wildcard = 0;
-		if (!in_nullhost(inp->inp_faddr))
+		if (!in_nullhost(in4p_faddr(inp)))
 			wildcard++;
-		if (in_nullhost(inp->inp_laddr)) {
+		if (in_nullhost(in4p_laddr(inp))) {
 			if (!in_nullhost(laddr))
 				wildcard++;
 		} else {
 			if (in_nullhost(laddr))
 				wildcard++;
 			else {
-				if (!in_hosteq(inp->inp_laddr, laddr))
+				if (!in_hosteq(in4p_laddr(inp), laddr))
 					continue;
 			}
 		}
@@ -1002,10 +1019,10 @@ in_pcblookup_connect(struct inpcbtable *
 		if (inp->inp_af != AF_INET)
 			continue;
 
-		if (in_hosteq(inp->inp_faddr, faddr) &&
+		if (in_hosteq(in4p_faddr(inp), faddr) &&
 		    inp->inp_fport == fport &&
 		    inp->inp_lport == lport &&
-		    in_hosteq(inp->inp_laddr, laddr))
+		    in_hosteq(in4p_laddr(inp), laddr))
 			goto out;
 	}
 	if (vp && table->vestige) {
@@ -1046,7 +1063,7 @@ in_pcblookup_bind(struct inpcbtable *tab
 			continue;
 
 		if (inp->inp_lport == lport &&
-		    in_hosteq(inp->inp_laddr, laddr))
+		    in_hosteq(in4p_laddr(inp), laddr))
 			goto out;
 	}
 	head = INPCBHASH_BIND(table, zeroin_addr, lport);
@@ -1055,7 +1072,7 @@ in_pcblookup_bind(struct inpcbtable *tab
 			continue;
 
 		if (inp->inp_lport == lport &&
-		    in_hosteq(inp->inp_laddr, zeroin_addr))
+		    in_hosteq(in4p_laddr(inp), zeroin_addr))
 			goto out;
 	}
 #ifdef DIAGNOSTIC
@@ -1090,13 +1107,13 @@ in_pcbstate(struct inpcb *inp, int state
 	switch (state) {
 	case INP_BOUND:
 		LIST_INSERT_HEAD(INPCBHASH_BIND(inp->inp_table,
-		    inp->inp_laddr, inp->inp_lport), inp,
+		    in4p_laddr(inp), inp->inp_lport), inp,
 		    inp_hash);
 		break;
 	case INP_CONNECTED:
 		LIST_INSERT_HEAD(INPCBHASH_CONNECT(inp->inp_table,
-		    inp->inp_faddr, inp->inp_fport,
-		    inp->inp_laddr, inp->inp_lport), inp,
+		    in4p_faddr(inp), inp->inp_fport,
+		    in4p_laddr(inp), inp->inp_lport), inp,
 		    inp_hash);
 		break;
 	}
@@ -1120,7 +1137,7 @@ in_pcbrtentry(struct inpcb *inp)
 
 	ro = &inp->inp_route;
 
-	sockaddr_in_init(&u.dst4, &inp->inp_faddr, 0);
+	sockaddr_in_init(&u.dst4, &in4p_faddr(inp), 0);
 	return rtcache_lookup(ro, &u.dst);
 }
 

Index: src/sys/netinet/in_pcb.h
diff -u src/sys/netinet/in_pcb.h:1.72 src/sys/netinet/in_pcb.h:1.73
--- src/sys/netinet/in_pcb.h:1.72	Fri Oct 28 05:23:09 2022
+++ src/sys/netinet/in_pcb.h	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_pcb.h,v 1.72 2022/10/28 05:23:09 ozaki-r Exp $	*/
+/*	$NetBSD: in_pcb.h,v 1.73 2022/10/28 05:25:36 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -104,42 +104,55 @@ struct inpcb {
 	u_int16_t	inp_fport;	/* foreign port */
 	u_int16_t	inp_lport;	/* local port */
 	int	 	inp_flags;	/* generic IP/datagram flags */
-	union {				/* header prototype. */
-		struct ip inp_ip;
-		struct ip6_hdr inp_ip6;
-	};
-#define	inp_flowinfo	inp_ip6.ip6_flow
 	struct mbuf	*inp_options;	/* IP options */
 	bool		inp_bindportonsend;
 
-	/* We still need both for IPv6 due to v4-mapped addresses */
+	/* We still need it for IPv6 due to v4-mapped addresses */
 	struct ip_moptions *inp_moptions;	/* IPv4 multicast options */
-	struct ip6_moptions *inp_moptions6;	/* IPv6 multicast options */
-
-	union {
-		/* IPv4 only stuffs */
-		struct {
-			int	inp_errormtu;	/* MTU of last xmit status = EMSGSIZE */
-			uint8_t	inp_ip_minttl;
-			struct in_addr	inp_prefsrcip; /* preferred src IP when wild  */
-		};
-		/* IPv6 only stuffs */
-		struct {
-			int	inp_hops6;	/* default IPv6 hop limit */
-			int	inp_cksum6;	/* IPV6_CHECKSUM setsockopt */
-			struct icmp6_filter	*inp_icmp6filt;
-			struct ip6_pktopts	*inp_outputopts6; /* IP6 options for outgoing packets */
-		};
-	};
 
 	pcb_overudp_cb_t	inp_overudp_cb;
 	void		*inp_overudp_arg;
 };
 
-#define	inp_faddr	inp_ip.ip_dst
-#define	inp_laddr	inp_ip.ip_src
-#define inp_faddr6	inp_ip6.ip6_dst
-#define inp_laddr6	inp_ip6.ip6_src
+struct in4pcb {
+	struct inpcb	in4p_pcb;
+	struct ip	in4p_ip;
+	int		in4p_errormtu;	/* MTU of last xmit status = EMSGSIZE */
+	uint8_t		in4p_ip_minttl;
+	struct in_addr	in4p_prefsrcip; /* preferred src IP when wild  */
+};
+
+#define in4p_faddr(inpcb)	(((struct in4pcb *)(inpcb))->in4p_ip.ip_dst)
+#define in4p_laddr(inpcb)	(((struct in4pcb *)(inpcb))->in4p_ip.ip_src)
+#define const_in4p_faddr(inpcb)	(((const struct in4pcb *)(inpcb))->in4p_ip.ip_dst)
+#define const_in4p_laddr(inpcb)	(((const struct in4pcb *)(inpcb))->in4p_ip.ip_src)
+#define in4p_ip(inpcb)		(((struct in4pcb *)(inpcb))->in4p_ip)
+#define in4p_errormtu(inpcb)	(((struct in4pcb *)(inpcb))->in4p_errormtu)
+#define in4p_ip_minttl(inpcb)	(((struct in4pcb *)(inpcb))->in4p_ip_minttl)
+#define in4p_prefsrcip(inpcb)	(((struct in4pcb *)(inpcb))->in4p_prefsrcip)
+
+struct in6pcb {
+	struct inpcb	in6p_pcb;
+	struct ip6_hdr	in6p_ip6;
+	int		in6p_hops;	/* default IPv6 hop limit */
+	int		in6p_cksum;	/* IPV6_CHECKSUM setsockopt */
+	struct icmp6_filter	*in6p_icmp6filt;
+	struct ip6_pktopts	*in6p_outputopts; /* IP6 options for outgoing packets */
+	struct ip6_moptions *in6p_moptions;	/* IPv6 multicast options */
+};
+
+#define in6p_faddr(inpcb)	(((struct in6pcb *)(inpcb))->in6p_ip6.ip6_dst)
+#define in6p_laddr(inpcb)	(((struct in6pcb *)(inpcb))->in6p_ip6.ip6_src)
+#define const_in6p_faddr(inpcb)	(((const struct in6pcb *)(inpcb))->in6p_ip6.ip6_dst)
+#define const_in6p_laddr(inpcb)	(((const struct in6pcb *)(inpcb))->in6p_ip6.ip6_src)
+#define in6p_ip6(inpcb)		(((struct in6pcb *)(inpcb))->in6p_ip6)
+#define in6p_flowinfo(inpcb)	(((struct in6pcb *)(inpcb))->in6p_ip6.ip6_flow)
+#define const_in6p_flowinfo(inpcb)	(((const struct in6pcb *)(inpcb))->in6p_ip6.ip6_flow)
+#define in6p_hops6(inpcb)	(((struct in6pcb *)(inpcb))->in6p_hops)
+#define in6p_cksum(inpcb)	(((struct in6pcb *)(inpcb))->in6p_cksum)
+#define in6p_icmp6filt(inpcb)	(((struct in6pcb *)(inpcb))->in6p_icmp6filt)
+#define in6p_outputopts(inpcb)	(((struct in6pcb *)(inpcb))->in6p_outputopts)
+#define in6p_moptions(inpcb)	(((struct in6pcb *)(inpcb))->in6p_moptions)
 
 LIST_HEAD(inpcbhead, inpcb);
 

Index: src/sys/netinet/ip_output.c
diff -u src/sys/netinet/ip_output.c:1.321 src/sys/netinet/ip_output.c:1.322
--- src/sys/netinet/ip_output.c:1.321	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet/ip_output.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.321 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.322 2022/10/28 05:25:36 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.321 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.322 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -763,7 +763,7 @@ fragment:
 	if (ntohs(ip->ip_off) & IP_DF) {
 		if (flags & IP_RETURNMTU) {
 			KASSERT(inp != NULL);
-			inp->inp_errormtu = mtu;
+			in4p_errormtu(inp) = mtu;
 		}
 		error = EMSGSIZE;
 		IP_STATINC(IP_STAT_CANTFRAG);
@@ -1088,7 +1088,7 @@ int
 ip_ctloutput(int op, struct socket *so, struct sockopt *sopt)
 {
 	struct inpcb *inp = sotoinpcb(so);
-	struct ip *ip = &inp->inp_ip;
+	struct ip *ip = &in4p_ip(inp);
 	int inpflags = inp->inp_flags;
 	int optval = 0, error = 0;
 	struct in_pktinfo pktinfo;
@@ -1136,7 +1136,7 @@ ip_ctloutput(int op, struct socket *so, 
 
 			case IP_MINTTL:
 				if (optval > 0 && optval <= MAXTTL)
-					inp->inp_ip_minttl = optval;
+					in4p_ip_minttl(inp) = optval;
 				else
 					error = EINVAL;
 				break;
@@ -1193,7 +1193,7 @@ ip_ctloutput(int op, struct socket *so, 
 				break;
 
 			if (pktinfo.ipi_ifindex == 0) {
-				inp->inp_prefsrcip = pktinfo.ipi_addr;
+				in4p_prefsrcip(inp) = pktinfo.ipi_addr;
 				break;
 			}
 
@@ -1216,7 +1216,7 @@ ip_ctloutput(int op, struct socket *so, 
 				error = EADDRNOTAVAIL;
 				break;
 			}
-			inp->inp_prefsrcip = IA_SIN(ia)->sin_addr;
+			in4p_prefsrcip(inp) = IA_SIN(ia)->sin_addr;
 			pserialize_read_exit(s);
 			break;
 		break;
@@ -1315,11 +1315,11 @@ ip_ctloutput(int op, struct socket *so, 
 				break;
 
 			case IP_MINTTL:
-				optval = inp->inp_ip_minttl;
+				optval = in4p_ip_minttl(inp);
 				break;
 
 			case IP_ERRORMTU:
-				optval = inp->inp_errormtu;
+				optval = in4p_errormtu(inp);
 				break;
 
 #define	OPTBIT(bit)	(inpflags & bit ? 1 : 0)
@@ -1365,7 +1365,7 @@ ip_ctloutput(int op, struct socket *so, 
 			case sizeof(struct in_pktinfo):
 				/* Solaris compatibility */
 				pktinfo.ipi_ifindex = 0;
-				pktinfo.ipi_addr = inp->inp_prefsrcip;
+				pktinfo.ipi_addr = in4p_prefsrcip(inp);
 				error = sockopt_set(sopt, &pktinfo,
 				    sizeof(pktinfo));
 				break;
@@ -1503,8 +1503,8 @@ ip_setpktopts(struct mbuf *control, stru
 
 	pktopts->ippo_imo = inp->inp_moptions;
 
-	struct in_addr *ia = in_nullhost(inp->inp_prefsrcip) ? &inp->inp_laddr :
-	    &inp->inp_prefsrcip;
+	struct in_addr *ia = in_nullhost(in4p_prefsrcip(inp)) ? &in4p_laddr(inp) :
+	    &in4p_prefsrcip(inp);
 	sockaddr_in_init(&pktopts->ippo_laddr, ia, 0);
 
 	if (control == NULL)

Index: src/sys/netinet/portalgo.c
diff -u src/sys/netinet/portalgo.c:1.12 src/sys/netinet/portalgo.c:1.13
--- src/sys/netinet/portalgo.c:1.12	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet/portalgo.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: portalgo.c,v 1.12 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: portalgo.c,v 1.13 2022/10/28 05:25:36 ozaki-r Exp $	*/
 
 /*
  * Copyright 2011 Vlad Balan
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: portalgo.c,v 1.12 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: portalgo.c,v 1.13 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -260,7 +260,7 @@ check_suitable_port(uint16_t port, struc
 		if (__BITMAP_ISSET(port, &inet4_reserve))
 			return false;
 
-		sin.sin_addr = inp->inp_laddr;
+		sin.sin_addr = in4p_laddr(inp);
 		pcb = in_pcblookup_port(table, sin.sin_addr, htons(port), 1,
 		    &vestigial);
 
@@ -304,7 +304,7 @@ check_suitable_port(uint16_t port, struc
 		if (__BITMAP_ISSET(port, &inet6_reserve))
 			return false;
 
-		sin6.sin6_addr = inp->inp_laddr6;
+		sin6.sin6_addr = in6p_laddr(inp);
 		so = inp->inp_socket;
 
 		/* XXX: this is redundant when called from in6_pcbbind */
@@ -521,10 +521,10 @@ Fhash(const struct inpcb *inp)
 	switch (inp->inp_af) {
 #ifdef INET
 	case AF_INET: {
-		MD5Update(&f_ctx, (const u_char *)&inp->inp_laddr,
-		    sizeof(inp->inp_laddr));
-		MD5Update(&f_ctx, (const u_char *)&inp->inp_faddr,
-		    sizeof(inp->inp_faddr));
+		MD5Update(&f_ctx, (const u_char *)&const_in4p_laddr(inp),
+		    sizeof(const_in4p_laddr(inp)));
+		MD5Update(&f_ctx, (const u_char *)&const_in4p_faddr(inp),
+		    sizeof(const_in4p_faddr(inp)));
 		MD5Update(&f_ctx, (const u_char *)&inp->inp_fport,
 		    sizeof(inp->inp_fport));
 		break;
@@ -532,10 +532,10 @@ Fhash(const struct inpcb *inp)
 #endif
 #ifdef INET6
 	case AF_INET6: {
-		MD5Update(&f_ctx, (const u_char *)&inp->inp_laddr6,
-		    sizeof(inp->inp_laddr6));
-		MD5Update(&f_ctx, (const u_char *)&inp->inp_faddr6,
-		    sizeof(inp->inp_faddr6));
+		MD5Update(&f_ctx, (const u_char *)&const_in6p_laddr(inp),
+		    sizeof(const_in6p_laddr(inp)));
+		MD5Update(&f_ctx, (const u_char *)&const_in6p_faddr(inp),
+		    sizeof(const_in6p_faddr(inp)));
 		MD5Update(&f_ctx, (const u_char *)&inp->inp_fport,
 		    sizeof(inp->inp_fport));
 		break;
@@ -565,7 +565,7 @@ iscompletetuple(struct inpcb *inp)
 	switch (inp->inp_af) {
 #ifdef INET
 	case AF_INET: {
-		if (inp->inp_fport == 0 || in_nullhost(inp->inp_faddr)) {
+		if (inp->inp_fport == 0 || in_nullhost(in4p_faddr(inp))) {
 			DPRINTF("%s fport or faddr missing, delaying port "
 			    "to connect/send\n", __func__);
 			inp->inp_bindportonsend = true;
@@ -578,8 +578,8 @@ iscompletetuple(struct inpcb *inp)
 #endif
 #ifdef INET6
 	case AF_INET6: {
-		if (inp->inp_fport == 0 || memcmp(&inp->inp_faddr6,
-		    &in6addr_any, sizeof(inp->inp_faddr6)) == 0) {
+		if (inp->inp_fport == 0 || memcmp(&in6p_faddr(inp),
+		    &in6addr_any, sizeof(in6p_faddr(inp))) == 0) {
 			DPRINTF("%s fport or faddr missing, delaying port "
 			    "to connect/send\n", __func__);
 			inp->inp_bindportonsend = true;
@@ -783,9 +783,9 @@ portalgo_randport(uint16_t *port, struct
 #ifdef INET
 	case AF_INET: {
 		char buf[INET_ADDRSTRLEN];
-		DPRINTF("local addr: %s\n", IN_PRINT(buf, &inp->inp_laddr));
+		DPRINTF("local addr: %s\n", IN_PRINT(buf, &in4p_laddr(inp)));
 		DPRINTF("local port: %d\n", inp->inp_lport);
-		DPRINTF("foreign addr: %s\n", IN_PRINT(buf, &inp->inp_faddr));
+		DPRINTF("foreign addr: %s\n", IN_PRINT(buf, &in4p_faddr(inp)));
 		DPRINTF("foreign port: %d\n", inp->inp_fport);
 		break;
 	}
@@ -793,10 +793,10 @@ portalgo_randport(uint16_t *port, struct
 #ifdef INET6
 	case AF_INET6: {
 		char buf[INET6_ADDRSTRLEN];
-		DPRINTF("local addr: %s\n", IN6_PRINT(buf, &inp->inp_laddr6));
+		DPRINTF("local addr: %s\n", IN6_PRINT(buf, &in6p_laddr(inp)));
 		DPRINTF("local port: %d\n", inp->inp_lport);
 		DPRINTF("foreign addr: %s\n", IN6_PRINT(buf,
-		    &inp->inp_laddr6));
+		    &in6p_laddr(inp)));
 		DPRINTF("foreign port: %d\n", inp->inp_fport);
 		break;
 	}

Index: src/sys/netinet/raw_ip.c
diff -u src/sys/netinet/raw_ip.c:1.182 src/sys/netinet/raw_ip.c:1.183
--- src/sys/netinet/raw_ip.c:1.182	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet/raw_ip.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: raw_ip.c,v 1.182 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: raw_ip.c,v 1.183 2022/10/28 05:25:36 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.182 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.183 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -185,13 +185,13 @@ rip_input(struct mbuf *m, int off, int p
 	TAILQ_FOREACH(inp, &rawcbtable.inpt_queue, inp_queue) {
 		if (inp->inp_af != AF_INET)
 			continue;
-		if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != proto)
+		if (in4p_ip(inp).ip_p && in4p_ip(inp).ip_p != proto)
 			continue;
-		if (!in_nullhost(inp->inp_laddr) &&
-		    !in_hosteq(inp->inp_laddr, ip->ip_dst))
+		if (!in_nullhost(in4p_laddr(inp)) &&
+		    !in_hosteq(in4p_laddr(inp), ip->ip_dst))
 			continue;
-		if (!in_nullhost(inp->inp_faddr) &&
-		    !in_hosteq(inp->inp_faddr, ip->ip_src))
+		if (!in_nullhost(in4p_faddr(inp)) &&
+		    !in_hosteq(in4p_faddr(inp), ip->ip_src))
 			continue;
 
 		if (last == NULL) {
@@ -246,10 +246,10 @@ rip_pcbnotify(struct inpcbtable *table,
 	TAILQ_FOREACH(inp, &table->inpt_queue, inp_queue) {
 		if (inp->inp_af != AF_INET)
 			continue;
-		if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != proto)
+		if (in4p_ip(inp).ip_p && in4p_ip(inp).ip_p != proto)
 			continue;
-		if (in_hosteq(inp->inp_faddr, faddr) &&
-		    in_hosteq(inp->inp_laddr, laddr)) {
+		if (in_hosteq(in4p_faddr(inp), faddr) &&
+		    in_hosteq(in4p_laddr(inp), laddr)) {
 			(*notify)(inp, errno);
 			nmatch++;
 		}
@@ -335,10 +335,10 @@ rip_output(struct mbuf *m, struct inpcb 
 		ip = mtod(m, struct ip *);
 		ip->ip_tos = 0;
 		ip->ip_off = htons(0);
-		ip->ip_p = inp->inp_ip.ip_p;
+		ip->ip_p = in4p_ip(inp).ip_p;
 		ip->ip_len = htons(m->m_pkthdr.len);
 		ip->ip_src = pktopts.ippo_laddr.sin_addr;
-		ip->ip_dst = inp->inp_faddr;
+		ip->ip_dst = in4p_faddr(inp);
 		ip->ip_ttl = MAXTTL;
 		opts = inp->inp_options;
 	} else {
@@ -498,7 +498,7 @@ rip_connect_pcb(struct inpcb *inp, struc
 		return (EAFNOSUPPORT);
 	if (addr->sin_len != sizeof(*addr))
 		return EINVAL;
-	inp->inp_faddr = addr->sin_addr;
+	in4p_faddr(inp) = addr->sin_addr;
 	return (0);
 }
 
@@ -506,7 +506,7 @@ static void
 rip_disconnect1(struct inpcb *inp)
 {
 
-	inp->inp_faddr = zeroin_addr;
+	in4p_faddr(inp) = zeroin_addr;
 }
 
 static int
@@ -530,7 +530,7 @@ rip_attach(struct socket *so, int proto)
 		return error;
 	}
 	inp = sotoinpcb(so);
-	inp->inp_ip.ip_p = proto;
+	in4p_ip(inp).ip_p = proto;
 	KASSERT(solocked(so));
 
 	return 0;
@@ -605,7 +605,7 @@ rip_bind(struct socket *so, struct socka
 	}
 	pserialize_read_exit(ss);
 
-	inp->inp_laddr = addr->sin_addr;
+	in4p_laddr(inp) = addr->sin_addr;
 
 release:
 	splx(s);

Index: src/sys/netinet/tcp_input.c
diff -u src/sys/netinet/tcp_input.c:1.435 src/sys/netinet/tcp_input.c:1.436
--- src/sys/netinet/tcp_input.c:1.435	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet/tcp_input.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.435 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.436 2022/10/28 05:25:36 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -138,7 +138,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.435 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.436 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1453,7 +1453,7 @@ findpcb:
 	so = NULL;
 	if (inp) {
 		/* Check the minimum TTL for socket. */
-		if (inp->inp_af == AF_INET && ip->ip_ttl < inp->inp_ip_minttl)
+		if (inp->inp_af == AF_INET && ip->ip_ttl < in4p_ip_minttl(inp))
 			goto drop;
 
 		tp = intotcpcb(inp);
@@ -1481,7 +1481,7 @@ findpcb:
 
 #ifdef INET6
 	/* save packet options if user wanted */
-	if (inp && (inp->inp_flags & IN6P_CONTROLOPTS)) {
+	if (inp->inp_af == AF_INET6 && (inp->inp_flags & IN6P_CONTROLOPTS)) {
 		if (inp->inp_options) {
 			m_freem(inp->inp_options);
 			inp->inp_options = NULL;
@@ -2088,10 +2088,10 @@ after_listen:
 			tp->snd_cwnd = tp->t_peermss;
 		else {
 			int ss = tcp_init_win;
-			if (inp->inp_af == AF_INET && in_localaddr(inp->inp_faddr))
+			if (inp->inp_af == AF_INET && in_localaddr(in4p_faddr(inp)))
 				ss = tcp_init_win_local;
 #ifdef INET6
-			else if (inp->inp_af == AF_INET6 && in6_localaddr(&inp->inp_faddr6))
+			else if (inp->inp_af == AF_INET6 && in6_localaddr(&in6p_faddr(inp)))
 				ss = tcp_init_win_local;
 #endif
 			tp->snd_cwnd = TCP_INITIAL_WINDOW(ss, tp->t_peermss);

Index: src/sys/netinet/tcp_output.c
diff -u src/sys/netinet/tcp_output.c:1.215 src/sys/netinet/tcp_output.c:1.216
--- src/sys/netinet/tcp_output.c:1.215	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet/tcp_output.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_output.c,v 1.215 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: tcp_output.c,v 1.216 2022/10/28 05:25:36 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -135,7 +135,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.215 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.216 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -276,16 +276,16 @@ tcp_segsize(struct tcpcb *tp, int *txseg
 #endif
 	} else if (ifp->if_flags & IFF_LOOPBACK)
 		size = ifp->if_mtu - hdrlen;
-	else if (inp && tp->t_mtudisc)
+	else if (inp->inp_af == AF_INET && tp->t_mtudisc)
 		size = ifp->if_mtu - hdrlen;
-	else if (inp && in_localaddr(inp->inp_faddr))
+	else if (inp->inp_af == AF_INET && in_localaddr(in4p_faddr(inp)))
 		size = ifp->if_mtu - hdrlen;
 #ifdef INET6
 	else if (inp->inp_af == AF_INET6) {
-		if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) {
+		if (IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp))) {
 			/* mapped addr case */
 			struct in_addr d;
-			memcpy(&d, &inp->inp_faddr6.s6_addr32[3], sizeof(d));
+			memcpy(&d, &in6p_faddr(inp).s6_addr32[3], sizeof(d));
 			if (tp->t_mtudisc || in_localaddr(d))
 				size = ifp->if_mtu - hdrlen;
 		} else {
@@ -619,11 +619,11 @@ tcp_output(struct tcpcb *tp)
 			 */
 			int ss = tcp_init_win;
 			if (tp->t_inpcb->inp_af == AF_INET &&
-			    in_localaddr(tp->t_inpcb->inp_faddr))
+			    in_localaddr(in4p_faddr(tp->t_inpcb)))
 				ss = tcp_init_win_local;
 #ifdef INET6
 			else if (tp->t_inpcb->inp_af == AF_INET6 &&
-			    in6_localaddr(&tp->t_inpcb->inp_faddr6))
+			    in6_localaddr(&in6p_faddr(tp->t_inpcb)))
 				ss = tcp_init_win_local;
 #endif
 			tp->snd_cwnd = uimin(tp->snd_cwnd,
@@ -1541,8 +1541,8 @@ timer:
 		ip->ip_len = htons(m->m_pkthdr.len);
 		packetlen = m->m_pkthdr.len;
 		if (tp->t_inpcb->inp_af == AF_INET) {
-			ip->ip_ttl = tp->t_inpcb->inp_ip.ip_ttl;
-			ip->ip_tos = tp->t_inpcb->inp_ip.ip_tos | ecn_tos;
+			ip->ip_ttl = in4p_ip(tp->t_inpcb).ip_ttl;
+			ip->ip_tos = in4p_ip(tp->t_inpcb).ip_tos | ecn_tos;
 		}
 #ifdef INET6
 		else if (tp->t_inpcb->inp_af == AF_INET6) {
@@ -1579,7 +1579,7 @@ timer:
 	    {
 		struct mbuf *opts;
 
-		if (tp->t_inpcb && tp->t_family == AF_INET)
+		if (tp->t_inpcb->inp_af == AF_INET)
 			opts = tp->t_inpcb->inp_options;
 		else
 			opts = NULL;
@@ -1593,8 +1593,8 @@ timer:
 	    {
 		struct ip6_pktopts *opts;
 
-		if (tp->t_inpcb && tp->t_family == AF_INET6)
-			opts = tp->t_inpcb->inp_outputopts6;
+		if (tp->t_inpcb->inp_af == AF_INET6)
+			opts = in6p_outputopts(tp->t_inpcb);
 		else
 			opts = NULL;
 		error = ip6_output(m, opts, ro, so->so_options & SO_DONTROUTE,

Index: src/sys/netinet/tcp_subr.c
diff -u src/sys/netinet/tcp_subr.c:1.292 src/sys/netinet/tcp_subr.c:1.293
--- src/sys/netinet/tcp_subr.c:1.292	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet/tcp_subr.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_subr.c,v 1.292 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: tcp_subr.c,v 1.293 2022/10/28 05:25:36 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.292 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.293 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -460,8 +460,8 @@ tcp_template(struct tcpcb *tp)
 #ifdef INET6
 		if (inp->inp_af == AF_INET6) {
 			/* mapped addr case */
-			if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6)
-			 && IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6))
+			if (IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp))
+			 && IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp)))
 				break;
 		}
 #endif
@@ -516,15 +516,15 @@ tcp_template(struct tcpcb *tp)
 		ipov->ih_pr = IPPROTO_TCP;
 		ipov->ih_len = htons(sizeof(struct tcphdr));
 		if (inp->inp_af == AF_INET) {
-			ipov->ih_src = inp->inp_laddr;
-			ipov->ih_dst = inp->inp_faddr;
+			ipov->ih_src = in4p_laddr(inp);
+			ipov->ih_dst = in4p_faddr(inp);
 		}
 #ifdef INET6
 		else if (inp->inp_af == AF_INET6) {
 			/* mapped addr case */
-			bcopy(&inp->inp_laddr6.s6_addr32[3], &ipov->ih_src,
+			bcopy(&in6p_laddr(inp).s6_addr32[3], &ipov->ih_src,
 				sizeof(ipov->ih_src));
-			bcopy(&inp->inp_faddr6.s6_addr32[3], &ipov->ih_dst,
+			bcopy(&in6p_faddr(inp).s6_addr32[3], &ipov->ih_dst,
 				sizeof(ipov->ih_dst));
 		}
 #endif
@@ -549,9 +549,9 @@ tcp_template(struct tcpcb *tp)
 		ip6 = mtod(m, struct ip6_hdr *);
 		ip6->ip6_nxt = IPPROTO_TCP;
 		ip6->ip6_plen = htons(sizeof(struct tcphdr));
-		ip6->ip6_src = inp->inp_laddr6;
-		ip6->ip6_dst = inp->inp_faddr6;
-		ip6->ip6_flow = inp->inp_flowinfo & IPV6_FLOWINFO_MASK;
+		ip6->ip6_src = in6p_laddr(inp);
+		ip6->ip6_dst = in6p_faddr(inp);
+		ip6->ip6_flow = in6p_flowinfo(inp) & IPV6_FLOWINFO_MASK;
 		if (ip6_auto_flowlabel) {
 			ip6->ip6_flow &= ~IPV6_FLOWLABEL_MASK;
 			ip6->ip6_flow |=
@@ -567,8 +567,8 @@ tcp_template(struct tcpcb *tp)
 		 * checksum right before the packet is sent off onto
 		 * the wire.
 		 */
-		n->th_sum = in6_cksum_phdr(&inp->inp_laddr6,
-		    &inp->inp_faddr6, htonl(sizeof(struct tcphdr)),
+		n->th_sum = in6_cksum_phdr(&in6p_laddr(inp),
+		    &in6p_faddr(inp), htonl(sizeof(struct tcphdr)),
 		    htonl(IPPROTO_TCP));
 		break;
 	    }
@@ -823,7 +823,7 @@ tcp_respond(struct tcpcb *tp, struct mbu
 	if (tp != NULL && tp->t_inpcb->inp_af == AF_INET) {
 		ro = &tp->t_inpcb->inp_route;
 		KASSERT(family == AF_INET);
-		KASSERT(in_hosteq(ip->ip_dst, tp->t_inpcb->inp_faddr));
+		KASSERT(in_hosteq(ip->ip_dst, in4p_faddr(tp->t_inpcb)));
 	}
 #ifdef INET6
 	else if (tp != NULL && tp->t_inpcb->inp_af == AF_INET6) {
@@ -831,16 +831,16 @@ tcp_respond(struct tcpcb *tp, struct mbu
 
 #ifdef DIAGNOSTIC
 		if (family == AF_INET) {
-			if (!IN6_IS_ADDR_V4MAPPED(&tp->t_inpcb->inp_faddr6))
+			if (!IN6_IS_ADDR_V4MAPPED(&in6p_faddr(tp->t_inpcb)))
 				panic("tcp_respond: not mapped addr");
 			if (memcmp(&ip->ip_dst,
-			    &tp->t_inpcb->inp_faddr6.s6_addr32[3],
+			    &in6p_faddr(tp->t_inpcb).s6_addr32[3],
 			    sizeof(ip->ip_dst)) != 0) {
 				panic("tcp_respond: ip_dst != in6p_faddr");
 			}
 		} else if (family == AF_INET6) {
 			if (!IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,
-			    &tp->t_inpcb->inp_faddr6))
+			    &in6p_faddr(tp->t_inpcb)))
 				panic("tcp_respond: ip6_dst != in6p_faddr");
 		} else
 			panic("tcp_respond: address family mismatch");
@@ -967,7 +967,7 @@ tcp_newtcpcb(int family, struct inpcb *i
 
 	switch (family) {
 	case AF_INET:
-		inp->inp_ip.ip_ttl = ip_defttl;
+		in4p_ip(inp).ip_ttl = ip_defttl;
 		inp->inp_ppcb = (void *)tp;
 
 		tp->t_inpcb = inp;
@@ -975,7 +975,7 @@ tcp_newtcpcb(int family, struct inpcb *i
 		break;
 #ifdef INET6
 	case AF_INET6:
-		inp->inp_ip6.ip6_hlim = in6_selecthlim_rt(inp);
+		in6p_ip6(inp).ip6_hlim = in6_selecthlim_rt(inp);
 		inp->inp_ppcb = (void *)tp;
 
 		tp->t_inpcb = inp;
@@ -1843,7 +1843,7 @@ tcp_established(struct tcpcb *tp)
 		rt = in_pcbrtentry(tp->t_inpcb);
 #endif
 		if (__predict_true(tcp_msl_enable)) {
-			if (tp->t_inpcb->inp_laddr.s_addr == INADDR_LOOPBACK) {
+			if (in4p_laddr(tp->t_inpcb).s_addr == INADDR_LOOPBACK) {
 				tp->t_msl = tcp_msl_loop ? tcp_msl_loop : (TCPTV_MSL >> 2);
 				break;
 			}
@@ -1853,7 +1853,7 @@ tcp_established(struct tcpcb *tp)
 				tp->t_msl = tcp_msl_local ? tcp_msl_local : (TCPTV_MSL >> 1);
 				break;
 			}
-			if (in_localaddr(tp->t_inpcb->inp_faddr)) {
+			if (in_localaddr(in4p_faddr(tp->t_inpcb))) {
 				tp->t_msl = tcp_msl_local ? tcp_msl_local : (TCPTV_MSL >> 1);
 				break;
 			}
@@ -1874,7 +1874,7 @@ tcp_established(struct tcpcb *tp)
 		if (__predict_true(tcp_msl_enable)) {
 			extern const struct in6_addr in6addr_loopback;
 
-			if (IN6_ARE_ADDR_EQUAL(&tp->t_inpcb->inp_laddr6,
+			if (IN6_ARE_ADDR_EQUAL(&in6p_laddr(tp->t_inpcb),
 			    &in6addr_loopback)) {
 				tp->t_msl = tcp_msl_loop ? tcp_msl_loop : (TCPTV_MSL >> 2);
 				break;
@@ -1885,7 +1885,7 @@ tcp_established(struct tcpcb *tp)
 				tp->t_msl = tcp_msl_local ? tcp_msl_local : (TCPTV_MSL >> 1);
 				break;
 			}
-			if (in6_localaddr(&tp->t_inpcb->inp_faddr6)) {
+			if (in6_localaddr(&in6p_faddr(tp->t_inpcb))) {
 				tp->t_msl = tcp_msl_local ? tcp_msl_local : (TCPTV_MSL >> 1);
 				break;
 			}
@@ -1977,15 +1977,15 @@ tcp_new_iss(struct tcpcb *tp)
 {
 
 	if (tp->t_inpcb->inp_af == AF_INET) {
-		return tcp_new_iss1(&tp->t_inpcb->inp_laddr,
-		    &tp->t_inpcb->inp_faddr, tp->t_inpcb->inp_lport,
-		    tp->t_inpcb->inp_fport, sizeof(tp->t_inpcb->inp_laddr));
+		return tcp_new_iss1(&in4p_laddr(tp->t_inpcb),
+		    &in4p_faddr(tp->t_inpcb), tp->t_inpcb->inp_lport,
+		    tp->t_inpcb->inp_fport, sizeof(in4p_laddr(tp->t_inpcb)));
 	}
 #ifdef INET6
 	if (tp->t_inpcb->inp_af == AF_INET6) {
-		return tcp_new_iss1(&tp->t_inpcb->inp_laddr6,
-		    &tp->t_inpcb->inp_faddr6, tp->t_inpcb->inp_lport,
-		    tp->t_inpcb->inp_fport, sizeof(tp->t_inpcb->inp_laddr6));
+		return tcp_new_iss1(&in6p_laddr(tp->t_inpcb),
+		    &in6p_faddr(tp->t_inpcb), tp->t_inpcb->inp_lport,
+		    tp->t_inpcb->inp_fport, sizeof(in6p_laddr(tp->t_inpcb)));
 	}
 #endif
 

Index: src/sys/netinet/tcp_syncache.c
diff -u src/sys/netinet/tcp_syncache.c:1.3 src/sys/netinet/tcp_syncache.c:1.4
--- src/sys/netinet/tcp_syncache.c:1.3	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet/tcp_syncache.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_syncache.c,v 1.3 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: tcp_syncache.c,v 1.4 2022/10/28 05:25:36 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_syncache.c,v 1.3 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_syncache.c,v 1.4 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -610,7 +610,7 @@ syn_cache_get(struct sockaddr *src, stru
 	switch (src->sa_family) {
 	case AF_INET:
 		if (inp->inp_af == AF_INET) {
-			inp->inp_laddr = ((struct sockaddr_in *)dst)->sin_addr;
+			in4p_laddr(inp) = ((struct sockaddr_in *)dst)->sin_addr;
 			inp->inp_lport = ((struct sockaddr_in *)dst)->sin_port;
 			inp->inp_options = ip_srcroute(m);
 			in_pcbstate(inp, INP_BOUND);
@@ -622,10 +622,10 @@ syn_cache_get(struct sockaddr *src, stru
 #ifdef INET6
 		else if (inp->inp_af == AF_INET6) {
 			/* IPv4 packet to AF_INET6 socket */
-			memset(&inp->inp_laddr6, 0, sizeof(inp->inp_laddr6));
-			inp->inp_laddr6.s6_addr16[5] = htons(0xffff);
+			memset(&in6p_laddr(inp), 0, sizeof(in6p_laddr(inp)));
+			in6p_laddr(inp).s6_addr16[5] = htons(0xffff);
 			bcopy(&((struct sockaddr_in *)dst)->sin_addr,
-				&inp->inp_laddr6.s6_addr32[3],
+				&in6p_laddr(inp).s6_addr32[3],
 				sizeof(((struct sockaddr_in *)dst)->sin_addr));
 			inp->inp_lport = ((struct sockaddr_in *)dst)->sin_port;
 			intotcpcb(inp)->t_family = AF_INET;
@@ -640,7 +640,7 @@ syn_cache_get(struct sockaddr *src, stru
 #ifdef INET6
 	case AF_INET6:
 		if (inp->inp_af == AF_INET6) {
-			inp->inp_laddr6 = ((struct sockaddr_in6 *)dst)->sin6_addr;
+			in6p_laddr(inp) = ((struct sockaddr_in6 *)dst)->sin6_addr;
 			inp->inp_lport = ((struct sockaddr_in6 *)dst)->sin6_port;
 			in_pcbstate(inp, INP_BOUND);
 		}
@@ -746,10 +746,10 @@ syn_cache_get(struct sockaddr *src, stru
 		tp->snd_cwnd = tp->t_peermss;
 	else {
 		int ss = tcp_init_win;
-		if (inp->inp_af == AF_INET && in_localaddr(inp->inp_faddr))
+		if (inp->inp_af == AF_INET && in_localaddr(in4p_faddr(inp)))
 			ss = tcp_init_win_local;
 #ifdef INET6
-		else if (inp->inp_af == AF_INET6 && in6_localaddr(&inp->inp_faddr6))
+		else if (inp->inp_af == AF_INET6 && in6_localaddr(&in6p_faddr(inp)))
 			ss = tcp_init_win_local;
 #endif
 		tp->snd_cwnd = TCP_INITIAL_WINDOW(ss, tp->t_peermss);

Index: src/sys/netinet/tcp_timer.c
diff -u src/sys/netinet/tcp_timer.c:1.97 src/sys/netinet/tcp_timer.c:1.98
--- src/sys/netinet/tcp_timer.c:1.97	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet/tcp_timer.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_timer.c,v 1.97 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: tcp_timer.c,v 1.98 2022/10/28 05:25:36 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.97 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.98 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -330,7 +330,7 @@ tcp_timer_rexmt(void *arg)
 		icmp.icmp_nextmtu = tp->t_pmtud_nextmtu;
 		icmp.icmp_ip.ip_len = tp->t_pmtud_ip_len;
 		icmp.icmp_ip.ip_hl = tp->t_pmtud_ip_hl;
-		icmpsrc.sin_addr = tp->t_inpcb->inp_faddr;
+		icmpsrc.sin_addr = in4p_faddr(tp->t_inpcb);
 		icmp_mtudisc(&icmp, icmpsrc.sin_addr);
 
 		/*

Index: src/sys/netinet/tcp_usrreq.c
diff -u src/sys/netinet/tcp_usrreq.c:1.233 src/sys/netinet/tcp_usrreq.c:1.234
--- src/sys/netinet/tcp_usrreq.c:1.233	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet/tcp_usrreq.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_usrreq.c,v 1.233 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: tcp_usrreq.c,v 1.234 2022/10/28 05:25:36 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -99,7 +99,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.233 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.234 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -573,7 +573,7 @@ tcp_bind(struct socket *so, struct socka
 		error = in6_pcbbind(inp, sin6, l);
 		if (!error) {
 			/* mapped addr case */
-			if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6))
+			if (IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp)))
 				tp->t_family = AF_INET;
 			else
 				tp->t_family = AF_INET6;
@@ -667,7 +667,7 @@ tcp_connect(struct socket *so, struct so
 		error = in6_pcbconnect(inp, (struct sockaddr_in6 *)nam, l);
 		if (!error) {
 			/* mapped addr case */
-			if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6))
+			if (IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp)))
 				tp->t_family = AF_INET;
 			else
 				tp->t_family = AF_INET6;
@@ -1665,13 +1665,13 @@ sysctl_inpcblist(SYSCTLFN_ARGS)
 			in->sin_len = sizeof(*in);
 			in->sin_family = pf;
 			in->sin_port = inp->inp_lport;
-			in->sin_addr = inp->inp_laddr;
+			in->sin_addr = const_in4p_laddr(inp);
 			if (pcb.ki_prstate >= INP_CONNECTED) {
 				in = satosin(&pcb.ki_dst);
 				in->sin_len = sizeof(*in);
 				in->sin_family = pf;
 				in->sin_port = inp->inp_fport;
-				in->sin_addr = inp->inp_faddr;
+				in->sin_addr = const_in4p_faddr(inp);
 			}
 			break;
 #ifdef INET6
@@ -1705,8 +1705,8 @@ sysctl_inpcblist(SYSCTLFN_ARGS)
 			in6->sin6_len = sizeof(*in6);
 			in6->sin6_family = pf;
 			in6->sin6_port = inp->inp_lport;
-			in6->sin6_flowinfo = inp->inp_flowinfo;
-			in6->sin6_addr = inp->inp_laddr6;
+			in6->sin6_flowinfo = const_in6p_flowinfo(inp);
+			in6->sin6_addr = const_in6p_laddr(inp);
 			in6->sin6_scope_id = 0; /* XXX? */
 
 			if (pcb.ki_prstate >= INP_CONNECTED) {
@@ -1714,8 +1714,8 @@ sysctl_inpcblist(SYSCTLFN_ARGS)
 				in6->sin6_len = sizeof(*in6);
 				in6->sin6_family = pf;
 				in6->sin6_port = inp->inp_fport;
-				in6->sin6_flowinfo = inp->inp_flowinfo;
-				in6->sin6_addr = inp->inp_faddr6;
+				in6->sin6_flowinfo = const_in6p_flowinfo(inp);
+				in6->sin6_addr = const_in6p_faddr(inp);
 				in6->sin6_scope_id = 0; /* XXX? */
 			}
 			break;

Index: src/sys/netinet/tcp_vtw.c
diff -u src/sys/netinet/tcp_vtw.c:1.22 src/sys/netinet/tcp_vtw.c:1.23
--- src/sys/netinet/tcp_vtw.c:1.22	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet/tcp_vtw.c	Fri Oct 28 05:25:36 2022
@@ -121,7 +121,7 @@
 
 #include <netinet/tcp_vtw.h>
 
-__KERNEL_RCSID(0, "$NetBSD: tcp_vtw.c,v 1.22 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_vtw.c,v 1.23 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #define db_trace(__a, __b)	do { } while (/*CONSTCOND*/0)
 
@@ -1900,8 +1900,8 @@ vtw_add(int af, struct tcpcb *tp)
 			struct inpcb	*inp = tp->t_inpcb;
 			vtw_v4_t	*v4  = (void*)vtw;
 
-			v4->faddr = inp->inp_faddr.s_addr;
-			v4->laddr = inp->inp_laddr.s_addr;
+			v4->faddr = in4p_faddr(inp).s_addr;
+			v4->laddr = in4p_laddr(inp).s_addr;
 			v4->fport = inp->inp_fport;
 			v4->lport = inp->inp_lport;
 
@@ -1922,14 +1922,14 @@ vtw_add(int af, struct tcpcb *tp)
 			if (enable & 4) {
 				KASSERT(vtw_lookup_hash_v4
 					(ctl
-					 , inp->inp_faddr.s_addr, inp->inp_fport
-					 , inp->inp_laddr.s_addr, inp->inp_lport
+					 , in4p_faddr(inp).s_addr, inp->inp_fport
+					 , in4p_laddr(inp).s_addr, inp->inp_lport
 					 , 0)
 					== vtw);
 				KASSERT(vtw_lookup_hash_v4
 					(ctl
-					 , inp->inp_faddr.s_addr, inp->inp_fport
-					 , inp->inp_laddr.s_addr, inp->inp_lport
+					 , in4p_faddr(inp).s_addr, inp->inp_fport
+					 , in4p_laddr(inp).s_addr, inp->inp_lport
 					 , 1));
 			}
 			/* Immediate port iterator functionality check: not wild
@@ -1939,7 +1939,7 @@ vtw_add(int af, struct tcpcb *tp)
 				struct vestigial_inpcb res;
 				int cnt = 0;
 
-				it = tcp_init_ports_v4(inp->inp_laddr
+				it = tcp_init_ports_v4(in4p_laddr(inp)
 						       , inp->inp_lport, 0);
 
 				while (tcp_next_port_v4(it, &res)) {
@@ -1972,8 +1972,8 @@ vtw_add(int af, struct tcpcb *tp)
 			struct inpcb	*inp = tp->t_inpcb;
 			vtw_v6_t	*v6  = (void*)vtw;
 
-			v6->faddr = inp->inp_faddr6;
-			v6->laddr = inp->inp_laddr6;
+			v6->faddr = in6p_faddr(inp);
+			v6->laddr = in6p_laddr(inp);
 			v6->fport = inp->inp_fport;
 			v6->lport = inp->inp_lport;
 
@@ -1992,14 +1992,14 @@ vtw_add(int af, struct tcpcb *tp)
 			 */
 			if (enable & 4) {
 				KASSERT(vtw_lookup_hash_v6(ctl
-					 , &inp->inp_faddr6, inp->inp_fport
-					 , &inp->inp_laddr6, inp->inp_lport
+					 , &in6p_faddr(inp), inp->inp_fport
+					 , &in6p_laddr(inp), inp->inp_lport
 					 , 0)
 					== vtw);
 				KASSERT(vtw_lookup_hash_v6
 					(ctl
-					 , &inp->inp_faddr6, inp->inp_fport
-					 , &inp->inp_laddr6, inp->inp_lport
+					 , &in6p_faddr(inp), inp->inp_fport
+					 , &in6p_laddr(inp), inp->inp_lport
 					 , 1));
 			}
 			/* Immediate port iterator functionality check: not wild
@@ -2009,7 +2009,7 @@ vtw_add(int af, struct tcpcb *tp)
 				struct vestigial_inpcb res;
 				int cnt = 0;
 
-				it = tcp_init_ports_v6(&inp->inp_laddr6
+				it = tcp_init_ports_v6(&in6p_laddr(inp)
 						       , inp->inp_lport, 0);
 
 				while (tcp_next_port_v6(it, &res)) {

Index: src/sys/netinet/udp_usrreq.c
diff -u src/sys/netinet/udp_usrreq.c:1.262 src/sys/netinet/udp_usrreq.c:1.263
--- src/sys/netinet/udp_usrreq.c:1.262	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet/udp_usrreq.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: udp_usrreq.c,v 1.262 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: udp_usrreq.c,v 1.263 2022/10/28 05:25:36 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.262 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.263 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -533,12 +533,12 @@ udp4_realinput(struct sockaddr_in *src, 
 
 			if (inp->inp_lport != *dport)
 				continue;
-			if (!in_nullhost(inp->inp_laddr)) {
-				if (!in_hosteq(inp->inp_laddr, *dst4))
+			if (!in_nullhost(in4p_laddr(inp))) {
+				if (!in_hosteq(in4p_laddr(inp), *dst4))
 					continue;
 			}
-			if (!in_nullhost(inp->inp_faddr)) {
-				if (!in_hosteq(inp->inp_faddr, *src4) ||
+			if (!in_nullhost(in4p_faddr(inp))) {
+				if (!in_hosteq(in4p_faddr(inp), *src4) ||
 				    inp->inp_fport != *sport)
 					continue;
 			}
@@ -623,7 +623,7 @@ udp4_realinput(struct sockaddr_in *src, 
 		/*
 		 * Check the minimum TTL for socket.
 		 */
-		if (mtod(m, struct ip *)->ip_ttl < inp->inp_ip_minttl)
+		if (mtod(m, struct ip *)->ip_ttl < in4p_ip_minttl(inp))
 			goto bad;
 
 		udp4_sendup(m, off, (struct sockaddr *)src, inp->inp_socket);
@@ -816,7 +816,7 @@ udp_output(struct mbuf *m, struct inpcb 
 	ui = mtod(m, struct udpiphdr *);
 	ui->ui_pr = IPPROTO_UDP;
 	ui->ui_src = pktopts.ippo_laddr.sin_addr;
-	ui->ui_dst = inp->inp_faddr;
+	ui->ui_dst = in4p_faddr(inp);
 	ui->ui_sport = inp->inp_lport;
 	ui->ui_dport = inp->inp_fport;
 	ui->ui_ulen = htons((u_int16_t)len + sizeof(struct udphdr));
@@ -840,8 +840,8 @@ udp_output(struct mbuf *m, struct inpcb 
 		ui->ui_sum = 0;
 
 	((struct ip *)ui)->ip_len = htons(sizeof(struct udpiphdr) + len);
-	((struct ip *)ui)->ip_ttl = inp->inp_ip.ip_ttl;	/* XXX */
-	((struct ip *)ui)->ip_tos = inp->inp_ip.ip_tos;	/* XXX */
+	((struct ip *)ui)->ip_ttl = in4p_ip(inp).ip_ttl;	/* XXX */
+	((struct ip *)ui)->ip_tos = in4p_ip(inp).ip_tos;	/* XXX */
 	UDP_STATINC(UDP_STAT_OPACKETS);
 
 	flags |= inp->inp_socket->so_options & (SO_DONTROUTE|SO_BROADCAST);
@@ -882,7 +882,7 @@ udp_attach(struct socket *so, int proto)
 		return error;
 	}
 	inp = sotoinpcb(so);
-	inp->inp_ip.ip_ttl = ip_defttl;
+	in4p_ip(inp).ip_ttl = ip_defttl;
 	KASSERT(solocked(so));
 
 	return error;
@@ -976,7 +976,7 @@ udp_disconnect(struct socket *so)
 	/*soisdisconnected(so);*/
 	so->so_state &= ~SS_ISCONNECTED;	/* XXX */
 	in_pcbdisconnect(inp);
-	inp->inp_laddr = zeroin_addr;		/* XXX */
+	in4p_laddr(inp) = zeroin_addr;		/* XXX */
 	in_pcbstate(inp, INP_BOUND);		/* XXX */
 	splx(s);
 
@@ -1087,7 +1087,7 @@ udp_send(struct socket *so, struct mbuf 
 
 	s = splsoftnet();
 	if (nam) {
-		laddr = inp->inp_laddr;		/* XXX */
+		laddr = in4p_laddr(inp);		/* XXX */
 		if ((so->so_state & SS_ISCONNECTED) != 0) {
 			error = EISCONN;
 			goto die;
@@ -1106,7 +1106,7 @@ udp_send(struct socket *so, struct mbuf 
 	control = NULL;
 	if (nam) {
 		in_pcbdisconnect(inp);
-		inp->inp_laddr = laddr;		/* XXX */
+		in4p_laddr(inp) = laddr;		/* XXX */
 		in_pcbstate(inp, INP_BOUND);	/* XXX */
 	}
   die:

Index: src/sys/netinet6/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.253 src/sys/netinet6/icmp6.c:1.254
--- src/sys/netinet6/icmp6.c:1.253	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet6/icmp6.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.253 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.254 2022/10/28 05:25:36 ozaki-r Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.253 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.254 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1965,17 +1965,17 @@ icmp6_rip6_input(struct mbuf **mp, int o
 	TAILQ_FOREACH(inp, &raw6cbtable.inpt_queue, inp_queue) {
 		if (inp->inp_af != AF_INET6)
 			continue;
-		if (inp->inp_ip6.ip6_nxt != IPPROTO_ICMPV6)
+		if (in6p_ip6(inp).ip6_nxt != IPPROTO_ICMPV6)
 			continue;
-		if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) &&
-		    !IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &ip6->ip6_dst))
+		if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)) &&
+		    !IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), &ip6->ip6_dst))
 			continue;
-		if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6) &&
-		    !IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, &ip6->ip6_src))
+		if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp)) &&
+		    !IN6_ARE_ADDR_EQUAL(&in6p_faddr(inp), &ip6->ip6_src))
 			continue;
-		if (inp->inp_icmp6filt &&
+		if (in6p_icmp6filt(inp) &&
 		    ICMP6_FILTER_WILLBLOCK(icmp6->icmp6_type,
-		    inp->inp_icmp6filt))
+		    in6p_icmp6filt(inp)))
 			continue;
 
 		if (last == NULL) {
@@ -2755,7 +2755,7 @@ icmp6_ctloutput(int op, struct socket *s
 			error = sockopt_get(sopt, &fil, sizeof(fil));
 			if (error)
 				break;
-			memcpy(inp->inp_icmp6filt, &fil,
+			memcpy(in6p_icmp6filt(inp), &fil,
 			    sizeof(struct icmp6_filter));
 			error = 0;
 			break;
@@ -2771,11 +2771,11 @@ icmp6_ctloutput(int op, struct socket *s
 		switch (sopt->sopt_name) {
 		case ICMP6_FILTER:
 		    {
-			if (inp->inp_icmp6filt == NULL) {
+			if (in6p_icmp6filt(inp) == NULL) {
 				error = EINVAL;
 				break;
 			}
-			error = sockopt_set(sopt, inp->inp_icmp6filt,
+			error = sockopt_set(sopt, in6p_icmp6filt(inp),
 			    sizeof(struct icmp6_filter));
 			break;
 		    }

Index: src/sys/netinet6/in6_pcb.c
diff -u src/sys/netinet6/in6_pcb.c:1.172 src/sys/netinet6/in6_pcb.c:1.173
--- src/sys/netinet6/in6_pcb.c:1.172	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet6/in6_pcb.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_pcb.c,v 1.172 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: in6_pcb.c,v 1.173 2022/10/28 05:25:36 ozaki-r Exp $	*/
 /*	$KAME: in6_pcb.c,v 1.84 2001/02/08 18:02:08 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.172 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.173 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -219,7 +219,7 @@ in6_pcbbind_addr(struct inpcb *inp, stru
 			goto out;
 		}
 	}
-	inp->inp_laddr6 = sin6->sin6_addr;
+	in6p_laddr(inp) = sin6->sin6_addr;
 	error = 0;
 out:
 	pserialize_read_exit(s);
@@ -336,9 +336,9 @@ in6_pcbbind(void *v, struct sockaddr_in6
 	 * If we already have a local port or a local address it means we're
 	 * bounded.
 	 */
-	if (inp->inp_lport || !(IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) ||
-	    (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6) &&
-	      inp->inp_laddr6.s6_addr32[3] == 0)))
+	if (inp->inp_lport || !(IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)) ||
+	    (IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp)) &&
+	      in6p_laddr(inp).s6_addr32[3] == 0)))
 		return (EINVAL);
 
 	if (NULL != sin6) {
@@ -364,14 +364,14 @@ in6_pcbbind(void *v, struct sockaddr_in6
 		 * Reset the address here to "any" so we don't "leak" the
 		 * inpcb.
 		 */
-		inp->inp_laddr6 = in6addr_any;
+		in6p_laddr(inp) = in6addr_any;
 
 		return (error);
 	}
 
 
 #if 0
-	inp->inp_flowinfo = 0;	/* XXX */
+	in6p_flowinfo(inp) = 0;	/* XXX */
 #endif
 	return (0);
 }
@@ -424,13 +424,13 @@ in6_pcbconnect(void *v, struct sockaddr_
 	if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
 		if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)
 			return EINVAL;
-		if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6))
-			inp->inp_laddr6.s6_addr16[5] = htons(0xffff);
-		if (!IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6))
+		if (IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)))
+			in6p_laddr(inp).s6_addr16[5] = htons(0xffff);
+		if (!IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp)))
 			return EINVAL;
 	} else
 	{
-		if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6))
+		if (IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp)))
 			return EINVAL;
 	}
 
@@ -440,8 +440,8 @@ in6_pcbconnect(void *v, struct sockaddr_
 
 	bound = curlwp_bind();
 	/* Source address selection. */
-	if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6) &&
-	    inp->inp_laddr6.s6_addr32[3] == 0) {
+	if (IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp)) &&
+	    in6p_laddr(inp).s6_addr32[3] == 0) {
 #ifdef INET
 		struct sockaddr_in sin;
 		struct in_ifaddr *ia4;
@@ -476,8 +476,8 @@ in6_pcbconnect(void *v, struct sockaddr_
 		 * with the address specified by setsockopt(IPV6_PKTINFO).
 		 * Is it the intended behavior?
 		 */
-		error = in6_selectsrc(sin6, inp->inp_outputopts6,
-		    inp->inp_moptions6, &inp->inp_route, &inp->inp_laddr6,
+		error = in6_selectsrc(sin6, in6p_outputopts(inp),
+		    in6p_moptions(inp), &inp->inp_route, &in6p_laddr(inp),
 		    &ifp, &psref, &ia6);
 		if (error == 0)
 			in6a = &ia6;
@@ -498,37 +498,37 @@ in6_pcbconnect(void *v, struct sockaddr_
 	}
 
 	if (ifp != NULL) {
-		inp->inp_ip6.ip6_hlim = (u_int8_t)in6_selecthlim(inp, ifp);
+		in6p_ip6(inp).ip6_hlim = (u_int8_t)in6_selecthlim(inp, ifp);
 		if_put(ifp, &psref);
 	} else
-		inp->inp_ip6.ip6_hlim = (u_int8_t)in6_selecthlim_rt(inp);
+		in6p_ip6(inp).ip6_hlim = (u_int8_t)in6_selecthlim_rt(inp);
 	curlwp_bindx(bound);
 
 	if (in6_pcblookup_connect(inp->inp_table, &sin6->sin6_addr,
 	    sin6->sin6_port,
-	    IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) ? in6a : &inp->inp_laddr6,
+	    IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)) ? in6a : &in6p_laddr(inp),
 				  inp->inp_lport, 0, &vestige)
 		|| vestige.valid)
 		return (EADDRINUSE);
-	if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) ||
-	    (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6) &&
-	     inp->inp_laddr6.s6_addr32[3] == 0))
+	if (IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)) ||
+	    (IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp)) &&
+	     in6p_laddr(inp).s6_addr32[3] == 0))
 	{
 		if (inp->inp_lport == 0) {
 			error = in6_pcbbind(inp, NULL, l);
 			if (error != 0)
 				return error;
 		}
-		inp->inp_laddr6 = *in6a;
+		in6p_laddr(inp) = *in6a;
 	}
-	inp->inp_faddr6 = sin6->sin6_addr;
+	in6p_faddr(inp) = sin6->sin6_addr;
 	inp->inp_fport = sin6->sin6_port;
 
         /* Late bind, if needed */
 	if (inp->inp_bindportonsend) {
                struct sockaddr_in6 lsin = *((const struct sockaddr_in6 *)
 		    inp->inp_socket->so_proto->pr_domain->dom_sa_any);
-		lsin.sin6_addr = inp->inp_laddr6;
+		lsin.sin6_addr = in6p_laddr(inp);
 		lsin.sin6_port = 0;
 
                if ((error = in6_pcbbind_port(inp, &lsin, l)) != 0)
@@ -536,9 +536,9 @@ in6_pcbconnect(void *v, struct sockaddr_
 	}
 	
 	in_pcbstate(inp, INP_CONNECTED);
-	inp->inp_flowinfo &= ~IPV6_FLOWLABEL_MASK;
+	in6p_flowinfo(inp) &= ~IPV6_FLOWLABEL_MASK;
 	if (ip6_auto_flowlabel)
-		inp->inp_flowinfo |=
+		in6p_flowinfo(inp) |=
 		    (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK);
 #if defined(IPSEC)
 	if (ipsec_enabled && inp->inp_socket->so_type == SOCK_STREAM)
@@ -550,10 +550,10 @@ in6_pcbconnect(void *v, struct sockaddr_
 void
 in6_pcbdisconnect(struct inpcb *inp)
 {
-	memset((void *)&inp->inp_faddr6, 0, sizeof(inp->inp_faddr6));
+	memset((void *)&in6p_faddr(inp), 0, sizeof(in6p_faddr(inp)));
 	inp->inp_fport = 0;
 	in_pcbstate(inp, INP_BOUND);
-	inp->inp_flowinfo &= ~IPV6_FLOWLABEL_MASK;
+	in6p_flowinfo(inp) &= ~IPV6_FLOWLABEL_MASK;
 #if defined(IPSEC)
 	if (ipsec_enabled)
 		ipsec_pcbdisconn(inp->inp_sp);
@@ -569,7 +569,7 @@ in6_setsockaddr(struct inpcb *inp, struc
 	if (inp->inp_af != AF_INET6)
 		return;
 
-	sockaddr_in6_init(sin6, &inp->inp_laddr6, inp->inp_lport, 0, 0);
+	sockaddr_in6_init(sin6, &in6p_laddr(inp), inp->inp_lport, 0, 0);
 	(void)sa6_recoverscope(sin6); /* XXX: should catch errors */
 }
 
@@ -580,7 +580,7 @@ in6_setpeeraddr(struct inpcb *inp, struc
 	if (inp->inp_af != AF_INET6)
 		return;
 
-	sockaddr_in6_init(sin6, &inp->inp_faddr6, inp->inp_fport, 0, 0);
+	sockaddr_in6_init(sin6, &in6p_faddr(inp), inp->inp_fport, 0, 0);
 	(void)sa6_recoverscope(sin6); /* XXX: should catch errors */
 }
 
@@ -680,7 +680,7 @@ in6_pcbnotify(struct inpcbtable *table, 
 		 *   icmp6_mtudisc_update().
 		 */
 		if ((PRC_IS_REDIRECT(cmd) || cmd == PRC_HOSTDEAD) &&
-		    IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) &&
+		    IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)) &&
 		    (rt = rtcache_validate(&inp->inp_route)) != NULL &&
 		    !(rt->rt_flags & RTF_HOST)) {
 			const struct sockaddr_in6 *dst6;
@@ -707,8 +707,8 @@ in6_pcbnotify(struct inpcbtable *table, 
 		 * XXX: should we avoid to notify the value to TCP sockets?
 		 */
 		if (cmd == PRC_MSGSIZE && (inp->inp_flags & IN6P_MTU) != 0 &&
-		    (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6) ||
-		     IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, &sa6_dst->sin6_addr))) {
+		    (IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp)) ||
+		     IN6_ARE_ADDR_EQUAL(&in6p_faddr(inp), &sa6_dst->sin6_addr))) {
 			ip6_notify_pmtu(inp, (const struct sockaddr_in6 *)dst,
 					(u_int32_t *)cmdarg);
 		}
@@ -723,15 +723,15 @@ in6_pcbnotify(struct inpcbtable *table, 
 		 */
 		if (lport == 0 && fport == 0 && flowinfo &&
 		    inp->inp_socket != NULL &&
-		    flowinfo == (inp->inp_flowinfo & IPV6_FLOWLABEL_MASK) &&
-		    IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &sa6_src.sin6_addr))
+		    flowinfo == (in6p_flowinfo(inp) & IPV6_FLOWLABEL_MASK) &&
+		    IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), &sa6_src.sin6_addr))
 			goto do_notify;
-		else if (!IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6,
+		else if (!IN6_ARE_ADDR_EQUAL(&in6p_faddr(inp),
 					     &sa6_dst->sin6_addr) ||
 		    inp->inp_socket == NULL ||
 		    (lport && inp->inp_lport != lport) ||
 		    (!IN6_IS_ADDR_UNSPECIFIED(&sa6_src.sin6_addr) &&
-		     !IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6,
+		     !IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp),
 					 &sa6_src.sin6_addr)) ||
 		    (fport && inp->inp_fport != fport))
 			continue;
@@ -763,7 +763,7 @@ in6_pcbpurgeif0(struct inpcbtable *table
 			inp_lock(inp);
 			need_unlock = true;
 		}
-		im6o = inp->inp_moptions6;
+		im6o = in6p_moptions(inp);
 		if (im6o) {
 			/*
 			 * Unselect the outgoing interface if it is being
@@ -849,13 +849,13 @@ in6_pcblookup_port(struct inpcbtable *ta
 		if (inp->inp_lport != lport)
 			continue;
 		wildcard = 0;
-		if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) {
+		if (IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp))) {
 			if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)
 				continue;
 		}
-		if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6))
+		if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp)))
 			wildcard++;
-		if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6)) {
+		if (IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp))) {
 			if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)
 				continue;
 			if (!IN6_IS_ADDR_V4MAPPED(laddr6))
@@ -863,22 +863,22 @@ in6_pcblookup_port(struct inpcbtable *ta
 
 			/* duplicate of IPv4 logic */
 			wildcard = 0;
-			if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6) &&
-			    inp->inp_faddr6.s6_addr32[3])
+			if (IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp)) &&
+			    in6p_faddr(inp).s6_addr32[3])
 				wildcard++;
-			if (!inp->inp_laddr6.s6_addr32[3]) {
+			if (!in6p_laddr(inp).s6_addr32[3]) {
 				if (laddr6->s6_addr32[3])
 					wildcard++;
 			} else {
 				if (!laddr6->s6_addr32[3])
 					wildcard++;
 				else {
-					if (inp->inp_laddr6.s6_addr32[3] !=
+					if (in6p_laddr(inp).s6_addr32[3] !=
 					    laddr6->s6_addr32[3])
 						continue;
 				}
 			}
-		} else if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) {
+		} else if (IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp))) {
 			if (IN6_IS_ADDR_V4MAPPED(laddr6)) {
 				if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)
 					continue;
@@ -893,7 +893,7 @@ in6_pcblookup_port(struct inpcbtable *ta
 			if (IN6_IS_ADDR_UNSPECIFIED(laddr6))
 				wildcard++;
 			else {
-				if (!IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6,
+				if (!IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp),
 				    laddr6))
 					continue;
 			}
@@ -988,27 +988,27 @@ in6_pcbrtentry(struct inpcb *inp)
 		;
 #ifdef INET
 	else if (cdst.sa->sa_family == AF_INET) {
-		KASSERT(IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6));
-		if (cdst.sa4->sin_addr.s_addr != inp->inp_faddr6.s6_addr32[3])
+		KASSERT(IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp)));
+		if (cdst.sa4->sin_addr.s_addr != in6p_faddr(inp).s6_addr32[3])
 			rtcache_free(ro);
 	}
 #endif
 	else {
 		if (!IN6_ARE_ADDR_EQUAL(&cdst.sa6->sin6_addr,
-					&inp->inp_faddr6))
+					&in6p_faddr(inp)))
 			rtcache_free(ro);
 	}
 	if ((rt = rtcache_validate(ro)) == NULL)
 		rt = rtcache_update(ro, 1);
 #ifdef INET
-	if (rt == NULL && IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) {
+	if (rt == NULL && IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp))) {
 		union {
 			struct sockaddr		dst;
 			struct sockaddr_in	dst4;
 		} u;
 		struct in_addr addr;
 
-		addr.s_addr = inp->inp_faddr6.s6_addr32[3];
+		addr.s_addr = in6p_faddr(inp).s6_addr32[3];
 
 		sockaddr_in_init(&u.dst4, &addr, 0);
 		if (rtcache_setdst(ro, &u.dst) != 0)
@@ -1017,13 +1017,13 @@ in6_pcbrtentry(struct inpcb *inp)
 		rt = rtcache_init(ro);
 	} else
 #endif
-	if (rt == NULL && !IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) {
+	if (rt == NULL && !IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp))) {
 		union {
 			struct sockaddr		dst;
 			struct sockaddr_in6	dst6;
 		} u;
 
-		sockaddr_in6_init(&u.dst6, &inp->inp_faddr6, 0, 0, 0);
+		sockaddr_in6_init(&u.dst6, &in6p_faddr(inp), 0, 0, 0);
 		if (rtcache_setdst(ro, &u.dst) != 0)
 			return NULL;
 
@@ -1062,13 +1062,13 @@ in6_pcblookup_connect(struct inpcbtable 
 			continue;
 		if (inp->inp_lport != lport)
 			continue;
-		if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6))
+		if (IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp)))
 			continue;
-		if (!IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, faddr6))
+		if (!IN6_ARE_ADDR_EQUAL(&in6p_faddr(inp), faddr6))
 			continue;
-		if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6))
+		if (IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)))
 			continue;
-		if (!IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, laddr6))
+		if (!IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), laddr6))
 			continue;
 		if ((IN6_IS_ADDR_V4MAPPED(laddr6) ||
 		     IN6_IS_ADDR_V4MAPPED(faddr6)) &&
@@ -1110,7 +1110,7 @@ in6_pcblookup_bind(struct inpcbtable *ta
 		if (IN6_IS_ADDR_V4MAPPED(laddr6) &&
 		    (inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)
 			continue;
-		if (IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, laddr6))
+		if (IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), laddr6))
 			goto out;
 	}
 #ifdef INET
@@ -1130,7 +1130,7 @@ in6_pcblookup_bind(struct inpcbtable *ta
 				continue;
 			if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)
 				continue;
-			if (IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &zero_mapped))
+			if (IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), &zero_mapped))
 				goto out;
 		}
 	}
@@ -1149,7 +1149,7 @@ in6_pcblookup_bind(struct inpcbtable *ta
 		if (IN6_IS_ADDR_V4MAPPED(laddr6) &&
 		    (inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)
 			continue;
-		if (IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &zeroin6_addr))
+		if (IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), &zeroin6_addr))
 			goto out;
 	}
 	return (NULL);
@@ -1175,13 +1175,13 @@ in6_pcbstate(struct inpcb *inp, int stat
 	switch (state) {
 	case INP_BOUND:
 		LIST_INSERT_HEAD(IN6PCBHASH_BIND(inp->inp_table,
-		    &inp->inp_laddr6, inp->inp_lport), inp,
+		    &in6p_laddr(inp), inp->inp_lport), inp,
 		    inp_hash);
 		break;
 	case INP_CONNECTED:
 		LIST_INSERT_HEAD(IN6PCBHASH_CONNECT(inp->inp_table,
-		    &inp->inp_faddr6, inp->inp_fport,
-		    &inp->inp_laddr6, inp->inp_lport), inp,
+		    &in6p_faddr(inp), inp->inp_fport,
+		    &in6p_laddr(inp), inp->inp_lport), inp,
 		    inp_hash);
 		break;
 	}

Index: src/sys/netinet6/in6_src.c
diff -u src/sys/netinet6/in6_src.c:1.89 src/sys/netinet6/in6_src.c:1.90
--- src/sys/netinet6/in6_src.c:1.89	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet6/in6_src.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_src.c,v 1.89 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: in6_src.c,v 1.90 2022/10/28 05:25:36 ozaki-r Exp $	*/
 /*	$KAME: in6_src.c,v 1.159 2005/10/19 01:40:32 t-momose Exp $	*/
 
 /*
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.89 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.90 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -811,8 +811,8 @@ out:
 int
 in6_selecthlim(struct inpcb *inp, struct ifnet *ifp)
 {
-	if (inp && inp->inp_hops6 >= 0)
-		return (inp->inp_hops6);
+	if (inp && in6p_hops6(inp) >= 0)
+		return in6p_hops6(inp);
 	else if (ifp)
 		return (ND_IFINFO(ifp)->chlim);
 	else

Index: src/sys/netinet6/ip6_output.c
diff -u src/sys/netinet6/ip6_output.c:1.230 src/sys/netinet6/ip6_output.c:1.231
--- src/sys/netinet6/ip6_output.c:1.230	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet6/ip6_output.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_output.c,v 1.230 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_output.c,v 1.231 2022/10/28 05:25:36 ozaki-r Exp $	*/
 /*	$KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.230 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.231 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1341,7 +1341,7 @@ ip6_ctloutput(int op, struct socket *so,
 		switch (optname) {
 #ifdef RFC2292
 		case IPV6_2292PKTOPTIONS:
-			error = ip6_pcbopts(&inp->inp_outputopts6, so, sopt);
+			error = ip6_pcbopts(&in6p_outputopts(inp), so, sopt);
 			break;
 #endif
 
@@ -1388,7 +1388,7 @@ ip6_ctloutput(int op, struct socket *so,
 					error = EINVAL;
 				else {
 					/* -1 = kernel default */
-					inp->inp_hops6 = optval;
+					in6p_hops6(inp) = optval;
 				}
 				break;
 #define OPTSET(bit) \
@@ -1434,7 +1434,7 @@ else 					\
 					break;
 				}
 #endif
-				optp = &inp->inp_outputopts6;
+				optp = &in6p_outputopts(inp);
 				error = ip6_pcbopt(IPV6_HOPLIMIT,
 						   (u_char *)&optval,
 						   sizeof(optval),
@@ -1520,7 +1520,7 @@ else 					\
 				 * see ipng mailing list, Jun 22 2001.
 				 */
 				if (inp->inp_lport ||
-				    !IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) {
+				    !IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp))) {
 					error = EINVAL;
 					break;
 				}
@@ -1563,7 +1563,7 @@ else 					\
 			error = sockopt_get(sopt, &tclass, sizeof(tclass));
 			if (error)
 				break;
-			optp = &inp->inp_outputopts6;
+			optp = &in6p_outputopts(inp);
 			error = ip6_pcbopt(optname,
 					   (u_char *)&tclass,
 					   sizeof(tclass),
@@ -1581,7 +1581,7 @@ else 					\
 				break;
 			{
 				struct ip6_pktopts **optp;
-				optp = &inp->inp_outputopts6;
+				optp = &in6p_outputopts(inp);
 				error = ip6_pcbopt(optname,
 						   (u_char *)&optval,
 						   sizeof(optval),
@@ -1669,7 +1669,7 @@ else 					\
 				free(optbuf, M_IP6OPT);
 				break;
 			}
-			optp = &inp->inp_outputopts6;
+			optp = &in6p_outputopts(inp);
 			error = ip6_pcbopt(optname, optbuf, optbuflen,
 			    optp, kauth_cred_get(), uproto);
 
@@ -1783,7 +1783,7 @@ else 					\
 				break;
 
 			case IPV6_UNICAST_HOPS:
-				optval = inp->inp_hops6;
+				optval = in6p_hops6(inp);
 				break;
 
 			case IPV6_RECVPKTINFO:
@@ -1854,7 +1854,7 @@ else 					\
 			 * routing, or optional information to specify
 			 * the outgoing interface.
 			 */
-			sockaddr_in6_init(&u.dst6, &inp->inp_faddr6, 0, 0, 0);
+			sockaddr_in6_init(&u.dst6, &in6p_faddr(inp), 0, 0, 0);
 			rt = rtcache_lookup(ro, &u.dst);
 			error = ip6_getpmtu(rt, NULL, &pmtu, NULL);
 			rtcache_unref(rt, ro);
@@ -1910,7 +1910,7 @@ else 					\
 		case IPV6_DONTFRAG:
 		case IPV6_USE_MIN_MTU:
 		case IPV6_PREFER_TEMPADDR:
-			error = ip6_getpcbopt(inp->inp_outputopts6,
+			error = ip6_getpcbopt(in6p_outputopts(inp),
 			    optname, sopt);
 			break;
 
@@ -1994,14 +1994,14 @@ ip6_raw_ctloutput(int op, struct socket 
 				if (optval != icmp6off)
 					error = EINVAL;
 			} else
-				inp->inp_cksum6 = optval;
+				in6p_cksum(inp) = optval;
 			break;
 
 		case PRCO_GETOPT:
 			if (so->so_proto->pr_protocol == IPPROTO_ICMPV6)
 				optval = icmp6off;
 			else
-				optval = inp->inp_cksum6;
+				optval = in6p_cksum(inp);
 
 			error = sockopt_setint(sopt, optval);
 			break;
@@ -2429,7 +2429,7 @@ ip6_setmoptions(const struct sockopt *so
 	struct ipv6_mreq mreq;
 	struct in6_addr ia;
 	struct ifnet *ifp;
-	struct ip6_moptions *im6o = inp->inp_moptions6;
+	struct ip6_moptions *im6o = in6p_moptions(inp);
 	struct in6_multi_mship *imm;
 
 	KASSERT(inp_locked(inp));
@@ -2442,7 +2442,7 @@ ip6_setmoptions(const struct sockopt *so
 		im6o = malloc(sizeof(*im6o), M_IPMOPTS, M_NOWAIT);
 		if (im6o == NULL)
 			return (ENOBUFS);
-		inp->inp_moptions6 = im6o;
+		in6p_moptions(inp) = im6o;
 		im6o->im6o_multicast_if_index = 0;
 		im6o->im6o_multicast_hlim = ip6_defmcasthlim;
 		im6o->im6o_multicast_loop = IPV6_DEFAULT_MULTICAST_LOOP;
@@ -2674,8 +2674,8 @@ ip6_setmoptions(const struct sockopt *so
 	    im6o->im6o_multicast_hlim == ip6_defmcasthlim &&
 	    im6o->im6o_multicast_loop == IPV6_DEFAULT_MULTICAST_LOOP &&
 	    LIST_EMPTY(&im6o->im6o_memberships)) {
-		free(inp->inp_moptions6, M_IPMOPTS);
-		inp->inp_moptions6 = NULL;
+		free(in6p_moptions(inp), M_IPMOPTS);
+		in6p_moptions(inp) = NULL;
 	}
 
 	return (error);
@@ -2689,7 +2689,7 @@ ip6_getmoptions(struct sockopt *sopt, st
 {
 	u_int optval;
 	int error;
-	struct ip6_moptions *im6o = inp->inp_moptions6;
+	struct ip6_moptions *im6o = in6p_moptions(inp);
 
 	switch (sopt->sopt_name) {
 	case IPV6_MULTICAST_IF:
@@ -3302,17 +3302,17 @@ ip6_optlen(struct inpcb *inp)
 {
 	int len;
 
-	if (!inp->inp_outputopts6)
+	if (!in6p_outputopts(inp))
 		return 0;
 
 	len = 0;
 #define elen(x) \
     (((struct ip6_ext *)(x)) ? (((struct ip6_ext *)(x))->ip6e_len + 1) << 3 : 0)
 
-	len += elen(inp->inp_outputopts6->ip6po_hbh);
-	len += elen(inp->inp_outputopts6->ip6po_dest1);
-	len += elen(inp->inp_outputopts6->ip6po_rthdr);
-	len += elen(inp->inp_outputopts6->ip6po_dest2);
+	len += elen(in6p_outputopts(inp)->ip6po_hbh);
+	len += elen(in6p_outputopts(inp)->ip6po_dest1);
+	len += elen(in6p_outputopts(inp)->ip6po_rthdr);
+	len += elen(in6p_outputopts(inp)->ip6po_dest2);
 	return len;
 #undef elen
 }

Index: src/sys/netinet6/raw_ip6.c
diff -u src/sys/netinet6/raw_ip6.c:1.179 src/sys/netinet6/raw_ip6.c:1.180
--- src/sys/netinet6/raw_ip6.c:1.179	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet6/raw_ip6.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: raw_ip6.c,v 1.179 2022/10/28 05:18:39 ozaki-r Exp $	*/
+/*	$NetBSD: raw_ip6.c,v 1.180 2022/10/28 05:25:36 ozaki-r Exp $	*/
 /*	$KAME: raw_ip6.c,v 1.82 2001/07/23 18:57:56 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: raw_ip6.c,v 1.179 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_ip6.c,v 1.180 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -191,16 +191,16 @@ rip6_input(struct mbuf **mp, int *offp, 
 	TAILQ_FOREACH(inp, &raw6cbtable.inpt_queue, inp_queue) {
 		if (inp->inp_af != AF_INET6)
 			continue;
-		if (inp->inp_ip6.ip6_nxt &&
-		    inp->inp_ip6.ip6_nxt != proto)
+		if (in6p_ip6(inp).ip6_nxt &&
+		    in6p_ip6(inp).ip6_nxt != proto)
 			continue;
-		if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) &&
-		    !IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &ip6->ip6_dst))
+		if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)) &&
+		    !IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), &ip6->ip6_dst))
 			continue;
-		if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6) &&
-		    !IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, &ip6->ip6_src))
+		if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp)) &&
+		    !IN6_ARE_ADDR_EQUAL(&in6p_faddr(inp), &ip6->ip6_src))
 			continue;
-		if (inp->inp_cksum6 != -1) {
+		if (in6p_cksum(inp) != -1) {
 			RIP6_STATINC(RIP6_STAT_ISUM);
 			if (in6_cksum(m, proto, *offp,
 			    m->m_pkthdr.len - *offp)) {
@@ -323,8 +323,8 @@ rip6_ctlinput(int cmd, const struct sock
 		}
 #endif
 
-		if (inp && inp->inp_ip6.ip6_nxt &&
-		    inp->inp_ip6.ip6_nxt == nxt)
+		if (inp && in6p_ip6(inp).ip6_nxt &&
+		    in6p_ip6(inp).ip6_nxt == nxt)
 			valid++;
 
 		/*
@@ -375,13 +375,13 @@ rip6_output(struct mbuf *m, struct socke
 	dst = &dstsock->sin6_addr;
 	if (control) {
 		if ((error = ip6_setpktopts(control, &opt,
-		    inp->inp_outputopts6,
+		    in6p_outputopts(inp),
 		    kauth_cred_get(), so->so_proto->pr_protocol)) != 0) {
 			goto bad;
 		}
 		optp = &opt;
 	} else
-		optp = inp->inp_outputopts6;
+		optp = in6p_outputopts(inp);
 
 	/*
 	 * Check and convert scope zone ID into internal form.
@@ -428,8 +428,8 @@ rip6_output(struct mbuf *m, struct socke
 	/*
 	 * Source address selection.
 	 */
-	error = in6_selectsrc(dstsock, optp, inp->inp_moptions6,
-	    &inp->inp_route, &inp->inp_laddr6, &oifp, &psref, &ip6->ip6_src);
+	error = in6_selectsrc(dstsock, optp, in6p_moptions(inp),
+	    &inp->inp_route, &in6p_laddr(inp), &oifp, &psref, &ip6->ip6_src);
 	if (error != 0)
 		goto bad;
 
@@ -449,18 +449,18 @@ rip6_output(struct mbuf *m, struct socke
 	ip6->ip6_dst = dstsock->sin6_addr;
 
 	/* fill in the rest of the IPv6 header fields */
-	ip6->ip6_flow = inp->inp_flowinfo & IPV6_FLOWINFO_MASK;
+	ip6->ip6_flow = in6p_flowinfo(inp) & IPV6_FLOWINFO_MASK;
 	ip6->ip6_vfc  &= ~IPV6_VERSION_MASK;
 	ip6->ip6_vfc  |= IPV6_VERSION;
 	/* ip6_plen will be filled in ip6_output, so not fill it here. */
-	ip6->ip6_nxt   = inp->inp_ip6.ip6_nxt;
+	ip6->ip6_nxt   = in6p_ip6(inp).ip6_nxt;
 	ip6->ip6_hlim = in6_selecthlim(inp, oifp);
 
 	if_put(oifp, &psref);
 	oifp = NULL;
 
 	if (so->so_proto->pr_protocol == IPPROTO_ICMPV6 ||
-	    inp->inp_cksum6 != -1) {
+	    in6p_cksum(inp) != -1) {
 		const uint8_t nxt = ip6->ip6_nxt;
 		int off;
 		u_int16_t sum;
@@ -469,7 +469,7 @@ rip6_output(struct mbuf *m, struct socke
 		if (so->so_proto->pr_protocol == IPPROTO_ICMPV6)
 			off = offsetof(struct icmp6_hdr, icmp6_cksum);
 		else
-			off = inp->inp_cksum6;
+			off = in6p_cksum(inp);
 		if (plen < off + 1) {
 			error = EINVAL;
 			goto bad;
@@ -496,7 +496,7 @@ rip6_output(struct mbuf *m, struct socke
 		struct ifnet *ret_oifp = NULL;
 
 		error = ip6_output(m, optp, &inp->inp_route, 0,
-		    inp->inp_moptions6, inp, &ret_oifp);
+		    in6p_moptions(inp), inp, &ret_oifp);
 		if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) {
 			if (ret_oifp)
 				icmp6_ifoutstat_inc(ret_oifp, type, code);
@@ -604,11 +604,11 @@ rip6_attach(struct socket *so, int proto
 	}
 	splx(s);
 	inp = sotoinpcb(so);
-	inp->inp_ip6.ip6_nxt = proto;
-	inp->inp_cksum6 = -1;
+	in6p_ip6(inp).ip6_nxt = proto;
+	in6p_cksum(inp) = -1;
 
-	inp->inp_icmp6filt = kmem_alloc(sizeof(struct icmp6_filter), KM_SLEEP);
-	ICMP6_FILTER_SETPASSALL(inp->inp_icmp6filt);
+	in6p_icmp6filt(inp) = kmem_alloc(sizeof(struct icmp6_filter), KM_SLEEP);
+	ICMP6_FILTER_SETPASSALL(in6p_icmp6filt(inp));
 	KASSERT(solocked(so));
 	return error;
 }
@@ -625,9 +625,9 @@ rip6_detach(struct socket *so)
 		ip6_mrouter_done();
 	}
 	/* xxx: RSVP */
-	if (inp->inp_icmp6filt != NULL) {
-		kmem_free(inp->inp_icmp6filt, sizeof(struct icmp6_filter));
-		inp->inp_icmp6filt = NULL;
+	if (in6p_icmp6filt(inp) != NULL) {
+		kmem_free(in6p_icmp6filt(inp), sizeof(struct icmp6_filter));
+		in6p_icmp6filt(inp) = NULL;
 	}
 	in_pcbdetach(inp);
 }
@@ -679,7 +679,7 @@ rip6_bind(struct socket *so, struct sock
 		goto out;
 	}
 
-	inp->inp_laddr6 = addr->sin6_addr;
+	in6p_laddr(inp) = addr->sin6_addr;
 	error = 0;
 out:
 	pserialize_read_exit(s);
@@ -732,9 +732,9 @@ rip6_connect(struct socket *so, struct s
 
 	bound = curlwp_bind();
 	/* Source address selection. XXX: need pcblookup? */
-	error = in6_selectsrc(addr, inp->inp_outputopts6,
-	    inp->inp_moptions6, &inp->inp_route,
-	    &inp->inp_laddr6, &ifp, &psref, &in6a);
+	error = in6_selectsrc(addr, in6p_outputopts(inp),
+	    in6p_moptions(inp), &inp->inp_route,
+	    &in6p_laddr(inp), &ifp, &psref, &in6a);
 	if (error != 0)
 		goto out;
 	/* XXX: see above */
@@ -742,8 +742,8 @@ rip6_connect(struct socket *so, struct s
 	    (error = in6_setscope(&addr->sin6_addr, ifp, NULL)) != 0) {
 		goto out;
 	}
-	inp->inp_laddr6 = in6a;
-	inp->inp_faddr6 = addr->sin6_addr;
+	in6p_laddr(inp) = in6a;
+	in6p_faddr(inp) = addr->sin6_addr;
 	soisconnected(so);
 out:
 	if_put(ifp, &psref);
@@ -770,7 +770,7 @@ rip6_disconnect(struct socket *so)
 	if ((so->so_state & SS_ISCONNECTED) == 0)
 		return ENOTCONN;
 
-	inp->inp_faddr6 = in6addr_any;
+	in6p_faddr(inp) = in6addr_any;
 	so->so_state &= ~SS_ISCONNECTED;	/* XXX */
 	return 0;
 }
@@ -875,7 +875,7 @@ rip6_send(struct socket *so, struct mbuf
 			goto release;
 		}
 		/* XXX */
-		sockaddr_in6_init(&tmp, &inp->inp_faddr6, 0, 0, 0);
+		sockaddr_in6_init(&tmp, &in6p_faddr(inp), 0, 0, 0);
 		dst = &tmp;
 	} else {
 		if (nam == NULL) {

Index: src/sys/netinet6/udp6_usrreq.c
diff -u src/sys/netinet6/udp6_usrreq.c:1.151 src/sys/netinet6/udp6_usrreq.c:1.152
--- src/sys/netinet6/udp6_usrreq.c:1.151	Fri Oct 28 05:18:39 2022
+++ src/sys/netinet6/udp6_usrreq.c	Fri Oct 28 05:25:36 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: udp6_usrreq.c,v 1.151 2022/10/28 05:18:39 ozaki-r Exp $ */
+/* $NetBSD: udp6_usrreq.c,v 1.152 2022/10/28 05:25:36 ozaki-r Exp $ */
 /* $KAME: udp6_usrreq.c,v 1.86 2001/05/27 17:33:00 itojun Exp $ */
 /* $KAME: udp6_output.c,v 1.43 2001/10/15 09:19:52 itojun Exp $ */
 
@@ -63,7 +63,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.151 2022/10/28 05:18:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.152 2022/10/28 05:25:36 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -474,8 +474,8 @@ udp6_realinput(int af, struct sockaddr_i
 
 			if (inp->inp_lport != dport)
 				continue;
-			if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) {
-				if (!IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6,
+			if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp))) {
+				if (!IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp),
 				    dst6))
 					continue;
 			} else {
@@ -483,8 +483,8 @@ udp6_realinput(int af, struct sockaddr_i
 				    (inp->inp_flags & IN6P_IPV6_V6ONLY))
 					continue;
 			}
-			if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) {
-				if (!IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6,
+			if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp))) {
+				if (!IN6_ARE_ADDR_EQUAL(&in6p_faddr(inp),
 				    &src6) || inp->inp_fport != sport)
 					continue;
 			} else {
@@ -788,11 +788,11 @@ udp6_output(struct inpcb * const inp, st
 			panic("%s: control but no lwp", __func__);
 		}
 		if ((error = ip6_setpktopts(control, &opt,
-		    inp->inp_outputopts6, l->l_cred, IPPROTO_UDP)) != 0)
+		    in6p_outputopts(inp), l->l_cred, IPPROTO_UDP)) != 0)
 			goto release;
 		optp = &opt;
 	} else
-		optp = inp->inp_outputopts6;
+		optp = in6p_outputopts(inp);
 
 
 	if (sin6) {
@@ -808,7 +808,7 @@ udp6_output(struct inpcb * const inp, st
 			goto release;
 		}
 
-		if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) {
+		if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp))) {
 			/* how about ::ffff:0.0.0.0 case? */
 			error = EISCONN;
 			goto release;
@@ -832,8 +832,8 @@ udp6_output(struct inpcb * const inp, st
 				error = EINVAL;
 				goto release;
 			}
-			if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) &&
-			    !IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6)) {
+			if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)) &&
+			    !IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp))) {
 				/*
 				 * when remote addr is an IPv4-mapped address,
 				 * local addr should not be an IPv6 address,
@@ -852,9 +852,9 @@ udp6_output(struct inpcb * const inp, st
 			int bound = curlwp_bind();
 
 			error = in6_selectsrc(sin6, optp,
-			    inp->inp_moptions6,
+			    in6p_moptions(inp),
 			    &inp->inp_route,
-			    &inp->inp_laddr6, &oifp, &psref, &_laddr);
+			    &in6p_laddr(inp), &oifp, &psref, &_laddr);
 			if (error)
 				laddr = NULL;
 			else
@@ -875,7 +875,7 @@ udp6_output(struct inpcb * const inp, st
 			 * udp_output() directly in this case, and thus we'll
 			 * never see this path.
 			 */
-			if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) {
+			if (IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp))) {
 				struct sockaddr_in sin_dst;
 				struct in_addr ina;
 				struct in_ifaddr *ia4;
@@ -904,7 +904,7 @@ udp6_output(struct inpcb * const inp, st
 				laddr = &laddr_mapped;
 			} else
 			{
-				laddr = &inp->inp_laddr6;	/* XXX */
+				laddr = &in6p_laddr(inp);	/* XXX */
 			}
 		}
 		if (laddr == NULL) {
@@ -928,16 +928,16 @@ udp6_output(struct inpcb * const inp, st
 			error = in6_pcbsetport(&lsin6, inp, l);
 
 			if (error) {
-				inp->inp_laddr6 = in6addr_any;
+				in6p_laddr(inp) = in6addr_any;
 				goto release;
 			}
 		}
 	} else {
-		if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) {
+		if (IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp))) {
 			error = ENOTCONN;
 			goto release;
 		}
-		if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) {
+		if (IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp))) {
 			if ((inp->inp_flags & IN6P_IPV6_V6ONLY))
 			{
 				/*
@@ -954,8 +954,8 @@ udp6_output(struct inpcb * const inp, st
 			} else
 				af = AF_INET;
 		}
-		laddr = &inp->inp_laddr6;
-		faddr = &inp->inp_faddr6;
+		laddr = &in6p_laddr(inp);
+		faddr = &in6p_faddr(inp);
 		fport = inp->inp_fport;
 	}
 
@@ -987,7 +987,7 @@ udp6_output(struct inpcb * const inp, st
 	switch (af) {
 	case AF_INET6:
 		ip6 = mtod(m, struct ip6_hdr *);
-		ip6->ip6_flow	= inp->inp_flowinfo & IPV6_FLOWINFO_MASK;
+		ip6->ip6_flow	= in6p_flowinfo(inp) & IPV6_FLOWINFO_MASK;
 		ip6->ip6_vfc 	&= ~IPV6_VERSION_MASK;
 		ip6->ip6_vfc 	|= IPV6_VERSION;
 #if 0		/* ip6_plen will be filled in ip6_output. */
@@ -1005,7 +1005,7 @@ udp6_output(struct inpcb * const inp, st
 
 		UDP6_STATINC(UDP6_STAT_OPACKETS);
 		error = ip6_output(m, optp, &inp->inp_route, 0,
-		    inp->inp_moptions6, inp, NULL);
+		    in6p_moptions(inp), inp, NULL);
 		break;
 	case AF_INET:
 #ifdef INET
@@ -1084,7 +1084,7 @@ udp6_attach(struct socket *so, int proto
 	}
 
 	inp = sotoinpcb(so);
-	inp->inp_cksum6 = -1;	/* just to be sure */
+	in6p_cksum(inp) = -1;	/* just to be sure */
 
 	KASSERT(solocked(so));
 	return 0;
@@ -1147,7 +1147,7 @@ udp6_connect(struct socket *so, struct s
 	KASSERT(solocked(so));
 	KASSERT(inp != NULL);
 
-	if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6))
+	if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp)))
 		return EISCONN;
 	s = splsoftnet();
 	error = in6_pcbconnect(inp, (struct sockaddr_in6 *)nam, l);
@@ -1175,12 +1175,12 @@ udp6_disconnect(struct socket *so)
 	KASSERT(solocked(so));
 	KASSERT(inp != NULL);
 
-	if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6))
+	if (IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp)))
 		return ENOTCONN;
 
 	s = splsoftnet();
 	in6_pcbdisconnect(inp);
-	memset((void *)&inp->inp_laddr6, 0, sizeof(inp->inp_laddr6));
+	memset((void *)&in6p_laddr(inp), 0, sizeof(in6p_laddr(inp)));
 	splx(s);
 
 	so->so_state &= ~SS_ISCONNECTED;	/* XXX */

Reply via email to