2 * Copyright (C) 2012 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef _NETD_CONSTANTS_H
18 #define _NETD_CONSTANTS_H
28 #include <private/android_filesystem_config.h>
30 #include "utils/RWLock.h"
32 const int PROTECT_MARK = 0x1;
33 const int MAX_SYSTEM_UID = AID_APP - 1;
35 extern const char * const IPTABLES_PATH;
36 extern const char * const IP6TABLES_PATH;
37 extern const char * const IP_PATH;
38 extern const char * const TC_PATH;
39 extern const char * const OEM_SCRIPT_PATH;
40 extern const char * const ADD;
41 extern const char * const DEL;
43 enum IptablesTarget { V4, V6, V4V6 };
45 int execIptables(IptablesTarget target, ...);
46 int execIptablesSilently(IptablesTarget target, ...);
47 int execIptablesRestore(IptablesTarget target, const std::string& commands);
48 bool isIfaceName(const char *name);
49 int parsePrefix(const char *prefix, uint8_t *family, void *address, int size, uint8_t *prefixlen);
51 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
53 #define __INT_STRLEN(i) sizeof(#i)
54 #define _INT_STRLEN(i) __INT_STRLEN(i)
55 #define INT32_STRLEN _INT_STRLEN(INT32_MIN)
56 #define UINT32_STRLEN _INT_STRLEN(UINT32_MAX)
57 #define UINT32_HEX_STRLEN sizeof("0x12345678")
59 #define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
61 const uid_t INVALID_UID = static_cast<uid_t>(-1);
65 Stopwatch() : mStart(std::chrono::steady_clock::now()) {}
66 virtual ~Stopwatch() {};
68 float timeTaken() const {
69 using ms = std::chrono::duration<float, std::ratio<1, 1000>>;
70 return (std::chrono::duration_cast<ms>(
71 std::chrono::steady_clock::now() - mStart)).count();
75 std::chrono::time_point<std::chrono::steady_clock> mStart;
79 struct AddrinfoDeleter {
80 void operator()(struct addrinfo* p) const {
87 typedef std::unique_ptr<struct addrinfo, struct AddrinfoDeleter> ScopedAddrinfo;
90 struct IfaddrsDeleter {
91 void operator()(struct ifaddrs *p) const {
98 typedef std::unique_ptr<struct ifaddrs, struct IfaddrsDeleter> ScopedIfaddrs;
104 * This lock exists to make NetdNativeService RPCs (which come in on multiple Binder threads)
105 * coexist with the commands in CommandListener.cpp. These are presumed not thread-safe because
106 * CommandListener has only one user (NetworkManagementService), which is connected through a
107 * FrameworkListener that passes in commands one at a time.
109 extern android::RWLock gBigNetdLock;
112 } // namespace android
114 #endif // _NETD_CONSTANTS_H