Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Aug 2002 17:25:12 +0800
From:      "ouyang kai" <oykai@msn.com>
To:        "Lambert Terry" <tlambert2@mindspring.com>, <freebsd-hackers@FreeBSD.ORG>
Subject:   Re: About 'sysctl' routine problem?
Message-ID:  <OE173Kegmprho5fimNY000222e7@hotmail.com>

next in thread | raw e-mail | index | archive | help

------=_NextPart_001_0000_01C24480.B630A860
Content-Type: multipart/alternative; boundary="----=_NextPart_002_0001_01C24480.B630A860"


------=_NextPart_002_0001_01C24480.B630A860
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: quoted-printable

Dear Terry,
  Thank you!
>Once again, we are talking about linker sets.  This is a little
>more complex, though, since you have to take the "boot environment"
>into account, as well (the boot environment is the basis for a
>preinitialized sysctl space contents, seperate from the code you
>see in the kernel itself for the declarations of specific sysctl
>OIDs that are added to the ones exported before the kernel is even
>really started.
 in kern_mib.c:
SYSCTL_NODE(, CTL_NET,   net,    CTLFLAG_RW, 0,
 "Network, (see socket.h)");
-->
struct sysctl_oid_list sysctl_net_children;
static struct sysctl_oid sysctl__net =3D {   =20
 &sysctl_children, { 0 },    =20
 CTL_NET, CTLTYPE_NODE|CTLFLAG_RW, (void*)&sysctl_net_children, =20
 0, "net", 0, "N", 0 }; =20
DATA_SET(sysctl_set, sysctl__net);
It seem like the SYSINIT macro.
> TUNABLE_INT_DECL
> TUNABLE_INT_FETCH
> SYSCTL_DECL
> SYSCTL_NODE
> SYSCTL_INT
> SYSCTL_STRUCT
> SYSCTL_PROC
 Whether do they register also in mi_startup() like other devices, when t=
he
'sipp' is looped to 'SI_SUB_TUNABLES'?
 You said some specific sysctl OIDs can be added before the kernel is eve=
n really started,
I want to know when they will be added? Could you give me an example?
  =20
I try to trace some routine from the 'ifconfig' program source code.
The following code is copied from 'ifconfig' program:
 mib[0] =3D CTL_NET;
 mib[1] =3D PF_ROUTE;
 mib[2] =3D 0;
 mib[3] =3D 0; /* address family */
 mib[4] =3D NET_RT_IFLIST;
 mib[5] =3D 0;
 /* if particular family specified, only ask about it */
 if (afp)
  mib[3] =3D afp->af_af;
 if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
  errx(1, "iflist-sysctl-estimate");
From the SYSCTL_NODE(_net, PF_ROUTE, routetable, CTLFLAG_RD, sysctl_rtsoc=
k, "");
we can know the RF_ROUTE is the 'net's children', and its' handler is sys=
ctl_rtsock.
So, the kernel will call sysctl_rtsock, right?
in sysctl_rtsock function:
 case NET_RT_IFLIST:
  error =3D sysctl_iflist(af, &w);
So, this time, the kernel will call sysctl_iflist finally, right?
But I have some wonder how the 'sysctl' command transfer from user space =
to kernel space?
I find the line in sysproto.h:
int __sysctl __P((struct proc *, struct sysctl_args *));
I think whether the 'sysctl' is changed to '__sysctl' in kernel space?
If that is right, the __sysctl is how conect with sysctl_rtsock?
   Thank you very much!:-)
Best Regards
Ouyang KaiGet more from the Web.  FREE MSN Explorer download : http://exp=
lorer.msn.com

------=_NextPart_002_0001_01C24480.B630A860
Content-Type: text/html; charset="gb2312"
Content-Transfer-Encoding: quoted-printable

