summaryrefslogtreecommitdiff
path: root/lib/net.c
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2023-03-06 11:57:40 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2023-03-06 11:57:40 +0100
commit6b38285f587be9d4b128ae816bc25cb338f7f07c (patch)
tree5d1499d7ce6744208002d46e6e35df64b75b844d /lib/net.c
parent0f679438f36d8c2a31dfe490007e983b085caef6 (diff)
Net: Replace runtime checks with STATIC_ASSERT()
Diffstat (limited to 'lib/net.c')
-rw-r--r--lib/net.c32
1 files changed, 13 insertions, 19 deletions
diff --git a/lib/net.c b/lib/net.c
index 976ddbcc..289a4297 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -57,6 +57,19 @@ const u16 net_max_text_length[] = {
[NET_MPLS] = 7, /* "1048575" */
};
+/* There should be no implicit padding in net_addr structures */
+STATIC_ASSERT(sizeof(net_addr) == 24);
+STATIC_ASSERT(sizeof(net_addr_ip4) == 8);
+STATIC_ASSERT(sizeof(net_addr_ip6) == 20);
+STATIC_ASSERT(sizeof(net_addr_vpn4) == 16);
+STATIC_ASSERT(sizeof(net_addr_vpn6) == 32);
+STATIC_ASSERT(sizeof(net_addr_roa4) == 16);
+STATIC_ASSERT(sizeof(net_addr_roa6) == 28);
+STATIC_ASSERT(sizeof(net_addr_flow4) == 8);
+STATIC_ASSERT(sizeof(net_addr_flow6) == 20);
+STATIC_ASSERT(sizeof(net_addr_ip6_sadr) == 40);
+STATIC_ASSERT(sizeof(net_addr_mpls) == 8);
+
int
rd_format(const u64 rd, char *buf, int buflen)
@@ -310,22 +323,3 @@ net_in_netX(const net_addr *a, const net_addr *n)
return (net_pxlen(n) <= net_pxlen(a)) && ipa_in_netX(net_prefix(a), n);
}
-
-#define CHECK_NET(T,S) \
- ({ if (sizeof(T) != S) die("sizeof %s is %d/%d", #T, (int) sizeof(T), S); })
-
-void
-net_init(void)
-{
- CHECK_NET(net_addr, 24);
- CHECK_NET(net_addr_ip4, 8);
- CHECK_NET(net_addr_ip6, 20);
- CHECK_NET(net_addr_vpn4, 16);
- CHECK_NET(net_addr_vpn6, 32);
- CHECK_NET(net_addr_roa4, 16);
- CHECK_NET(net_addr_roa6, 28);
- CHECK_NET(net_addr_flow4, 8);
- CHECK_NET(net_addr_flow6, 20);
- CHECK_NET(net_addr_ip6_sadr, 40);
- CHECK_NET(net_addr_mpls, 8);
-}