On daemon shutdown iptables cleanup successfully

Fixes #8307.

Pulls a commit from #8581, and adds a test.

It was broken in 1.2 so not needed necessarily for 1.3. but a nice fix