1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
#ifndef PPP_H
#define PPP_H
#include <sys/types.h>
#include <time.h>
#include <pthread.h>
#include <netinet/in.h>
#include "triton.h"
#include "list.h"
/*
* Packet header = Code, id, length.
*/
#define PPP_HEADERLEN 4
#define PPP_MTU 1500
/*
* Protocol field values.
*/
#define PPP_IP 0x21 /* Internet Protocol */
#define PPP_AT 0x29 /* AppleTalk Protocol */
#define PPP_IPX 0x2b /* IPX protocol */
#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */
#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */
#define PPP_IPV6 0x57 /* Internet Protocol Version 6 */
#define PPP_COMP 0xfd /* compressed packet */
#define PPP_IPCP 0x8021 /* IP Control Protocol */
#define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */
#define PPP_IPXCP 0x802b /* IPX Control Protocol */
#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */
#define PPP_CCP 0x80fd /* Compression Control Protocol */
#define PPP_ECP 0x8053 /* Encryption Control Protocol */
#define PPP_LCP 0xc021 /* Link Control Protocol */
#define PPP_PAP 0xc023 /* Password Authentication Protocol */
#define PPP_LQR 0xc025 /* Link Quality Report protocol */
#define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */
#define PPP_CBCP 0xc029 /* Callback Control Protocol */
#define PPP_EAP 0xc227 /* Extensible Authentication Protocol */
#define PPP_SESSIONID_LEN 16
#define PPP_IFNAME_LEN 10
#define PPP_STATE_STARTING 1
#define PPP_STATE_ACTIVE 2
#define PPP_STATE_FINISHING 3
#define TERM_USER_REQUEST 1
#define TERM_SESSION_TIMEOUT 2
#define TERM_ADMIN_RESET 3
#define TERM_USER_ERROR 4
#define TERM_NAS_ERROR 5
#define TERM_NAS_REQUEST 6
#define TERM_NAS_REBOOT 7
#define TERM_AUTH_ERROR 8
#define TERM_LOST_CARRIER 9
#define CTRL_TYPE_PPTP 1
#define CTRL_TYPE_L2TP 2
#define CTRL_TYPE_PPPOE 3
#define MPPE_UNSET -2
#define MPPE_ALLOW -1
#define MPPE_DENY 0
#define MPPE_PREFER 1
#define MPPE_REQUIRE 2
struct ppp_t;
struct ipv4db_item_t;
struct ipv6db_item_t;
struct ppp_ctrl_t
{
struct triton_context_t *ctx;
int type;
const char *name;
int max_mtu;
int mppe;
char *calling_station_id;
char *called_station_id;
void (*started)(struct ppp_t*);
void (*finished)(struct ppp_t*);
};
struct ppp_pd_t
{
struct list_head entry;
void *key;
};
struct ppp_t
{
struct list_head entry;
struct triton_md_handler_t chan_hnd;
struct triton_md_handler_t unit_hnd;
int fd;
int chan_fd;
int unit_fd;
int chan_idx;
int unit_idx;
int state;
char *chan_name;
char ifname[PPP_IFNAME_LEN];
int ifindex;
char sessionid[PPP_SESSIONID_LEN+1];
time_t start_time;
time_t stop_time;
char *username;
struct ipv4db_item_t *ipv4;
struct ipv6db_item_t *ipv6;
char *ipv4_pool_name;
char *ipv6_pool_name;
const char *comp;
struct ppp_ctrl_t *ctrl;
int terminating:1;
int terminated:1;
int terminate_cause;
void *buf;
int buf_size;
struct list_head chan_handlers;
struct list_head unit_handlers;
struct list_head layers;
struct ppp_lcp_t *lcp;
struct list_head pd_list;
};
struct ppp_layer_t;
struct layer_node_t;
struct ppp_layer_data_t
{
struct list_head entry;
struct ppp_layer_t *layer;
struct layer_node_t *node;
int passive:1;
int optional:1;
int starting:1;
int started:1;
int finished:1;
};
struct ppp_layer_t
{
struct list_head entry;
struct ppp_layer_data_t *(*init)(struct ppp_t *);
int (*start)(struct ppp_layer_data_t*);
void (*finish)(struct ppp_layer_data_t*);
void (*free)(struct ppp_layer_data_t *);
};
struct ppp_handler_t
{
struct list_head entry;
int proto;
void (*recv)(struct ppp_handler_t*);
void (*recv_proto_rej)(struct ppp_handler_t *h);
};
struct ppp_stat_t
{
unsigned int active;
unsigned int starting;
unsigned int finishing;
};
struct ppp_t *alloc_ppp(void);
void ppp_init(struct ppp_t *ppp);
int establish_ppp(struct ppp_t *ppp);
int ppp_chan_send(struct ppp_t *ppp, void *data, int size);
int ppp_unit_send(struct ppp_t *ppp, void *data, int size);
void lcp_send_proto_rej(struct ppp_t *ppp, uint16_t proto);
void ppp_recv_proto_rej(struct ppp_t *ppp, uint16_t proto);
struct ppp_fsm_t* ppp_lcp_init(struct ppp_t *ppp);
void ppp_layer_started(struct ppp_t *ppp,struct ppp_layer_data_t*);
void ppp_layer_finished(struct ppp_t *ppp,struct ppp_layer_data_t*);
void ppp_layer_passive(struct ppp_t *ppp,struct ppp_layer_data_t*);
void ppp_terminate(struct ppp_t *ppp, int hard, int cause);
void ppp_register_chan_handler(struct ppp_t *, struct ppp_handler_t *);
void ppp_register_unit_handler(struct ppp_t * ,struct ppp_handler_t *);
void ppp_unregister_handler(struct ppp_t *, struct ppp_handler_t *);
int ppp_register_layer(const char *name, struct ppp_layer_t *);
void ppp_unregister_layer(struct ppp_layer_t *);
struct ppp_layer_data_t *ppp_find_layer_data(struct ppp_t *, struct ppp_layer_t *);
extern int ppp_shutdown;
void ppp_shutdown_soft(void);
int ppp_ipv6_nd_start(struct ppp_t *ppp, uint64_t intf_id);
extern int conf_ppp_verbose;
extern int conf_single_session;
extern pthread_rwlock_t ppp_lock;
extern struct list_head ppp_list;
extern struct ppp_stat_t ppp_stat;
extern int sock_fd; // internet socket for ioctls
extern int sock6_fd; // internet socket for ioctls
extern int urandom_fd;
#endif
|