+ def getnextfilename(self,type,chain):
+ dir = sfatables_config + "/"+chain;
+ last_rule_number = 0
+
+ for (root, dirs, files) in os.walk(dir):
+ for file in files:
+ if (file.startswith('sfatables-') and file.endswith(type)):
+ number_str = file.split('-')[1]
+ number = int(number_str)
+ if (number>last_rule_number):
+ last_rule_number = number
+
+ return "sfatables-%d-%s"%(last_rule_number+1,type)
+
+ def call_gen(self, chain, type, dir, options):
+ filename = dir + "/"+options.name+".xml"
+ xmldoc = libxml2.parseFile(filename)
+
+ p = xmldoc.xpathNewContext()
+
+ supplied_arguments = options.arguments
+ for option in supplied_arguments:
+ option_name = option['name']
+ option_value = getattr(options,option_name)
+
+ if (hasattr(options,option_name)):
+ context = p.xpathEval("//rule/argument[name='%s']"%option_name)
+ if (not context):
+ raise Exception('Unknown option %s for match %s'%(option,option['name']))
+ else:
+ # Add the value of option
+ valueNode = libxml2.newNode('value')
+ valueNode.addContent(option_value)
+ context[0].addChild(valueNode)
+
+ filename = self.getnextfilename(type,chain)
+ file_path = sfatables_config + '/' + chain + '/' + filename
+ xmldoc.saveFile(file_path)
+ p.xpathFreeContext()
+ xmldoc.freeDoc()
+