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-2017 The strace developers.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <linux/sysctl.h>
35 #include "xlat/sysctl_root.h"
36 #include "xlat/sysctl_kern.h"
37 #include "xlat/sysctl_vm.h"
38 #include "xlat/sysctl_net.h"
39 #include "xlat/sysctl_net_core.h"
40 #include "xlat/sysctl_net_unix.h"
41 #include "xlat/sysctl_net_ipv4.h"
42 #include "xlat/sysctl_net_ipv4_route.h"
43 #include "xlat/sysctl_net_ipv4_conf.h"
44 #include "xlat/sysctl_net_ipv6.h"
45 #include "xlat/sysctl_net_ipv6_route.h"
49 struct __sysctl_args info;
53 if (umove_or_printaddr(tcp, tcp->u_arg[0], &info))
56 size = sizeof(int) * (unsigned long) info.nlen;
57 name = (size / sizeof(int) != (unsigned long) info.nlen) ? NULL : malloc(size);
59 umoven(tcp, (unsigned long) info.name, size, name) < 0) {
62 tprintf("{%p, %d, %p, %p, %p, %lu}",
63 info.name, info.nlen, info.oldval,
64 info.oldlenp, info.newval, (unsigned long)info.newlen);
69 unsigned int cnt = 0, max_cnt;
75 printxval(sysctl_root, name[0], "CTL_???");
83 printxval(sysctl_kern, name[1], "KERN_???");
88 printxval(sysctl_vm, name[1], "VM_???");
93 printxval(sysctl_net, name[1], "NET_???");
101 printxval(sysctl_net_core, name[2],
106 printxval(sysctl_net_unix, name[2],
111 printxval(sysctl_net_ipv4, name[2],
119 printxval(sysctl_net_ipv4_route,
121 "NET_IPV4_ROUTE_???");
125 printxval(sysctl_net_ipv4_conf,
127 "NET_IPV4_CONF_???");
135 printxval(sysctl_net_ipv6, name[2],
143 printxval(sysctl_net_ipv6_route,
145 "NET_IPV6_ROUTE_???");
160 if (abbrev(tcp) && max_cnt > max_strlen)
161 max_cnt = max_strlen;
162 while (cnt < max_cnt)
163 tprintf(", %x", name[cnt++]);
164 if (cnt < (unsigned) info.nlen)
166 tprintf("}, %d, ", info.nlen);
169 if (info.oldval == NULL) {
171 } else if (umove(tcp, ptr_to_kulong(info.oldlenp), &oldlen) >= 0
173 && ((name[0] == CTL_KERN
174 && (name[1] == KERN_OSRELEASE
175 || name[1] == KERN_OSTYPE
177 printpath(tcp, ptr_to_kulong(info.oldval));
179 tprintf("%p", info.oldval);
181 tprintf(", %lu, ", (unsigned long)oldlen);
182 if (info.newval == NULL)
184 else if (syserror(tcp))
185 tprintf("%p", info.newval);
187 printpath(tcp, ptr_to_kulong(info.newval));
188 tprintf(", %lu", (unsigned long)info.newlen);