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")
This commit is contained in:
Kristof Provost 2025-03-04 09:44:41 +01:00
parent d3a892ce14
commit 4cdcdf0e5f
3 changed files with 12 additions and 15 deletions

View file

@ -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];

View file

@ -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 */

View file

@ -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;