i can read this code as functions, but it takes too much effort as macros.
-/* $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
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)
{
-/* $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
#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); \
-/* $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
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_ */