xref: /OK3568_Linux_fs/kernel/include/net/sctp/ulpevent.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /* SCTP kernel implementation
3*4882a593Smuzhiyun  * (C) Copyright IBM Corp. 2001, 2004
4*4882a593Smuzhiyun  * Copyright (c) 1999-2000 Cisco, Inc.
5*4882a593Smuzhiyun  * Copyright (c) 1999-2001 Motorola, Inc.
6*4882a593Smuzhiyun  * Copyright (c) 2001 Intel Corp.
7*4882a593Smuzhiyun  * Copyright (c) 2001 Nokia, Inc.
8*4882a593Smuzhiyun  * Copyright (c) 2001 La Monte H.P. Yarroll
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * These are the definitions needed for the sctp_ulpevent type.  The
11*4882a593Smuzhiyun  * sctp_ulpevent type is used to carry information from the state machine
12*4882a593Smuzhiyun  * upwards to the ULP.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * This file is part of the SCTP kernel implementation
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * Please send any bug reports or fixes you make to the
17*4882a593Smuzhiyun  * email address(es):
18*4882a593Smuzhiyun  *    lksctp developers <linux-sctp@vger.kernel.org>
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * Written or modified by:
21*4882a593Smuzhiyun  *   Jon Grimm             <jgrimm@us.ibm.com>
22*4882a593Smuzhiyun  *   La Monte H.P. Yarroll <piggy@acm.org>
23*4882a593Smuzhiyun  *   Karl Knutson          <karl@athena.chicago.il.us>
24*4882a593Smuzhiyun  *   Sridhar Samudrala     <sri@us.ibm.com>
25*4882a593Smuzhiyun  */
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #ifndef __sctp_ulpevent_h__
28*4882a593Smuzhiyun #define __sctp_ulpevent_h__
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /* A structure to carry information to the ULP (e.g. Sockets API) */
31*4882a593Smuzhiyun /* Warning: This sits inside an skb.cb[] area.  Be very careful of
32*4882a593Smuzhiyun  * growing this structure as it is at the maximum limit now.
33*4882a593Smuzhiyun  *
34*4882a593Smuzhiyun  * sctp_ulpevent is saved in sk->cb(48 bytes), whose last 4 bytes
35*4882a593Smuzhiyun  * have been taken by sock_skb_cb, So here it has to use 'packed'
36*4882a593Smuzhiyun  * to make sctp_ulpevent fit into the rest 44 bytes.
37*4882a593Smuzhiyun  */
38*4882a593Smuzhiyun struct sctp_ulpevent {
39*4882a593Smuzhiyun 	struct sctp_association *asoc;
40*4882a593Smuzhiyun 	struct sctp_chunk *chunk;
41*4882a593Smuzhiyun 	unsigned int rmem_len;
42*4882a593Smuzhiyun 	union {
43*4882a593Smuzhiyun 		__u32 mid;
44*4882a593Smuzhiyun 		__u16 ssn;
45*4882a593Smuzhiyun 	};
46*4882a593Smuzhiyun 	union {
47*4882a593Smuzhiyun 		__u32 ppid;
48*4882a593Smuzhiyun 		__u32 fsn;
49*4882a593Smuzhiyun 	};
50*4882a593Smuzhiyun 	__u32 tsn;
51*4882a593Smuzhiyun 	__u32 cumtsn;
52*4882a593Smuzhiyun 	__u16 stream;
53*4882a593Smuzhiyun 	__u16 flags;
54*4882a593Smuzhiyun 	__u16 msg_flags;
55*4882a593Smuzhiyun } __packed;
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun /* Retrieve the skb this event sits inside of. */
sctp_event2skb(const struct sctp_ulpevent * ev)58*4882a593Smuzhiyun static inline struct sk_buff *sctp_event2skb(const struct sctp_ulpevent *ev)
59*4882a593Smuzhiyun {
60*4882a593Smuzhiyun 	return container_of((void *)ev, struct sk_buff, cb);
61*4882a593Smuzhiyun }
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /* Retrieve & cast the event sitting inside the skb. */
sctp_skb2event(struct sk_buff * skb)64*4882a593Smuzhiyun static inline struct sctp_ulpevent *sctp_skb2event(struct sk_buff *skb)
65*4882a593Smuzhiyun {
66*4882a593Smuzhiyun 	return (struct sctp_ulpevent *)skb->cb;
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun void sctp_ulpevent_free(struct sctp_ulpevent *);
70*4882a593Smuzhiyun int sctp_ulpevent_is_notification(const struct sctp_ulpevent *);
71*4882a593Smuzhiyun unsigned int sctp_queue_purge_ulpevents(struct sk_buff_head *list);
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun struct sctp_ulpevent *sctp_ulpevent_make_assoc_change(
74*4882a593Smuzhiyun 	const struct sctp_association *asoc,
75*4882a593Smuzhiyun 	__u16 flags,
76*4882a593Smuzhiyun 	__u16 state,
77*4882a593Smuzhiyun 	__u16 error,
78*4882a593Smuzhiyun 	__u16 outbound,
79*4882a593Smuzhiyun 	__u16 inbound,
80*4882a593Smuzhiyun 	struct sctp_chunk *chunk,
81*4882a593Smuzhiyun 	gfp_t gfp);
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun void sctp_ulpevent_notify_peer_addr_change(struct sctp_transport *transport,
84*4882a593Smuzhiyun 					   int state, int error);
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun struct sctp_ulpevent *sctp_ulpevent_make_remote_error(
87*4882a593Smuzhiyun 	const struct sctp_association *asoc,
88*4882a593Smuzhiyun 	struct sctp_chunk *chunk,
89*4882a593Smuzhiyun 	__u16 flags,
90*4882a593Smuzhiyun 	gfp_t gfp);
91*4882a593Smuzhiyun struct sctp_ulpevent *sctp_ulpevent_make_send_failed(
92*4882a593Smuzhiyun 	const struct sctp_association *asoc,
93*4882a593Smuzhiyun 	struct sctp_chunk *chunk,
94*4882a593Smuzhiyun 	__u16 flags,
95*4882a593Smuzhiyun 	__u32 error,
96*4882a593Smuzhiyun 	gfp_t gfp);
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun struct sctp_ulpevent *sctp_ulpevent_make_send_failed_event(
99*4882a593Smuzhiyun 	const struct sctp_association *asoc,
100*4882a593Smuzhiyun 	struct sctp_chunk *chunk,
101*4882a593Smuzhiyun 	__u16 flags,
102*4882a593Smuzhiyun 	__u32 error,
103*4882a593Smuzhiyun 	gfp_t gfp);
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event(
106*4882a593Smuzhiyun 	const struct sctp_association *asoc,
107*4882a593Smuzhiyun 	__u16 flags,
108*4882a593Smuzhiyun 	gfp_t gfp);
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun struct sctp_ulpevent *sctp_ulpevent_make_pdapi(
111*4882a593Smuzhiyun 	const struct sctp_association *asoc,
112*4882a593Smuzhiyun 	__u32 indication, __u32 sid, __u32 seq,
113*4882a593Smuzhiyun 	__u32 flags, gfp_t gfp);
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun struct sctp_ulpevent *sctp_ulpevent_make_adaptation_indication(
116*4882a593Smuzhiyun 	const struct sctp_association *asoc, gfp_t gfp);
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
119*4882a593Smuzhiyun 	struct sctp_chunk *chunk,
120*4882a593Smuzhiyun 	gfp_t gfp);
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun struct sctp_ulpevent *sctp_ulpevent_make_authkey(
123*4882a593Smuzhiyun 	const struct sctp_association *asoc, __u16 key_id,
124*4882a593Smuzhiyun 	__u32 indication, gfp_t gfp);
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun struct sctp_ulpevent *sctp_ulpevent_make_sender_dry_event(
127*4882a593Smuzhiyun 	const struct sctp_association *asoc, gfp_t gfp);
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun struct sctp_ulpevent *sctp_ulpevent_make_stream_reset_event(
130*4882a593Smuzhiyun 	const struct sctp_association *asoc, __u16 flags,
131*4882a593Smuzhiyun 	__u16 stream_num, __be16 *stream_list, gfp_t gfp);
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun struct sctp_ulpevent *sctp_ulpevent_make_assoc_reset_event(
134*4882a593Smuzhiyun 	const struct sctp_association *asoc, __u16 flags,
135*4882a593Smuzhiyun 	 __u32 local_tsn, __u32 remote_tsn, gfp_t gfp);
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun struct sctp_ulpevent *sctp_ulpevent_make_stream_change_event(
138*4882a593Smuzhiyun 	const struct sctp_association *asoc, __u16 flags,
139*4882a593Smuzhiyun 	__u32 strchange_instrms, __u32 strchange_outstrms, gfp_t gfp);
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun struct sctp_ulpevent *sctp_make_reassembled_event(
142*4882a593Smuzhiyun 	struct net *net, struct sk_buff_head *queue,
143*4882a593Smuzhiyun 	struct sk_buff *f_frag, struct sk_buff *l_frag);
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event,
146*4882a593Smuzhiyun 				   struct msghdr *);
147*4882a593Smuzhiyun void sctp_ulpevent_read_rcvinfo(const struct sctp_ulpevent *event,
148*4882a593Smuzhiyun 				struct msghdr *);
149*4882a593Smuzhiyun void sctp_ulpevent_read_nxtinfo(const struct sctp_ulpevent *event,
150*4882a593Smuzhiyun 				struct msghdr *, struct sock *sk);
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun __u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event);
153*4882a593Smuzhiyun 
sctp_ulpevent_type_set(__u16 * subscribe,__u16 sn_type,__u8 on)154*4882a593Smuzhiyun static inline void sctp_ulpevent_type_set(__u16 *subscribe,
155*4882a593Smuzhiyun 					  __u16 sn_type, __u8 on)
156*4882a593Smuzhiyun {
157*4882a593Smuzhiyun 	if (sn_type > SCTP_SN_TYPE_MAX)
158*4882a593Smuzhiyun 		return;
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun 	if (on)
161*4882a593Smuzhiyun 		*subscribe |=  (1 << (sn_type - SCTP_SN_TYPE_BASE));
162*4882a593Smuzhiyun 	else
163*4882a593Smuzhiyun 		*subscribe &= ~(1 << (sn_type - SCTP_SN_TYPE_BASE));
164*4882a593Smuzhiyun }
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun /* Is this event type enabled? */
sctp_ulpevent_type_enabled(__u16 subscribe,__u16 sn_type)167*4882a593Smuzhiyun static inline bool sctp_ulpevent_type_enabled(__u16 subscribe, __u16 sn_type)
168*4882a593Smuzhiyun {
169*4882a593Smuzhiyun 	if (sn_type > SCTP_SN_TYPE_MAX)
170*4882a593Smuzhiyun 		return false;
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun 	return subscribe & (1 << (sn_type - SCTP_SN_TYPE_BASE));
173*4882a593Smuzhiyun }
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun /* Given an event subscription, is this event enabled? */
sctp_ulpevent_is_enabled(const struct sctp_ulpevent * event,__u16 subscribe)176*4882a593Smuzhiyun static inline bool sctp_ulpevent_is_enabled(const struct sctp_ulpevent *event,
177*4882a593Smuzhiyun 					    __u16 subscribe)
178*4882a593Smuzhiyun {
179*4882a593Smuzhiyun 	__u16 sn_type;
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun 	if (!sctp_ulpevent_is_notification(event))
182*4882a593Smuzhiyun 		return true;
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun 	sn_type = sctp_ulpevent_get_notification_type(event);
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun 	return sctp_ulpevent_type_enabled(subscribe, sn_type);
187*4882a593Smuzhiyun }
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun #endif /* __sctp_ulpevent_h__ */
190