FreeBSD kernel kern code
kern_sysctl.c File Reference
#include <sys/cdefs.h>
#include "opt_capsicum.h"
#include "opt_compat.h"
#include "opt_ktrace.h"
#include <sys/param.h>
#include <sys/fail.h>
#include <sys/systm.h>
#include <sys/capability.h>
#include <sys/kernel.h>
#include <sys/sysctl.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/jail.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/sbuf.h>
#include <sys/sx.h>
#include <sys/sysproto.h>
#include <sys/uio.h>
#include <net/vnet.h>
#include <security/mac/mac_framework.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>
Include dependency graph for kern_sysctl.c:

Go to the source code of this file.

Data Structures

struct  sysctl_args
 

Macros

#define SYSCTL_XLOCK()   sx_xlock(&sysctllock)
 
#define SYSCTL_XUNLOCK()   sx_xunlock(&sysctllock)
 
#define SYSCTL_ASSERT_XLOCKED()   sx_assert(&sysctllock, SA_XLOCKED)
 
#define SYSCTL_INIT()   sx_init(&sysctllock, "sysctl lock")
 
#define SYSCTL_SLEEP(ch, wmesg, timo)   sx_sleep(ch, &sysctllock, 0, wmesg, timo)
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static MALLOC_DEFINE (M_SYSCTL,"sysctl","sysctl internal magic")
 
static MALLOC_DEFINE (M_SYSCTLOID,"sysctloid","sysctl dynamic oids")
 
static MALLOC_DEFINE (M_SYSCTLTMP,"sysctltmp","sysctl temp output buffer")
 
static int sysctl_root (SYSCTL_HANDLER_ARGS)
 
static int sysctl_remove_oid_locked (struct sysctl_oid *oidp, int del, int recurse)
 
static struct sysctl_oid * sysctl_find_oidname (const char *name, struct sysctl_oid_list *list)
 
void sysctl_lock (void)
 
void sysctl_unlock (void)
 
void sysctl_register_oid (struct sysctl_oid *oidp)
 
void sysctl_unregister_oid (struct sysctl_oid *oidp)
 
int sysctl_ctx_init (struct sysctl_ctx_list *c)
 
int sysctl_ctx_free (struct sysctl_ctx_list *clist)
 
struct sysctl_ctx_entry * sysctl_ctx_entry_add (struct sysctl_ctx_list *clist, struct sysctl_oid *oidp)
 
struct sysctl_ctx_entry * sysctl_ctx_entry_find (struct sysctl_ctx_list *clist, struct sysctl_oid *oidp)
 
int sysctl_ctx_entry_del (struct sysctl_ctx_list *clist, struct sysctl_oid *oidp)
 
int sysctl_remove_oid (struct sysctl_oid *oidp, int del, int recurse)
 
int sysctl_remove_name (struct sysctl_oid *parent, const char *name, int del, int recurse)
 
struct sysctl_oid * sysctl_add_oid (struct sysctl_ctx_list *clist, struct sysctl_oid_list *parent, int number, const char *name, int kind, void *arg1, intptr_t arg2, int(*handler)(SYSCTL_HANDLER_ARGS), const char *fmt, const char *descr)
 
void sysctl_rename_oid (struct sysctl_oid *oidp, const char *name)
 
int sysctl_move_oid (struct sysctl_oid *oid, struct sysctl_oid_list *parent)
 
 SET_DECLARE (sysctl_set, struct sysctl_oid)
 
static void sysctl_register_all (void *arg)
 
 SYSINIT (sysctl, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_all, 0)
 
static int sysctl_sysctl_name (SYSCTL_HANDLER_ARGS)
 
static SYSCTL_NODE (_sysctl, 1, name, CTLFLAG_RD|CTLFLAG_CAPRD, sysctl_sysctl_name,"")
 
static int sysctl_sysctl_next_ls (struct sysctl_oid_list *lsp, int *name, u_int namelen, int *next, int *len, int level, struct sysctl_oid **oidpp)
 
