12eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt/* 22eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt * Copyright (C) 2012 The Android Open Source Project 32eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt * 42eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt * Licensed under the Apache License, Version 2.0 (the "License"); 52eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt * you may not use this file except in compliance with the License. 62eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt * You may obtain a copy of the License at 72eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt * 8329c3b4681e2ca4831adc7c8cf257e9e32971710Sasha Levitskiy * http://www.apache.org/licenses/LICENSE-2.0 92eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt * 102eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt * Unless required by applicable law or agreed to in writing, software 112eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt * distributed under the License is distributed on an "AS IS" BASIS, 122eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt * See the License for the specific language governing permissions and 142eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt * limitations under the License. 152eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt */ 162eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt 172eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt#ifndef _INTERFACE_CONTROLLER_H 182eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt#define _INTERFACE_CONTROLLER_H 192eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt 20de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz#include <functional> 21b218a87e0777d3d2c93231e03ef7315d783e3279Erik Kline#include <string> 22b218a87e0777d3d2c93231e03ef7315d783e3279Erik Kline 23de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz#include <netdutils/Status.h> 24de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz 25de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz// TODO: move InterfaceController into android::net namespace. 26de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelznamespace android { 27de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelznamespace net { 28de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelzclass StablePrivacyTest; 29de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz} // namespace net 30de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz} // namespace android 31de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz 322eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidtclass InterfaceController { 332c5aaa1876db659556c2e9605beccc670e6b7c0dErik Klinepublic: 342c5aaa1876db659556c2e9605beccc670e6b7c0dErik Kline static void initializeAll(); 35329c3b4681e2ca4831adc7c8cf257e9e32971710Sasha Levitskiy 362c5aaa1876db659556c2e9605beccc670e6b7c0dErik Kline static int setEnableIPv6(const char *interface, const int on); 37de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz static android::netdutils::Status setIPv6AddrGenMode(const std::string& interface, int mode); 382c5aaa1876db659556c2e9605beccc670e6b7c0dErik Kline static int setAcceptIPv6Ra(const char *interface, const int on); 392c5aaa1876db659556c2e9605beccc670e6b7c0dErik Kline static int setAcceptIPv6Dad(const char *interface, const int on); 4059d8c48cee74679d2305c535ab61d4a6f8258c64Erik Kline static int setIPv6DadTransmits(const char *interface, const char *value); 412c5aaa1876db659556c2e9605beccc670e6b7c0dErik Kline static int setIPv6PrivacyExtensions(const char *interface, const int on); 422c5aaa1876db659556c2e9605beccc670e6b7c0dErik Kline static int setIPv6NdOffload(char* interface, const int on); 432c5aaa1876db659556c2e9605beccc670e6b7c0dErik Kline static int setMtu(const char *interface, const char *mtu); 44c296f098b63a986265ded8adf13118ba512a0fa7Erik Kline static int addAddress(const char *interface, const char *addrString, int prefixLength); 45c296f098b63a986265ded8adf13118ba512a0fa7Erik Kline static int delAddress(const char *interface, const char *addrString, int prefixLength); 462c5aaa1876db659556c2e9605beccc670e6b7c0dErik Kline 47b218a87e0777d3d2c93231e03ef7315d783e3279Erik Kline // Read and write values in files of the form: 48b218a87e0777d3d2c93231e03ef7315d783e3279Erik Kline // /proc/sys/net/<family>/<which>/<interface>/<parameter> 49b218a87e0777d3d2c93231e03ef7315d783e3279Erik Kline static int getParameter( 50b218a87e0777d3d2c93231e03ef7315d783e3279Erik Kline const char *family, const char *which, const char *interface, const char *parameter, 51b218a87e0777d3d2c93231e03ef7315d783e3279Erik Kline std::string *value); 52b218a87e0777d3d2c93231e03ef7315d783e3279Erik Kline static int setParameter( 53b218a87e0777d3d2c93231e03ef7315d783e3279Erik Kline const char *family, const char *which, const char *interface, const char *parameter, 54b218a87e0777d3d2c93231e03ef7315d783e3279Erik Kline const char *value); 55b218a87e0777d3d2c93231e03ef7315d783e3279Erik Kline 562c5aaa1876db659556c2e9605beccc670e6b7c0dErik Klineprivate: 57de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz friend class android::net::StablePrivacyTest; 58de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz 59de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz using GetPropertyFn = 60de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz std::function<std::string(const std::string& key, const std::string& dflt)>; 61de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz using SetPropertyFn = 62de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz std::function<android::netdutils::Status(const std::string& key, const std::string& val)>; 63de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz 64de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz // Helper function exported from this compilation unit for testing. 65de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz static android::netdutils::Status enableStablePrivacyAddresses(const std::string& iface, 66de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz GetPropertyFn getProperty, 67de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz SetPropertyFn setProperty); 68de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz 69de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz static void setAcceptRA(const char* value); 70de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz static void setAcceptRARouteTable(int tableOrOffset); 71de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz static void setBaseReachableTimeMs(unsigned int millis); 72de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz static void setIPv6OptimisticMode(const char* value); 732c5aaa1876db659556c2e9605beccc670e6b7c0dErik Kline 74de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz InterfaceController() = delete; 75de9379641d5fc4b5912d6838075df9490518cca6Joel Scherpelz ~InterfaceController() = delete; 762eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt}; 772eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt 782eab1f762badb7ba46b95716e62ea4548a979903Dmitry Shmidt#endif 79