Skip to content

Commit

Permalink
netdevsim: fix backwards compatibility in nsim_get_iflink()
Browse files Browse the repository at this point in the history
The default ndo_get_iflink() implementation returns the current ifindex
of the netdev. But the overridden nsim_get_iflink() returns 0 if the
current nsim is not linked, breaking backwards compatibility for
userspace that depend on this behaviour.

Fix the problem by returning the current ifindex if not linked to a
peer.

Fixes: 8debcf5 ("netdevsim: add ndo_get_iflink() implementation")
Reported-by: Yu Watanabe <watanabe.yu@gmail.com>
Suggested-by: Yu Watanabe <watanabe.yu@gmail.com>
Signed-off-by: David Wei <dw@davidwei.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David Wei authored and David S. Miller committed Jun 10, 2024
1 parent 0579f27 commit 5add2f7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/net/netdevsim/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ static int nsim_get_iflink(const struct net_device *dev)

rcu_read_lock();
peer = rcu_dereference(nsim->peer);
iflink = peer ? READ_ONCE(peer->netdev->ifindex) : 0;
iflink = peer ? READ_ONCE(peer->netdev->ifindex) :
READ_ONCE(dev->ifindex);
rcu_read_unlock();

return iflink;
Expand Down

0 comments on commit 5add2f7

Please sign in to comment.