diff options
author | Thomas Haller <thaller@redhat.com> | 2022-08-05 22:18:18 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-08-09 08:02:42 +0200 |
commit | 8bdd416972b2c3907ac99bc79f45690b21c32ada (patch) | |
tree | 097fb5eb2b252c050de56f2500e7e25dca0cc379 | |
parent | 92fe4c383eca478ed3f59bb29af96777ff40baab (diff) | |
download | NetworkManager-8bdd416972b2c3907ac99bc79f45690b21c32ada.tar.gz |
platform: use nlmsg_parse_error() in _netlink_recv_handle()
-rw-r--r-- | src/libnm-platform/nm-linux-platform.c | 45 |
1 files changed, 8 insertions, 37 deletions
diff --git a/src/libnm-platform/nm-linux-platform.c b/src/libnm-platform/nm-linux-platform.c index 37cef59261..fc3ca60aeb 100644 --- a/src/libnm-platform/nm-linux-platform.c +++ b/src/libnm-platform/nm-linux-platform.c @@ -9856,49 +9856,20 @@ continue_reading: * NL_SKIP or NL_PROCEED (dangerous) */ retval = -NME_NL_MSG_OVERFLOW; } else if (msg.nm_nlh->nlmsg_type == NLMSG_ERROR) { - /* Message carries a nlmsgerr */ - struct nlmsgerr *e = nlmsg_data(msg.nm_nlh); - - if (msg.nm_nlh->nlmsg_len < nlmsg_size(sizeof(*e))) { - /* Truncated error message, the default action - * is to stop parsing. The user may overrule - * this action by returning NL_SKIP or - * NL_PROCEED (dangerous) */ - retval = -NME_NL_MSG_TRUNC; - } else if (e->error) { - int errsv = nm_errno_native(e->error); - - if (NM_FLAGS_HAS(msg.nm_nlh->nlmsg_flags, NLM_F_ACK_TLVS) - && msg.nm_nlh->nlmsg_len >= sizeof(*e) + e->msg.nlmsg_len) { - static const struct nla_policy policy[] = { - [NLMSGERR_ATTR_MSG] = {.type = NLA_STRING}, - [NLMSGERR_ATTR_OFFS] = {.type = NLA_U32}, - }; - struct nlattr *tb[G_N_ELEMENTS(policy)]; - struct nlattr *tlvs; - - tlvs = (struct nlattr *) ((char *) e + sizeof(*e) + e->msg.nlmsg_len - - NLMSG_HDRLEN); - if (nla_parse_arr(tb, - tlvs, - msg.nm_nlh->nlmsg_len - sizeof(*e) - e->msg.nlmsg_len, - policy) - >= 0) { - if (tb[NLMSGERR_ATTR_MSG]) - extack_msg = nla_get_string(tb[NLMSGERR_ATTR_MSG]); - } - } + int errsv; - /* Error message reported back from kernel. */ + errsv = nlmsg_parse_error(msg.nm_nlh, &extack_msg); + if (errsv == 0) + seq_result = WAIT_FOR_NL_RESPONSE_RESULT_RESPONSE_OK; + else { _LOGD("%s: recvmsg: error message from kernel: %s (%d)%s%s%s for request %d", log_prefix, - nm_strerror_native(errsv), + nm_strerror(errsv), errsv, NM_PRINT_FMT_QUOTED(extack_msg, " \"", extack_msg, "\"", ""), msg.nm_nlh->nlmsg_seq); - seq_result = -NM_ERRNO_NATIVE(errsv); - } else - seq_result = WAIT_FOR_NL_RESPONSE_RESULT_RESPONSE_OK; + seq_result = errsv; + } } else process_valid_msg = TRUE; |