static int sysctl_sysctl_next (SYSCTL_HANDLER_ARGS)
 
static SYSCTL_NODE (_sysctl, 2, next, CTLFLAG_RD|CTLFLAG_CAPRD, sysctl_sysctl_next,"")
 
static int name2oid (char *name, int *oid, int *len, struct sysctl_oid **oidpp)
 
static int sysctl_sysctl_name2oid (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_sysctl, 3, name2oid, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY|CTLFLAG_MPSAFE|CTLFLAG_CAPRW, 0, 0, sysctl_sysctl_name2oid,"I","")
 
static int sysctl_sysctl_oidfmt (SYSCTL_HANDLER_ARGS)
 
static SYSCTL_NODE (_sysctl, 4, oidfmt, CTLFLAG_RD|CTLFLAG_MPSAFE|CTLFLAG_CAPRD, sysctl_sysctl_oidfmt,"")
 
static int sysctl_sysctl_oiddescr (SYSCTL_HANDLER_ARGS)
 
static SYSCTL_NODE (_sysctl, 5, oiddescr, CTLFLAG_RD|CTLFLAG_CAPRD, sysctl_sysctl_oiddescr,"")
 
int sysctl_handle_int (SYSCTL_HANDLER_ARGS)
 
int sysctl_msec_to_ticks (SYSCTL_HANDLER_ARGS)
 
int sysctl_handle_long (SYSCTL_HANDLER_ARGS)
 
int sysctl_handle_64 (SYSCTL_HANDLER_ARGS)
 
int sysctl_handle_string (SYSCTL_HANDLER_ARGS)
 
int sysctl_handle_opaque (SYSCTL_HANDLER_ARGS)
 
static int sysctl_old_kernel (struct sysctl_req *req, const void *p, size_t l)
 
static int sysctl_new_kernel (struct sysctl_req *req, void *p, size_t l)
 
int kernel_sysctl (struct thread *td, int *name, u_int namelen, void *old, size_t *oldlenp, void *new, size_t newlen, size_t *retval, int flags)
 
int kernel_sysctlbyname (struct thread *td, char *name, void *old, size_t *oldlenp, void *new, size_t newlen, size_t *retval, int flags)
 
static int sysctl_old_user (struct sysctl_req *req, const void *p, size_t l)
 
static int sysctl_new_user (struct sysctl_req *req, void *p, size_t l)
 
int sysctl_wire_old_buffer (struct sysctl_req *req, size_t len)
 
int sysctl_find_oid (int *name, u_int namelen, struct sysctl_oid **noid, int *nindx, struct sysctl_req *req)
 
int sys___sysctl (struct thread *td, struct sysctl_args *uap)
 
int userland_sysctl (struct thread *td, int *name, u_int namelen, void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen, size_t *retval, int flags)
 
static int sbuf_sysctl_drain (void *arg, const char *data, int len)
 
struct sbuf * sbuf_new_for_sysctl (struct sbuf *s, char *buf, int length, struct sysctl_req *req)
 

Variables

static struct sx sysctllock
 
static struct sx sysctlmemlock
 
struct sysctl_oid_list sysctl__children
 

Macro Definition Documentation

#define SYSCTL_INIT ( )    sx_init(&sysctllock, "sysctl lock")

Definition at line 95 of file kern_sysctl.c.

Referenced by sysctl_register_all().

#define SYSCTL_SLEEP (   ch,
  wmesg,
  timo 
)    sx_sleep(ch, &sysctllock, 0, wmesg, timo)

Definition at line 96 of file kern_sysctl.c.

Referenced by sysctl_remove_oid_locked().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
int kernel_sysctl ( struct thread *  td,
int *  name,
u_int  namelen,
void *  old,
size_t *  oldlenp,
void *  new,
size_t  newlen,
size_t *  retval,
int  flags 
)

