mirror of
https://github.com/hufrea/byedpi.git
synced 2024-12-21 22:05:32 +00:00
More pedantic code
This commit is contained in:
parent
38f4fe169e
commit
276073ddea
24
desync.c
24
desync.c
@ -47,7 +47,7 @@ int setttl(int fd, int ttl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
int drop_sack(int fd)
|
static int drop_sack(int fd)
|
||||||
{
|
{
|
||||||
struct sock_filter code[] = {
|
struct sock_filter code[] = {
|
||||||
{ 0x30, 0, 0, 0x0000000c },
|
{ 0x30, 0, 0, 0x0000000c },
|
||||||
@ -85,7 +85,7 @@ static inline void delay(long ms)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
void wait_send(int sfd)
|
static void wait_send(int sfd)
|
||||||
{
|
{
|
||||||
for (int i = 0; params.wait_send && i < 500; i++) {
|
for (int i = 0; params.wait_send && i < 500; i++) {
|
||||||
struct tcp_info tcpi = {};
|
struct tcp_info tcpi = {};
|
||||||
@ -122,7 +122,7 @@ void wait_send(int sfd)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
ssize_t send_fake(int sfd, char *buffer,
|
static ssize_t send_fake(int sfd, const char *buffer,
|
||||||
int cnt, long pos, struct desync_params *opt)
|
int cnt, long pos, struct desync_params *opt)
|
||||||
{
|
{
|
||||||
struct sockaddr_in6 addr = {};
|
struct sockaddr_in6 addr = {};
|
||||||
@ -234,7 +234,7 @@ ssize_t send_fake(int sfd, char *buffer,
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
OVERLAPPED ov = {};
|
OVERLAPPED ov = {};
|
||||||
|
|
||||||
ssize_t send_fake(int sfd, char *buffer,
|
static ssize_t send_fake(int sfd, const char *buffer,
|
||||||
int cnt, long pos, struct desync_params *opt)
|
int cnt, long pos, struct desync_params *opt)
|
||||||
{
|
{
|
||||||
struct packet pkt;
|
struct packet pkt;
|
||||||
@ -334,8 +334,8 @@ ssize_t send_fake(int sfd, char *buffer,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ssize_t send_oob(int sfd, char *buffer,
|
static ssize_t send_oob(int sfd, char *buffer,
|
||||||
ssize_t n, long pos, char *c)
|
ssize_t n, long pos, const char *c)
|
||||||
{
|
{
|
||||||
char rchar = buffer[pos];
|
char rchar = buffer[pos];
|
||||||
buffer[pos] = c[1] ? c[0] : 'a';
|
buffer[pos] = c[1] ? c[0] : 'a';
|
||||||
@ -357,8 +357,8 @@ ssize_t send_oob(int sfd, char *buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ssize_t send_disorder(int sfd,
|
static ssize_t send_disorder(int sfd,
|
||||||
char *buffer, long pos)
|
const char *buffer, long pos)
|
||||||
{
|
{
|
||||||
int bttl = 1;
|
int bttl = 1;
|
||||||
|
|
||||||
@ -378,8 +378,8 @@ ssize_t send_disorder(int sfd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ssize_t send_late_oob(int sfd, char *buffer,
|
static ssize_t send_late_oob(int sfd, char *buffer,
|
||||||
ssize_t n, long pos, char *c)
|
ssize_t n, long pos, const char *c)
|
||||||
{
|
{
|
||||||
int bttl = 1;
|
int bttl = 1;
|
||||||
|
|
||||||
@ -427,7 +427,7 @@ static long gen_offset(long pos, int flag,
|
|||||||
|
|
||||||
|
|
||||||
ssize_t desync(int sfd, char *buffer, size_t bfsize,
|
ssize_t desync(int sfd, char *buffer, size_t bfsize,
|
||||||
ssize_t n, ssize_t offset, struct sockaddr *dst, int dp_c)
|
ssize_t n, ssize_t offset, const struct sockaddr *dst, int dp_c)
|
||||||
{
|
{
|
||||||
struct desync_params dp = params.dp[dp_c];
|
struct desync_params dp = params.dp[dp_c];
|
||||||
|
|
||||||
@ -599,7 +599,7 @@ int post_desync(int sfd, int dp_c)
|
|||||||
|
|
||||||
|
|
||||||
ssize_t desync_udp(int sfd, char *buffer, size_t bfsize,
|
ssize_t desync_udp(int sfd, char *buffer, size_t bfsize,
|
||||||
ssize_t n, struct sockaddr *dst, int dp_c)
|
ssize_t n, const struct sockaddr *dst, int dp_c)
|
||||||
{
|
{
|
||||||
struct desync_params *dp = ¶ms.dp[dp_c];
|
struct desync_params *dp = ¶ms.dp[dp_c];
|
||||||
|
|
||||||
|
4
desync.h
4
desync.h
@ -10,9 +10,9 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ssize_t desync(int sfd, char *buffer, size_t bfsize, ssize_t n, ssize_t offset, struct sockaddr *dst, int dp_c);
|
ssize_t desync(int sfd, char *buffer, size_t bfsize, ssize_t n, ssize_t offset, const struct sockaddr *dst, int dp_c);
|
||||||
|
|
||||||
ssize_t desync_udp(int sfd, char *buffer, size_t bfsize, ssize_t n, struct sockaddr *dst, int dp_c);
|
ssize_t desync_udp(int sfd, char *buffer, size_t bfsize, ssize_t n, const struct sockaddr *dst, int dp_c);
|
||||||
|
|
||||||
int setttl(int fd, int ttl);
|
int setttl(int fd, int ttl);
|
||||||
|
|
||||||
|
25
extend.c
25
extend.c
@ -72,7 +72,7 @@ static ssize_t serialize_addr(const struct sockaddr_ina *dst,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int cache_get(struct sockaddr_ina *dst)
|
static int cache_get(const struct sockaddr_ina *dst)
|
||||||
{
|
{
|
||||||
uint8_t key[KEY_SIZE] = { 0 };
|
uint8_t key[KEY_SIZE] = { 0 };
|
||||||
int len = serialize_addr(dst, key, sizeof(key));
|
int len = serialize_addr(dst, key, sizeof(key));
|
||||||
@ -90,7 +90,7 @@ static int cache_get(struct sockaddr_ina *dst)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int cache_add(struct sockaddr_ina *dst, int m)
|
static int cache_add(const struct sockaddr_ina *dst, int m)
|
||||||
{
|
{
|
||||||
assert(m >= 0 && m < params.dp_count);
|
assert(m >= 0 && m < params.dp_count);
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ static int cache_add(struct sockaddr_ina *dst, int m)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline bool check_port(uint16_t *p, struct sockaddr_in6 *dst)
|
static inline bool check_port(const uint16_t *p, const struct sockaddr_in6 *dst)
|
||||||
{
|
{
|
||||||
return (dst->sin6_port >= p[0]
|
return (dst->sin6_port >= p[0]
|
||||||
&& dst->sin6_port <= p[1]);
|
&& dst->sin6_port <= p[1]);
|
||||||
@ -125,7 +125,7 @@ static inline bool check_port(uint16_t *p, struct sockaddr_in6 *dst)
|
|||||||
|
|
||||||
|
|
||||||
int connect_hook(struct poolhd *pool, struct eval *val,
|
int connect_hook(struct poolhd *pool, struct eval *val,
|
||||||
struct sockaddr_ina *dst, int next)
|
const struct sockaddr_ina *dst, int next)
|
||||||
{
|
{
|
||||||
int m = cache_get(dst);
|
int m = cache_get(dst);
|
||||||
val->cache = (m == 0);
|
val->cache = (m == 0);
|
||||||
@ -135,7 +135,7 @@ int connect_hook(struct poolhd *pool, struct eval *val,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int socket_mod(int fd, struct sockaddr *dst)
|
int socket_mod(int fd)
|
||||||
{
|
{
|
||||||
if (params.custom_ttl) {
|
if (params.custom_ttl) {
|
||||||
if (setttl(fd, params.def_ttl) < 0) {
|
if (setttl(fd, params.def_ttl) < 0) {
|
||||||
@ -171,7 +171,8 @@ static int reconnect(struct poolhd *pool, struct eval *val, int m)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool check_host(struct mphdr *hosts, char *buffer, ssize_t n)
|
static bool check_host(
|
||||||
|
struct mphdr *hosts, const char *buffer, ssize_t n)
|
||||||
{
|
{
|
||||||
char *host = 0;
|
char *host = 0;
|
||||||
int len;
|
int len;
|
||||||
@ -195,7 +196,7 @@ static bool check_host(struct mphdr *hosts, char *buffer, ssize_t n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool check_proto_tcp(int proto, char *buffer, ssize_t n)
|
static bool check_proto_tcp(int proto, const char *buffer, ssize_t n)
|
||||||
{
|
{
|
||||||
if (proto & IS_TCP) {
|
if (proto & IS_TCP) {
|
||||||
return 1;
|
return 1;
|
||||||
@ -212,7 +213,7 @@ static bool check_proto_tcp(int proto, char *buffer, ssize_t n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool check_round(int *nr, int r)
|
static bool check_round(const int *nr, int r)
|
||||||
{
|
{
|
||||||
return (!nr[1] && r <= 1) || (r >= nr[0] && r <= nr[1]);
|
return (!nr[1] && r <= 1) || (r >= nr[0] && r <= nr[1]);
|
||||||
}
|
}
|
||||||
@ -279,7 +280,7 @@ static int on_fin(struct poolhd *pool, struct eval *val)
|
|||||||
|
|
||||||
|
|
||||||
static int on_response(struct poolhd *pool, struct eval *val,
|
static int on_response(struct poolhd *pool, struct eval *val,
|
||||||
char *resp, ssize_t sn)
|
const char *resp, ssize_t sn)
|
||||||
{
|
{
|
||||||
int m = val->pair->attempt + 1;
|
int m = val->pair->attempt + 1;
|
||||||
|
|
||||||
@ -318,7 +319,7 @@ static inline void free_first_req(struct eval *client)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int setup_conn(struct eval *client, char *buffer, ssize_t n)
|
static int setup_conn(struct eval *client, const char *buffer, ssize_t n)
|
||||||
{
|
{
|
||||||
int m = client->attempt;
|
int m = client->attempt;
|
||||||
|
|
||||||
@ -361,7 +362,7 @@ static int cancel_setup(struct eval *remote)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int send_saved_req(struct poolhd *pool,
|
static int send_saved_req(struct poolhd *pool,
|
||||||
struct eval *client, char *buffer, ssize_t bfsize)
|
struct eval *client, char *buffer, ssize_t bfsize)
|
||||||
{
|
{
|
||||||
ssize_t offset = client->buff.offset;
|
ssize_t offset = client->buff.offset;
|
||||||
@ -547,7 +548,7 @@ ssize_t udp_hook(struct eval *val,
|
|||||||
|
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
int protect(int conn_fd, const char *path)
|
static int protect(int conn_fd, const char *path)
|
||||||
{
|
{
|
||||||
struct sockaddr_un sa;
|
struct sockaddr_un sa;
|
||||||
sa.sun_family = AF_UNIX;
|
sa.sun_family = AF_UNIX;
|
||||||
|
6
extend.h
6
extend.h
@ -5,10 +5,10 @@
|
|||||||
|
|
||||||
#include "proxy.h"
|
#include "proxy.h"
|
||||||
|
|
||||||
int socket_mod(int fd, struct sockaddr *dst);
|
int socket_mod(int fd);
|
||||||
|
|
||||||
int connect_hook(struct poolhd *pool, struct eval *val,
|
int connect_hook(struct poolhd *pool, struct eval *val,
|
||||||
struct sockaddr_ina *dst, int next);
|
const struct sockaddr_ina *dst, int next);
|
||||||
|
|
||||||
ssize_t tcp_send_hook(struct eval *val,
|
ssize_t tcp_send_hook(struct eval *val,
|
||||||
char *buffer, size_t bfsize, ssize_t n);
|
char *buffer, size_t bfsize, ssize_t n);
|
||||||
@ -23,7 +23,7 @@ int on_first_tunnel(struct poolhd *pool,
|
|||||||
struct eval *val, char *buffer, ssize_t bfsize, int etype);
|
struct eval *val, char *buffer, ssize_t bfsize, int etype);
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
int protect(int conn_fd, const char *path);
|
static int protect(int conn_fd, const char *path);
|
||||||
#else
|
#else
|
||||||
#define protect(fd, path) 0
|
#define protect(fd, path) 0
|
||||||
#endif
|
#endif
|
||||||
|
2
main.c
2
main.c
@ -59,7 +59,7 @@ struct params params = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const char help_text[] = {
|
const static char help_text[] = {
|
||||||
" -i, --ip, <ip> Listening IP, default 0.0.0.0\n"
|
" -i, --ip, <ip> Listening IP, default 0.0.0.0\n"
|
||||||
" -p, --port <num> Listening port, default 1080\n"
|
" -p, --port <num> Listening port, default 1080\n"
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
41
packets.c
41
packets.c
@ -60,9 +60,9 @@ char http_data[43] = {
|
|||||||
char udp_data[64] = { 0 };
|
char udp_data[64] = { 0 };
|
||||||
|
|
||||||
|
|
||||||
char *strncasestr(char *a, size_t as, char *b, size_t bs)
|
static const char *strncasestr(const char *a, size_t as, const char *b, size_t bs)
|
||||||
{
|
{
|
||||||
for (char *p = a; ; p++) {
|
for (const char *p = a; ; p++) {
|
||||||
p = memchr(p, *b, as - (p - a));
|
p = memchr(p, *b, as - (p - a));
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -78,8 +78,8 @@ char *strncasestr(char *a, size_t as, char *b, size_t bs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t find_tls_ext_offset(uint16_t type,
|
static size_t find_tls_ext_offset(uint16_t type,
|
||||||
char *data, size_t size, size_t skip)
|
const char *data, size_t size, size_t skip)
|
||||||
{
|
{
|
||||||
if (size <= (skip + 2)) {
|
if (size <= (skip + 2)) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -102,7 +102,7 @@ size_t find_tls_ext_offset(uint16_t type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t chello_ext_offset(uint16_t type, char *data, size_t size)
|
static size_t chello_ext_offset(uint16_t type, const char *data, size_t size)
|
||||||
{
|
{
|
||||||
if (size < 44) {
|
if (size < 44) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -155,7 +155,7 @@ int change_tls_sni(const char *host, char *buffer, size_t bsize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool is_tls_chello(char *buffer, size_t bsize)
|
bool is_tls_chello(const char *buffer, size_t bsize)
|
||||||
{
|
{
|
||||||
return (bsize > 5 &&
|
return (bsize > 5 &&
|
||||||
ANTOHS(buffer, 0) == 0x1603 &&
|
ANTOHS(buffer, 0) == 0x1603 &&
|
||||||
@ -163,7 +163,7 @@ bool is_tls_chello(char *buffer, size_t bsize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int parse_tls(char *buffer, size_t bsize, char **hs)
|
int parse_tls(const char *buffer, size_t bsize, char **hs)
|
||||||
{
|
{
|
||||||
if (!is_tls_chello(buffer, bsize)) {
|
if (!is_tls_chello(buffer, bsize)) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -178,12 +178,12 @@ int parse_tls(char *buffer, size_t bsize, char **hs)
|
|||||||
if ((sni_offs + 9 + len) > bsize) {
|
if ((sni_offs + 9 + len) > bsize) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*hs = &buffer[sni_offs + 9];
|
*hs = (char *)&buffer[sni_offs + 9];
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool is_http(char *buffer, size_t bsize)
|
bool is_http(const char *buffer, size_t bsize)
|
||||||
{
|
{
|
||||||
if (bsize < 16 || *buffer > 'T' || *buffer < 'C') {
|
if (bsize < 16 || *buffer > 'T' || *buffer < 'C') {
|
||||||
return 0;
|
return 0;
|
||||||
@ -201,10 +201,10 @@ bool is_http(char *buffer, size_t bsize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int parse_http(char *buffer, size_t bsize, char **hs, uint16_t *port)
|
int parse_http(const char *buffer, size_t bsize, char **hs, uint16_t *port)
|
||||||
{
|
{
|
||||||
char *host = buffer, *h_end;
|
const char *host = buffer, *h_end;
|
||||||
char *buff_end = buffer + bsize;
|
const char *buff_end = buffer + bsize;
|
||||||
|
|
||||||
if (!is_http(buffer, bsize)) {
|
if (!is_http(buffer, bsize)) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -218,7 +218,7 @@ int parse_http(char *buffer, size_t bsize, char **hs, uint16_t *port)
|
|||||||
while ((buff_end - host) > 0 && isblank((unsigned char) *host)) {
|
while ((buff_end - host) > 0 && isblank((unsigned char) *host)) {
|
||||||
host++;
|
host++;
|
||||||
}
|
}
|
||||||
char *l_end = memchr(host, '\n', buff_end - host);
|
const char *l_end = memchr(host, '\n', buff_end - host);
|
||||||
if (!l_end) {
|
if (!l_end) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -227,7 +227,7 @@ int parse_http(char *buffer, size_t bsize, char **hs, uint16_t *port)
|
|||||||
if (!(isdigit((unsigned char) *(l_end - 1))))
|
if (!(isdigit((unsigned char) *(l_end - 1))))
|
||||||
h_end = 0;
|
h_end = 0;
|
||||||
else {
|
else {
|
||||||
char *h = host;
|
const char *h = host;
|
||||||
h_end = 0;
|
h_end = 0;
|
||||||
do {
|
do {
|
||||||
h = memchr(h, ':', l_end - h);
|
h = memchr(h, ':', l_end - h);
|
||||||
@ -249,12 +249,12 @@ int parse_http(char *buffer, size_t bsize, char **hs, uint16_t *port)
|
|||||||
return 0;
|
return 0;
|
||||||
*port = i;
|
*port = i;
|
||||||
}
|
}
|
||||||
*hs = host;
|
*hs = (char *)host;
|
||||||
return h_end - host;
|
return h_end - host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int get_http_code(char *b, size_t n)
|
static int get_http_code(const char *b, size_t n)
|
||||||
{
|
{
|
||||||
if (n < 13) return 0;
|
if (n < 13) return 0;
|
||||||
if (strncmp(b, "HTTP/1.", 7)) {
|
if (strncmp(b, "HTTP/1.", 7)) {
|
||||||
@ -272,7 +272,8 @@ int get_http_code(char *b, size_t n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool is_http_redirect(char *req, size_t qn, char *resp, size_t sn)
|
bool is_http_redirect(
|
||||||
|
const char *req, size_t qn, const char *resp, size_t sn)
|
||||||
{
|
{
|
||||||
char *host = 0;
|
char *host = 0;
|
||||||
int len = parse_http(req, qn, &host, 0);
|
int len = parse_http(req, qn, &host, 0);
|
||||||
@ -284,7 +285,7 @@ bool is_http_redirect(char *req, size_t qn, char *resp, size_t sn)
|
|||||||
if (code > 308 || code < 300) {
|
if (code > 308 || code < 300) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
char *location = strncasestr(resp, sn, "\nLocation:", 10);
|
const char *location = strncasestr(resp, sn, "\nLocation:", 10);
|
||||||
if (!location) {
|
if (!location) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -329,7 +330,7 @@ bool is_http_redirect(char *req, size_t qn, char *resp, size_t sn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool neq_tls_sid(char *req, size_t qn, char *resp, size_t sn)
|
bool neq_tls_sid(const char *req, size_t qn, const char *resp, size_t sn)
|
||||||
{
|
{
|
||||||
if (qn < 75 || sn < 75) {
|
if (qn < 75 || sn < 75) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -351,7 +352,7 @@ bool neq_tls_sid(char *req, size_t qn, char *resp, size_t sn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool is_tls_shello(char *buffer, size_t bsize)
|
bool is_tls_shello(const char *buffer, size_t bsize)
|
||||||
{
|
{
|
||||||
return (bsize > 5 &&
|
return (bsize > 5 &&
|
||||||
ANTOHS(buffer, 0) == 0x1603 &&
|
ANTOHS(buffer, 0) == 0x1603 &&
|
||||||
|
16
packets.h
16
packets.h
@ -23,23 +23,21 @@ extern char udp_data[64];
|
|||||||
|
|
||||||
int change_tls_sni(const char *host, char *buffer, size_t bsize);
|
int change_tls_sni(const char *host, char *buffer, size_t bsize);
|
||||||
|
|
||||||
bool is_tls_chello(char *buffer, size_t bsize);
|
bool is_tls_chello(const char *buffer, size_t bsize);
|
||||||
|
|
||||||
int parse_tls(char *buffer, size_t bsize, char **hs);
|
int parse_tls(const char *buffer, size_t bsize, char **hs);
|
||||||
|
|
||||||
bool is_http(char *buffer, size_t bsize);
|
bool is_http(const char *buffer, size_t bsize);
|
||||||
|
|
||||||
int parse_http(char *buffer, size_t bsize, char **hs, uint16_t *port);
|
int parse_http(const char *buffer, size_t bsize, char **hs, uint16_t *port);
|
||||||
|
|
||||||
int mod_http(char *buffer, size_t bsize, int m);
|
int mod_http(char *buffer, size_t bsize, int m);
|
||||||
|
|
||||||
int get_http_code(char *b, size_t n);
|
bool is_http_redirect(const char *req, size_t qn, const char *resp, size_t sn);
|
||||||
|
|
||||||
bool is_http_redirect(char *req, size_t qn, char *resp, size_t sn);
|
bool neq_tls_sid(const char *req, size_t qn, const char *resp, size_t sn);
|
||||||
|
|
||||||
bool neq_tls_sid(char *req, size_t qn, char *resp, size_t sn);
|
bool is_tls_shello(const char *buffer, size_t bsize);
|
||||||
|
|
||||||
bool is_tls_shello(char *buffer, size_t bsize);
|
|
||||||
|
|
||||||
int part_tls(char *buffer, size_t bsize, ssize_t n, long pos);
|
int part_tls(char *buffer, size_t bsize, ssize_t n, long pos);
|
||||||
|
|
||||||
|
46
proxy.c
46
proxy.c
@ -75,7 +75,7 @@ void map_fix(struct sockaddr_ina *addr, char f6)
|
|||||||
|
|
||||||
|
|
||||||
static inline char addr_equ(
|
static inline char addr_equ(
|
||||||
struct sockaddr_ina *a, struct sockaddr_ina *b)
|
const struct sockaddr_ina *a, const struct sockaddr_ina *b)
|
||||||
{
|
{
|
||||||
if (a->sa.sa_family == AF_INET) {
|
if (a->sa.sa_family == AF_INET) {
|
||||||
return
|
return
|
||||||
@ -121,7 +121,7 @@ static inline int nb_socket(int domain, int type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int resolve(char *host, int len,
|
static int resolve(char *host, int len,
|
||||||
struct sockaddr_ina *addr, int type)
|
struct sockaddr_ina *addr, int type)
|
||||||
{
|
{
|
||||||
struct addrinfo hints = {0}, *res = 0;
|
struct addrinfo hints = {0}, *res = 0;
|
||||||
@ -149,7 +149,7 @@ int resolve(char *host, int len,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int auth_socks5(int fd, char *buffer, ssize_t n)
|
static int auth_socks5(int fd, const char *buffer, ssize_t n)
|
||||||
{
|
{
|
||||||
if (n <= 2 || (uint8_t)buffer[1] != (n - 2)) {
|
if (n <= 2 || (uint8_t)buffer[1] != (n - 2)) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -160,8 +160,8 @@ int auth_socks5(int fd, char *buffer, ssize_t n)
|
|||||||
c = S_AUTH_NONE;
|
c = S_AUTH_NONE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buffer[1] = c;
|
uint8_t a[2] = { S_VER5, c };
|
||||||
if (send(fd, buffer, 2, 0) < 0) {
|
if (send(fd, a, sizeof(a), 0) < 0) {
|
||||||
uniperror("send");
|
uniperror("send");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -169,7 +169,7 @@ int auth_socks5(int fd, char *buffer, ssize_t n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int resp_s5_error(int fd, int e)
|
static int resp_s5_error(int fd, int e)
|
||||||
{
|
{
|
||||||
struct s5_rep s5r = {
|
struct s5_rep s5r = {
|
||||||
.ver = 0x05, .code = (uint8_t )e,
|
.ver = 0x05, .code = (uint8_t )e,
|
||||||
@ -179,7 +179,7 @@ int resp_s5_error(int fd, int e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int resp_error(int fd, int e, int flag)
|
static int resp_error(int fd, int e, int flag)
|
||||||
{
|
{
|
||||||
if (flag == FLAG_S4) {
|
if (flag == FLAG_S4) {
|
||||||
struct s4_req s4r = {
|
struct s4_req s4r = {
|
||||||
@ -220,8 +220,8 @@ int resp_error(int fd, int e, int flag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int s4_get_addr(char *buff, size_t n,
|
static int s4_get_addr(const char *buff,
|
||||||
struct sockaddr_ina *dst)
|
size_t n, struct sockaddr_ina *dst)
|
||||||
{
|
{
|
||||||
if (n < sizeof(struct s4_req) + 1) {
|
if (n < sizeof(struct s4_req) + 1) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -257,8 +257,8 @@ int s4_get_addr(char *buff, size_t n,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int s5_get_addr(char *buffer, size_t n,
|
static int s5_get_addr(const char *buffer,
|
||||||
struct sockaddr_ina *addr, int type)
|
size_t n, struct sockaddr_ina *addr, int type)
|
||||||
{
|
{
|
||||||
if (n < S_SIZE_MIN) {
|
if (n < S_SIZE_MIN) {
|
||||||
LOG(LOG_E, "ss: request too small\n");
|
LOG(LOG_E, "ss: request too small\n");
|
||||||
@ -303,8 +303,8 @@ int s5_get_addr(char *buffer, size_t n,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int s5_set_addr(char *buffer, size_t n,
|
static int s5_set_addr(char *buffer, size_t n,
|
||||||
struct sockaddr_ina *addr, char end)
|
const struct sockaddr_ina *addr, char end)
|
||||||
{
|
{
|
||||||
struct s5_req *r = (struct s5_req *)buffer;
|
struct s5_req *r = (struct s5_req *)buffer;
|
||||||
if (n < S_SIZE_I4) {
|
if (n < S_SIZE_I4) {
|
||||||
@ -350,7 +350,7 @@ static int remote_sock(struct sockaddr_ina *dst, int type)
|
|||||||
uniperror("socket");
|
uniperror("socket");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (socket_mod(sfd, &dst->sa) < 0) {
|
if (socket_mod(sfd) < 0) {
|
||||||
close(sfd);
|
close(sfd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -374,7 +374,7 @@ static int remote_sock(struct sockaddr_ina *dst, int type)
|
|||||||
|
|
||||||
|
|
||||||
int create_conn(struct poolhd *pool,
|
int create_conn(struct poolhd *pool,
|
||||||
struct eval *val, struct sockaddr_ina *dst, int next)
|
struct eval *val, const struct sockaddr_ina *dst, int next)
|
||||||
{
|
{
|
||||||
struct sockaddr_ina addr = *dst;
|
struct sockaddr_ina addr = *dst;
|
||||||
|
|
||||||
@ -444,8 +444,8 @@ int create_conn(struct poolhd *pool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int udp_associate(struct poolhd *pool,
|
static int udp_associate(struct poolhd *pool,
|
||||||
struct eval *val, struct sockaddr_ina *dst)
|
struct eval *val, const struct sockaddr_ina *dst)
|
||||||
{
|
{
|
||||||
struct sockaddr_ina addr = *dst;
|
struct sockaddr_ina addr = *dst;
|
||||||
|
|
||||||
@ -563,7 +563,7 @@ static inline int transp_conn(struct poolhd *pool, struct eval *val)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline int on_accept(struct poolhd *pool, struct eval *val)
|
static int on_accept(struct poolhd *pool, const struct eval *val)
|
||||||
{
|
{
|
||||||
struct sockaddr_ina client;
|
struct sockaddr_ina client;
|
||||||
struct eval *rval;
|
struct eval *rval;
|
||||||
@ -619,7 +619,7 @@ static inline int on_accept(struct poolhd *pool, struct eval *val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int on_tunnel(struct poolhd *pool, struct eval *val,
|
static int on_tunnel(struct poolhd *pool, struct eval *val,
|
||||||
char *buffer, size_t bfsize, int etype)
|
char *buffer, size_t bfsize, int etype)
|
||||||
{
|
{
|
||||||
ssize_t n = 0;
|
ssize_t n = 0;
|
||||||
@ -694,7 +694,7 @@ int on_tunnel(struct poolhd *pool, struct eval *val,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int on_udp_tunnel(struct eval *val, char *buffer, size_t bfsize)
|
static int on_udp_tunnel(struct eval *val, char *buffer, size_t bfsize)
|
||||||
{
|
{
|
||||||
char *data = buffer;
|
char *data = buffer;
|
||||||
size_t data_len = bfsize;
|
size_t data_len = bfsize;
|
||||||
@ -887,7 +887,7 @@ static inline int on_connect(struct poolhd *pool, struct eval *val, int e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void close_conn(struct poolhd *pool, struct eval *val)
|
static void close_conn(struct poolhd *pool, struct eval *val)
|
||||||
{
|
{
|
||||||
struct eval *cval = val;
|
struct eval *cval = val;
|
||||||
do {
|
do {
|
||||||
@ -986,7 +986,7 @@ int event_loop(int srvfd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int listen_socket(struct sockaddr_ina *srv)
|
int listen_socket(const struct sockaddr_ina *srv)
|
||||||
{
|
{
|
||||||
int srvfd = nb_socket(srv->sa.sa_family, SOCK_STREAM);
|
int srvfd = nb_socket(srv->sa.sa_family, SOCK_STREAM);
|
||||||
if (srvfd < 0) {
|
if (srvfd < 0) {
|
||||||
@ -1014,7 +1014,7 @@ int listen_socket(struct sockaddr_ina *srv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int run(struct sockaddr_ina *srv)
|
int run(const struct sockaddr_ina *srv)
|
||||||
{
|
{
|
||||||
#ifdef SIGPIPE
|
#ifdef SIGPIPE
|
||||||
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
|
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
|
||||||
|
13
proxy.h
13
proxy.h
@ -106,18 +106,13 @@ enum s4_rep {
|
|||||||
|
|
||||||
void map_fix(struct sockaddr_ina *addr, char f6);
|
void map_fix(struct sockaddr_ina *addr, char f6);
|
||||||
|
|
||||||
int resp_error(int fd, int e, int flag);
|
|
||||||
|
|
||||||
int create_conn(struct poolhd *pool,
|
int create_conn(struct poolhd *pool,
|
||||||
struct eval *val, struct sockaddr_ina *dst, int next);
|
struct eval *val, const struct sockaddr_ina *dst, int next);
|
||||||
|
|
||||||
int on_tunnel(struct poolhd *pool, struct eval *val,
|
int listen_socket(const struct sockaddr_ina *srv);
|
||||||
char *buffer, size_t bfsize, int out);
|
|
||||||
|
|
||||||
int listen_socket(struct sockaddr_ina *srv);
|
|
||||||
|
|
||||||
int event_loop(int srvfd);
|
int event_loop(int srvfd);
|
||||||
|
|
||||||
int run(struct sockaddr_ina *srv);
|
int run(const struct sockaddr_ina *srv);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user