History log of /openbsd-current/sbin/pfctl/parse.y
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.715 02-Nov-2023 sthen

Use pfctl_fopen (which checks to ensure the given file isn't a directory)
for pfctl -f /path/to/pf.conf. Otherwise, if you accidentally use a dir
instead of a file (e.g. if you have an /etc/pf directory and don't notice
the name when tab-completing), you successfully install an empty ruleset.
ok sashan@


# 1.714 26-Oct-2023 deraadt

whitespace cleanup my fingers couldn't avoid doing while i was re-reading
the parsing code


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.713 07-Feb-2023 sashan

internal representation of icmp type/code in pfctl(8)/pf(4) does not
fit into u_int8_t. Issue has been noticed and kindly reported by
amalinin _at_ bh0.amt.ru via bugs@.

OK bluhm@


Revision tags: OPENBSD_7_2_BASE
# 1.712 23-Sep-2022 bluhm

Fix detection of duplicate sticky-address in pf.conf parser.
reported to FreeBSD by Franco Fichtner; from Kristof Provost


Revision tags: OPENBSD_7_1_BASE
# 1.711 25-Oct-2021 sashan

- pfctl $nr incorrect macro expansion

Issue reported by Kristof Provost from FreeBSD.
[ https://reviews.freebsd.org/D32488 ]

In order to fix the issue we must delay '$nr' macro
expansion after optimizer collapses ruleset.

OK kn@


# 1.710 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.709 01-Feb-2021 dlg

change route-to so it sends packets to IPs instead of interfaces.

this is a significant (and breaking) reworking of the policy based
routing that pf can do. the intention is to make it as easy as
nat/rdr to use, and more robust when it's operating.

the main reasons for this change are:

- route-to, reply-to, and dup-to do not work with pfsync

this is because the information about where to route-to is stored in
rules, and it is hard to have a ruleset synced between firewalls,
and impossible to have them synced 100% of the time.

- i can make my boxes panic in certain situations using route-to

yeah...

- the configuration and syntax for route-to rules are confusing.

the argument to route-to and co is an interace name with an optional
ip address. there are several problems with this. one is that people
tend to think about routing as sending packets to peers by their
address, not by the interface they're reachable on. another is that
we currently have no way to synchronise interface topology information
between firewalls, so using an interface to say where packets go
means we can't do failover of these states with pfsync. another
is that a change in routing topology means a host may become
reachable over a different interface. tying routing policy to
interfaces gets in the way of failover and load balancing.

this change does the following:

- stores the route info in the state instead of the pf rule

this allows route-to to keep working when the ruleset changes, and
allows route-to info to be sent over pfsync. there's enough spare bits
in pfsync messages that the protocol doesnt break.

the caveat is that route-to becomes tied to pass rules that create
state, like rdr-to and nat-to.

- the argument to route-to etc is a destination ip address

it's not limited to a next-hop address (thought a next-hop can be a
destination address). this allows for the failover and load balancing
referred to above.

- deprecates the address@interface host syntax in pfctl

because routing is done entirely by IPs, the interface is derived from
the route lookup, not pf. any attempt to use the @interface syntax
will fail now in all contexts.

there's enthusiasm from proctor@ jmatthew@ and others
ok sashan@ bluhm@


# 1.708 12-Jan-2021 bluhm

Sometimes a user ID was logged in pflog(4) although the logopt of
the rule did not specify it. Check the option again for the log
rule in case another rule has triggered a socket lookup. Remove
logopt group, it is not documented and cannot work as struct pfloghdr
does not contain a gid. Rename PF_LOG_SOCKET_LOOKUP to PF_LOG_USER
to express what it does. The lookup involved is only an implemntation
detail.
OK kn@ sashan@ mvs@


# 1.707 16-Dec-2020 kn

Fail to parse rules with invalid ranges

This makes pfctl(8) detect bogus ranges (with and without `-n') before
loading the ruleset and completes the previous commit.

OK sashan sthen


# 1.706 16-Dec-2020 kn

Reject rules with invalid port ranges

Ranges where the left boundary is bigger than the right one are always bogus
as they work like `port any' (`port 34<>12' means "all ports") or in way
that inverts the rule's action (`pass ... port 34:12' means "pass no port at
all").

Add checks for all ranges and invalidate those that yield no or all ports.

For this to work on redirections, make pfctl(8) pass the range's type,
otherwise boundary including ranges are not detected as such; that is to
say, `struct pf_pool's `port_op' member was unused in the kernel so far.

`rdr-to' rules with invalid ranges could panic the kernel when hit.
Reported-by: syzbot+9c309db201f06e39a8ba@syzkaller.appspotmail.com

OK sashan


# 1.705 07-Dec-2020 sashan

synproxy should be processing incoming SYN packets only.
issue noticed by sthen@. fix discussed with bluhm@ and procter@

OK bluhm@, kn@, procter@


# 1.704 01-Oct-2020 kn

rdomain IDs do not need to exist for "on rdomain N" to work

Unlike "... rtable N", pf.conf(5)'s "on rdomain N" does not alter packet
state and will always work no matter if rdomain N currently exists or not,
i.e. the rule "pass on rdomain 42" will simply match (and pass) packets if
rdomain 42 exists, and it will simply not match (neither pass nor block)
packets if 42 does not exist.

There's no need to reload the ruleset whenever routing domains are created
or deleted, which can already be observed now by creating an rdomain,
loading rules referencing it and deleting the same rdomain immediately
afterwards: pf will continue to work as expected.

Relax both pfctl(8)'s parser check as well as pf(4)'s copyin routine to
accept any valid routing domain ID without expecting it to exist at the time
of ruleset creation - this lifts the requirement to create rdomains before
referencing them in pf.conf while keeping pf behaviour unchanged.

Prompted by yasuoka's recent pfctl parse.y r1.702 commit requiring an rtable
to exist upon ruleset creation.

Discussed with claudio and bluhm at k2k20.

Feedback sashan
OK sashan yasouka claudio


Revision tags: OPENBSD_6_8_BASE
# 1.703 17-Sep-2020 yasuoka

Fix the previous commit whose conditions were reversed.

ok kn


# 1.702 17-Sep-2020 yasuoka

Make pfctl(8) check if the rtable really exists when parsing the
config. work with and diff from kn

ok kn


Revision tags: OPENBSD_6_7_BASE
# 1.701 28-Jan-2020 bket

sbin/pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT

OK kn@, sashan@, florian@


# 1.700 15-Jan-2020 kn

Do the actual pfr_strerror() to pf_strerror() rename

Missed in previous


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.714 26-Oct-2023 deraadt

whitespace cleanup my fingers couldn't avoid doing while i was re-reading
the parsing code


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.713 07-Feb-2023 sashan

internal representation of icmp type/code in pfctl(8)/pf(4) does not
fit into u_int8_t. Issue has been noticed and kindly reported by
amalinin _at_ bh0.amt.ru via bugs@.

OK bluhm@


Revision tags: OPENBSD_7_2_BASE
# 1.712 23-Sep-2022 bluhm

Fix detection of duplicate sticky-address in pf.conf parser.
reported to FreeBSD by Franco Fichtner; from Kristof Provost


Revision tags: OPENBSD_7_1_BASE
# 1.711 25-Oct-2021 sashan

- pfctl $nr incorrect macro expansion

Issue reported by Kristof Provost from FreeBSD.
[ https://reviews.freebsd.org/D32488 ]

In order to fix the issue we must delay '$nr' macro
expansion after optimizer collapses ruleset.

OK kn@


# 1.710 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.709 01-Feb-2021 dlg

change route-to so it sends packets to IPs instead of interfaces.

this is a significant (and breaking) reworking of the policy based
routing that pf can do. the intention is to make it as easy as
nat/rdr to use, and more robust when it's operating.

the main reasons for this change are:

- route-to, reply-to, and dup-to do not work with pfsync

this is because the information about where to route-to is stored in
rules, and it is hard to have a ruleset synced between firewalls,
and impossible to have them synced 100% of the time.

- i can make my boxes panic in certain situations using route-to

yeah...

- the configuration and syntax for route-to rules are confusing.

the argument to route-to and co is an interace name with an optional
ip address. there are several problems with this. one is that people
tend to think about routing as sending packets to peers by their
address, not by the interface they're reachable on. another is that
we currently have no way to synchronise interface topology information
between firewalls, so using an interface to say where packets go
means we can't do failover of these states with pfsync. another
is that a change in routing topology means a host may become
reachable over a different interface. tying routing policy to
interfaces gets in the way of failover and load balancing.

this change does the following:

- stores the route info in the state instead of the pf rule

this allows route-to to keep working when the ruleset changes, and
allows route-to info to be sent over pfsync. there's enough spare bits
in pfsync messages that the protocol doesnt break.

the caveat is that route-to becomes tied to pass rules that create
state, like rdr-to and nat-to.

- the argument to route-to etc is a destination ip address

it's not limited to a next-hop address (thought a next-hop can be a
destination address). this allows for the failover and load balancing
referred to above.

- deprecates the address@interface host syntax in pfctl

because routing is done entirely by IPs, the interface is derived from
the route lookup, not pf. any attempt to use the @interface syntax
will fail now in all contexts.

there's enthusiasm from proctor@ jmatthew@ and others
ok sashan@ bluhm@


# 1.708 12-Jan-2021 bluhm

Sometimes a user ID was logged in pflog(4) although the logopt of
the rule did not specify it. Check the option again for the log
rule in case another rule has triggered a socket lookup. Remove
logopt group, it is not documented and cannot work as struct pfloghdr
does not contain a gid. Rename PF_LOG_SOCKET_LOOKUP to PF_LOG_USER
to express what it does. The lookup involved is only an implemntation
detail.
OK kn@ sashan@ mvs@


# 1.707 16-Dec-2020 kn

Fail to parse rules with invalid ranges

This makes pfctl(8) detect bogus ranges (with and without `-n') before
loading the ruleset and completes the previous commit.

OK sashan sthen


# 1.706 16-Dec-2020 kn

Reject rules with invalid port ranges

Ranges where the left boundary is bigger than the right one are always bogus
as they work like `port any' (`port 34<>12' means "all ports") or in way
that inverts the rule's action (`pass ... port 34:12' means "pass no port at
all").

Add checks for all ranges and invalidate those that yield no or all ports.

For this to work on redirections, make pfctl(8) pass the range's type,
otherwise boundary including ranges are not detected as such; that is to
say, `struct pf_pool's `port_op' member was unused in the kernel so far.

`rdr-to' rules with invalid ranges could panic the kernel when hit.
Reported-by: syzbot+9c309db201f06e39a8ba@syzkaller.appspotmail.com

OK sashan


# 1.705 07-Dec-2020 sashan

synproxy should be processing incoming SYN packets only.
issue noticed by sthen@. fix discussed with bluhm@ and procter@

OK bluhm@, kn@, procter@


# 1.704 01-Oct-2020 kn

rdomain IDs do not need to exist for "on rdomain N" to work

Unlike "... rtable N", pf.conf(5)'s "on rdomain N" does not alter packet
state and will always work no matter if rdomain N currently exists or not,
i.e. the rule "pass on rdomain 42" will simply match (and pass) packets if
rdomain 42 exists, and it will simply not match (neither pass nor block)
packets if 42 does not exist.

There's no need to reload the ruleset whenever routing domains are created
or deleted, which can already be observed now by creating an rdomain,
loading rules referencing it and deleting the same rdomain immediately
afterwards: pf will continue to work as expected.

Relax both pfctl(8)'s parser check as well as pf(4)'s copyin routine to
accept any valid routing domain ID without expecting it to exist at the time
of ruleset creation - this lifts the requirement to create rdomains before
referencing them in pf.conf while keeping pf behaviour unchanged.

Prompted by yasuoka's recent pfctl parse.y r1.702 commit requiring an rtable
to exist upon ruleset creation.

Discussed with claudio and bluhm at k2k20.

Feedback sashan
OK sashan yasouka claudio


Revision tags: OPENBSD_6_8_BASE
# 1.703 17-Sep-2020 yasuoka

Fix the previous commit whose conditions were reversed.

ok kn


# 1.702 17-Sep-2020 yasuoka

Make pfctl(8) check if the rtable really exists when parsing the
config. work with and diff from kn

ok kn


Revision tags: OPENBSD_6_7_BASE
# 1.701 28-Jan-2020 bket

sbin/pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT

OK kn@, sashan@, florian@


# 1.700 15-Jan-2020 kn

Do the actual pfr_strerror() to pf_strerror() rename

Missed in previous


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.713 07-Feb-2023 sashan

internal representation of icmp type/code in pfctl(8)/pf(4) does not
fit into u_int8_t. Issue has been noticed and kindly reported by
amalinin _at_ bh0.amt.ru via bugs@.

OK bluhm@


Revision tags: OPENBSD_7_2_BASE
# 1.712 23-Sep-2022 bluhm

Fix detection of duplicate sticky-address in pf.conf parser.
reported to FreeBSD by Franco Fichtner; from Kristof Provost


Revision tags: OPENBSD_7_1_BASE
# 1.711 25-Oct-2021 sashan

- pfctl $nr incorrect macro expansion

Issue reported by Kristof Provost from FreeBSD.
[ https://reviews.freebsd.org/D32488 ]

In order to fix the issue we must delay '$nr' macro
expansion after optimizer collapses ruleset.

OK kn@


# 1.710 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.709 01-Feb-2021 dlg

change route-to so it sends packets to IPs instead of interfaces.

this is a significant (and breaking) reworking of the policy based
routing that pf can do. the intention is to make it as easy as
nat/rdr to use, and more robust when it's operating.

the main reasons for this change are:

- route-to, reply-to, and dup-to do not work with pfsync

this is because the information about where to route-to is stored in
rules, and it is hard to have a ruleset synced between firewalls,
and impossible to have them synced 100% of the time.

- i can make my boxes panic in certain situations using route-to

yeah...

- the configuration and syntax for route-to rules are confusing.

the argument to route-to and co is an interace name with an optional
ip address. there are several problems with this. one is that people
tend to think about routing as sending packets to peers by their
address, not by the interface they're reachable on. another is that
we currently have no way to synchronise interface topology information
between firewalls, so using an interface to say where packets go
means we can't do failover of these states with pfsync. another
is that a change in routing topology means a host may become
reachable over a different interface. tying routing policy to
interfaces gets in the way of failover and load balancing.

this change does the following:

- stores the route info in the state instead of the pf rule

this allows route-to to keep working when the ruleset changes, and
allows route-to info to be sent over pfsync. there's enough spare bits
in pfsync messages that the protocol doesnt break.

the caveat is that route-to becomes tied to pass rules that create
state, like rdr-to and nat-to.

- the argument to route-to etc is a destination ip address

it's not limited to a next-hop address (thought a next-hop can be a
destination address). this allows for the failover and load balancing
referred to above.

- deprecates the address@interface host syntax in pfctl

because routing is done entirely by IPs, the interface is derived from
the route lookup, not pf. any attempt to use the @interface syntax
will fail now in all contexts.

there's enthusiasm from proctor@ jmatthew@ and others
ok sashan@ bluhm@


# 1.708 12-Jan-2021 bluhm

Sometimes a user ID was logged in pflog(4) although the logopt of
the rule did not specify it. Check the option again for the log
rule in case another rule has triggered a socket lookup. Remove
logopt group, it is not documented and cannot work as struct pfloghdr
does not contain a gid. Rename PF_LOG_SOCKET_LOOKUP to PF_LOG_USER
to express what it does. The lookup involved is only an implemntation
detail.
OK kn@ sashan@ mvs@


# 1.707 16-Dec-2020 kn

Fail to parse rules with invalid ranges

This makes pfctl(8) detect bogus ranges (with and without `-n') before
loading the ruleset and completes the previous commit.

OK sashan sthen


# 1.706 16-Dec-2020 kn

Reject rules with invalid port ranges

Ranges where the left boundary is bigger than the right one are always bogus
as they work like `port any' (`port 34<>12' means "all ports") or in way
that inverts the rule's action (`pass ... port 34:12' means "pass no port at
all").

Add checks for all ranges and invalidate those that yield no or all ports.

For this to work on redirections, make pfctl(8) pass the range's type,
otherwise boundary including ranges are not detected as such; that is to
say, `struct pf_pool's `port_op' member was unused in the kernel so far.

`rdr-to' rules with invalid ranges could panic the kernel when hit.
Reported-by: syzbot+9c309db201f06e39a8ba@syzkaller.appspotmail.com

OK sashan


# 1.705 07-Dec-2020 sashan

synproxy should be processing incoming SYN packets only.
issue noticed by sthen@. fix discussed with bluhm@ and procter@

OK bluhm@, kn@, procter@


# 1.704 01-Oct-2020 kn

rdomain IDs do not need to exist for "on rdomain N" to work

Unlike "... rtable N", pf.conf(5)'s "on rdomain N" does not alter packet
state and will always work no matter if rdomain N currently exists or not,
i.e. the rule "pass on rdomain 42" will simply match (and pass) packets if
rdomain 42 exists, and it will simply not match (neither pass nor block)
packets if 42 does not exist.

There's no need to reload the ruleset whenever routing domains are created
or deleted, which can already be observed now by creating an rdomain,
loading rules referencing it and deleting the same rdomain immediately
afterwards: pf will continue to work as expected.

Relax both pfctl(8)'s parser check as well as pf(4)'s copyin routine to
accept any valid routing domain ID without expecting it to exist at the time
of ruleset creation - this lifts the requirement to create rdomains before
referencing them in pf.conf while keeping pf behaviour unchanged.

Prompted by yasuoka's recent pfctl parse.y r1.702 commit requiring an rtable
to exist upon ruleset creation.

Discussed with claudio and bluhm at k2k20.

Feedback sashan
OK sashan yasouka claudio


Revision tags: OPENBSD_6_8_BASE
# 1.703 17-Sep-2020 yasuoka

Fix the previous commit whose conditions were reversed.

ok kn


# 1.702 17-Sep-2020 yasuoka

Make pfctl(8) check if the rtable really exists when parsing the
config. work with and diff from kn

ok kn


Revision tags: OPENBSD_6_7_BASE
# 1.701 28-Jan-2020 bket

sbin/pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT

OK kn@, sashan@, florian@


# 1.700 15-Jan-2020 kn

Do the actual pfr_strerror() to pf_strerror() rename

Missed in previous


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.712 23-Sep-2022 bluhm

Fix detection of duplicate sticky-address in pf.conf parser.
reported to FreeBSD by Franco Fichtner; from Kristof Provost


Revision tags: OPENBSD_7_1_BASE
# 1.711 25-Oct-2021 sashan

- pfctl $nr incorrect macro expansion

Issue reported by Kristof Provost from FreeBSD.
[ https://reviews.freebsd.org/D32488 ]

In order to fix the issue we must delay '$nr' macro
expansion after optimizer collapses ruleset.

OK kn@


# 1.710 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.709 01-Feb-2021 dlg

change route-to so it sends packets to IPs instead of interfaces.

this is a significant (and breaking) reworking of the policy based
routing that pf can do. the intention is to make it as easy as
nat/rdr to use, and more robust when it's operating.

the main reasons for this change are:

- route-to, reply-to, and dup-to do not work with pfsync

this is because the information about where to route-to is stored in
rules, and it is hard to have a ruleset synced between firewalls,
and impossible to have them synced 100% of the time.

- i can make my boxes panic in certain situations using route-to

yeah...

- the configuration and syntax for route-to rules are confusing.

the argument to route-to and co is an interace name with an optional
ip address. there are several problems with this. one is that people
tend to think about routing as sending packets to peers by their
address, not by the interface they're reachable on. another is that
we currently have no way to synchronise interface topology information
between firewalls, so using an interface to say where packets go
means we can't do failover of these states with pfsync. another
is that a change in routing topology means a host may become
reachable over a different interface. tying routing policy to
interfaces gets in the way of failover and load balancing.

this change does the following:

- stores the route info in the state instead of the pf rule

this allows route-to to keep working when the ruleset changes, and
allows route-to info to be sent over pfsync. there's enough spare bits
in pfsync messages that the protocol doesnt break.

the caveat is that route-to becomes tied to pass rules that create
state, like rdr-to and nat-to.

- the argument to route-to etc is a destination ip address

it's not limited to a next-hop address (thought a next-hop can be a
destination address). this allows for the failover and load balancing
referred to above.

- deprecates the address@interface host syntax in pfctl

because routing is done entirely by IPs, the interface is derived from
the route lookup, not pf. any attempt to use the @interface syntax
will fail now in all contexts.

there's enthusiasm from proctor@ jmatthew@ and others
ok sashan@ bluhm@


# 1.708 12-Jan-2021 bluhm

Sometimes a user ID was logged in pflog(4) although the logopt of
the rule did not specify it. Check the option again for the log
rule in case another rule has triggered a socket lookup. Remove
logopt group, it is not documented and cannot work as struct pfloghdr
does not contain a gid. Rename PF_LOG_SOCKET_LOOKUP to PF_LOG_USER
to express what it does. The lookup involved is only an implemntation
detail.
OK kn@ sashan@ mvs@


# 1.707 16-Dec-2020 kn

Fail to parse rules with invalid ranges

This makes pfctl(8) detect bogus ranges (with and without `-n') before
loading the ruleset and completes the previous commit.

OK sashan sthen


# 1.706 16-Dec-2020 kn

Reject rules with invalid port ranges

Ranges where the left boundary is bigger than the right one are always bogus
as they work like `port any' (`port 34<>12' means "all ports") or in way
that inverts the rule's action (`pass ... port 34:12' means "pass no port at
all").

Add checks for all ranges and invalidate those that yield no or all ports.

For this to work on redirections, make pfctl(8) pass the range's type,
otherwise boundary including ranges are not detected as such; that is to
say, `struct pf_pool's `port_op' member was unused in the kernel so far.

`rdr-to' rules with invalid ranges could panic the kernel when hit.
Reported-by: syzbot+9c309db201f06e39a8ba@syzkaller.appspotmail.com

OK sashan


# 1.705 07-Dec-2020 sashan

synproxy should be processing incoming SYN packets only.
issue noticed by sthen@. fix discussed with bluhm@ and procter@

OK bluhm@, kn@, procter@


# 1.704 01-Oct-2020 kn

rdomain IDs do not need to exist for "on rdomain N" to work

Unlike "... rtable N", pf.conf(5)'s "on rdomain N" does not alter packet
state and will always work no matter if rdomain N currently exists or not,
i.e. the rule "pass on rdomain 42" will simply match (and pass) packets if
rdomain 42 exists, and it will simply not match (neither pass nor block)
packets if 42 does not exist.

There's no need to reload the ruleset whenever routing domains are created
or deleted, which can already be observed now by creating an rdomain,
loading rules referencing it and deleting the same rdomain immediately
afterwards: pf will continue to work as expected.

Relax both pfctl(8)'s parser check as well as pf(4)'s copyin routine to
accept any valid routing domain ID without expecting it to exist at the time
of ruleset creation - this lifts the requirement to create rdomains before
referencing them in pf.conf while keeping pf behaviour unchanged.

Prompted by yasuoka's recent pfctl parse.y r1.702 commit requiring an rtable
to exist upon ruleset creation.

Discussed with claudio and bluhm at k2k20.

Feedback sashan
OK sashan yasouka claudio


Revision tags: OPENBSD_6_8_BASE
# 1.703 17-Sep-2020 yasuoka

Fix the previous commit whose conditions were reversed.

ok kn


# 1.702 17-Sep-2020 yasuoka

Make pfctl(8) check if the rtable really exists when parsing the
config. work with and diff from kn

ok kn


Revision tags: OPENBSD_6_7_BASE
# 1.701 28-Jan-2020 bket

sbin/pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT

OK kn@, sashan@, florian@


# 1.700 15-Jan-2020 kn

Do the actual pfr_strerror() to pf_strerror() rename

Missed in previous


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.711 25-Oct-2021 sashan

- pfctl $nr incorrect macro expansion

Issue reported by Kristof Provost from FreeBSD.
[ https://reviews.freebsd.org/D32488 ]

In order to fix the issue we must delay '$nr' macro
expansion after optimizer collapses ruleset.

OK kn@


# 1.710 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.709 01-Feb-2021 dlg

change route-to so it sends packets to IPs instead of interfaces.

this is a significant (and breaking) reworking of the policy based
routing that pf can do. the intention is to make it as easy as
nat/rdr to use, and more robust when it's operating.

the main reasons for this change are:

- route-to, reply-to, and dup-to do not work with pfsync

this is because the information about where to route-to is stored in
rules, and it is hard to have a ruleset synced between firewalls,
and impossible to have them synced 100% of the time.

- i can make my boxes panic in certain situations using route-to

yeah...

- the configuration and syntax for route-to rules are confusing.

the argument to route-to and co is an interace name with an optional
ip address. there are several problems with this. one is that people
tend to think about routing as sending packets to peers by their
address, not by the interface they're reachable on. another is that
we currently have no way to synchronise interface topology information
between firewalls, so using an interface to say where packets go
means we can't do failover of these states with pfsync. another
is that a change in routing topology means a host may become
reachable over a different interface. tying routing policy to
interfaces gets in the way of failover and load balancing.

this change does the following:

- stores the route info in the state instead of the pf rule

this allows route-to to keep working when the ruleset changes, and
allows route-to info to be sent over pfsync. there's enough spare bits
in pfsync messages that the protocol doesnt break.

the caveat is that route-to becomes tied to pass rules that create
state, like rdr-to and nat-to.

- the argument to route-to etc is a destination ip address

it's not limited to a next-hop address (thought a next-hop can be a
destination address). this allows for the failover and load balancing
referred to above.

- deprecates the address@interface host syntax in pfctl

because routing is done entirely by IPs, the interface is derived from
the route lookup, not pf. any attempt to use the @interface syntax
will fail now in all contexts.

there's enthusiasm from proctor@ jmatthew@ and others
ok sashan@ bluhm@


# 1.708 12-Jan-2021 bluhm

Sometimes a user ID was logged in pflog(4) although the logopt of
the rule did not specify it. Check the option again for the log
rule in case another rule has triggered a socket lookup. Remove
logopt group, it is not documented and cannot work as struct pfloghdr
does not contain a gid. Rename PF_LOG_SOCKET_LOOKUP to PF_LOG_USER
to express what it does. The lookup involved is only an implemntation
detail.
OK kn@ sashan@ mvs@


# 1.707 16-Dec-2020 kn

Fail to parse rules with invalid ranges

This makes pfctl(8) detect bogus ranges (with and without `-n') before
loading the ruleset and completes the previous commit.

OK sashan sthen


# 1.706 16-Dec-2020 kn

Reject rules with invalid port ranges

Ranges where the left boundary is bigger than the right one are always bogus
as they work like `port any' (`port 34<>12' means "all ports") or in way
that inverts the rule's action (`pass ... port 34:12' means "pass no port at
all").

Add checks for all ranges and invalidate those that yield no or all ports.

For this to work on redirections, make pfctl(8) pass the range's type,
otherwise boundary including ranges are not detected as such; that is to
say, `struct pf_pool's `port_op' member was unused in the kernel so far.

`rdr-to' rules with invalid ranges could panic the kernel when hit.
Reported-by: syzbot+9c309db201f06e39a8ba@syzkaller.appspotmail.com

OK sashan


# 1.705 07-Dec-2020 sashan

synproxy should be processing incoming SYN packets only.
issue noticed by sthen@. fix discussed with bluhm@ and procter@

OK bluhm@, kn@, procter@


# 1.704 01-Oct-2020 kn

rdomain IDs do not need to exist for "on rdomain N" to work

Unlike "... rtable N", pf.conf(5)'s "on rdomain N" does not alter packet
state and will always work no matter if rdomain N currently exists or not,
i.e. the rule "pass on rdomain 42" will simply match (and pass) packets if
rdomain 42 exists, and it will simply not match (neither pass nor block)
packets if 42 does not exist.

There's no need to reload the ruleset whenever routing domains are created
or deleted, which can already be observed now by creating an rdomain,
loading rules referencing it and deleting the same rdomain immediately
afterwards: pf will continue to work as expected.

Relax both pfctl(8)'s parser check as well as pf(4)'s copyin routine to
accept any valid routing domain ID without expecting it to exist at the time
of ruleset creation - this lifts the requirement to create rdomains before
referencing them in pf.conf while keeping pf behaviour unchanged.

Prompted by yasuoka's recent pfctl parse.y r1.702 commit requiring an rtable
to exist upon ruleset creation.

Discussed with claudio and bluhm at k2k20.

Feedback sashan
OK sashan yasouka claudio


Revision tags: OPENBSD_6_8_BASE
# 1.703 17-Sep-2020 yasuoka

Fix the previous commit whose conditions were reversed.

ok kn


# 1.702 17-Sep-2020 yasuoka

Make pfctl(8) check if the rtable really exists when parsing the
config. work with and diff from kn

ok kn


Revision tags: OPENBSD_6_7_BASE
# 1.701 28-Jan-2020 bket

sbin/pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT

OK kn@, sashan@, florian@


# 1.700 15-Jan-2020 kn

Do the actual pfr_strerror() to pf_strerror() rename

Missed in previous


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.710 15-Oct-2021 naddy

Don't declare variables as "unsigned char *" that are passed to
functions that take "char *" arguments. Where such chars are
assigned to int or passed to ctype functions, explicitly cast them
to unsigned char.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when the parse.y code was built elsewhere, the compiler would
complain.

With help from millert@
ok benno@ deraadt@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.709 01-Feb-2021 dlg

change route-to so it sends packets to IPs instead of interfaces.

this is a significant (and breaking) reworking of the policy based
routing that pf can do. the intention is to make it as easy as
nat/rdr to use, and more robust when it's operating.

the main reasons for this change are:

- route-to, reply-to, and dup-to do not work with pfsync

this is because the information about where to route-to is stored in
rules, and it is hard to have a ruleset synced between firewalls,
and impossible to have them synced 100% of the time.

- i can make my boxes panic in certain situations using route-to

yeah...

- the configuration and syntax for route-to rules are confusing.

the argument to route-to and co is an interace name with an optional
ip address. there are several problems with this. one is that people
tend to think about routing as sending packets to peers by their
address, not by the interface they're reachable on. another is that
we currently have no way to synchronise interface topology information
between firewalls, so using an interface to say where packets go
means we can't do failover of these states with pfsync. another
is that a change in routing topology means a host may become
reachable over a different interface. tying routing policy to
interfaces gets in the way of failover and load balancing.

this change does the following:

- stores the route info in the state instead of the pf rule

this allows route-to to keep working when the ruleset changes, and
allows route-to info to be sent over pfsync. there's enough spare bits
in pfsync messages that the protocol doesnt break.

the caveat is that route-to becomes tied to pass rules that create
state, like rdr-to and nat-to.

- the argument to route-to etc is a destination ip address

it's not limited to a next-hop address (thought a next-hop can be a
destination address). this allows for the failover and load balancing
referred to above.

- deprecates the address@interface host syntax in pfctl

because routing is done entirely by IPs, the interface is derived from
the route lookup, not pf. any attempt to use the @interface syntax
will fail now in all contexts.

there's enthusiasm from proctor@ jmatthew@ and others
ok sashan@ bluhm@


# 1.708 12-Jan-2021 bluhm

Sometimes a user ID was logged in pflog(4) although the logopt of
the rule did not specify it. Check the option again for the log
rule in case another rule has triggered a socket lookup. Remove
logopt group, it is not documented and cannot work as struct pfloghdr
does not contain a gid. Rename PF_LOG_SOCKET_LOOKUP to PF_LOG_USER
to express what it does. The lookup involved is only an implemntation
detail.
OK kn@ sashan@ mvs@


# 1.707 16-Dec-2020 kn

Fail to parse rules with invalid ranges

This makes pfctl(8) detect bogus ranges (with and without `-n') before
loading the ruleset and completes the previous commit.

OK sashan sthen


# 1.706 16-Dec-2020 kn

Reject rules with invalid port ranges

Ranges where the left boundary is bigger than the right one are always bogus
as they work like `port any' (`port 34<>12' means "all ports") or in way
that inverts the rule's action (`pass ... port 34:12' means "pass no port at
all").

Add checks for all ranges and invalidate those that yield no or all ports.

For this to work on redirections, make pfctl(8) pass the range's type,
otherwise boundary including ranges are not detected as such; that is to
say, `struct pf_pool's `port_op' member was unused in the kernel so far.

`rdr-to' rules with invalid ranges could panic the kernel when hit.
Reported-by: syzbot+9c309db201f06e39a8ba@syzkaller.appspotmail.com

OK sashan


# 1.705 07-Dec-2020 sashan

synproxy should be processing incoming SYN packets only.
issue noticed by sthen@. fix discussed with bluhm@ and procter@

OK bluhm@, kn@, procter@


# 1.704 01-Oct-2020 kn

rdomain IDs do not need to exist for "on rdomain N" to work

Unlike "... rtable N", pf.conf(5)'s "on rdomain N" does not alter packet
state and will always work no matter if rdomain N currently exists or not,
i.e. the rule "pass on rdomain 42" will simply match (and pass) packets if
rdomain 42 exists, and it will simply not match (neither pass nor block)
packets if 42 does not exist.

There's no need to reload the ruleset whenever routing domains are created
or deleted, which can already be observed now by creating an rdomain,
loading rules referencing it and deleting the same rdomain immediately
afterwards: pf will continue to work as expected.

Relax both pfctl(8)'s parser check as well as pf(4)'s copyin routine to
accept any valid routing domain ID without expecting it to exist at the time
of ruleset creation - this lifts the requirement to create rdomains before
referencing them in pf.conf while keeping pf behaviour unchanged.

Prompted by yasuoka's recent pfctl parse.y r1.702 commit requiring an rtable
to exist upon ruleset creation.

Discussed with claudio and bluhm at k2k20.

Feedback sashan
OK sashan yasouka claudio


Revision tags: OPENBSD_6_8_BASE
# 1.703 17-Sep-2020 yasuoka

Fix the previous commit whose conditions were reversed.

ok kn


# 1.702 17-Sep-2020 yasuoka

Make pfctl(8) check if the rtable really exists when parsing the
config. work with and diff from kn

ok kn


Revision tags: OPENBSD_6_7_BASE
# 1.701 28-Jan-2020 bket

sbin/pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT

OK kn@, sashan@, florian@


# 1.700 15-Jan-2020 kn

Do the actual pfr_strerror() to pf_strerror() rename

Missed in previous


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.709 01-Feb-2021 dlg

change route-to so it sends packets to IPs instead of interfaces.

this is a significant (and breaking) reworking of the policy based
routing that pf can do. the intention is to make it as easy as
nat/rdr to use, and more robust when it's operating.

the main reasons for this change are:

- route-to, reply-to, and dup-to do not work with pfsync

this is because the information about where to route-to is stored in
rules, and it is hard to have a ruleset synced between firewalls,
and impossible to have them synced 100% of the time.

- i can make my boxes panic in certain situations using route-to

yeah...

- the configuration and syntax for route-to rules are confusing.

the argument to route-to and co is an interace name with an optional
ip address. there are several problems with this. one is that people
tend to think about routing as sending packets to peers by their
address, not by the interface they're reachable on. another is that
we currently have no way to synchronise interface topology information
between firewalls, so using an interface to say where packets go
means we can't do failover of these states with pfsync. another
is that a change in routing topology means a host may become
reachable over a different interface. tying routing policy to
interfaces gets in the way of failover and load balancing.

this change does the following:

- stores the route info in the state instead of the pf rule

this allows route-to to keep working when the ruleset changes, and
allows route-to info to be sent over pfsync. there's enough spare bits
in pfsync messages that the protocol doesnt break.

the caveat is that route-to becomes tied to pass rules that create
state, like rdr-to and nat-to.

- the argument to route-to etc is a destination ip address

it's not limited to a next-hop address (thought a next-hop can be a
destination address). this allows for the failover and load balancing
referred to above.

- deprecates the address@interface host syntax in pfctl

because routing is done entirely by IPs, the interface is derived from
the route lookup, not pf. any attempt to use the @interface syntax
will fail now in all contexts.

there's enthusiasm from proctor@ jmatthew@ and others
ok sashan@ bluhm@


# 1.708 12-Jan-2021 bluhm

Sometimes a user ID was logged in pflog(4) although the logopt of
the rule did not specify it. Check the option again for the log
rule in case another rule has triggered a socket lookup. Remove
logopt group, it is not documented and cannot work as struct pfloghdr
does not contain a gid. Rename PF_LOG_SOCKET_LOOKUP to PF_LOG_USER
to express what it does. The lookup involved is only an implemntation
detail.
OK kn@ sashan@ mvs@


# 1.707 16-Dec-2020 kn

Fail to parse rules with invalid ranges

This makes pfctl(8) detect bogus ranges (with and without `-n') before
loading the ruleset and completes the previous commit.

OK sashan sthen


# 1.706 16-Dec-2020 kn

Reject rules with invalid port ranges

Ranges where the left boundary is bigger than the right one are always bogus
as they work like `port any' (`port 34<>12' means "all ports") or in way
that inverts the rule's action (`pass ... port 34:12' means "pass no port at
all").

Add checks for all ranges and invalidate those that yield no or all ports.

For this to work on redirections, make pfctl(8) pass the range's type,
otherwise boundary including ranges are not detected as such; that is to
say, `struct pf_pool's `port_op' member was unused in the kernel so far.

`rdr-to' rules with invalid ranges could panic the kernel when hit.
Reported-by: syzbot+9c309db201f06e39a8ba@syzkaller.appspotmail.com

OK sashan


# 1.705 07-Dec-2020 sashan

synproxy should be processing incoming SYN packets only.
issue noticed by sthen@. fix discussed with bluhm@ and procter@

OK bluhm@, kn@, procter@


# 1.704 01-Oct-2020 kn

rdomain IDs do not need to exist for "on rdomain N" to work

Unlike "... rtable N", pf.conf(5)'s "on rdomain N" does not alter packet
state and will always work no matter if rdomain N currently exists or not,
i.e. the rule "pass on rdomain 42" will simply match (and pass) packets if
rdomain 42 exists, and it will simply not match (neither pass nor block)
packets if 42 does not exist.

There's no need to reload the ruleset whenever routing domains are created
or deleted, which can already be observed now by creating an rdomain,
loading rules referencing it and deleting the same rdomain immediately
afterwards: pf will continue to work as expected.

Relax both pfctl(8)'s parser check as well as pf(4)'s copyin routine to
accept any valid routing domain ID without expecting it to exist at the time
of ruleset creation - this lifts the requirement to create rdomains before
referencing them in pf.conf while keeping pf behaviour unchanged.

Prompted by yasuoka's recent pfctl parse.y r1.702 commit requiring an rtable
to exist upon ruleset creation.

Discussed with claudio and bluhm at k2k20.

Feedback sashan
OK sashan yasouka claudio


Revision tags: OPENBSD_6_8_BASE
# 1.703 17-Sep-2020 yasuoka

Fix the previous commit whose conditions were reversed.

ok kn


# 1.702 17-Sep-2020 yasuoka

Make pfctl(8) check if the rtable really exists when parsing the
config. work with and diff from kn

ok kn


Revision tags: OPENBSD_6_7_BASE
# 1.701 28-Jan-2020 bket

sbin/pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT

OK kn@, sashan@, florian@


# 1.700 15-Jan-2020 kn

Do the actual pfr_strerror() to pf_strerror() rename

Missed in previous


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.708 12-Jan-2021 bluhm

Sometimes a user ID was logged in pflog(4) although the logopt of
the rule did not specify it. Check the option again for the log
rule in case another rule has triggered a socket lookup. Remove
logopt group, it is not documented and cannot work as struct pfloghdr
does not contain a gid. Rename PF_LOG_SOCKET_LOOKUP to PF_LOG_USER
to express what it does. The lookup involved is only an implemntation
detail.
OK kn@ sashan@ mvs@


# 1.707 16-Dec-2020 kn

Fail to parse rules with invalid ranges

This makes pfctl(8) detect bogus ranges (with and without `-n') before
loading the ruleset and completes the previous commit.

OK sashan sthen


# 1.706 16-Dec-2020 kn

Reject rules with invalid port ranges

Ranges where the left boundary is bigger than the right one are always bogus
as they work like `port any' (`port 34<>12' means "all ports") or in way
that inverts the rule's action (`pass ... port 34:12' means "pass no port at
all").

Add checks for all ranges and invalidate those that yield no or all ports.

For this to work on redirections, make pfctl(8) pass the range's type,
otherwise boundary including ranges are not detected as such; that is to
say, `struct pf_pool's `port_op' member was unused in the kernel so far.

`rdr-to' rules with invalid ranges could panic the kernel when hit.
Reported-by: syzbot+9c309db201f06e39a8ba@syzkaller.appspotmail.com

OK sashan


# 1.705 07-Dec-2020 sashan

synproxy should be processing incoming SYN packets only.
issue noticed by sthen@. fix discussed with bluhm@ and procter@

OK bluhm@, kn@, procter@


# 1.704 01-Oct-2020 kn

rdomain IDs do not need to exist for "on rdomain N" to work

Unlike "... rtable N", pf.conf(5)'s "on rdomain N" does not alter packet
state and will always work no matter if rdomain N currently exists or not,
i.e. the rule "pass on rdomain 42" will simply match (and pass) packets if
rdomain 42 exists, and it will simply not match (neither pass nor block)
packets if 42 does not exist.

There's no need to reload the ruleset whenever routing domains are created
or deleted, which can already be observed now by creating an rdomain,
loading rules referencing it and deleting the same rdomain immediately
afterwards: pf will continue to work as expected.

Relax both pfctl(8)'s parser check as well as pf(4)'s copyin routine to
accept any valid routing domain ID without expecting it to exist at the time
of ruleset creation - this lifts the requirement to create rdomains before
referencing them in pf.conf while keeping pf behaviour unchanged.

Prompted by yasuoka's recent pfctl parse.y r1.702 commit requiring an rtable
to exist upon ruleset creation.

Discussed with claudio and bluhm at k2k20.

Feedback sashan
OK sashan yasouka claudio


Revision tags: OPENBSD_6_8_BASE
# 1.703 17-Sep-2020 yasuoka

Fix the previous commit whose conditions were reversed.

ok kn


# 1.702 17-Sep-2020 yasuoka

Make pfctl(8) check if the rtable really exists when parsing the
config. work with and diff from kn

ok kn


Revision tags: OPENBSD_6_7_BASE
# 1.701 28-Jan-2020 bket

sbin/pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT

OK kn@, sashan@, florian@


# 1.700 15-Jan-2020 kn

Do the actual pfr_strerror() to pf_strerror() rename

Missed in previous


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.707 16-Dec-2020 kn

Fail to parse rules with invalid ranges

This makes pfctl(8) detect bogus ranges (with and without `-n') before
loading the ruleset and completes the previous commit.

OK sashan sthen


# 1.706 16-Dec-2020 kn

Reject rules with invalid port ranges

Ranges where the left boundary is bigger than the right one are always bogus
as they work like `port any' (`port 34<>12' means "all ports") or in way
that inverts the rule's action (`pass ... port 34:12' means "pass no port at
all").

Add checks for all ranges and invalidate those that yield no or all ports.

For this to work on redirections, make pfctl(8) pass the range's type,
otherwise boundary including ranges are not detected as such; that is to
say, `struct pf_pool's `port_op' member was unused in the kernel so far.

`rdr-to' rules with invalid ranges could panic the kernel when hit.
Reported-by: syzbot+9c309db201f06e39a8ba@syzkaller.appspotmail.com

OK sashan


# 1.705 07-Dec-2020 sashan

synproxy should be processing incoming SYN packets only.
issue noticed by sthen@. fix discussed with bluhm@ and procter@

OK bluhm@, kn@, procter@


# 1.704 01-Oct-2020 kn

rdomain IDs do not need to exist for "on rdomain N" to work

Unlike "... rtable N", pf.conf(5)'s "on rdomain N" does not alter packet
state and will always work no matter if rdomain N currently exists or not,
i.e. the rule "pass on rdomain 42" will simply match (and pass) packets if
rdomain 42 exists, and it will simply not match (neither pass nor block)
packets if 42 does not exist.

There's no need to reload the ruleset whenever routing domains are created
or deleted, which can already be observed now by creating an rdomain,
loading rules referencing it and deleting the same rdomain immediately
afterwards: pf will continue to work as expected.

Relax both pfctl(8)'s parser check as well as pf(4)'s copyin routine to
accept any valid routing domain ID without expecting it to exist at the time
of ruleset creation - this lifts the requirement to create rdomains before
referencing them in pf.conf while keeping pf behaviour unchanged.

Prompted by yasuoka's recent pfctl parse.y r1.702 commit requiring an rtable
to exist upon ruleset creation.

Discussed with claudio and bluhm at k2k20.

Feedback sashan
OK sashan yasouka claudio


Revision tags: OPENBSD_6_8_BASE
# 1.703 17-Sep-2020 yasuoka

Fix the previous commit whose conditions were reversed.

ok kn


# 1.702 17-Sep-2020 yasuoka

Make pfctl(8) check if the rtable really exists when parsing the
config. work with and diff from kn

ok kn


Revision tags: OPENBSD_6_7_BASE
# 1.701 28-Jan-2020 bket

sbin/pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT

OK kn@, sashan@, florian@


# 1.700 15-Jan-2020 kn

Do the actual pfr_strerror() to pf_strerror() rename

Missed in previous


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.705 07-Dec-2020 sashan

synproxy should be processing incoming SYN packets only.
issue noticed by sthen@. fix discussed with bluhm@ and procter@

OK bluhm@, kn@, procter@


# 1.704 01-Oct-2020 kn

rdomain IDs do not need to exist for "on rdomain N" to work

Unlike "... rtable N", pf.conf(5)'s "on rdomain N" does not alter packet
state and will always work no matter if rdomain N currently exists or not,
i.e. the rule "pass on rdomain 42" will simply match (and pass) packets if
rdomain 42 exists, and it will simply not match (neither pass nor block)
packets if 42 does not exist.

There's no need to reload the ruleset whenever routing domains are created
or deleted, which can already be observed now by creating an rdomain,
loading rules referencing it and deleting the same rdomain immediately
afterwards: pf will continue to work as expected.

Relax both pfctl(8)'s parser check as well as pf(4)'s copyin routine to
accept any valid routing domain ID without expecting it to exist at the time
of ruleset creation - this lifts the requirement to create rdomains before
referencing them in pf.conf while keeping pf behaviour unchanged.

Prompted by yasuoka's recent pfctl parse.y r1.702 commit requiring an rtable
to exist upon ruleset creation.

Discussed with claudio and bluhm at k2k20.

Feedback sashan
OK sashan yasouka claudio


Revision tags: OPENBSD_6_8_BASE
# 1.703 17-Sep-2020 yasuoka

Fix the previous commit whose conditions were reversed.

ok kn


# 1.702 17-Sep-2020 yasuoka

Make pfctl(8) check if the rtable really exists when parsing the
config. work with and diff from kn

ok kn


Revision tags: OPENBSD_6_7_BASE
# 1.701 28-Jan-2020 bket

sbin/pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT

OK kn@, sashan@, florian@


# 1.700 15-Jan-2020 kn

Do the actual pfr_strerror() to pf_strerror() rename

Missed in previous


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.704 01-Oct-2020 kn

rdomain IDs do not need to exist for "on rdomain N" to work

Unlike "... rtable N", pf.conf(5)'s "on rdomain N" does not alter packet
state and will always work no matter if rdomain N currently exists or not,
i.e. the rule "pass on rdomain 42" will simply match (and pass) packets if
rdomain 42 exists, and it will simply not match (neither pass nor block)
packets if 42 does not exist.

There's no need to reload the ruleset whenever routing domains are created
or deleted, which can already be observed now by creating an rdomain,
loading rules referencing it and deleting the same rdomain immediately
afterwards: pf will continue to work as expected.

Relax both pfctl(8)'s parser check as well as pf(4)'s copyin routine to
accept any valid routing domain ID without expecting it to exist at the time
of ruleset creation - this lifts the requirement to create rdomains before
referencing them in pf.conf while keeping pf behaviour unchanged.

Prompted by yasuoka's recent pfctl parse.y r1.702 commit requiring an rtable
to exist upon ruleset creation.

Discussed with claudio and bluhm at k2k20.

Feedback sashan
OK sashan yasouka claudio


Revision tags: OPENBSD_6_8_BASE
# 1.703 17-Sep-2020 yasuoka

Fix the previous commit whose conditions were reversed.

ok kn


# 1.702 17-Sep-2020 yasuoka

Make pfctl(8) check if the rtable really exists when parsing the
config. work with and diff from kn

ok kn


Revision tags: OPENBSD_6_7_BASE
# 1.701 28-Jan-2020 bket

sbin/pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT

OK kn@, sashan@, florian@


# 1.700 15-Jan-2020 kn

Do the actual pfr_strerror() to pf_strerror() rename

Missed in previous


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.703 17-Sep-2020 yasuoka

Fix the previous commit whose conditions were reversed.

ok kn


# 1.702 17-Sep-2020 yasuoka

Make pfctl(8) check if the rtable really exists when parsing the
config. work with and diff from kn

ok kn


Revision tags: OPENBSD_6_7_BASE
# 1.701 28-Jan-2020 bket

sbin/pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT

OK kn@, sashan@, florian@


# 1.700 15-Jan-2020 kn

Do the actual pfr_strerror() to pf_strerror() rename

Missed in previous


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.701 28-Jan-2020 bket

sbin/pfctl: replace TAILQ concatenation loop with TAILQ_CONCAT

OK kn@, sashan@, florian@


# 1.700 15-Jan-2020 kn

Do the actual pfr_strerror() to pf_strerror() rename

Missed in previous


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.700 15-Jan-2020 kn

Do the actual pfr_strerror() to pf_strerror() rename

Missed in previous


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.699 17-Oct-2019 millert

Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.
This is the userland portion. OK deraadt@ sashan@


Revision tags: OPENBSD_6_6_BASE
# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.698 26-Aug-2019 tobhe

Fix file descriptor leak due to popfile() never closing the main config file.

The fix is the same as for other parse.y files in the tree (see bgpd(8) or
unwind(8))

ok bluhm@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.697 05-Jul-2019 patrick

Fix integer sizes in format strings and enable formatting warnings
for yyerror.

From Moritz Buhl
ok bluhm@ claudio@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.696 08-May-2019 sashan

pfctl should check pfctl.astack is not overrun
(bug found and fixed by Petr Hoffmann _at_ oracle.com)

OK kn@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.695 18-Apr-2019 kn

Fix table definition parsing as unprivileged user

revision 1.689 introduced warn_duplicate_tables() unconditionally, breaking
the parser on tables withs insufficient permissions to open pf(4):

$ echo 'table <t>' | pfctl -nf-
pfctl: pfr_get_tables: Bad file descriptor

So simply check whether pfctl is able to get the table list first. If not,
instead of silently avoiding namespace collision checks, print a brief
notice iff `-v' is given to help finding duplicate definitions by hand:

$ echo 'table <t>' | ./obj/pfctl -vnf-
table <t>
stdin:1: skipping duplicate table checks for <t>

Reported by Rivo Nurges, thanks!
OK benno sashan


Revision tags: OPENBSD_6_5_BASE
# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.694 06-Mar-2019 kn

Fix once rules

parse.y revision 1.682 from 16.07.2018 errornously allowed `match once' and
`anchor "a" once'.

Fix both by checking for PF_DROP not PF_MATCH and creating anchors in the
parser already such that they can be used to distinguish anchor rules in
the same check as well.

Found and fixed by Petr Hoffmann <petr.hoffmann at oracle dot com>, thanks!

While here, remove an unneeded cast and make pfctl_add_rule() void as it
always returned 0.

OK sashan


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.693 13-Feb-2019 deraadt

(unsigned) means (unsigned int) which on ptrdiff_t or size_t or other
larger types really is a range reduction...
Almost any cast to (unsigned) is a bug.
ok millert tb benno


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.692 10-Feb-2019 kn

Anchor names must not be empty

The parser would allow bogus input and sometimes even produce invalid rules
on empty anchor names, so error out immediately.

OK sashan


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.691 10-Feb-2019 kn

Unify anchor name sanity checks

For anchor names, make `load anchor' use the same grammar as `anchor' and
merge unique checks from both places so that anchor names are validated
regardless of the specific rule at hand.

OK sashan


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.690 31-Jan-2019 kn

Make divert-packet port accept any port specification

Contrary to other rules accepting a single port, this one only works with
numerical values. Fix it by simply using the proper grammar.

Port ranges are not accepted, but an error message on a range without start
was missing in general, so add it while here.

OK bluhm


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.689 11-Jan-2019 kn

When creating tables inside anchors, pfctl warned about namespace
collisions with global tables, but only in certain cases and with
limited information sometimes leaving users clueless.

Deferring the check to process_tabledefs() where tables are eventually
created, both anchor and table name are known which allows for checking
all existing anchors.

With this, warn on all duplicates even in dry-runs (`-n') and print
quoted names so they can be copied to fix configurations right away.

No functional change in parsing or ruleset production.

Discussed with and OK sashan


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.688 15-Nov-2018 dlg

scrub opts dont set tos, so remove it from the scrub_opts struct

ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@


# 1.687 10-Nov-2018 kn

Unbreak `-D macro=value' (r1.686 regression)

Zap trailing semicolon introduced with miko's cmdline_symset() leading to
unconditional err(3). Zap trailing tab while here.


# 1.686 07-Nov-2018 miko

sync cmdline_symset() changes with src/usr.sbin; OK sashan@ claudio@


# 1.685 01-Nov-2018 sashan

- odd condition/test in PF lexer
(and other lexers too)

This commit rectifies earlier change:

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).

OK deraadt@, OK millert@


Revision tags: OPENBSD_6_4_BASE
# 1.684 16-Sep-2018 millert

Use uid_from_user(3) and gid_from_group(3) in utilities that
do repeated lookups. OK tb@


# 1.683 06-Sep-2018 kn

Remove unused af argument from unmask()

This has been unused for years.

While here, zap the duplicate function signature from pfctl.h (already
present in pfctl_parser.h); spotted by sashan, thanks.

OK sashan


# 1.682 16-Jul-2018 kn

reduce duplicate code, fix typo/free correct buffer

In filteropts_to_rule():

* Merge `once' handling from `anchorrule' and `pfrule'
* Remove/shorten duplicate code block
* Fix typo I introduced with r1.678 that frees the wrong buffer (twice)

OK sashan


# 1.681 13-Jul-2018 kn

Fix regression on child queue definitions

I comitted the wrong diff in 1.680 which turned `queue cq parent pq ...'
into invalid syntax by changing `interface' to `ON if_item'.

Found by bket, thanks!


# 1.680 11-Jul-2018 kn

Prevent invalid interface specifiers on queue rules

pf.conf(5) states that queues attach to actual interfaces only, yet the
following parses:

# echo queue eq on egress bandwidth 1G default | pfctl -f-
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

# echo queue rq on rdomain 0 bandwidth 1G default | pfctl -vf-
queue rq bandwidth 1G default
# pfctl -sq
pfctl: DIOCGETQSTATS: Bad file descriptor

On rdomains, ifa_exists() returns NULL.
On interface groups, ifa_exists() returns non-NULL but af is never set
to AF_LINK.

OK henning sashan


# 1.679 11-Jul-2018 krw

Do for most running out of memory err() what was done for most running
out of memory log_warn(). i.e. ("%s", __func__) instead of manual
function names and redundant verbiage about which wrapper detected the
out of memory condition.

ok henning@


# 1.678 10-Jul-2018 henning

'set delay' for the generic packet delay mechanism, ok benno sashan


# 1.677 10-Jul-2018 kn

fix anchor rules with filter opts, introduce filteropts_to_rule()

Some filter options were parsed but not set on anchor rules due to missing
copies of the respective struct members:

$ cat pf.conf
queue rq on trunk0 bandwidth 1G
queue dq parent rq bandwidth 1G default
anchor a set queue dq
$ pfctl -vnf pf.conf | fgrep queue
anchor "a" all

Fix this by moving common code from `anchorrule' and `pfrule' into a new
helper filteropts_to_rule().

Input from henning and benno
OK henning sashan jca


# 1.676 09-Jul-2018 kn

Zap dead code

Commented since r1.465 (2004).

OK deraadt benno jca sashan


# 1.675 09-Jul-2018 krw

No need to mention which memory allocation entry point failed (malloc,
calloc or strdup), we just need to log that we ran out of memory in a
particular function.

Recommended by florian@ and deraadt@

ok benno@ henning@ tb@


# 1.674 08-Jul-2018 krw

Be consistent in warn() and log_warn() usage when
running out of memory.

Next step, be correct *and* consistent.

ok dennis@ tb@ benno@ schwarze@


# 1.673 18-May-2018 benno

A pf rule with a "on rdomain n" with nonexisting rdomain n will cause an

pfctl: DIOCADDRULE: Device busy

error when loading the ruleset, with no information which rule caused
the problem and no indication that the problem is the rdomain
<nonexisting>.

This diff makes pfctl check if the rdomain really exists when parsing
the config.

ok bluhm@


# 1.672 09-May-2018 otto

Fix (include file ) line number counting by keeping track of the unget
buffer per file; also use that buffer to expand macros.
ok sashan@ dennis@ krw@


# 1.671 26-Apr-2018 krw

Plug leak in error case of the common 'varset' implementations.

ok benno@


Revision tags: OPENBSD_6_3_BASE
# 1.670 08-Feb-2018 henning

make the watermarks/thresholds for entering and leaving syncookie mode when
syncookies are set to adaptive tunable, ok claudio benno


# 1.669 06-Feb-2018 henning

allow control over syncookies: set syncookies never/always/adaptive


# 1.668 28-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Adapt the pf rule struct in kernel and pfctl, no functional change.
Note that kernel and pfctl have to be updated together.
OK sashan@


# 1.667 27-Nov-2017 bluhm

The divert structure was using the port number to indicate that
divert-to or divert-reply was active. If the address was also set,
it meant divert-to. Divert packet used a separate structure. This
is confusing and makes it hard to add new features. It is better
to have a divert type that explicitly says what is configured.
Convert the pfctl(8) rule parser to divert types, kernel cleanup
will be the next step.
OK sashan@


# 1.666 25-Nov-2017 sashan

- pfctl fails to handle nested 'load anchor' properly
[ + yet another 'anchor name vs. path mix up in load anchor (parse.y) ]

OK bluhm@


# 1.665 14-Nov-2017 sashan

- nested anchors vs. pfctl/parse.y
bug reported and fix tested by Leonardo Guardati

OK bluhm@


# 1.664 13-Nov-2017 henning

add a generic packet rate matching filter. allows things like
pass in proto icmp max-pkt-rate 100/10
all packets matching the rule in the direction the state was created are
taken into consideration (typically: requests, but not replies).
Just like with the other max-*, the rule stops matching if the maximum is
reached, so in typical scenarios the default block rule would kick in then.
with input from Holger Mikolon
ok mikeb


Revision tags: OPENBSD_6_2_BASE
# 1.663 11-Aug-2017 benno

add option -N (no domain resolution)
manpage wording and reminder about usage() jmc@
ok florian@ henning@


# 1.662 19-Jul-2017 mikeb

Allow HFSC classes to use flow queues

The FQ-CoDel related configuration (flows, quantum) becomes available
for the regular bandwidth queue. Internally the kernel will pick the
FQ-CoDel for use as a queue manager for the specified class instead of
the FIFO.

Discussed with and OK henning@ at d2k17 as a part of a larger diff.


# 1.661 19-Jul-2017 mikeb

Rework HFSC vs FQ-CoDel checks

The selection mechanism introduced in pf_ioctl.c -r1.316 suffers
from being too ambiguous and lacks robustness. Instead of relying
on composition of multiple flags in the queue specification, it's
easier to identify the root class (if it exists) and derive all
further checks from it.


# 1.660 28-May-2017 akfaew

Don't check np->port for NULL - it's an array, it's never NULL.

OK bluhm@


# 1.659 15-May-2017 mikeb

Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)

OK sthen, visa


# 1.658 28-Apr-2017 mikeb

Remove double assignments


Revision tags: OPENBSD_6_1_BASE
# 1.657 05-Jan-2017 krw

Replace symset()'s hand-rolled for(;;) traversal of 'symhead' TAILQ
with more modern TAILQ_FOREACH(). This what symget() was already
doing.

Add paranoia '{}' around body of symget()'s TAILQ_FOREACH().

No intentional functional change.

ok bluhm@ otto@


# 1.656 23-Nov-2016 bluhm

Explicitly forbid to combine af-to with route-to in pfctl. The
parser cannot handle that correctly and is is unclear wether the
kernel code would work. Remove the feature until someone needs it
and properly implements and tests it.
OK mike@ sashan@ mpi@


# 1.655 26-Aug-2016 guenther

Add <time.h> for time(); sort <*.h> includes

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.654 18-Jul-2016 henning

g/c unused (global!) var: oqueues isn't used any more. ALTQ leftover; not
noticed since struct node_queue stayed. ok claudio benno gcc


# 1.653 22-Jun-2016 kettenis

Add curly braces that were missed in rev 1.651. Add parenthesis to make the
condition in the if statement more readable while I'm there.

ok phessler@, benno@, florian@


# 1.652 21-Jun-2016 benno

do not allow whitespace in macro names, i.e. "this is" = "a variable".
change this in all config parsers in our tree that support macros.
problem reported by sven falempin.

feedback from henning@, stsp@, deraadt@
ok florian@ mikeb@


# 1.651 21-Jun-2016 benno

the manpage documents that af-to does not work on pass out rules, but
the pf.conf parser allows it, which leads a non working configuration
being loaded.
this changes the parser to make pass out .. af-to an error.

ok henning@ mikeb@


# 1.650 16-Jun-2016 henning

allow include in inline anchors
with this,
anchor foo {
include "/path/to/rules"
}
works and "load anchor" is obsolete, to be removed somewhen later after
release.
co-production with reky at bsdcan, ok reyk mikeb benno sasha


Revision tags: OPENBSD_5_9_BASE
# 1.649 01-Sep-2015 sashan

- route-to, dup-to, reply-to should not override the block action

Spotted by Dilli Paudel <dilli ! paudel at oracle ! com>

ok jung@, ok mikeb@


Revision tags: OPENBSD_5_8_BASE
# 1.648 21-Apr-2015 mikeb

Improve divert-to specification parsing w.r.t. rule address family.
ok henning


Revision tags: OPENBSD_5_7_BASE
# 1.647 26-Feb-2015 sthen

%% not % in error message; ok millert@ henning@


# 1.646 14-Feb-2015 sthen

Rather than using 0xff as a placeholder for "don't check prio", use 0xff to
mean "prio is 0". This avoids the need for code changes in programs which add
pf rules (as was done in pfctl but not other programs) to handle the new
"check prio" functionality. Specifically this unbreaks ftp-proxy.

Use of #define rather than magic 0xff suggested by benno.
ok benno "if henning doesnt like it he can change it when he recovers from jet-lag"


# 1.645 10-Feb-2015 henning

since we inherit prio (as in, the queuing priority) from outside sources,
i. e. on vlan interfaces, it is useful to be able to match on it -
effectively matching on classification done elsewhere.
i thought i had long implemented that, but chrisz@ asking for it made
me notice that wasn't the case.
tests by chrisz, ok phessler pelikan


# 1.644 16-Jan-2015 deraadt

Replace <sys/param.h> with <limits.h> and other less dirty headers where
possible. Annotate <sys/param.h> lines with their current reasons. Switch
to PATH_MAX, NGROUPS_MAX, HOST_NAME_MAX+1, LOGIN_NAME_MAX, etc. Change
MIN() and MAX() to local definitions of MINIMUM() and MAXIMUM() where
sensible to avoid pulling in the pollution. These are the files confirmed
through binary verification.
ok guenther, millert, doug (helped with the verification protocol)


# 1.643 19-Dec-2014 reyk

Support source-hash and random with tables and dynifs; not just pools.
This finally allows to use source-hash for dynamic loadbalancing, eg.
"rdr-to <hosts> source-hash", instead of just round-robin and least-states.

An older pre-siphash version of this diff was tested by many people.

OK tedu@ benno@


# 1.642 20-Nov-2014 jsg

Don't allow embedded nul characters in strings.
Fixes a pfctl crash with an anchor name containing
an embedded nul found with the afl fuzzer.

pfctl parse.y patch from and ok deraadt@


# 1.641 27-Oct-2014 mikeb

Fixup incorrect expansion of the networking mask for dynamic interface
specifications under certain circumstances resulting in potentially
elevated access permissions for IPv6 traffic. Reported by sthen@;
ok henning benno sthen


# 1.640 25-Oct-2014 lteo

Remove unnecessary netinet/in_systm.h include.

ok millert@


# 1.639 13-Sep-2014 doug

Replace all queue *_END macro calls except CIRCLEQ_END with NULL.

CIRCLEQ_* is deprecated and not called in the tree. The other queue types
have *_END macros which were added for symmetry with CIRCLEQ_END. They are
defined as NULL. There's no reason to keep the other *_END macro calls.

ok millert@


# 1.638 23-Aug-2014 pelikan

when you specify queues in a rule, make sure they have been defined.

DIOCADDRULE EBUSY turns into an error message that pfctl -n catches.
DIOCXCOMMIT EINVAL after the kernel rejected the rules was reported
to occur, possibly from hfsc.c: this should be fixed as well.

ok henning mikeb sthen


# 1.637 21-Aug-2014 mikeb

deny "once" flags for match rules; ok henning


Revision tags: OPENBSD_5_6_BASE
# 1.636 02-Jul-2014 mikeb

branches: 1.636.4;
condition above makes this part of the check useless;
overlooked in the previous commit


# 1.635 30-Jun-2014 mikeb

Merge two loops in collapse_redirspec into one

This lets us do the checks only once and also make smarter decisions
about the rule's own address family. As a result af-to rules no longer
need to specify the address family after 'pass'.

ok henning


# 1.634 25-Jun-2014 mikeb

Make stricter decisions when handling translation specifications.

In particular, disallow specifications containing addresses of
different address families when rule doesn't specify one, for
example "pass out nat-to { ::1 1.1.1.1 }" will now produce an
error instead of silently picking one of the addresses.

sthen and deraadt agree


# 1.633 17-May-2014 bluhm

When parsing a numerical value for the TOS bits, make sure that it
is in a valid range.
OK henning@


# 1.632 19-Apr-2014 henning

remove altq bits here, too
(i was convinced i committed that yesterday already, hrm)


Revision tags: OPENBSD_5_5_BASE
# 1.631 22-Jan-2014 henning

branches: 1.631.4;
relax the cfg file secrecy check slightly to allow group readability
default permissions and mtree NOT changed.
prodded by benno, ok phessler benno jmatthew theo pelikan florian


# 1.630 21-Jan-2014 henning

if_item can be "any" now.
allows things like
block out on $someif received-on any
to prevent packets to get forwarded to $someif


# 1.629 20-Jan-2014 henning

support "!received-on <interface>", ok dlg benno


# 1.628 25-Nov-2013 benno

use u_char for buffers in yylex, for ctype calls
found by millert@, ok deraadt@


# 1.627 22-Nov-2013 deraadt

Whole bunch of (unsigned char) casts carefully added for ctype calls.
Careful second audit by millert


# 1.626 17-Oct-2013 henning

cannot have queue definitions inside anchors.
don't attempt to load them and err out if we run into one
ran into by Gregor Best <gbe@@ring0.de>, analysis & fix your's truly


# 1.625 12-Oct-2013 henning

config bits for the bandwidth shaping part of the new queueing subsystem
syntax worked out with many in ljubljana using a whiteboard, testing &
looking over by many, ok phessler sthen


# 1.624 01-Aug-2013 mikeb

Provide local implementations of if_nametoindex(3) and if_indextoname(3)
that make use of the cache of addresses populated by the ifa_load on
startup to save the trouble of calling expensive getaddrinfo(3) up to
four times per rule. Performance wise this change provides a speed up
factor of 20 with a 11k line ruleset on a machine with 150 VLANs and 250
IP addresses (20 seconds down to 1 in this case).

"wow!" henning, ok benno, florian


Revision tags: OPENBSD_5_4_BASE
# 1.623 01-Jun-2013 henning

branches: 1.623.2;
remove set-tos backwards compat, moved into the set {} block a year ago
ok ryan


# 1.622 02-Mar-2013 sthen

When a PF rule contains 'set tos' *followed by* a scrub option, the tos
value is changed to 0x00. Left-over from the previous implementation where
set-tos was part of "scrub". Problem reported by Jason Mader, ok henning


Revision tags: OPENBSD_5_3_BASE
# 1.621 16-Jan-2013 henning

for consistency with prio etc, the queue assignment really belongs
into the set block. so make pfctl accept, print and the manpage document
. match set queue foo
instead of
. match queue foo
but keep accepting the old way without the explicit set.
ok bob, man jmc


# 1.620 18-Oct-2012 reyk

Disallow tables and interface address pools for rdr-to, nat-to and
route-to with any other scheduling algorithms than round-robin or
least-states. Before this change, pfctl accepted and loaded invalid
address pools, eg. "rdr-to <table> source-hash", but it is not
supported by the kernel and was silently ignored in operation.

Also clarify the manpage a bit by mentioning that tables are only
valid with round-robin or least-states.

ok zinke@


# 1.619 18-Sep-2012 henning

prio 0 is valid, therefore, I chose an "impossible" value for prio meaning
"not set" and used a PF_PRIO_NOTSET define for it. now that means that
everything that creates a struct pf_rule doesn't get away with bzero'ing it,
which turned out to be not so nice. so get rid of PF_PRIO_NOTSET, instead,
make a rule+state flag PFSTATE_SETPRIO which indicates wether the prio
should be set. ok benno claudio mikeb


Revision tags: OPENBSD_5_2_BASE
# 1.618 10-Jul-2012 bluhm

Allow an implicit address family for af-to rules. If the address
family can be determined by the "from" or "to" parameter in the
matching part, it is no longer necessary to specify "inet" or "inet6"
there.
OK henning@ mikeb@


# 1.617 10-Jul-2012 henning

set { ... } -> set ( ... )
brought up by ryan, discussed with him and theo and they convinced me


# 1.616 09-Jul-2012 henning

fix some of the confusion we have in pf regarding filter criteria vs
options that "write" to the packet by putting the latter in a set { } block.
for now prio and tos, maintain set-tos backwards compat for the moment.
"match set { prio 6, tos lowdelay }"
"match set prio 6"
from a discussion with ryan in tokyo a while ago, ok ryan phessler


# 1.615 07-Jul-2012 henning

remove incorrect check in pfctl preventing set-tos for ipvshit.
the kernel has code to deal with set-tos and that crap. don't ask for
details. stuart ok


# 1.614 07-Jul-2012 henning

rename prio in struct pf_rule and related structs to set_prio so it is
utterly clear this is not a filter criteria but a packet modification thing.
also preparation for upcoming changes, including one to unscrew this mess
(I should not have to touch half the tree for this - ifixitlater)
not user visible, ok gcc


Revision tags: OPENBSD_5_1_BASE
# 1.613 19-Dec-2011 mikeb

unbreak rule optimizer; ok henning, looks


# 1.612 12-Dec-2011 mikeb

fixup af-to regression with match rules

pfctl should not infer the af-to behavior from the af/naf difference.
instead, we should be clear that this is an af-to rule. essentially
this change converts FOM_AFTO marker into a rule flag PFRULE_AFTO so
that we don't rely on ambiguous checks (like r->af != r->naf) when
setting things up.

positive review and comments from claudio, ok henning, sperreault


# 1.611 03-Dec-2011 mcbride

pfctl_set_hostid always returns 0; don't pretend otherwise and make it a
void function instead.

ok dlg


# 1.610 13-Oct-2011 claudio

pfctl change for af-to / NAT64 support.
The general syntax is:
pass in inet from any to 192.168.1.1 af-to inet6 from 2001::1 to 2001::2
In the NAT64 case the "to" is not needed in af-to and the IP is extraced
from the IPv6 dst (assuming a /64 prefix).
Again most work by sperreault@, mikeb@ and reyk@
OK mcbride@, put it in deraadt@


# 1.609 07-Sep-2011 haesbaert

Avoid possible SIGSEGV when wrong tos option.


# 1.608 30-Aug-2011 mikeb

One shot rules can be used in pf.conf by specifying a "once" filter option.

ok henning, mcbride


Revision tags: OPENBSD_5_0_BASE
# 1.607 29-Jul-2011 mcbride

Remove requirement to quote 'debug' loglevel for the 'debug' option.

ok henning


# 1.606 27-Jul-2011 mcbride

Add support for weighted round-robin in load balancing pools and tables.
Diff from zinke@ with a some minor cleanup.
ok henning claudio deraadt


# 1.605 13-Jul-2011 mcbride

Force user to specify protocol when filtering on user, gid, and os
attributes (this is now required by pf_rule_test().

ok sthen henning


# 1.604 08-Jul-2011 henning

allow rules to specify "prio X" or "prio (X, Y)" to assign priority levels
for the new priority queueing implementation. valid range is 0 to 7. the old
trick for priorizing empty ACKs etc remains thru the latter notation
ok ryan mpf sthen plus pea testing and halex and claudio reading


# 1.603 07-Jul-2011 mcbride

Fold pf_test_fragment() into pf_test_rule(), reduce code and fixes
a bunch of bugs with fragment handling not being in sync with the
rest of the ruleset.

Much feedback from mpf, bluhm & markus
Thanks to Tony Sarendal for help with testing

ok bluhm; various previous versions ok henning, claudio, mpf, markus


# 1.602 04-Jul-2011 henning

bye bye require-order.
i added that button many many many years ago since the order (options, scrub,
nat, filter) was enforced back then, which I hated. now we had that turned
off for ages, and with the scrub and nat rulesets being gone, there is very
little reason to enforce an order at all. so let's get rid of it.
introducing this button was one of my very early commits to openbsd... feels
a bit strange to remove it now :)
ok ryan dlg theo


# 1.601 03-Jul-2011 henning

g/c RIO traces (aka clean up after tedu :))


