1 /* $Id$
2  * --------------------------------------------------------------------------
3  *
4  *           //=====   //===== ===//=== //===//  //       //   //===//
5  *          //        //         //    //    // //       //   //    //
6  *         //====//  //         //    //===//  //       //   //===<<
7  *              //  //         //    //       //       //   //    //
8  *       ======//  //=====    //    //       //=====  //   //===//
9  *
10  * -------------- An SCTP implementation according to RFC 4960 --------------
11  *
12  * Copyright (C) 2000 by Siemens AG, Munich, Germany.
13  * Copyright (C) 2001-2004 Andreas Jungmaier
14  * Copyright (C) 2004-2019 Thomas Dreibholz
15  *
16  * Acknowledgements:
17  * Realized in co-operation between Siemens AG and the University of
18  * Duisburg-Essen, Institute for Experimental Mathematics, Computer
19  * Networking Technology group.
20  * This work was partially funded by the Bundesministerium fuer Bildung und
21  * Forschung (BMBF) of the Federal Republic of Germany
22  * (Förderkennzeichen 01AK045).
23  * The authors alone are responsible for the contents.
24  *
25  * This library is free software: you can redistribute it and/or modify it
26  * under the terms of the GNU Lesser General Public License as published by
27  * the Free Software Foundation, either version 2.1 of the License, or
28  * (at your option) any later version.
29  *
30  * This library is distributed in the hope that it will be useful,
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33  * GNU General Public License for more details.
34  *
35  * You should have received a copy of the GNU Lesser General Public License
36  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
37  *
38  * Contact: sctp-discussion@sctp.de
39  *          dreibh@iem.uni-due.de
40  *          tuexen@fh-muenster.de
41  *          andreas.jungmaier@web.de
42  */
43 
44 #ifndef BUNDLING_H
45 #define BUNDLING_H
46 
47 
48 #include "globals.h"            /* for chunk struct definition */
49 #include "SCTP-control.h"
50 #include "pathmanagement.h"
51 
52 void bu_init_bundling(void);
53 gint bu_put_Ctrl_Chunk(SCTP_simple_chunk * chunk,unsigned int * dest_index);
54 gint bu_put_Data_Chunk(SCTP_simple_chunk * chunk,unsigned int * dest_index);
55 
56 
57 /*
58  * bu_new: Creates a new bundling instance and returns a pointer to its data.
59  */
60 gpointer bu_new(void);
61 
62 /*
63  * bu_delete: Deletes a bundling instance
64  *
65  * Params: Pointer/handle which was returned by bu_new()
66  */
67 void bu_delete(gpointer instancePtr);
68 
69 /**
70  * returns a value indicating which chunks are in the packet.
71  */
72 unsigned int rbu_scanPDU(guchar * pdu, guint len);
73 
74 /*
75  * rbu_datagramContains: looks for chunk_type in a newly received datagram
76  * Should be called after rbu_scanPDU().
77  * The chunkArray parameter is inspected. This only really checks for chunks
78  * with an ID <= 30. For all other chunks, it just guesses...
79  * @return true is chunk_type exists in chunkArray, false if it is not in there
80  */
81 gboolean rbu_datagramContains(gushort chunk_type, unsigned int chunkArray);
82 
83 guchar* rbu_scanInitChunkForParameter(guchar * chunk, gushort paramType);
84 
85 /*
86  * rbu_findChunk: looks for chunk_type in a newly received datagram
87  *
88  * All chunks within the datagram are looked at, until one is found
89  * that equals the parameter chunk_type.
90  * @return pointer to first chunk of chunk_type in SCTP datagram, else NULL
91  */
92 guchar* rbu_findChunk(guchar * datagram, guint len, gushort chunk_type);
93 
94 /*
95  * rbu_scanDatagramForError : looks for Error chunk_type in a newly received datagram
96  * that contains a special error cause code
97  *
98  * All chunks within the datagram are lookes at, until one is found
99  * that equals the parameter chunk_type.
100  * @return true is chunk_type exists in SCTP datagram, false if it is not in there
101  */
102 gboolean rbu_scanDatagramForError(guchar * datagram, guint len, gushort error_cause);
103 
104 /*
105  * rbu_findAddress: looks for address type parameters in INIT or INIT-ACKs
106  * All parameters within the chunk are looked at, and the n-th supported address is
107  * copied into the provided buffer pointed to by the foundAddress parameter.
108  * If there are less than n addresses, an appropriate error is
109  * returned. n should be at least 1, of course.
110  * @param  chunk            pointer to an INIT or INIT ACK chunk
111  * @param  n                get the n-th address
112  * @param  foundAddress     pointer to a buffer where an address, if found, will be copied
113  * @return -1  for parameter problem, 0 for success (i.e. address found), 1 if there are not
114  *             that many addresses in the chunk.
115  */
116 gint rbu_findAddress(guchar * chunk, guint n, union sockunion* foundAddress, int supportedAddressTypes);
117 
118 /*
119  * rbu_rcvDatagram: Hands a lower layer datagram over to bundling (for de-bundling)
120  *
121  * All chunks within the datagram are dispatched and sent to the appropriate
122  * module, i.e.: control chunks are sent to sctp_control/pathmanagement,
123  * SACK chunks to reliable_transfer, and data_chunks to RX_control.
124  * Those modules must get a pointer to the start of a chunk and
125  * information about its size (without padding).
126  */
127 gint rbu_rcvDatagram(guint address_index, guchar * datagram, guint len);
128 
129 
130 void bu_lock_sender(void);
131 void bu_unlock_sender(guint* ad_idx);
132 gboolean bu_userDataOutbound(void);
133 
134 /**
135  * bu_put_SACK_Chunk: Called by recvcontrol, when a SACK must be piggy-backed
136  *
137  * @param chunk pointer to chunk, that is to be put in the bundling buffer
138  * @return error value, 0 on success, -1 on error
139  */
140 gint bu_put_SACK_Chunk(SCTP_sack_chunk * chunk, unsigned int* dest_index);
141 
142 
143 /*
144  * bu_sendAllChunks: Trigger to send all chunks previously entered with putChunk.
145  *
146  * Return value: error value
147  * Chunks sent are deleted afterwards.
148  */
149 gint bu_sendAllChunks(guint * ad_idx);
150 
151 void bu_request_sack(void);
152 
153 #endif
154