Definition at line 1232 of file kern_sysctl.c.

References sysctl_new_kernel(), sysctl_old_kernel(), sysctl_root(), SYSCTL_XLOCK, and SYSCTL_XUNLOCK.

Referenced by kernel_sysctlbyname().

Here is the call graph for this function:

Here is the caller graph for this function:

int kernel_sysctlbyname ( struct thread *  td,
char *  name,
void *  old,
size_t *  oldlenp,
void *  new,
size_t  newlen,
size_t *  retval,
int  flags 
)

Definition at line 1281 of file kern_sysctl.c.

References kernel_sysctl().

Here is the call graph for this function:

static MALLOC_DEFINE ( M_SYSCTL  ,
"sysctl"  ,
"sysctl internal magic"   
)
static
static MALLOC_DEFINE ( M_SYSCTLOID  ,
"sysctloid"  ,
"sysctl dynamic oids"   
)
static
static MALLOC_DEFINE ( M_SYSCTLTMP  ,
"sysctltmp"  ,
"sysctl temp output buffer"   
)
static
static int name2oid ( char *  name,
int *  oid,
int *  len,
struct sysctl_oid **  oidpp 
)
static

Definition at line 841 of file kern_sysctl.c.

References sysctl__children, and SYSCTL_ASSERT_XLOCKED.

Referenced by sysctl_sysctl_name2oid().

Here is the caller graph for this function:

struct sbuf* sbuf_new_for_sysctl ( struct sbuf *  s,
char *  buf,
int  length,
struct sysctl_req *  req 
)
static int sbuf_sysctl_drain ( void *  arg,
const char *  data,
int  len 
)
static

Definition at line 1665 of file kern_sysctl.c.

Referenced by sbuf_new_for_sysctl().

Here is the caller graph for this function:

SET_DECLARE ( sysctl_set  ,
struct sysctl_oid   
)
int sys___sysctl ( struct thread *  td,
struct sysctl_args uap 
)

Definition at line 1548 of file kern_sysctl.c.

References sysctl_args::name, sysctl_args::namelen, sysctl_args::new, sysctl_args::newlen, sysctl_args::old, sysctl_args::oldlenp, and userland_sysctl().

Here is the call graph for this function:

struct sysctl_oid* sysctl_add_oid ( struct sysctl_ctx_list *  clist,
struct sysctl_oid_list *  parent,
int  number,
const char *  name,
int  kind,
void *  arg1,
intptr_t  arg2,
int(*)(SYSCTL_HANDLER_ARGS)  handler,
const char *  fmt,
const char *  descr 
)

Definition at line 491 of file kern_sysctl.c.

References malloc(), parent, printf(), sysctl_ctx_entry_add(), sysctl_find_oidname(), sysctl_register_oid(), SYSCTL_XLOCK, and SYSCTL_XUNLOCK.

Here is the call graph for this function:

struct sysctl_ctx_entry* sysctl_ctx_entry_add ( struct sysctl_ctx_list *  clist,
struct sysctl_oid *  oidp 
)

Definition at line 330 of file kern_sysctl.c.

References malloc(), and SYSCTL_ASSERT_XLOCKED.

Referenced by sysctl_add_oid().

Here is the call graph for this function:

Here is the caller graph for this function:

int sysctl_ctx_entry_del ( struct sysctl_ctx_list *  clist,
struct sysctl_oid *  oidp 
)

Definition at line 365 of file kern_sysctl.c.

References free(), sysctl_ctx_entry_find(), SYSCTL_XLOCK, and SYSCTL_XUNLOCK.

Here is the call graph for this function:

struct sysctl_ctx_entry* sysctl_ctx_entry_find ( struct sysctl_ctx_list *  clist,
struct sysctl_oid *  oidp 
)

Definition at line 345 of file kern_sysctl.c.

References SYSCTL_ASSERT_XLOCKED.

Referenced by sysctl_ctx_entry_del().

Here is the caller graph for this function:

