diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-06-28 09:56:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-28 09:56:59 +0200 |
commit | 3c8792988930bf7c1bdd7ae4fc1330d246347b4f (patch) | |
tree | 91ad40198eedd344751230f1cf1a014aaceae956 /lib | |
parent | f9aa26129473358c29bf85b25935e24e1a8a3f43 (diff) | |
parent | c4dde502c86c1da3c328e722cb74d8a19e70fc11 (diff) |
Merge pull request #86 from jow-/rtnl-fix-strict-chk
rtnl: update NETLINK_GET_STRICT_CHK socket flag with every request
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rtnl.c | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -3119,9 +3119,10 @@ uc_nl_request(uc_vm_t *vm, size_t nargs) uc_value_t *payload = uc_fn_arg(2); request_state_t st = { .vm = vm }; uint16_t flagval = 0; - int enable = 1, err; struct nl_msg *msg; struct nl_cb *cb; + socklen_t optlen; + int enable, err; void *buf; size_t i; @@ -3155,16 +3156,21 @@ uc_nl_request(uc_vm_t *vm, size_t nargs) if (err != 0) err_return(err, NULL); + } - if (flagval & NLM_F_STRICT_CHK) { - if (setsockopt(sock->s_fd, SOL_NETLINK, NETLINK_GET_STRICT_CHK, &enable, sizeof(enable)) < 0) - err_return(nl_syserr2nlerr(errno), "Unable to enable NETLINK_GET_STRICT_CHK"); + optlen = sizeof(enable); - flagval &= ~NLM_F_STRICT_CHK; - } + if (getsockopt(sock->s_fd, SOL_NETLINK, NETLINK_GET_STRICT_CHK, &enable, &optlen) < 0) + enable = 0; + + if (!!(flagval & NLM_F_STRICT_CHK) != enable) { + enable = !!(flagval & NLM_F_STRICT_CHK); + + if (setsockopt(sock->s_fd, SOL_NETLINK, NETLINK_GET_STRICT_CHK, &enable, sizeof(enable)) < 0) + err_return(nl_syserr2nlerr(errno), "Unable to toggle NETLINK_GET_STRICT_CHK"); } - msg = nlmsg_alloc_simple(ucv_int64_get(cmd), NLM_F_REQUEST | flagval); + msg = nlmsg_alloc_simple(ucv_int64_get(cmd), NLM_F_REQUEST | (flagval & ~NLM_F_STRICT_CHK)); if (!msg) err_return(NLE_NOMEM, NULL); |