Skip to content

Commit

Permalink
rtnl: update NETLINK_GET_STRICT_CHK socket flag with every request
Browse files Browse the repository at this point in the history
So far the NETLINK_GET_STRICT_CHK socket flag was only set on the implicit
socket creation performed during the first request and ignored for
subsequent ones which made it impossible to perform only some requests
with enabled strict checking.

Modify the logic to check the flag state for every request and change
it if needed. This allows performing both strict and non-strict requests
over the same connection.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
  • Loading branch information
jow- committed Jun 27, 2022
1 parent 44bf33a commit c4dde50
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/rtnl.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c4dde50

Please sign in to comment.