From owner-svn-src-head@FreeBSD.ORG Mon Jun 22 10:59:34 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B2DB41065676; Mon, 22 Jun 2009 10:59:34 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A00B18FC17; Mon, 22 Jun 2009 10:59:34 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n5MAxYU6037570; Mon, 22 Jun 2009 10:59:34 GMT (envelope-from rwatson@svn.freebsd.org) Received: (from rwatson@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n5MAxYGd037562; Mon, 22 Jun 2009 10:59:34 GMT (envelope-from rwatson@svn.freebsd.org) Message-Id: <200906221059.n5MAxYGd037562@svn.freebsd.org> From: Robert Watson Date: Mon, 22 Jun 2009 10:59:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r194622 - in head/sys: dev/cxgb/ulp/iw_cxgb net netinet netipx X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Jun 2009 10:59:35 -0000 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; }