sysctl_net_unix.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * NET4: Sysctl interface to net af_unix subsystem.
  3. *
  4. * Authors: Mike Shaver.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/mm.h>
  12. #include <linux/slab.h>
  13. #include <linux/sysctl.h>
  14. #include <net/af_unix.h>
  15. static struct ctl_table unix_table[] = {
  16. {
  17. .procname = "max_dgram_qlen",
  18. .data = &init_net.unx.sysctl_max_dgram_qlen,
  19. .maxlen = sizeof(int),
  20. .mode = 0644,
  21. .proc_handler = proc_dointvec
  22. },
  23. { }
  24. };
  25. int __net_init unix_sysctl_register(struct net *net)
  26. {
  27. struct ctl_table *table;
  28. table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
  29. if (table == NULL)
  30. goto err_alloc;
  31. /* Don't export sysctls to unprivileged users */
  32. if (net->user_ns != &init_user_ns)
  33. table[0].procname = NULL;
  34. table[0].data = &net->unx.sysctl_max_dgram_qlen;
  35. net->unx.ctl = register_net_sysctl(net, "net/unix", table);
  36. if (net->unx.ctl == NULL)
  37. goto err_reg;
  38. return 0;
  39. err_reg:
  40. kfree(table);
  41. err_alloc:
  42. return -ENOMEM;
  43. }
  44. void unix_sysctl_unregister(struct net *net)
  45. {
  46. struct ctl_table *table;
  47. table = net->unx.ctl->ctl_table_arg;
  48. unregister_net_sysctl_table(net->unx.ctl);
  49. kfree(table);
  50. }