From owner-svn-src-head@FreeBSD.ORG Fri Dec 7 02:22:49 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B0E99B9A; Fri, 7 Dec 2012 02:22:49 +0000 (UTC) (envelope-from kevlo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 8AD2B8FC0C; Fri, 7 Dec 2012 02:22:49 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qB72MnTx085682; Fri, 7 Dec 2012 02:22:49 GMT (envelope-from kevlo@svn.freebsd.org) Received: (from kevlo@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qB72MnNX085679; Fri, 7 Dec 2012 02:22:49 GMT (envelope-from kevlo@svn.freebsd.org) Message-Id: <201212070222.qB72MnNX085679@svn.freebsd.org> From: Kevin Lo Date: Fri, 7 Dec 2012 02:22:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r243965 - in head/sys: kern sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 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: Fri, 07 Dec 2012 02:22:49 -0000 Author: kevlo Date: Fri Dec 7 02:22:48 2012 New Revision: 243965 URL: http://svnweb.freebsd.org/changeset/base/243965 Log: - according to POSIX, make socket(2) return EAFNOSUPPORT rather than EPROTONOSUPPORT if the address family is not supported. - introduce pffinddomain() to find a domain by family and use it as appropriate. Reviewed by: glebius Modified: head/sys/kern/uipc_domain.c head/sys/kern/uipc_socket.c head/sys/sys/protosw.h Modified: head/sys/kern/uipc_domain.c ============================================================================== --- head/sys/kern/uipc_domain.c Fri Dec 7 01:36:53 2012 (r243964) +++ head/sys/kern/uipc_domain.c Fri Dec 7 02:22:48 2012 (r243965) @@ -270,21 +270,31 @@ domainfinalize(void *dummy) callout_reset(&pfslow_callout, 1, pfslowtimo, NULL); } +struct domain * +pffinddomain(int family) +{ + struct domain *dp; + + for (dp = domains; dp != NULL; dp = dp->dom_next) + if (dp->dom_family == family) + return (dp); + return (NULL); +} + struct protosw * pffindtype(int family, int type) { struct domain *dp; struct protosw *pr; - for (dp = domains; dp; dp = dp->dom_next) - if (dp->dom_family == family) - goto found; - return (0); -found: + dp = pffinddomain(family); + if (dp == NULL) + return (NULL); + for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) if (pr->pr_type && pr->pr_type == type) return (pr); - return (0); + return (NULL); } struct protosw * @@ -292,21 +302,22 @@ pffindproto(int family, int protocol, in { struct domain *dp; struct protosw *pr; - struct protosw *maybe = 0; + struct protosw *maybe; + maybe = NULL; if (family == 0) - return (0); - for (dp = domains; dp; dp = dp->dom_next) - if (dp->dom_family == family) - goto found; - return (0); -found: + return (NULL); + + dp = pffinddomain(family); + if (dp == NULL) + return (NULL); + for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { if ((pr->pr_protocol == protocol) && (pr->pr_type == type)) return (pr); if (type == SOCK_RAW && pr->pr_type == SOCK_RAW && - pr->pr_protocol == 0 && maybe == (struct protosw *)0) + pr->pr_protocol == 0 && maybe == NULL) maybe = pr; } return (maybe); @@ -334,12 +345,10 @@ pf_proto_register(int family, struct pro return (ENXIO); /* Try to find the specified domain based on the family. */ - for (dp = domains; dp; dp = dp->dom_next) - if (dp->dom_family == family) - goto found; - return (EPFNOSUPPORT); + dp = pffinddomain(family); + if (dp == NULL) + return (EPFNOSUPPORT); -found: /* Initialize backpointer to struct domain. */ npr->pr_domain = dp; fpr = NULL; @@ -405,12 +414,10 @@ pf_proto_unregister(int family, int prot return (EPROTOTYPE); /* Try to find the specified domain based on the family type. */ - for (dp = domains; dp; dp = dp->dom_next) - if (dp->dom_family == family) - goto found; - return (EPFNOSUPPORT); + dp = pffinddomain(family); + if (dp == NULL) + return (EPFNOSUPPORT); -found: dpr = NULL; /* Lock out everyone else while we are manipulating the protosw. */ Modified: head/sys/kern/uipc_socket.c ============================================================================== --- head/sys/kern/uipc_socket.c Fri Dec 7 01:36:53 2012 (r243964) +++ head/sys/kern/uipc_socket.c Fri Dec 7 02:22:48 2012 (r243965) @@ -425,7 +425,16 @@ socreate(int dom, struct socket **aso, i else prp = pffindtype(dom, type); - if (prp == NULL || prp->pr_usrreqs->pru_attach == NULL || + if (prp == NULL) { + /* No support for domain. */ + if (pffinddomain(dom) == NULL) + return (EAFNOSUPPORT); + /* No support for socket type. */ + if (proto == 0 && type != 0) + return (EPROTOTYPE); + return (EPROTONOSUPPORT); + } + if (prp->pr_usrreqs->pru_attach == NULL || prp->pr_usrreqs->pru_attach == pru_attach_notsupp) return (EPROTONOSUPPORT); Modified: head/sys/sys/protosw.h ============================================================================== --- head/sys/sys/protosw.h Fri Dec 7 01:36:53 2012 (r243964) +++ head/sys/sys/protosw.h Fri Dec 7 02:22:48 2012 (r243965) @@ -330,6 +330,7 @@ char *prcorequests[] = { #ifdef _KERNEL void pfctlinput(int, struct sockaddr *); void pfctlinput2(int, struct sockaddr *, void *); +struct domain *pffinddomain(int family); struct protosw *pffindproto(int family, int protocol, int type); struct protosw *pffindtype(int family, int type); int pf_proto_register(int family, struct protosw *npr);