Compare commits

..

275 Commits

Author SHA1 Message Date
Tom Eastep
e068f58363 Merge branch '4.5.2' of ssh://shorewall.git.sourceforge.net/gitroot/shorewall/shorewall into 4.5.2
Conflicts:
	Shorewall/install.sh

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-30 09:11:00 -07:00
Tom Eastep
1f5e30d0d3 Make products start automatically at boot on Debian and derivatives
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-30 08:41:37 -07:00
Tom Eastep
fb6bbf8cac Install fixes for Slackware
Signed-off-by: Tom Eastep <teastep@shorewall.net>

Conflicts:

	Shorewall/install.sh
2012-04-30 08:18:30 -07:00
Tom Eastep
b6e2c1ea88 Fix IPv4 'reset'
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-30 08:15:40 -07:00
Tom Eastep
9dd9b9e105 Do SHA/SHA1 test if $BUILD = $TEST, independent of $DESTDIR
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-30 08:15:21 -07:00
Tom Eastep
0b67d6ecfe Install fixes for Slackware
Signed-off-by: Tom Eastep <teastep@shorewall.net>

Conflicts:

	Shorewall/install.sh

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-27 07:21:13 -07:00
Tom Eastep
29a5c23c7b Do SHA/SHA1 test if $BUILD = $TEST, independent of $DESTDIR
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-24 08:49:52 -07:00
Tom Eastep
f0afb3b3bb Merge branch '4.5.2' of ssh://shorewall.git.sourceforge.net/gitroot/shorewall/shorewall into 4.5.2
Conflicts:
	Shorewall-core/lib.cli

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-23 14:14:43 -07:00
Tom Eastep
7737d844da Allow TC experts to SAVE/RESTORE all parts of the packet mark
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-23 09:00:32 -07:00
Tom Eastep
c82ebe840d Patch from Roberto
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-21 17:51:06 -07:00
Tom Eastep
2570fcca2c Corret tcrules manpages
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-21 09:52:01 -07:00
Tom Eastep
e0c9a15f13 Add TCP to macro.Amanda
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-20 09:46:47 -07:00
Tom Eastep
8183bac615 Add a comment about 'find_tables()'
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-17 06:57:59 -07:00
Tom Eastep
3a967d66cf Fix configure
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-16 12:57:34 -07:00
Tom Eastep
5a350d1899 More variable synchronization
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-16 11:40:49 -07:00
Tom Eastep
9d219445d9 Make 'show routing work with iproute 20111117
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-16 11:40:36 -07:00
Tom Eastep
caf60e6c1f Make 'show routing work with iproute 20111117
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-16 08:21:26 -07:00
Tom Eastep
1462fcd351 Synchronize global settings
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-15 09:43:41 -07:00
Tom Eastep
a32ce5c34a Correct Makefiles
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-14 12:01:37 -07:00
Tom Eastep
baa1a2983b Fix redhat PERLLIBDIR.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-14 11:38:13 -07:00
Tom Eastep
fdc4a84a83 Delete code to modify Makefile
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-14 11:36:08 -07:00
Tom Eastep
d3943ea0fe Install correct Makefile
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-14 11:17:27 -07:00
Tom Eastep
79b5c38ecb Handle trailing whitespace in Shorewall::Config::read_a_line1()
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-14 10:14:25 -07:00
Tom Eastep
1477d60926 Correct the output of 'version -a'
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-12 18:58:06 -07:00
Tom Eastep
32264c2e7e Make arguments to the configure script optional
- Scripts detects vendor
- Scripts Annotate the shorewallrc file with version and argument info
- configure detects BASH version
2012-04-12 14:43:02 -07:00
Tom Eastep
69a133083c Modify Makefiles for directory relocation
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-12 10:15:55 -07:00
Tom Eastep
9ba9aad5f7 Reverse relocation of -lite Makefiles in the 4.5.2 branch
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-12 07:48:47 -07:00
Tom Eastep
1f2ac17091 Remove blank line in shorewallrc.suse
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-12 07:03:41 -07:00
Tom Eastep
06588c2e4a Fix configure.pl
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-12 07:03:32 -07:00
Tom Eastep
3c09368032 Make changes suggested by Orion Poplawski
- Change shorewallrc.redhat LIBEXECDIR and PERLLIBDIR settings
- Install -lite Makefiles in ${SHAREDIR}/${PRODUCT}/

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-11 15:41:21 -07:00
Tom Eastep
4fa71d122c Add comments to shorewallrc files.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-11 15:23:19 -07:00
Tom Eastep
8b7d60065e Clean up configure.pl
- Remove blank lines at the end
- Simply the handling of vendor

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-11 08:05:52 -07:00
Tom Eastep
e263a3c27d Remove redundant logic
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-11 07:11:05 -07:00
Tom Eastep
0b5e30aa7b Fix INCLUDE inside an ?IF ... ?ENDIF
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-10 17:27:47 -07:00
Tom Eastep
25125c47e4 Document configure.pl
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-10 11:57:08 -07:00
Tom Eastep
76de9bf1fa Add Perl version of configure for use in rpm builds
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-10 10:20:53 -07:00
Tom Eastep
623e545f09 Don't allow accounting chains to be altered when OPTIMIZE_ACCOUNTING=No
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-09 21:44:44 -07:00
Tom Eastep
74fdd97b14 Warn about not using sections in the accounting file
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-09 16:47:56 -07:00
Tom Eastep
2545322163 Cleanup of read_a_line()
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-09 16:00:26 -07:00
Tom Eastep
7b511f449f Don't strip comments until after embedded Perl or Shell have been handled.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-09 15:12:13 -07:00
Tom Eastep
94097e2561 Add newlines to embedded multi-line shell and perl
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-08 12:17:00 -07:00
Tom Eastep
50405f57ba Don't suppress whitespace in embedded Perl and Shell
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-08 07:54:03 -07:00
Tom Eastep
860141127a Re-enable '#' in quoted strings within embedded shell and perl
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-08 07:30:46 -07:00
Tom Eastep
58d8ee79f8 Fix -lite installer
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-07 11:57:38 -07:00
Tom Eastep
f8f599c1db Restore progress message that was inadvertently deleted.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-07 09:34:32 -07:00
Tom Eastep
a2abad3f68 Modify getparams to use the installed shorewallrc file.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-07 09:07:07 -07:00
Tom Eastep
c5f44d8737 Move read_a_line() prototype before first use.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-07 07:42:27 -07:00
Tom Eastep
25bca70ff2 Merge branch 'master' into 4.5.2 2012-04-07 07:39:14 -07:00
Tom Eastep
55cd81747d Add emphasis in some examples; correct a typo.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-07 07:38:38 -07:00
Tom Eastep
7204220991 Some more fixes to conditional inclusion.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-07 07:16:17 -07:00
Tom Eastep
97cc4930cf Deimplement option leading ? in embedded directives
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-06 16:26:05 -07:00
Tom Eastep
5688dc77a3 Make ?BEGIN PERL end ?END PERL work.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-06 15:58:21 -07:00
Tom Eastep
9dd6f86c55 Use read_a_line() in the embedded_shell() and embedded_perl() functions.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-06 15:46:01 -07:00
Tom Eastep
f85321e201 Clean up conditional include documentation.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-06 11:50:22 -07:00
Tom Eastep
53395e788d Add a comment
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-06 11:49:59 -07:00
Tom Eastep
2de64d5820 Remove find_echo() from lib.core
- Also correct a couple of typos in comments

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-06 08:01:07 -07:00
Tom Eastep
24e115d0f9 Move a comment
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-06 08:00:20 -07:00
Tom Eastep
334394a5d4 Deprecate the vardir file. 2012-04-05 08:03:31 -07:00
Tom Eastep
6fb2fcbc8a Update base library version
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-05 08:03:10 -07:00
Tom Eastep
29a820b2f2 Make handling of remote configuration data consistent.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-04 11:47:45 -07:00
Tom Eastep
b0c07aa6d6 Fix typo in ifupdown.sh
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-04 11:47:00 -07:00
Tom Eastep
bff3473279 Fix preceding commit -- it missed to cases of absolute pathnames.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-04 09:43:39 -07:00
Tom Eastep
d9fddf67af Merge branch '4.5.2'
Conflicts:
	Shorewall/Perl/Shorewall/Compiler.pm

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-04 09:28:53 -07:00
Tom Eastep
319d07b1d3 Remove more absolute path names
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-04 09:24:48 -07:00
Tom Eastep
38b6dca223 Correct a number of issues with Shorewall-lite
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-04 07:08:02 -07:00
Tom Eastep
24d30275fa Correct syntax errors in the generated script
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-03 17:08:14 -07:00
Tom Eastep
41266627cd Fix secondary CLIs
- construct the correct pathname for lib.cli
2012-04-03 08:09:18 -07:00
Tom Eastep
abd864eecb Update copyrights in init scripts that have them
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-03 07:52:39 -07:00
Tom Eastep
7db79a6d40 Fix ifupdown
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-03 07:52:14 -07:00
Tom Eastep
fb428bf564 Don't modify CONFDIR and SHAREDIR in the shell code
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-02 12:39:49 -07:00
Tom Eastep
9e506d797a Don't modify CONFDIR and SHAREDIR in the shell code
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-02 11:34:33 -07:00
Tom Eastep
348c99c7d0 Compiler changes for Shorewall[6]-lite relocation
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-02 07:46:38 -07:00
Tom Eastep
a11e2dd452 Correct uninstall scripts
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-02 06:48:23 -07:00
Tom Eastep
85fce606dc Give all config files access to shorewallrc variables.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-01 13:19:38 -07:00
Tom Eastep
bb6e17fd3e Many changes involved in getting a relocated installations to work
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-04-01 10:47:24 -07:00
Tom Eastep
e48e13012c Fix up lib.base during installation
- Shorewall-core installer creates all necessary directories.
2012-04-01 08:16:07 -07:00
Tom Eastep
c616e203df Merge branch 'master' into 4.5.2 2012-03-31 20:03:57 -07:00
Tom Eastep
c26f6d45dd Document install changes
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-31 20:02:03 -07:00
Tom Eastep
02a68aa436 Look for ./shorewallrc first
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-31 17:40:18 -07:00
Tom Eastep
d4f93688b5 Correct typo
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-31 15:25:18 -07:00
Tom Eastep
766370e22a More work on installers
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-31 14:42:01 -07:00
Tom Eastep
75b57b926a Revert "Replace lib.base with symbolic link"
This reverts commit 98f4a1c545.
2012-03-31 12:57:38 -07:00
Tom Eastep
6b698759ca Correct a typo.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-31 09:45:45 -07:00
Tom Eastep
cf176474ac Merge branch '4.5.2'
Conflicts:
	Shorewall/Perl/Shorewall/Chains.pm
2012-03-31 09:44:36 -07:00
Tom Eastep
6ed207aba0 Fix 'dhcp' with 'nets'
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-31 09:30:29 -07:00
Tom Eastep
924ec49d09 Add OWNER_NAME_MATCH to do_user
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-30 16:58:38 -07:00
Tom Eastep
a4097b7a02 Correct Typo in setup_null_routing()
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-30 16:57:26 -07:00
Tom Eastep
e38fcb2bfc Correct ipset creation and add a WARNING when creating an ipset
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-30 16:56:43 -07:00
Tom Eastep
c3b56d4123 Add BLACKLIST Macro
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-30 16:53:02 -07:00
Tom Eastep
fead683f18 Modify init scripts if ${SHAREDIR} is non-standard
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-30 16:21:37 -07:00
Tom Eastep
98f4a1c545 Replace lib.base with symbolic link
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-30 15:30:04 -07:00
Tom Eastep
9ca82d8bf6 More relocation bugs fixed
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-30 15:22:06 -07:00
Tom Eastep
6a2f907ee1 Append product name to ${vardir}
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-30 15:01:34 -07:00
Tom Eastep
7c0a0d81f8 Correct include of lib.base from lib.cli
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-30 14:49:10 -07:00
Tom Eastep
f5414d0fd1 Create ${SYSTEMD} if needed.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-30 13:56:59 -07:00
Tom Eastep
15335f8615 Modify CLIs and libs to know where shorewallrc is.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-30 12:02:25 -07:00
Tom Eastep
4c2cdd5a07 Redeclare pn
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-29 19:05:17 -07:00
Tom Eastep
8a695b4073 Correct syntax error in configure
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-29 18:53:21 -07:00
Tom Eastep
74ca7b5269 Correct syntax error in configure
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-29 18:50:53 -07:00
Tom Eastep
82e7bc707d Correct syntax error in configure
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-29 18:22:11 -07:00
Tom Eastep
c4afe0922e Update shorewallrc.suse per Togan Muftuoglu
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-29 08:38:52 -07:00
Tom Eastep
279fbe4543 Add additional param mapping and eliminate syntax error in configure script
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-29 07:40:15 -07:00
Tom Eastep
2d841269ee Remove 'local file'
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-28 17:01:56 -07:00
Tom Eastep
9713fe358b Add aliases for certain parameters.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-28 17:01:43 -07:00
Tom Eastep
0d19c99699 Correct default setting of CONFDIR when .shorewallrc is not found
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-28 06:28:53 -07:00
Tom Eastep
416f854311 Rename vendor -> host
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-28 06:13:10 -07:00
Tom Eastep
62f37e6b23 Correct type on Shorewall-core install script
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-27 20:30:26 -07:00
Tom Eastep
c2fa5ae78f Correct typo in install.sh files
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-27 20:19:06 -07:00
Tom Eastep
7ded1df94b Add a configure script
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-27 14:33:49 -07:00
Tom Eastep
e1e4855211 Rename USR to PREFIX
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-27 07:47:22 -07:00
Tom Eastep
e09457cdf9 Correct Typo in setup_null_routing()
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-27 07:46:53 -07:00
Tom Eastep
f2311f1987 Update install scripts to look for .shorewallrc in many places
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-26 17:01:55 -07:00
Tom Eastep
b31f656d63 Update uninstall scripts for multiple .shorewallrc locations.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-26 16:19:40 -07:00
Tom Eastep
e641bf7ac2 Correct typo
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-26 16:01:35 -07:00
Tom Eastep
8a164adf98 Export TMPDIR if it exists in the .shorewallrc file
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-26 15:43:04 -07:00
Tom Eastep
7b9c1d43cd Look in additional places for .shorewallrc
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-26 15:00:43 -07:00
Tom Eastep
fd82877312 Another fix for init.sh
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-26 07:49:49 -07:00
Tom Eastep
2518c653af Modify RedHat/Fedora init scripts for shorewallrc.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-26 07:20:31 -07:00
Tom Eastep
c23deed3a7 Correct syntax error in init.sh
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-26 07:04:21 -07:00
Tom Eastep
dee20c8d74 Add OWNER_NAME_MATCH to do_user
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-25 20:18:20 -07:00
Tom Eastep
ee15baf98c Correct typo in Chains.pm
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-25 12:48:57 -07:00
Tom Eastep
25e7555e80 Correct typo in the compiler 2012-03-25 12:36:25 -07:00
Tom Eastep
74c7760d9d Correct typo in shorewallrc.suse
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-25 08:30:30 -07:00
Tom Eastep
9dd9ee614b Correct ipset creation and add a WARNING when creating an ipset
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-25 08:27:28 -07:00
Tom Eastep
8a18dac870 Installer tweaks
- Give instructions when Shorewall-core installer finds no rc file
- Update help

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-25 07:49:52 -07:00
Tom Eastep
5aed14ffdc Set PRODUCT before processing rc file.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-25 07:25:15 -07:00
Tom Eastep
294babcfbb Add USR to the rc files for easier modification
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-25 07:20:40 -07:00
Tom Eastep
59aab485c3 Handle 'PRODUCT' more gracefully
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-24 22:21:42 -07:00
Tom Eastep
877796a7ca Add shorewallrc processing to other CLI programs
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-24 22:14:01 -07:00
Tom Eastep
173d29969d Improve shorewallrc variable expansion
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-24 21:34:24 -07:00
Tom Eastep
7390789b5e Add BLACKLIST Macro
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-24 21:33:57 -07:00
Tom Eastep
fc4aaa97c6 Expand variables in shorewallrc
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-24 21:26:20 -07:00
Tom Eastep
217d5e636c Add BLACKLIST Macro
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-24 19:29:27 -07:00
Tom Eastep
eb118e4443 Add shorewallrc files.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-24 13:05:39 -07:00
Tom Eastep
f4ed4109c6 Fix LENGTH handling (again)
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-23 15:40:48 -07:00
Tom Eastep
398c843643 Concatenate match options when not KLUDGEFREE
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-23 15:40:25 -07:00
Tom Eastep
01d07f55a9 Only include user exit basename in exported progress messages
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-20 07:33:32 -07:00
Tom Eastep
a7b10c99da Add some comments to lib.core
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-20 07:17:19 -07:00
Tom Eastep
bdc8cb66bd Correct load_kernel_modules()
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-20 07:15:47 -07:00
Tom Eastep
7bc823fb8b Support 'kerneltz'
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-19 15:57:38 -07:00
Tom Eastep
48b7594b64 Delete prog.header*
- Move functions into lib.core with ?IF ... ?ELSE ... ?END

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-19 15:56:02 -07:00
Tom Eastep
88b1180817 Support ?IF in copied files
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-19 13:38:24 -07:00
Tom Eastep
8803cd8d3b ?IF improvements
- Pass line number to make process_conditional more general
- Add debugging output
- Do first_line processing prior to looking for ?

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-19 12:51:22 -07:00
Tom Eastep
0063de1564 Add capabilities to conditionals
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-19 11:57:33 -07:00
Tom Eastep
f104596b39 Merge branch '4.5.1' 2012-03-19 10:13:08 -07:00
Tom Eastep
146d66f0aa Don't complain about SHOREWALL_INIT_SCRIPT
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-19 09:52:55 -07:00
Tom Eastep
0ccb398cec Merge branch '4.5.1' 2012-03-19 09:22:44 -07:00
Tom Eastep
287a44be52 Allow TOS to work on RHEL5
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-19 09:22:21 -07:00
Tom Eastep
86f3667b82 Correct nested ?IF
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-19 08:19:32 -07:00
Tom Eastep
962b1cca1f Remove Perl diagnostic
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-19 07:46:45 -07:00
Tom Eastep
2026fdab6a Correct IPSET_WARNINGS
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-19 07:44:52 -07:00
Tom Eastep
722e888043 Fix ?IF
- Allow nested ?IFs to work correctly
- Correct push logic for $ifstack

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-19 07:38:52 -07:00
Tom Eastep
e3997abfb9 Merge branch '4.5.2'
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-19 07:27:53 -07:00
Tom Eastep
710687bbd6 Revert "Move conditional processing to it's own function"
This reverts commit 8262cff71a.
2012-03-19 07:23:57 -07:00
Tom Eastep
d4a1e7dba9 Revert "Allow ?IF, ?ELSE and ?ENDIF in copied files"
This reverts commit 29dd342118.
2012-03-19 07:23:24 -07:00
Tom Eastep
c7237e5c8e Revert "Move all functions from prog.header* to lib.core"
This reverts commit f9f557e1c6.
2012-03-19 07:22:51 -07:00
Tom Eastep
c299c6d61a Revert "Correct spelling"
This reverts commit 1d021e3701.
2012-03-19 07:22:29 -07:00
Tom Eastep
6769acc7a7 Revert "Some corrections to conditional inclusion"
This reverts commit 164d2f5d1b.
2012-03-19 07:22:07 -07:00
Tom Eastep
df33587395 Revert "Clean up of conditional inclusion."
This reverts commit 5f3ba4eb40.
2012-03-19 07:21:36 -07:00
Tom Eastep
508f33a183 Revert "Eliminate prog.header6"
This reverts commit 60f1004339.
2012-03-19 07:21:12 -07:00
Tom Eastep
11f970d1c2 Revert "Eliminate prog.header"
This reverts commit 13bf383ce8.
2012-03-19 07:20:57 -07:00
Tom Eastep
72e6330ff4 Revert "Add capabilities to ?IF conditionals"
This reverts commit 0d71c590e4.
2012-03-19 07:20:31 -07:00
Tom Eastep
5caf68bc31 Remove .project
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-18 19:31:40 -07:00
Tom Eastep
29ccde1603 Add an Id to the default location section of the Install doc
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-18 19:31:12 -07:00
Tom Eastep
826d864448 Document MANDIR
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-18 19:30:41 -07:00
Tom Eastep
78306e9f5b Don't issue missing SHOREWALL_SHELL warning when compiling for export
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-18 19:30:32 -07:00
Tom Eastep
15ca0fd1f0 Add IPSET_WARNINGS option
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-18 19:30:04 -07:00
Tom Eastep
955a9f0051 Correct Steven's issues
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-18 19:10:46 -07:00
Tom Eastep
bd56caf74f Don't issue missing SHOREWALL_SHELL warning when compiling for export
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-18 12:54:53 -07:00
Tom Eastep
5bfd2cc2c9 Remove some WARNINGs
- Mr Dash4 has decided he doesn't want them after all.
2012-03-18 12:42:32 -07:00
Tom Eastep
e47ae4f26e Don't issue missing SHOREWALL_SHELL warning when compiling for export
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-18 12:28:26 -07:00
Tom Eastep
c51e387e79 Document MANDIR
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-18 12:09:22 -07:00
Tom Eastep
56f66bd966 Require the correct PROTO to use a port range in the ADDRESS column of masq
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-18 11:22:37 -07:00
Tom Eastep
0415883628 Add an Id to the default location section of the Install doc
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-18 11:22:29 -07:00
Tom Eastep
6e089fb0e2 Require the correct PROTO to use a port range in the ADDRESS column of masq
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-18 11:21:53 -07:00
Tom Eastep
0fac1d182f Add an Id to the default location section of the Install doc
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-18 11:20:24 -07:00
Tom Eastep
0d71c590e4 Add capabilities to ?IF conditionals
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-18 08:48:26 -07:00
Tom Eastep
d1661c95d5 Remove .project
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-17 18:29:32 -07:00
Tom Eastep
13bf383ce8 Eliminate prog.header
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-17 18:07:36 -07:00
Tom Eastep
60f1004339 Eliminate prog.header6
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-17 17:51:56 -07:00
Tom Eastep
81714ee81f Document '!' in ?IF
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-17 16:58:25 -07:00
Tom Eastep
5f3ba4eb40 Clean up of conditional inclusion.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-17 12:12:32 -07:00
Tom Eastep
164d2f5d1b Some corrections to conditional inclusion
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-17 10:26:36 -07:00
Tom Eastep
1d021e3701 Correct spelling
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-17 09:42:15 -07:00
Tom Eastep
f9f557e1c6 Move all functions from prog.header* to lib.core
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-17 09:35:35 -07:00
Tom Eastep
29dd342118 Allow ?IF, ?ELSE and ?ENDIF in copied files
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-17 09:33:40 -07:00
Tom Eastep
8262cff71a Move conditional processing to it's own function
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-17 09:32:56 -07:00
Tom Eastep
b7465262ca Rename MARK/CLASSIFY column to ACTION
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-16 10:09:13 -07:00
Tom Eastep
ab13fbe95e Allow conditional compilation
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-16 08:16:12 -07:00
Tom Eastep
f7a2cd4ef1 Correct typos in accounting manpages.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-14 15:34:19 -07:00
Tom Eastep
95e4f8dd91 Fix TOS(tos/mask) in tcrules.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-14 15:34:11 -07:00
Tom Eastep
8e413a7bf0 Fix TOS(tos/mask) in tcrules.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-14 15:33:31 -07:00
Tom Eastep
3e9edcb7e8 Correct typos in accounting manpages.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-14 14:50:25 -07:00
Tom Eastep
4ba88d2e9c Merge branch '4.5.1' 2012-03-14 11:00:56 -07:00
Tom Eastep
aa503e7211 Apply Tuomo Soini's Makefile patch
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-14 10:57:41 -07:00
Tom Eastep
2a67a202b0 Merge branch '4.5.1' 2012-03-13 20:16:01 -07:00
Tom Eastep
7e14777b8f Fix typo
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-13 19:54:58 -07:00
Tom Eastep
c1d0681e17 Correct LENGTH column validation
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-13 17:58:18 -07:00
Tom Eastep
98f8edbde5 Apply two patches from Tuomo Soini
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-13 13:27:20 -07:00
Tom Eastep
1dd6a8b291 Document use of chain designators with DSCP and TOS
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-13 13:26:29 -07:00
Tom Eastep
e839648b8e Add a restriction to the SHELL and PERL directives.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-13 13:26:09 -07:00
Tom Eastep
feb5cc0093 Document use of chain designators with DSCP and TOS
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-13 13:25:37 -07:00
Tom Eastep
a3219f71c9 Add a restriction to the SHELL and PERL directives.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-13 12:27:04 -07:00
Tom Eastep
e3f2c49c7e Remove level of indirection for the 'super' property
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-13 12:23:33 -07:00
Tom Eastep
fecd091078 Remove %zones{option}{nested}
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-13 11:31:13 -07:00
Tom Eastep
e0b360513c Remove a level of indirection for 'complex' zone flag.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-13 09:47:31 -07:00
Tom Eastep
01d99d4873 Move zone mss handling to the Rules File
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-12 15:59:35 -07:00
Tom Eastep
acb2e2a8ab Implement mss= in hosts file.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-12 15:14:35 -07:00
Tom Eastep
0223439e2b Don't compile if ${DESTDIR}
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-12 14:02:44 -07:00
Tom Eastep
fa9f8329b5 Apply two patches from Tuomo Soini
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-12 13:57:37 -07:00
Tom Eastep
4ffcd80b02 Don't test compilation if $DESTDIR
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-11 09:49:26 -07:00
Tom Eastep
48570227ba Big cleanup of TOS handling
- Validate settings/matches
- Allow setting in the tcrules file.
- Deprecate /etc/shorewall[6]/tos
2012-03-09 16:16:25 -08:00
Tom Eastep
fd5b7b20cf Remove trailing white-space
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-08 13:05:56 -08:00
Tom Eastep
c112f20e17 Tighten editing of LENGTH column(s)
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-07 14:07:04 -08:00
Tom Eastep
05f025e422 Don't install isusable script by default
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-07 07:46:53 -08:00
Tom Eastep
3ee9150deb Fix syntax error in the generated script
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-06 09:15:34 -08:00
Tom Eastep
b2842ae8d4 Don't allow reserved variables to be set in params
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-05 15:42:53 -08:00
Tom Eastep
dff5136134 Correct issues with debugging the generated script
a) Rename DEBUG to g_debug_iptablesb
b) Clear all of the tables prior to handling iptables-restore input.
2012-03-05 15:21:10 -08:00
Tom Eastep
1d249567ed Add unsubscribe instructions to the FAQ.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-05 13:32:12 -08:00
Tom Eastep
a84e131115 Fix bug in DSCP implementation.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-05 09:50:15 -08:00
Tom Eastep
4b74fe2823 Restore SAVE_IPSET functionality
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-01 07:53:42 -08:00
Tom Eastep
9493bda0cc Mention Shorewall-core in the 4.5.0 upgrade issues.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-01 07:28:16 -08:00
Tom Eastep
36d4fff7b2 Shorewall-init tweaks
1) Remove root check
2) Fix/add progress messages in the installer.

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-01 07:21:17 -08:00
Tom Eastep
67a1438a41 Tweak /sbin/shorewall-init
1) Make indentation consistent
2) Remove IPSET_SAVE logic

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-03-01 06:41:06 -08:00
Tom Eastep
aab6e67e70 Omit non-default geometry settings from updated shorewall.conf.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-29 12:34:06 -08:00
Tom Eastep
2397449fa4 Add /sbin/shorewall-init for use with service.d
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-29 08:39:27 -08:00
Tom Eastep
fc12125223 Include Shorewall status in the heading of the dump output
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-26 16:14:43 -08:00
Tom Eastep
61bf2d5bfd Fix installer
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-25 16:02:20 -08:00
Tom Eastep
bd9a3e5a3e Update the release model web page
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-25 08:24:48 -08:00
Tom Eastep
90b33af3bd Fix incorrect manpage
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-25 07:53:05 -08:00
Tom Eastep
016fe4bcf1 Merge branch 'master' of ssh://shorewall.git.sourceforge.net/gitroot/shorewall/shorewall
Conflicts:
	Shorewall-core/install.sh
	Shorewall/install.sh

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-25 07:30:07 -08:00
Roberto C. Sanchez
87381a0f65 FIx typos 2012-02-24 23:02:30 -05:00
Tom Eastep
47453a20f7 Tweak to Run-time gateway variables
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-24 09:02:04 -08:00
Tom Eastep
b78d4ca41f Correct typo
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-23 13:54:50 -08:00
Tom Eastep
7273f4d8d4 Implement run-time gateway variables.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-23 13:36:00 -08:00
Tom Eastep
37a3dbb6f6 Don't install SysV init script if systemd is specified.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-23 10:59:10 -08:00
Tom Eastep
c252005e25 Add support for packager's config file
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-23 10:07:02 -08:00
Tom Eastep
09ad6bba1a Fix Shorewall-core installer
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-22 15:59:28 -08:00
Tom Eastep
c975cddfda Correct init script installation
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-22 14:51:41 -08:00
Tom Eastep
a6afac0f3c Use standard rpm macros
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-22 13:32:10 -08:00
Tom Eastep
ef850e4537 Use standard rpm macros
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-22 12:40:16 -08:00
Tom Eastep
2624005fa8 Fix FORMAT-2 interfaces
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-21 16:41:56 -08:00
Tom Eastep
20f990f2eb Fix install on SuSE
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-21 14:24:50 -08:00
Tom Eastep
7de961ebfe Fix broken init scripts.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-21 13:16:12 -08:00
Tom Eastep
f6cc44eb6b Rename HOST -> TARGET and BUILD -> HOST
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-21 13:00:09 -08:00
Tom Eastep
3acd01a44d Rename some variables:
HOST -> TARGET
%initdir -> %shorewall_initdir

Also add %shorewall_target

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-21 12:34:41 -08:00
Tom Eastep
d5af9c360d Implement FORMAT-2 interfaces file.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-21 11:23:58 -08:00
Tom Eastep
2137840fec Fix bug in DSCP support
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-20 16:40:11 -08:00
Tom Eastep
ed9e03b095 Correct FEDORA/REDHAT fiasco
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-20 16:11:28 -08:00
Tom Eastep
3180e13719 Require LIBEXEC and LIBPERL to be absolute path names
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-20 12:04:00 -08:00
Tom Eastep
c751a0ada3 Documentation updates suggested by Jeffrey Spain.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-20 11:30:06 -08:00
Tom Eastep
9869b4c068 Rename environmental variables:
INSTALLSYS => BUILD
TARGET     => HOST

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-20 10:12:52 -08:00
Tom Eastep
8c981e0464 Cleanup of install scripts based on feedback from Mr. Dash4
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-20 10:08:42 -08:00
Tom Eastep
76f8a9e171 Update the Install article for 4.5.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-20 09:02:04 -08:00
Tom Eastep
a1ec1dc178 Add DSCP match support
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-20 08:47:48 -08:00
Tom Eastep
e2f4af6e48 Create a Perl-style switch statement to handle irregular entries in
the tcrules file.

Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-19 17:28:49 -08:00
Tom Eastep
b1272e8835 Add DSCP target support.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-19 17:04:16 -08:00
Tom Eastep
75d5957020 Unify 'dont_' chain flags
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-19 14:20:09 -08:00
Tom Eastep
1896e56894 Rework some newbie code in add_group_to_zone()
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-19 08:39:17 -08:00
Tom Eastep
7cd7f1ebbe Make zone-option hashes and constants global
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-19 08:30:39 -08:00
Tom Eastep
7fef97d92d Fix compiler crash from unknown interface
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-18 10:02:39 -08:00
Tom Eastep
cd3a9854f8 Change ipset flags error to a warning
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-18 08:22:16 -08:00
Tom Eastep
f8057fed88 Correct typo in the modified install scripts.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-18 08:21:50 -08:00
Tom Eastep
59950a7242 Add new install methodology to Shorewall-core
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-18 08:19:39 -08:00
Tom Eastep
6d13069ffb Correct usage text for 'update'.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-18 08:17:52 -08:00
Tom Eastep
59fea1a05d Add a SWITCH column to /etc/shorewall/masq
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-18 08:17:14 -08:00
Tom Eastep
1c7476fe61 Validate SOURCE/DEST fit for ipset flags
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-17 15:46:28 -08:00
Tom Eastep
58f0425d4a Correct a typo in the blrules manpages
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-17 15:33:45 -08:00
Tom Eastep
ee7ea4adb9 Unify the supported install script os/distro set.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-17 15:26:02 -08:00
Tom Eastep
8a3f1f7111 Merge branch '4.5.0' 2012-02-17 13:39:22 -08:00
Tom Eastep
33b0821f8d Separate install system from target system in the install.sh scripts
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-17 13:22:06 -08:00
Tom Eastep
7bf6419a7b Install the correct init script on Fedora 2012-02-15 17:19:54 -08:00
Tom Eastep
460efbac77 Merge branch '4.5.0' 2012-02-11 11:36:38 -08:00
Tom Eastep
f4be778b86 Restore 'update -b' functionality
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-07 07:38:07 -08:00
Tom Eastep
bd959884cc Don't require a MARK value on the default class.
Signed-off-by: Tom Eastep <teastep@shorewall.net>
2012-02-06 14:40:22 -08:00
125 changed files with 6601 additions and 3088 deletions

189
Shorewall-core/configure vendored Executable file
View File

@@ -0,0 +1,189 @@
#!/bin/bash
#
# Shorewall Packet Filtering Firewall RPM configuration program - V4.5
#
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
#
# (c) 2012 - Tom Eastep (teastep@shorewall.net)
#
# Shorewall documentation is available at http://www.shorewall.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of Version 2 of the GNU General Public License
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Usage: ./configure [ <option>=<setting> ] ...
#
#
################################################################################################
#
# Build updates this
#
VERSION=4.5.2.1
case "$BASH_VERSION" in
[4-9].*)
;;
*)
echo "ERROR: This program requires Bash 4.0 or later" >&2
exit 1
;;
esac
declare -A params
declare -A options
getfileparams() {
while read option; do
case $option in
\#*)
;;
*)
on=${option%=*}
ov=${option#*=}
ov=${ov%#*}
[ -n "$on" ] && options[${on}]="${ov}"
;;
esac
done
return 0
}
for p in $@; do
if [ -n "${p}" ]; then
declare -u pn
pn=${p%=*}
pn=${pn#--}
pv=${p#*=}
if [ -n "${pn}" ]; then
case ${pn} in
VENDOR)
pn=HOST
;;
SHAREDSTATEDIR)
pn=VARDIR
;;
DATADIR)
pn=SHAREDIR
;;
SYSCONFDIR)
pn=CONFDIR
;;
esac
params[${pn}]="${pv}"
else
echo "ERROR: Invalid option ($p)" >&2
exit 1
fi
fi
done
vendor=${params[HOST]}
if [ -z "$vendor" ]; then
case `uname` in
Darwin)
$params[HOST]=apple
rcfile=shorewallrc.apple
;;
cygwin*)
$params[HOST]=cygwin
rcfile=shorewallrc.cygwin
;;
*)
if [ -f /etc/debian_version ]; then
params[HOST]=debian
rcfile=shorewallrc.debian
elif [ -f /etc/redhat-release ]; then
params[HOST]=redhat
rcfile=shorewallrc.redhat
elif [ -f /etc/slackware-version ] ; then
params[HOST]=slackware
rcfile=shorewallrc.slackware
elif [ -f /etc/SuSE-release ]; then
params[HOST]=suse
rcfile=shorewallrc.suse
elif [ -f /etc/arch-release ] ; then
params[HOST]=archlinux
rcfile=shorewallrc.archlinux
else
params[HOST]=linux
rcfile=shorewallrc.default
fi
;;
esac
vendor=${params[HOST]}
elif [ $vendor = linux ]; then
rcfile=$shorewallrc.default;
else
rcfile=shorewallrc.$vendor
if [ ! -f $rcfile ]; then
echo "ERROR: $vendor is not a recognized host type" >&2
exit 1
fi
fi
if [ $vendor = linux ]; then
echo "INFO: Creating a generic Linux installation - " `date`;
else
echo "INFO: Creating a ${vendor}-specific installation - " `date`;
fi
echo
getfileparams < $rcfile || exit 1
for p in ${!params[@]}; do
options[${p}]="${params[${p}]}"
done
echo '#' > shorewallrc
echo "# Created by Shorewall Core version $VERSION configure - " `date` >> shorewallrc
echo '#' >> shorewallrc
if [ $# -gt 0 ]; then
echo "# Input: $@" >> shorewallrc
echo '#' >> shorewallrc
fi
for on in \
HOST \
PREFIX \
SHAREDIR \
LIBEXECDIR \
PERLLIBDIR \
CONFDIR \
SBINDIR \
MANDIR \
INITDIR \
INITSOURCE \
INITFILE \
AUXINITSOURCE \
AUXINITFILE \
SYSTEMD \
SYSCONFFILE \
SYSCONFDIR \
ANNOTATED \
VARDIR
do
echo "$on=${options[${on}]}"
echo "$on=${options[${on}]}" >> shorewallrc
done

154
Shorewall-core/configure.pl Executable file
View File

@@ -0,0 +1,154 @@
#! /usr/bin/perl -w
#
# Shorewall Packet Filtering Firewall RPM configuration program - V4.5
#
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
#
# (c) 2012 - Tom Eastep (teastep@shorewall.net)
#
# Shorewall documentation is available at http://www.shorewall.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of Version 2 of the GNU General Public License
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Usage: ./configure.pl <option>=<setting> ...
#
#
################################################################################################
use strict;
#
# Build updates this
#
use constant {
VERSION => '4.5.2.1'
};
my %params;
my %options;
my %aliases = ( VENDOR => 'HOST',
SHAREDSTATEDIR => 'VARDIR',
DATADIR => 'SHAREDIR',
SYSCONFDIR => 'CONFDIR' );
for ( @ARGV ) {
die "ERROR: Invalid option specification ( $_ )" unless /^(?:--)?(\w+)=(.*)$/;
my $pn = uc $1;
my $pv = $2 || '';
$pn = $aliases{$pn} if exists $aliases{$pn};
$params{$pn} = $pv;
}
my $vendor = $params{HOST};
my $rcfile;
my $rcfilename;
if ( defined $vendor ) {
$rcfilename = $vendor eq 'linux' ? 'shorewallrc.default' : 'shorewallrc.' . $vendor;
die qq("ERROR: $vendor" is not a recognized host type) unless -f $rcfilename;
} else {
if ( -f '/etc/debian_version' ) {
$vendor = 'debian';
$rcfilename = 'shorewallrc.debian';
} elsif ( -f '/etc/redhat-release' ){
$vendor = 'redhat';
$rcfilename = 'shorewallrc.redhat';
} elsif ( -f '/etc/slackware-version' ) {
$vendor = 'slackware';
$rcfilename = 'shorewallrc.slackware';
} elsif ( -f '/etc/SuSE-release' ) {
$vendor = 'suse';
$rcfilename = 'shorewallrc.suse';
} elsif ( -f '/etc/arch-release' ) {
$vendor = 'archlinux';
$rcfilename = 'shorewallrc.archlinux';
} elsif ( `uname` =~ '^Darwin' ) {
$vendor = 'apple';
$rcfilename = 'shorewallrc.apple';
} elsif ( `uname` =~ '^Cygwin' ) {
$vendor = 'cygwin';
$rcfilename = 'shorewallrc.cygwin';
} else {
$vendor = 'linux';
$rcfilename = 'shorewallrc.default';
}
$params{HOST} = $vendor;
}
my @localtime = localtime;
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
if ( $vendor eq 'linux' ) {
printf "INFO: Creating a generic Linux installation - %s %2d %04d %02d:%02d:%02d\n\n", $abbr[$localtime[4]], $localtime[3], 1900 + $localtime[5] , @localtime[2,1,0];;
} else {
printf "INFO: Creating a %s-specific installation - %s %2d %04d %02d:%02d:%02d\n\n", $vendor, $abbr[$localtime[4]], $localtime[3], 1900 + $localtime[5] , @localtime[2,1,0];;
}
open $rcfile, '<', $rcfilename or die "Unable to open $rcfilename for input: $!";
while ( <$rcfile> ) {
s/\s*#.*//;
unless ( /^\s*$/ ) {
chomp;
die "ERROR: Invalid entry ($_) in $rcfilename, line $." unless /\s*(\w+)=(.*)/;
$options{$1} = $2;
}
}
close $rcfile;
while ( my ( $p, $v ) = each %params ) {
$options{$p} = ${v};
}
my $outfile;
open $outfile, '>', 'shorewallrc' or die "Can't open 'shorewallrc' for output: $!";
printf $outfile "#\n# Created by Shorewall Core version %s configure.pl - %s %2d %04d %02d:%02d:%02d\n#\n", VERSION, $abbr[$localtime[4]], $localtime[3], 1900 + $localtime[5] , @localtime[2,1,0];
print $outfile "# Input: @ARGV\n#\n" if @ARGV;
for ( qw/ HOST
PREFIX
SHAREDIR
LIBEXECDIR
PERLLIBDIR
CONFDIR
SBINDIR
MANDIR
INITDIR
INITSOURCE
INITFILE
AUXINITSOURCE
AUXINITFILE
SYSTEMD
SYSCONFFILE
SYSCONFDIR
ANNOTATED
VARDIR / ) {
my $val = $options{$_} || '';
print "$_=$val\n";
print $outfile "$_=$val\n";
}
close $outfile;
1;

View File

@@ -27,14 +27,18 @@ VERSION=xxx #The Build script inserts the actual version
usage() # $1 = exit status usage() # $1 = exit status
{ {
ME=$(basename $0) ME=$(basename $0)
echo "usage: $ME" echo "usage: $ME [ <configuration-file> ] "
echo " $ME -v" echo " $ME -v"
echo " $ME -h" echo " $ME -h"
echo " $ME -s"
echo " $ME -f"
exit $1 exit $1
} }
fatal_error()
{
echo " ERROR: $@" >&2
exit 1
}
split() { split() {
local ifs local ifs
ifs=$IFS ifs=$IFS
@@ -87,69 +91,16 @@ install_file() # $1 = source $2 = target $3 = mode
run_install $T $OWNERSHIP -m $3 $1 ${2} run_install $T $OWNERSHIP -m $3 $1 ${2}
} }
[ -n "$DESTDIR" ] || DESTDIR="$PREFIX" require()
{
eval [ -n "\$$1" ] || fatal_error "Required option $1 not set"
}
cd "$(dirname $0)"
# #
# Parse the run line # Parse the run line
# #
# ARGS is "yes" if we've already parsed an argument
#
T="-T"
[ -n "${LIBEXEC:=/usr/share}" ]
[ -n "${PERLLIB:=/usr/share/shorewall}" ]
MACHOST=
case "$LIBEXEC" in
/*)
;;
*)
LIBEXEC=/usr/${LIBEXEC}
;;
esac
case "$PERLLIB" in
/*)
;;
*)
PERLLIB=/usr/${PERLLIB}
;;
esac
INSTALLD='-D'
case $(uname) in
CYGWIN*)
if [ -z "$DESTDIR" ]; then
DEST=
INIT=
fi
OWNER=$(id -un)
GROUP=$(id -gn)
CYGWIN=Yes
;;
Darwin)
if [ -z "$DESTDIR" ]; then
DEST=
INIT=
fi
[ -z "$OWNER" ] && OWNER=root
[ -z "$GROUP" ] && GROUP=wheel
MAC=Yes
MACHOST=Yes
INSTALLD=
T=
;;
*)
[ -z "$OWNER" ] && OWNER=root
[ -z "$GROUP" ] && GROUP=root
;;
esac
OWNERSHIP="-o $OWNER -g $GROUP"
finished=0 finished=0
while [ $finished -eq 0 ]; do while [ $finished -eq 0 ]; do
@@ -168,14 +119,6 @@ while [ $finished -eq 0 ]; do
echo "Shorewall Firewall Installer Version $VERSION" echo "Shorewall Firewall Installer Version $VERSION"
exit 0 exit 0
;; ;;
a*)
ANNOTATED=Yes
option=${option#a}
;;
p*)
ANNOTATED=
option=${option#p}
;;
*) *)
usage 1 usage 1
;; ;;
@@ -185,102 +128,227 @@ while [ $finished -eq 0 ]; do
shift shift
;; ;;
*) *)
[ -n "$option" ] && usage 1
finished=1 finished=1
;; ;;
esac esac
done done
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin #
# Read the RC file
#
if [ $# -eq 0 ]; then
if [ -f ./shorewallrc ]; then
. ./shorewallrc
file=./shorewallrc
elif [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc || exit 1
file=~/.shorewallrc
elif [ -f /usr/share/shorewall/shorewallrc ]; then
. /usr/share/shorewall/shorewallrc
file=/usr/share/shorewall/shorewallrc
else
fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
fi
elif [ $# -eq 1 ]; then
file=$1
case $file in
/*|.*)
;;
*)
file=./$file || exit 1
;;
esac
. $file
else
usage 1
fi
for var in SHAREDIR LIBEXECDIR PERLLIBDIR CONFDIR SBINDIR VARDIR; do
require $var
done
[ "${INITFILE}" != 'none/' ] && require INITSOURCE && require INITDIR
T="-T"
INSTALLD='-D'
if [ -z "$BUILD" ]; then
case $(uname) in
cygwin*)
BUILD=cygwin
;;
Darwin)
BUILD=apple
;;
*)
if [ -f /etc/debian_version ]; then
BUILD=debian
elif [ -f /etc/redhat-release ]; then
BUILD=redhat
elif [ -f /etc/slackware-version ] ; then
BUILD=slackware
elif [ -f /etc/SuSE-release ]; then
BUILD=suse
elif [ -f /etc/arch-release ] ; then
BUILD=archlinux
else
BUILD=linux
fi
;;
esac
fi
case $BUILD in
cygwin*)
if [ -z "$DESTDIR" ]; then
DEST=
INIT=
fi
OWNER=$(id -un)
GROUP=$(id -gn)
;;
apple)
if [ -z "$DESTDIR" ]; then
DEST=
INIT=
SPARSE=Yes
fi
[ -z "$OWNER" ] && OWNER=root
[ -z "$GROUP" ] && GROUP=wheel
INSTALLD=
T=
;;
*)
[ -z "$OWNER" ] && OWNER=root
[ -z "$GROUP" ] && GROUP=root
;;
esac
OWNERSHIP="-o $OWNER -g $GROUP"
# #
# Determine where to install the firewall script # Determine where to install the firewall script
# #
[ -n "$HOST" ] || HOST=$BUILD
case "$HOST" in
cygwin)
echo "Installing Cygwin-specific configuration..."
;;
apple)
echo "Installing Mac-specific configuration...";
;;
debian|redhat|slackware|archlinux|linux|suse)
;;
*)
echo "ERROR: Unknown HOST \"$HOST\"" >&2
exit 1;
;;
esac
if [ -z "$file" ]; then
if $HOST = linux; then
file=shorewallrc.default
else
file=shorewallrc.${HOST}
fi
echo "You have not specified a configuration file and ~/.shorewallrc does not exist" >&2
echo "Shorewall-core $VERSION has determined that the $file configuration is appropriate for your system" >&2
echo "Please review the settings in that file. If you wish to change them, make a copy and modify the copy" >&2
echo "Then re-run install.sh passing either $file or the name of your modified copy" >&2
echo "" >&2
echo "Example:" >&2
echo "" >&2
echo " ./install.sh $file" &>2
fi
if [ -n "$DESTDIR" ]; then if [ -n "$DESTDIR" ]; then
if [ -z "$CYGWIN" ]; then if [ $BUILD != cygwin ]; then
if [ `id -u` != 0 ] ; then if [ `id -u` != 0 ] ; then
echo "Not setting file owner/group permissions, not running as root." echo "Not setting file owner/group permissions, not running as root."
OWNERSHIP="" OWNERSHIP=""
fi fi
fi fi
install -d $OWNERSHIP -m 755 ${DESTDIR}/sbin
install -d $OWNERSHIP -m 755 ${DESTDIR}${DEST}
CYGWIN=
MAC=
else
if [ -n "$CYGWIN" ]; then
echo "Installing Cygwin-specific configuration..."
elif [ -n "$MAC" ]; then
echo "Installing Mac-specific configuration..."
else
if [ -f /etc/debian_version ]; then
echo "Installing Debian-specific configuration..."
DEBIAN=yes
elif [ -f /etc/redhat-release ]; then
echo "Installing Redhat/Fedora-specific configuration..."
FEDORA=yes
elif [ -f /etc/slackware-version ] ; then
echo "Installing Slackware-specific configuration..."
DEST="/etc/rc.d"
MANDIR="/usr/man"
SLACKWARE=yes
elif [ -f /etc/arch-release ] ; then
echo "Installing ArchLinux-specific configuration..."
DEST="/etc/rc.d"
INIT="shorewall"
ARCHLINUX=yes
fi
fi
fi fi
#
# Change to the directory containing this script
#
cd "$(dirname $0)"
echo "Installing Shorewall Core Version $VERSION" echo "Installing Shorewall Core Version $VERSION"
# #
# Create /usr/share/shorewall # Create directories
# #
mkdir -p ${DESTDIR}${LIBEXEC}/shorewall mkdir -p ${DESTDIR}${LIBEXECDIR}/shorewall
chmod 755 ${DESTDIR}/usr/share/shorewall chmod 755 ${DESTDIR}${LIBEXECDIR}/shorewall
mkdir -p ${DESTDIR}${SHAREDIR}/shorewall
chmod 755 ${DESTDIR}${SHAREDIR}/shorewall
mkdir -p ${DESTDIR}${CONFDIR}
chmod 755 ${DESTDIR}${CONFDIR}
if [ -n "${SYSCONFDIR}" ]; then
mkdir -p ${DESTDIR}${SYSCONFDIR}
chmod 755 ${DESTDIR}${SYSCONFDIR}
fi
if [ -n "${SYSTEMD}" ]; then
mkdir -p ${DESTDIR}${SYSTEMD}
chmod 755 ${DESTDIR}${SYSTEMD}
fi
mkdir -p ${DESTDIR}${SBINDIR}
chmod 755 ${DESTDIR}${SBINDIR}
mkdir -p ${DESTDIR}${MANDIR}
chmod 755 ${DESTDIR}${MANDIR}
#
# Note: ${VARDIR} is created at run-time since it has always been
# a relocatable directory on a per-product basis
# #
# Install wait4ifup # Install wait4ifup
# #
install_file wait4ifup ${DESTDIR}${LIBEXEC}/shorewall/wait4ifup 0755 install_file wait4ifup ${DESTDIR}${LIBEXECDIR}/shorewall/wait4ifup 0755
echo echo
echo "wait4ifup installed in ${DESTDIR}${LIBEXEC}/shorewall/wait4ifup" echo "wait4ifup installed in ${DESTDIR}${LIBEXECDIR}/shorewall/wait4ifup"
# #
# Install the libraries # Install the libraries
# #
for f in lib.* ; do for f in lib.* ; do
install_file $f ${DESTDIR}/usr/share/shorewall/$f 0644 install_file $f ${DESTDIR}${SHAREDIR}/shorewall/$f 0644
echo "Library ${f#*.} file installed as ${DESTDIR}/usr/share/shorewall/$f" echo "Library ${f#*.} file installed as ${DESTDIR}${SHAREDIR}/shorewall/$f"
done done
if [ -z "$MACHOST" ]; then
eval sed -i \'s\|g_libexec=.\*\|g_libexec=$LIBEXEC\|\' ${DESTDIR}/usr/share/shorewall/lib.cli
eval sed -i \'s\|g_perllib=.\*\|g_perllib=$PERLLIB\|\' ${DESTDIR}/usr/share/shorewall/lib.cli
else
eval sed -i \'\' -e \'s\|g_libexec=.\*\|g_libexec=$LIBEXEC\|\' ${DESTDIR}/usr/share/shorewall/lib.cli
eval sed -i \'\' -e \'s\|g_perllib=.\*\|g_perllib=$PERLLIB\|\' ${DESTDIR}/usr/share/shorewall/lib.cli
fi
# #
# Symbolically link 'functions' to lib.base # Symbolically link 'functions' to lib.base
# #
ln -sf lib.base ${DESTDIR}/usr/share/shorewall/functions ln -sf lib.base ${DESTDIR}${SHAREDIR}/shorewall/functions
# #
# Create the version file # Create the version file
# #
echo "$VERSION" > ${DESTDIR}/usr/share/shorewall/coreversion echo "$VERSION" > ${DESTDIR}${SHAREDIR}/shorewall/coreversion
chmod 644 ${DESTDIR}/usr/share/shorewall/coreversion chmod 644 ${DESTDIR}${SHAREDIR}/shorewall/coreversion
[ $file != "${SHAREDIR}/shorewall/shorewallrc" ] && cp $file ${DESTDIR}${SHAREDIR}/shorewall/shorewallrc
[ -z "${DESTDIR}" ] && [ ! -f ~/.shorewallrc ] && cp ${SHAREDIR}/shorewall/shorewallrc ~/.shorewallrc
if [ ${SHAREDIR} != /usr/share ]; then
for f in lib.*; do
if [ $BUILD != apple ]; then
eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}/${SHAREDIR}/shorewall/$f
else
eval sed -i \'\' -e \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}/${SHAREDIR}/shorewall/$f
fi
done
fi
# #
# Report Success # Report Success
# #

View File

@@ -27,50 +27,57 @@
# and /usr/share/shorewall[6]-lite/shorecap. # and /usr/share/shorewall[6]-lite/shorecap.
# #
SHOREWALL_LIBVERSION=40500 SHOREWALL_LIBVERSION=40502
SHOREWALL_CAPVERSION=40501 SHOREWALL_CAPVERSION=40502
[ -n "${g_program:=shorewall}" ] [ -n "${g_program:=shorewall}" ]
if [ -z "$g_readrc" ]; then
#
# This is modified by the installer when ${SHAREDIR} != /usr/share
#
. /usr/share/shorewall/shorewallrc
g_libexec="$LIBEXECDIR"
g_sharedir="$SHAREDIR"/$g_program
g_sbindir="$SBINDIR"
g_perllib="$PERLLIBDIR"
g_vardir="$VARDIR"
g_confdir="$CONFDIR"/$g_program
g_readrc=1
fi
g_basedir=${SHAREDIR}/shorewall
case $g_program in case $g_program in
shorewall) shorewall)
SHAREDIR=/usr/share/shorewall
CONFDIR=/etc/shorewall
g_product="Shorewall" g_product="Shorewall"
g_family=4 g_family=4
g_tool= g_tool=
g_basedir=/usr/share/shorewall
g_lite= g_lite=
;; ;;
shorewall6) shorewall6)
SHAREDIR=/usr/share/shorewall6
CONFDIR=/etc/shorewall6
g_product="Shorewall6" g_product="Shorewall6"
g_family=6 g_family=6
g_tool= g_tool=
g_basedir=/usr/share/shorewall
g_lite= g_lite=
;; ;;
shorewall-lite) shorewall-lite)
SHAREDIR=/usr/share/shorewall-lite
CONFDIR=/etc/shorewall-lite
g_product="Shorewall Lite" g_product="Shorewall Lite"
g_family=4 g_family=4
g_tool=iptables g_tool=iptables
g_basedir=/usr/share/shorewall-lite
g_lite=Yes g_lite=Yes
;; ;;
shorewall6-lite) shorewall6-lite)
SHAREDIR=/usr/share/shorewall6-lite
CONFDIR=/etc/shorewall6-lite
g_product="Shorewall6 Lite" g_product="Shorewall6 Lite"
g_family=6 g_family=6
g_tool=ip6tables g_tool=ip6tables
g_basedir=/usr/share/shorewall6-lite
g_lite=Yes g_lite=Yes
;; ;;
esac esac
VARDIR=${VARDIR}/${g_program}
# #
# Conditionally produce message # Conditionally produce message
# #
@@ -186,7 +193,7 @@ mutex_off()
rm -f ${LOCKFILE:=${VARDIR}/lock} rm -f ${LOCKFILE:=${VARDIR}/lock}
} }
[ -z "$LEFTSHIFT" ] && . /usr/share/shorewall/lib.common [ -z "$LEFTSHIFT" ] && . ${g_basedir}/lib.common
# #
# Validate an IP address # Validate an IP address
@@ -344,7 +351,7 @@ ip_vlsm() {
# #
ensure_config_path() { ensure_config_path() {
local F local F
F=${SHAREDIR}/configpath F=${g_sharedir}/configpath
if [ -z "$CONFIG_PATH" ]; then if [ -z "$CONFIG_PATH" ]; then
[ -f $F ] || { echo " ERROR: $F does not exist"; exit 2; } [ -f $F ] || { echo " ERROR: $F does not exist"; exit 2; }
. $F . $F
@@ -455,14 +462,14 @@ mktempfile() {
else else
case "$MKTEMP" in case "$MKTEMP" in
BSD) BSD)
mktemp /tmp/shorewall.XXXXXX mktemp ${TMPDIR:-/tmp}/shorewall.XXXXXX
;; ;;
STD) STD)
mktemp -t shorewall.XXXXXX mktemp -t shorewall.XXXXXX
;; ;;
None) None)
rm -f /tmp/shorewall-$$ rm -f ${TMPDIR:-/tmp}/shorewall-$$
> /tmp/shorewall-$$ && echo /tmp/shorewall-$$ > ${TMPDIR:-}/shorewall-$$ && echo ${TMPDIR:-/tmp}/shorewall-$$
;; ;;
*) *)
error_message "ERROR:Internal error in mktempfile" error_message "ERROR:Internal error in mktempfile"

View File

@@ -23,7 +23,25 @@
# This library contains the command processing code common to /sbin/shorewall[6] and # This library contains the command processing code common to /sbin/shorewall[6] and
# /sbin/shorewall[6]-lite. # /sbin/shorewall[6]-lite.
# #
. /usr/share/shorewall/lib.base
if [ -z "$g_readrc" ]; then
#
# This is modified by the installer when ${SHAREDIR} <> /usr/share
#
. /usr/share/shorewall/shorewallrc
g_libexec="$LIBEXECDIR"
g_sharedir="$SHAREDIR"/$g_program
g_sbindir="$SBINDIR"
g_perllib="$PERLLIBDIR"
g_vardir="$VARDIR"
g_confdir="$CONFDIR"/$g_program
g_readrc=1
fi
. ${SHAREDIR}/shorewall/lib.base
# #
# Fatal Error # Fatal Error
# #
@@ -438,16 +456,28 @@ sort_routes() {
done | sort -r | while read dest rest; do echo $rest; done done | sort -r | while read dest rest; do echo $rest; done
} }
#
# Isolate the table in the routing rules being read from stdin.
# Piping through sed to remove trailing whitespace works around
# recent 'features' in dash and ip.
#
find_tables() {
sed -r 's/[[:space:]]+$//' | while read rule; do
echo ${rule##* }
done
}
# #
# Show routing configuration # Show routing configuration
# #
show_routing() { show_routing() {
local rule
local table
if [ -n "$(ip -$g_family rule list)" ]; then if [ -n "$(ip -$g_family rule list)" ]; then
heading "Routing Rules" heading "Routing Rules"
ip -$g_family rule list ip -$g_family rule list
ip -$g_family rule list | while read rule; do ip -$g_family rule list | find_tables | sort -u | while read table; do
echo ${rule##* }
done | sort -u | while read table; do
heading "Table $table:" heading "Table $table:"
if [ $g_family -eq 6 ]; then if [ $g_family -eq 6 ]; then
ip -$g_family -o route list table $table | fgrep -v cache ip -$g_family -o route list table $table | fgrep -v cache
@@ -543,11 +573,11 @@ version_command() {
[ $# -gt 0 ] && usage 1 [ $# -gt 0 ] && usage 1
if [ -n "$all" ]; then if [ -n "$all" ]; then
echo "shorewall-core: $(cat /usr/share/shorewall/coreversion)" echo "shorewall-core: $(cat $g_sharedir/coreversion)"
for product in shorewall shorewall6 shorewall-lite shorewall6-lite shorewall-init; do for product in shorewall shorewall6 shorewall-lite shorewall6-lite shorewall-init; do
if [ -f /usr/share/$product/version ]; then if [ -f ${SHAREDIR}/$product/version ]; then
echo "$product: $(cat /usr/share/$product/version)" echo "$product: $(cat ${SHAREDIR}/$product/version)"
fi fi
done done
else else
@@ -837,16 +867,20 @@ show_command() {
show_routing show_routing
;; ;;
config) config)
. ${SHAREDIR}/configpath . ${g_sharedir}/configpath
if [ -n "$g_filemode" ]; then if [ -n "$g_filemode" ]; then
echo "CONFIG_PATH=$CONFIG_PATH" echo "CONFIG_PATH=$CONFIG_PATH"
echo "VARDIR=$VARDIR" echo "VARDIR=$VARDIR"
echo "LIBEXEC=$g_libexec" echo "LIBEXEC=$g_libexec"
[ -n "$g_lite" ] && ${VARDIR} ne /var/lib/$program && echo "LITEDIR=${VARDIR}" echo "SBINDIR=$g_sbindir"
echo "CONFDIR=${CONFDIR}"
[ -n "$g_lite" ] && [ ${VARDIR} != /var/lib/$g_program ] && echo "LITEDIR=${VARDIR}"
else else
echo "Default CONFIG_PATH is $CONFIG_PATH" echo "Default CONFIG_PATH is $CONFIG_PATH"
echo "Default VARDIR is /var/lib/$g_program" echo "Default VARDIR is /var/lib/$g_program"
echo "LIBEXEC is $g_libexec" echo "LIBEXEC is $g_libexec"
echo "SBINDIR is $g_sbindir"
echo "CONFDIR is ${CONFDIR}"
[ -n "$g_lite" ] && [ ${VARDIR} != /var/lib/$g_program ] && echo "LITEDIR is ${VARDIR}" [ -n "$g_lite" ] && [ ${VARDIR} != /var/lib/$g_program ] && echo "LITEDIR is ${VARDIR}"
fi fi
;; ;;
@@ -907,10 +941,10 @@ show_command() {
echo "forwardUPnP # Allow traffic that upnpd has redirected from" echo "forwardUPnP # Allow traffic that upnpd has redirected from"
echo "rejNotSyn # Silently Reject Non-syn TCP packets" echo "rejNotSyn # Silently Reject Non-syn TCP packets"
if [ -f ${CONFDIR}/actions ]; then if [ -f ${g_confdir}/actions ]; then
cat ${SHAREDIR}/actions.std ${CONFDIR}/actions | grep -Ev '^\#|^$' cat ${g_sharedir}/actions.std ${g_confdir}/actions | grep -Ev '^\#|^$'
else else
grep -Ev '^\#|^$' ${SHAREDIR}/actions.std grep -Ev '^\#|^$' ${g_sharedir}/actions.std
fi fi
return return
@@ -1108,11 +1142,11 @@ do_dump_command() {
echo "$g_product $SHOREWALL_VERSION Dump at $g_hostname - $(date)" echo "$g_product $SHOREWALL_VERSION Dump at $g_hostname - $(date)"
echo echo
if [ $g_family -eq 6 ] && [ -f /usr/share/shorewall/version ]; then if [ $g_family -eq 6 ] && [ -f ${SHAREDIR}/shorewall/version ]; then
echo " Shorewall $(cat /usr/share/shorewall/version)" echo " Shorewall $(cat ${SHAREDIR}/shorewall/version)"
echo echo
fi fi
show_status
show_reset show_reset
host=$(echo $g_hostname | sed 's/\..*$//') host=$(echo $g_hostname | sed 's/\..*$//')
$g_tool -L $g_ipt_options $g_tool -L $g_ipt_options
@@ -1908,6 +1942,7 @@ determine_capabilities() {
IPRANGE_MATCH= IPRANGE_MATCH=
RECENT_MATCH= RECENT_MATCH=
OWNER_MATCH= OWNER_MATCH=
OWNER_NAME_MATCH=
IPSET_MATCH= IPSET_MATCH=
OLD_IPSET_MATCH= OLD_IPSET_MATCH=
IPSET_V5= IPSET_V5=
@@ -1957,6 +1992,8 @@ determine_capabilities() {
CT_TARGET= CT_TARGET=
STATISTIC_MATCH= STATISTIC_MATCH=
IMQ_TARGET= IMQ_TARGET=
DSCP_MATCH=
DSCP_TARGET=
chain=fooX$$ chain=fooX$$
@@ -2044,6 +2081,11 @@ determine_capabilities() {
qt $g_tool -A $chain -m recent --update -j ACCEPT && RECENT_MATCH=Yes qt $g_tool -A $chain -m recent --update -j ACCEPT && RECENT_MATCH=Yes
qt $g_tool -A $chain -m owner --uid-owner 0 -j ACCEPT && OWNER_MATCH=Yes qt $g_tool -A $chain -m owner --uid-owner 0 -j ACCEPT && OWNER_MATCH=Yes
local name
name=$(id -un 2> /dev/null)
[ -n "$name" ] && qt $g_tool -A $chain -m owner --uid-owner $name -j ACCEPT && OWNER_NAME_MATCH=Yes
if qt $g_tool -A $chain -m connmark --mark 2 -j ACCEPT; then if qt $g_tool -A $chain -m connmark --mark 2 -j ACCEPT; then
CONNMARK_MATCH=Yes CONNMARK_MATCH=Yes
qt $g_tool -A $chain -m connmark --mark 2/0xFF -j ACCEPT && XCONNMARK_MATCH=Yes qt $g_tool -A $chain -m connmark --mark 2/0xFF -j ACCEPT && XCONNMARK_MATCH=Yes
@@ -2081,10 +2123,14 @@ determine_capabilities() {
qt $g_tool -t mangle -A $chain -j CLASSIFY --set-class 1:1 && CLASSIFY_TARGET=Yes qt $g_tool -t mangle -A $chain -j CLASSIFY --set-class 1:1 && CLASSIFY_TARGET=Yes
qt $g_tool -t mangle -A $chain -j IPMARK --addr src && IPMARK_TARGET=Yes qt $g_tool -t mangle -A $chain -j IPMARK --addr src && IPMARK_TARGET=Yes
qt $g_tool -t mangle -A $chain -p tcp -j TPROXY --on-port 0 --tproxy-mark 1 && TPROXY_TARGET=Yes qt $g_tool -t mangle -A $chain -p tcp -j TPROXY --on-port 0 --tproxy-mark 1 && TPROXY_TARGET=Yes
qt $g_tool -t mangle -A $chain -j IMQ --todev 0 && IMQ_TARGET=Yes
qt $g_tool -t mangle -A $chain -m dscp --dscp 0 && DSCP_MATCH=Yes
qt $g_tool -t mangle -A $chain -j DSCP --set-dscp 0 && DSCP_TARGET=Yes
qt $g_tool -t mangle -F $chain qt $g_tool -t mangle -F $chain
qt $g_tool -t mangle -X $chain qt $g_tool -t mangle -X $chain
qt $g_tool -t mangle -L FORWARD -n && MANGLE_FORWARD=Yes qt $g_tool -t mangle -L FORWARD -n && MANGLE_FORWARD=Yes
qt $g_tool -t mangle -A $chain -j IMQ --todev 0 && IMQ_TARGET=Yes
fi fi
qt $g_tool -t raw -L -n && RAW_TABLE=Yes qt $g_tool -t raw -L -n && RAW_TABLE=Yes
@@ -2203,79 +2249,82 @@ report_capabilities() {
if [ $VERBOSITY -gt 1 ]; then if [ $VERBOSITY -gt 1 ]; then
echo "$g_product has detected the following iptables/netfilter capabilities:" echo "$g_product has detected the following iptables/netfilter capabilities:"
report_capability "NAT" $NAT_ENABLED report_capability "NAT (NAT_ENABLED)" $NAT_ENABLED
report_capability "Packet Mangling" $MANGLE_ENABLED report_capability "Packet Mangling (MANGLE_ENABLED)" $MANGLE_ENABLED
report_capability "Multi-port Match" $MULTIPORT report_capability "Multi-port Match (MULTIPORT)" $MULTIPORT
[ -n "$MULTIPORT" ] && report_capability "Extended Multi-port Match" $XMULTIPORT [ -n "$MULTIPORT" ] && report_capability "Extended Multi-port Match (XMULIPORT)" $XMULTIPORT
report_capability "Connection Tracking Match" $CONNTRACK_MATCH report_capability "Connection Tracking Match (CONNTRACK_MATCH)" $CONNTRACK_MATCH
if [ -n "$CONNTRACK_MATCH" ]; then if [ -n "$CONNTRACK_MATCH" ]; then
report_capability "Extended Connection Tracking Match Support" $NEW_CONNTRACK_MATCH report_capability "Extended Connection Tracking Match Support (NEW_CONNTRACK_MATCH)" $NEW_CONNTRACK_MATCH
[ -n "$OLD_CONNTRACK_MATCH" ] && report_capability "Old Connection Tracking Match Syntax" $OLD_CONNTRACK_MATCH [ -n "$OLD_CONNTRACK_MATCH" ] && report_capability "Old Connection Tracking Match Syntax (OLD_CONNTRACK_MATCH)" $OLD_CONNTRACK_MATCH
fi fi
report_capability "Packet Type Match" $USEPKTTYPE report_capability "Packet Type Match (USEPKTTYPE)" $USEPKTTYPE
report_capability "Policy Match" $POLICY_MATCH report_capability "Policy Match (POLICY_MATCH)" $POLICY_MATCH
report_capability "Physdev Match" $PHYSDEV_MATCH report_capability "Physdev Match (PHYSDEV_MATCH)" $PHYSDEV_MATCH
report_capability "Physdev-is-bridged Support" $PHYSDEV_BRIDGE report_capability "Physdev-is-bridged Support (PHYSDEV_BRIDGE)" $PHYSDEV_BRIDGE
report_capability "Packet length Match" $LENGTH_MATCH report_capability "Packet length Match (LENGTH_MATCH)" $LENGTH_MATCH
report_capability "IP range Match" $IPRANGE_MATCH report_capability "IP range Match(IPRANGE_MATCH)" $IPRANGE_MATCH
report_capability "Recent Match" $RECENT_MATCH report_capability "Recent Match (RECENT_MATCH)" $RECENT_MATCH
report_capability "Owner Match" $OWNER_MATCH report_capability "Owner Match (OWNER_MATCH)" $OWNER_MATCH
report_capability "Owner Name Match (OWNER_NAME_MATCH)" $OWNER_NAME_MATCH
if [ -n "$IPSET_MATCH" ]; then if [ -n "$IPSET_MATCH" ]; then
report_capability "Ipset Match" $IPSET_MATCH report_capability "Ipset Match (IPSET_MATCH)" $IPSET_MATCH
[ -n "$OLD_IPSET_MATCH" ] && report_capability "OLD_Ipset Match" $OLD_IPSET_MATCH [ -n "$OLD_IPSET_MATCH" ] && report_capability "OLD_Ipset Match (OLD_IPSET_MATCH)" $OLD_IPSET_MATCH
fi fi
report_capability "CONNMARK Target" $CONNMARK report_capability "CONNMARK Target (CONNMARK)" $CONNMARK
[ -n "$CONNMARK" ] && report_capability "Extended CONNMARK Target" $XCONNMARK [ -n "$CONNMARK" ] && report_capability "Extended CONNMARK Target (XCONNMARK)" $XCONNMARK
report_capability "Connmark Match" $CONNMARK_MATCH report_capability "Connmark Match (CONNMARK_MATCH)" $CONNMARK_MATCH
[ -n "$CONNMARK_MATCH" ] && report_capability "Extended Connmark Match" $XCONNMARK_MATCH [ -n "$CONNMARK_MATCH" ] && report_capability "Extended Connmark Match (XCONNMARK_MATCH)" $XCONNMARK_MATCH
report_capability "Raw Table" $RAW_TABLE report_capability "Raw Table (RAW_TABLE)" $RAW_TABLE
report_capability "Rawpost Table" $RAWPOST_TABLE report_capability "Rawpost Table (RAWPOST_TABLE)" $RAWPOST_TABLE
report_capability "IPP2P Match" $IPP2P_MATCH report_capability "IPP2P Match (IPP2P_MATCH)" $IPP2P_MATCH
[ -n "$OLD_IPP2P_MATCH" ] && report_capability "Old IPP2P Match Syntax" $OLD_IPP2P_MATCH [ -n "$OLD_IPP2P_MATCH" ] && report_capability "Old IPP2P Match Syntax (OLD_IPP2P_MATCH)" $OLD_IPP2P_MATCH
report_capability "CLASSIFY Target" $CLASSIFY_TARGET report_capability "CLASSIFY Target (CLASSIFY_TARGET)" $CLASSIFY_TARGET
report_capability "Extended REJECT" $ENHANCED_REJECT report_capability "Extended REJECT (ENHANCED_REJECT)" $ENHANCED_REJECT
report_capability "Repeat match" $KLUDGEFREE report_capability "Repeat match (KLUDGEFREE)" $KLUDGEFREE
report_capability "MARK Target" $MARK report_capability "MARK Target (MARK)" $MARK
[ -n "$MARK" ] && report_capability "Extended MARK Target" $XMARK [ -n "$MARK" ] && report_capability "Extended MARK Target (XMARK)" $XMARK
[ -n "$XMARK" ] && report_capability "Extended MARK Target 2" $EXMARK [ -n "$XMARK" ] && report_capability "Extended MARK Target 2 (EXMARK)" $EXMARK
report_capability "Mangle FORWARD Chain" $MANGLE_FORWARD report_capability "Mangle FORWARD Chain (MANGLE_FORWARD)" $MANGLE_FORWARD
report_capability "Comments" $COMMENTS report_capability "Comments (COMMENTS)" $COMMENTS
report_capability "Address Type Match" $ADDRTYPE report_capability "Address Type Match (ADDRTYPE)" $ADDRTYPE
report_capability "TCPMSS Match" $TCPMSS_MATCH report_capability "TCPMSS Match (TCPMSS_MATCH)" $TCPMSS_MATCH
report_capability "Hashlimit Match" $HASHLIMIT_MATCH report_capability "Hashlimit Match (HASHLIMIT_MATCH)" $HASHLIMIT_MATCH
[ -n "$OLD_HL_MATCH" ] && report_capability "Old Hashlimit Match" $OLD_HL_MATCH [ -n "$OLD_HL_MATCH" ] && report_capability "Old Hashlimit Match (OLD_HL_MATCH)" $OLD_HL_MATCH
report_capability "NFQUEUE Target" $NFQUEUE_TARGET report_capability "NFQUEUE Target (NFQUEUE_TARGET)" $NFQUEUE_TARGET
report_capability "Realm Match" $REALM_MATCH report_capability "Realm Match (REALM_MATCH)" $REALM_MATCH
report_capability "Helper Match" $HELPER_MATCH report_capability "Helper Match (HELPER_MATCH)" $HELPER_MATCH
report_capability "Connlimit Match" $CONNLIMIT_MATCH report_capability "Connlimit Match (CONNLIMIT_MATCH)" $CONNLIMIT_MATCH
report_capability "Time Match" $TIME_MATCH report_capability "Time Match (TIME_MATCH)" $TIME_MATCH
report_capability "Goto Support" $GOTO_TARGET report_capability "Goto Support (GOTO_TARGET)" $GOTO_TARGET
report_capability "LOGMARK Target" $LOGMARK_TARGET report_capability "LOGMARK Target (LOGMARK_TARGET)" $LOGMARK_TARGET
report_capability "IPMARK Target" $IPMARK_TARGET report_capability "IPMARK Target (IPMARK_TARGET)" $IPMARK_TARGET
report_capability "LOG Target" $LOG_TARGET report_capability "LOG Target (LOG_TARGET)" $LOG_TARGET
report_capability "ULOG Target" $ULOG_TARGET report_capability "ULOG Target (ULOG_TARGET)" $ULOG_TARGET
report_capability "NFLOG Target" $NFLOG_TARGET report_capability "NFLOG Target (NFLOG_TARGET)" $NFLOG_TARGET
report_capability "Persistent SNAT" $PERSISTENT_SNAT report_capability "Persistent SNAT (PERSISTENT_SNAT)" $PERSISTENT_SNAT
report_capability "TPROXY Target" $TPROXY_TARGET report_capability "TPROXY Target (TPROXY_TARGET)" $TPROXY_TARGET
report_capability "FLOW Classifier" $FLOW_FILTER report_capability "FLOW Classifier (FLOW_FILTER)" $FLOW_FILTER
report_capability "fwmark route mask" $FWMARK_RT_MASK report_capability "fwmark route mask (FWMARK_RT_MASK)" $FWMARK_RT_MASK
report_capability "Mark in any table" $MARK_ANYWHERE report_capability "Mark in any table (MARK_ANYWHERE)" $MARK_ANYWHERE
report_capability "Header Match" $HEADER_MATCH report_capability "Header Match (HEADER_MATCH)" $HEADER_MATCH
report_capability "ACCOUNT Target" $ACCOUNT_TARGET report_capability "ACCOUNT Target (ACCOUNT_TARGET)" $ACCOUNT_TARGET
report_capability "AUDIT Target" $AUDIT_TARGET report_capability "AUDIT Target (AUDIT_TARGET)" $AUDIT_TARGET
report_capability "ipset V5" $IPSET_V5 report_capability "ipset V5 (IPSET_V5)" $IPSET_V5
report_capability "Condition Match" $CONDITION_MATCH report_capability "Condition Match (CONDITION_MATCH)" $CONDITION_MATCH
report_capability "Statistic Match" $STATISTIC_MATCH report_capability "Statistic Match (STATISTIC_MATCH)" $STATISTIC_MATCH
report_capability "IMQ Target" $IMQ_TARGET report_capability "IMQ Target (IMQ_TARGET)" $IMQ_TARGET
report_capability "DSCP Match (DSCP_MATCH)" $DSCP_MATCH
report_capability "DSCP Target (DSCP_TARGET)" $DSCP_TARGET
if [ $g_family -eq 4 ]; then if [ $g_family -eq 4 ]; then
report_capability "iptables -S" $IPTABLES_S report_capability "iptables -S (IPTABLES_S)" $IPTABLES_S
else else
report_capability "ip6tables -S" $IPTABLES_S report_capability "ip6tables -S (IPTABLES_S)" $IPTABLES_S
fi fi
report_capability "Basic Filter" $BASIC_FILTER report_capability "Basic Filter (BASIC_FILTER)" $BASIC_FILTER
report_capability "CT Target" $CT_TARGET report_capability "CT Target (CT_TARGET)" $CT_TARGET
fi fi
[ -n "$PKTTYPE" ] || USEPKTTYPE= [ -n "$PKTTYPE" ] || USEPKTTYPE=
@@ -2306,6 +2355,7 @@ report_capabilities1() {
report_capability1 IPRANGE_MATCH report_capability1 IPRANGE_MATCH
report_capability1 RECENT_MATCH report_capability1 RECENT_MATCH
report_capability1 OWNER_MATCH report_capability1 OWNER_MATCH
report_capability1 OWNER_NAME_MATCH
report_capability1 IPSET_MATCH report_capability1 IPSET_MATCH
report_capability1 OLD_IPSET_MATCH report_capability1 OLD_IPSET_MATCH
report_capability1 CONNMARK report_capability1 CONNMARK
@@ -2354,14 +2404,14 @@ report_capabilities1() {
report_capability1 CT_TARGET report_capability1 CT_TARGET
report_capability1 STATISTIC_MATCH report_capability1 STATISTIC_MATCH
report_capability1 IMQ_TARGET report_capability1 IMQ_TARGET
report_capability1 DSCP_MATCH
report_capability1 DSCP_TARGET
echo CAPVERSION=$SHOREWALL_CAPVERSION echo CAPVERSION=$SHOREWALL_CAPVERSION
echo KERNELVERSION=$KERNELVERSION echo KERNELVERSION=$KERNELVERSION
} }
status_command() { show_status() {
echo "${g_product}-$SHOREWALL_VERSION Status at $g_hostname - $(date)"
echo
if product_is_started ; then if product_is_started ; then
echo "$g_product is running" echo "$g_product is running"
status=0 status=0
@@ -2381,6 +2431,12 @@ status_command() {
state=Unknown state=Unknown
fi fi
echo "State:$state" echo "State:$state"
}
status_command() {
echo "${g_product}-$SHOREWALL_VERSION Status at $g_hostname - $(date)"
echo
show_status
echo echo
exit $status exit $status
} }
@@ -2936,14 +2992,12 @@ shorewall_cli() {
g_annotate= g_annotate=
g_recovering= g_recovering=
g_timestamp= g_timestamp=
g_libexec=/usr/share
g_perllib=/usr/share/shorewall
g_shorewalldir= g_shorewalldir=
VERBOSE= VERBOSE=
VERBOSITY= VERBOSITY=
[ -n "$g_lite" ] || . /usr/share/shorewall/lib.cli-std [ -n "$g_lite" ] || . ${g_basedir}/lib.cli-std
finished=0 finished=0
@@ -3048,7 +3102,7 @@ shorewall_cli() {
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
MUTEX_TIMEOUT= MUTEX_TIMEOUT=
[ -f ${CONFDIR}/vardir ] && . ${CONFDIR}/vardir [ -f ${g_confdir}/vardir ] && . ${g_confdir}/vardir
[ -n "${VARDIR:=/var/lib/$g_program}" ] [ -n "${VARDIR:=/var/lib/$g_program}" ]
@@ -3058,7 +3112,7 @@ shorewall_cli() {
g_firewall=${VARDIR}/firewall g_firewall=${VARDIR}/firewall
version_file=$SHAREDIR/version version_file=${g_sharedir}/version
if [ -f $version_file ]; then if [ -f $version_file ]; then
SHOREWALL_VERSION=$(cat $version_file) SHOREWALL_VERSION=$(cat $version_file)
else else

View File

@@ -676,7 +676,7 @@ find_file()
fi fi
done done
echo ${CONFDIR}/$1 echo ${g_confdir}/$1
;; ;;
esac esac
} }

View File

@@ -0,0 +1,20 @@
#
# Apple OS X Shorewall 4.5 rc file
#
BUILD=apple
HOST=apple
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/share #Directory for executable scripts.
PERLLIBDIR=${PREFIX}/share/shorewall #Directory to install Shorewall Perl module directory
CONFDIR=/etc #Directory where subsystem configurations are installed
SBINDIR=/sbin #Directory where system administration programs are installed
MANDIR=${SHAREDIR}/man #Directory where manpages are installed.
INITDIR= #Unused on OS X
INITFILE= #Unused on OS X
INITSOURCE= #Unused on OS X
ANNOTATED= #Unused on OS X
SYSTEMD= #Unused on OS X
SYSCONFDIR= #Unused on OS X
SPARSE=Yes #Only install $PRODUCT/$PRODUCT.conf in $CONFDIR.
VARDIR=/var/lib #Unused on OS X

View File

@@ -0,0 +1,20 @@
#
# Archlinux Shorewall 4.5 rc file
#
BUILD=archlinux
HOST=archlinux
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/share #Directory for executable scripts.
PERLLIBDIR=${PREFIX}/share/shorewall #Directory to install Shorewall Perl module directory
CONFDIR=/etc #Directory where subsystem configurations are installed
SBINDIR=/sbin #Directory where system administration programs are installed
MANDIR=${SHAREDIR}/man #Directory where manpages are installed.
INITDIR=/etc/rc.d #Directory where SysV init scripts are installed.
INITFILE=$PRODUCT #Name of the product's installed SysV init script
INITSOURCE=init.sh #Name of the distributed file to be installed as the SysV init script
ANNOTATED= #If non-zero, annotated configuration files are installed
SYSCONFDIR= #Directory where SysV init parameter files are installed
SYSTEMD= #Directory where .service files are installed (systems running systemd only)
SPARSE= #If non-empty, only install $PRODUCT/$PRODUCT.conf in $CONFDIR
VARDIR=/var/lib #Directory where product variable data is stored.

View File

@@ -0,0 +1,20 @@
#
# Cygwin Shorewall 4.5 rc file
#
BUILD=cygwin
HOST=cygwin
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/share #Directory for executable scripts.
PERLLIBDIR=${PREFIX}/share/shorewall #Directory to install Shorewall Perl module directory
CONFDIR=/etc #Directory where subsystem configurations are installed
SBINDIR=/bin #Directory where system administration programs are installed
MANDIR=${SHAREDIR}/man #Directory where manpages are installed.
INITDIR=/etc/init.d #Unused on Cygwin
INITFILE= #Unused on Cygwin
INITSOURCE= #Unused on Cygwin
ANNOTATED= #Unused on Cygwin
SYSTEMD= #Unused on Cygwin
SYSCONFDIR= #Unused on Cygwin
SPARSE=Yes #Only install $PRODUCT/$PRODUCT.conf in $CONFDIR.
VARDIR=/var/lib #Unused on Cygwin

View File

@@ -0,0 +1,21 @@
#
# Debian Shorewall 4.5 rc file
#
BUILD= #Default is to detect the build system
HOST=debian
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/share #Directory for executable scripts.
PERLLIBDIR=${PREFIX}/share/shorewall #Directory to install Shorewall Perl module directory
CONFDIR=/etc #Directory where subsystem configurations are installed
SBINDIR=/sbin #Directory where system administration programs are installed
MANDIR=${PREFIX}/share/man #Directory where manpages are installed.
INITDIR=/etc/init.d #Directory where SysV init scripts are installed.
INITFILE=$PRODUCT #Name of the product's installed SysV init script
INITSOURCE=init.debian.sh #Name of the distributed file to be installed as the SysV init script
ANNOTATED= #If non-zero, annotated configuration files are installed
SYSCONFFILE=default.debian #Name of the distributed file to be installed in $SYSCONFDIR
SYSCONFDIR=/etc/default #Directory where SysV init parameter files are installed
SYSTEMD= #Directory where .service files are installed (systems running systemd only)
SPARSE=Yes #If non-empty, only install $PRODUCT/$PRODUCT.conf in $CONFDIR
VARDIR=/var/lib #Directory where product variable data is stored.

View File

@@ -0,0 +1,21 @@
#
# Default Shorewall 4.5 rc file
#
HOST=linux #Generic Linux
BUILD= #Default is to detect the build system
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/share #Directory for executable scripts.
PERLLIBDIR=${PREFIX}/share/shorewall #Directory to install Shorewall Perl module directory
CONFDIR=/etc #Directory where subsystem configurations are installed
SBINDIR=/sbin #Directory where system administration programs are installed
MANDIR=${PREFIX}/man #Directory where manpages are installed.
INITDIR=etc/init.d #Directory where SysV init scripts are installed.
INITFILE=$PRODUCT #Name of the product's installed SysV init script
INITSOURCE=init.sh #Name of the distributed file to be installed as the SysV init script
ANNOTATED= #If non-zero, annotated configuration files are installed
SYSTEMD= #Directory where .service files are installed (systems running systemd only)
SYSCONFFILE= #Name of the distributed file to be installed in $SYSCONFDIR
SYSCONFDIR= #Directory where SysV init parameter files are installed
SPARSE= #If non-empty, only install $PRODUCT/$PRODUCT.conf in $CONFDIR
VARDIR=/var/lib #Directory where product variable data is stored.

View File

@@ -0,0 +1,21 @@
#
# RedHat/FedoraShorewall 4.5 rc file
#
BUILD= #Default is to detect the build system
HOST=redhat
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/libexec #Directory for executable scripts.
PERLLIBDIR=/usr/share/perl5/vendor_perl #Directory to install Shorewall Perl module directory
CONFDIR=/etc #Directory where subsystem configurations are installed
SBINDIR=/sbin #Directory where system administration programs are installed
MANDIR=${SHAREDIR}/man #Directory where manpages are installed.
INITDIR=/etc/rc.d/init.d #Directory where SysV init scripts are installed.
INITFILE=$PRODUCT #Name of the product's installed SysV init script
INITSOURCE=init.fedora.sh #Name of the distributed file to be installed as the SysV init script
ANNOTATED= #If non-zero, annotated configuration files are installed
SYSTEMD=/lib/systemd/system #Directory where .service files are installed (systems running systemd only)
SYSCONFFILE=sysconfig #Name of the distributed file to be installed as $SYSCONFDIR/$PRODUCT
SYSCONFDIR=/etc/sysconfig/ #Directory where SysV init parameter files are installed
SPARSE= #If non-empty, only install $PRODUCT/$PRODUCT.conf in $CONFDIR
VARDIR=/var/lib #Directory where product variable data is stored.

View File

@@ -0,0 +1,22 @@
#
# Slackware Shorewall 4.5 rc file
#
BUILD=slackware
HOST=slackware
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/share #Directory for executable scripts.
PERLLIBDIR=${PREFIX}/share/shorewall #Directory to install Shorewall Perl module directory
CONFDIR=/etc #Directory where subsystem configurations are installed
SBINDIR=/sbin #Directory where system administration programs are installed
MANDIR=${PREFIX}/man #Directory where manpages are installed.
INITDIR=/etc/rc.d #Directory where SysV init scripts are installed.
INITSOURCE=init.slackware.firewall.sh #Name of the distributed file to be installed as the SysV init script
INITFILE=rc.firewall #Name of the product's installed SysV init script
AUXINITSOURCE=init.slackware.$PRODUCT.sh #Name of the distributed file to be installed as a second SysV init script
AUXINITFILE=rc.$PRODUCT #Name of the product's installed second init script
SYSTEMD= #Name of the directory where .service files are installed (systems running systemd only)
SYSCONFFILE= #Name of the distributed file to be installed in $SYSCONFDIR
SYSCONFDIR= #Name of the directory where SysV init parameter files are installed.
ANNOTATED= #If non-empty, install annotated configuration files
VARDIR=/var/lib #Directory where product variable data is stored.

View File

@@ -0,0 +1,21 @@
#
# SuSE Shorewall 4.5 rc file
#
BUILD= #Default is to detect the build system
HOST=suse
PREFIX=/usr #Top-level directory for shared files, libraries, etc.
CONFDIR=/etc #Directory where subsystem configurations are installed
SHAREDIR=${PREFIX}/share #Directory for arch-neutral files.
LIBEXECDIR=${PREFIX}/lib #Directory for executable scripts.
PERLLIBDIR=${PREFIX}/lib/perl5/vendor_perl/5.14.2 #Directory to install Shorewall Perl module directory
SBINDIR=/sbin #Directory where system administration programs are installed
MANDIR=${SHAREDIR}/man/ #Directory where manpages are installed.
INITDIR=/etc/init.d #Directory where SysV init scripts are installed.
INITFILE=$PRODUCT #Name of the product's SysV init script
INITSOURCE=init.sh #Name of the distributed file to be installed as the SysV init script
ANNOTATED= #If non-zero, annotated configuration files are installed
SYSTEMD= #Directory where .service files are installed (systems running systemd only)
SYSCONFFILE= #Name of the distributed file to be installed in $SYSCONFDIR
SYSCONFDIR=/etc/sysconfig/ #Directory where SysV init parameter files are installed
SPARSE= #If non-empty, only install $PRODUCT/$PRODUCT.conf in $CONFDIR
VARDIR=/var/lib #Directory where persistent product data is stored.

View File

@@ -31,7 +31,7 @@ VERSION=xxx #The Build script inserts the actual version
usage() # $1 = exit status usage() # $1 = exit status
{ {
ME=$(basename $0) ME=$(basename $0)
echo "usage: $ME" echo "usage: $ME [ <shorewallrc file> ]"
exit $1 exit $1
} }
@@ -60,8 +60,37 @@ remove_file() # $1 = file to restore
fi fi
} }
if [ -f /usr/share/shorewall/coreversion ]; then #
INSTALLED_VERSION="$(cat /usr/share/shorewall/coreversion)" # Read the RC file
#
if [ $# -eq 0 ]; then
if [ -f ./shorewallrc ]; then
. ./shorewallrc
elif [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc || exit 1
file=./.shorewallrc
elif [ -f /usr/share/shorewall/shorewallrc ]; then
. /usr/share/shorewall/shorewallrc
else
fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
fi
elif [ $# -eq 1 ]; then
file=$1
case $file in
/*|.*)
;;
*)
file=./$file
;;
esac
. $file
else
usage 1
fi
if [ -f ${SHAREDIR}/shorewall/coreversion ]; then
INSTALLED_VERSION="$(cat ${SHAREDIR}/shorewall/coreversion)"
if [ "$INSTALLED_VERSION" != "$VERSION" ]; then if [ "$INSTALLED_VERSION" != "$VERSION" ]; then
echo "WARNING: Shorewall Core Version $INSTALLED_VERSION is installed" echo "WARNING: Shorewall Core Version $INSTALLED_VERSION is installed"
echo " and this is the $VERSION uninstaller." echo " and this is the $VERSION uninstaller."
@@ -72,12 +101,9 @@ else
VERSION="" VERSION=""
fi fi
[ -n "${LIBEXEC:=/usr/share}" ]
[ -n "${PERLLIB:=/usr/share/shorewall}" ]
echo "Uninstalling Shorewall Core $VERSION" echo "Uninstalling Shorewall Core $VERSION"
rm -rf /usr/share/shorewall rm -rf ${SHAREDIR}/shorewall
echo "Shorewall Core Uninstalled" echo "Shorewall Core Uninstalled"

View File

@@ -71,6 +71,11 @@ Debian_SuSE_ppp() {
IFUPDOWN=0 IFUPDOWN=0
PRODUCTS= PRODUCTS=
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
if [ -f /etc/default/shorewall-init ]; then if [ -f /etc/default/shorewall-init ]; then
. /etc/default/shorewall-init . /etc/default/shorewall-init
elif [ -f /etc/sysconfig/shorewall-init ]; then elif [ -f /etc/sysconfig/shorewall-init ]; then
@@ -182,15 +187,19 @@ else
fi fi
for PRODUCT in $PRODUCTS; do for PRODUCT in $PRODUCTS; do
VARDIR=/var/lib/$PRODUCT #
[ -f /etc/$PRODUCT/vardir ] && . /etc/$PRODUCT/vardir # For backward compatibility, lib.base appends the product name to VARDIR
if [ -x $VARDIR/firewall ]; then # Save it here and restore it below
( . /usr/share/$PRODUCT/lib.base #
save_vardir=${VARDIR}
if [ -x $VARDIR/$PRODUCT/firewall ]; then
( . ${SHAREDIR}/shorewall/lib.base
mutex_on mutex_on
${VARDIR}/firewall -V0 $COMMAND $INTERFACE || echo_notdone ${VARDIR}/firewall -V0 $COMMAND $INTERFACE || echo_notdone
mutex_off mutex_off
) )
fi fi
VARDIR=${save_vardir}
done done
exit 0 exit 0

View File

@@ -1,10 +1,10 @@
#!/bin/sh #!/bin/sh
# #
# The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.4 # The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.5
# #
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt] # This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
# #
# (c) 2010 - Tom Eastep (teastep@shorewall.net) # (c) 2010,2012 - Tom Eastep (teastep@shorewall.net)
# #
# On most distributions, this file should be called /etc/init.d/shorewall. # On most distributions, this file should be called /etc/init.d/shorewall.
# #
@@ -62,10 +62,15 @@ not_configured () {
exit 0 exit 0
} }
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
# check if shorewall-init is configured or not # check if shorewall-init is configured or not
if [ -f "/etc/default/shorewall-init" ] if [ -f "$SYSCONFDIR/shorewall-init" ]
then then
. /etc/default/shorewall-init . $SYSCONFDIR/shorewall-init
if [ -z "$PRODUCTS" ] if [ -z "$PRODUCTS" ]
then then
not_configured not_configured

View File

@@ -13,6 +13,15 @@
# Description: Place the firewall in a safe state at boot time # Description: Place the firewall in a safe state at boot time
# prior to bringing up the network. # prior to bringing up the network.
### END INIT INFO ### END INIT INFO
#determine where the files were installed
if [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc || exit 1
else
SBINDIR=/sbin
SYSCONFDIR=/etc/default
VARDIR=/var/lib
fi
prog="shorewall-init" prog="shorewall-init"
logger="logger -i -t $prog" logger="logger -i -t $prog"
lockfile="/var/lock/subsys/shorewall-init" lockfile="/var/lock/subsys/shorewall-init"
@@ -44,10 +53,8 @@ start () {
echo -n "Initializing \"Shorewall-based firewalls\": " echo -n "Initializing \"Shorewall-based firewalls\": "
for product in $PRODUCTS; do for product in $PRODUCTS; do
vardir=/var/lib/$product if [ -x ${VARDIR}/$product/firewall ]; then
[ -f /etc/$product/vardir ] && . /etc/$product/vardir ${VARDIR}/$product/firewall stop 2>&1 | $logger
if [ -x ${vardir}/firewall ]; then
${vardir}/firewall stop 2>&1 | $logger
retval=${PIPESTATUS[0]} retval=${PIPESTATUS[0]}
[ retval -ne 0 ] && break [ retval -ne 0 ] && break
fi fi
@@ -70,10 +77,8 @@ stop () {
echo -n "Clearing \"Shorewall-based firewalls\": " echo -n "Clearing \"Shorewall-based firewalls\": "
for product in $PRODUCTS; do for product in $PRODUCTS; do
vardir=/var/lib/$product if [ -x ${VARDIR}/$product/firewall ]; then
[ -f /etc/$product/vardir ] && . /etc/$product/vardir ${VARDIR}/$product/firewall clear 2>&1 | $logger
if [ -x ${vardir}/firewall ]; then
${vardir}/firewall clear 2>&1 | $logger
retval=${PIPESTATUS[0]} retval=${PIPESTATUS[0]}
[ retval -ne 0 ] && break [ retval -ne 0 ] && break
fi fi

View File

@@ -1,9 +1,9 @@
#! /bin/bash #! /bin/bash
# The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.4 # The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.5
# #
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt] # This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
# #
# (c) 2010 - Tom Eastep (teastep@shorewall.net) # (c) 2010,2012 - Tom Eastep (teastep@shorewall.net)
# #
# On most distributions, this file should be called /etc/init.d/shorewall. # On most distributions, this file should be called /etc/init.d/shorewall.
# #
@@ -53,6 +53,11 @@ else
exit 0 exit 0
fi fi
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
# Initialize the firewall # Initialize the firewall
shorewall_start () { shorewall_start () {
local PRODUCT local PRODUCT
@@ -60,10 +65,8 @@ shorewall_start () {
echo -n "Initializing \"Shorewall-based firewalls\": " echo -n "Initializing \"Shorewall-based firewalls\": "
for PRODUCT in $PRODUCTS; do for PRODUCT in $PRODUCTS; do
VARDIR=/var/lib/$PRODUCT
[ -f /etc/$PRODUCT/vardir ] && . /etc/$PRODUCT/vardir
if [ -x ${VARDIR}/firewall ]; then if [ -x ${VARDIR}/firewall ]; then
if ! /sbin/$PRODUCT status > /dev/null 2>&1; then if ! ${SBIN}/$PRODUCT status > /dev/null 2>&1; then
${VARDIR}/firewall stop || echo_notdone ${VARDIR}/firewall stop || echo_notdone
fi fi
fi fi
@@ -83,8 +86,6 @@ shorewall_stop () {
echo -n "Clearing \"Shorewall-based firewalls\": " echo -n "Clearing \"Shorewall-based firewalls\": "
for PRODUCT in $PRODUCTS; do for PRODUCT in $PRODUCTS; do
VARDIR=/var/lib/$PRODUCT
[ -f /etc/$PRODUCT/vardir ] && . /etc/$PRODUCT/vardir
if [ -x ${VARDIR}/firewall ]; then if [ -x ${VARDIR}/firewall ]; then
${VARDIR}/firewall clear || exit 1 ${VARDIR}/firewall clear || exit 1
fi fi

View File

@@ -28,12 +28,18 @@ VERSION=xxx #The Build script inserts the actual version.
usage() # $1 = exit status usage() # $1 = exit status
{ {
ME=$(basename $0) ME=$(basename $0)
echo "usage: $ME" echo "usage: $ME [ <configuration-file> ]"
echo " $ME -v" echo " $ME -v"
echo " $ME -h" echo " $ME -h"
exit $1 exit $1
} }
fatal_error()
{
echo " ERROR: $@" >&2
exit 1
}
split() { split() {
local ifs local ifs
ifs=$IFS ifs=$IFS
@@ -76,9 +82,9 @@ cant_autostart()
echo "WARNING: Unable to configure shorewall init to start automatically at boot" >&2 echo "WARNING: Unable to configure shorewall init to start automatically at boot" >&2
} }
delete_file() # $1 = file to delete require()
{ {
rm -f $1 eval [ -n "\$$1" ] || fatal_error "Required option $1 not set"
} }
install_file() # $1 = source $2 = target $3 = mode install_file() # $1 = source $2 = target $3 = mode
@@ -86,148 +92,201 @@ install_file() # $1 = source $2 = target $3 = mode
run_install $T $OWNERSHIP -m $3 $1 ${2} run_install $T $OWNERSHIP -m $3 $1 ${2}
} }
[ -n "$DESTDIR" ] || DESTDIR="$PREFIX" cd "$(dirname $0)"
PRODUCT=shorewall-init
# DEST is the SysVInit script directory
# INIT is the name of the script in the $DEST directory
# ARGS is "yes" if we've already parsed an argument
# #
ARGS="" # Parse the run line
#
finished=0
if [ -z "$DEST" ] ; then while [ $finished -eq 0 ] ; do
DEST="/etc/init.d"
fi
if [ -z "$INIT" ] ; then
INIT="shorewall-init"
fi
while [ $# -gt 0 ] ; do
case "$1" in case "$1" in
-h|help|?) -*)
usage 0 option=${option#-}
;;
-v) while [ -n "$option" ]; do
echo "Shorewall Init Installer Version $VERSION" case $option in
exit 0 h)
usage 0
;;
v)
echo "Shorewall-init Firewall Installer Version $VERSION"
exit 0
;;
*)
usage 1
;;
esac
done
shift
;; ;;
*) *)
usage 1 finished=1
;; ;;
esac esac
shift done
ARGS="yes"
#
# Read the RC file
#
if [ $# -eq 0 ]; then
#
# Load packager's settings if any
#
if [ -f ./shorewallrc ]; then
. ./shorewallrc || exit 1
file=~/.shorewallrc
elif [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc || exit 1
file=./.shorewallrc
else
fatal_error "No configuration file specified and ~/.shorewallrc not found"
fi
elif [ $# -eq 1 ]; then
file=$1
case $file in
/*|.*)
;;
*)
file=./$file
;;
esac
. $file
else
usage 1
fi
for var in SHAREDIR LIBEXECDIR CONFDIR SBINDIR VARDIR; do
require $var
done done
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
[ -n "${LIBEXEC:=/usr/share}" ] if [ -z "$BUILD" ]; then
case $(uname) in
cygwin*)
BUILD=cygwin
;;
Darwin)
BUILD=apple
;;
*)
if [ -f /etc/debian_version ]; then
BUILD=debian
elif [ -f /etc/redhat-release ]; then
BUILD=redhat
elif [ -f /etc/SuSE-release ]; then
BUILD=suse
elif [ -f /etc/slackware-version ] ; then
BUILD=slackware
elif [ -f /etc/arch-release ] ; then
BUILD=archlinux
else
BUILD=linux
fi
;;
esac
fi
case "$LIBEXEC" in [ -n "$OWNER" ] || OWNER=$(id -un)
/*) [ -n "$GROUP" ] || GROUP=$(id -gn)
;;
*)
LIBEXEC=/usr/${LIBEXEC}
;;
esac
# case $BUILD in
# Determine where to install the firewall script apple)
#
case $(uname) in
Darwin)
[ -z "$OWNER" ] && OWNER=root
[ -z "$GROUP" ] && GROUP=wheel
T= T=
;; ;;
debian|redhat|suse|slackware|archlinux)
;;
*) *)
[ -z "$OWNER" ] && OWNER=root [ -n "$BUILD" ] && echo "ERROR: Unknown BUILD environment ($BUILD)" >&2 || echo "ERROR: Unknown BUILD environment"
[ -z "$GROUP" ] && GROUP=root exit 1
;; ;;
esac esac
OWNERSHIP="-o $OWNER -g $GROUP" OWNERSHIP="-o $OWNER -g $GROUP"
[ -n "$HOST" ] || HOST=$BUILD
case "$HOST" in
debian)
echo "Installing Debian-specific configuration..."
;;
redhat|redhat)
echo "Installing Redhat/Fedora-specific configuration..."
;;
slackware)
echo "Shorewall-init is currently not supported on Slackware" >&2
exit 1
;;
archlinux)
echo "Shorewall-init is currently not supported on Arch Linux" >&2
exit 1
;;
suse|suse)
echo "Installing SuSE-specific configuration..."
;;
linux)
echo "ERROR: Shorewall-init is not supported on this system" >&2
;;
*)
echo "ERROR: Unsupported HOST distribution: \"$HOST\"" >&2
exit 1;
;;
esac
[ -z "$TARGET" ] && TARGET=$HOST
if [ -n "$DESTDIR" ]; then if [ -n "$DESTDIR" ]; then
if [ `id -u` != 0 ] ; then if [ `id -u` != 0 ] ; then
echo "Not setting file owner/group permissions, not running as root." echo "Not setting file owner/group permissions, not running as root."
OWNERSHIP="" OWNERSHIP=""
fi fi
install -d $OWNERSHIP -m 755 ${DESTDIR}${DEST} install -d $OWNERSHIP -m 755 ${DESTDIR}${INITDIR}
elif [ -f /etc/debian_version ]; then
DEBIAN=yes
elif [ -f /etc/SuSE-release ]; then
SUSE=Yes
elif [ -f /etc/redhat-release ]; then
FEDORA=Yes
elif [ -f /etc/slackware-version ] ; then
echo "Shorewall-init is currently not supported on Slackware" >&2
exit 1
# DEST="/etc/rc.d"
# INIT="rc.firewall"
elif [ -f /etc/arch-release ] ; then
echo "Shorewall-init is currently not supported on Arch Linux" >&2
exit 1
# DEST="/etc/rc.d"
# INIT="shorewall-init"
# ARCHLINUX=yes
elif [ -d /etc/sysconfig/network-scripts/ ]; then
#
# Assume RedHat-based
#
REDHAT=Yes
else
echo "Unknown distribution: Shorewall-init support is not available" >&2
exit 1
fi fi
if [ -z "$DESTDIR" ]; then
if [ -f /lib/systemd/system ]; then
SYSTEMD=Yes
fi
elif [ -n "$SYSTEMD" ]; then
mkdir -p ${DESTDIR}/lib/systemd/system
fi
#
# Change to the directory containing this script
#
cd "$(dirname $0)"
echo "Installing Shorewall Init Version $VERSION" echo "Installing Shorewall Init Version $VERSION"
# #
# Check for /usr/share/shorewall-init/version # Check for /usr/share/shorewall-init/version
# #
if [ -f ${DESTDIR}/usr/share/shorewall-init/version ]; then if [ -f ${DESTDIR}${SHAREDIR}/shorewall-init/version ]; then
first_install="" first_install=""
else else
first_install="Yes" first_install="Yes"
fi fi
# #
# Install the Init Script # Install the Firewall Script
# #
if [ -n "$DEBIAN" ]; then if [ -n "$INITFILE" ]; then
install_file init.debian.sh ${DESTDIR}/etc/init.d/shorewall-init 0544 install_file $INITSOURCE ${DESTDIR}${INITDIR}/$INITFILE 0544
elif [ -n "$FEDORA" ]; then [ "${SHAREDIR}" = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}${INITDIR}/$INITFILE
install_file init.fedora.sh ${DESTDIR}/etc/init.d/shorewall-init 0544
#elif [ -n "$ARCHLINUX" ]; then
# install_file init.archlinux.sh ${DESTDIR}${DEST}/$INIT 0544
else
install_file init.sh ${DESTDIR}${DEST}/$INIT 0544
fi
echo "Shorewall Init script installed in ${DESTDIR}${DEST}/$INIT" if [ -n "${AUXINITSOURCE}" ]; then
install_file $INITSOURCE ${DESTDIR}${INITDIR}/$AUXINITFILE 0544
fi
echo "Shorewall-init script installed in ${DESTDIR}${INITDIR}/$INITFILE"
fi
# #
# Install the .service file # Install the .service file
# #
if [ -n "$SYSTEMD" ]; then if [ -n "$SYSTEMD" ]; then
run_install $OWNERSHIP -m 600 shorewall-init.service ${DESTDIR}/lib/systemd/system/shorewall-init.service mkdir -p ${DESTDIR}${SYSTEMD}
echo "Service file installed as ${DESTDIR}/lib/systemd/system/shorewall-init.service" run_install $OWNERSHIP -m 600 shorewall-init.service ${DESTDIR}${SYSTEMD}/shorewall-init.service
echo "Service file installed as ${DESTDIR}${SYSTEMD}/shorewall-init.service"
if [ -n "$DESTDIR" ]; then
mkdir -p ${DESTDIR}${SBINDIR}
chmod 755 ${DESTDIR}${SBINDIR}
fi
run_install $OWNERSHIP -m 700 shorewall-init ${DESTDIR}${SBINDIR}/shorewall-init
echo "CLI installed as ${DESTDIR}${SBINDIR}/shorewall-init"
fi fi
# #
@@ -247,10 +306,10 @@ chmod 644 ${DESTDIR}/usr/share/shorewall-init/version
# #
if [ -z "$DESTDIR" ]; then if [ -z "$DESTDIR" ]; then
rm -f /usr/share/shorewall-init/init rm -f /usr/share/shorewall-init/init
ln -s ${DEST}/${INIT} /usr/share/shorewall-init/init ln -s ${INITDIR}/${INITFILE} ${SHAREDIR}/shorewall-init/init
fi fi
if [ -n "$DEBIAN" ]; then if [ $HOST = debian ]; then
if [ -n "${DESTDIR}" ]; then if [ -n "${DESTDIR}" ]; then
mkdir -p ${DESTDIR}/etc/network/if-up.d/ mkdir -p ${DESTDIR}/etc/network/if-up.d/
mkdir -p ${DESTDIR}/etc/network/if-post-down.d/ mkdir -p ${DESTDIR}/etc/network/if-post-down.d/
@@ -265,20 +324,20 @@ if [ -n "$DEBIAN" ]; then
fi fi
else else
if [ -n "$DESTDIR" ]; then if [ -n "$DESTDIR" ]; then
mkdir -p ${DESTDIR}/etc/sysconfig mkdir -p ${DESTDIR}${SYSCONFDIR}
if [ -z "$RPM" ]; then if [ -z "$RPM" ]; then
if [ -n "$SUSE" ]; then if [ $HOST = suse ]; then
mkdir -p ${DESTDIR}/etc/sysconfig/network/if-up.d mkdir -p ${DESTDIR}/etc/sysconfig/network/if-up.d
mkdir -p ${DESTDIR}/etc/sysconfig/network/if-down.d mkdir -p ${DESTDIR}${SYSCONFDIR}/network/if-down.d
else else
mkdir -p ${DESTDIR}/etc/NetworkManager/dispatcher.d mkdir -p ${DESTDIR}/etc/NetworkManager/dispatcher.d
fi fi
fi fi
fi fi
if [ -d ${DESTDIR}/etc/sysconfig -a ! -f ${DESTDIR}/etc/sysconfig/shorewall-init ]; then if [ -d ${DESTDIR}${SYSCONFDIR} -a ! -f ${DESTDIR}${SYSCONFDIR}/shorewall-init ]; then
install_file sysconfig ${DESTDIR}/etc/sysconfig/shorewall-init 0644 install_file sysconfig ${DESTDIR}${SYSCONFDIR}/shorewall-init 0644
fi fi
fi fi
@@ -286,32 +345,42 @@ fi
# Install the ifupdown script # Install the ifupdown script
# #
mkdir -p ${DESTDIR}${LIBEXEC}/shorewall-init cp ifupdown.sh ifupdown
install_file ifupdown.sh ${DESTDIR}${LIBEXEC}/shorewall-init/ifupdown 0544 d[ "${SHAREDIR}" = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ifupdown
mkdir -p ${DESTDIR}${LIBEXECDIR}/shorewall-init
install_file ifupdown ${DESTDIR}${LIBEXECDIR}/shorewall-init/ifupdown 0544
if [ -d ${DESTDIR}/etc/NetworkManager ]; then if [ -d ${DESTDIR}/etc/NetworkManager ]; then
install_file ifupdown.sh ${DESTDIR}/etc/NetworkManager/dispatcher.d/01-shorewall 0544 install_file ifupdown ${DESTDIR}/etc/NetworkManager/dispatcher.d/01-shorewall 0544
fi fi
if [ -n "$DEBIAN" ]; then case $HOST in
install_file ifupdown.sh ${DESTDIR}/etc/network/if-up.d/shorewall 0544 debian)
install_file ifupdown.sh ${DESTDIR}/etc/network/if-post-down.d/shorewall 0544 install_file ifupdown ${DESTDIR}/etc/network/if-up.d/shorewall 0544
elif [ -n "$SUSE" ]; then install_file ifupdown ${DESTDIR}/etc/network/if-post-down.d/shorewall 0544
install_file ifupdown.sh ${DESTDIR}/etc/sysconfig/network/if-up.d/shorewall 0544 ;;
install_file ifupdown.sh ${DESTDIR}/etc/sysconfig/network/if-down.d/shorewall 0544 suse)
elif [ -n "$REDHAT" ]; then if [ -z "$RPM" ]; then
if [ -f ${DESTDIR}/sbin/ifup-local -o -f ${DESTDIR}/sbin/ifdown-local ]; then install_file ifupdown ${DESTDIR}${SYSCONFDIR}/network/if-up.d/shorewall 0544
echo "WARNING: /sbin/ifup-local and/or /sbin/ifdown-local already exist; up/down events will not be handled" install_file ifupdown ${DESTDIR}${SYSCONFDIR}/network/if-down.d/shorewall 0544
else fi
install_file ifupdown.sh ${DESTDIR}/sbin/ifup-local 0544 ;;
install_file ifupdown.sh ${DESTDIR}/sbin/ifdown-local 0544 redhat)
fi if [ -f ${DESTDIR}${SBINDIR}/ifup-local -o -f ${DESTDIR}${SBINDIR}/ifdown-local ]; then
fi echo "WARNING: ${SBINDIR}/ifup-local and/or ${SBINDIR}/ifdown-local already exist; up/down events will not be handled"
elif [ -z "$DESTDIR" ]; then
install_file ifupdown ${DESTDIR}${SBINDIR}/ifup-local 0544
install_file ifupdown ${DESTDIR}${SBINDIR}/ifdown-local 0544
fi
;;
esac
if [ -z "$DESTDIR" ]; then if [ -z "$DESTDIR" ]; then
if [ -n "$first_install" ]; then if [ -n "$first_install" ]; then
if [ -n "$DEBIAN" ]; then if [ $HOST = debian ]; then
update-rc.d shorewall-init defaults update-rc.d shorewall-init defaults
@@ -321,70 +390,73 @@ if [ -z "$DESTDIR" ]; then
if systemctl enable shorewall-init; then if systemctl enable shorewall-init; then
echo "Shorewall Init will start automatically at boot" echo "Shorewall Init will start automatically at boot"
fi fi
elif [ -x /sbin/insserv -o -x /usr/sbin/insserv ]; then elif [ -x ${SBINDIR}/insserv -o -x /usr${SBINDIR}/insserv ]; then
if insserv /etc/init.d/shorewall-init ; then if insserv ${INITDIR}/shorewall-init ; then
echo "Shorewall Init will start automatically at boot" echo "Shorewall Init will start automatically at boot"
else else
cant_autostart cant_autostart
fi fi
elif [ -x /sbin/chkconfig -o -x /usr/sbin/chkconfig ]; then elif [ -x ${SBINDIR}/chkconfig -o -x /usr${SBINDIR}/chkconfig ]; then
if chkconfig --add shorewall-init ; then if chkconfig --add shorewall-init ; then
echo "Shorewall Init will start automatically in run levels as follows:" echo "Shorewall Init will start automatically in run levels as follows:"
chkconfig --list shorewall-init chkconfig --list shorewall-init
else else
cant_autostart cant_autostart
fi fi
elif [ -x /sbin/rc-update ]; then elif [ -x ${SBINDIR}/rc-update ]; then
if rc-update add shorewall-init default; then if rc-update add shorewall-init default; then
echo "Shorewall Init will start automatically at boot" echo "Shorewall Init will start automatically at boot"
else else
cant_autostart cant_autostart
fi fi
elif [ "$INIT" != rc.firewall ]; then #Slackware starts this automatically else
cant_autostart cant_autostart
fi fi
fi fi
fi fi
else else
if [ -n "$first_install" ]; then if [ -n "$first_install" ]; then
if [ -n "$DEBIAN" ]; then if [ $HOST = debian ]; then
if [ -n "${DESTDIR}" ]; then if [ -n "${DESTDIR}" ]; then
mkdir -p ${DESTDIR}/etc/rcS.d mkdir -p ${DESTDIR}/etc/rcS.d
fi fi
ln -sf ../init.d/shorewall-init ${DESTDIR}/etc/rcS.d/S38shorewall-init ln -sf ../init.d/shorewall-init ${DESTDIR}${CONFDIR}/rcS.d/S38shorewall-init
echo "Shorewall Init will start automatically at boot" echo "Shorewall Init will start automatically at boot"
fi fi
fi fi
fi fi
if [ -f ${DESTDIR}/etc/ppp ]; then [ -z "${DESTDIR}" ] && [ ! -f ~/.shorewallrc ] && cp ${SHAREDIR}/shorewall/shorewallrc .
if [ -n "$DEBIAN" ] -o -n "$SUSE" ]; then
for directory in ip-up.d ip-down.d ipv6-up.d ipv6-down.d; do
mkdir -p ${DESTDIR}/etc/ppp/$directory #SuSE doesn't create the IPv6 directories
cp -fp ${DESTDIR}${LIBEXEC}/shorewall-init/ifupdown ${DESTDIR}/etc/ppp/$directory/shorewall
done
elif [ -n "$REDHAT" ]; then
#
# Must use the dreaded ip_xxx.local file
#
for file in ip-up.local ip-down.local; do
FILE=${DESTDIR}/etc/ppp/$file
if [ -f $FILE ]; then
if fgrep -q Shorewall-based $FILE ; then
cp -fp ${DESTDIR}${LIBEXEC}/shorewall-init/ifupdown $FILE
else
echo "$FILE already exists -- ppp devices will not be handled"
break
fi
else
cp -fp ${DESTDIR}${LIBEXEC}/shorewall-init/ifupdown $FILE
fi
done
fi
fi
if [ -f ${DESTDIR}/etc/ppp ]; then
case $HOST in
debian|suse)
for directory in ip-up.d ip-down.d ipv6-up.d ipv6-down.d; do
mkdir -p ${DESTDIR}/etc/ppp/$directory #SuSE doesn't create the IPv6 directories
cp -fp ${DESTDIR}${LIBEXECDIR}/shorewall-init/ifupdown ${DESTDIR}${CONFDIR}/ppp/$directory/shorewall
done
;;
redhat)
#
# Must use the dreaded ip_xxx.local file
#
for file in ip-up.local ip-down.local; do
FILE=${DESTDIR}/etc/ppp/$file
if [ -f $FILE ]; then
if fgrep -q Shorewall-based $FILE ; then
cp -fp ${DESTDIR}${LIBEXECDIR}/shorewall-init/ifupdown $FILE
else
echo "$FILE already exists -- ppp devices will not be handled"
break
fi
else
cp -fp ${DESTDIR}${LIBEXECDIR}/shorewall-init/ifupdown $FILE
fi
done
;;
esac
fi
# #
# Report Success # Report Success
# #

View File

@@ -0,0 +1,100 @@
#! /bin/bash
# The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.5
#
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
#
# (c) 2012 - Tom Eastep (teastep@shorewall.net)
#
# On most distributions, this file should be called /etc/init.d/shorewall.
#
# Complete documentation is available at http://shorewall.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of Version 2 of the GNU General Public License
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#########################################################################################
#
# This is modified by the installer when ${SHAREDIR} <> /usr/share
#
. /usr/share/shorewall/shorewallrc
# check if shorewall-init is configured or not
if [ -f "$SYSCONFDIR/shorewall-init" ]; then
. $SYSCONFDIR/shorewall-init
if [ -z "$PRODUCTS" ]; then
echo "ERROR: No products configured" >&2
exit 1
fi
else
echo "ERROR: /etc/sysconfig/shorewall-init not found" >&2
exit 1
fi
# Initialize the firewall
shorewall_start () {
local PRODUCT
local VARDIR
echo -n "Initializing \"Shorewall-based firewalls\": "
for PRODUCT in $PRODUCTS; do
if [ -x ${VARDIR}/firewall ]; then
if ! /sbin/$PRODUCT status > /dev/null 2>&1; then
${VARDIR}/firewall stop || exit 1
fi
fi
done
if [ -n "$SAVE_IPSETS" -a -f "$SAVE_IPSETS" ]; then
ipset -R < "$SAVE_IPSETS"
fi
return 0
}
# Clear the firewall
shorewall_stop () {
local PRODUCT
local VARDIR
echo -n "Clearing \"Shorewall-based firewalls\": "
for PRODUCT in $PRODUCTS; do
VARDIR=/var/lib/$PRODUCT
[ -f /etc/$PRODUCT/vardir ] && . /etc/$PRODUCT/vardir
if [ -x ${VARDIR}/firewall ]; then
${VARDIR}/firewall clear || exit 1
fi
done
if [ -n "$SAVE_IPSETS" ]; then
mkdir -p $(dirname "$SAVE_IPSETS")
if ipset -S > "${SAVE_IPSETS}.tmp"; then
grep -qE -- '^(-N|create )' "${SAVE_IPSETS}.tmp" && mv -f "${SAVE_IPSETS}.tmp" "$SAVE_IPSETS"
fi
fi
return 0
}
case "$1" in
start)
shorewall_start
;;
stop)
shorewall_stop
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0

View File

@@ -31,7 +31,7 @@ VERSION=xxx #The Build script inserts the actual version
usage() # $1 = exit status usage() # $1 = exit status
{ {
ME=$(basename $0) ME=$(basename $0)
echo "usage: $ME" echo "usage: $ME [ <shorewallrc file> ]"
exit $1 exit $1
} }
@@ -40,6 +40,27 @@ qt()
"$@" >/dev/null 2>&1 "$@" >/dev/null 2>&1
} }
split() {
local ifs
ifs=$IFS
IFS=:
set -- $1
echo $*
IFS=$ifs
}
mywhich() {
local dir
for dir in $(split $PATH); do
if [ -x $dir/$1 ]; then
return 0
fi
done
return 2
}
remove_file() # $1 = file to restore remove_file() # $1 = file to restore
{ {
if [ -f $1 -o -L $1 ] ; then if [ -f $1 -o -L $1 ] ; then
@@ -48,8 +69,37 @@ remove_file() # $1 = file to restore
fi fi
} }
if [ -f /usr/share/shorewall-init/version ]; then #
INSTALLED_VERSION="$(cat /usr/share/shorewall-init/version)" # Read the RC file
#
if [ $# -eq 0 ]; then
if [ -f ./shorewallrc ]; then
. ./shorewallrc
elif [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc || exit 1
file=./.shorewallrc
elif [ -f /usr/share/shorewall/shorewallrc ]; then
. /usr/share/shorewall/shorewallrc
else
fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
fi
elif [ $# -eq 1 ]; then
file=$1
case $file in
/*|.*)
;;
*)
file=./$file
;;
esac
. $file || exit 1
else
usage 1
fi
if [ -f ${SHAREDIR}/shorewall-init/version ]; then
INSTALLED_VERSION="$(cat ${SHAREDIR}/shorewall-init/version)"
if [ "$INSTALLED_VERSION" != "$VERSION" ]; then if [ "$INSTALLED_VERSION" != "$VERSION" ]; then
echo "WARNING: Shorewall Init Version $INSTALLED_VERSION is installed" echo "WARNING: Shorewall Init Version $INSTALLED_VERSION is installed"
echo " and this is the $VERSION uninstaller." echo " and this is the $VERSION uninstaller."
@@ -60,56 +110,55 @@ else
VERSION="" VERSION=""
fi fi
[ -n "${LIBEXEC:=/usr/share}" ] [ -n "${LIBEXEC:=${SHAREDIR}}" ]
echo "Uninstalling Shorewall Init $VERSION" echo "Uninstalling Shorewall Init $VERSION"
INITSCRIPT=/etc/init.d/shorewall-init INITSCRIPT=${CONFDIR}/init.d/shorewall-init
if [ -n "$INITSCRIPT" ]; then if [ -f "$INITSCRIPT" ]; then
if [ -x /usr/sbin/updaterc.d ]; then if mywhich updaterc.d ; then
updaterc.d shorewall-init remove updaterc.d shorewall-init remove
elif [ -x /sbin/insserv -o -x /usr/sbin/insserv ]; then elif mywhich insserv ; then
insserv -r $INITSCRIPT insserv -r $INITSCRIPT
elif [ -x /sbin/chkconfig -o -x /usr/sbin/chkconfig ]; then elif mywhich chkconfig ; then
chkconfig --del $(basename $INITSCRIPT) chkconfig --del $(basename $INITSCRIPT)
elif [ -x /sbin/systemctl ]; then elif mywhich systemctl ; then
systemctl disable shorewall-init systemctl disable shorewall-init
else
rm -f /etc/rc*.d/*$(basename $INITSCRIPT)
fi fi
remove_file $INITSCRIPT remove_file $INITSCRIPT
fi fi
[ "$(readlink -m -q /sbin/ifup-local)" = /usr/share/shorewall-init ] && remove_file /sbin/ifup-local [ "$(readlink -m -q ${SBINDIR}/ifup-local)" = ${SHAREDIR}/shorewall-init ] && remove_file ${SBINDIR}/ifup-local
[ "$(readlink -m -q /sbin/ifdown-local)" = /usr/share/shorewall-init ] && remove_file /sbin/ifdown-local [ "$(readlink -m -q ${SBINDIR}/ifdown-local)" = ${SHAREDIR}/shorewall-init ] && remove_file ${SBINDIR}/ifdown-local
remove_file /etc/default/shorewall-init remove_file ${CONFDIR}/default/shorewall-init
remove_file /etc/sysconfig/shorewall-init remove_file ${CONFDIR}/sysconfig/shorewall-init
remove_file /etc/NetworkManager/dispatcher.d/01-shorewall remove_file ${CONFDIR}/NetworkManager/dispatcher.d/01-shorewall
remove_file /etc/network/if-up.d/shorewall remove_file ${CONFDIR}/network/if-up.d/shorewall
remove_file /etc/network/if-down.d/shorewall remove_file ${CONFDIR}/network/if-down.d/shorewall
remove_file /etc/sysconfig/network/if-up.d/shorewall remove_file ${CONFDIR}/sysconfig/network/if-up.d/shorewall
remove_file /etc/sysconfig/network/if-down.d/shorewall remove_file ${CONFDIR}/sysconfig/network/if-down.d/shorewall
remove_file /lib/systemd/system/shorewall.service
if [ -d /etc/ppp ]; then [ -n "$SYSTEMD" ] && remove_file ${SYSTEMD}/shorewall.service
if [ -d ${CONFDIR}/ppp ]; then
for directory in ip-up.d ip-down.d ipv6-up.d ipv6-down.d; do for directory in ip-up.d ip-down.d ipv6-up.d ipv6-down.d; do
remove_file /etc/ppp/$directory/shorewall remove_file ${CONFDIR}/ppp/$directory/shorewall
done done
for file in if-up.local if-down.local; do for file in if-up.local if-down.local; do
if fgrep -q Shorewall-based /etc/ppp/$FILE; then if fgrep -q Shorewall-based ${CONFDIR}/ppp/$FILE; then
remove_file /etc/ppp/$FILE remove_file ${CONFDIR}/ppp/$FILE
fi fi
done done
fi fi
rm -rf /usr/share/shorewall-init rm -rf ${SHAREDIR}/shorewall-init
rm -rf ${LIBEXEC}/shorewall-init rm -rf ${LIBEXEC}/shorewall-init
echo "Shorewall Init Uninstalled" echo "Shorewall Init Uninstalled"

View File

@@ -3,16 +3,16 @@ VARDIR=$(shell /sbin/shorewall-lite show vardir)
SHAREDIR=/usr/share/shorewall-lite SHAREDIR=/usr/share/shorewall-lite
RESTOREFILE?=.restore RESTOREFILE?=.restore
all: $(VARDIR)/${RESTOREFILE} all: $(VARDIR)/$(RESTOREFILE)
$(VARDIR)/${RESTOREFILE}: $(VARDIR)/firewall $(VARDIR)/$(RESTOREFILE): $(VARDIR)/firewall
@/sbin/shorewall-lite -q save >/dev/null; \ @/sbin/shorewall-lite -q save >/dev/null; \
if \ if \
/sbin/shorewall-lite -q restart >/dev/null 2>&1; \ /sbin/shorewall-lite -q restart >/dev/null 2>&1; \
then \ then \
/sbin/shorewall-lite -q save >/dev/null; \ /sbin/shorewall-lite -q save >/dev/null; \
else \ else \
/sbin/shorewall-lite -q restart 2>&1 | tail >&2; \ /sbin/shorewall-lite -q restart 2>&1 | tail >&2; exit 1; \
fi fi
# EOF # EOF

View File

@@ -57,17 +57,23 @@ not_configured () {
exit 0 exit 0
} }
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
# parse the shorewall params file in order to use params in # parse the shorewall params file in order to use params in
# /etc/default/shorewall # /etc/default/shorewall
if [ -f "/etc/shorewall-lite/params" ]
if [ -f "$CONFDIR/shorewall-lite/params" ]
then then
. /etc/shorewall-lite/params . $CONFDIR/shorewall-lite/params
fi fi
# check if shorewall is configured or not # check if shorewall is configured or not
if [ -f "/etc/default/shorewall-lite" ] if [ -f "$SYSCONFDIR/shorewall-lite" ]
then then
. /etc/default/shorewall-lite . $SYSCONFDIR/shorewall-lite
SRWL_OPTS="$SRWL_OPTS $OPTIONS" SRWL_OPTS="$SRWL_OPTS $OPTIONS"
if [ "$startup" != "1" ] if [ "$startup" != "1" ]
then then

View File

@@ -20,16 +20,21 @@
# Source function library. # Source function library.
. /etc/rc.d/init.d/functions . /etc/rc.d/init.d/functions
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
prog="shorewall-lite" prog="shorewall-lite"
shorewall="/sbin/$prog" shorewall="${SBINDIR}/$prog"
logger="logger -i -t $prog" logger="logger -i -t $prog"
lockfile="/var/lock/subsys/$prog" lockfile="/var/lock/subsys/$prog"
# Get startup options (override default) # Get startup options (override default)
OPTIONS= OPTIONS=
if [ -f /etc/sysconfig/$prog ]; then if [ -f ${SYSCONFDIR}/$prog ]; then
. /etc/sysconfig/$prog . ${SYSCONFDIR}/$prog
fi fi
start() { start() {

View File

@@ -1,11 +1,11 @@
#!/bin/sh #!/bin/sh
RCDLINKS="2,S41 3,S41 6,K41" RCDLINKS="2,S41 3,S41 6,K41"
# #
# The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.1 # The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.5
# #
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt] # This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
# #
# (c) 1999,2000,2001,2002,2003,2004,2005,2006,2007 - Tom Eastep (teastep@shorewall.net) # (c) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2012 - Tom Eastep (teastep@shorewall.net)
# #
# On most distributions, this file should be called /etc/init.d/shorewall. # On most distributions, this file should be called /etc/init.d/shorewall.
# #
@@ -61,10 +61,14 @@ usage() {
# Get startup options (override default) # Get startup options (override default)
################################################################################ ################################################################################
OPTIONS= OPTIONS=
if [ -f /etc/sysconfig/shorewall ]; then
. /etc/sysconfig/shorewall #
elif [ -f /etc/default/shorewall ] ; then # The installer may alter this
. /etc/default/shorewall #
. /usr/share/shorewall/shorewallrc
if [ -f ${SYSCONFDIR}/shorewall-lite ]; then
. ${SYSCONFDIR}/shorewall-lite
fi fi
SHOREWALL_INIT_SCRIPT=1 SHOREWALL_INIT_SCRIPT=1
@@ -76,13 +80,13 @@ command="$1"
case "$command" in case "$command" in
start) start)
exec /sbin/shorewall-lite $OPTIONS start $STARTOPTIONS $@ exec ${SBINDIR}/shorewall-lite $OPTIONS start $STARTOPTIONS
;; ;;
restart|reload) restart|reload)
exec /sbin/shorewall-lite $OPTIONS restart $RESTARTOPTIONS $@ exec ${SBINDIR}/shorewall-lite $OPTIONS restart $RESTARTOPTIONS
;; ;;
status|stop) status|stop)
exec /sbin/shorewall-lite $OPTIONS $command $@ exec ${SBINDIR}/shorewall-lite $OPTIONS $command $@
;; ;;
*) *)
usage usage

View File

@@ -27,12 +27,18 @@ VERSION=xxx #The Build script inserts the actual version
usage() # $1 = exit status usage() # $1 = exit status
{ {
ME=$(basename $0) ME=$(basename $0)
echo "usage: $ME" echo "usage: $ME [ <configuration-file> ]"
echo " $ME -v" echo " $ME -v"
echo " $ME -h" echo " $ME -h"
exit $1 exit $1
} }
fatal_error()
{
echo " ERROR: $@" >&2
exit 1
}
split() { split() {
local ifs local ifs
ifs=$IFS ifs=$IFS
@@ -85,6 +91,11 @@ install_file() # $1 = source $2 = target $3 = mode
run_install $T $OWNERSHIP -m $3 $1 ${2} run_install $T $OWNERSHIP -m $3 $1 ${2}
} }
require()
{
eval [ -n "\$$1" ] || fatal_error "Required option $1 not set"
}
# #
# Change to the directory containing this script # Change to the directory containing this script
# #
@@ -98,68 +109,116 @@ else
Product="Shorewall6 Lite" Product="Shorewall6 Lite"
fi fi
[ -n "$DESTDIR" ] || DESTDIR="$PREFIX"
# #
# Parse the run line # Parse the run line
# #
# DEST is the SysVInit script directory finished=0
# INIT is the name of the script in the $DEST directory
#
if [ -z "$DEST" ] ; then
DEST="/etc/init.d"
fi
if [ -z "$INIT" ] ; then while [ $finished -eq 0 ] ; do
INIT="$PRODUCT"
fi
while [ $# -gt 0 ] ; do
case "$1" in case "$1" in
-h|help|?) -*)
usage 0 option=${option#-}
;;
-v) while [ -n "$option" ]; do
echo "$Product Firewall Installer Version $VERSION" case $option in
exit 0 h)
usage 0
;;
v)
echo "$Product Firewall Installer Version $VERSION"
exit 0
;;
*)
usage 1
;;
esac
done
shift
;; ;;
*) *)
usage 1 finished=1
;; ;;
esac esac
shift
done done
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin #
# Read the RC file
#
if [ $# -eq 0 ]; then
if [ -f ./shorewallrc ]; then
. ./shorewallrc || exit 1
file=./shorewallrc
elif [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc
elif [ -f /usr/share/shorewall/shorewallrc ]; then
. /usr/share/shorewall/shorewallrc
else
fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
fi
elif [ $# -eq 1 ]; then
file=$1
case $file in
/*|.*)
;;
*)
file=./$file
;;
esac
[ -n "${LIBEXEC:=/usr/share}" ] . $file
else
usage 1
fi
case "$LIBEXEC" in for var in SHAREDIR LIBEXECDIRDIRDIR CONFDIR SBINDIR VARDIR; do
/*) require $var
;; done
*)
LIBEXEC=/usr/${LIBEXEC} PATH=${SBINDIR}:/bin:/usr${SBINDIR}:/usr/bin:/usr/local/bin:/usr/local${SBINDIR}
;;
esac
# #
# Determine where to install the firewall script # Determine where to install the firewall script
# #
CYGWIN= cygwin=
INSTALLD='-D' INSTALLD='-D'
INITFILE=$PRODUCT
T='-T' T='-T'
case $(uname) in if [ -z "$BUILD" ]; then
CYGWIN*) case $(uname) in
if [ -z "$DESTDIR" ]; then cygwin*)
DEST= BUILD=cygwin
INIT= ;;
fi Darwin)
BUILD=apple
;;
*)
if [ -f ${CONFDIR}/debian_version ]; then
BUILD=debian
elif [ -f ${CONFDIR}/redhat-release ]; then
BUILD=redhat
elif [ -f ${CONFDIR}/SuSE-release ]; then
BUILD=suse
elif [ -f ${CONFDIR}/slackware-version ] ; then
BUILD=slackware
elif [ -f ${CONFDIR}/arch-release ] ; then
BUILD=archlinux
else
BUILD=linux
fi
;;
esac
fi
case $BUILD in
cygwin*)
OWNER=$(id -un) OWNER=$(id -un)
GROUP=$(id -gn) GROUP=$(id -gn)
;; ;;
Darwin) apple)
[ -z "$OWNER" ] && OWNER=root
[ -z "$GROUP" ] && GROUP=wheel
INSTALLD= INSTALLD=
T= T=
;; ;;
@@ -171,28 +230,53 @@ esac
OWNERSHIP="-o $OWNER -g $GROUP" OWNERSHIP="-o $OWNER -g $GROUP"
[ -n "$HOST" ] || HOST=$BUILD
case "$HOST" in
cygwin)
echo "$PRODUCT is not supported on Cygwin" >&2
exit 1
;;
apple)
echo "$PRODUCT is not supported on OS X" >&2
exit 1
;;
debian)
echo "Installing Debian-specific configuration..."
;;
redhat)
echo "Installing Redhat/Fedora-specific configuration..."
;;
slackware)
echo "Installing Slackware-specific configuration..."
;;
archlinux)
echo "Installing ArchLinux-specific configuration..."
;;
linux|suse)
;;
*)
echo "ERROR: Unknown HOST \"$HOST\"" >&2
exit 1;
;;
esac
[ -z "$INITDIR" ] && INITDIR="${CONFDIR}/init.d"
if [ -n "$DESTDIR" ]; then if [ -n "$DESTDIR" ]; then
if [ `id -u` != 0 ] ; then if [ `id -u` != 0 ] ; then
echo "Not setting file owner/group permissions, not running as root." echo "Not setting file owner/group permissions, not running as root."
OWNERSHIP="" OWNERSHIP=""
fi fi
install -d $OWNERSHIP -m 755 ${DESTDIR}/sbin install -d $OWNERSHIP -m 755 ${DESTDIR}/${SBINDIR}
install -d $OWNERSHIP -m 755 ${DESTDIR}${DEST} install -d $OWNERSHIP -m 755 ${DESTDIR}${INITDIR}
elif [ -d /etc/apt -a -e /usr/bin/dpkg ]; then
DEBIAN=yes
elif [ -f /etc/redhat-release ]; then
FEDORA=yes
elif [ -f /etc/slackware-version ] ; then
DEST="/etc/rc.d"
INIT="rc.firewall"
elif [ -f /etc/arch-release ] ; then
DEST="/etc/rc.d"
INIT="$PRODUCT"
ARCHLINUX=yes
fi
if [ -z "$DESTDIR" ]; then if [ -n "$SYSTEMD" ]; then
mkdir -p ${DESTDIR}/lib/systemd/system
INITFILE=
fi
else
if [ ! -f /usr/share/shorewall/coreversion ]; then if [ ! -f /usr/share/shorewall/coreversion ]; then
echo "$PRODUCT $VERSION requires Shorewall Core which does not appear to be installed" >&2 echo "$PRODUCT $VERSION requires Shorewall Core which does not appear to be installed" >&2
exit 1 exit 1
@@ -200,35 +284,34 @@ if [ -z "$DESTDIR" ]; then
if [ -f /lib/systemd/system ]; then if [ -f /lib/systemd/system ]; then
SYSTEMD=Yes SYSTEMD=Yes
INITFILE=
fi fi
elif [ -n "$SYSTEMD" ]; then
mkdir -p ${DESTDIR}/lib/systemd/system
fi fi
echo "Installing $Product Version $VERSION" echo "Installing $Product Version $VERSION"
# #
# Check for /etc/$PRODUCT # Check for ${CONFDIR}/$PRODUCT
# #
if [ -z "$DESTDIR" -a -d /etc/$PRODUCT ]; then if [ -z "$DESTDIR" -a -d ${CONFDIR}/$PRODUCT ]; then
if [ ! -f /usr/share/shorewall/coreversion ]; then if [ ! -f /usr/share/shorewall/coreversion ]; then
echo "$PRODUCT $VERSION requires Shorewall Core which does not appear to be installed" >&2 echo "$PRODUCT $VERSION requires Shorewall Core which does not appear to be installed" >&2
exit 1 exit 1
fi fi
[ -f /etc/$PRODUCT/shorewall.conf ] && \ [ -f ${CONFDIR}/$PRODUCT/shorewall.conf ] && \
mv -f /etc/$PRODUCT/shorewall.conf /etc/$PRODUCT/$PRODUCT.conf mv -f ${CONFDIR}/$PRODUCT/shorewall.conf ${CONFDIR}/$PRODUCT/$PRODUCT.conf
else else
rm -rf ${DESTDIR}/etc/$PRODUCT rm -rf ${DESTDIR}${CONFDIR}/$PRODUCT
rm -rf ${DESTDIR}/usr/share/$PRODUCT rm -rf ${DESTDIR}/usr/share/$PRODUCT
rm -rf ${DESTDIR}/var/lib/$PRODUCT rm -rf ${DESTDIR}/var/lib/$PRODUCT
[ "$LIBEXEC" = /usr/share ] || rm -rf /usr/share/$PRODUCT/wait4ifup /usr/share/$PRODUCT/shorecap [ "$LIBEXECDIR" = /usr/share ] || rm -rf ${DESTDIR}/usr/share/$PRODUCT/wait4ifup ${DESTDIR}/usr/share/$PRODUCT/shorecap
fi fi
# #
# Check for /sbin/$PRODUCT # Check for ${SBINDIR}/$PRODUCT
# #
if [ -f ${DESTDIR}/sbin/$PRODUCT ]; then if [ -f ${DESTDIR}${SBINDIR}/$PRODUCT ]; then
first_install="" first_install=""
else else
first_install="Yes" first_install="Yes"
@@ -236,113 +319,111 @@ fi
delete_file ${DESTDIR}/usr/share/$PRODUCT/xmodules delete_file ${DESTDIR}/usr/share/$PRODUCT/xmodules
install_file $PRODUCT ${DESTDIR}/sbin/$PRODUCT 0544 install_file $PRODUCT ${DESTDIR}${SBINDIR}/$PRODUCT 0544
echo "$Product control program installed in ${DESTDIR}/sbin/$PRODUCT" echo "$Product control program installed in ${DESTDIR}${SBINDIR}/$PRODUCT"
# #
# Install the Firewall Script # Create ${CONFDIR}/$PRODUCT, /usr/share/$PRODUCT and /var/lib/$PRODUCT if needed
# #
if [ -n "$DEBIAN" ]; then mkdir -p ${DESTDIR}${CONFDIR}/$PRODUCT
install_file init.debian.sh ${DESTDIR}/etc/init.d/$PRODUCT 0544
elif [ -n "$FEDORA" ]; then
install_file init.fedora.sh ${DESTDIR}/etc/init.d/$PRODUCT 0544
elif [ -n "$ARCHLINUX" ]; then
install_file init.archlinux.sh ${DESTDIR}/${DEST}/$INIT 0544
else
install_file init.sh ${DESTDIR}/${DEST}/$INIT 0544
fi
echo "$Product script installed in ${DESTDIR}${DEST}/$INIT"
#
# Create /etc/$PRODUCT, /usr/share/$PRODUCT and /var/lib/$PRODUCT if needed
#
mkdir -p ${DESTDIR}/etc/$PRODUCT
mkdir -p ${DESTDIR}/usr/share/$PRODUCT mkdir -p ${DESTDIR}/usr/share/$PRODUCT
mkdir -p ${DESTDIR}${LIBEXEC}/$PRODUCT mkdir -p ${DESTDIR}${LIBEXECDIR}/$PRODUCT
mkdir -p ${DESTDIR}/var/lib/$PRODUCT mkdir -p ${DESTDIR}/var/lib/$PRODUCT
chmod 755 ${DESTDIR}/etc/$PRODUCT chmod 755 ${DESTDIR}${CONFDIR}/$PRODUCT
chmod 755 ${DESTDIR}/usr/share/$PRODUCT chmod 755 ${DESTDIR}/usr/share/$PRODUCT
if [ -n "$DESTDIR" ]; then if [ -n "$DESTDIR" ]; then
mkdir -p ${DESTDIR}/etc/logrotate.d mkdir -p ${DESTDIR}${CONFDIR}/logrotate.d
chmod 755 ${DESTDIR}/etc/logrotate.d chmod 755 ${DESTDIR}${CONFDIR}/logrotate.d
mkdir -p ${DESTDIR}${INITDIR}
chmod 755 ${DESTDIR}${INITDIR}
fi fi
if [ -n "$INITFILE" ]; then
initfile="${DESTDIR}/${INITDIR}/${INITFILE}"
install_file ${INITSOURCE} "$initfile" 0544
[ "${SHAREDIR}" = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' "$initfile"
echo "$Product init script installed in $initfile"
fi
# #
# Install the .service file # Install the .service file
# #
if [ -n "$SYSTEMD" ]; then if [ -n "$SYSTEMD" ]; then
run_install $OWNERSHIP -m 600 $PRODUCT.service ${DESTDIR}/lib/systemd/system/$PRODUCT.service run_install $OWNERSHIP -m 600 $PRODUCT.service ${DESTDIR}/${SYSTEMD}/$PRODUCT.service
echo "Service file installed as ${DESTDIR}/lib/systemd/system/$PRODUCT.service" echo "Service file installed as ${DESTDIR}/lib/systemd/system/$PRODUCT.service"
fi fi
# #
# Install the config file # Install the config file
# #
if [ ! -f ${DESTDIR}/etc/$PRODUCT/$PRODUCT.conf ]; then if [ ! -f ${DESTDIR}${CONFDIR}/$PRODUCT/$PRODUCT.conf ]; then
install_file $PRODUCT.conf ${DESTDIR}/etc/$PRODUCT/$PRODUCT.conf 0744 install_file $PRODUCT.conf ${DESTDIR}${CONFDIR}/$PRODUCT/$PRODUCT.conf 0744
echo "Config file installed as ${DESTDIR}/etc/$PRODUCT/$PRODUCT.conf" echo "Config file installed as ${DESTDIR}${CONFDIR}/$PRODUCT/$PRODUCT.conf"
fi fi
if [ -n "$ARCHLINUX" ] ; then if [ $HOST = archlinux ] ; then
sed -e 's!LOGFILE=/var/log/messages!LOGFILE=/var/log/messages.log!' -i ${DESTDIR}/etc/$PRODUCT/$PRODUCT.conf sed -e 's!LOGFILE=/var/log/messages!LOGFILE=/var/log/messages.log!' -i ${DESTDIR}${CONFDIR}/$PRODUCT/$PRODUCT.conf
fi fi
# #
# Install the Makefile # Install the Makefile
# #
run_install $OWNERSHIP -m 0600 Makefile ${DESTDIR}/etc/$PRODUCT run_install $OWNERSHIP -m 0600 Makefile ${DESTDIR}${CONFDIR}/$PRODUCT
echo "Makefile installed as ${DESTDIR}/etc/$PRODUCT/Makefile" [ $SHAREDIR = /usr/share ] || eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}/${CONFDIR}/$PRODUCT/Makefile
[ $SBINDIR = /sbin ] || eval sed -i \'s\|/sbin/\|${SBINDIR}/\|\' ${DESTDIR}/${CONFDIR}/$PRODUCT/Makefile
echo "Makefile installed as ${DESTDIR}${CONFDIR}/$PRODUCT/Makefile"
# #
# Install the default config path file # Install the default config path file
# #
install_file configpath ${DESTDIR}/usr/share/$PRODUCT/configpath 0644 install_file configpath ${DESTDIR}${SHAREDIR}/$PRODUCT/configpath 0644
echo "Default config path file installed as ${DESTDIR}/usr/share/$PRODUCT/configpath" echo "Default config path file installed as ${DESTDIR}${SHAREDIR}/$PRODUCT/configpath"
# #
# Install the libraries # Install the libraries
# #
for f in lib.* ; do for f in lib.* ; do
if [ -f $f ]; then if [ -f $f ]; then
install_file $f ${DESTDIR}/usr/share/$PRODUCT/$f 0644 install_file $f ${DESTDIR}${SHAREDIR}/$PRODUCT/$f 0644
echo "Library ${f#*.} file installed as ${DESTDIR}/usr/share/$PRODUCT/$f" echo "Library ${f#*.} file installed as ${DESTDIR}/${SHAREDIR}/$PRODUCT/$f"
fi fi
done done
ln -sf lib.base ${DESTDIR}/usr/share/$PRODUCT/functions ln -sf lib.base ${DESTDIR}${SHAREDIR}/$PRODUCT/functions
echo "Common functions linked through ${DESTDIR}/usr/share/$PRODUCT/functions" echo "Common functions linked through ${DESTDIR}${SHAREDIR}/$PRODUCT/functions"
# #
# Install Shorecap # Install Shorecap
# #
install_file shorecap ${DESTDIR}${LIBEXEC}/$PRODUCT/shorecap 0755 install_file shorecap ${DESTDIR}${LIBEXECDIR}/$PRODUCT/shorecap 0755
echo echo
echo "Capability file builder installed in ${DESTDIR}${LIBEXEC}/$PRODUCT/shorecap" echo "Capability file builder installed in ${DESTDIR}${LIBEXECDIR}/$PRODUCT/shorecap"
# #
# Install the Modules files # Install the Modules files
# #
if [ -f modules ]; then if [ -f modules ]; then
run_install $OWNERSHIP -m 0600 modules ${DESTDIR}/usr/share/$PRODUCT run_install $OWNERSHIP -m 0600 modules ${DESTDIR}${SHAREDIR}/$PRODUCT
echo "Modules file installed as ${DESTDIR}/usr/share/$PRODUCT/modules" echo "Modules file installed as ${DESTDIR}${SHAREDIR}/$PRODUCT/modules"
fi fi
if [ -f helpers ]; then if [ -f helpers ]; then
run_install $OWNERSHIP -m 0600 helpers ${DESTDIR}/usr/share/$PRODUCT run_install $OWNERSHIP -m 0600 helpers ${DESTDIR}${SHAREDIR}/$PRODUCT
echo "Helper modules file installed as ${DESTDIR}/usr/share/$PRODUCT/helpers" echo "Helper modules file installed as ${DESTDIR}${SHAREDIR}/$PRODUCT/helpers"
fi fi
for f in modules.*; do for f in modules.*; do
run_install $OWNERSHIP -m 0644 $f ${DESTDIR}/usr/share/$PRODUCT/$f run_install $OWNERSHIP -m 0644 $f ${DESTDIR}${SHAREDIR}/$PRODUCT/$f
echo "Module file $f installed as ${DESTDIR}/usr/share/$PRODUCT/$f" echo "Module file $f installed as ${DESTDIR}${SHAREDIR}/$PRODUCT/$f"
done done
# #
@@ -352,18 +433,18 @@ done
if [ -d manpages ]; then if [ -d manpages ]; then
cd manpages cd manpages
[ -n "$INSTALLD" ] || mkdir -p ${DESTDIR}/usr/share/man/man5/ ${DESTDIR}/usr/share/man/man8/ [ -n "$INSTALLD" ] || mkdir -p ${DESTDIR}${SHAREDIR}/man/man5/ ${DESTDIR}${SHAREDIR}/man/man8/
for f in *.5; do for f in *.5; do
gzip -c $f > $f.gz gzip -c $f > $f.gz
run_install $T $INSTALLD $OWNERSHIP -m 0644 $f.gz ${DESTDIR}/usr/share/man/man5/$f.gz run_install $T $INSTALLD $OWNERSHIP -m 0644 $f.gz ${DESTDIR}${SHAREDIR}/man/man5/$f.gz
echo "Man page $f.gz installed to ${DESTDIR}/usr/share/man/man5/$f.gz" echo "Man page $f.gz installed to ${DESTDIR}${SHAREDIR}/man/man5/$f.gz"
done done
for f in *.8; do for f in *.8; do
gzip -c $f > $f.gz gzip -c $f > $f.gz
run_install $T $INSTALLD $OWNERSHIP -m 0644 $f.gz ${DESTDIR}/usr/share/man/man8/$f.gz run_install $T $INSTALLD $OWNERSHIP -m 0644 $f.gz ${DESTDIR}${SHAREDIR}/man/man8/$f.gz
echo "Man page $f.gz installed to ${DESTDIR}/usr/share/man/man8/$f.gz" echo "Man page $f.gz installed to ${DESTDIR}${SHAREDIR}/man/man8/$f.gz"
done done
cd .. cd ..
@@ -371,73 +452,79 @@ if [ -d manpages ]; then
echo "Man Pages Installed" echo "Man Pages Installed"
fi fi
if [ -d ${DESTDIR}/etc/logrotate.d ]; then if [ -d ${DESTDIR}${CONFDIR}/logrotate.d ]; then
run_install $OWNERSHIP -m 0644 logrotate ${DESTDIR}/etc/logrotate.d/$PRODUCT run_install $OWNERSHIP -m 0644 logrotate ${DESTDIR}${CONFDIR}/logrotate.d/$PRODUCT
echo "Logrotate file installed as ${DESTDIR}/etc/logrotate.d/$PRODUCT" echo "Logrotate file installed as ${DESTDIR}${CONFDIR}/logrotate.d/$PRODUCT"
fi fi
# #
# Create the version file # Create the version file
# #
echo "$VERSION" > ${DESTDIR}/usr/share/$PRODUCT/version echo "$VERSION" > ${DESTDIR}${SHAREDIR}/$PRODUCT/version
chmod 644 ${DESTDIR}/usr/share/$PRODUCT/version chmod 644 ${DESTDIR}${SHAREDIR}/$PRODUCT/version
# #
# Remove and create the symbolic link to the init script # Remove and create the symbolic link to the init script
# #
if [ -z "$DESTDIR" ]; then if [ -z "$DESTDIR" ]; then
rm -f /usr/share/$PRODUCT/init rm -f ${SHAREDIR}/$PRODUCT/init
ln -s ${DEST}/${INIT} /usr/share/$PRODUCT/init ln -s ${INITDIR}/${INITFILE} ${SHAREDIR}/$PRODUCT/init
fi fi
delete_file ${DESTDIR}/usr/share/$PRODUCT/lib.common delete_file ${DESTDIR}${SHAREDIR}/$PRODUCT/lib.common
delete_file ${DESTDIR}/usr/share/$PRODUCT/lib.cli delete_file ${DESTDIR}${SHAREDIR}/$PRODUCT/lib.cli
delete_file ${DESTDIR}/usr/share/$PRODUCT/wait4ifup delete_file ${DESTDIR}${SHAREDIR}/$PRODUCT/wait4ifup
if [ -z "$DESTDIR" ]; then if [ -n "$SYSCONFFILE" -a ! -f ${DESTDIR}${SYSCONFDIR}/${PRODUCT} ]; then
touch /var/log/$PRODUCT-init.log if [ ${DESTDIR} ]; then
mkdir -p ${DESTDIR}${SYSCONFDIR}
chmod 755 ${DESTDIR}${SYSCONFDIR}
fi
if [ -n "$first_install" ]; then run_install $OWNERSHIP -m 0644 default.debian ${DESTDIR}${SYSCONFDIR}/${PRODUCT}
if [ -n "$DEBIAN" ]; then echo "$SYSCONFFILE installed in ${DESTDIR}${SYSCONFDIR}/${PRODUCT}"
run_install $OWNERSHIP -m 0644 default.debian /etc/default/$PRODUCT fi
update-rc.d $PRODUCT defaults if [ ${SHAREDIR} != /usr/share ]; then
eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}/${SHAREDIR}/${PRODUCT}/lib.base
if [ -x /sbin/insserv ]; then eval sed -i \'s\|/usr/share/\|${SHAREDIR}/\|\' ${DESTDIR}/${SBINDIR}/$PRODUCT
insserv /etc/init.d/$PRODUCT fi
else
ln -s ../init.d/$PRODUCT /etc/rcS.d/S40$PRODUCT
fi
if [ -z "$DESTDIR" -a -n "$first_install" -a -z "${cygwin}${mac}" ]; then
if mywhich update-rc.d ; then
echo "$PRODUCT will start automatically at boot"
echo "Set startup=1 in ${SYSCONFDIR}/$PRODUCT to enable"
touch /var/log/$PRODUCT-init.log
perl -p -w -i -e 's/^STARTUP_ENABLED=No/STARTUP_ENABLED=Yes/;s/^IP_FORWARDING=On/IP_FORWARDING=Keep/;s/^SUBSYSLOCK=.*/SUBSYSLOCK=/;' ${CONFDIR}/${PRODUCT}/${PRODUCT}.conf
update-rc.d $PRODUCT enable defaults
elif [ -n "$SYSTEMD" ]; then
if systemctl enable $PRODUCT; then
echo "$Product will start automatically at boot" echo "$Product will start automatically at boot"
else
if [ -n "$SYSTEMD" ]; then
if systemctl enable $PRODUCT; then
echo "$Product will start automatically at boot"
fi
elif [ -x /sbin/insserv -o -x /usr/sbin/insserv ]; then
if insserv /etc/init.d/$PRODUCT ; then
echo "$Product will start automatically at boot"
else
cant_autostart
fi
elif [ -x /sbin/chkconfig -o -x /usr/sbin/chkconfig ]; then
if chkconfig --add $PRODUCT ; then
echo "$Product will start automatically in run levels as follows:"
chkconfig --list $PRODUCT
else
cant_autostart
fi
elif [ -x /sbin/rc-update ]; then
if rc-update add $PRODUCT default; then
echo "$Product will start automatically at boot"
else
cant_autostart
fi
elif [ "$INIT" != rc.firewall ]; then #Slackware starts this automatically
cant_autostart
fi
fi fi
elif mywhich insserv; then
if insserv ${INITDIR}/${INITFILE} ; then
echo "$PRODUCT will start automatically at boot"
echo "Set STARTUP_ENABLED=Yes in ${CONFDIR}/$PRODUCT/${PRODUCT}.conf to enable"
else
cant_autostart
fi
elif mywhich chkconfig; then
if chkconfig --add $PRODUCT ; then
echo "$PRODUCT will start automatically in run levels as follows:"
echo "Set STARTUP_ENABLED=Yes in ${CONFDIR}/$PRODUCT/${PRODUCT}.conf to enable"
chkconfig --list $PRODUCT
else
cant_autostart
fi
elif mywhich rc-update ; then
if rc-update add $PRODUCT default; then
echo "$PRODUCT will start automatically at boot"
echo "Set STARTUP_ENABLED=Yes in ${CONFDIR}/$PRODUCT/$PRODUCT.conf to enable"
else
cant_autostart
fi
elif [ "$INITFILE" != rc.${PRODUCT} ]; then #Slackware starts this automatically
cant_autostart
fi fi
fi fi

View File

@@ -24,11 +24,10 @@
g_program=shorewall-lite g_program=shorewall-lite
g_family=4 g_family=4
#
# This may be altered by the installer
#
g_basedir=/usr/share/shorewall g_basedir=/usr/share/shorewall
[ -n "${VARDIR:=/var/lib/$g_program}" ] . ${g_basedir}/lib.base
[ -n "${SHAREDIR:=/usr/share/$g_program}" ]
[ -n "${CONFDIR:=/etc/$g_program}" ]
. /usr/share/shorewall/lib.base

View File

@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
<refentry> <refentry>
<refmeta> <refmeta>
<refentrytitle>shorewall-lite-vardir</refentrytitle> <refentrytitle>shorewall-lite-vardir</refentrytitle>
@@ -34,6 +36,28 @@
directory. If you add this file, you should copy the files from directory. If you add this file, you should copy the files from
<filename>/var/lib/shorewall-lite</filename> to the new directory before <filename>/var/lib/shorewall-lite</filename> to the new directory before
performing a <command>shorewall-lite restart</command>.</para> performing a <command>shorewall-lite restart</command>.</para>
<note>
<para>Beginning with Shorewall 4.5.2, use of this file is deprecated in
favor of specifying VARDIR in the <filename>shorewallrc</filename> file
used during installation of Shorewall Core. While the name of the
variable remains VARDIR, the meaning is slightly different. When set in
shorewallrc, Shorewall Lite, will create a directory under the specified
path name to hold state information.</para>
<para>Example:</para>
<blockquote>
<para>VARDIR=<filename><filename>/opt/var/lib/</filename></filename></para>
<para>The state directory for Shorewall Lite will be
/opt/var/lib/shorewall-lite/.</para>
</blockquote>
<para> When VARDIR is set in /etc/shorewall-lite/vardir, Shorewall Lite
will save its state in the <replaceable>directory</replaceable>
specified.</para>
</note>
</refsect1> </refsect1>
<refsect1> <refsect1>

View File

@@ -517,15 +517,17 @@
defined in the <ulink defined in the <ulink
url="shorewall-interfaces.html">shorewall-interfaces</ulink>(5) url="shorewall-interfaces.html">shorewall-interfaces</ulink>(5)
file. A <emphasis>host-list</emphasis> is comma-separated list whose file. A <emphasis>host-list</emphasis> is comma-separated list whose
elements are host or network addresses.<caution> elements are host or network addresses.</para>
<para>The <command>add</command> command is not very robust. If
there are errors in the <replaceable>host-list</replaceable>, <caution>
you may see a large number of error messages yet a subsequent <para>The <command>add</command> command is not very robust. If
<command>shorewall-lite show zones</command> command will there are errors in the <replaceable>host-list</replaceable>, you
indicate that all hosts were added. If this happens, replace may see a large number of error messages yet a subsequent
<command>add</command> by <command>delete</command> and run the <command>shorewall-lite show zones</command> command will indicate
same command again. Then enter the correct command.</para> that all hosts were added. If this happens, replace
</caution></para> <command>add</command> by <command>delete</command> and run the
same command again. Then enter the correct command.</para>
</caution>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@@ -27,6 +27,18 @@
################################################################################################ ################################################################################################
g_program=shorewall-lite g_program=shorewall-lite
. /usr/share/shorewall/lib.cli #
# This is modified by the installer when ${SHAREDIR} != /usr/share
#
. /usr/share/shorewall/shorewallrc
g_libexec="$LIBEXECDIR"
g_sharedir="$SHAREDIR"/shorewall-lite
g_sbindir="$SBINDIR"
g_vardir="$VARDIR"
g_confdir="$CONFDIR"/shorewall-lite
g_readrc=1
. ${SHAREDIR}/shorewall/lib.cli
shorewall_cli $@ shorewall_cli $@

View File

@@ -31,7 +31,7 @@ VERSION=xxx #The Build script inserts the actual version
usage() # $1 = exit status usage() # $1 = exit status
{ {
ME=$(basename $0) ME=$(basename $0)
echo "usage: $ME" echo "usage: $ME [ <shorewallrc file> ]"
exit $1 exit $1
} }
@@ -40,16 +40,25 @@ qt()
"$@" >/dev/null 2>&1 "$@" >/dev/null 2>&1
} }
restore_file() # $1 = file to restore split() {
{ local ifs
if [ -f ${1}-shorewall.bkout ]; then ifs=$IFS
if (mv -f ${1}-shorewall-lite.bkout $1); then IFS=:
echo set -- $1
echo "$1 restored" echo $*
else IFS=$ifs
exit 1 }
fi
fi mywhich() {
local dir
for dir in $(split $PATH); do
if [ -x $dir/$1 ]; then
return 0
fi
done
return 2
} }
remove_file() # $1 = file to restore remove_file() # $1 = file to restore
@@ -60,8 +69,37 @@ remove_file() # $1 = file to restore
fi fi
} }
if [ -f /usr/share/shorewall-lite/version ]; then #
INSTALLED_VERSION="$(cat /usr/share/shorewall-lite/version)" # Read the RC file
#
if [ $# -eq 0 ]; then
if [ -f ./shorewallrc ]; then
. ./shorewallrc
elif [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc || exit 1
file=./.shorewallrc
elif [ -f /usr/share/shorewall/shorewallrc ]; then
. /usr/share/shorewall/shorewallrc
else
fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
fi
elif [ $# -eq 1 ]; then
file=$1
case $file in
/*|.*)
;;
*)
file=./$file
;;
esac
. $file
else
usage 1
fi
if [ -f ${SHAREDIR}/shorewall-lite/version ]; then
INSTALLED_VERSION="$(cat ${SHAREDIR}/shorewall-lite/version)"
if [ "$INSTALLED_VERSION" != "$VERSION" ]; then if [ "$INSTALLED_VERSION" != "$VERSION" ]; then
echo "WARNING: Shorewall Lite Version $INSTALLED_VERSION is installed" echo "WARNING: Shorewall Lite Version $INSTALLED_VERSION is installed"
echo " and this is the $VERSION uninstaller." echo " and this is the $VERSION uninstaller."
@@ -72,49 +110,40 @@ else
VERSION="" VERSION=""
fi fi
[ -n "${LIBEXEC:=/usr/share}" ]
echo "Uninstalling Shorewall Lite $VERSION" echo "Uninstalling Shorewall Lite $VERSION"
if qt iptables -L shorewall -n && [ ! -f /sbin/shorewall ]; then if qt iptables -L shorewall -n && [ ! -f ${SBINDIR}/shorewall ]; then
/sbin/shorewall-lite clear shorewall-lite clear
fi fi
if [ -L /usr/share/shorewall-lite/init ]; then if [ -L ${SHAREDIR}/shorewall-lite/init ]; then
FIREWALL=$(readlink -m -q /usr/share/shorewall-lite/init) FIREWALL=$(readlink -m -q ${SHAREDIR}/shorewall-lite/init)
else elIF [ -n "$INITFILE" ]; then
FIREWALL=/etc/init.d/shorewall-lite FIREWALL=${INITDIR}/${INITFILE}
fi fi
if [ -n "$FIREWALL" ]; then if [ -f "$FIREWALL" ]; then
if [ -x /usr/sbin/updaterc.d ]; then if mywhich updaterc.d ; then
updaterc.d shorewall-lite remove updaterc.d shorewall-lite remove
elif [ -x /sbin/insserv -o -x /usr/sbin/insserv ]; then elif if mywhich insserv ; then
insserv -r $FIREWALL insserv -r $FIREWALL
elif [ -x /sbin/chkconfig -o -x /usr/sbin/chkconfig ]; then elif [ mywhich chkconfig ; then
chkconfig --del $(basename $FIREWALL) chkconfig --del $(basename $FIREWALL)
elif [ -x /sbin/systemctl ]; then elif mywhich systemctl ; then
systemctl disable shorewall-lite systemctl disable shorewall-lite
else
rm -f /etc/rc*.d/*$(basename $FIREWALL)
fi fi
remove_file $FIREWALL remove_file $FIREWALL
rm -f ${FIREWALL}-*.bkout
fi fi
rm -f /sbin/shorewall-lite rm -f ${SBINDIR}/shorewall-lite
rm -f /sbin/shorewall-lite-*.bkout
rm -rf /etc/shorewall-lite rm -rf ${SBINDIR}/shorewall-lite
rm -rf /etc/shorewall-lite-*.bkout rm -rf ${VARDIR}/shorewall-lite
rm -rf /var/lib/shorewall-lite rm -rf ${SHAREDIR}/shorewall-lite
rm -rf /var/lib/shorewall-lite-*.bkout
rm -rf /usr/share/shorewall-lite
rm -rf ${LIBEXEC}/shorewall-lite rm -rf ${LIBEXEC}/shorewall-lite
rm -rf /usr/share/shorewall-lite-*.bkout rm -f ${CONFDIR}/logrotate.d/shorewall-lite
rm -f /etc/logrotate.d/shorewall-lite [ -n "$SYSTEMD" ] && rm -f ${SYSTEMD}/shorewall-lite.service
rm -f /lib/systemd/system/shorewall-lite.service
echo "Shorewall Lite Uninstalled" echo "Shorewall Lite Uninstalled"

View File

@@ -11,6 +11,7 @@
#ACTION SOURCE DEST PROTO DEST SOURCE RATE USER/ #ACTION SOURCE DEST PROTO DEST SOURCE RATE USER/
# PORT(S) PORT(S) LIMIT GROUP # PORT(S) PORT(S) LIMIT GROUP
PARAM - - udp 10080 PARAM - - udp 10080
PARAM - - tcp 10080
# #
# You may also need this rule. With AMANDA 2.4.4 on Linux kernel 2.6, # You may also need this rule. With AMANDA 2.4.4 on Linux kernel 2.6,
# it should not be necessary to use this. The ip_conntrack_amanda # it should not be necessary to use this. The ip_conntrack_amanda

View File

@@ -0,0 +1,11 @@
#
# Shorewall version 4 - blacklist Macro
#
# /usr/share/shorewall/macro.blacklist
#
# This macro handles blacklisting using BLACKLIST_DISPOSITION and BLACKLIST_LOGLEVEL
#
###############################################################################
#ACTION SOURCE DEST PROTO DEST SOURCE RATE USER/
# PORT(S) PORT(S) LIMIT GROUP
$BLACKLIST_DISPOSITION:$BLACKLIST_LOGLEVEL

View File

@@ -2,20 +2,22 @@
VARDIR=$(shell /sbin/shorewall show vardir) VARDIR=$(shell /sbin/shorewall show vardir)
CONFDIR=/etc/shorewall CONFDIR=/etc/shorewall
RESTOREFILE?=firewall RESTOREFILE?=firewall
all: $(VARDIR)/${RESTOREFILE}
$(VARDIR)/${RESTOREFILE}: $(CONFDIR)/* all: $(VARDIR)/$(RESTOREFILE)
$(VARDIR)/$(RESTOREFILE): $(CONFDIR)/*
@/sbin/shorewall -q save >/dev/null; \ @/sbin/shorewall -q save >/dev/null; \
if \ if \
/sbin/shorewall -q restart >/dev/null 2>&1; \ /sbin/shorewall -q restart >/dev/null 2>&1; \
then \ then \
/sbin/shorewall -q save >/dev/null; \ /sbin/shorewall -q save >/dev/null; \
else \ else \
/sbin/shorewall -q restart 2>&1 | tail >&2; \ /sbin/shorewall -q restart 2>&1 | tail >&2; exit 1; \
fi fi
clean: clean:
@rm -f $(CONFDIR)/*~ $(CONFDIR)/.*~ @rm -f $(CONFDIR)/*~ $(CONFDIR)/.*~
.PHONY: clean .PHONY: clean
# EOF # EOF

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Shorewall</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.epic.perleditor.perlbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.epic.perleditor.perlnature</nature>
</natures>
</projectDescription>

View File

@@ -322,7 +322,7 @@ sub process_accounting_rule( ) {
} }
} }
dont_optimize( $chainref ) if $target eq 'RETURN'; set_optflags( $chainref, DONT_OPTIMIZE ) if $target eq 'RETURN';
if ( $jumpchainref ) { if ( $jumpchainref ) {
if ( $asection ) { if ( $asection ) {
@@ -407,7 +407,7 @@ sub setup_accounting() {
} }
if ( $tableref->{accounting} ) { if ( $tableref->{accounting} ) {
dont_optimize( 'accounting' ); set_optflags( 'accounting' , DONT_OPTIMIZE );
for my $chain ( qw/INPUT FORWARD/ ) { for my $chain ( qw/INPUT FORWARD/ ) {
insert_ijump( $tableref->{$chain}, j => 'accounting', 0 ); insert_ijump( $tableref->{$chain}, j => 'accounting', 0 );
} }
@@ -429,7 +429,7 @@ sub setup_accounting() {
insert_ijump( $tableref->{POSTROUTING}, j => 'accountpost', 0 ); insert_ijump( $tableref->{POSTROUTING}, j => 'accountpost', 0 );
} }
} elsif ( $tableref->{accounting} ) { } elsif ( $tableref->{accounting} ) {
dont_optimize( 'accounting' ); set_optflags( 'accounting' , DONT_OPTIMIZE );
for my $chain ( qw/INPUT FORWARD OUTPUT/ ) { for my $chain ( qw/INPUT FORWARD OUTPUT/ ) {
insert_ijump( $tableref->{$chain}, j => 'accounting', 0 ); insert_ijump( $tableref->{$chain}, j => 'accounting', 0 );
} }

View File

@@ -36,6 +36,10 @@ use strict;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT = qw( our @EXPORT = qw(
DONT_OPTIMIZE
DONT_DELETE
DONT_MOVE
add_rule add_rule
add_irule add_irule
add_jump add_jump
@@ -62,6 +66,11 @@ our @EXPORT = qw(
require_audit require_audit
newlogchain newlogchain
log_rule_limit log_rule_limit
allow_optimize
allow_delete
allow_move
set_optflags
reset_optflags
dont_optimize dont_optimize
dont_delete dont_delete
dont_move dont_move
@@ -182,6 +191,7 @@ our %EXPORT_TAGS = (
do_time do_time
do_user do_user
do_length do_length
decode_tos
do_tos do_tos
do_connbytes do_connbytes
do_helper do_helper
@@ -189,6 +199,7 @@ our %EXPORT_TAGS = (
do_headers do_headers
do_probability do_probability
do_condition do_condition
do_dscp
have_ipset_rules have_ipset_rules
record_runtime_address record_runtime_address
conditional_rule conditional_rule
@@ -228,6 +239,7 @@ our %EXPORT_TAGS = (
create_chainlist_reload create_chainlist_reload
create_stop_load create_stop_load
%targets %targets
%dscpmap
) ], ) ],
); );
@@ -246,9 +258,7 @@ our $VERSION = 'MODULEVERSION';
# builtin => undef|1 -- If 1, one of Netfilter's built-in chains. # builtin => undef|1 -- If 1, one of Netfilter's built-in chains.
# manual => undef|1 -- If 1, a manual chain. # manual => undef|1 -- If 1, a manual chain.
# accounting => undef|1 -- If 1, an accounting chain # accounting => undef|1 -- If 1, an accounting chain
# dont_optimize=> undef|1 -- Don't optimize away if this chain is 'short' # optflags => <optimization flags>
# dont_delete => undef|1 -- Don't delete if this chain is not referenced
# dont_move => undef|1 -- Don't copy the rules of this chain somewhere else
# log => <logging rule number for use when LOGRULENUMBERS> # log => <logging rule number for use when LOGRULENUMBERS>
# policy => <policy> # policy => <policy>
# policychain => <name of policy chain> -- self-reference if this is a policy chain # policychain => <name of policy chain> -- self-reference if this is a policy chain
@@ -360,6 +370,37 @@ use constant {
use constant { OPTIMIZE_MASK => OPTIMIZE_POLICY_MASK | OPTIMIZE_RULESET_MASK }; use constant { OPTIMIZE_MASK => OPTIMIZE_POLICY_MASK | OPTIMIZE_RULESET_MASK };
use constant { DONT_OPTIMIZE => 1 , DONT_DELETE => 2, DONT_MOVE => 4 };
our %dscpmap = ( CS0 => 0x00,
CS1 => 0x08,
CS2 => 0x10,
CS3 => 0x18,
CS4 => 0x20,
CS5 => 0x28,
CS6 => 0x30,
CS7 => 0x38,
BE => 0x00,
AF11 => 0x0a,
AF12 => 0x0c,
AF13 => 0x0e,
AF21 => 0x12,
AF22 => 0x14,
AF23 => 0x16,
AF31 => 0x1a,
AF32 => 0x1c,
AF33 => 0x1e,
AF41 => 0x22,
AF42 => 0x24,
AF43 => 0x26,
EF => 0x2e,
);
our %tosmap = ( 'Minimize-Delay' => 0x10,
'Maximize-Throughput' => 0x08,
'Maximize-Reliability' => 0x04,
'Minimize-Cost' => 0x02,
'Normal-Service' => 0x00 );
# #
# These hashes hold the shell code to set shell variables. The key is the name of the variable; the value is the code to generate the variable's contents # These hashes hold the shell code to set shell variables. The key is the name of the variable; the value is the code to generate the variable's contents
# #
@@ -683,17 +724,19 @@ sub set_rule_option( $$$ ) {
assert( defined( my $value1 = $ruleref->{$option} ) ); assert( defined( my $value1 = $ruleref->{$option} ) );
if ( $opttype == MATCH ) { if ( $opttype == MATCH ) {
assert( $globals{KLUDGEFREE} ); if ( $globals{KLUDGEFREE} ) {
unless ( reftype $value1 ) {
unless ( reftype $value ) {
return if $value1 eq $value;
}
unless ( reftype $value1 ) { $ruleref->{$option} = [ $ruleref->{$option} ];
unless ( reftype $value ) {
return if $value1 eq $value;
} }
$ruleref->{$option} = [ $ruleref->{$option} ]; push @{$ruleref->{$option}}, ( reftype $value ? @$value : $value );
} else {
$ruleref->{$option} = join(' ', $value1, $value );
} }
push @{$ruleref->{$option}}, ( reftype $value ? @$value : $value );
} elsif ( $opttype == EXCLUSIVE ) { } elsif ( $opttype == EXCLUSIVE ) {
$ruleref->{$option} .= ",$value"; $ruleref->{$option} .= ",$value";
} elsif ( $opttype == UNIQUE ) { } elsif ( $opttype == UNIQUE ) {
@@ -1151,7 +1194,7 @@ sub push_matches {
} }
} }
$dont_optimize; DONT_OPTIMIZE if $dont_optimize;
} }
sub push_irule( $$$;@ ) { sub push_irule( $$$;@ ) {
@@ -1180,7 +1223,7 @@ sub push_irule( $$$;@ ) {
$chainref->{referenced} = 1; $chainref->{referenced} = 1;
unless ( $ruleref->{simple} = ! @matches ) { unless ( $ruleref->{simple} = ! @matches ) {
$chainref->{dont_optimize} = 1 if push_matches( $ruleref, @matches ); $chainref->{optflags} |= push_matches( $ruleref, @matches );
} }
push @{$chainref->{rules}}, $ruleref; push @{$chainref->{rules}}, $ruleref;
@@ -1294,7 +1337,7 @@ sub insert_irule( $$$$;@ ) {
} }
unless ( $ruleref->{simple} = ! @matches ) { unless ( $ruleref->{simple} = ! @matches ) {
$chainref->{dont_optimize} = 1 if push_matches( $ruleref, @matches ); $chainref->{optflags} |= push_matches( $ruleref, @matches );
} }
if ( $comment ) { if ( $comment ) {
@@ -1867,7 +1910,8 @@ sub new_chain($$)
log => 1, log => 1,
cmdlevel => 0, cmdlevel => 0,
references => {}, references => {},
filtered => 0 filtered => 0,
optflags => 0,
}; };
trace( $chainref, 'N', undef, '' ) if $debug; trace( $chainref, 'N', undef, '' ) if $debug;
@@ -1928,7 +1972,7 @@ sub add_jump( $$$;$$$ ) {
my $param = $goto_ok && $toref && have_capability( 'GOTO_TARGET' ) ? 'g' : 'j'; my $param = $goto_ok && $toref && have_capability( 'GOTO_TARGET' ) ? 'g' : 'j';
$fromref->{dont_optimize} = 1 if $predicate =~ /! -[piosd] /; $fromref->{optflags} |= DONT_OPTIMIZE if $predicate =~ /! -[piosd] /;
if ( defined $index ) { if ( defined $index ) {
assert( ! $expandports ); assert( ! $expandports );
@@ -2052,49 +2096,70 @@ sub delete_jumps ( $$ ) {
} }
} }
# sub reset_optflags( $$ ) {
# Set the dont_optimize flag for a chain my ( $chain, $flags ) = @_;
#
sub dont_optimize( $ ) {
my $chain = shift;
my $chainref = reftype $chain ? $chain : $filter_table->{$chain}; my $chainref = reftype $chain ? $chain : $filter_table->{$chain};
$chainref->{dont_optimize} = 1; $chainref->{optflags} ^= $flags;
trace( $chainref, '!O', undef, '' ) if $debug;
$chainref;
}
sub set_optflags( $$ ) {
my ( $chain, $flags ) = @_;
my $chainref = reftype $chain ? $chain : $filter_table->{$chain};
$chainref->{optflags} |= $flags;
trace( $chainref, '!O', undef, '' ) if $debug; trace( $chainref, '!O', undef, '' ) if $debug;
$chainref; $chainref;
} }
#
# Reset the dont_optimize flag for a chain
#
sub allow_optimize( $ ) {
reset_optflags( shift, DONT_OPTIMIZE );
}
#
# Reset the dont_delete flags for a chain
#
sub allow_delete( $ ) {
reset_optflags( shift, DONT_DELETE );
}
#
# Reset the dont_move flag for a chain
#
sub allow_move( $ ) {
reset_optflags( shift, DONT_MOVE );
}
#
# Set the dont_optimize flag for a chain
#
sub dont_optimize( $ ) {
set_optflags( shift, DONT_OPTIMIZE );
}
# #
# Set the dont_optimize and dont_delete flags for a chain # Set the dont_optimize and dont_delete flags for a chain
# #
sub dont_delete( $ ) { sub dont_delete( $ ) {
my $chain = shift; set_optflags( shift, DONT_OPTIMIZE | DONT_DELETE );
my $chainref = reftype $chain ? $chain : $filter_table->{$chain};
$chainref->{dont_optimize} = $chainref->{dont_delete} = 1;
trace( $chainref, '!OD', undef, '' ) if $debug;
$chainref;
} }
# #
# Set the dont_move flag for a chain # Set the dont_move flag for a chain
# #
sub dont_move( $ ) { sub dont_move( $ ) {
my $chain = shift; set_optflags( shift, DONT_MOVE );
my $chainref = reftype $chain ? $chain : $filter_table->{$chain};
$chainref->{dont_move} = 1;
trace( $chainref, '!M', undef, '' ) if $debug;
$chainref;
} }
# #
@@ -2136,7 +2201,7 @@ sub ensure_accounting_chain( $$$ )
$chainref->{restriction} = $restriction; $chainref->{restriction} = $restriction;
$chainref->{restricted} = NO_RESTRICT; $chainref->{restricted} = NO_RESTRICT;
$chainref->{ipsec} = $ipsec; $chainref->{ipsec} = $ipsec;
$chainref->{dont_optimize} = 1 unless $config{OPTIMIZE_ACCOUNTING}; $chainref->{optflags} |= ( DONT_OPTIMIZE | DONT_MOVE | DONT_DELETE ) unless $config{OPTIMIZE_ACCOUNTING};
unless ( $chain eq 'accounting' ) { unless ( $chain eq 'accounting' ) {
my $file = find_file $chain; my $file = find_file $chain;
@@ -2208,7 +2273,7 @@ sub new_builtin_chain($$$)
$chainref->{referenced} = 1; $chainref->{referenced} = 1;
$chainref->{policy} = $policy; $chainref->{policy} = $policy;
$chainref->{builtin} = 1; $chainref->{builtin} = 1;
$chainref->{dont_delete} = 1; $chainref->{optflags} = DONT_DELETE;
$chainref; $chainref;
} }
@@ -2636,7 +2701,7 @@ sub conditionally_copy_rules( $$ ) {
my $targetref = $chain_table{$chainref->{table}}{$basictarget}; my $targetref = $chain_table{$chainref->{table}}{$basictarget};
if ( $targetref && ! $targetref->{dont_move} ) { if ( $targetref && ! ( $targetref->{optflags} & DONT_MOVE ) ) {
# #
# Move is safe -- start with an empty rule list # Move is safe -- start with an empty rule list
# #
@@ -2678,7 +2743,7 @@ sub optimize_level0() {
# #
# If the chain isn't branched to, then delete it # If the chain isn't branched to, then delete it
# #
unless ( $chainref->{dont_delete} || keys %{$chainref->{references}} ) { unless ( $chainref->{optflags} & DONT_DELETE || keys %{$chainref->{references}} ) {
delete_chain $chainref if $chainref->{referenced}; delete_chain $chainref if $chainref->{referenced};
} }
} }
@@ -2696,7 +2761,7 @@ sub optimize_level4( $$ ) {
# When a chain with a single entry is found, replace it's references by its contents # When a chain with a single entry is found, replace it's references by its contents
# #
# The search continues until no short chains remain # The search continues until no short chains remain
# Chains with 'dont_optimize = 1' are exempted from optimization # Chains with 'DONT_OPTIMIZE' are exempted from optimization
# #
while ( $progress ) { while ( $progress ) {
$progress = 0; $progress = 0;
@@ -2708,15 +2773,16 @@ sub optimize_level4( $$ ) {
progress_message "\n Table $table pass $passes, $chains referenced chains, level 4a..."; progress_message "\n Table $table pass $passes, $chains referenced chains, level 4a...";
for my $chainref ( @chains ) { for my $chainref ( @chains ) {
my $optflags = $chainref->{optflags};
# #
# If the chain isn't branched to, then delete it # If the chain isn't branched to, then delete it
# #
unless ( $chainref->{dont_delete} || keys %{$chainref->{references}} ) { unless ( ( $optflags & DONT_DELETE ) || keys %{$chainref->{references}} ) {
delete_chain $chainref if $chainref->{referenced}; delete_chain $chainref if $chainref->{referenced};
next; next;
} }
unless ( $chainref->{dont_optimize} ) { unless ( $optflags & DONT_OPTIMIZE ) {
my $numrules = @{$chainref->{rules}}; my $numrules = @{$chainref->{rules}};
if ( $numrules == 0 ) { if ( $numrules == 0 ) {
@@ -2727,7 +2793,7 @@ sub optimize_level4( $$ ) {
# #
# Built-in -- mark it 'dont_optimize' so we ignore it in follow-on passes # Built-in -- mark it 'dont_optimize' so we ignore it in follow-on passes
# #
$chainref->{dont_optimize} = 1; $chainref->{optflags} |= DONT_OPTIMIZE;
} else { } else {
# #
# Not a built-in -- we can delete it and it's references # Not a built-in -- we can delete it and it's references
@@ -2758,7 +2824,7 @@ sub optimize_level4( $$ ) {
# #
# Target was a built-in. Ignore this chain in follow-on passes # Target was a built-in. Ignore this chain in follow-on passes
# #
$chainref->{dont_optimize} = 1; $chainref->{optflags} |= DONT_OPTIMIZE;
} }
} else { } else {
# #
@@ -2774,9 +2840,9 @@ sub optimize_level4( $$ ) {
if ( $chainref->{builtin} || ! $globals{KLUDGEFREE} ) { if ( $chainref->{builtin} || ! $globals{KLUDGEFREE} ) {
# #
# This case requires a new rule merging algorithm. Ignore this chain for # This case requires a new rule merging algorithm. Ignore this chain for
# now. # now on.
# #
$chainref->{dont_optimize} = 1; $chainref->{optflags} |= DONT_OPTIMIZE;
} else { } else {
# #
# Replace references to this chain with the target and add the matches # Replace references to this chain with the target and add the matches
@@ -2813,7 +2879,9 @@ sub optimize_level4( $$ ) {
# Last rule is a simple branch # Last rule is a simple branch
my $targetref = $tableref->{$lastrule->{target}}; my $targetref = $tableref->{$lastrule->{target}};
if ( $targetref && ( keys %{$targetref->{references}} < 2 || @{$targetref->{rules}} < 4 ) ) { if ( $targetref &&
($targetref->{optflags} & DONT_MOVE) == 0 &&
( keys %{$targetref->{references}} < 2 || @{$targetref->{rules}} < 4 ) ) {
copy_rules( $targetref, $chainref ); copy_rules( $targetref, $chainref );
$progress = 1; $progress = 1;
} }
@@ -2866,7 +2934,7 @@ sub optimize_level8( $$$ ) {
# #
for my $chainref1 ( @chains1 ) { for my $chainref1 ( @chains1 ) {
next unless @{$chainref1->{rules}}; next unless @{$chainref1->{rules}};
next if $chainref1->{dont_delete}; next if $chainref1->{optflags} & DONT_DELETE;
if ( $chainref->{digest} eq $chainref1->{digest} ) { if ( $chainref->{digest} eq $chainref1->{digest} ) {
progress_message " Chain $chainref1->{name} combined with $chainref->{name}"; progress_message " Chain $chainref1->{name} combined with $chainref->{name}";
replace_references $chainref1, $chainref->{name}, undef; replace_references $chainref1, $chainref->{name}, undef;
@@ -3190,6 +3258,16 @@ sub set_mss( $$$ ) {
# #
# Interate over all zones with 'mss=' settings adding TCPMSS rules as appropriate. # Interate over all zones with 'mss=' settings adding TCPMSS rules as appropriate.
# #
sub imatch_source_dev( $;$ );
sub imatch_dest_dev( $;$ );
sub imatch_source_net( $;$\$ );
sub imatch_dest_net( $ );
sub newmsschain( ) {
my $seq = $chainseq{filter}++;
"~mss${seq}";
}
sub setup_zone_mss() { sub setup_zone_mss() {
for my $zone ( all_zones ) { for my $zone ( all_zones ) {
my $zoneref = find_zone( $zone ); my $zoneref = find_zone( $zone );
@@ -3197,6 +3275,29 @@ sub setup_zone_mss() {
set_mss( $zone, $zoneref->{options}{in_out}{mss}, '' ) if $zoneref->{options}{in_out}{mss}; set_mss( $zone, $zoneref->{options}{in_out}{mss}, '' ) if $zoneref->{options}{in_out}{mss};
set_mss( $zone, $zoneref->{options}{in}{mss}, '_in' ) if $zoneref->{options}{in}{mss}; set_mss( $zone, $zoneref->{options}{in}{mss}, '_in' ) if $zoneref->{options}{in}{mss};
set_mss( $zone, $zoneref->{options}{out}{mss}, '_out' ) if $zoneref->{options}{out}{mss}; set_mss( $zone, $zoneref->{options}{out}{mss}, '_out' ) if $zoneref->{options}{out}{mss};
my $hosts = find_zone_hosts_by_option( $zone, 'mss' );
for my $hostref ( @$hosts ) {
my $mss = $hostref->[4];
my @mssmatch = have_capability( 'TCPMSS_MATCH' ) ? ( tcpmss => "--mss $mss:" ) : ();
my @sourcedev = imatch_source_dev $hostref->[0];
my @destdev = imatch_dest_dev $hostref->[0];
my @source = imatch_source_net $hostref->[2];
my @dest = imatch_dest_net $hostref->[2];
my @ipsecin = (have_ipsec ? ( policy => "--pol $hostref->[1] --dir in" ) : () );
my @ipsecout = (have_ipsec ? ( policy => "--pol $hostref->[1] --dir out" ) : () );
my $chainref = new_chain 'filter', newmsschain;
my $target = source_exclusion( $hostref->[3], $chainref );
add_ijump $chainref, j => 'TCPMSS', targetopts => "--set-mss $mss", p => 'tcp --tcp-flags SYN,RST SYN';
for my $zone1 ( all_zones ) {
add_ijump ensure_chain( 'filter', rules_chain( $zone, $zone1 ) ), j => $target , @sourcedev, @source, p => 'tcp --tcp-flags SYN,RST SYN', @mssmatch, @ipsecin ;
add_ijump ensure_chain( 'filter', rules_chain( $zone1, $zone ) ), j => $target , @destdev, @dest, p => 'tcp --tcp-flags SYN,RST SYN', @mssmatch, @ipsecout ;
}
}
} }
} }
@@ -3957,7 +4058,7 @@ sub do_time( $ ) {
} }
} elsif ( $element =~ /^(datestart|datestop)=(\d{4}(-\d{2}(-\d{2}(T\d{1,2}(:\d{1,2}){0,2})?)?)?)$/ ) { } elsif ( $element =~ /^(datestart|datestop)=(\d{4}(-\d{2}(-\d{2}(T\d{1,2}(:\d{1,2}){0,2})?)?)?)$/ ) {
$result .= "--$1 $2 "; $result .= "--$1 $2 ";
} elsif ( $element =~ /^(utc|localtz)$/ ) { } elsif ( $element =~ /^(utc|localtz|kerneltz)$/ ) {
$result .= "--$1 "; $result .= "--$1 ";
} else { } else {
fatal_error "Invalid time element ($element)"; fatal_error "Invalid time element ($element)";
@@ -3967,6 +4068,21 @@ sub do_time( $ ) {
$result; $result;
} }
sub resolve_id( $$ ) {
my ( $id, $type ) = @_;
if ( $globals{EXPORT} ) {
require_capability 'OWNER_NAME_MATCH', "Specifying a $type name", 's';
} else {
my $num = $type eq 'user' ? getpwnam( $id ) : getgrnam( $id );
fatal_error "Unknown $type ($id)" unless supplied $num;
$id = $num;
}
$id;
}
# #
# Create a "-m owner" match for the passed USER/GROUP # Create a "-m owner" match for the passed USER/GROUP
# #
@@ -3976,6 +4092,8 @@ sub do_user( $ ) {
return '' unless defined $user and $user ne '-'; return '' unless defined $user and $user ne '-';
require_capability 'OWNER_MATCH', 'A non-empty USER column', 's';
if ( $user =~ /^(!)?(.*)\+(.*)$/ ) { if ( $user =~ /^(!)?(.*)\+(.*)$/ ) {
$rule .= "! --cmd-owner $2 " if supplied $2; $rule .= "! --cmd-owner $2 " if supplied $2;
$user = "!$1"; $user = "!$1";
@@ -3987,37 +4105,82 @@ sub do_user( $ ) {
if ( $user =~ /^(!)?(.*):(.*)$/ ) { if ( $user =~ /^(!)?(.*):(.*)$/ ) {
my $invert = $1 ? '! ' : ''; my $invert = $1 ? '! ' : '';
my $group = defined $3 ? $3 : ''; my $group = defined $3 ? $3 : '';
if ( supplied $2 ) { if ( supplied $2 ) {
$user = $2; $user = $2;
fatal_error "Unknown user ($user)" unless $user =~ /^\d+$/ || $globals{EXPORT} || defined getpwnam( $user ); $user = resolve_id( $user, 'user' ) unless $user =~ /\d+$/;
$rule .= "${invert}--uid-owner $user "; $rule .= "${invert}--uid-owner $user ";
} }
if ( $group ne '' ) { if ( $group ne '' ) {
fatal_error "Unknown group ($group)" unless $group =~ /\d+$/ || $globals{EXPORT} || defined getgrnam( $group ); $group = resolve_id( $group, 'group' ) unless $group =~ /^\d+$/;
$rule .= "${invert}--gid-owner $group "; $rule .= "${invert}--gid-owner $group ";
} }
} elsif ( $user =~ /^(!)?(.*)$/ ) { } elsif ( $user =~ /^(!)?(.*)$/ ) {
my $invert = $1 ? '! ' : ''; my $invert = $1 ? '! ' : '';
$user = $2; $user = $2;
fatal_error "Invalid USER/GROUP (!)" if $user eq ''; fatal_error "Invalid USER/GROUP (!)" if $user eq '';
fatal_error "Unknown user ($user)" unless $user =~ /^\d+$/ || $globals{EXPORT} || defined getpwnam( $user ); $user = resolve_id ($user, 'user' ) unless $user =~ /\d+$/;
$rule .= "${invert}--uid-owner $user "; $rule .= "${invert}--uid-owner $user ";
} else { } else {
fatal_error "Unknown user ($user)" unless $user =~ /^\d+$/ || $globals{EXPORT} || defined getpwnam( $user ); $user = resolve_id( $user, 'user' ) unless $user =~ /\d+$/;
$rule .= "--uid-owner $user "; $rule .= "--uid-owner $user ";
} }
$rule; $rule;
} }
# #
# Create a "-m tos" match for the passed TOS # Create a "-m tos" match for the passed TOS
# #
sub do_tos( $ ) { # This helper is also used during tos file processing
my $tos = $_[0]; #
sub decode_tos( $$ ) {
my ( $tos, $set ) = @_;
$tos ne '-' ? "-m tos --tos $tos " : ''; if ( $tos eq '-' ) {
fatal_error [ '', # 0
'A value must be supplied in the TOS column', # 1
'Invalid TOS() parameter (-)', # 2
]->[$set] if $set;
return '';
}
my $mask = 0xff;
my $value;
if ( $tos =~ m"^(.+)/(.+)$" ) {
$value = numeric_value $1;
$mask = numeric_value $2;
} elsif ( ! defined ( $value = numeric_value( $tos ) ) ) {
$value = $tosmap{$tos};
$mask = '';
}
fatal_error( [ 'Invalid TOS column value',
'Invalid TOS column value',
'Invalid TOS() parameter', ]->[$set] . " ($tos)" )
unless ( defined $value &&
$value <= 0xff &&
( $mask eq '' ||
( defined $mask &&
$mask <= 0xff ) ) );
unless ( $mask eq '' ) {
warning_message "Unmatchable TOS ($tos)" unless $set || $value & $mask;
}
$tos = $mask ? in_hex( $value) . '/' . in_hex( $mask ) . ' ' : in_hex( $value ) . ' ';
$set ? " --set-tos $tos" : "-m tos --tos $tos ";
}
sub do_tos( $ ) {
decode_tos( $_[0], 0 );
} }
my %dir = ( O => 'original' , my %dir = ( O => 'original' ,
@@ -4098,8 +4261,33 @@ sub do_helper( $ ) {
sub do_length( $ ) { sub do_length( $ ) {
my $length = $_[0]; my $length = $_[0];
return '' if $length eq '-';
require_capability( 'LENGTH_MATCH' , 'A Non-empty LENGTH' , 's' ); require_capability( 'LENGTH_MATCH' , 'A Non-empty LENGTH' , 's' );
$length ne '-' ? "-m length --length $length " : '';
my ( $max, $min );
if ( $length =~ /^\d+$/ ) {
fatal_error "Invalid LENGTH ($length)" unless $length < 65536;
$min = $max = $1;
} else {
if ( $length =~ /^:(\d+)$/ ) {
$min = 0;
$max = $1;
} elsif ( $length =~ /^(\d+):$/ ) {
$min = $1;
$max = 65535;
} elsif ( $length =~ /^(\d+):(\d+)$/ ) {
$min = $1;
$max = $2;
} else {
fatal_error "Invalid LENGTH ($length)";
}
fatal_error "First length must be < second length" unless $min < $max;
}
"-m length --length $length ";
} }
# #
@@ -4186,6 +4374,26 @@ sub do_condition( $ ) {
"-m condition ${invert}--condition $condition " "-m condition ${invert}--condition $condition "
} }
#
# Generate a -m dscp match
#
sub do_dscp( $ ) {
my $dscp = shift;
return '' if $dscp eq '-';
require_capability 'DSCP_MATCH', 'A non-empty DSCP column', 's';
my $invert = $dscp =~ s/^!// ? '! ' : '';
my $value = numeric_value( $dscp );
$value = $dscpmap{$value} unless defined $value;
fatal_error( "Invalid DSCP ($dscp)" ) unless defined $value && $value < 0x2f && ! ( $value & 1 );
"-m dscp ${invert}--dscp $value ";
}
# #
# Match Source Interface # Match Source Interface
# #
@@ -4313,16 +4521,27 @@ sub get_set_flags( $$ ) {
} elsif ( $setname =~ /^(.*)\[((src|dst)(,(src|dst))*)\]$/ ) { } elsif ( $setname =~ /^(.*)\[((src|dst)(,(src|dst))*)\]$/ ) {
$setname = $1; $setname = $1;
$options = $2; $options = $2;
my @options = split /,/, $options;
my %typemap = ( src => 'Source', dst => 'Destination' );
if ( $config{IPSET_WARNINGS} ) {
for ( @options ) {
warning_message( "The '$_' ipset flag is used in a $typemap{$option} column" ), last unless $_ eq $option;
}
}
} }
$setname =~ s/^\+//; $setname =~ s/^\+//;
unless ( $export || $> != 0 ) { if ( $config{IPSET_WARNINGS} ) {
unless ( $ipset_exists{$setname} ) { unless ( $export || $> != 0 ) {
warning_message "Ipset $setname does not exist" unless qt "ipset -L $setname"; unless ( $ipset_exists{$setname} ) {
} warning_message "Ipset $setname does not exist" unless qt "ipset -L $setname";
}
$ipset_exists{$setname} = 1; # Suppress subsequent checks/warnings $ipset_exists{$setname} = 1; # Suppress subsequent checks/warnings
}
} }
fatal_error "Invalid ipset name ($setname)" unless $setname =~ /^(6_)?[a-zA-Z]\w*/; fatal_error "Invalid ipset name ($setname)" unless $setname =~ /^(6_)?[a-zA-Z]\w*/;
@@ -4337,11 +4556,21 @@ sub have_ipset_rules() {
sub get_interface_address( $ ); sub get_interface_address( $ );
sub record_runtime_address( $ ) { sub record_runtime_address( $$;$ ) {
my $interface = shift; my ( $addrtype, $interface, $protect ) = @_;
fatal_error "Unknown interface address variable (&$interface)" unless known_interface( $interface ); fatal_error "Unknown interface address variable (&$interface)" unless known_interface( $interface );
fatal_error "Invalid interface address variable (&$interface)" if $interface =~ /\+$/; fatal_error "Invalid interface address variable (&$interface)" if $interface =~ /\+$/;
get_interface_address( $interface ) . ' ';
my $addr;
if ( $addrtype eq '&' ) {
$addr = get_interface_address( $interface );
} else {
$addr = get_interface_gateway( $interface, $protect );
}
$addr . ' ';
} }
# #
@@ -4353,12 +4582,19 @@ sub record_runtime_address( $ ) {
sub conditional_rule( $$ ) { sub conditional_rule( $$ ) {
my ( $chainref, $address ) = @_; my ( $chainref, $address ) = @_;
if ( $address =~ /^!?&(.+)$/ ) { if ( $address =~ /^!?([&%])(.+)$/ ) {
my $interface = $1; my ($type, $interface) = ($1, $2);
if ( my $ref = known_interface $interface ) { if ( my $ref = known_interface $interface ) {
if ( $ref->{options}{optional} ) { if ( $ref->{options}{optional} ) {
my $variable = get_interface_address( $interface ); my $variable;
add_commands( $chainref , "if [ $variable != " . NILIP . ' ]; then' ); if ( $type eq '&' ) {
$variable = get_interface_address( $interface );
add_commands( $chainref , "if [ $variable != " . NILIP . ' ]; then' );
} else {
$variable = get_interface_gateway( $interface );
add_commands( $chainref , qq(if [ -n "$variable" ]; then) );
}
incr_cmd_level $chainref; incr_cmd_level $chainref;
return 1; return 1;
} }
@@ -4422,16 +4658,16 @@ sub match_source_net( $;$\$ ) {
} }
if ( $net =~ s/^!// ) { if ( $net =~ s/^!// ) {
if ( $net =~ /^&(.+)/ ) { if ( $net =~ /^([&%])(.+)/ ) {
return '! -s ' . record_runtime_address $1; return '! -s ' . record_runtime_address $1, $2;
} }
validate_net $net, 1; validate_net $net, 1;
return "! -s $net "; return "! -s $net ";
} }
if ( $net =~ /^&(.+)/ ) { if ( $net =~ /^([&%])(.+)/ ) {
return '-s ' . record_runtime_address $1; return '-s ' . record_runtime_address $1, $2;
} }
validate_net $net, 1; validate_net $net, 1;
@@ -4476,16 +4712,16 @@ sub imatch_source_net( $;$\$ ) {
} }
if ( $net =~ s/^!// ) { if ( $net =~ s/^!// ) {
if ( $net =~ /^&(.+)/ ) { if ( $net =~ /^([&%])(.+)/ ) {
return ( s => '! ' . record_runtime_address $1 ); return ( s => '! ' . record_runtime_address( $1, $2, 1 ) );
} }
validate_net $net, 1; validate_net $net, 1;
return ( s => "! $net " ); return ( s => "! $net " );
} }
if ( $net =~ /^&(.+)/ ) { if ( $net =~ /^([&%])(.+)/ ) {
return ( s => record_runtime_address $1 ); return ( s => record_runtime_address( $1, $2, 1 ) );
} }
validate_net $net, 1; validate_net $net, 1;
@@ -4525,16 +4761,16 @@ sub match_dest_net( $ ) {
} }
if ( $net =~ s/^!// ) { if ( $net =~ s/^!// ) {
if ( $net =~ /^&(.+)/ ) { if ( $net =~ /^([&%])(.+)/ ) {
return '! -d ' . record_runtime_address $1; return '! -d ' . record_runtime_address $1, $2;
} }
validate_net $net, 1; validate_net $net, 1;
return "! -d $net "; return "! -d $net ";
} }
if ( $net =~ /^&(.+)/ ) { if ( $net =~ /^([&%])(.+)/ ) {
return '-d ' . record_runtime_address $1; return '-d ' . record_runtime_address $1, $2;
} }
validate_net $net, 1; validate_net $net, 1;
@@ -4572,16 +4808,16 @@ sub imatch_dest_net( $ ) {
} }
if ( $net =~ s/^!// ) { if ( $net =~ s/^!// ) {
if ( $net =~ /^&(.+)/ ) { if ( $net =~ /^([&%])(.+)/ ) {
return ( d => '! ' . record_runtime_address $1 ); return ( d => '! ' . record_runtime_address( $1, $2, 1 ) );
} }
validate_net $net, 1; validate_net $net, 1;
return ( d => "! $net " ); return ( d => "! $net " );
} }
if ( $net =~ /^&(.+)/ ) { if ( $net =~ /^([&%])(.+)/ ) {
return ( d => record_runtime_address $1 ); return ( d => record_runtime_address( $1, $2, 1 ) );
} }
validate_net $net, 1; validate_net $net, 1;
@@ -4599,7 +4835,7 @@ sub match_orig_dest ( $ ) {
if ( $net =~ s/^!// ) { if ( $net =~ s/^!// ) {
if ( $net =~ /^&(.+)/ ) { if ( $net =~ /^&(.+)/ ) {
$net = record_runtime_address $1; $net = record_runtime_address '&', $1;
} else { } else {
validate_net $net, 1; validate_net $net, 1;
} }
@@ -4607,7 +4843,7 @@ sub match_orig_dest ( $ ) {
have_capability( 'OLD_CONNTRACK_MATCH' ) ? "-m conntrack --ctorigdst ! $net " : "-m conntrack ! --ctorigdst $net "; have_capability( 'OLD_CONNTRACK_MATCH' ) ? "-m conntrack --ctorigdst ! $net " : "-m conntrack ! --ctorigdst $net ";
} else { } else {
if ( $net =~ /^&(.+)/ ) { if ( $net =~ /^&(.+)/ ) {
$net = record_runtime_address $1; $net = record_runtime_address '&', $1;
} else { } else {
validate_net $net, 1; validate_net $net, 1;
} }
@@ -4623,10 +4859,10 @@ sub match_ipsec_in( $$ ) {
my ( $zone , $hostref ) = @_; my ( $zone , $hostref ) = @_;
my @match; my @match;
my $zoneref = find_zone( $zone ); my $zoneref = find_zone( $zone );
my $optionsref = $zoneref->{options};
unless ( $optionsref->{super} || $zoneref->{type} == VSERVER ) { unless ( $zoneref->{super} || $zoneref->{type} == VSERVER ) {
my $match = '--dir in --pol '; my $match = '--dir in --pol ';
my $optionsref = $zoneref->{options};
if ( $zoneref->{type} & IPSEC ) { if ( $zoneref->{type} & IPSEC ) {
$match .= "ipsec $optionsref->{in_out}{ipsec}$optionsref->{in}{ipsec}"; $match .= "ipsec $optionsref->{in_out}{ipsec}$optionsref->{in}{ipsec}";
@@ -5055,8 +5291,8 @@ sub interface_gateway( $ ) {
# #
# Record that the ruleset requires the gateway address on the passed interface # Record that the ruleset requires the gateway address on the passed interface
# #
sub get_interface_gateway ( $ ) { sub get_interface_gateway ( $;$ ) {
my ( $logical ) = $_[0]; my ( $logical, $protect ) = @_;
my $interface = get_physical $logical; my $interface = get_physical $logical;
my $variable = interface_gateway( $interface ); my $variable = interface_gateway( $interface );
@@ -5073,7 +5309,7 @@ sub get_interface_gateway ( $ ) {
); );
} }
"\$$variable"; $protect ? "\${$variable:-" . NILIP . '}' : "\$$variable";
} }
# #
@@ -5383,7 +5619,7 @@ sub expand_rule( $$$$$$$$$$;$ )
} else { } else {
$inets = $source; $inets = $source;
} }
} elsif ( $source =~ /(?:\+|&|~|\..*\.)/ ) { } elsif ( $source =~ /(?:\+|&|%|~|\..*\.)/ ) {
$inets = $source; $inets = $source;
} else { } else {
$iiface = $source; $iiface = $source;
@@ -5468,7 +5704,7 @@ sub expand_rule( $$$$$$$$$$;$ )
if ( $dest =~ /^(.+?):(.+)$/ ) { if ( $dest =~ /^(.+?):(.+)$/ ) {
$diface = $1; $diface = $1;
$dnets = $2; $dnets = $2;
} elsif ( $dest =~ /\+|&|~|\..*\./ ) { } elsif ( $dest =~ /\+|&|%|~|\..*\./ ) {
$dnets = $dest; $dnets = $dest;
} else { } else {
$diface = $dest; $diface = $dest;
@@ -6213,16 +6449,24 @@ sub ensure_ipset( $ ) {
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
if ( have_capability 'IPSET_V5' ) { if ( have_capability 'IPSET_V5' ) {
emit ( " qt \$IPSET -L $set -n || \$IPSET -N $_ hash:ip family inet" ); emit ( qq( if ! qt \$IPSET -L $set -n; then) ,
qq( error_message "WARNING: ipset $set does not exist; creating it as an hash:ip set") ,
qq( \$IPSET -N $set hash:ip family inet) ,
qq( fi) );
} else { } else {
emit ( " qt \$IPSET -L $set -n || \$IPSET -N $_ iphash" ); emit ( qq( if ! qt \$IPSET -L $set -n; then) ,
qq( error_message "WARNING: ipset $set does not exist; creating it as an iphash set") ,
qq( \$IPSET -N $set iphash) ,
qq( fi) );
} }
} else { } else {
emit ( " qt \$IPSET -L $set -n || \$IPSET -N $_ hash:ip family inet6" ); emit ( qq( if ! qt \$IPSET -L $set -n; then) ,
qq( error_message "WARNING: ipset $set does not exist; creating it as an hash:ip set") ,
qq( \$IPSET -N $set hash:ip family inet6) ,
qq( fi) );
} }
} }
sub load_ipsets() { sub load_ipsets() {
my @ipsets = all_ipsets; my @ipsets = all_ipsets;
@@ -6413,7 +6657,7 @@ sub create_netfilter_load( $ ) {
# #
emit( 'exec 3>&-', emit( 'exec 3>&-',
'', '',
'[ -n "$DEBUG" ] && command=debug_restore_input || command=$' . $UTILITY, '[ -n "$g_debug_iptables" ] && command=debug_restore_input || command=$' . $UTILITY,
'', '',
'progress_message2 "Running $command..."', 'progress_message2 "Running $command..."',
'', '',

View File

@@ -54,10 +54,10 @@ my $family;
# #
# Initilize the package-globals in the other modules # Initilize the package-globals in the other modules
# #
sub initialize_package_globals( $ ) { sub initialize_package_globals( $$ ) {
Shorewall::Config::initialize($family); Shorewall::Config::initialize($family, $_[1]);
Shorewall::Chains::initialize ($family, 1, $export ); Shorewall::Chains::initialize ($family, 1, $export );
Shorewall::Zones::initialize ($family, shift); Shorewall::Zones::initialize ($family, $_[0]);
Shorewall::Nat::initialize; Shorewall::Nat::initialize;
Shorewall::Providers::initialize($family); Shorewall::Providers::initialize($family);
Shorewall::Tc::initialize($family); Shorewall::Tc::initialize($family);
@@ -71,7 +71,7 @@ sub initialize_package_globals( $ ) {
# #
# First stage of script generation. # First stage of script generation.
# #
# Copy prog.header, lib.core and lib.common to the generated script. # Copy lib.core and lib.common to the generated script.
# Generate the various user-exit jacket functions. # Generate the various user-exit jacket functions.
# #
# Note: This function is not called when $command eq 'check'. So it must have no side effects other # Note: This function is not called when $command eq 'check'. So it must have no side effects other
@@ -89,13 +89,7 @@ sub generate_script_1( $ ) {
emit "#!$config{SHOREWALL_SHELL}\n#\n# Compiled firewall script generated by Shorewall $globals{VERSION} - $date\n#"; emit "#!$config{SHOREWALL_SHELL}\n#\n# Compiled firewall script generated by Shorewall $globals{VERSION} - $date\n#";
if ( $family == F_IPV4 ) { copy $globals{SHAREDIRPL} . '/lib.core', 0;
copy $globals{SHAREDIRPL} . 'prog.header';
} else {
copy $globals{SHAREDIRPL} . 'prog.header6';
}
copy2 $globals{SHAREDIRPL} . '/lib.core', 0;
copy2 $globals{SHAREDIRPL} . '/lib.common', 0; copy2 $globals{SHAREDIRPL} . '/lib.common', 0;
} }
@@ -154,7 +148,9 @@ sub generate_script_2() {
' #', ' #',
' # Be sure that umask is sane', ' # Be sure that umask is sane',
' #', ' #',
' umask 077', ' umask 077' );
emit ( '',
' #', ' #',
' # These variables are required by the library functions called in this script', ' # These variables are required by the library functions called in this script',
' #' ' #'
@@ -162,61 +158,63 @@ sub generate_script_2() {
push_indent; push_indent;
if ( $shorewallrc{TEMPDIR} ) {
emit( '',
qq(TMPDIR="$shorewallrc{TEMPDIR}") ,
q(export TMPDIR) );
}
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
emit( 'g_family=4' ); emit( 'g_family=4' );
if ( $export ) { if ( $export ) {
emit ( 'SHAREDIR=/usr/share/shorewall-lite', emit ( qq(g_confdir=$shorewallrc{CONFDIR}/shorewall-lite),
'CONFDIR=/etc/shorewall-lite',
'g_product="Shorewall Lite"', 'g_product="Shorewall Lite"',
'g_program=shorewall-lite', 'g_program=shorewall-lite',
'g_basedir=/usr/share/shorewall-lite', 'g_basedir=/usr/share/shorewall-lite',
qq(CONFIG_PATH="$shorewallrc{CONFDIR}/shorewall-lite:$shorewallrc{SHAREDIR}/shorewall-lite") ,
); );
} else { } else {
emit ( 'SHAREDIR=/usr/share/shorewall', emit ( qq(g_confdir=$shorewallrc{CONFDIR}/shorewall),
'CONFDIR=/etc/shorewall',
'g_product=Shorewall', 'g_product=Shorewall',
'g_program=shorewall', 'g_program=shorewall',
'g_basedir=/usr/share/shorewall', 'g_basedir=/usr/share/shorewall',
qq(CONFIG_PATH="$config{CONFIG_PATH}") ,
); );
} }
} else { } else {
emit( 'g_family=6' ); emit( 'g_family=6' );
if ( $export ) { if ( $export ) {
emit ( 'SHAREDIR=/usr/share/shorewall6-lite', emit ( qq(g_confdir=$shorewallrc{CONFDIR}/shorewall6-lite),
'CONFDIR=/etc/shorewall6-lite',
'g_product="Shorewall6 Lite"', 'g_product="Shorewall6 Lite"',
'g_program=shorewall6-lite', 'g_program=shorewall6-lite',
'g_basedir=/usr/share/shorewall6', 'g_basedir=/usr/share/shorewall6',
qq(CONFIG_PATH="$shorewallrc{CONFDIR}/shorewall6-lite:$shorewallrc{SHAREDIR}/shorewall6-lite") ,
); );
} else { } else {
emit ( 'SHAREDIR=/usr/share/shorewall6', emit ( qq(g_confdir=$shorewallrc{CONFDIR}/shorewall6),
'CONFDIR=/etc/shorewall6',
'g_product=Shorewall6', 'g_product=Shorewall6',
'g_program=shorewall6', 'g_program=shorewall6',
'g_basedir=/usr/share/shorewall' 'g_basedir=/usr/share/shorewall',
qq(CONFIG_PATH="$config{CONFIG_PATH}") ,
); );
} }
} }
emit( '[ -f ${CONFDIR}/vardir ] && . ${CONFDIR}/vardir' ); emit( '[ -f ${g_confdir}/vardir ] && . ${g_confdir}/vardir' );
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
if ( $export ) { if ( $export ) {
emit ( 'CONFIG_PATH="/etc/shorewall-lite:/usr/share/shorewall-lite"' , emit ( '[ -n "${VARDIR:=' . $shorewallrc{VARDIR} . '/shorewall-lite}" ]' );
'[ -n "${VARDIR:=/var/lib/shorewall-lite}" ]' );
} else { } else {
emit ( qq(CONFIG_PATH="$config{CONFIG_PATH}") , emit ( '[ -n "${VARDIR:=' . $shorewallrc{VARDIR} . '/shorewall}" ]' );
'[ -n "${VARDIR:=/var/lib/shorewall}" ]' );
} }
} else { } else {
if ( $export ) { if ( $export ) {
emit ( 'CONFIG_PATH="/etc/shorewall6-lite:/usr/share/shorewall6-lite"' , emit ( '[ -n "${VARDIR:=' . $shorewallrc{VARDIR} . '/shorewall6-lite}" ]' );
'[ -n "${VARDIR:=/var/lib/shorewall6-lite}" ]' );
} else { } else {
emit ( qq(CONFIG_PATH="$config{CONFIG_PATH}") , emit ( '[ -n "${VARDIR:=' . $shorewallrc{VARDIR} . '/shorewall6}" ]' );
'[ -n "${VARDIR:=/var/lib/shorewall6}" ]' );
} }
} }
@@ -547,8 +545,8 @@ EOF
# #
sub compiler { sub compiler {
my ( $scriptfilename, $directory, $verbosity, $timestamp , $debug, $chains , $log , $log_verbosity, $preview, $confess , $update , $annotate , $convert, $config_path ) = my ( $scriptfilename, $directory, $verbosity, $timestamp , $debug, $chains , $log , $log_verbosity, $preview, $confess , $update , $annotate , $convert, $config_path, $shorewallrc ) =
( '', '', -1, '', 0, '', '', -1, 0, 0, 0, 0, , 0 , ''); ( '', '', -1, '', 0, '', '', -1, 0, 0, 0, 0, , 0 , '' , '');
$export = 0; $export = 0;
$test = 0; $test = 0;
@@ -586,6 +584,7 @@ sub compiler {
convert => { store => \$convert, validate=> \&validate_boolean } , convert => { store => \$convert, validate=> \&validate_boolean } ,
annotate => { store => \$annotate, validate=> \&validate_boolean } , annotate => { store => \$annotate, validate=> \&validate_boolean } ,
config_path => { store => \$config_path } , config_path => { store => \$config_path } ,
shorewallrc => { store => \$shorewallrc } ,
); );
# #
# P A R A M E T E R P R O C E S S I N G # P A R A M E T E R P R O C E S S I N G
@@ -603,7 +602,7 @@ sub compiler {
# #
# Now that we know the address family (IPv4/IPv6), we can initialize the other modules' globals # Now that we know the address family (IPv4/IPv6), we can initialize the other modules' globals
# #
initialize_package_globals( $update ); initialize_package_globals( $update, $shorewallrc );
set_config_path( $config_path ) if $config_path; set_config_path( $config_path ) if $config_path;
@@ -709,10 +708,6 @@ sub compiler {
# Proxy Arp/Ndp # Proxy Arp/Ndp
# #
setup_proxy_arp; setup_proxy_arp;
#
# Handle MSS settings in the zones file
#
setup_zone_mss;
if ( $scriptfilename || $debug ) { if ( $scriptfilename || $debug ) {
emit 'return 0'; emit 'return 0';

View File

@@ -141,6 +141,7 @@ our %EXPORT_TAGS = ( internal => [ qw( create_temp_script
%config %config
%globals %globals
%config_files %config_files
%shorewallrc
@auditoptions @auditoptions
@@ -243,6 +244,8 @@ my %capdesc = ( NAT_ENABLED => 'NAT',
IPRANGE_MATCH => 'IP Range Match', IPRANGE_MATCH => 'IP Range Match',
RECENT_MATCH => 'Recent Match', RECENT_MATCH => 'Recent Match',
OWNER_MATCH => 'Owner Match', OWNER_MATCH => 'Owner Match',
OWNER_NAME_MATCH
=> 'Owner Name Match',
IPSET_MATCH => 'Ipset Match', IPSET_MATCH => 'Ipset Match',
OLD_IPSET_MATCH => 'Old Ipset Match', OLD_IPSET_MATCH => 'Old Ipset Match',
IPSET_V5 => 'Version 5 ipsets', IPSET_V5 => 'Version 5 ipsets',
@@ -292,6 +295,8 @@ my %capdesc = ( NAT_ENABLED => 'NAT',
STATISTIC_MATCH => STATISTIC_MATCH =>
'Statistics Match', 'Statistics Match',
IMQ_TARGET => 'IMQ Target', IMQ_TARGET => 'IMQ Target',
DSCP_MATCH => 'DSCP Match',
DSCP_TARGET => 'DSCP Target',
CAPVERSION => 'Capability Version', CAPVERSION => 'Capability Version',
KERNELVERSION => 'Kernel Version', KERNELVERSION => 'Kernel Version',
); );
@@ -389,8 +394,8 @@ my $toolNAME; # Tool name in CAPS
our $product; # Name of product that will run the generated script our $product; # Name of product that will run the generated script
our $Product; # $product with initial cap. our $Product; # $product with initial cap.
my $sillyname; # Name of temporary filter chains for testing capabilities our $sillyname; # Name of temporary filter chains for testing capabilities
my $sillyname1; our $sillyname1;
my $iptables; # Path to iptables/ip6tables my $iptables; # Path to iptables/ip6tables
my $tc; # Path to tc my $tc; # Path to tc
my $ip; # Path to ip my $ip; # Path to ip
@@ -419,6 +424,23 @@ my %deprecated = ( LOGRATE => '' ,
HIGH_ROUTE_MARKS => 'no' HIGH_ROUTE_MARKS => 'no'
); );
# #
# Deprecated options that are eliminated via update
#
my %converted = ( WIDE_TC_MARKS => 1,
HIGH_ROUTE_MARKS => 1 );
#
# Variables involved in ?IF, ?ELSE ?ENDIF processing
#
my $omitting;
my @ifstack;
my $ifstack;
#
# From .shorewallrc
#
our %shorewallrc;
sub process_shorewallrc($);
#
# Rather than initializing globals in an INIT block or during declaration, # Rather than initializing globals in an INIT block or during declaration,
# we initialize them in a function. This is done for two reasons: # we initialize them in a function. This is done for two reasons:
# #
@@ -428,8 +450,8 @@ my %deprecated = ( LOGRATE => '' ,
# 2. The compiler can run multiple times in the same process so it has to be # 2. The compiler can run multiple times in the same process so it has to be
# able to re-initialize its dependent modules' state. # able to re-initialize its dependent modules' state.
# #
sub initialize( $ ) { sub initialize( $;$ ) {
$family = shift; ( $family, my $shorewallrc ) = @_;
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
( $product, $Product, $toolname, $toolNAME ) = qw( shorewall Shorewall iptables IPTABLES ); ( $product, $Product, $toolname, $toolNAME ) = qw( shorewall Shorewall iptables IPTABLES );
@@ -451,13 +473,16 @@ sub initialize( $ ) {
$tempfile = ''; # Temporary File Name $tempfile = ''; # Temporary File Name
$sillyname = $sillyname =
$sillyname1 = ''; # Temporary ipchains $sillyname1 = ''; # Temporary ipchains
$omitting = 0;
$ifstack = 0;
@ifstack = ();
# #
# Misc Globals # Misc Globals
# #
%globals = ( SHAREDIRPL => '/usr/share/shorewall/' , %globals = ( SHAREDIRPL => '' ,
CONFDIR => '/etc/shorewall', # Run-time configuration directory CONFDIR => '', # Run-time configuration directory
CONFIGDIR => '', # Compile-time configuration directory (location of $product.conf) CONFIGDIR => '', # Compile-time configuration directory (location of $product.conf)
LOGPARMS => '', LOGPARMS => '',
TC_SCRIPT => '', TC_SCRIPT => '',
EXPORT => 0, EXPORT => 0,
@@ -465,7 +490,7 @@ sub initialize( $ ) {
STATEMATCH => '-m state --state', STATEMATCH => '-m state --state',
UNTRACKED => 0, UNTRACKED => 0,
VERSION => "4.4.22.1", VERSION => "4.4.22.1",
CAPVERSION => 40501 , CAPVERSION => 40502 ,
); );
# #
# From shorewall.conf file # From shorewall.conf file
@@ -551,6 +576,7 @@ sub initialize( $ ) {
MAPOLDACTIONS => undef, MAPOLDACTIONS => undef,
FASTACCEPT => undef, FASTACCEPT => undef,
IMPLICIT_CONTINUE => undef, IMPLICIT_CONTINUE => undef,
IPSET_WARNINGS => undef,
HIGH_ROUTE_MARKS => undef, HIGH_ROUTE_MARKS => undef,
USE_ACTIONS=> undef, USE_ACTIONS=> undef,
OPTIMIZE => undef, OPTIMIZE => undef,
@@ -644,6 +670,7 @@ sub initialize( $ ) {
IPRANGE_MATCH => undef, IPRANGE_MATCH => undef,
RECENT_MATCH => undef, RECENT_MATCH => undef,
OWNER_MATCH => undef, OWNER_MATCH => undef,
OWNER_NAME_MATCH => undef,
IPSET_MATCH => undef, IPSET_MATCH => undef,
OLD_IPSET_MATCH => undef, OLD_IPSET_MATCH => undef,
IPSET_V5 => undef, IPSET_V5 => undef,
@@ -692,6 +719,8 @@ sub initialize( $ ) {
CT_TARGET => undef, CT_TARGET => undef,
STATISTIC_MATCH => undef, STATISTIC_MATCH => undef,
IMQ_TARGET => undef, IMQ_TARGET => undef,
DSCP_MATCH => undef,
DSCP_TARGET => undef,
CAPVERSION => undef, CAPVERSION => undef,
KERNELVERSION => undef, KERNELVERSION => undef,
); );
@@ -725,17 +754,28 @@ sub initialize( $ ) {
@actparms = (); @actparms = ();
if ( $family == F_IPV4 ) { %shorewallrc = (
$globals{SHAREDIR} = '/usr/share/shorewall'; SHAREDIR => '/usr/share/',
$globals{CONFDIR} = '/etc/shorewall'; CONFDIR => '/etc/',
$globals{PRODUCT} = 'shorewall'; );
$config{IPTABLES} = undef;
$validlevels{ULOG} = 'ULOG'; if ( $shorewallrc ) {
} else { process_shorewallrc( $shorewallrc );
$globals{SHAREDIR} = '/usr/share/shorewall6';
$globals{CONFDIR} = '/etc/shorewall6'; $globals{SHAREDIRPL} = "$shorewallrc{SHAREDIR}/shorewall/";
$globals{PRODUCT} = 'shorewall6';
$config{IP6TABLES} = undef; if ( $family == F_IPV4 ) {
$globals{SHAREDIR} = "$shorewallrc{SHAREDIR}/shorewall";
$globals{CONFDIR} = "$shorewallrc{CONFDIR}/shorewall";
$globals{PRODUCT} = 'shorewall';
$config{IPTABLES} = undef;
$validlevels{ULOG} = 'ULOG';
} else {
$globals{SHAREDIR} = "$shorewallrc{SHAREDIR}/shorewall6";
$globals{CONFDIR} = "$shorewallrc{CONFDIR}/shorewall6";
$globals{PRODUCT} = 'shorewall6';
$config{IP6TABLES} = undef;
}
} }
} }
@@ -747,7 +787,7 @@ my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
sub warning_message sub warning_message
{ {
my $linenumber = $currentlinenumber || 1; my $linenumber = $currentlinenumber || 1;
my $currentlineinfo = $currentfile ? " : $currentfilename (line $linenumber)" : ''; my $currentlineinfo = $currentfile ? " : $currentfilename " . ( $linenumber eq 'EOF' ? '(EOF)' : "(line $linenumber)" ) : '';
our @localtime; our @localtime;
$| = 1; #Reset output buffering (flush any partially filled buffers). $| = 1; #Reset output buffering (flush any partially filled buffers).
@@ -803,7 +843,7 @@ sub cleanup() {
# #
sub fatal_error { sub fatal_error {
my $linenumber = $currentlinenumber || 1; my $linenumber = $currentlinenumber || 1;
my $currentlineinfo = $currentfile ? " : $currentfilename (line $linenumber)" : ''; my $currentlineinfo = $currentfile ? " : $currentfilename " . ( $linenumber eq 'EOF' ? '(EOF)' : "(line $linenumber)" ) : '';
$| = 1; #Reset output buffering (flush any partially filled buffers). $| = 1; #Reset output buffering (flush any partially filled buffers).
@@ -1450,6 +1490,7 @@ sub do_open_file( $ ) {
my $fname = $_[0]; my $fname = $_[0];
open $currentfile, '<', $fname or fatal_error "Unable to open $fname: $!"; open $currentfile, '<', $fname or fatal_error "Unable to open $fname: $!";
$currentlinenumber = 0; $currentlinenumber = 0;
$ifstack = @ifstack;
$currentfilename = $fname; $currentfilename = $fname;
} }
@@ -1462,6 +1503,7 @@ sub open_file( $ ) {
$first_entry = 0; $first_entry = 0;
do_open_file $fname;; do_open_file $fname;;
} else { } else {
$ifstack = @ifstack;
''; '';
} }
} }
@@ -1472,10 +1514,17 @@ sub open_file( $ ) {
sub pop_include() { sub pop_include() {
my $arrayref = pop @includestack; my $arrayref = pop @includestack;
unless ( $ifstack == @ifstack ) {
my $lastref = $ifstack[-1];
$currentlinenumber = 'EOF';
fatal_error qq(Missing "?ENDIF" to match ?IF at line number $lastref->[2])
}
if ( $arrayref ) { if ( $arrayref ) {
( $currentfile, $currentfilename, $currentlinenumber ) = @$arrayref; ( $currentfile, $currentfilename, $currentlinenumber, $ifstack ) = @$arrayref;
} else { } else {
$currentfile = undef; $currentfile = undef;
$currentlinenumber = 'EOF';
} }
} }
@@ -1496,6 +1545,70 @@ sub close_file() {
} }
} }
#
# Process an ?IF, ?ELSE or ?END directive
#
sub have_capability( $ );
sub process_conditional( $$$ ) {
my ( $omitting, $line, $linenumber ) = @_;
print "CD===> $currentline\n" if $debug;
fatal_error "Invalid compiler directive ($line)" unless $line =~ /^\s*\?(IF\s+|ELSE|ENDIF)(.*)$/;
my ($keyword, $rest) = ( $1, $2 );
if ( supplied $rest ) {
$rest =~ s/#.*//;
$rest =~ s/\s*$//;
} else {
$rest = '';
}
my ( $lastkeyword, $prioromit, $lastomit, $lastlinenumber ) = @ifstack ? @{$ifstack[-1]} : ('', 0, 0, 0 );
if ( $keyword =~ /^IF/ ) {
fatal_error "Missing IF variable" unless $rest;
my $invert = $rest =~ s/^!\s*//;
fatal_error "Invalid IF variable ($rest)" unless ($rest =~ s/^\$// || $rest =~ /^__/ ) && $rest =~ /^\w+$/;
push @ifstack, [ 'IF', $lastomit, $omitting, $linenumber ];
if ( $rest eq '__IPV6' ) {
$omitting = $family == F_IPV4;
} elsif ( $rest eq '__IPV4' ) {
$omitting = $family == F_IPV6;
} else {
my $cap = $rest;
$cap =~ s/^__//;
$omitting = ! ( exists $ENV{$rest} ? $ENV{$rest} :
exists $params{$rest} ? $params{$rest} :
exists $config{$rest} ? $config{$rest} :
exists $capdesc{$cap} ? have_capability( $cap ) : 0 );
}
$omitting = ! $omitting if $invert;
$omitting ||= $lastomit; #?IF cannot transition from omitting -> not omitting
} elsif ( $keyword eq 'ELSE' ) {
fatal_error "Invalid ?ELSE" unless $rest eq '';
fatal_error "?ELSE has no matching ?IF" unless @ifstack > $ifstack && $lastkeyword eq 'IF';
$omitting = ! $omitting unless $lastomit;
$ifstack[-1] = [ 'ELSE', $prioromit, $omitting, $lastlinenumber ];
} else {
fatal_error "Invalid ?ENDIF" unless $rest eq '';
fatal_error q(Unexpected "?ENDIF" without matching ?IF or ?ELSE) if @ifstack <= $ifstack;
$omitting = $prioromit;
pop @ifstack;
}
$omitting;
}
# #
# Functions for copying a file into the script # Functions for copying a file into the script
# #
@@ -1503,12 +1616,27 @@ sub copy( $ ) {
assert( $script_enabled ); assert( $script_enabled );
if ( $script ) { if ( $script ) {
my $file = $_[0]; my $file = $_[0];
my $omitting = 0;
my $save_ifstack = $ifstack;
my $lineno = 0;
$ifstack = @ifstack;
open IF , $file or fatal_error "Unable to open $file: $!"; open IF , $file or fatal_error "Unable to open $file: $!";
while ( <IF> ) { while ( <IF> ) {
chomp; chomp;
$lineno++;
if ( /^\s*\?/ ) {
$omitting = process_conditional( $omitting, $_, $lineno );
next;
}
next if $omitting;
if ( /^\s*$/ ) { if ( /^\s*$/ ) {
print $script "\n" unless $lastlineblank; print $script "\n" unless $lastlineblank;
$lastlineblank = 1; $lastlineblank = 1;
@@ -1524,6 +1652,14 @@ sub copy( $ ) {
} }
} }
if ( $ifstack < @ifstack ) {
$currentlinenumber = 'EOF';
$currentfilename = $file;
fatal_error "Missing ?ENDIF to match the ?IF at line $ifstack[-1]->[3]";
} else {
$ifstack = $save_ifstack;
}
close IF; close IF;
} }
} }
@@ -1547,6 +1683,11 @@ sub copy1( $ ) {
chomp; chomp;
if ( /^\s*\?/ ) {
$omitting = process_conditional( $omitting, $_, $currentlinenumber );
next;
}
if ( /^${here_documents}\s*$/ ) { if ( /^${here_documents}\s*$/ ) {
if ( $script ) { if ( $script ) {
print $script $here_documents if $here_documents; print $script $here_documents if $here_documents;
@@ -1598,7 +1739,7 @@ sub copy1( $ ) {
fatal_error "Directory ($filename) not allowed in INCLUDE" if -d _; fatal_error "Directory ($filename) not allowed in INCLUDE" if -d _;
if ( -s _ ) { if ( -s _ ) {
push @includestack, [ $currentfile, $currentfilename, $currentlinenumber ]; push @includestack, [ $currentfile, $currentfilename, $currentlinenumber, $ifstack ];
$currentfile = undef; $currentfile = undef;
do_open_file $filename; do_open_file $filename;
} else { } else {
@@ -1649,10 +1790,14 @@ sub copy2( $$ ) {
if ( $script || $trace ) { if ( $script || $trace ) {
my $file = $_[0]; my $file = $_[0];
my $omitting = 0;
my $save_ifstack = $ifstack;
my $lineno = 0;
open IF , $file or fatal_error "Unable to open $file: $!"; open IF , $file or fatal_error "Unable to open $file: $!";
while ( <IF> ) { while ( <IF> ) {
$lineno++;
$empty = 0, last unless /^#/; $empty = 0, last unless /^#/;
} }
@@ -1666,7 +1811,16 @@ EOF
emit( $_ ) unless /^\s*$/; emit( $_ ) unless /^\s*$/;
while ( <IF> ) { while ( <IF> ) {
$lineno++;
chomp; chomp;
if ( /^\s*\?/ ) {
$omitting = process_conditional( $omitting, $_, $lineno );
next;
}
next if $omitting;
if ( /^\s*$/ ) { if ( /^\s*$/ ) {
unless ( $lastlineblank ) { unless ( $lastlineblank ) {
print $script "\n" if $script; print $script "\n" if $script;
@@ -1694,8 +1848,6 @@ EOF
} }
} }
close IF;
unless ( $lastlineblank ) { unless ( $lastlineblank ) {
print $script "\n" if $script; print $script "\n" if $script;
print "GS----->\n" if $trace; print "GS----->\n" if $trace;
@@ -1705,6 +1857,17 @@ EOF
"# End of imports from $file", "# End of imports from $file",
'################################################################################' ); '################################################################################' );
} }
if ( $ifstack < @ifstack ) {
$currentfilename = $file;
$currentlinenumber = 'EOF';
fatal_error "Missing ?ENDIF to match the ?IF at line $ifstack[-1]->[3]";
} else {
$ifstack = $save_ifstack;
}
close IF;
} }
} }
@@ -1714,7 +1877,7 @@ EOF
# #
sub push_open( $ ) { sub push_open( $ ) {
push @includestack, [ $currentfile, $currentfilename, $currentlinenumber ]; push @includestack, [ $currentfile, $currentfilename, $currentlinenumber, $ifstack ];
my @a = @includestack; my @a = @includestack;
push @openstack, \@a; push @openstack, \@a;
@includestack = (); @includestack = ();
@@ -1772,6 +1935,8 @@ sub first_entry( $ ) {
} }
} }
sub read_a_line(;$$$$);
sub embedded_shell( $ ) { sub embedded_shell( $ ) {
my $multiline = shift; my $multiline = shift;
@@ -1787,24 +1952,24 @@ sub embedded_shell( $ ) {
my $last = 0; my $last = 0;
while ( <$currentfile> ) { while ( read_a_line( 0, 0, 0, 0 ) ) {
$currentlinenumber++; last if $last = $currentline =~ s/^\s*END(\s+SHELL)?\s*;?//;
last if $last = s/^\s*END(\s+SHELL)?\s*;?//; $command .= "$currentline\n";
$command .= $_;
} }
fatal_error ( "Missing END SHELL" ) unless $last; fatal_error ( "Missing END SHELL" ) unless $last;
fatal_error ( "Invalid END SHELL directive" ) unless /^\s*$/; fatal_error ( "Invalid END SHELL directive" ) unless $currentline =~ /^\s*$/;
} }
$command .= q('); $command .= q(');
push @includestack, [ $currentfile, $currentfilename, $currentlinenumber ]; push @includestack, [ $currentfile, $currentfilename, $currentlinenumber, $ifstack ];
$currentfile = undef; $currentfile = undef;
open $currentfile , '-|', $command or fatal_error qq(Shell Command failed); open $currentfile , '-|', $command or fatal_error qq(Shell Command failed);
$currentfilename = "SHELL\@$currentfilename:$currentlinenumber"; $currentfilename = "SHELL\@$currentfilename:$currentlinenumber";
$currentline = ''; $currentline = '';
$currentlinenumber = 0; $currentlinenumber = 0;
$ifstack = @ifstack;
} }
sub embedded_perl( $ ) { sub embedded_perl( $ ) {
@@ -1821,21 +1986,20 @@ sub embedded_perl( $ ) {
my $last = 0; my $last = 0;
while ( <$currentfile> ) { while ( read_a_line( 0, 0, 0, 0 ) ) {
$currentlinenumber++; last if $last = $currentline =~ s/^\s*END(\s+PERL)?\s*;?//;
last if $last = s/^\s*END(\s+PERL)?\s*;?//; $command .= "$currentline\n";
$command .= $_;
} }
fatal_error ( "Missing END PERL" ) unless $last; fatal_error ( "Missing END PERL" ) unless $last;
fatal_error ( "Invalid END PERL directive" ) unless /^\s*$/; fatal_error ( "Invalid END PERL directive" ) unless $currentline =~ /^\s*$/;
} }
unless (my $return = eval $command ) { unless (my $return = eval $command ) {
#
# Perl found the script offensive or the script itself died
#
if ( $@ ) { if ( $@ ) {
#
# Perl found the script offensive or the script itself died
#
$@ =~ s/, <\$currentfile> line \d+//g; $@ =~ s/, <\$currentfile> line \d+//g;
fatal_error1 "$@"; fatal_error1 "$@";
} }
@@ -1855,7 +2019,7 @@ sub embedded_perl( $ ) {
$perlscript = undef; $perlscript = undef;
push @includestack, [ $currentfile, $currentfilename, $currentlinenumber ]; push @includestack, [ $currentfile, $currentfilename, $currentlinenumber , $ifstack ];
$currentfile = undef; $currentfile = undef;
open $currentfile, '<', $perlscriptname or fatal_error "Unable to open Perl Script $perlscriptname"; open $currentfile, '<', $perlscriptname or fatal_error "Unable to open Perl Script $perlscriptname";
@@ -1867,6 +2031,7 @@ sub embedded_perl( $ ) {
$currentfilename = "PERL\@$currentfilename:$linenumber"; $currentfilename = "PERL\@$currentfilename:$linenumber";
$currentline = ''; $currentline = '';
$currentlinenumber = 0; $currentlinenumber = 0;
$ifstack = @ifstack;
} }
} }
@@ -1951,6 +2116,8 @@ sub expand_variables( \$ ) {
$val = $actparms[$var]; $val = $actparms[$var];
} elsif ( exists $params{$var} ) { } elsif ( exists $params{$var} ) {
$val = $params{$var}; $val = $params{$var};
} elsif ( exists $shorewallrc{$var} ) {
$val = $shorewallrc{$var}
} else { } else {
fatal_error "Undefined shell variable (\$$var)" unless exists $config{$var}; fatal_error "Undefined shell variable (\$$var)" unless exists $config{$var};
$val = $config{$var}; $val = $config{$var};
@@ -1962,6 +2129,18 @@ sub expand_variables( \$ ) {
} }
} }
#
# Handle first-entry processing
#
sub handle_first_entry() {
#
# $first_entry can contain either a function reference or a message. If it
# contains a reference, call the function -- otherwise issue the message
#
reftype( $first_entry ) ? $first_entry->() : progress_message2( $first_entry );
$first_entry = 0;
}
# #
# Read a line from the current include stack. # Read a line from the current include stack.
# #
@@ -1971,12 +2150,14 @@ sub expand_variables( \$ ) {
# - Handle embedded SHELL and PERL scripts # - Handle embedded SHELL and PERL scripts
# - Expand shell variables from %params and %ENV. # - Expand shell variables from %params and %ENV.
# - Handle INCLUDE <filename> # - Handle INCLUDE <filename>
# - Handle ?IF, ?ELSE, ?ENDIF
# #
sub read_a_line(;$$$) { sub read_a_line(;$$$$) {
my $embedded_enabled = defined $_[0] ? shift : 1; my $embedded_enabled = defined $_[0] ? shift : 1;
my $expand_variables = defined $_[0] ? shift : 1; my $expand_variables = defined $_[0] ? shift : 1;
my $strip_comments = defined $_[0] ? shift : 1; my $strip_comments = defined $_[0] ? shift : 1;
my $suppress_whitespace = defined $_[0] ? shift : 1;
while ( $currentfile ) { while ( $currentfile ) {
@@ -1991,57 +2172,65 @@ sub read_a_line(;$$$) {
# #
# Suppress leading whitespace in certain continuation lines # Suppress leading whitespace in certain continuation lines
# #
s/^\s*// if $currentline =~ /[,:]$/; s/^\s*// if $currentline =~ /[,:]$/ && $suppress_whitespace;
# #
# If this isn't a continued line, remove trailing comments. Note that # If this is a continued line with a trailing comment, remove comment. Note that
# the result may now end in '\'. # the result will now end in '\'.
# #
s/\s*#.*$// if $strip_comments && ! /\\$/; s/\s*#.*$// if $strip_comments && /[\\]\s*#.*$/;
# #
# Continuation # Continuation
# #
chop $currentline, next if substr( ( $currentline .= $_ ), -1, 1 ) eq '\\'; chop $currentline, next if ($currentline .= $_) =~ /\\$/;
# #
# Now remove concatinated comments # Handle conditionals
# #
$currentline =~ s/#.*$// if $strip_comments; if ( $currentline =~ /^\s*\?(?:IF|ELSE|ENDIF)/ ) {
# $omitting = process_conditional( $omitting, $currentline, $currentlinenumber );
# Ignore ( concatenated ) Blank Lines $currentline='';
# next;
$currentline = '', $currentlinenumber = 0, next if $currentline =~ /^\s*$/; }
#
# Line not blank -- Handle any first-entry message/capabilities check if ( $omitting ) {
# print "OMIT=> $currentline\n" if $debug;
if ( $first_entry ) { $currentline='';
# $currentlinenumber = 0;
# $first_entry can contain either a function reference or a message. If it next;
# contains a reference, call the function -- otherwise issue the message
#
reftype( $first_entry ) ? $first_entry->() : progress_message2( $first_entry );
$first_entry = 0;
} }
# #
# Must check for shell/perl before doing variable expansion # Must check for shell/perl before doing variable expansion
# #
if ( $embedded_enabled ) { if ( $embedded_enabled ) {
if ( $currentline =~ s/^\s*(BEGIN\s+)?SHELL\s*;?// ) { if ( $currentline =~ s/^\s*(BEGIN\s+)?SHELL\s*;?// ) {
handle_first_entry if $first_entry;
embedded_shell( $1 ); embedded_shell( $1 );
next; next;
} }
if ( $currentline =~ s/^\s*(BEGIN\s+)?PERL\s*\;?// ) { if ( $currentline =~ s/^\s*(BEGIN\s+)?PERL\s*\;?// ) {
handle_first_entry if $first_entry;
embedded_perl( $1 ); embedded_perl( $1 );
next; next;
} }
} }
#
my $count = 0; # Now remove concatinated comments
#
$currentline =~ s/\s*#.*$// if $strip_comments;
#
# Ignore ( concatenated ) Blank Lines after comments are removed.
#
$currentline = '', $currentlinenumber = 0, next if $currentline =~ /^\s*$/ && $suppress_whitespace;
#
# Line not blank -- Handle any first-entry message/capabilities check
#
handle_first_entry if $first_entry;
# #
# Expand Shell Variables using %params and @actparms # Expand Shell Variables using %params and @actparms
# #
expand_variables( $currentline ) if $expand_variables; expand_variables( $currentline ) if $expand_variables;
if ( $currentline =~ /^\s*INCLUDE\s/ ) { if ( $currentline =~ /^\s*\??INCLUDE\s/ ) {
my @line = split ' ', $currentline; my @line = split ' ', $currentline;
@@ -2054,7 +2243,7 @@ sub read_a_line(;$$$) {
fatal_error "Directory ($filename) not allowed in INCLUDE" if -d _; fatal_error "Directory ($filename) not allowed in INCLUDE" if -d _;
if ( -s _ ) { if ( -s _ ) {
push @includestack, [ $currentfile, $currentfilename, $currentlinenumber ]; push @includestack, [ $currentfile, $currentfilename, $currentlinenumber, $ifstack ];
$currentfile = undef; $currentfile = undef;
do_open_file $filename; do_open_file $filename;
} else { } else {
@@ -2080,8 +2269,9 @@ sub read_a_line1() {
while ( $currentline = <$currentfile> ) { while ( $currentline = <$currentfile> ) {
next if $currentline =~ /^\s*#/; next if $currentline =~ /^\s*#/;
chomp $currentline; chomp $currentline;
next if $currentline =~ /^\s*$/;
$currentline =~ s/#.*$//; # Remove Trailing Comments $currentline =~ s/#.*$//; # Remove Trailing Comments
$currentline =~ s/\s*$//; # Remove Trailing Whitespace
next if $currentline =~ /^\s*$/;
fatal_error "Non-ASCII gunk in file" if $currentline =~ /[^\s[:print:]]/; fatal_error "Non-ASCII gunk in file" if $currentline =~ /[^\s[:print:]]/;
$currentlinenumber = $.; $currentlinenumber = $.;
print "IN===> $currentline\n" if $debug; print "IN===> $currentline\n" if $debug;
@@ -2092,6 +2282,27 @@ sub read_a_line1() {
} }
} }
sub process_shorewallrc( $ ) {
my $shorewallrc = shift;
$shorewallrc{PRODUCT} = $family == F_IPV4 ? 'shorewall' : 'shorewall6';
if ( open_file $shorewallrc ) {
while ( read_a_line1 ) {
if ( $currentline =~ /^([a-zA-Z]\w*)=(.*)$/ ) {
my ($var, $val) = ($1, $2);
$val = $1 if $val =~ /^\"([^\"]*)\"$/;
expand_variables($val) if supplied $val;
$shorewallrc{$var} = $val;
} else {
fatal_error "Unrecognized shorewallrc entry";
}
}
} else {
fatal_error "Failed to open $shorewallrc: $!";
}
}
# #
# Provide the passed default value for the passed configuration variable # Provide the passed default value for the passed configuration variable
# #
@@ -2416,8 +2627,6 @@ sub determine_kernelversion() {
# #
# Capability Reporting and detection. # Capability Reporting and detection.
# #
sub have_capability( $ );
sub Nat_Enabled() { sub Nat_Enabled() {
$family == F_IPV4 ? qt1( "$iptables -t nat -L -n" ) : ''; $family == F_IPV4 ? qt1( "$iptables -t nat -L -n" ) : '';
} }
@@ -2515,6 +2724,12 @@ sub Owner_Match() {
qt1( "$iptables -A $sillyname -m owner --uid-owner 0 -j ACCEPT" ); qt1( "$iptables -A $sillyname -m owner --uid-owner 0 -j ACCEPT" );
} }
sub Owner_Name_Match() {
if ( my $name = `id -un 2> /dev/null` ) {
qt1( "$iptables -A $sillyname -m owner --uid-owner $name -j ACCEPT" );
}
}
sub Connmark_Match() { sub Connmark_Match() {
qt1( "$iptables -A $sillyname -m connmark --mark 2 -j ACCEPT" ); qt1( "$iptables -A $sillyname -m connmark --mark 2 -j ACCEPT" );
} }
@@ -2778,7 +2993,15 @@ sub Statistic_Match() {
} }
sub Imq_Target() { sub Imq_Target() {
qt1( "$iptables -t mangle -A $sillyname -j IMQ --todev 0" ); have_capability 'MANGLE_ENABLED' && qt1( "$iptables -t mangle -A $sillyname -j IMQ --todev 0" );
}
sub Dscp_Match() {
have_capability 'MANGLE_ENABLED' && qt1( "$iptables -t mangle -A $sillyname -m dscp --dscp 0" );
}
sub Dscp_Target() {
have_capability 'MANGLE_ENABLED' && qt1( "$iptables -t mangle -A $sillyname -j DSCP --set-dscp 0" );
} }
our %detect_capability = our %detect_capability =
@@ -2794,6 +3017,8 @@ our %detect_capability =
CONNMARK_MATCH => \&Connmark_Match, CONNMARK_MATCH => \&Connmark_Match,
CONNTRACK_MATCH => \&Conntrack_Match, CONNTRACK_MATCH => \&Conntrack_Match,
CT_TARGET => \&Ct_Target, CT_TARGET => \&Ct_Target,
DSCP_MATCH => \&Dscp_Match,
DSCP_TARGET => \&Dscp_Target,
ENHANCED_REJECT => \&Enhanced_Reject, ENHANCED_REJECT => \&Enhanced_Reject,
EXMARK => \&Exmark, EXMARK => \&Exmark,
FLOW_FILTER => \&Flow_Filter, FLOW_FILTER => \&Flow_Filter,
@@ -2828,6 +3053,7 @@ our %detect_capability =
OLD_HL_MATCH => \&Old_Hashlimit_Match, OLD_HL_MATCH => \&Old_Hashlimit_Match,
OLD_IPP2P_MATCH => \&Old_Ipp2p_Match, OLD_IPP2P_MATCH => \&Old_Ipp2p_Match,
OWNER_MATCH => \&Owner_Match, OWNER_MATCH => \&Owner_Match,
OWNER_NAME_MATCH => \&Owner_Name_Match,
PERSISTENT_SNAT => \&Persistent_Snat, PERSISTENT_SNAT => \&Persistent_Snat,
PHYSDEV_BRIDGE => \&Physdev_Bridge, PHYSDEV_BRIDGE => \&Physdev_Bridge,
PHYSDEV_MATCH => \&Physdev_Match, PHYSDEV_MATCH => \&Physdev_Match,
@@ -2923,6 +3149,8 @@ sub determine_capabilities() {
$capabilities{IPRANGE_MATCH} = detect_capability( 'IPRANGE_MATCH' ); $capabilities{IPRANGE_MATCH} = detect_capability( 'IPRANGE_MATCH' );
$capabilities{RECENT_MATCH} = detect_capability( 'RECENT_MATCH' ); $capabilities{RECENT_MATCH} = detect_capability( 'RECENT_MATCH' );
$capabilities{OWNER_MATCH} = detect_capability( 'OWNER_MATCH' ); $capabilities{OWNER_MATCH} = detect_capability( 'OWNER_MATCH' );
$capabilities{OWNER_NAME_MATCH}
= detect_capability( 'OWNER_NAME_MATCH' );
$capabilities{CONNMARK_MATCH} = detect_capability( 'CONNMARK_MATCH' ); $capabilities{CONNMARK_MATCH} = detect_capability( 'CONNMARK_MATCH' );
$capabilities{XCONNMARK_MATCH} = detect_capability( 'XCONNMARK_MATCH' ); $capabilities{XCONNMARK_MATCH} = detect_capability( 'XCONNMARK_MATCH' );
$capabilities{IPP2P_MATCH} = detect_capability( 'IPP2P_MATCH' ); $capabilities{IPP2P_MATCH} = detect_capability( 'IPP2P_MATCH' );
@@ -2941,11 +3169,6 @@ sub determine_capabilities() {
$capabilities{IPMARK_TARGET} = detect_capability( 'IPMARK_TARGET' ); $capabilities{IPMARK_TARGET} = detect_capability( 'IPMARK_TARGET' );
$capabilities{TPROXY_TARGET} = detect_capability( 'TPROXY_TARGET' ); $capabilities{TPROXY_TARGET} = detect_capability( 'TPROXY_TARGET' );
if ( $capabilities{MANGLE_ENABLED} ) {
qt1( "$iptables -t mangle -F $sillyname" );
qt1( "$iptables -t mangle -X $sillyname" );
}
$capabilities{MANGLE_FORWARD} = detect_capability( 'MANGLE_FORWARD' ); $capabilities{MANGLE_FORWARD} = detect_capability( 'MANGLE_FORWARD' );
$capabilities{RAW_TABLE} = detect_capability( 'RAW_TABLE' ); $capabilities{RAW_TABLE} = detect_capability( 'RAW_TABLE' );
$capabilities{RAWPOST_TABLE} = detect_capability( 'RAWPOST_TABLE' ); $capabilities{RAWPOST_TABLE} = detect_capability( 'RAWPOST_TABLE' );
@@ -2975,6 +3198,8 @@ sub determine_capabilities() {
$capabilities{CT_TARGET} = detect_capability( 'CT_TARGET' ); $capabilities{CT_TARGET} = detect_capability( 'CT_TARGET' );
$capabilities{STATISTIC_MATCH} = detect_capability( 'STATISTIC_MATCH' ); $capabilities{STATISTIC_MATCH} = detect_capability( 'STATISTIC_MATCH' );
$capabilities{IMQ_TARGET} = detect_capability( 'IMQ_TARGET' ); $capabilities{IMQ_TARGET} = detect_capability( 'IMQ_TARGET' );
$capabilities{DSCP_MATCH} = detect_capability( 'DSCP_MATCH' );
$capabilities{DSCP_TARGET} = detect_capability( 'DSCP_TARGET' );
qt1( "$iptables -F $sillyname" ); qt1( "$iptables -F $sillyname" );
@@ -2982,6 +3207,16 @@ sub determine_capabilities() {
qt1( "$iptables -F $sillyname1" ); qt1( "$iptables -F $sillyname1" );
qt1( "$iptables -X $sillyname1" ); qt1( "$iptables -X $sillyname1" );
if ( $capabilities{MANGLE_ENABLED} ) {
qt1( "$iptables -t mangle -F $sillyname" );
qt1( "$iptables -t mangle -X $sillyname" );
}
if ( $capabilities{NAT_ENABLED} ) {
qt1( "$iptables -t nat -F $sillyname" );
qt1( "$iptables -t nat -X $sillyname" );
}
$sillyname = $sillyname1 = undef; $sillyname = $sillyname1 = undef;
} }
} }
@@ -3002,7 +3237,7 @@ sub ensure_config_path() {
my $f = "$globals{SHAREDIR}/configpath"; my $f = "$globals{SHAREDIR}/configpath";
$globals{CONFDIR} = "/usr/share/$product/configfiles/" if $> != 0; $globals{CONFDIR} = "$shorewallrc{SHAREDIR}/$product/configfiles/" if $> != 0;
unless ( $config{CONFIG_PATH} ) { unless ( $config{CONFIG_PATH} ) {
fatal_error "$f does not exist" unless -f $f; fatal_error "$f does not exist" unless -f $f;
@@ -3145,7 +3380,7 @@ sub update_config_file( $ ) {
my $heading_printed; my $heading_printed;
for ( keys %deprecated ) { for ( grep ! $converted{$_} , keys %deprecated ) {
if ( supplied( my $val = $config{$_} ) ) { if ( supplied( my $val = $config{$_} ) ) {
if ( lc $val ne $deprecated{$_} ) { if ( lc $val ne $deprecated{$_} ) {
unless ( $heading_printed ) { unless ( $heading_printed ) {
@@ -3181,7 +3416,7 @@ EOF
progress_message3 "No update required to configuration file $configfile; $configfile.bak not saved"; progress_message3 "No update required to configuration file $configfile; $configfile.bak not saved";
} else { } else {
warning_message "Unable to unlink $configfile.bak"; warning_message "Unable to unlink $configfile.bak";
progress_message3 "No update required to configuration file $configfile; $configfile.b"; progress_message3 "No update required to configuration file $configfile";
} }
exit 0 unless -f find_file 'blacklist'; exit 0 unless -f find_file 'blacklist';
@@ -3209,7 +3444,7 @@ sub process_shorewall_conf( $$ ) {
# #
# Don't expand shell variables or allow embedded scripting # Don't expand shell variables or allow embedded scripting
# #
while ( read_a_line( 0, 0 ) ) { while ( read_a_line1 ) {
if ( $currentline =~ /^\s*([a-zA-Z]\w*)=(.*?)\s*$/ ) { if ( $currentline =~ /^\s*([a-zA-Z]\w*)=(.*?)\s*$/ ) {
my ($var, $val) = ($1, $2); my ($var, $val) = ($1, $2);
@@ -3355,6 +3590,8 @@ sub unsupported_yes_no_warning( $ ) {
sub get_params() { sub get_params() {
my $fn = find_file 'params'; my $fn = find_file 'params';
my %reserved = ( COMMAND => 1, CONFDIR => 1, SHAREDIR => 1, VARDIR => 1 );
if ( -f $fn ) { if ( -f $fn ) {
progress_message2 "Processing $fn ..."; progress_message2 "Processing $fn ...";
@@ -3458,6 +3695,13 @@ sub get_params() {
} }
} }
for ( keys %params ) {
unless ( $_ eq 'SHOREWALL_INIT_SCRIPT' ) {
fatal_error "The variable name $_ is reserved and may not be set in the params file"
if /^SW_/ || /^SHOREWALL_/ || ( exists $config{$_} && ! exists $ENV{$_} ) || exists $reserved{$_};
}
}
if ( $debug ) { if ( $debug ) {
print "PARAMS:\n"; print "PARAMS:\n";
my $value; my $value;
@@ -3758,6 +4002,7 @@ sub get_configuration( $$$ ) {
default_yes_no 'EXPORTMODULES' , ''; default_yes_no 'EXPORTMODULES' , '';
default_yes_no 'LEGACY_FASTSTART' , 'Yes'; default_yes_no 'LEGACY_FASTSTART' , 'Yes';
default_yes_no 'USE_PHYSICAL_NAMES' , ''; default_yes_no 'USE_PHYSICAL_NAMES' , '';
default_yes_no 'IPSET_WARNINGS' , 'Yes';
require_capability 'MARK' , 'FORWARD_CLEAR_MARK=Yes', 's', if $config{FORWARD_CLEAR_MARK}; require_capability 'MARK' , 'FORWARD_CLEAR_MARK=Yes', 's', if $config{FORWARD_CLEAR_MARK};
@@ -4035,8 +4280,9 @@ sub append_file( $;$$ ) {
# #
# Include progress message -- Pretend progress_message call was in the file # Include progress message -- Pretend progress_message call was in the file
# #
my $name = $globals{EXPORT} ? "$file user exit" : $user_exit;
$result = 1; $result = 1;
save_progress_message "Processing $user_exit ..."; save_progress_message "Processing $name ...";
copy1 $user_exit; copy1 $user_exit;
} }
} }

View File

@@ -76,6 +76,7 @@ our @EXPORT = qw( ALLIPv4
proto_name proto_name
validate_port validate_port
validate_portpair validate_portpair
validate_portpair1
validate_port_list validate_port_list
validate_icmp validate_icmp
validate_icmp6 validate_icmp6
@@ -371,6 +372,7 @@ sub validate_port( $$ ) {
sub validate_portpair( $$ ) { sub validate_portpair( $$ ) {
my ($proto, $portpair) = @_; my ($proto, $portpair) = @_;
my $what;
fatal_error "Invalid port range ($portpair)" if $portpair =~ tr/:/:/ > 1; fatal_error "Invalid port range ($portpair)" if $portpair =~ tr/:/:/ > 1;
@@ -379,16 +381,57 @@ sub validate_portpair( $$ ) {
my @ports = split /:/, $portpair, 2; my @ports = split /:/, $portpair, 2;
$_ = validate_port( $proto, $_) for ( grep $_, @ports ); my $protonum = resolve_proto( $proto ) || 0;
$_ = validate_port( $protonum, $_) for grep $_, @ports;
if ( @ports == 2 ) { if ( @ports == 2 ) {
$what = 'port range';
fatal_error "Invalid port range ($portpair)" unless $ports[0] < $ports[1]; fatal_error "Invalid port range ($portpair)" unless $ports[0] < $ports[1];
} else {
$what = 'port';
} }
fatal_error "Using a $what ( $portpair ) requires PROTO TCP, UDP, SCTP or DCCP" unless
defined $protonum && ( $protonum == TCP ||
$protonum == UDP ||
$protonum == SCTP ||
$protonum == DCCP );
join ':', @ports; join ':', @ports;
} }
sub validate_portpair1( $$ ) {
my ($proto, $portpair) = @_;
my $what;
fatal_error "Invalid port range ($portpair)" if $portpair =~ tr/-/-/ > 1;
$portpair = "0$portpair" if substr( $portpair, 0, 1 ) eq ':';
$portpair = "${portpair}65535" if substr( $portpair, -1, 1 ) eq ':';
my @ports = split /-/, $portpair, 2;
my $protonum = resolve_proto( $proto ) || 0;
$_ = validate_port( $protonum, $_) for grep $_, @ports;
if ( @ports == 2 ) {
$what = 'port range';
fatal_error "Invalid port range ($portpair)" unless $ports[0] < $ports[1];
} else {
$what = 'port';
}
fatal_error "Using a $what ( $portpair ) requires PROTO TCP, UDP, SCTP or DCCP" unless
defined $protonum && ( $protonum == TCP ||
$protonum == UDP ||
$protonum == SCTP ||
$protonum == DCCP );
join '-', @ports;
}
sub validate_port_list( $$ ) { sub validate_port_list( $$ ) {
my $result = ''; my $result = '';
my ( $proto, $list ) = @_; my ( $proto, $list ) = @_;

View File

@@ -67,18 +67,17 @@ sub process_tos() {
my $chain = have_capability( 'MANGLE_FORWARD' ) ? 'fortos' : 'pretos'; my $chain = have_capability( 'MANGLE_FORWARD' ) ? 'fortos' : 'pretos';
my $stdchain = have_capability( 'MANGLE_FORWARD' ) ? 'FORWARD' : 'PREROUTING'; my $stdchain = have_capability( 'MANGLE_FORWARD' ) ? 'FORWARD' : 'PREROUTING';
my %tosoptions = ( 'minimize-delay' => 0x10 , if ( my $fn = open_file 'tos' ) {
'maximize-throughput' => 0x08 ,
'maximize-reliability' => 0x04 ,
'minimize-cost' => 0x02 ,
'normal-service' => 0x00 );
if ( my $fn = open_file 'tos' ) {
my $first_entry = 1; my $first_entry = 1;
my ( $pretosref, $outtosref ); my ( $pretosref, $outtosref );
first_entry( sub { progress_message2 "$doing $fn..."; $pretosref = ensure_chain 'mangle' , $chain; $outtosref = ensure_chain 'mangle' , 'outtos'; } ); first_entry( sub { progress_message2 "$doing $fn...";
warning_message "Use of the tos file is deprecated in favor of the TOS target in tcrules";
$pretosref = ensure_chain 'mangle' , $chain;
$outtosref = ensure_chain 'mangle' , 'outtos';
}
);
while ( read_a_line ) { while ( read_a_line ) {
@@ -86,14 +85,7 @@ sub process_tos() {
$first_entry = 0; $first_entry = 0;
fatal_error 'A value must be supplied in the TOS column' if $tos eq '-'; $tos = decode_tos( $tos , 1 );
if ( defined ( my $tosval = $tosoptions{"\L$tos"} ) ) {
$tos = $tosval;
} else {
my $val = numeric_value( $tos );
fatal_error "Invalid TOS value ($tos)" unless defined( $val ) && $val < 0x1f;
}
my $chainref; my $chainref;
@@ -129,7 +121,7 @@ sub process_tos() {
$src , $src ,
$dst , $dst ,
'' , '' ,
"TOS --set-tos $tos" , 'TOS' . $tos ,
'' , '' ,
'TOS' , 'TOS' ,
''; '';
@@ -216,8 +208,8 @@ sub setup_blacklist() {
# for 'refresh' to work properly. # for 'refresh' to work properly.
# #
if ( @$zones || @$zones1 ) { if ( @$zones || @$zones1 ) {
$chainref = dont_delete new_standard_chain 'blacklst' if @$zones; $chainref = set_optflags( new_standard_chain( 'blacklst' ), DONT_OPTIMIZE | DONT_DELETE ) if @$zones;
$chainref1 = dont_delete new_standard_chain 'blackout' if @$zones1; $chainref1 = set_optflags( new_standard_chain( 'blackout' ), DONT_OPTIMIZE | DONT_DELETE ) if @$zones1;
if ( supplied $level ) { if ( supplied $level ) {
$target = ensure_blacklog_chain ( $target, $disposition, $level, $audit ); $target = ensure_blacklog_chain ( $target, $disposition, $level, $audit );
@@ -695,9 +687,9 @@ sub add_common_rules ( $ ) {
my $rejectref = $filter_table->{reject}; my $rejectref = $filter_table->{reject};
if ( $config{DYNAMIC_BLACKLIST} ) { if ( $config{DYNAMIC_BLACKLIST} ) {
add_rule_pair dont_delete( new_standard_chain( 'logdrop' ) ), '' , 'DROP' , $level ; add_rule_pair( set_optflags( new_standard_chain( 'logdrop' ) , DONT_OPTIMIZE | DONT_DELETE ), '' , 'DROP' , $level );
add_rule_pair dont_delete( new_standard_chain( 'logreject' ) ), '' , 'reject' , $level ; add_rule_pair( set_optflags( new_standard_chain( 'logreject' ), DONT_OPTIMIZE | DONT_DELETE ), '' , 'reject' , $level );
$dynamicref = dont_optimize( new_standard_chain( 'dynamic' ) ); $dynamicref = set_optflags( new_standard_chain( 'dynamic' ) , DONT_OPTIMIZE );
add_commands( $dynamicref, '[ -f ${VARDIR}/.dynamic ] && cat ${VARDIR}/.dynamic >&3' ); add_commands( $dynamicref, '[ -f ${VARDIR}/.dynamic ] && cat ${VARDIR}/.dynamic >&3' );
} }
@@ -927,6 +919,13 @@ sub add_common_rules ( $ ) {
p => "udp --dport $ports" , p => "udp --dport $ports" ,
imatch_dest_dev( $interface ) ) imatch_dest_dev( $interface ) )
if get_interface_option( $interface, 'bridge' ); if get_interface_option( $interface, 'bridge' );
unless ( $family == F_IPV6 || get_interface_option( $interface, 'allip' ) ) {
add_ijump( $filter_table->{input_chain( $interface ) } ,
j => 'ACCEPT' ,
p => "udp --dport $ports" ,
s => NILIPv4 . '/32' );
}
} }
} }
@@ -994,7 +993,7 @@ sub add_common_rules ( $ ) {
if ( @$list ) { if ( @$list ) {
progress_message2 "$doing UPnP"; progress_message2 "$doing UPnP";
$chainref = dont_optimize new_nat_chain( 'UPnP' ); $chainref = set_optflags( new_nat_chain( 'UPnP' ), DONT_OPTIMIZE );
add_commands( $chainref, '[ -s /${VARDIR}/.UPnP ] && cat ${VARDIR}/.UPnP >&3' ); add_commands( $chainref, '[ -s /${VARDIR}/.UPnP ] && cat ${VARDIR}/.UPnP >&3' );
@@ -1013,9 +1012,10 @@ sub add_common_rules ( $ ) {
for $interface ( @$list ) { for $interface ( @$list ) {
my $chainref = $filter_table->{input_option_chain $interface}; my $chainref = $filter_table->{input_option_chain $interface};
my $base = uc chain_base get_physical $interface; my $base = uc chain_base get_physical $interface;
my $variable = get_interface_gateway $interface; my $optional = interface_is_optional( $interface );
my $variable = get_interface_gateway( $interface, ! $optional );
if ( interface_is_optional $interface ) { if ( $optional ) {
add_commands( $chainref, add_commands( $chainref,
qq(if [ -n "SW_\$${base}_IS_USABLE" -a -n "$variable" ]; then) ); qq(if [ -n "SW_\$${base}_IS_USABLE" -a -n "$variable" ]; then) );
incr_cmd_level( $chainref ); incr_cmd_level( $chainref );
@@ -1481,7 +1481,7 @@ sub generate_matrix() {
for my $zone ( @zones ) { for my $zone ( @zones ) {
my $zoneref = find_zone( $zone ); my $zoneref = find_zone( $zone );
next if @zones <= 2 && ! $zoneref->{options}{complex}; next if @zones <= 2 && ! $zoneref->{complex};
# #
# Complex zone or we have more than one non-firewall zone -- process_rules created a zone forwarding chain # Complex zone or we have more than one non-firewall zone -- process_rules created a zone forwarding chain
# #
@@ -1560,13 +1560,12 @@ sub generate_matrix() {
my $source_hosts_ref = $zoneref->{hosts}; my $source_hosts_ref = $zoneref->{hosts};
my $chain1 = rules_target firewall_zone , $zone; my $chain1 = rules_target firewall_zone , $zone;
my $chain2 = rules_target $zone, firewall_zone; my $chain2 = rules_target $zone, firewall_zone;
my $complex = $zoneref->{options}{complex} || 0;
my $type = $zoneref->{type}; my $type = $zoneref->{type};
my $frwd_ref = $filter_table->{zone_forward_chain $zone}; my $frwd_ref = $filter_table->{zone_forward_chain $zone};
my $chain = 0; my $chain = 0;
my $dnatref = ensure_chain 'nat' , dnat_chain( $zone ); my $dnatref = ensure_chain 'nat' , dnat_chain( $zone );
my $notrackref = ensure_chain 'raw' , notrack_chain( $zone ); my $notrackref = ensure_chain 'raw' , notrack_chain( $zone );
my $nested = $zoneref->{options}{nested}; my $nested = @{$zoneref->{parents}};
my $parenthasnat = 0; my $parenthasnat = 0;
my $parenthasnotrack = 0; my $parenthasnotrack = 0;

View File

@@ -54,8 +54,8 @@ sub initialize() {
# #
sub process_one_masq( ) sub process_one_masq( )
{ {
my ($interfacelist, $networks, $addresses, $proto, $ports, $ipsec, $mark, $user ) = my ($interfacelist, $networks, $addresses, $proto, $ports, $ipsec, $mark, $user, $condition ) =
split_line1 'masq file', { interface => 0, source => 1, address => 2, proto => 3, port => 4, ipsec => 5, mark => 6, user => 7 }; split_line1 'masq file', { interface => 0, source => 1, address => 2, proto => 3, port => 4, ipsec => 5, mark => 6, user => 7, switch => 8 };
if ( $interfacelist eq 'COMMENT' ) { if ( $interfacelist eq 'COMMENT' ) {
process_comment; process_comment;
@@ -88,7 +88,7 @@ sub process_one_masq( )
$interfacelist = $1; $interfacelist = $1;
} elsif ( $interfacelist =~ /^([^:]+):([^:]*)$/ ) { } elsif ( $interfacelist =~ /^([^:]+):([^:]*)$/ ) {
my ( $one, $two ) = ( $1, $2 ); my ( $one, $two ) = ( $1, $2 );
if ( $2 =~ /\./ ) { if ( $2 =~ /\./ || $2 =~ /^%/ ) {
$interfacelist = $one; $interfacelist = $one;
$destnets = $two; $destnets = $two;
} }
@@ -117,9 +117,9 @@ sub process_one_masq( )
} }
# #
# Handle Protocol and Ports # Handle Protocol, Ports and Condition
# #
$baserule .= do_proto $proto, $ports, ''; $baserule .= do_proto( $proto, $ports, '' ) . do_condition( $condition );
# #
# Handle Mark # Handle Mark
# #
@@ -195,7 +195,7 @@ sub process_one_masq( )
if ( $conditional = conditional_rule( $chainref, $addr ) ) { if ( $conditional = conditional_rule( $chainref, $addr ) ) {
$addrlist .= '--to-source ' . get_interface_address $1; $addrlist .= '--to-source ' . get_interface_address $1;
} else { } else {
$addrlist .= '--to-source ' . record_runtime_address $1; $addrlist .= '--to-source ' . record_runtime_address( '&', $1 );
} }
} elsif ( $addr =~ /^.*\..*\..*\./ ) { } elsif ( $addr =~ /^.*\..*\..*\./ ) {
$target = 'SNAT '; $target = 'SNAT ';
@@ -210,9 +210,7 @@ sub process_one_masq( )
} else { } else {
my $ports = $addr; my $ports = $addr;
$ports =~ s/^://; $ports =~ s/^://;
my $portrange = $ports; validate_portpair1( $proto, $ports );
$portrange =~ s/-/:/;
validate_portpair( $proto, $portrange );
$addrlist .= "--to-ports $ports "; $addrlist .= "--to-ports $ports ";
$exceptionrule = do_proto( $proto, '', '' ); $exceptionrule = do_proto( $proto, '', '' );
} }

View File

@@ -160,9 +160,7 @@ sub setup_route_marking() {
my $chainref2 = new_chain( 'mangle', load_chain( $physical ) ); my $chainref2 = new_chain( 'mangle', load_chain( $physical ) );
dont_optimize $chainref2; set_optflags( $chainref2, DONT_OPTIMIZE | DONT_MOVE | DONT_DELETE );
dont_move $chainref2;
dont_delete $chainref2;
add_ijump ( $chainref1, add_ijump ( $chainref1,
j => $chainref2 , j => $chainref2 ,
@@ -918,7 +916,7 @@ sub add_an_rtrule( ) {
if ( $source eq '-' ) { if ( $source eq '-' ) {
$source = 'from ' . ALLIP; $source = 'from ' . ALLIP;
} elsif ( $source =~ s/^&// ) { } elsif ( $source =~ s/^&// ) {
$source = 'from ' . record_runtime_address $source; $source = 'from ' . record_runtime_address '&', $source;
} elsif ( $family == F_IPV4 ) { } elsif ( $family == F_IPV4 ) {
if ( $source =~ /:/ ) { if ( $source =~ /:/ ) {
( my $interface, $source , my $remainder ) = split( /:/, $source, 3 ); ( my $interface, $source , my $remainder ) = split( /:/, $source, 3 );
@@ -1023,7 +1021,7 @@ sub add_a_route( ) {
sub setup_null_routing() { sub setup_null_routing() {
save_progress_message "Null Routing the RFC 1918 subnets"; save_progress_message "Null Routing the RFC 1918 subnets";
emit "> \${VARDIR}undo_rfc1918_routing\n"; emit "> \${VARDIR}/undo_rfc1918_routing\n";
for ( rfc1918_networks ) { for ( rfc1918_networks ) {
emit( qq(if ! \$IP -4 route ls | grep -q '^$_.* dev '; then), emit( qq(if ! \$IP -4 route ls | grep -q '^$_.* dev '; then),
qq( run_ip route replace unreachable $_), qq( run_ip route replace unreachable $_),

View File

@@ -963,7 +963,7 @@ sub createlogactionchain( $$$$$ ) {
unless ( $targets{$action} & BUILTIN ) { unless ( $targets{$action} & BUILTIN ) {
dont_optimize $chainref; set_optflags( $chainref, DONT_OPTIMIZE );
my $file = find_file $chain; my $file = find_file $chain;
@@ -997,7 +997,7 @@ sub createsimpleactionchain( $ ) {
unless ( $targets{$action} & BUILTIN ) { unless ( $targets{$action} & BUILTIN ) {
dont_optimize $chainref; set_optflags( $chainref, DONT_OPTIMIZE );
my $file = find_file $action; my $file = find_file $action;
@@ -1306,7 +1306,7 @@ sub allowInvalid ( $$$$ ) {
} }
sub forwardUPnP ( $$$$ ) { sub forwardUPnP ( $$$$ ) {
my $chainref = dont_optimize 'forwardUPnP'; my $chainref = set_optflags( 'forwardUPnP', DONT_OPTIMIZE );
add_commands( $chainref , '[ -f ${VARDIR}/.forwardUPnP ] && cat ${VARDIR}/.forwardUPnP >&3' ); add_commands( $chainref , '[ -f ${VARDIR}/.forwardUPnP ] && cat ${VARDIR}/.forwardUPnP >&3' );
} }
@@ -2238,7 +2238,7 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$ $) {
} }
} }
dont_move( dont_optimize( $nonat_chain ) ) if $tgt eq 'RETURN'; set_optflags( $nonat_chain, DONT_MOVE | DONT_OPTIMIZE ) if $tgt eq 'RETURN';
expand_rule( $nonat_chain , expand_rule( $nonat_chain ,
PREROUTE_RESTRICT , PREROUTE_RESTRICT ,
@@ -2262,7 +2262,7 @@ sub process_rule1 ( $$$$$$$$$$$$$$$$ $) {
$action = $usedactions{$normalized_target}{name}; $action = $usedactions{$normalized_target}{name};
$loglevel = ''; $loglevel = '';
} else { } else {
dont_move( dont_optimize ( $chainref ) ) if $action eq 'RETURN'; set_optflags( $chainref , DONT_MOVE | DONT_OPTIMIZE ) if $action eq 'RETURN';
} }
if ( $origdest ) { if ( $origdest ) {
@@ -2458,6 +2458,12 @@ sub process_rule ( ) {
progress_message qq( Rule "$thisline" $done); progress_message qq( Rule "$thisline" $done);
} }
sub intrazone_allowed( $$ ) {
my ( $zone, $zoneref ) = @_;
$zoneref->{complex} && $filter_table->{rules_chain( $zone, $zone )}{policy} ne 'NONE';
}
# #
# Add jumps to the blacklst and blackout chains # Add jumps to the blacklst and blackout chains
# #
@@ -2470,7 +2476,7 @@ sub classic_blacklist() {
for my $zone ( @zones ) { for my $zone ( @zones ) {
my $zoneref = find_zone( $zone ); my $zoneref = find_zone( $zone );
my $simple = @zones <= 2 && ! $zoneref->{options}{complex}; my $simple = @zones <= 2 && ! $zoneref->{complex};
if ( $zoneref->{options}{in}{blacklist} ) { if ( $zoneref->{options}{in}{blacklist} ) {
my $blackref = $filter_table->{blacklst}; my $blackref = $filter_table->{blacklst};
@@ -2484,7 +2490,7 @@ sub classic_blacklist() {
my $ruleschain = rules_chain( $zone, $zone1 ); my $ruleschain = rules_chain( $zone, $zone1 );
my $ruleschainref = $filter_table->{$ruleschain}; my $ruleschainref = $filter_table->{$ruleschain};
if ( ( $zone ne $zone1 || $ruleschainref->{referenced} ) && $ruleschainref->{policy} ne 'NONE' ) { if ( $zone ne $zone1 || intrazone_allowed( $zone, $zoneref ) ) {
add_ijump( ensure_rules_chain( $ruleschain ), j => $blackref, @state ); add_ijump( ensure_rules_chain( $ruleschain ), j => $blackref, @state );
} }
} }
@@ -2501,7 +2507,7 @@ sub classic_blacklist() {
my $ruleschain = rules_chain( $zone1, $zone ); my $ruleschain = rules_chain( $zone1, $zone );
my $ruleschainref = $filter_table->{$ruleschain}; my $ruleschainref = $filter_table->{$ruleschain};
if ( ( $zone ne $zone1 || $ruleschainref->{referenced} ) && $ruleschainref->{policy} ne 'NONE' ) { if ( ( $zone ne $zone1 || intrazone_allowed( $zone, $zoneref ) ) ) {
add_ijump( ensure_rules_chain( $ruleschain ), j => $blackref, @state ); add_ijump( ensure_rules_chain( $ruleschain ), j => $blackref, @state );
} }
} }
@@ -2568,6 +2574,11 @@ sub process_rules( $ ) {
add_interface_options( $blrules ); add_interface_options( $blrules );
#
# Handle MSS settings in the zones file
#
setup_zone_mss;
$fn = open_file 'rules'; $fn = open_file 'rules';
if ( $fn ) { if ( $fn ) {

View File

@@ -194,14 +194,14 @@ sub initialize( $ ) {
} }
sub process_tc_rule( ) { sub process_tc_rule( ) {
my ( $originalmark, $source, $dest, $proto, $ports, $sports, $user, $testval, $length, $tos , $connbytes, $helper, $headers, $probability ); my ( $originalmark, $source, $dest, $proto, $ports, $sports, $user, $testval, $length, $tos , $connbytes, $helper, $headers, $probability , $dscp );
if ( $family == F_IPV4 ) { if ( $family == F_IPV4 ) {
( $originalmark, $source, $dest, $proto, $ports, $sports, $user, $testval, $length, $tos , $connbytes, $helper, $probability ) = ( $originalmark, $source, $dest, $proto, $ports, $sports, $user, $testval, $length, $tos , $connbytes, $helper, $probability, $dscp ) =
split_line1 'tcrules file', { mark => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, user => 6, test => 7, length => 8, tos => 9, connbytes => 10, helper => 11, probability => 12 }; split_line1 'tcrules file', { mark => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, user => 6, test => 7, length => 8, tos => 9, connbytes => 10, helper => 11, probability => 12 , dscp => 13 };
$headers = '-'; $headers = '-';
} else { } else {
( $originalmark, $source, $dest, $proto, $ports, $sports, $user, $testval, $length, $tos , $connbytes, $helper, $headers, $probability ) = ( $originalmark, $source, $dest, $proto, $ports, $sports, $user, $testval, $length, $tos , $connbytes, $helper, $headers, $probability, $dscp ) =
split_line1 'tcrules file', { mark => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, user => 6, test => 7, length => 8, tos => 9, connbytes => 10, helper => 11, headers => 12, probability => 13 }; split_line1 'tcrules file', { mark => 0, source => 1, dest => 2, proto => 3, dport => 4, sport => 5, user => 6, test => 7, length => 8, tos => 9, connbytes => 10, helper => 11, headers => 12, probability => 13 , dscp => 14 };
} }
our @tccmd; our @tccmd;
@@ -239,6 +239,157 @@ sub process_tc_rule( ) {
my $device = ''; my $device = '';
my $fw = firewall_zone; my $fw = firewall_zone;
my $list; my $list;
my $restriction = 0;
my $cmd;
my $rest;
my %processtcc = ( sticky => sub() {
if ( $chain eq 'tcout' ) {
$target = 'sticko';
} else {
fatal_error "SAME rules are only allowed in the PREROUTING and OUTPUT chains" if $chain ne 'tcpre';
}
$restriction = DESTIFACE_DISALLOW;
ensure_mangle_chain($target);
$sticky++;
},
IPMARK => sub() {
my ( $srcdst, $mask1, $mask2, $shift ) = ('src', 255, 0, 0 );
require_capability 'IPMARK_TARGET', 'IPMARK', 's';
if ( $cmd =~ /^IPMARK\((.+?)\)$/ ) {
my $params = $1;
my $val;
my ( $sd, $m1, $m2, $s , $bad ) = split ',', $params;
fatal_error "Invalid IPMARK parameters ($params)" if $bad;
fatal_error "Invalid IPMARK parameter ($sd)" unless ( $sd eq 'src' || $sd eq 'dst' );
$srcdst = $sd;
if ( supplied $m1 ) {
$val = numeric_value ($m1);
fatal_error "Invalid Mask ($m1)" unless defined $val && $val && $val <= 0xffffffff;
$mask1 = in_hex ( $val & 0xffffffff );
}
if ( supplied $m2 ) {
$val = numeric_value ($m2);
fatal_error "Invalid Mask ($m2)" unless defined $val && $val <= 0xffffffff;
$mask2 = in_hex ( $val & 0xffffffff );
}
if ( defined $s ) {
$val = numeric_value ($s);
fatal_error "Invalid Shift Bits ($s)" unless defined $val && $val >= 0 && $val < 128;
$shift = $s;
}
} else {
fatal_error "Invalid MARK/CLASSIFY ($cmd)" unless $cmd eq 'IPMARK';
}
$target = "IPMARK --addr $srcdst --and-mask $mask1 --or-mask $mask2 --shift $shift";
},
TPROXY => sub() {
require_capability( 'TPROXY_TARGET', 'Use of TPROXY', 's');
fatal_error "Invalid TPROXY specification( $cmd/$rest )" if $rest;
$chain = 'tcpre';
$cmd =~ /TPROXY\((.+?)\)$/;
my $params = $1;
fatal_error "Invalid TPROXY specification( $cmd )" unless defined $params;
( $mark, my $port, my $ip, my $bad ) = split ',', $params;
fatal_error "Invalid TPROXY specification( $cmd )" if defined $bad;
if ( $port ) {
$port = validate_port( 'tcp', $port );
} else {
$port = 0;
}
$target .= " --on-port $port";
if ( supplied $ip ) {
if ( $family == F_IPV6 ) {
$ip = $1 if $ip =~ /^\[(.+)\]$/ || $ip =~ /^<(.+)>$/;
}
validate_address $ip, 1;
$target .= " --on-ip $ip";
}
$target .= ' --tproxy-mark';
},
TTL => sub() {
fatal_error "TTL is not supported in IPv6 - use HL instead" if $family == F_IPV6;
fatal_error "Invalid TTL specification( $cmd/$rest )" if $rest;
fatal_error "Chain designator $designator not allowed with TTL" if $designator && ! ( $designator eq 'F' );
$chain = 'tcfor';
$cmd =~ /^TTL\(([-+]?\d+)\)$/;
my $param = $1;
fatal_error "Invalid TTL specification( $cmd )" unless $param && ( $param = abs $param ) < 256;
if ( $1 =~ /^\+/ ) {
$target .= " --ttl-inc $param";
} elsif ( $1 =~ /\-/ ) {
$target .= " --ttl-dec $param";
} else {
$target .= " --ttl-set $param";
}
},
HL => sub() {
fatal_error "HL is not supported in IPv4 - use TTL instead" if $family == F_IPV4;
fatal_error "Invalid HL specification( $cmd/$rest )" if $rest;
fatal_error "Chain designator $designator not allowed with HL" if $designator && ! ( $designator eq 'F' );
$chain = 'tcfor';
$cmd =~ /^HL\(([-+]?\d+)\)$/;
my $param = $1;
fatal_error "Invalid HL specification( $cmd )" unless $param && ( $param = abs $param ) < 256;
if ( $1 =~ /^\+/ ) {
$target .= " --hl-inc $param";
} elsif ( $1 =~ /\-/ ) {
$target .= " --hl-dec $param";
} else {
$target .= " --hl-set $param";
}
},
IMQ => sub() {
assert( $cmd =~ /^IMQ\((\d+)\)$/ );
require_capability 'IMQ_TARGET', 'IMQ', 's';
$target .= " --todev $1";
},
DSCP => sub() {
assert( $cmd =~ /^DSCP\((\w+)\)$/ );
require_capability 'DSCP_TARGET', 'The DSCP action', 's';
my $dscp = numeric_value( $1 );
$dscp = $dscpmap{$1} unless defined $dscp;
fatal_error( "Invalid DSCP ($1)" ) unless defined $dscp && $dscp <= 0x38 && ! ( $dscp & 1 );
$target .= ' --set-dscp ' . in_hex( $dscp );
},
TOS => sub() {
assert( $cmd =~ /^TOS\((.+)\)$/ );
$target .= decode_tos( $1 , 2 );
},
);
if ( $source ) { if ( $source ) {
if ( $source eq $fw ) { if ( $source eq $fw ) {
@@ -312,12 +463,15 @@ sub process_tc_rule( ) {
} }
} }
my ($cmd, $rest) = split( '/', $mark, 2 ); if ( $mark =~ /^TOS/ ) {
$cmd = $mark;
$rest = '';
} else {
($cmd, $rest) = split( '/', $mark, 2 );
}
$list = ''; $list = '';
my $restriction = 0;
unless ( $classid ) { unless ( $classid ) {
MARK: MARK:
{ {
@@ -336,134 +490,8 @@ sub process_tc_rule( ) {
$mark =~ s/^[|&]//; $mark =~ s/^[|&]//;
} }
if ( $target eq 'sticky' ) { if ( my $f = $processtcc{$target} ) {
if ( $chain eq 'tcout' ) { $f->();
$target = 'sticko';
} else {
fatal_error "SAME rules are only allowed in the PREROUTING and OUTPUT chains" if $chain ne 'tcpre';
}
$restriction = DESTIFACE_DISALLOW;
ensure_mangle_chain($target);
$sticky++;
} elsif ( $target eq 'IPMARK' ) {
my ( $srcdst, $mask1, $mask2, $shift ) = ('src', 255, 0, 0 );
require_capability 'IPMARK_TARGET', 'IPMARK', 's';
if ( $cmd =~ /^IPMARK\((.+?)\)$/ ) {
my $params = $1;
my $val;
my ( $sd, $m1, $m2, $s , $bad ) = split ',', $params;
fatal_error "Invalid IPMARK parameters ($params)" if $bad;
fatal_error "Invalid IPMARK parameter ($sd)" unless ( $sd eq 'src' || $sd eq 'dst' );
$srcdst = $sd;
if ( supplied $m1 ) {
$val = numeric_value ($m1);
fatal_error "Invalid Mask ($m1)" unless defined $val && $val && $val <= 0xffffffff;
$mask1 = in_hex ( $val & 0xffffffff );
}
if ( supplied $m2 ) {
$val = numeric_value ($m2);
fatal_error "Invalid Mask ($m2)" unless defined $val && $val <= 0xffffffff;
$mask2 = in_hex ( $val & 0xffffffff );
}
if ( defined $s ) {
$val = numeric_value ($s);
fatal_error "Invalid Shift Bits ($s)" unless defined $val && $val >= 0 && $val < 128;
$shift = $s;
}
} else {
fatal_error "Invalid MARK/CLASSIFY ($cmd)" unless $cmd eq 'IPMARK';
}
$target = "IPMARK --addr $srcdst --and-mask $mask1 --or-mask $mask2 --shift $shift";
} elsif ( $target eq 'TPROXY' ) {
require_capability( 'TPROXY_TARGET', 'Use of TPROXY', 's');
fatal_error "Invalid TPROXY specification( $cmd/$rest )" if $rest;
$chain = 'tcpre';
$cmd =~ /TPROXY\((.+?)\)$/;
my $params = $1;
fatal_error "Invalid TPROXY specification( $cmd )" unless defined $params;
( $mark, my $port, my $ip, my $bad ) = split ',', $params;
fatal_error "Invalid TPROXY specification( $cmd )" if defined $bad;
if ( $port ) {
$port = validate_port( 'tcp', $port );
} else {
$port = 0;
}
$target .= " --on-port $port";
if ( supplied $ip ) {
if ( $family == F_IPV6 ) {
$ip = $1 if $ip =~ /^\[(.+)\]$/ || $ip =~ /^<(.+)>$/;
}
validate_address $ip, 1;
$target .= " --on-ip $ip";
}
$target .= ' --tproxy-mark';
} elsif ( $target eq 'TTL' ) {
fatal_error "TTL is not supported in IPv6 - use HL instead" if $family == F_IPV6;
fatal_error "Invalid TTL specification( $cmd/$rest )" if $rest;
fatal_error "Chain designator $designator not allowed with TTL" if $designator && ! ( $designator eq 'F' );
$chain = 'tcfor';
$cmd =~ /^TTL\(([-+]?\d+)\)$/;
my $param = $1;
fatal_error "Invalid TTL specification( $cmd )" unless $param && ( $param = abs $param ) < 256;
if ( $1 =~ /^\+/ ) {
$target .= " --ttl-inc $param";
} elsif ( $1 =~ /\-/ ) {
$target .= " --ttl-dec $param";
} else {
$target .= " --ttl-set $param";
}
} elsif ( $target eq 'HL' ) {
fatal_error "HL is not supported in IPv4 - use TTL instead" if $family == F_IPV4;
fatal_error "Invalid HL specification( $cmd/$rest )" if $rest;
fatal_error "Chain designator $designator not allowed with HL" if $designator && ! ( $designator eq 'F' );
$chain = 'tcfor';
$cmd =~ /^HL\(([-+]?\d+)\)$/;
my $param = $1;
fatal_error "Invalid HL specification( $cmd )" unless $param && ( $param = abs $param ) < 256;
if ( $1 =~ /^\+/ ) {
$target .= " --hl-inc $param";
} elsif ( $1 =~ /\-/ ) {
$target .= " --hl-dec $param";
} else {
$target .= " --hl-set $param";
}
} elsif ( $target eq 'IMQ' ) {
assert( $cmd =~ /^IMQ\((\d+)\)$/ );
require_capability 'IMQ_TARGET', 'IMQ', 's';
$target .= " --todev $1";
} }
if ( $rest ) { if ( $rest ) {
@@ -510,7 +538,8 @@ sub process_tc_rule( ) {
do_connbytes( $connbytes ) . do_connbytes( $connbytes ) .
do_helper( $helper ) . do_helper( $helper ) .
do_headers( $headers ) . do_headers( $headers ) .
do_probability( $probability ) , do_probability( $probability ) .
do_dscp( $dscp ),
$source , $source ,
$dest , $dest ,
'' , '' ,
@@ -855,7 +884,7 @@ sub validate_tc_device( ) {
pfifo => $pfifo, pfifo => $pfifo,
tablenumber => 1 , tablenumber => 1 ,
redirected => \@redirected, redirected => \@redirected,
default => 0, default => undef,
nextclass => 2, nextclass => 2,
qdisc => $qdisc, qdisc => $qdisc,
guarantee => 0, guarantee => 0,
@@ -998,6 +1027,7 @@ sub validate_tc_class( ) {
} }
} else { } else {
fatal_error "Duplicate Class NUMBER ($classnumber)" if $tcref->{$classnumber}; fatal_error "Duplicate Class NUMBER ($classnumber)" if $tcref->{$classnumber};
$markval = '-';
} }
if ( $parentclass != 1 ) { if ( $parentclass != 1 ) {
@@ -1009,7 +1039,7 @@ sub validate_tc_class( ) {
fatal_error "Unknown Parent class ($parentnum)" unless $parentref && $parentref->{occurs} == 1; fatal_error "Unknown Parent class ($parentnum)" unless $parentref && $parentref->{occurs} == 1;
fatal_error "The class ($parentnum) specifies UMAX and/or DMAX; it cannot serve as a parent" if $parentref->{dmax}; fatal_error "The class ($parentnum) specifies UMAX and/or DMAX; it cannot serve as a parent" if $parentref->{dmax};
fatal_error "The class ($parentnum) specifies flow; it cannot serve as a parent" if $parentref->{flow}; fatal_error "The class ($parentnum) specifies flow; it cannot serve as a parent" if $parentref->{flow};
fatal_error "The default class ($parentnum) may not have sub-classes" if $devref->{default} == $parentclass; fatal_error "The default class ($parentnum) may not have sub-classes" if ( $devref->{default} || 0 ) == $parentclass;
$parentref->{leaf} = 0; $parentref->{leaf} = 0;
$ratemax = $parentref->{rate}; $ratemax = $parentref->{rate};
$ratename = q(the parent class's RATE); $ratename = q(the parent class's RATE);
@@ -1114,8 +1144,10 @@ sub validate_tc_class( ) {
} }
unless ( $devref->{classify} || $occurs > 1 ) { unless ( $devref->{classify} || $occurs > 1 ) {
fatal_error "Missing MARK" if $mark eq '-'; if ( $mark ne '-' ) {
warning_message "Class NUMBER ignored -- INTERFACE $device does not have the 'classify' option" if $devclass =~ /:/; fatal_error "Missing MARK" if $mark eq '-';
warning_message "Class NUMBER ignored -- INTERFACE $device does not have the 'classify' option" if $devclass =~ /:/;
}
} }
$tcref->{flow} = $devref->{flow} unless $tcref->{flow}; $tcref->{flow} = $devref->{flow} unless $tcref->{flow};
@@ -1596,7 +1628,7 @@ sub process_traffic_shaping() {
my $devnum = in_hexp $devref->{number}; my $devnum = in_hexp $devref->{number};
my $r2q = int calculate_r2q $devref->{out_bandwidth}; my $r2q = int calculate_r2q $devref->{out_bandwidth};
fatal_error "No default class defined for device $devname" unless $devref->{default}; fatal_error "No default class defined for device $devname" unless defined $devref->{default};
my $device = physical_name $devname; my $device = physical_name $devname;
@@ -1708,7 +1740,7 @@ sub process_traffic_shaping() {
# #
# add filters # add filters
# #
unless ( $devref->{classify} ) { unless ( $mark eq '-' ) {
emit "run_tc filter add dev $device protocol all parent $devicenumber:0 prio " . ( $priority | 20 ) . " handle $mark fw classid $classid" if $tcref->{occurs} == 1; emit "run_tc filter add dev $device protocol all parent $devicenumber:0 prio " . ( $priority | 20 ) . " handle $mark fw classid $classid" if $tcref->{occurs} == 1;
} }
@@ -1927,13 +1959,13 @@ sub setup_tc() {
if ( $config{TC_ENABLED} ) { if ( $config{TC_ENABLED} ) {
our @tccmd = ( { match => sub ( $ ) { $_[0] eq 'SAVE' } , our @tccmd = ( { match => sub ( $ ) { $_[0] eq 'SAVE' } ,
target => 'CONNMARK --save-mark --mask' , target => 'CONNMARK --save-mark --mask' ,
mark => SMALLMARK , mark => $config{TC_EXPERT} ? HIGHMARK : SMALLMARK,
mask => in_hex( $globals{TC_MASK} ) , mask => in_hex( $globals{TC_MASK} ) ,
connmark => 1 connmark => 1
} , } ,
{ match => sub ( $ ) { $_[0] eq 'RESTORE' }, { match => sub ( $ ) { $_[0] eq 'RESTORE' },
target => 'CONNMARK --restore-mark --mask' , target => 'CONNMARK --restore-mark --mask' ,
mark => SMALLMARK , mark => $config{TC_EXPERT} ? HIGHMARK : SMALLMARK ,
mask => in_hex( $globals{TC_MASK} ) , mask => in_hex( $globals{TC_MASK} ) ,
connmark => 1 connmark => 1
} , } ,
@@ -1988,6 +2020,18 @@ sub setup_tc() {
mask => '', mask => '',
connmark => 0 connmark => 0
}, },
{ match => sub( $ ) { $_[0] =~ /^DSCP\(\w+\)$/ },
target => 'DSCP',
mark => NOMARK,
mask => '',
connmark => 0
},
{ match => sub( $ ) { $_[0] =~ /^TOS\(.+\)$/ },
target => 'TOS',
mark => NOMARK,
mask => '',
connmark => 0
},
); );
if ( my $fn = open_file 'tcrules' ) { if ( my $fn = open_file 'tcrules' ) {

View File

@@ -83,6 +83,7 @@ our @EXPORT = qw( NOTHING
compile_updown compile_updown
validate_hosts_file validate_hosts_file
find_hosts_by_option find_hosts_by_option
find_zone_hosts_by_option
find_zones_by_option find_zones_by_option
all_ipsets all_ipsets
have_ipsec have_ipsec
@@ -113,11 +114,10 @@ use constant { IN_OUT => 1,
# #
# @zones contains the ordered list of zones with sub-zones appearing before their parents. # @zones contains the ordered list of zones with sub-zones appearing before their parents.
# #
# %zones{<zone1> => {type = > <zone type> FIREWALL, IP, IPSEC, BPORT; # %zones{<zone1> => {type => <zone type> FIREWALL, IP, IPSEC, BPORT;
# options => { complex => 0|1 # complex => 0|1
# nested => 0|1 # super => 0|1
# super => 0|1 # options => { in_out => < policy match string >
# in_out => < policy match string >
# in => < policy match string > # in => < policy match string >
# out => < policy match string > # out => < policy match string >
# } # }
@@ -227,6 +227,25 @@ my %maxoptionvalue = ( routefilter => 2, mss => 100000 , wait => 120 );
my %validhostoptions; my %validhostoptions;
my %validzoneoptions = ( mss => NUMERIC,
nomark => NOTHING,
blacklist => NOTHING,
strict => NOTHING,
next => NOTHING,
reqid => NUMERIC,
spi => NUMERIC,
proto => IPSECPROTO,
mode => IPSECMODE,
"tunnel-src" => NETWORK,
"tunnel-dst" => NETWORK,
);
use constant { UNRESTRICTED => 1, NOFW => 2 , COMPLEX => 8, IN_OUT_ONLY => 16 };
#
# Hash of options that have their own key in the returned hash.
#
my %zonekey = ( mss => UNRESTRICTED | COMPLEX , blacklist => NOFW, nomark => NOFW | IN_OUT_ONLY );
# #
# Rather than initializing globals in an INIT block or during declaration, # Rather than initializing globals in an INIT block or during declaration,
# we initialize them in a function. This is done for two reasons: # we initialize them in a function. This is done for two reasons:
@@ -290,6 +309,7 @@ sub initialize( $$ ) {
broadcast => 1, broadcast => 1,
destonly => 1, destonly => 1,
sourceonly => 1, sourceonly => 1,
mss => 1,
); );
%zonetypes = ( 1 => 'firewall', 2 => 'ipv4', 4 => 'bport4', 8 => 'ipsec4', 16 => 'vserver' ); %zonetypes = ( 1 => 'firewall', 2 => 'ipv4', 4 => 'bport4', 8 => 'ipsec4', 16 => 'vserver' );
} else { } else {
@@ -316,6 +336,7 @@ sub initialize( $$ ) {
maclist => 1, maclist => 1,
routeback => 1, routeback => 1,
tcpflags => 1, tcpflags => 1,
mss => 1,
); );
%zonetypes = ( 1 => 'firewall', 2 => 'ipv6', 4 => 'bport6', 8 => 'ipsec4', 16 => 'vserver' ); %zonetypes = ( 1 => 'firewall', 2 => 'ipv6', 4 => 'bport6', 8 => 'ipsec4', 16 => 'vserver' );
} }
@@ -329,25 +350,6 @@ sub initialize( $$ ) {
# #
sub parse_zone_option_list($$\$$) sub parse_zone_option_list($$\$$)
{ {
my %validoptions = ( mss => NUMERIC,
nomark => NOTHING,
blacklist => NOTHING,
strict => NOTHING,
next => NOTHING,
reqid => NUMERIC,
spi => NUMERIC,
proto => IPSECPROTO,
mode => IPSECMODE,
"tunnel-src" => NETWORK,
"tunnel-dst" => NETWORK,
);
use constant { UNRESTRICTED => 1, NOFW => 2 , COMPLEX => 8, IN_OUT_ONLY => 16 };
#
# Hash of options that have their own key in the returned hash.
#
my %key = ( mss => UNRESTRICTED | COMPLEX , blacklist => NOFW, nomark => NOFW | IN_OUT_ONLY );
my ( $list, $zonetype, $complexref, $column ) = @_; my ( $list, $zonetype, $complexref, $column ) = @_;
my %h; my %h;
my $options = ''; my $options = '';
@@ -367,7 +369,7 @@ sub parse_zone_option_list($$\$$)
$e = $1; $e = $1;
} }
$fmt = $validoptions{$e}; $fmt = $validzoneoptions{$e};
fatal_error "Invalid Option ($e)" unless $fmt; fatal_error "Invalid Option ($e)" unless $fmt;
@@ -378,7 +380,7 @@ sub parse_zone_option_list($$\$$)
fatal_error "Invalid value ($val) for option \"$e\"" unless $val =~ /^($fmt)$/; fatal_error "Invalid value ($val) for option \"$e\"" unless $val =~ /^($fmt)$/;
} }
my $key = $key{$e}; my $key = $zonekey{$e};
if ( $key ) { if ( $key ) {
fatal_error "Option '$e' not permitted with this zone type " if $key & NOFW && ($zonetype & ( FIREWALL | VSERVER) ); fatal_error "Option '$e' not permitted with this zone type " if $key & NOFW && ($zonetype & ( FIREWALL | VSERVER) );
@@ -403,13 +405,13 @@ sub parse_zone_option_list($$\$$)
# #
# Set the super option on the passed zoneref and propagate to its parents # Set the super option on the passed zoneref and propagate to its parents
# #
sub set_super( $ ); sub set_super( $ ); #required for recursion
sub set_super( $ ) { sub set_super( $ ) {
my $zoneref = shift; my $zoneref = shift;
unless ( $zoneref->{options}{super} ) { unless ( $zoneref->{super} ) {
$zoneref->{options}{super} = 1; $zoneref->{super} = 1;
set_super( $zones{$_} ) for @{$zoneref->{parents}}; set_super( $zones{$_} ) for @{$zoneref->{parents}};
} }
} }
@@ -487,10 +489,9 @@ sub process_zone( \$ ) {
options => { in_out => parse_zone_option_list( $options , $type, $complex , IN_OUT ) , options => { in_out => parse_zone_option_list( $options , $type, $complex , IN_OUT ) ,
in => parse_zone_option_list( $in_options , $type , $complex , IN ) , in => parse_zone_option_list( $in_options , $type , $complex , IN ) ,
out => parse_zone_option_list( $out_options , $type , $complex , OUT ) , out => parse_zone_option_list( $out_options , $type , $complex , OUT ) ,
complex => ( $type & IPSEC || $complex ) ,
nested => @parents > 0 ,
super => 0 ,
} , } ,
super => 0 ,
complex => ( $type & IPSEC || $complex ) ,
interfaces => {} , interfaces => {} ,
children => [] , children => [] ,
hosts => {} hosts => {}
@@ -506,7 +507,7 @@ sub process_zone( \$ ) {
fatal_error "Zone mark overflow - please increase the setting of ZONE_BITS" if $zonemark >= $zonemarklimit; fatal_error "Zone mark overflow - please increase the setting of ZONE_BITS" if $zonemark >= $zonemarklimit;
$mark = $zonemark; $mark = $zonemark;
$zonemark += $zonemarkincr; $zonemark += $zonemarkincr;
$zoneref->{options}{complex} = 1; $zoneref->{complex} = 1;
} }
} }
@@ -517,7 +518,6 @@ sub process_zone( \$ ) {
} }
} }
if ( $zoneref->{options}{in_out}{blacklist} ) { if ( $zoneref->{options}{in_out}{blacklist} ) {
for ( qw/in out/ ) { for ( qw/in out/ ) {
unless ( $zoneref->{options}{$_}{blacklist} ) { unless ( $zoneref->{options}{$_}{blacklist} ) {
@@ -769,20 +769,24 @@ sub add_group_to_zone($$$$$)
my $gtype = $type & IPSEC ? 'ipsec' : 'ip'; my $gtype = $type & IPSEC ? 'ipsec' : 'ip';
$hostsref = ( $zoneref->{hosts} || ( $zoneref->{hosts} = {} ) ); $hostsref = ( $zoneref->{hosts} ||= {} );
$typeref = ( $hostsref->{$gtype} || ( $hostsref->{$gtype} = {} ) ); $typeref = ( $hostsref->{$gtype} ||= {} );
$interfaceref = ( $typeref->{$interface} || ( $typeref->{$interface} = [] ) ); $interfaceref = ( $typeref->{$interface} ||= [] );
fatal_error "Duplicate Host Group ($interface:" . ALLIP . ") in zone $zone" if $allip && @$interfaceref; fatal_error "Duplicate Host Group ($interface:" . ALLIP . ") in zone $zone" if $allip && @$interfaceref;
$zoneref->{options}{complex} = 1 if @$interfaceref || ( @newnetworks > 1 ) || ( @exclusions ) || $options->{routeback}; $zoneref->{complex} = 1 if @$interfaceref || @newnetworks > 1 || @exclusions || $options->{routeback};
push @{$interfaceref}, { options => $options, push @{$interfaceref}, { options => $options,
hosts => \@newnetworks, hosts => \@newnetworks,
ipsec => $type & IPSEC ? 'ipsec' : 'none' , ipsec => $type & IPSEC ? 'ipsec' : 'none' ,
exclusions => \@exclusions }; exclusions => \@exclusions };
$interfaces{$interface}{options}{routeback} ||= ( $type != IPSEC && $options->{routeback} ); if ( $type != IPSEC ) {
my $optref = $interfaces{$interface}{options};
$optref->{routeback} ||= $options->{routeback};
$optref->{allip} ||= $allip;
}
} }
# #
@@ -838,7 +842,7 @@ sub all_parent_zones() {
} }
sub complex_zones() { sub complex_zones() {
grep( $zones{$_}{options}{complex} , @zones ); grep( $zones{$_}{complex} , @zones );
} }
sub vserver_zones() { sub vserver_zones() {
@@ -912,9 +916,26 @@ sub process_interface( $$ ) {
my ( $nextinum, $export ) = @_; my ( $nextinum, $export ) = @_;
my $netsref = ''; my $netsref = '';
my $filterref = []; my $filterref = [];
my ($zone, $originalinterface, $bcasts, $options ) = split_line 'interfaces file', { zone => 0, interface => 1, broadcast => 2, options => 3 }; my ($zone, $originalinterface, $bcasts, $options );
my $zoneref; my $zoneref;
my $bridge = ''; my $bridge = '';
our $format;
if ( $format == 1 ) {
($zone, $originalinterface, $bcasts, $options ) = split_line1 'interfaces file', { zone => 0, interface => 1, broadcast => 2, options => 3 }, { COMMENT => 0, FORMAT => 2 };
} else {
($zone, $originalinterface, $options ) = split_line1 'interfaces file', { zone => 0, interface => 1, options => 2 }, { COMMENT => 0, FORMAT => 2 };
$bcasts = '-';
}
if ( $zone eq 'FORMAT' ) {
if ( $originalinterface =~ /^([12])$/ ) {
$format = $1;
return;
}
fatal_error "Invalid FORMAT ($1)";
}
if ( $zone eq '-' ) { if ( $zone eq '-' ) {
$zone = ''; $zone = '';
@@ -1185,7 +1206,8 @@ sub process_interface( $$ ) {
# Parse the interfaces file. # Parse the interfaces file.
# #
sub validate_interfaces_file( $ ) { sub validate_interfaces_file( $ ) {
my $export = shift; my $export = shift;
our $format = 1;
my @ifaces; my @ifaces;
my $nextinum = 1; my $nextinum = 1;
@@ -1820,7 +1842,7 @@ sub process_host( ) {
} }
if ( $hosts =~ /^!?\+/ ) { if ( $hosts =~ /^!?\+/ ) {
$zoneref->{options}{complex} = 1; $zoneref->{complex} = 1;
fatal_error "ipset name qualification is disallowed in this file" if $hosts =~ /[\[\]]/; fatal_error "ipset name qualification is disallowed in this file" if $hosts =~ /[\[\]]/;
fatal_error "Invalid ipset name ($hosts)" unless $hosts =~ /^!?\+[a-zA-Z][-\w]*$/; fatal_error "Invalid ipset name ($hosts)" unless $hosts =~ /^!?\+[a-zA-Z][-\w]*$/;
} }
@@ -1844,12 +1866,16 @@ sub process_host( ) {
if ( $option eq 'ipsec' ) { if ( $option eq 'ipsec' ) {
require_capability 'POLICY_MATCH' , q(The 'ipsec' option), 's'; require_capability 'POLICY_MATCH' , q(The 'ipsec' option), 's';
$type = IPSEC; $type = IPSEC;
$zoneref->{options}{complex} = 1; $zoneref->{complex} = 1;
$ipsec = $interfaceref->{ipsec} = 1; $ipsec = $interfaceref->{ipsec} = 1;
} elsif ( $option eq 'norfc1918' ) { } elsif ( $option eq 'norfc1918' ) {
warning_message "The 'norfc1918' host option is no longer supported" warning_message "The 'norfc1918' host option is no longer supported"
} elsif ( $option eq 'blacklist' ) { } elsif ( $option eq 'blacklist' ) {
$zoneref->{options}{in}{blacklist} = 1; $zoneref->{options}{in}{blacklist} = 1;
} elsif ( $option =~ /^mss=(\d+)$/ ) {
fatal_error "Invalid mss ($1)" unless $1 >= 500;
$options{mss} = $1;
$zoneref->{options}{complex} = 1;
} elsif ( $validhostoptions{$option}) { } elsif ( $validhostoptions{$option}) {
fatal_error qq(The "$option" option is not allowed with Vserver zones) if $type & VSERVER && ! ( $validhostoptions{$option} & IF_OPTION_VSERVER ); fatal_error qq(The "$option" option is not allowed with Vserver zones) if $type & VSERVER && ! ( $validhostoptions{$option} & IF_OPTION_VSERVER );
$options{$option} = 1; $options{$option} = 1;
@@ -1914,8 +1940,7 @@ sub validate_hosts_file()
$have_ipsec = $ipsec || haveipseczones; $have_ipsec = $ipsec || haveipseczones;
$_->{options}{complex} ||= ( keys %{$_->{interfaces}} > 1 ) for values %zones; $_->{complex} ||= ( keys %{$_->{interfaces}} > 1 ) for values %zones;
} }
# #
@@ -1927,7 +1952,7 @@ sub have_ipsec() {
# #
# Returns a reference to a array of host entries. Each entry is a # Returns a reference to a array of host entries. Each entry is a
# reference to an array containing ( interface , polciy match type {ipsec|none} , network , exclusions ); # reference to an array containing ( interface , polciy match type {ipsec|none} , network , exclusions, value );
# #
sub find_hosts_by_option( $ ) { sub find_hosts_by_option( $ ) {
my $option = $_[0]; my $option = $_[0];
@@ -1937,9 +1962,9 @@ sub find_hosts_by_option( $ ) {
while ( my ($type, $interfaceref) = each %{$zones{$zone}{hosts}} ) { while ( my ($type, $interfaceref) = each %{$zones{$zone}{hosts}} ) {
while ( my ( $interface, $arrayref) = ( each %{$interfaceref} ) ) { while ( my ( $interface, $arrayref) = ( each %{$interfaceref} ) ) {
for my $host ( @{$arrayref} ) { for my $host ( @{$arrayref} ) {
if ( $host->{options}{$option} ) { if ( my $value = $host->{options}{$option} ) {
for my $net ( @{$host->{hosts}} ) { for my $net ( @{$host->{hosts}} ) {
push @hosts, [ $interface, $host->{ipsec} , $net , $host->{exclusions}]; push @hosts, [ $interface, $host->{ipsec} , $net , $host->{exclusions}, $value ];
} }
} }
} }
@@ -1956,6 +1981,30 @@ sub find_hosts_by_option( $ ) {
\@hosts; \@hosts;
} }
#
# As above but for a single zone
#
sub find_zone_hosts_by_option( $$ ) {
my ($zone, $option ) = @_;
my @hosts;
unless ( $zones{$zone}{type} & FIREWALL ) {
while ( my ($type, $interfaceref) = each %{$zones{$zone}{hosts}} ) {
while ( my ( $interface, $arrayref) = ( each %{$interfaceref} ) ) {
for my $host ( @{$arrayref} ) {
if ( my $value = $host->{options}{$option} ) {
for my $net ( @{$host->{hosts}} ) {
push @hosts, [ $interface, $host->{ipsec} , $net , $host->{exclusions}, $value ];
}
}
}
}
}
}
\@hosts;
}
# #
# Returns a reference to a list of zones with the passed in/out option # Returns a reference to a list of zones with the passed in/out option
# #

View File

@@ -65,6 +65,7 @@ sub usage( $ ) {
[ --annotate ] [ --annotate ]
[ --update ] [ --update ]
[ --convert ] [ --convert ]
[ --shorewallrc ]
[ --config_path=<path-list> ] [ --config_path=<path-list> ]
'; ';
@@ -91,6 +92,7 @@ my $annotate = 0;
my $update = 0; my $update = 0;
my $convert = 0; my $convert = 0;
my $config_path = ''; my $config_path = '';
my $shorewallrc = '';
Getopt::Long::Configure ('bundling'); Getopt::Long::Configure ('bundling');
@@ -122,6 +124,7 @@ my $result = GetOptions('h' => \$help,
'update' => \$update, 'update' => \$update,
'convert' => \$convert, 'convert' => \$convert,
'config_path=s' => \$config_path, 'config_path=s' => \$config_path,
'shorewallrc=s' => \$shorewallrc,
); );
usage(1) unless $result && @ARGV < 2; usage(1) unless $result && @ARGV < 2;
@@ -144,4 +147,5 @@ compiler( script => $ARGV[0] || '',
convert => $convert, convert => $convert,
annotate => $annotate, annotate => $annotate,
config_path => $config_path, config_path => $config_path,
shorewallrc => $shorewallrc
); );

View File

@@ -33,7 +33,19 @@ else
g_program=shorewall g_program=shorewall
fi fi
. /usr/share/shorewall/lib.cli #
# This is modified by the installer when ${SHAREDIR} != /usr/share
#
. /usr/share/shorewall/shorewallrc
g_libexec="$LIBEXECDIR"
g_sharedir="$SHAREDIR"/shorewall
g_sbindir="$SBINDIR"
g_perllib="$PERLLIBDIR"
g_confdir="$CONFDIR"/shorewall
g_readrc=1
. $g_sharedir/lib.cli
CONFIG_PATH="$2" CONFIG_PATH="$2"

View File

@@ -0,0 +1,11 @@
#
# Shorewall version 4 - blacklist Macro
#
# /usr/share/shorewall/macro.blacklist
#
# This macro handles blacklisting using BLACKLIST_DISPOSITION and BLACKLIST_LOGLEVEL
#
###############################################################################
#ACTION SOURCE DEST PROTO DEST SOURCE RATE USER/
# PORT(S) PORT(S) LIMIT GROUP
$BLACKLIST_DISPOSITION:$BLACKLIST_LOGLEVEL

View File

@@ -62,12 +62,14 @@ checkkernelversion() {
# #
# Start trace if first arg is "debug" or "trace" # Start trace if first arg is "debug" or "trace"
# #
g_debug_iptables=
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
if [ "x$1" = "xtrace" ]; then if [ "x$1" = "xtrace" ]; then
set -x set -x
shift shift
elif [ "x$1" = "xdebug" ]; then elif [ "x$1" = "xdebug" ]; then
DEBUG=Yes g_debug_iptables=Yes
shift shift
fi fi
fi fi
@@ -233,8 +235,8 @@ case "$COMMAND" in
status=2 status=2
elif checkkernelversion; then elif checkkernelversion; then
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
$IP6TABLES -Z $g_tool -Z
$IP6TABLES -t mangle -Z $g_tool -t mangle -Z
date > ${VARDIR}/restarted date > ${VARDIR}/restarted
status=0 status=0
progress_message3 "$g_product Counters Reset" progress_message3 "$g_product Counters Reset"
@@ -243,7 +245,7 @@ case "$COMMAND" in
status=0 status=0
for chain in $@; do for chain in $@; do
if chain_exists $chain; then if chain_exists $chain; then
if qt $IP6TABLES -Z $chain; then if qt $g_tool-Z $chain; then
progress_message3 "Filter $chain Counters Reset" progress_message3 "Filter $chain Counters Reset"
else else
error_message "ERROR: Reset of chain $chain failed" error_message "ERROR: Reset of chain $chain failed"

View File

@@ -1,402 +0,0 @@
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
#
# (c) 1999-2011 - Tom Eastep (teastep@shorewall.net)
#
# Options are:
#
# -n Don't alter Routing
# -v and -q Standard Shorewall Verbosity control
# -t Timestamp progress messages
# -p Purge conntrack table
# -r Recover from failed start/restart
# -V <verbosity> Set verbosity level explicitly
# -R <restore> Overrides RESTOREFILE setting
#
# Commands are:
#
# start Starts the firewall
# refresh Refresh the firewall
# restart Restarts the firewall
# reload Reload the firewall
# clear Removes all firewall rules
# stop Stops the firewall
# status Displays firewall status
# version Displays the version of Shorewall that
# generated this program
#
################################################################################
# Functions imported from /usr/share/shorewall/prog.header
################################################################################
#
# Find the value 'weight' in the passed arguments then echo the next value
#
find_weight() {
while [ $# -gt 1 ]; do
[ "x$1" = xweight ] && echo $2 && return
shift
done
}
#
# Find the interfaces that have a route to the passed address - the default
# route is not used.
#
find_rt_interface() {
$IP -4 route list | while read addr rest; do
case $addr in
*/*)
in_network ${1%/*} $addr && echo $(find_device $rest)
;;
default)
;;
*)
if [ "$addr" = "$1" -o "$addr/32" = "$1" ]; then
echo $(find_device $rest)
fi
;;
esac
done
}
#
# Echo the name of the interface(s) that will be used to send to the
# passed address
#
find_interface_by_address() {
local dev
dev="$(find_rt_interface $1)"
local first
local rest
[ -z "$dev" ] && dev=$(find_default_interface)
[ -n "$dev" ] && echo $dev
}
#
# echo the list of networks routed out of a given interface
#
get_routed_networks() # $1 = interface name, $2-n = Fatal error message
{
local address
local rest
$IP -4 route show dev $1 2> /dev/null |
while read address rest; do
case "$address" in
default)
if [ $# -gt 1 ]; then
shift
fatal_error "$@"
else
echo "WARNING: default route ignored on interface $1" >&2
fi
;;
multicast|broadcast|prohibit|nat|throw|nexthop)
;;
*)
[ "$address" = "${address%/*}" ] && address="${address}/32"
echo $address
;;
esac
done
}
#
# Get the broadcast addresses associated with an interface
#
get_interface_bcasts() # $1 = interface
{
local addresses
addresses=
$IP -f inet addr show dev $1 2> /dev/null | grep 'inet.*brd' | sed 's/inet.*brd //; s/scope.*//;' | sort -u
}
#
# Delete IP address
#
del_ip_addr() # $1 = address, $2 = interface
{
[ $(find_first_interface_address_if_any $2) = $1 ] || qtnoin $IP addr del $1 dev $2
}
# Add IP Aliases
#
add_ip_aliases() # $* = List of addresses
{
local local
local addresses
local external
local interface
local inet
local cidr
local rest
local val
local arping
arping=$(mywhich arping)
address_details()
{
#
# Folks feel uneasy if they don't see all of the same
# decoration on these IP addresses that they see when their
# distro's net config tool adds them. In an attempt to reduce
# the anxiety level, we have the following code which sets
# the VLSM and BRD from an existing address in the same networks
#
# Get all of the lines that contain inet addresses with broadcast
#
$IP -f inet addr show $interface 2> /dev/null | grep 'inet.*brd' | while read inet cidr rest ; do
case $cidr in
*/*)
if in_network $external $cidr; then
echo "/${cidr#*/} brd $(broadcastaddress $cidr)"
break
fi
;;
esac
done
}
do_one()
{
val=$(address_details)
$IP addr add ${external}${val} dev $interface $label
[ -n "$arping" ] && qt $arping -U -c 2 -I $interface $external
echo "$external $interface" >> $VARDIR/nat
[ -n "$label" ] && label="with $label"
progress_message " IP Address $external added to interface $interface $label"
}
progress_message "Adding IP Addresses..."
while [ $# -gt 0 ]; do
external=$1
interface=$2
label=
if [ "$interface" != "${interface%:*}" ]; then
label="${interface#*:}"
interface="${interface%:*}"
label="label $interface:$label"
fi
shift 2
list_search $external $(find_interface_addresses $interface) || do_one
done
}
#
# Detect the gateway through a PPP or DHCP-configured interface
#
detect_dynamic_gateway() { # $1 = interface
local interface
interface=$1
local GATEWAYS
GATEWAYS=
local gateway
gateway=$(run_findgw_exit $1);
if [ -z "$gateway" ]; then
gateway=$( find_peer $($IP addr list $interface ) )
fi
if [ -z "$gateway" -a -f /var/lib/dhcpcd/dhcpcd-${1}.info ]; then
eval $(grep ^GATEWAYS= /var/lib/dhcpcd/dhcpcd-${1}.info 2> /dev/null)
[ -n "$GATEWAYS" ] && GATEWAYS=${GATEWAYS%,*} && gateway=$GATEWAYS
fi
if [ -z "$gateway" -a -f /var/lib/dhcp/dhclient-${1}.lease ]; then
gateway=$(grep 'option routers' /var/lib/dhcp/dhclient-${1}.lease | tail -n 1 | while read j1 j2 gateway; do echo $gateway ; return 0; done)
fi
[ -n "$gateway" ] && echo $gateway
}
#
# Detect the gateway through an interface
#
detect_gateway() # $1 = interface
{
local interface
interface=$1
local gateway
#
# First assume that this is some sort of dynamic interface
#
gateway=$( detect_dynamic_gateway $interface )
#
# Maybe there's a default route through this gateway already
#
[ -n "$gateway" ] || gateway=$(find_gateway $($IP -4 route list dev $interface | grep ^default))
#
# Last hope -- is there a load-balancing route through the interface?
#
[ -n "$gateway" ] || gateway=$(find_nexthop $interface)
#
# Be sure we found one
#
[ -n "$gateway" ] && echo $gateway
}
#
# Disable IPV6
#
disable_ipv6() {
local foo
foo="$($IP -f inet6 addr list 2> /dev/null)"
if [ -n "$foo" ]; then
if [ -x "$IP6TABLES" ]; then
$IP6TABLES -P FORWARD DROP
$IP6TABLES -P INPUT DROP
$IP6TABLES -P OUTPUT DROP
$IP6TABLES -F
$IP6TABLES -X
$IP6TABLES -A OUTPUT -o lo -j ACCEPT
$IP6TABLES -A INPUT -i lo -j ACCEPT
else
error_message "WARNING: DISABLE_IPV6=Yes in shorewall.conf but this system does not appear to have ip6tables"
fi
fi
}
#
# Add an additional gateway to the default route
#
add_gateway() # $1 = Delta $2 = Table Number
{
local route
local weight
local delta
local dev
route=`$IP -4 -o route ls table $2 | grep ^default | sed 's/default //; s/[\]//g'`
if [ -z "$route" ]; then
run_ip route add default scope global table $2 $1
else
delta=$1
if ! echo $route | fgrep -q ' nexthop '; then
route=`echo $route | sed 's/via/nexthop via/'`
dev=$(find_device $route)
if [ -f ${VARDIR}/${dev}_weight ]; then
weight=`cat ${VARDIR}/${dev}_weight`
route="$route weight $weight"
fi
fi
run_ip route replace default scope global table $2 $route $delta
fi
}
#
# Remove a gateway from the default route
#
delete_gateway() # $! = Description of the Gateway $2 = table number $3 = device
{
local route
local gateway
local dev
route=`$IP -4 -o route ls table $2 | grep ^default | sed 's/[\]//g'`
gateway=$1
if [ -n "$route" ]; then
if echo $route | fgrep -q ' nexthop '; then
gateway="nexthop $gateway"
eval route=\`echo $route \| sed \'s/$gateway/ /\'\`
run_ip route replace table $2 $route
else
dev=$(find_device $route)
[ "$dev" = "$3" ] && run_ip route delete default table $2
fi
fi
}
#
# Determine the MAC address of the passed IP through the passed interface
#
find_mac() # $1 = IP address, $2 = interface
{
if interface_is_usable $2 ; then
qt ping -nc 1 -t 2 -I $2 $1
local result
result=$($IP neigh list | awk "/^$1 / {print \$5}")
case $result in
\<*\>)
;;
*)
[ -n "$result" ] && echo $result
;;
esac
fi
}
#
# Clear Proxy Arp
#
delete_proxyarp() {
if [ -f ${VARDIR}/proxyarp ]; then
while read address interface external haveroute; do
qtnoin $IP -4 neigh del proxy $address dev $external
[ -z "${haveroute}${g_noroutes}" ] && qtnoin $IP -4 route del $address/32 dev $interface
f=/proc/sys/net/ipv4/conf/$interface/proxy_arp
[ -f $f ] && echo 0 > $f
done < ${VARDIR}/proxyarp
rm -f ${VARDIR}/proxyarp
fi
}
#
# Remove all Shorewall-added rules
#
clear_firewall() {
stop_firewall
setpolicy INPUT ACCEPT
setpolicy FORWARD ACCEPT
setpolicy OUTPUT ACCEPT
run_iptables -F
qt $IPTABLES -t raw -F
echo 1 > /proc/sys/net/ipv4/ip_forward
if [ -n "$DISABLE_IPV6" ]; then
if [ -x $IP6TABLES ]; then
$IP6TABLES -P INPUT ACCEPT 2> /dev/null
$IP6TABLES -P OUTPUT ACCEPT 2> /dev/null
$IP6TABLES -P FORWARD ACCEPT 2> /dev/null
fi
fi
run_clear_exit
set_state "Cleared"
logger -p kern.info "$g_product Cleared"
}
#
# Get a list of all configured broadcast addresses on the system
#
get_all_bcasts()
{
$IP -f inet addr show 2> /dev/null | grep 'inet.*brd' | grep -v '/32 ' | sed 's/inet.*brd //; s/scope.*//;' | sort -u
}
################################################################################
# End of functions in /usr/share/shorewall/prog.header
################################################################################

View File

@@ -1,311 +0,0 @@
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
#
# (c) 1999-2011- Tom Eastep (teastep@shorewall.net)
#
# Options are:
#
# -n Don't alter Routing
# -v and -q Standard Shorewall Verbosity control
# -t Timestamp progress messages
# -p Purge conntrack table
# -r Recover from failed start/restart
# -V <verbosity> Set verbosity level explicitly
# -R <restore> Overrides RESTOREFILE setting
#
# Commands are:
#
# start Starts the firewall
# refresh Refresh the firewall
# restart Restarts the firewall
# reload Reload the firewall
# clear Removes all firewall rules
# stop Stops the firewall
# status Displays firewall status
# version Displays the version of Shorewall that
# generated this program
#
################################################################################
# Functions imported from /usr/share/shorewall/prog.header6
################################################################################
#
# Get all interface addresses with VLSMs
#
find_interface_full_addresses() # $1 = interface
{
$IP -f inet6 addr show $1 2> /dev/null | grep 'inet6 ' | sed 's/\s*inet6 //;s/ scope.*//;s/ peer.*//'
}
#
# Normalize an IPv6 Address by compressing out consecutive zero elements
#
normalize_address() # $1 = valid IPv6 Address
{
local address
address=$1
local j
while true; do
case $address in
::*)
address=0$address
;;
*::*)
list_count $(split $address)
j=$?
if [ $j -eq 7 ]; then
address=${address%::*}:0:${address#*::}
elif [ $j -eq 8 ]; then
$address=${address%::*}:${address#*::}
break 2
else
address=${address%::*}:0::${address#*::}
fi
;;
*)
echo $address
break 2
;;
esac
done
}
#
# Reads correctly-formed and fully-qualified host and subnet addresses from STDIN. For each
# that defines a /120 or larger network, it sends to STDOUT:
#
# The corresponding subnet-router anycast address (all host address bits are zero)
# The corresponding anycast addresses defined by RFC 2526 (the last 128 addresses in the subnet)
#
convert_to_anycast() {
local address
local badress
local vlsm
local host
local o
local m
m=
local z
z=65535
local l
while read address; do
case $address in
2*|3*)
vlsm=${address#*/}
vlsm=${vlsm:=128}
if [ $vlsm -le 120 ]; then
#
# Defines a viable subnet -- first get the subnet-router anycast address
#
host=$((128 - $vlsm))
address=$(normalize_address ${address%/*})
while [ $host -ge 16 ]; do
address=${address%:*}
host=$(($host - 16))
done
if [ $host -gt 0 ]; then
#
# VLSM is not a multiple of 16
#
host=$((16 - $host))
o=$((0x${address##*:}))
m=0
while [ $host -gt 0 ]; do
m=$((($m >> 1) | 0x8000))
z=$(($z >> 1))
host=$(($host - 1))
done
o=$(($o & $m))
badress=${address%:*}
address=$badress:$(printf %04x $o)
z=$(($o | $z))
if [ $vlsm -gt 112 ]; then
z=$(($z & 0xff80))
fi
badress=$badress:$(printf %04x $z)
else
badress=$address
fi
#
# Note: at this point $address and $badress are the same except possibly for
# the contents of the last half-word
#
list_count $(split $address)
l=$?
#
# Now generate the anycast addresses defined by RFC 2526
#
if [ $l -lt 8 ]; then
#
# The subnet-router address
#
echo $address::
while [ $l -lt 8 ]; do
badress=$badress:ffff
l=$(($l + 1 ))
done
else
#
# The subnet-router address
#
echo $address
fi
#
# And the RFC 2526 addresses
#
echo $badress/121
fi
;;
esac
done
}
#
# Generate a list of anycast addresses for a given interface
#
get_interface_acasts() # $1 = interface
{
local addresses
addresses=
find_interface_full_addresses $1 | convert_to_anycast | sort -u
}
#
# Get a list of all configured anycast addresses on the system
#
get_all_acasts()
{
find_interface_full_addresses | convert_to_anycast | sort -u
}
#
# Detect the gateway through an interface
#
detect_gateway() # $1 = interface
{
local interface
interface=$1
#
# First assume that this is some sort of point-to-point interface
#
gateway=$( find_peer $($IP -6 addr list $interface ) )
#
# Maybe there's a default route through this gateway already
#
[ -n "$gateway" ] || gateway=$(find_gateway $($IP -6 route list dev $interface | grep '^default'))
#
# Last hope -- is there a load-balancing route through the interface?
#
[ -n "$gateway" ] || gateway=$(find_nexthop $interface)
#
# Be sure we found one
#
[ -n "$gateway" ] && echo $gateway
}
#
# Add an additional gateway to the default route
#
add_gateway() # $1 = Delta $2 = Table Number
{
local route
local weight
local delta
local dev
run_ip route add default scope global table $2 $1
}
#
# Remove a gateway from the default route
#
delete_gateway() # $! = Description of the Gateway $2 = table number $3 = device
{
local route
local gateway
local dev
route=`$IP -6 -o route ls table $2 | grep ^default | sed 's/[\]//g'`
gateway=$1
dev=$(find_device $route)
[ "$dev" = "$3" ] && run_ip route delete default table $2
}
#
# Determine how to do "echo -e"
#
find_echo() {
local result
result=$(echo "a\tb")
[ ${#result} -eq 3 ] && { echo echo; return; }
result=$(echo -e "a\tb")
[ ${#result} -eq 3 ] && { echo "echo -e"; return; }
result=$(which echo)
[ -n "$result" ] && { echo "$result -e"; return; }
echo echo
}
#
# Clear Proxy NDP
#
delete_proxyndp() {
if [ -f ${VARDIR}/proxyndp ]; then
while read address interface external haveroute; do
qt $IP -6 neigh del proxy $address dev $external
[ -z "${haveroute}${g_noroutes}" ] && qt $IP -6 route del $address/128 dev $interface
f=/proc/sys/net/ipv6/conf/$interface/proxy_ndp
[ -f $f ] && echo 0 > $f
done < ${VARDIR}/proxyndp
rm -f ${VARDIR}/proxyndp
fi
}
#
# Remove all Shorewall-added rules
#
clear_firewall() {
stop_firewall
setpolicy INPUT ACCEPT
setpolicy FORWARD ACCEPT
setpolicy OUTPUT ACCEPT
run_iptables -F
qt $IP6TABLES -t raw -F
echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
run_clear_exit
set_state "Cleared"
logger -p kern.info "$g_product Cleared"
}
################################################################################
# End of functions imported from /usr/share/shorewall/prog.header6
################################################################################

View File

@@ -53,7 +53,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH=/etc/shorewall:/usr/share/shorewall CONFIG_PATH=${CONFDIR}/shorewall:${SHAREDIR}/shorewall
IPTABLES= IPTABLES=
@@ -138,6 +138,8 @@ FORWARD_CLEAR_MARK=
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=On IP_FORWARDING=On
KEEP_RT_TABLES=No KEEP_RT_TABLES=No

View File

@@ -64,7 +64,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH=/etc/shorewall:/usr/share/shorewall CONFIG_PATH=${CONFDIR}/shorewall:${SHAREDIR}/shorewall
IPTABLES= IPTABLES=
@@ -149,6 +149,8 @@ FORWARD_CLEAR_MARK=
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=Off IP_FORWARDING=Off
KEEP_RT_TABLES=No KEEP_RT_TABLES=No

View File

@@ -62,7 +62,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH=/etc/shorewall:/usr/share/shorewall CONFIG_PATH=${CONFDIR}/shorewall:${SHAREDIR}/shorewall
IPTABLES= IPTABLES=
@@ -147,6 +147,8 @@ FORWARD_CLEAR_MARK=
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=On IP_FORWARDING=On
KEEP_RT_TABLES=No KEEP_RT_TABLES=No

View File

@@ -65,7 +65,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH=/etc/shorewall:/usr/share/shorewall CONFIG_PATH=${CONFDIR}/shorewall:${SHAREDIR}/shorewall
IPTABLES= IPTABLES=
@@ -150,6 +150,8 @@ FORWARD_CLEAR_MARK=
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=On IP_FORWARDING=On
KEEP_RT_TABLES=No KEEP_RT_TABLES=No

View File

@@ -49,7 +49,7 @@ my $target = require_audit ( $action , $audit );
log_rule_limit $level, $chainref, 'Invalid' , $action, '', $tag, 'add', "$globals{STATEMATCH} INVALID " if $level ne ''; log_rule_limit $level, $chainref, 'Invalid' , $action, '', $tag, 'add', "$globals{STATEMATCH} INVALID " if $level ne '';
add_jump $chainref , $target, 0, "$globals{STATEMATCH} INVALID "; add_jump $chainref , $target, 0, "$globals{STATEMATCH} INVALID ";
$chainref->{dont_optimize} = 0; allow_optimize( $chainref );
1; 1;

View File

@@ -49,7 +49,7 @@ my $target = require_audit ( $action , $audit );
log_rule_limit $level, $chainref, 'NotSyn' , $action, '', $tag, 'add', '-p 6 ! --syn ' if $level ne ''; log_rule_limit $level, $chainref, 'NotSyn' , $action, '', $tag, 'add', '-p 6 ! --syn ' if $level ne '';
add_jump $chainref , $target, 0, '-p 6 ! --syn '; add_jump $chainref , $target, 0, '-p 6 ! --syn ';
$chainref->{dont_optimize} = 0; allow_optimize( $chainref );
1; 1;

View File

@@ -7,4 +7,8 @@
# http://www.shorewall.net/manpages/shorewall-interfaces.html # http://www.shorewall.net/manpages/shorewall-interfaces.html
# #
############################################################################### ###############################################################################
FORMAT 1
#ZONE INTERFACE BROADCAST OPTIONS #ZONE INTERFACE BROADCAST OPTIONS
FORMAT 2
#ZONE INTERFACE OPTIONS

View File

@@ -6,6 +6,6 @@
# The manpage is also online at # The manpage is also online at
# http://www.shorewall.net/manpages/shorewall-masq.html # http://www.shorewall.net/manpages/shorewall-masq.html
# #
############################################################################################# ######################################################################################################
#INTERFACE:DEST SOURCE ADDRESS PROTO PORT(S) IPSEC MARK USER/ #INTERFACE:DEST SOURCE ADDRESS PROTO PORT(S) IPSEC MARK USER/ SWITCH
# GROUP # GROUP

View File

@@ -53,7 +53,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH="/etc/shorewall:/usr/share/shorewall" CONFIG_PATH="${CONFDIR}/shorewall:${SHAREDIR}/shorewall"
IPTABLES= IPTABLES=
@@ -138,6 +138,8 @@ FORWARD_CLEAR_MARK=
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=On IP_FORWARDING=On
KEEP_RT_TABLES=No KEEP_RT_TABLES=No

View File

@@ -9,7 +9,7 @@
# #
# See http://shorewall.net/PacketMarking.html for a detailed description of # See http://shorewall.net/PacketMarking.html for a detailed description of
# the Netfilter/Shorewall packet marking mechanism. # the Netfilter/Shorewall packet marking mechanism.
###################################################################################################################################### ##########################################################################################################################################
#MARK SOURCE DEST PROTO DEST SOURCE USER TEST LENGTH TOS CONNBYTES HELPER PROBABILITY #ACTION SOURCE DEST PROTO DEST SOURCE USER TEST LENGTH TOS CONNBYTES HELPER PROBABILITY DSCP
# PORT(S) PORT(S) # PORT(S) PORT(S)

View File

@@ -4,5 +4,5 @@
# For information about entries in this file, type "man shorewall-tos" # For information about entries in this file, type "man shorewall-tos"
# #
############################################################################### ###############################################################################
#SOURCE DEST PROTOCOL SOURCE DEST TOS MARK #SOURCE DEST PROTOCOL DEST SOURCE TOS MARK
# PORTS PORTS # PORTS PORTS

View File

@@ -10,4 +10,4 @@
# /usr/share/shorewall/configfiles/. This prevents 'compile -e' # /usr/share/shorewall/configfiles/. This prevents 'compile -e'
# from trying to use configuration information from /etc/shorewall. # from trying to use configuration information from /etc/shorewall.
CONFIG_PATH=${CONFDIR}:/usr/share/shorewall CONFIG_PATH=${CONFDIR}:${SHAREDIR}/shorewall

View File

@@ -11,7 +11,6 @@
### END INIT INFO ### END INIT INFO
SRWL=/sbin/shorewall SRWL=/sbin/shorewall
SRWL_OPTS="-tvv" SRWL_OPTS="-tvv"
WAIT_FOR_IFUP=/usr/share/shorewall/wait4ifup WAIT_FOR_IFUP=/usr/share/shorewall/wait4ifup
@@ -54,10 +53,15 @@ not_configured () {
exit 0 exit 0
} }
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
# check if shorewall is configured or not # check if shorewall is configured or not
if [ -f "/etc/default/shorewall" ] if [ -f "${SYSCONFDIR}/shorewall" ]
then then
. /etc/default/shorewall . ${SYSCONFDIR}/shorewall
SRWL_OPTS="$SRWL_OPTS $OPTIONS" SRWL_OPTS="$SRWL_OPTS $OPTIONS"
if [ "$startup" != "1" ] if [ "$startup" != "1" ]
then then

View File

@@ -20,16 +20,21 @@
# Source function library. # Source function library.
. /etc/rc.d/init.d/functions . /etc/rc.d/init.d/functions
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
prog="shorewall" prog="shorewall"
shorewall="/sbin/$prog" shorewall="${SBINDIR}/$prog"
logger="logger -i -t $prog" logger="logger -i -t $prog"
lockfile="/var/lock/subsys/$prog" lockfile="/var/lock/subsys/$prog"
# Get startup options (override default) # Get startup options (override default)
OPTIONS= OPTIONS=
if [ -f /etc/sysconfig/$prog ]; then if [ -f ${SYSCONFDIR}/$prog ]; then
. /etc/sysconfig/$prog . ${SYSCONFDIR}/$prog
fi fi
start() { start() {

View File

@@ -54,7 +54,7 @@ RCDLINKS="2,S41 3,S41 6,K41"
# Give Usage Information # # Give Usage Information #
################################################################################ ################################################################################
usage() { usage() {
echo "Usage: $0 start|stop|reload|restart|status" echo "Usage: $0 start|stop|reload|restart|status" >&2
exit 1 exit 1
} }
@@ -62,10 +62,14 @@ usage() {
# Get startup options (override default) # Get startup options (override default)
################################################################################ ################################################################################
OPTIONS="-v0" OPTIONS="-v0"
if [ -f /etc/sysconfig/shorewall ]; then
. /etc/sysconfig/shorewall #
elif [ -f /etc/default/shorewall ] ; then # The installer may alter this
. /etc/default/shorewall #
. /usr/share/shorewall/shorewallrc
if [ -f ${SYSCONFDIR}/shorewall ]; then
. ${SYSCONFDIR}/shorewall
fi fi
export SHOREWALL_INIT_SCRIPT=1 export SHOREWALL_INIT_SCRIPT=1
@@ -78,13 +82,13 @@ shift
case "$command" in case "$command" in
start) start)
exec /sbin/shorewall $OPTIONS start $STARTOPTIONS $@ exec $SBINDIR/shorewall $OPTIONS start $STARTOPTIONS
;; ;;
restart|reload) restart|reload)
exec /sbin/shorewall $OPTIONS restart $RESTARTOPTIONS $@ exec $SBINDIR/shorewall $OPTIONS restart $RESTARTOPTIONS
;; ;;
status|stop) status|stop)
exec /sbin/shorewall $OPTIONS $command $@ exec $SBINDIR/shorewall $OPTIONS $command
;; ;;
*) *)
usage usage

File diff suppressed because it is too large Load Diff

View File

@@ -34,6 +34,8 @@ get_config() {
ensure_config_path ensure_config_path
if [ "$1" = Yes ]; then if [ "$1" = Yes ]; then
params=$(find_file params) params=$(find_file params)
@@ -239,7 +241,7 @@ get_config() {
LOG_VERBOSITY=-1 LOG_VERBOSITY=-1
fi fi
if [ -n "$SHOREWALL_SHELL" ]; then if [ -n "$SHOREWALL_SHELL" -a -z "$g_export" ]; then
if [ ! -x "$SHOREWALL_SHELL" ]; then if [ ! -x "$SHOREWALL_SHELL" ]; then
echo " WARNING: The program specified in SHOREWALL_SHELL does not exist or is not executable; falling back to /bin/sh" >&2 echo " WARNING: The program specified in SHOREWALL_SHELL does not exist or is not executable; falling back to /bin/sh" >&2
SHOREWALL_SHELL=/bin/sh SHOREWALL_SHELL=/bin/sh
@@ -360,6 +362,8 @@ uptodate() {
# #
compiler() { compiler() {
local pc local pc
local shorewallrc
pc=$g_libexec/shorewall/compiler.pl pc=$g_libexec/shorewall/compiler.pl
if [ $(id -u) -ne 0 ]; then if [ $(id -u) -ne 0 ]; then
@@ -374,7 +378,7 @@ compiler() {
# #
# Get the config from $g_shorewalldir # Get the config from $g_shorewalldir
# #
[ -n "$g_shorewalldir" -a "$g_shorewalldir" != /etc/$g_program ] && get_config [ -n "$g_shorewalldir" -a "$g_shorewalldir" != ${g_confdir} ] && get_config
case $COMMAND in case $COMMAND in
*start|try|refresh) *start|try|refresh)
@@ -395,7 +399,14 @@ compiler() {
[ "$1" = nolock ] && shift; [ "$1" = nolock ] && shift;
shift shift
options="--verbose=$VERBOSITY --family=$g_family --config_path=$CONFIG_PATH" if [ -n "$g_export" ]; then
shorewallrc=$(find_file shorewallrc)
[ -f "$shorewallrc" ] || fatal_error "Compiling for export requires a shorewallrc file"
else
shorewallrc="${g_basedir}/shorewallrc"
fi
options="--verbose=$VERBOSITY --family=$g_family --config_path=$CONFIG_PATH --shorewallrc=${shorewallrc}"
[ -n "$STARTUP_LOG" ] && options="$options --log=$STARTUP_LOG" [ -n "$STARTUP_LOG" ] && options="$options --log=$STARTUP_LOG"
[ -n "$LOG_VERBOSITY" ] && options="$options --log_verbosity=$LOG_VERBOSITY"; [ -n "$LOG_VERBOSITY" ] && options="$options --log_verbosity=$LOG_VERBOSITY";
[ -n "$g_export" ] && options="$options --export" [ -n "$g_export" ] && options="$options --export"
@@ -1297,6 +1308,10 @@ reload_command() # $* = original arguments less the command.
root=root root=root
local libexec local libexec
libexec=/usr/share libexec=/usr/share
local confdir
confdir=/etc
local sbindir
sbindir=/sbin
litedir=/var/lib/${g_program}-lite litedir=/var/lib/${g_program}-lite
@@ -1353,11 +1368,11 @@ reload_command() # $* = original arguments less the command.
;; ;;
esac esac
temp=$(rsh_command /sbin/${g_program}-lite show config 2> /dev/null | grep ^LITEDIR | sed 's/LITEDIR is //') temp=$(rsh_command ${g_program}-lite show config 2> /dev/null | grep ^LITEDIR | sed 's/LITEDIR is //')
[ -n "$temp" ] && litedir="$temp" [ -n "$temp" ] && litedir="$temp"
temp=$(rsh_command /sbin/${g_program}-lite show config 2> /dev/null | grep ^LIBEXEC | sed 's/LIBEXEC is //') temp=$(rsh_command ${g_program}-lite show config 2> /dev/null | grep ^LIBEXEC | sed 's/LIBEXEC is //')
if [ -n "$temp" ]; then if [ -n "$temp" ]; then
case $temp in case $temp in
@@ -1370,6 +1385,14 @@ reload_command() # $* = original arguments less the command.
esac esac
fi fi
temp=$(rsh_command ${g_program}-lite show config 2> /dev/null | grep ^SBINDIR | sed 's/SBINDIR is //')
[ -n "$temp" ] && sbindir="$temp"
temp=$(rsh_command ${g_program}-lite show config 2> /dev/null | grep ^CONFDIR | sed 's/CONFDIR is //')
[ -n "$temp" ] && confdir="$temp"
if [ -z "$getcaps" ]; then if [ -z "$getcaps" ]; then
g_shorewalldir=$(resolve_file $directory) g_shorewalldir=$(resolve_file $directory)
ensure_config_path ensure_config_path
@@ -1410,19 +1433,20 @@ reload_command() # $* = original arguments less the command.
then then
save=$(find_file save); save=$(find_file save);
[ -f $save ] && progress_message3 "Copying $save to ${system}:/etc/${g_program}-lite/" && rcp_command $save /etc/shorewall-lite/ [ -f $save ] && progress_message3 "Copying $save to ${system}:${confdir}/${g_program}-lite/" && rcp_command $save ${confdir}/shorewall-lite/
progress_message3 "Copy complete" progress_message3 "Copy complete"
if [ $COMMAND = reload ]; then if [ $COMMAND = reload ]; then
rsh_command "/sbin/${g_program}-lite $g_debugging $verbose $timestamp restart" && \ rsh_command "${sbindir}/${g_program}-lite $g_debugging $verbose $timestamp restart" && \
progress_message3 "System $system reloaded" || saveit= progress_message3 "System $system reloaded" || saveit=
else else
rsh_command "/sbin/${g_program}-lite $g_debugging $verbose $timestamp start" && \ rsh_command "${sbindir}/${g_program}-lite $g_debugging $verbose $timestamp start" && \
progress_message3 "System $system loaded" || saveit= progress_message3 "System $system loaded" || saveit=
fi fi
if [ -n "$saveit" ]; then if [ -n "$saveit" ]; then
rsh_command "/sbin/${g_program}-lite $g_debugging $verbose $timestamp save" && \ rsh_command "${sbindir}/${g_program}-lite $g_debugging $verbose $timestamp save" && \
progress_message3 "Configuration on system $system saved" progress_message3 "Configuration on system $system saved"
fi fi
fi fi

View File

@@ -1,30 +1,34 @@
#
# Shorewall 4.5 -- /usr/share/shorewall/lib.core.
#
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt] # This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
# #
# (c) 2010-2012 - Tom Eastep (teastep@shorewall.net) # (c) 1999-2012 - Tom Eastep (teastep@shorewall.net)
# #
# Complete documentation is available at http://shorewall.net # Options are:
# #
# This program is free software; you can redistribute it and/or modify # -n Don't alter Routing
# it under the terms of Version 2 of the GNU General Public License # -v and -q Standard Shorewall Verbosity control
# as published by the Free Software Foundation. # -t Timestamp progress messages
# -p Purge conntrack table
# -r Recover from failed start/restart
# -V <verbosity> Set verbosity level explicitly
# -R <restore> Overrides RESTOREFILE setting
# #
# This program is distributed in the hope that it will be useful, # Commands are:
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # start Starts the firewall
# along with this program; if not, write to the Free Software # refresh Refresh the firewall
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # restart Restarts the firewall
# reload Reload the firewall
# clear Removes all firewall rules
# stop Stops the firewall
# status Displays firewall status
# version Displays the version of Shorewall that
# generated this program
# #
# The purpose of this library is to hold those functions used by the generated ################################################################################
# scripts (both IPv4 and IPv6 -- the functions that are specific to one or the other # Functions imported from /usr/share/shorewall/lib.core
# are found in prog.header and prog.header6). ################################################################################
# # Address family-neutral Functions
######################################################################################### ################################################################################
# #
# Conditionally produce message # Conditionally produce message
# #
@@ -510,6 +514,20 @@ debug_restore_input() {
qt1 $g_tool -t raw -P $chain ACCEPT qt1 $g_tool -t raw -P $chain ACCEPT
done done
qt1 $g_tool -t rawpost -F
qt1 $g_tool -t rawpost -X
for chain in POSTROUTING; do
qt1 $g_tool -t rawpost -P $chain ACCEPT
done
qt1 $g_tool -t nat -F
qt1 $g_tool -t nat -X
for chain in PREROUTING POSTROUTING; do
qt1 $g_tool -t nat -P $chain ACCEPT
done
qt1 $g_tool -t filter -F qt1 $g_tool -t filter -F
qt1 $g_tool -t filter -X qt1 $g_tool -t filter -X
@@ -616,3 +634,642 @@ EOF
done done
fi fi
} }
?IF __IPV4
#################################################################################
# IPv4-specific Functions
#################################################################################
# Find the value 'weight' in the passed arguments then echo the next value
#
find_weight() {
while [ $# -gt 1 ]; do
[ "x$1" = xweight ] && echo $2 && return
shift
done
}
#
# Find the interfaces that have a route to the passed address - the default
# route is not used.
#
find_rt_interface() {
$IP -4 route list | while read addr rest; do
case $addr in
*/*)
in_network ${1%/*} $addr && echo $(find_device $rest)
;;
default)
;;
*)
if [ "$addr" = "$1" -o "$addr/32" = "$1" ]; then
echo $(find_device $rest)
fi
;;
esac
done
}
#
# Echo the name of the interface(s) that will be used to send to the
# passed address
#
find_interface_by_address() {
local dev
dev="$(find_rt_interface $1)"
local first
local rest
[ -z "$dev" ] && dev=$(find_default_interface)
[ -n "$dev" ] && echo $dev
}
#
# echo the list of networks routed out of a given interface
#
get_routed_networks() # $1 = interface name, $2-n = Fatal error message
{
local address
local rest
$IP -4 route show dev $1 2> /dev/null |
while read address rest; do
case "$address" in
default)
if [ $# -gt 1 ]; then
shift
fatal_error "$@"
else
echo "WARNING: default route ignored on interface $1" >&2
fi
;;
multicast|broadcast|prohibit|nat|throw|nexthop)
;;
*)
[ "$address" = "${address%/*}" ] && address="${address}/32"
echo $address
;;
esac
done
}
#
# Get the broadcast addresses associated with an interface
#
get_interface_bcasts() # $1 = interface
{
local addresses
addresses=
$IP -f inet addr show dev $1 2> /dev/null | grep 'inet.*brd' | sed 's/inet.*brd //; s/scope.*//;' | sort -u
}
#
# Delete IP address
#
del_ip_addr() # $1 = address, $2 = interface
{
[ $(find_first_interface_address_if_any $2) = $1 ] || qtnoin $IP addr del $1 dev $2
}
# Add IP Aliases
#
add_ip_aliases() # $* = List of addresses
{
local local
local addresses
local external
local interface
local inet
local cidr
local rest
local val
local arping
arping=$(mywhich arping)
address_details()
{
#
# Folks feel uneasy if they don't see all of the same
# decoration on these IP addresses that they see when their
# distro's net config tool adds them. In an attempt to reduce
# the anxiety level, we have the following code which sets
# the VLSM and BRD from an existing address in the same network
#
# Get all of the lines that contain inet addresses with broadcast
#
$IP -f inet addr show $interface 2> /dev/null | grep 'inet.*brd' | while read inet cidr rest ; do
case $cidr in
*/*)
if in_network $external $cidr; then
echo "/${cidr#*/} brd $(broadcastaddress $cidr)"
break
fi
;;
esac
done
}
do_one()
{
val=$(address_details)
$IP addr add ${external}${val} dev $interface $label
[ -n "$arping" ] && qt $arping -U -c 2 -I $interface $external
echo "$external $interface" >> $VARDIR/nat
[ -n "$label" ] && label="with $label"
progress_message " IP Address $external added to interface $interface $label"
}
progress_message "Adding IP Addresses..."
while [ $# -gt 0 ]; do
external=$1
interface=$2
label=
if [ "$interface" != "${interface%:*}" ]; then
label="${interface#*:}"
interface="${interface%:*}"
label="label $interface:$label"
fi
shift 2
list_search $external $(find_interface_addresses $interface) || do_one
done
}
#
# Detect the gateway through a PPP or DHCP-configured interface
#
detect_dynamic_gateway() { # $1 = interface
local interface
interface=$1
local GATEWAYS
GATEWAYS=
local gateway
gateway=$(run_findgw_exit $1);
if [ -z "$gateway" ]; then
gateway=$( find_peer $($IP addr list $interface ) )
fi
if [ -z "$gateway" -a -f /var/lib/dhcpcd/dhcpcd-${1}.info ]; then
eval $(grep ^GATEWAYS= /var/lib/dhcpcd/dhcpcd-${1}.info 2> /dev/null)
[ -n "$GATEWAYS" ] && GATEWAYS=${GATEWAYS%,*} && gateway=$GATEWAYS
fi
if [ -z "$gateway" -a -f /var/lib/dhcp/dhclient-${1}.lease ]; then
gateway=$(grep 'option routers' /var/lib/dhcp/dhclient-${1}.lease | tail -n 1 | while read j1 j2 gateway; do echo $gateway ; return 0; done)
fi
[ -n "$gateway" ] && echo $gateway
}
#
# Detect the gateway through an interface
#
detect_gateway() # $1 = interface
{
local interface
interface=$1
local gateway
#
# First assume that this is some sort of dynamic interface
#
gateway=$( detect_dynamic_gateway $interface )
#
# Maybe there's a default route through this gateway already
#
[ -n "$gateway" ] || gateway=$(find_gateway $($IP -4 route list dev $interface | grep ^default))
#
# Last hope -- is there a load-balancing route through the interface?
#
[ -n "$gateway" ] || gateway=$(find_nexthop $interface)
#
# Be sure we found one
#
[ -n "$gateway" ] && echo $gateway
}
#
# Disable IPV6
#
disable_ipv6() {
local foo
foo="$($IP -f inet6 addr list 2> /dev/null)"
if [ -n "$foo" ]; then
if [ -x "$IP6TABLES" ]; then
$IP6TABLES -P FORWARD DROP
$IP6TABLES -P INPUT DROP
$IP6TABLES -P OUTPUT DROP
$IP6TABLES -F
$IP6TABLES -X
$IP6TABLES -A OUTPUT -o lo -j ACCEPT
$IP6TABLES -A INPUT -i lo -j ACCEPT
else
error_message "WARNING: DISABLE_IPV6=Yes in shorewall.conf but this system does not appear to have ip6tables"
fi
fi
}
#
# Add an additional gateway to the default route
#
add_gateway() # $1 = Delta $2 = Table Number
{
local route
local weight
local delta
local dev
route=`$IP -4 -o route ls table $2 | grep ^default | sed 's/default //; s/[\]//g'`
if [ -z "$route" ]; then
run_ip route add default scope global table $2 $1
else
delta=$1
if ! echo $route | fgrep -q ' nexthop '; then
route=`echo $route | sed 's/via/nexthop via/'`
dev=$(find_device $route)
if [ -f ${VARDIR}/${dev}_weight ]; then
weight=`cat ${VARDIR}/${dev}_weight`
route="$route weight $weight"
fi
fi
run_ip route replace default scope global table $2 $route $delta
fi
}
#
# Remove a gateway from the default route
#
delete_gateway() # $! = Description of the Gateway $2 = table number $3 = device
{
local route
local gateway
local dev
route=`$IP -4 -o route ls table $2 | grep ^default | sed 's/[\]//g'`
gateway=$1
if [ -n "$route" ]; then
if echo $route | fgrep -q ' nexthop '; then
gateway="nexthop $gateway"
eval route=\`echo $route \| sed \'s/$gateway/ /\'\`
run_ip route replace table $2 $route
else
dev=$(find_device $route)
[ "$dev" = "$3" ] && run_ip route delete default table $2
fi
fi
}
#
# Determine the MAC address of the passed IP through the passed interface
#
find_mac() # $1 = IP address, $2 = interface
{
if interface_is_usable $2 ; then
qt ping -nc 1 -t 2 -I $2 $1
local result
result=$($IP neigh list | awk "/^$1 / {print \$5}")
case $result in
\<*\>)
;;
*)
[ -n "$result" ] && echo $result
;;
esac
fi
}
#
# Clear Proxy Arp
#
delete_proxyarp() {
if [ -f ${VARDIR}/proxyarp ]; then
while read address interface external haveroute; do
qtnoin $IP -4 neigh del proxy $address dev $external
[ -z "${haveroute}${g_noroutes}" ] && qtnoin $IP -4 route del $address/32 dev $interface
f=/proc/sys/net/ipv4/conf/$interface/proxy_arp
[ -f $f ] && echo 0 > $f
done < ${VARDIR}/proxyarp
rm -f ${VARDIR}/proxyarp
fi
}
#
# Remove all Shorewall-added rules
#
clear_firewall() {
stop_firewall
setpolicy INPUT ACCEPT
setpolicy FORWARD ACCEPT
setpolicy OUTPUT ACCEPT
run_iptables -F
qt $IPTABLES -t raw -F
echo 1 > /proc/sys/net/ipv4/ip_forward
if [ -n "$DISABLE_IPV6" ]; then
if [ -x $IP6TABLES ]; then
$IP6TABLES -P INPUT ACCEPT 2> /dev/null
$IP6TABLES -P OUTPUT ACCEPT 2> /dev/null
$IP6TABLES -P FORWARD ACCEPT 2> /dev/null
fi
fi
run_clear_exit
set_state "Cleared"
logger -p kern.info "$g_product Cleared"
}
#
# Get a list of all configured broadcast addresses on the system
#
get_all_bcasts()
{
$IP -f inet addr show 2> /dev/null | grep 'inet.*brd' | grep -v '/32 ' | sed 's/inet.*brd //; s/scope.*//;' | sort -u
}
?ELSE
#################################################################################
# IPv6-specific Functions
#################################################################################
#
# Get all interface addresses with VLSMs
#
find_interface_full_addresses() # $1 = interface
{
$IP -f inet6 addr show $1 2> /dev/null | grep 'inet6 ' | sed 's/\s*inet6 //;s/ scope.*//;s/ peer.*//'
}
#
# Normalize an IPv6 Address by compressing out consecutive zero elements
#
normalize_address() # $1 = valid IPv6 Address
{
local address
address=$1
local j
while true; do
case $address in
::*)
address=0$address
;;
*::*)
list_count $(split $address)
j=$?
if [ $j -eq 7 ]; then
address=${address%::*}:0:${address#*::}
elif [ $j -eq 8 ]; then
$address=${address%::*}:${address#*::}
break 2
else
address=${address%::*}:0::${address#*::}
fi
;;
*)
echo $address
break 2
;;
esac
done
}
#
# Reads correctly-formed and fully-qualified host and subnet addresses from STDIN. For each
# that defines a /120 or larger network, it sends to STDOUT:
#
# The corresponding subnet-router anycast address (all host address bits are zero)
# The corresponding anycast addresses defined by RFC 2526 (the last 128 addresses in the subnet)
#
convert_to_anycast() {
local address
local badress
local vlsm
local host
local o
local m
m=
local z
z=65535
local l
while read address; do
case $address in
2*|3*)
vlsm=${address#*/}
vlsm=${vlsm:=128}
if [ $vlsm -le 120 ]; then
#
# Defines a viable subnet -- first get the subnet-router anycast address
#
host=$((128 - $vlsm))
address=$(normalize_address ${address%/*})
while [ $host -ge 16 ]; do
address=${address%:*}
host=$(($host - 16))
done
if [ $host -gt 0 ]; then
#
# VLSM is not a multiple of 16
#
host=$((16 - $host))
o=$((0x${address##*:}))
m=0
while [ $host -gt 0 ]; do
m=$((($m >> 1) | 0x8000))
z=$(($z >> 1))
host=$(($host - 1))
done
o=$(($o & $m))
badress=${address%:*}
address=$badress:$(printf %04x $o)
z=$(($o | $z))
if [ $vlsm -gt 112 ]; then
z=$(($z & 0xff80))
fi
badress=$badress:$(printf %04x $z)
else
badress=$address
fi
#
# Note: at this point $address and $badress are the same except possibly for
# the contents of the last half-word
#
list_count $(split $address)
l=$?
#
# Now generate the anycast addresses defined by RFC 2526
#
if [ $l -lt 8 ]; then
#
# The subnet-router address
#
echo $address::
while [ $l -lt 8 ]; do
badress=$badress:ffff
l=$(($l + 1 ))
done
else
#
# The subnet-router address
#
echo $address
fi
#
# And the RFC 2526 addresses
#
echo $badress/121
fi
;;
esac
done
}
#
# Generate a list of anycast addresses for a given interface
#
get_interface_acasts() # $1 = interface
{
local addresses
addresses=
find_interface_full_addresses $1 | convert_to_anycast | sort -u
}
#
# Get a list of all configured anycast addresses on the system
#
get_all_acasts()
{
find_interface_full_addresses | convert_to_anycast | sort -u
}
#
# Detect the gateway through an interface
#
detect_gateway() # $1 = interface
{
local interface
interface=$1
#
# First assume that this is some sort of point-to-point interface
#
gateway=$( find_peer $($IP -6 addr list $interface ) )
#
# Maybe there's a default route through this gateway already
#
[ -n "$gateway" ] || gateway=$(find_gateway $($IP -6 route list dev $interface | grep '^default'))
#
# Last hope -- is there a load-balancing route through the interface?
#
[ -n "$gateway" ] || gateway=$(find_nexthop $interface)
#
# Be sure we found one
#
[ -n "$gateway" ] && echo $gateway
}
#
# Add an additional gateway to the default route
#
add_gateway() # $1 = Delta $2 = Table Number
{
local route
local weight
local delta
local dev
run_ip route add default scope global table $2 $1
}
#
# Remove a gateway from the default route
#
delete_gateway() # $! = Description of the Gateway $2 = table number $3 = device
{
local route
local gateway
local dev
route=`$IP -6 -o route ls table $2 | grep ^default | sed 's/[\]//g'`
gateway=$1
dev=$(find_device $route)
[ "$dev" = "$3" ] && run_ip route delete default table $2
}
#
# Clear Proxy NDP
#
delete_proxyndp() {
if [ -f ${VARDIR}/proxyndp ]; then
while read address interface external haveroute; do
qt $IP -6 neigh del proxy $address dev $external
[ -z "${haveroute}${g_noroutes}" ] && qt $IP -6 route del $address/128 dev $interface
f=/proc/sys/net/ipv6/conf/$interface/proxy_ndp
[ -f $f ] && echo 0 > $f
done < ${VARDIR}/proxyndp
rm -f ${VARDIR}/proxyndp
fi
}
#
# Remove all Shorewall-added rules
#
clear_firewall() {
stop_firewall
setpolicy INPUT ACCEPT
setpolicy FORWARD ACCEPT
setpolicy OUTPUT ACCEPT
run_iptables -F
qt $IP6TABLES -t raw -F
echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
run_clear_exit
set_state "Cleared"
logger -p kern.info "$g_product Cleared"
}
?ENDIF

View File

@@ -57,6 +57,17 @@
of them may be omitted). The first non-commentary record in the accounting of them may be omitted). The first non-commentary record in the accounting
file must be a section header when sectioning is used.</para> file must be a section header when sectioning is used.</para>
<warning>
<para>If sections are not used, the Shorewall rules compiler cannot
detect certain violations of netfilter restrictions. These violations
can result in run-time errors such as the following:</para>
<blockquote>
<para><emphasis role="bold">iptables-restore v1.4.13: Can't use -o
with INPUT</emphasis></para>
</blockquote>
</warning>
<para>Beginning with Shorewall 4.4.20, the ACCOUNTING_TABLE setting was <para>Beginning with Shorewall 4.4.20, the ACCOUNTING_TABLE setting was
added to shorewall.conf and shorewall6.conf. That setting determines the added to shorewall.conf and shorewall6.conf. That setting determines the
Netfilter table (filter or mangle) where the accounting rules are added. Netfilter table (filter or mangle) where the accounting rules are added.
@@ -75,12 +86,9 @@
<itemizedlist> <itemizedlist>
<listitem> <listitem>
<para>A jump to a user-defined accounting chain before entries that <para>A jump to a user-defined accounting chain must appear before
add rules to that chain.</para> entries that add rules to that chain. This eliminates loops and
</listitem> unreferenced chains.</para>
<listitem>
<para>This eliminates loops and unreferenced chains.</para>
</listitem> </listitem>
<listitem> <listitem>

View File

@@ -118,32 +118,6 @@
must have no embedded white space.</para> must have no embedded white space.</para>
<variablelist> <variablelist>
<varlistentry>
<term><emphasis role="bold">maclist</emphasis></term>
<listitem>
<para>Connection requests from these hosts are compared
against the contents of <ulink
url="shorewall-maclist.html">shorewall-maclist</ulink>(5). If
this option is specified, the interface must be an ethernet
NIC or equivalent and must be up before Shorewall is
started.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">routeback</emphasis></term>
<listitem>
<para>Shorewall should set up the infrastructure to pass
packets from this/these address(es) back to themselves. This
is necessary if hosts in this group use the services of a
transparent proxy that is a member of the group or if DNAT is
used to send requests originating from this group to a server
in the group.</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><emphasis role="bold">blacklist</emphasis></term> <term><emphasis role="bold">blacklist</emphasis></term>
@@ -154,48 +128,6 @@
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><emphasis role="bold">tcpflags</emphasis></term>
<listitem>
<para>Packets arriving from these hosts are checked for
certain illegal combinations of TCP flags. Packets found to
have such a combination of flags are handled according to the
setting of TCP_FLAGS_DISPOSITION after having been logged
according to the setting of TCP_FLAGS_LOG_LEVEL.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">nosmurfs</emphasis></term>
<listitem>
<para>This option only makes sense for ports on a
bridge.</para>
<para>Filter packets for smurfs (packets with a broadcast
address as the source).</para>
<para>Smurfs will be optionally logged based on the setting of
SMURF_LOG_LEVEL in <ulink
url="shorewall.conf.html">shorewall.conf</ulink>(5). After
logging, the packets are dropped.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">ipsec</emphasis></term>
<listitem>
<para>The zone is accessed via a kernel 2.6 ipsec SA. Note
that if the zone named in the ZONE column is specified as an
IPSEC zone in the <ulink
url="shorewall-zones.html">shorewall-zones</ulink>(5) file
then you do NOT need to specify the 'ipsec' option
here.</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><emphasis role="bold">broadcast</emphasis></term> <term><emphasis role="bold">broadcast</emphasis></term>
@@ -229,6 +161,86 @@
net(s).</para> net(s).</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><emphasis role="bold">ipsec</emphasis></term>
<listitem>
<para>The zone is accessed via a kernel 2.6 ipsec SA. Note
that if the zone named in the ZONE column is specified as an
IPSEC zone in the <ulink
url="shorewall-zones.html">shorewall-zones</ulink>(5) file
then you do NOT need to specify the 'ipsec' option
here.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">maclist</emphasis></term>
<listitem>
<para>Connection requests from these hosts are compared
against the contents of <ulink
url="shorewall-maclist.html">shorewall-maclist</ulink>(5). If
this option is specified, the interface must be an ethernet
NIC or equivalent and must be up before Shorewall is
started.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis
role="bold">mss</emphasis>=<replaceable>mss</replaceable></term>
<listitem>
<para>Added in Shorewall 4.5.2. When present, causes the TCP
mss for new connections to/from the hosts given in the HOST(S)
column to be clamped at the specified
<replaceable>mss</replaceable>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">nosmurfs</emphasis></term>
<listitem>
<para>This option only makes sense for ports on a
bridge.</para>
<para>Filter packets for smurfs (packets with a broadcast
address as the source).</para>
<para>Smurfs will be optionally logged based on the setting of
SMURF_LOG_LEVEL in <ulink
url="shorewall.conf.html">shorewall.conf</ulink>(5). After
logging, the packets are dropped.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">routeback</emphasis></term>
<listitem>
<para>Shorewall should set up the infrastructure to pass
packets from this/these address(es) back to themselves. This
is necessary if hosts in this group use the services of a
transparent proxy that is a member of the group or if DNAT is
used to send requests originating from this group to a server
in the group.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis role="bold">tcpflags</emphasis></term>
<listitem>
<para>Packets arriving from these hosts are checked for
certain illegal combinations of TCP flags. Packets found to
have such a combination of flags are handled according to the
setting of TCP_FLAGS_DISPOSITION after having been logged
according to the setting of TCP_FLAGS_LOG_LEVEL.</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@@ -35,8 +35,8 @@
<para>If you have more than one ISP link, adding entries to this file <para>If you have more than one ISP link, adding entries to this file
will <emphasis role="bold">not</emphasis> force connections to go out will <emphasis role="bold">not</emphasis> force connections to go out
through a particular link. You must use entries in <ulink through a particular link. You must use entries in <ulink
url="shorewall-rtrules.html">shorewall-rtrules</ulink>(5) or url="shorewall-rtrules.html">shorewall-rtrules</ulink>(5) or PREROUTING
PREROUTING entries in <ulink entries in <ulink
url="shorewall-tcrules.html">shorewall-tcrules</ulink>(5) to do url="shorewall-tcrules.html">shorewall-tcrules</ulink>(5) to do
that.</para> that.</para>
</warning> </warning>
@@ -88,7 +88,8 @@
addresses to indicate that you only want to change the source IP addresses to indicate that you only want to change the source IP
address for packets being sent to those particular destinations. address for packets being sent to those particular destinations.
Exclusion is allowed (see <ulink Exclusion is allowed (see <ulink
url="shorewall-exclusion.html">shorewall-exclusion</ulink>(5)).</para> url="shorewall-exclusion.html">shorewall-exclusion</ulink>(5)) as
are ipset names preceded by a plus sign '+';</para>
<para>If you wish to inhibit the action of ADD_SNAT_ALIASES for this <para>If you wish to inhibit the action of ADD_SNAT_ALIASES for this
entry then include the ":" but omit the digit:</para> entry then include the ":" but omit the digit:</para>
@@ -149,6 +150,10 @@
<para>In that example traffic from eth1 would be masqueraded unless <para>In that example traffic from eth1 would be masqueraded unless
it came from 192.168.1.4 or 196.168.32.0/27</para> it came from 192.168.1.4 or 196.168.32.0/27</para>
<para>The preferred way to specify the SOURCE is to supply one or
more host or network addresses separated by comma. You may use ipset
names preceded by a plus sign (+) to specify a set of hosts.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
@@ -467,6 +472,43 @@
</variablelist> </variablelist>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><emphasis role="bold">SWITCH -
[!]<replaceable>switch-name</replaceable></emphasis></term>
<listitem>
<para>Added in Shorewall 4.5.1 and allows enabling and disabling the
rule without requiring <command>shorewall restart</command>.</para>
<para>The rule is enabled if the value stored in
<filename>/proc/net/nf_condition/<replaceable>switch-name</replaceable></filename>
is 1. The rule is disabled if that file contains 0 (the default). If
'!' is supplied, the test is inverted such that the rule is enabled
if the file contains 0. <replaceable>switch-name</replaceable> must
begin with a letter and be composed of letters, decimal digits,
underscores or hyphens. Switch names must be 30 characters or less
in length.</para>
<para>Switches are normally <emphasis role="bold">off</emphasis>. To
turn a switch <emphasis role="bold">on</emphasis>:</para>
<simplelist>
<member><command>echo 1 &gt;
/proc/net/nf_condition/<replaceable>switch-name</replaceable></command></member>
</simplelist>
<para>To turn it <emphasis role="bold">off</emphasis> again:</para>
<simplelist>
<member><command>echo 0 &gt;
/proc/net/nf_condition/<replaceable>switch-name</replaceable></command></member>
</simplelist>
<para>Switch settings are retained over <command>shorewall
restart</command>.</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>
@@ -548,6 +590,19 @@
</warning> </warning>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>Example 6:</term>
<listitem>
<para>Connections leaving on eth0 and destined to any host defined
in the ipset <emphasis>myset</emphasis> should have the source IP
address changed to 206.124.146.177.</para>
<programlisting> #INTERFACE SOURCE ADDRESS
eth0:+myset[dst] - 206.124.146.177</programlisting>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>

View File

@@ -23,7 +23,11 @@
<refsect1> <refsect1>
<title>Description</title> <title>Description</title>
<para>Assign any shell variables that you need in this file.</para> <para>Assign any shell variables that you need in this file. The file is
always processed by <filename>/bin/sh</filename> or by the shell specified
through SHOREWALL_SHELL in <ulink
url="shorewall.conf.html">shorewall.conf</ulink> (5) so the full range of
shell capabilities may be used.</para>
<para>It is suggested that variable names begin with an upper case letter <para>It is suggested that variable names begin with an upper case letter
to distinguish them from variables used internally within the Shorewall to distinguish them from variables used internally within the Shorewall
@@ -128,12 +132,13 @@ net eth0 130.252.100.255 routefilter,norfc1918</programlisting>
url="http://www.shorewall.net/configuration_file_basics.htm#Variables?">http://www.shorewall.net/configuration_file_basics.htm#Variables</ulink></para> url="http://www.shorewall.net/configuration_file_basics.htm#Variables?">http://www.shorewall.net/configuration_file_basics.htm#Variables</ulink></para>
<para>shorewall(8), shorewall-accounting(5), shorewall-actions(5), <para>shorewall(8), shorewall-accounting(5), shorewall-actions(5),
shorewall-blacklist(5), shorewall-hosts(5), shorewall_interfaces(5), shorewall-ipsets(5), shorewall-blacklist(5), shorewall-hosts(5), shorewall_interfaces(5),
shorewall-maclist(5), shorewall-masq(5), shorewall-nat(5), shorewall-ipsets(5), shorewall-maclist(5), shorewall-masq(5),
shorewall-netmap(5), shorewall-policy(5), shorewall-providers(5), shorewall-nat(5), shorewall-netmap(5), shorewall-policy(5),
shorewall-proxyarp(5), shorewall-rtrules(5), shorewall-providers(5), shorewall-proxyarp(5), shorewall-rtrules(5),
shorewall-routestopped(5), shorewall-rules(5), shorewall.conf(5), shorewall-secmarks(5), shorewall-routestopped(5), shorewall-rules(5), shorewall.conf(5),
shorewall-tcclasses(5), shorewall-tcdevices(5), shorewall-tcrules(5), shorewall-secmarks(5), shorewall-tcclasses(5), shorewall-tcdevices(5),
shorewall-tos(5), shorewall-tunnels(5), shorewall-zones(5)</para> shorewall-tcrules(5), shorewall-tos(5), shorewall-tunnels(5),
shorewall-zones(5)</para>
</refsect1> </refsect1>
</refentry> </refentry>

View File

@@ -226,7 +226,7 @@
<listitem> <listitem>
<para>like DROP but exempts the rule from being suppressed by <para>like DROP but exempts the rule from being suppressed by
OPTIMIZE=1 in <ulink OPTIMIZE=1 in <ulink
url="shorewall.conf.html">shorewall.conf</ulink>(5). </para> url="shorewall.conf.html">shorewall.conf</ulink>(5).</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
@@ -782,7 +782,7 @@
</orderedlist></para> </orderedlist></para>
<blockquote> <blockquote>
<para></para> <para/>
<para>Except when <emphasis role="bold">all</emphasis>[<emphasis <para>Except when <emphasis role="bold">all</emphasis>[<emphasis
role="bold">+]|[-</emphasis>] is specified, the server may be role="bold">+]|[-</emphasis>] is specified, the server may be
@@ -1230,8 +1230,18 @@
<term>localtz</term> <term>localtz</term>
<listitem> <listitem>
<para>Times are expressed in Local Civil Time <para>Deprecated by the Netfilter team in favor of <emphasis
(default).</para> role="bold">kerneltz</emphasis>. Times are expressed in Local
Civil Time (default).</para>
</listitem>
</varlistentry>
<varlistentry>
<term>kerneltz</term>
<listitem>
<para>Added in Shorewall 4.5.2. Times are expressed in Local
Kernel Time (requires iptables 1.4.12 or later).</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
@@ -1548,9 +1558,9 @@
shorewall_interfaces(5), shorewall-ipsets(5), shorewall-maclist(5), shorewall_interfaces(5), shorewall-ipsets(5), shorewall-maclist(5),
shorewall-masq(5), shorewall-nat(5), shorewall-netmap(5), shorewall-masq(5), shorewall-nat(5), shorewall-netmap(5),
shorewall-params(5), shorewall-policy(5), shorewall-providers(5), shorewall-params(5), shorewall-policy(5), shorewall-providers(5),
shorewall-proxyarp(5), shorewall-rtrules(5), shorewall-proxyarp(5), shorewall-rtrules(5), shorewall-routestopped(5),
shorewall-routestopped(5), shorewall.conf(5), shorewall-secmarks(5), shorewall.conf(5), shorewall-secmarks(5), shorewall-tcclasses(5),
shorewall-tcclasses(5), shorewall-tcdevices(5), shorewall-tcrules(5), shorewall-tcdevices(5), shorewall-tcrules(5), shorewall-tos(5),
shorewall-tos(5), shorewall-tunnels(5), shorewall-zones(5)</para> shorewall-tunnels(5), shorewall-zones(5)</para>
</refsect1> </refsect1>
</refentry> </refentry>

View File

@@ -44,7 +44,7 @@
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><emphasis role="bold">MARK/CLASSIFY</emphasis> (mark) - <term><emphasis role="bold">ACTION</emphasis> (mark) -
<replaceable>mark</replaceable></term> <replaceable>mark</replaceable></term>
<listitem> <listitem>
@@ -271,8 +271,8 @@
target allows you to work around that problem. SAME may be used target allows you to work around that problem. SAME may be used
in the PREROUTING and OUTPUT chains. When used in PREROUTING, it in the PREROUTING and OUTPUT chains. When used in PREROUTING, it
causes matching connections from an individual local system to causes matching connections from an individual local system to
all use the same provider. For example: <programlisting>#MARK/ SOURCE DEST PROTO DEST all use the same provider. For example: <programlisting>#ACTION SOURCE DEST PROTO DEST
#CLASSIFY PORT(S) # PORT(S)
SAME:P 192.168.1.0/24 0.0.0.0/0 tcp 80,443</programlisting> SAME:P 192.168.1.0/24 0.0.0.0/0 tcp 80,443</programlisting>
If a host in 192.168.1.0/24 attempts a connection on TCP port 80 If a host in 192.168.1.0/24 attempts a connection on TCP port 80
or 443 and it has sent a packet on either of those ports in the or 443 and it has sent a packet on either of those ports in the
@@ -282,8 +282,8 @@ SAME:P 192.168.1.0/24 0.0.0.0/0 tcp 80,443</programlisting>
<para>When used in the OUTPUT chain, it causes all matching <para>When used in the OUTPUT chain, it causes all matching
connections to an individual remote system to all use the same connections to an individual remote system to all use the same
provider. For example:<programlisting>#MARK/ SOURCE DEST PROTO DEST provider. For example:<programlisting>#ACTION SOURCE DEST PROTO DEST
#CLASSIFY PORT(S) # PORT(S)
SAME $FW 0.0.0.0/0 tcp 80,443</programlisting> SAME $FW 0.0.0.0/0 tcp 80,443</programlisting>
If the firewall attempts a connection on TCP port 80 or 443 and If the firewall attempts a connection on TCP port 80 or 443 and
it has sent a packet on either of those ports in the last five it has sent a packet on either of those ports in the last five
@@ -468,6 +468,112 @@ SAME $FW 0.0.0.0/0 tcp 80,443</programlisting>
<replaceable>number</replaceable>. Requires IMQ Target support <replaceable>number</replaceable>. Requires IMQ Target support
in your kernel and iptables.</para> in your kernel and iptables.</para>
</listitem> </listitem>
<listitem>
<para><emphasis
role="bold">DSCP</emphasis>(<replaceable>dscp</replaceable>)</para>
<para>Added in Shorewall 4.5.1. Sets the
<firstterm>Differentiated Services Code Point</firstterm> field
in the IP header. The <replaceable>dscp</replaceable> value may
be given as an even number (hex or decimal) or as the name of a
DSCP class. Valid class names and their associated hex numeric
values are:</para>
<programlisting> CS0 =&gt; 0x00
CS1 =&gt; 0x08
CS2 =&gt; 0x10
CS3 =&gt; 0x18
CS4 =&gt; 0x20
CS5 =&gt; 0x28
CS6 =&gt; 0x30
CS7 =&gt; 0x38
BE =&gt; 0x00
AF11 =&gt; 0x0a
AF12 =&gt; 0x0c
AF13 =&gt; 0x0e
AF21 =&gt; 0x12
AF22 =&gt; 0x14
AF23 =&gt; 0x16
AF31 =&gt; 0x1a
AF32 =&gt; 0x1c
AF33 =&gt; 0x1e
AF41 =&gt; 0x22
AF42 =&gt; 0x24
AF43 =&gt; 0x26
EF =&gt; 0x2e</programlisting>
<para>May be optionally followed by ':' and a capital letter
designating the chain where classification is to occur.</para>
<variablelist>
<varlistentry>
<term>F</term>
<listitem>
<para>FORWARD chain.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>T</term>
<listitem>
<para>POSTROUTING chain (default).</para>
</listitem>
</varlistentry>
</variablelist>
</listitem>
<listitem>
<para><emphasis
role="bold">TOS</emphasis>(<replaceable>tos</replaceable>[/<replaceable>mask</replaceable>])</para>
<para>Added in Shorewall 4.5.1. Sets the <firstterm>Type of
Service</firstterm> field in the IP header. The
<replaceable>tos</replaceable> value may be given as an number
(hex or decimal) or as the name of a TOS type. Valid type names
and their associated hex numeric values are:</para>
<programlisting>Minimize-Delay =&gt; 0x10,
Maximize-Throughput =&gt; 0x08,
Maximize-Reliability =&gt; 0x04,
Minimize-Cost =&gt; 0x02,
Normal-Service =&gt; 0x00</programlisting>
<para>When <replaceable>tos</replaceable> is given as a number,
it may be optionally followed by '/' and a
<replaceable>mask</replaceable>. When no
<replaceable>mask</replaceable> is given, the value 0xff is
assumed. When <replaceable>tos</replaceable> is given as a type
name, the <replaceable>mask</replaceable> 0x3f is
assumed.</para>
<para>The action performed is to zero out the bits specified by
the <replaceable>mask</replaceable>, then set the bits specified
by <replaceable>tos</replaceable>.</para>
<para>May be optionally followed by ':' and a capital letter
designating the chain where classification is to occur.</para>
<variablelist>
<varlistentry>
<term>F</term>
<listitem>
<para>FORWARD chain.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>T</term>
<listitem>
<para>POSTROUTING chain.</para>
</listitem>
</varlistentry>
</variablelist>
</listitem>
</orderedlist> </orderedlist>
</listitem> </listitem>
</varlistentry> </varlistentry>
@@ -494,7 +600,7 @@ SAME $FW 0.0.0.0/0 tcp 80,443</programlisting>
MAC addresses. <emphasis role="bold">This form will not match MAC addresses. <emphasis role="bold">This form will not match
traffic that originates on the firewall itself unless either traffic that originates on the firewall itself unless either
&lt;major&gt;&lt;minor&gt; or the :T chain qualifier is used in &lt;major&gt;&lt;minor&gt; or the :T chain qualifier is used in
the MARK column.</emphasis></para> the ACTION column.</emphasis></para>
<para>Examples:<simplelist> <para>Examples:<simplelist>
<member>0.0.0.0/0</member> <member>0.0.0.0/0</member>
@@ -516,7 +622,7 @@ SAME $FW 0.0.0.0/0 tcp 80,443</programlisting>
<para>$FW optionally followed by a colon (":") and a <para>$FW optionally followed by a colon (":") and a
comma-separated list of host or network IP addresses. Matches comma-separated list of host or network IP addresses. Matches
packets originating on the firewall. May not be used with a packets originating on the firewall. May not be used with a
chain qualifier (:P, :F, etc.) in the MARK column.</para> chain qualifier (:P, :F, etc.) in the ACTION column.</para>
</listitem> </listitem>
</orderedlist> </orderedlist>
@@ -832,15 +938,15 @@ SAME $FW 0.0.0.0/0 tcp 80,443</programlisting>
original connection was made on.</para> original connection was made on.</para>
<para>Example: Mark all FTP data connections with mark <para>Example: Mark all FTP data connections with mark
4:<programlisting>#MARK/ SOURCE DEST PROTO PORT(S) SOURCE USER TEST LENGTH TOS CONNBYTES HELPER 4:<programlisting>#ACTION SOURCE DEST PROTO PORT(S) SOURCE USER TEST LENGTH TOS CONNBYTES HELPER
#CLASSIFY PORT(S) # PORT(S)
4:T 0.0.0.0/0 0.0.0.0/0 TCP - - - - - - - ftp</programlisting></para> 4:T 0.0.0.0/0 0.0.0.0/0 TCP - - - - - - - ftp</programlisting></para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><emphasis role="bold">PROBABILITY</emphasis> - <term><emphasis role="bold">PROBABILITY</emphasis> -
[probability]</term> [<replaceable>probability</replaceable>]</term>
<listitem> <listitem>
<para>Added in Shorewall 4.5.0. When non-empty, requires the <para>Added in Shorewall 4.5.0. When non-empty, requires the
@@ -852,6 +958,44 @@ SAME $FW 0.0.0.0/0 tcp 80,443</programlisting>
at up to 8 decimal points of precision.</para> at up to 8 decimal points of precision.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><emphasis role="bold">DSCP -</emphasis>
[[!]<replaceable>dscp</replaceable>]</term>
<listitem>
<para>Added in Shorewall 4.5.1. When non-empty, match packets whose
<firstterm>Differentiated Service Code Point</firstterm> field
matches the supplied value (when '!' is given, the rule matches
packets whose DSCP field does not match the supplied value). The
<replaceable>dscp</replaceable> value may be given as an even number
(hex or decimal) or as the name of a DSCP class. Valid class names
and their associated hex numeric values are:</para>
<programlisting> CS0 =&gt; 0x00
CS1 =&gt; 0x08
CS2 =&gt; 0x10
CS3 =&gt; 0x18
CS4 =&gt; 0x20
CS5 =&gt; 0x28
CS6 =&gt; 0x30
CS7 =&gt; 0x38
BE =&gt; 0x00
AF11 =&gt; 0x0a
AF12 =&gt; 0x0c
AF13 =&gt; 0x0e
AF21 =&gt; 0x12
AF22 =&gt; 0x14
AF23 =&gt; 0x16
AF31 =&gt; 0x1a
AF32 =&gt; 0x1c
AF33 =&gt; 0x1e
AF41 =&gt; 0x22
AF42 =&gt; 0x24
AF43 =&gt; 0x26
EF =&gt; 0x2e</programlisting>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>
@@ -873,8 +1017,8 @@ SAME $FW 0.0.0.0/0 tcp 80,443</programlisting>
<para>We assume packet/connection mark 0 means unclassified.</para> <para>We assume packet/connection mark 0 means unclassified.</para>
<programlisting> #MARK/ SOURCE DEST PROTO PORT(S) SOURCE USER TEST <programlisting> #ACTION SOURCE DEST PROTO PORT(S) SOURCE USER TEST
#CLASSIFY PORT(S) # PORT(S)
1:T 0.0.0.0/0 0.0.0.0/0 icmp echo-request 1:T 0.0.0.0/0 0.0.0.0/0 icmp echo-request
1:T 0.0.0.0/0 0.0.0.0/0 icmp echo-reply 1:T 0.0.0.0/0 0.0.0.0/0 icmp echo-reply
RESTORE:T 0.0.0.0/0 0.0.0.0/0 all - - - 0 RESTORE:T 0.0.0.0/0 0.0.0.0/0 all - - - 0

View File

@@ -23,7 +23,9 @@
<refsect1> <refsect1>
<title>Description</title> <title>Description</title>
<para>This file defines rules for setting Type Of Service (TOS)</para> <para>This file defines rules for setting Type Of Service (TOS). Its use
is deprecated, beginning in Shorewall 4.5.1, in favor of the TOS target in
<ulink url="shorewall-tcrules.html">shorewall-tcrules</ulink> (5).</para>
<para>The columns in the file are as follows (where the column name is <para>The columns in the file are as follows (where the column name is
followed by a different name in parentheses, the different name is used in followed by a different name in parentheses, the different name is used in

View File

@@ -848,6 +848,29 @@ net all DROP info</programlisting>then the chain name is 'net2all'
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><emphasis role="bold">IPSET_WARNINGS=</emphasis>{<emphasis
role="bold">Yes</emphasis>|<emphasis role="bold">No</emphasis>}</term>
<listitem>
<para>Added in Shorewall 4.5.2. Default is Yes. When set, causes the
rules compiler to issue a warning when:</para>
<itemizedlist>
<listitem>
<para>The compiler is being run by root and an ipset specified
in the configuration does not exists. Only one warning is issued
for each missing ipset.</para>
</listitem>
<listitem>
<para>When [src] is specified in a destination column and when
[dst] is specified in a source column.</para>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><emphasis <term><emphasis
role="bold">IPTABLES=</emphasis>[<emphasis>pathname</emphasis>]</term> role="bold">IPTABLES=</emphasis>[<emphasis>pathname</emphasis>]</term>
@@ -2092,14 +2115,14 @@ net all DROP info</programlisting>then the chain name is 'net2all'
tcrules. This was done so that tcrules could reset the packet mark tcrules. This was done so that tcrules could reset the packet mark
to zero, thus allowing the packet to be routed using the 'main' to zero, thus allowing the packet to be routed using the 'main'
routing table. Using the main table allowed dynamic routes (such as routing table. Using the main table allowed dynamic routes (such as
those added for VPNs) to be effective. The rtrules file was those added for VPNs) to be effective. The rtrules file was created
created to provide a better alternative to clearing the packet mark. to provide a better alternative to clearing the packet mark. As a
As a consequence, passing these packets to PREROUTING complicates consequence, passing these packets to PREROUTING complicates things
things without providing any real benefit. Beginning with Shorewall without providing any real benefit. Beginning with Shorewall 4.4.6,
4.4.6, when TRACK_PROVIDERS=Yes and TC_EXPERT=No, packets arriving when TRACK_PROVIDERS=Yes and TC_EXPERT=No, packets arriving through
through 'tracked' interfaces will not be passed to the PREROUTING 'tracked' interfaces will not be passed to the PREROUTING rules.
rules. Since TRACK_PROVIDERS was just introduced in 4.4.3, this Since TRACK_PROVIDERS was just introduced in 4.4.3, this change
change should be transparent to most, if not all, users.</para> should be transparent to most, if not all, users.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@@ -1243,7 +1243,7 @@
directory is given, then Shorewall will look in that directory first directory is given, then Shorewall will look in that directory first
when opening configuration files.</para> when opening configuration files.</para>
<para>Begining with Shorewall 4.5.0, you may specify a different <para>Beginning with Shorewall 4.5.0, you may specify a different
<replaceable>timeout</replaceable> value using the <replaceable>timeout</replaceable> value using the
<option>-t</option> option. The numeric <option>-t</option> option. The numeric
<replaceable>timeout</replaceable> may optionally be followed by an <replaceable>timeout</replaceable> may optionally be followed by an
@@ -1265,7 +1265,7 @@
Shorewall will look in that directory first when opening Shorewall will look in that directory first when opening
configuration files.</para> configuration files.</para>
<para>Begining with Shorewall 4.5.0, you may specify a different <para>Beginning with Shorewall 4.5.0, you may specify a different
<replaceable>timeout</replaceable> value using the <replaceable>timeout</replaceable> value using the
<option>-t</option> option. The numeric <option>-t</option> option. The numeric
<replaceable>timeout</replaceable> may optionally be followed by an <replaceable>timeout</replaceable> may optionally be followed by an
@@ -1600,7 +1600,7 @@
role="bold">restore</emphasis> is performed after role="bold">restore</emphasis> is performed after
<replaceable>timeout</replaceable> seconds.</para> <replaceable>timeout</replaceable> seconds.</para>
<para>Begining with Shorewall 4.5.0, the numeric <para>Beginning with Shorewall 4.5.0, the numeric
<replaceable>timeout</replaceable> may optionally be followed by an <replaceable>timeout</replaceable> may optionally be followed by an
<option>s</option>, <option>m</option> or <option>h</option> suffix <option>s</option>, <option>m</option> or <option>h</option> suffix
(e.g., 5m) to specify seconds, minutes or hours respectively. If the (e.g., 5m) to specify seconds, minutes or hours respectively. If the

View File

@@ -27,6 +27,19 @@
################################################################################################ ################################################################################################
g_program=shorewall g_program=shorewall
. /usr/share/shorewall/lib.cli #
# This is modified by the installer when ${SHAREDIR} != /usr/share
#
. /usr/share/shorewall/shorewallrc
g_libexec="$LIBEXECDIR"
g_sharedir="$SHAREDIR"/shorewall
g_sbindir="$SBINDIR"
g_perllib="$PERLLIBDIR"
g_vardir="$VARDIR"
g_confdir="$CONFDIR"/shorewall
g_readrc=1
. $g_sharedir/lib.cli
shorewall_cli $@ shorewall_cli $@

View File

@@ -31,7 +31,7 @@ VERSION=xxx #The Build script inserts the actual version
usage() # $1 = exit status usage() # $1 = exit status
{ {
ME=$(basename $0) ME=$(basename $0)
echo "usage: $ME" echo "usage: $ME [ <shorewallrc file> ]"
exit $1 exit $1
} }
@@ -40,16 +40,25 @@ qt()
"$@" >/dev/null 2>&1 "$@" >/dev/null 2>&1
} }
restore_file() # $1 = file to restore split() {
{ local ifs
if [ -f ${1}-shorewall.bkout ]; then ifs=$IFS
if (mv -f ${1}-shorewall.bkout $1); then IFS=:
echo set -- $1
echo "$1 restored" echo $*
else IFS=$ifs
exit 1 }
fi
fi mywhich() {
local dir
for dir in $(split $PATH); do
if [ -x $dir/$1 ]; then
return 0
fi
done
return 2
} }
remove_file() # $1 = file to restore remove_file() # $1 = file to restore
@@ -60,8 +69,34 @@ remove_file() # $1 = file to restore
fi fi
} }
if [ -f /usr/share/shorewall/version ]; then if [ $# -eq 0 ]; then
INSTALLED_VERSION="$(cat /usr/share/shorewall/version)" if [ -f ./shorewallrc ]; then
. ./shorewallrc
elif [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc || exit 1
file=./.shorewallrc
elif [ -f /usr/share/shorewall/shorewallrc ]; then
. /usr/share/shorewall/shorewallrc
else
fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
fi
elif [ $# -eq 1 ]; then
file=$1
case $file in
/*|.*)
;;
*)
file=./$file
;;
esac
. $file
else
usage 1
fi
if [ -f ${SHAREDIR}/shorewall/version ]; then
INSTALLED_VERSION="$(cat ${SHAREDIR}/shorewall/version)"
if [ "$INSTALLED_VERSION" != "$VERSION" ]; then if [ "$INSTALLED_VERSION" != "$VERSION" ]; then
echo "WARNING: Shorewall Version $INSTALLED_VERSION is installed" echo "WARNING: Shorewall Version $INSTALLED_VERSION is installed"
echo " and this is the $VERSION uninstaller." echo " and this is the $VERSION uninstaller."
@@ -72,62 +107,33 @@ else
VERSION="" VERSION=""
fi fi
[ -n "${LIBEXEC:=/usr/share}" ]
[ -n "${PERLLIB:=/usr/share/shorewall}" ]
echo "Uninstalling shorewall $VERSION" echo "Uninstalling shorewall $VERSION"
if qt iptables -L shorewall -n && [ ! -f /sbin/shorewall-lite ]; then if qt iptables -L shorewall -n && [ ! -f ${SBINDIR}/shorewall-lite ]; then
/sbin/shorewall clear shorewall clear
fi fi
if [ -L /usr/share/shorewall/init ]; then rm -f ${SBINDIR}/shorewall
FIREWALL=$(readlink -m -q /usr/share/shorewall/init)
else
FIREWALL=/etc/init.d/shorewall
fi
if [ -n "$FIREWALL" ]; then rm -rf ${SHAREDIR}/shorewall/version
if [ -x /usr/sbin/updaterc.d ]; then rm -rf ${CONFDIR}/shorewall
updaterc.d shorewall remove rm -rf ${VARDIR}/shorewall
elif [ -x /sbin/insserv -o -x /usr/sbin/insserv ]; then rm -rf ${PERLLIB}/Shorewall/*
insserv -r $FIREWALL
elif [ -x /sbin/systemctl ]; then
systemctl disable shorewall
elif [ -x /sbin/chkconfig -o -x /usr/sbin/chkconfig ]; then
chkconfig --del $(basename $FIREWALL)
else
rm -f /etc/rc*.d/*$(basename $FIREWALL)
fi
remove_file $FIREWALL
rm -f ${FIREWALL}-*.bkout
fi
rm -f /sbin/shorewall
rm -f /sbin/shorewall-*.bkout
rm -rf /usr/share/shorewall/version
rm -rf /etc/shorewall
rm -rf /etc/shorewall-*.bkout
rm -rf /var/lib/shorewall
rm -rf /var/lib/shorewall-*.bkout
rm -rf $PERLLIB}/Shorewall/*
rm -rf ${LIBEXEC}/shorewall rm -rf ${LIBEXEC}/shorewall
rm -rf /usr/share/shorewall/configfiles/ rm -rf ${SHAREDIR}/shorewall/configfiles/
rm -rf /usr/share/shorewall/Samples/ rm -rf ${SHAREDIR}/shorewall/Samples/
rm -rf /usr/share/shorewall/Shorewall/ rm -rf ${SHAREDIR}/shorewall/Shorewall/
rm -f /usr/share/shorewall/lib.cli-std rm -f ${SHAREDIR}/shorewall/lib.cli-std
rm -f /usr/share/shorewall/lib.core rm -f ${SHAREDIR}/shorewall/lib.core
rm -f /usr/share/shorewall/compiler.pl rm -f ${SHAREDIR}/shorewall/compiler.pl
rm -f /usr/share/shorewall/prog.* rm -f ${SHAREDIR}/shorewall/prog.*
rm -f /usr/share/shorewall/module* rm -f ${SHAREDIR}/shorewall/module*
rm -f /usr/share/shorewall/helpers rm -f ${SHAREDIR}/shorewall/helpers
rm -f /usr/share/shorewall/action* rm -f ${SHAREDIR}/shorewall/action*
rm -f /usr/share/shorewall/init rm -f ${SHAREDIR}/shorewall/init
rm -rf /usr/share/shorewall-*.bkout
for f in /usr/share/man/man5/shorewall* /usr/share/man/man8/shorewall*; do for f in ${MANDIR}/man5/shorewall* ${MANDIR}/man8/shorewall*; do
case $f in case $f in
shorewall6*|shorewall-lite*) shorewall6*|shorewall-lite*)
;; ;;
@@ -137,8 +143,10 @@ for f in /usr/share/man/man5/shorewall* /usr/share/man/man8/shorewall*; do
esac esac
done done
rm -f /etc/logrotate.d/shorewall rm -f ${CONFDIR}/logrotate.d/shorewall
rm -f /lib/systemd/system/shorewall.service
if [ -n "$SYSTEMD" ]; THEN
rm -f ${SYSTEMD}/shorewall.service
echo "Shorewall Uninstalled" echo "Shorewall Uninstalled"

View File

@@ -3,16 +3,16 @@ VARDIR=$(shell /sbin/shorewall6-lite show vardir)
SHAREDIR=/usr/share/shorewall6-lite SHAREDIR=/usr/share/shorewall6-lite
RESTOREFILE?=.restore RESTOREFILE?=.restore
all: $(VARDIR)/${RESTOREFILE} all: $(VARDIR)/$(RESTOREFILE)
$(VARDIR)/${RESTOREFILE}: $(VARDIR)/firewall $(VARDIR)/$(RESTOREFILE): $(VARDIR)/firewall
@/sbin/shorewall6-lite -q save >/dev/null; \ @/sbin/shorewall6-lite -q save >/dev/null; \
if \ if \
/sbin/shorewall6-lite -q restart >/dev/null 2>&1; \ /sbin/shorewall6-lite -q restart >/dev/null 2>&1; \
then \ then \
/sbin/shorewall6-lite -q save >/dev/null; \ /sbin/shorewall6-lite -q save >/dev/null; \
else \ else \
/sbin/shorewall6-lite -q restart 2>&1 | tail >&2; \ /sbin/shorewall6-lite -q restart 2>&1 | tail >&2; exit 1; \
fi fi
# EOF # EOF

View File

@@ -78,6 +78,11 @@ else
not_configured not_configured
fi fi
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
# start the firewall # start the firewall
shorewall6_start () { shorewall6_start () {
echo -n "Starting \"Shorewall6 Lite firewall\": " echo -n "Starting \"Shorewall6 Lite firewall\": "

View File

@@ -20,16 +20,21 @@
# Source function library. # Source function library.
. /etc/rc.d/init.d/functions . /etc/rc.d/init.d/functions
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
prog="shorewall6-lite" prog="shorewall6-lite"
shorewall="/sbin/$prog" shorewall="${SBINDIR}/$prog"
logger="logger -i -t $prog" logger="logger -i -t $prog"
lockfile="/var/lock/subsys/$prog" lockfile="/var/lock/subsys/$prog"
# Get startup options (override default) # Get startup options (override default)
OPTIONS= OPTIONS=
if [ -f /etc/sysconfig/$prog ]; then if [ -f ${SYSCONFDIR}/$prog ]; then
. /etc/sysconfig/$prog . ${SYSCONFDIR}/$prog
fi fi
start() { start() {

View File

@@ -1,11 +1,11 @@
#!/bin/sh #!/bin/sh
RCDLINKS="2,S41 3,S41 6,K41" RCDLINKS="2,S41 3,S41 6,K41"
# #
# The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.1 # The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V4.5
# #
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt] # This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
# #
# (c) 1999,2000,2001,2002,2003,2004,2005,2006,2007 - Tom Eastep (teastep@shorewall.net) # (c) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2012 - Tom Eastep (teastep@shorewall.net)
# #
# On most distributions, this file should be called /etc/init.d/shorewall. # On most distributions, this file should be called /etc/init.d/shorewall.
# #
@@ -61,11 +61,11 @@ usage() {
# Get startup options (override default) # Get startup options (override default)
################################################################################ ################################################################################
OPTIONS= OPTIONS=
if [ -f /etc/sysconfig/shorewall6-lite ]; then
. /etc/sysconfig/shorewall6-lite #
elif [ -f /etc/default/shorewall6-lite ] ; then # The installer may alter this
. /etc/default/shorewall6-lite #
fi . /usr/share/shorewall/shorewallrc
export SHOREWALL_INIT_SCRIPT=1 export SHOREWALL_INIT_SCRIPT=1
@@ -76,13 +76,13 @@ command="$1"
case "$command" in case "$command" in
start) start)
exec /sbin/shorewall6-lite $OPTIONS start $STARTOPTIONS $@ exec ${SBINDIR}/shorewall6-lite $OPTIONS start $STARTOPTIONS
;; ;;
restart|reload) restart|reload)
exec /sbin/shorewall6-lite $OPTIONS restart $RESTARTOPTIONS $@ exec ${SBINDIR}/shorewall6-lite $OPTIONS restart $RESTARTOPTIONS
;; ;;
status|stop) status|stop)
exec /sbin/shorewall6-lite $OPTIONS $command $@ exec ${SBINDIR}/shorewall6-lite $OPTIONS $command $@
;; ;;
*) *)
usage usage

View File

@@ -36,6 +36,29 @@
directory. If you add this file, you should copy the files from directory. If you add this file, you should copy the files from
<filename>/var/lib/shorewall6-lite</filename> to the new directory before <filename>/var/lib/shorewall6-lite</filename> to the new directory before
performing a <command>shorewall6-lite restart</command>.</para> performing a <command>shorewall6-lite restart</command>.</para>
<note>
<para>Beginning with Shorewall 4.5.2, use of this file is deprecated in
favor of specifying VARDIR in the <filename>shorewallrc</filename> file
used during installation of Shorewall Core. While the name of the
variable remains VARDIR, the meaning is slightly different. When set in
shorewallrc, Shorewall6 Lite will create a directory under the specified
path name to hold state information.</para>
<para>Example:</para>
<blockquote>
<para>VARDIR=<filename>/opt/var/lib/</filename></para>
<para>The state directory for Shorewall Lite will be
<filename>/opt/var/lib/shorewall6-lite</filename>.</para>
</blockquote>
<para>When VARDIR is set in
<filename>/etc/shorewall6-lite/vardir</filename>, Shorewall Lite will
save its state in the <replaceable>directory</replaceable>
specified.</para>
</note>
</refsect1> </refsect1>
<refsect1> <refsect1>

View File

@@ -27,6 +27,18 @@
################################################################################################ ################################################################################################
g_program=shorewall6-lite g_program=shorewall6-lite
. /usr/share/shorewall/lib.cli #
# This is modified by the installer when ${SHAREDIR} != /usr/share
#
. /usr/share/shorewall/shorewallrc
g_libexec="$LIBEXECDIR"
g_sharedir="$SHAREDIR"/shorewall6-lite
g_sbindir="$SBINDIR"
g_vardir="$VARDIR"
g_confdir="$CONFDIR"/shorewall6-lite
g_readrc=1
. ${SHAREDIR}/shorewall/lib.cli
shorewall_cli $@ shorewall_cli $@

View File

@@ -31,7 +31,7 @@ VERSION=xxx #The Build script inserts the actual version
usage() # $1 = exit status usage() # $1 = exit status
{ {
ME=$(basename $0) ME=$(basename $0)
echo "usage: $ME" echo "usage: $ME [ <shorewallrc file> ]"
exit $1 exit $1
} }
@@ -40,6 +40,27 @@ qt()
"$@" >/dev/null 2>&1 "$@" >/dev/null 2>&1
} }
split() {
local ifs
ifs=$IFS
IFS=:
set -- $1
echo $*
IFS=$ifs
}
mywhich() {
local dir
for dir in $(split $PATH); do
if [ -x $dir/$1 ]; then
return 0
fi
done
return 2
}
remove_file() # $1 = file to restore remove_file() # $1 = file to restore
{ {
if [ -f $1 -o -L $1 ] ; then if [ -f $1 -o -L $1 ] ; then
@@ -48,8 +69,37 @@ remove_file() # $1 = file to restore
fi fi
} }
if [ -f /usr/share/shorewall6-lite/version ]; then #
INSTALLED_VERSION="$(cat /usr/share/shorewall6-lite/version)" # Read the RC file
#
if [ $# -eq 0 ]; then
if [ -f ./shorewallrc ]; then
. ./shorewallrc
elif [ -f ~/.shorewallrc ]; then
. ~/.shorewallrc || exit 1
file=./.shorewallrc
elif [ -f /usr/share/shorewall/shorewallrc ]; then
. /usr/share/shorewall/shorewallrc
else
fatal_error "No configuration file specified and /usr/share/shorewall/shorewallrc not found"
fi
elif [ $# -eq 1 ]; then
file=$1
case $file in
/*|.*)
;;
*)
file=./$file
;;
esac
. $file
else
usage 1
fi
if [ -f ${SHAREDIR}/shorewall6-lite/version ]; then
INSTALLED_VERSION="$(cat ${SHAREDIR}/shorewall6-lite/version)"
if [ "$INSTALLED_VERSION" != "$VERSION" ]; then if [ "$INSTALLED_VERSION" != "$VERSION" ]; then
echo "WARNING: Shorewall Lite Version $INSTALLED_VERSION is installed" echo "WARNING: Shorewall Lite Version $INSTALLED_VERSION is installed"
echo " and this is the $VERSION uninstaller." echo " and this is the $VERSION uninstaller."
@@ -60,49 +110,39 @@ else
VERSION="" VERSION=""
fi fi
[ -n "${LIBEXEC:=/usr/share}" ]
echo "Uninstalling Shorewall Lite $VERSION" echo "Uninstalling Shorewall Lite $VERSION"
if qt ip6tables -L shorewall -n && [ ! -f /sbin/shorewall6 ]; then if qt ip6tables -L shorewall -n && [ ! -f ${SBINDIR)/shorewall6 ]; then
/sbin/shorewall6-lite clear ${SBINDIR}/shorewall6-lite clear
fi fi
if [ -L /usr/share/shorewall6-lite/init ]; then if [ -l ${SHAREDIR}/shorewall6-lite/init ]; then
FIREWALL=$(readlink -m -q /usr/share/shorewall6-lite/init) FIREWALL=$(readlink -m -q ${SHAREDIR}/shorewall6-lite/init)
else elif [ -n "$INITFILE" ]; then
FIREWALL=/etc/init.d/shorewall6-lite FIREWALL=${INITDIR}/${INITFILE}
fi fi
if [ -n "$FIREWALL" ]; then if [ -f "$FIREWALL" ]; then
if [ -x /usr/sbin/updaterc.d ]; then if mywhich updaterc.d ; then
updaterc.d shorewall6-lite remove updaterc.d shorewall6-lite remove
elif [ -x /sbin/insserv -o -x /usr/sbin/insserv ]; then elif mywhich insserv ; then
insserv -r $FIREWALL insserv -r $FIREWALL
elif [ -x /sbin/chkconfig -o -x /usr/sbin/chkconfig ]; then elif mywhich chkconfig ; then
chkconfig --del $(basename $FIREWALL) chkconfig --del $(basename $FIREWALL)
elif [ -x /sbin/systemctl ]; then elif mywhich systemctl ; then
systemctl disable shorewall6-lite systemctl disable shorewall6-lite
else
rm -f /etc/rc*.d/*$(basename $FIREWALL)
fi fi
remove_file $FIREWALL remove_file $FIREWALL
rm -f ${FIREWALL}-*.bkout
fi fi
rm -f /sbin/shorewall6-lite rm -f ${SBINDIR}/shorewall6-lite
rm -f /sbin/shorewall6-lite-*.bkout rm -rf ${CONFDIR}/shorewall6-lite
rm -rf ${VARDIR}/shorewall6-lite
rm -rf /etc/shorewall6-lite rm -rf ${SHAREDIR}/shorewall6-lite
rm -rf /etc/shorewall6-lite-*.bkout
rm -rf /var/lib/shorewall6-lite
rm -rf /var/lib/shorewall6-lite-*.bkout
rm -rf /usr/share/shorewall6-lite
rm -rf ${LIBEXEC}/shorewall6-lite rm -rf ${LIBEXEC}/shorewall6-lite
rm -rf /usr/share/shorewall6-lite-*.bkout rm -f ${CONFDIR}/logrotate.d/shorewall6-lite
rm -f /etc/logrotate.d/shorewall6-lite [ -n "$SYSTEMD" ] && rm -f ${SYSTEMD}/shorewall6-lite.service
rm -f /lib/systemd/system/shorewall6-lite.service
echo "Shorewall6 Lite Uninstalled" echo "Shorewall6 Lite Uninstalled"

View File

@@ -2,20 +2,22 @@
VARDIR=$(shell /sbin/shorewall6 show vardir) VARDIR=$(shell /sbin/shorewall6 show vardir)
CONFDIR=/etc/shorewall6 CONFDIR=/etc/shorewall6
RESTOREFILE?=firewall RESTOREFILE?=firewall
all: $(VARDIR)/${RESTOREFILE}
$(VARDIR)/${RESTOREFILE}: $(CONFDIR)/* all: $(VARDIR)/$(RESTOREFILE)
$(VARDIR)/$(RESTOREFILE): $(CONFDIR)/*
@/sbin/shorewall6 -q save >/dev/null; \ @/sbin/shorewall6 -q save >/dev/null; \
if \ if \
/sbin/shorewall6 -q restart >/dev/null 2>&1; \ /sbin/shorewall6 -q restart >/dev/null 2>&1; \
then \ then \
/sbin/shorewall6 -q save >/dev/null; \ /sbin/shorewall6 -q save >/dev/null; \
else \ else \
/sbin/shorewall6 -q restart 2>&1 | tail >&2; \ /sbin/shorewall6 -q restart 2>&1 | tail >&2; exit 1; \
fi fi
clean: clean:
@rm -f $(CONFDIR)/*~ $(CONFDIR)/.*~ @rm -f $(CONFDIR)/*~ $(CONFDIR)/.*~
.PHONY: clean .PHONY: clean
# EOF # EOF

View File

@@ -52,7 +52,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH=/etc/shorewall6:/usr/share/shorewall6:/usr/share/shorewall CONFIG_PATH=${CONFDIR}/shorewall6:${SHAREDIR}/shorewall6:${SHAREDIR}/shorewall
IP6TABLES= IP6TABLES=
@@ -129,6 +129,8 @@ FORWARD_CLEAR_MARK=
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=Off IP_FORWARDING=Off
KEEP_RT_TABLES=Yes KEEP_RT_TABLES=Yes

View File

@@ -52,7 +52,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH=/etc/shorewall6:/usr/share/shorewall6:/usr/share/shorewall CONFIG_PATH=${CONFDIR}/shorewall6:${SHAREDIR}/shorewall6:${SHAREDIR}/shorewall
IP6TABLES= IP6TABLES=
@@ -129,6 +129,8 @@ FORWARD_CLEAR_MARK=
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=Off IP_FORWARDING=Off
KEEP_RT_TABLES=Yes KEEP_RT_TABLES=Yes

View File

@@ -52,7 +52,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH=/etc/shorewall6:/usr/share/shorewall6:/usr/share/shorewall CONFIG_PATH=${CONFDIR}/shorewall6:${SHAREDIR}/shorewall6:${SHAREDIR}/shorewall
IP6TABLES= IP6TABLES=
@@ -129,6 +129,8 @@ FORWARD_CLEAR_MARK=
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=On IP_FORWARDING=On
KEEP_RT_TABLES=Yes KEEP_RT_TABLES=Yes

View File

@@ -52,7 +52,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH=/etc/shorewall6:/usr/share/shorewall6:/usr/share/shorewall CONFIG_PATH=${CONFDIR}/shorewall6:${SHAREDIR}/shorewall6:${SHAREDIR}/shorewall
IP6TABLES= IP6TABLES=
@@ -129,6 +129,8 @@ FORWARD_CLEAR_MARK=
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=On IP_FORWARDING=On
KEEP_RT_TABLES=Yes KEEP_RT_TABLES=Yes

View File

@@ -7,4 +7,8 @@
# http://www.shorewall.net/manpages6/shorewall6-interfaces.html # http://www.shorewall.net/manpages6/shorewall6-interfaces.html
# #
############################################################################### ###############################################################################
FORMAT 1
#ZONE INTERFACE ANYCAST OPTIONS #ZONE INTERFACE ANYCAST OPTIONS
FORMAT 2
#ZONE INTERFACE OPTIONS

View File

@@ -8,13 +8,15 @@
# #
# The script is invoked inside a function that accepts an interface # The script is invoked inside a function that accepts an interface
# name as a single argument. The file below is designed to work with # name as a single argument. The file below is designed to work with
# both swping and lsm as described at http://www.shorewall.net/MultiISP.html # both swping and lsm as described at
# http://www.shorewall.net/MultiISP.html
# #
# See http://shorewall.net/shorewall_extension_scripts.htm for additional # See http://shorewall.net/shorewall_extension_scripts.htm for additional
# information. # information.
# #
############################################################################### ###############################################################################
local status=0 local status
status=0
[ -f ${VARDIR}/${1}.status ] && status=$(cat ${VARDIR}/${1}.status) [ -f ${VARDIR}/${1}.status ] && status=$(cat ${VARDIR}/${1}.status)

View File

@@ -52,7 +52,7 @@ TCP_FLAGS_LOG_LEVEL=info
# L O C A T I O N O F F I L E S A N D D I R E C T O R I E S # L O C A T I O N O F F I L E S A N D D I R E C T O R I E S
############################################################################### ###############################################################################
CONFIG_PATH="/etc/shorewall6:/usr/share/shorewall6:/usr/share/shorewall" CONFIG_PATH="${CONFDIR}/shorewall6:/usr/share/shorewall6:${SHAREDIR}/shorewall"
IP6TABLES= IP6TABLES=
@@ -129,6 +129,8 @@ FORWARD_CLEAR_MARK=Yes
IMPLICIT_CONTINUE=No IMPLICIT_CONTINUE=No
IPSET_WARNINGS=Yes
IP_FORWARDING=Off IP_FORWARDING=Off
KEEP_RT_TABLES=Yes KEEP_RT_TABLES=Yes

View File

@@ -9,6 +9,6 @@
# #
# See http://shorewall.net/PacketMarking.html for a detailed description of # See http://shorewall.net/PacketMarking.html for a detailed description of
# the Netfilter/Shorewall packet marking mechanism. # the Netfilter/Shorewall packet marking mechanism.
############################################################################################################################################## ###################################################################################################################################################
#MARK SOURCE DEST PROTO DEST SOURCE USER TEST LENGTH TOS CONNBYTES HELPER HEADERS PROBABILITY #ACTION SOURCE DEST PROTO DEST SOURCE USER TEST LENGTH TOS CONNBYTES HELPER HEADERS PROBABILITY DSCP
# PORT(S) PORT(S) # PORT(S) PORT(S)

View File

@@ -4,5 +4,5 @@
# For information about entries in this file, type "man shorewall6-tos" # For information about entries in this file, type "man shorewall6-tos"
# #
############################################################################### ###############################################################################
#SOURCE DEST PROTOCOL SOURCE DEST TOS MARK #SOURCE DEST PROTOCOL DEST SOURCE TOS MARK
# PORTS PORTS # PORTS PORTS

View File

@@ -54,10 +54,15 @@ not_configured () {
exit 0 exit 0
} }
#
# The installer may alter this
#
. /usr/share/shorewall/shorewallrc
# check if shorewall is configured or not # check if shorewall is configured or not
if [ -f "/etc/default/shorewall6" ] if [ -f "${SYSCONFDIR}/shorewall6" ]
then then
. /etc/default/shorewall6 . ${SYSCONFDIR}/shorewall6
SRWL_OPTS="$SRWL_OPTS $OPTIONS" SRWL_OPTS="$SRWL_OPTS $OPTIONS"
if [ "$startup" != "1" ] if [ "$startup" != "1" ]
then then

Some files were not shown because too many files have changed in this diff Show More