<HTML><BODY STYLE=3D"font:10pt verdana; border:none;"><DIV>Dear Terry,<BR=
>&nbsp; Thank you!</DIV> <DIV>&gt;Once again, we are talking about linker=
 sets.&nbsp; This is a little<BR>&gt;more complex, though, since you have=
 to take the "boot environment"<BR>&gt;into account, as well (the boot en=
vironment is the basis for a<BR>&gt;preinitialized sysctl space contents,=
 seperate from the code you<BR>&gt;see in the kernel itself for the decla=
rations of specific sysctl<BR>&gt;OIDs that are added to the ones exporte=
d before the kernel is even<BR>&gt;really started.</DIV> <DIV>&nbsp;in ke=
rn_mib.c:<BR>SYSCTL_NODE(, CTL_NET,&nbsp;&nbsp; net,&nbsp;&nbsp;&nbsp; CT=
LFLAG_RW, 0,<BR>&nbsp;"Network, (see socket.h)");<BR>--&gt;<BR>struct sys=
ctl_oid_list sysctl_net_children;<BR>static struct sysctl_oid sysctl__net=
 =3D {&nbsp;&nbsp; <BR>&nbsp;&amp;sysctl_children, { 0 },&nbsp;&nbsp;&nbs=
p; <BR>&nbsp;CTL_NET, CTLTYPE_NODE|CTLFLAG_RW, (void*)&amp;sysctl_net_chi=
ldren, <BR>&nbsp;0, "net", 0, "N", 0 };&nbsp;<BR>DATA_SET(sysctl_set, sys=
ctl__net);</DIV> <DIV>It seem like the SYSINIT macro.<BR>&gt;&nbsp;TUNABL=
E_INT_DECL<BR>&gt;&nbsp;TUNABLE_INT_FETCH<BR>&gt;&nbsp;SYSCTL_DECL<BR>&gt=
;&nbsp;SYSCTL_NODE<BR>&gt;&nbsp;SYSCTL_INT<BR>&gt;&nbsp;SYSCTL_STRUCT<BR>=
&gt;&nbsp;SYSCTL_PROC<BR>&nbsp;Whether do they register also in mi_startu=
p() like other devices, when the<BR>'sipp' is looped to 'SI_SUB_TUNABLES'=
?<BR>&nbsp;You said some specific sysctl OIDs can be added before the ker=
nel is even really started,<BR>I want to know when they will be added? Co=
uld you give me an example?<BR>&nbsp; <BR>I try to trace some routine fro=
m the 'ifconfig' program source code.<BR>The following code is copied fro=
m 'ifconfig' program:<BR>&nbsp;mib[0] =3D CTL_NET;<BR>&nbsp;mib[1] =3D PF=
_ROUTE;<BR>&nbsp;mib[2] =3D 0;<BR>&nbsp;mib[3] =3D 0;&nbsp;/* address fam=
ily */<BR>&nbsp;mib[4] =3D NET_RT_IFLIST;<BR>&nbsp;mib[5] =3D 0;</DIV> <D=
IV>&nbsp;/* if particular family specified, only ask about it */<BR>&nbsp=
;if (afp)<BR>&nbsp;&nbsp;mib[3] =3D afp-&gt;af_af;</DIV> <DIV>&nbsp;if (s=
ysctl(mib, 6, NULL, &amp;needed, NULL, 0) &lt; 0)<BR>&nbsp;&nbsp;errx(1, =
"iflist-sysctl-estimate");</DIV> <DIV>From the SYSCTL_NODE(_net, PF_ROUTE=
, routetable, CTLFLAG_RD, sysctl_rtsock, "");<BR>we can know the RF_ROUTE=
 is the 'net's children', and its' handler is sysctl_rtsock.<BR>So, the k=
ernel will call sysctl_rtsock, right?<BR>in sysctl_rtsock function:<BR>&n=
bsp;case NET_RT_IFLIST:<BR>&nbsp;&nbsp;error =3D sysctl_iflist(af, &amp;w=
);<BR>So, this time, the kernel will call sysctl_iflist finally, right?<B=
R>But I have some wonder how the 'sysctl' command transfer from user spac=
e to kernel space?<BR>I find the line in sysproto.h:<BR>int&nbsp;__sysctl=
 __P((struct proc *, struct sysctl_args *));<BR>I think whether the 'sysc=
tl' is changed to '__sysctl' in kernel space?<BR>If that is right, the __=
sysctl is how conect with sysctl_rtsock?</DIV> <DIV>&nbsp;&nbsp; Thank yo=
u very much!:-)</DIV> <DIV>Best Regards<BR>Ouyang Kai</DIV></BODY></HTML>=
<br clear=3Dall><hr>Get more from the Web.  FREE MSN Explorer download : =
<a href=3D'http://explorer.msn.com'>http://explorer.msn.com</a><br></p>;

