1 // Copyright (c) 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef QUICHE_QUIC_QBONE_BONNET_TUN_DEVICE_INTERFACE_H_ 6 #define QUICHE_QUIC_QBONE_BONNET_TUN_DEVICE_INTERFACE_H_ 7 8 #include <vector> 9 10 namespace quic { 11 12 // An interface with methods for interacting with a TUN device. 13 class TunDeviceInterface { 14 public: 15 virtual ~TunDeviceInterface() = default; 16 17 // Actually creates/reopens and configures the device. 18 virtual bool Init() = 0; 19 20 // Marks the interface up to start receiving packets. 21 virtual bool Up() = 0; 22 23 // Marks the interface down to stop receiving packets. 24 virtual bool Down() = 0; 25 26 // Closes the open file descriptor for the TUN device (if one exists). 27 // It is safe to reinitialize and reuse this TunTapDevice after calling 28 // CloseDevice. 29 virtual void CloseDevice() = 0; 30 31 // Gets the file descriptor that can be used to send/receive packets. 32 // This returns -1 when the TUN device is in an invalid state. 33 virtual int GetFileDescriptor() const = 0; 34 }; 35 36 } // namespace quic 37 38 #endif // QUICHE_QUIC_QBONE_BONNET_TUN_DEVICE_INTERFACE_H_ 39