Skip to content

Commit 623e7d9

Browse files
author
Naredula Janardhana Reddy
committed
Bug 13964:
Summary of changes: Added Hairpin Nat. - defined Harpin NAT function. - Called Hairpin NAT while adding/deleting port forwading and Static NAT rules. - added rules in IPtables config file, this will be iniated during bootup to forward New/established connectons from eth0 to eth0.
1 parent 09591d6 commit 623e7d9

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎patches/systemvm/debian/config/etc/iptables/iptables-router‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ COMMIT
2222
-A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
2323
-A FORWARD -i eth0 -o eth2 -j ACCEPT
2424
-A FORWARD -i eth2 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
25+
-A FORWARD -i eth0 -o eth0 -m state --state NEW -j ACCEPT
26+
-A FORWARD -i eth0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
2527
COMMIT
2628
*mangle
2729
:PREROUTING ACCEPT [0:0]

‎patches/systemvm/debian/config/root/firewall.sh‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ ip_to_dev() {
4848
return 1
4949
}
5050

51+
doHairpinNat () {
52+
local vrGuestIPNetwork=$(sudo ip addr show dev eth0 | grep inet | grep eth0 | awk '{print $2}' )
53+
local vrGuestIP=$(echo $vrGuestIPNetwork | awk -F'/' '{print $1}')
54+
55+
local publicIp=$1
56+
local prot=$2
57+
local port=$3
58+
local guestVmIp=$4
59+
local guestPort=$(echo $5 | sed 's/:/-/')
60+
local op=$6
61+
logger -t cloud "$(basename $0): create HairPin entry : public ip=$publicIp \
62+
instance ip=$guestVmIp proto=$proto portRange=$guestPort op=$op"
63+
64+
(sudo iptables -t nat $op PREROUTING -d $publicIp -i eth0 -p $prot --dport $port -j DNAT --to-destination $guestVmIp:$guestPort &>> $OUTFILE || [ "$op" == "-D" ]) &&
65+
(sudo iptables -t nat $op POSTROUTING -s $vrGuestIPNetwork -p $prot --dport $port -d $guestVmIp -j SNAT -o eth0 --to-source $vrGuestIP &>> $OUTFILE || [ "$op" == "-D" ])
66+
}
5167

5268
#Port (address translation) forwarding for tcp or udp
5369
tcp_or_udp_entry() {
@@ -78,6 +94,7 @@ tcp_or_udp_entry() {
7894
--destination-port $port -j MARK --set-mark $tableNo &>> $OUTFILE || [ "$op" == "-D" ]) &&
7995
(sudo iptables -t mangle $op PREROUTING --proto $proto -i $dev -d $publicIp \
8096
--destination-port $port -m state --state NEW -j CONNMARK --save-mark &>> $OUTFILE || [ "$op" == "-D" ]) &&
97+
(doHairpinNat $publicIp $proto $port $instIp $dport0 $op) &&
8198
(sudo iptables -t nat $op OUTPUT --proto $proto -d $publicIp \
8299
--destination-port $port -j DNAT \
83100
--to-destination $instIp:$dport &>> $OUTFILE || [ "$op" == "-D" ]) &&
@@ -141,6 +158,7 @@ one_to_one_fw_entry() {
141158
(sudo iptables -t nat $op PREROUTING -i $dev -d $publicIp --proto $proto \
142159
--destination-port $portRange -j DNAT \
143160
--to-destination $instIp &>> $OUTFILE || [ "$op" == "-D" ]) &&
161+
(doHairpinNat $publicIp $proto $portRange $instIp $portRange $op) &&
144162
(sudo iptables $op FORWARD -i $dev -o eth0 -d $instIp --proto $proto \
145163
--destination-port $portRange -m state \
146164
--state NEW -j ACCEPT &>> $OUTFILE )

0 commit comments

Comments
 (0)