git: 4cdcdf0e5f18 - main - pf: Expand ancient NTOHL/NTOHS/HTONS/HTONL macros.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 21 Mar 2025 01:39:27 UTC
The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=4cdcdf0e5f1833e2ca7ce3bbf099b32c67064523 commit 4cdcdf0e5f1833e2ca7ce3bbf099b32c67064523 Author: Kristof Provost <kp@FreeBSD.org> AuthorDate: 2025-03-04 08:44:41 +0000 Commit: Kristof Provost <kp@FreeBSD.org> CommitDate: 2025-03-21 01:29:04 +0000 pf: Expand ancient NTOHL/NTOHS/HTONS/HTONL macros. ok guenther@, henning@ Obtained from: OpenBSD, mpi <mpi@openbsd.org>, faf7e06f4d Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/netpfil/pf/pf.c | 15 ++++++--------- sys/netpfil/pf/pf_lb.c | 8 ++++---- sys/netpfil/pf/pf_osfp.c | 4 ++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index bfff339a66f5..2c06c0253d4b 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -2266,7 +2266,7 @@ pf_icmp_mapping(struct pf_pdesc *pd, u_int8_t type, *icmp_dir = PF_IN; *virtual_type = type; *virtual_id = 0; - HTONS(*virtual_type); + *virtual_type = htons(*virtual_type); return (1); /* These types match to another state */ /* @@ -2333,7 +2333,7 @@ pf_icmp_mapping(struct pf_pdesc *pd, u_int8_t type, *icmp_dir = PF_IN; *virtual_type = type; *virtual_id = 0; - HTONS(*virtual_type); + *virtual_type = htons(*virtual_type); return (1); /* These types match to another state */ /* * All remaining ICMP6 types get their own states, @@ -2350,7 +2350,7 @@ pf_icmp_mapping(struct pf_pdesc *pd, u_int8_t type, default: unhandled_af(pd->af); } - HTONS(*virtual_type); + *virtual_type = htons(*virtual_type); return (0); /* These types match to their own state */ } @@ -4101,7 +4101,7 @@ pf_build_tcp(const struct pf_krule *r, sa_family_t af, opt = (char *)(th + 1); opt[0] = TCPOPT_MAXSEG; opt[1] = 4; - HTONS(mss); + mss = htons(mss); memcpy((opt + 2), &mss, 2); } @@ -4527,10 +4527,7 @@ pf_match(u_int8_t op, u_int32_t a1, u_int32_t a2, u_int32_t p) int pf_match_port(u_int8_t op, u_int16_t a1, u_int16_t a2, u_int16_t p) { - NTOHS(a1); - NTOHS(a2); - NTOHS(p); - return (pf_match(op, a1, a2, p)); + return (pf_match(op, ntohs(a1), ntohs(a2), ntohs(p))); } static int @@ -5034,7 +5031,7 @@ pf_get_mss(struct pf_pdesc *pd) break; case TCPOPT_MAXSEG: memcpy(&mss, (opt + 2), 2); - NTOHS(mss); + mss = ntohs(mss); /* FALLTHROUGH */ default: optlen = opt[1]; diff --git a/sys/netpfil/pf/pf_lb.c b/sys/netpfil/pf/pf_lb.c index ea9fbc46af63..f0cad4bb43c2 100644 --- a/sys/netpfil/pf/pf_lb.c +++ b/sys/netpfil/pf/pf_lb.c @@ -1065,19 +1065,19 @@ pf_get_transaddr_af(struct pf_krule *r, struct pf_pdesc *pd) } if (pd->proto == IPPROTO_ICMPV6 && pd->naf == AF_INET) { - NTOHS(pd->ndport); + pd->ndport = ntohs(pd->ndport); if (pd->ndport == ICMP6_ECHO_REQUEST) pd->ndport = ICMP_ECHO; else if (pd->ndport == ICMP6_ECHO_REPLY) pd->ndport = ICMP_ECHOREPLY; - HTONS(pd->ndport); + pd->ndport = htons(pd->ndport); } else if (pd->proto == IPPROTO_ICMP && pd->naf == AF_INET6) { - NTOHS(pd->ndport); + pd->nsport = ntohs(pd->nsport); if (pd->ndport == ICMP_ECHO) pd->ndport = ICMP6_ECHO_REQUEST; else if (pd->ndport == ICMP_ECHOREPLY) pd->ndport = ICMP6_ECHO_REPLY; - HTONS(pd->ndport); + pd->nsport = htons(pd->nsport); } /* get the destination address and port */ diff --git a/sys/netpfil/pf/pf_osfp.c b/sys/netpfil/pf/pf_osfp.c index de60619bdc18..3e00cc7c80a2 100644 --- a/sys/netpfil/pf/pf_osfp.c +++ b/sys/netpfil/pf/pf_osfp.c @@ -157,13 +157,13 @@ pf_osfp_fingerprint_hdr(const struct ip *ip, const struct ip6_hdr *ip6, const st sizeof(fp.fp_mss)); fp.fp_tcpopts = (fp.fp_tcpopts << PF_OSFP_TCPOPT_BITS) | PF_OSFP_TCPOPT_MSS; - NTOHS(fp.fp_mss); + fp.fp_mss = ntohs(fp.fp_mss); break; case TCPOPT_WINDOW: if (optlen >= TCPOLEN_WINDOW) memcpy(&fp.fp_wscale, &optp[2], sizeof(fp.fp_wscale)); - NTOHS(fp.fp_wscale); + fp.fp_wscale = ntohs(fp.fp_wscale); fp.fp_tcpopts = (fp.fp_tcpopts << PF_OSFP_TCPOPT_BITS) | PF_OSFP_TCPOPT_WSCALE;