Re: Checking sysctl values from within the kernel.

2005-08-11 Thread Doug Ambrisko
John Baldwin writes:
| On Friday 05 August 2005 10:50 am, Dan Nelson wrote:
| > In the last episode (Aug 05), Thordur I. Bjornsson said:
| > > If I want to check a sysctl value from within the kernel (e.g. an
| > > KLD), should I use the system calls described in sysctl(3) ?
| > >
| > > If not, what is the propper way to do so ?
| >
| > Since most sysctls are direct mappings onto integer variables in the
| > kernel, just check the variable directly.
| 
| There's also a kernel_sysctl() function available in the kernel for in-kernel 
| access to sysctls.  You might have to lookup the OID for a given name 
| yourself though.  Actually, there's a kernel_sysctlbyname() as well.

This could be a fragile interface though.  I used this scheme to do 
"soft-linking" between modules that could be kldloaded into the kernel
or static.  We called it several times every few seconds.  Over time
the system would wedge on a setjmp or something like that.  We changed
it to a function call since in a static kernel then the problem went away.

Doug A.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Checking sysctl values from within the kernel.

2005-08-06 Thread Jeremie Le Hen
Hi Thordur,

> PS: If you don't mind, what is a "real accessor function" ?

This is a function acting as a wrapper for accessing an integer
declared as static.  This function must of course live in the same
file.  This may be something like this, there may exist neater
interfaces though :


static int age;

int
age_accessor(int *get, int set)
{

if (get != NULL)
*get = age;
else if (set < 0 || set > 125)
return -1;
else
age = set;
return 0;
}


