Some more micro-optimizations

git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@5697 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
teastep 2007-03-26 02:53:51 +00:00
parent 377b23e183
commit da9c54a426
3 changed files with 123 additions and 124 deletions

View File

@ -38,6 +38,7 @@ our @EXPORT = qw(ALLIPv4
create_temp_object
finalize_object
emit
emitj
emit_unindented
emit_as_is
save_progress_message
@ -179,6 +180,18 @@ sub emit ( $ ) {
}
}
sub emitj {
if ( $object ) {
#
# 'compile' as opposed to 'check'
#
for my $line ( @_ ) {
emit $line;
}
}
}
#
# Write passed message to the object with no indentation.
#

View File

@ -100,8 +100,7 @@ sub setup_providers() {
$match =~ s/ /\|/g;
emit join ( "\n",
"ip route show table $duplicate | while read net route; do",
emitj ( "ip route show table $duplicate | while read net route; do",
' case $net in',
' default|nexthop)',
' ;;',
@ -186,8 +185,7 @@ sub setup_providers() {
$gateway = '-' unless $gateway;
if ( $gateway eq 'detect' ) {
emit join( "\n",
"gateway=\$(detect_gateway $interface)\n",
emitj ( "gateway=\$(detect_gateway $interface)\n",
'if [ -n "$gateway" ]; then',
" run_ip route replace \$gateway src \$(find_first_interface_address $interface) dev $interface table $number",
" run_ip route add default via \$gateway dev $interface table $number",
@ -262,8 +260,7 @@ sub setup_providers() {
emit "\nrulenum=0\n";
emit join( "\n" ,
"find_interface_addresses $interface | while read address; do",
emitj ( "find_interface_addresses $interface | while read address; do",
' qt ip rule del from $address',
" run_ip rule add from \$address pref \$(( $rulebase + \$rulenum )) table $number",
" echo \"qt ip rule del from \$address\" >> \${VARDIR}/undo_routing",
@ -345,8 +342,7 @@ sub setup_providers() {
emit "\nif [ -z \"\$NOROUTES\" ]; then";
push_indent;
emit join( "\n",
'#',
emitj ( '#',
'# Undo any changes made since the last time that we [re]started -- this will not restore the default route',
'#',
'undo_routing',
@ -387,8 +383,7 @@ sub setup_providers() {
if ( $providers ) {
if ( $balance ) {
emit join ( "\n",
'if [ -n "$DEFAULT_ROUTE" ]; then',
emitj ( 'if [ -n "$DEFAULT_ROUTE" ]; then',
' run_ip route replace default scope global $DEFAULT_ROUTE',
" progress_message \"Default route '\$(echo \$DEFAULT_ROUTE | sed 's/\$\\s*//')' Added\"",
'else',

View File

@ -71,21 +71,18 @@ sub generate_script_1 {
emit join ( '', "#\n# Compiled firewall script generated by Shorewall-pl ", $env{VERSION}, " - $date\n#" );
if ( $ENV{EXPORT} ) {
emit join ( "\n",
'SHAREDIR=/usr/share/shorewall-lite',
emitj ( 'SHAREDIR=/usr/share/shorewall-lite',
'CONFDIR=/etc/shorewall-lite',
'VARDIR=/var/lib/shorewall-lite',
'PRODUCT="Shorewall Lite"' );
copy "$env{SHAREDIR}/lib.base";
emit join ( "\n",
'################################################################################',
emitj ( '################################################################################',
'# End of /usr/share/shorewall/lib.base',
'################################################################################' );
} else {
emit join ( "\n",
'SHAREDIR=/usr/share/shorewall',
emitj ( 'SHAREDIR=/usr/share/shorewall',
'CONFDIR=/etc/shorewall',
'VARDIR=/var/lib/shorewall',
'PRODUCT=\'Shorewall\'',
@ -110,14 +107,12 @@ sub generate_script_1 {
push_indent;
if ( $ENV{EXPORT} ) {
emit join ( "\n",
'#',
emitj ( '#',
'# These variables are required by the library functions called in this script',
'#',
'CONFIG_PATH="/etc/shorewall-lite:/usr/share/shorewall-lite"' );
} else {
emit join ( "\n",
'if [ ! -f ${SHAREDIR}/version ]; then',
emitj ( 'if [ ! -f ${SHAREDIR}/version ]; then',
' fatal_error "This script requires Shorewall which do not appear to be installed on this system (did you forget \"-e\" when you compiled?)"',
'fi',
'',
@ -134,8 +129,7 @@ sub generate_script_1 {
propagateconfig;
emit join ( "\n" ,
'[ -n "${COMMAND:=restart}" ]',
emitj ( '[ -n "${COMMAND:=restart}" ]',
'[ -n "${VERBOSE:=0}" ]',
'[ -n "${RESTOREFILE:=$RESTOREFILE}" ]',
'[ -n "$LOGFORMAT" ] || LOGFORMAT="Shorewall:%s:%s:"',
@ -154,8 +148,7 @@ sub generate_script_1 {
append_file 'params' if $config{EXPORTPARAMS};
emit join ( "\n",
'',
emitj ( '',
"STOPPING=",
"COMMENT=\n", # Maintain compability with lib.base
'#',
@ -319,8 +312,7 @@ stop_firewall() {
if ( @$criticalhosts ) {
if ( $config{ADMINISABSENTMINDED} ) {
emit join ( "\n",
' for chain in INPUT OUTPUT; do',
emitj ( ' for chain in INPUT OUTPUT; do',
' setpolicy $chain ACCEPT',
" done\n",
" setpolicy FORWARD DROP\n",
@ -488,8 +480,7 @@ sub generate_script_2 () {
emit '';
for my $interface ( @{find_interfaces_by_option 'norfc1918'} ) {
emit join( "\n",
"addr=\$(ip -f inet addr show $interface 2> /dev/null | grep 'inet\ ' | head -n1)",
emitj ( "addr=\$(ip -f inet addr show $interface 2> /dev/null | grep 'inet\ ' | head -n1)",
'if [ -n "$addr" ]; then',
' addr=$(echo $addr | sed \'s/inet //;s/\/.*//;s/ peer.*//\')',
' for network in 10.0.0.0/8 176.16.0.0/12 192.168.0.0/16; do',