Dmitry Shmidt | 2eab1f7 | 2012-07-26 16:08:02 -0700 | [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 | * |
Sasha Levitskiy | 329c3b4 | 2012-07-30 16:11:23 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Dmitry Shmidt | 2eab1f7 | 2012-07-26 16:08:02 -0700 | [diff] [blame] | 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 _INTERFACE_CONTROLLER_H |
| 18 | #define _INTERFACE_CONTROLLER_H |
| 19 | |
Joel Scherpelz | de93796 | 2017-06-01 13:20:21 +0900 | [diff] [blame] | 20 | #include <functional> |
Bernie Innocenti | 97f388f | 2018-10-16 19:17:08 +0900 | [diff] [blame] | 21 | #include <map> |
Erik Kline | b218a87 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 22 | #include <string> |
| 23 | |
Luke Huang | f778204 | 2018-08-08 13:13:04 +0800 | [diff] [blame^] | 24 | #include <android/net/InterfaceConfigurationParcel.h> |
Joel Scherpelz | de93796 | 2017-06-01 13:20:21 +0900 | [diff] [blame] | 25 | #include <netdutils/Status.h> |
Chenbo Feng | 7e97405 | 2018-02-28 22:57:21 -0800 | [diff] [blame] | 26 | #include <netdutils/StatusOr.h> |
Joel Scherpelz | de93796 | 2017-06-01 13:20:21 +0900 | [diff] [blame] | 27 | |
Joel Scherpelz | de93796 | 2017-06-01 13:20:21 +0900 | [diff] [blame] | 28 | namespace android { |
| 29 | namespace net { |
Bernie Innocenti | 4debf3b | 2018-09-12 13:54:50 +0900 | [diff] [blame] | 30 | |
Joel Scherpelz | de93796 | 2017-06-01 13:20:21 +0900 | [diff] [blame] | 31 | class StablePrivacyTest; |
Joel Scherpelz | de93796 | 2017-06-01 13:20:21 +0900 | [diff] [blame] | 32 | |
Dmitry Shmidt | 2eab1f7 | 2012-07-26 16:08:02 -0700 | [diff] [blame] | 33 | class InterfaceController { |
Erik Kline | 2c5aaa1 | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 34 | public: |
| 35 | static void initializeAll(); |
Dmitry Shmidt | 2eab1f7 | 2012-07-26 16:08:02 -0700 | [diff] [blame] | 36 | |
Luke Huang | f778204 | 2018-08-08 13:13:04 +0800 | [diff] [blame^] | 37 | static int setEnableIPv6(const char* ifName, const int on); |
| 38 | static android::netdutils::Status setIPv6AddrGenMode(const std::string& ifName, int mode); |
| 39 | static int setAcceptIPv6Ra(const char* ifName, const int on); |
| 40 | static int setAcceptIPv6Dad(const char* ifName, const int on); |
| 41 | static int setIPv6DadTransmits(const char* ifName, const char* value); |
| 42 | static int setIPv6PrivacyExtensions(const char* ifName, const int on); |
| 43 | static int setMtu(const char* ifName, const char* mtu); |
| 44 | static int addAddress(const char* ifName, const char* addrString, int prefixLength); |
| 45 | static int delAddress(const char* ifName, const char* addrString, int prefixLength); |
Hugo Benichi | c4b3a0c | 2018-05-22 08:48:40 +0900 | [diff] [blame] | 46 | static int disableIcmpRedirects(); |
Luke Huang | f778204 | 2018-08-08 13:13:04 +0800 | [diff] [blame^] | 47 | static android::netdutils::Status setCfg(const InterfaceConfigurationParcel& cfg); |
| 48 | static android::netdutils::StatusOr<InterfaceConfigurationParcel> getCfg( |
| 49 | const std::string& ifName); |
| 50 | static int clearAddrs(const std::string& ifName); |
Erik Kline | 2c5aaa1 | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 51 | |
Erik Kline | b218a87 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 52 | // Read and write values in files of the form: |
Luke Huang | f778204 | 2018-08-08 13:13:04 +0800 | [diff] [blame^] | 53 | // /proc/sys/net/<family>/<which>/<ifName>/<parameter> |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 54 | // |
| 55 | // NOTE: getParameter() trims whitespace so the caller does not need extra |
| 56 | // code to crop trailing newlines, for example. |
Luke Huang | f778204 | 2018-08-08 13:13:04 +0800 | [diff] [blame^] | 57 | static int getParameter(const char* family, const char* which, const char* ifName, |
| 58 | const char* parameter, std::string* value); |
| 59 | static int setParameter(const char* family, const char* which, const char* ifName, |
| 60 | const char* parameter, const char* value); |
Erik Kline | b218a87 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 61 | |
Nathan Harold | 172f8e4 | 2018-04-19 13:10:19 -0700 | [diff] [blame] | 62 | static android::netdutils::StatusOr<std::vector<std::string>> getIfaceNames(); |
Chenbo Feng | 7e97405 | 2018-02-28 22:57:21 -0800 | [diff] [blame] | 63 | static android::netdutils::StatusOr<std::map<std::string, uint32_t>> getIfaceList(); |
| 64 | |
Luke Huang | f778204 | 2018-08-08 13:13:04 +0800 | [diff] [blame^] | 65 | static std::mutex mutex; |
Erik Kline | 2c5aaa1 | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 66 | |
Luke Huang | f778204 | 2018-08-08 13:13:04 +0800 | [diff] [blame^] | 67 | private: |
| 68 | friend class android::net::StablePrivacyTest; |
Joel Scherpelz | de93796 | 2017-06-01 13:20:21 +0900 | [diff] [blame] | 69 | |
Luke Huang | f778204 | 2018-08-08 13:13:04 +0800 | [diff] [blame^] | 70 | using GetPropertyFn = |
| 71 | std::function<std::string(const std::string& key, const std::string& dflt)>; |
| 72 | using SetPropertyFn = std::function<android::netdutils::Status(const std::string& key, |
| 73 | const std::string& val)>; |
Joel Scherpelz | de93796 | 2017-06-01 13:20:21 +0900 | [diff] [blame] | 74 | |
Luke Huang | f778204 | 2018-08-08 13:13:04 +0800 | [diff] [blame^] | 75 | // Helper function exported from this compilation unit for testing. |
| 76 | static android::netdutils::Status enableStablePrivacyAddresses( |
| 77 | const std::string& ifName, const GetPropertyFn& getProperty, |
| 78 | const SetPropertyFn& setProperty); |
Joel Scherpelz | de93796 | 2017-06-01 13:20:21 +0900 | [diff] [blame] | 79 | |
Luke Huang | f778204 | 2018-08-08 13:13:04 +0800 | [diff] [blame^] | 80 | static void setAcceptRA(const char* value); |
| 81 | static void setAcceptRARouteTable(int tableOrOffset); |
| 82 | static void setBaseReachableTimeMs(unsigned int millis); |
| 83 | static void setIPv6OptimisticMode(const char* value); |
| 84 | |
| 85 | InterfaceController() = delete; |
| 86 | ~InterfaceController() = delete; |
Dmitry Shmidt | 2eab1f7 | 2012-07-26 16:08:02 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Bernie Innocenti | 4debf3b | 2018-09-12 13:54:50 +0900 | [diff] [blame] | 89 | } // namespace net |
| 90 | } // namespace android |
| 91 | |
Dmitry Shmidt | 2eab1f7 | 2012-07-26 16:08:02 -0700 | [diff] [blame] | 92 | #endif |