summaryrefslogtreecommitdiffstats
path: root/sys/net/raw_usrreq.c
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2008-07-09 15:48:16 +0000
committerrwatson <rwatson@FreeBSD.org>2008-07-09 15:48:16 +0000
commit754034c5cf572b6def935dfa55606273daf042c8 (patch)
tree723ae7ca9460a1b1337cd82ac0bd81bb312adb58 /sys/net/raw_usrreq.c
parentc490da6d2678016039a02b7fbe09affbc616e9f9 (diff)
downloadFreeBSD-src-754034c5cf572b6def935dfa55606273daf042c8.zip
FreeBSD-src-754034c5cf572b6def935dfa55606273daf042c8.tar.gz
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
Diffstat (limited to 'sys/net/raw_usrreq.c')
-rw-r--r--sys/net/raw_usrreq.c101
1 files changed, 30 insertions, 71 deletions
diff --git a/sys/net/raw_usrreq.c b/sys/net/raw_usrreq.c
index fb5f429..47afb4f 100644
--- a/sys/net/raw_usrreq.c
+++ b/sys/net/raw_usrreq.c
@@ -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 = {
OpenPOWER on IntegriCloud