blob: 5adbf18852d22543f1cca7e0517be2dff4ee674d [file] [log] [blame]
Lorenzo Colitti1e299c62017-02-27 17:16:10 +09001/*
2 * Copyright 2017 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 *
8 * http://www.apache.org/licenses/LICENSE-2.0
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 * tun_interface.h - creates tun interfaces for testing purposes
17 */
18
19#ifndef _SYSTEM_NETD_TESTS_TUN_INTERACE_H
20#define _SYSTEM_NETD_TESTS_TUN_INTERACE_H
21
22namespace android {
23namespace net {
24
25class TunInterface {
26public:
27 TunInterface() = default;
28 ~TunInterface() { destroy(); }
29
30 // Creates a tun interface. Returns 0 on success or -errno on failure. Must succeed before it is
31 // legal to call any of the other methods in this class.
Luke Huang528af602018-08-29 19:06:05 +080032 int init(const std::string& ifName = "");
Lorenzo Colitti1e299c62017-02-27 17:16:10 +090033 void destroy();
34
35 const std::string& name() const { return mIfName; }
Lorenzo Colitti54520a02018-02-09 18:39:16 +090036 int ifindex() const { return mIfIndex; }
Lorenzo Colitti1e299c62017-02-27 17:16:10 +090037 const in6_addr& srcAddr() const { return mSrcAddr; }
38 const in6_addr& dstAddr() const { return mDstAddr; }
39
Lorenzo Colitti8a9f1ad2019-02-26 00:30:18 +090040 int addAddress(const std::string& addr, int prefixlen);
41
42 private:
Lorenzo Colitti1e299c62017-02-27 17:16:10 +090043 int mFd = -1;
44 std::string mIfName;
Lorenzo Colitti54520a02018-02-09 18:39:16 +090045 int mIfIndex;
Lorenzo Colitti1e299c62017-02-27 17:16:10 +090046 in6_addr mSrcAddr, mDstAddr;
47};
48
49} // namespace net
50} // namespace android
51
52#endif