svn commit: r194622 - in head/sys: dev/cxgb/ulp/iw_cxgb net netinet netipx

Robert Watson rwatson at FreeBSD.org
Mon Jun 22 10:59:35 UTC 2009


Author: rwatson
Date: Mon Jun 22 10:59:34 2009
New Revision: 194622
URL: http://svn.freebsd.org/changeset/base/194622

Log:
  Add a new function, ifa_ifwithaddr_check(), which rather than returning
  a pointer to an ifaddr matching the passed socket address, returns a
  boolean indicating whether one was present.  In the (near) future,
  ifa_ifwithaddr() will return a referenced ifaddr rather than a raw
  ifaddr pointer, and the new wrapper will allow callers that care only
  about the boolean condition to avoid having to free that reference.
  
  MFC after:	3 weeks

Modified:
  head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c
  head/sys/net/if.c
  head/sys/net/if_var.h
  head/sys/net/route.c
  head/sys/netinet/in_pcb.c
  head/sys/netinet/raw_ip.c
  head/sys/netipx/ipx_pcb.c

Modified: head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c
==============================================================================
--- head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c	Mon Jun 22 10:56:08 2009	(r194621)
+++ head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c	Mon Jun 22 10:59:34 2009	(r194622)
@@ -1337,12 +1337,13 @@ static int 
 is_loopback_dst(struct iw_cm_id *cm_id)
 {
 	uint16_t port = cm_id->remote_addr.sin_port;
-	struct ifaddr *ifa;
+	int ifa_present;
 
 	cm_id->remote_addr.sin_port = 0;
-	ifa = ifa_ifwithaddr((struct sockaddr *)&cm_id->remote_addr);
+	ifa_present = ifa_ifwithaddr_check(
+	    (struct sockaddr *)&cm_id->remote_addr);
 	cm_id->remote_addr.sin_port = port;
-	return (ifa != NULL);
+	return (ifa_present);
 }
 
 int

Modified: head/sys/net/if.c
==============================================================================
--- head/sys/net/if.c	Mon Jun 22 10:56:08 2009	(r194621)
+++ head/sys/net/if.c	Mon Jun 22 10:59:34 2009	(r194622)
@@ -1466,8 +1466,8 @@ ifa_free(struct ifaddr *ifa)
  * Locate an interface based on a complete address.
  */
 /*ARGSUSED*/
-struct ifaddr *
-ifa_ifwithaddr(struct sockaddr *addr)
+static struct ifaddr *
+ifa_ifwithaddr_internal(struct sockaddr *addr)
 {
 	INIT_VNET_NET(curvnet);
 	struct ifnet *ifp;
@@ -1500,6 +1500,20 @@ done:
 	return (ifa);
 }
 
+struct ifaddr *
+ifa_ifwithaddr(struct sockaddr *addr)
+{
+
+	return (ifa_ifwithaddr_internal(addr));
+}
+
+int
+ifa_ifwithaddr_check(struct sockaddr *addr)
+{
+
+	return (ifa_ifwithaddr_internal(addr) != NULL);
+}
+
 /*
  * Locate an interface based on the broadcast address.
  */

Modified: head/sys/net/if_var.h
==============================================================================
--- head/sys/net/if_var.h	Mon Jun 22 10:56:08 2009	(r194621)
+++ head/sys/net/if_var.h	Mon Jun 22 10:59:34 2009	(r194622)
@@ -820,6 +820,7 @@ void	ifq_init(struct ifaltq *, struct if
 void	ifq_delete(struct ifaltq *);
 
 struct	ifaddr *ifa_ifwithaddr(struct sockaddr *);
+int		ifa_ifwithaddr_check(struct sockaddr *);
 struct	ifaddr *ifa_ifwithbroadaddr(struct sockaddr *);
 struct	ifaddr *ifa_ifwithdstaddr(struct sockaddr *);
 struct	ifaddr *ifa_ifwithnet(struct sockaddr *);

Modified: head/sys/net/route.c
==============================================================================
--- head/sys/net/route.c	Mon Jun 22 10:56:08 2009	(r194621)
+++ head/sys/net/route.c	Mon Jun 22 10:59:34 2009	(r194622)
@@ -547,7 +547,7 @@ rtredirect_fib(struct sockaddr *dst,
 	if (!(flags & RTF_DONE) && rt &&
 	     (!sa_equal(src, rt->rt_gateway) || rt->rt_ifa != ifa))
 		error = EINVAL;
-	else if (ifa_ifwithaddr(gateway))
+	else if (ifa_ifwithaddr_check(gateway))
 		error = EHOSTUNREACH;
 	if (error)
 		goto done;

Modified: head/sys/netinet/in_pcb.c
==============================================================================
--- head/sys/netinet/in_pcb.c	Mon Jun 22 10:56:08 2009	(r194621)
+++ head/sys/netinet/in_pcb.c	Mon Jun 22 10:59:34 2009	(r194622)
@@ -357,7 +357,7 @@ in_pcbbind_setup(struct inpcb *inp, stru
 			 * to any endpoint address, local or not.
 			 */
 			if ((inp->inp_flags & INP_BINDANY) == 0 &&
-			    ifa_ifwithaddr((struct sockaddr *)sin) == NULL)
+			    ifa_ifwithaddr_check((struct sockaddr *)sin) == 0) 
 				return (EADDRNOTAVAIL);
 		}
 		laddr = sin->sin_addr;

Modified: head/sys/netinet/raw_ip.c
==============================================================================
--- head/sys/netinet/raw_ip.c	Mon Jun 22 10:56:08 2009	(r194621)
+++ head/sys/netinet/raw_ip.c	Mon Jun 22 10:59:34 2009	(r194622)
@@ -875,7 +875,7 @@ rip_bind(struct socket *so, struct socka
 	    (addr->sin_family != AF_INET && addr->sin_family != AF_IMPLINK) ||
 	    (addr->sin_addr.s_addr &&
 	     (inp->inp_flags & INP_BINDANY) == 0 &&
-	     ifa_ifwithaddr((struct sockaddr *)addr) == NULL))
+	     ifa_ifwithaddr_check((struct sockaddr *)addr) == 0))
 		return (EADDRNOTAVAIL);
 
 	INP_INFO_WLOCK(&V_ripcbinfo);

Modified: head/sys/netipx/ipx_pcb.c
==============================================================================
--- head/sys/netipx/ipx_pcb.c	Mon Jun 22 10:56:08 2009	(r194621)
+++ head/sys/netipx/ipx_pcb.c	Mon Jun 22 10:59:34 2009	(r194622)
@@ -121,7 +121,7 @@ ipx_pcbbind(struct ipxpcb *ipxp, struct 
 		int tport = sipx->sipx_port;
 
 		sipx->sipx_port = 0;		/* yech... */
-		if (ifa_ifwithaddr((struct sockaddr *)sipx) == NULL)
+		if (ifa_ifwithaddr_check((struct sockaddr *)sipx) == 0)
 			return (EADDRNOTAVAIL);
 		sipx->sipx_port = tport;
 	}


More information about the svn-src-head mailing list