mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
disabled force socket buf size by default
This commit is contained in:
parent
c8113ccb06
commit
934a65e7bf
37
common.cpp
37
common.cpp
@ -15,6 +15,7 @@ int about_to_exit=0;
|
||||
raw_mode_t raw_mode=mode_faketcp;
|
||||
unordered_map<int, const char*> raw_mode_tostring = {{mode_faketcp, "faketcp"}, {mode_udp, "udp"}, {mode_icmp, "icmp"}};
|
||||
int socket_buf_size=1024*1024;
|
||||
int force_socket_buf=0;
|
||||
|
||||
static int random_number_fd=-1;
|
||||
string iptables_pattern="";
|
||||
@ -328,16 +329,32 @@ unsigned short csum(const unsigned short *ptr,int nbytes) {//works both for big
|
||||
|
||||
int set_buf_size(int fd)
|
||||
{
|
||||
if(setsockopt(fd, SOL_SOCKET, SO_SNDBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_SNDBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
myexit(1);
|
||||
}
|
||||
if(setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_RCVBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
myexit(1);
|
||||
}
|
||||
if(force_socket_buf)
|
||||
{
|
||||
if(setsockopt(fd, SOL_SOCKET, SO_SNDBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_SNDBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
myexit(1);
|
||||
}
|
||||
if(setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_RCVBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
myexit(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_SNDBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
myexit(1);
|
||||
}
|
||||
if(setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_RCVBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
myexit(1);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
1
common.h
1
common.h
@ -107,6 +107,7 @@ enum program_mode_t {unset_mode=0,client_mode,server_mode};
|
||||
extern program_mode_t program_mode;
|
||||
extern unordered_map<int, const char*> raw_mode_tostring ;
|
||||
extern int socket_buf_size;
|
||||
extern int force_socket_buf;
|
||||
|
||||
typedef u32_t id_t;
|
||||
|
||||
|
6
main.cpp
6
main.cpp
@ -2615,6 +2615,7 @@ void print_help()
|
||||
printf(" unless you suspect there is a bug\n");
|
||||
// printf("\n");
|
||||
printf(" --sock-buf <number> buf size for socket,>=10 and <=10240,unit:kbyte,default:1024\n");
|
||||
printf(" --force-sock-buf bypass system limitation while setting sock-buf\n");
|
||||
printf(" --seqmode <number> seq increase mode for faketcp:\n");
|
||||
printf(" 0:dont increase\n");
|
||||
printf(" 1:increase every packet(default)\n");
|
||||
@ -2748,6 +2749,7 @@ void process_arg(int argc, char *argv[]) //process all options
|
||||
{"sock-buf", required_argument, 0, 1},
|
||||
{"seq-mode", required_argument, 0, 1},
|
||||
{"conf-file", required_argument, 0, 1},
|
||||
{"force-sock-buf", no_argument, 0, 1},
|
||||
{NULL, 0, 0, 0}
|
||||
};
|
||||
|
||||
@ -3032,6 +3034,10 @@ void process_arg(int argc, char *argv[]) //process all options
|
||||
{
|
||||
//enable_log_position=1;
|
||||
}
|
||||
else if(strcmp(long_options[option_index].name,"force-sock-buf")==0)
|
||||
{
|
||||
force_socket_buf=1;
|
||||
}
|
||||
else if(strcmp(long_options[option_index].name,"disable-bpf")==0)
|
||||
{
|
||||
disable_bpf_filter=1;
|
||||
|
42
network.cpp
42
network.cpp
@ -199,11 +199,22 @@ int init_raw_socket()
|
||||
|
||||
}
|
||||
|
||||
if(setsockopt(raw_send_fd, SOL_SOCKET, SO_SNDBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_SNDBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
myexit(1);
|
||||
}
|
||||
if(force_socket_buf)
|
||||
{
|
||||
if(setsockopt(raw_send_fd, SOL_SOCKET, SO_SNDBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_SNDBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
myexit(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(setsockopt(raw_send_fd, SOL_SOCKET, SO_SNDBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_SNDBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
myexit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -217,11 +228,22 @@ int init_raw_socket()
|
||||
myexit(1);
|
||||
}
|
||||
|
||||
if(setsockopt(raw_recv_fd, SOL_SOCKET, SO_RCVBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_RCVBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
myexit(1);
|
||||
}
|
||||
if(force_socket_buf)
|
||||
{
|
||||
if(setsockopt(raw_recv_fd, SOL_SOCKET, SO_RCVBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_RCVBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
myexit(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(setsockopt(raw_recv_fd, SOL_SOCKET, SO_RCVBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||
{
|
||||
mylog(log_fatal,"SO_RCVBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||
myexit(1);
|
||||
}
|
||||
}
|
||||
|
||||
//IP_HDRINCL to tell the kernel that headers are included in the packet
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user