/*
 * Tentun - covert tunneling project
 *
 * Copyright (C) 2003 David Gordon
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 */


#ifndef _TENTUN_H_
#define _TENTUN_H_

#include "debug.h"


/* Tentun version, must synchronize with conifgure.in &&&& to be fixed */
#define TENTUN_VER "0.2"

/* Include debug output with program */
#define DEBUG_TENTUN 1

/* Default TENTUN port - no one seems to use this one*/
#define TENTUN_PORT 7654

/* Default TENTUN connect timeout in sec */
#define TENTUN_CONNECT_TIMEOUT 30

/* General TENTUN timeout for several operations, in sec */
#define TENTUN_TIMEOUT 30

/* Number of seconds for delay after pppd startup*/
#define TENTUN_DELAY_SEC  10 

/* Max length of device name */
#define TENTUN_DEV_LEN  20 
 

struct tentun_sopt {
  char *dev;
  char *laddr;
  int  lport;
  char *raddr;
  int  rport;
};

struct tentun_addr {
  char *name;
  char *ip;
  int port;
  int type;
};
/* Address types */
#define TENTUN_ADDR_IFACE 0x01 
#define TENTUN_ADDR_NAME  0x02

struct tentun_host {
  char *host;
  char *dev;

  int  flags;
  int  timeout;
  int  spd_in;
  int  spd_out;
  int  zlevel;
  int  svr;      /* is a server */

  int  rmt_fd;
  int  loc_fd;

  /* Persist mode */
  int  persist;

  /* Multiple connections */
  int  multi;

  /* Keep Alive */
  int ka_interval;
  int ka_failure;

  /* Source address */
  struct tentun_addr src_addr;

  struct tentun_sopt sopt;
};

/* Flags definitions */
#define TENTUN_TTY        0x0100
#define TENTUN_PIPE       0x0200
#define TENTUN_ETHER      0x0400
#define TENTUN_TUN        0x0800
#define TENTUN_TYPE_MASK  (TENTUN_TTY | TENTUN_PIPE | TENTUN_ETHER | TENTUN_TUN)

#define TENTUN_TCP        0x0010
#define TENTUN_UDP        0x0020
#define TENTUN_PACKET     0x0040
#define TENTUN_PROT_MASK  (TENTUN_TCP | TENTUN_UDP | TENTUN_PACKET)
#define TENTUN_KEEP_ALIVE 0x0080

/*
#define TENTUN_ZLIB       0x0001
#define TENTUN_LZO        0x0002
#define TENTUN_SHAPE      0x0004
#define TENTUN_ENCRYPT    0x0008
*/
#define TENTUN_S_HTTP     0x0001
#define TENTUN_DNS        0x0002

/* Mask to drop the flags which will be supplied by the server */
#define TENTUN_CLNT_MASK  0xf000

#define TENTUN_PERSIST    0x1000

/* Constants and flags for Tentun protocol */
#define TENTUN_FRAME_SIZE     2048
#define TENTUN_FRAME_OVERHEAD 100
#define TENTUN_FSIZE_MASK     0x0fff

#define TENTUN_CONN_CLOSE 0x1000
#define TENTUN_ECHO_REQ	  0x2000
#define TENTUN_ECHO_REP	  0x4000
#define TENTUN_BAD_FRAME  0x8000

/* Authentication message size */
#define TENTUN_MESG_SIZE	50

/* Support for multiple connections */
#define TENTUN_MULTI_DENY       0  /* no */ 
#define TENTUN_MULTI_ALLOW      1  /* yes */
#define TENTUN_MULTI_KILL       2

/* keep interface in persistant mode */
#define TENTUN_PERSIST_KEEPIF   2

/* Values for the signal flag */
#define TENTUN_SIG_TERM 1
#define TENTUN_SIG_HUP  2

/* Global options */
struct tentun_opts {
  int  timeout;
  int  persist;

  char *svr_name;       /* Server's host name */
  int  svr_port;	 /* Server's port */
  int  svr_type;	 /* Server mode */
};

extern struct tentun_opts tentun;

#define TENTUN_STAND_ALONE	0 
#define TENTUN_INETD		1	


#endif
