rewrite the pf_state_peer_ntoh and pf_state_peer_hton macros as functions.
authordlg <dlg@openbsd.org>
Fri, 11 Nov 2022 11:02:35 +0000 (11:02 +0000)
committerdlg <dlg@openbsd.org>
Fri, 11 Nov 2022 11:02:35 +0000 (11:02 +0000)
i can read this code as functions, but it takes too much effort as macros.

sys/net/pf.c
sys/net/pfvar.h
sys/net/pfvar_priv.h

index 06599d3..f61449a 100644 (file)
@@ -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)
 {
index d3baeb2..607c71c 100644 (file)
@@ -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);                             \
index a0a8298..9152e73 100644 (file)
@@ -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_ */