# 1.600 03-Jul-2011 zinke

bring in least-states load balancing algorithm

ok mcbride@ henning@


# 1.599 06-Apr-2011 claudio

Userland bits to allow PF to filter on the rdomain a packet belongs to.
This allows to write rules like "pass in on rdomain 1".
Tested by phessler@, OK henning@


# 1.598 05-Apr-2011 mikeb

ditch fastroute, an ipf feature that made its way into pf before
route-to and friends were introduced making it obsolete. one even
has to look it up int the ipf manual to get and idea what it's
supposed to do. reuse some kernel bits for the upcoming nat64
stuff. "kill it with fire" from mcbride, "what mcbride said"
from mpf, "kill kill kill" and ok henning.


Revision tags: OPENBSD_4_9_BASE
# 1.597 31-Dec-2010 bluhm

According to pf_scrub_ip6() pf does not support the scrub options
no-df, random-id, set-tos for IPv6 rules. Check this in pfctl and
document it in pf.conf(5).
ok henning@ jmc@


# 1.596 15-Dec-2010 henning

make the "invalid probability:" yyerror suck less
From: Thomas Pfaff <tpfaff@tp76.info>


# 1.595 01-Dec-2010 jsg

remove some unused tokens
ok henning@ mcbride@


# 1.594 24-Sep-2010 henning

remove the check that enforced rdr-to only inbound and nat-to only outbound.
both now can be used in both directions. the kernel allowed that ever since
we did the great NAT rewrite.
still enforce that a direction is given, a rule with rdr-to and/or nat-to
and no direction is pretty certainly an error (which it would work,
technically)
ok ryan claudio dlg


# 1.593 22-Sep-2010 henning

new log opt "matches"
awesome for debugging, a rule like
match log(matches) from $testbox
will show you exactly which subsequent rules match on that packet
real ok theo assumed oks ryan & dlg bikeshedding many
implementation time ~1 min bikeshedding about the keyword longish.
i voted for "matches" since i like to play with matches
idea was theo's, actually


# 1.592 02-Sep-2010 sobrado

remove trailing spaces and tabs; no binary change.

written with help from henning@, who suggested ensuring that there
are no changes in the digests for object files, thanks!

ok henning@


Revision tags: OPENBSD_4_8_BASE
# 1.591 03-Aug-2010 henning

fix linecount bug with comments spanning multiple lines
problem reported with the obvious fix for bgpd by Sebastian Benoit
<benoit-lists at fb12.de>, also PR 6432
applied to all the others by yours truly. ok theo
isn't it amazing how far this parser (and more) spread?


# 1.590 03-Jul-2010 mcbride

