From owner-freebsd-net Sun Jan 20 15:15:26 2002 Delivered-To: freebsd-net@freebsd.org Received: from InterJet.dellroad.org (adsl-63-194-81-26.dsl.snfc21.pacbell.net [63.194.81.26]) by hub.freebsd.org (Postfix) with ESMTP id 29A9B37B41D for ; Sun, 20 Jan 2002 15:15:05 -0800 (PST) Received: from arch20m.dellroad.org (arch20m.dellroad.org [10.1.1.20]) by InterJet.dellroad.org (8.9.1a/8.9.1) with ESMTP id PAA83308; Sun, 20 Jan 2002 15:08:57 -0800 (PST) Received: (from archie@localhost) by arch20m.dellroad.org (8.11.6/8.11.6) id g0KN8uc09321; Sun, 20 Jan 2002 15:08:56 -0800 (PST) (envelope-from archie) From: Archie Cobbs Message-Id: <200201202308.g0KN8uc09321@arch20m.dellroad.org> Subject: Re: netgraph: how to setsockopt on ksocket node ? In-Reply-To: <135740000.1011562445@blues.viagenie.qc.ca> "from Florent Parent at Jan 20, 2002 04:34:05 pm" To: Florent Parent Date: Sun, 20 Jan 2002 15:08:56 -0800 (PST) Cc: freebsd-net@FreeBSD.ORG, julian@elischer.org X-Mailer: ELM [version 2.4ME+ PL88 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org Florent Parent writes: > 'struct proc' member in the struct sockopt can be NULL. As per the comment > in that structure, NULL means that the calling entity is the kernel, not a > user process (my interpretation): > > struct sockopt { > enum sopt_dir sopt_dir; /* is this a get or a set? */ > int sopt_level; /* second arg of [gs]etsockopt */ > int sopt_name; /* third arg of [gs]etsockopt */ > void *sopt_val; /* fourth arg of [gs]etsockopt */ > size_t sopt_valsize; /* (almost) fifth arg of [gs]etsockopt */ > struct proc *sopt_p; /* calling process or null if kernel */ > }; > > This doesn't apply to socreate() since it isn't passed a 'struct sockopt' > as argument. From a quick glance, the socket functions that are concerned > are sosetopt() and sogetopt(). But socreate() does take a struct proc directly... perhaps it can be NULL too..? [ looks at code ... ] Nope, it doesn't appear that it can... > int > socreate(dom, aso, type, proto, p) > int dom; > struct socket **aso; > register int type; > int proto; > struct proc *p; > { > register struct protosw *prp; > register struct socket *so; > register int error; > > if (proto) > prp = pffindproto(dom, proto, type); > else > prp = pffindtype(dom, type); > > if (prp == 0 || prp->pr_usrreqs->pru_attach == 0) > return (EPROTONOSUPPORT); > > if (p->p_prison && jail_socket_unixiproute_only && > prp->pr_domain->dom_family != PF_LOCAL && > prp->pr_domain->dom_family != PF_INET && > prp->pr_domain->dom_family != PF_ROUTE) { > return (EPROTONOSUPPORT); > } > > if (prp->pr_type != type) > return (EPROTOTYPE); > so = soalloc(p != 0); > if (so == 0) > return (ENOBUFS); > > TAILQ_INIT(&so->so_incomp); > TAILQ_INIT(&so->so_comp); > so->so_type = type; > so->so_cred = p->p_ucred; > crhold(so->so_cred); > so->so_proto = prp; > error = (*prp->pr_usrreqs->pru_attach)(so, proto, p); > if (error) { > so->so_state |= SS_NOFDREF; > sofree(so); > return (error); > } > *aso = so; > return (0); > } But it's interesting the soalloc() is called with 'p != 0' as an argument. p is never 0 or else you would have already panic'd... you'd panic later on, too, referencing 'p->p_ucred'. -Archie __________________________________________________________________________ Archie Cobbs * Packet Design * http://www.packetdesign.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message