1196200Sscottl#!/bin/sh - 2196200Sscottl# Copyright (c) 1996 Poul-Henning Kamp 3196200Sscottl# All rights reserved. 4196200Sscottl# 5196200Sscottl# Redistribution and use in source and binary forms, with or without 6196200Sscottl# modification, are permitted provided that the following conditions 7196200Sscottl# are met: 8196200Sscottl# 1. Redistributions of source code must retain the above copyright 9196200Sscottl# notice, this list of conditions and the following disclaimer. 10196200Sscottl# 2. Redistributions in binary form must reproduce the above copyright 11196200Sscottl# notice, this list of conditions and the following disclaimer in the 12196200Sscottl# documentation and/or other materials provided with the distribution. 13196200Sscottl# 14196200Sscottl# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15196200Sscottl# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16196200Sscottl# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17196200Sscottl# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18196200Sscottl# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19196200Sscottl# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20196200Sscottl# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21196200Sscottl# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22196200Sscottl# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23196200Sscottl# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24196200Sscottl# SUCH DAMAGE. 25196200Sscottl# 26196200Sscottl# $FreeBSD: releng/10.2/etc/rc.firewall 285821 2015-07-23 19:53:49Z hrs $ 27196200Sscottl# 28196200Sscottl 29196200Sscottl# 30196200Sscottl# Setup system for ipfw(4) firewall service. 31196200Sscottl# 32196200Sscottl 33196200Sscottl# Suck in the configuration variables. 34196200Sscottlif [ -z "${source_rc_confs_defined}" ]; then 35196200Sscottl if [ -r /etc/defaults/rc.conf ]; then 36196200Sscottl . /etc/defaults/rc.conf 37196200Sscottl source_rc_confs 38196200Sscottl elif [ -r /etc/rc.conf ]; then 39196200Sscottl . /etc/rc.conf 40196200Sscottl fi 41196200Sscottlfi 42196200Sscottl 43196200Sscottl############ 44196200Sscottl# Define the firewall type in /etc/rc.conf. Valid values are: 45214396Sjhb# open - will allow anyone in 46196200Sscottl# client - will try to protect just this machine 47196200Sscottl# simple - will try to protect a whole network 48196200Sscottl# closed - totally disables IP services except via lo0 interface 49196200Sscottl# workstation - will try to protect just this machine using stateful 50214396Sjhb# firewalling. See below for rc.conf variables used 51196200Sscottl# UNKNOWN - disables the loading of firewall rules. 52196200Sscottl# filename - will load the rules in the given filename (full path required) 53196200Sscottl# 54214396Sjhb# For ``client'' and ``simple'' the entries below should be customized 55196200Sscottl# appropriately. 56214396Sjhb 57196200Sscottl############ 58196200Sscottl# 59196200Sscottl# If you don't know enough about packet filtering, we suggest that you 60196200Sscottl# take time to read this book: 61196200Sscottl# 62196200Sscottl# Building Internet Firewalls, 2nd Edition 63196200Sscottl# Brent Chapman and Elizabeth Zwicky 64196200Sscottl# 65196200Sscottl# O'Reilly & Associates, Inc 66196200Sscottl# ISBN 1-56592-871-7 67196200Sscottl# http://www.ora.com/ 68196200Sscottl# http://www.oreilly.com/catalog/fire2/ 69241776Sed# 70196200Sscottl# For a more advanced treatment of Internet Security read: 71241776Sed# 72214396Sjhb# Firewalls and Internet Security: Repelling the Wily Hacker, 2nd Edition 73214396Sjhb# William R. Cheswick, Steven M. Bellowin, Aviel D. Rubin 74196200Sscottl# 75196200Sscottl# Addison-Wesley / Prentice Hall 76196200Sscottl# ISBN 0-201-63466-X 77196200Sscottl# http://www.pearsonhighered.com/ 78196200Sscottl# http://www.pearsonhighered.com/educator/academic/product/0,3110,020163466X,00.html 79196200Sscottl# 80196200Sscottl 81196200Sscottlsetup_loopback() { 82196200Sscottl ############ 83196200Sscottl # Only in rare cases do you want to change these rules 84196200Sscottl # 85196200Sscottl ${fwcmd} add 100 pass all from any to any via lo0 86196200Sscottl ${fwcmd} add 200 deny all from any to 127.0.0.0/8 87196200Sscottl ${fwcmd} add 300 deny ip from 127.0.0.0/8 to any 88196200Sscottl if [ $ipv6_available -eq 0 ]; then 89196200Sscottl ${fwcmd} add 400 deny all from any to ::1 90196200Sscottl ${fwcmd} add 500 deny all from ::1 to any 91196200Sscottl fi 92196200Sscottl} 93196200Sscottl 94214396Sjhbsetup_ipv6_mandatory() { 95196200Sscottl [ $ipv6_available -eq 0 ] || return 0 96196200Sscottl 97196200Sscottl ############ 98196200Sscottl # Only in rare cases do you want to change these rules 99196200Sscottl # 100196200Sscottl # ND 101196200Sscottl # 102196200Sscottl # DAD 103196200Sscottl ${fwcmd} add pass ipv6-icmp from :: to ff02::/16 104214396Sjhb # RS, RA, NS, NA, redirect... 105196200Sscottl ${fwcmd} add pass ipv6-icmp from fe80::/10 to fe80::/10 106214396Sjhb ${fwcmd} add pass ipv6-icmp from fe80::/10 to ff02::/16 107196200Sscottl 108196200Sscottl # Allow ICMPv6 destination unreachable 109222899Sbz ${fwcmd} add pass ipv6-icmp from any to any icmp6types 1 110222899Sbz 111222899Sbz # Allow NS/NA/toobig (don't filter it out) 112196200Sscottl ${fwcmd} add pass ipv6-icmp from any to any icmp6types 2,135,136 113214396Sjhb} 114196200Sscottl 115222899Sbzif [ -n "${1}" ]; then 116196200Sscottl firewall_type="${1}" 117196200Sscottlfi 118196200Sscottl 119222899Sbz. /etc/rc.subr 120222899Sbz. /etc/network.subr 121196200Sscottlafexists inet6 122196200Sscottlipv6_available=$? 123237259Seadler 124196200Sscottl############ 125214396Sjhb# Set quiet mode if requested 126196200Sscottl# 127222899Sbzcase ${firewall_quiet} in 128196200Sscottl[Yy][Ee][Ss]) 129196200Sscottl fwcmd="/sbin/ipfw -q" 130196200Sscottl ;; 131196200Sscottl*) 132196200Sscottl fwcmd="/sbin/ipfw" 133196200Sscottl ;; 134196200Sscottlesac 135222899Sbz 136222899Sbz############ 137196200Sscottl# Flush out the list before we begin. 138196200Sscottl# 139196200Sscottl${fwcmd} -f flush 140196200Sscottl 141215526Sjhbsetup_loopback 142215526Sjhbsetup_ipv6_mandatory 143222899Sbz 144222899Sbz############ 145215526Sjhb# Network Address Translation. All packets are passed to natd(8) 146196200Sscottl# before they encounter your remaining rules. The firewall rules 147196200Sscottl# will then be run again on each packet after translation by natd 148196200Sscottl# starting at the rule number following the divert rule. 149196200Sscottl# 150196200Sscottl# For ``simple'' firewall type the divert rule should be put to a 151196200Sscottl# different place to not interfere with address-checking rules. 152196200Sscottl# 153222899Sbzcase ${firewall_type} in 154222899Sbz[Oo][Pp][Ee][Nn]|[Cc][Ll][Ii][Ee][Nn][Tt]) 155196200Sscottl case ${natd_enable} in 156196200Sscottl [Yy][Ee][Ss]) 157196200Sscottl if [ -n "${natd_interface}" ]; then 158196200Sscottl ${fwcmd} add 50 divert natd ip4 from any to any via ${natd_interface} 159196200Sscottl fi 160196200Sscottl ;; 161196200Sscottl esac 162196200Sscottl case ${firewall_nat_enable} in 163196200Sscottl [Yy][Ee][Ss]) 164222899Sbz if [ -n "${firewall_nat_interface}" ]; then 165222899Sbz if echo "${firewall_nat_interface}" | \ 166196200Sscottl grep -q -E '^[0-9]+(\.[0-9]+){0,3}$'; then 167196200Sscottl firewall_nat_flags="ip ${firewall_nat_interface} ${firewall_nat_flags}" 168196200Sscottl else 169196200Sscottl firewall_nat_flags="if ${firewall_nat_interface} ${firewall_nat_flags}" 170196200Sscottl fi 171196200Sscottl ${fwcmd} nat 123 config log ${firewall_nat_flags} 172196200Sscottl ${fwcmd} add 50 nat 123 ip4 from any to any via ${firewall_nat_interface} 173196200Sscottl fi 174196200Sscottl ;; 175196200Sscottl esac 176196200Sscottlesac 177196200Sscottl 178222899Sbz############ 179222899Sbz# If you just configured ipfw in the kernel as a tool to solve network 180196200Sscottl# problems or you just want to disallow some particular kinds of traffic 181196200Sscottl# then you will want to change the default policy to open. You can also 182214396Sjhb# do this as your only action by setting the firewall_type to ``open''. 183196200Sscottl# 184222899Sbz# ${fwcmd} add 65000 pass all from any to any 185222899Sbz 186222899Sbz 187222899Sbz# Prototype setups. 188222899Sbz# 189196200Sscottlcase ${firewall_type} in 190214396Sjhb[Oo][Pp][Ee][Nn]) 191196200Sscottl ${fwcmd} add 65000 pass all from any to any 192196200Sscottl ;; 193 194[Cc][Ll][Ii][Ee][Nn][Tt]) 195 ############ 196 # This is a prototype setup that will protect your system somewhat 197 # against people from outside your own network. 198 # 199 # Configuration: 200 # firewall_client_net: Network address of local IPv4 network. 201 # firewall_client_net_ipv6: Network address of local IPv6 network. 202 ############ 203 204 # set this to your local network 205 net="$firewall_client_net" 206 net6="$firewall_client_net_ipv6" 207 208 # Allow limited broadcast traffic from my own net. 209 ${fwcmd} add pass all from ${net} to 255.255.255.255 210 211 # Allow any traffic to or from my own net. 212 ${fwcmd} add pass all from me to ${net} 213 ${fwcmd} add pass all from ${net} to me 214 if [ -n "$net6" ]; then 215 ${fwcmd} add pass all from me to ${net6} 216 ${fwcmd} add pass all from ${net6} to me 217 fi 218 219 if [ -n "$net6" ]; then 220 # Allow any link-local multicast traffic 221 ${fwcmd} add pass all from fe80::/10 to ff02::/16 222 ${fwcmd} add pass all from ${net6} to ff02::/16 223 # Allow DHCPv6 224 ${fwcmd} add pass udp from fe80::/10 to me 546 225 fi 226 227 # Allow TCP through if setup succeeded 228 ${fwcmd} add pass tcp from any to any established 229 230 # Allow IP fragments to pass through 231 ${fwcmd} add pass all from any to any frag 232 233 # Allow setup of incoming email 234 ${fwcmd} add pass tcp from any to me 25 setup 235 236 # Allow setup of outgoing TCP connections only 237 ${fwcmd} add pass tcp from me to any setup 238 239 # Disallow setup of all other TCP connections 240 ${fwcmd} add deny tcp from any to any setup 241 242 # Allow DNS queries out in the world 243 ${fwcmd} add pass udp from me to any 53 keep-state 244 245 # Allow NTP queries out in the world 246 ${fwcmd} add pass udp from me to any 123 keep-state 247 248 # Everything else is denied by default, unless the 249 # IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel 250 # config file. 251 ;; 252 253[Ss][Ii][Mm][Pp][Ll][Ee]) 254 ############ 255 # This is a prototype setup for a simple firewall. Configure this 256 # machine as a DNS and NTP server, and point all the machines 257 # on the inside at this machine for those services. 258 # 259 # Configuration: 260 # firewall_simple_iif: Inside IPv4 network interface. 261 # firewall_simple_inet: Inside IPv4 network address. 262 # firewall_simple_oif: Outside IPv4 network interface. 263 # firewall_simple_onet: Outside IPv4 network address. 264 # firewall_simple_iif_ipv6: Inside IPv6 network interface. 265 # firewall_simple_inet_ipv6: Inside IPv6 network prefix. 266 # firewall_simple_oif_ipv6: Outside IPv6 network interface. 267 # firewall_simple_onet_ipv6: Outside IPv6 network prefix. 268 ############ 269 270 # set these to your outside interface network 271 oif="$firewall_simple_oif" 272 onet="$firewall_simple_onet" 273 oif6="${firewall_simple_oif_ipv6:-$firewall_simple_oif}" 274 onet6="$firewall_simple_onet_ipv6" 275 276 # set these to your inside interface network 277 iif="$firewall_simple_iif" 278 inet="$firewall_simple_inet" 279 iif6="${firewall_simple_iif_ipv6:-$firewall_simple_iif}" 280 inet6="$firewall_simple_inet_ipv6" 281 282 # Stop spoofing 283 ${fwcmd} add deny all from ${inet} to any in via ${oif} 284 ${fwcmd} add deny all from ${onet} to any in via ${iif} 285 if [ -n "$inet6" ]; then 286 ${fwcmd} add deny all from ${inet6} to any in via ${oif6} 287 if [ -n "$onet6" ]; then 288 ${fwcmd} add deny all from ${onet6} to any in \ 289 via ${iif6} 290 fi 291 fi 292 293 # Stop RFC1918 nets on the outside interface 294 ${fwcmd} add deny all from any to 10.0.0.0/8 via ${oif} 295 ${fwcmd} add deny all from any to 172.16.0.0/12 via ${oif} 296 ${fwcmd} add deny all from any to 192.168.0.0/16 via ${oif} 297 298 # Stop draft-manning-dsua-03.txt (1 May 2000) nets (includes RESERVED-1, 299 # DHCP auto-configuration, NET-TEST, MULTICAST (class D), and class E) 300 # on the outside interface 301 ${fwcmd} add deny all from any to 0.0.0.0/8 via ${oif} 302 ${fwcmd} add deny all from any to 169.254.0.0/16 via ${oif} 303 ${fwcmd} add deny all from any to 192.0.2.0/24 via ${oif} 304 ${fwcmd} add deny all from any to 224.0.0.0/4 via ${oif} 305 ${fwcmd} add deny all from any to 240.0.0.0/4 via ${oif} 306 307 # Network Address Translation. This rule is placed here deliberately 308 # so that it does not interfere with the surrounding address-checking 309 # rules. If for example one of your internal LAN machines had its IP 310 # address set to 192.0.2.1 then an incoming packet for it after being 311 # translated by natd(8) would match the `deny' rule above. Similarly 312 # an outgoing packet originated from it before being translated would 313 # match the `deny' rule below. 314 case ${natd_enable} in 315 [Yy][Ee][Ss]) 316 if [ -n "${natd_interface}" ]; then 317 ${fwcmd} add divert natd ip4 from any to any via ${natd_interface} 318 fi 319 ;; 320 esac 321 322 # Stop RFC1918 nets on the outside interface 323 ${fwcmd} add deny all from 10.0.0.0/8 to any via ${oif} 324 ${fwcmd} add deny all from 172.16.0.0/12 to any via ${oif} 325 ${fwcmd} add deny all from 192.168.0.0/16 to any via ${oif} 326 327 # Stop draft-manning-dsua-03.txt (1 May 2000) nets (includes RESERVED-1, 328 # DHCP auto-configuration, NET-TEST, MULTICAST (class D), and class E) 329 # on the outside interface 330 ${fwcmd} add deny all from 0.0.0.0/8 to any via ${oif} 331 ${fwcmd} add deny all from 169.254.0.0/16 to any via ${oif} 332 ${fwcmd} add deny all from 192.0.2.0/24 to any via ${oif} 333 ${fwcmd} add deny all from 224.0.0.0/4 to any via ${oif} 334 ${fwcmd} add deny all from 240.0.0.0/4 to any via ${oif} 335 336 if [ -n "$inet6" ]; then 337 # Stop unique local unicast address on the outside interface 338 ${fwcmd} add deny all from fc00::/7 to any via ${oif6} 339 ${fwcmd} add deny all from any to fc00::/7 via ${oif6} 340 341 # Stop site-local on the outside interface 342 ${fwcmd} add deny all from fec0::/10 to any via ${oif6} 343 ${fwcmd} add deny all from any to fec0::/10 via ${oif6} 344 345 # Disallow "internal" addresses to appear on the wire. 346 ${fwcmd} add deny all from ::ffff:0.0.0.0/96 to any \ 347 via ${oif6} 348 ${fwcmd} add deny all from any to ::ffff:0.0.0.0/96 \ 349 via ${oif6} 350 351 # Disallow packets to malicious IPv4 compatible prefix. 352 ${fwcmd} add deny all from ::224.0.0.0/100 to any via ${oif6} 353 ${fwcmd} add deny all from any to ::224.0.0.0/100 via ${oif6} 354 ${fwcmd} add deny all from ::127.0.0.0/104 to any via ${oif6} 355 ${fwcmd} add deny all from any to ::127.0.0.0/104 via ${oif6} 356 ${fwcmd} add deny all from ::0.0.0.0/104 to any via ${oif6} 357 ${fwcmd} add deny all from any to ::0.0.0.0/104 via ${oif6} 358 ${fwcmd} add deny all from ::255.0.0.0/104 to any via ${oif6} 359 ${fwcmd} add deny all from any to ::255.0.0.0/104 via ${oif6} 360 361 ${fwcmd} add deny all from ::0.0.0.0/96 to any via ${oif6} 362 ${fwcmd} add deny all from any to ::0.0.0.0/96 via ${oif6} 363 364 # Disallow packets to malicious 6to4 prefix. 365 ${fwcmd} add deny all from 2002:e000::/20 to any via ${oif6} 366 ${fwcmd} add deny all from any to 2002:e000::/20 via ${oif6} 367 ${fwcmd} add deny all from 2002:7f00::/24 to any via ${oif6} 368 ${fwcmd} add deny all from any to 2002:7f00::/24 via ${oif6} 369 ${fwcmd} add deny all from 2002:0000::/24 to any via ${oif6} 370 ${fwcmd} add deny all from any to 2002:0000::/24 via ${oif6} 371 ${fwcmd} add deny all from 2002:ff00::/24 to any via ${oif6} 372 ${fwcmd} add deny all from any to 2002:ff00::/24 via ${oif6} 373 374 ${fwcmd} add deny all from 2002:0a00::/24 to any via ${oif6} 375 ${fwcmd} add deny all from any to 2002:0a00::/24 via ${oif6} 376 ${fwcmd} add deny all from 2002:ac10::/28 to any via ${oif6} 377 ${fwcmd} add deny all from any to 2002:ac10::/28 via ${oif6} 378 ${fwcmd} add deny all from 2002:c0a8::/32 to any via ${oif6} 379 ${fwcmd} add deny all from any to 2002:c0a8::/32 via ${oif6} 380 381 ${fwcmd} add deny all from ff05::/16 to any via ${oif6} 382 ${fwcmd} add deny all from any to ff05::/16 via ${oif6} 383 fi 384 385 # Allow TCP through if setup succeeded 386 ${fwcmd} add pass tcp from any to any established 387 388 # Allow IP fragments to pass through 389 ${fwcmd} add pass all from any to any frag 390 391 # Allow setup of incoming email 392 ${fwcmd} add pass tcp from any to me 25 setup 393 394 # Allow access to our DNS 395 ${fwcmd} add pass tcp from any to me 53 setup 396 ${fwcmd} add pass udp from any to me 53 397 ${fwcmd} add pass udp from me 53 to any 398 399 # Allow access to our WWW 400 ${fwcmd} add pass tcp from any to me 80 setup 401 402 # Reject&Log all setup of incoming connections from the outside 403 ${fwcmd} add deny log ip4 from any to any in via ${oif} setup proto tcp 404 if [ -n "$inet6" ]; then 405 ${fwcmd} add deny log ip6 from any to any in via ${oif6} \ 406 setup proto tcp 407 fi 408 409 # Allow setup of any other TCP connection 410 ${fwcmd} add pass tcp from any to any setup 411 412 # Allow DNS queries out in the world 413 ${fwcmd} add pass udp from me to any 53 keep-state 414 415 # Allow NTP queries out in the world 416 ${fwcmd} add pass udp from me to any 123 keep-state 417 418 # Everything else is denied by default, unless the 419 # IPFIREWALL_DEFAULT_TO_ACCEPT option is set in your kernel 420 # config file. 421 ;; 422 423[Ww][Oo][Rr][Kk][Ss][Tt][Aa][Tt][Ii][Oo][Nn]) 424 # Configuration: 425 # firewall_myservices: List of ports/protocols on which this 426 # host offers services. 427 # firewall_allowservices: List of IPv4 and/or IPv6 addresses 428 # that have access to 429 # $firewall_myservices. 430 # firewall_trusted: List of IPv4 and/or IPv6 addresses 431 # that have full access to this host. 432 # Be very careful when setting this. 433 # This option can seriously degrade 434 # the level of protection provided by 435 # the firewall. 436 # firewall_logdeny: Boolean (YES/NO) specifying if the 437 # default denied packets should be 438 # logged (in /var/log/security). 439 # firewall_nologports: List of TCP/UDP ports for which 440 # denied incoming packets are not 441 # logged. 442 443 # Allow packets for which a state has been built. 444 ${fwcmd} add check-state 445 446 # For services permitted below. 447 ${fwcmd} add pass tcp from me to any established 448 449 # Allow any connection out, adding state for each. 450 ${fwcmd} add pass tcp from me to any setup keep-state 451 ${fwcmd} add pass udp from me to any keep-state 452 ${fwcmd} add pass icmp from me to any keep-state 453 if [ $ipv6_available -eq 0 ]; then 454 ${fwcmd} add pass ipv6-icmp from me to any keep-state 455 fi 456 457 # Allow DHCP. 458 ${fwcmd} add pass udp from 0.0.0.0 68 to 255.255.255.255 67 out 459 ${fwcmd} add pass udp from any 67 to me 68 in 460 ${fwcmd} add pass udp from any 67 to 255.255.255.255 68 in 461 if [ $ipv6_available -eq 0 ]; then 462 ${fwcmd} add pass udp from fe80::/10 to me 546 in 463 fi 464 # Some servers will ping the IP while trying to decide if it's 465 # still in use. 466 ${fwcmd} add pass icmp from any to any icmptype 8 467 if [ $ipv6_available -eq 0 ]; then 468 ${fwcmd} add pass ipv6-icmp from any to any icmp6type 128,129 469 fi 470 471 # Allow "mandatory" ICMP in. 472 ${fwcmd} add pass icmp from any to any icmptype 3,4,11 473 if [ $ipv6_available -eq 0 ]; then 474 ${fwcmd} add pass ipv6-icmp from any to any icmp6type 3 475 fi 476 477 # Add permits for this workstations published services below 478 # Only IPs and nets in firewall_allowservices is allowed in. 479 # If you really wish to let anyone use services on your 480 # workstation, then set "firewall_allowservices='any'" in /etc/rc.conf 481 # 482 # Note: We don't use keep-state as that would allow DoS of 483 # our statetable. 484 # You can add 'keep-state' to the lines for slightly 485 # better performance if you fell that DoS of your 486 # workstation won't be a problem. 487 # 488 for i in ${firewall_allowservices} ; do 489 for j in ${firewall_myservices} ; do 490 case $j in 491 [0-9A-Za-z]*/[Pp][Rr][Oo][Tt][Oo]) 492 ${fwcmd} add pass ${j%/[Pp][Rr][Oo][Tt][Oo]} from $i to me 493 ;; 494 [0-9A-Za-z]*/[Tt][Cc][Pp]) 495 ${fwcmd} add pass tcp from $i to me ${j%/[Tt][Cc][Pp]} 496 ;; 497 [0-9A-Za-z]*/[Uu][Dd][Pp]) 498 ${fwcmd} add pass udp from $i to me ${j%/[Uu][Dd][Pp]} 499 ;; 500 *[0-9A-Za-z]) 501 echo "Consider using ${j}/tcp in firewall_myservices." \ 502 > /dev/stderr 503 ${fwcmd} add pass tcp from $i to me $j 504 ;; 505 *) 506 echo "Invalid port in firewall_myservices: $j" > /dev/stderr 507 ;; 508 esac 509 done 510 done 511 512 # Allow all connections from trusted IPs. 513 # Playing with the content of firewall_trusted could seriously 514 # degrade the level of protection provided by the firewall. 515 for i in ${firewall_trusted} ; do 516 ${fwcmd} add pass ip from $i to me 517 done 518 519 ${fwcmd} add 65000 count ip from any to any 520 521 # Drop packets to ports where we don't want logging 522 for i in ${firewall_nologports} ; do 523 ${fwcmd} add deny { tcp or udp } from any to any $i in 524 done 525 526 # Broadcasts and multicasts 527 ${fwcmd} add deny ip from any to 255.255.255.255 528 ${fwcmd} add deny ip from any to 224.0.0.0/24 in # XXX 529 530 # Noise from routers 531 ${fwcmd} add deny udp from any to any 520 in 532 533 # Noise from webbrowsing. 534 # The stateful filter is a bit aggressive, and will cause some 535 # connection teardowns to be logged. 536 ${fwcmd} add deny tcp from any 80,443 to any 1024-65535 in 537 538 # Deny and (if wanted) log the rest unconditionally. 539 log="" 540 if [ ${firewall_logdeny:-x} = "YES" -o ${firewall_logdeny:-x} = "yes" ] ; then 541 log="log logamount 500" # The default of 100 is too low. 542 sysctl net.inet.ip.fw.verbose=1 >/dev/null 543 fi 544 ${fwcmd} add deny $log ip from any to any 545 ;; 546 547[Cc][Ll][Oo][Ss][Ee][Dd]) 548 ${fwcmd} add 65000 deny ip from any to any 549 ;; 550[Uu][Nn][Kk][Nn][Oo][Ww][Nn]) 551 ;; 552*) 553 if [ -r "${firewall_type}" ]; then 554 ${fwcmd} ${firewall_flags} ${firewall_type} 555 fi 556 ;; 557esac 558