blob: 96b955a0a7932569708c6978c7736f77d5bb39ad [file] [log] [blame]
Dmitry Shmidt2eab1f72012-07-26 16:08:02 -07001/*
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 Levitskiy329c3b42012-07-30 16:11:23 -07008 * http://www.apache.org/licenses/LICENSE-2.0
Dmitry Shmidt2eab1f72012-07-26 16:08:02 -07009 *
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 Scherpelzde937962017-06-01 13:20:21 +090020#include <functional>
Bernie Innocenti97f388f2018-10-16 19:17:08 +090021#include <map>
Erik Klineb218a872016-07-04 09:57:18 +090022#include <string>
23
Joel Scherpelzde937962017-06-01 13:20:21 +090024#include <netdutils/Status.h>
Chenbo Feng7e974052018-02-28 22:57:21 -080025#include <netdutils/StatusOr.h>
Joel Scherpelzde937962017-06-01 13:20:21 +090026
Joel Scherpelzde937962017-06-01 13:20:21 +090027namespace android {
28namespace net {
Bernie Innocenti4debf3b2018-09-12 13:54:50 +090029
Joel Scherpelzde937962017-06-01 13:20:21 +090030class StablePrivacyTest;
Joel Scherpelzde937962017-06-01 13:20:21 +090031
Dmitry Shmidt2eab1f72012-07-26 16:08:02 -070032class InterfaceController {
Erik Kline2c5aaa12016-06-08 13:24:45 +090033public:
34 static void initializeAll();
Dmitry Shmidt2eab1f72012-07-26 16:08:02 -070035
Erik Kline2c5aaa12016-06-08 13:24:45 +090036 static int setEnableIPv6(const char *interface, const int on);
Joel Scherpelzde937962017-06-01 13:20:21 +090037 static android::netdutils::Status setIPv6AddrGenMode(const std::string& interface, int mode);
Erik Kline2c5aaa12016-06-08 13:24:45 +090038 static int setAcceptIPv6Ra(const char *interface, const int on);
39 static int setAcceptIPv6Dad(const char *interface, const int on);
Erik Kline59d8c482016-08-09 15:28:42 +090040 static int setIPv6DadTransmits(const char *interface, const char *value);
Erik Kline2c5aaa12016-06-08 13:24:45 +090041 static int setIPv6PrivacyExtensions(const char *interface, const int on);
Erik Kline2c5aaa12016-06-08 13:24:45 +090042 static int setMtu(const char *interface, const char *mtu);
Erik Klinec296f092016-08-02 15:22:53 +090043 static int addAddress(const char *interface, const char *addrString, int prefixLength);
44 static int delAddress(const char *interface, const char *addrString, int prefixLength);
Hugo Benichic4b3a0c2018-05-22 08:48:40 +090045 static int disableIcmpRedirects();
Erik Kline2c5aaa12016-06-08 13:24:45 +090046
Erik Klineb218a872016-07-04 09:57:18 +090047 // Read and write values in files of the form:
48 // /proc/sys/net/<family>/<which>/<interface>/<parameter>
Erik Kline38e51f12018-09-06 20:14:44 +090049 //
50 // NOTE: getParameter() trims whitespace so the caller does not need extra
51 // code to crop trailing newlines, for example.
Erik Klineb218a872016-07-04 09:57:18 +090052 static int getParameter(
53 const char *family, const char *which, const char *interface, const char *parameter,
54 std::string *value);
55 static int setParameter(
56 const char *family, const char *which, const char *interface, const char *parameter,
57 const char *value);
58
Nathan Harold172f8e42018-04-19 13:10:19 -070059 static android::netdutils::StatusOr<std::vector<std::string>> getIfaceNames();
Chenbo Feng7e974052018-02-28 22:57:21 -080060 static android::netdutils::StatusOr<std::map<std::string, uint32_t>> getIfaceList();
61
Erik Kline2c5aaa12016-06-08 13:24:45 +090062private:
Joel Scherpelzde937962017-06-01 13:20:21 +090063 friend class android::net::StablePrivacyTest;
Erik Kline2c5aaa12016-06-08 13:24:45 +090064
Joel Scherpelzde937962017-06-01 13:20:21 +090065 using GetPropertyFn =
66 std::function<std::string(const std::string& key, const std::string& dflt)>;
67 using SetPropertyFn =
68 std::function<android::netdutils::Status(const std::string& key, const std::string& val)>;
69
70 // Helper function exported from this compilation unit for testing.
Bernie Innocenti15bb55c2018-06-03 16:19:51 +090071 static android::netdutils::Status enableStablePrivacyAddresses(
72 const std::string& iface,
73 const GetPropertyFn& getProperty,
74 const SetPropertyFn& setProperty);
Joel Scherpelzde937962017-06-01 13:20:21 +090075
76 static void setAcceptRA(const char* value);
77 static void setAcceptRARouteTable(int tableOrOffset);
78 static void setBaseReachableTimeMs(unsigned int millis);
79 static void setIPv6OptimisticMode(const char* value);
80
81 InterfaceController() = delete;
82 ~InterfaceController() = delete;
Dmitry Shmidt2eab1f72012-07-26 16:08:02 -070083};
84
Bernie Innocenti4debf3b2018-09-12 13:54:50 +090085} // namespace net
86} // namespace android
87
Dmitry Shmidt2eab1f72012-07-26 16:08:02 -070088#endif