Skip to content

Commit 7bda269

Browse files
fix: wrong src port if packet is processed by NAT
1 parent 67900ed commit 7bda269

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/fakehttp.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
set -eu
2222

23-
VERSION=0.9.0
23+
VERSION=0.9.1
2424

2525
PROGNAME=fakehttp
2626
FAKEHTTPNFQ=fakehttp_nfq
@@ -65,8 +65,9 @@ find_fakehttp_nfq()
6565
}
6666

6767

68-
cleanup_ipt()
68+
cleanup_ipt_090()
6969
{
70+
# Clean up for FakeHTTP v0.9.0
7071
iptables -t mangle -F FAKEHTTP
7172
iptables -t mangle -D PREROUTING -j FAKEHTTP
7273
iptables -t mangle -X FAKEHTTP
@@ -79,17 +80,24 @@ cleanup_ipt()
7980
}
8081

8182

82-
setup_ipt()
83+
cleanup_ipt()
8384
{
84-
iptables -t mangle -N FAKEHTTPMARK
85-
iptables -t mangle -I INPUT -j FAKEHTTPMARK
86-
iptables -t mangle -I FORWARD -j FAKEHTTPMARK
87-
iptables -t mangle -I OUTPUT -j FAKEHTTPMARK
88-
iptables -t mangle -A FAKEHTTPMARK -m mark --mark "$OPT_FWMARK" -j CONNMARK --save-mark
85+
cleanup_ipt_090
86+
87+
iptables -t mangle -F FAKEHTTP
88+
iptables -t mangle -D INPUT -j FAKEHTTP
89+
iptables -t mangle -D FORWARD -j FAKEHTTP
90+
iptables -t mangle -X FAKEHTTP
91+
}
92+
8993

94+
setup_ipt()
95+
{
9096
iptables -t mangle -N FAKEHTTP
91-
iptables -t mangle -I PREROUTING -j FAKEHTTP
97+
iptables -t mangle -I INPUT -j FAKEHTTP
98+
iptables -t mangle -I FORWARD -j FAKEHTTP
9299
# exclude marked packets
100+
iptables -t mangle -A FAKEHTTP -m mark --mark "$OPT_FWMARK" -j CONNMARK --save-mark
93101
iptables -t mangle -A FAKEHTTP -m connmark --mark "$OPT_FWMARK" -j CONNMARK --restore-mark
94102
iptables -t mangle -A FAKEHTTP -m mark --mark "$OPT_FWMARK" -j RETURN
95103
# exclude local IPs

src/fakehttp_nfq.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include <linux/netfilter/nfnetlink_queue.h>
3535
#include <libnetfilter_queue/libnetfilter_queue.h>
3636

37-
#define VERSION "0.9.0"
37+
#define VERSION "0.9.1"
3838

3939
#define E(...) logger(__func__, __FILE__, __LINE__, __VA_ARGS__)
4040

@@ -374,9 +374,9 @@ static int callback(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg,
374374
E("%s:%u <===HTTP(*)=== %s:%u", src_ip, ntohs(tcph->source), dst_ip,
375375
ntohs(tcph->dest));
376376

377-
goto ret_accept_mark;
377+
goto ret_mark_repeat;
378378
} else if (tcp_payload_len > 0) {
379-
goto ret_accept_mark;
379+
goto ret_mark_repeat;
380380
} else if (tcph->ack) {
381381
E("%s:%u ===ACK===> %s:%u", src_ip, ntohs(tcph->source), dst_ip,
382382
ntohs(tcph->dest));
@@ -401,8 +401,8 @@ static int callback(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg,
401401
ret_accept:
402402
return nfq_set_verdict(qh, pkt_id, NF_ACCEPT, 0, NULL);
403403

404-
ret_accept_mark:
405-
return nfq_set_verdict2(qh, pkt_id, NF_ACCEPT, g_fwmark, 0, NULL);
404+
ret_mark_repeat:
405+
return nfq_set_verdict2(qh, pkt_id, NF_REPEAT, g_fwmark, 0, NULL);
406406
}
407407

408408

0 commit comments

Comments
 (0)