Skip to content

router: fix routing table for marked packets #2579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions systemvm/debian/opt/cloud/bin/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,8 @@ def processStaticNatRule(self, rule):
"-I PREROUTING -s %s/32 -m state --state NEW -j CONNMARK --save-mark --nfmask 0xffffffff --ctmask 0xffffffff" %
rule["internal_ip"]])
self.fw.append(["mangle", "",
"-I PREROUTING -s %s/32 -m state --state NEW -j MARK --set-xmark 0x%s/0xffffffff" %
(rule["internal_ip"], device[len("eth"):])])
"-I PREROUTING -s %s/32 -m state --state NEW -j MARK --set-xmark %s/0xffffffff" %
(rule["internal_ip"], hex(int(device[len("eth"):])))])
self.fw.append(["nat", "front",
"-A PREROUTING -d %s/32 -j DNAT --to-destination %s" % (rule["public_ip"], rule["internal_ip"])])
self.fw.append(["nat", "front",
Expand Down
12 changes: 9 additions & 3 deletions systemvm/debian/opt/cloud/bin/cs/CsAddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,7 @@ def post_configure(self, address):

interfaces = [CsInterface(address, self.config)]
CsHelper.reconfigure_interfaces(self.cl, interfaces)
if not self.config.is_vpc() and (self.get_type() in ['public']):
self.set_mark()
if self.config.is_vpc() and (self.get_type() in ['public']):
if self.get_type() in ['public']:
self.set_mark()

if 'gateway' in self.address:
Expand Down Expand Up @@ -363,6 +361,7 @@ def setup_router_control(self):
def fw_router(self):
if self.config.is_vpc():
return

self.fw.append(["mangle", "front", "-A PREROUTING " +
"-m state --state RELATED,ESTABLISHED " +
"-j CONNMARK --restore-mark --nfmask 0xffffffff --ctmask 0xffffffff"])
Expand Down Expand Up @@ -534,6 +533,13 @@ def post_config_change(self, method):
if self.config.is_vpc():
if self.get_type() in ["public"] and "gateway" in self.address and self.address["gateway"] != "None":
route.add_route(self.dev, self.address["gateway"])
for inf, addresses in self.config.address().dbag.iteritems():
if not inf.startswith("eth"):
continue
for address in addresses:
if "nw_type" in address and address["nw_type"] == "guest":
route.add_network_route(self.dev, str(address["network"]))

route.add_network_route(self.dev, str(self.address["network"]))

CsHelper.execute("sudo ip route flush cache")
Expand Down
7 changes: 5 additions & 2 deletions systemvm/debian/opt/cloud/bin/cs/CsRoute.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ def add_network_route(self, dev, address):
table = self.get_tablename(dev)
logging.info("Adding route: dev " + dev + " table: " +
table + " network: " + address + " if not present")
cmd = "dev %s table %s throw %s proto static" % (dev, table, address)
cmd = "throw %s table %s proto static" % (address, table)
self.set_route(cmd)

def set_route(self, cmd, method="add"):
""" Add a route if it is not already defined """
found = False
for i in CsHelper.execute("ip route show " + cmd):
search = cmd
if "throw" in search:
search = "type " + search
for i in CsHelper.execute("ip route show " + search):
found = True
if not found and method == "add":
logging.info("Add " + cmd)
Expand Down