From owner-svn-src-all@FreeBSD.ORG Tue Oct 15 10:31:44 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 0824B3B4; Tue, 15 Oct 2013 10:31:44 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D99A82385; Tue, 15 Oct 2013 10:31:43 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9FAVhVw008290; Tue, 15 Oct 2013 10:31:43 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9FAVgRP008282; Tue, 15 Oct 2013 10:31:42 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201310151031.r9FAVgRP008282@svn.freebsd.org> From: Gleb Smirnoff Date: Tue, 15 Oct 2013 10:31:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r256519 - in head/sys: net netatalk netinet netinet6 netipx X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2013 10:31:44 -0000 Author: glebius Date: Tue Oct 15 10:31:42 2013 New Revision: 256519 URL: http://svnweb.freebsd.org/changeset/base/256519 Log: Remove ifa_init() and provide ifa_alloc() that will allocate and setup struct ifaddr internally. Sponsored by: Netflix Sponsored by: Nginx, Inc. Modified: head/sys/net/if.c head/sys/net/if_var.h head/sys/netatalk/at_control.c head/sys/netinet/in.c head/sys/netinet6/in6.c head/sys/netipx/ipx.c Modified: head/sys/net/if.c ============================================================================== --- head/sys/net/if.c Tue Oct 15 10:19:24 2013 (r256518) +++ head/sys/net/if.c Tue Oct 15 10:31:42 2013 (r256519) @@ -633,8 +633,7 @@ if_attach_internal(struct ifnet *ifp, in socksize = sizeof(*sdl); socksize = roundup2(socksize, sizeof(long)); ifasize = sizeof(*ifa) + 2 * socksize; - ifa = malloc(ifasize, M_IFADDR, M_WAITOK | M_ZERO); - ifa_init(ifa); + ifa = ifa_alloc(ifasize, M_WAITOK); sdl = (struct sockaddr_dl *)(ifa + 1); sdl->sdl_len = socksize; sdl->sdl_family = AF_LINK; @@ -1417,13 +1416,23 @@ if_maddr_runlock(struct ifnet *ifp) /* * Initialization, destruction and refcounting functions for ifaddrs. */ -void -ifa_init(struct ifaddr *ifa) +struct ifaddr * +ifa_alloc(size_t size, int flags) { + struct ifaddr *ifa; + + KASSERT(size >= sizeof(struct ifaddr), + ("%s: invalid size %zu", __func__, size)); + + ifa = malloc(size, M_IFADDR, M_ZERO | flags); + if (ifa == NULL) + return (NULL); mtx_init(&ifa->ifa_mtx, "ifaddr", NULL, MTX_DEF); refcount_init(&ifa->ifa_refcnt, 1); ifa->if_data.ifi_datalen = sizeof(ifa->if_data); + + return (ifa); } void Modified: head/sys/net/if_var.h ============================================================================== --- head/sys/net/if_var.h Tue Oct 15 10:19:24 2013 (r256518) +++ head/sys/net/if_var.h Tue Oct 15 10:31:42 2013 (r256519) @@ -819,8 +819,8 @@ struct ifaddr { #define IFA_LOCK(ifa) mtx_lock(&(ifa)->ifa_mtx) #define IFA_UNLOCK(ifa) mtx_unlock(&(ifa)->ifa_mtx) +struct ifaddr * ifa_alloc(size_t size, int flags); void ifa_free(struct ifaddr *ifa); -void ifa_init(struct ifaddr *ifa); void ifa_ref(struct ifaddr *ifa); #endif Modified: head/sys/netatalk/at_control.c ============================================================================== --- head/sys/netatalk/at_control.c Tue Oct 15 10:19:24 2013 (r256518) +++ head/sys/netatalk/at_control.c Tue Oct 15 10:31:42 2013 (r256519) @@ -199,16 +199,10 @@ at_control(struct socket *so, u_long cmd * allocate a fresh one. */ if (aa == NULL) { - aa = malloc(sizeof(struct at_ifaddr), M_IFADDR, - M_NOWAIT | M_ZERO); - if (aa == NULL) { - error = ENOBUFS; - goto out; - } - callout_init(&aa->aa_callout, CALLOUT_MPSAFE); + ifa = ifa_alloc(sizeof(struct at_ifaddr), M_WAITOK); + aa = (struct at_ifaddr *)ifa; - ifa = (struct ifaddr *)aa; - ifa_init(ifa); + callout_init(&aa->aa_callout, CALLOUT_MPSAFE); /* * As the at_ifaddr contains the actual sockaddrs, Modified: head/sys/netinet/in.c ============================================================================== --- head/sys/netinet/in.c Tue Oct 15 10:19:24 2013 (r256518) +++ head/sys/netinet/in.c Tue Oct 15 10:31:42 2013 (r256519) @@ -404,16 +404,8 @@ in_control(struct socket *so, u_long cmd goto out; } if (ia == NULL) { - ia = (struct in_ifaddr *) - malloc(sizeof *ia, M_IFADDR, M_NOWAIT | - M_ZERO); - if (ia == NULL) { - error = ENOBUFS; - goto out; - } - - ifa = &ia->ia_ifa; - ifa_init(ifa); + ifa = ifa_alloc(sizeof(struct in_ifaddr), M_WAITOK); + ia = (struct in_ifaddr *)ifa; ifa->ifa_addr = (struct sockaddr *)&ia->ia_addr; ifa->ifa_dstaddr = (struct sockaddr *)&ia->ia_dstaddr; ifa->ifa_netmask = (struct sockaddr *)&ia->ia_sockmask; Modified: head/sys/netinet6/in6.c ============================================================================== --- head/sys/netinet6/in6.c Tue Oct 15 10:19:24 2013 (r256518) +++ head/sys/netinet6/in6.c Tue Oct 15 10:31:42 2013 (r256519) @@ -1141,12 +1141,9 @@ in6_update_ifa(struct ifnet *ifp, struct * RA, it is called under an interrupt context. So, we should * call malloc with M_NOWAIT. */ - ia = (struct in6_ifaddr *) malloc(sizeof(*ia), M_IFADDR, - M_NOWAIT); + ia = (struct in6_ifaddr *)ifa_alloc(sizeof(*ia), M_NOWAIT); if (ia == NULL) return (ENOBUFS); - bzero((caddr_t)ia, sizeof(*ia)); - ifa_init(&ia->ia_ifa); LIST_INIT(&ia->ia6_memberships); /* Initialize the address and masks, and put time stamp */ ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr; Modified: head/sys/netipx/ipx.c ============================================================================== --- head/sys/netipx/ipx.c Tue Oct 15 10:19:24 2013 (r256518) +++ head/sys/netipx/ipx.c Tue Oct 15 10:31:42 2013 (r256519) @@ -190,13 +190,8 @@ ipx_control(struct socket *so, u_long cm if (td && (error = priv_check(td, PRIV_NET_SETLLADDR)) != 0) goto out; if (ia == NULL) { - ia = malloc(sizeof(*ia), M_IFADDR, M_NOWAIT | M_ZERO); - if (ia == NULL) { - error = ENOBUFS; - goto out; - } - ifa = (struct ifaddr *)ia; - ifa_init(ifa); + ifa = ifa_alloc(sizeof(struct ipx_ifaddr), M_WAITOK); + ia = (struct ipx_ifaddr *)ifa; ia->ia_ifp = ifp; ifa->ifa_addr = (struct sockaddr *)&ia->ia_addr; ifa->ifa_netmask = (struct sockaddr *)&ipx_netmask;