Annotation of embedaddon/coova-chilli/src/tun.h, revision 1.1
1.1 ! misho 1: /*
! 2: * TUN interface functions.
! 3: * Copyright (C) 2002, 2003, 2004, 2005 Mondru AB.
! 4: * Copyright (C) 2007-2008 David Bird <david@coova.com>
! 5: *
! 6: * The contents of this file may be used under the terms of the GNU
! 7: * General Public License Version 2, provided that the above copyright
! 8: * notice and this permission notice is included in all copies or
! 9: * substantial portions of the software.
! 10: *
! 11: */
! 12:
! 13: #ifndef _TUN_H
! 14: #define _TUN_H
! 15:
! 16: #include "pkt.h"
! 17: #include "net.h"
! 18:
! 19: #define PACKET_MAX 8196 /* Maximum packet size we receive */
! 20: #define TUN_SCRIPTSIZE 512
! 21: #define TUN_ADDRSIZE 128
! 22: #define TUN_NLBUFSIZE 1024
! 23: #define TUN_MAX_INTERFACES 4
! 24:
! 25: /* ***********************************************************
! 26: * Information storage for each tun instance
! 27: *************************************************************/
! 28:
! 29: struct tun_t {
! 30: int debug;
! 31: int addrs; /* Number of allocated IP addresses */
! 32: int routes; /* One if we allocated an automatic route */
! 33: int routeidx; /* default route interface index */
! 34: int (*cb_ind) (struct tun_t *tun, void *pack, size_t len, int idx);
! 35:
! 36: int _interface_count;
! 37: struct _net_interface _interfaces[TUN_MAX_INTERFACES];
! 38: };
! 39:
! 40: #define tun(x,i) ((x)->_interfaces[(i)])
! 41: #define tuntap(x) tun((x),0)
! 42:
! 43: int tun_new(struct tun_t **tun);
! 44: int tun_free(struct tun_t *this);
! 45: int tun_decaps(struct tun_t *this, int idx);
! 46: int tun_encaps(struct tun_t *this, void *pack, size_t len, int idx);
! 47:
! 48: /*int tun_addaddr(struct tun_t *this, struct in_addr *addr, struct in_addr *dstaddr, struct in_addr *netmask);
! 49: int tun_setaddr(struct tun_t *this, struct in_addr *our_adr, struct in_addr *his_adr, struct in_addr *net_mask);
! 50: int tun_addroute(struct tun_t *this, struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask);
! 51: int tun_delroute(struct tun_t *this, struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask);*/
! 52:
! 53: int tun_set_cb_ind(struct tun_t *this, int (*cb_ind) (struct tun_t *tun, void *pack, size_t len, int idx));
! 54:
! 55: int tun_setaddr(struct tun_t *this, struct in_addr *addr, struct in_addr *dstaddr, struct in_addr *netmask);
! 56:
! 57: int tun_runscript(struct tun_t *tun, char* script);
! 58:
! 59: net_interface *tun_nextif(struct tun_t *tun);
! 60: int tun_name2idx(struct tun_t *tun, char *name);
! 61:
! 62: #define tun_maxfd(tun,max) {int i; for (i=0; i<(tun)->_interface_count; i++) net_maxfd(&(tun)->_interfaces[i], (max));}
! 63: #define tun_fdset(tun,fds) {int i; for (i=0; i<(tun)->_interface_count; i++) net_fdset(&(tun)->_interfaces[i], (fds));}
! 64: #define tun_ckset(tun,fds) {int i; for (i=0; i<(tun)->_interface_count; i++) { \
! 65: if (net_isset(&(tun)->_interfaces[i], (fds)) && tun_decaps((tun), i) < 0) log_err(0, "tun_decaps()"); } }
! 66: #define tun_close(tun) {int i; for (i=0; i<(tun)->_interface_count; i++) net_close(&(tun)->_interfaces[i]);}
! 67:
! 68: #endif /* !_TUN_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>