aboutgitcodebugslistschat
path: root/tap.h
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-11-04 14:10:35 +1100
committerStefano Brivio <sbrivio@redhat.com>2022-11-04 12:04:24 +0100
commit7c7b68dbe02874324e4fcda9c13b9e8d9a8192cf (patch)
tree2cf45b6d9019e785f3c1c20bfee84576c46501a4 /tap.h
parentdd3470d9a92bd2fc83b3afd5ff9490b73de6a58c (diff)
downloadpasst-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 'tap.h')
-rw-r--r--tap.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/tap.h b/tap.h
index 743bc58..674ab5c 100644
--- a/tap.h
+++ b/tap.h
@@ -6,11 +6,11 @@
#ifndef TAP_H
#define TAP_H
-in_addr_t tap_ip4_daddr(const struct ctx *c);
-void tap_udp4_send(const struct ctx *c, in_addr_t src, in_port_t sport,
- in_addr_t dst, in_port_t dport,
+struct in_addr tap_ip4_daddr(const struct ctx *c);
+void tap_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sport,
+ struct in_addr dst, in_port_t dport,
const void *in, size_t len);
-void tap_icmp4_send(const struct ctx *c, in_addr_t src, in_addr_t dst,
+void tap_icmp4_send(const struct ctx *c, struct in_addr src, struct in_addr dst,
void *in, size_t len);
const struct in6_addr *tap_ip6_daddr(const struct ctx *c,
const struct in6_addr *src);