11e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti/*
21e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti * Copyright 2017 The Android Open Source Project
31e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti *
41e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti * Licensed under the Apache License, Version 2.0 (the "License");
51e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti * you may not use this file except in compliance with the License.
61e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti * You may obtain a copy of the License at
71e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti *
81e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti * http://www.apache.org/licenses/LICENSE-2.0
91e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti *
101e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti * Unless required by applicable law or agreed to in writing, software
111e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti * distributed under the License is distributed on an "AS IS" BASIS,
121e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti * See the License for the specific language governing permissions and
141e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti * limitations under the License.
151e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti *
161e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti * tun_interface.h - creates tun interfaces for testing purposes
171e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti */
181e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti
191e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti#ifndef _SYSTEM_NETD_TESTS_TUN_INTERACE_H
201e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti#define _SYSTEM_NETD_TESTS_TUN_INTERACE_H
211e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti
221e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colittinamespace android {
231e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colittinamespace net {
241e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti
251e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitticlass TunInterface {
261e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colittipublic:
271e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti    TunInterface() = default;
281e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti    ~TunInterface() { destroy(); }
291e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti
301e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti    // Creates a tun interface. Returns 0 on success or -errno on failure. Must succeed before it is
311e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti    // legal to call any of the other methods in this class.
321e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti    int init();
331e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti    void destroy();
341e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti
351e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti    const std::string& name() const { return mIfName; }
361e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti    const in6_addr& srcAddr() const { return mSrcAddr; }
371e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti    const in6_addr& dstAddr() const { return mDstAddr; }
381e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti
391e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colittiprivate:
401e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti    int mFd = -1;
411e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti    std::string mIfName;
421e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti    in6_addr mSrcAddr, mDstAddr;
431e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti};
441e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti
451e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti}  // namespace net
461e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti}  // namespace android
471e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti
481e299c63fd42f02f23547690275d4f6f9cd5fcc4Lorenzo Colitti#endif
49