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 | |
Luke Huang | d1ee462 | 2018-06-29 13:49:58 +0800 | [diff] [blame^] | 20 | #include <mutex> |
Jeff Sharkey | 8e188ed | 2012-07-12 18:32:03 -0700 | [diff] [blame] | 21 | #include <string> |
| 22 | #include <list> |
Erik Kline | cc4f273 | 2016-08-03 11:24:27 +0900 | [diff] [blame] | 23 | #include <ifaddrs.h> |
| 24 | #include <netdb.h> |
Jeff Sharkey | 8e188ed | 2012-07-12 18:32:03 -0700 | [diff] [blame] | 25 | #include <stdarg.h> |
Lorenzo Colitti | 699aa99 | 2016-04-15 10:22:37 +0900 | [diff] [blame] | 26 | |
| 27 | #include <chrono> |
| 28 | |
Felipe Leme | 5ebbbd8 | 2016-03-07 09:25:50 -0800 | [diff] [blame] | 29 | #include <private/android_filesystem_config.h> |
Robert Greenwalt | c462177 | 2012-01-31 12:46:45 -0800 | [diff] [blame] | 30 | |
Chad Brubaker | 2a39012 | 2014-02-19 17:51:05 -0800 | [diff] [blame] | 31 | const int PROTECT_MARK = 0x1; |
Felipe Leme | 5ebbbd8 | 2016-03-07 09:25:50 -0800 | [diff] [blame] | 32 | const int MAX_SYSTEM_UID = AID_APP - 1; |
Chad Brubaker | 2a39012 | 2014-02-19 17:51:05 -0800 | [diff] [blame] | 33 | |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 34 | extern const size_t SHA256_SIZE; |
| 35 | |
Robert Greenwalt | c462177 | 2012-01-31 12:46:45 -0800 | [diff] [blame] | 36 | extern const char * const ADD; |
| 37 | extern const char * const DEL; |
| 38 | |
Jeff Sharkey | 8e188ed | 2012-07-12 18:32:03 -0700 | [diff] [blame] | 39 | enum IptablesTarget { V4, V6, V4V6 }; |
| 40 | |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 41 | int execIptablesRestore(IptablesTarget target, const std::string& commands); |
Lorenzo Colitti | cd28377 | 2017-01-31 19:00:49 +0900 | [diff] [blame] | 42 | int execIptablesRestoreWithOutput(IptablesTarget target, const std::string& commands, |
| 43 | std::string *output); |
Lorenzo Colitti | c1306ea | 2017-03-27 05:52:31 +0900 | [diff] [blame] | 44 | int execIptablesRestoreCommand(IptablesTarget target, const std::string& table, |
| 45 | const std::string& command, std::string *output); |
Joel Scherpelz | bcad661 | 2017-05-30 10:55:11 +0900 | [diff] [blame] | 46 | bool isIfaceName(const std::string& 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); |
Lorenzo Colitti | 839d7d6 | 2017-04-03 15:37:19 +0900 | [diff] [blame] | 48 | void blockSigpipe(); |
Lorenzo Colitti | 548bbd4 | 2017-08-28 23:05:12 +0900 | [diff] [blame] | 49 | void setCloseOnExec(const char *sock); |
Jeff Sharkey | 8e188ed | 2012-07-12 18:32:03 -0700 | [diff] [blame] | 50 | |
Rom Lemarchand | 001f0a4 | 2013-01-31 12:41:03 -0800 | [diff] [blame] | 51 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a))) |
| 52 | |
Lorenzo Colitti | a10ac32 | 2014-04-11 18:26:17 +0900 | [diff] [blame] | 53 | #define __INT_STRLEN(i) sizeof(#i) |
| 54 | #define _INT_STRLEN(i) __INT_STRLEN(i) |
Lorenzo Colitti | 0a3eb85 | 2016-02-23 16:59:21 +0900 | [diff] [blame] | 55 | #define INT32_STRLEN _INT_STRLEN(INT32_MIN) |
Lorenzo Colitti | a10ac32 | 2014-04-11 18:26:17 +0900 | [diff] [blame] | 56 | #define UINT32_STRLEN _INT_STRLEN(UINT32_MAX) |
| 57 | #define UINT32_HEX_STRLEN sizeof("0x12345678") |
Benedict Wong | b9baf26 | 2017-12-03 15:43:08 -0800 | [diff] [blame] | 58 | #define IPSEC_IFACE_PREFIX "ipsec" |
Lorenzo Colitti | a10ac32 | 2014-04-11 18:26:17 +0900 | [diff] [blame] | 59 | |
Sreeram Ramachandran | f4f6c8d | 2014-06-23 09:54:06 -0700 | [diff] [blame] | 60 | #define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) |
| 61 | |
Sreeram Ramachandran | b1425cc | 2014-06-23 18:54:27 -0700 | [diff] [blame] | 62 | const uid_t INVALID_UID = static_cast<uid_t>(-1); |
| 63 | |
Erik Kline | cc4f273 | 2016-08-03 11:24:27 +0900 | [diff] [blame] | 64 | |
| 65 | struct AddrinfoDeleter { |
| 66 | void operator()(struct addrinfo* p) const { |
| 67 | if (p != nullptr) { |
| 68 | freeaddrinfo(p); |
| 69 | } |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | typedef std::unique_ptr<struct addrinfo, struct AddrinfoDeleter> ScopedAddrinfo; |
| 74 | |
| 75 | |
| 76 | struct IfaddrsDeleter { |
| 77 | void operator()(struct ifaddrs *p) const { |
| 78 | if (p != nullptr) { |
| 79 | freeifaddrs(p); |
| 80 | } |
| 81 | } |
| 82 | }; |
| 83 | |
| 84 | typedef std::unique_ptr<struct ifaddrs, struct IfaddrsDeleter> ScopedIfaddrs; |
| 85 | |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 86 | namespace android { |
| 87 | namespace net { |
| 88 | |
| 89 | /** |
| 90 | * This lock exists to make NetdNativeService RPCs (which come in on multiple Binder threads) |
| 91 | * coexist with the commands in CommandListener.cpp. These are presumed not thread-safe because |
| 92 | * CommandListener has only one user (NetworkManagementService), which is connected through a |
| 93 | * FrameworkListener that passes in commands one at a time. |
| 94 | */ |
Luke Huang | d1ee462 | 2018-06-29 13:49:58 +0800 | [diff] [blame^] | 95 | extern std::mutex gBigNetdLock; |
Lorenzo Colitti | e4d626e | 2016-02-02 17:19:04 +0900 | [diff] [blame] | 96 | |
| 97 | } // namespace net |
| 98 | } // namespace android |
| 99 | |
| 100 | #endif // _NETD_CONSTANTS_H |