diff --git a/New/Shorewall/Config.pm b/New/Shorewall/Config.pm index bd18fc1c1..76f714ca1 100644 --- a/New/Shorewall/Config.pm +++ b/New/Shorewall/Config.pm @@ -492,6 +492,64 @@ sub mywhich( $ ) { ''; } +sub load_kernel_modules( ) { + my $moduleloader = mywhich 'modprobe' ? 'modprobe' : 'insmod'; + + my $modulesdir = $config{MODULESDIR}; + + unless ( $modulesdir ) { + my $uname = `uname -r`; + fatal_error "The command 'uname -r' failed" unless $? == 0; + chomp $uname; + $modulesdir = "/lib/modules/$uname/kernel/net/ipv4/netfilter:/lib/modules/$uname/kernel/net/netfilter"; + } + + my @moduledirectories = split /:/, $modulesdir; + + if ( @moduledirectories && open_file 'modules' ) { + my %loadedmodules; + + progress_message "Loading Modules..."; + + open LSMOD , '-|', 'lsmod' or fatal_error "Can't run lsmod"; + + while ( $line = ) { + my $module = ( split( /\s+/, $line ) )[0]; + + unless ( $module eq 'Module' ) { + $loadedmodules{$module} = 1; + } + } + + close LSMOD; + + $config{MODULE_SUFFIX} = 'o gz ko o.gz ko.gz' unless $config{MODULES_SUFFIX}; + + my @suffixes = split /\s+/ , $config{MODULE_SUFFIX}; + + while ( read_a_line ) { + fatal_error "Invalid modules file entry" unless ( $line =~ /^loadmodule\s+([a-zA-Z]\w*)\s*(.*)$/ ); + my ( $module, $arguments ) = ( $1, $2 ); + unless ( $loadedmodules{ $module } ) { + for my $suffix ( @suffixes ) { + for my $directory ( @moduledirectories ) { + my $modulefile = "$directory/$module.$suffix"; + if ( -f $modulefile ) { + if ( $moduleloader eq 'insmod' ) { + system ("insmod $modulefile $arguments" ); + } else { + system( "modprobe $module $arguments" ); + } + + $loadedmodules{ $module } = 1; + } + } + } + } + } + } +} + # # Determine which optional facilities are supported by iptables/netfilter # @@ -632,6 +690,8 @@ sub get_configuration( $ ) { } else { fatal_error "\$IPTABLES=$capabilities{IPTABLES} does not exist or is not executable" unless -x $capabilities{IPTABLES}; } + + load_kernel_modules; unless ( open_file 'capabilities' ) { determine_capabilities; diff --git a/New/compiler.pl b/New/compiler.pl index 39d8c4491..5c0b9423e 100755 --- a/New/compiler.pl +++ b/New/compiler.pl @@ -31,7 +31,6 @@ # EXPORT=Yes -e option specified to /sbin/shorewall # SHOREWALL_DIR A directory name was passed to /sbin/shorewall # VERBOSE Standard Shorewall verbosity control. -# VERSION Shorewall Version # TIMESTAMP=Yes -t option specified to /sbin/shorewall # FW Firewall zone (for shell-variable expansion). #