net: mctp: Add support for gateway routing
Jeremy Kerr
maintainerv2 cover net: mctp: Add support for gateway routing
This series adds a gateway route type for the MCTP core, allowing non-local EIDs as the match for a route.
Example setup using the mctp tools:
mctp route add 9 via mctpi2c0
mctp neigh add 9 dev mctpi2c0 lladdr 0x1d
mctp route add 10 gw 9
- will route packets to eid 10 through mctpi2c0, using a dest lladdr of 0x1d (ie, that of the directly-attached eid 9).
The core change to support this is the introduction of a struct mctp_dst, which represents the result of a route lookup. Since this involves a bit of surgery through the routing code, we add a few tests along the way.
We're introducing an ABI change in the new RTM_{NEW,GET,DEL}ROUTE netlink formats, with the support for a RTA_GATEWAY attribute. Because we need a network ID specified to fully-qualify a gateway EID, the RTA_GATEWAY attribute carries the (net, eid) tuple in full:
struct mctp_fq_addr {
unsigned int net;
mctp_eid_t eid;
}Of course, any questions, comments etc are most welcome.
---
Changes in v2:
- 12/13: prevent uninitialsed gateway variable in nlparse_common
- 13/13: make test data static
- commit message spelling fixes
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Jeremy Kerr (13):
net: mctp: don't use source cb data when forwarding, ensure pkt_type is set
net: mctp: separate routing database from routing operations
net: mctp: separate cb from direct-addressing routing
net: mctp: test: Add an addressed device constructor
net: mctp: test: Add extaddr routing output test
net: mctp: test: move functions into utils.[ch]
net: mctp: test: add sock test infrastructure
net: mctp: test: Add initial socket tests
net: mctp: pass net into route creation
net: mctp: remove routes by netid, not by device
net: mctp: allow NL parsing directly into a struct mctp_route
net: mctp: add gateway routing support
net: mctp: test: Add tests for gateway routes
include/net/mctp.h | 52 +++- include/uapi/linux/mctp.h | 8 + net/mctp/af_mctp.c | 62 ++--- net/mctp/route.c | 563 ++++++++++++++++++++++++++++-------------- net/mctp/test/route-test.c | 604 +++++++++++++++++++++++++++++---------------- net/mctp/test/sock-test.c | 229 +++++++++++++++++ net/mctp/test/utils.c | 196 ++++++++++++++- net/mctp/test/utils.h | 44 ++++ 8 files changed, 1307 insertions(+), 451 deletions(-)
---
base-commit: 0097c4195b1d0ca57d15979626c769c74747b5a0
change-id: 20250520-dev-forwarding-0711973470bf
Best regards,
Signature · 1 line
Jeremy Kerr <[email protected]>
Jeremy Kerr
maintainerPATCH v2 1/13 net: mctp: don't use source cb data when forwarding, ensure pkt_type is set
In the output path, only check the skb->cb data when we know it's from a local socket; input packets will have source address information there instead.
In order to detect when we're forwarding, set skb->pkt_type on input/output.
--- net/mctp/route.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
net/mctp/route.c +12 -1
@@ -392,6 +392,9 @@ static int mctp_route_input(struct mctp_route *route, struct sk_buff *skb)*/ skb_orphan (skb); +if (skb->pkt_type ==PACKET_OUTGOING ) + skb->pkt_type =PACKET_LOOPBACK ; +/* ensure we have enough data for a header and a type */ if (skb->len <sizeof (struct mctp_hdr ) +1 ) goto out;
@@ -578,7 +581,13 @@ static int mctp_route_output(struct mctp_route *route, struct sk_buff *skb)return -EMSGSIZE ; } -if (cb->ifindex) { +/* If we're forwarding, we don't want to use the input path's cb, +* as it holds the *source* hardware addressing information. +* +* We will have a PACKET_HOST skb from the dev, or PACKET_OUTGOING +* from a socket; only use cb in the latter case. +*/ +if (skb->pkt_type ==PACKET_OUTGOING && cb->ifindex) {/* direct route; use the hwaddr we stashed in sendmsg */ if (cb->halen != skb->dev->addr_len) {/* sanity check, sendmsg should have already caught this */
@@ -587,6 +596,7 @@ static int mctp_route_output(struct mctp_route *route, struct sk_buff *skb) } daddr = cb->haddr; }else { + skb->pkt_type =PACKET_OUTGOING ;/* If lookup fails let the device handle daddr==NULL */ if (mctp_neigh_lookup (route->dev, hdr->dest, daddr_buf) ==0 ) daddr = daddr_buf;
@@ -1032,6 +1042,7 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt, tag = req_tag &MCTP_TAG_MASK ; } + skb->pkt_type =PACKET_OUTGOING ; skb->protocol =htons (ETH_P_MCTP ); skb->priority =0 ;skb_reset_transport_header (skb);
Signature · 1 line
2.39.5
Jeremy Kerr
maintainerPATCH v2 2/13 net: mctp: separate routing database from routing operations
In reply to Jeremy KerrThis change adds a struct mctp_dst, representing the result of a routing lookup. This decouples the struct mctp_route from the actual implementation of a routing operation.
This will allow for future routing changes which may require more involved lookup logic, such as gateway routing - which may require multiple traversals of the routing table.
Since we only use the struct mctp_route at lookup time, we no longer hold routes over a routing operation, as we only need it to populate the dst. However, we do hold the dev while the dst is active.
This requires some changes to the route test infrastructure, as we no longer have a mock route to handle the route output operation, and transient dsts are created by the routing code, so we can't override them as easily.
Instead, we use kunit->priv to stash a packet queue, and a custom dst_output function queues into that packet queue, which we can use for later expectations.
--- include/net/mctp.h | 35 +++++-- net/mctp/af_mctp.c | 59 ++++------- net/mctp/route.c | 205 +++++++++++++++++++------------------ net/mctp/test/route-test.c | 245 ++++++++++++++++++++++++++++----------------- 4 files changed, 308 insertions(+), 236 deletions(-)
include/net/mctp.h +29 -6
@@ -222,6 +222,8 @@ struct mctp_flow {struct mctp_sk_key *key; }; +struct mctp_dst ; +/* Route definition. * * These are held in the pernet->mctp.routes list, with RCU protection for
@@ -229,8 +231,7 @@ struct mctp_flow {* dropped on NETDEV_UNREGISTER events. * * Updates to the route table are performed under rtnl; all reads under RCU, -* so routes cannot be referenced over a RCU grace period. Specifically: A -* caller cannot block between mctp_route_lookup and mctp_route_release() +* so routes cannot be referenced over a RCU grace period. */ struct mctp_route {mctp_eid_t min, max;
@@ -238,7 +239,7 @@ struct mctp_route {unsigned char type;unsigned int mtu;struct mctp_dev *dev; -int (*output)(struct mctp_route *route, +int (*output)(struct mctp_dst *dst,struct sk_buff *skb);struct list_head list;
@@ -246,12 +247,34 @@ struct mctp_route {struct rcu_head rcu; }; +/* Route lookup result: dst. Represents the results of a routing decision, +* but is only held over the individual routing operation. +* +* Will typically be stored on the caller stack, and must be released after +* usage. +*/ +struct mctp_dst { +struct mctp_dev *dev; +unsigned int mtu; + +/* set for direct addressing */ +unsigned char halen; +unsigned char haddr[MAX_ADDR_LEN ]; + +int (*output)(struct mctp_dst *dst,struct sk_buff *skb); +}; + +int mctp_dst_from_extaddr (struct mctp_dst *dst,struct net *net,int ifindex, +unsigned char halen,const unsigned char *haddr); +/* route interfaces */ -struct mctp_route *mctp_route_lookup (struct net *net,unsigned int dnet, -mctp_eid_t daddr); +int mctp_route_lookup (struct net *net,unsigned int dnet, +mctp_eid_t daddr,struct mctp_dst *dst); + +void mctp_dst_release (struct mctp_dst *dst);/* always takes ownership of skb */ -int mctp_local_output (struct sock *sk,struct mctp_route *rt, +int mctp_local_output (struct sock *sk,struct mctp_dst *dst,struct sk_buff *skb,mctp_eid_t daddr,u8 req_tag);void mctp_key_unref (struct mctp_sk_key *key);
net/mctp/af_mctp.c +22 -37
94 lines not on this page · raw message
net/mctp/route.c +105 -100
375 lines not on this page · raw message
net/mctp/test/route-test.c +152 -93
689 lines not on this page · raw message
Signature · 1 line
2.39.5
Jeremy Kerr
maintainerPATCH v2 3/13 net: mctp: separate cb from direct-addressing routing
In reply to Jeremy KerrNow that we have the dst->haddr populated by sendmsg (when extended addressing is in use), we no longer need to stash the link-layer address in the skb->cb.
Instead, only use skb->cb for incoming lladdr data.
While we're at it: remove cb->src, as was never used.
--- include/net/mctp.h | 4 ++-- net/mctp/af_mctp.c | 3 +-- net/mctp/route.c | 21 +++++---------------- 3 files changed, 8 insertions(+), 20 deletions(-)
include/net/mctp.h +2 -2
@@ -183,8 +183,8 @@ struct mctp_sk_key {struct mctp_skb_cb {unsigned int magic;unsigned int net; -int ifindex;/* extended/direct addressing if set */ -mctp_eid_t src; +/* fields below provide extended addressing for ingress to recvmsg() */ +int ifindex;unsigned char halen;unsigned char haddr[MAX_ADDR_LEN ]; };
net/mctp/af_mctp.c +1 -2
@@ -134,8 +134,7 @@ static int mctp_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) DECLARE_SOCKADDR(struct sockaddr_mctp_ext *, extaddr, msg->msg_name); -if (!mctp_sockaddr_ext_is_ok (extaddr) || - extaddr->smctp_halen >sizeof (cb->haddr)) { +if (!mctp_sockaddr_ext_is_ok (extaddr)) { rc = -EINVAL ; goto err_free; }
net/mctp/route.c +5 -16
@@ -561,35 +561,28 @@ static int mctp_dst_input(struct mctp_dst *dst, struct sk_buff *skb)static int mctp_dst_output (struct mctp_dst *dst,struct sk_buff *skb) { -struct mctp_skb_cb *cb =mctp_cb (skb);struct mctp_hdr *hdr =mctp_hdr (skb);char daddr_buf[MAX_ADDR_LEN ];char *daddr =NULL ;int rc; skb->protocol =htons (ETH_P_MCTP ); + skb->pkt_type =PACKET_OUTGOING ;if (skb->len > dst->mtu) {kfree_skb (skb);return -EMSGSIZE ; } -/* If we're forwarding, we don't want to use the input path's cb, -* as it holds the *source* hardware addressing information. -* -* We will have a PACKET_HOST skb from the dev, or PACKET_OUTGOING -* from a socket; only use cb in the latter case. -*/ -if (skb->pkt_type ==PACKET_OUTGOING && cb->ifindex) { -/* direct route; use the hwaddr we stashed in sendmsg */ -if (cb->halen != skb->dev->addr_len) { +/* direct route; use the hwaddr we stashed in sendmsg */ +if (dst->halen) { +if (dst->halen != skb->dev->addr_len) {/* sanity check, sendmsg should have already caught this */ kfree_skb (skb);return -EMSGSIZE ; } - daddr = cb->haddr; + daddr = dst->haddr; }else { - skb->pkt_type =PACKET_OUTGOING ;/* If lookup fails let the device handle daddr==NULL */ if (mctp_neigh_lookup (dst->dev, hdr->dest, daddr_buf) ==0 ) daddr = daddr_buf;
@@ -1004,7 +997,6 @@ int mctp_local_output(struct sock *sk, struct mctp_dst *dst, struct sk_buff *skb, mctp_eid_t daddr, u8 req_tag) { struct mctp_sock *msk = container_of(sk, struct mctp_sock, sk); -struct mctp_skb_cb *cb =mctp_cb (skb);struct mctp_sk_key *key;struct mctp_hdr *hdr;unsigned long flags;
@@ -1059,9 +1051,6 @@ int mctp_local_output(struct sock *sk, struct mctp_dst *dst,skb_reset_network_header (skb); skb->dev = dst->dev->dev; -/* cb->net will have been set on initial ingress */ - cb->src = saddr; -/* set up common header fields */ hdr =mctp_hdr (skb); hdr->ver =1 ;
Signature · 1 line
2.39.5
Jeremy Kerr
maintainerPATCH v2 4/13 net: mctp: test: Add an addressed device constructor
In reply to Jeremy KerrUpcoming tests will check semantics of hardware addressing, which require a dev with ->addr_len != 0. Add a constructor to create a MCTP interface using a physically-addressed bus type.
--- net/mctp/test/utils.c | 20 ++++++++++++++++++-- net/mctp/test/utils.h | 7 +++++++ 2 files changed, 25 insertions(+), 2 deletions(-)
net/mctp/test/utils.c +18 -2
@@ -26,19 +26,22 @@ 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 ) +static struct mctp_test_dev *__mctp_test_create_dev (unsigned short lladdr_len, +const unsigned char *lladdr) {struct mctp_test_dev *dev;struct net_device *ndev;int rc; +if (WARN_ON (lladdr_len >MAX_ADDR_LEN )) +return NULL ; + ndev =alloc_netdev (sizeof (*dev),"mctptest%d" ,NET_NAME_ENUM , mctp_test_dev_setup);if (!ndev)
@@ -46,6 +49,8 @@ struct mctp_test_dev *mctp_test_create_dev(void) dev =netdev_priv (ndev); dev->ndev = ndev; + ndev->addr_len = lladdr_len; +dev_addr_set (ndev, lladdr); rc =register_netdev (ndev);if (rc) {
@@ -61,6 +66,17 @@ struct mctp_test_dev *mctp_test_create_dev(void)return dev; } +struct mctp_test_dev *mctp_test_create_dev (void ) +{ +return __mctp_test_create_dev (0 ,NULL ); +} + +struct mctp_test_dev *mctp_test_create_dev_lladdr (unsigned short lladdr_len, +const unsigned char *lladdr) +{ +return __mctp_test_create_dev (lladdr_len, lladdr); +} +void mctp_test_destroy_dev (struct mctp_test_dev *dev) {mctp_dev_put (dev->mdev);
net/mctp/test/utils.h +7 -0
@@ -3,6 +3,8 @@#ifndef __NET_MCTP_TEST_UTILS_H#define __NET_MCTP_TEST_UTILS_H +#include <uapi/linux/netdevice.h> +#include <kunit/test.h> #define MCTP_DEV_TEST_MTU 68
@@ -10,11 +12,16 @@struct mctp_test_dev {struct net_device *ndev;struct mctp_dev *mdev; + +unsigned short lladdr_len; +unsigned char lladdr[MAX_ADDR_LEN ]; };struct mctp_test_dev ;struct mctp_test_dev *mctp_test_create_dev (void ); +struct mctp_test_dev *mctp_test_create_dev_lladdr (unsigned short lladdr_len, +const unsigned char *lladdr);void mctp_test_destroy_dev (struct mctp_test_dev *dev);#endif /* __NET_MCTP_TEST_UTILS_H */
Signature · 1 line
2.39.5
Jeremy Kerr
maintainerPATCH v2 5/13 net: mctp: test: Add extaddr routing output test
In reply to Jeremy KerrTest that the routing code preserves the haddr data in a skb through an input route operation.
--- net/mctp/test/route-test.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
net/mctp/test/route-test.c +53 -0
@@ -1296,6 +1296,58 @@ static void mctp_test_route_output_key_create(struct kunit *test)mctp_test_destroy_dev (dev); } +static void mctp_test_route_extaddr_input (struct kunit *test) +{ +static const unsigned char haddr[] = {0xaa ,0x55 }; +struct mctp_test_pktqueue tpq; +struct mctp_skb_cb *cb, *cb2; +const unsigned int len =40 ; +struct mctp_test_dev *dev; +struct sk_buff *skb, *skb2; +struct mctp_dst dst; +struct mctp_hdr hdr; +struct socket *sock; +int rc; + + hdr.ver =1 ; + hdr.src =10 ; + hdr.dest =8 ; + hdr.flags_seq_tag =FL_S |FL_E |FL_TO ; + +__mctp_route_test_init (test, &dev, &dst, &tpq, &sock,MCTP_NET_ANY ); + + skb =mctp_test_create_skb (&hdr, len); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, skb); + +/* set our hardware addressing data */ + cb =mctp_cb (skb); +memcpy (cb->haddr, haddr,sizeof (haddr)); + cb->halen =sizeof (haddr); + +mctp_test_skb_set_dev (skb, dev); + + rc =mctp_dst_input (&dst, skb); +KUNIT_ASSERT_EQ (test, rc,0 ); + +mctp_test_dst_release (&dst, &tpq); + + skb2 =skb_recv_datagram (sock->sk,MSG_DONTWAIT , &rc); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, skb2); +KUNIT_ASSERT_EQ (test, skb2->len, len); + + cb2 =mctp_cb (skb2); + +/* Received SKB should have the hardware addressing as set above. +* We're likely to have the same actual cb here (ie., cb == cb2), +* but it's the comparison that we care about +*/ +KUNIT_EXPECT_EQ (test, cb2->halen,sizeof (haddr)); +KUNIT_EXPECT_MEMEQ (test, cb2->haddr, haddr,sizeof (haddr)); + +skb_free_datagram (sock->sk, skb2); +mctp_test_destroy_dev (dev); +} +static struct kunit_case mctp_test_cases[] = {KUNIT_CASE_PARAM (mctp_test_fragment, mctp_frag_gen_params),KUNIT_CASE_PARAM (mctp_test_rx_input, mctp_rx_input_gen_params),
@@ -1312,6 +1364,7 @@ static struct kunit_case mctp_test_cases[] = {KUNIT_CASE (mctp_test_fragment_flow),KUNIT_CASE (mctp_test_route_output_key_create),KUNIT_CASE (mctp_test_route_input_cloned_frag), + KUNIT_CASE(mctp_test_route_extaddr_input), {} };
Signature · 1 line
2.39.5
Jeremy Kerr
maintainerPATCH v2 6/13 net: mctp: test: move functions into utils.[ch]
In reply to Jeremy KerrA future change will add another mctp test .c file, so move some of the common test setup from route.c into the utils object.
--- net/mctp/test/route-test.c | 163 --------------------------------------------- net/mctp/test/utils.c | 150 +++++++++++++++++++++++++++++++++++++++++ net/mctp/test/utils.h | 32 +++++++++ 3 files changed, 182 insertions(+), 163 deletions(-)
net/mctp/test/route-test.c +0 -163
@@ -8,169 +8,6 @@#include "utils.h" -struct mctp_test_route { -struct mctp_route rt; -}; - -static const unsigned int test_pktqueue_magic =0x5f713aef ; - -struct mctp_test_pktqueue { -unsigned int magic; -struct sk_buff_head pkts; -}; - -static void mctp_test_pktqueue_init (struct mctp_test_pktqueue *tpq) -{ - tpq->magic = test_pktqueue_magic; -skb_queue_head_init (&tpq->pkts); -} - -static int mctp_test_dst_output (struct mctp_dst *dst,struct sk_buff *skb) -{ -struct kunit *test = current->kunit_test; -struct mctp_test_pktqueue *tpq = test->priv; - -KUNIT_ASSERT_EQ (test, tpq->magic, test_pktqueue_magic); - -skb_queue_tail (&tpq->pkts, skb); - -return 0 ; -} - -/* local version of mctp_route_alloc() */ -static struct mctp_test_route *mctp_route_test_alloc (void ) -{ -struct mctp_test_route *rt; - - rt =kzalloc (sizeof (*rt),GFP_KERNEL ); -if (!rt) -return NULL ; - -INIT_LIST_HEAD (&rt->rt.list); -refcount_set (&rt->rt.refs,1 ); - rt->rt.output = mctp_test_dst_output; - -return rt; -} - -static struct mctp_test_route *mctp_test_create_route (struct net *net, -struct mctp_dev *dev, -mctp_eid_t eid, -unsigned int mtu) -{ -struct mctp_test_route *rt; - - rt =mctp_route_test_alloc (); -if (!rt) -return NULL ; - - rt->rt.min = eid; - rt->rt.max = eid; - rt->rt.mtu = mtu; - rt->rt.type =RTN_UNSPEC ; -if (dev) -mctp_dev_hold (dev); - rt->rt.dev = dev; - -list_add_rcu (&rt->rt.list, &net->mctp.routes); - -return rt; -} - -/* Convenience function for our test dst; release with mctp_test_dst_release() -*/ -static void mctp_test_dst_setup (struct kunit *test,struct mctp_dst *dst, -struct mctp_test_dev *dev, -struct mctp_test_pktqueue *tpq, -unsigned int mtu) -{ -KUNIT_EXPECT_NOT_ERR_OR_NULL (test, dev); - -memset (dst,0 ,sizeof (*dst)); - - dst->dev = dev->mdev; -__mctp_dev_get (dst->dev->dev); - dst->mtu = mtu; - dst->output = mctp_test_dst_output; -mctp_test_pktqueue_init (tpq); - test->priv = tpq; -} - -static void mctp_test_dst_release (struct mctp_dst *dst, -struct mctp_test_pktqueue *tpq) -{ -mctp_dst_release (dst); -skb_queue_purge (&tpq->pkts); -} - -static void mctp_test_route_destroy (struct kunit *test, -struct mctp_test_route *rt) -{ -unsigned int refs; - -rtnl_lock (); -list_del_rcu (&rt->rt.list); -rtnl_unlock (); - -if (rt->rt.dev) -mctp_dev_put (rt->rt.dev); - - refs =refcount_read (&rt->rt.refs); -KUNIT_ASSERT_EQ_MSG (test, refs,1 ,"route ref imbalance" ); - -kfree_rcu (&rt->rt, rcu); -} - -static void mctp_test_skb_set_dev (struct sk_buff *skb, -struct mctp_test_dev *dev) -{ -struct mctp_skb_cb *cb; - - cb =mctp_cb (skb); - cb->net =READ_ONCE (dev->mdev->net); - skb->dev = dev->ndev; -} - -static struct sk_buff *mctp_test_create_skb (const struct mctp_hdr *hdr, -unsigned int data_len) -{ -size_t hdr_len =sizeof (*hdr); -struct sk_buff *skb; -unsigned int i; -u8 *buf; - - skb =alloc_skb (hdr_len + data_len,GFP_KERNEL ); -if (!skb) -return NULL ; - -__mctp_cb (skb); -memcpy (skb_put (skb, hdr_len), hdr, hdr_len); - - buf =skb_put (skb, data_len); -for (i =0 ; i < data_len; i++) - buf[i] = i &0xff ; - -return skb; -} - -static struct sk_buff *__mctp_test_create_skb_data (const struct mctp_hdr *hdr, -const void *data, -size_t data_len) -{ -size_t hdr_len =sizeof (*hdr); -struct sk_buff *skb; - - skb =alloc_skb (hdr_len + data_len,GFP_KERNEL ); -if (!skb) -return NULL ; - -__mctp_cb (skb); -memcpy (skb_put (skb, hdr_len), hdr, hdr_len); -memcpy (skb_put (skb, data_len), data, data_len); - -return skb; -} -#define mctp_test_create_skb_data (h, d) \ __mctp_test_create_skb_data(h, d, sizeof(*d))
net/mctp/test/utils.c +150 -0
153 lines not on this page · raw message
net/mctp/test/utils.h +32 -0
@@ -5,6 +5,9 @@#include <uapi/linux/netdevice.h> +#include <net/mctp.h> +#include <net/mctpdevice.h> +#include <kunit/test.h> #define MCTP_DEV_TEST_MTU 68
@@ -19,9 +22,38 @@ struct mctp_test_dev {struct mctp_test_dev ; +struct mctp_test_route { +struct mctp_route rt; +}; + +struct mctp_test_pktqueue { +unsigned int magic; +struct sk_buff_head pkts; +}; +struct mctp_test_dev *mctp_test_create_dev (void );struct mctp_test_dev *mctp_test_create_dev_lladdr (unsigned short lladdr_len,const unsigned char *lladdr);void mctp_test_destroy_dev (struct mctp_test_dev *dev); +struct mctp_test_route *mctp_test_create_route (struct net *net, +struct mctp_dev *dev, +mctp_eid_t eid, +unsigned int mtu); +void mctp_test_dst_setup (struct kunit *test,struct mctp_dst *dst, +struct mctp_test_dev *dev, +struct mctp_test_pktqueue *tpq,unsigned int mtu); +void mctp_test_dst_release (struct mctp_dst *dst, +struct mctp_test_pktqueue *tpq); +void mctp_test_pktqueue_init (struct mctp_test_pktqueue *tpq); +void mctp_test_route_destroy (struct kunit *test,struct mctp_test_route *rt); +void mctp_test_skb_set_dev (struct sk_buff *skb,struct mctp_test_dev *dev); +struct sk_buff *mctp_test_create_skb (const struct mctp_hdr *hdr, +unsigned int data_len); +struct sk_buff *__mctp_test_create_skb_data (const struct mctp_hdr *hdr, +const void *data,size_t data_len); + +#define mctp_test_create_skb_data (h, d) \ + __mctp_test_create_skb_data(h, d, sizeof(*d)) +#endif /* __NET_MCTP_TEST_UTILS_H */
Signature · 1 line
2.39.5
Jeremy Kerr
maintainerPATCH v2 7/13 net: mctp: test: add sock test infrastructure
In reply to Jeremy KerrAdd a new test object, for use with the af_mctp socket code. This is intially empty, but we'll start populating actual tests in an upcoming change.
--- net/mctp/af_mctp.c | 4 ++++ net/mctp/test/route-test.c | 2 +- net/mctp/test/sock-test.c | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-)
net/mctp/af_mctp.c +4 -0
@@ -777,3 +777,7 @@ MODULE_DESCRIPTION("MCTP core");MODULE_AUTHOR ("Jeremy Kerr <[email protected]>" );MODULE_ALIAS_NETPROTO (PF_MCTP ); + +#if IS_ENABLED (CONFIG_MCTP_TEST ) +#include "test/sock-test.c" +#endif
net/mctp/test/route-test.c +1 -1
@@ -1206,7 +1206,7 @@ static struct kunit_case mctp_test_cases[] = { };static struct kunit_suite mctp_test_suite = { - .name ="mctp" , + .name ="mctp-route" , .test_cases = mctp_test_cases, };
net/mctp/test/sock-test.c new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <kunit/test.h> + +#include "utils.h" + +static struct kunit_case mctp_test_cases[] = { + {} +}; + +static struct kunit_suite mctp_test_suite = { + .name ="mctp-sock" , + .test_cases = mctp_test_cases, +}; + +kunit_test_suite (mctp_test_suite);
Signature · 1 line
2.39.5
Jeremy Kerr
maintainerPATCH v2 8/13 net: mctp: test: Add initial socket tests
In reply to Jeremy KerrRecent changes have modified the extaddr path a little, so add a couple of kunit tests to af-mctp.c. These check that we're correctly passing lladdr data between sendmsg/recvmsg and the routing layer.
--- net/mctp/route.c | 5 ++ net/mctp/test/sock-test.c | 213 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 218 insertions(+)
net/mctp/route.c +5 -0
@@ -17,6 +17,8 @@#include <linux/rtnetlink.h> #include <linux/skbuff.h> +#include <kunit/static_stub.h> +#include <uapi/linux/if_arp.h> #include <net/mctp.h>
@@ -1006,6 +1008,9 @@ int mctp_local_output(struct sock *sk, struct mctp_dst *dst,int rc;u8 tag; +KUNIT_STATIC_STUB_REDIRECT (mctp_local_output, sk, dst, skb, daddr, + req_tag); + rc = -ENODEV ;spin_lock_irqsave (&dst->dev->addrs_lock, flags);
net/mctp/test/sock-test.c +213 -0
223 lines not on this page · raw message
Signature · 1 line
2.39.5
Jeremy Kerr
maintainerPATCH v2 9/13 net: mctp: pass net into route creation
In reply to Jeremy KerrWe may not have a mdev pointer, from which we currently extract the net.
Instead, pass the net directly.
--- net/mctp/route.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
net/mctp/route.c +16 -15
@@ -1081,12 +1081,11 @@ int mctp_local_output(struct sock *sk, struct mctp_dst *dst, }/* route management */ -static int mctp_route_add (struct mctp_dev *mdev,mctp_eid_t daddr_start, -unsigned int daddr_extent,unsigned int mtu, -unsigned char type) +static int mctp_route_add (struct net *net,struct mctp_dev *mdev, +mctp_eid_t daddr_start,unsigned int daddr_extent, +unsigned int mtu,unsigned char type) {int (*rtfn)(struct mctp_dst *dst,struct sk_buff *skb); -struct net *net =dev_net (mdev->dev);struct mctp_route *rt, *ert;if (!mctp_address_unicast (daddr_start))
@@ -1133,10 +1132,10 @@ static int mctp_route_add(struct mctp_dev *mdev, mctp_eid_t daddr_start,return 0 ; } -static int mctp_route_remove (struct mctp_dev *mdev,mctp_eid_t daddr_start, -unsigned int daddr_extent,unsigned char type) +static int mctp_route_remove (struct net *net,struct mctp_dev *mdev, +mctp_eid_t daddr_start,unsigned int daddr_extent, +unsigned char type) { -struct net *net =dev_net (mdev->dev);struct mctp_route *rt, *tmp;mctp_eid_t daddr_end;bool dropped;
@@ -1165,12 +1164,12 @@ static int mctp_route_remove(struct mctp_dev *mdev, mctp_eid_t daddr_start,int mctp_route_add_local (struct mctp_dev *mdev,mctp_eid_t addr) { -return mctp_route_add (mdev, addr,0 ,0 ,RTN_LOCAL ); +return mctp_route_add (dev_net (mdev->dev), mdev, addr,0 ,0 ,RTN_LOCAL ); }int mctp_route_remove_local (struct mctp_dev *mdev,mctp_eid_t addr) { -return mctp_route_remove (mdev, addr,0 ,RTN_LOCAL ); +return mctp_route_remove (dev_net (mdev->dev), mdev, addr,0 ,RTN_LOCAL ); }/* removes all entries for a given device */
@@ -1279,12 +1278,11 @@ static const struct nla_policy rta_mctp_policy[RTA_MAX + 1] = {/* Common part for RTM_NEWROUTE and RTM_DELROUTE parsing. * tb must hold RTA_MAX+1 elements. */ -static int mctp_route_nlparse (struct sk_buff *skb,struct nlmsghdr *nlh, +static int mctp_route_nlparse (struct net *net,struct nlmsghdr *nlh,struct netlink_ext_ack *extack,struct nlattr **tb,struct rtmsg **rtm,struct mctp_dev **mdev,mctp_eid_t *daddr_start) { -struct net *net =sock_net (skb->sk);struct net_device *dev;unsigned int ifindex;int rc;
@@ -1338,6 +1336,7 @@ static const struct nla_policy rta_metrics_policy[RTAX_MAX + 1] = {static int mctp_newroute (struct sk_buff *skb,struct nlmsghdr *nlh,struct netlink_ext_ack *extack) { +struct net *net =sock_net (skb->sk);struct nlattr *tb[RTA_MAX +1 ];struct nlattr *tbx[RTAX_MAX +1 ];mctp_eid_t daddr_start;
@@ -1346,7 +1345,7 @@ static int mctp_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,unsigned int mtu;int rc; - rc =mctp_route_nlparse (skb, nlh, extack, tb, + rc =mctp_route_nlparse (net, nlh, extack, tb, &rtm, &mdev, &daddr_start);if (rc <0 )return rc;
@@ -1366,7 +1365,7 @@ static int mctp_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, mtu =nla_get_u32 (tbx[RTAX_MTU ]); } - rc =mctp_route_add (mdev, daddr_start, rtm->rtm_dst_len, mtu, + rc =mctp_route_add (net, mdev, daddr_start, rtm->rtm_dst_len, mtu, rtm->rtm_type);return rc; }
@@ -1374,13 +1373,14 @@ static int mctp_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,static int mctp_delroute (struct sk_buff *skb,struct nlmsghdr *nlh,struct netlink_ext_ack *extack) { +struct net *net =sock_net (skb->sk);struct nlattr *tb[RTA_MAX +1 ];mctp_eid_t daddr_start;struct mctp_dev *mdev;struct rtmsg *rtm;int rc; - rc =mctp_route_nlparse (skb, nlh, extack, tb, + rc =mctp_route_nlparse (net, nlh, extack, tb, &rtm, &mdev, &daddr_start);if (rc <0 )return rc;
@@ -1389,7 +1389,8 @@ static int mctp_delroute(struct sk_buff *skb, struct nlmsghdr *nlh,if (rtm->rtm_type !=RTN_UNICAST )return -EINVAL ; - rc =mctp_route_remove (mdev, daddr_start, rtm->rtm_dst_len,RTN_UNICAST ); + rc =mctp_route_remove (net, mdev, daddr_start, rtm->rtm_dst_len, +RTN_UNICAST );return rc; }
Signature · 1 line
2.39.5
Jeremy Kerr
maintainerPATCH v2 10/13 net: mctp: remove routes by netid, not by device
In reply to Jeremy KerrIn upcoming changes, a route may not have a device associated. Since the route is matched on the (network, eid) tuple, pass the netid itself into mctp_route_remove.
--- net/mctp/route.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
net/mctp/route.c +10 -4
@@ -1080,6 +1080,11 @@ int mctp_local_output(struct sock *sk, struct mctp_dst *dst,return rc; } +static unsigned int mctp_route_netid (struct mctp_route *rt) +{ +return rt->dev->net; +} +/* route management */ static int mctp_route_add(struct net *net, struct mctp_dev *mdev, mctp_eid_t daddr_start, unsigned int daddr_extent,
@@ -1132,7 +1137,7 @@ static int mctp_route_add(struct net *net, struct mctp_dev *mdev,return 0 ; } -static int mctp_route_remove (struct net *net,struct mctp_dev *mdev, +static int mctp_route_remove (struct net *net,unsigned int netid,mctp_eid_t daddr_start,unsigned int daddr_extent,unsigned char type) {
@@ -1149,7 +1154,7 @@ static int mctp_route_remove(struct net *net, struct mctp_dev *mdev,ASSERT_RTNL ();list_for_each_entry_safe (rt, tmp, &net->mctp.routes, list) { -if (rt->dev == mdev && +if (mctp_route_netid (rt) == netid && rt->min == daddr_start && rt->max == daddr_end && rt->type == type) {list_del_rcu (&rt->list);
@@ -1169,7 +1174,8 @@ int mctp_route_add_local(struct mctp_dev *mdev, mctp_eid_t addr)int mctp_route_remove_local (struct mctp_dev *mdev,mctp_eid_t addr) { -return mctp_route_remove (dev_net (mdev->dev), mdev, addr,0 ,RTN_LOCAL ); +return mctp_route_remove (dev_net (mdev->dev), mdev->net, + addr,0 ,RTN_LOCAL ); }/* removes all entries for a given device */
@@ -1389,7 +1395,7 @@ static int mctp_delroute(struct sk_buff *skb, struct nlmsghdr *nlh,if (rtm->rtm_type !=RTN_UNICAST )return -EINVAL ; - rc =mctp_route_remove (net, mdev, daddr_start, rtm->rtm_dst_len, + rc =mctp_route_remove (net, mdev->net, daddr_start, rtm->rtm_dst_len,RTN_UNICAST );return rc; }
Signature · 1 line
2.39.5
Jeremy Kerr
maintainerPATCH v2 11/13 net: mctp: allow NL parsing directly into a struct mctp_route
In reply to Jeremy KerrThe netlink route parsing functions end up setting a bunch of output variables from the rt attributes. This will get messy when the routes become more complex.
So, split the rt parsing into two types: a lookup (returning route target data suitable for a route lookup, like when deleting a route) and a populate (setting fields of a struct mctp_route).
In doing this, we need to separate the route allocation from mctp_route_add, so add some comments on the lifetime semantics for the latter.
--- net/mctp/route.c | 194 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 130 insertions(+), 64 deletions(-)
net/mctp/route.c +130 -64
@@ -1086,25 +1086,32 @@ static unsigned int mctp_route_netid(struct mctp_route *rt) }/* route management */ -static int mctp_route_add (struct net *net,struct mctp_dev *mdev, -mctp_eid_t daddr_start,unsigned int daddr_extent, -unsigned int mtu,unsigned char type) + +/* mctp_route_add(): Add the provided route, previously allocated via +* mctp_route_alloc(). On success, takes ownership of @rt, which includes a +* hold on rt->dev for usage in the route table. On failure a caller will want +* to mctp_route_release(). +* +* We expect that the caller has set rt->type, rt->min, rt->max, rt->dev and +* rt->mtu, and that the route holds a reference to rt->dev (via mctp_dev_hold). +* Other fields will be populated. +*/ +static int mctp_route_add (struct net *net,struct mctp_route *rt) { -int (*rtfn)(struct mctp_dst *dst,struct sk_buff *skb); -struct mctp_route *rt, *ert; +struct mctp_route *ert; -if (!mctp_address_unicast (daddr_start)) +if (!mctp_address_unicast (rt->min) || !mctp_address_unicast (rt->max))return -EINVAL ; -if (daddr_extent >0xff || daddr_start + daddr_extent >=255 ) +if (!rt->dev)return -EINVAL ; -switch (type) { +switch (rt->type) {case RTN_LOCAL : - rtfn = mctp_dst_input; + rt->output = mctp_dst_input;break ;case RTN_UNICAST : - rtfn = mctp_dst_output; + rt->output = mctp_dst_output;break ;default :return -EINVAL ;
@@ -1112,22 +1119,9 @@ static int mctp_route_add(struct net *net, struct mctp_dev *mdev,ASSERT_RTNL (); - rt =mctp_route_alloc (); -if (!rt) -return -ENOMEM ; - - rt->min = daddr_start; - rt->max = daddr_start + daddr_extent; - rt->mtu = mtu; - rt->dev = mdev; -mctp_dev_hold (rt->dev); - rt->type = type; - rt->output = rtfn; -/* Prevent duplicate identical routes. */ list_for_each_entry (ert, &net->mctp.routes, list) {if (mctp_rt_compare_exact (rt, ert)) { -mctp_route_release (rt);return -EEXIST ; } }
@@ -1169,7 +1163,25 @@ static int mctp_route_remove(struct net *net, unsigned int netid,int mctp_route_add_local (struct mctp_dev *mdev,mctp_eid_t addr) { -return mctp_route_add (dev_net (mdev->dev), mdev, addr,0 ,0 ,RTN_LOCAL ); +struct mctp_route *rt; +int rc; + + rt =mctp_route_alloc (); +if (!rt) +return -ENOMEM ; + + rt->min = addr; + rt->max = addr; + rt->dev = mdev; + rt->type =RTN_LOCAL ; + +mctp_dev_hold (rt->dev); + + rc =mctp_route_add (dev_net (mdev->dev), rt); +if (rc) +mctp_route_release (rt); + +return rc; }int mctp_route_remove_local (struct mctp_dev *mdev,mctp_eid_t addr)
@@ -1281,13 +1293,16 @@ static const struct nla_policy rta_mctp_policy[RTA_MAX + 1] = { [RTA_OIF] = { .type = NLA_U32 }, }; -/* Common part for RTM_NEWROUTE and RTM_DELROUTE parsing. -* tb must hold RTA_MAX+1 elements. -*/ -static int mctp_route_nlparse (struct net *net,struct nlmsghdr *nlh, -struct netlink_ext_ack *extack, -struct nlattr **tb,struct rtmsg **rtm, -struct mctp_dev **mdev,mctp_eid_t *daddr_start) +static const struct nla_policy rta_metrics_policy[RTAX_MAX +1 ] = { + [RTAX_MTU ] = { .type =NLA_U32 }, +}; + +/* base parsing; common to both _lookup and _populate variants */ +static int mctp_route_nlparse_common (struct net *net,struct nlmsghdr *nlh, +struct netlink_ext_ack *extack, +struct nlattr **tb,struct rtmsg **rtm, +struct mctp_dev **mdev, +mctp_eid_t *daddr_start) {struct net_device *dev;unsigned int ifindex;
@@ -1318,61 +1333,114 @@ static int mctp_route_nlparse(struct net *net, struct nlmsghdr *nlh,return -EINVAL ; } +if ((*rtm)->rtm_type !=RTN_UNICAST ) { +NL_SET_ERR_MSG (extack,"rtm_type must be RTN_UNICAST" ); +return -EINVAL ; + } + dev =__dev_get_by_index (net, ifindex);if (!dev) {NL_SET_ERR_MSG (extack,"bad ifindex" );return -ENODEV ; } + *mdev =mctp_dev_get_rtnl (dev);if (!*mdev)return -ENODEV ; -if (dev->flags &IFF_LOOPBACK ) { -NL_SET_ERR_MSG (extack,"no routes to loopback" ); -return -EINVAL ; - } -return 0 ; } -static const struct nla_policy rta_metrics_policy[RTAX_MAX +1 ] = { - [RTAX_MTU ] = { .type =NLA_U32 }, -}; - -static int mctp_newroute (struct sk_buff *skb,struct nlmsghdr *nlh, -struct netlink_ext_ack *extack) +/* Route parsing for lookup operations; we only need the "route target" +* components (ie., network and dest-EID range). +*/ +static int mctp_route_nlparse_lookup (struct net *net,struct nlmsghdr *nlh, +struct netlink_ext_ack *extack, +unsigned char *type,unsigned int *netid, +mctp_eid_t *daddr_start, +unsigned int *daddr_extent) { -struct net *net =sock_net (skb->sk);struct nlattr *tb[RTA_MAX +1 ]; -struct nlattr *tbx[RTAX_MAX +1 ]; -mctp_eid_t daddr_start;struct mctp_dev *mdev;struct rtmsg *rtm; -unsigned int mtu;int rc; - rc =mctp_route_nlparse (net, nlh, extack, tb, - &rtm, &mdev, &daddr_start); -if (rc <0 ) + rc =mctp_route_nlparse_common (net, nlh, extack, tb, &rtm, + &mdev, daddr_start); +if (rc)return rc; -if (rtm->rtm_type !=RTN_UNICAST ) { -NL_SET_ERR_MSG (extack,"rtm_type must be RTN_UNICAST" ); + *netid = mdev->net; + *type = rtm->rtm_type; + *daddr_extent = rtm->rtm_dst_len; + +return 0 ; +} + +/* Full route parse for RTM_NEWROUTE: populate @rt */ +static int mctp_route_nlparse_populate (struct net *net,struct nlmsghdr *nlh, +struct netlink_ext_ack *extack, +struct mctp_route *rt) +{ +struct nlattr *tbx[RTAX_MAX +1 ]; +struct nlattr *tb[RTA_MAX +1 ]; +unsigned int daddr_extent; +struct rtmsg *rtm; +int rc; + + rc =mctp_route_nlparse_common (net, nlh, extack, tb, &rtm, + &rt->dev, &rt->min); +if (rc) +return rc; + + daddr_extent = rtm->rtm_dst_len; + +if (daddr_extent >0xff || daddr_extent + rt->min >=255 ) { +NL_SET_ERR_MSG (extack,"invalid eid range" );return -EINVAL ; } - mtu =0 ; + rt->type = rtm->rtm_type; + rt->max = rt->min + daddr_extent; + rt->mtu =0 ; +if (tb[RTA_METRICS ]) { rc =nla_parse_nested (tbx,RTAX_MAX , tb[RTA_METRICS ], rta_metrics_policy,NULL ); -if (rc <0 ) +if (rc <0 ) { +NL_SET_ERR_MSG (extack,"incorrect RTA_METRICS format" );return rc; + }if (tbx[RTAX_MTU ]) - mtu =nla_get_u32 (tbx[RTAX_MTU ]); + rt->mtu =nla_get_u32 (tbx[RTAX_MTU ]); } - rc =mctp_route_add (net, mdev, daddr_start, rtm->rtm_dst_len, mtu, - rtm->rtm_type); +return 0 ; +} + +static int mctp_newroute (struct sk_buff *skb,struct nlmsghdr *nlh, +struct netlink_ext_ack *extack) +{ +struct net *net =sock_net (skb->sk); +struct mctp_route *rt; +int rc; + + rt =mctp_route_alloc (); +if (!rt) +return -ENOMEM ; + + rc =mctp_route_nlparse_populate (net, nlh, extack, rt); +if (rc <0 ) + goto err_free; + +mctp_dev_hold (rt->dev); + + rc =mctp_route_add (net, rt); +if (!rc) +return 0 ; + +err_free: +mctp_route_release (rt);return rc; }
@@ -1380,23 +1448,21 @@ static int mctp_delroute(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk); -struct nlattr *tb[RTA_MAX +1 ]; +unsigned int netid, daddr_extent;mctp_eid_t daddr_start; -struct mctp_dev *mdev; -struct rtmsg *rtm; +unsigned char type;int rc; - rc =mctp_route_nlparse (net, nlh, extack, tb, - &rtm, &mdev, &daddr_start); + rc =mctp_route_nlparse_lookup (net, nlh, extack, &type, &netid, + &daddr_start, &daddr_extent);if (rc <0 )return rc;/* we only have unicast routes */ -if (rtm->rtm_type !=RTN_UNICAST ) +if (type !=RTN_UNICAST )return -EINVAL ; - rc =mctp_route_remove (net, mdev->net, daddr_start, rtm->rtm_dst_len, -RTN_UNICAST ); + rc =mctp_route_remove (net, netid, daddr_start, daddr_extent, type);return rc; }
Signature · 1 line
2.39.5
Jeremy Kerr
maintainerPATCH v2 12/13 net: mctp: add gateway routing support
In reply to Jeremy KerrThis change allows for gateway routing, where a route table entry may reference a routable endpoint (by network and EID), instead of routing directly to a netdevice.
We add support for a RTM_GATEWAY attribute for netlink route updates, with an attribute format of:
struct mctp_fq_addr {
unsigned int net;
mctp_eid_t eid;
}- we need the net here to uniquely identify the target EID, as we no longer have the device reference directly (which would provide the net id in the case of direct routes).
This makes route lookups recursive, as a route lookup that returns a gateway route must be resolved into a direct route (ie, to a device) eventually. We provide a limit to the route lookups, to prevent infinite loop routing.
The route lookup populates a new 'nexthop' field in the dst structure, which now specifies the key for the neighbour table lookup on device output, rather than using the packet destination address directly.
--
v2:
- prevent uninitialsed gateway variable in nlparse_common, as reported by Simon Horman via smatch
--- include/net/mctp.h | 13 ++- include/uapi/linux/mctp.h | 8 ++ net/mctp/route.c | 200 ++++++++++++++++++++++++++++++++++------------ net/mctp/test/utils.c | 3 +- 4 files changed, 171 insertions(+), 53 deletions(-)
include/net/mctp.h +12 -1
@@ -237,8 +237,18 @@ struct mctp_route {mctp_eid_t min, max;unsigned char type; +unsigned int mtu; -struct mctp_dev *dev; + +enum { +MCTP_ROUTE_DIRECT , +MCTP_ROUTE_GATEWAY , + } dst_type; +union { +struct mctp_dev *dev; +struct mctp_fq_addr gateway; + }; +int (*output)(struct mctp_dst *dst,struct sk_buff *skb);
@@ -256,6 +266,7 @@ struct mctp_route {struct mctp_dst {struct mctp_dev *dev;unsigned int mtu; +mctp_eid_t nexthop;/* set for direct addressing */ unsigned char halen;
include/uapi/linux/mctp.h +8 -0
@@ -37,6 +37,14 @@ struct sockaddr_mctp_ext {__u8 smctp_haddr[MAX_ADDR_LEN ]; }; +/* A "fully qualified" MCTP address, which includes the system-local network ID, +* required to uniquely resolve a routable EID. +*/ +struct mctp_fq_addr { +unsigned int net; +mctp_eid_t eid; +}; +#define MCTP_NET_ANY 0x0#define MCTP_ADDR_NULL 0x00
net/mctp/route.c +149 -51
384 lines not on this page · raw message
net/mctp/test/utils.c +2 -1
@@ -134,6 +134,7 @@ struct mctp_test_route *mctp_test_create_route(struct net *net, rt->rt.max = eid; rt->rt.mtu = mtu; rt->rt.type =RTN_UNSPEC ; + rt->rt.dst_type =MCTP_ROUTE_DIRECT ;if (dev)mctp_dev_hold (dev); rt->rt.dev = dev;
@@ -176,7 +177,7 @@ void mctp_test_route_destroy(struct kunit *test, struct mctp_test_route *rt)list_del_rcu (&rt->rt.list);rtnl_unlock (); -if (rt->rt.dev) +if (rt->rt.dst_type ==MCTP_ROUTE_DIRECT && rt->rt.dev)mctp_dev_put (rt->rt.dev); refs =refcount_read (&rt->rt.refs);
Signature · 1 line
2.39.5
Jeremy Kerr
maintainerPATCH v2 13/13 net: mctp: test: Add tests for gateway routes
In reply to Jeremy KerrAdd a few kunit tests for the gateway routing. Because we have multiple route types now (direct and gateway), rename mctp_test_create_route to mctp_test_create_route_direct, and add a _gateway variant too.
--
v2:
- static-ify mctp_route_gw_mty_tests, reported by kernel test robot
--- net/mctp/test/route-test.c | 233 ++++++++++++++++++++++++++++++++++++++++++++- net/mctp/test/sock-test.c | 2 +- net/mctp/test/utils.c | 33 ++++++- net/mctp/test/utils.h | 13 ++- 4 files changed, 271 insertions(+), 10 deletions(-)
net/mctp/test/route-test.c +232 -1
@@ -141,7 +141,7 @@ static void mctp_test_rx_input(struct kunit *test) dev =mctp_test_create_dev ();KUNIT_ASSERT_NOT_ERR_OR_NULL (test, dev); - rt =mctp_test_create_route (&init_net, dev->mdev,8 ,68 ); + rt =mctp_test_create_route_direct (&init_net, dev->mdev,8 ,68 );KUNIT_ASSERT_NOT_ERR_OR_NULL (test, rt); skb =mctp_test_create_skb (¶ms->hdr,1 );
@@ -1185,6 +1185,233 @@ static void mctp_test_route_extaddr_input(struct kunit *test)mctp_test_destroy_dev (dev); } +static void mctp_test_route_gw_lookup (struct kunit *test) +{ +struct mctp_test_route *rt1, *rt2; +struct mctp_dst dst = {0 }; +struct mctp_test_dev *dev; +int rc; + + dev =mctp_test_create_dev (); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, dev); + +/* 8 (local) -> 10 (gateway) via 9 (direct) */ + rt1 =mctp_test_create_route_direct (&init_net, dev->mdev,9 ,0 ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, rt1); + rt2 =mctp_test_create_route_gw (&init_net, dev->mdev->net,10 ,9 ,0 ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, rt2); + + rc =mctp_route_lookup (&init_net, dev->mdev->net,10 , &dst); +KUNIT_EXPECT_EQ (test, rc,0 ); +KUNIT_EXPECT_PTR_EQ (test, dst.dev, dev->mdev); +KUNIT_EXPECT_EQ (test, dst.mtu, dev->ndev->mtu); +KUNIT_EXPECT_EQ (test, dst.nexthop,9 ); +KUNIT_EXPECT_EQ (test, dst.halen,0 ); + +mctp_dst_release (&dst); + +mctp_test_route_destroy (test, rt2); +mctp_test_route_destroy (test, rt1); +mctp_test_destroy_dev (dev); +} + +static void mctp_test_route_gw_loop (struct kunit *test) +{ +struct mctp_test_route *rt1, *rt2; +struct mctp_dst dst = {0 }; +struct mctp_test_dev *dev; +int rc; + + dev =mctp_test_create_dev (); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, dev); + +/* two routes using each other as the gw */ + rt1 =mctp_test_create_route_gw (&init_net, dev->mdev->net,9 ,10 ,0 ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, rt1); + rt2 =mctp_test_create_route_gw (&init_net, dev->mdev->net,10 ,9 ,0 ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, rt2); + +/* this should fail, rather than infinite-loop */ + rc =mctp_route_lookup (&init_net, dev->mdev->net,10 , &dst); +KUNIT_EXPECT_NE (test, rc,0 ); + +mctp_test_route_destroy (test, rt2); +mctp_test_route_destroy (test, rt1); +mctp_test_destroy_dev (dev); +} + +struct mctp_route_gw_mtu_test { +/* working away from the local stack */ +unsigned int dev, neigh, gw, dst; +unsigned int exp; +}; + +static void mctp_route_gw_mtu_to_desc (const struct mctp_route_gw_mtu_test *t, +char *desc) +{ +sprintf (desc,"dev %d, neigh %d, gw %d, dst %d -> %d" , + t->dev, t->neigh, t->gw, t->dst, t->exp); +} + +static const struct mctp_route_gw_mtu_test mctp_route_gw_mtu_tests[] = { +/* no route-specific MTUs */ + {68 ,0 ,0 ,0 ,68 }, + {100 ,0 ,0 ,0 ,100 }, +/* one route MTU (smaller than dev mtu), others unrestricted */ + {100 ,68 ,0 ,0 ,68 }, + {100 ,0 ,68 ,0 ,68 }, + {100 ,0 ,0 ,68 ,68 }, +/* smallest applied, regardless of order */ + {100 ,99 ,98 ,68 ,68 }, + {99 ,100 ,98 ,68 ,68 }, + {98 ,99 ,100 ,68 ,68 }, + {68 ,98 ,99 ,100 ,68 }, +}; + +KUNIT_ARRAY_PARAM (mctp_route_gw_mtu, mctp_route_gw_mtu_tests, + mctp_route_gw_mtu_to_desc); + +static void mctp_test_route_gw_mtu (struct kunit *test) +{ +const struct mctp_route_gw_mtu_test *mtus = test->param_value; +struct mctp_test_route *rt1, *rt2, *rt3; +struct mctp_dst dst = {0 }; +struct mctp_test_dev *dev; +struct mctp_dev *mdev; +unsigned int netid; +int rc; + + dev =mctp_test_create_dev (); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, dev); + dev->ndev->mtu = mtus->dev; + mdev = dev->mdev; + netid = mdev->net; + +/* 8 (local) -> 11 (dst) via 10 (gw) via 9 (neigh) */ + rt1 =mctp_test_create_route_direct (&init_net, mdev,9 , mtus->neigh); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, rt1); + + rt2 =mctp_test_create_route_gw (&init_net, netid,10 ,9 , mtus->gw); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, rt2); + + rt3 =mctp_test_create_route_gw (&init_net, netid,11 ,10 , mtus->dst); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, rt3); + + rc =mctp_route_lookup (&init_net, dev->mdev->net,11 , &dst); +KUNIT_EXPECT_EQ (test, rc,0 ); +KUNIT_EXPECT_EQ (test, dst.mtu, mtus->exp); + +mctp_dst_release (&dst); + +mctp_test_route_destroy (test, rt3); +mctp_test_route_destroy (test, rt2); +mctp_test_route_destroy (test, rt1); +mctp_test_destroy_dev (dev); +} + +#define MCTP_TEST_LLADDR_LEN 2 +struct mctp_test_llhdr { +unsigned int magic; +unsigned char src[MCTP_TEST_LLADDR_LEN ]; +unsigned char dst[MCTP_TEST_LLADDR_LEN ]; +}; + +static const unsigned int mctp_test_llhdr_magic =0x5c78339c ; + +static int test_dev_header_create (struct sk_buff *skb,struct net_device *dev, +unsigned short type,const void *daddr, +const void *saddr,unsigned int len) +{ +struct kunit *test = current->kunit_test; +struct mctp_test_llhdr *hdr; + + hdr =skb_push (skb,sizeof (*hdr)); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, hdr); +skb_reset_mac_header (skb); + + hdr->magic = mctp_test_llhdr_magic; +memcpy (&hdr->src, saddr,sizeof (hdr->src)); +memcpy (&hdr->dst, daddr,sizeof (hdr->dst)); + +return 0 ; +} + +/* Test the dst_output path for a gateway-routed skb: we should have it +* lookup the nexthop EID in the neighbour table, and call into +* header_ops->create to resolve that to a lladdr. Our mock header_ops->create +* will just set a synthetic link-layer header, which we check after transmit. +*/ +static void mctp_test_route_gw_output (struct kunit *test) +{ +const unsigned char haddr_self[MCTP_TEST_LLADDR_LEN ] = {0xaa ,0x03 }; +const unsigned char haddr_peer[MCTP_TEST_LLADDR_LEN ] = {0xaa ,0x02 }; +const struct header_ops ops = { + .create = test_dev_header_create, + }; +struct mctp_neigh neigh = {0 }; +struct mctp_test_llhdr *ll_hdr; +struct mctp_dst dst = {0 }; +struct mctp_hdr hdr = {0 }; +struct mctp_test_dev *dev; +struct sk_buff *skb; +unsigned char *buf; +int i, rc; + + dev =mctp_test_create_dev_lladdr (sizeof (haddr_self), haddr_self); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, dev); + dev->ndev->header_ops = &ops; + + dst.dev = dev->mdev; +__mctp_dev_get (dst.dev->dev); + dst.mtu =68 ; + dst.nexthop =9 ; + +/* simple mctp_neigh_add for the gateway (not dest!) endpoint */ +INIT_LIST_HEAD (&neigh.list); + neigh.dev = dev->mdev; +mctp_dev_hold (dev->mdev); + neigh.eid =9 ; + neigh.source =MCTP_NEIGH_STATIC ; +memcpy (neigh.ha, haddr_peer,sizeof (haddr_peer)); +list_add_rcu (&neigh.list, &init_net.mctp.neighbours); + + hdr.ver =1 ; + hdr.src =8 ; + hdr.dest =10 ; + hdr.flags_seq_tag =FL_S |FL_E |FL_TO ; + +/* construct enough for a future link-layer header, the provided +* mctp header, and 4 bytes of data +*/ + skb =alloc_skb (sizeof (*ll_hdr) +sizeof (hdr) +4 ,GFP_KERNEL ); + skb->dev = dev->ndev; +__mctp_cb (skb); + +skb_reserve (skb,sizeof (*ll_hdr)); + +memcpy (skb_put (skb,sizeof (hdr)), &hdr,sizeof (hdr)); + buf =skb_put (skb,4 ); +for (i =0 ; i <4 ; i++) + buf[i] = i; + +/* extra ref over the dev_xmit */ +skb_get (skb); + + rc =mctp_dst_output (&dst, skb); +KUNIT_EXPECT_EQ (test, rc,0 ); + +mctp_dst_release (&dst); +list_del_rcu (&neigh.list); +mctp_dev_put (dev->mdev); + +/* check that we have our header created with the correct neighbour */ + ll_hdr = (void *)skb_mac_header (skb); +KUNIT_EXPECT_EQ (test, ll_hdr->magic, mctp_test_llhdr_magic); +KUNIT_EXPECT_MEMEQ (test, ll_hdr->src, haddr_self,sizeof (haddr_self)); +KUNIT_EXPECT_MEMEQ (test, ll_hdr->dst, haddr_peer,sizeof (haddr_peer)); +kfree_skb (skb); +} +static struct kunit_case mctp_test_cases[] = {KUNIT_CASE_PARAM (mctp_test_fragment, mctp_frag_gen_params),KUNIT_CASE_PARAM (mctp_test_rx_input, mctp_rx_input_gen_params),
@@ -1202,6 +1429,10 @@ static struct kunit_case mctp_test_cases[] = {KUNIT_CASE (mctp_test_route_output_key_create),KUNIT_CASE (mctp_test_route_input_cloned_frag),KUNIT_CASE (mctp_test_route_extaddr_input), +KUNIT_CASE (mctp_test_route_gw_lookup), +KUNIT_CASE (mctp_test_route_gw_loop), +KUNIT_CASE_PARAM (mctp_test_route_gw_mtu, mctp_route_gw_mtu_gen_params), + KUNIT_CASE(mctp_test_route_gw_output), {} };
net/mctp/test/sock-test.c +1 -1
@@ -40,7 +40,7 @@ static void __mctp_sock_test_init(struct kunit *test,kfree (addrs); - rt =mctp_test_create_route (dev_net (dev->ndev), dev->mdev,9 ,0 ); + rt =mctp_test_create_route_direct (dev_net (dev->ndev), dev->mdev,9 ,0 );KUNIT_ASSERT_NOT_ERR_OR_NULL (test, rt); rc =sock_create_kern (&init_net,AF_MCTP ,SOCK_DGRAM ,0 , &sock);
net/mctp/test/utils.c +29 -4
@@ -119,10 +119,10 @@ static struct mctp_test_route *mctp_route_test_alloc(void)return rt; } -struct mctp_test_route *mctp_test_create_route (struct net *net, -struct mctp_dev *dev, -mctp_eid_t eid, -unsigned int mtu) +struct mctp_test_route *mctp_test_create_route_direct (struct net *net, +struct mctp_dev *dev, +mctp_eid_t eid, +unsigned int mtu) {struct mctp_test_route *rt;
@@ -144,6 +144,31 @@ struct mctp_test_route *mctp_test_create_route(struct net *net,return rt; } +struct mctp_test_route *mctp_test_create_route_gw (struct net *net, +unsigned int netid, +mctp_eid_t eid, +mctp_eid_t gw, +unsigned int mtu) +{ +struct mctp_test_route *rt; + + rt =mctp_route_test_alloc (); +if (!rt) +return NULL ; + + rt->rt.min = eid; + rt->rt.max = eid; + rt->rt.mtu = mtu; + rt->rt.type =RTN_UNSPEC ; + rt->rt.dst_type =MCTP_ROUTE_GATEWAY ; + rt->rt.gateway.eid = gw; + rt->rt.gateway.net = netid; + +list_add_rcu (&rt->rt.list, &net->mctp.routes); + +return rt; +} +/* Convenience function for our test dst; release with mctp_test_dst_release() */ void mctp_test_dst_setup(struct kunit *test, struct mctp_dst *dst,
net/mctp/test/utils.h +9 -4
@@ -36,10 +36,15 @@ struct mctp_test_dev *mctp_test_create_dev_lladdr(unsigned short lladdr_len, const unsigned char *lladdr);void mctp_test_destroy_dev (struct mctp_test_dev *dev); -struct mctp_test_route *mctp_test_create_route (struct net *net, -struct mctp_dev *dev, -mctp_eid_t eid, -unsigned int mtu); +struct mctp_test_route *mctp_test_create_route_direct (struct net *net, +struct mctp_dev *dev, +mctp_eid_t eid, +unsigned int mtu); +struct mctp_test_route *mctp_test_create_route_gw (struct net *net, +unsigned int netid, +mctp_eid_t eid, +mctp_eid_t gw, +unsigned int mtu);void mctp_test_dst_setup (struct kunit *test,struct mctp_dst *dst,struct mctp_test_dev *dev,struct mctp_test_pktqueue *tpq,unsigned int mtu);
Signature · 1 line
2.39.5
kernel test robot
build botRe: [PATCH net-next v2 02/13] net: mctp: separate routing database from routing operations
In reply to Jeremy Kerrkernel test robot noticed the following build warnings:
Hi Jeremy,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 0097c4195b1d0ca57d15979626c769c74747b5a0]
url: https://github.com/intel-lab-lkp/linux/commits/Jeremy-Kerr/net-mctp-don-t-use-source-cb-data-when-forwarding-ensure-pkt_type-is-set/20250619-160339 base: 0097c4195b1d0ca57d15979626c769c74747b5a0 patch link: https://lore.kernel.org/r/20250619-dev-forwarding-v2-2-3f81801b06c2%40codeconstruct.com.au patch subject: [PATCH net-next v2 02/13] net: mctp: separate routing database from routing operations config: s390-allyesconfig (https://download.01.org/0day-ci/archive/20250624/[email protected]/config) compiler: s390-linux-gcc (GCC) 15.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250624/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from net/mctp/route.c:1554:
net/mctp/test/route-test.c: In function 'mctp_test_route_input_cloned_frag':
>> net/mctp/test/route-test.c:1091:1: warning: the frame size of 1152 bytes is larger than 1024 bytes [-Wframe-larger-than=]
1091 | }
| ^vim +1091 net/mctp/test/route-test.c
ce1219c3f76bb1 Jeremy Kerr 2024-12-18 983
f5d83cf0eeb90f Matt Johnston 2025-03-06 984 /* Input route to socket, using a fragmented message created from clones.
f5d83cf0eeb90f Matt Johnston 2025-03-06 985 */
f5d83cf0eeb90f Matt Johnston 2025-03-06 986 static void mctp_test_route_input_cloned_frag(struct kunit *test)
f5d83cf0eeb90f Matt Johnston 2025-03-06 987 {
f5d83cf0eeb90f Matt Johnston 2025-03-06 988 /* 5 packet fragments, forming 2 complete messages */
f5d83cf0eeb90f Matt Johnston 2025-03-06 989 const struct mctp_hdr hdrs[5] = {
f5d83cf0eeb90f Matt Johnston 2025-03-06 990 RX_FRAG(FL_S, 0),
f5d83cf0eeb90f Matt Johnston 2025-03-06 991 RX_FRAG(0, 1),
f5d83cf0eeb90f Matt Johnston 2025-03-06 992 RX_FRAG(FL_E, 2),
f5d83cf0eeb90f Matt Johnston 2025-03-06 993 RX_FRAG(FL_S, 0),
f5d83cf0eeb90f Matt Johnston 2025-03-06 994 RX_FRAG(FL_E, 1),
f5d83cf0eeb90f Matt Johnston 2025-03-06 995 };
fb025ae64bd1f2 Jeremy Kerr 2025-06-19 996 struct mctp_test_pktqueue tpq;
f5d83cf0eeb90f Matt Johnston 2025-03-06 997 struct mctp_test_dev *dev;
f5d83cf0eeb90f Matt Johnston 2025-03-06 998 struct sk_buff *skb[5];
f5d83cf0eeb90f Matt Johnston 2025-03-06 999 struct sk_buff *rx_skb;
fb025ae64bd1f2 Jeremy Kerr 2025-06-19 1000 struct mctp_dst dst;
f5d83cf0eeb90f Matt Johnston 2025-03-06 1001 struct socket *sock;
f5d83cf0eeb90f Matt Johnston 2025-03-06 1002 size_t data_len;
f5d83cf0eeb90f Matt Johnston 2025-03-06 1003 u8 compare[100];
f5d83cf0eeb90f Matt Johnston 2025-03-06 1004 u8 flat[100];
f5d83cf0eeb90f Matt Johnston 2025-03-06 1005 size_t total;
f5d83cf0eeb90f Matt Johnston 2025-03-06 1006 void *p;
f5d83cf0eeb90f Matt Johnston 2025-03-06 1007 int rc;
f5d83cf0eeb90f Matt Johnston 2025-03-06 1008
f5d83cf0eeb90f Matt Johnston 2025-03-06 1009 /* Arbitrary length */
f5d83cf0eeb90f Matt Johnston 2025-03-06 1010 data_len = 3;
f5d83cf0eeb90f Matt Johnston 2025-03-06 1011 total = data_len + sizeof(struct mctp_hdr);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1012
fb025ae64bd1f2 Jeremy Kerr 2025-06-19 1013 __mctp_route_test_init(test, &dev, &dst, &tpq, &sock, MCTP_NET_ANY);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1014
f5d83cf0eeb90f Matt Johnston 2025-03-06 1015 /* Create a single skb initially with concatenated packets */
f5d83cf0eeb90f Matt Johnston 2025-03-06 1016 skb[0] = mctp_test_create_skb(&hdrs[0], 5 * total);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1017 mctp_test_skb_set_dev(skb[0], dev);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1018 memset(skb[0]->data, 0 * 0x11, skb[0]->len);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1019 memcpy(skb[0]->data, &hdrs[0], sizeof(struct mctp_hdr));
f5d83cf0eeb90f Matt Johnston 2025-03-06 1020
f5d83cf0eeb90f Matt Johnston 2025-03-06 1021 /* Extract and populate packets */
f5d83cf0eeb90f Matt Johnston 2025-03-06 1022 for (int i = 1; i < 5; i++) {
f5d83cf0eeb90f Matt Johnston 2025-03-06 1023 skb[i] = skb_clone(skb[i - 1], GFP_ATOMIC);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1024 KUNIT_ASSERT_TRUE(test, skb[i]);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1025 p = skb_pull(skb[i], total);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1026 KUNIT_ASSERT_TRUE(test, p);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1027 skb_reset_network_header(skb[i]);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1028 memcpy(skb[i]->data, &hdrs[i], sizeof(struct mctp_hdr));
f5d83cf0eeb90f Matt Johnston 2025-03-06 1029 memset(&skb[i]->data[sizeof(struct mctp_hdr)], i * 0x11, data_len);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1030 }
f5d83cf0eeb90f Matt Johnston 2025-03-06 1031 for (int i = 0; i < 5; i++)
f5d83cf0eeb90f Matt Johnston 2025-03-06 1032 skb_trim(skb[i], total);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1033
f5d83cf0eeb90f Matt Johnston 2025-03-06 1034 /* SOM packets have a type byte to match the socket */
f5d83cf0eeb90f Matt Johnston 2025-03-06 1035 skb[0]->data[4] = 0;
f5d83cf0eeb90f Matt Johnston 2025-03-06 1036 skb[3]->data[4] = 0;
f5d83cf0eeb90f Matt Johnston 2025-03-06 1037
f5d83cf0eeb90f Matt Johnston 2025-03-06 1038 skb_dump("pkt1 ", skb[0], false);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1039 skb_dump("pkt2 ", skb[1], false);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1040 skb_dump("pkt3 ", skb[2], false);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1041 skb_dump("pkt4 ", skb[3], false);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1042 skb_dump("pkt5 ", skb[4], false);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1043
f5d83cf0eeb90f Matt Johnston 2025-03-06 1044 for (int i = 0; i < 5; i++) {
f5d83cf0eeb90f Matt Johnston 2025-03-06 1045 KUNIT_EXPECT_EQ(test, refcount_read(&skb[i]->users), 1);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1046 /* Take a reference so we can check refcounts at the end */
f5d83cf0eeb90f Matt Johnston 2025-03-06 1047 skb_get(skb[i]);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1048 }
f5d83cf0eeb90f Matt Johnston 2025-03-06 1049
f5d83cf0eeb90f Matt Johnston 2025-03-06 1050 /* Feed the fragments into MCTP core */
f5d83cf0eeb90f Matt Johnston 2025-03-06 1051 for (int i = 0; i < 5; i++) {
fb025ae64bd1f2 Jeremy Kerr 2025-06-19 1052 rc = mctp_dst_input(&dst, skb[i]);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1053 KUNIT_EXPECT_EQ(test, rc, 0);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1054 }
f5d83cf0eeb90f Matt Johnston 2025-03-06 1055
f5d83cf0eeb90f Matt Johnston 2025-03-06 1056 /* Receive first reassembled message */
f5d83cf0eeb90f Matt Johnston 2025-03-06 1057 rx_skb = skb_recv_datagram(sock->sk, MSG_DONTWAIT, &rc);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1058 KUNIT_EXPECT_EQ(test, rc, 0);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1059 KUNIT_EXPECT_EQ(test, rx_skb->len, 3 * data_len);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1060 rc = skb_copy_bits(rx_skb, 0, flat, rx_skb->len);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1061 for (int i = 0; i < rx_skb->len; i++)
f5d83cf0eeb90f Matt Johnston 2025-03-06 1062 compare[i] = (i / data_len) * 0x11;
f5d83cf0eeb90f Matt Johnston 2025-03-06 1063 /* Set type byte */
f5d83cf0eeb90f Matt Johnston 2025-03-06 1064 compare[0] = 0;
f5d83cf0eeb90f Matt Johnston 2025-03-06 1065
f5d83cf0eeb90f Matt Johnston 2025-03-06 1066 KUNIT_EXPECT_MEMEQ(test, flat, compare, rx_skb->len);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1067 KUNIT_EXPECT_EQ(test, refcount_read(&rx_skb->users), 1);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1068 kfree_skb(rx_skb);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1069
f5d83cf0eeb90f Matt Johnston 2025-03-06 1070 /* Receive second reassembled message */
f5d83cf0eeb90f Matt Johnston 2025-03-06 1071 rx_skb = skb_recv_datagram(sock->sk, MSG_DONTWAIT, &rc);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1072 KUNIT_EXPECT_EQ(test, rc, 0);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1073 KUNIT_EXPECT_EQ(test, rx_skb->len, 2 * data_len);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1074 rc = skb_copy_bits(rx_skb, 0, flat, rx_skb->len);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1075 for (int i = 0; i < rx_skb->len; i++)
f5d83cf0eeb90f Matt Johnston 2025-03-06 1076 compare[i] = (i / data_len + 3) * 0x11;
f5d83cf0eeb90f Matt Johnston 2025-03-06 1077 /* Set type byte */
f5d83cf0eeb90f Matt Johnston 2025-03-06 1078 compare[0] = 0;
f5d83cf0eeb90f Matt Johnston 2025-03-06 1079
f5d83cf0eeb90f Matt Johnston 2025-03-06 1080 KUNIT_EXPECT_MEMEQ(test, flat, compare, rx_skb->len);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1081 KUNIT_EXPECT_EQ(test, refcount_read(&rx_skb->users), 1);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1082 kfree_skb(rx_skb);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1083
f5d83cf0eeb90f Matt Johnston 2025-03-06 1084 /* Check input skb refcounts */
f5d83cf0eeb90f Matt Johnston 2025-03-06 1085 for (int i = 0; i < 5; i++) {
f5d83cf0eeb90f Matt Johnston 2025-03-06 1086 KUNIT_EXPECT_EQ(test, refcount_read(&skb[i]->users), 1);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1087 kfree_skb(skb[i]);
f5d83cf0eeb90f Matt Johnston 2025-03-06 1088 }
f5d83cf0eeb90f Matt Johnston 2025-03-06 1089
fb025ae64bd1f2 Jeremy Kerr 2025-06-19 1090 __mctp_route_test_fini(test, dev, &dst, &tpq, sock);f5d83cf0eeb90f Matt Johnston 2025-03-06 @1091 }f5d83cf0eeb90f Matt Johnston 2025-03-06 1092
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki