Example #1
0
	def _linux_addLocal(self, cidr):
		""" Add a local route redirect for the given CIDR """
		cmd = ["ip", "route", "add", "table", "local", "local", "%s/%d" % (cidr.basestr, cidr.maskbits),
				 "dev", "lo", "proto", "kernel"]
		run(cmd)
		cmd[2] = "del"
		self.localremovecmds[cidr] = cmd
Example #2
0
	def delFake(self, nodename, cidr):
		""" Remove the assigned fake range of addresses (cidr) from node """
		self.fakehash.setdefault(nodename, set()).discard(cidr)
		if cidr in self.localremovecmds:
			run(self.localremovecmds.pop(cidr))
		if cidr in self.routeremovecmds:
			run(self.routeremovecmds.pop(cidr))
Example #3
0
	def clear(self):
		"""
			Clear all of the routes that we added to this node
		"""
		for cmd in self.localremovecmds.itervalues() + self.routeremovecmds.itervalues():
			run(cmd)
		self.localremovecmds = dict()
		self.routeremovecmds = dict()
Example #4
0
	def addCounter(self, rulenum, **kwargs):
		cmd = ["/sbin/ipfw", "add", str(rulenum), "count", "ip", "from", "any", "to", "any"]
		if 'input' in kwargs:
			cmd.extend(["in", "via", kwargs['input']])
		else:
			cmd.extend(["out", "via", kwargs['output']])
		if 'marker' in kwargs:
			cmd.extend(["ipprecedence", str(kwargs['marker'])])
		run(cmd)
Example #5
0
	def delete(self, rulenum):
		"""
			Netfilter doesn't have 'global' rulenums so we need to remember the command we
			used to add the filter and use the same to delete it.
		"""
		try:
			run(self.removelist.pop(rulenum))
		except KeyError:
			log.error("Tried to remove rule %d, but it doesn't exist in list" % (rulenum))
Example #6
0
	def delRoute(self, cidr):
		"""
			Checks to see if this is a route 'we' added in which case we use the cached
			remove command for clear(), otherwise we call the hidden delRoute
		"""
		for c in self.routeremovecmds:
			if c.equals(cidr):
				run(self.routeremovecmds[c])
				return
		self._delRoute(cidr)
Example #7
0
    def delete(self, rulenum):
        """
			Netfilter doesn't have 'global' rulenums so we need to remember the command we
			used to add the filter and use the same to delete it.
		"""
        try:
            run(self.removelist.pop(rulenum))
        except KeyError:
            log.error("Tried to remove rule %d, but it doesn't exist in list" %
                      (rulenum))
Example #8
0
	def _windows_addDirect(self, cidr, intf):
		""" Add a route for a CIDR that is directly connected to an interface """
		ip4if = None
		for i in testbed.getInterfaceList():
			if i.name == intf:
				ip4if = i.ip
		cmd = ["/cygdrive/c/WINDOWS/system32/route", "add", cidr.basestr, "mask", cidr.maskstr, ip4if]
		run(cmd)
		cmd[1] = "delete"
		self.routeremovecmds[cidr] = cmd[0:-1]
Example #9
0
 def addCounter(self, rulenum, **kwargs):
     cmd = [
         "/sbin/ipfw", "add",
         str(rulenum), "count", "ip", "from", "any", "to", "any"
     ]
     if 'input' in kwargs:
         cmd.extend(["in", "via", kwargs['input']])
     else:
         cmd.extend(["out", "via", kwargs['output']])
     if 'marker' in kwargs:
         cmd.extend(["ipprecedence", str(kwargs['marker'])])
     run(cmd)
Example #10
0
 def doAndLogCommand(self, command, name):
     '''Run the given command and dump stdout and stderr to the log directory.'''
     # TODO: replace hardcoded file name with magi.util.config.MAGILOG 
     filename = os.path.join(config.getLogDir(), '%s-%s.log' % (self.TYPE, name))
     try:
         with open(filename, 'a') as fd: 
             return run(command, stdout=fd, stderr=subprocess.STDOUT, shell=True) == 0
     except Exception, e:
         self.log.warning('%s failed %s: %s. Check %s for details.', self.TYPE, name, e, filename)
         return False