------=_NextPart_002_0001_01C24480.B630A860--


------=_NextPart_001_0000_01C24480.B630A860
Content-Type: text/plain; name="sysctl2.txt"
Content-Disposition: attachment; filename="sysctl2.txt"
Content-Transfer-Encoding: quoted-printable

Dear Terry,
  Thank you!

>Once again, we are talking about linker sets.  This is a little
>more complex, though, since you have to take the "boot environment"
>into account, as well (the boot environment is the basis for a
>preinitialized sysctl space contents, seperate from the code you
>see in the kernel itself for the declarations of specific sysctl
>OIDs that are added to the ones exported before the kernel is even
>really started.

 in kern_mib.c:
SYSCTL_NODE(, CTL_NET,	  net,    CTLFLAG_RW, 0,
	"Network, (see socket.h)");
-->
struct sysctl_oid_list sysctl_net_children;
static struct sysctl_oid sysctl__net =3D {		 =20
	&sysctl_children, { 0 },			 =20
	CTL_NET, CTLTYPE_NODE|CTLFLAG_RW, (void*)&sysctl_net_children, =20
	0, "net", 0, "N", 0 };	=09
DATA_SET(sysctl_set, sysctl__net);

It seem like the SYSINIT macro.
>	TUNABLE_INT_DECL
>	TUNABLE_INT_FETCH
>	SYSCTL_DECL
>	SYSCTL_NODE
>	SYSCTL_INT
>	SYSCTL_STRUCT
>	SYSCTL_PROC
 Whether do they register also in mi_startup() like other devices, when t=
he
'sipp' is looped to 'SI_SUB_TUNABLES'?
 You said some specific sysctl OIDs can be added before the kernel is eve=
n really started,
I want to know when they will be added? Could you give me an example?
	 =20
I try to trace some routine from the 'ifconfig' program source code.
The following code is copied from 'ifconfig' program:
	mib[0] =3D CTL_NET;
	mib[1] =3D PF_ROUTE;
	mib[2] =3D 0;
	mib[3] =3D 0;	/* address family */
	mib[4] =3D NET_RT_IFLIST;
	mib[5] =3D 0;

	/* if particular family specified, only ask about it */
	if (afp)
		mib[3] =3D afp->af_af;

	if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
		errx(1, "iflist-sysctl-estimate");

From the SYSCTL_NODE(_net, PF_ROUTE, routetable, CTLFLAG_RD, sysctl_rtsoc=
k, "");
we can know the RF_ROUTE is the 'net's children', and its' handler is sys=
ctl_rtsock.
So, the kernel will call sysctl_rtsock, right?
in sysctl_rtsock function:
	case NET_RT_IFLIST:
		error =3D sysctl_iflist(af, &w);
So, this time, the kernel will call sysctl_iflist finally, right?
But I have some wonder how the 'sysctl' command transfer from user space =
to kernel space?
I find the line in sysproto.h:
int	__sysctl __P((struct proc *, struct sysctl_args *));
I think whether the 'sysctl' is changed to '__sysctl' in kernel space?
If that is right, the __sysctl is how conect with sysctl_rtsock?

   Thank you very much!:-)

Best Regards
Ouyang Kai

------=_NextPart_001_0000_01C24480.B630A860--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




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