1 | /* |
2 | * Copyright (c) 2018-2019 Apple Inc. All rights reserved. |
3 | * |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
5 | * |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License |
8 | * Version 2.0 (the 'License'). You may not use this file except in |
9 | * compliance with the License. The rights granted to you under the License |
10 | * may not be used to create, or enable the creation or redistribution of, |
11 | * unlawful or unlicensed copies of an Apple operating system, or to |
12 | * circumvent, violate, or enable the circumvention or violation of, any |
13 | * terms of an Apple operating system software license agreement. |
14 | * |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. |
17 | * |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and |
24 | * limitations under the License. |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
27 | */ |
28 | |
29 | |
30 | #include <sys/sysctl.h> |
31 | #include <sys/proc.h> |
32 | #include <net/multi_layer_pkt_log.h> |
33 | |
34 | SYSCTL_NODE(_net, OID_AUTO, mpklog, |
35 | CTLFLAG_RW | CTLFLAG_LOCKED, 0, "Multi-layer packet logging" ); |
36 | |
37 | /* |
38 | * Note: net_mpklog_enabled allows to override the interface flags IFXF_MPK_LOG |
39 | */ |
40 | int net_mpklog_enabled = 1; |
41 | static int sysctl_net_mpklog_enabled SYSCTL_HANDLER_ARGS; |
42 | SYSCTL_PROC(_net_mpklog, OID_AUTO, enabled, CTLTYPE_INT | CTLFLAG_LOCKED | CTLFLAG_RW, |
43 | 0, 0, &sysctl_net_mpklog_enabled, "I" , "Multi-layer packet logging enabled" ); |
44 | |
45 | static int sysctl_net_mpklog_type SYSCTL_HANDLER_ARGS; |
46 | uint8_t net_mpklog_type = OS_LOG_TYPE_DEFAULT; |
47 | SYSCTL_PROC(_net_mpklog, OID_AUTO, type, CTLTYPE_INT | CTLFLAG_LOCKED | CTLFLAG_RW, |
48 | 0, 0, &sysctl_net_mpklog_type, "I" , "Multi-layer packet logging type" ); |
49 | |
50 | SYSCTL_INT(_net_mpklog, OID_AUTO, version, CTLFLAG_RD | CTLFLAG_LOCKED, |
51 | (int *)NULL, MPKL_VERSION, "Multi-layer packet logging version" ); |
52 | |
53 | static int |
54 | sysctl_net_mpklog_enabled SYSCTL_HANDLER_ARGS |
55 | { |
56 | #pragma unused(arg1, arg2) |
57 | int value = net_mpklog_enabled; |
58 | |
59 | int error = sysctl_handle_int(oidp, arg1: &value, arg2: 0, req); |
60 | if (error || !req->newptr) { |
61 | return error; |
62 | } |
63 | |
64 | net_mpklog_enabled = (value == 0) ? 0 : 1; |
65 | |
66 | os_log(OS_LOG_DEFAULT, "%s:%d set net_mpklog_enabled to %d" , |
67 | proc_best_name(current_proc()), proc_selfpid(), net_mpklog_enabled); |
68 | |
69 | return 0; |
70 | } |
71 | |
72 | static int |
73 | sysctl_net_mpklog_type SYSCTL_HANDLER_ARGS |
74 | { |
75 | #pragma unused(arg1, arg2) |
76 | int value = net_mpklog_type; |
77 | |
78 | int error = sysctl_handle_int(oidp, arg1: &value, arg2: 0, req); |
79 | if (error || !req->newptr) { |
80 | return error; |
81 | } |
82 | |
83 | if (value != OS_LOG_TYPE_DEFAULT && |
84 | value != OS_LOG_TYPE_INFO) { |
85 | return EINVAL; |
86 | } |
87 | net_mpklog_type = (uint8_t)value; |
88 | |
89 | os_log(OS_LOG_DEFAULT, "%s:%d set net_mpklog_type to %u (%s)" , |
90 | proc_best_name(current_proc()), proc_selfpid(), net_mpklog_type, |
91 | net_mpklog_type == OS_LOG_TYPE_DEFAULT ? "default" : "info" ); |
92 | |
93 | return 0; |
94 | } |
95 | |