netlink: introduce bigendian integer types
Subsystems (4)
Florian Westphal
maintainerPATCH 1/1 netlink: introduce bigendian integer types
Jakub reported that the addition of the "network_byte_order" member in struct nla_policy increases size of 32bit platforms.
Instead of scraping the bit from elsewhere Johannes suggested to add explicit NLA_BE types instead, so do this here.
NLA_POLICY_MAX_BE() macro is removed again, there is no need for it: NLA_POLICY_MAX(NLA_BE.., ..) will do the right thing.
NLA_BE64 can be added later.
--- include/net/netlink.h | 19 +++++++++-------- lib/nlattr.c | 41 ++++++++++++++----------------------- net/netfilter/nft_payload.c | 6 +++--- 3 files changed, 28 insertions(+), 38 deletions(-)
include/net/netlink.h +10 -9
@@ -181,6 +181,8 @@ enum {NLA_S64 ,NLA_BITFIELD32 ,NLA_REJECT , +NLA_BE16 , +NLA_BE32 , __NLA_TYPE_MAX, };
@@ -231,6 +233,7 @@ enum nla_policy_validation {* NLA_U32, NLA_U64, * NLA_S8, NLA_S16, * NLA_S32, NLA_S64, +* NLA_BE16, NLA_BE32, * NLA_MSECS Leaving the length field zero will verify the * given type fits, using it verifies minimum length * just like "All other"
@@ -261,6 +264,8 @@ enum nla_policy_validation {* NLA_U16, * NLA_U32, * NLA_U64, +* NLA_BE16, +* NLA_BE32, * NLA_S8, * NLA_S16, * NLA_S32,
@@ -349,7 +354,6 @@ struct nla_policy {struct netlink_range_validation_signed *range_signed;struct {s16 min, max; -u8 network_byte_order:1 ; };int (*validate)(const struct nlattr *attr,struct netlink_ext_ack *extack);
@@ -374,6 +378,8 @@ struct nla_policy { (tp == NLA_U8 || tp == NLA_U16 || tp == NLA_U32 || tp == NLA_U64)#define __NLA_IS_SINT_TYPE (tp) \ (tp == NLA_S8 || tp == NLA_S16 || tp == NLA_S32 || tp == NLA_S64) +#define __NLA_IS_BEINT_TYPE (tp) \ + (tp == NLA_BE16 || tp == NLA_BE32)#define __NLA_ENSURE (condition) BUILD_BUG_ON_ZERO(!(condition))#define NLA_ENSURE_UINT_TYPE (tp) \
@@ -387,6 +393,7 @@ struct nla_policy {#define NLA_ENSURE_INT_OR_BINARY_TYPE (tp) \ (__NLA_ENSURE(__NLA_IS_UINT_TYPE(tp) || \ __NLA_IS_SINT_TYPE(tp) || \ + __NLA_IS_BEINT_TYPE(tp) || \ tp == NLA_MSECS || \ tp == NLA_BINARY) + tp)#define NLA_ENSURE_NO_VALIDATION_PTR (tp) \
@@ -394,6 +401,8 @@ struct nla_policy { tp != NLA_REJECT && \ tp != NLA_NESTED && \ tp != NLA_NESTED_ARRAY) + tp) +#define NLA_ENSURE_BEINT_TYPE (tp) \ + (__NLA_ENSURE(__NLA_IS_BEINT_TYPE(tp)) + tp)#define NLA_POLICY_RANGE (tp, _min, _max) { \ .type = NLA_ENSURE_INT_OR_BINARY_TYPE(tp), \
@@ -424,14 +433,6 @@ struct nla_policy { .type = NLA_ENSURE_INT_OR_BINARY_TYPE(tp), \ .validation_type = NLA_VALIDATE_MAX, \ .max = _max, \ - .network_byte_order = 0, \ -} - -#define NLA_POLICY_MAX_BE (tp, _max) { \ - .type = NLA_ENSURE_UINT_TYPE(tp), \ - .validation_type = NLA_VALIDATE_MAX, \ - .max = _max, \ - .network_byte_order = 1, \ }#define NLA_POLICY_MASK (tp, _mask) { \
lib/nlattr.c +15 -26
77 lines not on this page · raw message
net/netfilter/nft_payload.c +3 -3
@@ -173,10 +173,10 @@ static const struct nla_policy nft_payload_policy[NFTA_PAYLOAD_MAX + 1] = { [NFTA_PAYLOAD_SREG] = { .type = NLA_U32 }, [NFTA_PAYLOAD_DREG] = { .type = NLA_U32 }, [NFTA_PAYLOAD_BASE] = { .type = NLA_U32 }, - [NFTA_PAYLOAD_OFFSET] = NLA_POLICY_MAX_BE(NLA_U32, 255), - [NFTA_PAYLOAD_LEN] = NLA_POLICY_MAX_BE(NLA_U32, 255), + [NFTA_PAYLOAD_OFFSET] = NLA_POLICY_MAX(NLA_BE32, 255), + [NFTA_PAYLOAD_LEN] = NLA_POLICY_MAX(NLA_BE32, 255), [NFTA_PAYLOAD_CSUM_TYPE] = { .type = NLA_U32 }, - [NFTA_PAYLOAD_CSUM_OFFSET] = NLA_POLICY_MAX_BE(NLA_U32, 255), + [NFTA_PAYLOAD_CSUM_OFFSET] = NLA_POLICY_MAX(NLA_BE32, 255), [NFTA_PAYLOAD_CSUM_FLAGS] = { .type = NLA_U32 }, };
Signature · 1 line
2.38.1
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Mon, 31 Oct 2022 13:34:07 +0100 you wrote:
Jakub reported that the addition of the "
network_byte_order" member in structnla_policyincreases size of 32bit platforms.Instead of scraping the bit from elsewhere Johannes suggested to add explicit
NLA_BEtypes instead, so do this here.
NLA_POLICY_MAX_BE()macro is removed again, there is no need for it:NLA_POLICY_MAX(NLA_BE.., ..)will do the right thing.[...]
Here is the summary with links:
- [net] netlink: introduce bigendian integer types
https://git.kernel.org/netdev/net/c/ecaf75ffd5f5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html