sysctl_net_unix.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/mm.h>
  8. #include <linux/slab.h>
  9. #include <linux/sysctl.h>
  10. #include <net/af_unix.h>
  11. static struct ctl_table unix_table[] = {
  12. {
  13. .procname = "max_dgram_qlen",
  14. .data = &init_net.unx.sysctl_max_dgram_qlen,
  15. .maxlen = sizeof(int),
  16. .mode = 0644,
  17. .proc_handler = proc_dointvec
  18. },
  19. { }
  20. };
  21. int __net_init unix_sysctl_register(struct net *net)
  22. {
  23. struct ctl_table *table;
  24. if (net_eq(net, &init_net)) {
  25. table = unix_table;
  26. } else {
  27. table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
  28. if (!table)
  29. goto err_alloc;
  30. table[0].data = &net->unx.sysctl_max_dgram_qlen;
  31. }
  32. net->unx.ctl = register_net_sysctl(net, "net/unix", table);
  33. if (net->unx.ctl == NULL)
  34. goto err_reg;
  35. return 0;
  36. err_reg:
  37. if (!net_eq(net, &init_net))
  38. kfree(table);
  39. err_alloc:
  40. return -ENOMEM;
  41. }
  42. void unix_sysctl_unregister(struct net *net)
  43. {
  44. struct ctl_table *table;
  45. table = net->unx.ctl->ctl_table_arg;
  46. unregister_net_sysctl_table(net->unx.ctl);
  47. if (!net_eq(net, &init_net))
  48. kfree(table);
  49. }