blob: 4c5b27f02ec5a7d915017df1da3f7a123b93b75f [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>
Erik Klineb218a872016-07-04 09:57:18 +090021#include <string>
22
Joel Scherpelzde937962017-06-01 13:20:21 +090023#include <netdutils/Status.h>
Chenbo Feng7e974052018-02-28 22:57:21 -080024#include <netdutils/StatusOr.h>
Joel Scherpelzde937962017-06-01 13:20:21 +090025
Joel Scherpelzde937962017-06-01 13:20:21 +090026namespace android {
27namespace net {
Bernie Innocenti4debf3b2018-09-12 13:54:50 +090028
Joel Scherpelzde937962017-06-01 13:20:21 +090029class StablePrivacyTest;
Joel Scherpelzde937962017-06-01 13:20:21 +090030
Dmitry Shmidt2eab1f72012-07-26 16:08:02 -070031class InterfaceController {
Erik Kline2c5aaa12016-06-08 13:24:45 +090032public:
33 static void initializeAll();
Dmitry Shmidt2eab1f72012-07-26 16:08:02 -070034
Erik Kline2c5aaa12016-06-08 13:24:45 +090035 static int setEnableIPv6(const char *interface, const int on);
Joel Scherpelzde937962017-06-01 13:20:21 +090036 static android::netdutils::Status setIPv6AddrGenMode(const std::string& interface, int mode);
Erik Kline2c5aaa12016-06-08 13:24:45 +090037 static int setAcceptIPv6Ra(const char *interface, const int on);
38 static int setAcceptIPv6Dad(const char *interface, const int on);
Erik Kline59d8c482016-08-09 15:28:42 +090039 static int setIPv6DadTransmits(const char *interface, const char *value);
Erik Kline2c5aaa12016-06-08 13:24:45 +090040 static int setIPv6PrivacyExtensions(const char *interface, const int on);
Erik Kline2c5aaa12016-06-08 13:24:45 +090041 static int setMtu(const char *interface, const char *mtu);
Erik Klinec296f092016-08-02 15:22:53 +090042 static int addAddress(const char *interface, const char *addrString, int prefixLength);
43 static int delAddress(const char *interface, const char *addrString, int prefixLength);
Hugo Benichic4b3a0c2018-05-22 08:48:40 +090044 static int disableIcmpRedirects();
Erik Kline2c5aaa12016-06-08 13:24:45 +090045
Erik Klineb218a872016-07-04 09:57:18 +090046 // Read and write values in files of the form:
47 // /proc/sys/net/<family>/<which>/<interface>/<parameter>
Erik Kline38e51f12018-09-06 20:14:44 +090048 //
49 // NOTE: getParameter() trims whitespace so the caller does not need extra
50 // code to crop trailing newlines, for example.
Erik Klineb218a872016-07-04 09:57:18 +090051 static int getParameter(
52 const char *family, const char *which, const char *interface, const char *parameter,
53 std::string *value);
54 static int setParameter(
55 const char *family, const char *which, const char *interface, const char *parameter,
56 const char *value);
57
Nathan Harold172f8e42018-04-19 13:10:19 -070058 static android::netdutils::StatusOr<std::vector<std::string>> getIfaceNames();
Chenbo Feng7e974052018-02-28 22:57:21 -080059 static android::netdutils::StatusOr<std::map<std::string, uint32_t>> getIfaceList();
60
Erik Kline2c5aaa12016-06-08 13:24:45 +090061private:
Joel Scherpelzde937962017-06-01 13:20:21 +090062 friend class android::net::StablePrivacyTest;
Erik Kline2c5aaa12016-06-08 13:24:45 +090063
Joel Scherpelzde937962017-06-01 13:20:21 +090064 using GetPropertyFn =
65 std::function<std::string(const std::string& key, const std::string& dflt)>;
66 using SetPropertyFn =
67 std::function<android::netdutils::Status(const std::string& key, const std::string& val)>;
68
69 // Helper function exported from this compilation unit for testing.
Bernie Innocenti15bb55c2018-06-03 16:19:51 +090070 static android::netdutils::Status enableStablePrivacyAddresses(
71 const std::string& iface,
72 const GetPropertyFn& getProperty,
73 const SetPropertyFn& setProperty);
Joel Scherpelzde937962017-06-01 13:20:21 +090074
75 static void setAcceptRA(const char* value);
76 static void setAcceptRARouteTable(int tableOrOffset);
77 static void setBaseReachableTimeMs(unsigned int millis);
78 static void setIPv6OptimisticMode(const char* value);
79
80 InterfaceController() = delete;
81 ~InterfaceController() = delete;
Dmitry Shmidt2eab1f72012-07-26 16:08:02 -070082};
83
Bernie Innocenti4debf3b2018-09-12 13:54:50 +090084} // namespace net
85} // namespace android
86
Dmitry Shmidt2eab1f72012-07-26 16:08:02 -070087#endif