-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathnatcap_client.h
148 lines (123 loc) · 3.89 KB
/
natcap_client.h
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
/*
* Author: Chen Minqiang <[email protected]>
* Date : Sun, 05 Jun 2016 16:24:31 +0800
*
* This file is part of the natcap.
*
* natcap 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 3 of the License, or
* (at your option) any later version.
*
* natcap is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with natcap; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef _NATCAP_CLIENT_H_
#define _NATCAP_CLIENT_H_
#include <linux/types.h>
#include <linux/if_ether.h>
#include "natcap.h"
extern unsigned int server_index_natcap_mask;
extern unsigned int cnipwhitelist_mode;
enum {
NATCAP_ACL_NONE,
NATCAP_ACL_ALLOW,
NATCAP_ACL_DENY,
NATCAP_ACL_MAX
};
extern unsigned int macfilter;
extern const char *macfilter_acl_str[NATCAP_ACL_MAX];
extern unsigned int ipfilter;
extern const char *ipfilter_acl_str[NATCAP_ACL_MAX];
extern unsigned int dns_proxy_drop;
extern unsigned int server_persist_lock;
extern unsigned int server_persist_timeout;
extern unsigned int encode_http_only;
extern unsigned int http_confusion;
extern unsigned int sproxy;
extern unsigned int dns_server;
extern unsigned short dns_port;
extern struct tuple *dns_proxy_server;
extern u32 default_protocol;
extern u32 default_u_hash;
extern unsigned char default_mac_addr[ETH_ALEN];
void default_mac_addr_init(void);
enum server_group_t {
SERVER_GROUP_0,
SERVER_GROUP_1,
SERVER_GROUP_MAX
};
void natcap_server_info_change(enum server_group_t x, int change);
void natcap_server_info_cleanup(enum server_group_t x);
int natcap_server_info_add(enum server_group_t x, const struct tuple *dst);
int natcap_server_info_delete(enum server_group_t x, const struct tuple *dst);
void *natcap_server_info_get(enum server_group_t x, loff_t idx);
void natcap_server_in_touch(enum server_group_t x, __be32 ip);
extern unsigned int natcap_server_use_peer;
const struct tuple *natcap_server_info_current(enum server_group_t x);
int natcap_client_init(void);
void natcap_client_exit(void);
struct natcap_token_ctrl {
int tokens;
int tokens_per_jiffy;
unsigned long jiffies;
spinlock_t lock;
};
extern int tx_pkts_threshold;
extern int rx_pkts_threshold;
extern void natcap_tx_speed_set(int speed);
extern void natcap_rx_speed_set(int speed);
extern int natcap_tx_speed_get(void);
extern int natcap_rx_speed_get(void);
extern int is_natcap_server(__be32 ip);
/* for DNS decode */
static inline int get_rdata(const unsigned char *src_ptr, int src_len, int src_pos, unsigned char *dst_ptr, int dst_size)
{
int ptr_count = 0;
int ptr_limit = src_len / 2;
int pos = src_pos;
int dst_len = 0;
unsigned int v;
while (dst_len < dst_size && pos < src_len && (v = get_byte1(src_ptr + pos)) != 0) {
if (v > 0x3f) {
if (pos + 1 >= src_len) {
return -1;
}
if (++ptr_count >= ptr_limit) {
return -2;
}
pos = ntohs(get_byte2(src_ptr + pos)) & 0x3fff;
continue;
} else {
if (pos + v >= src_len) {
return -3;
}
if (dst_len + v >= dst_size) {
return -4;
}
memcpy(dst_ptr, src_ptr + pos + 1, v);
dst_ptr += v;
*dst_ptr = '.';
dst_ptr += 1;
dst_len += v + 1;
pos += v + 1;
}
}
return dst_len;
}
extern void cn_domain_clean(void);
extern void domain_copy(char *dst, char *from);
extern int domain_cmp(char *dst, char *src);
extern int cn_domain_insert(char *d);
extern int domain_match(char *dst, char *src);
extern int cn_domain_lookup(char *d);
extern int cn_domain_load_from_path(char *path);
extern int cn_domain_load_from_raw(char *path);
extern int cn_domain_dump_path(char *path);
#endif /* _NATCAP_CLIENT_H_ */