Skip to content

Commit

Permalink
netdevsim: forward skbs from one connected port to another
Browse files Browse the repository at this point in the history
Forward skbs sent from one netdevsim port to its connected netdevsim
port using dev_forward_skb, in a spirit similar to veth.

Signed-off-by: David Wei <dw@davidwei.uk>
Signed-off-by: NipaLocal <nipa@local>
  • Loading branch information
spikeh authored and NipaLocal committed Dec 12, 2023
1 parent 58d97c4 commit 297ff61
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions drivers/net/netdevsim/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,33 @@
static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct netdevsim *ns = netdev_priv(dev);
struct netdevsim *peer_ns;
int ret = NETDEV_TX_OK;

rcu_read_lock();
if (!nsim_ipsec_tx(ns, skb))
goto out;
goto err;

u64_stats_update_begin(&ns->syncp);
ns->tx_packets++;
ns->tx_bytes += skb->len;
u64_stats_update_end(&ns->syncp);

out:
dev_kfree_skb(skb);
peer_ns = rcu_dereference(ns->peer);
if (!peer_ns)
goto err;

skb_tx_timestamp(skb);
if (unlikely(dev_forward_skb(peer_ns->netdev, skb) == NET_RX_DROP))
ret = NET_XMIT_DROP;

return NETDEV_TX_OK;
rcu_read_unlock();
return ret;

err:
rcu_read_unlock();
dev_kfree_skb(skb);
return ret;
}

static void nsim_set_rx_mode(struct net_device *dev)
Expand Down Expand Up @@ -302,7 +316,6 @@ static void nsim_setup(struct net_device *dev)
eth_hw_addr_random(dev);

dev->tx_queue_len = 0;
dev->flags |= IFF_NOARP;
dev->flags &= ~IFF_MULTICAST;
dev->priv_flags |= IFF_LIVE_ADDR_CHANGE |
IFF_NO_QUEUE;
Expand Down

0 comments on commit 297ff61

Please sign in to comment.