route/link: fix sequence number handling in rtnl_link_change()

When rtnl_link_change() fails with -NLE_OPNOTSUPP, it retries
with RTM_SETLINK operation. However, it also needs to re-adjust
the sequence number. Otherwise, the second request might fail
with NLE_SEQ_MISMATCH, although it actually succeeded.

[thaller@redhat.com: changed commit message]

https://github.com/thom311/libnl/issues/179
https://github.com/thom311/libnl/pull/184
This commit is contained in:
Tuetuopay 2018-04-09 16:21:41 +02:00 committed by Thomas Haller
parent da4e707af8
commit 4e2f5dfa64

View File

@ -1772,6 +1772,10 @@ errout:
* @note The link name can only be changed if the link has been put
* in opertional down state. (~IF_UP)
*
* @note On versions up to 3.4.0, \c NLE_SEQ_MISMATCH would be returned if the
* kernel does not supports \c RTM_NEWLINK. It is advised to ignore the
* error code if you cannot upgrade the library.
*
* @return 0 on success or a negative error code.
*/
int rtnl_link_change(struct nl_sock *sk, struct rtnl_link *orig,
@ -1792,6 +1796,7 @@ retry:
err = wait_for_ack(sk);
if (err == -NLE_OPNOTSUPP && msg->nm_nlh->nlmsg_type == RTM_NEWLINK) {
msg->nm_nlh->nlmsg_type = RTM_SETLINK;
msg->nm_nlh->nlmsg_seq = NL_AUTO_SEQ;
goto retry;
}