]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/net/mctp.h
mctp: Add neighbour netlink interface
[mirror_ubuntu-jammy-kernel.git] / include / net / mctp.h
CommitLineData
2c8e2e9a
JK
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Management Component Transport Protocol (MCTP)
4 *
5 * Copyright (c) 2021 Code Construct
6 * Copyright (c) 2021 Google
7 */
8
9#ifndef __NET_MCTP_H
10#define __NET_MCTP_H
11
12#include <linux/bits.h>
583be982 13#include <linux/mctp.h>
889b7da2 14#include <net/net_namespace.h>
2c8e2e9a
JK
15
16/* MCTP packet definitions */
17struct mctp_hdr {
18 u8 ver;
19 u8 dest;
20 u8 src;
21 u8 flags_seq_tag;
22};
23
24#define MCTP_VER_MIN 1
25#define MCTP_VER_MAX 1
26
27/* Definitions for flags_seq_tag field */
28#define MCTP_HDR_FLAG_SOM BIT(7)
29#define MCTP_HDR_FLAG_EOM BIT(6)
30#define MCTP_HDR_FLAG_TO BIT(3)
31#define MCTP_HDR_FLAGS GENMASK(5, 3)
32#define MCTP_HDR_SEQ_SHIFT 4
33#define MCTP_HDR_SEQ_MASK GENMASK(1, 0)
34#define MCTP_HDR_TAG_SHIFT 0
35#define MCTP_HDR_TAG_MASK GENMASK(2, 0)
36
889b7da2
JK
37#define MCTP_HEADER_MAXLEN 4
38
583be982
JK
39static inline bool mctp_address_ok(mctp_eid_t eid)
40{
41 return eid >= 8 && eid < 255;
42}
43
44static inline struct mctp_hdr *mctp_hdr(struct sk_buff *skb)
45{
46 return (struct mctp_hdr *)skb_network_header(skb);
47}
48
889b7da2
JK
49struct mctp_skb_cb {
50 unsigned int magic;
51 unsigned int net;
52 mctp_eid_t src;
53};
54
55/* skb control-block accessors with a little extra debugging for initial
56 * development.
57 *
58 * TODO: remove checks & mctp_skb_cb->magic; replace callers of __mctp_cb
59 * with mctp_cb().
60 *
61 * __mctp_cb() is only for the initial ingress code; we should see ->magic set
62 * at all times after this.
63 */
64static inline struct mctp_skb_cb *__mctp_cb(struct sk_buff *skb)
65{
66 struct mctp_skb_cb *cb = (void *)skb->cb;
67
68 cb->magic = 0x4d435450;
69 return cb;
70}
71
72static inline struct mctp_skb_cb *mctp_cb(struct sk_buff *skb)
73{
74 struct mctp_skb_cb *cb = (void *)skb->cb;
75
76 WARN_ON(cb->magic != 0x4d435450);
77 return (void *)(skb->cb);
78}
79
80/* Route definition.
81 *
82 * These are held in the pernet->mctp.routes list, with RCU protection for
83 * removed routes. We hold a reference to the netdev; routes need to be
84 * dropped on NETDEV_UNREGISTER events.
85 *
86 * Updates to the route table are performed under rtnl; all reads under RCU,
87 * so routes cannot be referenced over a RCU grace period. Specifically: A
88 * caller cannot block between mctp_route_lookup and passing the route to
89 * mctp_do_route.
90 */
91struct mctp_route {
92 mctp_eid_t min, max;
93
94 struct mctp_dev *dev;
95 unsigned int mtu;
96 int (*output)(struct mctp_route *route,
97 struct sk_buff *skb);
98
99 struct list_head list;
100 refcount_t refs;
101 struct rcu_head rcu;
102};
103
104/* route interfaces */
105struct mctp_route *mctp_route_lookup(struct net *net, unsigned int dnet,
106 mctp_eid_t daddr);
107
108int mctp_do_route(struct mctp_route *rt, struct sk_buff *skb);
109
110int mctp_local_output(struct sock *sk, struct mctp_route *rt,
111 struct sk_buff *skb, mctp_eid_t daddr, u8 req_tag);
112
113/* routing <--> device interface */
06d2f4c5
MJ
114unsigned int mctp_default_net(struct net *net);
115int mctp_default_net_set(struct net *net, unsigned int index);
889b7da2
JK
116int mctp_route_add_local(struct mctp_dev *mdev, mctp_eid_t addr);
117int mctp_route_remove_local(struct mctp_dev *mdev, mctp_eid_t addr);
118void mctp_route_remove_dev(struct mctp_dev *mdev);
119
4d8b9319
MJ
120/* neighbour definitions */
121enum mctp_neigh_source {
122 MCTP_NEIGH_STATIC,
123 MCTP_NEIGH_DISCOVER,
124};
125
126struct mctp_neigh {
127 struct mctp_dev *dev;
128 mctp_eid_t eid;
129 enum mctp_neigh_source source;
130
131 unsigned char ha[MAX_ADDR_LEN];
132
133 struct list_head list;
134 struct rcu_head rcu;
135};
136
137int mctp_neigh_init(void);
138void mctp_neigh_exit(void);
139
140// ret_hwaddr may be NULL, otherwise must have space for MAX_ADDR_LEN
141int mctp_neigh_lookup(struct mctp_dev *dev, mctp_eid_t eid,
142 void *ret_hwaddr);
143void mctp_neigh_remove_dev(struct mctp_dev *mdev);
144
889b7da2
JK
145int mctp_routes_init(void);
146void mctp_routes_exit(void);
147
583be982
JK
148void mctp_device_init(void);
149void mctp_device_exit(void);
150
2c8e2e9a 151#endif /* __NET_MCTP_H */