Improve generated code

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2011-06-20 14:34:26 -07:00
parent ec28bdb5a0
commit 39e74911d8

View File

@ -4550,12 +4550,14 @@ sub load_ipsets() {
' $IPSET -X' , ' $IPSET -X' ,
' $IPSET -R < ${VARDIR}/ipsets.save' , ' $IPSET -R < ${VARDIR}/ipsets.save' ,
' fi' ); ' fi' );
}
if ( @ipsets ) { if ( @ipsets ) {
emit ( '' ); emit ( '' );
ensure_ipset( $_ ) for @ipsets;
emit ( '' );
}
} else {
ensure_ipset( $_ ) for @ipsets; ensure_ipset( $_ ) for @ipsets;
emit ( '' );
} }
emit ( 'elif [ "$COMMAND" = restore -a -z "$g_recovering" ]; then' ); emit ( 'elif [ "$COMMAND" = restore -a -z "$g_recovering" ]; then' );
@ -4571,21 +4573,30 @@ sub load_ipsets() {
' fi' , ' fi' ,
' fi' , ' fi' ,
); );
if ( @ipsets ) {
emit ( '' );
ensure_ipset( $_ ) for @ipsets;
emit ( '' );
}
} else {
ensure_ipset( $_ ) for @ipsets;
}
if ( @ipsets ) {
emit ( 'elif [ "$COMMAND" = restart ]; then' );
ensure_ipset( $_ ) for @ipsets;
} }
emit( 'elif [ "$COMMAND" = stop ]; then' );
if ( @ipsets ) { if ( @ipsets ) {
emit '';
ensure_ipset( $_ ) for @ipsets; ensure_ipset( $_ ) for @ipsets;
emit( '' );
emit ( '' , }
'elif [ "$COMMAND" = restart ]; then' ,
'' ); if ( $family == F_IPV4 ) {
emit ( ' if [ -f /etc/debian_version ] && [ $(cat /etc/debian_version) = 5.0.3 ]; then' ,
ensure_ipset( $_ ) for @ipsets;
emit ( '' ,
' if [ -f /etc/debian_version ] && [ $(cat /etc/debian_version) = 5.0.3 ]; then' ,
' #', ' #',
' # The \'grep -v\' is a hack for a bug in ipset\'s nethash implementation when xtables-addons is applied to Lenny' , ' # The \'grep -v\' is a hack for a bug in ipset\'s nethash implementation when xtables-addons is applied to Lenny' ,
' #', ' #',
@ -4596,9 +4607,15 @@ sub load_ipsets() {
'', '',
' if eval $IPSET -S $hack > ${VARDIR}/ipsets.tmp; then' , ' if eval $IPSET -S $hack > ${VARDIR}/ipsets.tmp; then' ,
' grep -qE -- "^(-N|create )" ${VARDIR}/ipsets.tmp && mv -f ${VARDIR}/ipsets.tmp ${VARDIR}/ipsets.save' , ' grep -qE -- "^(-N|create )" ${VARDIR}/ipsets.tmp && mv -f ${VARDIR}/ipsets.tmp ${VARDIR}/ipsets.save' ,
' fi', ' fi' );
'elif [ "$COMMAND" = refresh ]; then' ); } else {
emit ( ' if eval $IPSET -S > ${VARDIR}/ipsets.tmp; then' ,
' grep -qE -- "^(-N|create )" ${VARDIR}/ipsets.tmp && mv -f ${VARDIR}/ipsets.tmp ${VARDIR}/ipsets.save' ,
' fi' );
}
if ( @ipsets ) {
emit( 'elif [ "$COMMAND" = refresh ]; then' );
ensure_ipset( $_ ) for @ipsets; ensure_ipset( $_ ) for @ipsets;
} }