Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/sysctl.h>
- static struct ctl_table_header * test_sysctl_header1;
- static struct ctl_table_header * test_sysctl_header2;
- int value1 = 0;
- int value2 = 1;
- int min = 10;
- int max = 20;
- /*only values between min and max can be written to value1 and value2 respectively. */
- static ctl_table test_table1[] = {
- {
- .ctl_name = CTL_UNNUMBERED,
- .procname = "value1",
- .data = &value1,
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = &proc_dointvec_minmax,
- .strategy = &sysctl_intvec,
- .extra1 = &min,
- .extra2 = &max
- },
- {
- .ctl_name = CTL_UNNUMBERED,
- .procname = "value2",
- .data = &value2,
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = &proc_dointvec_minmax,
- .strategy = &sysctl_intvec,
- .extra1 = &min,
- .extra2 = &max
- },
- { .ctl_name = 0 }
- };
- static ctl_table test_table2[] = {
- {
- .ctl_name = CTL_UNNUMBERED,
- .procname = "value1",
- .data = &value1,
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = &proc_dointvec_minmax,
- .strategy = &sysctl_intvec,
- .extra1 = &min,
- .extra2 = &max
- },
- {
- .ctl_name = CTL_UNNUMBERED,
- .procname = "value2",
- .data = &value2,
- .maxlen = sizeof(int),
- .mode = 0644,
- .proc_handler = &proc_dointvec_minmax,
- .strategy = &sysctl_intvec,
- .extra1 = &min,
- .extra2 = &max
- },
- { .ctl_name = 0 }
- };
- static ctl_table test_net_table1[] = {
- {
- .ctl_name = CTL_UNNUMBERED,
- .procname = "test1",
- .mode = 0555,
- .child = test_table1
- },
- { .ctl_name = 0 }
- };
- static ctl_table test_net_table2[] = {
- {
- .ctl_name = CTL_UNNUMBERED,
- .procname = "test2",
- .mode = 0555,
- .child = test_table2
- },
- { .ctl_name = 0 }
- };
- static ctl_table test_root_table1[] = {
- {
- .ctl_name = CTL_UNNUMBERED,
- .procname = "net1",
- .mode = 0555,
- .child = test_net_table1
- },
- { .ctl_name = 0 }
- };
- static ctl_table test_root_table2[] = {
- {
- .ctl_name = CTL_UNNUMBERED,
- .procname = "net2",
- .mode = 0555,
- .child = test_net_table2
- },
- { .ctl_name = 0 }
- };
- static struct ctl_path net1_path[] = {
- { .procname = "my_net", .ctl_name = CTL_UNNUMBERED },
- { }
- };
- static int __init sysctl_module_init(void)
- {
- test_sysctl_header1 = register_sysctl_paths(net1_path, test_root_table1);
- test_sysctl_header2 = register_sysctl_paths(net1_path, test_root_table2);
- return 0;
- }
- static void __exit sysctl_module_exit(void)
- {
- unregister_sysctl_table(test_sysctl_header1);
- unregister_sysctl_table(test_sysctl_header2);
- }
- module_init(sysctl_module_init);
- module_exit(sysctl_module_exit);
- MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement