summaryrefslogtreecommitdiff
path: root/sbin/pfctl/pfctl_parser.c
AgeCommit message (Collapse)Author
2024-04-22Show pf fragment reassembly counters.Alexander Bluhm
Framgent count and statistics are stored in struct pf_status. From there pfctl(8) and systat(1) collect and show them. Note that pfctl -s info needs the -v switch to show fragments. As fragment reassembly has its own mutex, also grab this in pf ipctl(2) and sysctl(2) code. input claudio@; OK henning@
2024-02-07fix anchortypes bounds testJonathan Gray
found by "buffer overflow 'anchortypes' 10 <= 12" smatch error feedback and ok sashan@, ok miod@ on an earlier version
2023-10-26whitespace cleanup my fingers couldn't avoid doing while i was re-readingTheo de Raadt
the parsing code
2023-04-18Rewrite some ugly for loopsTheo Buehler
This fixes a few KNF issues and ugly line wrapping by using a local version of nitems(); fix two bsearch() on top. ok claudio
2022-11-09simplify expiration of 'once' rules.Alexandr Nedvedicky
let packet to mark 'once' rule as expired. The rule will be removed by pfctl(8) when rules are updated. OK kn@
2021-02-01change route-to so it sends packets to IPs instead of interfaces.David Gwynne
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@
2021-01-12Sometimes a user ID was logged in pflog(4) although the logopt ofAlexander Bluhm
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@
2020-12-29getifaddrs() can return entries where ifa_addr is NULL. Check for thisSebastian Benoit
before accessing anything in ifa_addr. ok claudio@
2020-05-15pf(4): use CLOCK_BOOTTIME to get time_uptime(9) in userspacecheloha
In pf(4), the pf_status.since timestamp is set with time_uptime(9). This is a low-res snapshot of nanouptime(9). nanouptime(9) is used to implement CLOCK_BOOTTIME for clock_gettime(2). It is not used to implement CLOCK_UPTIME, though. The names are misleading. Switch to CLOCK_BOOTTIME in places in userspace where we use pf_status.since so we are working with the right clock. Technically CLOCK_MONOTONIC is equivalent, but we shouldn't use that here. CLOCK_MONOTONIC is not necessarily the "time since boot": the standard says its absolute value is meaningless. ok patrick@ bluhm@
2019-10-17Use -1 to indicate an invalid uid/gid, not UID_MAX and GID_MAX.Todd C. Miller
This is the userland portion. OK deraadt@ sashan@
2019-06-28When system calls indicate an error they return -1, not some arbitraryTheo de Raadt
value < 0. errno is only updated in this case. Change all (most?) callers of syscalls to follow this better, and let's see if this strictness helps us in the future.
2019-03-30Fail on invalid netmasks when filling tableskn
Fix a regression of revision 1.326 "Zap v4mask and v6mask in host()" which allowed CIDR networks with more than one "/" to be loaded into tables. I took care of this code path with regard to rules coming the ruleset parser, which aborts earlier on such invalid specifications, but missed `-T add 1/2/3' and the like. Analyzed and fixed by Petr Hoffmann <petr dot hoffmann at oracle dot com>, thanks! OK deraadt
2019-01-29Reuse copy_satopfaddr() when killing entrieskn
Recently introduced in pfctl_parser.c r1.333, this helper nicely simplifies code when copying IPs based on their address family, so use it in five other places when killing state or source node entries. All addresses copied in these code paths result from either pfctl_parse_host() or pfctl_addrprefix() which guarantee the address family set to AF_INET or AF_INET6. Therefore, effectively relaxing the case of unhandled families from errx(3) in callers to warnx(3) in copy_satopfaddr() is safe since it's never reached. OK sashan
2018-09-16The kernel does not set the address family for the socket addressesAlexander Bluhm
that are used for netmask, broadcast, and destination address. In pfctl(8) take the family of the interface address and write it to the other addresses. This fixes some bugs when copy_satopfaddr() copied only part of IPv6 addresses. Print a warning if the address family is unknown. OK kn@
2018-09-13Avoid unneeded variable in gen_dynnode()kn
OK bluhm
2018-09-11Fix netmask regression in get_dynnode()kn
I introduced this error with r1.330 while removing the af parameter from unmask(). `pass inet from (lo0)/24' would result in `pass inet from (lo0)', sorry.
2018-09-11Remove unused buffer from host()kn
Left-over from pre-host_ip() times. While here, use __func__. OK henning benno
2018-09-10Merge host_v{4,6}() into simpler host_ip()kn
Except for networks such as "10/8" host_ip() now handles addresses in an AF-agnostic way with more duplicate code removed/merged. OK sashan (as for earlier copy_satopfaddr() diff) henning
2018-09-10Introduce copy_satopfaddr()kn
Move the same dance around v4/v6 for copying IP addresses from sockaddr into pf_addr to avoid duplicate code and improve readability. Feedback and OK bluhm
2018-09-07More __func__ to fix error messageskn
2018-09-07Remove wildcard address on loopack remnantskn
henning@ removed this functionality years ago, see the share/man/man4/lo.4 revision 1.27. OK jca claudio
2018-09-06Remove unused af argument from unmask()kn
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
2018-09-05Move AF-specific mask logic from callers into set_ipmask()kn
Instead of doing the same dance with every caller, check for user provided mask or address familiy specific maximum inside the function itself. Feedback and OK claudio
2018-09-05Use error label in host_if()kn
This brings it in line with host() and host_dns(). OK sashan miko
2018-08-10Zap bits in host_v4(), use mask parameterkn
This avoids a duplicate strrchr() call and makes the function consistent with host_v6() regarding mask handling. While here, use the destination's size in memcpy instead of hardcoding its type. OK sashan
2018-07-31Zap v4mask and v6mask in host()kn
Simply defer checks whether a mask has been specified to where it's set in host_*(); this is to reduce address family specific code. OK sashan
2018-07-30Simplify host()kn
Get rid of the `cont' flag, zap obvious comments, add error label. OK benno sashan
2018-07-28Use strtonum in host()kn
This is simpler than checking three cases for `q' and gives nicer error messages. While here, use `v6mask' as maximum netmask instead of hardcoding it. OK sashan
2018-07-24Move duplicate code into new helper print_addr_str()kn
This simply puts the wiggle around inet_ntop() from four into one location. OK benno
2018-07-24Simplify getaddrinfo() error handlingkn
`error' is not used so drop it and jump to the end. OK sashan
2018-07-10'set delay' for the generic packet delay mechanism, ok benno sashanHenning Brauer
2018-07-10Add "listenrepv2" for MLDv2 Listener Reports from RFC3810Jeremie Courreges-Anglas
ok benno@
2018-02-08show current synflood detection watermarks in pfctl -vsi, for the lackHenning Brauer
of a more appropriate place. ok claudio benno procter
2017-11-28The divert structure was using the port number to indicate thatAlexander Bluhm
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@
2017-11-13add a generic packet rate matching filter. allows things likeHenning Brauer
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
2017-08-14expose the half-open tcp states counter, ok bluhmHenning Brauer
2017-08-11add option -N (no domain resolution)Sebastian Benoit
manpage wording and reminder about usage() jmc@ ok florian@ henning@
2017-08-03Since nearly 20 years the correct spelling ofFlorian Obser
ICMP6_DST_UNREACH_NOTNEIGHBOR is ICMP6_DST_UNREACH_BEYONDSCOPE (RFC 1885 was obsoleted). sthen grepped the ports sources to make sure nothing uses it. OK millert, jca
2017-07-19Allow HFSC classes to use flow queuesMike Belopuhov
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.
2017-06-01Return time_uptime as value for when pf was enabled instead ofPatrick Wildt
time_second. Since time_second changes depending on the wall- clock time, time_second is not a reliable source for the status. We can even end up with a negative time delta. Thus, use the monotonically growing time_uptime and export it to userland. ok bluhm@ mikeb@
2017-05-15Fixup printing of queue bandwidth specificationsMike Belopuhov
Reported by Carl Mascott, thanks! OK sthen
2017-05-15Hook up FQ-CoDel to the tree and enable configuration in the pfctl(8)Mike Belopuhov
OK sthen, visa
2016-10-26When using a /32 IPv4 interface address, pfctl(8) reports a 0.0.0.0Alexander Bluhm
as broadcast address. The kernel does not consider this a broadcast address and ifconfig(8) has a check to exclude it. Use the same check in pfctl(8). Found by regress/sbin/pfctl pfi2; OK mikeb@
2016-09-03Let purge thread to remove once rules, not packets.Alexandr Nedvedicky
Thanks mikeb@ for idea to add expire time. OK mpi@, OK mikeb@
2016-08-26Add <time.h> for time(); sort <*.h> includesPhilip Guenther
ok deraadt@
2015-09-03interface should only be specified for root queues; found by jsgMike Belopuhov
2015-06-03Do not assume that asprintf() clears the pointer on failure, whichTodd C. Miller
is non-portable. Also add missing asprintf() return value checks. OK deraadt@ guenther@ doug@
2015-02-14Rather than using 0xff as a placeholder for "don't check prio", use 0xff toStuart Henderson
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"
2015-02-10since we inherit prio (as in, the queuing priority) from outside sources,Henning Brauer
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
2015-02-07parse debug levels with strtonum, so that debug 1banana doesn't parse.Ted Unangst
ok mikeb