Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Jul 2002 13:56:28 -0400 (EDT)
From:      Kelly Yancey <kbyanc@posi.net>
To:        Juan Francisco Rodriguez Hervella <jrh@it.uc3m.es>
Cc:        freebsd-net@FreeBSD.ORG
Subject:   Re: sysctl inferface question
Message-ID:  <Pine.BSF.4.05.10207111339020.32666-100000@kronos.networkrichmond.com>
In-Reply-To: <3D2D9D4E.74A1B6F4@it.uc3m.es>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 11 Jul 2002, Juan Francisco Rodriguez Hervella wrote:

> Hello:
> 
> I'm very confused with the sysctl internals.
> 
> For example, looking at the kernel source code of FreeBSD, I've realized
> 
> of the following:
> 
> netinet/in_proco.c:
>             SYSCTL_NODE(_net_inet6, IPPROTO_DIVERT,     divert,
> CTLFLAG_RW, 0,  "DIVERT");
> netinet/ip_divert.c:
>             SYSCTL_DECL(_net_inet_divert);
> netinet/ip_divert.c:
>             SYSCTL_PROC(_net_inet_divert, OID_AUTO, pcblist, CTLFLAG_RD,
> 0, 0,
>             div_pcblist, "S,xinpcb", "List of active divert sockets");
> 
> Isn't this redundant ? I mean, if there is a "SYSCTL_NODE", there is
> *no* need for having
> "SYSCTL_DECL" in "ip_divert.c"... I am wrong ?
> 

  It is a scoping/linking issue: the SYSCTL_DECL is needed in
netinet/ip_divert.c so that children may be added to the node which was
defined in netinet/in_proto.c.  Without it, the very next line in
netinet/ip_divert would fail to compile because it coulding find the
parent node.  A good C reference would probably better explain the
difference between declaring a variable and defining a variable, but that
is exactly the difference you are witnessing here.

> Also, I don't undertand the meaning of the "fmt" field....what is it for
> ? What's the
> meaning of "S,xinpcb" in the above example ?
> 
> Thanks.
> 
> --
> JFRH.
> 

  The fmt field is used by sysctl(8) to format the data returned from the
kernel.  The "S,xinpcb" format string tells sysctl(8) to use it's
definition of "xinpcb" formatting to render the structure.  Take a look at
/usr/src/sbin/sysctl/sysctl.c; it is a pretty light read.

  Good luck,

  Kelly

--
Kelly Yancey -- kbyanc@{posi.net,FreeBSD.org}



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?Pine.BSF.4.05.10207111339020.32666-100000>