Exemple #1
0
def startCaptureToFile(host, name, iface, filter=""):
	assert name, "Name not given"
	assert ifaceutil.interfaceExists(host, iface), "Interface does not exist"
	assert _checkSyntax(host, iface, filter), "Syntax error: tcpdump -i %s %s" % (iface, filter)
	rdir = _remoteDir(name) 
	fileutil.mkdir(host, rdir)
	ifaceutil.ifup(host, iface)
	_tcpdump(host, "-i %(iface)s -n -C 10 -w %(rdir)s/capture -U -W 5 -s0 %(filter)s >/dev/null 2>&1 </dev/null & echo $! > %(rdir)s.file.pid" % {"iface": util.escape(iface), "rdir": rdir, "filter": util.escape(filter) })		
Exemple #2
0
def _startDummyCapture(host):
	# Due to some weird kernel optimization bridges get sometimes skipped
	# and the link emulation will not work.
	# Using the pcap interface seams to prevent this issue
	if not ifaceutil.bridgeExists(host, "dummy"):
		ifaceutil.bridgeCreate(host, "dummy")
	ifaceutil.ifup(host, "dummy")
	if not tcpdump.captureToFileRunning(host, "_dummy"):
		tcpdump.startCaptureToFile(host, "_dummy", "dummy")
Exemple #3
0
def _startEndpoint(endpoint):
	assert getState(endpoint) == generic.State.PREPARED
	host = endpoint.getHost()
	assert host
	assert process.portFree(host, endpoint.getPort())
	iface = _tincName(endpoint)
	host.execute("tincd --net=%s" % iface )
	util.waitFor(lambda :ifaceutil.interfaceExists(host, iface))
	assert ifaceutil.interfaceExists(host, iface), "Tinc deamon did not start"
	ifaceutil.ifup(host, iface)
Exemple #4
0
def startCaptureViaNet(host, name, port, iface, filter=""):
	assert name, "Name not given"
	assert port, "Port not given"
	assert ifaceutil.interfaceExists(host, iface), "Interface does not exist"
	assert process.portFree(host, port), "Port already in use"
	assert _checkSyntax(host, iface, filter), "Syntax error: tcpdump -i %s %s" % (iface, filter)
	rdir = _remoteDir(name) 
	fileutil.mkdir(host, rdir)
	ifaceutil.ifup(host, iface)
	host.execute("tcpserver -qHRl 0 0 %(port)d tcpdump -i %(iface)s -nUw - '%(filter)s' >/dev/null 2>&1 </dev/null & echo $! > %(rdir)s.net.pid" % {"iface": util.escape(iface), "rdir": rdir, "filter": util.escape(filter), "port": port })
	assert not process.portFree(host, port)
Exemple #5
0
def _connectEndpoint(endpoint, mode):
	host = endpoint.getHost()
	assert host
	bridge = endpoint.getBridge()
	assert bridge
	if not ifaceutil.bridgeExists(host, bridge):
		ifaceutil.bridgeCreate(host, bridge)
	if mode == Mode.ROUTER:
		_setupRouting(endpoint)
	else:
		ifaceutil.ifup(host, bridge)
		ifaceutil.bridgeConnect(host, bridge, _tincName(endpoint))
Exemple #6
0
def _startEndpoint(endpoint):
	state = getState(endpoint)
	assert state != generic.State.CREATED
	if state == generic.State.STARTED:
		_stopEndpoint(endpoint)
	host = endpoint.getHost()
	assert host
	if not process.portFree(host, endpoint.getPort()):
		process.killPortUser(host, endpoint.getPort())
	iface = _tincName(endpoint)
	host.execute("tincd --net=%s" % iface )
	util.waitFor(lambda :ifaceutil.interfaceExists(host, iface))
	assert ifaceutil.interfaceExists(host, iface), "Tinc deamon did not start"
	ifaceutil.ifup(host, iface)
Exemple #7
0
def _setupRouting(endpoint):
	host = endpoint.getHost()
	assert host
	bridge = endpoint.getBridge()
	assert bridge
	id = endpoint.getId()
	assert id
	assert ifaceutil.bridgeExists(host, bridge)
	tincname = _tincName(endpoint)
	assert ifaceutil.interfaceExists(host, tincname)
	assert not ifaceutil.interfaceBridge(host, tincname)
	#enable ip forwarding
	host.execute ("sysctl -q -w net.ipv6.conf.all.forwarding=1");
	host.execute ("sysctl -q -w net.ipv4.conf.all.forwarding=1");
	#add gateway addresses
	for gw in endpoint.getGateways():
		ifaceutil.addAddress(host, bridge, gw)
	#set bridge up
	ifaceutil.ifup(host, bridge)
	ifaceutil.connectInterfaces(host, bridge, tincname, id, endpoint.getGateways())
Exemple #8
0
def _setupRouting(endpoint):
	host = endpoint.getHost()
	assert host
	bridge = endpoint.getBridge()
	assert bridge
	id = endpoint.getId()
	assert id
	assert ifaceutil.bridgeExists(host, bridge)
	tincname = _tincName(endpoint)
	assert ifaceutil.interfaceExists(host, tincname)
	assert not ifaceutil.interfaceBridge(host, tincname)
	#enable ip forwarding
	host.execute ("sysctl -q -w net.ipv6.conf.all.forwarding=1");
	host.execute ("sysctl -q -w net.ipv4.conf.all.forwarding=1");
	#add gateway addresses
	for gw in endpoint.getGateways():
		ifaceutil.addAddress(host, bridge, gw)
	#set bridge up
	ifaceutil.ifup(host, bridge)
	ifaceutil.connectInterfaces(host, bridge, tincname, id, endpoint.getGateways())
	for gw in endpoint.getGateways():
		ip = gw.split("/")[0]
		util.waitFor(lambda :ifaceutil.reachable(host, ip, iface=bridge))
		assert ifaceutil.reachable(host, ip, iface=bridge), "Cannot reach %s in interface %s" % (ip, bridge)
Exemple #9
0
def _checkSyntax(host, iface, filter):
	ifaceutil.ifup(host, iface)
	return _tcpdump(host, "-i %s -d %s >/dev/null 2>&1; echo $?" % (util.escape(iface), util.escape(filter))).strip() == "0"
Exemple #10
0
def _checkSyntax(host, iface, filter):
    ifaceutil.ifup(host, iface)
    return _tcpdump(host, "-i %s -d '%s' >/dev/null 2>&1; echo $?" % (iface, filter)).strip() == "0"
Exemple #11
0
def _checkSyntax(host, iface="lo", filter=""):
	if iface != "lo":
		ifaceutil.ifup(host, iface)
	return _tcpdump(host, "-i %s -d %s >/dev/null; echo $?" % (util.escape(iface), util.escape(filter))).strip() == "0"