Fix a couple of problems with printing of anchors, in particular recursive
printing, both of inline anchors and when requested explicitly with a '*'
in the anchor.
- Correct recursive printing of wildcard anchors (recurse into child anchors
rather than rules, which don't exist)
- Print multi-part anchor paths correctly (pr6065)
- Fix comments and prevent users from specifying multi-component names for
inline anchors.

tested by phessler
ok henning


# 1.589 23-Mar-2010 henning

remove -A, -O, -R and -T load
the partial loading of a ruleset (leaving ancors aside) is wrong and
conflicts with the general idea of how pf works. last not least it breaks
with the optimizer generating tables automagically.
ok deraadt sthen krw manpage jmc


Revision tags: OPENBSD_4_7_BASE
# 1.588 13-Jan-2010 deraadt

Move tokens before productions into more consistant places
ok mcbride


# 1.587 13-Jan-2010 mcbride

Allow /netmask notation in redir spec, fix the rest of the regress
tests for illegal conditions in translation/routing.


# 1.586 12-Jan-2010 mcbride

We actually have to keep the translate/route spec addresses around after
collapsing into tables, so that we can handle all possible address family
expansions.


# 1.585 12-Jan-2010 mcbride

Set roundrobin flag correctly, and don't treat a bare interface
like a dynamic one in the routespec.


# 1.584 12-Jan-2010 mcbride

Add restrictions to make @if illegal in outside of routing specs;
Fix binat-to sanity checks.


# 1.583 12-Jan-2010 mcbride

Fix some issues in redir spec handling, discovered thanks to dlg testing
- purge irrelevant addresses from the lists before collapsing
- ensure the lists are freed after they're collapsed
- more careful ifname copying, avoiding double-free / use-after-free traps


# 1.582 12-Jan-2010 mcbride

Don't leak @if0 format routing host names, pointed out by claudio.


# 1.581 12-Jan-2010 mcbride

First pass at removing the 'pf_pool' mechanism for translation and routing
actions. Allow interfaces to be specified in special table entries for
the routing actions. Lists of addresses can now only be done using tables,
which pfctl will generate automatically from the existing syntax.

Functionally, this deprecates the use of multiple tables or dynamic
interfaces in a single nat or rdr rule.

ok henning dlg claudio


# 1.580 10-Jan-2010 deraadt

lex <=, >=, and != into a single token for correctness and to reduce the
lookahead in the parser
ok henning otto


# 1.579 10-Jan-2010 deraadt

In the non-optimized case, an address list containing "any" (ie. { any 10.0.0.1 })
should be folded in the parser to any, not to 10.0.0.1. How long this bug has
been with us is unclear.
ok guenther mcbride


# 1.578 24-Dec-2009 sobrado

spelling fixes, from Brad Tilley; we will not fix src/sbin/dump/dump.h
as neither arrayified not arrayfied exist -- sanctioned dictionaries
like Merriam-Webster ones suggest a few alternatives (e.g., arrayed),
however these made up words are easy to understand and we are not
certain that current ones are not ok.

ok jmc@


# 1.577 24-Dec-2009 dlg

add support to pf for filtering a packet by the interface it was received
on. use the received-on IFNAME filter option on a pf.conf rule to restrict
which packet the interface had to be received on. eg:

pass out on em0 from $foo to $bar received-on fxp0

ive been running this in production for a week now. i find it particularly
usefull with interface groups.

no objections, and a few "i like"s from henning, claudio, deraadt, mpf


# 1.576 10-Dec-2009 deraadt

plug some memory leaks; found by parfait, ok henning


# 1.575 22-Nov-2009 henning

cleanup after the NAT changes. we used to have multiple rulesets (scrub,
NAT, filter). now we only have one. no need for an array any more. simplifies
the code quite a bit.
in the process fix the abuse of PF_RULESET_* by (surprise, isn't it) the
table code.
written at the filesystem hackathon in stockholm, committed from the
hardware hackathon in portugal. ok gcc and jsing


# 1.574 09-Nov-2009 jsg

A few more places to be updated for the route pool change.
expanded version of a diff from Vadim Zhukov.

ok henning@ claudio@


# 1.573 28-Oct-2009 jsg

Add a dedicated pf pool for route options as suggested by henning,
which unbreaks ie route-to after the recent pf changes.

With much help debugging and pointing out of missing bits from claudio@

ok claudio@ "looks good" henning@


# 1.572 28-Oct-2009 claudio

route_host initializes the netmask to a /128 no matter what af is used so
that the load balancing code does not freak out but because of this
check_netmask() is now complaining. So set the addr.type to PF_ADDR_DYNIFTL
so check_netmask() is fixing up the netmask for IPv4 and stops complaining.
This is a partial fix for the failing regress test 13.
found with jsg, looks good henning


# 1.571 28-Oct-2009 claudio

Correct function name in err and errx.


# 1.570 04-Oct-2009 michele

Add (again) support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 1

A lot of discussion have happened since my last commit that resulted
in many changes and improvements.
I would *really* like to thank everyone who took part in the discussion
especially canacar@ who spotted out which are the limitations of this approach.

OpenBSD divert(4) is meant to be compatible with software running on
top of FreeBSD's divert sockets even though they are pretty different and will
become even more with time.

discusses with many, but mainly reyk@ canacar@ deraadt@ dlg@ claudio@ beck@
tested by reyk@ and myself
ok reyk@ claudio@ beck@
manpage help and ok by jmc@


# 1.569 08-Sep-2009 michele

I had not enough oks to commit this diff.
Sorry.


# 1.568 08-Sep-2009 michele

Add support for divert sockets. They allow you to:

- queue packets from pf(4) to a userspace application
- reinject packets from the application into the kernel stack.

The divert socket can be bound to a special "divert port" and will
receive every packet diverted to that port by pf(4).

The pf syntax is pretty simple, e.g.:

pass on em0 inet proto tcp from any to any port 80 divert-packet port 8000

test, bugfix and ok by reyk@
manpage help and ok by jmc@
no objections from many others.


# 1.567 07-Sep-2009 reyk

implement binat-to as a macro-like rule: a rule using the new binat-to
syntax will be expanded by the parser to a nat-to+rdr-to combination
to be loaded into the kernel. this simplifies the migration from old
binat rules and is less error-prone.

feedback from many, manpage bits from jmc@
ok henning@


# 1.566 03-Sep-2009 reyk

this time i commit the right diff that was
ok henning@ (sorry)


# 1.565 03-Sep-2009 reyk

fix two route-to vs. rdr-to conflicts.

found by sthen@
ok henning@


# 1.564 02-Sep-2009 reyk

all the new *-to options are part of the "filteropts" section at the
end of a pf rule (nat-to, divert-to, rdr-to, ...). take the
historical chance to upgrade the grammar and move the route options to
the filteropts section as well.

for example,
pass in on em0 route-to (em1 192.168.1.1) from 10.1.1.1
becomes
pass in on em0 from 10.1.1.1 route-to (em1 192.168.1.1)

many people like this including pyr@ mk@ kettenis@ todd@ and others
ok henning@


# 1.563 01-Sep-2009 henning

the diff theo calls me insanae for:
rewrite of the NAT code, basically. nat and rdr become actions on regular
rules, seperate nat/rdr/binat rules do not exist any more.
match in on $intf rdr-to 1.2.3.4
match out on $intf nat-to 5.6.7.8
the code is capable of doing nat and rdr in any direction, but we prevent
this in pfctl for now, there are implications that need to be documented
better.
the address rewrite happens inline, subsequent rules will see the already
changed addresses. nat / rdr can be applied multiple times as well.
match in on $intf rdr-to 1.2.3.4
match in on $intf to 1.2.3.4 rdr-to 5.6.7.8
help and ok dlg sthen claudio, reyk tested too


# 1.562 28-Jul-2009 claudio

Bring back rev. 1.560:
Make it possible to use DiffServ Code Point in the TOS fields.
Requested by deraadt@


# 1.561 27-Jul-2009 deraadt

When will people learn to commit their .h file changes?


# 1.560 27-Jul-2009 claudio

Make it possible to use DiffServ Code Point in the TOS fields. Names like
af11, cs6 and ef will now be mapped to the coresponding TOS value.
OK henning@, sthen@, mcbride@


Revision tags: OPENBSD_4_6_BASE
# 1.559 14-May-2009 sthen

actually change the require-order default to No; I missed a part with
my last commit. ok deraadt@


# 1.558 26-Apr-2009 sthen

switch the require-order default to "no". regression tests still pass.
ok henning@ deraadt@


# 1.557 25-Apr-2009 henning

scrub_opts must not be empty, scrub on its own does nothing.
noticed due to a question from otto@, ok regress/sbin/pfctl/ ;)


# 1.556 06-Apr-2009 henning

1) scrub rules are completely gone.
2) packet reassembly: only one method remains, full reassembly. crop
and drop-ovl are gone.
. set reassemble yes|no [no-df]
if no-df is given fragments (and only fragments!) with the df bit set
have it cleared before entering the fragment cache, and thus the
reassembled packet doesn't have df set either. it does NOT touch
non-fragmented packets.
3) regular rules can have scrub options.
. pass scrub(no-df, min-ttl 64, max-mss 1400, set-tos lowdelay)
. match scrub(reassemble tcp, random-id)
of course all options are optional. the individual options still do
what they used to do on scrub rules, but everything is stateful now.
4) match rules
"match" is a new action, just like pass and block are, and can be used
like they do. opposed to pass or block, they do NOT change the
pass/block state of a packet. i. e.
. pass
. match
passes the packet, and
. block
. match
blocks it.
Every time (!) a match rule matches, i. e. not only when it is the
last matching rule, the following actions are set:
-queue assignment. can be overwritten later, the last rule that set a
queue wins. note how this is different from the last matching rule
wins, if the last matching rule has no queue assignments and the
second last matching rule was a match rule with queue assignments,
these assignments are taken.
-rtable assignments. works the same as queue assignments.
-set-tos, min-ttl, max-mss, no-df, random-id, reassemble tcp, all work
like the above
-logging. every matching rule causes the packet to be logged. this
means a single packet can get logged more than once (think multiple log
interfaces with different receivers, like pflogd and spamlogd)
.
almost entirely hacked at n2k9 in basel, could not be committed close to
release. this really should have been multiple diffs, but splitting them
now is not feasible any more. input from mcbride and dlg, and frantzen
about the fragment handling.
speedup around 7% for the common case, the more the more scrub rules
were in use.
manpage not up to date, being worked on.


Revision tags: OPENBSD_4_5_BASE
# 1.555 19-Feb-2009 deraadt

spacing


# 1.554 17-Oct-2008 henning

in findeol(), do not skip the pushback buffer. fixes PR 5952 by sthen@ and
should make the pushback buffer really transparent.
diagnosis by me, fix with mpf, some input deraadt, ok mpf


# 1.553 02-Oct-2008 henning

implement "set state-defaults X", where X is a list of state options as
permitted keep state(X). applies to all rules which do not have keep state
explicitely. e. g. "set state-defaults pflow, no-sync"
ok phessler deraadt


# 1.552 10-Sep-2008 deraadt

do not try to print $$ when it has not been set


# 1.551 09-Sep-2008 henning

welcome pflow(4), a netflow v5 compatible flow export interface.
flows export data gathered from pf states.
initial implementation by Joerg Goltermann <jg@osn.de>, guidance and many
changes by me. 'put it in' theo


# 1.550 07-Aug-2008 henning

correctly copy the log interface spec when expanding an antispoof rule that
covers loopback addresses. ok ryan
problem report from Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_4_4_BASE
# 1.549 03-Jul-2008 deraadt

do not forget to initialize other member of $$ in qname; noted by mark shroyer
ok henning


# 1.548 10-Jun-2008 mcbride

Make counters on table addresses optional and disabled by default.
Use the 'counters' table option in pf.conf if you actually need them.
If enabled, memory is not allocated until packets match an address.

This saves about 40% memory if counters are not being used, and paves the way
for some more significant cleanups coming soon.

ok henning mpf deraadt


# 1.547 10-Jun-2008 henning

new state option "sloppy" to use the sloppy tcp state tracker instead
of the good one. ok theo ryan reyk


# 1.546 09-May-2008 deraadt

Replace a crockpot of semi-cloned productions for handling port
numbers with one, and fix a few other bugs along the way
ok mpf henning


# 1.545 09-May-2008 markus

convert port byte order in the production; add port keyword; ok deraadt@


# 1.544 09-May-2008 markus

divert packets to local socket without modifying the ip header;
makes transparent proxies much easier; ok beck@, feedback claudio@


# 1.543 08-May-2008 deraadt

make "to any" optional in binat, or well, the implied default.
requested by reyk, ok reyk mpf


# 1.542 08-May-2008 deraadt

Loosen grammer to permit any number of newlines within most kinds of { }
blocks, as requested by reyk; ok reyk mpf henning


# 1.541 08-May-2008 deraadt

Bring back (in a more yacc friendly way) support for setting variables
to a sequence of strings and numbers, which get folded together into one
string (and later, when used, is re-lexed)
ok mpf


# 1.540 07-May-2008 deraadt

do not assume PF_INOUT is 0 in the enum; ok mcbride


# 1.539 07-May-2008 markus

scrub packets based on tags; ok henning


# 1.538 07-May-2008 markus

allow setting TOS with scrub; ok mcbride, claudio


# 1.537 21-Apr-2008 deraadt

optnl is a crutch for those who do not understand yacc. it
leads to a variety of errors; ok mcbride


Revision tags: OPENBSD_4_3_BASE
# 1.536 01-Feb-2008 mcbride

Enable the rest of the filter_opts to be used on anchors. These were accepted
by the parser but not passed to the kernel. This allows filtering based on
uid, gid, icmp options, tcp flags, os fingerprint, tos, tags, and probability;
It also allows the label to be set. State options and tagging are not
permitted.

ok henning mpf


# 1.535 13-Nov-2007 mpf

Bring back the number converter for 'set hostid'.
I forgot to think about hex numbers when I removed it.
OK deraadt@


# 1.534 12-Nov-2007 mpf

Remove space/tab compression function from lgetc() and replace
it with a simple filter in the yylex() loop.
The compression in lgetc() didn't happen for quoted strings,
thus creating a regression when tabs were used in variables.
Some testing by todd@ and pyr@
OK deraadt@


# 1.533 25-Oct-2007 mpf

Fix probability rules w/ numbers (e.g probability 0.4).
Add support for probablities of 0% and 100%.
With and OK deraadt@


# 1.532 22-Oct-2007 pyr

sync with daemon parser code.
ok deraadt@


# 1.531 22-Oct-2007 deraadt

pfctl does not need file secrecy


# 1.530 16-Oct-2007 mpf

Allow unquoted numbers in variables.
Change 'set hostid' to NUMBER and remove unneeded converter.
Add '=' to allowed_to_end_number(x) to make varsets like 4=5 illegal.

OK deraadt@


# 1.529 16-Oct-2007 deraadt

in the lex... even inside quotes, a \ followed by space or tab should
expand to space or tab, and a \ followed by newline should be ignored
(as a line continuation). compatible with the needs of hoststated
(which has the most strict quoted string requirements), and ifstated
(where one commonly does line continuations in strings).
pointed out by mpf, discussed with pyr


# 1.528 13-Oct-2007 deraadt

support an include directive; file of course must also be "secure" like
the main configuration file; ok henning


# 1.527 13-Oct-2007 deraadt

in all these programs using the same pfctl-derived parse.y, re-unify the
yylex implementation and the code which interacts with yylex. this also
brings the future potential for include support to all of the parsers.
in the future please do not silly modifications to one of these files
without checking if you are de-unifying the code.
checked by developers in all these areas.


# 1.526 11-Oct-2007 deraadt

next step in the yylex unification: handle quoted strings in a nicer fashion
as found in hoststated, and make all the code diff as clean as possible. a
few issues remain mostly surrounding include support, which will likely be
added to more of the grammers soon.
ok norby pyr, others


# 1.525 01-Oct-2007 mpf

Backout NUMBER to string conversion.
Requested by deraadt@


# 1.524 27-Sep-2007 mpf

Add loginterface support for groups.
Using a group sums up the statistics of all members.
Modify pfctl(1) slightly to allow a groupname "all",
which gives us an overall pf(4) statistic.

OK henning@, markus@


# 1.523 23-Sep-2007 mpf

Allow numbers to be used as unquoted strings again.
While there, also restrict the use of concatenated, unquoted
strings for variable assignments only.

Eyeballed by markus@, OK henning@


# 1.522 12-Sep-2007 deraadt

add a missing range check for rtable ids; ok cloder henning


# 1.521 12-Sep-2007 deraadt

Add support to the lex for parsing number out of the stream. handle
this in the parser. because the new numbers are int64_t, many new
range checks for < 0 are needed. re-check and improve all the
existing rangechecks while at it. thanks for help by cloder and
dhartmei


# 1.520 30-Aug-2007 dhartmei

add support for address ranges ("from 10.1.2.50 - 10.1.3.75") in from/to
criteria. ok mcbride@


Revision tags: OPENBSD_4_2_BASE
# 1.519 21-Jun-2007 henning

always initialize logif, from max laier, ok ryan


# 1.518 20-Jun-2007 mpf

Allow "log" for nat rules without "pass".
OK henning@, ``passt scho'' markus@


