xfrm_sysctl.c 1.9 KB

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