Example #11
0
 def delete(self, rulenum):
     """ ipfw lets us delete using just the rulenum we provided """
     run(["/sbin/ipfw", "delete", str(rulenum)])
Example #12
0
	def _add(self, cmd, rulenum):
		run(cmd)
		cmd[1] = "-D"
		self.removelist[rulenum] = cmd
Example #13
0
	def _bsd_addRoute(self, cidr, nexthop):
		""" Add a route given the cidr and nexthop """
		cmd = ["route", "add", "%s/%s" % (cidr.basestr, cidr.maskbits), nexthop]
		run(cmd)
		cmd[1] = "delete"
		self.routeremovecmds[cidr] = cmd
Example #14
0
	def blockInput(self, rulenum, **kwargs):
		run(["/sbin/ipfw", "add", str(rulenum), "drop"] + self._filterargs(**kwargs))
Example #15
0
	def _bsd_delRoute(self, cidr):
		run(["route", "delete", "%s/%s" % (cidr.basestr, cidr.maskbits)])
Example #16
0
	def _bsd_addDirect(self, cidr, intf):
		""" Add a route for a CIDR that is directly connected to an interface """
		cmd = ["route", "add", "%s/%s" % (cidr.basestr, cidr.maskbits), "-interface", intf]
		run(cmd)
		cmd[1] = "delete"
		self.routeremovecmds[cidr] = cmd
Example #17
0
	def delete(self, rulenum):
		""" ipfw lets us delete using just the rulenum we provided """
		run(["/sbin/ipfw", "delete", str(rulenum)])
Example #18
0
	def _linux_addRoute(self, cidr, nexthop):
		""" Add a route given the cidr and nexthop """
		cmd = ["route", "add", "-net", cidr.basestr, "netmask", cidr.maskstr, "gw", nexthop]
		run(cmd)
		cmd[1] = "del"
		self.routeremovecmds[cidr] = cmd
Example #19
0
 def _add(self, cmd, rulenum):
     run(cmd)
     cmd[1] = "-D"
     self.removelist[rulenum] = cmd
Example #20
0
	def _windows_delRoute(self, cidr):
		""" Delete a route given the cidr and nexthop """
		run(["/cygdrive/c/WINDOWS/system32/route", "delete", cidr.basestr, "mask", cidr.maskstr])
Example #21
0
	def enableModule(self, module):
		cmd = "a2enmod %s" %module
		run(cmd, close_fds=True)
		log.info("Module '%s' enabled" %module)
Example #22
0
	def runserver(self):
		""" subclass implementation """
		run("apache2ctl start", close_fds=True)
		log.info('Apache started.')
		return True
Example #23
0
	def _linux_delRoute(self, cidr):
		run(["route", "del", "-net", cidr.basestr, "netmask", cidr.maskstr])
Example #24
0
	def _linux_addDirect(self, cidr, intf):
		""" Add a route for a CIDR that is directly connected to an interface """
		cmd = ["route", "add", "-net", cidr.basestr, "netmask", cidr.maskstr, "dev", intf]
		run(cmd)
		cmd[1] = "del"
		self.routeremovecmds[cidr] = cmd
Example #25
0
	def terminateserver(self):
		""" subclass implementation """
		run("apache2ctl stop", close_fds=True)
		log.info('Apache stopped.')
		return True
Example #26
0
 def blockInput(self, rulenum, **kwargs):
     run(["/sbin/ipfw", "add", str(rulenum), "drop"] +
         self._filterargs(**kwargs))
Example #27
0
	def enableSite(self, site):
		cmd = "a2ensite %s" %site
		run(cmd, close_fds=True)
		log.info("Site '%s' enabled" %site)
Example #28
0
	def _windows_addRoute(self, cidr, nexthop):
		""" Add a route given the cidr and nexthop """
		cmd = ["/cygdrive/c/WINDOWS/system32/route", "add", cidr.basestr, "mask", cidr.maskstr, nexthop]
		run(cmd)
		cmd[1] = "delete"
		self.routeremovecmds[cidr] = cmd[0:-1]