diff mbox series

[v14,3/5] netdevsim: add ndo_get_iflink() implementation

Message ID 20240228232253.2875900-4-dw@davidwei.uk (mailing list archive)
State Accepted
Commit 8debcf5832c3e8a6baaea27c75ad8a6ba5077beb
Delegated to: Netdev Maintainers
Headers show
Series netdevsim: link and forward skbs between ports | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 940 this patch: 940
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 957 this patch: 957
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 957 this patch: 957
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 28 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-29--21-00 (tests: 885)

Commit Message

David Wei Feb. 28, 2024, 11:22 p.m. UTC
Add an implementation for ndo_get_iflink() in netdevsim that shows the
ifindex of the linked peer, if any.

Signed-off-by: David Wei <dw@davidwei.uk>
---
 drivers/net/netdevsim/netdev.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Maciek Machnikowski Feb. 29, 2024, 5:19 p.m. UTC | #1
On 29/02/2024 00:22, David Wei wrote:
> Add an implementation for ndo_get_iflink() in netdevsim that shows the
> ifindex of the linked peer, if any.
> 
> Signed-off-by: David Wei <dw@davidwei.uk>
> ---
>  drivers/net/netdevsim/netdev.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
> index c3f3fda5fdc0..8330bc0bcb7e 100644
> --- a/drivers/net/netdevsim/netdev.c
> +++ b/drivers/net/netdevsim/netdev.c
> @@ -283,6 +283,21 @@ nsim_set_features(struct net_device *dev, netdev_features_t features)
>  	return 0;
>  }
>  
> +static int nsim_get_iflink(const struct net_device *dev)
> +{
> +	struct netdevsim *nsim, *peer;
> +	int iflink;
> +
> +	nsim = netdev_priv(dev);
> +
> +	rcu_read_lock();
> +	peer = rcu_dereference(nsim->peer);
> +	iflink = peer ? READ_ONCE(peer->netdev->ifindex) : 0;
> +	rcu_read_unlock();
> +
> +	return iflink;
> +}
> +
>  static const struct net_device_ops nsim_netdev_ops = {
>  	.ndo_start_xmit		= nsim_start_xmit,
>  	.ndo_set_rx_mode	= nsim_set_rx_mode,
> @@ -300,6 +315,7 @@ static const struct net_device_ops nsim_netdev_ops = {
>  	.ndo_set_vf_rss_query_en = nsim_set_vf_rss_query_en,
>  	.ndo_setup_tc		= nsim_setup_tc,
>  	.ndo_set_features	= nsim_set_features,
> +	.ndo_get_iflink		= nsim_get_iflink,
>  	.ndo_bpf		= nsim_bpf,
>  };
>  
Reviewed-by: Maciek Machnikowski <maciek@machnikowski.net>
diff mbox series

Patch

diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index c3f3fda5fdc0..8330bc0bcb7e 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -283,6 +283,21 @@  nsim_set_features(struct net_device *dev, netdev_features_t features)
 	return 0;
 }
 
+static int nsim_get_iflink(const struct net_device *dev)
+{
+	struct netdevsim *nsim, *peer;
+	int iflink;
+
+	nsim = netdev_priv(dev);
+
+	rcu_read_lock();
+	peer = rcu_dereference(nsim->peer);
+	iflink = peer ? READ_ONCE(peer->netdev->ifindex) : 0;
+	rcu_read_unlock();
+
+	return iflink;
+}
+
 static const struct net_device_ops nsim_netdev_ops = {
 	.ndo_start_xmit		= nsim_start_xmit,
 	.ndo_set_rx_mode	= nsim_set_rx_mode,
@@ -300,6 +315,7 @@  static const struct net_device_ops nsim_netdev_ops = {
 	.ndo_set_vf_rss_query_en = nsim_set_vf_rss_query_en,
 	.ndo_setup_tc		= nsim_setup_tc,
 	.ndo_set_features	= nsim_set_features,
+	.ndo_get_iflink		= nsim_get_iflink,
 	.ndo_bpf		= nsim_bpf,
 };