sysctl.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. /* Keep the same order as in fs/proc/proc_sysctl.c */
  38. #define SYSCTL_ZERO ((void *)&sysctl_vals[0])
  39. #define SYSCTL_ONE ((void *)&sysctl_vals[1])
  40. #define SYSCTL_INT_MAX ((void *)&sysctl_vals[2])
  41. extern const int sysctl_vals[];
  42. typedef int proc_handler(struct ctl_table *ctl, int write, void *buffer,
  43. size_t *lenp, loff_t *ppos);
  44. int proc_dostring(struct ctl_table *, int, void *, size_t *, loff_t *);
  45. int proc_dointvec(struct ctl_table *, int, void *, size_t *, loff_t *);
  46. int proc_douintvec(struct ctl_table *, int, void *, size_t *, loff_t *);
  47. int proc_dointvec_minmax(struct ctl_table *, int, void *, size_t *, loff_t *);
  48. int proc_douintvec_minmax(struct ctl_table *table, int write, void *buffer,
  49. size_t *lenp, loff_t *ppos);
  50. int proc_dointvec_jiffies(struct ctl_table *, int, void *, size_t *, loff_t *);
  51. int proc_dointvec_userhz_jiffies(struct ctl_table *, int, void *, size_t *,
  52. loff_t *);
  53. int proc_dointvec_ms_jiffies(struct ctl_table *, int, void *, size_t *,
  54. loff_t *);
  55. int proc_doulongvec_minmax(struct ctl_table *, int, void *, size_t *, loff_t *);
  56. int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int, void *,
  57. size_t *, loff_t *);
  58. int proc_do_large_bitmap(struct ctl_table *, int, void *, size_t *, loff_t *);
  59. int proc_do_static_key(struct ctl_table *table, int write, void *buffer,
  60. size_t *lenp, loff_t *ppos);
  61. /*
  62. * Register a set of sysctl names by calling register_sysctl_table
  63. * with an initialised array of struct ctl_table's. An entry with
  64. * NULL procname terminates the table. table->de will be
  65. * set up by the registration and need not be initialised in advance.
  66. *
  67. * sysctl names can be mirrored automatically under /proc/sys. The
  68. * procname supplied controls /proc naming.
  69. *
  70. * The table's mode will be honoured for proc-fs access.
  71. *
  72. * Leaf nodes in the sysctl tree will be represented by a single file
  73. * under /proc; non-leaf nodes will be represented by directories. A
  74. * null procname disables /proc mirroring at this node.
  75. *
  76. * The data and maxlen fields of the ctl_table
  77. * struct enable minimal validation of the values being written to be
  78. * performed, and the mode field allows minimal authentication.
  79. *
  80. * There must be a proc_handler routine for any terminal nodes
  81. * mirrored under /proc/sys (non-terminals are handled by a built-in
  82. * directory handler). Several default handlers are available to
  83. * cover common cases.
  84. */
  85. /* Support for userspace poll() to watch for changes */
  86. struct ctl_table_poll {
  87. atomic_t event;
  88. wait_queue_head_t wait;
  89. };
  90. static inline void *proc_sys_poll_event(struct ctl_table_poll *poll)
  91. {
  92. return (void *)(unsigned long)atomic_read(&poll->event);
  93. }
  94. #define __CTL_TABLE_POLL_INITIALIZER(name) { \
  95. .event = ATOMIC_INIT(0), \
  96. .wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.wait) }
  97. #define DEFINE_CTL_TABLE_POLL(name) \
  98. struct ctl_table_poll name = __CTL_TABLE_POLL_INITIALIZER(name)
  99. /* A sysctl table is an array of struct ctl_table: */
  100. struct ctl_table {
  101. const char *procname; /* Text ID for /proc/sys, or zero */
  102. void *data;
  103. int maxlen;
  104. umode_t mode;
  105. struct ctl_table *child; /* Deprecated */
  106. proc_handler *proc_handler; /* Callback for text formatting */
  107. struct ctl_table_poll *poll;
  108. void *extra1;
  109. void *extra2;
  110. } __randomize_layout;
  111. struct ctl_node {
  112. struct rb_node node;
  113. struct ctl_table_header *header;
  114. };
  115. /* struct ctl_table_header is used to maintain dynamic lists of
  116. struct ctl_table trees. */
  117. struct ctl_table_header {
  118. union {
  119. struct {
  120. struct ctl_table *ctl_table;
  121. int used;
  122. int count;
  123. int nreg;
  124. };
  125. struct rcu_head rcu;
  126. };
  127. struct completion *unregistering;
  128. struct ctl_table *ctl_table_arg;
  129. struct ctl_table_root *root;
  130. struct ctl_table_set *set;
  131. struct ctl_dir *parent;
  132. struct ctl_node *node;
  133. struct hlist_head inodes; /* head for proc_inode->sysctl_inodes */
  134. };
  135. struct ctl_dir {
  136. /* Header must be at the start of ctl_dir */
  137. struct ctl_table_header header;
  138. struct rb_root root;
  139. };
  140. struct ctl_table_set {
  141. int (*is_seen)(struct ctl_table_set *);
  142. struct ctl_dir dir;
  143. };
  144. struct ctl_table_root {
  145. struct ctl_table_set default_set;
  146. struct ctl_table_set *(*lookup)(struct ctl_table_root *root);
  147. void (*set_ownership)(struct ctl_table_header *head,
  148. struct ctl_table *table,
  149. kuid_t *uid, kgid_t *gid);
  150. int (*permissions)(struct ctl_table_header *head, struct ctl_table *table);
  151. };
  152. /* struct ctl_path describes where in the hierarchy a table is added */
  153. struct ctl_path {
  154. const char *procname;
  155. };
  156. #ifdef CONFIG_SYSCTL
  157. void proc_sys_poll_notify(struct ctl_table_poll *poll);
  158. extern void setup_sysctl_set(struct ctl_table_set *p,
  159. struct ctl_table_root *root,
  160. int (*is_seen)(struct ctl_table_set *));
  161. extern void retire_sysctl_set(struct ctl_table_set *set);
  162. struct ctl_table_header *__register_sysctl_table(
  163. struct ctl_table_set *set,
  164. const char *path, struct ctl_table *table);
  165. struct ctl_table_header *__register_sysctl_paths(
  166. struct ctl_table_set *set,
  167. const struct ctl_path *path, struct ctl_table *table);
  168. struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table);
  169. struct ctl_table_header *register_sysctl_table(struct ctl_table * table);
  170. struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
  171. struct ctl_table *table);
  172. void unregister_sysctl_table(struct ctl_table_header * table);
  173. extern int sysctl_init(void);
  174. void do_sysctl_args(void);
  175. extern int pwrsw_enabled;
  176. extern int unaligned_enabled;
  177. extern int unaligned_dump_stack;
  178. extern int no_unaligned_warning;
  179. extern struct ctl_table sysctl_mount_point[];
  180. extern struct ctl_table random_table[];
  181. extern struct ctl_table firmware_config_table[];
  182. extern struct ctl_table epoll_table[];
  183. #else /* CONFIG_SYSCTL */
  184. static inline struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
  185. {
  186. return NULL;
  187. }
  188. static inline struct ctl_table_header *register_sysctl_paths(
  189. const struct ctl_path *path, struct ctl_table *table)
  190. {
  191. return NULL;
  192. }
  193. static inline struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table)
  194. {
  195. return NULL;
  196. }
  197. static inline void unregister_sysctl_table(struct ctl_table_header * table)
  198. {
  199. }
  200. static inline void setup_sysctl_set(struct ctl_table_set *p,
  201. struct ctl_table_root *root,
  202. int (*is_seen)(struct ctl_table_set *))
  203. {
  204. }
  205. static inline void do_sysctl_args(void)
  206. {
  207. }
  208. #endif /* CONFIG_SYSCTL */
  209. int sysctl_max_threads(struct ctl_table *table, int write, void *buffer,
  210. size_t *lenp, loff_t *ppos);
  211. #endif /* _LINUX_SYSCTL_H */