M1: pf.c compiles into pf.ko

This commit is contained in:
lgcosta committed 2026-11-11 14:55:20 -03:00
1 parent 1fcd7b3046
commit 0119e70960
54 files changed
+14853 -96

No files matched your search

+116
View File
@@ -652,3 +652,119 @@ port_c net/pf_ioctl.c -> pfsrc/pf_ioctl.c (includes dropped -> pfk.h; -D_KERNEL
```sh
port_c net/pf_ioctl.c -> pfsrc/pf_ioctl.c (includes dropped -> pfk.h; -D_KERNEL mode; renames)
```
## 2026-11-11T14:05:58-03:00 staging
```sh
port_c net/pf.c -> pfsrc/pf.c (includes dropped -> pfk.h; -D_KERNEL mode; renames)
```
## 2026-11-11T14:34:07-03:00 staging
```sh
port_c kern/subr_tree.c -> compat/subr_tree.c (includes dropped -> pfk.h; -D_KERNEL mode; renames)
```
## 2026-11-11T14:42:10-03:00 staging
```sh
port_c net/radix.c -> compat/radix.c (includes dropped -> pfk.h; -D_KERNEL mode; renames)
```
## 2026-11-11T14:42:10-03:00 staging
```sh
port_c net/rtable.c -> compat/rtable.c (includes dropped -> pfk.h; -D_KERNEL mode; renames)
```
## M1 pf.c compile-port — 2026-11-11: staging sed extensions
- `sa_len` removal extended to `->` accesses (pf.c: `dst->sin_len = ...;`).
- `ip_output(` → `pfk_ip_output(`, `ip_forward(` → `pfk_ip_forward(`,
`ip6_output(` → `pfk_ip6_output(` (Linux net/ip.h/net/dst.h own these names).
- pf_create_state prototype `struct pf_src_node **` → `struct pf_src_node *[PF_SN_MAX]`
(GCC -Werror=array-parameter: definition binds [4]).
- kern/subr_tree.c vendored+staged → compat/subr_tree.c (tree.h `_rb_*`
back end was never implemented; upstream OpenBSD file compiles verbatim
through port_c). net/rtable.c staged once and dropped again: it is the
OpenBSD ART-fib core (srp/domains) and is NOT buildable as a PF compat
layer; the port's route view stays in compat/pfk_rtable.c.
## M1 PFLINUX deviations (pf.c ↔ compat), each marked in code
- counters: counters_alloc/inc/zero/read/free implemented over the
compat cpumem per-CPU u64 slots; counters_read's `scratch` argument is
accepted and unused (OpenBSD walks cpu_info; we sum nr_cpu_ids slots).
- struct inpcb (compat/pfk_pcb.c): one pcb synthesised per successful
Linux socket lookup (established/listen/UDP-lib); refs via
in_pcbref/in_pcbunref mirror OpenBSD (lookup returns held).
`inp_socket->so_euid` = sock owner uid; `so_egid`/`so_cpid` are NOT
stored in struct sock by Linux → (gid_t)-1 / NO_PID (pfioc-anchored
user/pid matching degrades to uid-only until a lookup-side feature).
Wildcard matching: OpenBSD in_pcblookup finds bound-wildcard in one
pass; here exact=established + wildcard=in_pcblookup_listen — exactly
the sequence pf_socket_lookup already performs.
- if_get/if_get_smr → registry idr lookup (no refcount: pfk_ifnet is
RCU-freed on unregister); if_put is a no-op.
- smr_read_enter/leave → rcu_read_lock/unlock.
- if_congested(): OpenBSD gates on the global ifq congestion timestamp;
the port stamps the same instant from its xmit path (pfk_if_congestion
on ENOBUFS/ENETDOWN/EHOSTUNREACH drops in pfk_xmit.c/pfk_ip4.c).
- ip_forwarding/ip_directedbcast/ipmultipath/ip6_multipath/ip_mtudisc/
ip_defttl: OpenBSD sysctl ints kept as port globals; ip_forwarding is
synced from the Linux netns `all` ipv4 devconf FORWARDING on device
events (not instantaneous on sysctl change; values 1/2-ipsec map to
0/1).
- tcp_iss: stays 0; pf_tcp_iss() salt comes from the SHA512 digest +
per-call increment, which is what upstream relies on anyway.
- max_linkhdr: default 14, grown from device hard_header_len on refresh.
- ip_output/ip6_output/ip_forward/ip_send/icmp_error/ip_fragment
(compat/pfk_ip4.c): BSD semantics, mbuf-consuming. Deviations: no
record-route/IP-options processing, no IPsec coupling flags, and NO
ICMP-redirect generation when IP_REDIRECT/IPV6_REDIRECT is passed (the
Linux FIB emits redirects); ip_fragment always consumed, appended to
the mbuf_list.
- csum_flags: driver offload is not trusted yet (M1): ingress packets get
no M_TCP_CSUM_IN_OK, pf_check_tcp_cksum recomputes in software;
M_TCP_CSUM_OUT/M_UDP_CSUM_OUT are honoured by the port's own output
path (pseudo-header checksum computed there).
- ipstat_inc/tcpstat_inc: no-op macros (netinet per-CPU stats are not
ported; PF-visible counters live in pf_status/kif only).
- rtable_iterate: always NULL — multipath uRPF iteration is a single
Linux-FIB answer (documented).
- rtlabel_name2id/rtlabel_id2name/rtlabel_unref: report "unavailable"
(routing labels are a non-goal; ioctl layer rejects labeled rules).
- divert_packet/divert6_packet (pfsrc/divert_sock.c): no AF_DIVERT socket
layer exists yet (M6); with no socket attached OpenBSD frees the
packet — identical observable behaviour, plus one log line so it is
never silent.
- pflog_packet (compat/pfk_kern.c): NPFLOG=1 but if_pflog.c needs the
ifpf layer; returns success with a one-time pr_warn "packet not
logged" (M4 netlink backend).
- timeout/task: TIMEOUT_INITIALIZER/TASK_INITIALIZER static initializers
added; timeout_add/timeout_set lazily complete the Linux timer/work
plumbing on first use (BSD statics never call timeout_set()).
- struct pfk_socket/in_ifaddr views: ifatoia/ifatoia6 return port-owned
pfk_in_ifaddr/pfk_in6_ifaddr snapshots (Linux owns the in_ifaddr tag);
rt_ifa in pfk_rtentry is such a snapshot, freed with the entry.
- counters/atomic: atomic_cas_ptr/atomic_cas_uint return old-value-on-
success / 0|NULL-on-failure (OpenBSD) via cmpxchg.
- TCP_NSTATES=11 etc.: constants verified against OpenBSD master headers
(tcp_fsm.h, ip_icmp.h, ip6.h, icmp6.h, ip_var.h, ip6_var.h, route.h,
in_pcb.h, proc.h); pfk_net.h gained ip6_vfc overlay, ICMP icmp_pptr/
icmp_void/icmp_nextmtu hun fields, icmp6_pptr, ip6_opt/_jumbo/_rthdr,
sackblk, ICMP6/MLD/ND type constants.
- pfk.h TCPS_HAVEESTABLISHED corrected to upstream `>= TCPS_ESTABLISHED`
(was `<= TCPS_TIME_WAIT`, which would have matched LISTEN too).
- pfk_ifq.h/if_var.h: `struct ifnet` tag replaced by `struct pfk_ifnet`
throughout (upstream `struct ifnet` is sed-renamed; stale forward
declaration broke type identity).
- module/pfsrc/pfk_mod.c + pfk_hooks.c were missing from the tree (HEAD
commit deleted them; only stale .o files had kept pf.ko linking).
Restored: /dev/pf misc device now dispatches through the staged real
pfioctl() with OpenBSD-style copyin/copyout driven by the ioctl size
field (PFKIOC_SIZE); netfilter hooks remain accept-all until the M2
data-path task (announced in dmesg).
- pfk_ifnet_new: kzalloc leaves BSD TAILQ heads with tqh_last == NULL;
the first pfk_if_addrlist_refresh INSERT_TAIL oopsed on insmod (VM lab).
Fixed with TAILQ_INIT of if_addrlist/if_groups (compat/pfk_if.c).