-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinterfacesetup.py
77 lines (64 loc) · 2.58 KB
/
interfacesetup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#
# A plugin to setup capture interfaces
# The plugin is off by default. To enable it, add "interfacesetup.enabled=1" to broctl.cfg.
#
try:
import ZeekControl.plugin as PluginBase
except ImportError:
import BroControl.plugin as PluginBase
def extract_interfaces(intf):
#Handle interfaces that look like multi:p1p1,p1p2
if intf.startswith("pf_ring::multi:"):
return intf.replace("pf_ring::multi:", "").split(",")
#Handle interfaces that look like myricom::p1p1:4
if '::' in intf:
intf = intf.split('::')[1]
if ':' in intf:
intf = intf.split(':')[0]
return intf.split(',')
class InterfaceSetupPlugin(PluginBase.Plugin):
def __init__(self):
super(InterfaceSetupPlugin, self).__init__(apiversion=1)
def name(self):
return "InterfaceSetupPlugin"
def prefix(self):
return "interfacesetup"
def pluginVersion(self):
return 1
def init(self):
if self.getOption("enabled") == "0":
return False
return True
def options(self):
return [("mtu", "int", 9216, "Interface MTU"),
("enabled", "string", "0", "Set to enable plugin"),
("up_command", "string", "/sbin/ifconfig {interface} up mtu {mtu}", "Command to bring the interface up"),
("flags_command", "string", "/sbin/ethtool -K {interface} gro off lro off rx off tx off gso off", "Command to setup the interface for capturing"),
]
def cmd_start_pre(self, nodes):
if not nodes:
return
mtu = self.getOption("mtu")
up_template = self.getOption("up_command")
flags_template = self.getOption("flags_command")
self.message("InterfaceSetupPlugin: bringing up interfaces with an mtu of %s" % (mtu))
host_interfaces = {}
for n in nodes:
intf = n.interface
if not intf:
continue
if '*' in intf:
self.error("Interface setup can't handle wildcard interfaces")
continue
for intf in extract_interfaces(intf):
host_interfaces[(n.host, intf)] = (n, intf)
cmds = []
for (n, intf) in host_interfaces.values():
cmd = up_template.format(interface=intf, mtu=mtu)
cmds.append((n, cmd))
cmd = flags_template.format(interface=intf)
cmds.append((n, cmd))
for (n, success, output) in self.executeParallel(cmds):
if not success:
self.message("Failed to run command on {}:".format(n.host))
self.message(output)