Revision tags: OPENBSD_4_1_BASE
# 1.517 03-Feb-2007 dhartmei

in decide_address_family(), only limit a rule to a specific address family
when ALL entries have this specific AF (when even just one entry has no
specific AF, use any). found by Maurice Janssen, ok henning@


# 1.516 07-Nov-2006 mcbride

Unbreak authpf by handling non-inline anchors separately from the { } anchors
as pf_find_or_create_ruleset() will mangle relative anchor names and wildcards.
Also fixes some nits with nesting and printing inline anchors.

ok deraadt@


# 1.515 31-Oct-2006 mcbride

Allow pfctl ruleset optimizer to be controlled from the ruleset.

"set" "ruleset-optimization" [ "none" | "basic" | "profile" ]

You can optionally control ruleset optimization with these keywords on the
command line with the -o option; the command line setting will override the
pf.conf setting. The existing -o/-oo flags continue to work as expected.

cleanup and ok henning@


# 1.514 31-Oct-2006 mcbride

- don't allow anchors with _* names to be cleared or loaded from the
command line (but they can still be viewed)
- don't allow users to specify _* as an anchor name in the ruleset
- don't print _* anchor names with pfctl -sA unless -v is specified

'looks sensible' deraadt@


# 1.513 28-Oct-2006 mcbride

Load all rules into memory before loading into the kernel, and add support
for anchors loaded inline in pf.conf, enclosed in a brace-delimited
block ("{" "}").

anchor on fxp0 {
pass in proto tcp port 22
}

The anchor name is optional on inline loaded anchors.

testing ckuethe@
ok henning@ dhartmei@


# 1.512 25-Oct-2006 henning

make absolutely sure logif is 0 unless set specifically, even if log is 0.
logif is to be considered invalid unless log is set, but we need this to
please the optimizer...


# 1.511 25-Oct-2006 henning

and another nit, $$.log should be set to 0 explicitely on quick without log


# 1.510 25-Oct-2006 henning

urgs, $$.quick needs to be set to 0 explicitely on log (without quick)


# 1.509 25-Oct-2006 henning

allow the log interface to be selected like
pass log(to pflog5)
block out log(to pflog2)
input & ok mcbride


# 1.508 17-Oct-2006 mcbride

Don't automatically set 'flags S/SA' on stateless rules.

pointed out by david@

ok mpf@ dhartmei@


# 1.507 11-Oct-2006 deraadt

quotes around filename, pr 5253, sthen@zephyr.spacehopper.org


# 1.506 11-Oct-2006 mcbride

Allow the 'quick' keyword on an anchor. IFF there is a matching rule inside
the anchor, terminate ruleset evaluation when stepping out of the anchor.

This means that if you absolutely want the anchor to be terminal, you
probably want to use a 'block all' or 'pass all' rule at the start of the
anchor.

ok dhartmei@ henning@ deraadt@


# 1.505 06-Oct-2006 mcbride

Oops, flags S/SA doesn't work on fragments.


# 1.504 06-Oct-2006 mcbride

Make 'flags S/SA keep state' the implicit for filter rules, based on
a suggestion from dhartmei@. Also add 'flags any' and 'no state' options
to disable flag matching and stateful filtering respectively.

IMPORTANT NOTE:
Current rulesets will continue to load, but the behaviour may be slightly
changed as these defaults are more restrictive. If you are purposefully
filtering statelessly ('no state') or have a requirement to create states
on intermediate packets ('flags any') you should update your ruleset to
make use of the new keywords to explicitly request the behaviour.

Note that creation of states from intermediate packets in a connection is
not recommended, and will increasingly cause problems as more OSs enable
window scaling and increase buffer sizes by default.

ok dhartmei@ deraadt@ henning@


Revision tags: OPENBSD_4_0_BASE
# 1.503 22-Aug-2006 dhartmei

back out -r1.497 (support for "tagged {}" lists), it broke "tagged" support
for nat rules. sorry, existing functionality trumps syntactic sugar. feel
free to resubmit a complete patch. closes PR 5207.


# 1.502 06-Jul-2006 henning

add "rtable" to select alternate routing tables.
with & ok claudio hshoexer


# 1.501 17-Jun-2006 henning

KNF


# 1.500 28-May-2006 mcbride

Make per-rule adaptive timeouts behave the same way as the global adaptive
timeouts.


# 1.499 26-May-2006 deraadt

\<char> is <char> except for \<newline> -- no exceptions. much like how
other things work. ok henning


# 1.498 02-May-2006 dhartmei

fix creation of sub-anchors, e.g. if you create an anchor /foo/bar, create
only bar under foo, not /bar as well.
secondly, when using "load anchor from" from a sub-anchor, the loading
point should be relative to the sub-anchor doing the load (unless absolute
paths are used, of course).
from Boris Polevoy. probably a -stable candidate.


# 1.497 01-May-2006 dhartmei

add support for "tagged {}" lists, from Pierre-Yves Ritschard


# 1.496 06-Apr-2006 henning

allow lists inside lists for address specs, has been in my tree for
quite some time... theo likes


# 1.495 14-Mar-2006 djm

implement a Unicast Reverse Path Forwarding (uRPF) check for pf(4)
which optionally verifies that a packet is received on the interface
that holds the route back to the packet's source address. This makes
it an automatic ingress filter, but only when routing is fully
symmetric.

bugfix feedback claudio@; ok claudio@ and dhartmei@


Revision tags: OPENBSD_3_9_BASE
# 1.494 17-Nov-2005 dhartmei

for pfctl -f rules, open the file before resetting options. when opening
the file fails, produce only the error message and leave options
unchanged. reported by Tamas TEVESZ, ok deraadt@


# 1.493 13-Oct-2005 henning

unused parameters


Revision tags: OPENBSD_3_8_BASE
# 1.492 14-Jun-2005 henning

no need to restrict tagging to stateful rules any more, dhartmei ok
From: "Alexey E. Suslikov" <cruel@texnika.com.ua>


# 1.491 27-May-2005 dhartmei

get rid of 'log-all'. now that we have 'log (options)', make 'all' an
option to log. so, 'log-all' becomes 'log (all)'.


# 1.490 27-May-2005 dhartmei

get rid of shift/reduce conflicts, don't support empty logopts


# 1.489 27-May-2005 dhartmei

log two pairs of uid/pid through pflog: the uid/pid of the process that
inserted the rule which causes the logging. secondly, the uid/pid of the
process in case the logged packet is delivered to/from a local socket.
a lookup of the local socket can be forced for logged packets with a new
option, 'log (user)'. make tcpdump print the additional information when
-e and -v is used. note: this changes the pflog header struct, rebuild all
dependancies. ok bob@, henning@.


# 1.488 27-May-2005 dhartmei

allow 'tagged' in 'anchor' rules (without complaining about missing
'keep state'), as a condition to branch into the anchor. suggested
by Bill Marquette.


# 1.487 26-May-2005 camield

The illegalness of "no nat log" is already enforced by the grammar.

ok dhartmei


# 1.486 26-May-2005 dhartmei

support 'log' and 'log-all' in 'nat/rdr/binat pass' rules. original patch
from camield@. use #defines PF_LOG, PF_LOGALL instead of magic constants.
ok frantzen@, camield@


# 1.485 23-May-2005 camield

remove code that duplicates getservice()

ok dhartmei mcbride


# 1.484 21-May-2005 henning

clean up and rework the interface absraction code big time, rip out multiple
useless layers of indirection and make the code way cleaner overall.
this is just the start, more to come...
worked very hard on by Ryan and me in Montreal last week, on the airplane to
vancouver and yesterday here in calgary. it hurt.
ok ryan theo


# 1.483 22-Apr-2005 camield

Catch bad flags, ie. flags that always evaluate to false. This happens
if there are flags on the lefthandside that are masked off by the
righthand side.

ok mcbride@ (long time ago) dhartmei@ henning@


Revision tags: OPENBSD_3_7_BASE
# 1.482 07-Mar-2005 henning

print unsigned long with %lu, not with %d and not with %ld.
From: Andrey Matveev <andrushock@korovino.net>


# 1.481 06-Mar-2005 henning

allow commas in the hfsc service curve spec, inconsistency pointed out in
PR4134 / geoff@collyer.net and a longer mail exhcange with han boetes


# 1.480 06-Mar-2005 dhartmei

print "set skip on" with -v in such a way that the output is valid input
syntax, instead of the cryptic hex flags output.


# 1.479 27-Feb-2005 dhartmei

support 'tagged' in translation rules, non-delayed tag lookup
ok henning@, deraadt@


# 1.478 26-Feb-2005 henning

ypu sure get the impression the number of memory leaks in error pathes
is infinite... Andrey Matveev <andrushock@korovino.net> spotted a few again!


# 1.477 07-Feb-2005 david

KNF; ok henning@


# 1.476 28-Jan-2005 dhartmei

add messages for syntax errors that caused silent failure before.
found by Peter Fraser, ok henning@


# 1.475 27-Jan-2005 dhartmei

dynamic interface names must start with a letter. catches the nonsensical
"(10.1.2.3)" that results from a simple typo like "$(ext_ip)" instead of
"$(ext_if)".


# 1.474 05-Jan-2005 mcbride

Modify pfctl behaviour so that 'set ...' options are no longer "sticky", ie.
they are reset to default values if omitted from a subsequent ruleset load.
Also:
- make sure 'set ...' options are not loaded in anchors.
- add a -m ("merge") flag to pfctl which allows an individual option to be set
without reseting the others, eg:
# echo "set loginterface fxp0" | pfctl -mf -

ok henning@ dhartmei@


# 1.473 29-Dec-2004 mcbride

Print 'set fingerprints' correctly when parsing verbosely.


# 1.472 23-Dec-2004 dhartmei

set rule_flag PFRULE_SRCTRACK when setting srctrack, found by camield@
using regress test pf84


# 1.471 22-Dec-2004 dhartmei

Introduce 'set skip on <ifspec>' to support a list of interfaces where no
packet filtering should occur (like loopback, for instance).
Code from Max Laier, with minor improvements based on feedback from
deraadt@. ok mcbride@, henning@


# 1.470 15-Dec-2004 henning

missing free()s; with pat


# 1.469 10-Dec-2004 henning

allow pf to filter on route labels
pass in from route dtag keep state queue reallyslow
tested by Gabriel Kihlman <gk@stacken.kth.se> and
Michael Knudsen <e@molioner.dk> and ryan
ok ryan


# 1.468 08-Dec-2004 mcbride

Add "'overload' requires 'max-src-conn' or 'max-src-conn-rate'" sanity check,
fix some cut-n-paste mayhem in other related checks.


# 1.467 07-Dec-2004 dhartmei

re-commit mcbride@'s 'flush global', this time without the breakage in
pfvar.h. builds kernel and userland.


# 1.466 07-Dec-2004 deraadt

real backout


# 1.465 07-Dec-2004 deraadt

oops, incomplete backout


# 1.464 07-Dec-2004 deraadt

tree does not compile, spotted by dlg (not obvious how to fix)
----
Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.463 07-Dec-2004 mcbride

Change the default for 'overload <table> flush' to flush only states from the
offending source created by the rule. 'flush global' flushes all states
originating from the offending source. ABI change, requires kernel and pfctl
to be in sync.

ok deraadt@ henning@ dhartmei@


# 1.462 05-Dec-2004 dhartmei

initialize $$->tail and $$->next for MAXSRCCONNRATE


# 1.461 04-Dec-2004 mcbride

Userland support for limiting open tcp connections per source. eg:

keep state (max-src-conn 1000, max-src-conn-rate 100/10, overflow <bad> flush)

allow a maximum of 1000 open connections or 100 new connections in 10 seconds.
The addresses of offenders are added to the <bad> table which can be used in
the ruleset, and existing states from that host are flushed.

ok deraadt@ dhartmei@


# 1.460 21-Sep-2004 aaron

Implement "no scrub" to allow exclusion of specific traffic from scrub rules.
First match wins, just like "no {binat,nat,rdr}". henning@, dhartmei@ ok


Revision tags: OPENBSD_3_6_BASE
# 1.459 29-Jun-2004 henning

remove cedric's bogus interface name verification code.
this was meant to verify that ne3 is a valid interface that could show
up, but bogus0 is not. while this might sound like a good idea it is
completely broken and causes a shitload of problems. just allow for anything
as interface name, the kernel abstracts that nice enough. if no interface
by that name exists (or shows up) the rule never matches; that matches
pf semantics used everywhere else.
this also fixes the "pfctl always has to run as root" issue that cedric
did not fix over the last 6 months despite being bugged to regularily.
help & ok mcbride@


# 1.458 29-Jun-2004 frantzen

convert a few memcpy()s to strlcpy() so we don't copy uninitialized junk into
a interface name's slack space past the \0. will be needed for the optimizer.
ok henning@


# 1.457 26-Jun-2004 david

add back PF_INOUT, fixes reassemble tcp
ok canacar@ mcbride@


# 1.456 25-Jun-2004 deraadt

repair tree nanobreak by the nanobum


# 1.455 10-Jun-2004 dhartmei

rename struct pf_rule_addr member 'not' to 'neg', as 'not' is a reserved
keyword in C++. ok henning@, cedric@


# 1.454 21-May-2004 dhartmei

Use '/' instead of ':' as separator for anchor path components. Note that
the parser now needs quotes around paths containing separators.
ok mcbride@


# 1.453 19-May-2004 dhartmei

Allow recursive anchors (anchors within anchors, up to 64
levels deep). More work required, but this is already
functional. authpf users will need to adjust their anchor
calls, but this will change again soon. ok beck@, cedric@,
henning@, mcbride@


# 1.452 24-Apr-2004 cedric

Add "probability xxx" rule modifier. ok deraadt@


# 1.451 22-Apr-2004 henning

typo, From: Jared Yanovich <jjy2+@pitt.edu>


# 1.450 14-Apr-2004 cedric

make antispoof work with dynamic addresses. ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_5_BASE
# 1.449 20-Mar-2004 david

spelling fix; ok dhartmei@ henning@ deraadt@


# 1.448 14-Mar-2004 dhartmei

#include fixes, from Max Laier, ok beck@ henning@


# 1.447 08-Mar-2004 henning

plug 124 memory leaks
ok mcbride@ pb@ dhartmei@


# 1.446 06-Mar-2004 henning

from bgpd:
plug a memory leak in the lexer.
the issue is this code fragement from yylex():
. token = lookup(buf);
. yylval.v.string = strdup(buf);
. if (yylval.v.string == NULL)
. err(1, "yylex: strdup");
. return (token);
lookup() tries to match buf against a list of keywords, and returns the
associated token if it has a match, or the token STRING otherwise.
STRING is the only token that needs (and free()s) yylval.v.string. however,
we assigned memory for it with the strdup in yylex for each and every token.
the fix is obviously only setting yylval.v.string when lookup() returns STRING.
Patrick Latifi noticed that something was leaking with token handling,
analysis and fix by me.
ok deraadt@


# 1.445 01-Mar-2004 dhartmei

support "tagged <name>" on anchor rules, suggested by vd@vmunix.lt,
ok henning@, cedric@


# 1.444 24-Feb-2004 mcbride

'max-src-nodes' requires 'source-track rule'. Set that automatically,
unless 'source-track global' is explicit, in which case error out. Lots of
help from cedric@.

ok cedric@ henning@


# 1.443 24-Feb-2004 cedric

fixup.


# 1.442 24-Feb-2004 mcbride

Check for 'source-track rule' with 'max-src-nodes'.

ok cedric@ henning@


# 1.441 11-Feb-2004 cedric

Fix interface clobbering for link-local addresses. Found by Pyun YongHyeon.
Fix "antispoof for foo" when foo has no addresses.
ok+help dhartmei@, ok mcbride@


# 1.440 10-Feb-2004 henning

KNF


# 1.439 10-Feb-2004 henning

fix at leats the worst of Cedric "KNF is for everybody but me" Berger's fuckup


# 1.438 04-Feb-2004 mcbride

Handle rules like 'pass ... proto { tcp udp icmp } ... modulate state'

ok dhartmei@ henning@


# 1.437 03-Feb-2004 henning

fix PR 3664 / jared r r spiegel
we need to save the unexpanded tag/tagged strings before entering the
expansion loop, and at each loop, start with the unexpanded tag, so that
on subsequent loops the macros are replaced with current values and not
the values from previous loop persist
ryan theo ok


# 1.436 05-Jan-2004 henning

few off by ones in strlcpy overflow check; Patrick Latifi


# 1.435 04-Jan-2004 cedric

don't ignore "!" on "binat on !foo". ok mcbride@


# 1.434 31-Dec-2003 deraadt

spacing. note this, cedric


# 1.433 31-Dec-2003 cedric

Many improvements to the handling of interfaces in PF.

1) PF should do the right thing when unplugging/replugging or cloning/
destroying NICs.

2) Rules can be loaded in the kernel for not-yet-existing devices
(USB, PCMCIA, Cardbus). For example, it is valid to write:
"pass in on kue0" before kue USB is plugged in.

3) It is possible to write rules that apply to group of interfaces
(drivers), like "pass in on ppp all"

4) There is a new ":peer" modifier that completes the ":broadcast"
and ":network" modifiers.

5) There is a new ":0" modifier that will filter out interface aliases.
Can also be applied to DNS names to restore original PF behaviour.

6) The dynamic interface syntax (foo) has been vastly improved, and
now support multiple addresses, v4 and v6 addresses, and all userland
modifiers, like "pass in from (fxp0:network)"

7) Scrub rules now support the !if syntax.

8) States can be bound to the specific interface that created them or
to a group of interfaces for example:

- pass all keep state (if-bound)
- pass all keep state (group-bound)
- pass all keep state (floating)

9) The default value when only keep state is given can be selected by
using the "set state-policy" statement.

10) "pfctl -ss" will now print the interface scope of the state.

This diff change the pf_state structure slighltly, so you should
recompile your userland tools (pfctl, authpf, pflogd, tcpdump...)

Tested on i386, sparc, sparc64 by Ryan
Tested on macppc, sparc64 by Daniel

ok deraadt@ mcbride@


# 1.432 30-Dec-2003 henning

fix TAILQ abuse.
TAILQ_REMOVE is a no-no within a TAILQ_FOREACH loop.
also free the symbol itself after removal.
all found while hacking bgpd which incorporates pfctl's sym code (macros).

ok cedric@


# 1.431 19-Dec-2003 henning

i wrote much of these, assert my copyright


# 1.430 19-Dec-2003 deraadt

assert copyright. i rewrite much of this


# 1.429 16-Dec-2003 mcbride

Check that max-src-states and max-src-nodes are not being set to 0.


# 1.428 15-Dec-2003 henning

KNF here too


# 1.427 15-Dec-2003 mcbride

Whitespace.


# 1.426 15-Dec-2003 mcbride

Add initial support for pf state synchronization over the network.
Implemented as an in-kernel multicast IP protocol.

Turn it on like this:

# ifconfig pfsync0 up syncif fxp0

There is not yet any authentication on this protocol, so the syncif
must be on a trusted network. ie, a crossover cable between the two
firewalls.

NOTABLE CHANGES:
- A new index based on a unique (creatorid, stateid) tuple has been
added to the state tree.
- Updates now appear on the pfsync(4) interface; multiple updates may
be compressed into a single update.
- Applications which use bpf on pfsync(4) will need modification;
packets on pfsync no longer contains regular pf_state structs,
but pfsync_state structs which contain no pointers.

Much more to come.

ok deraadt@


# 1.425 15-Dec-2003 mcbride

Add support to track stateful connections by source ip. This allows us
to:
- Ensure that clients get a consistent IP mapping with load-balanced
translation/routing rules
- Limit the number of simultaneous connections a client can make
- Limit the number of clients which can connect through a rule

ok dhartmei@ deraadt@


# 1.424 29-Nov-2003 dhartmei

allow ':' (range including boundaries) to be used whereever '><' (range
excluding boundaries) is legal. already supported by kernel, requires only
removal of three error messages. ok henning@


# 1.423 22-Nov-2003 henning

daniel stumbled over a broken regress test, and it turned out that I forgot
to commit a diff from 11/6...
do not insert the "block in on ! interface" rule for antispoof statements when
the interface in question does not have any IP address, because that then
expands to
block in on ! interface all
which is obviously bad.
niklas@ found it, dhartmei@ ok, and I think some more ppl ok I don't remember


# 1.422 14-Nov-2003 henning

allow the debuglevel to be set from pf.conf (set debug)

ok cedric@


# 1.421 08-Nov-2003 mcbride

Add 'no-sync' state option to prevent state transition messages for states
created by this rule from appearing on the pfsync(4) interface. e.g.

pass in proto tcp to self flags S/SA keep state (no-sync)

ok cedric@ henning@ dhartmei@


# 1.420 06-Nov-2003 henning

and fix two err() that should be errx() while beeing here


# 1.419 06-Nov-2003 henning

need calloc here


# 1.418 06-Nov-2003 henning

