1111
1212#include <linux/bits.h>
1313#include <linux/mctp.h>
14+ #include <net/net_namespace.h>
1415
1516/* MCTP packet definitions */
1617struct mctp_hdr {
@@ -33,6 +34,8 @@ struct mctp_hdr {
3334#define MCTP_HDR_TAG_SHIFT 0
3435#define MCTP_HDR_TAG_MASK GENMASK(2, 0)
3536
37+ #define MCTP_HEADER_MAXLEN 4
38+
3639static inline bool mctp_address_ok (mctp_eid_t eid )
3740{
3841 return eid >= 8 && eid < 255 ;
@@ -43,6 +46,78 @@ static inline struct mctp_hdr *mctp_hdr(struct sk_buff *skb)
4346 return (struct mctp_hdr * )skb_network_header (skb );
4447}
4548
49+ struct 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+ */
64+ static 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+
72+ static 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+ */
91+ struct 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 */
105+ struct mctp_route * mctp_route_lookup (struct net * net , unsigned int dnet ,
106+ mctp_eid_t daddr );
107+
108+ int mctp_do_route (struct mctp_route * rt , struct sk_buff * skb );
109+
110+ int 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 */
114+ int mctp_route_add_local (struct mctp_dev * mdev , mctp_eid_t addr );
115+ int mctp_route_remove_local (struct mctp_dev * mdev , mctp_eid_t addr );
116+ void mctp_route_remove_dev (struct mctp_dev * mdev );
117+
118+ int mctp_routes_init (void );
119+ void mctp_routes_exit (void );
120+
46121void mctp_device_init (void );
47122void mctp_device_exit (void );
48123
0 commit comments