int sysctl_ctx_free ( struct sysctl_ctx_list *  clist)

Definition at line 278 of file kern_sysctl.c.

References free(), panic(), sysctl_register_oid(), sysctl_remove_oid_locked(), SYSCTL_XLOCK, and SYSCTL_XUNLOCK.

Referenced by cpufreq_detach(), and device_sysctl_fini().

Here is the call graph for this function:

Here is the caller graph for this function:

int sysctl_ctx_init ( struct sysctl_ctx_list *  c)

Definition at line 260 of file kern_sysctl.c.

Referenced by cpufreq_attach(), devclass_sysctl_init(), and device_sysctl_init().

Here is the caller graph for this function:

int sysctl_find_oid ( int *  name,
u_int  namelen,
struct sysctl_oid **  noid,
int *  nindx,
struct sysctl_req *  req 
)

Definition at line 1388 of file kern_sysctl.c.

References sysctl__children, and SYSCTL_ASSERT_XLOCKED.

Referenced by sysctl_root(), sysctl_sysctl_oiddescr(), and sysctl_sysctl_oidfmt().

Here is the caller graph for this function:

static struct sysctl_oid* sysctl_find_oidname ( const char *  name,
struct sysctl_oid_list *  list 
)
static

Definition at line 107 of file kern_sysctl.c.

References SYSCTL_ASSERT_XLOCKED.

Referenced by sysctl_add_oid(), sysctl_move_oid(), and sysctl_register_oid().

Here is the caller graph for this function:

int sysctl_handle_64 ( SYSCTL_HANDLER_ARGS  )

Definition at line 1089 of file kern_sysctl.c.

Referenced by sysctl_kern_timecounter_freq().

Here is the caller graph for this function:

int sysctl_handle_long ( SYSCTL_HANDLER_ARGS  )

Definition at line 1043 of file kern_sysctl.c.

Referenced by sysctl_handle_sb_max(), sysctl_hostid(), sysctl_hw_physmem(), sysctl_hw_realmem(), sysctl_hw_usermem(), sysctl_kmem_map_free(), and sysctl_kmem_map_size().

Here is the caller graph for this function:

int sysctl_handle_opaque ( SYSCTL_HANDLER_ARGS  )

Definition at line 1163 of file kern_sysctl.c.

Referenced by ntp_sysctl(), sysctl_intrcnt(), sysctl_intrnames(), sysctl_kern_clockrate(), and sysctl_kern_msgbuf().

Here is the caller graph for this function:

int sysctl_handle_string ( SYSCTL_HANDLER_ARGS  )
void sysctl_lock ( void  )

Definition at line 126 of file kern_sysctl.c.

References SYSCTL_XLOCK.

Referenced by linker_file_register_sysctls(), linker_file_unregister_sysctls(), and vfs_register().

Here is the caller graph for this function:

int sysctl_move_oid ( struct sysctl_oid *  oid,
struct sysctl_oid_list *  parent 
)

Definition at line 568 of file kern_sysctl.c.

References parent, sysctl_find_oidname(), sysctl_register_oid(), sysctl_unregister_oid(), SYSCTL_XLOCK, and SYSCTL_XUNLOCK.

Here is the call graph for this function:

int sysctl_msec_to_ticks ( SYSCTL_HANDLER_ARGS  )

Definition at line 1015 of file kern_sysctl.c.

References hz, and sysctl_handle_int().

Here is the call graph for this function:

static int sysctl_new_kernel ( struct sysctl_req *  req,
void *  p,
size_t  l 
)
static

Definition at line 1220 of file kern_sysctl.c.

Referenced by kernel_sysctl().

Here is the caller graph for this function:

static int sysctl_new_user ( struct sysctl_req *  req,
void *  p,
size_t  l 
)
static

Definition at line 1344 of file kern_sysctl.c.

Referenced by userland_sysctl().

Here is the caller graph for this function:

