Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sysctl.c 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright (c) 1999 Ulrich Drepper <drepper@cygnus.com>
  3. * Copyright (c) 2005 Roland McGrath <roland@redhat.com>
  4. * Copyright (c) 2005-2015 Dmitry V. Levin <ldv@altlinux.org>
  5. * Copyright (c) 2014-2018 The strace developers.
  6. * All rights reserved.
  7. *
  8. * SPDX-License-Identifier: LGPL-2.1-or-later
  9. */
  10. #include "defs.h"
  11. #include <linux/sysctl.h>
  12. #include "xlat/sysctl_root.h"
  13. #include "xlat/sysctl_kern.h"
  14. #include "xlat/sysctl_vm.h"
  15. #include "xlat/sysctl_net.h"
  16. #include "xlat/sysctl_net_core.h"
  17. #include "xlat/sysctl_net_unix.h"
  18. #include "xlat/sysctl_net_ipv4.h"
  19. #include "xlat/sysctl_net_ipv4_route.h"
  20. #include "xlat/sysctl_net_ipv4_conf.h"
  21. #include "xlat/sysctl_net_ipv6.h"
  22. #include "xlat/sysctl_net_ipv6_route.h"
  23. SYS_FUNC(sysctl)
  24. {
  25. struct __sysctl_args info;
  26. int *name;
  27. unsigned long size;
  28. if (umove_or_printaddr(tcp, tcp->u_arg[0], &info))
  29. return RVAL_DECODED;
  30. size = sizeof(int) * (unsigned long) info.nlen;
  31. name = (size / sizeof(int) != (unsigned long) info.nlen) ? NULL : malloc(size);
  32. if (name == NULL ||
  33. umoven(tcp, (unsigned long) info.name, size, name) < 0) {
  34. free(name);
  35. if (entering(tcp))
  36. tprintf("{%p, %d, %p, %p, %p, %lu}",
  37. info.name, info.nlen, info.oldval,
  38. info.oldlenp, info.newval, (unsigned long)info.newlen);
  39. return RVAL_DECODED;
  40. }
  41. if (entering(tcp)) {
  42. unsigned int cnt = 0, max_cnt;
  43. tprints("{{");
  44. if (info.nlen == 0)
  45. goto out;
  46. printxval(sysctl_root, name[0], "CTL_???");
  47. ++cnt;
  48. if (info.nlen == 1)
  49. goto out;
  50. switch (name[0]) {
  51. case CTL_KERN:
  52. tprints(", ");
  53. printxval(sysctl_kern, name[1], "KERN_???");
  54. ++cnt;
  55. break;
  56. case CTL_VM:
  57. tprints(", ");
  58. printxval(sysctl_vm, name[1], "VM_???");
  59. ++cnt;
  60. break;
  61. case CTL_NET:
  62. tprints(", ");
  63. printxval(sysctl_net, name[1], "NET_???");
  64. ++cnt;
  65. if (info.nlen == 2)
  66. goto out;
  67. switch (name[1]) {
  68. case NET_CORE:
  69. tprints(", ");
  70. printxval(sysctl_net_core, name[2],
  71. "NET_CORE_???");
  72. break;
  73. case NET_UNIX:
  74. tprints(", ");
  75. printxval(sysctl_net_unix, name[2],
  76. "NET_UNIX_???");
  77. break;
  78. case NET_IPV4:
  79. tprints(", ");
  80. printxval(sysctl_net_ipv4, name[2],
  81. "NET_IPV4_???");
  82. if (info.nlen == 3)
  83. goto out;
  84. switch (name[2]) {
  85. case NET_IPV4_ROUTE:
  86. tprints(", ");
  87. printxval(sysctl_net_ipv4_route,
  88. name[3],
  89. "NET_IPV4_ROUTE_???");
  90. break;
  91. case NET_IPV4_CONF:
  92. tprints(", ");
  93. printxval(sysctl_net_ipv4_conf,
  94. name[3],
  95. "NET_IPV4_CONF_???");
  96. break;
  97. default:
  98. goto out;
  99. }
  100. break;
  101. case NET_IPV6:
  102. tprints(", ");
  103. printxval(sysctl_net_ipv6, name[2],
  104. "NET_IPV6_???");
  105. if (info.nlen == 3)
  106. goto out;
  107. switch (name[2]) {
  108. case NET_IPV6_ROUTE:
  109. tprints(", ");
  110. printxval(sysctl_net_ipv6_route,
  111. name[3],
  112. "NET_IPV6_ROUTE_???");
  113. break;
  114. default:
  115. goto out;
  116. }
  117. break;
  118. default:
  119. goto out;
  120. }
  121. break;
  122. default:
  123. goto out;
  124. }
  125. out:
  126. max_cnt = info.nlen;
  127. if (abbrev(tcp) && max_cnt > max_strlen)
  128. max_cnt = max_strlen;
  129. while (cnt < max_cnt)
  130. tprintf(", %x", name[cnt++]);
  131. if (cnt < (unsigned) info.nlen)
  132. tprints(", ...");
  133. tprintf("}, %d, ", info.nlen);
  134. } else {
  135. size_t oldlen = 0;
  136. if (info.oldval == NULL) {
  137. tprints("NULL");
  138. } else if (umove(tcp, ptr_to_kulong(info.oldlenp), &oldlen) >= 0
  139. && info.nlen >= 2
  140. && ((name[0] == CTL_KERN
  141. && (name[1] == KERN_OSRELEASE
  142. || name[1] == KERN_OSTYPE
  143. )))) {
  144. printpath(tcp, ptr_to_kulong(info.oldval));
  145. } else {
  146. tprintf("%p", info.oldval);
  147. }
  148. tprintf(", %lu, ", (unsigned long)oldlen);
  149. if (info.newval == NULL)
  150. tprints("NULL");
  151. else if (syserror(tcp))
  152. tprintf("%p", info.newval);
  153. else
  154. printpath(tcp, ptr_to_kulong(info.newval));
  155. tprintf(", %lu", (unsigned long)info.newlen);
  156. }
  157. free(name);
  158. return 0;
  159. }