Skip to content

Commit 2fad87d

Browse files
Make the routers persistent
- After configuration save the ipdated in files * /etc/iptables/router_rules.v4 and /etc/iptables/router_rules.v6 * Reload the configuration on reboot via the /etc/rc.local using iptables-restore
1 parent e81161d commit 2fad87d

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

systemvm/patches/debian/config/etc/rc.local

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,16 @@ python /opt/cloud/bin/baremetal-vr.py &
4646

4747
date > /var/cache/cloud/boot_up_done
4848
logger -t cloud "Boot up process done"
49+
50+
#Restore the persistent iptables nat, rules and filters for IPv4 and IPv6 if they exist
51+
ipv4="/etc/iptables/router_rules.v4"
52+
if [ -e $ipv4 ]
53+
then
54+
iptables-restore < $ipv4
55+
fi
56+
57+
ipv6="/etc/iptables/router_rules.v6"
58+
if [ -e $ipv6 ]
59+
then
60+
iptables-restore < $ipv6
61+
fi

systemvm/patches/debian/config/opt/cloud/bin/configure.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,10 @@ def main(argv):
676676

677677
mon = CsMonitor("monitorservice", config)
678678
mon.process()
679-
679+
680+
#Save iptables configuration - will be loaded on reboot by the iptables-restore that is configured on /etc/rc.local
681+
CsHelper.save_iptables("iptables-save", "/etc/iptables/router_rules.v4")
682+
CsHelper.save_iptables("ip6tables-save", "/etc/iptables/router_rules.v6")
683+
680684
if __name__ == "__main__":
681685
main(sys.argv)

systemvm/patches/debian/config/opt/cloud/bin/cs/CsHelper.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818
""" General helper functions
19-
for use in the configuation process
19+
for use in the configuration process
2020
2121
"""
2222
import subprocess
@@ -27,7 +27,6 @@
2727
from netaddr import *
2828
from pprint import pprint
2929

30-
3130
def is_mounted(name):
3231
for i in execute("mount"):
3332
vals = i.lstrip().split()
@@ -163,6 +162,19 @@ def execute(command):
163162
return result.splitlines()
164163

165164

165+
def save_iptables(command, iptables_file):
166+
""" Execute command """
167+
logging.debug("Saving iptables for %s" % command)
168+
169+
result = execute(command)
170+
fIptables = open(iptables_file, "w+")
171+
172+
for line in result:
173+
fIptables.write(line)
174+
fIptables.write("\n")
175+
fIptables.close()
176+
177+
166178
def execute2(command):
167179
""" Execute command """
168180
logging.debug("Executing %s" % command)

0 commit comments

Comments
 (0)