]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/system/suricata
2 ########################################################################
3 # Begin $rc_base/init.d/suricata
5 # Description : Suricata Initscript
7 # Author : Stefan Schantl <stefan.schantl@ipfire.org>
13 ########################################################################
18 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/bin
:/usr
/bin
:/sbin
:/usr
/sbin
; export PATH
20 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/suricata
/settings
)
22 # Name of the firewall chain.
25 # Optional options for the Netfilter queue.
26 NFQ_OPTS
="--queue-bypass "
28 # Array containing the 4 possible network zones.
29 network_zones
=( red green blue orange
)
31 # Mark and Mask options.
35 # PID file of suricata.
36 PID_FILE
="/var/run/suricata.pid"
38 # Function to get the amount of CPU cores of the system.
39 function get_cpu_count
{
42 # Loop through "/proc/cpuinfo" and count the amount of CPU cores.
44 [ "$line" ] && [ -z "${line%processor*}" ] && ((CPUCOUNT
++))
50 # Function to create the firewall rules to pass the traffic to suricata.
51 function generate_fw_rules
{
52 cpu_count
=$
(get_cpu_count
)
54 # Flush the firewall chain.
55 iptables
-F "$FW_CHAIN"
57 # Loop through the array of network zones.
58 for zone
in "${network_zones[@]}"; do
59 # Convert zone into upper case.
62 # Generate variable name for checking if the IDS is
63 # enabled on the zone.
64 enable_ids_zone
="ENABLE_IDS_$zone_upper"
66 # Check if the IDS is enabled for this network zone.
67 if [ "${!enable_ids_zone}" == "on" ]; then
68 # Generate name of the network interface.
75 # Check if there are multiple cpu cores available.
76 if [ "$cpu_count" -gt "1" ]; then
77 # Balance beetween all queues.
78 NFQ_OPTIONS
+="--queue-balance 0:"
79 NFQ_OPTIONS
+=$
(($cpu_count-1))
81 # Send all packets to queue 0.
82 NFQ_OPTIONS
+="--queue-num 0"
85 # Create firewall rules to queue the traffic and pass to
87 iptables
-I "$FW_CHAIN" -i "$network_device" -m mark
! --mark "$MARK"/"$MASK" -j NFQUEUE
$NFQ_OPTIONS
88 iptables
-I "$FW_CHAIN" -o "$network_device" -m mark
! --mark "$MARK"/"$MASK" -j NFQUEUE
$NFQ_OPTIONS
93 # Function to flush the firewall chain.
94 function flush_fw_chain
{
95 # Call iptables and flush the chain
96 iptables
-F "$FW_CHAIN"
101 # Get amount of CPU cores.
102 cpu_count
=$
(get_cpu_count
)
107 for i
in $
(seq 0 $cpu_count); do
111 # Check if the IDS should be started.
112 if [ "$ENABLE_IDS" == "on" ]; then
114 boot_mesg
"Starting Intrusion Detection System..."
115 /usr
/bin
/suricata
-c /etc
/suricata
/suricata.yaml
-D $NFQUEUES >/dev
/null
2>/dev
/null
118 # Allow reading the pidfile.
121 # Flush the firewall chain
124 # Generate firewall rules
130 boot_mesg
"Stopping Intrusion Detection System..."
131 killproc
-p $PID_FILE /var
/run
133 # Flush firewall chain.
136 # Remove suricata control socket.
137 rm /var
/run
/suricata
/* >/dev
/null
2>/dev
/null
139 # Don't report returncode of rm if suricata was not started
144 statusproc
/usr
/bin
/suricata
152 # Send SIGUSR2 to the suricata process to perform a reload
154 kill -USR2 $
(pidof suricata
)
156 # Flush the firewall chain.
159 # Generate firewall rules.
164 echo "Usage: $0 {start|stop|restart|reload|status}"
169 chmod 644 /var
/log
/suricata
/* 2>/dev
/null
171 # End $rc_base/init.d/suricata