mirror of
https://github.com/bol-van/zapret.git
synced 2025-04-19 05:22:58 +03:00
nfqws : separate packet mod functions
This commit is contained in:
parent
fd2589ce02
commit
eba19570d4
78
nfq/nfqws.c
78
nfq/nfqws.c
@ -251,45 +251,22 @@ struct cbdata_s
|
||||
char hostspell[4];
|
||||
};
|
||||
|
||||
// ret: false - not modified, true - modified
|
||||
bool processPacketData(unsigned char *data,int len,const struct cbdata_s *cbdata)
|
||||
|
||||
static const char *http_methods[] = { "GET /","POST /","HEAD /","OPTIONS /","PUT /","DELETE /","CONNECT /","TRACE /",NULL };
|
||||
// data/len points to data payload
|
||||
bool modify_tcp_packet(unsigned char *data,int len,struct tcphdr *tcphdr,const struct cbdata_s *cbdata)
|
||||
{
|
||||
struct iphdr *iphdr = NULL;
|
||||
struct ip6_hdr *ip6hdr = NULL;
|
||||
struct tcphdr *tcphdr = NULL;
|
||||
const char **method;
|
||||
size_t method_len = 0;
|
||||
unsigned char *phost,*pua;
|
||||
int len_tcp;
|
||||
bool bRet = false;
|
||||
uint8_t proto;
|
||||
|
||||
if (proto_check_ipv4(data,len))
|
||||
{
|
||||
iphdr = (struct iphdr *) data;
|
||||
proto = iphdr->protocol;
|
||||
proto_skip_ipv4(&data,&len);
|
||||
}
|
||||
else if (proto_check_ipv6(data,len))
|
||||
{
|
||||
ip6hdr = (struct ip6_hdr *) data;
|
||||
proto_skip_ipv6(&data,&len,&proto);
|
||||
}
|
||||
else
|
||||
{
|
||||
// not ipv6 and not ipv4
|
||||
return false;
|
||||
}
|
||||
|
||||
if (proto==IPPROTO_TCP && proto_check_tcp(data,len))
|
||||
{
|
||||
tcphdr = (struct tcphdr *) data;
|
||||
len_tcp = len;
|
||||
proto_skip_tcp(&data,&len);
|
||||
//printf("got TCP packet. payload_len=%d\n",len);
|
||||
if (cbdata->wsize && tcp_synack_segment(tcphdr))
|
||||
{
|
||||
tcp_rewrite_winsize(tcphdr,(uint16_t)cbdata->wsize);
|
||||
bRet = true;
|
||||
}
|
||||
|
||||
if ((cbdata->hostcase || cbdata->hostnospace) && (phost = find_bin(data,len,"\r\nHost: ",8)))
|
||||
{
|
||||
if (cbdata->hostcase)
|
||||
@ -314,7 +291,45 @@ bool processPacketData(unsigned char *data,int len,const struct cbdata_s *cbdata
|
||||
bRet = true;
|
||||
}
|
||||
}
|
||||
if (bRet)
|
||||
return bRet;
|
||||
}
|
||||
|
||||
// ret: false - not modified, true - modified
|
||||
bool processPacketData(unsigned char *data,int len,const struct cbdata_s *cbdata)
|
||||
{
|
||||
struct iphdr *iphdr = NULL;
|
||||
struct ip6_hdr *ip6hdr = NULL;
|
||||
struct tcphdr *tcphdr = NULL;
|
||||
int len_tcp;
|
||||
bool bRet = false;
|
||||
uint8_t proto;
|
||||
|
||||
if (proto_check_ipv4(data,len))
|
||||
{
|
||||
iphdr = (struct iphdr *) data;
|
||||
proto = iphdr->protocol;
|
||||
proto_skip_ipv4(&data,&len);
|
||||
}
|
||||
else if (proto_check_ipv6(data,len))
|
||||
{
|
||||
ip6hdr = (struct ip6_hdr *) data;
|
||||
proto_skip_ipv6(&data,&len,&proto);
|
||||
}
|
||||
else
|
||||
{
|
||||
// not ipv6 and not ipv4
|
||||
return false;
|
||||
}
|
||||
|
||||
if (proto==IPPROTO_TCP && proto_check_tcp(data,len))
|
||||
{
|
||||
|
||||
tcphdr = (struct tcphdr *) data;
|
||||
len_tcp = len;
|
||||
proto_skip_tcp(&data,&len);
|
||||
//printf("got TCP packet. payload_len=%d\n",len);
|
||||
|
||||
if (bRet = modify_tcp_packet(data,len,tcphdr,cbdata))
|
||||
{
|
||||
if (iphdr)
|
||||
tcp_fix_checksum(tcphdr,len_tcp,iphdr->saddr,iphdr->daddr);
|
||||
@ -509,7 +524,6 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (daemon) daemonize();
|
||||
|
||||
h = NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user