xfrm_sysctl.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <linux/sysctl.h>
  2. #include <linux/slab.h>
  3. #include <net/net_namespace.h>
  4. #include <net/xfrm.h>
  5. static void __net_init __xfrm_sysctl_init(struct net *net)
  6. {
  7. net->xfrm.sysctl_aevent_etime = XFRM_AE_ETIME;
  8. net->xfrm.sysctl_aevent_rseqth = XFRM_AE_SEQT_SIZE;
  9. net->xfrm.sysctl_larval_drop = 1;
  10. net->xfrm.sysctl_acq_expires = 30;
  11. }
  12. #ifdef CONFIG_SYSCTL
  13. static struct ctl_table xfrm_table[] = {
  14. {
  15. .procname = "xfrm_aevent_etime",
  16. .maxlen = sizeof(u32),
  17. .mode = 0644,
  18. .proc_handler = proc_dointvec
  19. },
  20. {
  21. .procname = "xfrm_aevent_rseqth",
  22. .maxlen = sizeof(u32),
  23. .mode = 0644,
  24. .proc_handler = proc_dointvec
  25. },
  26. {
  27. .procname = "xfrm_larval_drop",
  28. .maxlen = sizeof(int),
  29. .mode = 0644,
  30. .proc_handler = proc_dointvec
  31. },
  32. {
  33. .procname = "xfrm_acq_expires",
  34. .maxlen = sizeof(int),
  35. .mode = 0644,
  36. .proc_handler = proc_dointvec
  37. },
  38. {}
  39. };
  40. int __net_init xfrm_sysctl_init(struct net *net)
  41. {
  42. struct ctl_table *table;
  43. __xfrm_sysctl_init(net);
  44. table = kmemdup(xfrm_table, sizeof(xfrm_table), GFP_KERNEL);
  45. if (!table)
  46. goto out_kmemdup;
  47. table[0].data = &net->xfrm.sysctl_aevent_etime;
  48. table[1].data = &net->xfrm.sysctl_aevent_rseqth;
  49. table[2].data = &net->xfrm.sysctl_larval_drop;
  50. table[3].data = &net->xfrm.sysctl_acq_expires;
  51. /* Don't export sysctls to unprivileged users */
  52. if (net->user_ns != &init_user_ns)
  53. table[0].procname = NULL;
  54. net->xfrm.sysctl_hdr = register_net_sysctl(net, "net/core", table);
  55. if (!net->xfrm.sysctl_hdr)
  56. goto out_register;
  57. return 0;
  58. out_register:
  59. kfree(table);
  60. out_kmemdup:
  61. return -ENOMEM;
  62. }
  63. void __net_exit xfrm_sysctl_fini(struct net *net)
  64. {
  65. struct ctl_table *table;
  66. table = net->xfrm.sysctl_hdr->ctl_table_arg;
  67. unregister_net_sysctl_table(net->xfrm.sysctl_hdr);
  68. kfree(table);
  69. }
  70. #else
  71. int __net_init xfrm_sysctl_init(struct net *net)
  72. {
  73. __xfrm_sysctl_init(net);
  74. return 0;
  75. }
  76. #endif