0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-08 12:18:42 +00:00

Net: explicit generic-to-specific typecast with checking

This commit is contained in:
Maria Matejka 2024-03-01 16:31:18 +01:00
parent 0dd6ec566d
commit 233004988b

View File

@ -155,6 +155,24 @@ extern const u16 net_max_text_length[];
#define NET_MAX_TEXT_LENGTH 256 #define NET_MAX_TEXT_LENGTH 256
#define NET_PTR_UNION(_n) SKIP_BACK(net_addr_union, n, (_n))
#define NET_ASSERT_TYPE(_n, _t) ASSERT_DIE((_n)->type == (_t))
#define NET_PTR_GEN(_n, _t, _u) ({ \
net_addr_union *u = NET_PTR_UNION(_n); \
NET_ASSERT_TYPE(&(u->n), _t); \
&u->_u; })
#define NET_PTR_IP4(_n) NET_PTR_GEN((_n), NET_IP4, ip4)
#define NET_PTR_IP6(_n) NET_PTR_GEN((_n), NET_IP6, ip6)
#define NET_PTR_VPN4(_n) NET_PTR_GEN((_n), NET_VPN4, vpn4)
#define NET_PTR_VPN6(_n) NET_PTR_GEN((_n), NET_VPN6, vpn6)
#define NET_PTR_ROA4(_n) NET_PTR_GEN((_n), NET_ROA4, roa4)
#define NET_PTR_ROA6(_n) NET_PTR_GEN((_n), NET_ROA6, roa6)
#define NET_PTR_FLOW4(_n) NET_PTR_GEN((_n), NET_FLOW4, flow4)
#define NET_PTR_FLOW6(_n) NET_PTR_GEN((_n), NET_FLOW6, flow6)
#define NET_PTR_IP6_SADR(_n) NET_PTR_GEN((_n), NET_IP6_SADR, ip6_sadr)
#define NET_PTR_MPLS(_n) NET_PTR_GEN((_n), NET_MPLS, mpls)
#define NET_ADDR_IP4(prefix,pxlen) \ #define NET_ADDR_IP4(prefix,pxlen) \
((net_addr_ip4) { NET_IP4, pxlen, sizeof(net_addr_ip4), prefix }) ((net_addr_ip4) { NET_IP4, pxlen, sizeof(net_addr_ip4), prefix })