#!/bin/bash # source application-specific settings [ -f /etc/conf.d/ipset ] && . /etc/conf.d/ipset # Set defaults if settings are missing [ -z "$IPSET_CONF" ] && IPSET_CONF=/etc/iptables/ipset.conf . /etc/rc.conf . /etc/rc.d/functions case "$1" in start) if [ ! -f "$IPSET_CONF" ]; then echo "Cannot load ipset data: $IPSET_CONF is missing!" >&2 exit 1 fi stat_busy "Loading IP sets" if ck_daemon ipset; then ipset restore < "$IPSET_CONF" if [ $? -gt 0 ]; then stat_fail else add_daemon ipset stat_done fi else stat_fail fi ;; stop) stat_busy "Destroying all IP sets" if ! ck_daemon ipset; then fail=0 ipset destroy if [ $? -gt 0 ]; then stat_fail else rm_daemon ipset stat_done fi else stat_fail fi ;; restart) $0 stop $0 start ;; save) stat_busy "Saving IP sets" ipset save > "$IPSET_CONF" if [ $? -gt 0 ]; then stat_fail else stat_done fi ;; *) echo "usage: $0 {start|stop|restart|save}" esac exit 0