allow the label macros to be used in tags as well.
the idea is not mine and I'dlove to get credit, but I cannot find the mail
any more :-((

ok canacar@ dhartmei@


# 1.417 21-Oct-2003 itojun

don't use NULL as (int)0. henning ok


# 1.416 26-Sep-2003 cedric

Rearchitecture of the userland/kernel IOCTL interface for transactions.
This brings us close to 100% atomicity for a "pfctl -f pf.conf" command.
(some splxxx work remain in the kernel). Basically, improvements are:

- Anchors/Rulesets cannot disappear unexpectedly anymore.
- No more leftover in the kernel if "pfctl -f" fail.
- Commit is now done in a single atomic IOCTL.

WARNING: The kernel code is fully backward compatible, but the new
pfctl/authpf userland utilities will only run on a new kernel.

The following ioctls are deprecated (i.e. will be deleted sooner or
later, depending on how many 3rd party utilities use them and how soon
they can be upgraded):

- DIOCBEGINRULES
- DIOCCOMMITRULES
- DIOCBEGINALTQS
- DIOCCOMMITALTQS
- DIOCRINABEGIN
- DIOCRINADEFINE

They are replaced by the following ioctls (yes, PF(4) will follow)
which operate on a vector of rulesets:

- DIOCXBEGIN
- DIOCXCOMMIT
- DIOCXROLLBACK

Ok dhartmei@ mcbride@


Revision tags: OPENBSD_3_4_BASE
# 1.415 01-Sep-2003 henning

KNF


# 1.414 28-Aug-2003 kjell

This change is busted. what's worse, REGRESSION TESTS WOULD HAVE CAUGHT IT!
You MUST test nework stack changes on BOTH BYTE-ORDERS.
Someone can fix this later, but right now I need to get the damn
firewall up. Grr.


# 1.413 26-Aug-2003 dhartmei

catch port/user/group a <>/>< b with a >= b, from mpech@


# 1.412 25-Aug-2003 dhartmei

catch return-rst ttl values > 255, from aaron@


# 1.411 24-Aug-2003 cedric

Tweaks:
- Make sure we allow only tables in round-robin pools for routing options,
same as what we do for translation rules.
- Don't reject rules like: "nat on sis0 -> <foo>" because
"no address family is given". This is perfectly valid.
ok henning@


# 1.410 22-Aug-2003 david

pf spelling police
ok dhartmei@ jmc@


# 1.409 21-Aug-2003 frantzen

Add Michal Zalewski's p0f v2 style passive OS fingerprinting to PF.
Exposes the source IP's operating system to the filter language.
Interesting policy decisions are now enforceable:
. block proto tcp from any os SCO
. block proto tcp from any os Windows to any port smtp
. rdr ... from any os "Windows 98" to port WWW -> 127.0.0.1 port 8001


# 1.408 20-Aug-2003 henning

braindeadness police: catch queues which specify itself as child... 'nuff said


# 1.407 20-Aug-2003 henning

err out nicer on errors in queue def


# 1.406 18-Aug-2003 dhartmei

catch max-mss values > 65535, report by Gregory Steuck


# 1.405 09-Aug-2003 cedric

This patch remove the restriction that tables cannot be used in routing or
redirection rules...

The advantage of using tables in redirection/routing rules is not efficiency,
in fact it will run slower than straight address pools. However, this brings
a lot of flexibility to PF, allowing simple scripts/daemons to add/remove
addresses from redirection/routing pools easily.

This implementation support all table features, including cidr blocks and
negated addresses. So specifying { 10.0.0.0/29 !10.0.0.0 !10.0.0.7 } will
correctly round-robin between the six addresses: .1, .2, .3, .4, .5, .6.

Tables can also be combined with simple addresses, so the following rule
will work as expected: "nat on foo0 -> { 1.1.1.1 <bar> }"

ok henning@ mcbride@


# 1.404 29-Jul-2003 deraadt

indent


# 1.403 19-Jul-2003 cedric

Simplify struct pf_pooladdr to include struct pf_addr_wrap directly
instead of indirectly trough struct pf_rule_addr.

Ryan McBride says:
If I'm not mistaken, the code _used_ to use the ports in pf_rule_addr as
well. The code was changed to fix some of the bugs with port ranges, but
it was too late in the release cycle to make kernel API changes, so the
structure was left as is.

Needless to say: KERNEL/USERLAND SYNC REQUIRED.

ok henning@ mcbride@


# 1.402 18-Jul-2003 cedric

Simplify handling of flags (-R, -N...). Remove PFCTL_FLAG_ALL.
ok dhartmei@


# 1.401 15-Jul-2003 cedric

Repair memory managment in table parsing code.
I need vacations.
Found and verified by Pyun YongHyeon.
ok dhartmei@


# 1.400 14-Jul-2003 dhartmei

tpo


# 1.399 11-Jul-2003 cedric

Better parsing and -v support for tables:

- remove the tableaddrs and tableaddr yacc production and reuse
host_list instead.
- produce better error messages.
- do not load addresses from external file when it is not
required (like with -R option).
- store initializers in a new node_tinit linked list before
putting them into the address buffer (see next point).
- add a new print_tabledef() function, which makes "pfctl -nvf"
print something useful for table definitions, which in turn
makes it possible to write better regress tests (see first chunk
of the diff) and bring table definition consistant with other
parsed rules.

ok dhartmei@


# 1.398 10-Jul-2003 cedric

Fix merging of host lists.
ok dhartmei@ henning@


# 1.397 04-Jul-2003 henning

KNF after cedric (grmpf)


# 1.396 04-Jul-2003 henning

allow for a "pass" modifier on translation rules:
nat pass on $ext_if from $a to $b -> $ext_if
when the pass modifier is given, the filter ruleset is _not_ evaluated but
the packets matching this translation rule are passed unconditionally.

ok dhartmei@ cedric@ markus@


# 1.395 03-Jul-2003 cedric

Bye bye atexit(), bye bye globals...
The pfctl.c part will probably need some further improvements.
ok henning@


# 1.394 03-Jul-2003 cedric

This patch finally cleanup pfctl_table.c. No more global buffer,
and a couple of parsing functions moved to parse.y or pfctl_parser
where they belong.

I also took the opportunity to replace "void" functions with exit(1)
or err() inside by "int" functions, with the caller checking the
return value for errors (much cleaner and an old request from Theo)

ok dhartmei@ henning@


# 1.393 19-Jun-2003 deraadt

knf


# 1.392 18-Jun-2003 henning

change expand_label_addr() to use a switch (h->addr.type) instead of
if .. else if .. else, and handle PF_ADDR_NOROUTE as well.
inspired by a comment from cedric.


# 1.391 18-Jun-2003 henning

when expanding the $srcaddr/$dstaddr label macros and the address is actually
a table refernence, don't print nonsense but the table name.
found by claudio jeker, fix by me, agreement by cedric


# 1.390 09-Jun-2003 mcbride

Attempt to resolve byte order confusion in nat code once and for all.

- pf_get_sport() leaves the translated port in the packet in network byte order
- merge code for the p1=0 p2=0 case and static-port case in pr_get_sport()

NOTE: people who use the static-port keyword in their pf.conf need to make sure pfctl is updated along with their kernel.


# 1.389 25-May-2003 henning

must not run check_netmask() before remove_invalid_hosts() - binat case had it
wrong for the redirection target.
reported by jared r r spiegel <jrrs@ice-nine.org>


# 1.388 19-May-2003 henning

reject invalid netmasks like 10.0.0.0/68, and fix up the netmask for
dynaddr rules after we know the address family

ok dhartmei@, inspired by a session with bob


# 1.387 19-May-2003 henning

all host() receivers have to test for NULL


# 1.386 19-May-2003 henning

if host() returns NULL, it is an error, so err the fuck out and don't
load bullshit


# 1.385 17-May-2003 henning

support inverse matching on tags like
block in ! tagged sometag

ok dhartmei@ pb@


# 1.384 16-May-2003 dhartmei

TCP SYN proxy. Instead of 'keep state' or 'modulate state', one can use
'synproxy state' for TCP connections. pf will complete the TCP handshake
with the active endpoint before passing any packets to the passive end-
point, preventing spoofed SYN floods from reaching the passive endpoint.

No additional memory requirements, no cookies needed, random initial
sequence numbers, uses the existing sequence number modulators to translate
packets after the handshakes.

ok frantzen@


# 1.383 15-May-2003 henning

properly complain about too long tags


# 1.382 14-May-2003 frantzen

add scrub modifier "reassemble tcp" to turn on stateful TCP normalizations
ok henning@ dhartmei@


# 1.381 14-May-2003 henning

tagging on binat


# 1.380 14-May-2003 henning

enabled tagging on rdr rules


# 1.379 14-May-2003 henning

with tag/tagged given, only whine about missing keep state on pass rules


# 1.378 14-May-2003 frantzen

allow SCRUB rules to specify protocol again. broken sometime in the past.
okie dhartmei@, yay pb@


# 1.377 14-May-2003 henning

tags on nat rules:
nat on $ext_if all tag humppa -> $ext_if
pass out tagged hummpa keep state


# 1.376 13-May-2003 henning

make sure tagging is only ever used with stateful filter rules


# 1.375 13-May-2003 henning

userland part for tagging.
it's now possible to tag packets with an arbitary tag and filter based on
that tag later on other interfaces:
pass in quick on fxp0 keep state tag blah
pass out quick on wi0 keep state with tag blah
can be used to express trust between interfaces, to distinguish between
NATed connections and connection originating from teh firewall itself
and much more

ok dhartmei@ frantzen@ pb@ mcbride@


# 1.374 11-May-2003 mcbride

Don't ntohs() the translation port for nat as it is already in host byte order.
Makes nat ... -> $ext_if port 500 rules work correctly again.

ok henning@ dhartemi@ frantzen@


# 1.373 10-May-2003 henning

support loading of anchors from within the main ruleset via
load anchor anchorname:rulesetname file /path/to/file

ok pb@ dhartmei@ cedric@


# 1.372 03-May-2003 henning

don't free() the char * carrying the rule label too early
noticed by Mathieu Sauve-Frankel <m.sauve at secureops.net> via silc


# 1.371 01-May-2003 henning

ease label handling

ok cedric@


# 1.370 01-May-2003 henning

allow label on antispoof; requested by Gregor Binder <gbinder at sysfive.com>

ok cedric@


# 1.369 30-Apr-2003 cedric

Allow tables to be loaded into anchors.
Most pfctl table commands (excluding 'show' and 'flush') support the "-a"
modifier.
ok dhartmei@


# 1.368 25-Apr-2003 dhartmei

Properly copy the second part of nat proxy port range, when specified.
ok henning@


# 1.367 15-Apr-2003 henning

pass down the unparsed queue opts (struct node_queue_opt) to
print_altq/print_hfsc -> print_hfsc_opts and extract struct node_hfsc_sc
there for each service curve and pass those down to print_hfsc_sc. now
bandwidth specifications in the service curves are printed correct in the
case of a queue belonging to more than one interface/parent queue, the
parent queues having different bandwidths and the bandwith on teh service
curve beeing specified in percent.


# 1.366 14-Apr-2003 henning

let print_altq and print_queue take a struct node_queue_bw parameter instead
of dintinct bw_percent


# 1.365 13-Apr-2003 henning

KNF


# 1.364 13-Apr-2003 henning

prevent double service curve specification


# 1.363 13-Apr-2003 henning

add support for the HFSC linkshare, realtime, and upperlimit service curves
to be specified.


# 1.362 13-Apr-2003 dhartmei

unbreak (missing })


# 1.361 13-Apr-2003 henning

say bye bye to hfscflags_list and hfscflags_item
welcome hfscopts_list and hfscopts_item, returning a full struct
node_hfsc_opt instead of just an int for the flags. needed because of all
the opts hfsc knows


# 1.360 13-Apr-2003 henning

new struct node_hfsc_opts for, surprise, hfsc options. needed because they
contain bandwidth specifications and we need to carry the unprocessed bw
specs around for quite some time until we can break them down to absolute
values.


# 1.359 13-Apr-2003 henning

pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.


# 1.358 13-Apr-2003 henning

move the structs node_queue_bw and node_queue_opt to pfctl_parser.h.
let eval_pfqueue() and eval_pfaltq() take a pointer to a struct
node_queue_bw instead of two distince bw_absolute and bw_percent parameters.


# 1.357 13-Apr-2003 henning

move the bandwidth keyword from within the bandwidth target up to the
queue_opts target so the bandwidth parser can be used for other things too;
will be needed for hfsc's linkshare etc


# 1.356 12-Apr-2003 henning

initial support for the HFSC scheduler.
whoever uses that for more than toying around is on drugs. it's far from done.


# 1.355 11-Apr-2003 henning

KNF


# 1.354 11-Apr-2003 henning

don't set r->qid and r->pqid in expand_rule any more, queue name -> queue ID
mapping is done in kernel land now


# 1.353 07-Apr-2003 dhartmei

Catch and refuse invalid icmp codes (> 255). ok pb@, mpech@.


# 1.352 05-Apr-2003 henning

ease netmask handling a bit

input theo, ok dhartmei@


# 1.351 05-Apr-2003 henning

allow queue specs to be limited to certain interfaces.

altq on { $if0 $if1 $if2 $if3 } priq bandwidth 10Mb queue { one two }
queue one priority 1 priq(default)
queue two on $if0 priority 15
queue two on ! $if0 priority 0

ok dhartmei@


# 1.350 05-Apr-2003 henning

whitespace KNF


# 1.349 04-Apr-2003 henning

clean up:
instead of letting the lexer interpret '<' '>' '=' '>=' '<=' and return them
as PF_OP_LT, PF_OP_GT etc etc etc in PORTUNARY, just let the lexer return
'<' '>' and '=' literally, and in the few cases where the old PORTUNARY was
really used like originally intended, replace that by a new unaryop yacc
target. in all other cases that gets rid of quite some checks wether PORTUNARY
is really < and nothing else etc etc etc.

ok cedric@ deraadt@


# 1.348 27-Mar-2003 henning

lotsa const char *
from David Hill <david at phobia.ms> a while ago


# 1.347 27-Mar-2003 henning

introduce a "yesno" target. eases code a bit and yes is no keyword any more.


# 1.346 27-Mar-2003 henning

handle invalid priq/cbq flags better and give a nice error message


# 1.345 27-Mar-2003 henning

default, borrow, ecn, red and rio are no keywords any more. use STRING and
strcmp instead.


# 1.344 27-Mar-2003 henning

switch symset/symget to TAILQ instead of using hand baked lists

ok dhartmei@ cedric@


Revision tags: OPENBSD_3_3_BASE
# 1.343 19-Mar-2003 henning

branches: 1.343.2;
kill the address token and move the host() invocation up to the host token,
so that host() always gets the full address to be parsed including the
netmask instead of applying the netmask afterwards. this could break some
edge cases and was broken since the (interface)/24 fix.
new token dynaddr for, well, dynaddr, and apply an eventually given netmask
afterwards in the host token just in this case.

found after bug report From: Julien Bordet <zejames@greyhats.org> via dhartmei

ok daniel cedric


# 1.342 10-Mar-2003 henning

correctly cope with errors returned by eval_pfqueue and pfctl_add_altq

ok dhartmei@ pb@ (as part of... you know, monsterdiff)


# 1.341 10-Mar-2003 henning

when complaining about a queue wiwthout parent, include the queue name in
the error message

ok dhartmei@ pb@ (as part of a monsterdiff)


# 1.340 09-Mar-2003 henning

cope with LOOP_THROUGH modifying the lis (queues).
in case of an error in the queue def in question the queues list remains
unmodified, but the LOOP_THROUGH caused a mod anyway, and the list can stay
empty. subsequent checks for NULL which check for a empty list fail then.
fix by adding an explicit check before looping.
fixes regress pfail31
error report by Kamil Andrusz via pb@, testcase from pb@
ok dhartmei@


# 1.339 09-Mar-2003 henning

cope with the fact that LOOP_THROUGH loops once even if the list is empty by
moving the addition of child queues a bit down after the successfull
addition of the current queue and an explicit NULL check before looping.
fixes regress pf59
found by kjc@
ok kjc@ cedric@ dhartmei@


# 1.338 08-Mar-2003 henning

fix the obvious:
since we do not modify the struct pf_altq *a any more but our private copy,
we can of course not inherit teh scheduler type from it, since it did not
inherit the scheduler type from the parent.
so just inherit the scheduler type from the parent directly...

ok dhartmei@ cedric@


# 1.337 08-Mar-2003 henning

in expand_queue, make a private copy of the struct pf_altq before modifying
it. modifying the original one had undesired side effects if a queue was
expanded to more than one because it belonged to more than one interface

ok pb@ cedric@ dhartmei@


# 1.336 06-Mar-2003 henning

fix queue assignment on filter rules which are not bound to an interface.
when looking up the queue IDs using qname_to_qid, we do not need to limit
the matching on the interface in question, as it is guaranteed that same
named queues on different interfaces habe the same queue id. moreover, we
must not limit the matches to the interface if we do not have an interface
given on the filter rule to match on ;-)

found after problems reported by Andre Nathan <andre at v2r dot com dot br>

ok dhartmei@ pb@ cedric@


# 1.335 02-Mar-2003 henning

when printing queues at load time that have bandwidth specified in percent,
print the bandwidth in percent instead of the calculated absolute value.
if a queue belongs to more than one interface and they have different
bandwidth the calculated absolute is of course different per interface.
previously the first calculated absolute value was shown; what of course is
incorrect on the second interface. note that only the print was wrong, the
correct values were passed to the kernel.

ok theo daniel


# 1.334 02-Mar-2003 henning

remove the control keyword for cbq queues.
the control class was a legacy of the original CBQ design by LBL/Sun
to support RSVP.
the control class is not used in openbsd, in the sense that
we don't automatically set filters for ICMP/IGMP/RSVP for the control
class.

ok dhartmei@ kjc@ deraadt@


# 1.333 27-Feb-2003 david

modify error message to match the same 7 sections in pf.conf(5)
ok deraadt@ henning@


# 1.332 26-Feb-2003 henning

in expand_rule, correctly set r->pqid if a priority queue was defined, and
reuse the value of r->qid if not.

ok dhartmei@ mcbride@


# 1.331 25-Feb-2003 henning

some minor KNF my fingers just did...

ok dhartmei@ cedric@


# 1.330 25-Feb-2003 cedric

repair/simplify/flexify binat userland.
ok dhartmei@ henning@


# 1.329 24-Feb-2003 henning

when a macro is redefined, don't bother with reusing the existing entry in
symset() but just prepend a new sym entry to symhead like we always did. as
symget searches the list sequentially, the newest one is picked first.
prevents an endless loop introduced when trying to reuse the existing entry
by an invalid setting for the next pointer.
fixes regress test pf57.

found after conversation with Chris Linn, celinn at mtu dot edu

ok dhartmei@ cedric@


# 1.328 21-Feb-2003 henning

re-allow set loginterface none
ok cedric@ dhartmei@


# 1.327 21-Feb-2003 henning

better error message if set loginterface is called with nonexistant
interface, found by krause (who is doing EXCELLENT work. Thank you very
much!), fix by me, ok dhartmei@ and cedric@


# 1.326 20-Feb-2003 henning

reject nonexistant interfaces in the dynaddr case, noticed during discussion
with jasondixon at myrealbox dot com

ok dhartmei@


# 1.325 19-Feb-2003 dhartmei

Make 'from (kue0)/24' work again (dynamic interface name translation with
a /prefix), reported by Jason Dixon. ok henning@


# 1.324 19-Feb-2003 henning

better error message on icmp version / address family mismatch

ok markus@


# 1.323 18-Feb-2003 henning

fix load option handling (-A, -N, -R) for options.
due to a bug in the loadopt check options were always loaded no matter which
loadopts where specified.
while beeing there, move the prints for that to where they belong, into the
appropriate pfctl_set_* functions, and thus only print when the options are
actually loaded.
fixes regress tests pfopt3, pfopt4, pfopt5 I added earlier.

ok dhartmei@


# 1.322 17-Feb-2003 henning

"optarg" was a bad pick for the variable name in pfctl_cmdline_symset, it
shadows a global. rename.


# 1.321 17-Feb-2003 mpech

-#include <sys/ioctl.h>

mcbride@, dhartmei@ ok


# 1.320 16-Feb-2003 henning

unneeded {}


# 1.319 16-Feb-2003 henning

throw a syntax error if the portunary operator in varset is no '='
extif>"whatever"
should not be the same as
extif="whatever"
but a syntax error.


# 1.318 14-Feb-2003 dhartmei

Allow route-to loopback interfaces again, since Ryan fixed the loops that
might have occured before.


# 1.317 14-Feb-2003 cedric

Better and more consistent error message.
Ok dhartmei@


# 1.316 13-Feb-2003 henning

ease the yacc a bit by using a "not" rule instead of having two rules w/ and
without '!' everywhere

ok dhartmei@


# 1.315 12-Feb-2003 henning

KNF after ryan


# 1.314 12-Feb-2003 mcbride

Simplify the code and make the parser handle the different rule types
more consistently.

- Merge expand_nat and expand_rdr into expand_rule
- Merge rdrrule token into natrule

ok concept henning@
ok dhartmei@


# 1.313 11-Feb-2003 henning

allow macro definition on the command line:
pfctl -Dextif=wi0 -f /etc/pf.conf
command line macro definitions override the ones made in the file (idea
theo), very handy if your notebook has another NIC at some conference, as
well as for debugging etc.
idea rezine@mistrusted.net via pb@
hacked live at FOSDEM

ok pb@ dhartmei@ cedric@


# 1.312 09-Feb-2003 henning

more live code from FOSDEM:
make
pass in proto tcp to port 80
work.
-allow to omit the "any" if you're specifying a port
-allow to omit the from or to part if you want "any" for the other

ok dhartmei@ pb@


# 1.311 09-Feb-2003 henning

KNF


# 1.310 09-Feb-2003 camield

Fix a few warnings and remove unnecessary check and cast.

ok dhartmei henning


# 1.309 08-Feb-2003 dhartmei

Add scrub option 'random-id', which replaces IP IDs with random values
for outgoing packets that are not fragmented (after reassembly), to
compensate for predictable IDs generated by some hosts, and defeat
fingerprinting and NAT detection as described in the Bellovin paper
http://www.research.att.com/~smb/papers/fnat.pdf. ok theo@


# 1.308 05-Feb-2003 cedric

Fix "pass out dup-to (tun0 1.1.1.1) inet6 all" error message
Allow "pass out dup-to tun0 all"
ok mcbride@ henning@


# 1.307 05-Feb-2003 mcbride

Set the network mask to all 1's if no address is specified for a
route-to/dup-to/reply-to rule. Keeps round-robin from incrementing through
the entire address space.

ok dhartmei@


# 1.306 03-Feb-2003 deraadt

pretty


# 1.305 03-Feb-2003 dhartmei

Don't allow loopback interfaces as route/reply/dup-to targets. ok henning@


# 1.304 03-Feb-2003 cedric

remove loadopt global definition and cleanup a bit.
ok henning@


# 1.303 03-Feb-2003 henning

fix a problem with queue definitions when load options (like -N etc) are
given; they used to check for their parent interface/queue even in this
case.

ok dhartmei@ cedric@


# 1.302 02-Feb-2003 henning

there is no need to pass opts to parse_rules explicitely; it's passed as
part of the struct pfctl.


# 1.301 27-Jan-2003 deraadt

KNF


# 1.300 25-Jan-2003 mcbride

Match changes for rdr port ranges made to pf.c:
- fixes behaviour of rdr on le0 from foo to bar port 1:20 -> (lo0) port 22
- makes calculated mapping more explicit for the -> (lo0) port 22:* case

testing from dhartmei@

ok dhartmei@


# 1.299 25-Jan-2003 cedric

Fix NOACTION with table statements.


# 1.298 25-Jan-2003 cedric

Permit initialisation of a table content from a file in pf.conf.
Cleaning up of the table options parsing, more flexible.
idea+cleanup deraadt@, ok dhartmei@, pass all regress tests.


# 1.297 25-Jan-2003 cedric

Correctly check illegal constructs with tables. Better error messages.
ok dhartmei@ pass all regress tests.


# 1.296 25-Jan-2003 henning

if a table name ist too long, it's actually nice to tell so instead of just
aborting with a syntax error


# 1.295 20-Jan-2003 camield

Remove unused argument from print_name() and fix two other nits
found by lint.

ok henning


# 1.294 19-Jan-2003 camield

Spin off label string expansion into a separate function. Clarifies
and tightens all expand_label functions.

ok dhartmei henning


# 1.293 18-Jan-2003 henning

KNF after ryan...


# 1.292 18-Jan-2003 mcbride

Add missing token string and assignment to make static-port work for real.

Diff and report courtesy of mpech@ and form@

ok dhartmei@


# 1.291 17-Jan-2003 camield

bandwith -> bandwidth

YYERROR on failed parseicmpspec()

ok dhartmei mcbride henning


# 1.290 15-Jan-2003 mpech

Typo in yyerror().

henning@


# 1.289 14-Jan-2003 henning

unified IP parser:
-move host(), set_ipmask and the ifa_* functions to pfctl_parser.[c|h]
-extend host() to handle /mask itself, plus minor adjustments
-use that in pfctl_table.c instead of coding the same shit again

discussed w/ cedric@
ok cedric@ dhartmei@


# 1.288 13-Jan-2003 camield

err() on all memory allocation failures

ok henning dhartmei


# 1.287 11-Jan-2003 mcbride

Whitespace KNF


# 1.286 09-Jan-2003 henning

no need for explicit numbering in enums

ok dhartmei@


# 1.285 09-Jan-2003 dhartmei

Check return values on the remaining strlcpy/strlcat. ok henning@


# 1.284 09-Jan-2003 henning

minor KNF


# 1.283 09-Jan-2003 cedric

Add support for active/inactive tablesets in the kernel.
Add table definition/initialisation construct in pfctl parser.
Add and fix documentation for pf.4 and pf.conf.5.
Tested on i386 and sparc64 by myself, macppc by Daniel.
ok dhartmei@


# 1.282 08-Jan-2003 deraadt

check more strlcpy; camield@


# 1.281 07-Jan-2003 dhartmei

Allow underscore at the beginning of strings, fixes
pass all user _spamd
which was refused as syntax error before. Reported by Joe Nall.
ok henning@


