Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 Jan 2002 15:08:56 -0800 (PST)
From:      Archie Cobbs <archie@dellroad.org>
To:        Florent Parent <Florent.Parent@viagenie.qc.ca>
Cc:        freebsd-net@FreeBSD.ORG, julian@elischer.org
Subject:   Re: netgraph: how to setsockopt on ksocket node ?
Message-ID:  <200201202308.g0KN8uc09321@arch20m.dellroad.org>
In-Reply-To: <135740000.1011562445@blues.viagenie.qc.ca> "from Florent Parent at Jan 20, 2002 04:34:05 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200201202308.g0KN8uc09321>