From 4103306ead01e8d3532b293f8cd3d438413c56b2 Mon Sep 17 00:00:00 2001 From: dlg Date: Fri, 11 Nov 2022 11:02:35 +0000 Subject: [PATCH] rewrite the pf_state_peer_ntoh and pf_state_peer_hton macros as functions. i can read this code as functions, but it takes too much effort as macros. --- sys/net/pf.c | 40 +++++++++++++++++++++++++++++++++++++++- sys/net/pfvar.h | 38 +------------------------------------- sys/net/pfvar_priv.h | 9 ++++++++- 3 files changed, 48 insertions(+), 39 deletions(-) diff --git a/sys/net/pf.c b/sys/net/pf.c index 06599d38009..f61449afa81 100644 --- a/sys/net/pf.c +++ b/sys/net/pf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf.c,v 1.1148 2022/11/10 16:29:20 sashan Exp $ */ +/* $OpenBSD: pf.c,v 1.1149 2022/11/11 11:02:35 dlg Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -1186,6 +1186,44 @@ pf_find_state_all(struct pf_state_key_cmp *key, u_int dir, int *more) return (ret ? ret->s : NULL); } +void +pf_state_peer_hton(const struct pf_state_peer *s, struct pfsync_state_peer *d) +{ + d->seqlo = htonl(s->seqlo); + d->seqhi = htonl(s->seqhi); + d->seqdiff = htonl(s->seqdiff); + d->max_win = htons(s->max_win); + d->mss = htons(s->mss); + d->state = s->state; + d->wscale = s->wscale; + if (s->scrub) { + d->scrub.pfss_flags = + htons(s->scrub->pfss_flags & PFSS_TIMESTAMP); + d->scrub.pfss_ttl = (s)->scrub->pfss_ttl; + d->scrub.pfss_ts_mod = htonl((s)->scrub->pfss_ts_mod); + d->scrub.scrub_flag = PFSYNC_SCRUB_FLAG_VALID; + } +} + +void +pf_state_peer_ntoh(const struct pfsync_state_peer *s, struct pf_state_peer *d) +{ + d->seqlo = ntohl(s->seqlo); + d->seqhi = ntohl(s->seqhi); + d->seqdiff = ntohl(s->seqdiff); + d->max_win = ntohs(s->max_win); + d->mss = ntohs(s->mss); + d->state = s->state; + d->wscale = s->wscale; + if (s->scrub.scrub_flag == PFSYNC_SCRUB_FLAG_VALID && + d->scrub != NULL) { + d->scrub->pfss_flags = + ntohs(s->scrub.pfss_flags) & PFSS_TIMESTAMP; + d->scrub->pfss_ttl = s->scrub.pfss_ttl; + d->scrub->pfss_ts_mod = ntohl(s->scrub.pfss_ts_mod); + } +} + void pf_state_export(struct pfsync_state *sp, struct pf_state *st) { diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index d3baeb28056..607c71c3e84 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pfvar.h,v 1.518 2022/11/11 10:55:48 dlg Exp $ */ +/* $OpenBSD: pfvar.h,v 1.519 2022/11/11 11:02:35 dlg Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -822,42 +822,6 @@ struct pfsync_state { #define PFSYNC_FLAG_SRCNODE 0x04 #define PFSYNC_FLAG_NATSRCNODE 0x08 -/* for copies to/from network byte order */ -/* ioctl interface also uses network byte order */ -#define pf_state_peer_hton(s,d) do { \ - (d)->seqlo = htonl((s)->seqlo); \ - (d)->seqhi = htonl((s)->seqhi); \ - (d)->seqdiff = htonl((s)->seqdiff); \ - (d)->max_win = htons((s)->max_win); \ - (d)->mss = htons((s)->mss); \ - (d)->state = (s)->state; \ - (d)->wscale = (s)->wscale; \ - if ((s)->scrub) { \ - (d)->scrub.pfss_flags = \ - htons((s)->scrub->pfss_flags & PFSS_TIMESTAMP); \ - (d)->scrub.pfss_ttl = (s)->scrub->pfss_ttl; \ - (d)->scrub.pfss_ts_mod = htonl((s)->scrub->pfss_ts_mod);\ - (d)->scrub.scrub_flag = PFSYNC_SCRUB_FLAG_VALID; \ - } \ -} while (0) - -#define pf_state_peer_ntoh(s,d) do { \ - (d)->seqlo = ntohl((s)->seqlo); \ - (d)->seqhi = ntohl((s)->seqhi); \ - (d)->seqdiff = ntohl((s)->seqdiff); \ - (d)->max_win = ntohs((s)->max_win); \ - (d)->mss = ntohs((s)->mss); \ - (d)->state = (s)->state; \ - (d)->wscale = (s)->wscale; \ - if ((s)->scrub.scrub_flag == PFSYNC_SCRUB_FLAG_VALID && \ - (d)->scrub != NULL) { \ - (d)->scrub->pfss_flags = \ - ntohs((s)->scrub.pfss_flags) & PFSS_TIMESTAMP; \ - (d)->scrub->pfss_ttl = (s)->scrub.pfss_ttl; \ - (d)->scrub->pfss_ts_mod = ntohl((s)->scrub.pfss_ts_mod);\ - } \ -} while (0) - #define pf_state_counter_hton(s,d) do { \ d[0] = htonl((s>>32)&0xffffffff); \ d[1] = htonl(s&0xffffffff); \ diff --git a/sys/net/pfvar_priv.h b/sys/net/pfvar_priv.h index a0a82984980..9152e73a772 100644 --- a/sys/net/pfvar_priv.h +++ b/sys/net/pfvar_priv.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pfvar_priv.h,v 1.13 2022/11/11 10:55:48 dlg Exp $ */ +/* $OpenBSD: pfvar_priv.h,v 1.14 2022/11/11 11:02:35 dlg Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -311,6 +311,13 @@ extern struct rwlock pf_state_lock; extern void pf_purge_timeout(void *); extern void pf_purge(void *); + +/* for copies to/from network byte order */ +void pf_state_peer_hton(const struct pf_state_peer *, + struct pfsync_state_peer *); +void pf_state_peer_ntoh(const struct pfsync_state_peer *, + struct pf_state_peer *); + #endif /* _KERNEL */ #endif /* _NET_PFVAR_PRIV_H_ */ -- 2.20.1