Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 583be98

Browse files
jk-ozlabsdavem330
authored andcommitted
mctp: Add device handling and netlink interface
This change adds the infrastructure for managing MCTP netdevices; we add a pointer to the AF_MCTP-specific data to struct netdevice, and hook up the rtnetlink operations for adding and removing addresses. Includes changes from Matt Johnston <[email protected]>. Signed-off-by: Jeremy Kerr <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4b2e693 commit 583be98

File tree

10 files changed

+491
-1
lines changed

10 files changed

+491
-1
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11039,6 +11039,7 @@ L: [email protected]
1103911039
S: Maintained
1104011040
F: drivers/net/mctp/
1104111041
F: include/net/mctp.h
11042+
F: include/net/mctpdevice.h
1104211043
F: net/mctp/
1104311044

1104411045
MAN-PAGES: MANUAL PAGES FOR LINUX -- Sections 2, 3, 4, 5, and 7

include/linux/netdevice.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,7 @@ enum netdev_ml_priv_type {
18231823
* @ieee802154_ptr: IEEE 802.15.4 low-rate Wireless Personal Area Network
18241824
* device struct
18251825
* @mpls_ptr: mpls_dev struct pointer
1826+
* @mctp_ptr: MCTP specific data
18261827
*
18271828
* @dev_addr: Hw address (before bcast,
18281829
* because most packets are unicast)
@@ -2110,6 +2111,9 @@ struct net_device {
21102111
#if IS_ENABLED(CONFIG_MPLS_ROUTING)
21112112
struct mpls_dev __rcu *mpls_ptr;
21122113
#endif
2114+
#if IS_ENABLED(CONFIG_MCTP)
2115+
struct mctp_dev __rcu *mctp_ptr;
2116+
#endif
21132117

21142118
/*
21152119
* Cache lines mostly used on receive path (including eth_type_trans())

include/net/mctp.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define __NET_MCTP_H
1111

1212
#include <linux/bits.h>
13+
#include <linux/mctp.h>
1314

1415
/* MCTP packet definitions */
1516
struct mctp_hdr {
@@ -32,4 +33,17 @@ struct mctp_hdr {
3233
#define MCTP_HDR_TAG_SHIFT 0
3334
#define MCTP_HDR_TAG_MASK GENMASK(2, 0)
3435

36+
static inline bool mctp_address_ok(mctp_eid_t eid)
37+
{
38+
return eid >= 8 && eid < 255;
39+
}
40+
41+
static inline struct mctp_hdr *mctp_hdr(struct sk_buff *skb)
42+
{
43+
return (struct mctp_hdr *)skb_network_header(skb);
44+
}
45+
46+
void mctp_device_init(void);
47+
void mctp_device_exit(void);
48+
3549
#endif /* __NET_MCTP_H */

include/net/mctpdevice.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Management Component Transport Protocol (MCTP) - device
4+
* definitions.
5+
*
6+
* Copyright (c) 2021 Code Construct
7+
* Copyright (c) 2021 Google
8+
*/
9+
10+
#ifndef __NET_MCTPDEVICE_H
11+
#define __NET_MCTPDEVICE_H
12+
13+
#include <linux/list.h>
14+
#include <linux/types.h>
15+
#include <linux/refcount.h>
16+
17+
struct mctp_dev {
18+
struct net_device *dev;
19+
20+
unsigned int net;
21+
22+
/* Only modified under RTNL. Reads have addrs_lock held */
23+
u8 *addrs;
24+
size_t num_addrs;
25+
spinlock_t addrs_lock;
26+
27+
struct rcu_head rcu;
28+
};
29+
30+
#define MCTP_INITIAL_DEFAULT_NET 1
31+
32+
struct mctp_dev *mctp_dev_get_rtnl(const struct net_device *dev);
33+
struct mctp_dev *__mctp_dev_get(const struct net_device *dev);
34+
35+
#endif /* __NET_MCTPDEVICE_H */

include/uapi/linux/if_ether.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@
151151
#define ETH_P_MAP 0x00F9 /* Qualcomm multiplexing and
152152
* aggregation protocol
153153
*/
154+
#define ETH_P_MCTP 0x00FA /* Management component transport
155+
* protocol packets
156+
*/
154157

155158
/*
156159
* This is an Ethernet frame header.

include/uapi/linux/if_link.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,4 +1260,14 @@ struct ifla_rmnet_flags {
12601260
__u32 mask;
12611261
};
12621262

1263+
/* MCTP section */
1264+
1265+
enum {
1266+
IFLA_MCTP_UNSPEC,
1267+
IFLA_MCTP_NET,
1268+
__IFLA_MCTP_MAX,
1269+
};
1270+
1271+
#define IFLA_MCTP_MAX (__IFLA_MCTP_MAX - 1)
1272+
12631273
#endif /* _UAPI_LINUX_IF_LINK_H */

include/uapi/linux/mctp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct sockaddr_mctp {
2626
};
2727

2828
#define MCTP_NET_ANY 0x0
29+
#define MCTP_NET_DEFAULT 0x0
2930

3031
#define MCTP_ADDR_NULL 0x00
3132
#define MCTP_ADDR_ANY 0xff

net/mctp/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# SPDX-License-Identifier: GPL-2.0
22
obj-$(CONFIG_MCTP) += mctp.o
3-
mctp-objs := af_mctp.o
3+
mctp-objs := af_mctp.o device.o

net/mctp/af_mctp.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
* Copyright (c) 2021 Google
77
*/
88

9+
#include <linux/if_arp.h>
910
#include <linux/net.h>
1011
#include <linux/mctp.h>
1112
#include <linux/module.h>
1213
#include <linux/socket.h>
1314

15+
#include <net/mctp.h>
16+
#include <net/mctpdevice.h>
1417
#include <net/sock.h>
1518

19+
/* socket implementation */
20+
1621
struct mctp_sock {
1722
struct sock sk;
1823
};
@@ -152,6 +157,8 @@ static __init int mctp_init(void)
152157
if (rc)
153158
goto err_unreg_sock;
154159

160+
mctp_device_init();
161+
155162
return 0;
156163

157164
err_unreg_sock:
@@ -162,6 +169,7 @@ static __init int mctp_init(void)
162169

163170
static __exit void mctp_exit(void)
164171
{
172+
mctp_device_exit();
165173
proto_unregister(&mctp_proto);
166174
sock_unregister(PF_MCTP);
167175
}

0 commit comments

Comments
 (0)