linux/net/mctp/test/utils.c
Jeremy Kerr a1f4cf5791 net: mctp: tests: create test skbs with the correct net and device
In our test skb creation functions, we're not setting up the net and
device data. This doesn't matter at the moment, but we will want to add
support for distinct net IDs in future.

Set the ->net identifier on the test MCTP device, and ensure that test
skbs are set up with the correct device-related data on creation. Create
a helper for setting skb->dev and mctp_skb_cb->net.

We have a few cases where we're calling __mctp_cb() to initialise the cb
(which we need for the above) separately, so integrate this into the skb
creation helpers.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2024-02-22 13:32:55 +01:00

69 lines
1.4 KiB
C

// SPDX-License-Identifier: GPL-2.0
#include <linux/netdevice.h>
#include <linux/mctp.h>
#include <linux/if_arp.h>
#include <net/mctp.h>
#include <net/mctpdevice.h>
#include <net/pkt_sched.h>
#include "utils.h"
static netdev_tx_t mctp_test_dev_tx(struct sk_buff *skb,
struct net_device *ndev)
{
kfree_skb(skb);
return NETDEV_TX_OK;
}
static const struct net_device_ops mctp_test_netdev_ops = {
.ndo_start_xmit = mctp_test_dev_tx,
};
static void mctp_test_dev_setup(struct net_device *ndev)
{
ndev->type = ARPHRD_MCTP;
ndev->mtu = MCTP_DEV_TEST_MTU;
ndev->hard_header_len = 0;
ndev->addr_len = 0;
ndev->tx_queue_len = DEFAULT_TX_QUEUE_LEN;
ndev->flags = IFF_NOARP;
ndev->netdev_ops = &mctp_test_netdev_ops;
ndev->needs_free_netdev = true;
}
struct mctp_test_dev *mctp_test_create_dev(void)
{
struct mctp_test_dev *dev;
struct net_device *ndev;
int rc;
ndev = alloc_netdev(sizeof(*dev), "mctptest%d", NET_NAME_ENUM,
mctp_test_dev_setup);
if (!ndev)
return NULL;
dev = netdev_priv(ndev);
dev->ndev = ndev;
rc = register_netdev(ndev);
if (rc) {
free_netdev(ndev);
return NULL;
}
rcu_read_lock();
dev->mdev = __mctp_dev_get(ndev);
dev->mdev->net = mctp_default_net(dev_net(ndev));
rcu_read_unlock();
return dev;
}
void mctp_test_destroy_dev(struct mctp_test_dev *dev)
{
mctp_dev_put(dev->mdev);
unregister_netdev(dev->ndev);
}