git: 63220460d0af - stable/13 - libpfctl: fix creatorid endianness

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Fri, 18 Feb 2022 10:46:05 UTC
The branch stable/13 has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=63220460d0af381abfaddc4a203c3df21bd9719d

commit 63220460d0af381abfaddc4a203c3df21bd9719d
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2022-01-21 16:50:15 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-02-18 10:14:58 +0000

    libpfctl: fix creatorid endianness
    
    We provide the hostid (which is the state creatorid) to the kernel as a
    big endian number (see pfctl/pfctl.c pfctl_set_hostid()), so convert it
    back to system endianness when we get it from the kernel.
    
    This avoids a confusing mismatch between the value the user configures
    and the value displayed in the state.
    
    MFC after:      3 weeks
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D33989
    
    (cherry picked from commit 735748f30aad80593e2b7f5f5f175d64484c5eeb)
---
 lib/libpfctl/libpfctl.c   | 4 ++--
 sbin/pfctl/pfctl_parser.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c
index 9252f64969bb..e77bdee93deb 100644
--- a/lib/libpfctl/libpfctl.c
+++ b/lib/libpfctl/libpfctl.c
@@ -188,7 +188,7 @@ pfctl_get_status(int dev)
 	status->running = nvlist_get_bool(nvl, "running");
 	status->since = nvlist_get_number(nvl, "since");
 	status->debug = nvlist_get_number(nvl, "debug");
-	status->hostid = nvlist_get_number(nvl, "hostid");
+	status->hostid = ntohl(nvlist_get_number(nvl, "hostid"));
 	status->states = nvlist_get_number(nvl, "states");
 	status->src_nodes = nvlist_get_number(nvl, "src_nodes");
 
@@ -809,7 +809,7 @@ pf_state_export_to_state(struct pfctl_state *ps, const struct pf_state_export *s
 	ps->packets[1] = s->packets[1];
 	ps->bytes[0] = s->bytes[0];
 	ps->bytes[1] = s->bytes[1];
-	ps->creatorid = s->creatorid;
+	ps->creatorid = ntohl(s->creatorid);
 	ps->key[0].proto = s->proto;
 	ps->key[1].proto = s->proto;
 	ps->key[0].af = s->af;
diff --git a/sbin/pfctl/pfctl_parser.c b/sbin/pfctl/pfctl_parser.c
index 8dde3c916009..8537d2933dc8 100644
--- a/sbin/pfctl/pfctl_parser.c
+++ b/sbin/pfctl/pfctl_parser.c
@@ -541,7 +541,7 @@ print_status(struct pfctl_status *s, struct pfctl_syncookies *cookies, int opts)
 	}
 
 	if (opts & PF_OPT_VERBOSE) {
-		printf("Hostid:   0x%08x\n", ntohl(s->hostid));
+		printf("Hostid:   0x%08x\n", s->hostid);
 
 		for (i = 0; i < PF_MD5_DIGEST_LENGTH; i++) {
 			buf[i + i] = hex[s->pf_chksum[i] >> 4];