# 1.280 07-Jan-2003 dhartmei

Remove table name hashing (pass the name in each ioctl instead), and
introduce reference counting for tables, they are now automatically
created and deleted through referencing rules. Diff partly from cedric@.
ok mcbride@, henning@, cedric@


# 1.279 06-Jan-2003 mcbride

Fix some oversights with address pools for route-to/dup-to/reply-to
- copy key for src-hash
- copy pool type (pools were being set to round-robin in all cases)

+ some minor knf.

ok dhartmei@


# 1.278 05-Jan-2003 henning

err after calloc failure, not errx


# 1.277 05-Jan-2003 dhartmei

Move ifname from pf_addr to pf_addr_wrap, prepare pf_addr_wrap for table
name. ok henning@, mcbride@, cedric@


# 1.276 04-Jan-2003 dhartmei

move noroute from flag in pf_rule_addr into type in pf_addr_wrap.
ok henning@, mcbride@


# 1.275 04-Jan-2003 deraadt

I do not know where this policy of "one .h file for every .c file" comes
from, but whoever thought of it is stupid.


# 1.274 03-Jan-2003 dhartmei

whitespace KNF (no, i don't touch the option inits)


# 1.273 03-Jan-2003 cedric

Bring in userland code for accessing PF radix tables.
ok dhartmei@ mcbride@


# 1.272 02-Jan-2003 mcbride

Require a direction to be specified for rules which do routing.

ok dhartmei@ henning@


# 1.271 30-Dec-2002 mcbride

Change ipv6-icmp-type to icpm6-type. pf.conf files will need to be adjusted
to reflect this.

ok dhartmei@ henning@


# 1.270 27-Dec-2002 mcbride

Since pf_norm.c looks at rule.log to see if it should log packets being
dropped due to scrub violations, this adds the ability to set this in
pf.conf.

ok henning@


# 1.269 21-Dec-2002 henning

always initialize rpool.key; diff from Frank Denis; KNF by me


# 1.268 21-Dec-2002 henning

KNF


# 1.267 20-Dec-2002 dhartmei

remove a redundant assignment.


# 1.266 19-Dec-2002 dhartmei

fix 'no rdr'.


# 1.265 18-Dec-2002 henning

more KNF


# 1.264 18-Dec-2002 dhartmei

proto list expansion is not supported in binat-anchor yet, print an error
when attempted.


# 1.263 18-Dec-2002 dhartmei

Support (single) destination port in rdr-anchor rules. Print an error
where parameters are not supported (in rdr-anchor and binat-anchor) yet.
If those are needed, we'll have to expand them properly.


# 1.262 18-Dec-2002 deraadt

fix some INCREDIBLE new bugs which were introduced


# 1.261 17-Dec-2002 henning

add support for the PRIQ scheduler

partitially from kjc@

ok kjc@ dhartmei@


# 1.260 17-Dec-2002 mcbride

Match merge of pf_nat/pf_binat/pf_rdr structs into pf_rule

ok dhartmei@ henning@


# 1.259 17-Dec-2002 henning

missing break in switch


# 1.258 17-Dec-2002 henning

beautify the %type block


# 1.257 17-Dec-2002 henning

PRIQ and HFSC support functions, not yet used.
mostly from kjc@ with adjustments by me.

ok theo ryan daniel


# 1.256 16-Dec-2002 henning

only create a root queue if scheduler = cbq


# 1.255 16-Dec-2002 henning

get full [scheduler]_opts struct instead of just .flags, and wrap in into a
switch (scheduler) statement in one case

inspired by kjc@


# 1.254 13-Dec-2002 henning

allow a second queue for higher priorized (currently: tos=lowdelay) packets
to be specified per rule

queue (qname, priorized_qname)

idea dhartmei
ok dhartmei@ frantzen@ deraadt@


# 1.253 13-Dec-2002 henning

a bit KNF originally part of another diff soon to come; frantzen@ correctly
pointed out that should be a seperate commit.


# 1.252 13-Dec-2002 deraadt

permit re-ordering of some scrub parameters, and also clean up some other
grammer balony; henning ok


# 1.251 12-Dec-2002 henning

KNF


# 1.250 12-Dec-2002 henning

we don't need to keep a private copy of the queue name in expand_rule,
r->qname is never modified

discussed with dhartmei@


# 1.249 11-Dec-2002 mcbride

Replace strncpy + ugly pointer math with sscanif for reading source-hash keys

ok dhartmei@ henning@


# 1.248 09-Dec-2002 dhartmei

(properly guarded) strcpy() -> strlcpy()


# 1.247 09-Dec-2002 deraadt

do not allow redefinitions in variable option blocks; henning ok


# 1.246 08-Dec-2002 henning

strncpy is evil.


# 1.245 08-Dec-2002 henning

allow flexible options order like Theo did for rules.

idea, lots of input, motivation and ok deraadt@

ATTENTION:
this changes the syntax. the "scheduler" keyword is gone now.
old: altq on $interface scheduler cbq ...
new: altq on $interface cbq ...


# 1.244 07-Dec-2002 dhartmei

Support parameters in anchor rules. Allows conditional evaluation, like:

anchor spews inet proto tcp from any to any port smtp

ok deraadt


# 1.243 07-Dec-2002 henning

more KNF


# 1.242 07-Dec-2002 henning

KNF


# 1.241 07-Dec-2002 henning

shadow cleanup

ok mcbride@ frantzen@


# 1.240 07-Dec-2002 henning

kill an unused param to lungetc


# 1.239 07-Dec-2002 mcbride

Convert the hash of a string key to network byte order. Makes regression
work on all platforms.

Bug found by dhartmei@

ok dhartmei@ henning@


# 1.238 06-Dec-2002 dhartmei

Remove negated address list check again, doesn't work right yet.


# 1.237 06-Dec-2002 dhartmei

Introduce anchors and named rule sets, allowing to load additional rule
sets with pfctl and evaluate them from the main rule set using a new type
of rule (which will support conditional evaluation soon). Makes
maintenance of sub-rulesets simpler for pfctl and daemons.

Idea and ok deraadt@


# 1.236 05-Dec-2002 henning

fix a small cosmetic problem. if ifa_lookup was called in LOOKUP_NET mode,
it would return things like 127.0.0.1/8. when 127.0.0.1/8 is passed through
the new selftests, it becomes 127.0.0.0/8.
fix: instead of just copying addr.mask in ifa_lookup, use set_ipmask, so it
is 127.0.0.0/8 from the beginning on.


# 1.235 05-Dec-2002 henning

-quote varset in -v output
-don't add 's' in set timeout -v output

makes the feedback regression tests succeed.

ok markus@ mcbride@


# 1.234 04-Dec-2002 henning

in host(), apply a given netmask to all members of the node_host list
returned by ifa_lookup().

reported by Alejandro G. Belluscio

ok dhartmei@


# 1.233 04-Dec-2002 deraadt

do not warn for unused variables except with -v -v; henning ok


# 1.232 02-Dec-2002 henning

KNF


# 1.231 02-Dec-2002 deraadt

permit more flexible pass/block lines. the options giving at the end of
a line can now be placed in any order, and some merging of duplicat options
is also done. this is easier to use.


# 1.230 02-Dec-2002 henning

allow for "altq on $interface" without specifying a bandwidth. The
interface's bandwidth is taken then.
as a side-effect, "altq on $interface bandwidth xx%" is also possible now,
it's relative to the interface's bandwidth then.

ok theo


# 1.229 30-Nov-2002 mickey

move damn unmask() proto into place as well


# 1.228 29-Nov-2002 henning

coredumps are not nice.
deal with the fact that when we are merging the lists in host_list both can
be NULL.
found at EuroBSDCon 2002 while I was explaining the expansion process to
Paul de Weerd

ok dhartmei@


# 1.227 29-Nov-2002 henning

print queuespec only once in verbose mode, even if referenced more often


# 1.226 29-Nov-2002 henning

FREE_LIST nqueues later; can be used more than once


# 1.225 28-Nov-2002 henning

allow qlimit on altq spec


# 1.224 28-Nov-2002 mcbride

- Adjust to match replacement of md5 with pf_hash
- Allow keys to be specified in hex (must be 128 bits, mainly to make
pfctl -v output paresable by pfctl) or as a string. Randomly generate key
if one is not specified.

Suggestions and fixes from camield@

ok mickey@ camield@ henning@


# 1.223 27-Nov-2002 henning

handle the "no bandwidth specified" case earlier and easier.


# 1.222 27-Nov-2002 henning

-use a #define for default qlimit instead of hardcoding it
-print qlimit in print_queue if it is not the default one
-assign the default qlimit early in the parser instead of using 0


# 1.221 27-Nov-2002 henning

next round in print fixes:
-only print priority if it is not equal to the default one
-space handling overhaul


# 1.220 27-Nov-2002 henning

use a #define for default priority instead of hardcoding it


# 1.219 27-Nov-2002 henning

fix tbrsize spec


# 1.218 27-Nov-2002 henning

fix error message for altq ifspec without child queues


# 1.217 26-Nov-2002 henning

make bandwidth specification on queue truly optional


# 1.216 26-Nov-2002 henning

queue comes before NAT


# 1.215 25-Nov-2002 henning

repair decide_address_family
you cannot just taked the first address family you meet as rule's address
family... either all are equal, or the rule has no explicit AF.

found by danh@
ok theo


# 1.214 25-Nov-2002 mickey

for loN and link1 translate the iface into address properly; henning@ ok


# 1.213 25-Nov-2002 henning

1Kb = 1000b, not 1024; as discussed with kjc@ and theo


# 1.212 25-Nov-2002 henning

KNF


# 1.211 24-Nov-2002 pb

enforce that queue comes right before filtering
'options, normalization, translation, queue, filter' now

henning@ ok


# 1.210 24-Nov-2002 dhartmei

Cosmetics and removal of a redundant code block.


# 1.209 23-Nov-2002 deraadt

sigh


# 1.208 23-Nov-2002 henning

KNF


# 1.207 23-Nov-2002 henning

better error checking in expand_queue


# 1.206 23-Nov-2002 henning

easier


# 1.205 23-Nov-2002 mcbride

Daniel's diff to untangle my mess with ifa_pick_ips like so:

- add decide_address_family() which runs through the list to find hosts
with the af set
- replace ifa_pick_ips with remove_invalid_hosts() which removes hosts with
the wrong address family from the list

from/ok dhartmei@


# 1.204 23-Nov-2002 henning

better error checking, round 1
this time in expand_altq


# 1.203 23-Nov-2002 henning

KNF


# 1.202 23-Nov-2002 deraadt

KNF


# 1.201 23-Nov-2002 dhartmei

$$->ifname is NULL, leave it NULL, don't $$->ifname[0] = 0;


# 1.200 23-Nov-2002 mcbride

Fix brokenness in parse.y, clean up:
- remove requirement for ( ) in route-to ( if )
- calloc route_host
- initialise route_host->next
- globally convert malloc to calloc

ok dhartmei@


# 1.199 23-Nov-2002 mcbride

code to support loading of pf rules with multiple redirection addresses
(in nat, rdr, route-to, dup-to and reply-to)

Syntax looks like this, see pf.conf(5) for details:

nat on wi0 proto { tcp, icmp } from any to 192.168.0.2 -> \
192.168.0.16/29 source-hash random

rdr on wi0 proto { tcp } from any to 192.168.0.34 port 22 -> \
{ 192.168.0.8/31, 192.168.0.15 } port 22 round-robin

ok dhartmei@ henning@


# 1.198 22-Nov-2002 henning

print altq and queue lines in the pfctl -v case including the child queue
assignment


# 1.197 19-Nov-2002 henning

only take cbq opts from schedtype if type=CBQ


# 1.196 19-Nov-2002 henning

repair queuespec syntax glitch, theo agrees


# 1.195 19-Nov-2002 henning

default priority is 1, not 0
found by pb@


# 1.194 19-Nov-2002 camield

- match 'Gb' case-sensitively
- match "%" unit only, not "%crap"

ok henning@


# 1.193 19-Nov-2002 wilfried

icmp-type was off by one, ok henning@


# 1.192 18-Nov-2002 deraadt

no; do not use };


# 1.191 18-Nov-2002 henning

more using strl* return values instead of strlen calls


# 1.190 18-Nov-2002 henning

easier "queue name too long" detection; from theo


# 1.189 18-Nov-2002 deraadt

KNF


# 1.188 18-Nov-2002 deraadt

KNF


# 1.187 18-Nov-2002 henning

altq and pf merged

this isn't 100% done yet: the print_ stuff isn't finished, some features
will be added later, and there is no documetation yet, but committing now
enables a few more people to work on.

print_altq_node stuff hacked by Daniel at euroBSDcon; lotsa stuff from kjc,
debugging help also pb and camiel. lots of good ideas by theo.

"commit now" theo philipp daniel


# 1.186 13-Nov-2002 henning

as scrub rules end up in a struct pf_rule just call expand_rule instead of
handcrufting this.
has quite a few positive side effects:
-interface list expansion works (fries@ asked for that)
-can specify address family, very helpful with dynamic interface expansion
(pointed out by daniel)
-src/dst ip/port list expansion works
-fixes a long standing, scary, though never noticed bug:
scrub out on lo1 from any to 10.0.0.1
expanded to
scrub out on lo1 all
... this bug was there from day #1.

"sneaky diff of the month award" dhartmei@


# 1.185 13-Nov-2002 dhartmei

Add label macro $if, as we support {} list expansion for interfaces now.
From David Gwynne. ok henning@, camield@


# 1.184 13-Nov-2002 dhartmei

Initialize tail pointer to node, found by fries@


# 1.183 08-Nov-2002 henning

init buf to NULL just in case...
there isn't a single codepath where it can remain uninitialized, but this
might prevent a stupid bug if we change something later


# 1.182 07-Nov-2002 henning

move the ifa_exists block a bit up in host()
inspired by mpech@ pointing out a missing free(buf). so handle the
it-is-an-interface case where we don't need the buf before allocating memory.


# 1.181 04-Nov-2002 henning

welcome to CIDR world, pfctl!

use inet_net_pton to parse IP adresses.
stuff like
block in from 10/8 to any
works now.

some input camield@ and dhartmei@

ok dhartmei@, camield@, mcbride@


# 1.180 02-Nov-2002 dhartmei

%i -> %d, matches the style of existing code, from millert@


# 1.179 02-Nov-2002 dhartmei

printf int with %i, not %u. from pilot@monkey.org.


# 1.178 30-Oct-2002 henning

simplify


# 1.177 30-Oct-2002 henning

fix interface expansion. since the reversed list expansion code was
committed this was broken, only the first IP address was returned.

pointed out by danh@, who sent an excellent bug report.

ok dhartmei@


# 1.176 29-Oct-2002 henning

introduce
set require-order [yes|no]
default is yes.
with set to "no", it isn't required to have the rules in order (options,
scrub, nat, filter) any more, though of course NATing still happens before
filtering and so on, so one has to take care.

ok camield@ mcbride@ dhartmei@
idea discussed with a whole lotta more people and basically ok for everyone ;-)


# 1.175 27-Oct-2002 henning

remove the "flags X" syntax.
noone who wrote "flags S" meant that, but actually something like "flags
S/SA". with "flags S" changing its actual meaning as more flags got
supported, things got worse.

ok dhartmei@, pb@


# 1.174 22-Oct-2002 mpech

%ul -> %lu

dhartmei@ ok


# 1.173 22-Oct-2002 mcbride

More conversion of "int af" and "u_int8_t af" declarations and function
arguments to the more correct and descriptive "sa_family_t af"

ok dhartmei@ henning@


# 1.172 22-Oct-2002 camield

Rename ipmask to set_ipmask and add some functionality: the netmask
is applied immediately to the address.

This way, the parsed rules output shows exactly which bits of an
address are significant for a match and errors due to wrong netmasks
can be spotted more easily.

Example:
$ pfctl -nvf -
pass in on lo0 from 172.17.0.0/12 to any
@0 pass in on lo0 inet from 172.16.0.0/12 to any

idea refined by dhartmei@
ok frantzen@ henning@


# 1.171 17-Oct-2002 mcbride

These checks are also made in nat_consistent() and rdr_consistent().

ok dhartmei@ henning@


# 1.170 17-Oct-2002 camield

- accept all protocols that are specified by number if they are in
the valid range (also when they're not listed in /etc/protocols)
- explicitly disallow protocol number 0, because it has special meaning
to pf

ok dhartmei@ henning@


# 1.169 16-Oct-2002 mpech

Fix and improve binat mask comparison.

dhartmei@, henning@ ok


# 1.168 14-Oct-2002 henning

Allow one to specify a netblock in a binat rule:

binat on fxp0 from 192.168.0.32/27 to any -> 10.0.7.128/27

Both the network mask on the source and redirect addresses MUST be the
same, and it works by essentially combining the network section of the
redirect address with the host section of the source address.

from ryan

ok dhartmei@


# 1.167 11-Oct-2002 camield

When a macro cannot be expanded because it is not defined, say so. Also warn
about unused macros.

ok dhartmei@ henning@


# 1.166 11-Oct-2002 camield

In lgetc(), compress strings of whitespace to a single space. This makes
macros come out right in verbose mode and is less functional overhead.

Also err on whitespace after a backslash. That type of error is hard to
find otherwise.

ok dhartmei@ henning@


# 1.165 08-Oct-2002 vincent

remove <0 checks on unsigned numbers.

ok henning@


# 1.164 07-Oct-2002 dhartmei

-Wsign-compare clean


# 1.163 07-Oct-2002 dhartmei

Two cases of const-correctness and make one global local.


# 1.162 07-Oct-2002 henning

set block-policy [drop|return]
drop is default, same behaviour as before

support
block drop
to override a return policy


# 1.161 07-Oct-2002 henning

support a generic return
block return in|out ...
acts like return-rst on tcp, like return-icmp on udp and like an ordinary
block on anything else

ok dhartmei@


# 1.160 07-Oct-2002 henning

make return-icmp work for rules covering both v4 and v6
-new field "return_icmp6" in�pf_rule
-parser accepts
block return-icmp(ipv4-icmpcode, ipv6-icmpcode)

ok and some input dhartmei@


# 1.159 07-Oct-2002 henning

use a new rule_flag PFRULE_RETURNICMP to decide wether to return-icmp or not
instead of just testing return_icmp > 0

ok dhartmei@


# 1.158 07-Oct-2002 dhartmei

Add 'reply-to' to filter rules, similar to route-to, but applying to
replies (packets that flow in the opposite direction of the packet that
created state), used for symmetric routing enforcement.
Document how route-to and reply-to work in context of stateful filtering.


# 1.157 06-Oct-2002 dhartmei

Move CHECK_ROOT into LOOP_THROUGH, gets rid of one macro and saves
several lines, no functional difference. From Camiel Dobbelaar.


# 1.156 05-Oct-2002 dhartmei

Expand {} lists from left to right, so 'pass in from { a, b } to any'
becomes '@0 pass in from a to any @1 pass in from b to any' instead of
the other way around. Patch from Camiel Dobbelaar.


# 1.155 05-Oct-2002 dhartmei

Allow filtering based on IP header's tos field.


Revision tags: OPENBSD_3_2_BASE
# 1.154 22-Sep-2002 henning

little KNF: return(something) -> return (something)


# 1.153 22-Sep-2002 henning

fix linenumber counting in findeol, and simplify by ignoring the \ case,
that's already handled earlier.
fast-forward on errnous lines

partitially from camield@, parts result of a discussion with Mike

ok frantzen@ dhartmei@


# 1.152 22-Sep-2002 henning

antispoof, take 2.
also block incoming packets with our own IP as src.

discussion & help frantzen

ok ho@ dhartmei@ frantzen@


# 1.151 17-Sep-2002 henning

easier "self" implementation.
no functional changes

ok pb@


# 1.150 15-Sep-2002 henning

set a netmask in the dynaddr case
noticed by <han@mijncomputer.nl>

ok pb@


# 1.149 14-Sep-2002 henning

bit more clue in rdr/nat rules wrt address family examination
don't take the af from host_node structs based on interface lookups, most
interfaces will have both IPv4 and IPv6 addresses. Most rdr/nat rules will
at least have one IP address specified from whoch we take the af for the
whole rule. The rare exceptional cases require the user to specify the af.

ok frantzen@


# 1.148 12-Sep-2002 henning

check for calloc() failure; ho@


# 1.147 12-Sep-2002 henning

antispoof [log] [quick] for [interface|interface_list] [af]

e. g.

antispoof log quick for { dc0, dc1 } inet

docs & regress coming

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@
IPv6 help itojun@

finally, a long story finds its happy end here.


# 1.146 12-Sep-2002 henning

rework netmask handling:
-don't set netmask in host token handler
-clear netmask in ipmask() proper before setting it
-in ifa_load(), also store interface's netmask and broadcast address
-allow ifa_lookup() to return either the interface's IP address(es), network(s)
or broadcast address(es) - not used anywhere yet. This implies that
ifa_lookup() also returns the netmask now.
-host() returns netmasks, too

ok pb@, frantzen@, deraadt@
also looked over kjell@, markus@, itojun@, dhartmei@


# 1.145 08-Sep-2002 henning

be more clueful wrt address family in nat/rdr rules.
behaviour noticed by Paul de Weerd, thanks!

ok dhartmei@


# 1.144 02-Sep-2002 dhartmei

Fix parsing of port ranges in translation rules (port a:b -> port c:d).
ok henning@


# 1.143 02-Sep-2002 dhartmei

Make sure the interface specified with route-to/dup-to/fastroute exists
and null-terminate the interface name. Found by Michael Wallis.
ok henning@


# 1.142 20-Aug-2002 dhartmei

Increase lineno on newlines inside multi-line macro definitions, otherwise
errors on subsequent lines are reported with wrong line numbers.
From Paul B. Henson.


# 1.141 16-Aug-2002 henning

kill duplicated check for '(' and ')' in allowed_in_string


# 1.140 12-Aug-2002 dhartmei

Catch null pointer deref (segfault), from wilfried@


# 1.139 06-Aug-2002 henning

missing free(), mpech@
ok pb@


# 1.138 06-Aug-2002 henning

check fo strdup() allocation errors

pointed out by mpech@
ok pb@


# 1.137 31-Jul-2002 henning

KNF, esp. missing prototypes


# 1.136 30-Jul-2002 henning

grmpf.
in some cases, on non-tcp rules flags weren't resetted. cosmetical only
problem. but, well, checking for r->flags and r->flagset if we could have
assigned them zero just one round ago is just stupid, and it's not needed to
check them at all.

ok pb@, dhartmei@


# 1.135 30-Jul-2002 henning

allow to specify flags on all rules that include tcp.

these are valid:

pass in from any to any flags S
pass in proto { tcp, udp, icmp } from any to any flags S
pass in proto tcp from any to any flags S

these are invalid:

pass in proto { udp, icmp } from any to any flags S
pass in proto udp from any to any flags S

ok "I've lost my slacker status for at least a week" frantzen@
ok pb@, dhartmei@, deraadt@


# 1.134 26-Jul-2002 henning

make the order of log and quick irrelevant. now both
block in log quick all
and
block in quick log all
work.

ok dhartmei@, deraadt@


# 1.133 23-Jul-2002 henning

timeout_list/_spec and limit_list/_spec don't return anything -> no %type.

ok theo


# 1.132 21-Jul-2002 deraadt

fix route-to also


# 1.131 21-Jul-2002 deraadt

make the , optional in many places. This makes string concat a lot more
useful. Now you can
in = ssh domain www
out = $in ftp finger
pass in proto tcp from any to any port { $in }
pass out proto tcp from any to any port { $out }
a poor example, but the idea is obvious


# 1.130 21-Jul-2002 deraadt

string concat, ie.
a=a b
c=$a $a


# 1.129 20-Jul-2002 deraadt

minor indent tweaks


# 1.128 20-Jul-2002 deraadt

properly split yacc and lex use


# 1.127 19-Jul-2002 deraadt

minor tweaks, sigh


# 1.126 19-Jul-2002 dhartmei

And back out the last change again.


# 1.125 19-Jul-2002 henning

rework the interface lookup routines internals.
less and easier code than before.
no functional changes.

ok frantzen@, dhartmei@


# 1.124 19-Jul-2002 dhartmei

Support # comments at the end of lines and inside (multi-line) string
literals, so you can do things like

macro="{ foo, # first entry
bar, # second entry
baz }" # last entry

