sysctl_net_unix.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * NET4: Sysctl interface to net af_unix subsystem.
  4. *
  5. * Authors: Mike Shaver.
  6. */
  7. #include <linux/slab.h>
  8. #include <linux/string.h>
  9. #include <linux/sysctl.h>
  10. #include <net/af_unix.h>
  11. #include <net/net_namespace.h>
  12. #include "af_unix.h"
  13. static struct ctl_table unix_table[] = {
  14. {
  15. .procname = "max_dgram_qlen",
  16. .data = &init_net.unx.sysctl_max_dgram_qlen,
  17. .maxlen = sizeof(int),
  18. .mode = 0644,
  19. .proc_handler = proc_dointvec
  20. },
  21. };
  22. int __net_init unix_sysctl_register(struct net *net)
  23. {
  24. struct ctl_table *table;
  25. if (net_eq(net, &init_net)) {
  26. table = unix_table;
  27. } else {
  28. table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
  29. if (!table)
  30. goto err_alloc;
  31. table[0].data = &net->unx.sysctl_max_dgram_qlen;
  32. }
  33. net->unx.ctl = register_net_sysctl_sz(net, "net/unix", table,
  34. ARRAY_SIZE(unix_table));
  35. if (net->unx.ctl == NULL)
  36. goto err_reg;
  37. return 0;
  38. err_reg:
  39. if (!net_eq(net, &init_net))
  40. kfree(table);
  41. err_alloc:
  42. return -ENOMEM;
  43. }
  44. void unix_sysctl_unregister(struct net *net)
  45. {
  46. const struct ctl_table *table;
  47. table = net->unx.ctl->ctl_table_arg;
  48. unregister_net_sysctl_table(net->unx.ctl);
  49. if (!net_eq(net, &init_net))
  50. kfree(table);
  51. }