Robert Greenwalt | c462177 | 2012-01-31 12:46:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _NETD_CONSTANTS_H |
| 18 | #define _NETD_CONSTANTS_H |
| 19 | |
Jeff Sharkey | 8e188ed | 2012-07-12 18:32:03 -0700 | [diff] [blame] | 20 | #include <string> |
| 21 | #include <list> |
| 22 | #include <stdarg.h> |
Lorenzo Colitti | 699aa99 | 2016-04-15 10:22:37 +0900 | [diff] [blame^] | 23 | |
| 24 | #include <chrono> |
| 25 | |
Felipe Leme | 5ebbbd8 | 2016-03-07 09:25:50 -0800 | [diff] [blame] | 26 | #include <private/android_filesystem_config.h> |
Robert Greenwalt | c462177 | 2012-01-31 12:46:45 -0800 | [diff] [blame] | 27 | |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 28 | #include "utils/RWLock.h" |
| 29 | |
Chad Brubaker | 2a39012 | 2014-02-19 17:51:05 -0800 | [diff] [blame] | 30 | const int PROTECT_MARK = 0x1; |
Felipe Leme | 5ebbbd8 | 2016-03-07 09:25:50 -0800 | [diff] [blame] | 31 | const int MAX_SYSTEM_UID = AID_APP - 1; |
Chad Brubaker | 2a39012 | 2014-02-19 17:51:05 -0800 | [diff] [blame] | 32 | |
Robert Greenwalt | c462177 | 2012-01-31 12:46:45 -0800 | [diff] [blame] | 33 | extern const char * const IPTABLES_PATH; |
JP Abgrall | 0031cea | 2012-04-17 16:38:23 -0700 | [diff] [blame] | 34 | extern const char * const IP6TABLES_PATH; |
Robert Greenwalt | c462177 | 2012-01-31 12:46:45 -0800 | [diff] [blame] | 35 | extern const char * const IP_PATH; |
| 36 | extern const char * const TC_PATH; |
| 37 | extern const char * const OEM_SCRIPT_PATH; |
| 38 | extern const char * const ADD; |
| 39 | extern const char * const DEL; |
| 40 | |
Jeff Sharkey | 8e188ed | 2012-07-12 18:32:03 -0700 | [diff] [blame] | 41 | enum IptablesTarget { V4, V6, V4V6 }; |
| 42 | |
| 43 | int execIptables(IptablesTarget target, ...); |
| 44 | int execIptablesSilently(IptablesTarget target, ...); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 45 | int execIptablesRestore(IptablesTarget target, const std::string& commands); |
JP Abgrall | 69261cb | 2014-06-19 18:35:24 -0700 | [diff] [blame] | 46 | bool isIfaceName(const char *name); |
Lorenzo Colitti | ba25df9 | 2014-06-18 00:22:17 +0900 | [diff] [blame] | 47 | int parsePrefix(const char *prefix, uint8_t *family, void *address, int size, uint8_t *prefixlen); |
Jeff Sharkey | 8e188ed | 2012-07-12 18:32:03 -0700 | [diff] [blame] | 48 | |
Rom Lemarchand | 001f0a4 | 2013-01-31 12:41:03 -0800 | [diff] [blame] | 49 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a))) |
| 50 | |
Lorenzo Colitti | a10ac32 | 2014-04-11 18:26:17 +0900 | [diff] [blame] | 51 | #define __INT_STRLEN(i) sizeof(#i) |
| 52 | #define _INT_STRLEN(i) __INT_STRLEN(i) |
Lorenzo Colitti | 0a3eb85 | 2016-02-23 16:59:21 +0900 | [diff] [blame] | 53 | #define INT32_STRLEN _INT_STRLEN(INT32_MIN) |
Lorenzo Colitti | a10ac32 | 2014-04-11 18:26:17 +0900 | [diff] [blame] | 54 | #define UINT32_STRLEN _INT_STRLEN(UINT32_MAX) |
| 55 | #define UINT32_HEX_STRLEN sizeof("0x12345678") |
| 56 | |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 57 | #define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) |
| 58 | |
Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 59 | const uid_t INVALID_UID = static_cast<uid_t>(-1); |
| 60 | |
Lorenzo Colitti | 699aa99 | 2016-04-15 10:22:37 +0900 | [diff] [blame^] | 61 | class Stopwatch { |
| 62 | public: |
| 63 | Stopwatch() : mStart(std::chrono::steady_clock::now()) {} |
| 64 | virtual ~Stopwatch() {}; |
| 65 | |
| 66 | float timeTaken() const { |
| 67 | using ms = std::chrono::duration<float, std::ratio<1, 1000>>; |
| 68 | return (std::chrono::duration_cast<ms>( |
| 69 | std::chrono::steady_clock::now() - mStart)).count(); |
| 70 | } |
| 71 | |
| 72 | private: |
| 73 | std::chrono::time_point<std::chrono::steady_clock> mStart; |
| 74 | }; |
| 75 | |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 76 | namespace android { |
| 77 | namespace net { |
| 78 | |
| 79 | /** |
| 80 | * This lock exists to make NetdNativeService RPCs (which come in on multiple Binder threads) |
| 81 | * coexist with the commands in CommandListener.cpp. These are presumed not thread-safe because |
| 82 | * CommandListener has only one user (NetworkManagementService), which is connected through a |
| 83 | * FrameworkListener that passes in commands one at a time. |
| 84 | */ |
| 85 | extern android::RWLock gBigNetdLock; |
| 86 | |
| 87 | } // namespace net |
| 88 | } // namespace android |
| 89 | |
| 90 | #endif // _NETD_CONSTANTS_H |