git: e3ba0d6adde3 - main - inpcb: do not copy so_options into inp_flags2
Date: Thu, 27 Jul 2023 03:51:36 UTC
The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=e3ba0d6adde3c694f46a30b3b67eba43a7099395 commit e3ba0d6adde3c694f46a30b3b67eba43a7099395 Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2023-07-27 03:35:41 +0000 Commit: Gleb Smirnoff <glebius@FreeBSD.org> CommitDate: 2023-07-27 03:35:42 +0000 inpcb: do not copy so_options into inp_flags2 Since f71cb9f74808 socket stays connnected with inpcb through latter's lifetime and there is no reason to complicate things and copy these flags. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D41198 --- sys/netinet/in_pcb.c | 29 +++++------------------------ sys/netinet/in_pcb.h | 7 +++---- sys/netinet/ip_output.c | 27 --------------------------- sys/netinet6/in6_pcb.c | 12 ++++++------ sys/netinet6/ip6_output.c | 27 --------------------------- 5 files changed, 14 insertions(+), 88 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 44775e21e201..e7b5e3221ae4 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -850,25 +850,6 @@ in_pcb_lport(struct inpcb *inp, struct in_addr *laddrp, u_short *lportp, return (in_pcb_lport_dest(inp, laddrp ? (struct sockaddr *) &laddr : NULL, lportp, NULL, 0, cred, lookupflags)); } - -/* - * Return cached socket options. - */ -int -inp_so_options(const struct inpcb *inp) -{ - int so_options; - - so_options = 0; - - if ((inp->inp_flags2 & INP_REUSEPORT_LB) != 0) - so_options |= SO_REUSEPORT_LB; - if ((inp->inp_flags2 & INP_REUSEPORT) != 0) - so_options |= SO_REUSEPORT; - if ((inp->inp_flags2 & INP_REUSEADDR) != 0) - so_options |= SO_REUSEADDR; - return (so_options); -} #endif /* INET || INET6 */ #ifdef INET @@ -979,16 +960,16 @@ in_pcbbind_setup(struct inpcb *inp, struct sockaddr_in *sin, in_addr_t *laddrp, ntohl(t->inp_faddr.s_addr) == INADDR_ANY) && (ntohl(sin->sin_addr.s_addr) != INADDR_ANY || ntohl(t->inp_laddr.s_addr) != INADDR_ANY || - (t->inp_flags2 & INP_REUSEPORT) || - (t->inp_flags2 & INP_REUSEPORT_LB) == 0) && + (t->inp_socket->so_options & SO_REUSEPORT) || + (t->inp_socket->so_options & SO_REUSEPORT_LB) == 0) && (inp->inp_cred->cr_uid != t->inp_cred->cr_uid)) return (EADDRINUSE); } t = in_pcblookup_local(pcbinfo, sin->sin_addr, lport, lookupflags, cred); - if (t != NULL && (reuseport & inp_so_options(t)) == 0 && - (reuseport_lb & inp_so_options(t)) == 0) { + if (t != NULL && (reuseport & t->inp_socket->so_options) == 0 && + (reuseport_lb & t->inp_socket->so_options) == 0) { #ifdef INET6 if (ntohl(sin->sin_addr.s_addr) != INADDR_ANY || @@ -2658,7 +2639,7 @@ in_pcbinshash(struct inpcb *inp) * Add entry to load balance group. * Only do this if SO_REUSEPORT_LB is set. */ - if ((inp->inp_flags2 & INP_REUSEPORT_LB) != 0) { + if ((inp->inp_socket->so_options & SO_REUSEPORT_LB) != 0) { int error = in_pcbinslbgrouphash(inp, M_NODOM); if (error != 0) return (error); diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index a989776105fb..44e9cfd3c861 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -490,7 +490,6 @@ struct tcpcb * inp_inpcbtotcpcb(struct inpcb *inp); void inp_4tuple_get(struct inpcb *inp, uint32_t *laddr, uint16_t *lp, uint32_t *faddr, uint16_t *fp); -int inp_so_options(const struct inpcb *inp); #endif /* _KERNEL */ @@ -597,9 +596,9 @@ int inp_so_options(const struct inpcb *inp); /* 0x00000001 */ /* 0x00000002 */ /* 0x00000004 */ -#define INP_REUSEPORT 0x00000008 /* SO_REUSEPORT option is set */ +/* 0x00000008 */ /* 0x00000010 */ -#define INP_REUSEADDR 0x00000020 /* SO_REUSEADDR option is set */ +/* 0x00000020 */ /* 0x00000040 */ /* 0x00000080 */ #define INP_RECVFLOWID 0x00000100 /* populate recv datagram with flow info */ @@ -607,7 +606,7 @@ int inp_so_options(const struct inpcb *inp); #define INP_RATE_LIMIT_CHANGED 0x00000400 /* rate limit needs attention */ #define INP_ORIGDSTADDR 0x00000800 /* receive IP dst address/port */ /* 0x00001000 */ -#define INP_REUSEPORT_LB 0x00002000 /* SO_REUSEPORT_LB option is set */ +/* 0x00002000 */ /* 0x00004000 */ /* 0x00008000 */ /* 0x00010000 */ diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 3f30c63cdc87..9c4d98a979ee 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -1084,33 +1084,6 @@ ip_ctloutput(struct socket *so, struct sockopt *sopt) if (sopt->sopt_level == SOL_SOCKET && sopt->sopt_dir == SOPT_SET) { switch (sopt->sopt_name) { - case SO_REUSEADDR: - INP_WLOCK(inp); - if ((so->so_options & SO_REUSEADDR) != 0) - inp->inp_flags2 |= INP_REUSEADDR; - else - inp->inp_flags2 &= ~INP_REUSEADDR; - INP_WUNLOCK(inp); - error = 0; - break; - case SO_REUSEPORT: - INP_WLOCK(inp); - if ((so->so_options & SO_REUSEPORT) != 0) - inp->inp_flags2 |= INP_REUSEPORT; - else - inp->inp_flags2 &= ~INP_REUSEPORT; - INP_WUNLOCK(inp); - error = 0; - break; - case SO_REUSEPORT_LB: - INP_WLOCK(inp); - if ((so->so_options & SO_REUSEPORT_LB) != 0) - inp->inp_flags2 |= INP_REUSEPORT_LB; - else - inp->inp_flags2 &= ~INP_REUSEPORT_LB; - INP_WUNLOCK(inp); - error = 0; - break; case SO_SETFIB: INP_WLOCK(inp); inp->inp_inc.inc_fibnum = so->so_fibnum; diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 43f567461598..c43d4e804b46 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -256,8 +256,8 @@ in6_pcbbind(struct inpcb *inp, struct sockaddr_in6 *sin6, struct ucred *cred) IN6_IS_ADDR_UNSPECIFIED(&t->in6p_faddr)) && (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) || !IN6_IS_ADDR_UNSPECIFIED(&t->in6p_laddr) || - (t->inp_flags2 & INP_REUSEPORT) || - (t->inp_flags2 & INP_REUSEPORT_LB) == 0) && + (t->inp_socket->so_options & SO_REUSEPORT) || + (t->inp_socket->so_options & SO_REUSEPORT_LB) == 0) && (inp->inp_cred->cr_uid != t->inp_cred->cr_uid)) return (EADDRINUSE); @@ -283,8 +283,8 @@ in6_pcbbind(struct inpcb *inp, struct sockaddr_in6 *sin6, struct ucred *cred) } t = in6_pcblookup_local(pcbinfo, &sin6->sin6_addr, lport, lookupflags, cred); - if (t && (reuseport & inp_so_options(t)) == 0 && - (reuseport_lb & inp_so_options(t)) == 0) { + if (t && (reuseport & t->inp_socket->so_options) == 0 && + (reuseport_lb & t->inp_socket->so_options) == 0) { return (EADDRINUSE); } #ifdef INET @@ -296,8 +296,8 @@ in6_pcbbind(struct inpcb *inp, struct sockaddr_in6 *sin6, struct ucred *cred) t = in_pcblookup_local(pcbinfo, sin.sin_addr, lport, lookupflags, cred); if (t && - (reuseport & inp_so_options(t)) == 0 && - (reuseport_lb & inp_so_options(t)) == 0 && + (reuseport & t->inp_socket->so_options) == 0 && + (reuseport_lb & t->inp_socket->so_options) == 0 && (ntohl(t->inp_laddr.s_addr) != INADDR_ANY || (t->inp_vflag & INP_IPV6PROTO) != 0)) { return (EADDRINUSE); diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index 7e3c98270cc2..2a447a8a738f 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1641,33 +1641,6 @@ ip6_ctloutput(struct socket *so, struct sockopt *sopt) if (sopt->sopt_level == SOL_SOCKET && sopt->sopt_dir == SOPT_SET) { switch (sopt->sopt_name) { - case SO_REUSEADDR: - INP_WLOCK(inp); - if ((so->so_options & SO_REUSEADDR) != 0) - inp->inp_flags2 |= INP_REUSEADDR; - else - inp->inp_flags2 &= ~INP_REUSEADDR; - INP_WUNLOCK(inp); - error = 0; - break; - case SO_REUSEPORT: - INP_WLOCK(inp); - if ((so->so_options & SO_REUSEPORT) != 0) - inp->inp_flags2 |= INP_REUSEPORT; - else - inp->inp_flags2 &= ~INP_REUSEPORT; - INP_WUNLOCK(inp); - error = 0; - break; - case SO_REUSEPORT_LB: - INP_WLOCK(inp); - if ((so->so_options & SO_REUSEPORT_LB) != 0) - inp->inp_flags2 |= INP_REUSEPORT_LB; - else - inp->inp_flags2 &= ~INP_REUSEPORT_LB; - INP_WUNLOCK(inp); - error = 0; - break; case SO_SETFIB: INP_WLOCK(inp); inp->inp_inc.inc_fibnum = so->so_fibnum;