or

pass in on $ext_if \ # external interface
proto tcp \ # TCP connections
from any to $ext_if \ # to the gateway itself
keep state

And sneaking in two minor fixes for KNF.


# 1.123 19-Jul-2002 henning

deal with the fact that the struct node_host ifa_pick_ip gets is not always
the result of an interface expansion. in this case ifa_pick_ip does an
address family check (that's actually a (wanted) side effect). Thus, we need
to spit out a meaningfull error message in case of a mismatch.
also adjust all the other error messages, they were also assuming that nh is
the result of an interface expansion.
after a looooong discussion on icb (dhartmei@, pb@, me) we agreed on the term
"translation address" for that.

okay dhartmei@


# 1.122 17-Jul-2002 henning

support "self" as address. self expands to all IPv4 and IPv6 addresses of
the machine, on all interfaces. I wanted
block in log on ! lo0 from any to self
for years, and now it's possible.

ok "I may lose my slacking status if I OK it" frantzen@
ok dhartmei@

documentation in pf.conf.5 to come with pb@'s rewrite


# 1.121 16-Jul-2002 dhartmei

Add nat_consistent() and rdr_consistent() for checks that should occur
after rule expansion, similar to rule_consistent(). Fixes the
non-effective test for rdr rules for non-TCP/UDP protocols with ports,
found by mpech@, ok frantzen@


# 1.120 15-Jul-2002 henning

add support for
pass|block on ! $interface ...

ok dhartmei@

will be documented in pf.conf(5) by "I'm not slacking!" pb@ who's currently
reworking this manpage


# 1.119 15-Jul-2002 pb

cosmetics/consolidations to manpage in yyerror()s

ok henning@, dhartmei@


# 1.118 15-Jul-2002 henning

o complain about keep state on block rules
o complain about return-rst on rules which aren't limited to tcp

pointed out by not-slacking-but-testing pb@

ok pb@, dhartmei@


# 1.117 13-Jul-2002 henning

add list expansion for interface and proto in nat rules and for proto in rdr
rules (interface was already there). since the nat.conf/pf.conf merge the
parser accepted these but didn't expand them. ugh.

ok dhartmei@


# 1.116 09-Jul-2002 itojun

check sin6_scope_id field, just in case we change the routing socket API
for scoped address (unlikely due to the deployed codebase...).


# 1.115 09-Jul-2002 itojun

getifaddrs(3) grabs link-local addrs in kernel internal form, convert them
into proper sockaddr_in6.


# 1.114 09-Jul-2002 henning

rework the interface-to-IP routines.

you can use interface names instead of an IP in most places. However, until
now, it was only expanded to the interface's first IPv4 address if existant
(and address family unset or inet) and the first IPv6 address otherwise.

this diff changes that. the interface is proper expanded to all IPs, IPv4
_and_ IPv6, now.

it also cleans up the lookup procedures (well, in fact, they are replaced by
a new one), there's no need for different procedures for IPv4 and IPv6. we
now just have one list of interfaces (AF_LINK) and one list with IPs
(AF_INET and AF_INET6) with corresponding lookup functions, ifa_exists and
ifa_lookup.

nat, rdr & friends now use the new function ifa_pick_ip to get the IP in
rules like

nat on $interface from $whatever to any -> $interface

ifa_pick_ip tries to be smart.
if the interface has only one IP address and the nat rule doesn't specify an
address family (or it matches with this address), take this one.
If the address family is specified in the nat rule and there is only one IP
for the given address family, this one is used. if the address family is not
specified and there is more than one IP pfctl throws an error. The same
applies for multiple IPs per address family.

This causes regression tests 18 and 20 to fail because the address family
isn't specified there; diff for those coming.

also fix some prototypes while I'm here.

pb@ found another problem while testing that we must have introduced somewhat
after 3.1.

$cat t
nat on ne3 from any to any -> 213.128.133.5
$pfctl -nvf t
nat on ne3 all -> ?

it's only a representation bug as far as I've checked, nontheless it should
be fixed. as a nat/rdr rule always nats/redirects to one IP only we can just
steal its target's IP af and set the rule's af accordingly. then inet_ntop
does play nice.
binat rules already enforce having an address family set always and thus are
not affected.

ok dhartmei@, pb@, kjell@
"It looks good" frantzen@


# 1.113 08-Jul-2002 dhartmei

Don't allow 'flags' option in non-TCP rules, found by mpech@


# 1.112 05-Jul-2002 henning

unbreak.


# 1.111 05-Jul-2002 henning

another small bug I found while installing a -current pf firewall.
we don't support

pass/block in on ! <interface>

(at least, not yet)
let the parser complain instead of ignoring the '!'

ok pb@, dhartmei@


# 1.110 01-Jul-2002 espie

streamline parse buffer handling (no need to copy value that is not
going to go away).

add explicit pushback buffer, to be able to push IPv6 failed parses back.

handle pushback + parse buffer interactions by using negative indices.

okay dhartmei@, deraadt@


# 1.109 01-Jul-2002 deraadt

KNF


# 1.108 28-Jun-2002 dhartmei

Don't check for address family conflicts in nat/rdr before expansion,
rules will expand to all valid combinations, and there's an error when
none is found. Makes "nat on tun0 from 10.0.0.0/8 to any -> (tun0)"
work (again).


# 1.107 25-Jun-2002 henning

move pfctl options -t, -m, -O and -l to pf.conf. These are set using the
"set" keyword. example rulefile:

set optimization aggressive
set timeout { tcp.closing 6, tcp.opening 6 }
set limit { states 1000, frags 1000 }
set loginterface wi0
pass out all keep state label "$nr:$srcaddr:$srcport:$dstaddr:$dstport"
block in all

fries@ is working on an updated pf.conf(5)
discussed at c2k2 and on icb
ok dhartmei@, kjell@


# 1.106 24-Jun-2002 dhartmei

Use interface when specified in scrub rule. No support for ! or {} yet.


# 1.105 23-Jun-2002 deraadt

uid_t and gid_t are unsigned


# 1.104 20-Jun-2002 dhartmei

Copy address family from inet/inet6 keyword, if specified.


# 1.103 18-Jun-2002 frantzen

propogate a '!' when a host resolves to multiple IP addresses
ok dhartmei@


# 1.102 18-Jun-2002 frantzen

don't allow individual keep state rules to specify timeouts for 'interval' and
'frag' -- they aren't applied anyway
ok dhartmei@ and henning@


# 1.101 16-Jun-2002 aaron

Rules must in order -> Rules must be in order


# 1.100 15-Jun-2002 dhartmei

Reset rulestate in parse_rules(), so consecutive calls (like from authpf)
will not fail. Reported by Chris Kuethe.


# 1.99 13-Jun-2002 kjell

Fix the numbering of scrub rules. pointed out and oked by frantzen@


# 1.98 12-Jun-2002 kjell

Fix uninitialized access. Spotted by danh@ This is a good reason to
develop with "ln -s 'J' /etc/malloc.conf" enabled.
ok henning@


# 1.97 11-Jun-2002 frantzen

split the grammar of scrub(fragcache) into scrub ... 'fragment reassemble',
'fragment crop' or a new 'fragment drop-ovl' which will drop overlapping
fragments and all corresponding ones
ok kjell@ with feedback from kjell@ and deraadt@. the rest are slacking


# 1.96 11-Jun-2002 frantzen

SCRUB(fragcache) to do gap tracking and overlap pruning of IPv4 fragments
without the memory overhead of the conventional defrag in SCRUB
ok dhartmei@, idea by deraadt@


# 1.95 11-Jun-2002 dhartmei

Make NAT proxy port range configurable per rule, for instance privileged
source ports can mapped to privileged proxy ports, or source port 500
to proxy port 500. ok frantzen@


# 1.94 10-Jun-2002 kjell

Merge the NAT and rules files into a single rulefile. Rules must be
in this order, to remove any ambiguity about what order things happen in:

scrub rules
nat rules
filter rules

The -N and -R modifiers go away. Rulefiles are now loaded with the
more POSIXly-correct '-f'

ok frantzen@


# 1.93 10-Jun-2002 dhartmei

Allow ports to be specified in nat rules, useful later on for individual
proxy port ranges.


# 1.92 10-Jun-2002 dhartmei

Move enum out of struct (gcc 3.1 wasn't happy), from David Krause


# 1.91 10-Jun-2002 kjell

split scrub rule processing into its own yacc target,
for imminent config file merge. ok frantzen@


# 1.90 09-Jun-2002 dhartmei

Make pf_nat.saddr/daddr a pf_rule_addr instead of pf_addr_wrap, so it
includes ports and operator.


# 1.89 09-Jun-2002 deraadt

spaced out developers...


# 1.88 09-Jun-2002 kjell

Add list parsing in RDR rules: e.g.

rdr on $IFLIST proto tcp from $SRC_LIST to $DST_LIST port 21 \
-> 127.0.0.1 port 8021

ok dhartmei@


# 1.87 08-Jun-2002 henning

nuke unused parameter af to expand_label_port
ok dhartmei@, pb@


# 1.86 08-Jun-2002 dhartmei

Change remaining read-only lookup tables to const, suggestion drahn@


# 1.85 08-Jun-2002 itojun

comment on IPv6 link-local twists


# 1.84 08-Jun-2002 kjell

add list expansion to src/dest in NAT rules. i.e.

nat on fxp0 from { 10.0.0.0/24, 10.0.1.0/24 } to \
{ 172.6.1.1, 172.14.1.2/32 } -> fxp0

ok theo, dhartmei@


# 1.83 08-Jun-2002 henning

remove macro concatenation via += per Theo's advice


# 1.82 08-Jun-2002 henning

allow macro concatenation like
webservers = "{ 10.0.0.1, 10.0.0.7, 10.0.0.8, "
webservers += " 10.0.0.17, 10.0.0.25, 10.0.0.37 }"
ok frantzen@, dhartmei@


# 1.81 08-Jun-2002 dhartmei

Make state timeouts configurable per rule, like

pass in from any to any port www keep state (tcp.established 60)

ok frantzen@


# 1.80 08-Jun-2002 henning

expand $nr -> rule number in rule labels
okay dhartmei@, frantzen@


# 1.79 08-Jun-2002 henning

expand $proto in rule labels
okay frantzen@ dhartmei@


# 1.78 07-Jun-2002 dhartmei

Handle realloc() failure gracefully. Terminates with err() anyway in this
case, but we don't want to trigger "p = realloc(p," grepping causing false
alarms here.


# 1.77 07-Jun-2002 deraadt

henning, read this to see what i mean by KNF


# 1.76 07-Jun-2002 pb

add the possibility to configure a TTL while return-rst

ok dhartmei@, ipv6 part itojun@ ok


# 1.75 07-Jun-2002 dhartmei

Add "(max <number>)" option for "keep/modulate state" to limit the number
of concurrent connections a rule can create. ok frantzen@


# 1.74 07-Jun-2002 henning

allow using $srcaddr, $srcport, $dstaddr and $dstport in rule labels,
evaluated at parse time.
ok dhartmei@


# 1.73 07-Jun-2002 itojun

make IPv6 scope identification work for dst (from any to fe80::1%lo0)


# 1.72 07-Jun-2002 itojun

support scoped IPv6 address in from/to portion.


# 1.71 01-Jun-2002 hugh

ECN flag support for pf. Committed in consultation with Daniel.


# 1.70 24-May-2002 dhartmei

Support mixed (IPv4/v6) address lists, expand to all possible and valid
combinations. 'pass in from { 10.1.2.3, ::1 } to { 10.4.5.6, ::2 }' will
expand to two rules, 'from 10.1.2.3 to 10.4.5.6' and 'from ::1 to ::2'.
Also applies to host name resolution (when multiple addresses are returned
for one name). ok frantzen@, itojun@


# 1.69 23-May-2002 deraadt

tiny KNF, some malloc checks, etc


# 1.68 23-May-2002 itojun

new_addr is not used from anywhere. daniel@benzedrine.cx ok


# 1.67 19-May-2002 deraadt

KNF


# 1.66 12-May-2002 dhartmei

Explain that user/group 'unknown' can only be used with operators = and !=
and refuse other constructs in the parser. Also note that 'user >= 0' does
not match forwarded packets with unknown user ID.


# 1.65 12-May-2002 dhartmei

Add gid based filtering, reduce to one (effective) uid, rename parser
keywords to 'user' and 'group'.


# 1.64 10-May-2002 dhartmei

Handle host name resolution returning multiple addresses in the rule
parser (expand to every address). ok frantzen@


# 1.63 09-May-2002 jasoni

Add a max-mss option to the scrub rule which will enforce a maximum mss
by lowering it to the given value.
- ok dhartmei@, provos@


# 1.62 09-May-2002 dhartmei

Introduce user based filtering. Rules can specify ruid and euid (real and
effective user ID) much like ports. The user of a packet is either the
user that opens an outgoing connection, the one that listens on a socket,
or 'unknown' if the firewall is not a connection endpoint (for forwarded
connections). Socket uid lookup code from jwk@bug.it.


# 1.61 24-Apr-2002 dhartmei

Add dynamic (in-kernel) interface name -> address translation. Instead of
using just the interface name instead of an address and reloading the rule
set whenever the interface changes its address, the interface name can be
put in parentheses, and the kernel will keep track of changes and update
rules. There is no additional cost for evaluating rules (per packet),
the cost occurs when an interface changes address (and the rules are
traversed and updated where necessary).


# 1.60 23-Apr-2002 dhartmei

Allow explicit filtering of fragments when they are not reassembled.
Document fragment handling in the man page. Short version: if you're
scrubbing everything (as is recommended, in general), nothing changes.
If you want to deal with fragments manually, read the man page.
ok frantzen.


# 1.59 18-Apr-2002 deraadt

use strlcpy


# 1.58 17-Apr-2002 dhartmei

Reset lineno for each file, so pfctl -R ... -N ... reports the right
line number for non-first files. Reported by aaron@


Revision tags: OPENBSD_3_1_BASE
# 1.57 27-Mar-2002 mickey

implement a "no-route" keyword.
usage semantics are analogous w/ "any", meaning is
"any ip address for which there is no route in the
current routing table", could be used in both from and to.
typical usage would be (assuming symmetrical routing):
block in from no-route to any
also doc "any" in the pf.conf.5, include in regress, etc.
tested by me on i386 and sparc.
dhartmei@ and frantzen@ ok


# 1.56 27-Feb-2002 dhartmei

Instead of printing useless @0 rule numbers from pfctl -vR, increase a
counter. Helps debugging rule sets that are not loaded. Suggested by
John Kerbawy.


# 1.55 11-Jan-2002 mickey

use bsearch() for keywords lookup, swap couple of entries to make the keywords array sorted and add a comment to keep it that way; dhartmei@ ok


# 1.54 10-Jan-2002 hugh

Let port 0 be specified as it's not special here.
Agreement with Daniel and others.


# 1.53 09-Jan-2002 mpech

Port must be >0 and <=65535. Idea while have fun with ssh.

dhartmei@ ok


# 1.52 09-Jan-2002 mpech

free() 'interface' in {nat,binat,rdr}rule

dhartmei@ ok


# 1.51 09-Jan-2002 dhartmei

Add labels to rules. These are arbitrary names (not to be confused with
tags that will be used to tag packets later on). Add pfctl -z to clear
per-rule counters. Add pfctl -s labels to output per-rule counters in
terse format and only for rules that have labels. Suggested by
Henning Brauer.


# 1.50 08-Jan-2002 dhartmei

Add "no nat/rdr/binat" to nat.conf. The first matching rule applies.
If it is a "no" rule, no translation occurs. Useful to exclude certain
packets from translation. Suggested by Henning Brauer.


# 1.49 07-Jan-2002 mpech

remove 3rd argument from ipmask(), not used.

dhartmei@ ok


# 1.48 23-Dec-2001 deraadt

find correct line number in lval, instead of val


# 1.47 10-Dec-2001 dhartmei

Add stateful filtering for other (non-TCP/UDP/ICMP) protocol, based on
source/destination addresses/ports only.
Add RDR for ICMP. Add NAT/RDR/BINAT for other protocols.
Destination and redirection port(s) are now optional for RDR rules.
Not specifying destination port(s) means 'redirect all ports', not
specifying redirection port(s) means 'redirect to the original port'.


# 1.46 05-Dec-2001 dhartmei

Correctly parse hex numbers. Spotted by Claudio Jeker. Closes PR 2234.


# 1.45 03-Dec-2001 dhartmei

For nat, binat and rdr rules, don't allow different address families in
one rule. pf can't translate IPv4 <-> IPv6 packets. Such rules didn't work,
even if they were falsely accepted before.


# 1.44 26-Nov-2001 jasoni

add fastroute options similar to what is found in ipf
ok dhartmei@, frantzen@


# 1.43 05-Nov-2001 deraadt

noone responds.
this diff makes } and { not be part of symbols


# 1.42 24-Oct-2001 dhartmei

Check interface names using ifa0_lookup() and print error message for
non-existant interfaces (instead of the generic ioctl error returned by
the kernel in this case).


Revision tags: OPENBSD_3_0_BASE
# 1.41 15-Oct-2001 dhartmei

branches: 1.41.2;
Add 'allow-opts' to rules. Packets with IP options will be blocked by
default now, and can be allowed per rule. ok deraadt@


# 1.40 11-Oct-2001 frantzen

Don't htonl() past buffer bounds if ipmask == 128


# 1.39 07-Oct-2001 dhartmei

Add interface name to address translation to pfctl, document it and add
a regress test. Translation is done on rule set load-time only, so the
rule sets must be reloaded when an interface address changes.
parse.y patch from Cedric Berger. Similar patch from Jonathon Fletcher.
Thanks to both.


# 1.38 01-Oct-2001 markus

print variable asignments only if -v is given. ok dhartmei/deraadt


# 1.37 28-Sep-2001 dhartmei

Support underscores in macro names and document it in the man page.


# 1.36 20-Sep-2001 dhartmei

Fix uninitialized structure fields. Problem reported by Cedric Berger.


# 1.35 15-Sep-2001 wilfried

Implement return-icmp(number), return-icmp6(number)
Differentiate between return-icmp and return-icmp6,
icmp-type and ipv6-icmp-type. ok dhartmei@


# 1.34 15-Sep-2001 dhartmei

Fix 'binat ... to any ...' (binat.af wasn't set).


# 1.33 15-Sep-2001 dhartmei

Parse bug, found by wilfried@


# 1.32 15-Sep-2001 frantzen

IPv6 support from Ryan McBride (mcbride@countersiege.com)


# 1.31 12-Sep-2001 markus

check calloc() return value


# 1.30 06-Sep-2001 jasoni

- you can only binat between hosts
- add binat example and description


# 1.29 06-Sep-2001 jasoni

1:1 bidrectional NAT (binat); ok dhartmei@ and frantzen@


# 1.28 04-Sep-2001 dhartmei

Support parameter lists {} for interfaces in filter rules, like
pass in on { gm0, kue0 } from any to any


# 1.27 28-Aug-2001 markus

move '!' from host_list to host: "xhost : '!' host | host;"; ok dhartmei@


# 1.26 28-Aug-2001 markus

check for malloc/strdup == NULL


# 1.25 28-Aug-2001 dhartmei

Support ! operator in host parameter lists. Fixes PR system/2030. Reported
by Kamil Andrusz <wizz@mniam.net>.


# 1.24 26-Aug-2001 deraadt

sort keywords


# 1.23 25-Aug-2001 frantzen

PF ISN randomization. Or in trekkie techno-babble, ISN phase modulation.


# 1.22 23-Aug-2001 millert

o for a port_item, initialize the "next" pointer to NULL
o for an address, use calloc() instead of malloc() so the struct is zeroed
Fixes a SEGV in pfctl due to uninitialized "next" pointers.


# 1.21 23-Aug-2001 deraadt

Support var="string". Expansion (at lex time) done using $var, for instance:
okproto="{ssh, smtp, domain, auth}"
pass in on key0 proto tcp from any to any port $okproto keep state
Can I ask someone else to document this in pf.conf(5)?


# 1.20 19-Aug-2001 dhartmei

Add parameter list support to parser. Handles lists for protocol, hosts
and ports in filter rules, like

block in from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 } to any
pass in proto tcp from any to any port { ssh, 1024 >< 2000, > 65000 }
block in proto { udp, igmp }

and does rule expansion (generate all needed rule combinations).


# 1.19 16-Aug-2001 deraadt

track the line number per-token, so that we can report errors correctly


# 1.18 14-Aug-2001 mickey

optimize the flags parsing; markus@ ok


# 1.17 11-Aug-2001 deraadt

\+\n support, and spit out cc-style error messages. the parser's line
counting is lex dependent, and will need to be tweaked


# 1.16 31-Jul-2001 wilfried

allow to test that flags are unset, ok dhartmei@, mickey@


# 1.15 19-Jul-2001 krw

Fix/complete the handling of the binary ops >< and <> to behave
like the ipf operators.

The 'n >< m' construct (Include Range = PF_OP_IRG) should match
ports greater than n and less than m, not greater than or equal to
n and less than or equal to m.

The 'n <> m' construct (Exclude Range = PF_OP_XRG) should match
all ports less than n OR greater than m, not be treated as an
alias for ><.

Thus PF_OP_GL, which was used for both <> and >< is replaced with
PF_OP_IRG and PF_OP_XRG with the 'correct' semantics.

OK dhartmei@


# 1.14 18-Jul-2001 markus

new ERROR token, errx() -> warnx() + ERROR; ok deraadt@


# 1.13 18-Jul-2001 markus

KNF for return


# 1.12 18-Jul-2001 mickey

check number range to fit in 32 bits


# 1.11 18-Jul-2001 mickey

put range checks on NUMBER, pointed out by deraadt


# 1.10 17-Jul-2001 mickey

spaces, parens, err instead of errx+strerror


# 1.9 17-Jul-2001 markus

warnx()/YYERROR instead of errx(); suggested by mickey@


# 1.8 17-Jul-2001 provos

markus doesnt like min-ttl =, begone


# 1.7 17-Jul-2001 provos

support min-ttl, okay dhartmei@


# 1.6 17-Jul-2001 provos

normalize ip_off, make IP_DF stripping optional, return rst is a flag now.
okay markus@


# 1.5 17-Jul-2001 marc

bitch about ! in pf rule; ok dhartmei@ and markus@


# 1.4 17-Jul-2001 millert

Only set default proto in the rdr case; markus@ OK


# 1.3 16-Jul-2001 markus

errx() if getservbyname() fails


# 1.2 16-Jul-2001 markus

better flags parsing; dhartmei


# 1.1 16-Jul-2001 markus

add a yacc parser for pf.conf and nat.conf, with help from mickey@,
plus: -n now turns off all operations, and just parses the conf files
ok deraadt@