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