If `get' is not NULL, this means the caller wants to retrieve the
current age value.  Else, this means the caller wants to set the age
value to a new one : if the latter is lower than 0 and greater than
125, this is an incredible age and the accessor reports an error.
Else it sets the new value.

I hope this helped.

Regards,
-- 
Jeremie Le Hen
< jeremie at le-hen dot org >< ttz at chchile dot org >
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Checking sysctl values from within the kernel.

2005-08-05 Thread John Baldwin
On Friday 05 August 2005 12:44 pm, Thordur I. Bjornsson wrote:
> On Fri, 5 Aug 2005 11:01:32 -0400
>
> John Baldwin <[EMAIL PROTECTED]> wrote:
> > On Friday 05 August 2005 10:50 am, Dan Nelson wrote:
> > > In the last episode (Aug 05), Thordur I. Bjornsson said:
> > > > If I want to check a sysctl value from within the kernel (e.g. an
> > > > KLD), should I use the system calls described in sysctl(3) ?
> > > >
> > > > If not, what is the propper way to do so ?
> > >
> > > Since most sysctls are direct mappings onto integer variables in the
> > > kernel, just check the variable directly.
> >
> > There's also a kernel_sysctl() function available in the kernel for
> > in-kernel  access to sysctls.  You might have to lookup the OID for a
> > given name  yourself though.  Actually, there's a
> > kernel_sysctlbyname() as well.
> >
> > --
> > John Baldwin <[EMAIL PROTECTED]>  <><  http://www.FreeBSD.org/~jhb/
> > "Power Users Use the Power to Serve"  =  http://www.FreeBSD.org
>
> Ahh. Cool
> This is not in any manpage ...
>
> I'm trying to understand the first argument to kernel_systcl(),
> kernel_sysctl(struct thread *td, ... )
>
> This thread, that it takes as an argument is this something that I need
> to worry about when writing KLD's or could I just pass a NULL pointer ?
>
> The proplem is that I do not know/understand how threading works in the
> kernel. I'll be lookin into that (although pointers are more then
> welcome ;)

Pass curthread as the thread.

-- 
John Baldwin <[EMAIL PROTECTED]>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Checking sysctl values from within the kernel.

2005-08-05 Thread Scott Long

John Baldwin wrote:

On Friday 05 August 2005 10:50 am, Dan Nelson wrote:


In the last episode (Aug 05), Thordur I. Bjornsson said:


If I want to check a sysctl value from within the kernel (e.g. an
KLD), should I use the system calls described in sysctl(3) ?

If not, what is the propper way to do so ?


Since most sysctls are direct mappings onto integer variables in the
kernel, just check the variable directly.



There's also a kernel_sysctl() function available in the kernel for in-kernel 
access to sysctls.  You might have to lookup the OID for a given name 
yourself though.  Actually, there's a kernel_sysctlbyname() as well.




Shoot, forgot about that function.  However, exporting data throughout
the kernel via the sysctl interface sounds like poor design.

Scott
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Checking sysctl values from within the kernel.

2005-08-05 Thread Thordur I. Bjornsson
On Fri, 5 Aug 2005 11:01:32 -0400
John Baldwin <[EMAIL PROTECTED]> wrote:

> On Friday 05 August 2005 10:50 am, Dan Nelson wrote:
> > In the last episode (Aug 05), Thordur I. Bjornsson said:
> > > If I want to check a sysctl value from within the kernel (e.g. an
> > > KLD), should I use the system calls described in sysctl(3) ?
> > >
> > > If not, what is the propper way to do so ?
> >
> > Since most sysctls are direct mappings onto integer variables in the
> > kernel, just check the variable directly.
> 
> There's also a kernel_sysctl() function available in the kernel for
> in-kernel  access to sysctls.  You might have to lookup the OID for a
> given name  yourself though.  Actually, there's a
> kernel_sysctlbyname() as well.
> 
> -- 
> John Baldwin <[EMAIL PROTECTED]>  <><  http://www.FreeBSD.org/~jhb/
> "Power Users Use the Power to Serve"  =  http://www.FreeBSD.org

Ahh. Cool
This is not in any manpage ... 

I'm trying to understand the first argument to kernel_systcl(),
kernel_sysctl(struct thread *td, ... )

This thread, that it takes as an argument is this something that I need
to worry about when writing KLD's or could I just pass a NULL pointer ?

The proplem is that I do not know/understand how threading works in the
kernel. I'll be lookin into that (although pointers are more then
welcome ;)


-- 
Thordur I.  <[EMAIL PROTECTED]>
Humppa!
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Checking sysctl values from within the kernel.

2005-08-05 Thread Thordur I. Bjornsson
On Fri, 05 Aug 2005 09:33:06 -0600
Scott Long <[EMAIL PROTECTED]> wrote:

> Dan Nelson wrote:
> 
> > In the last episode (Aug 05), Thordur I. Bjornsson said:
> > 
> >>If I want to check a sysctl value from within the kernel (e.g. an
> >>KLD), should I use the system calls described in sysctl(3) ?
> >>
> >>If not, what is the propper way to do so ?
> > 
> > 
> > Since most sysctls are direct mappings onto integer variables in the
> > kernel, just check the variable directly.
> > 
> 
> Most of those integer values are also declared static, so they won't
> be visible to external code, especially not kld's.
> 
> There is no easy way to do this.  I'm sure that you could hack up some
> code to simulate a sysctl syscall from within the kernel, but that
> would be really really gross, evil, and wrong.  What values are you
> trying to get at?  Would it make more sense to export them via real
> accessor functions?
> 
> Scott

I thought that would be a proplem. I'm trying to see the value of
net.inet.tcp.drop_synfin . I could always just use the 
#ifdef TCP_DROP_SYNFIN wich gets set with the kernel option but that
does not mean that the sysctl is set and the user/admin want's to drop
SYNFIN packet's.

Since I'm a novice/newbie when it comes to "kernel" programming any tips
will be really good.

I'll continue to search for this.

PS: If you don't mind, what is a "real accessor function" ?
-- 
Thordur I.  <[EMAIL PROTECTED]>
Humppa!
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Checking sysctl values from within the kernel.

2005-08-05 Thread John Baldwin
On Friday 05 August 2005 10:50 am, Dan Nelson wrote:
> In the last episode (Aug 05), Thordur I. Bjornsson said:
> > If I want to check a sysctl value from within the kernel (e.g. an
> > KLD), should I use the system calls described in sysctl(3) ?
> >
> > If not, what is the propper way to do so ?
>
> Since most sysctls are direct mappings onto integer variables in the
> kernel, just check the variable directly.

There's also a kernel_sysctl() function available in the kernel for in-kernel 
access to sysctls.  You might have to lookup the OID for a given name 
yourself though.  Actually, there's a kernel_sysctlbyname() as well.

-- 
John Baldwin <[EMAIL PROTECTED]>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Checking sysctl values from within the kernel.

2005-08-05 Thread Scott Long

Dan Nelson wrote:


In the last episode (Aug 05), Thordur I. Bjornsson said:


If I want to check a sysctl value from within the kernel (e.g. an
KLD), should I use the system calls described in sysctl(3) ?

If not, what is the propper way to do so ?



Since most sysctls are direct mappings onto integer variables in the
kernel, just check the variable directly.



Most of those integer values are also declared static, so they won't
be visible to external code, especially not kld's.

There is no easy way to do this.  I'm sure that you could hack up some
code to simulate a sysctl syscall from within the kernel, but that would
be really really gross, evil, and wrong.  What values are you trying to
get at?  Would it make more sense to export them via real accessor
functions?

Scott
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Checking sysctl values from within the kernel.

2005-08-05 Thread Dan Nelson
In the last episode (Aug 05), Thordur I. Bjornsson said:
> If I want to check a sysctl value from within the kernel (e.g. an
> KLD), should I use the system calls described in sysctl(3) ?
> 
> If not, what is the propper way to do so ?

Since most sysctls are direct mappings onto integer variables in the
kernel, just check the variable directly.

-- 
Dan Nelson
[EMAIL PROTECTED]
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Checking sysctl values from within the kernel.

2005-08-04 Thread Thordur I. Bjornsson
Hello list.

If I want to check a sysctl value from within the kernel (e.g. an KLD),
should I use the system calls described in sysctl(3) ?

If not, what is the propper way to do so ?

And if it is and I want to do error checking e.g:

if((sysctl(name, namelen, &val, NULL, 0)) != 0) {
"Error in call to sysctl(3) blah blah blah";
}

What would be the correct way to report,stop, &c ?
This is propaply depentand on what I'm doing so...

If this is A&A I'm sorry for the noize, I have not been able to find
anything on google/archives. (It's late ;)

-- 
Thordur I.  <[EMAIL PROTECTED]>
Humppa!
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"