xref: /aosp_15_r20/system/netd/server/InterfaceController.h (revision 8542734a0dd1db395a4d42aae09c37f3c3c3e7a1)
1*8542734aSAndroid Build Coastguard Worker /*
2*8542734aSAndroid Build Coastguard Worker  * Copyright (C) 2012 The Android Open Source Project
3*8542734aSAndroid Build Coastguard Worker  *
4*8542734aSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*8542734aSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*8542734aSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*8542734aSAndroid Build Coastguard Worker  *
8*8542734aSAndroid Build Coastguard Worker  *	  http://www.apache.org/licenses/LICENSE-2.0
9*8542734aSAndroid Build Coastguard Worker  *
10*8542734aSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*8542734aSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*8542734aSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*8542734aSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*8542734aSAndroid Build Coastguard Worker  * limitations under the License.
15*8542734aSAndroid Build Coastguard Worker  */
16*8542734aSAndroid Build Coastguard Worker 
17*8542734aSAndroid Build Coastguard Worker #ifndef _INTERFACE_CONTROLLER_H
18*8542734aSAndroid Build Coastguard Worker #define _INTERFACE_CONTROLLER_H
19*8542734aSAndroid Build Coastguard Worker 
20*8542734aSAndroid Build Coastguard Worker #include <functional>
21*8542734aSAndroid Build Coastguard Worker #include <map>
22*8542734aSAndroid Build Coastguard Worker #include <string>
23*8542734aSAndroid Build Coastguard Worker 
24*8542734aSAndroid Build Coastguard Worker #include <android/net/InterfaceConfigurationParcel.h>
25*8542734aSAndroid Build Coastguard Worker #include <netdutils/Status.h>
26*8542734aSAndroid Build Coastguard Worker #include <netdutils/StatusOr.h>
27*8542734aSAndroid Build Coastguard Worker 
28*8542734aSAndroid Build Coastguard Worker namespace android {
29*8542734aSAndroid Build Coastguard Worker namespace net {
30*8542734aSAndroid Build Coastguard Worker 
31*8542734aSAndroid Build Coastguard Worker class StablePrivacyTest;
32*8542734aSAndroid Build Coastguard Worker 
33*8542734aSAndroid Build Coastguard Worker class InterfaceController {
34*8542734aSAndroid Build Coastguard Worker public:
35*8542734aSAndroid Build Coastguard Worker     static void initializeAll();
36*8542734aSAndroid Build Coastguard Worker 
37*8542734aSAndroid Build Coastguard Worker     static int setEnableIPv6(const char* ifName, const int on);
38*8542734aSAndroid Build Coastguard Worker     static android::netdutils::Status setIPv6AddrGenMode(const std::string& ifName, int mode);
39*8542734aSAndroid Build Coastguard Worker     static int setAcceptIPv6Ra(const char* ifName, const int on);
40*8542734aSAndroid Build Coastguard Worker     static int setAcceptIPv6Dad(const char* ifName, const int on);
41*8542734aSAndroid Build Coastguard Worker     static int setIPv6DadTransmits(const char* ifName, const char* value);
42*8542734aSAndroid Build Coastguard Worker     static int setIPv6PrivacyExtensions(const char* ifName, const int on);
43*8542734aSAndroid Build Coastguard Worker     static int setMtu(const char* ifName, const char* mtu);
44*8542734aSAndroid Build Coastguard Worker     static int addAddress(const char* ifName, const char* addrString, int prefixLength);
45*8542734aSAndroid Build Coastguard Worker     static int delAddress(const char* ifName, const char* addrString, int prefixLength);
46*8542734aSAndroid Build Coastguard Worker     static int disableIcmpRedirects();
47*8542734aSAndroid Build Coastguard Worker     static android::netdutils::Status setCfg(const InterfaceConfigurationParcel& cfg);
48*8542734aSAndroid Build Coastguard Worker     static android::netdutils::StatusOr<InterfaceConfigurationParcel> getCfg(
49*8542734aSAndroid Build Coastguard Worker             const std::string& ifName);
50*8542734aSAndroid Build Coastguard Worker     static int clearAddrs(const std::string& ifName);
51*8542734aSAndroid Build Coastguard Worker 
52*8542734aSAndroid Build Coastguard Worker     // Read and write values in files of the form:
53*8542734aSAndroid Build Coastguard Worker     //     /proc/sys/net/<family>/<which>/<ifName>/<parameter>
54*8542734aSAndroid Build Coastguard Worker     //
55*8542734aSAndroid Build Coastguard Worker     // NOTE: getParameter() trims whitespace so the caller does not need extra
56*8542734aSAndroid Build Coastguard Worker     // code to crop trailing newlines, for example.
57*8542734aSAndroid Build Coastguard Worker     static int getParameter(const char* family, const char* which, const char* ifName,
58*8542734aSAndroid Build Coastguard Worker                             const char* parameter, std::string* value);
59*8542734aSAndroid Build Coastguard Worker     static int setParameter(const char* family, const char* which, const char* ifName,
60*8542734aSAndroid Build Coastguard Worker                             const char* parameter, const char* value);
61*8542734aSAndroid Build Coastguard Worker 
62*8542734aSAndroid Build Coastguard Worker     static std::mutex mutex;
63*8542734aSAndroid Build Coastguard Worker 
64*8542734aSAndroid Build Coastguard Worker   private:
65*8542734aSAndroid Build Coastguard Worker     friend class android::net::StablePrivacyTest;
66*8542734aSAndroid Build Coastguard Worker 
67*8542734aSAndroid Build Coastguard Worker     using GetPropertyFn =
68*8542734aSAndroid Build Coastguard Worker             std::function<std::string(const std::string& key, const std::string& dflt)>;
69*8542734aSAndroid Build Coastguard Worker     using SetPropertyFn = std::function<android::netdutils::Status(const std::string& key,
70*8542734aSAndroid Build Coastguard Worker                                                                    const std::string& val)>;
71*8542734aSAndroid Build Coastguard Worker 
72*8542734aSAndroid Build Coastguard Worker     // Helper function exported from this compilation unit for testing.
73*8542734aSAndroid Build Coastguard Worker     static android::netdutils::Status enableStablePrivacyAddresses(
74*8542734aSAndroid Build Coastguard Worker             const std::string& ifName, const GetPropertyFn& getProperty,
75*8542734aSAndroid Build Coastguard Worker             const SetPropertyFn& setProperty);
76*8542734aSAndroid Build Coastguard Worker 
77*8542734aSAndroid Build Coastguard Worker     static void setAcceptRA(const char* value);
78*8542734aSAndroid Build Coastguard Worker     static void setAcceptRARouteTable(int tableOrOffset);
79*8542734aSAndroid Build Coastguard Worker     static void setBaseReachableTimeMs(unsigned int millis);
80*8542734aSAndroid Build Coastguard Worker     static void setIPv6OptimisticMode(const char* value);
81*8542734aSAndroid Build Coastguard Worker 
82*8542734aSAndroid Build Coastguard Worker     InterfaceController() = delete;
83*8542734aSAndroid Build Coastguard Worker     ~InterfaceController() = delete;
84*8542734aSAndroid Build Coastguard Worker };
85*8542734aSAndroid Build Coastguard Worker 
86*8542734aSAndroid Build Coastguard Worker }  // namespace net
87*8542734aSAndroid Build Coastguard Worker }  // namespace android
88*8542734aSAndroid Build Coastguard Worker 
89*8542734aSAndroid Build Coastguard Worker #endif
90