]>
git.ipfire.org Git - 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
)
21 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
23 # Name of the firewall chain.
26 # Optional options for the Netfilter queue.
27 NFQ_OPTS
="--queue-bypass "
29 # Array containing the 4 possible network zones.
30 network_zones
=( red green blue orange
)
32 # Mark and Mask options.
36 # PID file of suricata.
37 PID_FILE
="/var/run/suricata.pid"
39 # Function to get the amount of CPU cores of the system.
40 function get_cpu_count
{
43 # Loop through "/proc/cpuinfo" and count the amount of CPU cores.
45 [ "$line" ] && [ -z "${line%processor*}" ] && ((CPUCOUNT
++))
51 # Function to flush the firewall chain.
52 function flush_fw_chain
{
53 # Call iptables and flush the chain
54 iptables
-F "$FW_CHAIN"
57 # Function to create the firewall rules to pass the traffic to suricata.
58 function generate_fw_rules
{
59 cpu_count
=$
(get_cpu_count
)
61 # Flush the firewall chain.
64 # Loop through the array of network zones.
65 for zone
in "${network_zones[@]}"; do
66 # Convert zone into upper case.
69 # Generate variable name for checking if the IDS is
70 # enabled on the zone.
71 enable_ids_zone
="ENABLE_IDS_$zone_upper"
73 # Check if the IDS is enabled for this network zone.
74 if [ "${!enable_ids_zone}" == "on" ]; then
75 # Check if the current processed zone is "red" and the configured type is PPPoE dialin.
76 if [ "$zone" == "red" ] && [ "$RED_TYPE" == "PPPOE" ]; then
77 # Set device name to ppp0.
80 # Generate variable name which contains the device name.
81 zone_name
="$zone_upper"
85 network_device
=${!zone_name}
91 # Check if there are multiple cpu cores available.
92 if [ "$cpu_count" -gt "1" ]; then
93 # Balance beetween all queues.
94 NFQ_OPTIONS
+="--queue-balance 0:$(($cpu_count-1))"
95 NFQ_OPTIONS
+=" --queue-cpu-fanout"
97 # Send all packets to queue 0.
98 NFQ_OPTIONS
+="--queue-num 0"
101 # Create firewall rules to queue the traffic and pass to
103 iptables
-I "$FW_CHAIN" -i "$network_device" -m mark
! --mark "$MARK"/"$MASK" -j NFQUEUE
$NFQ_OPTIONS
104 iptables
-I "$FW_CHAIN" -o "$network_device" -m mark
! --mark "$MARK"/"$MASK" -j NFQUEUE
$NFQ_OPTIONS
108 # Clear repeat bit, so that it does not confuse IPsec or QoS
109 iptables
-A "${FW_CHAIN}" -j MARK
--set-xmark "0x0/${MASK}"
114 # Get amount of CPU cores.
115 cpu_count
=$
(get_cpu_count
)
120 for i
in $
(seq 0 $
((cpu_count-1
)) ); do
124 # Check if the IDS should be started.
125 if [ "$ENABLE_IDS" == "on" ]; then
127 boot_mesg
"Starting Intrusion Detection System..."
128 /usr
/bin
/suricata
-c /etc
/suricata
/suricata.yaml
-D $NFQUEUES >/dev
/null
2>/dev
/null
131 # Allow reading the pidfile.
134 # Flush the firewall chain
137 # Generate firewall rules
143 boot_mesg
"Stopping Intrusion Detection System..."
144 killproc
-p $PID_FILE /var
/run
146 # Flush firewall chain.
149 # Remove suricata control socket.
150 rm /var
/run
/suricata
/* >/dev
/null
2>/dev
/null
152 # Don't report returncode of rm if suricata was not started
157 statusproc
/usr
/bin
/suricata
165 # Send SIGUSR2 to the suricata process to perform a reload
167 kill -USR2 $
(pidof suricata
)
169 # Flush the firewall chain.
172 # Generate firewall rules.
177 echo "Usage: $0 {start|stop|restart|reload|status}"
182 chmod 644 /var
/log
/suricata
/* 2>/dev
/null
184 # End $rc_base/init.d/suricata