-/* $OpenBSD: uipc_usrreq.c,v 1.168 2022/08/15 09:11:38 mvs Exp $ */
+/* $OpenBSD: uipc_usrreq.c,v 1.169 2022/08/20 23:48:57 mvs Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */
/*
.pru_usrreq = uipc_usrreq,
.pru_attach = uipc_attach,
.pru_detach = uipc_detach,
+ .pru_bind = uipc_bind,
};
void
switch (req) {
- case PRU_BIND:
- error = unp_bind(unp, nam, p);
- break;
-
case PRU_LISTEN:
if (unp->unp_vnode == NULL)
error = EINVAL;
return (0);
}
+int
+uipc_bind(struct socket *so, struct mbuf *nam, struct proc *p)
+{
+ struct unpcb *unp = sotounpcb(so);
+
+ return unp_bind(unp, nam, p);
+}
+
int
uipc_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
size_t newlen)
-/* $OpenBSD: pfkeyv2.c,v 1.235 2022/08/15 09:11:38 mvs Exp $ */
+/* $OpenBSD: pfkeyv2.c,v 1.236 2022/08/20 23:48:57 mvs Exp $ */
/*
* @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
switch (req) {
/* no connect, bind, accept. Socket is connected from the start */
case PRU_CONNECT:
- case PRU_BIND:
case PRU_CONNECT2:
case PRU_LISTEN:
case PRU_ACCEPT:
-/* $OpenBSD: rtsock.c,v 1.335 2022/08/15 09:11:38 mvs Exp $ */
+/* $OpenBSD: rtsock.c,v 1.336 2022/08/20 23:48:58 mvs Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
switch (req) {
/* no connect, bind, accept. Socket is connected from the start */
case PRU_CONNECT:
- case PRU_BIND:
case PRU_CONNECT2:
case PRU_LISTEN:
case PRU_ACCEPT:
-/* $OpenBSD: ip_divert.c,v 1.69 2022/08/15 09:11:39 mvs Exp $ */
+/* $OpenBSD: ip_divert.c,v 1.70 2022/08/20 23:48:58 mvs Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
.pru_usrreq = divert_usrreq,
.pru_attach = divert_attach,
.pru_detach = divert_detach,
+ .pru_bind = divert_bind,
};
int divbhashsize = DIVERTHASHSIZE;
}
switch (req) {
- case PRU_BIND:
- error = in_pcbbind(inp, addr, p);
- break;
-
case PRU_SHUTDOWN:
socantsendmore(so);
break;
return (0);
}
+int
+divert_bind(struct socket *so, struct mbuf *addr, struct proc *p)
+{
+ struct inpcb *inp = sotoinpcb(so);
+
+ soassertlocked(so);
+ return in_pcbbind(inp, addr, p);
+}
+
int
divert_sysctl_divstat(void *oldp, size_t *oldlenp, void *newp)
{
-/* $OpenBSD: ip_divert.h,v 1.16 2022/08/15 09:11:39 mvs Exp $ */
+/* $OpenBSD: ip_divert.h,v 1.17 2022/08/20 23:48:58 mvs Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
int divert_attach(struct socket *, int);
int divert_detach(struct socket *);
+int divert_bind(struct socket *, struct mbuf *, struct proc *);
#endif /* _KERNEL */
#endif /* _IP_DIVERT_H_ */
-/* $OpenBSD: ip_gre.c,v 1.75 2022/08/15 09:11:39 mvs Exp $ */
+/* $OpenBSD: ip_gre.c,v 1.76 2022/08/20 23:48:58 mvs Exp $ */
/* $NetBSD: ip_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */
/*
.pru_usrreq = gre_usrreq,
.pru_attach = rip_attach,
.pru_detach = rip_detach,
+ .pru_bind = rip_bind,
};
int
-/* $OpenBSD: ip_var.h,v 1.97 2022/08/15 09:11:39 mvs Exp $ */
+/* $OpenBSD: ip_var.h,v 1.98 2022/08/20 23:48:58 mvs Exp $ */
/* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */
/*
int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
int rip_attach(struct socket *, int);
int rip_detach(struct socket *);
+int rip_bind(struct socket *so, struct mbuf *, struct proc *);
#ifdef MROUTING
extern struct socket *ip_mrouter[]; /* multicast routing daemon */
#endif
-/* $OpenBSD: raw_ip.c,v 1.130 2022/08/15 09:11:39 mvs Exp $ */
+/* $OpenBSD: raw_ip.c,v 1.131 2022/08/20 23:48:58 mvs Exp $ */
/* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */
/*
.pru_usrreq = rip_usrreq,
.pru_attach = rip_attach,
.pru_detach = rip_detach,
+ .pru_bind = rip_bind,
};
/*
in_pcbdetach(inp);
break;
- case PRU_BIND:
- {
- struct sockaddr_in *addr;
-
- if ((error = in_nam2sin(nam, &addr)))
- break;
- if (!((so->so_options & SO_BINDANY) ||
- addr->sin_addr.s_addr == INADDR_ANY ||
- addr->sin_addr.s_addr == INADDR_BROADCAST ||
- in_broadcast(addr->sin_addr, inp->inp_rtableid) ||
- ifa_ifwithaddr(sintosa(addr), inp->inp_rtableid))) {
- error = EADDRNOTAVAIL;
- break;
- }
- inp->inp_laddr = addr->sin_addr;
- break;
- }
case PRU_CONNECT:
{
struct sockaddr_in *addr;
return (0);
}
+
+int
+rip_bind(struct socket *so, struct mbuf *nam, struct proc *p)
+{
+ struct inpcb *inp = sotoinpcb(so);
+ struct sockaddr_in *addr;
+ int error;
+
+ soassertlocked(so);
+
+ if ((error = in_nam2sin(nam, &addr)))
+ return (error);
+
+ if (!((so->so_options & SO_BINDANY) ||
+ addr->sin_addr.s_addr == INADDR_ANY ||
+ addr->sin_addr.s_addr == INADDR_BROADCAST ||
+ in_broadcast(addr->sin_addr, inp->inp_rtableid) ||
+ ifa_ifwithaddr(sintosa(addr), inp->inp_rtableid)))
+ return (EADDRNOTAVAIL);
+
+ inp->inp_laddr = addr->sin_addr;
+
+ return (0);
+}
-/* $OpenBSD: tcp_usrreq.c,v 1.188 2022/08/15 14:44:18 mvs Exp $ */
+/* $OpenBSD: tcp_usrreq.c,v 1.189 2022/08/20 23:48:58 mvs Exp $ */
/* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */
/*
.pru_usrreq = tcp_usrreq,
.pru_attach = tcp_attach,
.pru_detach = tcp_detach,
+ .pru_bind = tcp_bind,
};
static int pr_slowhz = PR_SLOWHZ;
switch (req) {
- /*
- * Give the socket an address.
- */
- case PRU_BIND:
- error = in_pcbbind(inp, nam, p);
- break;
-
/*
* Prepare to accept connections.
*/
return (error);
}
+/*
+ * Give the socket an address.
+ */
+int
+tcp_bind(struct socket *so, struct mbuf *nam, struct proc *p)
+{
+ struct inpcb *inp;
+ struct tcpcb *tp;
+ int error;
+ short ostate;
+
+ soassertlocked(so);
+
+ if ((error = tcp_sogetpcb(so, &inp, &tp)))
+ return (error);
+
+ if (so->so_options & SO_DEBUG)
+ ostate = tp->t_state;
+
+ error = in_pcbbind(inp, nam, p);
+
+ if (so->so_options & SO_DEBUG)
+ tcp_trace(TA_USER, ostate, tp, tp, NULL, PRU_BIND, 0);
+ return (error);
+}
+
/*
* Initiate (or continue) disconnect.
* If embryonic state, just send reset (once).
-/* $OpenBSD: tcp_var.h,v 1.141 2022/08/15 09:11:39 mvs Exp $ */
+/* $OpenBSD: tcp_var.h,v 1.142 2022/08/20 23:48:58 mvs Exp $ */
/* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */
/*
int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
int tcp_attach(struct socket *, int);
int tcp_detach(struct socket *);
+int tcp_bind(struct socket *, struct mbuf *, struct proc *);
void tcp_xmit_timer(struct tcpcb *, int);
void tcpdropoldhalfopen(struct tcpcb *, u_int16_t);
void tcp_sack_option(struct tcpcb *,struct tcphdr *,u_char *,int);
-/* $OpenBSD: udp_usrreq.c,v 1.282 2022/08/15 09:11:39 mvs Exp $ */
+/* $OpenBSD: udp_usrreq.c,v 1.283 2022/08/20 23:48:58 mvs Exp $ */
/* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */
/*
.pru_usrreq = udp_usrreq,
.pru_attach = udp_attach,
.pru_detach = udp_detach,
+ .pru_bind = udp_bind,
};
const struct sysctl_bounded_args udpctl_vars[] = {
*/
switch (req) {
- case PRU_BIND:
- error = in_pcbbind(inp, addr, p);
- break;
-
case PRU_LISTEN:
error = EOPNOTSUPP;
break;
return (0);
}
+int
+udp_bind(struct socket *so, struct mbuf *addr, struct proc *p)
+{
+ struct inpcb *inp = sotoinpcb(so);
+
+ soassertlocked(so);
+ return in_pcbbind(inp, addr, p);
+}
+
/*
* Sysctl for udp variables.
*/
-/* $OpenBSD: udp_var.h,v 1.38 2022/08/15 09:11:39 mvs Exp $ */
+/* $OpenBSD: udp_var.h,v 1.39 2022/08/20 23:48:58 mvs Exp $ */
/* $NetBSD: udp_var.h,v 1.12 1996/02/13 23:44:41 christos Exp $ */
/*
int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
int udp_attach(struct socket *, int);
int udp_detach(struct socket *);
+int udp_bind(struct socket *, struct mbuf *, struct proc *);
#endif /* _KERNEL */
#endif /* _NETINET_UDP_VAR_H_ */
-/* $OpenBSD: ip6_divert.c,v 1.68 2022/08/15 09:11:39 mvs Exp $ */
+/* $OpenBSD: ip6_divert.c,v 1.69 2022/08/20 23:48:58 mvs Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
.pru_usrreq = divert6_usrreq,
.pru_attach = divert6_attach,
.pru_detach = divert6_detach,
+ .pru_bind = divert6_bind,
};
int divb6hashsize = DIVERTHASHSIZE;
}
switch (req) {
- case PRU_BIND:
- error = in_pcbbind(inp, addr, p);
- break;
-
case PRU_SHUTDOWN:
socantsendmore(so);
break;
return (0);
}
+int
+divert6_bind(struct socket *so, struct mbuf *addr, struct proc *p)
+{
+ struct inpcb *inp = sotoinpcb(so);
+
+ soassertlocked(so);
+ return in_pcbbind(inp, addr, p);
+}
+
int
divert6_sysctl_div6stat(void *oldp, size_t *oldlenp, void *newp)
{
-/* $OpenBSD: ip6_divert.h,v 1.14 2022/08/15 09:11:39 mvs Exp $ */
+/* $OpenBSD: ip6_divert.h,v 1.15 2022/08/20 23:48:58 mvs Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
int divert6_attach(struct socket *, int);
int divert6_detach(struct socket *);
+int divert6_bind(struct socket *, struct mbuf *, struct proc *);
#endif /* _KERNEL */
#endif /* _IP6_DIVERT_H_ */
-/* $OpenBSD: ip6_var.h,v 1.95 2022/08/15 09:11:39 mvs Exp $ */
+/* $OpenBSD: ip6_var.h,v 1.96 2022/08/20 23:48:58 mvs Exp $ */
/* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */
/*
int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
int rip6_attach(struct socket *, int);
int rip6_detach(struct socket *);
+int rip6_bind(struct socket *, struct mbuf *, struct proc *);
int rip6_sysctl(int *, u_int, void *, size_t *, void *, size_t);
int dest6_input(struct mbuf **, int *, int, int);
-/* $OpenBSD: raw_ip6.c,v 1.150 2022/08/15 09:11:39 mvs Exp $ */
+/* $OpenBSD: raw_ip6.c,v 1.151 2022/08/20 23:48:58 mvs Exp $ */
/* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */
/*
.pru_usrreq = rip6_usrreq,
.pru_attach = rip6_attach,
.pru_detach = rip6_detach,
+ .pru_bind = rip6_bind,
};
/*
in_pcbdetach(in6p);
break;
- case PRU_BIND:
- {
- struct sockaddr_in6 *addr;
-
- if ((error = in6_nam2sin6(nam, &addr)))
- break;
- /*
- * Make sure to not enter in_pcblookup_local(), local ports
- * are non-sensical for raw sockets.
- */
- addr->sin6_port = 0;
-
- if ((error = in6_pcbaddrisavail(in6p, addr, 0, p)))
- break;
-
- in6p->inp_laddr6 = addr->sin6_addr;
- break;
- }
-
case PRU_CONNECT:
{
struct sockaddr_in6 *addr;
return (0);
}
+int
+rip6_bind(struct socket *so, struct mbuf *nam, struct proc *p)
+{
+ struct inpcb *in6p = sotoinpcb(so);
+ struct sockaddr_in6 *addr;
+ int error;
+
+ soassertlocked(so);
+
+ if ((error = in6_nam2sin6(nam, &addr)))
+ return (error);
+
+ /*
+ * Make sure to not enter in_pcblookup_local(), local ports
+ * are non-sensical for raw sockets.
+ */
+ addr->sin6_port = 0;
+
+ if ((error = in6_pcbaddrisavail(in6p, addr, 0, p)))
+ return (error);
+
+ in6p->inp_laddr6 = addr->sin6_addr;
+ return (0);
+}
+
int
rip6_sysctl_rip6stat(void *oldp, size_t *oldplen, void *newp)
{
-/* $OpenBSD: protosw.h,v 1.37 2022/08/15 09:11:39 mvs Exp $ */
+/* $OpenBSD: protosw.h,v 1.38 2022/08/20 23:48:58 mvs Exp $ */
/* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */
/*-
int (*pru_attach)(struct socket *, int);
int (*pru_detach)(struct socket *);
+ int (*pru_bind)(struct socket *, struct mbuf *, struct proc *);
};
struct protosw {
static inline int
pru_bind(struct socket *so, struct mbuf *nam, struct proc *p)
{
- return (*so->so_proto->pr_usrreqs->pru_usrreq)(so,
- PRU_BIND, NULL, nam, NULL, p);
+ if (so->so_proto->pr_usrreqs->pru_bind)
+ return (*so->so_proto->pr_usrreqs->pru_bind)(so, nam, p);
+ return (EOPNOTSUPP);
}
static inline int
-/* $OpenBSD: unpcb.h,v 1.27 2022/08/15 09:11:39 mvs Exp $ */
+/* $OpenBSD: unpcb.h,v 1.28 2022/08/20 23:48:58 mvs Exp $ */
/* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */
/*
struct mbuf *, struct mbuf *, struct proc *);
int uipc_attach(struct socket *, int);
int uipc_detach(struct socket *);
+int uipc_bind(struct socket *, struct mbuf *, struct proc *);
void unp_init(void);
int unp_bind(struct unpcb *, struct mbuf *, struct proc *);