Bug 717583

Summary: systemd: rcSuSEfirewall2 does not work
Product: [openSUSE] openSUSE 12.1 Reporter: Bernhard Wiedemann <bwiedemann>
Component: NetworkAssignee: Ludwig Nussel <lnussel>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: fcrozat
Version: Factory   
Target Milestone: ---   
Hardware: All   
OS: SUSE Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Bug Depends on:    
Bug Blocks: 696902    
Attachments: initscript

Description Bernhard Wiedemann 2011-09-13 16:57:44 UTC
User-Agent:       Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0

on current factory with systemd
the cure-all for firewall problems does not work

Reproducible: Always

Steps to Reproduce:
as root do: 
1. rcSuSEfirewall2 stop 
1b. or systemctl stop SuSEfirewall2_init ; systemctl stop SuSEfirewall2_setup
2. iptables -L
Actual Results:  
network still firewalled

Expected Results:  
firewall should be disabled
Comment 1 Frederic Crozat 2011-09-16 12:39:56 UTC
reassigning to SuSEfirewall2 maintainer, SuSEfirewall2 is hardcoded to not unload its firewall rules when called from systemd (check /etc/init.d/SuSEfirewall2_setup)
Comment 2 Ludwig Nussel 2011-09-19 07:20:27 UTC
SuSEfirewall2 needs to know whether is was called manually or during shutdown. During shutdown rules must not be unloaded to avoid exposing the machine in case some network interfaces are still online (and it's a waste of time anyways). Please correct if I'm wrong but AFAIK there is no way to find out so never unloading rules was the best I could do. Has that changed meanwhile or is there any way to tell systemd to just not call SuSEfirewall2 on shutdown?

Users can still call /sbin/SuSEfirewall2 stop directly to unload rules btw.
Comment 3 Frederic Crozat 2011-09-19 09:42:23 UTC
There is a way, I've justed tested.

--- /etc/init.d/SuSEfirewall2_setup	2011-04-08 23:31:19.000000000 +0200
+++ /home/fcrozat/SuSEfirewall2_setup	2011-09-19 11:41:14.120301321 +0200
@@ -41,9 +41,12 @@
 		# called due to shutdown of the machine. So we can't
 		# unload rules here. Call /sbin/SuSEfirewall2
 		# directly instead to unload rules.
-		echo -n "Not unloading firewall rules when using systemd "
-		rc_status -s
-	elif [ -z "$REDIRECT" ]; then
+		systemctl show -p ActiveState shutdown.target | grep -qi inactive
+		if [ $? != 0 ]; then
+			unset REDIRECT
+		fi
+	fi
+	if [ -z "$REDIRECT" ]; then
 		echo -n "Unloading firewall rules"
 		$SUSEFWALL -q stop
 		rc_status -v

This is not very pretty but it works ;)

Of course, for 12.2, we will probably switch to systemd unit files which could help in this regard.
Comment 4 Ludwig Nussel 2011-09-29 09:58:18 UTC
There are actually more things wrong.

rcSuSEfirewall2 doesn't work because the rc.status magic doesn't detect the symlink to SuSEfirewall2_setup

"systemctl SuSEfirewall2_setup.service status" doesn't actually call the script but simply claims success. Someone could have manually unloaded the rules so the script must be called always. There is no daemon after all.
Comment 5 Ludwig Nussel 2011-10-05 12:07:19 UTC
(In reply to comment #3)
> +        systemctl show -p ActiveState shutdown.target | grep -qi inactive

Doesn't work for me.
I've added the following code to SuSEfirewall2_setup:

   for i in shutdown reboot; do
   echo -n $i...
       /bin/systemctl --no-pager show -p ActiveState $i.target
   done > /dev/tty10
   echo -n "sleeping " > /dev/tty10
   for i in 1 2 3 4 5 6 7; do
       sleep 1
       echo -n . > /dev/tty10
   done

On tty10 one can see that neither target is active. Neither on
reboot nor on shutdown. So SuSEfirewall2 would always unload the
ruels which is not supposed to happen
Comment 6 Frederic Crozat 2011-10-06 14:30:26 UTC
Created attachment 454897 [details]
initscript 

please test attached file, it doesn't unload iptables rules for me, either on reboot nor shutdown ( I left a sleep 10 call when unloading rules, so it really delays the shutdown / reboot process).


For the status, rc* script should not use the initscript, but do the check itself ( see http://www.freedesktop.org/wiki/Software/systemd/Incompatibilities )
Comment 7 Ludwig Nussel 2011-10-14 07:59:02 UTC
So it does not unload rules at shutdown but neither does it when called manually. the shutdown.target is always inactive, even on shutdown.
systemctl list-units shows 'stop' for basic.target when shutting down though.
Is there a way to isolate that other than 'systemctl list-units|grep 'basic.target.*stop'?
Comment 8 Bernhard Wiedemann 2011-10-14 10:00:07 UTC
This is an autogenerated message for OBS integration:
This bug (717583) was mentioned in
https://build.opensuse.org/request/show/87807 Factory / SuSEfirewall2
Comment 9 Ludwig Nussel 2011-10-14 12:10:54 UTC
added list-units and grep for basic.target as workaround