Annotation of embedaddon/strongswan/src/libstrongswan/networking/tun_device.h, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2012 Tobias Brunner
! 3: * Copyright (C) 2012 Giuliano Grassi
! 4: * Copyright (C) 2012 Ralf Sager
! 5: * HSR Hochschule fuer Technik Rapperswil
! 6: *
! 7: * This program is free software; you can redistribute it and/or modify it
! 8: * under the terms of the GNU General Public License as published by the
! 9: * Free Software Foundation; either version 2 of the License, or (at your
! 10: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
! 11: *
! 12: * This program is distributed in the hope that it will be useful, but
! 13: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 14: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
! 15: * for more details.
! 16: */
! 17:
! 18: /**
! 19: * @defgroup tun_device tun_device
! 20: * @{ @ingroup networking
! 21: */
! 22:
! 23: #ifndef TUN_DEVICE_H_
! 24: #define TUN_DEVICE_H_
! 25:
! 26: #include <networking/host.h>
! 27:
! 28: typedef struct tun_device_t tun_device_t;
! 29:
! 30: /**
! 31: * Class to create TUN devices
! 32: *
! 33: * Creating such a device requires the CAP_NET_ADMIN capability.
! 34: */
! 35: struct tun_device_t {
! 36:
! 37: /**
! 38: * Read a packet from the TUN device
! 39: *
! 40: * @note This call blocks until a packet is available. It is a thread
! 41: * cancellation point.
! 42: *
! 43: * @param packet the packet read from the device, allocated
! 44: * @return TRUE if successful
! 45: */
! 46: bool (*read_packet)(tun_device_t *this, chunk_t *packet);
! 47:
! 48: /**
! 49: * Write a packet to the TUN device
! 50: *
! 51: * @param packet the packet to write to the TUN device
! 52: * @return TRUE if successful
! 53: */
! 54: bool (*write_packet)(tun_device_t *this, chunk_t packet);
! 55:
! 56: /**
! 57: * Set the IP address of the device
! 58: *
! 59: * @param addr the desired interface address
! 60: * @param netmask the netmask to use
! 61: * @return TRUE if operation successful
! 62: */
! 63: bool (*set_address)(tun_device_t *this, host_t *addr, uint8_t netmask);
! 64:
! 65: /**
! 66: * Get the IP address previously assigned to using set_address().
! 67: *
! 68: * @param netmask pointer receiving the configured netmask, or NULL
! 69: * @return address previously set, NULL if none
! 70: */
! 71: host_t* (*get_address)(tun_device_t *this, uint8_t *netmask);
! 72:
! 73: /**
! 74: * Bring the TUN device up
! 75: *
! 76: * @return TRUE if operation successful
! 77: */
! 78: bool (*up)(tun_device_t *this);
! 79:
! 80: /**
! 81: * Set the MTU for this TUN device
! 82: *
! 83: * @param mtu new MTU
! 84: * @return TRUE if operation successful
! 85: */
! 86: bool (*set_mtu)(tun_device_t *this, int mtu);
! 87:
! 88: /**
! 89: * Get the current MTU for this TUN device
! 90: *
! 91: * @return current MTU
! 92: */
! 93: int (*get_mtu)(tun_device_t *this);
! 94:
! 95: /**
! 96: * Get the interface name of this device
! 97: *
! 98: * @return interface name
! 99: */
! 100: char *(*get_name)(tun_device_t *this);
! 101:
! 102: /**
! 103: * Get the underlying tun file descriptor.
! 104: *
! 105: * @return file descriptor of this tun device
! 106: */
! 107: int (*get_fd)(tun_device_t *this);
! 108:
! 109: /**
! 110: * Destroy a tun_device_t
! 111: */
! 112: void (*destroy)(tun_device_t *this);
! 113:
! 114: };
! 115:
! 116: /**
! 117: * Create a TUN device using the given name template.
! 118: *
! 119: * @param name_tmpl name template, defaults to "tun%d" if not given
! 120: * @return TUN device
! 121: */
! 122: tun_device_t *tun_device_create(const char *name_tmpl);
! 123:
! 124: #endif /** TUN_DEVICE_H_ @}*/
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>