diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2022-11-04 14:10:35 +1100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2022-11-04 12:04:24 +0100 |
commit | 7c7b68dbe02874324e4fcda9c13b9e8d9a8192cf (patch) | |
tree | 2cf45b6d9019e785f3c1c20bfee84576c46501a4 /passt.h | |
parent | dd3470d9a92bd2fc83b3afd5ff9490b73de6a58c (diff) | |
download | passt-7c7b68dbe02874324e4fcda9c13b9e8d9a8192cf.tar passt-7c7b68dbe02874324e4fcda9c13b9e8d9a8192cf.tar.gz passt-7c7b68dbe02874324e4fcda9c13b9e8d9a8192cf.tar.bz2 passt-7c7b68dbe02874324e4fcda9c13b9e8d9a8192cf.tar.lz passt-7c7b68dbe02874324e4fcda9c13b9e8d9a8192cf.tar.xz passt-7c7b68dbe02874324e4fcda9c13b9e8d9a8192cf.tar.zst passt-7c7b68dbe02874324e4fcda9c13b9e8d9a8192cf.zip |
Use typing to reduce chances of IPv4 endianness errors
We recently corrected some errors handling the endianness of IPv4
addresses. These are very easy errors to make since although we mostly
store them in network endianness, we sometimes need to manipulate them in
host endianness.
To reduce the chances of making such mistakes again, change to always using
a (struct in_addr) instead of a bare in_addr_t or uint32_t to store network
endian addresses. This makes it harder to accidentally do arithmetic or
comparisons on such addresses as if they were host endian.
We introduce a number of IN4_IS_ADDR_*() helpers to make it easier to
directly work with struct in_addr values. This has the additional benefit
of making the IPv4 and IPv6 paths more visually similar.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'passt.h')
-rw-r--r-- | passt.h | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -105,12 +105,12 @@ enum passt_modes { * @dns_fwd: Address forwarded (UDP) to first IPv4 DNS, network order */ struct ip4_ctx { - uint32_t addr; - uint32_t addr_seen; + struct in_addr addr; + struct in_addr addr_seen; int prefix_len; - uint32_t gw; - uint32_t dns[MAXNS + 1]; - uint32_t dns_fwd; + struct in_addr gw; + struct in_addr dns[MAXNS + 1]; + struct in_addr dns_fwd; }; /** @@ -248,6 +248,6 @@ struct ctx { }; void proto_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s, - const uint32_t *ip_da); + const struct in_addr *ip_da); #endif /* PASST_H */ |