summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-08-10 16:37:28 +0200
committerThomas Haller <thaller@redhat.com>2021-08-17 13:18:06 +0200
commit386b367bfa41cb160c23c9fa37ee7729eda73b1e (patch)
treec4603126bd117fc606ab4ad31f68a886f5e3652e
parent0adc4fc4f6b8fc5a445060be0e6a32038c7642cf (diff)
downloadNetworkManager-386b367bfa41cb160c23c9fa37ee7729eda73b1e.tar.gz
platform/netlink: cleanup handling of nla_attr_minlen
- make nla_attr_minlen[] and array of uint8_t. That is large enough for all values we have. - don't handle NLA_UNSPEC specially. nla_attr_minlen[NLA_UNSPEC] returns zero just fine.
-rw-r--r--src/libnm-platform/nm-netlink.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/libnm-platform/nm-netlink.c b/src/libnm-platform/nm-netlink.c
index c45d73891d..efe41bca07 100644
--- a/src/libnm-platform/nm-netlink.c
+++ b/src/libnm-platform/nm-netlink.c
@@ -585,21 +585,20 @@ nla_nest_end(struct nl_msg *msg, struct nlattr *start)
return _nest_end(msg, start, 0);
}
-static const uint16_t nla_attr_minlen[NLA_TYPE_MAX + 1] = {
+static const uint8_t nla_attr_minlen[NLA_TYPE_MAX + 1] = {
[NLA_U8] = sizeof(uint8_t),
[NLA_U16] = sizeof(uint16_t),
[NLA_U32] = sizeof(uint32_t),
[NLA_U64] = sizeof(uint64_t),
[NLA_STRING] = 1,
- [NLA_FLAG] = 0,
};
static int
validate_nla(const struct nlattr *nla, int maxtype, const struct nla_policy *policy)
{
const struct nla_policy *pt;
- unsigned int minlen = 0;
- int type = nla_type(nla);
+ uint16_t minlen;
+ int type = nla_type(nla);
if (type < 0 || type > maxtype)
return 0;
@@ -611,7 +610,7 @@ validate_nla(const struct nlattr *nla, int maxtype, const struct nla_policy *pol
if (pt->minlen)
minlen = pt->minlen;
- else if (pt->type != NLA_UNSPEC)
+ else
minlen = nla_attr_minlen[pt->type];
if (nla_len(nla) < minlen)