diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2023-01-06 11:43:12 +1100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2023-01-23 18:54:42 +0100 |
commit | f5a950115be5aca6d19ea183247bc36088c472c9 (patch) | |
tree | 7e0add34ee2462c58da9d7db588aac427ca8d0cf /dhcpv6.c | |
parent | 6d011c1faab0d149bb1cbd0e922f26746e50cae6 (diff) | |
download | passt-f5a950115be5aca6d19ea183247bc36088c472c9.tar passt-f5a950115be5aca6d19ea183247bc36088c472c9.tar.gz passt-f5a950115be5aca6d19ea183247bc36088c472c9.tar.bz2 passt-f5a950115be5aca6d19ea183247bc36088c472c9.tar.lz passt-f5a950115be5aca6d19ea183247bc36088c472c9.tar.xz passt-f5a950115be5aca6d19ea183247bc36088c472c9.tar.zst passt-f5a950115be5aca6d19ea183247bc36088c472c9.zip |
util: Introduce hton*_constant() in place of #ifdefs
We have several places where we have fairly ugly #ifdefs on __BYTE_ORDER
where we need network order values in a constant expression (so we can't
use htons() or htonl()). We can do this more cleanly by using a single
__BYTE_ORDER ifdef to define htons_constant() and htonl_constant()
macros, then using those in all the other places.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'dhcpv6.c')
-rw-r--r-- | dhcpv6.c | 50 |
1 files changed, 13 insertions, 37 deletions
@@ -39,37 +39,21 @@ */ struct opt_hdr { uint16_t t; -#if __BYTE_ORDER == __BIG_ENDIAN -# define OPT_CLIENTID 1 -# define OPT_SERVERID 2 -# define OPT_IA_NA 3 -# define OPT_IA_TA 4 -# define OPT_IAAADR 5 -# define OPT_STATUS_CODE 13 -# define STATUS_NOTONLINK 4 -# define OPT_DNS_SERVERS 23 -# define OPT_DNS_SEARCH 24 -#else -# define OPT_CLIENTID __bswap_constant_16(1) -# define OPT_SERVERID __bswap_constant_16(2) -# define OPT_IA_NA __bswap_constant_16(3) -# define OPT_IA_TA __bswap_constant_16(4) -# define OPT_IAAADR __bswap_constant_16(5) -# define OPT_STATUS_CODE __bswap_constant_16(13) -# define STATUS_NOTONLINK __bswap_constant_16(4) -# define OPT_DNS_SERVERS __bswap_constant_16(23) -# define OPT_DNS_SEARCH __bswap_constant_16(24) -#endif +# define OPT_CLIENTID htons_constant(1) +# define OPT_SERVERID htons_constant(2) +# define OPT_IA_NA htons_constant(3) +# define OPT_IA_TA htons_constant(4) +# define OPT_IAAADR htons_constant(5) +# define OPT_STATUS_CODE htons_constant(13) +# define STATUS_NOTONLINK htons_constant(4) +# define OPT_DNS_SERVERS htons_constant(23) +# define OPT_DNS_SEARCH htons_constant(24) #define STR_NOTONLINK "Prefix not appropriate for link." uint16_t l; } __attribute__((packed)); -#if __BYTE_ORDER == __BIG_ENDIAN -# define OPT_SIZE_CONV(x) (x) -#else -# define OPT_SIZE_CONV(x) (__bswap_constant_16(x)) -#endif +# define OPT_SIZE_CONV(x) (htons_constant(x)) #define OPT_SIZE(x) OPT_SIZE_CONV(sizeof(struct opt_##x) - \ sizeof(struct opt_hdr)) #define OPT_VSIZE(x) (sizeof(struct opt_##x) - \ @@ -103,19 +87,11 @@ struct opt_server_id { uint8_t duid_lladdr[ETH_ALEN]; } __attribute__ ((packed)); -#if __BYTE_ORDER == __BIG_ENDIAN -#define SERVER_ID { \ +#define SERVER_ID { \ { OPT_SERVERID, OPT_SIZE(server_id) }, \ - DUID_TYPE_LLT, ARPHRD_ETHER, 0, { 0 } \ + htons_constant(DUID_TYPE_LLT), \ + htons_constant(ARPHRD_ETHER), 0, { 0 } \ } -#else -#define SERVER_ID { \ - { OPT_SERVERID, OPT_SIZE(server_id) }, \ - __bswap_constant_16(DUID_TYPE_LLT), \ - __bswap_constant_16(ARPHRD_ETHER), \ - 0, { 0 } \ -} -#endif /** * struct opt_ia_na - Identity Association for Non-temporary Addresses Option |