static SYSCTL_NODE ( _sysctl  ,
,
name  ,
CTLFLAG_RD|  CTLFLAG_CAPRD,
sysctl_sysctl_name  ,
""   
)
static
static SYSCTL_NODE ( _sysctl  ,
,
next  ,
CTLFLAG_RD|  CTLFLAG_CAPRD,
sysctl_sysctl_next  ,
""   
)
static
static SYSCTL_NODE ( _sysctl  ,
,
oidfmt  ,
CTLFLAG_RD|CTLFLAG_MPSAFE|  CTLFLAG_CAPRD,
sysctl_sysctl_oidfmt  ,
""   
)
static
static SYSCTL_NODE ( _sysctl  ,
,
oiddescr  ,
CTLFLAG_RD|  CTLFLAG_CAPRD,
sysctl_sysctl_oiddescr  ,
""   
)
static
static int sysctl_old_kernel ( struct sysctl_req *  req,
const void *  p,
size_t  l 
)
static

Definition at line 1199 of file kern_sysctl.c.

Referenced by kernel_sysctl().

Here is the caller graph for this function:

static int sysctl_old_user ( struct sysctl_req *  req,
const void *  p,
size_t  l 
)
static

Definition at line 1306 of file kern_sysctl.c.

References copyout_nofault().

Referenced by sysctl_wire_old_buffer(), and userland_sysctl().

Here is the call graph for this function:

Here is the caller graph for this function:

SYSCTL_PROC ( _sysctl  ,
,
name2oid  ,
CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_ANYBODY|CTLFLAG_MPSAFE|  CTLFLAG_CAPRW,
,
,
sysctl_sysctl_name2oid  ,
"I"  ,
""   
)
static void sysctl_register_all ( void *  arg)
static

Definition at line 596 of file kern_sysctl.c.

References SYSCTL_INIT, sysctl_register_oid(), SYSCTL_XLOCK, SYSCTL_XUNLOCK, and sysctlmemlock.

Here is the call graph for this function:

void sysctl_register_oid ( struct sysctl_oid *  oidp)

Definition at line 140 of file kern_sysctl.c.

References panic(), parent, printf(), SYSCTL_ASSERT_XLOCKED, sysctl_find_oidname(), and timeout().

Referenced by linker_file_register_sysctls(), sysctl_add_oid(), sysctl_ctx_free(), sysctl_move_oid(), sysctl_register_all(), and vfs_register().

Here is the call graph for this function:

Here is the caller graph for this function:

int sysctl_remove_name ( struct sysctl_oid *  parent,
const char *  name,
int  del,
int  recurse 
)

Definition at line 402 of file kern_sysctl.c.

References sysctl_remove_oid_locked(), SYSCTL_XLOCK, and SYSCTL_XUNLOCK.

Here is the call graph for this function:

int sysctl_remove_oid ( struct sysctl_oid *  oidp,
int  del,
int  recurse 
)

Definition at line 391 of file kern_sysctl.c.

References sysctl_remove_oid_locked(), SYSCTL_XLOCK, and SYSCTL_XUNLOCK.

Referenced by et_deregister().

Here is the call graph for this function:

Here is the caller graph for this function:

static int sysctl_remove_oid_locked ( struct sysctl_oid *  oidp,
int  del,
int  recurse 
)
static

Definition at line 423 of file kern_sysctl.c.

References free(), printf(), SYSCTL_ASSERT_XLOCKED, SYSCTL_SLEEP, and sysctl_unregister_oid().

Referenced by sysctl_ctx_free(), sysctl_remove_name(), and sysctl_remove_oid().

Here is the call graph for this function:

Here is the caller graph for this function:

void sysctl_rename_oid ( struct sysctl_oid *  oidp,
const char *  name 
)

Definition at line 551 of file kern_sysctl.c.

References free(), SYSCTL_XLOCK, and SYSCTL_XUNLOCK.

Referenced by device_sysctl_update().

Here is the call graph for this function:

