Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys inpcb: separate inpcb again to reduce the size of PCB fo...
details: https://anonhg.NetBSD.org/src/rev/f98282c03752
branches: trunk
changeset: 372132:f98282c03752
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Fri Oct 28 05:25:36 2022 +0000
description:
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).
diffstat:
sys/netinet/in_pcb.c | 111 ++++++++++++++++++++++----------------
sys/netinet/in_pcb.h | 69 ++++++++++++++---------
sys/netinet/ip_output.c | 24 ++++----
sys/netinet/portalgo.c | 38 ++++++------
sys/netinet/raw_ip.c | 32 +++++-----
sys/netinet/tcp_input.c | 12 ++--
sys/netinet/tcp_output.c | 26 ++++----
sys/netinet/tcp_subr.c | 58 ++++++++++----------
sys/netinet/tcp_syncache.c | 18 +++---
sys/netinet/tcp_timer.c | 6 +-
sys/netinet/tcp_usrreq.c | 20 +++---
sys/netinet/tcp_vtw.c | 30 +++++-----
sys/netinet/udp_usrreq.c | 28 ++++----
sys/netinet6/icmp6.c | 24 ++++----
sys/netinet6/in6_pcb.c | 130 ++++++++++++++++++++++----------------------
sys/netinet6/in6_src.c | 8 +-
sys/netinet6/ip6_output.c | 48 ++++++++--------
sys/netinet6/raw_ip6.c | 70 ++++++++++++------------
sys/netinet6/udp6_usrreq.c | 52 +++++++++---------
19 files changed, 417 insertions(+), 387 deletions(-)
diffs (truncated from 2455 to 300 lines):
diff -r 841f5a43a67d -r f98282c03752 sys/netinet/in_pcb.c
--- a/sys/netinet/in_pcb.c Fri Oct 28 05:24:07 2022 +0000
+++ b/sys/netinet/in_pcb.c Fri Oct 28 05:25:36 2022 +0000
@@ -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 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 @@
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 @@
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 @@
*/
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 @@
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 @@
/* 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 @@
* 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 @@
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 @@
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 @@
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 @@
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);
+ 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));
}
- rtcache_free(&inp->inp_route);
- ip6_freemoptions(inp->inp_moptions6);
- ip_freemoptions(inp->inp_moptions);
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 @@
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 @@
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 @@
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 @@
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 @@
* 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 @@
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 @@
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 @@
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 @@
switch (state) {
case INP_BOUND:
LIST_INSERT_HEAD(INPCBHASH_BIND(inp->inp_table,
Home |
Main Index |
Thread Index |
Old Index