Proposed commit message:

Remove unused support for local and foreign addresses in generic raw
socket support.  These utility routines are used by 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 for
to be ignored for compatibility reasons, but this is now done in a
more consistent way (and with a comment).

NB: This does not affect netinet, netinet6, or other wire protocol
raw sockets, which provide their own independent infrastructure with
control block address support.

MFC after: 3 weeks
Reviewed by: bz

Index: net/raw_cb.c
===================================================================
--- net/raw_cb.c	(revision 180311)
+++ net/raw_cb.c	(working copy)
@@ -101,11 +101,6 @@
 	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);
 }
 
@@ -116,27 +111,4 @@
 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
Index: net/raw_cb.h
===================================================================
--- net/raw_cb.h	(revision 180311)
+++ net/raw_cb.h	(working copy)
@@ -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 */
 };
 
@@ -73,8 +71,7 @@
 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
Index: net/rtsock.c
===================================================================
--- net/rtsock.c	(revision 180311)
+++ net/rtsock.c	(working copy)
@@ -61,7 +61,6 @@
 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 @@
 	} 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 @@
 		route_cb.ipx_count++;
 		break;
 	}
-	rp->rcb_faddr = &route_src;
 	route_cb.any_count++;
 	RTSOCK_UNLOCK();
 	soisconnected(so);
Index: net/raw_usrreq.c
===================================================================
--- net/raw_usrreq.c	(revision 180311)
+++ net/raw_usrreq.c	(working copy)
@@ -67,8 +67,7 @@
  * 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 @@
 		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);
@@ -203,11 +189,8 @@
 	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);
+
+	return (ENOTCONN);
 }
 
 /* pru_listen is EOPNOTSUPP */
@@ -218,10 +201,8 @@
 	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);
+
+	return (ENOTCONN);
 }
 
 /* pru_rcvd is EOPNOTSUPP */
@@ -245,20 +226,13 @@
 		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;
-	}
+
+	/*
+	 * For historical (bad?) reasons, we effectively ignore the address
+	 * argument to sendto(2).  Perhaps we should return an error instead?
+	 */
 	error = (*so->so_proto->pr_output)(m, so);
 	m = NULL;
-	if (nam)
-		rp->rcb_faddr = 0;
 release:
 	if (m != NULL)
 		m_freem(m);
@@ -282,10 +256,7 @@
 	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);
+	return (EINVAL);
 }
 
 struct pr_usrreqs raw_usrreqs = {
Index: netipsec/keysock.c
===================================================================
--- netipsec/keysock.c	(revision 180311)
+++ netipsec/keysock.c	(working copy)
@@ -67,7 +67,6 @@
 };
 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 @@
 	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;
 