Here is the caller graph for this function:

static int sysctl_root ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 1437 of file kern_sysctl.c.

References Giant, priv_check(), securelevel_gt(), SYSCTL_ASSERT_XLOCKED, sysctl_find_oid(), SYSCTL_XLOCK, SYSCTL_XUNLOCK, and wakeup().

Referenced by kernel_sysctl(), and userland_sysctl().

Here is the call graph for this function:

Here is the caller graph for this function:

static int sysctl_sysctl_name ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 691 of file kern_sysctl.c.

References buf, snprintf(), sysctl__children, SYSCTL_XLOCK, and SYSCTL_XUNLOCK.

Here is the call graph for this function:

static int sysctl_sysctl_name2oid ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 880 of file kern_sysctl.c.

References free(), malloc(), name2oid(), SYSCTL_XLOCK, and SYSCTL_XUNLOCK.

Here is the call graph for this function:

static int sysctl_sysctl_next ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 815 of file kern_sysctl.c.

References sysctl__children, sysctl_sysctl_next_ls(), SYSCTL_XLOCK, and SYSCTL_XUNLOCK.

Here is the call graph for this function:

static int sysctl_sysctl_next_ls ( struct sysctl_oid_list *  lsp,
int *  name,
u_int  namelen,
int *  next,
int *  len,
int  level,
struct sysctl_oid **  oidpp 
)
static

Definition at line 755 of file kern_sysctl.c.

References level, and SYSCTL_ASSERT_XLOCKED.

Referenced by sysctl_sysctl_next().

Here is the caller graph for this function:

static int sysctl_sysctl_oiddescr ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 951 of file kern_sysctl.c.

References sysctl_find_oid(), SYSCTL_XLOCK, and SYSCTL_XUNLOCK.

Here is the call graph for this function:

static int sysctl_sysctl_oidfmt ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 923 of file kern_sysctl.c.

References sysctl_find_oid(), SYSCTL_XLOCK, and SYSCTL_XUNLOCK.

Here is the call graph for this function:

void sysctl_unlock ( void  )

Definition at line 133 of file kern_sysctl.c.

References SYSCTL_XUNLOCK.

Referenced by linker_file_register_sysctls(), linker_file_unregister_sysctls(), and vfs_register().

Here is the caller graph for this function:

void sysctl_unregister_oid ( struct sysctl_oid *  oidp)

Definition at line 229 of file kern_sysctl.c.

References printf(), and SYSCTL_ASSERT_XLOCKED.

Referenced by linker_file_unregister_sysctls(), sysctl_move_oid(), sysctl_remove_oid_locked(), and vfs_register().

Here is the call graph for this function:

Here is the caller graph for this function:

int sysctl_wire_old_buffer ( struct sysctl_req *  req,
size_t  len 
)
SYSINIT ( sysctl  ,
SI_SUB_KMEM  ,
SI_ORDER_ANY  ,
sysctl_register_all  ,
 
)
int userland_sysctl ( struct thread *  td,
int *  name,
u_int  namelen,
void *  old,
size_t *  oldlenp,
int  inkernel,
void *  new,
size_t  newlen,
size_t *  retval,
int  flags 
)

Definition at line 1578 of file kern_sysctl.c.

References kern_yield(), sysctl_new_user(), sysctl_old_user(), sysctl_root(), SYSCTL_XLOCK, SYSCTL_XUNLOCK, and sysctlmemlock.

Referenced by sys___sysctl().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

struct sysctl_oid_list sysctl__children

Definition at line 101 of file kern_sysctl.c.

Referenced by name2oid(), sysctl_find_oid(), sysctl_sysctl_name(), and sysctl_sysctl_next().

struct sx sysctllock
static

Definition at line 89 of file kern_sysctl.c.

struct sx sysctlmemlock
static

Definition at line 90 of file kern_sysctl.c.

Referenced by sysctl_register_all(), and userland_sysctl().