Remove unused support for local and foreign addresses in generic raw
socket support. These utility routines are used only for routing and pfkey sockets, neither of which have a notion of address, so were required to mock up fake socket addresses to avoid connection requirements for applications that did not specify their own fake addresses (most of them). Quite a bit of the removed code is #ifdef notdef, since raw sockets don't support bind() or connect() in practice. Removing this simplifies the raw socket implementation, and removes two (commented out) uses of dtom(9). Fake addresses passed to sendto(2) by applications are ignored for compatibility reasons, but this is now done in a more consistent way (and with a comment). Possibly, EINVAL could be returned here in the future if it is determined that no applications depend on the semantic inconsistency of specifying a destination address for a protocol without address support, but this will require some amount of careful surveying. NB: This does not affect netinet, netinet6, or other wire protocol raw sockets, which provide their own independent infrastructure with control block address support specific to the protocol. MFC after: 3 weeks Reviewed by: bz
This commit is contained in:
parent
05e423585f
commit
4d896055ce
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=180385
@ -101,42 +101,5 @@ raw_detach(struct rawcb *rp)
|
||||
mtx_lock(&rawcb_mtx);
|
||||
LIST_REMOVE(rp, list);
|
||||
mtx_unlock(&rawcb_mtx);
|
||||
#ifdef notdef
|
||||
if (rp->rcb_laddr)
|
||||
m_freem(dtom(rp->rcb_laddr));
|
||||
rp->rcb_laddr = 0;
|
||||
#endif
|
||||
free((caddr_t)(rp), M_PCB);
|
||||
}
|
||||
|
||||
/*
|
||||
* Disconnect raw socket.
|
||||
*/
|
||||
void
|
||||
raw_disconnect(struct rawcb *rp)
|
||||
{
|
||||
|
||||
#ifdef notdef
|
||||
if (rp->rcb_faddr)
|
||||
m_freem(dtom(rp->rcb_faddr));
|
||||
rp->rcb_faddr = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef notdef
|
||||
#include <sys/mbuf.h>
|
||||
|
||||
int
|
||||
raw_bind(struct socket *so, struct mbuf *nam)
|
||||
{
|
||||
struct sockaddr *addr = mtod(nam, struct sockaddr *);
|
||||
struct rawcb *rp;
|
||||
|
||||
if (ifnet == 0)
|
||||
return (EADDRNOTAVAIL);
|
||||
rp = sotorawcb(so);
|
||||
nam = m_copym(nam, 0, M_COPYALL, M_WAIT);
|
||||
rp->rcb_laddr = mtod(nam, struct sockaddr *);
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
@ -43,8 +43,6 @@
|
||||
struct rawcb {
|
||||
LIST_ENTRY(rawcb) list;
|
||||
struct socket *rcb_socket; /* back pointer to socket */
|
||||
struct sockaddr *rcb_faddr; /* destination address */
|
||||
struct sockaddr *rcb_laddr; /* socket's address */
|
||||
struct sockproto rcb_proto; /* protocol family, protocol */
|
||||
};
|
||||
|
||||
@ -72,9 +70,7 @@ pr_init_t raw_init;
|
||||
*/
|
||||
int raw_attach(struct socket *, int);
|
||||
void raw_detach(struct rawcb *);
|
||||
void raw_disconnect(struct rawcb *);
|
||||
void raw_input(struct mbuf *, struct sockproto *, struct sockaddr *,
|
||||
struct sockaddr *);
|
||||
void raw_input(struct mbuf *, struct sockproto *, struct sockaddr *);
|
||||
|
||||
/*
|
||||
* Generic pr_usrreqs entries for raw socket protocols, usually wrapped so
|
||||
|
@ -67,8 +67,7 @@ raw_init(void)
|
||||
* Raw protocol interface.
|
||||
*/
|
||||
void
|
||||
raw_input(struct mbuf *m0, struct sockproto *proto, struct sockaddr *src,
|
||||
struct sockaddr *dst)
|
||||
raw_input(struct mbuf *m0, struct sockproto *proto, struct sockaddr *src)
|
||||
{
|
||||
struct rawcb *rp;
|
||||
struct mbuf *m = m0;
|
||||
@ -82,19 +81,6 @@ raw_input(struct mbuf *m0, struct sockproto *proto, struct sockaddr *src,
|
||||
if (rp->rcb_proto.sp_protocol &&
|
||||
rp->rcb_proto.sp_protocol != proto->sp_protocol)
|
||||
continue;
|
||||
/*
|
||||
* We assume the lower level routines have placed the address
|
||||
* in a canonical format suitable for a structure comparison.
|
||||
*
|
||||
* Note that if the lengths are not the same the comparison
|
||||
* will fail at the first byte.
|
||||
*/
|
||||
#define equal(a1, a2) \
|
||||
(bcmp((caddr_t)(a1), (caddr_t)(a2), a1->sa_len) == 0)
|
||||
if (rp->rcb_laddr && !equal(rp->rcb_laddr, dst))
|
||||
continue;
|
||||
if (rp->rcb_faddr && !equal(rp->rcb_faddr, src))
|
||||
continue;
|
||||
if (last) {
|
||||
struct mbuf *n;
|
||||
n = m_copy(m, 0, (int)M_COPYALL);
|
||||
@ -133,20 +119,18 @@ raw_ctlinput(int cmd, struct sockaddr *arg, void *dummy)
|
||||
static void
|
||||
raw_uabort(struct socket *so)
|
||||
{
|
||||
struct rawcb *rp = sotorawcb(so);
|
||||
|
||||
KASSERT(rp != NULL, ("raw_uabort: rp == NULL"));
|
||||
raw_disconnect(rp);
|
||||
KASSERT(sotorawcb(so) != NULL, ("raw_uabort: rp == NULL"));
|
||||
|
||||
soisdisconnected(so);
|
||||
}
|
||||
|
||||
static void
|
||||
raw_uclose(struct socket *so)
|
||||
{
|
||||
struct rawcb *rp = sotorawcb(so);
|
||||
|
||||
KASSERT(rp != NULL, ("raw_uabort: rp == NULL"));
|
||||
raw_disconnect(rp);
|
||||
KASSERT(sotorawcb(so) != NULL, ("raw_uabort: rp == NULL"));
|
||||
|
||||
soisdisconnected(so);
|
||||
}
|
||||
|
||||
@ -159,16 +143,16 @@ raw_uattach(struct socket *so, int proto, struct thread *td)
|
||||
|
||||
/*
|
||||
* Implementors of raw sockets will already have allocated the PCB,
|
||||
* so it must be non-NULL here.
|
||||
* so it must be non-NULL here.
|
||||
*/
|
||||
KASSERT(sotorawcb(so) != NULL, ("raw_uattach: so_pcb == NULL"));
|
||||
|
||||
if (td != NULL) {
|
||||
error = priv_check(td, PRIV_NET_RAW);
|
||||
if (error)
|
||||
return error;
|
||||
return (error);
|
||||
}
|
||||
return raw_attach(so, proto);
|
||||
return (raw_attach(so, proto));
|
||||
}
|
||||
|
||||
static int
|
||||
@ -194,20 +178,17 @@ raw_udetach(struct socket *so)
|
||||
struct rawcb *rp = sotorawcb(so);
|
||||
|
||||
KASSERT(rp != NULL, ("raw_udetach: rp == NULL"));
|
||||
|
||||
raw_detach(rp);
|
||||
}
|
||||
|
||||
static int
|
||||
raw_udisconnect(struct socket *so)
|
||||
{
|
||||
struct rawcb *rp = sotorawcb(so);
|
||||
|
||||
KASSERT(rp != NULL, ("raw_udisconnect: rp == NULL"));
|
||||
if (rp->rcb_faddr == 0)
|
||||
return (ENOTCONN);
|
||||
raw_disconnect(rp);
|
||||
soisdisconnected(so);
|
||||
return (0);
|
||||
KASSERT(sotorawcb(so) != NULL, ("raw_udisconnect: rp == NULL"));
|
||||
|
||||
return (ENOTCONN);
|
||||
}
|
||||
|
||||
/* pru_listen is EOPNOTSUPP */
|
||||
@ -215,13 +196,10 @@ raw_udisconnect(struct socket *so)
|
||||
static int
|
||||
raw_upeeraddr(struct socket *so, struct sockaddr **nam)
|
||||
{
|
||||
struct rawcb *rp = sotorawcb(so);
|
||||
|
||||
KASSERT(rp != NULL, ("raw_upeeraddr: rp == NULL"));
|
||||
if (rp->rcb_faddr == 0)
|
||||
return (ENOTCONN);
|
||||
*nam = sodupsockaddr(rp->rcb_faddr, M_WAITOK);
|
||||
return (0);
|
||||
KASSERT(sotorawcb(so) != NULL, ("raw_upeeraddr: rp == NULL"));
|
||||
|
||||
return (ENOTCONN);
|
||||
}
|
||||
|
||||
/* pru_rcvd is EOPNOTSUPP */
|
||||
@ -231,38 +209,21 @@ static int
|
||||
raw_usend(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
|
||||
struct mbuf *control, struct thread *td)
|
||||
{
|
||||
int error;
|
||||
struct rawcb *rp = sotorawcb(so);
|
||||
|
||||
KASSERT(rp != NULL, ("raw_usend: rp == NULL"));
|
||||
KASSERT(sotorawcb(so) != NULL, ("raw_usend: rp == NULL"));
|
||||
|
||||
if (flags & PRUS_OOB) {
|
||||
error = EOPNOTSUPP;
|
||||
goto release;
|
||||
if ((flags & PRUS_OOB) || (control && control->m_len)) {
|
||||
/* XXXRW: Should control also be freed here? */
|
||||
if (m != NULL)
|
||||
m_freem(m);
|
||||
return (EOPNOTSUPP);
|
||||
}
|
||||
|
||||
if (control && control->m_len) {
|
||||
error = EOPNOTSUPP;
|
||||
goto release;
|
||||
}
|
||||
if (nam) {
|
||||
if (rp->rcb_faddr) {
|
||||
error = EISCONN;
|
||||
goto release;
|
||||
}
|
||||
rp->rcb_faddr = nam;
|
||||
} else if (rp->rcb_faddr == 0) {
|
||||
error = ENOTCONN;
|
||||
goto release;
|
||||
}
|
||||
error = (*so->so_proto->pr_output)(m, so);
|
||||
m = NULL;
|
||||
if (nam)
|
||||
rp->rcb_faddr = 0;
|
||||
release:
|
||||
if (m != NULL)
|
||||
m_freem(m);
|
||||
return (error);
|
||||
/*
|
||||
* For historical (bad?) reasons, we effectively ignore the address
|
||||
* argument to sendto(2). Perhaps we should return an error instead?
|
||||
*/
|
||||
return ((*so->so_proto->pr_output)(m, so));
|
||||
}
|
||||
|
||||
/* pru_sense is null */
|
||||
@ -272,6 +233,7 @@ raw_ushutdown(struct socket *so)
|
||||
{
|
||||
|
||||
KASSERT(sotorawcb(so) != NULL, ("raw_ushutdown: rp == NULL"));
|
||||
|
||||
socantsendmore(so);
|
||||
return (0);
|
||||
}
|
||||
@ -279,13 +241,10 @@ raw_ushutdown(struct socket *so)
|
||||
static int
|
||||
raw_usockaddr(struct socket *so, struct sockaddr **nam)
|
||||
{
|
||||
struct rawcb *rp = sotorawcb(so);
|
||||
|
||||
KASSERT(rp != NULL, ("raw_usockaddr: rp == NULL"));
|
||||
if (rp->rcb_laddr == 0)
|
||||
return (EINVAL);
|
||||
*nam = sodupsockaddr(rp->rcb_laddr, M_WAITOK);
|
||||
return (0);
|
||||
KASSERT(sotorawcb(so) != NULL, ("raw_usockaddr: rp == NULL"));
|
||||
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
struct pr_usrreqs raw_usrreqs = {
|
||||
|
@ -61,7 +61,6 @@ extern void sctp_addr_change(struct ifaddr *ifa, int cmd);
|
||||
MALLOC_DEFINE(M_RTABLE, "routetbl", "routing tables");
|
||||
|
||||
/* NB: these are not modified */
|
||||
static struct sockaddr route_dst = { 2, PF_ROUTE, };
|
||||
static struct sockaddr route_src = { 2, PF_ROUTE, };
|
||||
static struct sockaddr sa_zero = { sizeof(sa_zero), AF_INET, };
|
||||
|
||||
@ -137,7 +136,7 @@ rts_input(struct mbuf *m)
|
||||
} else
|
||||
route_proto.sp_protocol = 0;
|
||||
|
||||
raw_input(m, &route_proto, &route_src, &route_dst);
|
||||
raw_input(m, &route_proto, &route_src);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -203,7 +202,6 @@ rts_attach(struct socket *so, int proto, struct thread *td)
|
||||
route_cb.ipx_count++;
|
||||
break;
|
||||
}
|
||||
rp->rcb_faddr = &route_src;
|
||||
route_cb.any_count++;
|
||||
RTSOCK_UNLOCK();
|
||||
soisconnected(so);
|
||||
|
@ -67,7 +67,6 @@ struct key_cb {
|
||||
};
|
||||
static struct key_cb key_cb;
|
||||
|
||||
static struct sockaddr key_dst = { 2, PF_KEY, };
|
||||
static struct sockaddr key_src = { 2, PF_KEY, };
|
||||
|
||||
static int key_sendup0 __P((struct rawcb *, struct mbuf *, int));
|
||||
@ -412,8 +411,6 @@ key_attach(struct socket *so, int proto, struct thread *td)
|
||||
if (kp->kp_raw.rcb_proto.sp_protocol == PF_KEY) /* XXX: AF_KEY */
|
||||
key_cb.key_count++;
|
||||
key_cb.any_count++;
|
||||
kp->kp_raw.rcb_laddr = &key_src;
|
||||
kp->kp_raw.rcb_faddr = &key_dst;
|
||||
soisconnected(so);
|
||||
so->so_options |= SO_USELOOPBACK;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user