sysctl.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * sysctl.h: General linux system control interface
  4. *
  5. * Begun 24 March 1995, Stephen Tweedie
  6. *
  7. ****************************************************************
  8. ****************************************************************
  9. **
  10. ** WARNING:
  11. ** The values in this file are exported to user space via
  12. ** the sysctl() binary interface. Do *NOT* change the
  13. ** numbering of any existing values here, and do not change
  14. ** any numbers within any one set of values. If you have to
  15. ** redefine an existing interface, use a new number for it.
  16. ** The kernel will then return -ENOTDIR to any application using
  17. ** the old binary interface.
  18. **
  19. ****************************************************************
  20. ****************************************************************
  21. */
  22. #ifndef _LINUX_SYSCTL_H
  23. #define _LINUX_SYSCTL_H
  24. #include <linux/list.h>
  25. #include <linux/rcupdate.h>
  26. #include <linux/wait.h>
  27. #include <linux/rbtree.h>
  28. #include <linux/uidgid.h>
  29. #include <uapi/linux/sysctl.h>
  30. /* For the /proc/sys support */
  31. struct completion;
  32. struct ctl_table;
  33. struct nsproxy;
  34. struct ctl_table_root;
  35. struct ctl_table_header;
  36. struct ctl_dir;
  37. typedef int proc_handler (struct ctl_table *ctl, int write,
  38. void __user *buffer, size_t *lenp, loff_t *ppos);
  39. extern int proc_dostring(struct ctl_table *, int,
  40. void __user *, size_t *, loff_t *);
  41. extern int proc_dointvec(struct ctl_table *, int,
  42. void __user *, size_t *, loff_t *);
  43. extern int proc_douintvec(struct ctl_table *, int,
  44. void __user *, size_t *, loff_t *);
  45. extern int proc_dointvec_minmax(struct ctl_table *, int,
  46. void __user *, size_t *, loff_t *);
  47. extern int proc_douintvec_minmax(struct ctl_table *table, int write,
  48. void __user *buffer, size_t *lenp,
  49. loff_t *ppos);
  50. extern int proc_dointvec_jiffies(struct ctl_table *, int,
  51. void __user *, size_t *, loff_t *);
  52. extern int proc_dointvec_userhz_jiffies(struct ctl_table *, int,
  53. void __user *, size_t *, loff_t *);
  54. extern int proc_dointvec_ms_jiffies(struct ctl_table *, int,
  55. void __user *, size_t *, loff_t *);
  56. extern int proc_doulongvec_minmax(struct ctl_table *, int,
  57. void __user *, size_t *, loff_t *);
  58. extern int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int,
  59. void __user *, size_t *, loff_t *);
  60. extern int proc_do_large_bitmap(struct ctl_table *, int,
  61. void __user *, size_t *, loff_t *);
  62. /*
  63. * Register a set of sysctl names by calling register_sysctl_table
  64. * with an initialised array of struct ctl_table's. An entry with
  65. * NULL procname terminates the table. table->de will be
  66. * set up by the registration and need not be initialised in advance.
  67. *
  68. * sysctl names can be mirrored automatically under /proc/sys. The
  69. * procname supplied controls /proc naming.
  70. *
  71. * The table's mode will be honoured both for sys_sysctl(2) and
  72. * proc-fs access.
  73. *
  74. * Leaf nodes in the sysctl tree will be represented by a single file
  75. * under /proc; non-leaf nodes will be represented by directories. A
  76. * null procname disables /proc mirroring at this node.
  77. *
  78. * sysctl(2) can automatically manage read and write requests through
  79. * the sysctl table. The data and maxlen fields of the ctl_table
  80. * struct enable minimal validation of the values being written to be
  81. * performed, and the mode field allows minimal authentication.
  82. *
  83. * There must be a proc_handler routine for any terminal nodes
  84. * mirrored under /proc/sys (non-terminals are handled by a built-in
  85. * directory handler). Several default handlers are available to
  86. * cover common cases.
  87. */
  88. /* Support for userspace poll() to watch for changes */
  89. struct ctl_table_poll {
  90. atomic_t event;
  91. wait_queue_head_t wait;
  92. };
  93. static inline void *proc_sys_poll_event(struct ctl_table_poll *poll)
  94. {
  95. return (void *)(unsigned long)atomic_read(&poll->event);
  96. }
  97. #define __CTL_TABLE_POLL_INITIALIZER(name) { \
  98. .event = ATOMIC_INIT(0), \
  99. .wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.wait) }
  100. #define DEFINE_CTL_TABLE_POLL(name) \
  101. struct ctl_table_poll name = __CTL_TABLE_POLL_INITIALIZER(name)
  102. /* A sysctl table is an array of struct ctl_table: */
  103. struct ctl_table
  104. {
  105. const char *procname; /* Text ID for /proc/sys, or zero */
  106. void *data;
  107. int maxlen;
  108. umode_t mode;
  109. struct ctl_table *child; /* Deprecated */
  110. proc_handler *proc_handler; /* Callback for text formatting */
  111. struct ctl_table_poll *poll;
  112. void *extra1;
  113. void *extra2;
  114. } __randomize_layout;
  115. struct ctl_node {
  116. struct rb_node node;
  117. struct ctl_table_header *header;
  118. };
  119. /* struct ctl_table_header is used to maintain dynamic lists of
  120. struct ctl_table trees. */
  121. struct ctl_table_header
  122. {
  123. union {
  124. struct {
  125. struct ctl_table *ctl_table;
  126. int used;
  127. int count;
  128. int nreg;
  129. };
  130. struct rcu_head rcu;
  131. };
  132. struct completion *unregistering;
  133. struct ctl_table *ctl_table_arg;
  134. struct ctl_table_root *root;
  135. struct ctl_table_set *set;
  136. struct ctl_dir *parent;
  137. struct ctl_node *node;
  138. struct hlist_head inodes; /* head for proc_inode->sysctl_inodes */
  139. };
  140. struct ctl_dir {
  141. /* Header must be at the start of ctl_dir */
  142. struct ctl_table_header header;
  143. struct rb_root root;
  144. };
  145. struct ctl_table_set {
  146. int (*is_seen)(struct ctl_table_set *);
  147. struct ctl_dir dir;
  148. };
  149. struct ctl_table_root {
  150. struct ctl_table_set default_set;
  151. struct ctl_table_set *(*lookup)(struct ctl_table_root *root);
  152. void (*set_ownership)(struct ctl_table_header *head,
  153. struct ctl_table *table,
  154. kuid_t *uid, kgid_t *gid);
  155. int (*permissions)(struct ctl_table_header *head, struct ctl_table *table);
  156. };
  157. /* struct ctl_path describes where in the hierarchy a table is added */
  158. struct ctl_path {
  159. const char *procname;
  160. };
  161. #ifdef CONFIG_SYSCTL
  162. void proc_sys_poll_notify(struct ctl_table_poll *poll);
  163. extern void setup_sysctl_set(struct ctl_table_set *p,
  164. struct ctl_table_root *root,
  165. int (*is_seen)(struct ctl_table_set *));
  166. extern void retire_sysctl_set(struct ctl_table_set *set);
  167. struct ctl_table_header *__register_sysctl_table(
  168. struct ctl_table_set *set,
  169. const char *path, struct ctl_table *table);
  170. struct ctl_table_header *__register_sysctl_paths(
  171. struct ctl_table_set *set,
  172. const struct ctl_path *path, struct ctl_table *table);
  173. struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table);
  174. struct ctl_table_header *register_sysctl_table(struct ctl_table * table);
  175. struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
  176. struct ctl_table *table);
  177. void unregister_sysctl_table(struct ctl_table_header * table);
  178. extern int sysctl_init(void);
  179. extern struct ctl_table sysctl_mount_point[];
  180. #else /* CONFIG_SYSCTL */
  181. static inline struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
  182. {
  183. return NULL;
  184. }
  185. static inline struct ctl_table_header *register_sysctl_paths(
  186. const struct ctl_path *path, struct ctl_table *table)
  187. {
  188. return NULL;
  189. }
  190. static inline struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table)
  191. {
  192. return NULL;
  193. }
  194. static inline void unregister_sysctl_table(struct ctl_table_header * table)
  195. {
  196. }
  197. static inline void setup_sysctl_set(struct ctl_table_set *p,
  198. struct ctl_table_root *root,
  199. int (*is_seen)(struct ctl_table_set *))
  200. {
  201. }
  202. #endif /* CONFIG_SYSCTL */
  203. int sysctl_max_threads(struct ctl_table *table, int write,
  204. void __user *buffer, size_t *lenp, loff_t *ppos);
  205. #endif /* _LINUX_SYSCTL_H */