mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	Previously, the ethernet device index was used as rt_table index and packet marking id/integer. With eth0 that is sometimes used as link-local interface, the rt_table index `0` would fail as `0` is already defined as a catchall (unspecified). The fwmarking on packets on eth0 with 0x0 would also fail. This fixes the routing issues, by adding 100 to the ethernet device index so the value is a non-zero, for example then the relationship between rt_table index and ethernet would be like: 100 -> Table_eth0 -> eth0 -> fwmark 100 or 0x64 101 -> Table_eth1 -> eth1 -> fwmark 101 or 0x65 102 -> Table_eth2 -> eth2 -> fwmark 102 or 0x66 This would maintain the legacy design of routing based on packet mark and appropriate routing table rules per table/ids. This also fixes a minor NPE issue around listing of snapshots. This also backports fixes to smoketests from master. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
		
			
				
	
	
		
			63 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
| # -- coding: utf-8 --
 | |
| # Licensed to the Apache Software Foundation (ASF) under one
 | |
| # or more contributor license agreements.  See the NOTICE file
 | |
| # distributed with this work for additional information
 | |
| # regarding copyright ownership.  The ASF licenses this file
 | |
| # to you under the Apache License, Version 2.0 (the
 | |
| # "License"); you may not use this file except in compliance
 | |
| # with the License.  You may obtain a copy of the License at
 | |
| #
 | |
| # http://www.apache.org/licenses/LICENSE-2.0
 | |
| #
 | |
| # Unless required by applicable law or agreed to in writing,
 | |
| # software distributed under the License is distributed on an
 | |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 | |
| # KIND, either express or implied.  See the License for the
 | |
| # specific language governing permissions and limitations
 | |
| # under the License.
 | |
| import CsHelper
 | |
| import logging
 | |
| 
 | |
| 
 | |
| class CsRule:
 | |
|     """ Manage iprules
 | |
|     Supported Types:
 | |
|     fwmark
 | |
|     """
 | |
| 
 | |
|     def __init__(self, dev):
 | |
|         self.dev = dev
 | |
|         self.tableNo = 100 + int(dev[3:])
 | |
|         self.table = "Table_%s" % (dev)
 | |
| 
 | |
|     def addRule(self, rule):
 | |
|         if not self.findRule(rule + " lookup " + self.table):
 | |
|             cmd = "ip rule add " + rule + " table " + self.table
 | |
|             CsHelper.execute(cmd)
 | |
|             logging.info("Added rule %s for %s" % (cmd, self.table))
 | |
| 
 | |
|     def findRule(self, rule):
 | |
|         for i in CsHelper.execute("ip rule show"):
 | |
|             if rule in i.strip():
 | |
|                 return True
 | |
|         return False
 | |
| 
 | |
|     def addMark(self):
 | |
|         if not self.findMark():
 | |
|             cmd = "ip rule add fwmark %s table %s" % (self.tableNo, self.table)
 | |
|             CsHelper.execute(cmd)
 | |
|             logging.info("Added fwmark rule for %s" % (self.table))
 | |
| 
 | |
|     def delMark(self):
 | |
|         if self.findMark():
 | |
|             cmd = "ip rule delete fwmark %s table %s" % (self.tableNo, self.table)
 | |
|             CsHelper.execute(cmd)
 | |
|             logging.info("Deleting fwmark rule for %s" % (self.table))
 | |
| 
 | |
|     def findMark(self):
 | |
|         srch = "from all fwmark %s lookup %s" % (hex(self.tableNo), self.table)
 | |
|         for i in CsHelper.execute("ip rule show"):
 | |
|             if srch in i.strip():
 | |
|                 return True
 | |
|         return False
 |