mirror of
https://git.FreeBSD.org/src.git
synced 2024-11-24 07:40:52 +00:00
Reduce network stack oddness: implement .pru_sockaddr and .pru_peeraddr
protocol entry points using functions named proto_getsockaddr and proto_getpeeraddr rather than proto_setsockaddr and proto_setpeeraddr. While it's true that sockaddrs are allocated and set, the net effect is to retrieve (get) the socket address or peer address from a socket, not set it, so align names to that intent.
This commit is contained in:
parent
169db7b25d
commit
54d642bbe5
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=169462
@ -285,19 +285,19 @@ ddp_clean(void)
|
||||
#endif
|
||||
|
||||
static int
|
||||
at_setpeeraddr(struct socket *so, struct sockaddr **nam)
|
||||
at_getpeeraddr(struct socket *so, struct sockaddr **nam)
|
||||
{
|
||||
|
||||
return (EOPNOTSUPP);
|
||||
}
|
||||
|
||||
static int
|
||||
at_setsockaddr(struct socket *so, struct sockaddr **nam)
|
||||
at_getsockaddr(struct socket *so, struct sockaddr **nam)
|
||||
{
|
||||
struct ddpcb *ddp;
|
||||
|
||||
ddp = sotoddpcb(so);
|
||||
KASSERT(ddp != NULL, ("at_setsockaddr: ddp == NULL"));
|
||||
KASSERT(ddp != NULL, ("at_getsockaddr: ddp == NULL"));
|
||||
|
||||
DDP_LOCK(ddp);
|
||||
at_sockaddr(ddp, nam);
|
||||
@ -313,9 +313,9 @@ struct pr_usrreqs ddp_usrreqs = {
|
||||
.pru_control = at_control,
|
||||
.pru_detach = ddp_detach,
|
||||
.pru_disconnect = ddp_disconnect,
|
||||
.pru_peeraddr = at_setpeeraddr,
|
||||
.pru_peeraddr = at_getpeeraddr,
|
||||
.pru_send = ddp_send,
|
||||
.pru_shutdown = ddp_shutdown,
|
||||
.pru_sockaddr = at_setsockaddr,
|
||||
.pru_sockaddr = at_getsockaddr,
|
||||
.pru_close = ddp_close,
|
||||
};
|
||||
|
@ -466,7 +466,7 @@ ngd_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
|
||||
* Used for both data and control sockets
|
||||
*/
|
||||
static int
|
||||
ng_setsockaddr(struct socket *so, struct sockaddr **addr)
|
||||
ng_getsockaddr(struct socket *so, struct sockaddr **addr)
|
||||
{
|
||||
struct ngpcb *pcbp;
|
||||
struct sockaddr_ng *sg;
|
||||
@ -1053,7 +1053,7 @@ static struct pr_usrreqs ngc_usrreqs = {
|
||||
.pru_peeraddr = NULL,
|
||||
.pru_send = ngc_send,
|
||||
.pru_shutdown = NULL,
|
||||
.pru_sockaddr = ng_setsockaddr,
|
||||
.pru_sockaddr = ng_getsockaddr,
|
||||
.pru_close = NULL,
|
||||
};
|
||||
|
||||
@ -1067,7 +1067,7 @@ static struct pr_usrreqs ngd_usrreqs = {
|
||||
.pru_peeraddr = NULL,
|
||||
.pru_send = ngd_send,
|
||||
.pru_shutdown = NULL,
|
||||
.pru_sockaddr = ng_setsockaddr,
|
||||
.pru_sockaddr = ng_getsockaddr,
|
||||
.pru_close = NULL,
|
||||
};
|
||||
|
||||
|
@ -772,6 +772,9 @@ in_pcbdrop(struct inpcb *inp)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Common routines to return the socket addresses associated with inpcbs.
|
||||
*/
|
||||
struct sockaddr *
|
||||
in_sockaddr(in_port_t port, struct in_addr *addr_p)
|
||||
{
|
||||
@ -787,23 +790,15 @@ in_sockaddr(in_port_t port, struct in_addr *addr_p)
|
||||
return (struct sockaddr *)sin;
|
||||
}
|
||||
|
||||
/*
|
||||
* The wrapper function will pass down the pcbinfo for this function to lock.
|
||||
* The socket must have a valid
|
||||
* (i.e., non-nil) PCB, but it should be impossible to get an invalid one
|
||||
* except through a kernel programming error, so it is acceptable to panic
|
||||
* (or in this case trap) if the PCB is invalid. (Actually, we don't trap
|
||||
* because there actually /is/ a programming error somewhere... XXX)
|
||||
*/
|
||||
int
|
||||
in_setsockaddr(struct socket *so, struct sockaddr **nam)
|
||||
in_getsockaddr(struct socket *so, struct sockaddr **nam)
|
||||
{
|
||||
struct inpcb *inp;
|
||||
struct in_addr addr;
|
||||
in_port_t port;
|
||||
|
||||
inp = sotoinpcb(so);
|
||||
KASSERT(inp != NULL, ("in_setsockaddr: inp == NULL"));
|
||||
KASSERT(inp != NULL, ("in_getsockaddr: inp == NULL"));
|
||||
|
||||
INP_LOCK(inp);
|
||||
port = inp->inp_lport;
|
||||
@ -814,18 +809,15 @@ in_setsockaddr(struct socket *so, struct sockaddr **nam)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* The wrapper function will pass down the pcbinfo for this function to lock.
|
||||
*/
|
||||
int
|
||||
in_setpeeraddr(struct socket *so, struct sockaddr **nam)
|
||||
in_getpeeraddr(struct socket *so, struct sockaddr **nam)
|
||||
{
|
||||
struct inpcb *inp;
|
||||
struct in_addr addr;
|
||||
in_port_t port;
|
||||
|
||||
inp = sotoinpcb(so);
|
||||
KASSERT(inp != NULL, ("in_setpeeraddr: inp == NULL"));
|
||||
KASSERT(inp != NULL, ("in_getpeeraddr: inp == NULL"));
|
||||
|
||||
INP_LOCK(inp);
|
||||
port = inp->inp_fport;
|
||||
|
@ -391,8 +391,8 @@ void in_pcbnotifyall(struct inpcbinfo *pcbinfo, struct in_addr,
|
||||
int, struct inpcb *(*)(struct inpcb *, int));
|
||||
void in_pcbrehash(struct inpcb *);
|
||||
void in_pcbsetsolabel(struct socket *so);
|
||||
int in_setpeeraddr(struct socket *so, struct sockaddr **nam);
|
||||
int in_setsockaddr(struct socket *so, struct sockaddr **nam);
|
||||
int in_getpeeraddr(struct socket *so, struct sockaddr **nam);
|
||||
int in_getsockaddr(struct socket *so, struct sockaddr **nam);
|
||||
struct sockaddr *
|
||||
in_sockaddr(in_port_t port, struct in_addr *addr);
|
||||
void in_pcbsosetlabel(struct socket *so);
|
||||
|
@ -635,10 +635,10 @@ struct pr_usrreqs div_usrreqs = {
|
||||
.pru_bind = div_bind,
|
||||
.pru_control = in_control,
|
||||
.pru_detach = div_detach,
|
||||
.pru_peeraddr = in_setpeeraddr,
|
||||
.pru_peeraddr = in_getpeeraddr,
|
||||
.pru_send = div_send,
|
||||
.pru_shutdown = div_shutdown,
|
||||
.pru_sockaddr = in_setsockaddr,
|
||||
.pru_sockaddr = in_getsockaddr,
|
||||
.pru_sosetlabel = in_pcbsosetlabel
|
||||
};
|
||||
|
||||
|
@ -920,10 +920,10 @@ struct pr_usrreqs rip_usrreqs = {
|
||||
.pru_control = in_control,
|
||||
.pru_detach = rip_detach,
|
||||
.pru_disconnect = rip_disconnect,
|
||||
.pru_peeraddr = in_setpeeraddr,
|
||||
.pru_peeraddr = in_getpeeraddr,
|
||||
.pru_send = rip_send,
|
||||
.pru_shutdown = rip_shutdown,
|
||||
.pru_sockaddr = in_setsockaddr,
|
||||
.pru_sockaddr = in_getsockaddr,
|
||||
.pru_sosetlabel = in_pcbsosetlabel,
|
||||
.pru_close = rip_close,
|
||||
};
|
||||
|
@ -618,7 +618,7 @@ tcp_usr_accept(struct socket *so, struct sockaddr **nam)
|
||||
TCPDEBUG1();
|
||||
|
||||
/*
|
||||
* We inline in_setpeeraddr and COMMON_END here, so that we can
|
||||
* We inline in_getpeeraddr and COMMON_END here, so that we can
|
||||
* copy the data of interest and defer the malloc until after we
|
||||
* release the lock.
|
||||
*/
|
||||
@ -1036,12 +1036,12 @@ struct pr_usrreqs tcp_usrreqs = {
|
||||
.pru_detach = tcp_usr_detach,
|
||||
.pru_disconnect = tcp_usr_disconnect,
|
||||
.pru_listen = tcp_usr_listen,
|
||||
.pru_peeraddr = in_setpeeraddr,
|
||||
.pru_peeraddr = in_getpeeraddr,
|
||||
.pru_rcvd = tcp_usr_rcvd,
|
||||
.pru_rcvoob = tcp_usr_rcvoob,
|
||||
.pru_send = tcp_usr_send,
|
||||
.pru_shutdown = tcp_usr_shutdown,
|
||||
.pru_sockaddr = in_setsockaddr,
|
||||
.pru_sockaddr = in_getsockaddr,
|
||||
.pru_sosetlabel = in_pcbsosetlabel,
|
||||
.pru_close = tcp_usr_close,
|
||||
};
|
||||
|
@ -1143,11 +1143,11 @@ struct pr_usrreqs udp_usrreqs = {
|
||||
.pru_control = in_control,
|
||||
.pru_detach = udp_detach,
|
||||
.pru_disconnect = udp_disconnect,
|
||||
.pru_peeraddr = in_setpeeraddr,
|
||||
.pru_peeraddr = in_getpeeraddr,
|
||||
.pru_send = udp_send,
|
||||
.pru_sosend = sosend_dgram,
|
||||
.pru_shutdown = udp_shutdown,
|
||||
.pru_sockaddr = in_setsockaddr,
|
||||
.pru_sockaddr = in_getsockaddr,
|
||||
.pru_sosetlabel = in_pcbsosetlabel,
|
||||
.pru_close = udp_close,
|
||||
};
|
||||
|
@ -501,18 +501,8 @@ in6_v4mapsin6_sockaddr(port, addr_p)
|
||||
return (struct sockaddr *)sin6_p;
|
||||
}
|
||||
|
||||
/*
|
||||
* The calling convention of in6_setsockaddr() and in6_setpeeraddr() was
|
||||
* modified to match the pru_sockaddr() and pru_peeraddr() entry points
|
||||
* in struct pr_usrreqs, so that protocols can just reference then directly
|
||||
* without the need for a wrapper function. The socket must have a valid
|
||||
* (i.e., non-nil) PCB, but it should be impossible to get an invalid one
|
||||
* except through a kernel programming error, so it is acceptable to panic
|
||||
* (or in this case trap) if the PCB is invalid. (Actually, we don't trap
|
||||
* because there actually /is/ a programming error somewhere... XXX)
|
||||
*/
|
||||
int
|
||||
in6_setsockaddr(so, nam)
|
||||
in6_getsockaddr(so, nam)
|
||||
struct socket *so;
|
||||
struct sockaddr **nam;
|
||||
{
|
||||
@ -521,7 +511,7 @@ in6_setsockaddr(so, nam)
|
||||
in_port_t port;
|
||||
|
||||
inp = sotoinpcb(so);
|
||||
KASSERT(inp != NULL, ("in6_setsockaddr: inp == NULL"));
|
||||
KASSERT(inp != NULL, ("in6_getsockaddr: inp == NULL"));
|
||||
|
||||
INP_LOCK(inp);
|
||||
port = inp->inp_lport;
|
||||
@ -533,7 +523,7 @@ in6_setsockaddr(so, nam)
|
||||
}
|
||||
|
||||
int
|
||||
in6_setpeeraddr(so, nam)
|
||||
in6_getpeeraddr(so, nam)
|
||||
struct socket *so;
|
||||
struct sockaddr **nam;
|
||||
{
|
||||
@ -542,7 +532,7 @@ in6_setpeeraddr(so, nam)
|
||||
in_port_t port;
|
||||
|
||||
inp = sotoinpcb(so);
|
||||
KASSERT(inp != NULL, ("in6_setpeeraddr: inp == NULL"));
|
||||
KASSERT(inp != NULL, ("in6_getpeeraddr: inp == NULL"));
|
||||
|
||||
INP_LOCK(inp);
|
||||
port = inp->inp_fport;
|
||||
@ -563,12 +553,12 @@ in6_mapped_sockaddr(struct socket *so, struct sockaddr **nam)
|
||||
KASSERT(inp != NULL, ("in6_mapped_sockaddr: inp == NULL"));
|
||||
|
||||
if ((inp->inp_vflag & (INP_IPV4 | INP_IPV6)) == INP_IPV4) {
|
||||
error = in_setsockaddr(so, nam);
|
||||
error = in_getsockaddr(so, nam);
|
||||
if (error == 0)
|
||||
in6_sin_2_v4mapsin6_in_sock(nam);
|
||||
} else {
|
||||
/* scope issues will be handled in in6_setsockaddr(). */
|
||||
error = in6_setsockaddr(so, nam);
|
||||
/* scope issues will be handled in in6_getsockaddr(). */
|
||||
error = in6_getsockaddr(so, nam);
|
||||
}
|
||||
|
||||
return error;
|
||||
@ -584,12 +574,12 @@ in6_mapped_peeraddr(struct socket *so, struct sockaddr **nam)
|
||||
KASSERT(inp != NULL, ("in6_mapped_peeraddr: inp == NULL"));
|
||||
|
||||
if ((inp->inp_vflag & (INP_IPV4 | INP_IPV6)) == INP_IPV4) {
|
||||
error = in_setpeeraddr(so, nam);
|
||||
error = in_getpeeraddr(so, nam);
|
||||
if (error == 0)
|
||||
in6_sin_2_v4mapsin6_in_sock(nam);
|
||||
} else
|
||||
/* scope issues will be handled in in6_setpeeraddr(). */
|
||||
error = in6_setpeeraddr(so, nam);
|
||||
/* scope issues will be handled in in6_getpeeraddr(). */
|
||||
error = in6_getpeeraddr(so, nam);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -95,8 +95,8 @@ struct sockaddr *
|
||||
in6_sockaddr __P((in_port_t port, struct in6_addr *addr_p));
|
||||
struct sockaddr *
|
||||
in6_v4mapsin6_sockaddr __P((in_port_t port, struct in_addr *addr_p));
|
||||
int in6_setpeeraddr __P((struct socket *so, struct sockaddr **nam));
|
||||
int in6_setsockaddr __P((struct socket *so, struct sockaddr **nam));
|
||||
int in6_getpeeraddr __P((struct socket *so, struct sockaddr **nam));
|
||||
int in6_getsockaddr __P((struct socket *so, struct sockaddr **nam));
|
||||
int in6_mapped_sockaddr __P((struct socket *so, struct sockaddr **nam));
|
||||
int in6_mapped_peeraddr __P((struct socket *so, struct sockaddr **nam));
|
||||
int in6_selecthlim __P((struct in6pcb *, struct ifnet *));
|
||||
|
@ -819,9 +819,9 @@ struct pr_usrreqs rip6_usrreqs = {
|
||||
.pru_control = in6_control,
|
||||
.pru_detach = rip6_detach,
|
||||
.pru_disconnect = rip6_disconnect,
|
||||
.pru_peeraddr = in6_setpeeraddr,
|
||||
.pru_peeraddr = in6_getpeeraddr,
|
||||
.pru_send = rip6_send,
|
||||
.pru_shutdown = rip6_shutdown,
|
||||
.pru_sockaddr = in6_setsockaddr,
|
||||
.pru_sockaddr = in6_getsockaddr,
|
||||
.pru_close = rip6_close,
|
||||
};
|
||||
|
@ -333,7 +333,7 @@ ipx_pcbfree(ipxp)
|
||||
}
|
||||
|
||||
void
|
||||
ipx_setsockaddr(ipxp, nam)
|
||||
ipx_getsockaddr(ipxp, nam)
|
||||
register struct ipxpcb *ipxp;
|
||||
struct sockaddr **nam;
|
||||
{
|
||||
@ -350,7 +350,7 @@ ipx_setsockaddr(ipxp, nam)
|
||||
}
|
||||
|
||||
void
|
||||
ipx_setpeeraddr(ipxp, nam)
|
||||
ipx_getpeeraddr(ipxp, nam)
|
||||
register struct ipxpcb *ipxp;
|
||||
struct sockaddr **nam;
|
||||
{
|
||||
|
@ -131,8 +131,8 @@ void ipx_pcbdisconnect(struct ipxpcb *ipxp);
|
||||
void ipx_pcbfree(struct ipxpcb *ipxp);
|
||||
struct ipxpcb *
|
||||
ipx_pcblookup(struct ipx_addr *faddr, int lport, int wildp);
|
||||
void ipx_setpeeraddr(struct ipxpcb *ipxp, struct sockaddr **nam);
|
||||
void ipx_setsockaddr(struct ipxpcb *ipxp, struct sockaddr **nam);
|
||||
void ipx_getpeeraddr(struct ipxpcb *ipxp, struct sockaddr **nam);
|
||||
void ipx_getsockaddr(struct ipxpcb *ipxp, struct sockaddr **nam);
|
||||
|
||||
#define IPX_LIST_LOCK_INIT() mtx_init(&ipxpcb_list_mtx, "ipx_list_mtx", \
|
||||
NULL, MTX_DEF | MTX_RECURSE)
|
||||
|
@ -586,7 +586,7 @@ ipx_peeraddr(so, nam)
|
||||
struct ipxpcb *ipxp = sotoipxpcb(so);
|
||||
|
||||
KASSERT(ipxp != NULL, ("ipx_peeraddr: ipxp == NULL"));
|
||||
ipx_setpeeraddr(ipxp, nam);
|
||||
ipx_getpeeraddr(ipxp, nam);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -671,7 +671,7 @@ ipx_sockaddr(so, nam)
|
||||
struct ipxpcb *ipxp = sotoipxpcb(so);
|
||||
|
||||
KASSERT(ipxp != NULL, ("ipx_sockaddr: ipxp == NULL"));
|
||||
ipx_setsockaddr(ipxp, nam);
|
||||
ipx_getsockaddr(ipxp, nam);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user