aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2021-10-18 17:11:20 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2021-10-18 17:19:03 +0000
commit147f018a720b80da4ba61bec90a6efc6eaa4913e (patch)
tree7bdd33cfaf6acd01a76a6bb9f4a261624bb2d6d5 /sys
parent744a64bd920c79b74a695a53cddfbecee4935c05 (diff)
downloadsrc-147f018a720b80da4ba61bec90a6efc6eaa4913e.tar.gz
src-147f018a720b80da4ba61bec90a6efc6eaa4913e.zip
Move in6_pcbsetport() to in6_pcb.c
This function was originally carved out of in6_pcbbind(), which is in in6_pcb.c. This function also uses KPI private to the PCB database - in_pcb_lport().
Diffstat (limited to 'sys')
-rw-r--r--sys/netinet6/in6_pcb.c38
-rw-r--r--sys/netinet6/in6_src.c42
2 files changed, 38 insertions, 42 deletions
diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c
index 14b95dfe0254..10a29f339773 100644
--- a/sys/netinet6/in6_pcb.c
+++ b/sys/netinet6/in6_pcb.c
@@ -115,6 +115,44 @@ __FBSDID("$FreeBSD$");
#include <netinet6/scope6_var.h>
int
+in6_pcbsetport(struct in6_addr *laddr, struct inpcb *inp, struct ucred *cred)
+{
+ struct socket *so = inp->inp_socket;
+ u_int16_t lport = 0;
+ int error, lookupflags = 0;
+#ifdef INVARIANTS
+ struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
+#endif
+
+ INP_WLOCK_ASSERT(inp);
+ INP_HASH_WLOCK_ASSERT(pcbinfo);
+
+ error = prison_local_ip6(cred, laddr,
+ ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0));
+ if (error)
+ return(error);
+
+ /* XXX: this is redundant when called from in6_pcbbind */
+ if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT|SO_REUSEPORT_LB)) == 0)
+ lookupflags = INPLOOKUP_WILDCARD;
+
+ inp->inp_flags |= INP_ANONPORT;
+
+ error = in_pcb_lport(inp, NULL, &lport, cred, lookupflags);
+ if (error != 0)
+ return (error);
+
+ inp->inp_lport = lport;
+ if (in_pcbinshash(inp) != 0) {
+ inp->in6p_laddr = in6addr_any;
+ inp->inp_lport = 0;
+ return (EAGAIN);
+ }
+
+ return (0);
+}
+
+int
in6_pcbbind(struct inpcb *inp, struct sockaddr *nam,
struct ucred *cred)
{
diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c
index 7f623709de13..875e0a63745c 100644
--- a/sys/netinet6/in6_src.c
+++ b/sys/netinet6/in6_src.c
@@ -926,48 +926,6 @@ in6_selecthlim(struct inpcb *inp, struct ifnet *ifp)
return (V_ip6_defhlim);
}
-/*
- * XXX: this is borrowed from in6_pcbbind(). If possible, we should
- * share this function by all *bsd*...
- */
-int
-in6_pcbsetport(struct in6_addr *laddr, struct inpcb *inp, struct ucred *cred)
-{
- struct socket *so = inp->inp_socket;
- u_int16_t lport = 0;
- int error, lookupflags = 0;
-#ifdef INVARIANTS
- struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
-#endif
-
- INP_WLOCK_ASSERT(inp);
- INP_HASH_WLOCK_ASSERT(pcbinfo);
-
- error = prison_local_ip6(cred, laddr,
- ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0));
- if (error)
- return(error);
-
- /* XXX: this is redundant when called from in6_pcbbind */
- if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT|SO_REUSEPORT_LB)) == 0)
- lookupflags = INPLOOKUP_WILDCARD;
-
- inp->inp_flags |= INP_ANONPORT;
-
- error = in_pcb_lport(inp, NULL, &lport, cred, lookupflags);
- if (error != 0)
- return (error);
-
- inp->inp_lport = lport;
- if (in_pcbinshash(inp) != 0) {
- inp->in6p_laddr = in6addr_any;
- inp->inp_lport = 0;
- return (EAGAIN);
- }
-
- return (0);
-}
-
void
addrsel_policy_init(void)
{