#ifndef PPTP_H
#define PPTP_H 1
#define PPTP_MES_TYPE_CTRL 1
#define PPTP_MAGIC_COOKIE 0x1a2b3c4d
#define PPTP_RFC_2637_VERSION 0x0100
#ifndef PPTP_MAX_CALL
#define PPTP_MAX_CALL 8192
#endif
#define PPTP_CTRL_MES_CODE_SCCRQ 1
#define PPTP_CTRL_MES_CODE_SCCRP 2
#define PPTP_CTRL_MES_CODE_StopCCRQ 3
#define PPTP_CTRL_MES_CODE_StopCCRP 4
#define PPTP_CTRL_MES_CODE_ECHO_RQ 5
#define PPTP_CTRL_MES_CODE_ECHO_RP 6
#define PPTP_CTRL_MES_CODE_OCRQ 7
#define PPTP_CTRL_MES_CODE_OCRP 8
#define PPTP_CTRL_MES_CODE_ICRQ 9
#define PPTP_CTRL_MES_CODE_ICRP 10
#define PPTP_CTRL_MES_CODE_ICCN 11
#define PPTP_CTRL_MES_CODE_CCR 12
#define PPTP_CTRL_MES_CODE_CDN 13
#define PPTP_CTRL_MES_CODE_SLI 15
#define PPTP_CTRL_FRAMING_ASYNC 1
#define PPTP_CTRL_FRAMING_SYNC 2
#define PPTP_CTRL_BEARER_ANALOG 1
#define PPTP_CTRL_BEARER_DIGITAL 2
#define PPTP_SCCRP_RESULT_SUCCESS 1
#define PPTP_SCCRP_RESULT_GENERIC_ERROR 2
#define PPTP_SCCRP_RESULT_CHANNEL_EXISTS 3
#define PPTP_SCCRP_RESULT_NOT_AUTHORIZIZED 4
#define PPTP_SCCRP_RESULT_BAD_PROTOCOL_VERSION 5
#define PPTP_ERROR_NONE 0
#define PPTP_ERROR_NOT_CONNECTED 1
#define PPTP_ERROR_BAD_FORMAT 2
#define PPTP_ERROR_NO_RESOURCE 3
#define PPTP_ERROR_BAD_CALL 4
#define PPTP_ERROR_PAC_ERROR 5
#define PPTP_OCRP_RESULT_CONNECTED 1
#define PPTP_OCRP_RESULT_GENERIC_ERROR 2
#define PPTP_OCRP_RESULT_NO_CARRIER 3
#define PPTP_OCRP_RESULT_BUSY 4
#define PPTP_OCRP_RESULT_NO_DIALTONE 5
#define PPTP_OCRP_RESULT_TIMEOUT 6
#define PPTP_OCRP_RESULT_DO_NOT_ACCEPT 7
#define PPTP_ECHO_RP_RESULT_OK 1
#define PPTP_ECHO_RP_RESULT_GENERIC_ERROR 2
#define PPTP_StopCCRQ_REASON_NONE 1
#define PPTP_StopCCRQ_REASON_STOP_PROTOCOL 2
#define PPTP_StopCCRQ_REASON_STOP_LOCAL_SHUTDOWN 3
#define PPTP_StopCCRP_RESULT_OK 1
#define PPTP_StopCCRP_RESULT_GENERIC_ERROR 2
#define PPTP_CDN_RESULT_LOST_CARRIER 1
#define PPTP_CDN_RESULT_GENRIC_ERROR 2
#define PPTP_CDN_RESULT_ADMIN_SHUTDOWN 3
#define PPTP_CDN_RESULT_REQUEST 4
#define PPTPD_DEFAULT_TCP_PORT 1723
#define PPTP_GRE_PROTOCOL_TYPE 0x880b
#define PPTP_GRE_VERSION 1
#include "pptp_conf.h"
#define PPTPD_STATE_INIT 0
#define PPTPD_STATE_RUNNING 1
#define PPTPD_STATE_SHUTTING_DOWN 2
#define PPTPD_STATE_STOPPED 3
#define PPTPD_CONFIG_BUFSIZ 65535
#define PPTP_BACKLOG 32
#define PPTP_BUFSIZ 1024
#define PPTPD_DEFAULT_LAYER2_LABEL "PPTP"
#define PPTP_CTRL_STATE_IDLE 0
#define PPTP_CTRL_STATE_WAIT_CTRL_REPLY 1
#define PPTP_CTRL_STATE_ESTABLISHED 2
#define PPTP_CTRL_STATE_WAIT_STOP_REPLY 3
#define PPTP_CTRL_STATE_DISPOSING 4
#ifndef PPTPD_DEFAULT_VENDOR_NAME
#define PPTPD_DEFAULT_VENDOR_NAME ""
#endif
#ifndef PPTP_CALL_DEFAULT_MAXWINSZ
#define PPTP_CALL_DEFAULT_MAXWINSZ 64
#endif
#ifndef PPTP_CALL_CONNECT_SPEED
#define PPTP_CALL_CONNECT_SPEED 10000000
#endif
#ifndef PPTP_CALL_INITIAL_PPD
#define PPTP_CALL_INITIAL_PPD 0
#endif
#define PPTP_CALL_DELAY_LIMIT 64
#define PPTP_CALL_STATE_IDLE 0
#define PPTP_CALL_STATE_WAIT_CONN 1
#define PPTP_CALL_STATE_ESTABLISHED 2
#define PPTP_CALL_STATE_CLEANUP_WAIT 3
#define PPTPD_SHUTDOWN_TIMEOUT 5
#define PPTPD_IDLE_TIMEOUT 60
#define PPTP_CALL_CLEANUP_WAIT_TIME 3
#define PPTP_CTRL_DEFAULT_ECHO_INTERVAL 60
#define PPTP_CTRL_DEFAULT_ECHO_TIMEOUT 60
#define PPTP_CTRL_StopCCRP_WAIT_TIME 3
#ifndef PPTP_NLISTENER
#define PPTP_NLISTENER 6
#endif
#define pptpd_is_stopped(pptpd) \
(((pptpd)->state != PPTPD_STATE_SHUTTING_DOWN && \
(pptpd)->state != PPTPD_STATE_RUNNING)? 1 : 0)
#define pptpd_is_shutting_down(pptpd) \
(((pptpd)->state == PPTPD_STATE_SHUTTING_DOWN)? 1 : 0)
struct _pptpd;
typedef struct _pptpd_listener {
struct event ev_sock_gre;
struct _pptpd *self;
uint16_t index;
int sock;
int sock_gre;
struct sockaddr_in bind_sin;
struct sockaddr_in bind_sin_gre;
char tun_name[PPTP_NAME_LEN];
struct pptp_conf *conf;
} pptpd_listener;
typedef struct _pptpd {
unsigned id;
slist listener;
int state;
struct event ev_timer;
slist ctrl_list;
slist call_free_list;
hash_table *call_id_map;
uint32_t
initialized:1;
} pptpd;
#define pptp_ctrl_sock_gre(ctrl) \
((pptpd_listener *)slist_get(&(ctrl)->pptpd->listener,\
(ctrl)->listener_index))->sock_gre
#define PPTP_CTRL_LISTENER_TUN_NAME(ctrl) \
((pptpd_listener *)slist_get(&(ctrl)->pptpd->listener,\
(ctrl)->listener_index))->tun_name
#define PPTP_CTRL_CONF(ctrl) \
((pptpd_listener *)slist_get(&(ctrl)->pptpd->listener, \
(ctrl)->listener_index))->conf
typedef struct _pptp_ctrl {
pptpd *pptpd;
uint16_t listener_index;
unsigned id;
int state;
int sock;
struct sockaddr_storage peer;
struct sockaddr_storage our;
struct event ev_sock;
struct event ev_timer;
int echo_interval;
int echo_timeout;
int send_ready;
bytebuffer *recv_buf;
bytebuffer *send_buf;
slist call_list;
time_t last_snd_ctrl;
time_t last_rcv_ctrl;
uint32_t echo_seq;
uint16_t
on_io_event:1,
reserved:15;
} pptp_ctrl;
typedef struct _pptp_call {
pptp_ctrl *ctrl;
unsigned id;
int ifidx;
int state;
unsigned peers_call_id;
void *ppp;
uint32_t snd_una;
uint32_t snd_nxt;
uint32_t rcv_nxt;
uint32_t rcv_acked;
int winsz;
int maxwinsz;
int peers_maxwinsz;
time_t last_io;
} pptp_call;
#ifdef __cplusplus
extern "C" {
#endif
int pptpd_init (pptpd *);
void pptpd_uninit (pptpd *);
int pptpd_assign_call (pptpd *, pptp_call *);
void pptpd_release_call (pptpd *, pptp_call *);
int pptpd_start (pptpd *);
void pptpd_stop (pptpd *);
void pptpd_stop_immediatly (pptpd *);
void pptpd_ctrl_finished_notify(pptpd *, pptp_ctrl *);
int pptpd_add_listener(pptpd *, int, struct pptp_conf *, struct sockaddr *);
pptp_ctrl *pptp_ctrl_create (void);
int pptp_ctrl_init (pptp_ctrl *);
int pptp_ctrl_start (pptp_ctrl *);
void pptp_ctrl_stop (pptp_ctrl *, int);
void pptp_ctrl_destroy (pptp_ctrl *);
void pptp_ctrl_output (pptp_ctrl *, u_char *, int);
pptp_call *pptp_call_create (void);
int pptp_call_init (pptp_call *, pptp_ctrl *);
int pptp_call_start (pptp_call *);
int pptp_call_stop (pptp_call *);
void pptp_call_destroy (pptp_call *);
void pptp_call_input (pptp_call *, int, u_char *, int);
void pptp_call_gre_input (pptp_call *, uint32_t, uint32_t, int, u_char *, int);
void pptp_call_disconnect(pptp_call *, int, int, const char *);
int pptpd_reload(pptpd *, struct pptp_confs *);
#ifdef __cplusplus
}
#endif
#endif