We no longer need _ldp_global_ifmgr_callback because
[mpls-ldp-portable.git] / doc / mpls_encdec_02.c
blob8de11f0256d7ae1ab32de76300a16c0ec577a72b
1 /******************************************************************************
2 * Nortel Networks Software License *
3 * *
4 * READ THE TERMS OF THIS LICENSE CAREFULLY. BY USING, MODIFYING, OR *
5 * DISTRIBUTING THIS SOFTWARE AND ANY ACCOMPANYING DOCUMENTATION (COLLECTIVELY,*
6 * "SOFTWARE") YOU ARE AGREEING TO ALL OF THE TERMS OF THIS LICENSE. *
7 * *
8 * 1. Nortel Telecom Limited, on behalf of itself and its subsidiaries *
9 * (collectively "Nortel Networks") grants to you a non-exclusive, perpetual, *
10 * world-wide right to use, copy, modify, and distribute the Software at no *
11 * charge. *
12 * *
13 * 2. You may sublicense recipients of redistributed Software to use, *
14 * copy, modify, and distribute the Software on substantially the same terms as*
15 * this License. You may not impose any further restrictions on the *
16 * recipient's exercise of the rights in the Software granted under this *
17 * License. Software distributed to other parties must be accompanied by a *
18 * License containing a grant, disclaimer and limitation of liability *
19 * substantially in the form of 3, 4, and 5 below provided that references to *
20 * "Nortel Networks" may be changed to "Supplier". *
21 * *
22 * 3. Nortel Networks reserves the right to modify and release new *
23 * versions of the Software from time to time which may include modifications *
24 * made by third parties like you. Accordingly, you agree that you shall *
25 * automatically grant a license to Nortel Networks to include, at its option, *
26 * in any new version of the Software any modifications to the Software made by*
27 * you and made available directly or indirectly to Nortel Networks. Nortel *
28 * Networks shall have the right to use, copy, modify, and distribute any such *
29 * modified Software on substantially the same terms as this License. *
30 * *
31 * 4. THE SOFTWARE IS PROVIDED ON AN "AS IS" BASIS. NORTEL NETWORKS AND *
32 * ITS AGENTS AND SUPPLIERS DISCLAIM ALL REPRESENTATIONS, WARRANTIES AND *
33 * CONDITIONS RELATING TO THE SOFTWARE, INCLUDING, BUT NOT LIMITED TO, IMPLIED *
34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
35 * NON-INFRINGEMENT OF THIRD-PARTY INTELLECTUAL PROPERTY RIGHTS. NORTEL *
36 * NETWORKS AND ITS AGENTS AND SUPPLIERS DO NOT WARRANT, GUARANTEE, OR MAKE ANY*
37 * REPRESENTATIONS REGARDING THE USE, OR THE RESULTS OF THE USE, OF THE *
38 * SOFTWARE IN TERMS OR CORRECTNESS, ACCURACY, RELIABILITY, CURRENTNESS, OR *
39 * OTHERWISE. *
40 * *
41 * 5. NEITHER NORTEL NETWORKS NOR ANY OF ITS AGENTS OR SUPPLIERS SHALL BE *
42 * LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR EXEMPLARY *
43 * DAMAGES, OR ECONOMIC LOSSES (INCLUDING DAMAGES FOR LOSS OF BUSINESS PROFITS,*
44 * BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION AND THE LIKE), ARISING *
45 * FROM THE SOFTWARE OR THIS LICENSE AGREEMENT, EVEN IF NORTEL NETWORKS OR SUCH*
46 * AGENT OR SUPPLIER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR *
47 * LOSSES, AND WHETHER ANY SUCH DAMAGE OR LOSS ARISES OUT OF CONTRACT, TORT, OR*
48 * OTHERWISE. *
49 * *
50 * 6. This License shall be governed by the laws of the Province of *
51 * Ontario, Canada. *
52 *******************************************************************************/
54 /******************************************************************************
55 * This file contains the C implementation for encode/decode functions *
56 * for the following types of messages: notification, hello, initialization, *
57 * keepAlive, address, address Withdraw, label Mapping, label Request, label *
58 * Withdraw and label Release. There are also encode/decode methods for all *
59 * tlv types required by the previously enumerated messages. *
60 * Please remember that the pdu will always contain the header followed by 1 *
61 * or more LDP messages. The file contains functions to encode/decode the LDP *
62 * header as well. *
63 * All the messages, header message and the tlvs are in conformity with the *
64 * draft-ietf-mpls-ldp-04 (May 1999) and with draft-ietf-mpls-cr-ldp-01 *
65 * (Jan 1999). *
66 * *
67 * Please note that the U bit in the message and the F bit in the tlv are *
68 * ignored in this version of the code. *
69 * *
70 * Please note that the traffic parameters for traffic TLV have to be IEEE *
71 * single precision floating point numbers. *
72 * *
73 * Please note that there might be a small chance for bit field manipulation *
74 * portability inconsistency. If such problems occure, the code requires *
75 * changes for a suitable bit-field manipulation. The code for encoding and *
76 * decoding makes the assumption that the compiler packs the bit fields in a *
77 * structure into adjacent bits of the same unit. *
78 * *
79 * The usage of the encode/decode functions is described below. *
80 * *
81 * The encode functions take as arguments: a pointer to the structure which *
82 * implements msg/tlv, a nbuffer (where the encoding is done) and the buffer *
83 * length. *
84 * If the encode is successfull, the function returns the total encoded *
85 * length. *
86 * If the encode fails, the function returns an error code. *
87 * The encode functions for messages and message headers do not modify the *
88 * content of the struct which is to be encoded. All the other encode *
89 * functions will change the content of the structure. The pointer which *
90 * points to the beginning of the buffer is not changed. *
91 * *
92 * The decode functions take as arguments: a pointer to the structure which *
93 * is going to be populated after decoding, a pointer to a buffer and the *
94 * buffer length. *
95 * If the decode is successful, the function returns the total decoded length *
96 * If the decode fails, the function returns an error code. The decode *
97 * functions do not modify the pointer to the buffer which contains the data *
98 * to be decoded. *
99 * *
100 * Example on how to use the encode/decode functions for a keepAlive message: *
102 * Encode the keep alive message: *
103 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ *
104 * u_char buffer[500]; *
105 * int returnCode; *
106 * struct mplsLdpKeepAlMsg_s keepAliveMsg; *
107 * keepAliveMsg.baseMsg.msgType = MPLS_KEEPAL_MSGTYPE; *
108 * keepAliveMsg.baseMsg.msgLength = MPLS_MSGIDFIXLEN; *
109 * keepAliveMsg.baseMsg.msgId = 123; *
110 * bzero(buffer, 500); *
111 * returnCode = Mpls_encodeLdpKeepAliveMsg(&keepAliveMsg, *
112 * buffer, *
113 * 500); *
114 * if (returnCode < 0) *
115 * check the error code *
116 * else *
117 * write(fd, buffer, returnCode); *
120 * Decode the keep alive meesage: *
121 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ *
122 * u_char buffer[500]; *
123 * int returnCode; *
124 * struct mplsLdpKeepAlMsg_s keepAliveMsg; *
125 * read(fd, buffer, length); *
126 * returnCode = Mpls_decodeLdpKeepAliveMsg(&keepAliveMsg, *
127 * buffer, *
128 * 500); *
129 * if (returnCode < 0) *
130 * check the error code *
131 * else *
132 * { *
133 * printKeepAliveMsg(&keepAliveMsg); *
134 * } *
136 * An example on how to use the decode functions for the header and the *
137 * messages can be found in the main function. *
139 * The code was tested for big endian and little endian for sparc5, linux *
140 * and i960. *
142 * In order to compile for little endian, the LITTLE_ENDIAN_BYTE_ORDER should *
143 * be defined. *
145 * At the end of this file there is an examples of a hex buffers and its *
146 * corresponding values. *
149 * Version History *
150 * Version Date Authors Description *
151 * =========== ======== ========= ====================== *
152 * mpls_encdec_01.c 99/03/15 Antonela Paraschiv draft-ietf-mpls-ldp-03 and *
153 * draft-ietf-mpls-cr-ldp-01 *
155 * mpls_encdec_02.c 99/05/19 Antonela Paraschiv draft-ietf-mpls-ldp-04 and *
156 * draft-ietf-mpls-cr-ldp-01 *
158 ******************************************************************************/
161 #define LITTLE_ENDIAN_BYTE_ORDER 1 /* <----- Please define this accordingly */
162 /* #define VXWORKS 1 */
164 #include <stdio.h>
165 #include <stdlib.h>
166 #include <string.h>
168 #ifdef VXWORKS
169 #include <in.h> /* htons, htonl, ntohs, ntohl */
170 #include <types.h> /* u_int, u_char, u_short, float etc. */
171 #else
172 #include <netinet/in.h> /* htons, htonl, ntohs, ntohl */
173 #include <sys/types.h> /* u_int, u_char, u_short, float etc. */
174 #endif VXWORKS
177 #define MEM_COPY(X, Y, Z) memcpy(X, Y, Z)
179 /* macros to handle different byte orders (little endian or big endian) */
180 #ifdef LITTLE_ENDIAN_BYTE_ORDER
181 #define BITFIELDS_ASCENDING_2(X, Y) Y; X;
182 #define BITFIELDS_ASCENDING_3(X, Y, Z) Z; Y; X;
183 #define BITFIELDS_ASCENDING_4(X, Y, Z, W) W; Z; Y; X;
184 #define BITFIELDS_ASCENDING_7(X, Y, Z, W, U, A, B) B; A; U; W; Z; Y; X;
185 # else
186 #define BITFIELDS_ASCENDING_2(X, Y) X; Y;
187 #define BITFIELDS_ASCENDING_3(X, Y, Z) X; Y; Z;
188 #define BITFIELDS_ASCENDING_4(X, Y, Z, W) X; Y; Z; W;
189 #define BITFIELDS_ASCENDING_7(X, Y, Z, W, U, A, B) X; Y; Z; W; U; A; B;
190 #endif LITTLE_ENDIAN_BYTE_ORDER
192 /* macros used to decode the entire LDP; they declare local var for
193 different type of messages */
194 #define MPLS_MSGSTRUCT( e ) \
195 mplsLdp ## e ## Msg_t test ## e ## Msg; \
197 #define MPLS_MSGPARAM( e ) \
198 test ## e ## Msg \
201 #define DEBUG_INFO 1 /* set this to 0 if no debug info
202 required */
204 /* debug macros */
205 #define DEBUG_CALL(X) if (DEBUG_INFO) X;
206 #define PRINT_2(X, Y) if (DEBUG_INFO) printf(X, Y)
207 #define PRINT_4(X, Y, Z, W) if (DEBUG_INFO) printf(X, Y, Z, W)
208 #define PRINT_ERR(X) if (DEBUG_INFO) printf(X)
209 #define PRINT_ERR_2(X, Y) if (DEBUG_INFO) printf(X, Y)
210 #define PRINT_ERR_4(X, Y, Z, W) if (DEBUG_INFO) printf(X, Y, Z, W)
214 * MESSAGE TYPE CONSTANS & TLV CONSTANTS
217 #define MPLS_LDP_HDRSIZE 10 /* the size for mpls ldp hdr */
218 #define MPLS_TLVFIXLEN 4 /* type + len */
219 #define MPLS_MSGIDFIXLEN 4 /* type + len */
220 #define MPLS_LDPIDLEN 6
221 #define MPLS_PDUMAXLEN 4096 /* octets */
222 #define MPLS_VERSION 0x0001
223 #define MPLS_IPV4ADDRFAMILYN 0x0100 /* rfc 1700 (network order) */
224 #define MPLS_INIFINITE_TIMEVAL 0xfffff
226 /* for initialize message */
227 #define MPLS_INIT_MSGTYPE 0x0200 /* initialization msg */
228 #define MPLS_CSP_TLVTYPE 0x0500 /* common params for init msg */
229 #define MPLS_ASP_TLVTYPE 0x0501 /* atm session params */
230 #define MPLS_FSP_TLVTYPE 0x0502 /* frame relay session params */
231 #define MPLS_ASPFIXLEN 4 /* M + N + D + res */
232 #define MPLS_FSPFIXLEN 4 /* M + N + res */
233 #define MPLS_CSPFIXLEN 14 /* protocolV + ... + ldp ids */
234 #define MPLS_ATMLBLMAXLEN 10
235 #define MPLS_ATMLRGFIXLEN 8
236 #define MPLS_FRLRGFIXLEN 8
237 #define MPLS_ASP_NOMERGE 0
238 #define MPLS_ASP_VPMERGE 1
239 #define MPLS_ASP_VCMERGE 2
240 #define MPLS_ASP_VPVCMERGE 3
241 #define MPLS_FRLBLMAXLEN 10
242 #define MPLS_FRDLCI10BITS 0
243 #define MPLS_FRDLCI17BITS 1
244 #define MPLS_FRDLCI23BITS 2
246 /* for notification message */
247 #define MPLS_NOT_MSGTYPE 0x0001 /* notification msg */
248 #define MPLS_NOT_ST_TLVTYPE 0x0300 /* status tlv for not msg */
249 #define MPLS_NOT_ES_TLVTYPE 0x0301 /* extended status for not msg */
250 #define MPLS_NOT_RP_TLVTYPE 0x0302 /* returned PDU for not msg */
251 #define MPLS_NOT_RM_TLVTYPE 0x0303 /* returned msg for not msg */
252 #define MPLS_STATUSFIXLEN 10 /* status code + id + type */
253 #define MPLS_EXSTATUSLEN 4
254 #define MPLS_NOT_MAXSIZE MPLS_PDUMAXLEN - MPLS_TLVFIXLEN - \
255 MPLS_MSGIDFIXLEN
257 /* for hello message */
258 #define MPLS_HELLO_MSGTYPE 0x0100 /* hello msg */
259 #define MPLS_CHP_TLVTYPE 0x0400 /* Common Hello Param Tlv */
260 #define MPLS_TRADR_TLVTYPE 0x0401 /* Transport Address Param Tlv */
261 #define MPLS_CSN_TLVTYPE 0x0402 /* Conf Seq Number Param Tlv */
262 #define MPLS_CHPFIXLEN 4
263 #define MPLS_CSNFIXLEN 4
264 #define MPLS_TRADRFIXLEN 4
266 /* for keep alive message */
267 #define MPLS_KEEPAL_MSGTYPE 0x0201 /* keep alive msg */
269 /* for address messages */
270 #define MPLS_ADDR_MSGTYPE 0x0300 /* address msg */
271 #define MPLS_ADDRWITH_MSGTYPE 0x0301 /* address withdraw msg */
272 #define MPLS_ADDRLIST_TLVTYPE 0x0101 /* addrss list tlv type */
273 #define MPLS_IPv4LEN 4
274 #define MPLS_ADDFAMFIXLEN 2
275 #define MPLS_ADDLISTMAXLEN MPLS_PDUMAXLEN - 2*MPLS_TLVFIXLEN - \
276 MPLS_MSGIDFIXLEN - MPLS_ADDFAMFIXLEN
277 #define MPLS_MAXNUMBERADR MPLS_ADDLISTMAXLEN / 4
279 /* for label mapping message */
280 #define MPLS_LBLMAP_MSGTYPE 0x0400 /* label mapping msg */
281 #define MPLS_FEC_TLVTYPE 0x0100 /* label mapping msg */
282 #define MPLS_GENLBL_TLVTYPE 0x0200 /* generic label tlv */
283 #define MPLS_ATMLBL_TLVTYPE 0x0201 /* atm label tlv */
284 #define MPLS_FRLBL_TLVTYPE 0x0202 /* frame relay label tlv */
285 #define MPLS_HOPCOUNT_TLVTYPE 0x0103 /* ho count tlv */
286 #define MPLS_PATH_TLVTYPE 0x0104 /* path vector tlv */
287 #define MPLS_REQMSGID_TLVTYPE 0x0600 /* lbl request msg id tlv */
288 #define MPLS_WC_FEC 0x01 /* wildcard fec element */
289 #define MPLS_PREFIX_FEC 0x02 /* prefix fec element */
290 #define MPLS_HOSTADR_FEC 0x03 /* host addr fec element */
291 #define MPLS_CRLSP_FEC 0x04 /* crlsp fec element */
292 #define MPLS_MARTINIVC_FEC 0x80 /* Martini VC fec element */
293 #define MPLS_FECMAXLEN MPLS_PDUMAXLEN - 2*MPLS_TLVFIXLEN - \
294 MPLS_MSGIDFIXLEN
295 #define MPLS_LBLFIXLEN 4 /* v + vpi + vci + res */
296 #define MPLS_HOPCOUNTFIXLEN 1 /* v + vpi + vci + res */
297 #define MPLS_VCIDLEN 4 /* Martini VC id length */
298 #define MPLS_VCIFPARAMMAXLEN 80 /* Martini VC Intf param max size */
299 #define MPLS_VCIFPARAM_HDR 2 /* size of TL in a VC Intf Param TLV */
300 #define MPLS_FEC_ELEMTYPELEN 1
301 #define MPLS_FEC_PRELENLEN 1
302 #define MPLS_FEC_ADRFAMLEN 2
303 #define MPLS_FEC_CRLSPLEN 4 /* length of cr lsp fec */
304 #define MPLS_FEC_MARTINILEN 8 /* length of the min martin fec*/
305 #define MPLS_MAXHOPSNUMBER 20 /* max # hops in path vector */
306 #define MPLS_MAXNUMFECELEMENT 10 /* max # of fec elements */
308 #define MPLS_VCIFPARAM_MTU 0x1
309 #define MPLS_VCIFPARAM_ATMCONCAT 0x2
310 #define MPLS_VCIFPARAM_INFO 0x3
311 #define MPLS_VCIFPARAM_CEMBYTES 0x4
312 #define MPLS_VCIFPARAM_CEMOPTION 0x5
314 /* for label request message */
315 #define MPLS_LBLREQ_MSGTYPE 0x0401 /* label request msg */
316 #define MPLS_LBLMSGID_TLVTYPE 0x0601 /* lbl return msg id tlv */
318 /* for label withdraw and release messages */
319 #define MPLS_LBLWITH_MSGTYPE 0x0402 /* label withdraw msg */
320 #define MPLS_LBLREL_MSGTYPE 0x0403 /* label release msg */
322 /* for ER tlvs */
323 #define MPLS_ER_TLVTYPE 0x0800 /* constraint routing tlv */
324 #define MPLS_TRAFFIC_TLVTYPE 0x0810 /* traffic parameters tlv */
325 #define MPLS_PDR_TLVTYPE 0x0811 /* traffic peak data rate tlv */
326 #define MPLS_CDR_TLVTYPE 0x0812 /* committed data rate tlv */
327 #define MPLS_CBT_TLVTYPE 0x0813 /* committed burst tolerance */
328 #define MPLS_PREEMPT_TLVTYPE 0x0820 /* preemption tlv */
329 #define MPLS_LSPID_TLVTYPE 0x0821 /* lspid tlv */
330 #define MPLS_RESCLASS_TLVTYPE 0x0822 /* resource class tlv */
331 #define MPLS_PINNING_TLVTYPE 0x0823 /* route pinning tlv */
332 #define MPLS_ERHOP_IPV4_TLVTYPE 0x801 /* explicit routing ipv4 tlv */
333 #define MPLS_ERHOP_IPV6_TLVTYPE 0x802 /* explicit routing ipv6 tlv */
334 #define MPLS_ERHOP_AS_TLVTYPE 0x803 /* explicit routing autonomous
335 system number tlv */
336 #define MPLS_ERHOP_LSPID_TLVTYPE 0x804 /* explicit routing lspid tlv */
337 #define MPLS_ERHOP_IPV4_FIXLEN 8 /* fix length in bytes */
338 #define MPLS_ERHOP_IPV6_FIXLEN 20 /* fix length in bytes */
339 #define MPLS_ERHOP_AS_FIXLEN 4 /* fix length in bytes */
340 #define MPLS_ERHOP_LSPID_FIXLEN 8 /* fix length in bytes */
341 #define MPLS_IPV6ADRLENGTH 16
342 #define MPLS_MAX_ER_HOPS 20 /* decent number of hops;
343 change if required */
344 #define MPLS_PREEMPTTLV_FIXLEN 4 /* setPrio + holdPrio + res */
345 #define MPLS_LSPIDTLV_FIXLEN 8 /* res + crlspId + routerId */
346 #define MPLS_TRAFFICPARAMLENGTH 4 /* traffic parameters length */
348 /* for label abort request message */
349 #define MPLS_LBLABORT_MSGTYPE 0x0404 /* label abort request msg */
353 * Error codes
356 #define MPLS_ENC_BUFFTOOSMALL -1
357 #define MPLS_DEC_BUFFTOOSMALL -2
358 #define MPLS_ENC_TLVERROR -3
359 #define MPLS_DEC_TLVERROR -4
360 #define MPLS_ENC_ATMLBLERROR -5
361 #define MPLS_DEC_ATMLBLERROR -6
362 #define MPLS_ENC_BASEMSGERROR -7
363 #define MPLS_DEC_BASEMSGERROR -8
364 #define MPLS_ENC_CSPERROR -9
365 #define MPLS_DEC_CSPERROR -10
366 #define MPLS_ENC_ASPERROR -11
367 #define MPLS_DEC_ASPERROR -12
368 #define MPLS_ENC_FSPERROR -13
369 #define MPLS_DEC_FSPERROR -14
370 #define MPLS_ENC_STATUSERROR -16
371 #define MPLS_DEC_STATUSERROR -17
372 #define MPLS_ENC_EXSTATERROR -18
373 #define MPLS_DEC_EXSTATERROR -19
374 #define MPLS_ENC_RETPDUERROR -20
375 #define MPLS_DEC_RETPDUERROR -21
376 #define MPLS_ENC_RETMSGERROR -22
377 #define MPLS_DEC_RETMSGERROR -23
378 #define MPLS_PDU_LENGTH_ERROR -24
379 #define MPLS_ENC_CHPERROR -25
380 #define MPLS_DEC_CHPERROR -26
381 #define MPLS_ENC_CSNERROR -27
382 #define MPLS_DEC_CSNERROR -28
383 #define MPLS_ENC_TRADRERROR -29
384 #define MPLS_DEC_TRADRERROR -30
385 #define MPLS_ENC_ADRLISTERROR -31
386 #define MPLS_DEC_ADRLISTERROR -32
387 #define MPLS_WC_FECERROR -33
388 #define MPLS_PATHVECTORERROR -34
389 #define MPLS_ENC_FECERROR -35
390 #define MPLS_DEC_FECERROR -36
391 #define MPLS_ENC_GENLBLERROR -37
392 #define MPLS_DEC_GENLBLERROR -38
393 #define MPLS_ENC_MAPATMERROR -39
394 #define MPLS_DEC_MAPATMERROR -40
395 #define MPLS_ENC_FRLBLERROR -41
396 #define MPLS_DEC_FRLBLERROR -42
397 #define MPLS_ENC_COSERROR -43
398 #define MPLS_DEC_COSERROR -44
399 #define MPLS_ENC_HOPCOUNTERROR -45
400 #define MPLS_DEC_HOPCOUNTERROR -46
401 #define MPLS_ENC_PATHVECERROR -47
402 #define MPLS_DEC_PATHVECERROR -48
403 #define MPLS_ENC_LBLMSGIDERROR -49
404 #define MPLS_DEC_LBLMSGIDERROR -50
405 #define MPLS_ENC_HDRTLVERROR -51
406 #define MPLS_DEC_HDRTLVERROR -52
407 #define MPLS_ENC_FECELEMERROR -53
408 #define MPLS_DEC_FECELEMERROR -54
409 #define MPLS_ENC_FSPLBLERROR -55
410 #define MPLS_DEC_FSPLBLERROR -56
411 #define MPLS_ENC_ERHOPERROR -57
412 #define MPLS_DEC_ERHOPERROR -58
413 #define MPLS_ENC_ERTLVERROR -59
414 #define MPLS_DEC_ERTLVERROR -60
415 #define MPLS_ENC_ERHOPLENERROR -61
416 #define MPLS_DEC_ERHOPLENERROR -62
417 #define MPLS_TLVTYPEERROR -63
418 #define MPLS_MSGTYPEERROR -64
419 #define MPLS_FECERROR -65
420 #define MPLS_ENC_TRAFFICERROR -66
421 #define MPLS_DEC_TRAFFICERROR -67
422 #define MPLS_ENC_LSPIDERROR -68
423 #define MPLS_DEC_LSPIDERROR -69
424 #define MPLS_ENC_RESCLSERROR -70
425 #define MPLS_DEC_RESCLSERROR -71
426 #define MPLS_ENC_PREEMPTERROR -72
427 #define MPLS_DEC_PREEMPTERROR -73
428 #define MPLS_ENC_PINNINGERROR -74
429 #define MPLS_DEC_PINNINGERROR -75
430 #define MPLS_FLOATTYPEERROR -76
431 #define MPLS_FECTLVERROR -77
432 #define MPLS_IPV4LENGTHERROR -78
433 #define MPLS_ER_HOPSNUMERROR -79
436 /**********************************************************************
437 LDP header
439 0 1 2 3
440 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
441 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
442 | Version | PDU Length |
443 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
444 | LDP Identifier |
445 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
447 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
448 **********************************************************************/
450 typedef struct mplsLdpHeader_s
452 u_short protocolVersion;
453 u_short pduLength; /* length excluding the version and length */
454 u_int lsrAddress; /* IP address assigned to LSR */
455 u_short labelSpace; /* within LSR */
457 } mplsLdpHeader_t;
460 /**********************************************************************
461 LDP Messages (All LDP messages have the following format:)
463 0 1 2 3
464 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
465 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
466 |U| Message Type | Message Length |
467 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
468 | Message ID |
469 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
472 | Mandatory Parameters |
475 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
478 | Optional Parameters |
481 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
482 Note: the U flag is ignored for now. There is not check for its value.
483 **********************************************************************/
485 typedef struct mplsLdpMsgFlag_s
487 BITFIELDS_ASCENDING_2( u_short uBit :1,
488 u_short msgType:15 )
489 } mplsLdpMsgFlag_t;
491 typedef struct mplsLdpMsg_s
493 union { struct mplsLdpMsgFlag_s flags;
494 u_short mark;
495 } flags;
497 u_short msgLength; /* msgId + mandatory param + optional param */
498 u_int msgId; /* used to identify the notification msg */
500 } mplsLdpMsg_t;
504 /**********************************************************************
505 Type-Length-Value Encoding
507 0 1 2 3
508 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
509 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
510 |U|F| Type | Length |
511 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
513 | Value |
516 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
518 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
519 Note: the decode functions for tlv do not check the values for
520 F flag. They check only the value of the U flag; if
521 it is set will ignore the tlv and keep processing the message;
522 otherwise will ignore the message and return error. Please note
523 that the unknown tlv which is skipped will not be stored anywhere.
524 **********************************************************************/
526 typedef struct mplsLdpTlvFlag_s
528 BITFIELDS_ASCENDING_3( u_short uBit:1,
529 u_short fBit:1,
530 u_short type:14 )
531 } mplsLdpTlvFlag_t;
533 typedef struct mplsLdpTlv_s
535 union { struct mplsLdpTlvFlag_s flags;
536 u_short mark;
537 } flags;
539 u_short length; /* length of the value field */
541 } mplsLdpTlv_t;
546 /**********************************************************************
547 Common Session Parameters TLV
549 0 1 2 3
550 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
551 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
552 |U|F| Common Sess Parms (0x0500)| Length |
553 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
554 | Protocol Version | Keep Alive Time |
555 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
556 |A|D| Reserved | PVLim | Max PDU Length |
557 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
558 | Receiver LDP Identifer |
559 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
561 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-++
562 ***********************************************************************/
564 typedef struct mplsLdpCspFlag_s
566 BITFIELDS_ASCENDING_4( u_short lad:1, /* 1 = downstream on demand */
567 u_short ld :1, /* loop detection */
568 u_short res:6, /* reserved */
569 u_short pvl:8 /* path vec limit */
571 } mplsLdpCspFlag_t;
573 typedef struct mplsLdpCspTlv_s
575 struct mplsLdpTlv_s baseTlv;
576 u_short protocolVersion;
577 u_short holdTime; /* proposed keep alive interval */
579 union { struct mplsLdpCspFlag_s flags;
580 u_short mark;
581 } flags;
583 u_short maxPduLen;
584 u_int rcvLsrAddress;
585 u_short rcvLsId;
587 } mplsLdpCspTlv_t;
592 /***********************************************************************
593 ATM Label Range Component
595 0 1 2 3
596 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
597 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
598 | Res | Minimum VPI | Minimum VCI |
599 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
600 | Res | Maximum VPI | Maximum VCI |
601 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
602 ***********************************************************************/
604 typedef struct mplsLdpAtmLblRngFlag_s
606 BITFIELDS_ASCENDING_3( u_int res1 :4, /* reserved : 0 on transmision */
607 u_int minVpi:12, /* if <12 bits right justified */
608 u_int minVci:16 /* if <16 bits right justified */
610 BITFIELDS_ASCENDING_3( u_int res2 :4, /* reserved : 0 on transmision */
611 u_int maxVpi:12, /* if <12 bits right justified */
612 u_int maxVci:16 /* if <16 bits right justified */
614 } mplsLdpAtmLblRngFlag_t;
616 typedef struct mplsLdpAtmLblRng_s
618 union {
619 struct mplsLdpAtmLblRngFlag_s flags;
620 u_int mark[2];
621 } flags;
622 } mplsLdpAtmLblRng_t;
626 /***********************************************************************
627 Flags for ATM Session Parameters TLV and
628 Frame Relay Session Parameters TLV
630 Note: both types of session parameters have the same type of flags;
631 use then the same struct
632 ***********************************************************************/
634 typedef struct mplsLdpSPFlag_s
636 BITFIELDS_ASCENDING_4( u_int mergeType:2, /* merge typ */
637 u_int numLblRng:4, /* # of label range com */
638 u_int dir :1, /* 0 => bidirectional */
639 u_int res :25
641 } mplsLdpSPFlag_t;
644 /***********************************************************************
645 ATM Session Parameters TLV
647 0 1 2 3
648 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
649 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
650 |U|F| ATM Sess Parms (0x0501) | Length |
651 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
652 | M | N |D| Reserved |
653 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
654 | ATM Label Range Component 1 |
655 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
659 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
660 | ATM Label Range Component N |
661 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
662 ***********************************************************************/
664 typedef struct mplsLdpAspTlv_s
666 struct mplsLdpTlv_s baseTlv;
667 union { struct mplsLdpSPFlag_s flags;
668 u_int mark;
669 } flags;
670 struct mplsLdpAtmLblRng_s lblRngList[MPLS_ATMLBLMAXLEN];
672 } mplsLdpAspTlv_t;
677 /***********************************************************************
678 Frame Relay Label Range Component
680 0 1 2 3
681 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
682 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
683 | Reserved |Len| Minimum DLCI |
684 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
685 | Reserved | Maximum DLCI |
686 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
687 ***********************************************************************/
689 typedef struct mplsLdpFrFlag_s
691 BITFIELDS_ASCENDING_3( u_int res_min:7,
692 u_int len :2,
693 u_int minDlci:23 )
694 BITFIELDS_ASCENDING_2( u_int res_max:9,
695 u_int maxDlci:23 )
696 } mplsLdpFrFlag_t;
698 typedef struct mplsLdpFrLblRng_s
700 union {
701 struct mplsLdpFrFlag_s flags;
702 u_int mark[2];
703 } flags;
705 } mplsLdpFrLblRng_t;
709 /**********************************************************************
710 Frame Relay Session Parameters TLV
712 0 1 2 3
713 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
714 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
715 |U|F| FR Sess Parms (0x0502) | Length |
716 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
717 | M | N |D| Reserved |
718 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
719 | Frame Relay Label Range Component 1 |
720 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
724 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
725 | Frame Relay Label Range Component N |
726 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
727 ***********************************************************************/
729 typedef struct mplsLdpFspTlv_s
731 struct mplsLdpTlv_s baseTlv;
732 union {
733 struct mplsLdpSPFlag_s flags;
734 u_int mark;
735 } flags;
736 struct mplsLdpFrLblRng_s lblRngList[MPLS_FRLBLMAXLEN];
738 } mplsLdpFspTlv_t;
743 /***********************************************************************
744 Initialization Message Encoding
746 0 1 2 3
747 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
748 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
749 |U| Initialization (0x0200) | Message Length |
750 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
751 | Message ID |
752 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
753 | Common Session Parameters TLV |
754 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
755 | Optional Parameters |
756 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
757 ***********************************************************************/
759 typedef struct mplsLdpInitMsg_s
761 struct mplsLdpMsg_s baseMsg;
762 struct mplsLdpCspTlv_s csp;
763 struct mplsLdpAspTlv_s asp;
764 struct mplsLdpFspTlv_s fsp;
765 u_char cspExists:1;
766 u_char aspExists:1;
767 u_char fspExists:1;
769 } mplsLdpInitMsg_t;
773 /***********************************************************************
774 Status Code Encoding
776 0 1 2 3
777 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
778 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
779 |E|F| Status Data |
780 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
781 ***********************************************************************/
782 typedef struct mplsLdpStautsFlag_s
784 BITFIELDS_ASCENDING_3( u_int error :1, /* E bit */
785 u_int forward:1, /* F bit */
786 u_int status :30 )
787 } mplsLdpStautsFlag_t;
791 /***********************************************************************
792 Status (TLV) Encoding
794 0 1 2 3
795 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
796 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
797 |U|F| Status (0x0300) | Length |
798 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
799 | Status Code |
800 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
801 | Message ID |
802 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
803 | Message Type |
804 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
805 ***********************************************************************/
807 typedef struct mplsLdpStatusTlv_s
809 struct mplsLdpTlv_s baseTlv;
810 union {
811 struct mplsLdpStautsFlag_s flags;
812 u_int mark;
813 } flags;
814 u_int msgId;
815 u_short msgType;
817 } mplsLdpStatusTlv_t;
821 /***********************************************************************
822 Extended Status (TLV) Encoding
823 ***********************************************************************/
825 typedef struct mplsLdpExStatusTlv_s
827 struct mplsLdpTlv_s baseTlv;
828 u_int value; /* additional info for status */
830 } mplsLdpExStatusTlv_t;
834 /***********************************************************************
835 Returned PDU (TLV) Encoding
836 ***********************************************************************/
838 typedef struct mplsLdpRetPduTlv_s
840 struct mplsLdpTlv_s baseTlv;
841 struct mplsLdpHeader_s headerTlv;
842 u_char data[MPLS_NOT_MAXSIZE];
844 } mplsLdpRetPduTlv_t;
848 /***********************************************************************
849 Returned MSG (TLV) Encoding
850 ***********************************************************************/
852 typedef struct mplsLdpRetMsgTlv_s
854 struct mplsLdpTlv_s baseTlv;
855 u_short msgType;
856 u_short msgLength;
857 u_char data[MPLS_NOT_MAXSIZE];
859 } mplsLdpRetMsgTlv_t;
863 /***********************************************************************
864 LSPID Tlv encoding
866 0 1 2 3
867 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
868 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
869 |U|F| LSPID-TLV (0x0821) | Length |
870 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
871 | Reserved | Local CRLSP ID |
872 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
873 | Ingress LSR Router ID |
874 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
875 ***********************************************************************/
877 typedef struct mplsLdpLspIdTlv_s
879 struct mplsLdpTlv_s baseTlv;
880 u_short res;
881 u_short localCrlspId;
882 u_int routerId; /* ingress lsr router id */
884 } mplsLdpLspIdTlv_t;
887 /***********************************************************************
888 Notification Message Encoding
890 0 1 2 3
891 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
892 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
893 |U| Notification (0x0001) | Message Length |
894 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
895 | Message ID |
896 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
897 | Status (TLV) |
898 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
899 | Optional Parameters |
900 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
901 | LSPID TLV (optional for CR-LDP) |
902 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
903 ***********************************************************************/
905 typedef struct mplsLdpNotifMsg_s
907 struct mplsLdpMsg_s baseMsg;
908 struct mplsLdpStatusTlv_s status;
909 struct mplsLdpExStatusTlv_s exStatus; /* extended status tlv */
910 struct mplsLdpRetPduTlv_s retPdu; /* returned PDU tlv */
911 struct mplsLdpRetMsgTlv_s retMsg; /* returned MSG tlv */
912 struct mplsLdpLspIdTlv_s lspidTlv; /* lspid tlv */
914 u_char statusTlvExists:1;
915 u_char exStatusTlvExists:1;
916 u_char retPduTlvExists:1;
917 u_char retMsgTlvExists:1;
918 u_char lspidTlvExists;
920 } mplsLdpNotifMsg_t;
923 /***********************************************************************
924 Common Hello Parameters Tlv encoding
926 0 1 2 3
927 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
928 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
929 |U|F| Common Hello Parms(0x0400)| Length |
930 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
931 | Hold Time |T|R| Reserved |
932 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
933 ***********************************************************************/
934 typedef struct mplsLdpChpFlag_s
936 BITFIELDS_ASCENDING_3( u_short target :1, /* T bit */
937 u_short request:1, /* R bit */
938 u_short res :14 )
939 } mplsLdpChpFlag_t;
941 typedef struct mplsLdpChpTlv_s
943 struct mplsLdpTlv_s baseTlv;
944 u_short holdTime;
945 union { struct mplsLdpChpFlag_s flags;
946 u_short mark;
947 } flags;
949 } mplsLdpChpTlv_t;
953 /***********************************************************************
954 Transport Address (TLV) Encoding
955 ***********************************************************************/
957 typedef struct mplsLdpTrAdrTlv_s
959 struct mplsLdpTlv_s baseTlv;
960 u_int address;
962 } mplsLdpTrAdrTlv_t;
966 /***********************************************************************
967 Configuration Sequence Number (TLV) Encoding
968 ***********************************************************************/
970 typedef struct mplsLdpCsnTlv_s
972 struct mplsLdpTlv_s baseTlv;
973 u_int seqNumber;
975 } mplsLdpCsnTlv_t;
979 /***********************************************************************
980 Hello message encoding
982 0 1 2 3
983 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
984 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
985 |U| Hello (0x0100) | Message Length |
986 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
987 | Message ID |
988 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
989 | Common Hello Parameters TLV |
990 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
991 | Optional Parameters |
992 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
993 ***********************************************************************/
995 typedef struct mplsLdpHelloMsg_s
997 struct mplsLdpMsg_s baseMsg;
998 struct mplsLdpChpTlv_s chp; /* common hello param tlv */
999 struct mplsLdpTrAdrTlv_s trAdr; /* transport address tlv */
1000 struct mplsLdpCsnTlv_s csn; /* configuration seq # tlv */
1001 u_char chpTlvExists:1;
1002 u_char trAdrTlvExists:1;
1003 u_char csnTlvExists:1;
1005 } mplsLdpHelloMsg_t;
1008 /***********************************************************************
1009 KeepAlive Message encoding
1011 0 1 2 3
1012 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1013 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1014 |U| KeepAlive (0x0201) | Message Length |
1015 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1016 | Message ID |
1017 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1018 | Optional Parameters |
1019 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1021 Note: there are no optional param defined for keep alive.
1022 ***********************************************************************/
1024 typedef struct mplsLdpKeepAlMsg_s
1026 struct mplsLdpMsg_s baseMsg;
1028 } mplsLdpKeepAlMsg_t ;
1032 /***********************************************************************
1033 Address List TLV encoding
1035 0 1 2 3
1036 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1037 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1038 |U|F| Address List (0x0101) | Length |
1039 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1040 | Address Family | |
1041 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
1043 | Addresses |
1046 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1047 ***********************************************************************/
1049 typedef struct mplsLdpAdrTlv_s
1051 struct mplsLdpTlv_s baseTlv;
1052 u_short addrFamily;
1053 u_int address[MPLS_MAXNUMBERADR];
1055 } mplsLdpAdrTlv_t;
1060 /***********************************************************************
1061 Address (0x0300) / Address Withdraw(0x0301) message encoding
1063 0 1 2 3
1064 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1065 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1066 |U| Address | Message Length |
1067 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1068 | Message ID |
1069 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1071 | Address List TLV |
1073 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1074 | Optional Parameters |
1075 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1077 Note: there are no optional param defined for address message.
1078 ***********************************************************************/
1080 typedef struct mplsLdpAdrMsg_s
1082 struct mplsLdpMsg_s baseMsg;
1083 struct mplsLdpAdrTlv_s addressList;
1084 u_char adrListTlvExists:1;
1086 } mplsLdpAdrMsg_t;
1090 /***********************************************************************
1091 Wildcard FEC Element encoding
1092 ***********************************************************************/
1094 typedef struct mplsLdpWildFec_s
1096 u_char type;
1098 } mplsLdpWildFec_t;
1102 /***********************************************************************
1103 Prefix FEC Element encoding
1105 0 1 2 3
1106 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1107 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1108 | Prefix (2) | Address Family | PreLen |
1109 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1110 | Prefix |
1111 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1113 Host Address FEC Element encoding
1115 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1116 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1117 | Host Addr (3) | Address Family | Host Addr Len |
1118 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1119 | Host Addr |
1120 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1122 Note: the code handles prefixes and host addresses whose length is
1123 less or equal to 4 bytes.
1124 ***********************************************************************/
1126 typedef struct mplsLdpAddressFec_s
1128 u_char type;
1129 u_short addressFam;
1130 u_char preLen; /* prefix FEC: length of the adr prefix (in bits)
1131 or host adr FEC: length of the host address (in
1132 bytes) */
1133 u_int address;
1135 } mplsLdpAddressFec_t;
1138 /***********************************************************************
1139 CRLSP FEC Element encoding
1141 0 1 2 3
1142 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1143 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1144 | CR-LSP (4) | Reserved |
1145 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1146 ***********************************************************************/
1148 typedef struct mplsLdpCrlspFec_s
1150 u_char type;
1151 u_char res1; /* reserved */
1152 u_short res2; /* reserved */
1154 } mplsLdpCrlspFec_t;
1157 /***********************************************************************
1158 Martini VC FEC Element encoding
1160 0 1 2 3
1161 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1162 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1163 | VC tlv(128) |C| VC Type |VC info Length |
1164 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1165 | Group ID |
1166 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1167 | VC ID |
1168 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1169 | Interface parameters |
1170 | " |
1171 | " |
1172 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1174 Interface Parameter encoding
1176 0 1 2 3
1177 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1178 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1179 | Parameter ID | Length | Variable Length Value |
1180 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1181 | Variable Length Value |
1182 | " |
1183 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1185 ***********************************************************************/
1189 typedef struct mplsLdpMartiniInterfaceParams_s
1191 u_char id;
1192 u_char len;
1193 u_char value[MPLS_VCIFPARAMMAXLEN];
1194 } mplsLdpMartiniInterfaceParams_t;
1196 typedef struct mplsLdMartiniVcFlag_s
1198 BITFIELDS_ASCENDING_4( u_int type:8,
1199 u_int control:1, /* C bit */
1200 u_int vcType:15, /* VC type */
1201 u_int vcInfoLen:8);
1202 } mplsLdMartiniVcFlag_t;
1204 typedef struct mplsLdpMartiniVcFec_s
1206 union { struct mplsLdMartiniVcFlag_s flags;
1207 u_int mark;
1208 } flags;
1209 u_int groupId;
1210 u_int vcId;
1212 struct mplsLdpMartiniInterfaceParams_s vcIfParams[5];
1213 int vcIfParamsLen;
1215 } mplsLdpMartiniVcFec_t;
1218 /***********************************************************************
1219 FEC Tlv encoding
1221 0 1 2 3
1222 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1223 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1224 |U|F| FEC (0x0100) | Length |
1225 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1226 | FEC Element 1 |
1227 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1231 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1232 | FEC Element n |
1233 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1234 ***********************************************************************/
1236 typedef union mplsFecElement_u
1238 struct mplsLdpAddressFec_s addressEl; /* prefix | host adr */
1239 struct mplsLdpWildFec_s wildcardEl; /* for wilcard fec */
1240 struct mplsLdpCrlspFec_s crlspEl; /* CRLSP fec elem */
1241 struct mplsLdpMartiniVcFec_s martiniVcEl; /* Martini VC fec elem */
1243 } mplsFecElement_t;
1245 typedef struct mplsLdpFecTlv_s
1247 struct mplsLdpTlv_s baseTlv;
1248 union mplsFecElement_u fecElArray[MPLS_MAXNUMFECELEMENT];
1249 u_short fecElemTypes[MPLS_MAXNUMFECELEMENT];
1250 u_char wcElemExists:1;
1251 u_short numberFecElements;
1253 } mplsLdpFecTlv_t;
1256 /***********************************************************************
1257 Generic Label Tlv encoding
1259 0 1 2 3
1260 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1261 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1262 |U|F| Generic Label (0x0200) | Length |
1263 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1264 | Label |
1265 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1266 ***********************************************************************/
1268 typedef struct mplsLdpGenLblTlv_s
1270 struct mplsLdpTlv_s baseTlv;
1271 u_int label; /* 20-bit number in 4 octet field */
1273 } mplsLdpGenLblTlv_t;
1276 /***********************************************************************
1277 Atm Label Tlv encoding
1279 0 1 2 3
1280 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1281 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1282 |U|F| ATM Label (0x0201) | Length |
1283 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1284 |Res| V | VPI | VCI |
1285 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1286 ***********************************************************************/
1288 typedef struct mplsLdpAtmLblFlag_s
1290 BITFIELDS_ASCENDING_3( u_short res:2,
1291 u_short v :2,
1292 u_short vpi:12 )
1293 } mplsLdpAtmLblFlag_t;
1295 typedef struct mplsLdpAtmLblTlv_s
1297 struct mplsLdpTlv_s baseTlv;
1299 union { struct mplsLdpAtmLblFlag_s flags;
1300 u_short mark;
1301 } flags;
1303 u_short vci;
1305 } mplsLdpAtmLblTlv_t;
1309 /***********************************************************************
1310 Frame Relay Label Tlv encoding
1312 0 1 2 3
1313 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1314 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1315 |U|F| Frame Relay Label (0x0202)| Length |
1316 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1317 | Reserved |Len| DLCI |
1318 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1319 ***********************************************************************/
1321 typedef struct mplsLdpFrLblFlag_s
1323 BITFIELDS_ASCENDING_3( u_int res :7,
1324 u_int len :2,
1325 u_int dlci:23 )
1327 } mplsLdpFrLblFlag_t;
1329 typedef struct mplsLdpFrLblTlv_s
1331 struct mplsLdpTlv_s baseTlv;
1333 union { struct mplsLdpFrLblFlag_s flags;
1334 u_int mark;
1335 } flags;
1337 } mplsLdpFrLblTlv_t;
1341 /***********************************************************************
1342 Hop Count Tlv encoding
1344 0 1 2 3
1345 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1346 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1347 |U|F| Hop Count (0x0103) | Length |
1348 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1349 | HC Value |
1350 +-+-+-+-+-+-+-+-+
1351 ***********************************************************************/
1353 typedef struct mplsLdpHopTlv_s
1355 struct mplsLdpTlv_s baseTlv;
1356 u_char hcValue; /* hop count value */
1358 } mplsLdpHopTlv_t;
1362 /***********************************************************************
1363 Path Vector Tlv encoding
1365 0 1 2 3
1366 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1367 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1368 |U|F| Path Vector (0x0104) | Length |
1369 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1370 | LSR Id 1 |
1371 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1375 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1376 | LSR Id n |
1377 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1378 ***********************************************************************/
1380 typedef struct mplsLdpPathTlv_s
1382 struct mplsLdpTlv_s baseTlv;
1383 u_int lsrId[MPLS_MAXHOPSNUMBER];
1385 } mplsLdpPathTlv_t;
1389 /***********************************************************************
1390 Lbl request message id Tlv encoding
1391 ***********************************************************************/
1393 typedef struct mplsLdpLblMsgIdTlv_s
1395 struct mplsLdpTlv_s baseTlv;
1396 u_int msgId;
1398 } mplsLdpLblMsgIdTlv_t;
1402 /***********************************************************************
1403 Preemption Tlv encoding
1405 0 1 2 3
1406 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1407 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1408 |U|F| Preemption-TLV (0x0820) | Length |
1409 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1410 | SetPrio | HoldPrio | Reserved |
1411 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1412 ***********************************************************************/
1414 typedef struct mplsLdpPreemptTlv_s
1416 struct mplsLdpTlv_s baseTlv;
1417 u_char setPrio; /* 0 => most important path */
1418 u_char holdPrio; /* 0 => most important path */
1419 u_short res;
1421 } mplsLdpPreemptTlv_t;
1425 /***********************************************************************
1426 Resource class Tlv encoding
1428 0 1 2 3
1429 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1430 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1431 |U|F| ResCls-TLV (0x0822) | Length |
1432 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1433 | RsCls |
1434 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1435 ***********************************************************************/
1437 typedef struct mplsLdpResClsTlv_s
1439 struct mplsLdpTlv_s baseTlv;
1440 u_int rsCls; /* resource class bit mask */
1442 } mplsLdpResClsTlv_t;
1446 /***********************************************************************
1447 Lbl return message id Tlv encoding
1448 ***********************************************************************/
1450 typedef struct mplsLdpRetMsgIdTlv_s
1452 struct mplsLdpTlv_s baseTlv;
1454 } mplsLdpLblRetMsgIdTlv_t;
1458 /***********************************************************************
1459 ER flag structure which is common to IPV4 and IPV6 ER TLV
1460 ***********************************************************************/
1462 typedef struct mplsLdpErIPFlag_s
1464 BITFIELDS_ASCENDING_3( u_int l :1 , /* 0 => loose hop */
1465 u_int res :23,
1466 u_int preLen:8 )
1467 } mplsLdpErIPFlag_t;
1469 /***********************************************************************
1470 ER flag structure which is common to AS and LSPID ER TLV
1471 ***********************************************************************/
1472 typedef struct mplsLdpErFlag_s
1474 BITFIELDS_ASCENDING_2( u_short l :1 , /* 0 => loose hop */
1475 u_short res :15 )
1476 } mplsLdpErFlag_t;
1479 /***********************************************************************
1480 Explicit Routing IPv4 Tlv encoding
1482 0 1 2 3
1483 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1484 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1485 |U|F| 0x801 | Length |
1486 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1487 |L| Reserved | PreLen |
1488 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1489 | IPv4 Address (4 bytes) |
1490 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1491 ***********************************************************************/
1493 typedef struct mplsLdpErIpv4_s
1495 struct mplsLdpTlv_s baseTlv;
1496 union { struct mplsLdpErIPFlag_s flags;
1497 u_int mark;
1498 } flags;
1499 u_int address;
1501 } mplsLdpErIpv4_t;
1505 /***********************************************************************
1506 Explicit Routing IPv6 Tlv encoding
1508 0 1 2 3
1509 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1510 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1511 |U|F| 0x802 | Length |
1512 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1513 |L| Reserved | PreLen |
1514 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1515 | IPV6 address |
1516 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1517 | IPV6 address (continued) |
1518 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1519 | IPV6 address (continued) |
1520 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1521 | IPV6 address (continued) |
1522 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1523 ***********************************************************************/
1525 typedef struct mplsLdpErIpv6_s
1527 struct mplsLdpTlv_s baseTlv;
1528 union { struct mplsLdpErIPFlag_s flags;
1529 u_int mark;
1530 } flags;
1531 u_char address[MPLS_IPV6ADRLENGTH];
1533 } mplsLdpErIpv6_t;
1537 /***********************************************************************
1538 Explicit Routing Autonomous systen number Tlv encoding
1540 0 1 2 3
1541 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1542 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1543 |U|F| 0x803 | Length |
1544 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1545 |L| Reserved | AS Number |
1546 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1547 ***********************************************************************/
1549 typedef struct mplsLdpErAs_s
1551 struct mplsLdpTlv_s baseTlv;
1552 union { struct mplsLdpErFlag_s flags;
1553 u_short mark;
1554 } flags;
1555 u_short asNumber;
1557 } mplsLdpErAs_t;
1561 /***********************************************************************
1562 Explicit Routing LSPID Tlv encoding
1564 0 1 2 3
1565 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1566 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1567 |U|F| 0x804 | Length |
1568 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1569 |L| Reserved | Local LSPID |
1570 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1571 | Ingress LSR Router ID |
1572 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1573 ***********************************************************************/
1575 typedef struct mplsLdpErLspId_s
1577 struct mplsLdpTlv_s baseTlv;
1578 union { struct mplsLdpErFlag_s flags;
1579 u_short mark;
1580 } flags;
1581 u_short lspid;
1582 u_int routerId;
1584 } mplsLdpErLspId_t;
1588 /***********************************************************************
1589 Constraint Routing Tlv encoding
1591 0 1 2 3
1592 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1593 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1594 |U|F| ER-TLV (0x0800) | Length |
1595 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1596 | ER-Hop TLV 1 |
1597 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1598 | ER-Hop TLV 2 |
1599 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1600 ~ ............ ~
1601 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1602 | ER-Hop TLV n |
1603 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1604 ***********************************************************************/
1606 typedef union mplsLdpErHop_u
1608 struct mplsLdpErIpv4_s erIpv4;
1609 struct mplsLdpErIpv6_s erIpv6;
1610 struct mplsLdpErAs_s erAs;
1611 struct mplsLdpErLspId_s erLspId;
1613 } mplsLdpErHop_t;
1615 typedef struct mplsLdpErTlv_s
1617 struct mplsLdpTlv_s baseTlv;
1618 union mplsLdpErHop_u erHopArray[MPLS_MAX_ER_HOPS];
1619 u_short erHopTypes[MPLS_MAX_ER_HOPS]; /* need to know the
1620 types when handle
1621 the union */
1622 u_short numberErHops;
1624 } mplsLdpErTlv_t;
1628 /***********************************************************************
1629 Traffic parameters TLV
1631 0 1 2 3
1632 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1633 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1634 |U|F| Traf. Param. TLV (0x0810)| Length |
1635 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1636 | Flags | Frequency | Reserved | Weight |
1637 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1638 | Peak Data Rate (PDR) |
1639 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1640 | Peak Burst Size (PBS) |
1641 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1642 | Committed Data Rate (CDR) |
1643 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1644 | Committed Burst Size (CBS) |
1645 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1646 | Excess Burst Size (EBS) |
1647 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1649 Flag field:
1650 +--+--+--+--+--+--+--+--+
1651 | Res |F6|F5|F4|F3|F2|F1|
1652 +--+--+--+--+--+--+--+--+
1653 ***********************************************************************/
1655 typedef struct mplsLdpTrafficFlag_s
1657 BITFIELDS_ASCENDING_7( u_char res:2,
1658 u_char f6Bit:1,
1659 u_char f5Bit:1,
1660 u_char f4Bit:1,
1661 u_char f3Bit:1,
1662 u_char f2Bit:1,
1663 u_char f1Bit:1 )
1664 } mplsLdpTrafficFlag_t;
1666 typedef struct mplsLdpTrafficTlv_s
1668 struct mplsLdpTlv_s baseTlv;
1669 union { struct mplsLdpTrafficFlag_s flags;
1670 u_char mark;
1671 } flags;
1672 u_char freq;
1673 u_char res;
1674 u_char weight;
1675 union { float pdr;
1676 u_int mark;
1677 } pdr;
1678 union { float pbs;
1679 u_int mark;
1680 } pbs;
1681 union { float cdr;
1682 u_int mark;
1683 } cdr;
1684 union { float cbs;
1685 u_int mark;
1686 } cbs;
1687 union { float ebs;
1688 u_int mark;
1689 } ebs;
1691 } mplsLdpTrafficTlv_t;
1695 /***********************************************************************
1696 Route pinning TLV
1698 0 1 2 3
1699 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1700 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1701 |U|F| 0x823 | Length |
1702 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1703 |P| Reserved |
1704 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1705 ***********************************************************************/
1707 typedef struct mplsLdpPinningTlvFlag_s
1709 BITFIELDS_ASCENDING_2( u_int pBit:1, /* 1 => route pinning requested */
1710 u_int res:31 )
1711 } mplsLdpPinningTlvFlag_t;
1713 typedef struct mplsLdpPinningTlv_s
1715 struct mplsLdpTlv_s baseTlv;
1716 union { struct mplsLdpPinningTlvFlag_s flags;
1717 u_int mark;
1718 } flags;
1719 } mplsLdpPinningTlv_t;
1723 /***********************************************************************
1724 Label Mapping Message encoding
1726 0 1 2 3
1727 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1728 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1729 |U| Label Mapping (0x0400) | Message Length |
1730 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1731 | Message ID |
1732 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1733 | FEC TLV |
1734 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1735 | Label TLV |
1736 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1737 | Label Request Message ID TLV (mandatory) |
1738 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1739 | LSPID TLV (CR-LDP, mandatory) |
1740 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1741 | Traffic TLV (CR-LDP, optional) |
1742 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1743 ***********************************************************************/
1745 typedef struct mplsLdpLblMapMsg_s
1747 struct mplsLdpMsg_s baseMsg;
1749 /* FEC tlv */
1750 struct mplsLdpFecTlv_s fecTlv;
1752 /* Label TLV */
1753 struct mplsLdpGenLblTlv_s genLblTlv; /* generic label tlv */
1754 struct mplsLdpAtmLblTlv_s atmLblTlv; /* atm label tlv */
1755 struct mplsLdpFrLblTlv_s frLblTlv; /* fr label tlv */
1757 /* Optional parameters */
1758 struct mplsLdpHopTlv_s hopCountTlv; /* hop count tlv */
1759 struct mplsLdpPathTlv_s pathVecTlv; /* path vector tlv */
1760 struct mplsLdpLblMsgIdTlv_s lblMsgIdTlv; /* lbl msg id tlv */
1761 struct mplsLdpLspIdTlv_s lspidTlv; /* lspid tlv */
1762 struct mplsLdpTrafficTlv_s trafficTlv; /* traffic tlv */
1764 u_char fecTlvExists:1;
1765 u_char genLblTlvExists:1;
1766 u_char atmLblTlvExists:1;
1767 u_char frLblTlvExists:1;
1768 u_char hopCountTlvExists:1;
1769 u_char pathVecTlvExists:1;
1770 u_char lblMsgIdTlvExists:1;
1771 u_char lspidTlvExists:1;
1772 u_char trafficTlvExists:1;
1774 } mplsLdpLblMapMsg_t;
1778 /***********************************************************************
1779 Label Request Message encoding
1781 0 1 2 3
1782 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1783 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1784 |U| Label Request (0x0401) | Message Length |
1785 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1786 | Message ID |
1787 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1788 | FEC TLV |
1789 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1790 | Return Message ID TLV (mandatory) |
1791 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1792 | LSPID TLV (CR-LDP, mandatory) |
1793 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1794 | ER-TLV (CR-LDP, optional) |
1795 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1796 | Traffic TLV (CR-LDP, optional) |
1797 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1798 | Pinning TLV (CR-LDP, optional) |
1799 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1800 | Resource Class TLV (CR-LDP, optional) |
1801 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1802 | Pre-emption TLV (CR-LDP, optional) |
1803 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1804 ***********************************************************************/
1806 typedef struct mplsLdpLblReqMsg_s
1808 struct mplsLdpMsg_s baseMsg;
1810 /* FEC tlv */
1811 struct mplsLdpFecTlv_s fecTlv;
1813 /* Optional parameters */
1814 struct mplsLdpHopTlv_s hopCountTlv; /* hop count tlv */
1815 struct mplsLdpPathTlv_s pathVecTlv; /* path vector tlv */
1817 /* Optional parameters for CR */
1818 struct mplsLdpRetMsgIdTlv_s lblMsgIdTlv; /* lbl msg id tlv */
1819 struct mplsLdpErTlv_s erTlv; /* constraint rtg tlv*/
1820 struct mplsLdpTrafficTlv_s trafficTlv; /* traffic tlv */
1821 struct mplsLdpLspIdTlv_s lspidTlv; /* lspid tlv */
1822 struct mplsLdpPinningTlv_s pinningTlv; /* pinning tlv */
1823 struct mplsLdpResClsTlv_s resClassTlv; /* resource class tlv*/
1824 struct mplsLdpPreemptTlv_s preemptTlv; /* peemtion tlv */
1826 u_char fecTlvExists:1;
1827 u_char hopCountTlvExists:1;
1828 u_char pathVecTlvExists:1;
1829 u_char lblMsgIdTlvExists:1;
1830 u_char erTlvExists:1;
1831 u_char trafficTlvExists:1;
1832 u_char lspidTlvExists:1;
1833 u_char pinningTlvExists:1;
1834 u_char recClassTlvExists:1;
1835 u_char preemptTlvExists:1;
1837 } mplsLdpLblReqMsg_t;
1841 /***********************************************************************
1843 Label Withdraw Message encoding
1845 0 1 2 3
1846 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1847 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1848 |U| Label Withdraw (0x0402) | Message Length |
1849 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1850 | Message ID |
1851 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1852 | FEC TLV |
1853 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1854 | Label TLV (optional) |
1855 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1856 | LSPID TLV (optional for CR-LDP) |
1857 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1861 Label Release Message encoding
1863 0 1 2 3
1864 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1865 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1866 |U| Label Release (0x0403) | Message Length |
1867 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1868 | Message ID |
1869 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1870 | FEC TLV |
1871 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1872 | Label TLV (optional) |
1873 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1874 | LSPID TLV (optional for CR-LDP) |
1875 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1877 Note: the Label Withdraw Message encoding and the Label Release Message enc
1878 look very much the same. I will create only one type of struct for
1879 both message types.
1880 The Label Withdraw Message and Label Release Message can optionally
1881 carry LSPID TLV.
1882 ***********************************************************************/
1884 typedef struct mplsLdpLbl_W_R_Msg_s
1886 struct mplsLdpMsg_s baseMsg;
1888 /* FEC tlv */
1889 struct mplsLdpFecTlv_s fecTlv;
1891 /* Label TLV */
1892 struct mplsLdpGenLblTlv_s genLblTlv; /* generic label tlv */
1893 struct mplsLdpAtmLblTlv_s atmLblTlv; /* atm label tlv */
1894 struct mplsLdpFrLblTlv_s frLblTlv; /* fr label tlv */
1895 struct mplsLdpLspIdTlv_s lspidTlv; /* lspid tlv */
1898 u_char fecTlvExists:1;
1899 u_char genLblTlvExists:1;
1900 u_char atmLblTlvExists:1;
1901 u_char frLblTlvExists:1;
1902 u_char lspidTlvExists:1;
1904 } mplsLdpLbl_W_R_Msg_t;
1908 /***********************************************************************
1909 Label Abort Request Message encoding
1911 0 1 2 3
1912 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1913 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1914 |U| Label Abort Req (0x0404) | Message Length |
1915 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1916 | Message ID |
1917 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1918 | FEC TLV |
1919 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1920 | Label Request Message ID TLV |
1921 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1922 ***********************************************************************/
1924 typedef struct mplsLdpLblAbortMsg_s
1926 struct mplsLdpMsg_s baseMsg;
1928 struct mplsLdpFecTlv_s fecTlv; /* fec tlv */
1929 struct mplsLdpLblMsgIdTlv_s lblMsgIdTlv; /* lbl msg id tlv */
1931 u_char fecTlvExists:1;
1932 u_char lblMsgIdTlvExists:1;
1934 } mplsLdpLblAbortMsg_t;
1938 /***********************************************************************
1944 * Function declarations
1946 * Note: Encode functions return the length of the data which was encoded.
1947 * The first argument (which is a pointer to the structure which
1948 * contains the data to be encoded) is not modified in the encode functions
1949 * which encode the messages and message headers. All the other encode
1950 * fuctions modify the content of the structures to be encoded (tlvs,
1951 * message parameters, etc).
1953 * Decode functions for tlv return the length of the value.
1956 int Mpls_encodeLdpMsgHeader (mplsLdpHeader_t *, u_char *, int);
1957 int Mpls_decodeLdpMsgHeader (mplsLdpHeader_t *, u_char *, int);
1958 int Mpls_encodeLdpAtmLblRng (mplsLdpAtmLblRng_t *, u_char *, int);
1959 int Mpls_decodeLdpAtmLblRng (mplsLdpAtmLblRng_t *, u_char *, int);
1960 int Mpls_encodeLdpAsp (mplsLdpAspTlv_t *, u_char *, int);
1961 int Mpls_decodeLdpAsp (mplsLdpAspTlv_t *, u_char *, int);
1962 int Mpls_encodeLdpTlv (mplsLdpTlv_t *, u_char *, int);
1963 int Mpls_decodeLdpTlv (mplsLdpTlv_t *, u_char *, int);
1964 int Mpls_encodeLdpInitMsg (mplsLdpInitMsg_t *, u_char *, int);
1965 int Mpls_decodeLdpInitMsg (mplsLdpInitMsg_t *, u_char *, int);
1966 int Mpls_encodeLdpCsp (mplsLdpCspTlv_t *, u_char *, int);
1967 int Mpls_decodeLdpCsp (mplsLdpCspTlv_t *, u_char *, int);
1968 int Mpls_encodeLdpBaseMsg (mplsLdpMsg_t *, u_char *, int);
1969 int Mpls_decodeLdpBaseMsg (mplsLdpMsg_t *, u_char *, int);
1970 int Mpls_encodeLdpFrLblRng (mplsLdpFrLblRng_t *, u_char *, int);
1971 int Mpls_decodeLdpFrLblRng (mplsLdpFrLblRng_t *, u_char *, int);
1972 int Mpls_encodeLdpFsp (mplsLdpFspTlv_t *, u_char *, int);
1973 int Mpls_decodeLdpFsp (mplsLdpFspTlv_t *, u_char *, int);
1974 int Mpls_encodeLdpNotMsg (mplsLdpNotifMsg_t *, u_char *, int);
1975 int Mpls_decodeLdpNotMsg (mplsLdpNotifMsg_t *, u_char *, int);
1976 int Mpls_encodeLdpStatus (mplsLdpStatusTlv_t *, u_char *, int);
1977 int Mpls_decodeLdpStatus (mplsLdpStatusTlv_t *, u_char *, int);
1978 int Mpls_encodeLdpExStatus (mplsLdpExStatusTlv_t *, u_char *, int);
1979 int Mpls_decodeLdpExStatus (mplsLdpExStatusTlv_t *, u_char *, int);
1980 int Mpls_encodeLdpRetPdu (mplsLdpRetPduTlv_t *, u_char *, int);
1981 int Mpls_decodeLdpRetPdu (mplsLdpRetPduTlv_t *, u_char *, int, u_short);
1982 int Mpls_encodeLdpRetMsg (mplsLdpRetMsgTlv_t *, u_char *, int);
1983 int Mpls_decodeLdpRetMsg (mplsLdpRetMsgTlv_t *, u_char *, int, u_short);
1984 int Mpls_encodeLdpHelloMsg (mplsLdpHelloMsg_t *, u_char *, int);
1985 int Mpls_decodeLdpHelloMsg (mplsLdpHelloMsg_t *, u_char *, int);
1986 int Mpls_encodeLdpChp (mplsLdpChpTlv_t *, u_char *, int);
1987 int Mpls_decodeLdpChp (mplsLdpChpTlv_t *, u_char *, int);
1988 int Mpls_encodeLdpCsn (mplsLdpCsnTlv_t *, u_char *, int);
1989 int Mpls_decodeLdpCsn (mplsLdpCsnTlv_t *, u_char *, int);
1990 int Mpls_encodeLdpTrAdr (mplsLdpTrAdrTlv_t *, u_char *, int);
1991 int Mpls_decodeLdpTrAdr (mplsLdpTrAdrTlv_t *, u_char *, int);
1992 int Mpls_encodeLdpKeepAliveMsg (mplsLdpKeepAlMsg_t *, u_char *, int);
1993 int Mpls_decodeLdpKeepAliveMsg (mplsLdpKeepAlMsg_t *, u_char *, int);
1994 int Mpls_encodeLdpAdrTlv (mplsLdpAdrTlv_t *, u_char *, int);
1995 int Mpls_decodeLdpAdrTlv (mplsLdpAdrTlv_t *, u_char *, int, u_short);
1996 int Mpls_encodeLdpAdrMsg (mplsLdpAdrMsg_t *, u_char *, int);
1997 int Mpls_decodeLdpAdrMsg (mplsLdpAdrMsg_t *, u_char *, int);
1998 int Mpls_encodeLdpFecTlv (mplsLdpFecTlv_t *, u_char *, int);
1999 int Mpls_decodeLdpFecTlv (mplsLdpFecTlv_t *, u_char *, int, u_short);
2000 int Mpls_encodeLdpGenLblTlv (mplsLdpGenLblTlv_t *, u_char *, int);
2001 int Mpls_decodeLdpGenLblTlv (mplsLdpGenLblTlv_t *, u_char *, int);
2002 int Mpls_encodeLdpAtmLblTlv (mplsLdpAtmLblTlv_t *, u_char *, int);
2003 int Mpls_decodeLdpAtmLblTlv (mplsLdpAtmLblTlv_t *, u_char *, int);
2004 int Mpls_encodeLdpFrLblTlv (mplsLdpFrLblTlv_t *, u_char *, int);
2005 int Mpls_decodeLdpFrLblTlv (mplsLdpFrLblTlv_t *, u_char *, int);
2006 int Mpls_encodeLdpHopTlv (mplsLdpHopTlv_t *, u_char *, int);
2007 int Mpls_decodeLdpHopTlv (mplsLdpHopTlv_t *, u_char *, int);
2008 int Mpls_encodeLdpLblMsgIdTlv (mplsLdpLblMsgIdTlv_t *, u_char *, int);
2009 int Mpls_decodeLdpLblMsgIdTlv (mplsLdpLblMsgIdTlv_t *, u_char *, int);
2010 int Mpls_encodeLdpPathVectorTlv (mplsLdpPathTlv_t *, u_char *, int);
2011 int Mpls_decodeLdpPathVectorTlv (mplsLdpPathTlv_t *, u_char *, int, u_short);
2012 int Mpls_encodeLdpLblMapMsg (mplsLdpLblMapMsg_t *, u_char *, int);
2013 int Mpls_decodeLdpLblMapMsg (mplsLdpLblMapMsg_t *, u_char *, int);
2014 int Mpls_encodeLdpFecAdrEl (mplsFecElement_t *, u_char *, int ,u_char);
2015 int Mpls_decodeLdpFecAdrEl (mplsFecElement_t *, u_char *, int ,u_char);
2016 int Mpls_encodeLdpLblRetMsgIdTlv (mplsLdpLblRetMsgIdTlv_t *, u_char *, int);
2017 int Mpls_decodeLdpLblRetMsgIdTlv (mplsLdpLblRetMsgIdTlv_t *, u_char *, int);
2018 int Mpls_encodeLdpLbl_W_R_Msg (mplsLdpLbl_W_R_Msg_t *, u_char *, int);
2019 int Mpls_decodeLdpLbl_W_R_Msg (mplsLdpLbl_W_R_Msg_t *, u_char *, int);
2020 int Mpls_encodeLdpERTlv (mplsLdpErTlv_t *, u_char *, int);
2021 int Mpls_decodeLdpERTlv (mplsLdpErTlv_t *, u_char *, int, u_short);
2022 int Mpls_encodeLdpErHop (mplsLdpErHop_t *, u_char *, int, u_short);
2023 int Mpls_decodeLdpErHop (mplsLdpErHop_t *, u_char *, int, u_short *);
2024 int Mpls_encodeLdpTrafficTlv (mplsLdpTrafficTlv_t *, u_char *, int);
2025 int Mpls_decodeLdpTrafficTlv (mplsLdpTrafficTlv_t *, u_char *, int, u_short);
2026 int Mpls_encodeLdpLblReqMsg (mplsLdpLblReqMsg_t *, u_char *, int);
2027 int Mpls_decodeLdpLblReqMsg (mplsLdpLblReqMsg_t *, u_char *, int);
2028 int Mpls_encodeLdpPreemptTlv (mplsLdpPreemptTlv_t *, u_char *, int);
2029 int Mpls_decodeLdpPreemptTlv (mplsLdpPreemptTlv_t *, u_char *, int);
2030 int Mpls_encodeLdpLspIdTlv (mplsLdpLspIdTlv_t *, u_char *, int);
2031 int Mpls_decodeLdpLspIdTlv (mplsLdpLspIdTlv_t *, u_char *, int);
2032 int Mpls_encodeLdpResClsTlv (mplsLdpResClsTlv_t *, u_char *, int);
2033 int Mpls_decodeLdpResClsTlv (mplsLdpResClsTlv_t *, u_char *, int);
2034 int Mpls_encodeLdpPinningTlv (mplsLdpPinningTlv_t *, u_char *, int);
2035 int Mpls_decodeLdpPinningTlv (mplsLdpPinningTlv_t *, u_char *, int);
2036 int Mpls_encodeLdpLblAbortMsg (mplsLdpLblAbortMsg_t *, u_char *, int);
2037 int Mpls_decodeLdpLblAbortMsg (mplsLdpLblAbortMsg_t *, u_char *, int);
2044 * DEBUG function declarations
2047 void printTlv (mplsLdpTlv_t *);
2048 void printHeader (mplsLdpHeader_t *);
2049 void printCspFlags (mplsLdpCspFlag_t *);
2050 void printCspFlagsPerByte (u_short *);
2051 void printCspTlv (mplsLdpCspTlv_t *);
2052 void printAspFlags (mplsLdpSPFlag_t *);
2053 void printAspFlagsPerByte (u_int *);
2054 void printAspTlv (mplsLdpAspTlv_t *);
2055 void printFspFlags (mplsLdpSPFlag_t *);
2056 void printFspTlv (mplsLdpFspTlv_t *);
2057 void printInitMsg (mplsLdpInitMsg_t *);
2058 void printRetMsgTlv (mplsLdpRetMsgTlv_t *);
2059 void printRetPduTlv (mplsLdpRetPduTlv_t *);
2060 void printExStatusTlv (mplsLdpExStatusTlv_t *);
2061 void printStatusTlv (mplsLdpStatusTlv_t *);
2062 void printNotMsg (mplsLdpNotifMsg_t *);
2063 void printCsnTlv (mplsLdpCsnTlv_t *);
2064 void printTrAdrTlv (mplsLdpTrAdrTlv_t *);
2065 void printChpTlv (mplsLdpChpTlv_t *);
2066 void printHelloMsg (mplsLdpHelloMsg_t *);
2067 void printKeepAliveMsg (mplsLdpKeepAlMsg_t *);
2068 void printAdrListTlv (mplsLdpAdrTlv_t *);
2069 void printAddressMsg (mplsLdpAdrMsg_t *);
2070 void printFecListTlv (mplsLdpFecTlv_t *);
2071 void printLblMsgIdTlv (mplsLdpLblMsgIdTlv_t *);
2072 void printPathVecTlv (mplsLdpPathTlv_t *);
2073 void printHopTlv (mplsLdpHopTlv_t *);
2074 void printFrLblTlv (mplsLdpFrLblTlv_t *);
2075 void printAtmLblTlv (mplsLdpAtmLblTlv_t *);
2076 void printGenLblTlv (mplsLdpGenLblTlv_t *);
2077 void printLlbMapMsg (mplsLdpLblMapMsg_t *);
2078 void printErFlags (mplsLdpErFlag_t *);
2079 void printErIPFlags (mplsLdpErIPFlag_t *);
2080 void printErTlv (mplsLdpErTlv_t *);
2081 void printTrafficTlv (mplsLdpTrafficTlv_t *);
2082 void printLlbReqMsg (mplsLdpLblReqMsg_t *);
2083 void printAtmLabel (mplsLdpAtmLblRng_t *, int);
2084 void printFspLabel (mplsLdpFrLblRng_t *, int);
2085 void printErHop (mplsLdpErHop_t *, u_short);
2086 void printLbl_W_R_Msg (mplsLdpLbl_W_R_Msg_t *);
2087 void printPreemptTlv (mplsLdpPreemptTlv_t *);
2088 void printLspIdTlv (mplsLdpLspIdTlv_t *);
2089 void printResClsTlv (mplsLdpResClsTlv_t *);
2090 void printPinningTlv (mplsLdpPinningTlv_t *);
2091 void printLlbAbortMsg (mplsLdpLblAbortMsg_t *);
2093 int converAsciiToHex (u_char *, int, u_char *);
2094 int converHexToAscii (u_char *, int, u_char *);
2098 int main(void)
2100 mplsLdpHeader_t testHeaderDecode;
2101 u_char buff[10000];
2102 u_char buffHex[20002];
2103 u_char * startPtr;
2104 u_char currentChar;
2105 u_short totalSize;
2106 u_short type = 0;
2107 int encodedSize, sizeBuf;
2108 int continueRead;
2109 int n = 0;
2111 bzero(buffHex, 600);
2112 bzero(buff, 600);
2114 sizeBuf = sizeof(buff);
2116 /* the buffer should not contain blanks or invalid hex caracters */
2117 printf("Please provide the buffer (in hex). The buffer should end with 'q'!\n");
2118 continueRead = 1;
2120 scanf("%c", &currentChar);
2121 if ( currentChar == 'q')
2123 continueRead = 0;
2125 buffHex[n++] = currentChar;
2126 } while( continueRead);
2128 PRINT_2("n = %d\n", n-1);
2130 n = converHexToAscii(buffHex, n-1, buff);
2131 /*converAsciiToHex(buffHex, n, buff);*/
2132 PRINT_2("read %d chars \n", n);
2134 startPtr = buff;
2136 encodedSize = Mpls_decodeLdpMsgHeader( &testHeaderDecode,
2137 startPtr,
2139 if (encodedSize < 0)
2141 printf("Failed while decoding HEADER\n");
2142 return 0;
2144 DEBUG_CALL(printHeader(&testHeaderDecode));
2145 startPtr += encodedSize;
2147 totalSize = 0;
2148 if (testHeaderDecode.pduLength > sizeof(buff))
2150 PRINT_ERR("Buffer too small. Decoding failed\n");
2151 return 0;
2153 while(totalSize < (u_short)(testHeaderDecode.pduLength-6))
2155 /* found the message type */
2156 MEM_COPY((u_char*)&type, startPtr, 2);
2157 type = ntohs(type) & 0x7fff; /* ignore the U bit for now */
2158 PRINT_2("Found type %x\n", type);
2160 switch(type)
2162 case MPLS_INIT_MSGTYPE:
2164 MPLS_MSGSTRUCT(Init);
2165 encodedSize = Mpls_decodeLdpInitMsg( &MPLS_MSGPARAM(Init),
2166 startPtr,
2167 n-MPLS_LDP_HDRSIZE-totalSize);
2168 PRINT_2("decodedSize for Init msg = %d\n", encodedSize);
2169 if (encodedSize < 0)
2171 return 0;
2173 DEBUG_CALL(printInitMsg(&MPLS_MSGPARAM(Init)));
2174 totalSize += encodedSize;
2175 startPtr += encodedSize;
2176 break;
2178 case MPLS_NOT_MSGTYPE:
2180 MPLS_MSGSTRUCT(Notif);
2181 encodedSize = Mpls_decodeLdpNotMsg( &MPLS_MSGPARAM(Notif),
2182 startPtr,
2183 n-MPLS_LDP_HDRSIZE-totalSize);
2184 PRINT_2("decodedSize for Notif msg = %d\n", encodedSize);
2185 if (encodedSize < 0)
2187 return 0;
2189 DEBUG_CALL(printNotMsg(&MPLS_MSGPARAM(Notif)));
2190 totalSize += encodedSize;
2191 startPtr += encodedSize;
2192 break;
2194 case MPLS_KEEPAL_MSGTYPE:
2196 MPLS_MSGSTRUCT(KeepAl);
2197 encodedSize = Mpls_decodeLdpKeepAliveMsg(&MPLS_MSGPARAM(KeepAl),
2198 startPtr,
2199 n-MPLS_LDP_HDRSIZE-totalSize);
2200 PRINT_2("decodedSize for KeepAlive msg = %d\n", encodedSize);
2201 if (encodedSize < 0)
2203 return 0;
2205 DEBUG_CALL(printKeepAliveMsg(&MPLS_MSGPARAM(KeepAl)));
2206 totalSize += encodedSize;
2207 startPtr += encodedSize;
2208 break;
2210 case MPLS_HELLO_MSGTYPE:
2212 MPLS_MSGSTRUCT(Hello);
2213 encodedSize = Mpls_decodeLdpHelloMsg( &MPLS_MSGPARAM(Hello),
2214 startPtr,
2215 n-MPLS_LDP_HDRSIZE-totalSize);
2216 PRINT_2("decodedSize for Hello msg = %d\n", encodedSize);
2217 if (encodedSize < 0)
2219 return 0;
2221 DEBUG_CALL(printHelloMsg(&MPLS_MSGPARAM(Hello)));
2222 totalSize += encodedSize;
2223 startPtr += encodedSize;
2224 break;
2226 case MPLS_LBLREQ_MSGTYPE:
2228 MPLS_MSGSTRUCT(LblReq);
2229 encodedSize = Mpls_decodeLdpLblReqMsg( &MPLS_MSGPARAM(LblReq),
2230 startPtr,
2231 n-MPLS_LDP_HDRSIZE-totalSize);
2232 PRINT_2("decodedSize for Req msg = %d\n", encodedSize);
2233 if (encodedSize < 0)
2235 return 0;
2237 DEBUG_CALL(printLlbReqMsg(&MPLS_MSGPARAM(LblReq)));
2238 totalSize += encodedSize;
2239 startPtr += encodedSize;
2240 break;
2242 case MPLS_LBLMAP_MSGTYPE:
2244 MPLS_MSGSTRUCT(LblMap);
2245 encodedSize = Mpls_decodeLdpLblMapMsg( &MPLS_MSGPARAM(LblMap),
2246 startPtr,
2247 n-MPLS_LDP_HDRSIZE-totalSize);
2248 PRINT_2("decodedSize for Map msg = %d\n", encodedSize);
2249 if (encodedSize < 0)
2251 return 0;
2253 DEBUG_CALL(printLlbMapMsg(&MPLS_MSGPARAM(LblMap)));
2254 totalSize += encodedSize;
2255 startPtr += encodedSize;
2256 break;
2258 case MPLS_ADDR_MSGTYPE:
2259 case MPLS_ADDRWITH_MSGTYPE:
2261 MPLS_MSGSTRUCT(Adr);
2262 encodedSize = Mpls_decodeLdpAdrMsg( &MPLS_MSGPARAM(Adr),
2263 startPtr,
2264 n-MPLS_LDP_HDRSIZE-totalSize);
2265 PRINT_2("decodedSize for Adr msg = %d\n", encodedSize);
2266 if (encodedSize < 0)
2268 return 0;
2270 DEBUG_CALL(printAddressMsg(&MPLS_MSGPARAM(Adr)));
2271 totalSize += encodedSize;
2272 startPtr += encodedSize;
2273 break;
2275 case MPLS_LBLWITH_MSGTYPE:
2276 case MPLS_LBLREL_MSGTYPE:
2278 MPLS_MSGSTRUCT(Lbl_W_R_);
2279 encodedSize = Mpls_decodeLdpLbl_W_R_Msg( &MPLS_MSGPARAM(Lbl_W_R_),
2280 startPtr,
2281 n-MPLS_LDP_HDRSIZE-totalSize);
2282 PRINT_2("decodedSize for Lbl Release/Mapping msg = %d\n", encodedSize);
2283 if (encodedSize < 0)
2285 return 0;
2287 DEBUG_CALL(printLbl_W_R_Msg(&MPLS_MSGPARAM(Lbl_W_R_)));
2288 totalSize += encodedSize;
2289 startPtr += encodedSize;
2290 break;
2292 case MPLS_LBLABORT_MSGTYPE:
2294 MPLS_MSGSTRUCT(LblAbort);
2295 encodedSize = Mpls_decodeLdpLblAbortMsg( &MPLS_MSGPARAM(LblAbort),
2296 startPtr,
2297 n-MPLS_LDP_HDRSIZE-totalSize);
2298 PRINT_2("decodedSize for Abort msg = %d\n", encodedSize);
2299 if (encodedSize < 0)
2301 return 0;
2303 DEBUG_CALL(printLlbAbortMsg(&MPLS_MSGPARAM(LblAbort)));
2304 totalSize += encodedSize;
2305 startPtr += encodedSize;
2306 break;
2308 default:
2310 PRINT_ERR_2("Unknown message type = %x\n", type);
2311 return 0;
2313 } /* switch */
2314 } /* while */
2316 return 1;
2323 * Encode-decode for Ldp Msg Header
2327 * Encode:
2329 int Mpls_encodeLdpMsgHeader
2331 mplsLdpHeader_t * header,
2332 u_char * buff,
2333 int bufSize
2336 mplsLdpHeader_t headerCopy;
2338 if (MPLS_LDP_HDRSIZE > bufSize)
2340 /* not enough room for header */
2341 return MPLS_ENC_BUFFTOOSMALL;
2344 headerCopy = *header;
2345 headerCopy.protocolVersion = htons(headerCopy.protocolVersion);
2346 headerCopy.pduLength = htons(headerCopy.pduLength);
2347 headerCopy.lsrAddress = htonl(headerCopy.lsrAddress);
2348 headerCopy.labelSpace = htons(headerCopy.labelSpace);
2350 MEM_COPY(buff, (u_char *)&headerCopy, MPLS_LDP_HDRSIZE);
2352 return MPLS_LDP_HDRSIZE;
2354 } /* End : Mpls_encodeLdpMsgHeader */
2357 * Decode:
2359 int Mpls_decodeLdpMsgHeader
2361 mplsLdpHeader_t * header,
2362 u_char * buff,
2363 int bufSize
2366 if (MPLS_LDP_HDRSIZE > bufSize)
2368 return MPLS_DEC_BUFFTOOSMALL;
2371 MEM_COPY((u_char *)header, buff, MPLS_LDP_HDRSIZE);
2373 header->protocolVersion = ntohs(header->protocolVersion);
2374 header->pduLength = ntohs(header->pduLength);
2375 header->lsrAddress = ntohl(header->lsrAddress);
2376 header->labelSpace = ntohs(header->labelSpace);
2378 /* check if the length is over the max length */
2379 if (header->pduLength > MPLS_PDUMAXLEN)
2381 return MPLS_PDU_LENGTH_ERROR;
2384 return MPLS_LDP_HDRSIZE;
2386 } /* End: Mpls_decodeLdpMsgHeader */
2392 * Encode-decode for Ldp Base Message
2396 * Encode:
2398 int Mpls_encodeLdpBaseMsg
2400 mplsLdpMsg_t * ldpMsg,
2401 u_char * buff,
2402 int bufSize
2405 if (MPLS_MSGIDFIXLEN + MPLS_TLVFIXLEN > bufSize)
2407 /* not enough room for header */
2408 return MPLS_ENC_BUFFTOOSMALL;
2411 ldpMsg->flags.mark = htons(ldpMsg->flags.mark);
2412 ldpMsg->msgLength = htons(ldpMsg->msgLength);
2413 ldpMsg->msgId = htonl(ldpMsg->msgId);
2415 MEM_COPY(buff, (u_char *)ldpMsg, MPLS_MSGIDFIXLEN + MPLS_TLVFIXLEN);
2417 return (MPLS_MSGIDFIXLEN + MPLS_TLVFIXLEN);
2419 } /* End : Mpls_encodeLdpBaseMsg*/
2422 * Decode:
2424 int Mpls_decodeLdpBaseMsg
2426 mplsLdpMsg_t * ldpMsg,
2427 u_char * buff,
2428 int bufSize
2431 if (MPLS_MSGIDFIXLEN + MPLS_TLVFIXLEN > bufSize)
2433 return MPLS_DEC_BUFFTOOSMALL;
2436 MEM_COPY((u_char *)ldpMsg, buff, MPLS_MSGIDFIXLEN + MPLS_TLVFIXLEN);
2438 ldpMsg->flags.mark = ntohs(ldpMsg->flags.mark);
2439 ldpMsg->msgLength = ntohs(ldpMsg->msgLength);
2440 ldpMsg->msgId = ntohl(ldpMsg->msgId);
2442 return MPLS_MSGIDFIXLEN + MPLS_TLVFIXLEN;
2444 } /* End: Mpls_decodeLdpBaseMsg */
2448 * Encode-decode for ATM Label Range Component
2452 * encode:
2454 int Mpls_encodeLdpAtmLblRng
2456 mplsLdpAtmLblRng_t * atmLbl,
2457 u_char * buff,
2458 int bufSize
2461 if (MPLS_ATMLRGFIXLEN > bufSize)
2463 /* not enough room for label */
2464 return MPLS_ENC_BUFFTOOSMALL;
2467 atmLbl->flags.flags.res1 = 0;
2468 atmLbl->flags.flags.res2 = 0;
2469 atmLbl->flags.mark[0] = htonl(atmLbl->flags.mark[0]);
2470 atmLbl->flags.mark[1] = htonl(atmLbl->flags.mark[1]);
2472 MEM_COPY(buff, (u_char *)atmLbl, MPLS_ATMLRGFIXLEN);
2474 return MPLS_ATMLRGFIXLEN;
2476 } /* End Mpls_encodeLdpAtmLblRng */
2480 * decode:
2482 int Mpls_decodeLdpAtmLblRng
2484 mplsLdpAtmLblRng_t * atmLbl,
2485 u_char * buff,
2486 int bufSize
2489 if (MPLS_ATMLRGFIXLEN > bufSize)
2491 PRINT_ERR("failed decoding the Atm Lbl Rng\n");
2492 return MPLS_DEC_BUFFTOOSMALL;
2495 MEM_COPY((u_char *)atmLbl, buff, MPLS_ATMLRGFIXLEN);
2497 atmLbl->flags.mark[0] = ntohl(atmLbl->flags.mark[0]);
2498 atmLbl->flags.mark[1] = ntohl(atmLbl->flags.mark[1]);
2500 return MPLS_ATMLRGFIXLEN;
2502 } /* End Mpls_decodeLdpAtmLblRng */
2509 * Encode-decode for ATM Session Parameters
2513 * encode:
2515 int Mpls_encodeLdpAsp
2517 mplsLdpAspTlv_t * atmAsp,
2518 u_char * buff,
2519 int bufSize
2522 u_int encodedSize = 0;
2523 u_short totalSize = 0;
2524 u_char * tempBuf = buff; /* no change for the buff ptr */
2525 u_int i, numLblRng;
2527 /* get the size of the atmAsp to be encoded and check it against
2528 the buffer size */
2530 if (MPLS_TLVFIXLEN + (int)(atmAsp->baseTlv.length)> bufSize)
2532 /* not enough room */
2533 return MPLS_ENC_BUFFTOOSMALL;
2537 * encode for tlv
2539 encodedSize = Mpls_encodeLdpTlv( &(atmAsp->baseTlv),
2540 tempBuf,
2541 bufSize);
2542 if (encodedSize < 0)
2544 return MPLS_ENC_TLVERROR;
2546 tempBuf += encodedSize;
2547 totalSize += encodedSize;
2550 * encode for M + N + D + res
2552 numLblRng = atmAsp->flags.flags.numLblRng;
2553 atmAsp->flags.flags.res = 0;
2554 atmAsp->flags.mark = htonl(atmAsp->flags.mark);
2556 MEM_COPY( tempBuf,
2557 (u_char*)&(atmAsp->flags.mark),
2558 MPLS_ASPFIXLEN );
2559 tempBuf += MPLS_ASPFIXLEN;
2560 totalSize += MPLS_ASPFIXLEN;
2563 * encode for ATM labels
2565 for (i = 0; i < numLblRng; i++)
2567 encodedSize = Mpls_encodeLdpAtmLblRng( &(atmAsp->lblRngList[i]),
2568 tempBuf,
2569 bufSize-totalSize);
2570 if (encodedSize < 0)
2572 return MPLS_ENC_ATMLBLERROR;
2574 tempBuf += encodedSize;
2575 totalSize += encodedSize;
2578 return totalSize;
2580 } /* End Mpls_encodeLdpAsp */
2584 * decode:
2586 int Mpls_decodeLdpAsp
2588 mplsLdpAspTlv_t * atmAsp,
2589 u_char * buff,
2590 int bufSize
2593 int decodedSize = 0;
2594 u_short totalSize = 0;
2595 u_char * tempBuf = buff; /* no change for the buff ptr */
2596 u_int i;
2598 if (MPLS_ASPFIXLEN > bufSize)
2600 /* the buffer does not contain even the required field*/
2601 PRINT_ERR("failed in decoding LdpAsp\n");
2602 return MPLS_DEC_BUFFTOOSMALL;
2606 * decode for M + N + D + res
2608 MEM_COPY((u_char *)&(atmAsp->flags.mark), tempBuf, MPLS_ASPFIXLEN);
2609 tempBuf += MPLS_ASPFIXLEN;
2610 totalSize += MPLS_ASPFIXLEN;
2612 atmAsp->flags.mark = ntohl(atmAsp->flags.mark);
2615 * decode for ATM labels
2617 for (i = 0; i < atmAsp->flags.flags.numLblRng; i++)
2619 decodedSize = Mpls_decodeLdpAtmLblRng( &(atmAsp->lblRngList[i]),
2620 tempBuf,
2621 bufSize - totalSize);
2622 if (decodedSize < 0)
2624 PRINT_ERR_2("failed in decoding LdpAtmLabel[%d] for LdpAsp\n", i);
2625 return MPLS_DEC_ATMLBLERROR;
2627 tempBuf += decodedSize;
2628 totalSize += decodedSize;
2631 return totalSize;
2633 } /* End Mpls_decodeLdpAsp */
2638 * Encode-decode for TLV
2642 * encode:
2644 int Mpls_encodeLdpTlv
2646 mplsLdpTlv_t * tlv,
2647 u_char * buff,
2648 int bufSize
2651 if (MPLS_TLVFIXLEN > bufSize)
2653 /* not enough room for label */
2654 return MPLS_ENC_BUFFTOOSMALL;
2657 tlv->flags.mark = htons(tlv->flags.mark);
2658 tlv->length = htons(tlv->length);
2660 MEM_COPY(buff, (u_char *)tlv, MPLS_TLVFIXLEN);
2662 return MPLS_TLVFIXLEN;
2664 } /* End: Mpls_encodeLdpTlv */
2668 * decode:
2670 int Mpls_decodeLdpTlv
2672 mplsLdpTlv_t * tlv,
2673 u_char * buff,
2674 int bufSize
2677 if (MPLS_TLVFIXLEN > bufSize)
2679 PRINT_ERR("Failed decoding TLV\n");
2680 return MPLS_DEC_BUFFTOOSMALL;
2683 MEM_COPY((u_char *)tlv, buff, MPLS_TLVFIXLEN);
2685 tlv->flags.mark = ntohs(tlv->flags.mark);
2686 tlv->length = ntohs(tlv->length);
2688 return MPLS_TLVFIXLEN;
2690 } /* End: Mpls_decodeLdpTlv */
2696 * Encode-decode for CSP (common session param)
2700 * encode:
2702 int Mpls_encodeLdpCsp
2704 mplsLdpCspTlv_t * csp,
2705 u_char * buff,
2706 int bufSize
2709 u_int encodedSize = 0;
2710 u_char * tempBuf = buff; /* no change for the buff ptr */
2711 u_char * cspPtr;
2713 if (MPLS_CSPFIXLEN + MPLS_TLVFIXLEN > bufSize)
2715 /* not enough room */
2716 return MPLS_ENC_BUFFTOOSMALL;
2719 cspPtr = (u_char *)csp;
2722 * encode for tlv
2724 encodedSize = Mpls_encodeLdpTlv( &(csp->baseTlv),
2725 tempBuf,
2726 bufSize);
2727 if (encodedSize < 0)
2729 PRINT_ERR("failed encoding the tlv in CSP\n");
2730 return MPLS_ENC_TLVERROR;
2732 tempBuf += encodedSize;
2733 cspPtr += encodedSize;
2736 * encode for the rest of the Csp
2738 csp->protocolVersion = htons(csp->protocolVersion);
2739 csp->holdTime = htons(csp->holdTime);
2740 csp->flags.mark = htons(csp->flags.mark);
2741 csp->maxPduLen = htons(csp->maxPduLen);
2742 csp->rcvLsrAddress = htonl(csp->rcvLsrAddress);
2743 csp->rcvLsId = htons(csp->rcvLsId);
2745 MEM_COPY(tempBuf,
2746 cspPtr,
2747 MPLS_CSPFIXLEN);
2749 return (MPLS_CSPFIXLEN + MPLS_TLVFIXLEN);
2751 } /* End: Mpls_encodeLdpCsp*/
2755 * decode:
2757 int Mpls_decodeLdpCsp
2759 mplsLdpCspTlv_t * csp,
2760 u_char * buff,
2761 int bufSize
2764 u_char * cspPtr;
2766 if (MPLS_CSPFIXLEN > bufSize)
2768 /* not enough data for Csp */
2769 PRINT_ERR("failed decoding LdpCsp\n");
2770 return MPLS_DEC_BUFFTOOSMALL;
2773 cspPtr = (u_char *)csp;
2774 cspPtr += MPLS_TLVFIXLEN; /* we want to point to the flags since the
2775 tlv was decoded before we reach here */
2778 * decode for the rest of the Csp
2780 MEM_COPY( cspPtr,
2781 buff,
2782 MPLS_CSPFIXLEN);
2784 csp->protocolVersion = ntohs(csp->protocolVersion);
2785 csp->holdTime = ntohs(csp->holdTime);
2786 csp->flags.mark = ntohs(csp->flags.mark);
2787 csp->maxPduLen = ntohs(csp->maxPduLen);
2788 csp->rcvLsrAddress = ntohl(csp->rcvLsrAddress);
2789 csp->rcvLsId = ntohs(csp->rcvLsId);
2791 return MPLS_CSPFIXLEN;
2793 } /* Mpls_decodeLdpCsp*/
2798 * Encode-decode for Fr Session Parameters
2802 * encode
2804 int Mpls_encodeLdpFsp
2806 mplsLdpFspTlv_t * frFsp,
2807 u_char * buff,
2808 int bufSize
2811 u_int encodedSize = 0;
2812 u_short totalSize = 0;
2813 u_char * tempBuf = buff; /* no change for the buff ptr */
2814 u_int i, numLblRng;
2816 /* get the size of the frAsp to be encoded and check it against
2817 the buffer size */
2819 if (MPLS_TLVFIXLEN + (int)(frFsp->baseTlv.length)> bufSize)
2821 /* not enough room */
2822 return MPLS_ENC_BUFFTOOSMALL;
2826 * encode for tlv
2828 encodedSize = Mpls_encodeLdpTlv( &(frFsp->baseTlv),
2829 tempBuf,
2830 bufSize);
2831 if (encodedSize < 0)
2833 return MPLS_ENC_TLVERROR;
2835 tempBuf += encodedSize;
2836 totalSize += encodedSize;
2839 * encode for M + N + dir + res
2841 numLblRng = frFsp->flags.flags.numLblRng;
2842 frFsp->flags.flags.res = 0;
2843 frFsp->flags.mark = htonl(frFsp->flags.mark);
2845 MEM_COPY( tempBuf,
2846 (u_char*)&(frFsp->flags.mark),
2847 MPLS_FSPFIXLEN );
2848 tempBuf += MPLS_FSPFIXLEN;
2849 totalSize += MPLS_FSPFIXLEN;
2852 * encode for FR labels
2854 for (i = 0; i < numLblRng; i++)
2856 encodedSize = Mpls_encodeLdpFrLblRng( &(frFsp->lblRngList[i]),
2857 tempBuf,
2858 bufSize-totalSize);
2859 if (encodedSize < 0)
2861 return MPLS_ENC_FSPLBLERROR;
2863 tempBuf += encodedSize;
2864 totalSize += encodedSize;
2867 return totalSize;
2869 } /* End: Mpls_encodeLdpFsp */
2873 * decode
2875 int Mpls_decodeLdpFsp
2877 mplsLdpFspTlv_t * frFsp,
2878 u_char * buff,
2879 int bufSize
2882 int decodedSize = 0;
2883 u_short totalSize = 0;
2884 u_char * tempBuf = buff; /* no change for the buff ptr */
2885 u_int i;
2887 if (MPLS_FSPFIXLEN > bufSize)
2889 /* the buffer does not contain even the required field*/
2890 PRINT_ERR("failed in decoding LdpFsp\n");
2891 return MPLS_DEC_BUFFTOOSMALL;
2895 * decode for M + N + res
2897 MEM_COPY((u_char *)&(frFsp->flags.mark), tempBuf, MPLS_FSPFIXLEN);
2898 tempBuf += MPLS_FSPFIXLEN;
2899 totalSize += MPLS_FSPFIXLEN;
2901 frFsp->flags.mark = ntohl(frFsp->flags.mark);
2904 * decode for FR labels
2906 for (i = 0; i < frFsp->flags.flags.numLblRng; i++)
2908 decodedSize = Mpls_decodeLdpFrLblRng( &(frFsp->lblRngList[i]),
2909 tempBuf,
2910 bufSize - totalSize);
2911 if (decodedSize < 0)
2913 PRINT_ERR_2("failed in decoding LdpFrLabel[%d] for LdpFsp\n", i);
2914 return MPLS_DEC_FSPLBLERROR;
2916 tempBuf += decodedSize;
2917 totalSize += decodedSize;
2920 return totalSize;
2922 } /* End: Mpls_decodeLdpFsp */
2927 * Encode-decode for INIT msg
2931 * encode for init message
2933 int Mpls_encodeLdpInitMsg
2935 mplsLdpInitMsg_t * initMsg,
2936 u_char * buff,
2937 int bufSize
2940 mplsLdpInitMsg_t initMsgCopy;
2941 u_int encodedSize, totalSize;
2942 u_char * tempBuf = buff; /* no change for the buff ptr */
2944 initMsgCopy = *initMsg;
2945 totalSize = 0;
2947 /* check the length of the messageId + mandatory param +
2948 optional param */
2949 if ((int)(initMsgCopy.baseMsg.msgLength) + MPLS_TLVFIXLEN > bufSize)
2951 PRINT_ERR("failed to encode the init msg: BUFFER TOO SMALL\n");
2952 return MPLS_ENC_BUFFTOOSMALL;
2956 * encode the base part of the pdu message
2958 encodedSize = Mpls_encodeLdpBaseMsg( &(initMsgCopy.baseMsg),
2959 tempBuf,
2960 bufSize);
2961 if (encodedSize < 0)
2963 return MPLS_ENC_BASEMSGERROR;
2965 PRINT_2("Encode BaseMsg for init on %d bytes\n", encodedSize);
2966 tempBuf += encodedSize;
2967 totalSize += encodedSize;
2970 * encode the csp if any
2972 if (initMsgCopy.cspExists)
2974 encodedSize = Mpls_encodeLdpCsp( &(initMsgCopy.csp),
2975 tempBuf,
2976 bufSize-totalSize);
2977 if (encodedSize < 0)
2979 return MPLS_ENC_CSPERROR;
2981 PRINT_2("Encoded for CSP %d bytes\n", encodedSize);
2982 tempBuf += encodedSize;
2983 totalSize += encodedSize;
2987 * encode the asp if any
2989 if (initMsgCopy.aspExists)
2992 encodedSize = Mpls_encodeLdpAsp( &(initMsgCopy.asp),
2993 tempBuf,
2994 bufSize-totalSize);
2995 if (encodedSize < 0)
2997 return MPLS_ENC_ASPERROR;
2999 PRINT_2("Encoded for ASP %d bytes\n", encodedSize);
3000 tempBuf += encodedSize;
3001 totalSize += encodedSize;
3005 * encode the fsp if any
3007 if (initMsgCopy.fspExists)
3009 encodedSize = Mpls_encodeLdpFsp( &(initMsgCopy.fsp),
3010 tempBuf,
3011 bufSize-totalSize);
3012 if (encodedSize < 0)
3014 return MPLS_ENC_FSPERROR;
3016 tempBuf += encodedSize;
3017 totalSize += encodedSize;
3020 return totalSize;
3022 } /* End: Mpls_encodeLdpInitMsg */
3026 * decode for init message
3028 int Mpls_decodeLdpInitMsg
3030 mplsLdpInitMsg_t * initMsg,
3031 u_char * buff,
3032 int bufSize
3035 int decodedSize = 0;
3036 u_int totalSize = 0;
3037 u_int stopLength = 0;
3038 u_char * tempBuf = buff; /* no change for the buff ptr */
3039 u_int totalSizeParam = 0;
3040 mplsLdpTlv_t tlvTemp;
3043 * decode the base part of the pdu message
3045 bzero(initMsg, sizeof(mplsLdpInitMsg_t));
3046 decodedSize = Mpls_decodeLdpBaseMsg( &(initMsg->baseMsg),
3047 tempBuf,
3048 bufSize);
3049 if (decodedSize < 0)
3051 return MPLS_DEC_BASEMSGERROR;
3053 PRINT_2("Decode BaseMsg for init on %d bytes\n", decodedSize);
3055 if (initMsg->baseMsg.flags.flags.msgType != MPLS_INIT_MSGTYPE)
3057 PRINT_ERR_2("Not the right message type; expected init and got %x\n",
3058 initMsg->baseMsg.flags.flags.msgType);
3059 return MPLS_MSGTYPEERROR;
3061 tempBuf += decodedSize;
3062 totalSize += decodedSize;
3064 if (bufSize-totalSize <= 0)
3066 /* nothing left for decoding */
3067 PRINT_ERR("Init msg does not have anything beside base msg\n");
3068 return totalSize;
3071 PRINT_4("bufSize = %d, totalSize = %d, initMsg->baseMsg.msgLength = %d\n",
3072 bufSize, totalSize, initMsg->baseMsg.msgLength);
3074 /* Have to check the baseMsg.msgLength to know when to finish.
3075 * We finsh when the totalSizeParam is >= to the base message length - the
3076 * message id length (4)
3079 stopLength = initMsg->baseMsg.msgLength - MPLS_MSGIDFIXLEN;
3080 while (stopLength > totalSizeParam)
3083 * decode the tlv to check what's next
3085 decodedSize = Mpls_decodeLdpTlv(&tlvTemp, tempBuf, bufSize-totalSize);
3086 if (decodedSize < 0)
3088 /* something wrong */
3089 PRINT_ERR("INIT msg decode failed for tlv\n");
3090 return MPLS_DEC_TLVERROR;
3093 tempBuf += decodedSize;
3094 totalSize += decodedSize;
3095 totalSizeParam += decodedSize;
3097 switch (tlvTemp.flags.flags.type)
3099 case MPLS_CSP_TLVTYPE:
3101 decodedSize = Mpls_decodeLdpCsp( &(initMsg->csp),
3102 tempBuf,
3103 bufSize-totalSize);
3104 if (decodedSize < 0)
3106 PRINT_ERR("Failure when decoding Csp from init msg\n");
3107 return MPLS_DEC_CSPERROR;
3109 PRINT_2("Decoded for CSP %d bytes\n", decodedSize);
3110 tempBuf += decodedSize;
3111 totalSize += decodedSize;
3112 totalSizeParam += decodedSize;
3113 initMsg->cspExists = 1;
3114 initMsg->csp.baseTlv = tlvTemp;
3115 DEBUG_CALL(printCspTlv(&(initMsg->csp)));
3116 break;
3118 case MPLS_ASP_TLVTYPE:
3120 decodedSize = Mpls_decodeLdpAsp( &(initMsg->asp),
3121 tempBuf,
3122 bufSize-totalSize);
3123 if (decodedSize < 0)
3125 PRINT_ERR("Failure when decoding Asp from init msg\n");
3126 return MPLS_DEC_ASPERROR;
3128 PRINT_2("Decoded for ASP %d bytes\n", decodedSize);
3129 tempBuf += decodedSize;
3130 totalSize += decodedSize;
3131 totalSizeParam += decodedSize;
3132 initMsg->aspExists = 1;
3133 initMsg->asp.baseTlv = tlvTemp;
3134 DEBUG_CALL(printAspTlv(&(initMsg->asp)));
3135 break;
3137 case MPLS_FSP_TLVTYPE:
3139 decodedSize = Mpls_decodeLdpFsp( &(initMsg->fsp),
3140 tempBuf,
3141 bufSize-totalSize);
3142 if (decodedSize < 0)
3144 PRINT_ERR("Failure when decoding Fsp from init msg\n");
3145 return MPLS_DEC_FSPERROR;
3147 tempBuf += decodedSize;
3148 totalSize += decodedSize;
3149 totalSizeParam += decodedSize;
3150 initMsg->fspExists = 1;
3151 initMsg->fsp.baseTlv = tlvTemp;
3152 DEBUG_CALL(printFspTlv(&(initMsg->fsp)));
3153 break;
3155 default:
3157 PRINT_ERR_2("Found wrong tlv type while decoding init msg (%d)\n",
3158 tlvTemp.flags.flags.type);
3159 if (tlvTemp.flags.flags.uBit == 1)
3161 /* ignore the Tlv and continue processing */
3162 tempBuf += tlvTemp.length;
3163 totalSize += tlvTemp.length;
3164 totalSizeParam += tlvTemp.length;
3165 break;
3167 else
3169 /* drop the message; return error */
3170 return MPLS_TLVTYPEERROR;
3173 } /* switch type */
3175 } /* while */
3177 PRINT_2("totalsize for Mpls_decodeLdpInitMsg is %d\n", totalSize);
3179 return totalSize;
3181 } /* End: Mpls_decodeLdpInitMsg */
3186 * Encode-decode for Fr Label Range
3190 * encode
3192 int Mpls_encodeLdpFrLblRng
3194 mplsLdpFrLblRng_t * frLabel,
3195 u_char * buff,
3196 int bufSize
3199 if (MPLS_FRLRGFIXLEN > bufSize)
3201 /* not enough room for label */
3202 return MPLS_ENC_BUFFTOOSMALL;
3205 frLabel->flags.flags.res_min = 0;
3206 frLabel->flags.flags.res_max = 0;
3207 frLabel->flags.mark[0] = htonl(frLabel->flags.mark[0]);
3208 frLabel->flags.mark[1] = htonl(frLabel->flags.mark[1]);
3210 MEM_COPY(buff, (u_char *)frLabel, MPLS_FRLRGFIXLEN);
3212 return MPLS_FRLRGFIXLEN;
3214 } /* End: Mpls_encodeLdpFrLblRng */
3219 * decode
3221 int Mpls_decodeLdpFrLblRng
3223 mplsLdpFrLblRng_t * frLabel,
3224 u_char * buff,
3225 int bufSize
3228 if (MPLS_FRLRGFIXLEN > bufSize)
3230 PRINT_ERR("failed decoding the Fr Lbl Rng\n");
3231 return MPLS_DEC_BUFFTOOSMALL;
3234 MEM_COPY((u_char *)frLabel, buff, MPLS_FRLRGFIXLEN);
3236 frLabel->flags.mark[0] = ntohl(frLabel->flags.mark[0]);
3237 frLabel->flags.mark[1] = ntohl(frLabel->flags.mark[1]);
3239 return MPLS_FRLRGFIXLEN;
3241 } /* End: Mpls_decodeLdpFrLblRng */
3247 * Encode-decode for NOTIFICATION msg
3251 * encode for notification message
3253 int Mpls_encodeLdpNotMsg
3255 mplsLdpNotifMsg_t * notMsg,
3256 u_char * buff,
3257 int bufSize
3260 mplsLdpNotifMsg_t notMsgCopy;
3261 u_int encodedSize = 0;
3262 u_int totalSize = 0;
3263 u_char * tempBuf = buff; /* no change for the buff ptr */
3265 /* check the length of the messageId + mandatory param +
3266 optional param */
3267 if ((int)(notMsg->baseMsg.msgLength) + MPLS_TLVFIXLEN > bufSize)
3269 PRINT_ERR("failed to encode the not msg: BUFFER TOO SMALL\n");
3270 return MPLS_ENC_BUFFTOOSMALL;
3273 notMsgCopy = *notMsg;
3276 * encode the base part of the pdu message
3278 encodedSize = Mpls_encodeLdpBaseMsg( &(notMsgCopy.baseMsg),
3279 tempBuf,
3280 bufSize);
3281 if (encodedSize < 0)
3283 return MPLS_ENC_BASEMSGERROR;
3285 PRINT_2("Encode BaseMsg for not on %d bytes\n", encodedSize);
3287 tempBuf += encodedSize;
3288 totalSize += encodedSize;
3290 if (notMsgCopy.statusTlvExists)
3292 encodedSize = Mpls_encodeLdpStatus( &(notMsgCopy.status),
3293 tempBuf,
3294 bufSize-totalSize);
3295 if (encodedSize < 0)
3297 return MPLS_ENC_STATUSERROR;
3299 PRINT_2("Encoded for STATUS %d bytes\n", encodedSize);
3300 tempBuf += encodedSize;
3301 totalSize += encodedSize;
3303 if (notMsgCopy.exStatusTlvExists)
3305 encodedSize = Mpls_encodeLdpExStatus( &(notMsgCopy.exStatus),
3306 tempBuf,
3307 bufSize-totalSize);
3308 if (encodedSize < 0)
3310 return MPLS_ENC_EXSTATERROR;
3312 PRINT_2("Encoded for EXTENDED STATUS %d bytes\n", encodedSize);
3313 tempBuf += encodedSize;
3314 totalSize += encodedSize;
3316 if (notMsgCopy.retPduTlvExists)
3318 encodedSize = Mpls_encodeLdpRetPdu( &(notMsgCopy.retPdu),
3319 tempBuf,
3320 bufSize-totalSize);
3321 if (encodedSize < 0)
3323 return MPLS_ENC_RETPDUERROR;
3325 PRINT_2("Encoded for RET PDU %d bytes\n", encodedSize);
3326 tempBuf += encodedSize;
3327 totalSize += encodedSize;
3329 if (notMsgCopy.retMsgTlvExists)
3331 encodedSize = Mpls_encodeLdpRetMsg( &(notMsgCopy.retMsg),
3332 tempBuf,
3333 bufSize-totalSize);
3334 if (encodedSize < 0)
3336 return MPLS_ENC_RETMSGERROR;
3338 PRINT_2("Encoded for RET MSG %d bytes\n", encodedSize);
3339 tempBuf += encodedSize;
3340 totalSize += encodedSize;
3342 if (notMsgCopy.lspidTlvExists)
3344 encodedSize = Mpls_encodeLdpLspIdTlv( &(notMsgCopy.lspidTlv),
3345 tempBuf,
3346 bufSize-totalSize);
3347 if (encodedSize < 0)
3349 return MPLS_ENC_LSPIDERROR;
3351 PRINT_2("Encoded for LSPID Tlv %d bytes\n", encodedSize);
3352 tempBuf += encodedSize;
3353 totalSize += encodedSize;
3356 return totalSize;
3358 } /* End: Mpls_encodeLdpNotMsg */
3362 * decode for notification message
3364 int Mpls_decodeLdpNotMsg
3366 mplsLdpNotifMsg_t * notMsg,
3367 u_char * buff,
3368 int bufSize
3371 u_int decodedSize = 0;
3372 u_int totalSize = 0;
3373 u_int stopLength = 0;
3374 u_int totalSizeParam = 0;
3375 u_char * tempBuf = buff; /* no change for the buff ptr */
3376 mplsLdpTlv_t tlvTemp;
3379 * decode the base part of the pdu message
3381 bzero(notMsg, sizeof(mplsLdpNotifMsg_t));
3382 decodedSize = Mpls_decodeLdpBaseMsg( &(notMsg->baseMsg),
3383 tempBuf,
3384 bufSize);
3385 if (decodedSize < 0)
3387 return MPLS_DEC_BASEMSGERROR;
3389 PRINT_2("Decode BaseMsg for not on %d bytes\n", decodedSize);
3391 if (notMsg->baseMsg.flags.flags.msgType != MPLS_NOT_MSGTYPE)
3393 PRINT_ERR_2("Not the right message type; expected not and got %x\n",
3394 notMsg->baseMsg.flags.flags.msgType);
3395 return MPLS_MSGTYPEERROR;
3398 tempBuf += decodedSize;
3399 totalSize += decodedSize;
3401 if (bufSize-totalSize <= 0)
3403 /* nothing left for decoding */
3404 PRINT_ERR("Not msg does not have anything beside base msg\n");
3405 return totalSize;
3408 PRINT_4("bufSize = %d, totalSize = %d, notMsg->baseMsg.msgLength = %d\n",
3409 bufSize, totalSize, notMsg->baseMsg.msgLength);
3411 /* Have to check the baseMsg.msgLength to know when to finish.
3412 * We finsh when the totalSizeParam is >= to the base message length - the
3413 * message id length (4)
3416 stopLength = notMsg->baseMsg.msgLength - MPLS_MSGIDFIXLEN;
3417 while (stopLength > totalSizeParam)
3420 * decode the tlv to check what's next
3422 bzero(&tlvTemp, MPLS_TLVFIXLEN);
3423 decodedSize = Mpls_decodeLdpTlv(&tlvTemp, tempBuf, bufSize-totalSize);
3424 if (decodedSize < 0)
3426 /* something wrong */
3427 PRINT_ERR("NOT msg decode failed for tlv\n");
3428 return MPLS_DEC_TLVERROR;
3431 tempBuf += decodedSize;
3432 totalSize += decodedSize;
3433 totalSizeParam += decodedSize;
3435 switch (tlvTemp.flags.flags.type)
3437 case MPLS_NOT_ST_TLVTYPE:
3439 decodedSize = Mpls_decodeLdpStatus( &(notMsg->status),
3440 tempBuf,
3441 bufSize-totalSize);
3442 if (decodedSize < 0)
3444 PRINT_ERR("Failure when decoding Status from not msg\n");
3445 return MPLS_DEC_STATUSERROR;
3447 PRINT_2("Decoded for STATUS %d bytes\n", decodedSize);
3448 tempBuf += decodedSize;
3449 totalSize += decodedSize;
3450 totalSizeParam += decodedSize;
3452 notMsg->statusTlvExists = 1;
3453 notMsg->status.baseTlv = tlvTemp;
3454 DEBUG_CALL(printStatusTlv(&(notMsg->status)));
3455 break;
3457 case MPLS_NOT_ES_TLVTYPE:
3459 decodedSize = Mpls_decodeLdpExStatus( &(notMsg->exStatus),
3460 tempBuf,
3461 bufSize-totalSize);
3462 if (decodedSize < 0)
3464 PRINT_ERR("Failure when decoding Extended Status from not msg\n");
3465 return MPLS_DEC_EXSTATERROR;
3467 PRINT_2("Decoded for EX_STATUS %d bytes\n", decodedSize);
3468 tempBuf += decodedSize;
3469 totalSize += decodedSize;
3470 totalSizeParam += decodedSize;
3472 notMsg->exStatusTlvExists = 1;
3473 notMsg->exStatus.baseTlv = tlvTemp;
3474 DEBUG_CALL(printExStatusTlv(&(notMsg->exStatus)));
3475 break;
3477 case MPLS_NOT_RP_TLVTYPE:
3479 decodedSize = Mpls_decodeLdpRetPdu( &(notMsg->retPdu),
3480 tempBuf,
3481 bufSize-totalSize,
3482 tlvTemp.length);
3483 if (decodedSize < 0)
3485 PRINT_ERR("Failure when decoding Returned PDU from not msg\n");
3486 return MPLS_DEC_RETPDUERROR;
3488 PRINT_2("Decoded for RET_PDU %d bytes\n", decodedSize);
3489 tempBuf += decodedSize;
3490 totalSize += decodedSize;
3491 totalSizeParam += decodedSize;
3493 notMsg->retPduTlvExists = 1;
3494 notMsg->retPdu.baseTlv = tlvTemp;
3495 DEBUG_CALL(printRetPduTlv(&(notMsg->retPdu)));
3496 break;
3498 case MPLS_NOT_RM_TLVTYPE:
3500 decodedSize = Mpls_decodeLdpRetMsg( &(notMsg->retMsg),
3501 tempBuf,
3502 bufSize-totalSize,
3503 tlvTemp.length);
3504 if (decodedSize < 0)
3506 PRINT_ERR("Failure when decoding Returned MSG from not msg\n");
3507 return MPLS_DEC_RETMSGERROR;
3509 PRINT_2("Decoded for RET_MSG %d bytes\n", decodedSize);
3510 tempBuf += decodedSize;
3511 totalSize += decodedSize;
3512 totalSizeParam += decodedSize;
3514 notMsg->retMsgTlvExists = 1;
3515 notMsg->retMsg.baseTlv = tlvTemp;
3516 DEBUG_CALL(printRetMsgTlv(&(notMsg->retMsg)));
3517 break;
3519 case MPLS_LSPID_TLVTYPE:
3521 decodedSize = Mpls_decodeLdpLspIdTlv( &(notMsg->lspidTlv),
3522 tempBuf,
3523 bufSize-totalSize);
3524 if (decodedSize < 0)
3526 PRINT_ERR("Failure when dec LSPID tlv from Not msg\n");
3527 return MPLS_DEC_LSPIDERROR;
3529 PRINT_2("Decoded for lspid tlv %d bytes\n", decodedSize);
3530 tempBuf += decodedSize;
3531 totalSize += decodedSize;
3532 totalSizeParam += decodedSize;
3534 notMsg->lspidTlvExists = 1;
3535 notMsg->lspidTlv.baseTlv = tlvTemp;
3536 DEBUG_CALL(printLspIdTlv(&(notMsg->lspidTlv)));
3537 break;
3539 default:
3541 PRINT_ERR_2("Found wrong tlv type while decoding not msg (%d)\n",
3542 tlvTemp.flags.flags.type);
3543 if (tlvTemp.flags.flags.uBit == 1)
3545 /* ignore the Tlv and continue processing */
3546 tempBuf += tlvTemp.length;
3547 totalSize += tlvTemp.length;
3548 totalSizeParam += tlvTemp.length;
3549 break;
3551 else
3553 /* drop the message; return error */
3554 return MPLS_TLVTYPEERROR;
3557 } /* switch type */
3559 } /* while */
3561 PRINT_2("totalsize for Mpls_decodeLdpNotMsg is %d\n", totalSize);
3563 return totalSize;
3565 } /* End: Mpls_decodeLdpNotMsg */
3570 * Encode-decode for Status TLV
3574 * encode:
3576 int Mpls_encodeLdpStatus
3578 mplsLdpStatusTlv_t * status,
3579 u_char * buff,
3580 int bufSize
3583 u_int encodedSize = 0;
3584 u_char * tempBuf = buff; /* no change for the buff ptr */
3585 u_char * statusPtr;
3587 if (MPLS_STATUSFIXLEN + MPLS_TLVFIXLEN > bufSize)
3589 /* not enough room */
3590 return MPLS_ENC_BUFFTOOSMALL;
3594 * encode for tlv
3596 encodedSize = Mpls_encodeLdpTlv( &(status->baseTlv),
3597 tempBuf,
3598 bufSize);
3599 if (encodedSize < 0)
3601 PRINT_ERR("failed encoding the tlv in STATUS\n");
3602 return MPLS_ENC_TLVERROR;
3605 statusPtr = (u_char *)status;
3606 tempBuf += encodedSize;
3607 statusPtr += encodedSize;
3610 * encode for the rest of the Status
3612 status->flags.mark = htonl(status->flags.mark);
3613 status->msgId = htonl(status->msgId);
3614 status->msgType = htons(status->msgType);
3616 MEM_COPY(tempBuf,
3617 statusPtr,
3618 MPLS_STATUSFIXLEN);
3620 return (MPLS_STATUSFIXLEN + MPLS_TLVFIXLEN);
3622 } /* End: Mpls_encodeLdpStatus */
3626 * decode:
3628 int Mpls_decodeLdpStatus
3630 mplsLdpStatusTlv_t * status,
3631 u_char * buff,
3632 int bufSize
3635 u_char * statusPtr;
3637 if (MPLS_STATUSFIXLEN> bufSize)
3639 /* not enough data for Status*/
3640 PRINT_ERR("failed decoding Status\n");
3641 return MPLS_DEC_BUFFTOOSMALL;
3644 statusPtr = (u_char *)status;
3645 statusPtr += MPLS_TLVFIXLEN; /* we want to point to the flags since the
3646 tlv was decoded before we reach here */
3649 * decode for the rest of the Status
3651 MEM_COPY( statusPtr,
3652 buff,
3653 MPLS_STATUSFIXLEN);
3655 status->flags.mark = ntohl(status->flags.mark);
3656 status->msgId = ntohl(status->msgId);
3657 status->msgType = ntohs(status->msgType);
3659 return MPLS_STATUSFIXLEN;
3661 } /* End: Mpls_decodeLdpStatus */
3665 * Encode-decode for Extended Status TLV
3670 * encode:
3672 int Mpls_encodeLdpExStatus
3674 mplsLdpExStatusTlv_t * status,
3675 u_char * buff,
3676 int bufSize
3679 u_int encodedSize = 0;
3680 u_char * tempBuf = buff; /* no change for the buff ptr */
3682 if (MPLS_EXSTATUSLEN + MPLS_TLVFIXLEN > bufSize)
3684 /* not enough room */
3685 return MPLS_ENC_BUFFTOOSMALL;
3689 * encode for tlv
3691 encodedSize = Mpls_encodeLdpTlv( &(status->baseTlv),
3692 tempBuf,
3693 bufSize);
3694 if (encodedSize < 0)
3696 PRINT_ERR("failed encoding the tlv in EX_STATUS\n");
3697 return MPLS_ENC_TLVERROR;
3699 tempBuf += encodedSize;
3701 status->value = htonl(status->value);
3703 MEM_COPY(tempBuf,
3704 (u_char *)&(status->value),
3705 sizeof(u_int));
3707 return (MPLS_EXSTATUSLEN + MPLS_TLVFIXLEN);
3709 } /* End: Mpls_encodeLdpExStatus */
3713 * decode:
3715 int Mpls_decodeLdpExStatus
3717 mplsLdpExStatusTlv_t * status,
3718 u_char * buff,
3719 int bufSize
3722 if (MPLS_EXSTATUSLEN > bufSize)
3724 /* not enough data for ExStatus*/
3725 PRINT_ERR("failed decoding ExStatus\n");
3726 return MPLS_DEC_BUFFTOOSMALL;
3730 * decode for the rest of the Status
3732 MEM_COPY( &(status->value),
3733 buff,
3734 MPLS_EXSTATUSLEN);
3736 status->value = ntohl(status->value);
3738 return MPLS_EXSTATUSLEN;
3740 } /* End: Mpls_decodeLdpExStatus */
3746 * Encode-decode for Return PDU TLV
3750 * encode:
3752 int Mpls_encodeLdpRetPdu
3754 mplsLdpRetPduTlv_t * retPdu,
3755 u_char * buff,
3756 int bufSize
3759 u_int encodedSize = 0;
3760 u_char * tempBuf = buff; /* no change for the buff ptr */
3761 u_short tempLength; /* to store the tlv length for
3762 later use */
3764 if ( MPLS_TLVFIXLEN + (int)(retPdu->baseTlv.length) > bufSize )
3766 /* not enough room */
3767 return MPLS_ENC_BUFFTOOSMALL;
3770 tempLength = retPdu->baseTlv.length;
3772 * encode for tlv
3774 encodedSize = Mpls_encodeLdpTlv( &(retPdu->baseTlv),
3775 tempBuf,
3776 bufSize);
3777 if (encodedSize < 0)
3779 PRINT_ERR("failed encoding the tlv in RET_PDU\n");
3780 return MPLS_ENC_TLVERROR;
3782 tempBuf += encodedSize;
3785 * encode the data of the ret pdu
3788 encodedSize = Mpls_encodeLdpMsgHeader( &(retPdu->headerTlv),
3789 tempBuf,
3790 bufSize-encodedSize);
3791 if (encodedSize < 0)
3793 PRINT_ERR("failed encoding the header Tlv in RET_PDU\n");
3794 return MPLS_ENC_HDRTLVERROR;
3796 tempBuf += encodedSize;
3798 MEM_COPY(tempBuf,
3799 retPdu->data,
3800 tempLength);
3802 return (MPLS_TLVFIXLEN + tempLength);
3804 } /* End: Mpls_encodeLdpRetPdu */
3808 * decode:
3810 int Mpls_decodeLdpRetPdu
3812 mplsLdpRetPduTlv_t * retPdu,
3813 u_char * buff,
3814 int bufSize,
3815 u_short tlvLength
3818 u_char * tempBuf = buff; /* no change for the buff ptr */
3819 u_int decodedSize;
3821 if ((int)tlvLength > bufSize)
3823 /* not enough data for ExStatus*/
3824 PRINT_ERR("failed decoding Ret pdu\n");
3825 return MPLS_DEC_BUFFTOOSMALL;
3829 * decode data for ret pdu
3831 decodedSize = Mpls_decodeLdpMsgHeader( &(retPdu->headerTlv),
3832 tempBuf,
3833 bufSize);
3834 if (decodedSize < 0)
3836 PRINT_ERR("failed decoding the header Tlv in RET_PDU\n");
3837 return MPLS_DEC_HDRTLVERROR;
3839 tempBuf += decodedSize;
3841 MEM_COPY( retPdu->data,
3842 tempBuf,
3843 tlvLength);
3845 return tlvLength;
3847 } /* End: Mpls_decodeLdpRetPdu */
3852 * Encode-decode for Return Msg TLV
3856 * encode:
3858 int Mpls_encodeLdpRetMsg
3860 mplsLdpRetMsgTlv_t * retMsg,
3861 u_char * buff,
3862 int bufSize
3865 u_char * retMsgPtr;
3866 u_int encodedSize = 0;
3867 u_char * tempBuf = buff; /* no change for the buff ptr */
3868 u_short tempLength; /* to store the tlv length for
3869 later use */
3871 if ( MPLS_TLVFIXLEN + (int)(retMsg->baseTlv.length) > bufSize )
3873 /* not enough room */
3874 return MPLS_ENC_BUFFTOOSMALL;
3877 tempLength = retMsg->baseTlv.length;
3879 * encode for tlv
3881 encodedSize = Mpls_encodeLdpTlv( &(retMsg->baseTlv),
3882 tempBuf,
3883 bufSize);
3884 if (encodedSize < 0)
3886 PRINT_ERR("failed encoding the tlv in RET_MSG\n");
3887 return MPLS_ENC_TLVERROR;
3890 retMsgPtr = (u_char *)retMsg;
3891 tempBuf += encodedSize;
3892 retMsgPtr += encodedSize;
3895 * encode the data of the ret pdu
3898 retMsg->msgType = htons(retMsg->msgType);
3899 retMsg->msgLength = htons(retMsg->msgLength);
3901 MEM_COPY(tempBuf,
3902 retMsgPtr,
3903 tempLength);
3905 return (MPLS_TLVFIXLEN + tempLength);
3907 } /* End: Mpls_encodeLdpRetMsg */
3911 * decode:
3913 int Mpls_decodeLdpRetMsg
3915 mplsLdpRetMsgTlv_t * retMsg,
3916 u_char * buff,
3917 int bufSize,
3918 u_short tlvLength
3921 u_char * tempBuf = buff; /* no change for the buff ptr */
3922 u_char * retMsgPtr;
3924 if ((int)tlvLength > bufSize)
3926 /* not enough data for ExStatus*/
3927 PRINT_ERR("failed decoding Ret msg\n");
3928 return MPLS_DEC_BUFFTOOSMALL;
3930 retMsgPtr = (u_char *)retMsg;
3931 retMsgPtr += MPLS_TLVFIXLEN;
3934 * decode data for ret msg
3936 MEM_COPY( retMsgPtr,
3937 tempBuf,
3938 tlvLength);
3940 retMsg->msgType = ntohs(retMsg->msgType);
3941 retMsg->msgLength = ntohs(retMsg->msgLength);
3943 return tlvLength;
3945 } /* End: Mpls_decodeLdpRetMsg */
3949 * Encode-decode for HELLO msg
3953 * encode for HELLO message
3955 int Mpls_encodeLdpHelloMsg
3957 mplsLdpHelloMsg_t * helloMsg,
3958 u_char * buff,
3959 int bufSize
3962 mplsLdpHelloMsg_t helloMsgCopy;
3963 u_int encodedSize = 0;
3964 u_int totalSize = 0;
3965 u_char * tempBuf = buff; /* no change for the buff ptr */
3967 /* check the length of the messageId + mandatory param +
3968 optional param */
3969 if ((int)(helloMsg->baseMsg.msgLength) + MPLS_TLVFIXLEN > bufSize)
3971 PRINT_ERR("failed to encode the hello msg: BUFFER TOO SMALL\n");
3972 return MPLS_ENC_BUFFTOOSMALL;
3975 helloMsgCopy = *helloMsg;
3978 * encode the base part of the pdu message
3980 encodedSize = Mpls_encodeLdpBaseMsg( &(helloMsgCopy.baseMsg),
3981 tempBuf,
3982 bufSize);
3983 if (encodedSize < 0)
3985 return MPLS_ENC_BASEMSGERROR;
3987 PRINT_2("Encode BaseMsg for hello on %d bytes\n", encodedSize);
3988 tempBuf += encodedSize;
3989 totalSize += encodedSize;
3993 * encode the status tlv if any
3995 if (helloMsgCopy.chpTlvExists)
3997 encodedSize = Mpls_encodeLdpChp( &(helloMsgCopy.chp),
3998 tempBuf,
3999 bufSize-totalSize);
4000 if (encodedSize < 0)
4002 return MPLS_ENC_CHPERROR;
4004 PRINT_2("Encoded for CHP %d bytes\n", encodedSize);
4005 tempBuf += encodedSize;
4006 totalSize += encodedSize;
4008 if (helloMsgCopy.trAdrTlvExists)
4010 encodedSize = Mpls_encodeLdpTrAdr( &(helloMsgCopy.trAdr),
4011 tempBuf,
4012 bufSize-totalSize);
4013 if (encodedSize < 0)
4015 return MPLS_ENC_TRADRERROR;
4017 PRINT_2("Encoded for TR ADDR %d bytes\n", encodedSize);
4018 tempBuf += encodedSize;
4019 totalSize += encodedSize;
4021 if (helloMsgCopy.csnTlvExists)
4023 encodedSize = Mpls_encodeLdpCsn( &(helloMsgCopy.csn),
4024 tempBuf,
4025 bufSize-totalSize);
4026 if (encodedSize < 0)
4028 return MPLS_ENC_CSNERROR;
4030 PRINT_2("Encoded for CSN %d bytes\n", encodedSize);
4031 tempBuf += encodedSize;
4032 totalSize += encodedSize;
4035 return totalSize;
4037 } /* End: Mpls_encodeLdpHelloMsg */
4041 * decode for HELLO message
4043 int Mpls_decodeLdpHelloMsg
4045 mplsLdpHelloMsg_t * helloMsg,
4046 u_char * buff,
4047 int bufSize
4050 u_int decodedSize = 0;
4051 u_int totalSize = 0;
4052 u_int stopLength = 0;
4053 u_int totalSizeParam = 0;
4054 u_char * tempBuf = buff; /* no change for the buff ptr */
4055 mplsLdpTlv_t tlvTemp;
4058 * decode the base part of the pdu message
4060 bzero(helloMsg, sizeof(mplsLdpHelloMsg_t));
4061 decodedSize = Mpls_decodeLdpBaseMsg( &(helloMsg->baseMsg),
4062 tempBuf,
4063 bufSize);
4064 if (decodedSize < 0)
4066 return MPLS_DEC_BASEMSGERROR;
4068 PRINT_2("Decode BaseMsg for hello on %d bytes\n", decodedSize);
4070 if (helloMsg->baseMsg.flags.flags.msgType != MPLS_HELLO_MSGTYPE)
4072 PRINT_ERR_2("Not the right message type; expected hello and got %x\n",
4073 helloMsg->baseMsg.flags.flags.msgType);
4074 return MPLS_MSGTYPEERROR;
4077 tempBuf += decodedSize;
4078 totalSize += decodedSize;
4080 if (bufSize-totalSize <= 0)
4082 /* nothing left for decoding */
4083 PRINT_ERR("Hello msg does not have anything beside base msg\n");
4084 return totalSize;
4087 PRINT_4("bufSize = %d, totalSize = %d, helloMsg->baseMsg.msgLength = %d\n",
4088 bufSize, totalSize, helloMsg->baseMsg.msgLength);
4090 /* Have to check the baseMsg.msgLength to know when to finish.
4091 * We finsh when the totalSizeParam is >= to the base message length - the
4092 * message id length (4)
4095 stopLength = helloMsg->baseMsg.msgLength - MPLS_MSGIDFIXLEN;
4096 while (stopLength > totalSizeParam)
4099 * decode the tlv to check what's next
4101 bzero(&tlvTemp, MPLS_TLVFIXLEN);
4102 decodedSize = Mpls_decodeLdpTlv(&tlvTemp, tempBuf, bufSize-totalSize);
4103 if (decodedSize < 0)
4105 /* something wrong */
4106 PRINT_ERR("NOT msg decode failed for tlv\n");
4107 return MPLS_DEC_TLVERROR;
4110 tempBuf += decodedSize;
4111 totalSize += decodedSize;
4112 totalSizeParam += decodedSize;
4114 switch (tlvTemp.flags.flags.type)
4116 case MPLS_CHP_TLVTYPE:
4118 decodedSize = Mpls_decodeLdpChp( &(helloMsg->chp),
4119 tempBuf,
4120 bufSize-totalSize);
4121 if (decodedSize < 0)
4123 PRINT_ERR("Failure when decoding Chp from hello msg\n");
4124 return MPLS_DEC_CHPERROR;
4126 PRINT_2("Decoded for CHP %d bytes\n", decodedSize);
4127 tempBuf += decodedSize;
4128 totalSize += decodedSize;
4129 totalSizeParam += decodedSize;
4131 helloMsg->chpTlvExists = 1;
4132 helloMsg->chp.baseTlv = tlvTemp;
4133 DEBUG_CALL(printChpTlv(&(helloMsg->chp)));
4134 break;
4136 case MPLS_TRADR_TLVTYPE:
4138 decodedSize = Mpls_decodeLdpTrAdr( &(helloMsg->trAdr),
4139 tempBuf,
4140 bufSize-totalSize);
4141 if (decodedSize < 0)
4143 PRINT_ERR("Failure when decoding TrAdr from hello msg\n");
4144 return MPLS_DEC_TRADRERROR;
4146 PRINT_2("Decoded for TrAdr %d bytes\n", decodedSize);
4147 tempBuf += decodedSize;
4148 totalSize += decodedSize;
4149 totalSizeParam += decodedSize;
4151 helloMsg->trAdrTlvExists = 1;
4152 helloMsg->trAdr.baseTlv = tlvTemp;
4153 DEBUG_CALL(printTrAdrTlv(&(helloMsg->trAdr)));
4154 break;
4156 case MPLS_CSN_TLVTYPE:
4158 decodedSize = Mpls_decodeLdpCsn( &(helloMsg->csn),
4159 tempBuf,
4160 bufSize-totalSize);
4161 if (decodedSize < 0)
4163 PRINT_ERR("Failure when decoding Csn from hello msg\n");
4164 return MPLS_DEC_CSNERROR;
4166 PRINT_2("Decoded for CSN %d bytes\n", decodedSize);
4167 tempBuf += decodedSize;
4168 totalSize += decodedSize;
4169 totalSizeParam += decodedSize;
4171 helloMsg->csnTlvExists = 1;
4172 helloMsg->csn.baseTlv = tlvTemp;
4173 DEBUG_CALL(printCsnTlv(&(helloMsg->csn)));
4174 break;
4176 default:
4178 PRINT_ERR_2("Found wrong tlv type while decoding hello msg (%d)\n",
4179 tlvTemp.flags.flags.type);
4180 if (tlvTemp.flags.flags.uBit == 1)
4182 /* ignore the Tlv and continue processing */
4183 tempBuf += tlvTemp.length;
4184 totalSize += tlvTemp.length;
4185 totalSizeParam += tlvTemp.length;
4186 break;
4188 else
4190 /* drop the message; return error */
4191 return MPLS_TLVTYPEERROR;
4194 } /* switch type */
4196 } /* while */
4198 PRINT_2("totalsize for Mpls_decodeLdpHelloMsg is %d\n", totalSize);
4200 return totalSize;
4202 } /* End: Mpls_decodeLdpHelloMsg */
4208 * Encode for Common Hello Parameters TLV
4212 * encode
4214 int Mpls_encodeLdpChp
4216 mplsLdpChpTlv_t * chp,
4217 u_char * buff,
4218 int bufSize
4221 int encodedSize = 0;
4222 u_char * tempBuf = buff; /* no change for the buff ptr */
4223 u_char * chpPtr;
4225 /* get the size of the chp to be encoded and check it against
4226 the buffer size */
4228 if (MPLS_TLVFIXLEN + MPLS_CHPFIXLEN > bufSize)
4230 /* not enough room */
4231 return MPLS_ENC_BUFFTOOSMALL;
4235 * encode for tlv
4237 encodedSize = Mpls_encodeLdpTlv( &(chp->baseTlv),
4238 tempBuf,
4239 MPLS_TLVFIXLEN);
4240 if (encodedSize < 0)
4242 return MPLS_ENC_TLVERROR;
4245 chpPtr = (u_char *)chp;
4246 tempBuf += encodedSize;
4247 chpPtr += encodedSize;
4250 * encode for hold time + T + R + res
4252 chp->flags.flags.res = 0;
4253 chp->flags.mark = htons(chp->flags.mark);
4254 chp->holdTime = htons(chp->holdTime);
4256 MEM_COPY( tempBuf,
4257 chpPtr,
4258 MPLS_CHPFIXLEN);
4260 return (MPLS_TLVFIXLEN + MPLS_CHPFIXLEN);
4262 } /* End: Mpls_encodeLdpChp */
4266 * decode
4268 int Mpls_decodeLdpChp
4270 mplsLdpChpTlv_t * chp,
4271 u_char * buff,
4272 int bufSize
4275 u_char * chpPtr;
4277 if (MPLS_CHPFIXLEN > bufSize)
4279 /* not enough data for Chp */
4280 PRINT_ERR("failed decoding hello Chp\n");
4281 return MPLS_DEC_BUFFTOOSMALL;
4284 chpPtr = (u_char *)chp;
4285 chpPtr += MPLS_TLVFIXLEN; /* we want to point to the flags since the
4286 tlv was decoded before we reach here */
4289 * decode for the rest of the Chp
4291 MEM_COPY( chpPtr,
4292 buff,
4293 MPLS_CHPFIXLEN);
4295 chp->holdTime = ntohs(chp->holdTime);
4296 chp->flags.mark = ntohs(chp->flags.mark);
4298 return MPLS_CHPFIXLEN;
4300 } /* End: Mpls_decodeLdpChp */
4304 * Encode for Configuration Sequence Number TLV
4308 * encode
4310 int Mpls_encodeLdpCsn
4312 mplsLdpCsnTlv_t * csn,
4313 u_char * buff,
4314 int bufSize
4317 int encodedSize = 0;
4318 u_char * tempBuf = buff; /* no change for the buff ptr */
4320 if (MPLS_CSNFIXLEN + MPLS_TLVFIXLEN > bufSize)
4322 /* not enough room */
4323 return MPLS_ENC_BUFFTOOSMALL;
4327 * encode for tlv
4329 encodedSize = Mpls_encodeLdpTlv( &(csn->baseTlv),
4330 tempBuf,
4331 bufSize);
4332 if (encodedSize < 0)
4334 PRINT_ERR("failed encoding the tlv in hello Csn\n");
4335 return MPLS_ENC_TLVERROR;
4337 tempBuf += encodedSize;
4339 csn->seqNumber = htonl(csn->seqNumber);
4341 MEM_COPY(tempBuf,
4342 (u_char *)&(csn->seqNumber),
4343 MPLS_CSNFIXLEN);
4345 return (MPLS_CSNFIXLEN + MPLS_TLVFIXLEN);
4347 } /* End: Mpls_encodeLdpCsn */
4350 * decode
4352 int Mpls_decodeLdpCsn
4354 mplsLdpCsnTlv_t * csn,
4355 u_char * buff,
4356 int bufSize
4359 u_char * tempBuf = buff; /* no change for the buff ptr */
4361 if (MPLS_CSNFIXLEN > bufSize)
4363 /* not enough data for csn data*/
4364 PRINT_ERR("failed decoding hello Csn\n");
4365 return MPLS_DEC_BUFFTOOSMALL;
4369 * decode for the rest of the Csn
4371 MEM_COPY( &(csn->seqNumber),
4372 tempBuf,
4373 MPLS_CSNFIXLEN);
4375 csn->seqNumber = ntohl(csn->seqNumber);
4377 return MPLS_CSNFIXLEN;
4379 } /* End: Mpls_decodeLdpCsn */
4383 * Encode for Transport Address TLV
4387 * encode
4389 int Mpls_encodeLdpTrAdr
4391 mplsLdpTrAdrTlv_t * trAdr,
4392 u_char * buff,
4393 int bufSize
4396 int encodedSize = 0;
4397 u_char * tempBuf = buff; /* no change for the buff ptr */
4399 if (MPLS_TRADRFIXLEN + MPLS_TLVFIXLEN > bufSize)
4401 /* not enough room */
4402 return MPLS_ENC_BUFFTOOSMALL;
4406 * encode for tlv
4408 encodedSize = Mpls_encodeLdpTlv( &(trAdr->baseTlv),
4409 tempBuf,
4410 bufSize);
4411 if (encodedSize < 0)
4413 PRINT_ERR("failed encoding the tlv in hello TrAdr\n");
4414 return MPLS_ENC_TLVERROR;
4416 tempBuf += encodedSize;
4418 trAdr->address = htonl(trAdr->address);
4420 MEM_COPY(tempBuf,
4421 (u_char *)&(trAdr->address),
4422 MPLS_TRADRFIXLEN);
4424 return (MPLS_TRADRFIXLEN + MPLS_TLVFIXLEN);
4426 } /* End: Mpls_encodeLdpTrAdr */
4429 * decode
4431 int Mpls_decodeLdpTrAdr
4433 mplsLdpTrAdrTlv_t * trAdr,
4434 u_char * buff,
4435 int bufSize
4438 u_char * tempBuf = buff; /* no change for the buff ptr */
4440 if (MPLS_TRADRFIXLEN > bufSize)
4442 /* not enough data for csn data*/
4443 PRINT_ERR("failed decoding hello TrAdr\n");
4444 return MPLS_DEC_BUFFTOOSMALL;
4448 * decode for the rest of the TrAdr
4450 MEM_COPY( &(trAdr->address),
4451 tempBuf,
4452 MPLS_TRADRFIXLEN);
4454 trAdr->address = ntohl(trAdr->address);
4456 return MPLS_TRADRFIXLEN;
4458 } /* End: Mpls_decodeLdpTrAdr*/
4462 * Encode for KeepAlive Message
4466 * encode
4468 int Mpls_encodeLdpKeepAliveMsg
4470 mplsLdpKeepAlMsg_t * keepAlive,
4471 u_char * buff,
4472 int bufSize
4475 mplsLdpKeepAlMsg_t keepAliveCopy;
4476 u_int encodedSize = 0;
4478 if (MPLS_MSGIDFIXLEN + MPLS_TLVFIXLEN > bufSize)
4480 PRINT_ERR("failed to encode the keep alive msg: BUFFER TOO SMALL\n");
4481 return MPLS_ENC_BUFFTOOSMALL;
4484 keepAliveCopy = *keepAlive;
4486 encodedSize = Mpls_encodeLdpBaseMsg( &(keepAliveCopy.baseMsg),
4487 buff,
4488 bufSize);
4489 if (encodedSize < 0)
4491 return MPLS_ENC_BASEMSGERROR;
4493 PRINT_2("Encode BaseMsg for keep alive on %d bytes\n", encodedSize);
4495 return (MPLS_MSGIDFIXLEN + MPLS_TLVFIXLEN);
4497 } /* End: Mpls_encodeLdpKeepAliveMsg */
4501 * decode
4503 int Mpls_decodeLdpKeepAliveMsg
4505 mplsLdpKeepAlMsg_t * keepAlive,
4506 u_char * buff,
4507 int bufSize
4510 int decodedSize = 0;
4512 bzero(keepAlive, MPLS_MSGIDFIXLEN + MPLS_TLVFIXLEN);
4513 decodedSize = Mpls_decodeLdpBaseMsg( &(keepAlive->baseMsg),
4514 buff,
4515 bufSize);
4516 if (decodedSize < 0)
4518 return MPLS_DEC_BASEMSGERROR;
4520 PRINT_2("Decode BaseMsg for keep alive on %d bytes\n", decodedSize);
4522 if (keepAlive->baseMsg.flags.flags.msgType != MPLS_KEEPAL_MSGTYPE)
4524 PRINT_ERR_2("Not the right message type; expected keep alive and got %x\n",
4525 keepAlive->baseMsg.flags.flags.msgType);
4526 return MPLS_MSGTYPEERROR;
4529 return (MPLS_MSGIDFIXLEN + MPLS_TLVFIXLEN);
4531 } /* End: Mpls_decodeLdpKeepAliveMsg */
4536 * Encode for Address List TLV
4540 * encode
4542 int Mpls_encodeLdpAdrTlv
4544 mplsLdpAdrTlv_t * adrList,
4545 u_char * buff,
4546 int bufSize
4549 int i, numberAdr;
4550 int encodedSize = 0;
4551 u_char * tempBuf = buff; /* no change for the buff ptr */
4552 u_short tempLength; /* to store the tlv length for
4553 later use */
4555 if (MPLS_TLVFIXLEN + (int)(adrList->baseTlv.length) > bufSize)
4557 /* not enough room */
4558 return MPLS_ENC_BUFFTOOSMALL;
4561 tempLength = adrList->baseTlv.length;
4563 * encode for tlv
4565 encodedSize = Mpls_encodeLdpTlv( &(adrList->baseTlv),
4566 tempBuf,
4567 bufSize);
4568 if (encodedSize < 0)
4570 PRINT_ERR("failed encoding the tlv in AdrList\n");
4571 return MPLS_ENC_TLVERROR;
4574 tempBuf += encodedSize;
4576 adrList->addrFamily = htons(adrList->addrFamily);
4578 numberAdr = (tempLength - sizeof(u_short)) / sizeof(u_int);
4579 for (i = 0; i < numberAdr; i++)
4581 adrList->address[i] = htonl(adrList->address[i]);
4584 MEM_COPY(tempBuf,
4585 (u_char *)&adrList->addrFamily,
4586 sizeof(u_short));
4588 tempBuf += sizeof(u_short);
4590 MEM_COPY(tempBuf,
4591 (u_char *)&adrList->address,
4592 tempLength - sizeof(u_short));
4594 return (tempLength + MPLS_TLVFIXLEN);
4596 } /* End: Mpls_encodeLdpAdrTlv */
4599 * decode
4601 * Note: the tlvLength is used to specify what is the length of the
4602 * encoding in the AdrTlv.
4604 int Mpls_decodeLdpAdrTlv
4606 mplsLdpAdrTlv_t * adrList,
4607 u_char * buff,
4608 int bufSize,
4609 u_short tlvLength
4612 u_char * tempBuf = buff; /* no change for the buff ptr */
4613 int i, numberAdr;
4615 if ((int)tlvLength > bufSize)
4617 /* not enough data for Adr list tlv*/
4618 PRINT_ERR("failed decoding AddrList tlv\n");
4619 return MPLS_DEC_BUFFTOOSMALL;
4623 * decode for the addressFamily and addresses of the address list
4625 MEM_COPY( (u_char *)&adrList->addrFamily,
4626 tempBuf,
4627 sizeof(u_short));
4628 tempBuf += sizeof(u_short);
4630 adrList->addrFamily = ntohs(adrList->addrFamily);
4632 MEM_COPY( (u_char *)&adrList->address,
4633 tempBuf,
4634 tlvLength - sizeof(u_short));
4636 numberAdr = (tlvLength - sizeof(u_short)) / sizeof(u_int);
4637 for (i = 0; i < numberAdr; i++)
4639 adrList->address[i] = ntohl(adrList->address[i]);
4642 return tlvLength;
4644 } /* End: Mpls_decodeLdpAdrTlv */
4649 * Encode for Address / Address Withdraw messages
4653 * encode
4655 int Mpls_encodeLdpAdrMsg
4657 mplsLdpAdrMsg_t * addrMsg,
4658 u_char * buff,
4659 int bufSize
4662 mplsLdpAdrMsg_t addrMsgCopy;
4663 int encodedSize = 0;
4664 u_int totalSize = 0;
4665 u_char * tempBuf = buff; /* no change for the buff ptr */
4667 /* check the length of the messageId + param */
4668 if ((int)(addrMsg->baseMsg.msgLength) + MPLS_TLVFIXLEN > bufSize)
4670 PRINT_ERR("failed to encode the address msg: BUFFER TOO SMALL\n");
4671 return MPLS_ENC_BUFFTOOSMALL;
4674 addrMsgCopy = *addrMsg;
4677 * encode the base part of the pdu message
4679 encodedSize = Mpls_encodeLdpBaseMsg( &(addrMsgCopy.baseMsg),
4680 tempBuf,
4681 bufSize);
4682 if (encodedSize < 0)
4684 return MPLS_ENC_BASEMSGERROR;
4686 PRINT_2("Encode BaseMsg for address on %d bytes\n", encodedSize);
4687 tempBuf += encodedSize;
4688 totalSize += encodedSize;
4691 * encode the address list tlv if any
4693 if (addrMsg->adrListTlvExists)
4695 encodedSize = Mpls_encodeLdpAdrTlv( &(addrMsgCopy.addressList),
4696 tempBuf,
4697 bufSize-totalSize);
4698 if (encodedSize < 0)
4700 return MPLS_ENC_ADRLISTERROR;
4702 PRINT_2("Encoded for AddressList Tlv %d bytes\n", encodedSize);
4705 return (addrMsg->baseMsg.msgLength + MPLS_TLVFIXLEN);
4707 } /* End: */
4710 * decode
4712 int Mpls_decodeLdpAdrMsg
4714 mplsLdpAdrMsg_t * addrMsg,
4715 u_char * buff,
4716 int bufSize
4719 int decodedSize = 0;
4720 u_int totalSize = 0;
4721 u_int stopLength = 0;
4722 u_int totalSizeParam = 0;
4723 u_char * tempBuf = buff; /* no change for the buff ptr */
4724 mplsLdpTlv_t tlvTemp;
4727 * decode the base part of the pdu message
4729 bzero(addrMsg, sizeof(mplsLdpAdrMsg_t));
4730 decodedSize = Mpls_decodeLdpBaseMsg( &(addrMsg->baseMsg),
4731 tempBuf,
4732 bufSize);
4733 if (decodedSize < 0)
4735 return MPLS_DEC_BASEMSGERROR;
4737 PRINT_2("Decode BaseMsg for address msg on %d bytes\n", decodedSize);
4739 if ((addrMsg->baseMsg.flags.flags.msgType != MPLS_ADDR_MSGTYPE) &&
4740 (addrMsg->baseMsg.flags.flags.msgType != MPLS_ADDRWITH_MSGTYPE))
4742 PRINT_ERR_2("Not the right message type; expected adr and got %x\n",
4743 addrMsg->baseMsg.flags.flags.msgType);
4744 return MPLS_MSGTYPEERROR;
4747 tempBuf += decodedSize;
4748 totalSize += decodedSize;
4750 if (bufSize-totalSize <= 0)
4752 /* nothing left for decoding */
4753 PRINT_ERR("Adr msg does not have anything beside base msg\n");
4754 return totalSize;
4757 PRINT_4("bufSize = %d, totalSize = %d, addrMsg->baseMsg.msgLength = %d\n",
4758 bufSize, totalSize, addrMsg->baseMsg.msgLength);
4760 /* Have to check the baseMsg.msgLength to know when to finish.
4761 * We finsh when the totalSizeParam is >= to the base message length - the
4762 * message id length (4)
4765 stopLength = addrMsg->baseMsg.msgLength - MPLS_MSGIDFIXLEN;
4766 while (stopLength > totalSizeParam)
4769 * decode the tlv to check what's next
4771 bzero(&tlvTemp, MPLS_TLVFIXLEN);
4772 decodedSize = Mpls_decodeLdpTlv(&tlvTemp, tempBuf, bufSize-totalSize);
4773 if (decodedSize < 0)
4775 /* something wrong */
4776 PRINT_ERR("ADR msg decode failed for tlv\n");
4777 return MPLS_DEC_TLVERROR;
4780 tempBuf += decodedSize;
4781 totalSize += decodedSize;
4782 totalSizeParam += decodedSize;
4784 switch (tlvTemp.flags.flags.type)
4786 case MPLS_ADDRLIST_TLVTYPE:
4788 decodedSize = Mpls_decodeLdpAdrTlv( &(addrMsg->addressList),
4789 tempBuf,
4790 bufSize-totalSize,
4791 tlvTemp.length);
4792 if (decodedSize < 0)
4794 PRINT_ERR("Failure when decoding AdrList tlv from adr msg\n");
4795 return MPLS_DEC_ADRLISTERROR;
4797 PRINT_2("Decoded for ADRLIST %d bytes\n", decodedSize);
4798 tempBuf += decodedSize;
4799 totalSize += decodedSize;
4800 totalSizeParam += decodedSize;
4802 addrMsg->adrListTlvExists = 1;
4803 addrMsg->addressList.baseTlv = tlvTemp;
4804 DEBUG_CALL(printAdrListTlv(&(addrMsg->addressList)));
4805 break;
4807 default:
4809 PRINT_ERR_2("Found wrong tlv type while decoding adr msg (%x)\n",
4810 tlvTemp.flags.flags.type);
4811 if (tlvTemp.flags.flags.uBit == 1)
4813 /* ignore the Tlv and continue processing */
4814 tempBuf += tlvTemp.length;
4815 totalSize += tlvTemp.length;
4816 totalSizeParam += tlvTemp.length;
4817 break;
4819 else
4821 /* drop the message; return error */
4822 return MPLS_TLVTYPEERROR;
4825 } /* switch type */
4827 } /* while */
4829 PRINT_2("totalsize for Mpls_decodeLdpAdrMsg is %d\n", totalSize);
4831 return totalSize;
4833 } /* End: Mpls_decodeLdpAdrMsg*/
4838 * Encode for FEC ELEMENT
4842 * encode
4844 int Mpls_encodeLdpFecAdrEl
4846 mplsFecElement_t * fecAdrEl,
4847 u_char * buff,
4848 int bufSize,
4849 u_char type
4852 int encodedSize = 0;
4853 u_char * tempBuf = buff;
4855 switch (type)
4857 case MPLS_WC_FEC:
4859 if (MPLS_FEC_ELEMTYPELEN > bufSize)
4861 return MPLS_ENC_BUFFTOOSMALL;
4863 *buff = fecAdrEl->wildcardEl.type;
4864 encodedSize = MPLS_FEC_ELEMTYPELEN;
4865 break;
4867 case MPLS_PREFIX_FEC:
4869 fecAdrEl->addressEl.addressFam = htons(fecAdrEl->addressEl.addressFam);
4870 fecAdrEl->addressEl.address = htonl(fecAdrEl->addressEl.address);
4872 encodedSize = MPLS_FEC_ADRFAMLEN + MPLS_FEC_ELEMTYPELEN +
4873 MPLS_FEC_PRELENLEN +
4874 (int)(fecAdrEl->addressEl.preLen / 8) +
4875 ((int)(fecAdrEl->addressEl.preLen % 8) > 0 ? 1 : 0);
4877 if (encodedSize > bufSize)
4879 return MPLS_ENC_BUFFTOOSMALL;
4881 *tempBuf = fecAdrEl->addressEl.type;
4882 tempBuf++; /* for MPLS_FEC_ELEMTYPELEN */
4884 MEM_COPY( tempBuf,
4885 (u_char*)&(fecAdrEl->addressEl.addressFam),
4886 MPLS_FEC_ADRFAMLEN);
4887 tempBuf += MPLS_FEC_ADRFAMLEN;
4889 *tempBuf = fecAdrEl->addressEl.preLen;
4890 tempBuf++; /* for MPLS_FEC_PRELENLEN */
4892 MEM_COPY( tempBuf,
4893 (u_char*)&(fecAdrEl->addressEl.address),
4894 (int)(fecAdrEl->addressEl.preLen / 8) +
4895 ((int)(fecAdrEl->addressEl.preLen % 8) > 0 ? 1 : 0));
4896 break;
4898 case MPLS_HOSTADR_FEC:
4900 fecAdrEl->addressEl.addressFam = htons(fecAdrEl->addressEl.addressFam);
4901 fecAdrEl->addressEl.address = htonl(fecAdrEl->addressEl.address);
4903 encodedSize = MPLS_FEC_ADRFAMLEN + MPLS_FEC_ELEMTYPELEN +
4904 MPLS_FEC_PRELENLEN + fecAdrEl->addressEl.preLen;
4906 if (encodedSize > bufSize)
4908 return MPLS_ENC_BUFFTOOSMALL;
4910 *tempBuf = fecAdrEl->addressEl.type;
4911 tempBuf++; /* for MPLS_FEC_ELEMTYPELEN */
4913 MEM_COPY( tempBuf,
4914 (u_char*)&(fecAdrEl->addressEl.addressFam),
4915 MPLS_FEC_ADRFAMLEN);
4916 tempBuf += MPLS_FEC_ADRFAMLEN;
4918 *tempBuf = fecAdrEl->addressEl.preLen;
4919 tempBuf++; /* for MPLS_FEC_PRELENLEN */
4921 MEM_COPY( tempBuf,
4922 (u_char*)&(fecAdrEl->addressEl.address),
4923 fecAdrEl->addressEl.preLen);
4924 break;
4926 case MPLS_CRLSP_FEC:
4928 if (MPLS_FEC_CRLSPLEN > bufSize)
4930 return MPLS_ENC_BUFFTOOSMALL;
4932 fecAdrEl->crlspEl.res1 = 0;
4933 fecAdrEl->crlspEl.res2 = 0;
4934 MEM_COPY( tempBuf,
4935 (u_char*)&(fecAdrEl->crlspEl),
4936 MPLS_FEC_CRLSPLEN);
4937 encodedSize = MPLS_FEC_CRLSPLEN;
4938 break;
4940 case MPLS_MARTINIVC_FEC:
4942 u_char *vcHead = tempBuf;
4943 int encoded = 0;
4944 int cur = 0;
4946 if (MPLS_FEC_MARTINILEN > bufSize)
4948 return MPLS_ENC_BUFFTOOSMALL;
4951 /* skip past the first MPLS_FEC_MARTINILEN bytes, we need
4952 * to know the vcInfoLen before we write that info,
4953 * 'encoded' will keep track of the vcInfoLen */
4955 encodedSize = MPLS_FEC_MARTINILEN;
4956 tempBuf += MPLS_FEC_MARTINILEN;
4958 if (fecAdrEl->martiniVcEl.vcId)
4961 fecAdrEl->martiniVcEl.vcId = htonl(fecAdrEl->martiniVcEl.vcId);
4963 MEM_COPY( tempBuf,
4964 (u_char*)&(fecAdrEl->martiniVcEl.vcId),
4965 MPLS_VCIDLEN);
4967 tempBuf += MPLS_VCIDLEN;
4968 encoded += MPLS_VCIDLEN;
4970 for (cur = 0; cur < fecAdrEl->martiniVcEl.vcIfParamsLen; cur++)
4972 int valueLen = 0;
4974 * This is dumb, the length in vcIfParam includes the type
4975 * and the length, so a length of 4 means 2 bytes of value
4978 *tempBuf = fecAdrEl->martiniVcEl.vcIfParams[cur].id;
4979 tempBuf++;
4980 *tempBuf = fecAdrEl->martiniVcEl.vcIfParams[cur].len;
4981 tempBuf++;
4983 valueLen = fecAdrEl->martiniVcEl.vcIfParams[cur].len;
4984 if (valueLen < MPLS_VCIFPARAM_HDR)
4986 /* because of this encoding we MUST have
4987 * atleast a length of MPLS_VCIFPARAM_HDR */
4988 return MPLS_ENC_FECERROR;
4990 valueLen -= MPLS_VCIFPARAM_HDR;
4992 if (valueLen)
4994 MEM_COPY( tempBuf,
4995 (u_char*)&(fecAdrEl->martiniVcEl.
4996 vcIfParams[cur].value),
4997 valueLen);
4998 tempBuf += valueLen;
5001 encoded += fecAdrEl->martiniVcEl.vcIfParams[cur].len;
5004 encodedSize += encoded;
5006 fecAdrEl->martiniVcEl.flags.flags.vcInfoLen = encoded;
5007 fecAdrEl->martiniVcEl.flags.mark =
5008 htonl(fecAdrEl->martiniVcEl.flags.mark);
5009 fecAdrEl->martiniVcEl.groupId =
5010 htonl(fecAdrEl->martiniVcEl.groupId);
5012 MEM_COPY( vcHead,
5013 (u_char*)&(fecAdrEl->martiniVcEl),
5014 MPLS_FEC_MARTINILEN);
5016 break;
5019 default:
5021 PRINT_ERR_2("Found wrong FEC type while encoding FEC elem (%d)\n",
5022 type);
5023 return MPLS_ENC_FECELEMERROR;
5024 break;
5026 } /* end: switch */
5028 return encodedSize;
5030 } /* End: Mpls_encodeLdpFecAdrEl*/
5034 * decode
5036 int Mpls_decodeLdpFecAdrEl
5038 mplsFecElement_t * fecAdrEl,
5039 u_char * buff,
5040 int bufSize,
5041 u_char type
5044 int decodedSize = 0;
5045 u_char * tempBuff = buff;
5046 u_int preLen = 0;
5048 switch (type)
5050 case MPLS_WC_FEC:
5052 fecAdrEl->wildcardEl.type = *buff;
5053 decodedSize = MPLS_FEC_ELEMTYPELEN;
5054 break;
5056 case MPLS_PREFIX_FEC:
5058 decodedSize = MPLS_FEC_ADRFAMLEN + MPLS_FEC_ELEMTYPELEN +
5059 MPLS_FEC_PRELENLEN;
5060 if (decodedSize > bufSize)
5062 return MPLS_DEC_BUFFTOOSMALL;
5064 fecAdrEl->addressEl.type = *tempBuff;
5065 tempBuff++; /* for MPLS_FEC_ELEMTYPELEN */
5067 MEM_COPY( (u_char*)&(fecAdrEl->addressEl.addressFam),
5068 tempBuff,
5069 MPLS_FEC_ADRFAMLEN);
5070 tempBuff += MPLS_FEC_ADRFAMLEN;
5072 fecAdrEl->addressEl.preLen = *tempBuff;
5073 tempBuff++; /* for MPLS_FEC_PRELENLEN */
5075 fecAdrEl->addressEl.addressFam = ntohs(fecAdrEl->addressEl.addressFam);
5077 /* now we get the prefix; we need to use the preLen which was
5078 decoded from buff */
5080 preLen = (int)(fecAdrEl->addressEl.preLen / 8) +
5081 ((int)(fecAdrEl->addressEl.preLen % 8) > 0 ? 1 : 0);
5083 if (fecAdrEl->addressEl.preLen > sizeof(u_int) * 8)
5085 /* error - the length cannot exeed 32 bits */
5086 /* skip the FEC and return error code */
5087 /* fill in the preLen field to the number of bytes for this
5088 fec; we need it to know how much to skip from the buffer
5089 when we do the decoding for the following fec element */
5090 fecAdrEl->addressEl.preLen = preLen + decodedSize;
5091 return MPLS_FECERROR;
5093 if ((int)preLen > bufSize - decodedSize)
5095 return MPLS_DEC_BUFFTOOSMALL;
5097 MEM_COPY( (u_char *)&(fecAdrEl->addressEl.address),
5098 tempBuff,
5099 preLen);
5101 fecAdrEl->addressEl.address = ntohl(fecAdrEl->addressEl.address);
5102 decodedSize += preLen;
5103 break;
5105 case MPLS_HOSTADR_FEC:
5107 decodedSize = MPLS_FEC_ADRFAMLEN + MPLS_FEC_ELEMTYPELEN +
5108 MPLS_FEC_PRELENLEN;
5109 if (decodedSize > bufSize)
5111 return MPLS_DEC_BUFFTOOSMALL;
5113 fecAdrEl->addressEl.type = *tempBuff;
5114 tempBuff++; /* for MPLS_FEC_ELEMTYPELEN */
5116 MEM_COPY( (u_char*)&(fecAdrEl->addressEl.addressFam),
5117 tempBuff,
5118 MPLS_FEC_ADRFAMLEN);
5119 tempBuff += MPLS_FEC_ADRFAMLEN;
5121 fecAdrEl->addressEl.preLen = *tempBuff;
5122 tempBuff++; /* for MPLS_FEC_PRELENLEN */
5124 fecAdrEl->addressEl.addressFam = ntohs(fecAdrEl->addressEl.addressFam);
5126 /* now we get the host address; we need to use the preLen which was
5127 decoded from buff */
5129 preLen = fecAdrEl->addressEl.preLen;
5130 if (fecAdrEl->addressEl.preLen > sizeof(u_int))
5132 /* error - the length cannot exeed 32 bits */
5133 /* skip the FEC and return error code */
5134 /* fill in the preLen field to the number of bytes for this
5135 fec; we need it to know how much to skip from the buffer
5136 when we do the decoding for the following fec element */
5137 fecAdrEl->addressEl.preLen = preLen + decodedSize;
5138 return MPLS_FECERROR;
5140 if ((int)preLen > bufSize - decodedSize)
5142 return MPLS_DEC_BUFFTOOSMALL;
5144 MEM_COPY( (u_char *)&(fecAdrEl->addressEl.address),
5145 tempBuff,
5146 preLen);
5148 fecAdrEl->addressEl.address = ntohl(fecAdrEl->addressEl.address);
5149 decodedSize += preLen;
5150 break;
5152 case MPLS_CRLSP_FEC:
5154 if (MPLS_FEC_CRLSPLEN > bufSize)
5156 return MPLS_DEC_BUFFTOOSMALL;
5158 MEM_COPY( (u_char*)&(fecAdrEl->crlspEl),
5159 tempBuff,
5160 MPLS_FEC_CRLSPLEN);
5161 decodedSize = MPLS_FEC_CRLSPLEN;
5162 break;
5164 case MPLS_MARTINIVC_FEC:
5166 int decoded = 0;
5167 int cur = 0;
5169 if (MPLS_FEC_MARTINILEN > bufSize)
5171 return MPLS_DEC_BUFFTOOSMALL;
5173 MEM_COPY( (u_char*)&(fecAdrEl->martiniVcEl),
5174 tempBuff,
5175 MPLS_FEC_MARTINILEN);
5177 decodedSize = MPLS_FEC_MARTINILEN;
5178 tempBuff += MPLS_FEC_MARTINILEN;
5180 fecAdrEl->martiniVcEl.flags.mark =
5181 ntohl(fecAdrEl->martiniVcEl.flags.mark);
5182 fecAdrEl->martiniVcEl.groupId =
5183 ntohl(fecAdrEl->martiniVcEl.groupId);
5185 if (fecAdrEl->martiniVcEl.flags.flags.vcInfoLen)
5187 MEM_COPY( (u_char*)&(fecAdrEl->martiniVcEl.vcId),
5188 tempBuff, MPLS_VCIDLEN);
5189 tempBuff += MPLS_VCIDLEN;
5190 decoded += MPLS_VCIDLEN;
5192 fecAdrEl->martiniVcEl.vcId = ntohl(fecAdrEl->martiniVcEl.vcId);
5194 while (fecAdrEl->martiniVcEl.flags.flags.vcInfoLen > decoded)
5196 int valueLen = 0;
5198 * This is dumb, the length in vcIfParam includes the type
5199 * and the length, so a length of 4 means 2 bytes of value
5202 fecAdrEl->martiniVcEl.vcIfParams[cur].id = *tempBuff++;
5203 fecAdrEl->martiniVcEl.vcIfParams[cur].len = *tempBuff++;
5205 valueLen = fecAdrEl->martiniVcEl.vcIfParams[cur].len;
5206 if (valueLen < MPLS_VCIFPARAM_HDR)
5208 /* because of this encoding we MUST have
5209 * atleast a length of MPLS_VCIFPARAM_HDR */
5210 return MPLS_DEC_FECERROR;
5212 valueLen -= MPLS_VCIFPARAM_HDR;
5214 if (valueLen)
5216 /* impl limitation, in the future this might be bigger */
5217 // assert(valueLen <= MPLS_VCIFPARAMMAXLEN)
5219 MEM_COPY( (u_char*)&(fecAdrEl->martiniVcEl.
5220 vcIfParams[cur].value),
5221 tempBuff,
5222 valueLen);
5223 tempBuff += valueLen;
5226 decoded += fecAdrEl->martiniVcEl.vcIfParams[cur].len;
5228 cur++;
5229 /* impl limitation, there are only 5 types right now */
5230 // assert (cur <= 5);
5233 fecAdrEl->martiniVcEl.vcIfParamsLen = cur;
5234 decodedSize += decoded;
5235 break;
5237 default:
5239 PRINT_ERR_2("Found wrong FEC type while decoding FEC elem (%d)\n",
5240 type);
5241 return MPLS_DEC_FECELEMERROR;
5242 break;
5244 } /* end: switch */
5246 return decodedSize;
5248 } /* End: Mpls_decodeLdpFecAdrEl*/
5254 * Encode for FEC TLV
5258 * encode
5260 int Mpls_encodeLdpFecTlv
5262 mplsLdpFecTlv_t * fecTlv,
5263 u_char * buff,
5264 int bufSize
5267 u_char * tempBuf = buff; /* no change for the buff ptr */
5268 u_short i;
5269 int encodedSize = 0;
5270 u_int fecElSize = 0; /* used to compute the sum of
5271 all fec elements */
5273 if ((int)fecTlv->baseTlv.length + MPLS_TLVFIXLEN > bufSize)
5275 /* not enough room */
5276 return MPLS_ENC_BUFFTOOSMALL;
5279 /* check how many fec elements we have */
5280 if (fecTlv->numberFecElements > MPLS_MAXNUMFECELEMENT)
5282 /* too many fec elem; need to increase MPLS_MAXNUMFECELEMENT */
5283 PRINT_ERR("Too many fec elem\n");
5284 return MPLS_FECTLVERROR;
5287 for (i = 0; i < fecTlv->numberFecElements; i++)
5289 if ( (fecTlv->fecElemTypes[i] == MPLS_WC_FEC) &&
5290 (fecTlv->numberFecElements != 1) )
5292 return MPLS_WC_FECERROR;
5297 * encode for tlv
5299 encodedSize = Mpls_encodeLdpTlv( &(fecTlv->baseTlv),
5300 tempBuf,
5301 bufSize);
5302 if (encodedSize < 0)
5304 PRINT_ERR("failed encoding the tlv in FEC tlv\n");
5305 return MPLS_ENC_TLVERROR;
5307 tempBuf += encodedSize;
5308 fecElSize += encodedSize;
5310 /* encode now the FEC elements; check if wc exists; if it is there
5311 then it should be the only element */
5313 for (i = 0; i < fecTlv->numberFecElements; i++)
5315 encodedSize = Mpls_encodeLdpFecAdrEl(&(fecTlv->fecElArray[i]),
5316 tempBuf,
5317 bufSize - fecElSize,
5318 fecTlv->fecElemTypes[i]);
5319 if(encodedSize < 0)
5321 return MPLS_ENC_FECELEMERROR;
5323 tempBuf += encodedSize;
5324 fecElSize += encodedSize;
5327 return fecElSize;
5329 } /* End: Mpls_encodeLdpFecTlv */
5334 * decode
5336 int Mpls_decodeLdpFecTlv
5338 mplsLdpFecTlv_t * fecTlv,
5339 u_char * buff,
5340 int bufSize,
5341 u_short tlvLength
5344 u_char * tempBuf = buff; /* no change for the buff ptr */
5345 int decodedSize = 0;
5346 u_int fecElSize = 0; /* used to compute the sum of
5347 all fec elements */
5348 u_short i = 0;
5349 u_char type;
5351 if ((int)tlvLength > bufSize)
5353 /* not enough data for Fec elements tlv*/
5354 PRINT_ERR("failed decoding FEC elements tlv\n");
5355 return MPLS_DEC_BUFFTOOSMALL;
5359 * decode for the FEC elements; check also that if we have a wc element,
5360 * it is the only element encoded in the FEC;
5362 type = *tempBuf; /* first thing after the TLV base should be the type
5363 of the fec element */
5365 fecTlv->numberFecElements = 0;
5367 while (tlvLength > fecElSize)
5370 /* check how many fec elements we have */
5371 if (fecTlv->numberFecElements > (u_short)(MPLS_MAXNUMFECELEMENT-1))
5373 /* too many fec elem; need to increase MPLS_MAXNUMFECELEMENT */
5374 PRINT_ERR("Too many fec elem\n");
5375 return MPLS_FECTLVERROR;
5378 decodedSize = Mpls_decodeLdpFecAdrEl(&(fecTlv->fecElArray[i]),
5379 tempBuf,
5380 bufSize - fecElSize,
5381 type);
5382 if((decodedSize < 0) && (decodedSize != MPLS_FECERROR))
5384 return MPLS_DEC_FECELEMERROR;
5386 else
5388 /* if the element had wrong preLen value, just skip it */
5389 if (decodedSize != MPLS_FECERROR)
5391 fecTlv->fecElemTypes[i] = type;
5392 fecTlv->numberFecElements++;
5393 i++;
5395 tempBuf += decodedSize;
5396 fecElSize += decodedSize;
5398 else
5400 /* the preLen was filled with the total length
5401 of the fec element to be skipped */
5402 tempBuf += fecTlv->fecElArray[i].addressEl.preLen;
5403 fecElSize += fecTlv->fecElArray[i].addressEl.preLen;
5407 /* get the type of the next element */
5408 type = *tempBuf;
5410 } /* end while */
5412 for (i = 0; i < fecTlv->numberFecElements; i++)
5414 if ( (fecTlv->fecElemTypes[i] == MPLS_WC_FEC) &&
5415 (fecTlv->numberFecElements != 1) )
5417 return MPLS_WC_FECERROR;
5421 return fecElSize; /* fecElSize should be equal to tlvLength */
5423 } /* End: Mpls_decodeLdpFecTlv */
5428 * Encode for Generic label TLV
5432 * encode
5434 int Mpls_encodeLdpGenLblTlv
5436 mplsLdpGenLblTlv_t * genLbl,
5437 u_char * buff,
5438 int bufSize
5441 int encodedSize = 0;
5442 u_char * tempBuf = buff; /* no change for the buff ptr */
5444 if (MPLS_TLVFIXLEN + (int)(genLbl->baseTlv.length) > bufSize)
5446 /* not enough room */
5447 return MPLS_ENC_BUFFTOOSMALL;
5451 * encode for tlv
5453 encodedSize = Mpls_encodeLdpTlv( &(genLbl->baseTlv),
5454 tempBuf,
5455 bufSize);
5456 if (encodedSize < 0)
5458 PRINT_ERR("failed encoding the tlv in Generic Label\n");
5459 return MPLS_ENC_TLVERROR;
5461 tempBuf += encodedSize;
5463 genLbl->label = htonl(genLbl->label);
5465 MEM_COPY(tempBuf,
5466 (u_char*)&(genLbl->label),
5467 MPLS_LBLFIXLEN);
5469 return (MPLS_TLVFIXLEN + MPLS_LBLFIXLEN);
5471 } /* End: Mpls_encodeLdpGenLblTlv */
5475 * decode
5477 int Mpls_decodeLdpGenLblTlv
5479 mplsLdpGenLblTlv_t * genLbl,
5480 u_char * buff,
5481 int bufSize
5484 if (MPLS_LBLFIXLEN > bufSize)
5486 /* not enough data for generic label tlv*/
5487 PRINT_ERR("failed decoding Generic tlv\n");
5488 return MPLS_DEC_BUFFTOOSMALL;
5492 * decode the label
5494 MEM_COPY( (u_char*)&(genLbl->label),
5495 buff,
5496 MPLS_LBLFIXLEN);
5498 genLbl->label = ntohl(genLbl->label);
5500 return MPLS_LBLFIXLEN;
5502 } /* End: Mpls_decodeLdpGenLblTlv */
5507 * Encode for ATM Label TLV
5511 * encode
5513 int Mpls_encodeLdpAtmLblTlv
5515 mplsLdpAtmLblTlv_t * atmLblTlv,
5516 u_char * buff,
5517 int bufSize
5520 int encodedSize = 0;
5521 u_char * tempBuf = buff; /* no change for the buff ptr */
5522 u_char * atmLblPtr;
5524 if (MPLS_TLVFIXLEN + MPLS_LBLFIXLEN > bufSize)
5526 /* not enough room */
5527 return MPLS_ENC_BUFFTOOSMALL;
5530 atmLblPtr = (u_char*)atmLblTlv;
5533 * encode for tlv
5535 encodedSize = Mpls_encodeLdpTlv( &(atmLblTlv->baseTlv),
5536 tempBuf,
5537 MPLS_TLVFIXLEN);
5538 if (encodedSize < 0)
5540 return MPLS_ENC_TLVERROR;
5542 tempBuf += encodedSize;
5543 atmLblPtr += encodedSize;
5546 * encode for flags
5548 atmLblTlv->flags.flags.res = 0;
5549 atmLblTlv->flags.mark = htons(atmLblTlv->flags.mark);
5550 atmLblTlv->vci = htons(atmLblTlv->vci);
5552 MEM_COPY( tempBuf,
5553 atmLblPtr,
5554 MPLS_LBLFIXLEN);
5556 return (MPLS_LBLFIXLEN + MPLS_TLVFIXLEN);
5558 } /* End: Mpls_encodeLdpAtmLblTlv */
5562 * decode
5564 int Mpls_decodeLdpAtmLblTlv
5566 mplsLdpAtmLblTlv_t * atmLblTlv,
5567 u_char * buff,
5568 int bufSize
5571 u_char * atmLblTlvPtr;
5573 if (MPLS_LBLFIXLEN> bufSize)
5575 /* not enough data for AtmLabel*/
5576 PRINT_ERR("failed decoding atm label tlv\n");
5577 return MPLS_DEC_BUFFTOOSMALL;
5580 atmLblTlvPtr = (u_char *)atmLblTlv;
5581 atmLblTlvPtr += MPLS_TLVFIXLEN; /* to point after the Tlv which was
5582 decoded before we reach here */
5584 * decode for the rest of the AtmLblTlv
5586 MEM_COPY( atmLblTlvPtr,
5587 buff,
5588 MPLS_LBLFIXLEN);
5590 atmLblTlv->flags.mark = ntohs(atmLblTlv->flags.mark);
5591 atmLblTlv->vci = ntohs(atmLblTlv->vci);
5593 return MPLS_LBLFIXLEN;
5595 } /* End: Mpls_decodeLdpAtmLblTlv */
5599 * Encode for FR Label TLV
5603 * encode
5605 int Mpls_encodeLdpFrLblTlv
5607 mplsLdpFrLblTlv_t * frLblTlv,
5608 u_char * buff,
5609 int bufSize
5612 int encodedSize = 0;
5613 u_char * tempBuf = buff; /* no change for the buff ptr */
5615 if (MPLS_TLVFIXLEN + MPLS_LBLFIXLEN > bufSize)
5617 /* not enough room */
5618 return MPLS_ENC_BUFFTOOSMALL;
5622 * encode for tlv
5624 encodedSize = Mpls_encodeLdpTlv( &(frLblTlv->baseTlv),
5625 tempBuf,
5626 MPLS_TLVFIXLEN);
5627 if (encodedSize < 0)
5629 return MPLS_ENC_TLVERROR;
5631 tempBuf += encodedSize;
5634 * encode for flags
5636 frLblTlv->flags.mark = htonl(frLblTlv->flags.mark);
5638 MEM_COPY( tempBuf,
5639 (u_char*)&(frLblTlv->flags.mark),
5640 MPLS_LBLFIXLEN);
5642 return (MPLS_LBLFIXLEN + MPLS_TLVFIXLEN);
5644 } /* End: Mpls_encodeLdpFrLblTlv */
5648 * decode
5650 int Mpls_decodeLdpFrLblTlv
5652 mplsLdpFrLblTlv_t * frLblTlv,
5653 u_char * buff,
5654 int bufSize
5657 u_char * tempBuf = buff; /* no change for the buff ptr */
5659 if (MPLS_LBLFIXLEN> bufSize)
5661 /* not enough data for FrLabel */
5662 PRINT_ERR("failed decoding fr label tlv\n");
5663 return MPLS_DEC_BUFFTOOSMALL;
5667 * decode for the rest of the FrLblTlv
5669 MEM_COPY( (u_char*)&(frLblTlv->flags.mark),
5670 tempBuf,
5671 MPLS_LBLFIXLEN);
5673 frLblTlv->flags.mark = ntohl(frLblTlv->flags.mark);
5675 return MPLS_LBLFIXLEN;
5677 } /* End: Mpls_decodeLdpFrLblTlv */
5682 * Encode for Hop Count TLV
5686 * encode
5688 int Mpls_encodeLdpHopTlv
5690 mplsLdpHopTlv_t * hopCountTlv,
5691 u_char * buff,
5692 int bufSize
5695 int encodedSize = 0;
5696 u_char * tempBuf = buff; /* no change for the buff ptr */
5698 if (MPLS_TLVFIXLEN + MPLS_HOPCOUNTFIXLEN > bufSize)
5700 /* not enough room */
5701 return MPLS_ENC_BUFFTOOSMALL;
5705 * encode for tlv
5707 encodedSize = Mpls_encodeLdpTlv( &(hopCountTlv->baseTlv),
5708 tempBuf,
5709 MPLS_TLVFIXLEN);
5710 if (encodedSize < 0)
5712 return MPLS_ENC_TLVERROR;
5714 tempBuf += encodedSize;
5717 * encode for hop count value
5719 *tempBuf = hopCountTlv->hcValue;
5721 return (MPLS_HOPCOUNTFIXLEN + MPLS_TLVFIXLEN);
5723 } /* End: Mpls_encodeLdpFrLblTlv */
5727 * decode
5729 int Mpls_decodeLdpHopTlv
5731 mplsLdpHopTlv_t * hopCountTlv,
5732 u_char * buff,
5733 int bufSize
5736 if (MPLS_HOPCOUNTFIXLEN > bufSize)
5738 /* not enough data for hop count value*/
5739 PRINT_ERR("failed decoding hop count tlv\n");
5740 return MPLS_DEC_BUFFTOOSMALL;
5744 * decode for the hop count value
5746 hopCountTlv->hcValue = *buff;
5748 return MPLS_HOPCOUNTFIXLEN;
5750 } /* End: Mpls_decodeLdpHopTlv */
5756 * Encode for Lbl Msg Id TLV
5760 * encode
5762 int Mpls_encodeLdpLblMsgIdTlv
5764 mplsLdpLblMsgIdTlv_t * lblMsgIdTlv,
5765 u_char * buff,
5766 int bufSize
5769 int encodedSize = 0;
5770 u_char * tempBuf = buff; /* no change for the buff ptr */
5772 if (MPLS_TLVFIXLEN + MPLS_LBLFIXLEN > bufSize)
5774 /* not enough room */
5775 return MPLS_ENC_BUFFTOOSMALL;
5779 * encode for tlv
5781 encodedSize = Mpls_encodeLdpTlv( &(lblMsgIdTlv->baseTlv),
5782 tempBuf,
5783 MPLS_TLVFIXLEN);
5784 if (encodedSize < 0)
5786 return MPLS_ENC_TLVERROR;
5788 tempBuf += encodedSize;
5791 * encode for msg id
5794 lblMsgIdTlv->msgId = htonl(lblMsgIdTlv->msgId);
5796 MEM_COPY( tempBuf,
5797 (u_char*)&(lblMsgIdTlv->msgId),
5798 MPLS_LBLFIXLEN);
5800 return (MPLS_LBLFIXLEN + MPLS_TLVFIXLEN);
5802 } /* End: Mpls_encodeLdpFrLblTlv */
5806 * decode
5808 int Mpls_decodeLdpLblMsgIdTlv
5810 mplsLdpLblMsgIdTlv_t * lblMsgIdTlv,
5811 u_char * buff,
5812 int bufSize
5815 if (MPLS_LBLFIXLEN> bufSize)
5817 /* not enough data for msg id tlv*/
5818 PRINT_ERR("failed decoding lbl msg id tlv\n");
5819 return MPLS_DEC_BUFFTOOSMALL;
5823 * decode for the rest of the LblMsgId Tlv
5825 MEM_COPY( (u_char*)&(lblMsgIdTlv->msgId),
5826 buff,
5827 MPLS_LBLFIXLEN);
5829 lblMsgIdTlv->msgId = ntohl(lblMsgIdTlv->msgId);
5831 return MPLS_LBLFIXLEN;
5833 } /* End: Mpls_decodeLdpLblMsgIdTlv */
5838 * Encode for Path Vector TLV
5842 * encode
5844 int Mpls_encodeLdpPathVectorTlv
5846 mplsLdpPathTlv_t * pathVectorTlv,
5847 u_char * buff,
5848 int bufSize
5851 u_char * pathVectorTlvPtr;
5852 u_char * tempBuf = buff; /* no change for the buff ptr */
5853 int encodedSize = 0;
5854 u_int i, numLsrIds;
5855 u_short tempLength; /* to store the tlv length for
5856 later use */
5858 if (MPLS_TLVFIXLEN + (int)(pathVectorTlv->baseTlv.length)> bufSize)
5860 /* not enough room */
5861 return MPLS_ENC_BUFFTOOSMALL;
5864 pathVectorTlvPtr = (u_char*)pathVectorTlv;
5865 tempLength = pathVectorTlv->baseTlv.length;
5867 * encode for tlv
5869 encodedSize = Mpls_encodeLdpTlv( &(pathVectorTlv->baseTlv),
5870 tempBuf,
5871 MPLS_TLVFIXLEN);
5872 if (encodedSize < 0)
5874 return MPLS_ENC_TLVERROR;
5876 tempBuf += encodedSize;
5877 pathVectorTlvPtr += encodedSize;
5880 * encode for labels
5883 if (tempLength % MPLS_LBLFIXLEN != 0)
5885 return MPLS_PATHVECTORERROR;
5888 numLsrIds = tempLength / MPLS_LBLFIXLEN;
5889 if (numLsrIds > MPLS_MAXHOPSNUMBER)
5891 /* too many lsrIds; need to increase MPLS_MAXHOPSNUMBER */
5892 PRINT_ERR_2("Too many lsr ids (%d)\n", numLsrIds);
5893 return MPLS_PATHVECTORERROR;
5896 for (i = 0; i < numLsrIds; i++)
5898 pathVectorTlv->lsrId[i] = htonl(pathVectorTlv->lsrId[i]);
5901 MEM_COPY( tempBuf,
5902 pathVectorTlvPtr,
5903 tempLength);
5905 return (tempLength + MPLS_TLVFIXLEN);
5907 } /* End: Mpls_encodeLdpPathVectorTlv */
5911 * decode
5913 int Mpls_decodeLdpPathVectorTlv
5915 mplsLdpPathTlv_t * pathVectorTlv,
5916 u_char * buff,
5917 int bufSize,
5918 u_short tlvLength
5921 u_char * tempBuf = buff; /* no change for the buff ptr */
5922 u_int i, numLsrIds;
5924 if (MPLS_LBLFIXLEN> bufSize)
5926 /* not enough data for msg id tlv*/
5927 PRINT_ERR("failed decoding lbl msg id tlv\n");
5928 return MPLS_DEC_BUFFTOOSMALL;
5931 if (tlvLength % MPLS_LBLFIXLEN != 0)
5933 PRINT_ERR_2("Wrong length for Path vector tlv (%d)\n", tlvLength);
5934 return MPLS_PATHVECTORERROR;
5937 numLsrIds = tlvLength / MPLS_LBLFIXLEN;
5938 if (numLsrIds > MPLS_MAXHOPSNUMBER)
5940 /* too many lsrIds; need to increase MPLS_MAXHOPSNUMBER */
5941 PRINT_ERR_2("Too many lsr ids (%d)\n", numLsrIds);
5942 return MPLS_PATHVECTORERROR;
5946 * decode for the rest of the LblMsgId Tlv
5948 MEM_COPY( (u_char*)(pathVectorTlv->lsrId),
5949 tempBuf,
5950 tlvLength);
5952 for (i = 0; i < numLsrIds; i++)
5954 pathVectorTlv->lsrId[i] = ntohl(pathVectorTlv->lsrId[i]);
5957 return tlvLength;
5959 } /* End: Mpls_decodeLdpPathVectorTlv */
5964 * Encode for Label Mapping Message
5968 * encode
5970 int Mpls_encodeLdpLblMapMsg
5972 mplsLdpLblMapMsg_t * lblMapMsg,
5973 u_char * buff,
5974 int bufSize
5977 mplsLdpLblMapMsg_t lblMapMsgCopy;
5978 int encodedSize = 0;
5979 u_int totalSize = 0;
5980 u_char * tempBuf = buff; /* no change for the buff ptr */
5982 /* check the length of the messageId + param */
5983 if ((int)(lblMapMsg->baseMsg.msgLength) + MPLS_TLVFIXLEN > bufSize)
5985 PRINT_ERR("failed to encode the lbl mapping msg: BUFFER TOO SMALL\n");
5986 return MPLS_ENC_BUFFTOOSMALL;
5989 lblMapMsgCopy = *lblMapMsg;
5992 * encode the base part of the pdu message
5994 encodedSize = Mpls_encodeLdpBaseMsg( &(lblMapMsgCopy.baseMsg),
5995 tempBuf,
5996 bufSize);
5997 if (encodedSize < 0)
5999 return MPLS_ENC_BASEMSGERROR;
6001 PRINT_2("Encode BaseMsg for label mapping on %d bytes\n", encodedSize);
6002 tempBuf += encodedSize;
6003 totalSize += encodedSize;
6006 * encode the tlv if any
6008 if (lblMapMsgCopy.fecTlvExists)
6010 encodedSize = Mpls_encodeLdpFecTlv( &(lblMapMsgCopy.fecTlv),
6011 tempBuf,
6012 bufSize-totalSize);
6013 if (encodedSize < 0)
6015 return MPLS_ENC_FECERROR;
6017 PRINT_2("Encoded for FEC Tlv %d bytes\n", encodedSize);
6018 tempBuf += encodedSize;
6019 totalSize += encodedSize;
6022 if (lblMapMsgCopy.genLblTlvExists)
6024 encodedSize = Mpls_encodeLdpGenLblTlv( &(lblMapMsgCopy.genLblTlv),
6025 tempBuf,
6026 bufSize-totalSize);
6027 if (encodedSize < 0)
6029 return MPLS_ENC_GENLBLERROR;
6031 PRINT_2("Encoded for Generic Label Tlv %d bytes\n", encodedSize);
6032 tempBuf += encodedSize;
6033 totalSize += encodedSize;
6035 if (lblMapMsgCopy.atmLblTlvExists)
6037 encodedSize = Mpls_encodeLdpAtmLblTlv( &(lblMapMsgCopy.atmLblTlv),
6038 tempBuf,
6039 bufSize-totalSize);
6040 if (encodedSize < 0)
6042 return MPLS_ENC_MAPATMERROR;
6044 PRINT_2("Encoded for Atm Label Tlv %d bytes\n", encodedSize);
6045 tempBuf += encodedSize;
6046 totalSize += encodedSize;
6048 if (lblMapMsgCopy.frLblTlvExists)
6050 encodedSize = Mpls_encodeLdpFrLblTlv( &(lblMapMsgCopy.frLblTlv),
6051 tempBuf,
6052 bufSize-totalSize);
6053 if (encodedSize < 0)
6055 return MPLS_ENC_FRLBLERROR;
6057 PRINT_2("Encoded for Fr Label Tlv %d bytes\n", encodedSize);
6058 tempBuf += encodedSize;
6059 totalSize += encodedSize;
6061 if (lblMapMsgCopy.hopCountTlvExists)
6063 encodedSize = Mpls_encodeLdpHopTlv( &(lblMapMsgCopy.hopCountTlv),
6064 tempBuf,
6065 bufSize-totalSize);
6066 if (encodedSize < 0)
6068 return MPLS_ENC_HOPCOUNTERROR;
6070 PRINT_2("Encoded for Hop Count Tlv %d bytes\n", encodedSize);
6071 tempBuf += encodedSize;
6072 totalSize += encodedSize;
6074 if (lblMapMsgCopy.pathVecTlvExists)
6076 encodedSize = Mpls_encodeLdpPathVectorTlv( &(lblMapMsgCopy.pathVecTlv),
6077 tempBuf,
6078 bufSize-totalSize);
6079 if (encodedSize < 0)
6081 return MPLS_ENC_PATHVECERROR;
6083 PRINT_2("Encoded for Path Vector Tlv %d bytes\n", encodedSize);
6084 tempBuf += encodedSize;
6085 totalSize += encodedSize;
6087 if (lblMapMsgCopy.lblMsgIdTlvExists)
6089 encodedSize = Mpls_encodeLdpLblMsgIdTlv( &(lblMapMsgCopy.lblMsgIdTlv),
6090 tempBuf,
6091 bufSize-totalSize);
6092 if (encodedSize < 0)
6094 return MPLS_ENC_LBLMSGIDERROR;
6096 PRINT_2("Encoded for lbl request msg id Tlv %d bytes\n", encodedSize);
6097 tempBuf += encodedSize;
6098 totalSize += encodedSize;
6100 if (lblMapMsgCopy.trafficTlvExists)
6102 encodedSize = Mpls_encodeLdpTrafficTlv( &(lblMapMsgCopy.trafficTlv),
6103 tempBuf,
6104 bufSize-totalSize);
6105 if (encodedSize < 0)
6107 return MPLS_ENC_TRAFFICERROR;
6109 PRINT_2("Encoded for Traffic Tlv %d bytes\n", encodedSize);
6110 tempBuf += encodedSize;
6111 totalSize += encodedSize;
6113 if (lblMapMsgCopy.lspidTlvExists)
6115 encodedSize = Mpls_encodeLdpLspIdTlv( &(lblMapMsgCopy.lspidTlv),
6116 tempBuf,
6117 bufSize-totalSize);
6118 if (encodedSize < 0)
6120 return MPLS_ENC_LSPIDERROR;
6122 PRINT_2("Encoded for LSPID Tlv %d bytes\n", encodedSize);
6123 tempBuf += encodedSize;
6124 totalSize += encodedSize;
6127 return totalSize;
6129 } /* End: Mpls_encodeLdpLblMapMsg */
6133 * decode
6135 int Mpls_decodeLdpLblMapMsg
6137 mplsLdpLblMapMsg_t * lblMapMsg,
6138 u_char * buff,
6139 int bufSize
6142 int decodedSize = 0;
6143 u_int totalSize = 0;
6144 u_int stopLength = 0;
6145 u_int totalSizeParam = 0;
6146 u_char * tempBuf = buff; /* no change for the buff ptr */
6147 mplsLdpTlv_t tlvTemp;
6150 * decode the base part of the pdu message
6152 bzero(lblMapMsg, sizeof(mplsLdpLblMapMsg_t));
6153 decodedSize = Mpls_decodeLdpBaseMsg( &(lblMapMsg->baseMsg),
6154 tempBuf,
6155 bufSize);
6156 if (decodedSize < 0)
6158 return MPLS_DEC_BASEMSGERROR;
6160 PRINT_2("Decode BaseMsg for Lbl Mapping on %d bytes\n", decodedSize);
6162 if (lblMapMsg->baseMsg.flags.flags.msgType != MPLS_LBLMAP_MSGTYPE)
6164 PRINT_ERR_2("Not the right message type; expected lbl map and got %x\n",
6165 lblMapMsg->baseMsg.flags.flags.msgType);
6166 return MPLS_MSGTYPEERROR;
6169 tempBuf += decodedSize;
6170 totalSize += decodedSize;
6172 if (bufSize-totalSize <= 0)
6174 /* nothing left for decoding */
6175 PRINT_ERR("Lbl Mapping msg does not have anything beside base msg\n");
6176 return totalSize;
6179 PRINT_4("bufSize = %d, totalSize = %d, lblMapMsg->baseMsg.msgLength = %d\n",
6180 bufSize, totalSize, lblMapMsg->baseMsg.msgLength);
6182 /* Have to check the baseMsg.msgLength to know when to finish.
6183 * We finsh when the totalSizeParam is >= to the base message length - the
6184 * message id length (4)
6187 stopLength = lblMapMsg->baseMsg.msgLength - MPLS_MSGIDFIXLEN;
6188 while (stopLength > totalSizeParam)
6191 * decode the tlv to check what's next
6193 bzero(&tlvTemp, MPLS_TLVFIXLEN);
6194 decodedSize = Mpls_decodeLdpTlv(&tlvTemp, tempBuf, bufSize-totalSize);
6195 if (decodedSize < 0)
6197 /* something wrong */
6198 PRINT_ERR("Label Mapping msg decode failed for tlv\n");
6199 return MPLS_DEC_TLVERROR;
6202 tempBuf += decodedSize;
6203 totalSize += decodedSize;
6204 totalSizeParam += decodedSize;
6206 switch (tlvTemp.flags.flags.type)
6208 case MPLS_FEC_TLVTYPE:
6210 decodedSize = Mpls_decodeLdpFecTlv( &(lblMapMsg->fecTlv),
6211 tempBuf,
6212 bufSize-totalSize,
6213 tlvTemp.length);
6214 if (decodedSize < 0)
6216 PRINT_ERR("Failure when decoding FEC tlv from LblMap msg\n");
6217 return MPLS_DEC_FECERROR;
6219 PRINT_2("Decoded for FEC %d bytes\n", decodedSize);
6220 tempBuf += decodedSize;
6221 totalSize += decodedSize;
6222 totalSizeParam += decodedSize;
6224 lblMapMsg->fecTlvExists = 1;
6225 lblMapMsg->fecTlv.baseTlv = tlvTemp;
6226 DEBUG_CALL(printFecListTlv(&(lblMapMsg->fecTlv)));
6227 break;
6229 case MPLS_GENLBL_TLVTYPE:
6231 decodedSize = Mpls_decodeLdpGenLblTlv( &(lblMapMsg->genLblTlv),
6232 tempBuf,
6233 bufSize-totalSize);
6234 if (decodedSize < 0)
6236 PRINT_ERR("Failure when dec GEN Lbl tlv from LblMap msg\n");
6237 return MPLS_DEC_GENLBLERROR;
6239 PRINT_2("Decoded for Gen Lbl %d bytes\n", decodedSize);
6240 tempBuf += decodedSize;
6241 totalSize += decodedSize;
6242 totalSizeParam += decodedSize;
6244 lblMapMsg->genLblTlvExists = 1;
6245 lblMapMsg->genLblTlv.baseTlv = tlvTemp;
6246 DEBUG_CALL(printGenLblTlv(&(lblMapMsg->genLblTlv)));
6247 break;
6249 case MPLS_ATMLBL_TLVTYPE:
6251 decodedSize = Mpls_decodeLdpAtmLblTlv( &(lblMapMsg->atmLblTlv),
6252 tempBuf,
6253 bufSize-totalSize);
6254 if (decodedSize < 0)
6256 PRINT_ERR("Failure when dec ATM Lbl tlv from LblMap msg\n");
6257 return MPLS_DEC_MAPATMERROR;
6259 PRINT_2("Decoded for Atm Lbl %d bytes\n", decodedSize);
6260 tempBuf += decodedSize;
6261 totalSize += decodedSize;
6262 totalSizeParam += decodedSize;
6264 lblMapMsg->atmLblTlvExists = 1;
6265 lblMapMsg->atmLblTlv.baseTlv = tlvTemp;
6266 DEBUG_CALL(printAtmLblTlv(&(lblMapMsg->atmLblTlv)));
6267 break;
6269 case MPLS_FRLBL_TLVTYPE:
6271 decodedSize = Mpls_decodeLdpFrLblTlv( &(lblMapMsg->frLblTlv),
6272 tempBuf,
6273 bufSize-totalSize);
6274 if (decodedSize < 0)
6276 PRINT_ERR("Failure when dec FR Lbl tlv from LblMap msg\n");
6277 return MPLS_DEC_FRLBLERROR;
6279 PRINT_2("Decoded for Fr Lbl %d bytes\n", decodedSize);
6280 tempBuf += decodedSize;
6281 totalSize += decodedSize;
6282 totalSizeParam += decodedSize;
6284 lblMapMsg->frLblTlvExists = 1;
6285 lblMapMsg->frLblTlv.baseTlv = tlvTemp;
6286 DEBUG_CALL(printFrLblTlv(&(lblMapMsg->frLblTlv)));
6287 break;
6289 case MPLS_HOPCOUNT_TLVTYPE:
6291 decodedSize = Mpls_decodeLdpHopTlv( &(lblMapMsg->hopCountTlv),
6292 tempBuf,
6293 bufSize-totalSize);
6294 if (decodedSize < 0)
6296 PRINT_ERR("Failure when dec HopCount tlv from LblMap msg\n");
6297 return MPLS_DEC_HOPCOUNTERROR;
6299 PRINT_2("Decoded for HopCount %d bytes\n", decodedSize);
6300 tempBuf += decodedSize;
6301 totalSize += decodedSize;
6302 totalSizeParam += decodedSize;
6304 lblMapMsg->hopCountTlvExists = 1;
6305 lblMapMsg->hopCountTlv.baseTlv = tlvTemp;
6306 DEBUG_CALL(printHopTlv(&(lblMapMsg->hopCountTlv)));
6307 break;
6309 case MPLS_PATH_TLVTYPE:
6311 decodedSize = Mpls_decodeLdpPathVectorTlv(&(lblMapMsg->pathVecTlv),
6312 tempBuf,
6313 bufSize-totalSize,
6314 tlvTemp.length);
6315 if (decodedSize < 0)
6317 PRINT_ERR("Failure when dec Path Vec tlv from LblMap msg\n");
6318 return MPLS_DEC_PATHVECERROR;
6320 PRINT_2("Decoded for PATH VECTOR %d bytes\n", decodedSize);
6321 tempBuf += decodedSize;
6322 totalSize += decodedSize;
6323 totalSizeParam += decodedSize;
6325 lblMapMsg->pathVecTlvExists = 1;
6326 lblMapMsg->pathVecTlv.baseTlv = tlvTemp;
6327 DEBUG_CALL(printPathVecTlv(&(lblMapMsg->pathVecTlv)));
6328 break;
6330 case MPLS_REQMSGID_TLVTYPE:
6332 decodedSize = Mpls_decodeLdpLblMsgIdTlv( &(lblMapMsg->lblMsgIdTlv),
6333 tempBuf,
6334 bufSize-totalSize);
6335 if (decodedSize < 0)
6337 PRINT_ERR("Failure when dec LblMsgId tlv from LblMap msg\n");
6338 return MPLS_DEC_LBLMSGIDERROR;
6340 PRINT_2("Decoded for LblMsgId %d bytes\n", decodedSize);
6341 tempBuf += decodedSize;
6342 totalSize += decodedSize;
6343 totalSizeParam += decodedSize;
6345 lblMapMsg->lblMsgIdTlvExists = 1;
6346 lblMapMsg->lblMsgIdTlv.baseTlv = tlvTemp;
6347 DEBUG_CALL(printLblMsgIdTlv(&(lblMapMsg->lblMsgIdTlv)));
6348 break;
6350 case MPLS_TRAFFIC_TLVTYPE:
6352 decodedSize = Mpls_decodeLdpTrafficTlv( &(lblMapMsg->trafficTlv),
6353 tempBuf,
6354 bufSize-totalSize,
6355 tlvTemp.length);
6356 if (decodedSize < 0)
6358 PRINT_ERR("Failure when dec Traffic tlv from LblMap msg\n");
6359 return MPLS_DEC_TRAFFICERROR;
6361 PRINT_2("Decoded for Traffic %d bytes\n", decodedSize);
6362 tempBuf += decodedSize;
6363 totalSize += decodedSize;
6364 totalSizeParam += decodedSize;
6366 lblMapMsg->trafficTlvExists = 1;
6367 lblMapMsg->trafficTlv.baseTlv = tlvTemp;
6368 DEBUG_CALL(printTrafficTlv(&(lblMapMsg->trafficTlv)));
6369 break;
6371 case MPLS_LSPID_TLVTYPE:
6373 decodedSize = Mpls_decodeLdpLspIdTlv( &(lblMapMsg->lspidTlv),
6374 tempBuf,
6375 bufSize-totalSize);
6376 if (decodedSize < 0)
6378 PRINT_ERR("Failure when dec LSPID tlv from LblMap msg\n");
6379 return MPLS_DEC_LSPIDERROR;
6381 PRINT_2("Decoded for lspid tlv %d bytes\n", decodedSize);
6382 tempBuf += decodedSize;
6383 totalSize += decodedSize;
6384 totalSizeParam += decodedSize;
6386 lblMapMsg->lspidTlvExists = 1;
6387 lblMapMsg->lspidTlv.baseTlv = tlvTemp;
6388 DEBUG_CALL(printLspIdTlv(&(lblMapMsg->lspidTlv)));
6389 break;
6391 default:
6393 PRINT_ERR_2("Found wrong tlv type while decoding lbl map msg (%x)\n",
6394 tlvTemp.flags.flags.type);
6395 if (tlvTemp.flags.flags.uBit == 1)
6397 /* ignore the Tlv and continue processing */
6398 tempBuf += tlvTemp.length;
6399 totalSize += tlvTemp.length;
6400 totalSizeParam += tlvTemp.length;
6401 break;
6403 else
6405 /* drop the message; return error */
6406 return MPLS_TLVTYPEERROR;
6409 } /* switch type */
6411 } /* while */
6413 PRINT_2("totalsize for Mpls_decodeLdpLblMapMsg is %d\n", totalSize);
6415 return totalSize;
6417 } /* End: Mpls_decodeLdpLblMapMsg */
6422 * Encode for Retrun MessageId TLV
6426 * encode
6428 int Mpls_encodeLdpLblRetMsgIdTlv
6430 mplsLdpLblRetMsgIdTlv_t * lblMsgIdTlv,
6431 u_char * buff,
6432 int bufSize
6436 * encode for tlv
6438 if( Mpls_encodeLdpTlv( &(lblMsgIdTlv->baseTlv),
6439 buff,
6440 MPLS_TLVFIXLEN) < 0)
6442 return MPLS_ENC_TLVERROR;
6445 return MPLS_TLVFIXLEN;
6447 } /* End: Mpls_encodeLdpLblRetMsgIdTlv */
6450 * decode
6452 int Mpls_decodeLdpLblRetMsgIdTlv
6454 mplsLdpLblRetMsgIdTlv_t * lblMsgIdTlv,
6455 u_char * buff,
6456 int bufSize
6459 /* this function does not need to do anything */
6460 return 0;
6461 } /* End: Mpls_decodeLdpLblRetMsgIdTlv */
6467 * Encode for Label Request Message
6471 * encode
6473 int Mpls_encodeLdpLblReqMsg
6475 mplsLdpLblReqMsg_t * lblReqMsg,
6476 u_char * buff,
6477 int bufSize
6480 mplsLdpLblReqMsg_t lblReqMsgCopy;
6481 int encodedSize;
6482 u_int totalSize = 0;
6483 u_char * tempBuf = buff; /* no change for the buff ptr */
6485 /* check the length of the messageId + param */
6486 if ((int)(lblReqMsg->baseMsg.msgLength) + MPLS_TLVFIXLEN > bufSize)
6488 PRINT_ERR("failed to encode the lbl request msg: BUFFER TOO SMALL\n");
6489 return MPLS_ENC_BUFFTOOSMALL;
6492 lblReqMsgCopy = *lblReqMsg;
6495 * encode the base part of the pdu message
6497 encodedSize = Mpls_encodeLdpBaseMsg( &(lblReqMsgCopy.baseMsg),
6498 tempBuf,
6499 bufSize);
6500 if (encodedSize < 0)
6502 return MPLS_ENC_BASEMSGERROR;
6504 PRINT_2("Encode BaseMsg for label request on %d bytes\n", encodedSize);
6505 tempBuf += encodedSize;
6506 totalSize += encodedSize;
6509 * encode the tlv if any
6511 if (lblReqMsgCopy.fecTlvExists)
6513 encodedSize = Mpls_encodeLdpFecTlv( &(lblReqMsgCopy.fecTlv),
6514 tempBuf,
6515 bufSize-totalSize);
6516 if (encodedSize < 0)
6518 return MPLS_ENC_FECERROR;
6520 PRINT_2("Encoded for FEC Tlv %d bytes\n", encodedSize);
6521 tempBuf += encodedSize;
6522 totalSize += encodedSize;
6524 if (lblReqMsgCopy.hopCountTlvExists)
6526 encodedSize = Mpls_encodeLdpHopTlv( &(lblReqMsgCopy.hopCountTlv),
6527 tempBuf,
6528 bufSize-totalSize);
6529 if (encodedSize < 0)
6531 return MPLS_ENC_HOPCOUNTERROR;
6533 PRINT_2("Encoded for Hop Count Tlv %d bytes\n", encodedSize);
6534 tempBuf += encodedSize;
6535 totalSize += encodedSize;
6537 if (lblReqMsgCopy.pathVecTlvExists)
6539 encodedSize = Mpls_encodeLdpPathVectorTlv( &(lblReqMsgCopy.pathVecTlv),
6540 tempBuf,
6541 bufSize-totalSize);
6542 if (encodedSize < 0)
6544 return MPLS_ENC_PATHVECERROR;
6546 PRINT_2("Encoded for Hop Count Tlv %d bytes\n", encodedSize);
6547 tempBuf += encodedSize;
6548 totalSize += encodedSize;
6550 if (lblReqMsgCopy.lblMsgIdTlvExists)
6552 encodedSize = Mpls_encodeLdpLblRetMsgIdTlv( &(lblReqMsgCopy.lblMsgIdTlv),
6553 tempBuf,
6554 bufSize-totalSize);
6555 if (encodedSize < 0)
6557 return MPLS_ENC_LBLMSGIDERROR;
6559 PRINT_2("Encoded for Hop Count Tlv %d bytes\n", encodedSize);
6560 tempBuf += encodedSize;
6561 totalSize += encodedSize;
6563 if (lblReqMsgCopy.erTlvExists)
6565 encodedSize = Mpls_encodeLdpERTlv( &(lblReqMsgCopy.erTlv),
6566 tempBuf,
6567 bufSize-totalSize);
6568 if (encodedSize < 0)
6570 return MPLS_ENC_ERTLVERROR;
6572 PRINT_2("Encoded for CR Tlv %d bytes\n", encodedSize);
6573 tempBuf += encodedSize;
6574 totalSize += encodedSize;
6576 if (lblReqMsgCopy.trafficTlvExists)
6578 encodedSize = Mpls_encodeLdpTrafficTlv( &(lblReqMsgCopy.trafficTlv),
6579 tempBuf,
6580 bufSize-totalSize);
6581 if (encodedSize < 0)
6583 return MPLS_ENC_TRAFFICERROR;
6585 PRINT_2("Encoded for Traffic Tlv %d bytes\n", encodedSize);
6586 tempBuf += encodedSize;
6587 totalSize += encodedSize;
6589 if (lblReqMsgCopy.lspidTlvExists)
6591 encodedSize = Mpls_encodeLdpLspIdTlv( &(lblReqMsgCopy.lspidTlv),
6592 tempBuf,
6593 bufSize-totalSize);
6594 if (encodedSize < 0)
6596 return MPLS_ENC_LSPIDERROR;
6598 PRINT_2("Encoded for LSPID Tlv %d bytes\n", encodedSize);
6599 tempBuf += encodedSize;
6600 totalSize += encodedSize;
6602 if (lblReqMsgCopy.pinningTlvExists)
6604 encodedSize = Mpls_encodeLdpPinningTlv( &(lblReqMsgCopy.pinningTlv),
6605 tempBuf,
6606 bufSize-totalSize);
6607 if (encodedSize < 0)
6609 return MPLS_ENC_PINNINGERROR;
6611 PRINT_2("Encoded for Pinning Tlv %d bytes\n", encodedSize);
6612 tempBuf += encodedSize;
6613 totalSize += encodedSize;
6615 if (lblReqMsgCopy.recClassTlvExists)
6617 encodedSize = Mpls_encodeLdpResClsTlv( &(lblReqMsgCopy.resClassTlv),
6618 tempBuf,
6619 bufSize-totalSize);
6620 if (encodedSize < 0)
6622 return MPLS_ENC_RESCLSERROR;
6624 PRINT_2("Encoded for Resource class Tlv %d bytes\n", encodedSize);
6625 tempBuf += encodedSize;
6626 totalSize += encodedSize;
6628 if (lblReqMsgCopy.preemptTlvExists)
6630 encodedSize = Mpls_encodeLdpPreemptTlv( &(lblReqMsgCopy.preemptTlv),
6631 tempBuf,
6632 bufSize-totalSize);
6633 if (encodedSize < 0)
6635 return MPLS_ENC_PREEMPTERROR;
6637 PRINT_2("Encoded for Preempt Tlv %d bytes\n", encodedSize);
6638 tempBuf += encodedSize;
6639 totalSize += encodedSize;
6642 return totalSize;
6644 } /* End: Mpls_encodeLdpLblReqMsg */
6647 * decode
6649 int Mpls_decodeLdpLblReqMsg
6651 mplsLdpLblReqMsg_t * lblReqMsg,
6652 u_char * buff,
6653 int bufSize
6656 int decodedSize = 0;
6657 u_int totalSize = 0;
6658 u_int stopLength = 0;
6659 u_int totalSizeParam = 0;
6660 u_char * tempBuf = buff; /* no change for the buff ptr */
6661 mplsLdpTlv_t tlvTemp;
6664 * decode the base part of the pdu message
6666 bzero(lblReqMsg, sizeof(mplsLdpLblReqMsg_t));
6667 decodedSize = Mpls_decodeLdpBaseMsg( &(lblReqMsg->baseMsg),
6668 tempBuf,
6669 bufSize);
6670 if (decodedSize < 0)
6672 return MPLS_DEC_BASEMSGERROR;
6674 PRINT_2("Decode BaseMsg for Lbl Request on %d bytes\n", decodedSize);
6676 if (lblReqMsg->baseMsg.flags.flags.msgType != MPLS_LBLREQ_MSGTYPE)
6678 PRINT_ERR_2("Not the right message type; expected lbl req and got %x\n",
6679 lblReqMsg->baseMsg.flags.flags.msgType);
6680 return MPLS_MSGTYPEERROR;
6683 tempBuf += decodedSize;
6684 totalSize += decodedSize;
6686 if (bufSize-totalSize <= 0)
6688 /* nothing left for decoding */
6689 PRINT_ERR("Lbl Request msg does not have anything beside base msg\n");
6690 return totalSize;
6693 PRINT_4("bufSize = %d, totalSize = %d, lblReqMsg->baseMsg.msgLength = %d\n",
6694 bufSize, totalSize, lblReqMsg->baseMsg.msgLength);
6696 /* Have to check the baseMsg.msgLength to know when to finish.
6697 * We finsh when the totalSizeParam is >= to the base message length - the
6698 * message id length (4)
6701 stopLength = lblReqMsg->baseMsg.msgLength - MPLS_MSGIDFIXLEN;
6702 while (stopLength > totalSizeParam)
6705 * decode the tlv to check what's next
6707 bzero(&tlvTemp, MPLS_TLVFIXLEN);
6708 decodedSize = Mpls_decodeLdpTlv(&tlvTemp, tempBuf, bufSize-totalSize);
6709 if (decodedSize < 0)
6711 /* something wrong */
6712 PRINT_ERR("Label Request msg decode failed for tlv\n");
6713 return MPLS_DEC_TLVERROR;
6716 tempBuf += decodedSize;
6717 totalSize += decodedSize;
6718 totalSizeParam += decodedSize;
6720 switch (tlvTemp.flags.flags.type)
6722 case MPLS_FEC_TLVTYPE:
6724 decodedSize = Mpls_decodeLdpFecTlv( &(lblReqMsg->fecTlv),
6725 tempBuf,
6726 bufSize-totalSize,
6727 tlvTemp.length);
6728 if (decodedSize < 0)
6730 PRINT_ERR("Failure when decoding FEC tlv from LblReq msg\n");
6731 return MPLS_DEC_FECERROR;
6733 PRINT_2("Decoded for FEC %d bytes\n", decodedSize);
6734 tempBuf += decodedSize;
6735 totalSize += decodedSize;
6736 totalSizeParam += decodedSize;
6738 lblReqMsg->fecTlvExists = 1;
6739 lblReqMsg->fecTlv.baseTlv = tlvTemp;
6740 DEBUG_CALL(printFecListTlv(&(lblReqMsg->fecTlv)));
6741 break;
6743 case MPLS_HOPCOUNT_TLVTYPE:
6745 decodedSize = Mpls_decodeLdpHopTlv( &(lblReqMsg->hopCountTlv),
6746 tempBuf,
6747 bufSize-totalSize);
6748 if (decodedSize < 0)
6750 PRINT_ERR("Failure when dec HopCount tlv from LblReq msg\n");
6751 return MPLS_DEC_HOPCOUNTERROR;
6753 PRINT_2("Decoded for HopCount %d bytes\n", decodedSize);
6754 tempBuf += decodedSize;
6755 totalSize += decodedSize;
6756 totalSizeParam += decodedSize;
6758 lblReqMsg->hopCountTlvExists = 1;
6759 lblReqMsg->hopCountTlv.baseTlv = tlvTemp;
6760 DEBUG_CALL(printHopTlv(&(lblReqMsg->hopCountTlv)));
6761 break;
6763 case MPLS_PATH_TLVTYPE:
6765 decodedSize = Mpls_decodeLdpPathVectorTlv(&(lblReqMsg->pathVecTlv),
6766 tempBuf,
6767 bufSize-totalSize,
6768 tlvTemp.length);
6769 if (decodedSize < 0)
6771 PRINT_ERR("Failure when dec Path Vec tlv from LblReq msg\n");
6772 return MPLS_DEC_PATHVECERROR;
6774 PRINT_2("Decoded for PATH VECTOR %d bytes\n", decodedSize);
6775 tempBuf += decodedSize;
6776 totalSize += decodedSize;
6777 totalSizeParam += decodedSize;
6779 lblReqMsg->pathVecTlvExists = 1;
6780 lblReqMsg->pathVecTlv.baseTlv = tlvTemp;
6781 DEBUG_CALL(printPathVecTlv(&(lblReqMsg->pathVecTlv)));
6782 break;
6784 case MPLS_LBLMSGID_TLVTYPE:
6786 lblReqMsg->lblMsgIdTlvExists = 1;
6787 lblReqMsg->lblMsgIdTlv.baseTlv = tlvTemp;
6788 DEBUG_CALL(printTlv(&(lblReqMsg->lblMsgIdTlv.baseTlv)));
6789 break;
6791 case MPLS_ER_TLVTYPE:
6793 decodedSize = Mpls_decodeLdpERTlv( &(lblReqMsg->erTlv),
6794 tempBuf,
6795 bufSize-totalSize,
6796 tlvTemp.length);
6797 if (decodedSize < 0)
6799 PRINT_ERR("Failure when dec CR tlv from LblReq msg\n");
6800 return MPLS_DEC_ERTLVERROR;
6802 PRINT_2("Decoded for CR %d bytes\n", decodedSize);
6803 tempBuf += decodedSize;
6804 totalSize += decodedSize;
6805 totalSizeParam += decodedSize;
6807 lblReqMsg->erTlvExists = 1;
6808 lblReqMsg->erTlv.baseTlv = tlvTemp;
6809 DEBUG_CALL(printErTlv(&(lblReqMsg->erTlv)));
6810 break;
6812 case MPLS_TRAFFIC_TLVTYPE:
6814 decodedSize = Mpls_decodeLdpTrafficTlv( &(lblReqMsg->trafficTlv),
6815 tempBuf,
6816 bufSize-totalSize,
6817 tlvTemp.length);
6818 if (decodedSize < 0)
6820 PRINT_ERR("Failure when dec Traffic tlv from LblReq msg\n");
6821 return MPLS_DEC_TRAFFICERROR;
6823 PRINT_2("Decoded for Traffic %d bytes\n", decodedSize);
6824 tempBuf += decodedSize;
6825 totalSize += decodedSize;
6826 totalSizeParam += decodedSize;
6828 lblReqMsg->trafficTlvExists = 1;
6829 lblReqMsg->trafficTlv.baseTlv = tlvTemp;
6830 DEBUG_CALL(printTrafficTlv(&(lblReqMsg->trafficTlv)));
6831 break;
6833 case MPLS_LSPID_TLVTYPE:
6835 decodedSize = Mpls_decodeLdpLspIdTlv( &(lblReqMsg->lspidTlv),
6836 tempBuf,
6837 bufSize-totalSize);
6838 if (decodedSize < 0)
6840 PRINT_ERR("Failure when dec LSPID tlv from LblReq msg\n");
6841 return MPLS_DEC_LSPIDERROR;
6843 PRINT_2("Decoded for lspid tlv %d bytes\n", decodedSize);
6844 tempBuf += decodedSize;
6845 totalSize += decodedSize;
6846 totalSizeParam += decodedSize;
6848 lblReqMsg->lspidTlvExists = 1;
6849 lblReqMsg->lspidTlv.baseTlv = tlvTemp;
6850 DEBUG_CALL(printLspIdTlv(&(lblReqMsg->lspidTlv)));
6851 break;
6853 case MPLS_PINNING_TLVTYPE:
6855 decodedSize = Mpls_decodeLdpPinningTlv( &(lblReqMsg->pinningTlv),
6856 tempBuf,
6857 bufSize-totalSize);
6858 if (decodedSize < 0)
6860 PRINT_ERR("Failure when dec Pinning tlv from LblReq msg\n");
6861 return MPLS_DEC_PINNINGERROR;
6863 PRINT_2("Decoded for pining tlv %d bytes\n", decodedSize);
6864 tempBuf += decodedSize;
6865 totalSize += decodedSize;
6866 totalSizeParam += decodedSize;
6868 lblReqMsg->pinningTlvExists = 1;
6869 lblReqMsg->pinningTlv.baseTlv = tlvTemp;
6870 DEBUG_CALL(printPinningTlv(&(lblReqMsg->pinningTlv)));
6871 break;
6873 case MPLS_RESCLASS_TLVTYPE:
6875 decodedSize = Mpls_decodeLdpResClsTlv( &(lblReqMsg->resClassTlv),
6876 tempBuf,
6877 bufSize-totalSize);
6878 if (decodedSize < 0)
6880 PRINT_ERR("Failure when dec ResClass tlv from LblReq msg\n");
6881 return MPLS_DEC_RESCLSERROR;
6883 PRINT_2("Decoded for %d bytes\n", decodedSize);
6884 tempBuf += decodedSize;
6885 totalSize += decodedSize;
6886 totalSizeParam += decodedSize;
6888 lblReqMsg->recClassTlvExists = 1;
6889 lblReqMsg->resClassTlv.baseTlv = tlvTemp;
6890 DEBUG_CALL(printResClsTlv(&(lblReqMsg->resClassTlv)));
6891 break;
6893 case MPLS_PREEMPT_TLVTYPE:
6895 decodedSize = Mpls_decodeLdpPreemptTlv( &(lblReqMsg->preemptTlv),
6896 tempBuf,
6897 bufSize-totalSize);
6898 if (decodedSize < 0)
6900 PRINT_ERR("Failure when dec preempt tlv from LblReq msg\n");
6901 return MPLS_DEC_PREEMPTERROR;
6903 PRINT_2("Decoded for preempt tlv %d bytes\n", decodedSize);
6904 tempBuf += decodedSize;
6905 totalSize += decodedSize;
6906 totalSizeParam += decodedSize;
6908 lblReqMsg->preemptTlvExists = 1;
6909 lblReqMsg->preemptTlv.baseTlv = tlvTemp;
6910 DEBUG_CALL(printPreemptTlv(&(lblReqMsg->preemptTlv)));
6911 break;
6913 default:
6915 PRINT_ERR_2("Found wrong type while decoding lbl req msg (%x)\n",
6916 tlvTemp.flags.flags.type);
6917 if (tlvTemp.flags.flags.uBit == 1)
6919 /* ignore the Tlv and continue processing */
6920 tempBuf += tlvTemp.length;
6921 totalSize += tlvTemp.length;
6922 totalSizeParam += tlvTemp.length;
6923 break;
6925 else
6927 /* drop the message; return error */
6928 return MPLS_TLVTYPEERROR;
6931 } /* switch type */
6933 } /* while */
6935 PRINT_2("totalsize for Mpls_decodeLdpLblReqMsg is %d\n", totalSize);
6936 return totalSize;
6938 } /*End: Mpls_decodeLdpLblReqMsg */
6943 * Encode for Label Withdraw and Label Release Message
6947 * encode
6949 int Mpls_encodeLdpLbl_W_R_Msg
6951 mplsLdpLbl_W_R_Msg_t * lbl_W_R_Msg,
6952 u_char * buff,
6953 int bufSize
6956 mplsLdpLbl_W_R_Msg_t lbl_W_R_MsgCopy;
6957 int encodedSize;
6958 u_int totalSize = 0;
6959 u_char * tempBuf = buff; /* no change for the buff ptr */
6961 /* check the length of the messageId + param */
6962 if ((int)(lbl_W_R_Msg->baseMsg.msgLength) + MPLS_TLVFIXLEN > bufSize)
6964 PRINT_ERR("failed to encode the lbl mapping msg: BUFFER TOO SMALL\n");
6965 return MPLS_ENC_BUFFTOOSMALL;
6968 lbl_W_R_MsgCopy = *lbl_W_R_Msg;
6971 * encode the base part of the pdu message
6973 encodedSize = Mpls_encodeLdpBaseMsg( &(lbl_W_R_MsgCopy.baseMsg),
6974 tempBuf,
6975 bufSize);
6976 if (encodedSize < 0)
6978 return MPLS_ENC_BASEMSGERROR;
6980 PRINT_2("Encode BaseMsg for label withdraw on %d bytes\n", encodedSize);
6981 tempBuf += encodedSize;
6982 totalSize += encodedSize;
6985 * encode the tlv if any
6987 if (lbl_W_R_MsgCopy.fecTlvExists)
6989 encodedSize = Mpls_encodeLdpFecTlv( &(lbl_W_R_MsgCopy.fecTlv),
6990 tempBuf,
6991 bufSize-totalSize);
6992 if (encodedSize < 0)
6994 return MPLS_ENC_FECERROR;
6996 PRINT_2("Encoded for FEC Tlv %d bytes\n", encodedSize);
6997 tempBuf += encodedSize;
6998 totalSize += encodedSize;
7001 if (lbl_W_R_MsgCopy.genLblTlvExists)
7003 encodedSize = Mpls_encodeLdpGenLblTlv( &(lbl_W_R_MsgCopy.genLblTlv),
7004 tempBuf,
7005 bufSize-totalSize);
7006 if (encodedSize < 0)
7008 return MPLS_ENC_GENLBLERROR;
7010 PRINT_2("Encoded for Generic Label Tlv %d bytes\n", encodedSize);
7011 tempBuf += encodedSize;
7012 totalSize += encodedSize;
7014 if (lbl_W_R_MsgCopy.atmLblTlvExists)
7016 encodedSize = Mpls_encodeLdpAtmLblTlv( &(lbl_W_R_MsgCopy.atmLblTlv),
7017 tempBuf,
7018 bufSize-totalSize);
7019 if (encodedSize < 0)
7021 return MPLS_ENC_MAPATMERROR;
7023 PRINT_2("Encoded for Atm Label Tlv %d bytes\n", encodedSize);
7024 tempBuf += encodedSize;
7025 totalSize += encodedSize;
7027 if (lbl_W_R_MsgCopy.frLblTlvExists)
7029 encodedSize = Mpls_encodeLdpFrLblTlv( &(lbl_W_R_MsgCopy.frLblTlv),
7030 tempBuf,
7031 bufSize-totalSize);
7032 if (encodedSize < 0)
7034 return MPLS_ENC_FRLBLERROR;
7036 PRINT_2("Encoded for Fr Label Tlv %d bytes\n", encodedSize);
7037 tempBuf += encodedSize;
7038 totalSize += encodedSize;
7040 if (lbl_W_R_MsgCopy.lspidTlvExists)
7042 encodedSize = Mpls_encodeLdpLspIdTlv( &(lbl_W_R_MsgCopy.lspidTlv),
7043 tempBuf,
7044 bufSize-totalSize);
7045 if (encodedSize < 0)
7047 return MPLS_ENC_LSPIDERROR;
7049 PRINT_2("Encoded for LSPID Tlv %d bytes\n", encodedSize);
7050 tempBuf += encodedSize;
7051 totalSize += encodedSize;
7054 return totalSize;
7056 } /* End: Mpls_encodeLdpLbl_W_R_Msg */
7060 * decode
7062 int Mpls_decodeLdpLbl_W_R_Msg
7064 mplsLdpLbl_W_R_Msg_t * lbl_W_R_Msg,
7065 u_char * buff,
7066 int bufSize
7069 int decodedSize;
7070 u_int totalSize = 0;
7071 u_int stopLength = 0;
7072 u_int totalSizeParam = 0;
7073 u_char * tempBuf = buff; /* no change for the buff ptr */
7074 mplsLdpTlv_t tlvTemp;
7077 * decode the base part of the pdu message
7079 bzero(lbl_W_R_Msg, sizeof(mplsLdpLbl_W_R_Msg_t));
7080 decodedSize = Mpls_decodeLdpBaseMsg( &(lbl_W_R_Msg->baseMsg),
7081 tempBuf,
7082 bufSize);
7083 if (decodedSize < 0)
7085 return MPLS_DEC_BASEMSGERROR;
7087 PRINT_2("Decode BaseMsg for Lbl Withdraw on %d bytes\n", decodedSize);
7089 if ((lbl_W_R_Msg->baseMsg.flags.flags.msgType != MPLS_LBLWITH_MSGTYPE) &&
7090 (lbl_W_R_Msg->baseMsg.flags.flags.msgType != MPLS_LBLREL_MSGTYPE))
7092 PRINT_ERR_2("Not the right message type; expected lbl W_R and got %x\n",
7093 lbl_W_R_Msg->baseMsg.flags.flags.msgType);
7094 return MPLS_MSGTYPEERROR;
7097 tempBuf += decodedSize;
7098 totalSize += decodedSize;
7100 if (bufSize-totalSize <= 0)
7102 /* nothing left for decoding */
7103 PRINT_ERR("Lbl Withdraw msg does not have anything beside base msg\n");
7104 return totalSize;
7107 PRINT_4("bufSize = %d, totalSize = %d, lbl_W_R_Msg->baseMsg.msgLength = %d\n",
7108 bufSize, totalSize, lbl_W_R_Msg->baseMsg.msgLength);
7110 /* Have to check the baseMsg.msgLength to know when to finish.
7111 * We finsh when the totalSizeParam is >= to the base message length - the
7112 * message id length (4)
7115 stopLength = lbl_W_R_Msg->baseMsg.msgLength - MPLS_MSGIDFIXLEN;
7116 while (stopLength > totalSizeParam)
7119 * decode the tlv to check what's next
7121 bzero(&tlvTemp, MPLS_TLVFIXLEN);
7122 decodedSize = Mpls_decodeLdpTlv(&tlvTemp, tempBuf, bufSize-totalSize);
7123 if (decodedSize < 0)
7125 /* something wrong */
7126 PRINT_ERR("Label Mapping msg decode failed for tlv\n");
7127 return MPLS_DEC_TLVERROR;
7130 tempBuf += decodedSize;
7131 totalSize += decodedSize;
7132 totalSizeParam += decodedSize;
7134 switch (tlvTemp.flags.flags.type)
7136 case MPLS_FEC_TLVTYPE:
7138 decodedSize = Mpls_decodeLdpFecTlv( &(lbl_W_R_Msg->fecTlv),
7139 tempBuf,
7140 bufSize-totalSize,
7141 tlvTemp.length);
7142 if (decodedSize < 0)
7144 PRINT_ERR("Failure when decoding FEC tlv from LblWithdr msg\n");
7145 return MPLS_DEC_FECERROR;
7147 PRINT_2("Decoded for FEC %d bytes\n", decodedSize);
7148 tempBuf += decodedSize;
7149 totalSize += decodedSize;
7150 totalSizeParam += decodedSize;
7152 lbl_W_R_Msg->fecTlvExists = 1;
7153 lbl_W_R_Msg->fecTlv.baseTlv = tlvTemp;
7154 DEBUG_CALL(printFecListTlv(&(lbl_W_R_Msg->fecTlv)));
7155 break;
7157 case MPLS_GENLBL_TLVTYPE:
7159 decodedSize = Mpls_decodeLdpGenLblTlv( &(lbl_W_R_Msg->genLblTlv),
7160 tempBuf,
7161 bufSize-totalSize);
7162 if (decodedSize < 0)
7164 PRINT_ERR("Failure when dec GEN Lbl tlv from LblWithdr msg\n");
7165 return MPLS_DEC_GENLBLERROR;
7167 PRINT_2("Decoded for Gen Lbl %d bytes\n", decodedSize);
7168 tempBuf += decodedSize;
7169 totalSize += decodedSize;
7170 totalSizeParam += decodedSize;
7172 lbl_W_R_Msg->genLblTlvExists = 1;
7173 lbl_W_R_Msg->genLblTlv.baseTlv = tlvTemp;
7174 DEBUG_CALL(printGenLblTlv(&(lbl_W_R_Msg->genLblTlv)));
7175 break;
7177 case MPLS_ATMLBL_TLVTYPE:
7179 decodedSize = Mpls_decodeLdpAtmLblTlv( &(lbl_W_R_Msg->atmLblTlv),
7180 tempBuf,
7181 bufSize-totalSize);
7182 if (decodedSize < 0)
7184 PRINT_ERR("Failure when dec ATM Lbl tlv from LblWithdr msg\n");
7185 return MPLS_DEC_MAPATMERROR;
7187 PRINT_2("Decoded for Atm Lbl %d bytes\n", decodedSize);
7188 tempBuf += decodedSize;
7189 totalSize += decodedSize;
7190 totalSizeParam += decodedSize;
7192 lbl_W_R_Msg->atmLblTlvExists = 1;
7193 lbl_W_R_Msg->atmLblTlv.baseTlv = tlvTemp;
7194 DEBUG_CALL(printAtmLblTlv(&(lbl_W_R_Msg->atmLblTlv)));
7195 break;
7197 case MPLS_FRLBL_TLVTYPE:
7199 decodedSize = Mpls_decodeLdpFrLblTlv( &(lbl_W_R_Msg->frLblTlv),
7200 tempBuf,
7201 bufSize-totalSize);
7202 if (decodedSize < 0)
7204 PRINT_ERR("Failure when dec FR Lbl tlv from LblWithdr msg\n");
7205 return MPLS_DEC_FRLBLERROR;
7207 PRINT_2("Decoded for Fr Lbl %d bytes\n", decodedSize);
7208 tempBuf += decodedSize;
7209 totalSize += decodedSize;
7210 totalSizeParam += decodedSize;
7212 lbl_W_R_Msg->frLblTlvExists = 1;
7213 lbl_W_R_Msg->frLblTlv.baseTlv = tlvTemp;
7214 DEBUG_CALL(printFrLblTlv(&(lbl_W_R_Msg->frLblTlv)));
7215 break;
7217 case MPLS_LSPID_TLVTYPE:
7219 decodedSize = Mpls_decodeLdpLspIdTlv( &(lbl_W_R_Msg->lspidTlv),
7220 tempBuf,
7221 bufSize-totalSize);
7222 if (decodedSize < 0)
7224 PRINT_ERR("Failure when dec LSPID tlv from LblW_R msg\n");
7225 return MPLS_DEC_LSPIDERROR;
7227 PRINT_2("Decoded for lspid tlv %d bytes\n", decodedSize);
7228 tempBuf += decodedSize;
7229 totalSize += decodedSize;
7230 totalSizeParam += decodedSize;
7232 lbl_W_R_Msg->lspidTlvExists = 1;
7233 lbl_W_R_Msg->lspidTlv.baseTlv = tlvTemp;
7234 DEBUG_CALL(printLspIdTlv(&(lbl_W_R_Msg->lspidTlv)));
7235 break;
7237 default:
7239 PRINT_ERR_2("Found wrong tlv type while decoding lbl withdr msg (%x)\n",
7240 tlvTemp.flags.flags.type);
7241 if (tlvTemp.flags.flags.uBit == 1)
7243 /* ignore the Tlv and continue processing */
7244 tempBuf += tlvTemp.length;
7245 totalSize += tlvTemp.length;
7246 totalSizeParam += tlvTemp.length;
7247 break;
7249 else
7251 /* drop the message; return error */
7252 return MPLS_TLVTYPEERROR;
7255 } /* switch type */
7257 } /* while */
7259 PRINT_2("totalsize for Mpls_decodeLdpLblWithdrawMsgIdTlv is %d\n",
7260 totalSize);
7262 return totalSize;
7264 } /* End: Mpls_decodeLdpLbl_W_R_Msg */
7269 * Encode for CR Tlv
7273 * encode
7275 int Mpls_encodeLdpERTlv
7277 mplsLdpErTlv_t * erTlv,
7278 u_char * buff,
7279 int bufSize
7282 int encodedSize = 0;
7283 u_int totalSize = 0;
7284 u_char * tempBuf = buff; /* no change for the buff ptr */
7285 u_int i;
7287 if (MPLS_TLVFIXLEN + (int)(erTlv->baseTlv.length)> bufSize)
7289 /* not enough room */
7290 return MPLS_ENC_BUFFTOOSMALL;
7294 * encode for tlv
7296 encodedSize = Mpls_encodeLdpTlv( &(erTlv->baseTlv),
7297 tempBuf,
7298 MPLS_TLVFIXLEN);
7299 if (encodedSize < 0)
7301 return MPLS_ENC_TLVERROR;
7303 tempBuf += encodedSize;
7304 totalSize += encodedSize;
7306 if (erTlv->numberErHops > MPLS_MAX_ER_HOPS)
7308 PRINT_ERR("MPLS_MAX_ER_HOPS is too small. Increase it if nec\n");
7309 return MPLS_ER_HOPSNUMERROR;
7313 * encode for ER hops
7315 for (i = 0; i <erTlv->numberErHops ; i++)
7317 encodedSize = Mpls_encodeLdpErHop( &(erTlv->erHopArray[i]),
7318 tempBuf,
7319 bufSize - totalSize,
7320 erTlv->erHopTypes[i]);
7321 if (encodedSize < 0)
7323 return MPLS_ENC_ERHOPERROR;
7325 tempBuf += encodedSize;
7326 totalSize += encodedSize;
7329 return totalSize;
7331 } /* End: Mpls_encodeLdpERTlv */
7335 * decode
7337 int Mpls_decodeLdpERTlv
7339 mplsLdpErTlv_t * erTlv,
7340 u_char * buff,
7341 int bufSize,
7342 u_short tlvLength
7345 u_char * tempBuf = buff; /* no change for the buff ptr */
7346 u_char * erTlvPtr;
7347 u_int i = 0;
7348 int decodedSize = 0;
7349 u_int erHopSize = 0; /* used to compute the sum of
7350 all er hop elements + flags*/
7351 u_short type; /* filled in by Mpls_decodeLdpErHop
7352 with the type of the ER hop
7353 decoded */
7355 if ((int)tlvLength > bufSize)
7357 /* not enough data for Fec elements tlv*/
7358 PRINT_ERR("failed decoding CR tlv \n");
7359 return MPLS_DEC_BUFFTOOSMALL;
7362 erTlvPtr = (u_char *)erTlv;
7363 erTlvPtr += MPLS_TLVFIXLEN; /* we want to point to the flags since the
7364 tlv was decoded before we reach here */
7366 while (tlvLength > erHopSize)
7368 if (erTlv->numberErHops > (u_short)(MPLS_MAX_ER_HOPS - 1))
7370 PRINT_ERR("MPLS_MAX_ER_HOPS is too small. Increase it if nec\n");
7371 return MPLS_ER_HOPSNUMERROR;
7374 decodedSize = Mpls_decodeLdpErHop( &(erTlv->erHopArray[i]),
7375 tempBuf,
7376 bufSize - erHopSize,
7377 &type);
7378 if(decodedSize < 0)
7380 return MPLS_DEC_ERHOPERROR;
7383 erTlv->erHopTypes[i] = type;
7384 erTlv->numberErHops++;
7385 i++;
7387 tempBuf += decodedSize;
7388 erHopSize += decodedSize;
7390 } /* end while */
7392 return erHopSize;
7394 } /* End: Mpls_decodeLdpERTlv */
7399 * Encode for ER Hop
7403 * encode
7405 int Mpls_encodeLdpErHop
7407 mplsLdpErHop_t * erHop,
7408 u_char * buff,
7409 int bufSize,
7410 u_short type
7413 int encodedSize = 0;
7414 u_char * tempBuff = buff;
7415 u_char * startPtr;
7417 switch (type)
7419 case MPLS_ERHOP_IPV4_TLVTYPE:
7421 if (MPLS_ERHOP_IPV4_FIXLEN + MPLS_TLVFIXLEN > bufSize)
7423 return MPLS_ENC_BUFFTOOSMALL;
7426 /* check how much is the preLen; should be between 0-32 */
7427 if (erHop->erIpv4.flags.flags.preLen > 32)
7429 return MPLS_IPV4LENGTHERROR;
7432 encodedSize = Mpls_encodeLdpTlv( &(erHop->erIpv4.baseTlv),
7433 tempBuff, bufSize);
7434 if (encodedSize < 0)
7436 return MPLS_ENC_TLVERROR;
7438 tempBuff += encodedSize;
7439 startPtr = (u_char *)&(erHop->erIpv4);
7440 startPtr += encodedSize;
7442 erHop->erIpv4.flags.flags.res = 0;
7443 erHop->erIpv4.flags.mark = htonl(erHop->erIpv4.flags.mark);
7444 erHop->erIpv4.address = htonl(erHop->erIpv4.address);
7446 MEM_COPY( tempBuff,
7447 startPtr,
7448 MPLS_ERHOP_IPV4_FIXLEN);
7449 encodedSize += MPLS_ERHOP_IPV4_FIXLEN;
7450 break;
7452 case MPLS_ERHOP_IPV6_TLVTYPE:
7454 if (MPLS_ERHOP_IPV6_FIXLEN + MPLS_TLVFIXLEN > bufSize)
7456 return MPLS_ENC_BUFFTOOSMALL;
7458 encodedSize = Mpls_encodeLdpTlv( &(erHop->erIpv6.baseTlv),
7459 tempBuff, bufSize);
7460 if (encodedSize < 0)
7462 return MPLS_ENC_TLVERROR;
7464 tempBuff += encodedSize;
7465 startPtr = (u_char *)&(erHop->erIpv6);
7466 startPtr += encodedSize;
7468 erHop->erIpv6.flags.flags.res = 0;
7469 erHop->erIpv6.flags.mark = htonl(erHop->erIpv6.flags.mark);
7471 MEM_COPY( tempBuff,
7472 startPtr,
7473 MPLS_ERHOP_IPV6_FIXLEN);
7475 encodedSize += MPLS_ERHOP_IPV6_FIXLEN;
7476 break;
7478 case MPLS_ERHOP_AS_TLVTYPE:
7480 if (MPLS_ERHOP_AS_FIXLEN + MPLS_TLVFIXLEN > bufSize)
7482 return MPLS_ENC_BUFFTOOSMALL;
7484 encodedSize = Mpls_encodeLdpTlv( &(erHop->erAs.baseTlv),
7485 tempBuff, bufSize);
7486 if (encodedSize < 0)
7488 return MPLS_ENC_TLVERROR;
7490 tempBuff += encodedSize;
7491 startPtr = (u_char *)&(erHop->erAs);
7492 startPtr += encodedSize;
7494 erHop->erAs.flags.flags.res = 0;
7495 erHop->erAs.flags.mark = htons(erHop->erAs.flags.mark);
7496 erHop->erAs.asNumber = htons(erHop->erAs.asNumber);
7498 MEM_COPY( tempBuff,
7499 startPtr,
7500 MPLS_ERHOP_AS_FIXLEN);
7502 encodedSize += MPLS_ERHOP_AS_FIXLEN;
7503 break;
7505 case MPLS_ERHOP_LSPID_TLVTYPE:
7507 if (MPLS_ERHOP_LSPID_FIXLEN + MPLS_TLVFIXLEN > bufSize)
7509 return MPLS_ENC_BUFFTOOSMALL;
7511 encodedSize = Mpls_encodeLdpTlv( &(erHop->erLspId.baseTlv),
7512 tempBuff, bufSize);
7513 if (encodedSize < 0)
7515 return MPLS_ENC_TLVERROR;
7517 tempBuff += encodedSize;
7518 startPtr = (u_char *)&(erHop->erLspId);
7519 startPtr += encodedSize;
7521 erHop->erLspId.flags.flags.res = 0;
7522 erHop->erLspId.flags.mark = htons(erHop->erLspId.flags.mark);
7523 erHop->erLspId.lspid = htons(erHop->erLspId.lspid);
7524 erHop->erLspId.routerId = htonl(erHop->erLspId.routerId);
7526 MEM_COPY( tempBuff,
7527 startPtr,
7528 MPLS_ERHOP_LSPID_FIXLEN);
7530 encodedSize += MPLS_ERHOP_LSPID_FIXLEN;
7531 break;
7533 default:
7535 PRINT_ERR_2("Found wrong ER hop type while encoding FEC elem (%d)\n",
7536 type);
7537 return MPLS_ENC_ERHOPERROR;
7538 break;
7540 } /* end: switch */
7542 return encodedSize;
7544 } /* End: Mpls_encodeLdpErHop */
7547 * decode
7549 int Mpls_decodeLdpErHop
7551 mplsLdpErHop_t * erHop,
7552 u_char * buff,
7553 int bufSize,
7554 u_short * type
7557 int decodedSize = 0;
7558 u_char *tempBuf = buff;
7559 u_char *startPtr;
7560 mplsLdpTlv_t tlvTemp;
7563 * decode the tlv to check what is the type of the ER hop
7565 decodedSize = Mpls_decodeLdpTlv(&tlvTemp, tempBuf, bufSize);
7566 if (decodedSize < 0)
7568 /* something wrong */
7569 PRINT_ERR("ErHop decode failed for tlv\n");
7570 return MPLS_DEC_TLVERROR;
7572 tempBuf += decodedSize;
7574 switch (tlvTemp.flags.flags.type)
7576 case MPLS_ERHOP_IPV4_TLVTYPE:
7578 if (MPLS_ERHOP_IPV4_FIXLEN > bufSize - MPLS_TLVFIXLEN)
7580 return MPLS_DEC_BUFFTOOSMALL;
7582 startPtr = (u_char *)&(erHop->erIpv4);
7583 startPtr += decodedSize; /* skip the tlv */
7585 MEM_COPY( startPtr,
7586 tempBuf,
7587 MPLS_ERHOP_IPV4_FIXLEN);
7588 erHop->erIpv4.flags.mark = ntohl(erHop->erIpv4.flags.mark);
7589 erHop->erIpv4.address = ntohl(erHop->erIpv4.address);
7590 erHop->erIpv4.baseTlv = tlvTemp;
7592 /* check how much is the preLen; should be between 0-32 */
7593 if (erHop->erIpv4.flags.flags.preLen > 32)
7595 return MPLS_IPV4LENGTHERROR;
7598 decodedSize += MPLS_ERHOP_IPV4_FIXLEN;
7599 break;
7601 case MPLS_ERHOP_IPV6_TLVTYPE:
7603 if (MPLS_ERHOP_IPV6_FIXLEN > bufSize - MPLS_TLVFIXLEN)
7605 return MPLS_DEC_BUFFTOOSMALL;
7607 startPtr = (u_char *)&(erHop->erIpv6);
7608 startPtr += decodedSize; /* skip the tlv */
7610 MEM_COPY( startPtr,
7611 tempBuf,
7612 MPLS_ERHOP_IPV6_FIXLEN);
7613 erHop->erIpv6.flags.mark = ntohl(erHop->erIpv6.flags.mark);
7614 erHop->erIpv6.baseTlv = tlvTemp;
7616 decodedSize += MPLS_ERHOP_IPV6_FIXLEN;
7617 break;
7619 case MPLS_ERHOP_AS_TLVTYPE:
7621 if (MPLS_ERHOP_AS_FIXLEN > bufSize - MPLS_TLVFIXLEN)
7623 return MPLS_DEC_BUFFTOOSMALL;
7625 startPtr = (u_char *)&(erHop->erAs);
7626 startPtr += decodedSize; /* skip the tlv */
7628 MEM_COPY( startPtr,
7629 tempBuf,
7630 MPLS_ERHOP_AS_FIXLEN);
7631 erHop->erAs.flags.mark = ntohs(erHop->erAs.flags.mark);
7632 erHop->erAs.asNumber = ntohs(erHop->erAs.asNumber);
7633 erHop->erAs.baseTlv = tlvTemp;
7635 decodedSize += MPLS_ERHOP_AS_FIXLEN;
7636 break;
7638 case MPLS_ERHOP_LSPID_TLVTYPE:
7640 if (MPLS_ERHOP_LSPID_FIXLEN > bufSize - MPLS_TLVFIXLEN)
7642 return MPLS_DEC_BUFFTOOSMALL;
7644 startPtr = (u_char *)&(erHop->erLspId);
7645 startPtr += decodedSize; /* skip the tlv */
7647 MEM_COPY( startPtr,
7648 tempBuf,
7649 MPLS_ERHOP_LSPID_FIXLEN);
7650 erHop->erLspId.flags.mark = ntohs(erHop->erLspId.flags.mark);
7651 erHop->erLspId.lspid = ntohs(erHop->erLspId.lspid);
7652 erHop->erLspId.routerId = ntohl(erHop->erLspId.routerId);
7653 erHop->erLspId.baseTlv = tlvTemp;
7655 decodedSize += MPLS_ERHOP_LSPID_FIXLEN;
7656 break;
7658 default:
7660 PRINT_ERR_2("Found wrong ER hop type while decoding ER (%d)\n",
7661 *type);
7662 return MPLS_DEC_ERHOPERROR;
7663 break;
7665 } /* end: switch */
7667 *type = tlvTemp.flags.flags.type;
7668 return decodedSize;
7670 } /* End: Mpls_decodeLdpErHop */
7675 * Encode for Traffic Tlv
7679 * encode
7681 int Mpls_encodeLdpTrafficTlv
7683 mplsLdpTrafficTlv_t * trafficTlv,
7684 u_char * buff,
7685 int bufSize
7688 int encodedSize = 0;
7689 u_char * tempBuf = buff; /* no change for the buff ptr */
7690 u_char * trafficTlvPtr;
7691 u_short tempLength; /* to store the tlv length for
7692 later use */
7694 if (MPLS_TLVFIXLEN + (int)(trafficTlv->baseTlv.length)> bufSize)
7696 /* not enough room */
7697 return MPLS_ENC_BUFFTOOSMALL;
7700 tempLength = trafficTlv->baseTlv.length;
7702 * encode for tlv
7704 encodedSize = Mpls_encodeLdpTlv( &(trafficTlv->baseTlv),
7705 tempBuf,
7706 MPLS_TLVFIXLEN);
7707 if (encodedSize < 0)
7709 return MPLS_ENC_TLVERROR;
7711 tempBuf += encodedSize;
7712 trafficTlvPtr = (u_char *)trafficTlv;
7713 trafficTlvPtr += encodedSize;
7716 * encode Traffic flags + Frequency + Reserved + Weight
7718 encodedSize = sizeof(u_char) * 4;
7719 MEM_COPY( tempBuf,
7720 trafficTlvPtr,
7721 encodedSize);
7722 tempBuf += encodedSize;
7723 trafficTlvPtr += encodedSize;
7726 * encode for Traffic parameters
7728 if ( (MPLS_TRAFFICPARAMLENGTH != sizeof(float)) ||
7729 (sizeof(float) != sizeof(u_int)) )
7731 PRINT_ERR_2("There is not compatibility for float type (%d)\n",
7732 (int)sizeof(float));
7733 return MPLS_FLOATTYPEERROR;
7736 trafficTlv->pdr.mark = htonl(trafficTlv->pdr.mark);
7737 trafficTlv->pbs.mark = htonl(trafficTlv->pbs.mark);
7738 trafficTlv->cdr.mark = htonl(trafficTlv->cdr.mark);
7739 trafficTlv->cbs.mark = htonl(trafficTlv->cbs.mark);
7740 trafficTlv->ebs.mark = htonl(trafficTlv->ebs.mark);
7742 MEM_COPY( tempBuf,
7743 trafficTlvPtr,
7744 MPLS_TRAFFICPARAMLENGTH * 5);
7746 return (MPLS_TLVFIXLEN + tempLength);
7748 } /* End: Mpls_encodeLdpTrafficTlv */
7751 * decode
7753 int Mpls_decodeLdpTrafficTlv
7755 mplsLdpTrafficTlv_t * trafficTlv,
7756 u_char * buff,
7757 int bufSize,
7758 u_short tlvLength
7761 u_char * tempBuf = buff; /* no change for the buff ptr */
7762 int decodedSize = 0;
7763 u_char * trafficTlvPtr;
7765 if ((int)tlvLength > bufSize)
7767 /* not enough data for Fec elements tlv*/
7768 PRINT_ERR("failed decoding Traffic tlv \n");
7769 return MPLS_DEC_BUFFTOOSMALL;
7771 trafficTlvPtr = (u_char *)trafficTlv;
7772 trafficTlvPtr += MPLS_TLVFIXLEN;
7775 * decode Traffic flags + Frequency + Reserved + Weight
7777 decodedSize = sizeof(u_char) * 4;
7778 MEM_COPY( trafficTlvPtr,
7779 tempBuf,
7780 decodedSize);
7781 tempBuf += decodedSize;
7782 trafficTlvPtr += decodedSize;
7785 * decode the traffic parameters
7787 if (MPLS_TRAFFICPARAMLENGTH != sizeof(float))
7789 PRINT_ERR_2("There is not compatibility for float type (%d)\n",
7790 decodedSize);
7791 return MPLS_FLOATTYPEERROR;
7793 MEM_COPY( trafficTlvPtr,
7794 tempBuf,
7795 MPLS_TRAFFICPARAMLENGTH * 5);
7797 trafficTlv->pdr.mark = ntohl(trafficTlv->pdr.mark);
7798 trafficTlv->pbs.mark = ntohl(trafficTlv->pbs.mark);
7799 trafficTlv->cdr.mark = ntohl(trafficTlv->cdr.mark);
7800 trafficTlv->cbs.mark = ntohl(trafficTlv->cbs.mark);
7801 trafficTlv->ebs.mark = ntohl(trafficTlv->ebs.mark);
7803 return tlvLength;
7805 } /* End: Mpls_decodeLdpTrafficTlv */
7810 * Encode for Preempt Tlv
7814 * encode
7816 int Mpls_encodeLdpPreemptTlv
7818 mplsLdpPreemptTlv_t * preemptTlv,
7819 u_char * buff,
7820 int bufSize
7823 int encodedSize = 0;
7824 u_char * tempBuf = buff; /* no change for the buff ptr */
7825 u_char * preemptTlvPtr;
7827 if (MPLS_TLVFIXLEN + MPLS_PREEMPTTLV_FIXLEN > bufSize)
7829 /* not enough room */
7830 return MPLS_ENC_BUFFTOOSMALL;
7834 * encode for tlv
7836 encodedSize = Mpls_encodeLdpTlv( &(preemptTlv->baseTlv),
7837 tempBuf,
7838 MPLS_TLVFIXLEN);
7839 if (encodedSize < 0)
7841 return MPLS_ENC_TLVERROR;
7843 tempBuf += encodedSize;
7845 preemptTlv->res = 0;
7846 preemptTlvPtr = (u_char*)preemptTlv;
7847 preemptTlvPtr += encodedSize;
7849 MEM_COPY( tempBuf,
7850 preemptTlvPtr,
7851 MPLS_PREEMPTTLV_FIXLEN);
7853 return (MPLS_TLVFIXLEN + MPLS_PREEMPTTLV_FIXLEN);
7855 } /* End: Mpls_encodeLdpPreemptTlv */
7859 * decode
7861 int Mpls_decodeLdpPreemptTlv
7863 mplsLdpPreemptTlv_t * preemptTlv,
7864 u_char * buff,
7865 int bufSize
7868 u_char * preemptTlvPtr;
7870 if (MPLS_PREEMPTTLV_FIXLEN > bufSize)
7872 PRINT_ERR("failed decoding preempt tlv\n");
7873 return MPLS_DEC_BUFFTOOSMALL;
7875 preemptTlvPtr = (u_char *)preemptTlv;
7876 preemptTlvPtr += MPLS_TLVFIXLEN;
7878 MEM_COPY( preemptTlvPtr,
7879 buff,
7880 MPLS_PREEMPTTLV_FIXLEN);
7882 return MPLS_PREEMPTTLV_FIXLEN;
7884 } /* End: Mpls_decodeLdpPreemptTlv */
7889 * Encode for LSPID Tlv
7893 * encode
7895 int Mpls_encodeLdpLspIdTlv
7897 mplsLdpLspIdTlv_t * lspIdTlv,
7898 u_char * buff,
7899 int bufSize
7902 int encodedSize = 0;
7903 u_char * tempBuf = buff; /* no change for the buff ptr */
7904 u_char * lspIdTlvPtr;
7906 if (MPLS_TLVFIXLEN + MPLS_LSPIDTLV_FIXLEN > bufSize)
7908 /* not enough room */
7909 return MPLS_ENC_BUFFTOOSMALL;
7913 * encode for tlv
7915 encodedSize = Mpls_encodeLdpTlv( &(lspIdTlv->baseTlv),
7916 tempBuf,
7917 MPLS_TLVFIXLEN);
7918 if (encodedSize < 0)
7920 return MPLS_ENC_TLVERROR;
7922 tempBuf += encodedSize;
7924 lspIdTlvPtr = (u_char*)lspIdTlv;
7925 lspIdTlvPtr += encodedSize;
7927 lspIdTlv->res = 0;
7928 lspIdTlv->localCrlspId = htons(lspIdTlv->localCrlspId);
7929 lspIdTlv->routerId = htonl(lspIdTlv->routerId);
7931 MEM_COPY( tempBuf,
7932 lspIdTlvPtr,
7933 MPLS_LSPIDTLV_FIXLEN);
7935 return (MPLS_TLVFIXLEN + MPLS_LSPIDTLV_FIXLEN);
7937 } /* End: Mpls_encodeLdpLspIdTlv */
7941 * decode
7943 int Mpls_decodeLdpLspIdTlv
7945 mplsLdpLspIdTlv_t * lspIdTlv,
7946 u_char * buff,
7947 int bufSize
7950 u_char * lspIdTlvPtr;
7952 if (MPLS_PREEMPTTLV_FIXLEN > bufSize)
7954 PRINT_ERR("failed decoding LspId\n");
7955 return MPLS_DEC_BUFFTOOSMALL;
7957 lspIdTlvPtr = (u_char*)lspIdTlv;
7958 lspIdTlvPtr += MPLS_TLVFIXLEN;
7960 MEM_COPY( lspIdTlvPtr,
7961 buff,
7962 MPLS_LSPIDTLV_FIXLEN);
7964 lspIdTlv->localCrlspId = ntohs(lspIdTlv->localCrlspId);
7965 lspIdTlv->routerId = ntohl(lspIdTlv->routerId);
7967 return MPLS_LSPIDTLV_FIXLEN;
7969 } /* End: Mpls_decodeLdpLspIdTlv*/
7974 * Encode for Resource Class Tlv
7978 * encode
7980 int Mpls_encodeLdpResClsTlv
7982 mplsLdpResClsTlv_t * resClsTlv,
7983 u_char * buff,
7984 int bufSize
7987 int encodedSize = 0;
7988 u_char * tempBuf = buff; /* no change for the buff ptr */
7990 if (MPLS_TLVFIXLEN + (int)sizeof(u_int) > bufSize)
7992 /* not enough room */
7993 return MPLS_ENC_BUFFTOOSMALL;
7997 * encode for tlv
7999 encodedSize = Mpls_encodeLdpTlv( &(resClsTlv->baseTlv),
8000 tempBuf,
8001 MPLS_TLVFIXLEN);
8002 if (encodedSize < 0)
8004 return MPLS_ENC_TLVERROR;
8006 tempBuf += encodedSize;
8008 resClsTlv->rsCls = htonl(resClsTlv->rsCls);
8010 MEM_COPY( tempBuf,
8011 (u_char *)&(resClsTlv->rsCls),
8012 sizeof(u_int));
8014 return (MPLS_TLVFIXLEN + sizeof(u_int));
8016 } /* End: Mpls_encodeLdpResClsTlv */
8020 * decode
8022 int Mpls_decodeLdpResClsTlv
8024 mplsLdpResClsTlv_t * resClsTlv,
8025 u_char * buff,
8026 int bufSize
8029 if ((int)sizeof(u_int) > bufSize)
8031 PRINT_ERR("failed decoding resClass tlv\n");
8032 return MPLS_DEC_BUFFTOOSMALL;
8035 MEM_COPY( (u_char *)&(resClsTlv->rsCls),
8036 buff,
8037 sizeof(u_int));
8038 resClsTlv->rsCls = ntohl(resClsTlv->rsCls);
8040 return sizeof(u_int);
8042 } /* End: Mpls_decodeLdpResClsTlv */
8047 * Encode for Route Pinning Tlv
8051 * encode
8053 int Mpls_encodeLdpPinningTlv
8055 mplsLdpPinningTlv_t * pinningTlv,
8056 u_char * buff,
8057 int bufSize
8060 int encodedSize = 0;
8061 u_char * tempBuf = buff; /* no change for the buff ptr */
8063 if (MPLS_TLVFIXLEN + (int)sizeof(u_int) > bufSize)
8065 /* not enough room */
8066 return MPLS_ENC_BUFFTOOSMALL;
8070 * encode for tlv
8072 encodedSize = Mpls_encodeLdpTlv( &(pinningTlv->baseTlv),
8073 tempBuf,
8074 MPLS_TLVFIXLEN);
8075 if (encodedSize < 0)
8077 return MPLS_ENC_TLVERROR;
8079 tempBuf += encodedSize;
8081 pinningTlv->flags.flags.res = 0;
8082 pinningTlv->flags.mark = htonl(pinningTlv->flags.mark);
8084 MEM_COPY( tempBuf,
8085 (u_char *)&(pinningTlv->flags.mark),
8086 sizeof(u_int));
8088 return (MPLS_TLVFIXLEN + sizeof(u_int));
8090 } /* End: Mpls_encodeLdpPinningTlv*/
8094 * decode
8096 int Mpls_decodeLdpPinningTlv
8098 mplsLdpPinningTlv_t * pinningTlv,
8099 u_char * buff,
8100 int bufSize
8103 if ((int)sizeof(u_int) > bufSize)
8105 PRINT_ERR("failed decoding route pinning tlv\n");
8106 return MPLS_DEC_BUFFTOOSMALL;
8109 MEM_COPY( (u_char *)&(pinningTlv->flags.mark),
8110 buff,
8111 sizeof(u_int));
8112 pinningTlv->flags.mark = ntohl(pinningTlv->flags.mark);
8114 return sizeof(u_int);
8116 } /* End: Mpls_decodeLdpPinningTlv */
8120 * Label Abort Request Message
8124 * encode
8126 int Mpls_encodeLdpLblAbortMsg
8128 mplsLdpLblAbortMsg_t * lblAbortMsg,
8129 u_char * buff,
8130 int bufSize
8133 mplsLdpLblAbortMsg_t lblAbortMsgCopy;
8134 int encodedSize = 0;
8135 u_int totalSize = 0;
8136 u_char * tempBuf = buff; /* no change for the buff ptr */
8138 /* check the length of the messageId + param */
8139 if ((int)(lblAbortMsg->baseMsg.msgLength) + MPLS_TLVFIXLEN > bufSize)
8141 PRINT_ERR("failed to encode the lbl abort request msg: BUFFER TOO SMALL\n");
8142 return MPLS_ENC_BUFFTOOSMALL;
8145 lblAbortMsgCopy = *lblAbortMsg;
8148 * encode the base part of the pdu message
8150 encodedSize = Mpls_encodeLdpBaseMsg( &(lblAbortMsgCopy.baseMsg),
8151 tempBuf,
8152 bufSize);
8153 if (encodedSize < 0)
8155 return MPLS_ENC_BASEMSGERROR;
8157 PRINT_2("Encode BaseMsg for label abort request msg on %d bytes\n", encodedSize);
8158 tempBuf += encodedSize;
8159 totalSize += encodedSize;
8162 * encode the tlv if any
8164 if (lblAbortMsgCopy.fecTlvExists)
8166 encodedSize = Mpls_encodeLdpFecTlv( &(lblAbortMsgCopy.fecTlv),
8167 tempBuf,
8168 bufSize-totalSize);
8169 if (encodedSize < 0)
8171 return MPLS_ENC_FECERROR;
8173 PRINT_2("Encoded for FEC Tlv %d bytes\n", encodedSize);
8174 tempBuf += encodedSize;
8175 totalSize += encodedSize;
8177 if (lblAbortMsgCopy.lblMsgIdTlvExists)
8179 encodedSize = Mpls_encodeLdpLblMsgIdTlv( &(lblAbortMsgCopy.lblMsgIdTlv),
8180 tempBuf,
8181 bufSize-totalSize);
8182 if (encodedSize < 0)
8184 return MPLS_ENC_LBLMSGIDERROR;
8186 PRINT_2("Encoded for lbl request msg id Tlv %d bytes\n", encodedSize);
8187 tempBuf += encodedSize;
8188 totalSize += encodedSize;
8191 return totalSize;
8193 } /* End: Mpls_encodeLdpLblAbortMsg */
8197 * decode
8199 int Mpls_decodeLdpLblAbortMsg
8201 mplsLdpLblAbortMsg_t * lblAbortMsg,
8202 u_char * buff,
8203 int bufSize
8206 int decodedSize = 0;
8207 u_int totalSize = 0;
8208 u_int stopLength = 0;
8209 u_int totalSizeParam = 0;
8210 u_char * tempBuf = buff; /* no change for the buff ptr */
8211 mplsLdpTlv_t tlvTemp;
8214 * decode the base part of the pdu message
8216 bzero(lblAbortMsg, sizeof(mplsLdpLblAbortMsg_t));
8217 decodedSize = Mpls_decodeLdpBaseMsg( &(lblAbortMsg->baseMsg),
8218 tempBuf,
8219 bufSize);
8220 if (decodedSize < 0)
8222 return MPLS_DEC_BASEMSGERROR;
8224 PRINT_2("Decode BaseMsg for Lbl Abort Request Msg on %d bytes\n", decodedSize);
8226 if (lblAbortMsg->baseMsg.flags.flags.msgType != MPLS_LBLABORT_MSGTYPE)
8228 PRINT_ERR_2("Not the right message type; expected lbl abort and got %x\n",
8229 lblAbortMsg->baseMsg.flags.flags.msgType);
8230 return MPLS_MSGTYPEERROR;
8233 tempBuf += decodedSize;
8234 totalSize += decodedSize;
8236 if (bufSize-totalSize <= 0)
8238 /* nothing left for decoding */
8239 PRINT_ERR("Lbl Abort msg does not have anything beside base msg\n");
8240 return totalSize;
8243 PRINT_4("bufSize = %d, totalSize = %d, lblAbortMsg->baseMsg.msgLength = %d\n",
8244 bufSize, totalSize, lblAbortMsg->baseMsg.msgLength);
8246 /* Have to check the baseMsg.msgLength to know when to finish.
8247 * We finsh when the totalSizeParam is >= to the base message length - the
8248 * message id length (4)
8251 stopLength = lblAbortMsg->baseMsg.msgLength - MPLS_MSGIDFIXLEN;
8252 while (stopLength > totalSizeParam)
8255 * decode the tlv to check what's next
8257 bzero(&tlvTemp, MPLS_TLVFIXLEN);
8258 decodedSize = Mpls_decodeLdpTlv(&tlvTemp, tempBuf, bufSize-totalSize);
8259 if (decodedSize < 0)
8261 /* something wrong */
8262 PRINT_ERR("Label Abort msg decode failed for tlv\n");
8263 return MPLS_DEC_TLVERROR;
8266 tempBuf += decodedSize;
8267 totalSize += decodedSize;
8268 totalSizeParam += decodedSize;
8270 switch (tlvTemp.flags.flags.type)
8272 case MPLS_FEC_TLVTYPE:
8274 decodedSize = Mpls_decodeLdpFecTlv( &(lblAbortMsg->fecTlv),
8275 tempBuf,
8276 bufSize-totalSize,
8277 tlvTemp.length);
8278 if (decodedSize < 0)
8280 PRINT_ERR("Failure when decoding FEC tlv from LblAbort msg\n");
8281 return MPLS_DEC_FECERROR;
8283 PRINT_2("Decoded for FEC %d bytes\n", decodedSize);
8284 tempBuf += decodedSize;
8285 totalSize += decodedSize;
8286 totalSizeParam += decodedSize;
8288 lblAbortMsg->fecTlvExists = 1;
8289 lblAbortMsg->fecTlv.baseTlv = tlvTemp;
8290 DEBUG_CALL(printFecListTlv(&(lblAbortMsg->fecTlv)));
8291 break;
8293 case MPLS_REQMSGID_TLVTYPE:
8295 decodedSize = Mpls_decodeLdpLblMsgIdTlv( &(lblAbortMsg->lblMsgIdTlv),
8296 tempBuf,
8297 bufSize-totalSize);
8298 if (decodedSize < 0)
8300 PRINT_ERR("Failure when dec LblMsgId tlv from LblAbort msg\n");
8301 return MPLS_DEC_LBLMSGIDERROR;
8303 PRINT_2("Decoded for LblMsgId %d bytes\n", decodedSize);
8304 tempBuf += decodedSize;
8305 totalSize += decodedSize;
8306 totalSizeParam += decodedSize;
8308 lblAbortMsg->lblMsgIdTlvExists = 1;
8309 lblAbortMsg->lblMsgIdTlv.baseTlv = tlvTemp;
8310 DEBUG_CALL(printLblMsgIdTlv(&(lblAbortMsg->lblMsgIdTlv)));
8311 break;
8313 default:
8315 PRINT_ERR_2("Found wrong tlv type while decoding lbl abort msg (%x)\n",
8316 tlvTemp.flags.flags.type);
8317 if (tlvTemp.flags.flags.uBit == 1)
8319 /* ignore the Tlv and continue processing */
8320 tempBuf += tlvTemp.length;
8321 totalSize += tlvTemp.length;
8322 totalSizeParam += tlvTemp.length;
8323 break;
8325 else
8327 /* drop the message; return error */
8328 return MPLS_TLVTYPEERROR;
8331 } /* switch type */
8333 } /* while */
8335 PRINT_2("totalsize for Mpls_decodeLdpLblAbortMsg is %d\n", totalSize);
8337 return totalSize;
8339 } /* End: Mpls_decodeLdpLblAbortMsg */
8343 * DEBUG functions
8345 void printTlv(mplsLdpTlv_t *tlv)
8347 printf("\t Tlv:\n");
8348 printf("\t BaseTlv: uBit = %d\n \t\t fBit = %d\n \t\t type = %x\n \t\t length = %d\n",
8349 tlv->flags.flags.uBit,
8350 tlv->flags.flags.fBit,
8351 tlv->flags.flags.type,
8352 tlv->length);
8355 void printHeader(mplsLdpHeader_t *header)
8357 printf("LPD Header : protocolVersion = %d\n \tpduLength = %d\n \tlsrAddress = %x\n \tlabelSpace = %x\n",
8358 header->protocolVersion, header->pduLength, header->lsrAddress,
8359 header->labelSpace);
8362 void printCspFlags(mplsLdpCspFlag_t * cspFlags)
8364 printf("\tCSP Flags: lad = %d, ld = %d, pvl = %d, res = %d\n",
8365 cspFlags->lad,
8366 cspFlags->ld,
8367 cspFlags->pvl,
8368 cspFlags->res);
8371 void printCspFlagsPerByte(u_short * cspFlags)
8373 u_char *ptr;
8374 ptr = (u_char*)cspFlags;
8375 printf("\tCSP Flags: (byte 0) %x\n \t\t (byte 1) %x\n", *ptr++, *ptr);
8378 void printCspTlv(mplsLdpCspTlv_t * csp)
8380 printf("\tCSP:\n");
8381 printTlv(&(csp->baseTlv));
8382 printf("\tcsp : protocolVersion = %d\n \t\tholdTime = %d\n \t\tmaxPduLen = %d\n \t\trcvLsrAddress = %s\n \t\trcvLsId = %d\n",
8383 csp->protocolVersion, csp->holdTime,
8384 csp->maxPduLen, inet_ntoa(csp->rcvLsrAddress), csp->rcvLsId);
8385 printCspFlags(&(csp->flags.flags));
8388 void printAspFlags(mplsLdpSPFlag_t * aspFlags)
8390 printf("\t ASP Flags: mergeType = %d, numLblRng = %d, dir = %d, res = %d\n",
8391 aspFlags->mergeType,
8392 aspFlags->numLblRng,
8393 aspFlags->dir,
8394 aspFlags->res);
8397 void printAspFlagsPerByte(u_int * aspFlags)
8399 u_char *ptr;
8400 ptr = (u_char*)aspFlags;
8401 printf("\tASP Flags: (byte 0) %x\n \t\t (byte 1) %x\n \t\t (byte 2) %x\n\t\t (byte 3) %x\n",
8402 *ptr++, *ptr++, *ptr++, *ptr);
8406 void printAtmLabel(mplsLdpAtmLblRng_t *label, int i)
8408 printf("\tATM LABEL (%d) : res1 = %d, minVci = %d, minVpi = %d, res2 = %d, maxVci = %d, maxVpi = %d\n",
8410 label->flags.flags.res1,
8411 label->flags.flags.minVci,
8412 label->flags.flags.minVpi,
8413 label->flags.flags.res2,
8414 label->flags.flags.maxVci,
8415 label->flags.flags.maxVpi);
8418 void printAspTlv(mplsLdpAspTlv_t *asp)
8420 int i = 0;
8422 printf("\t asp:\n");
8423 printTlv(&(asp->baseTlv));
8424 printf("\t asp labes (%d)\n", (int)(asp->flags.flags.numLblRng));
8425 for (i = 0; i < (int)(asp->flags.flags.numLblRng); i++)
8427 printAtmLabel(&(asp->lblRngList[i]), i);
8429 printAspFlags(&(asp->flags.flags));
8432 void printFspFlags(mplsLdpSPFlag_t * fspFlags)
8434 printf("\t FSP Flags: mergeType = %d, numLblRng = %d, dir = %d, res = %d\n",
8435 fspFlags->mergeType,
8436 fspFlags->numLblRng,
8437 fspFlags->dir,
8438 fspFlags->res);
8441 void printFspLabel(mplsLdpFrLblRng_t *label, int i)
8443 printf("\tFR LABEL (%d) : res_max = %d, maxDlci = %d, res_min = %d, len = %d minDlci = %d\n",
8445 label->flags.flags.res_max,
8446 label->flags.flags.maxDlci,
8447 label->flags.flags.res_min,
8448 label->flags.flags.len,
8449 label->flags.flags.minDlci);
8452 void printFspTlv(mplsLdpFspTlv_t *fsp)
8454 int i = 0;
8456 printf("\t fsp:\n");
8457 printTlv(&(fsp->baseTlv));
8458 printf("\t fsp labes (%d)\n", (int)(fsp->flags.flags.numLblRng));
8459 for (i = 0; i < (int)(fsp->flags.flags.numLblRng); i++)
8461 printFspLabel(&(fsp->lblRngList[i]), i);
8463 printFspFlags(&(fsp->flags.flags));
8466 void printMsgBase(mplsLdpMsg_t * msg)
8468 printf("\tbaseMsg : uBit = %d\n \t\t msgType = %x\n \t\t msgLength = %d\n \t\t msgId = %d\n",
8469 msg->flags.flags.uBit,
8470 msg->flags.flags.msgType,
8471 msg->msgLength,
8472 msg->msgId);
8474 void printInitMsg(mplsLdpInitMsg_t *initMsg)
8476 printf("INIT MSG ***START***:\n");
8477 printMsgBase(&(initMsg->baseMsg));
8478 if (initMsg->cspExists)
8480 printCspTlv(&(initMsg->csp));
8482 else
8484 printf("\tINIT msg does NOT have CSP\n");
8486 if (initMsg->aspExists)
8488 printAspTlv(&(initMsg->asp));
8490 else
8492 printf("\tINIT msg does NOT have ASP\n");
8494 if (initMsg->fspExists)
8496 printFspTlv(&(initMsg->fsp));
8498 else
8500 printf("\tINIT msg does NOT have FSP\n");
8502 printf("\nINIT MSG ***END***\n");
8505 void printRetMsgTlv(mplsLdpRetMsgTlv_t * retMsg)
8507 printf("\t retMsgTlv:\n");
8508 printTlv(&(retMsg->baseTlv));
8509 printf("\t retMsgTlv.data is %s\n", retMsg->data);
8512 void printRetPduTlv(mplsLdpRetPduTlv_t * retPdu)
8514 printf("\t retPduTlv:\n");
8515 printTlv(&(retPdu->baseTlv));
8516 printf("\t retPduTlv.data is %s\n", retPdu->data);
8519 void printExStatusTlv(mplsLdpExStatusTlv_t * status)
8521 printf("\t exStatusTlv:\n");
8522 printTlv(&(status->baseTlv));
8523 printf("\t exStatus data: value = %d\n", status->value);
8526 void printStatusTlv(mplsLdpStatusTlv_t * status)
8528 printf("\t statusTlv:\n");
8529 printTlv(&(status->baseTlv));
8530 printf("\t status data: msgId = %x\n \t\t\tmsgType = %x\n",
8531 status->msgId, status->msgType);
8532 printf("\t status Flags: error = %d\n \t\t\tforward = %d\n \t\t\tstatus = %d\n",
8533 status->flags.flags.error,
8534 status->flags.flags.forward,
8535 status->flags.flags.status);
8538 void printNotMsg(mplsLdpNotifMsg_t * notMsg)
8540 printf("NOTIF MSG ***START***:\n");
8541 printMsgBase(&(notMsg->baseMsg));
8543 if (notMsg->statusTlvExists)
8545 printStatusTlv(&(notMsg->status));
8547 else
8549 printf("\tNotif msg does not have Status TLV\n");
8551 if (notMsg->exStatusTlvExists)
8553 printExStatusTlv(&(notMsg->exStatus));
8555 else
8557 printf("\tNotif msg does not have Extended Status TLV\n");
8559 if (notMsg->retPduTlvExists)
8561 printRetPduTlv(&(notMsg->retPdu));
8563 else
8565 printf("\tNotif msg does not have Return PDU\n");
8567 if (notMsg->retMsgTlvExists)
8569 printRetMsgTlv(&(notMsg->retMsg));
8571 else
8573 printf("\tNotif msg does not have Return MSG\n");
8575 printf("NOTIF MSG ***END***:\n");
8578 void printCsnTlv(mplsLdpCsnTlv_t *csn)
8580 printf("\t csnTlv:\n");
8581 printTlv(&(csn->baseTlv));
8582 printf("\t csnTlv data: value = %d\n", csn->seqNumber);
8585 void printTrAdrTlv(mplsLdpTrAdrTlv_t *trAdr)
8587 printf("\t trAdrTlv:\n");
8588 printTlv(&(trAdr->baseTlv));
8589 printf("\t trAdrTlv data: value = %08x\n", trAdr->address);
8592 void printChpTlv(mplsLdpChpTlv_t *chp)
8594 printf("\t chpTlv:\n");
8595 printTlv(&(chp->baseTlv));
8596 printf("\t chpTlv data: holdTime = %d\n", chp->holdTime);
8597 printf("\t chpTlv Flags: target = %d\n \t\t\trequest = %d\n \t\t\tres = %d\n",
8598 chp->flags.flags.target,
8599 chp->flags.flags.request,
8600 chp->flags.flags.res);
8603 void printHelloMsg(mplsLdpHelloMsg_t * helloMsg)
8605 printf("HELLO MSG ***START***:\n");
8606 printMsgBase(&(helloMsg->baseMsg));
8608 if (helloMsg->chpTlvExists)
8610 printChpTlv(&(helloMsg->chp));
8612 else
8614 printf("\tHello msg does not have Chp TLV\n");
8616 if (helloMsg->trAdrTlvExists)
8618 printTrAdrTlv(&(helloMsg->trAdr));
8620 else
8622 printf("\tHello msg does not have TrAdr TLV\n");
8624 if (helloMsg->csnTlvExists)
8626 printCsnTlv(&(helloMsg->csn));
8628 else
8630 printf("\tHello msg does not have Csn TLV\n");
8632 printf("HELLO MSG ***END***:\n");
8635 void printKeepAliveMsg(mplsLdpKeepAlMsg_t *keepAliveMsg)
8637 printf("KEEP ALIVE MSG ***START***:\n");
8638 printMsgBase(&(keepAliveMsg->baseMsg));
8639 printf("KEEP ALIVE MSG ***END***:\n");
8642 void printAdrListTlv(mplsLdpAdrTlv_t *adrList)
8644 u_short i;
8645 u_short length;
8647 printf("\t adrListTlv:\n");
8648 printTlv(&(adrList->baseTlv));
8649 printf("\t adrListTlv data: addrFamily = %x\n", adrList->addrFamily);
8651 /* get the current length of the encoding for addresses */
8653 length = adrList->baseTlv.length - MPLS_ADDFAMFIXLEN;
8654 printf("\t adrListTlv addresses (with %d addresses) :\n", length/4);
8655 for (i = 0; i < (u_short)(length/4); i++)
8657 if (i%4 == 0)
8659 printf("\n\t\t\t");
8661 printf("%02x ", adrList->address[i]);
8663 printf("\n");
8667 void printAddressMsg(mplsLdpAdrMsg_t *adrMsg)
8669 if (adrMsg->baseMsg.flags.flags.msgType == MPLS_ADDR_MSGTYPE)
8670 printf("ADDRESS MSG ***START***:\n");
8671 else if (adrMsg->baseMsg.flags.flags.msgType == MPLS_ADDRWITH_MSGTYPE)
8672 printf("ADDRESS WITHDRAW MSG ***START***:\n");
8674 printMsgBase(&(adrMsg->baseMsg));
8676 if (adrMsg->adrListTlvExists)
8678 printAdrListTlv(&(adrMsg->addressList));
8680 else
8682 printf("\tAddress msg does not have addrList Tlv\n");
8684 if (adrMsg->baseMsg.flags.flags.msgType == MPLS_ADDR_MSGTYPE)
8685 printf("ADDRESS MSG ***END***:\n");
8686 else if (adrMsg->baseMsg.flags.flags.msgType == MPLS_ADDRWITH_MSGTYPE)
8687 printf("ADDRESS WITHDRAW MSG ***END***:\n");
8690 void printFecListTlv(mplsLdpFecTlv_t *fecTlv)
8692 u_short i;
8693 u_short j;
8694 printf("\t fecTlv:\n");
8695 printTlv(&(fecTlv->baseTlv));
8696 printf("\t\tfecTlv->numberFecElements = %d\n", fecTlv->numberFecElements);
8697 for (i = 0; i < fecTlv->numberFecElements; i++)
8699 printf("\t\telem %d type is %d\n", i, fecTlv->fecElemTypes[i]);
8700 switch (fecTlv->fecElemTypes[i])
8702 case MPLS_PREFIX_FEC:
8703 case MPLS_HOSTADR_FEC:
8705 printf("\t\tFec Element : type = %d, addFam = %x, ",
8706 fecTlv->fecElArray[i].addressEl.type,
8707 fecTlv->fecElArray[i].addressEl.addressFam);
8708 printf("preLen = %d, address = %x\n",
8709 fecTlv->fecElArray[i].addressEl.preLen,
8710 fecTlv->fecElArray[i].addressEl.address);
8711 break;
8713 case MPLS_MARTINIVC_FEC:
8715 printf("\t\tMartini VC Element : type = %d, cBit = %d, ",
8716 fecTlv->fecElArray[i].martiniVcEl.flags.flags.type,
8717 fecTlv->fecElArray[i].martiniVcEl.flags.flags.control);
8718 printf("VC type = 0x%x\n",
8719 fecTlv->fecElArray[i].martiniVcEl.flags.flags.vcType);
8720 printf("\t\t\tVC info len = %d group id = %d\n",
8721 fecTlv->fecElArray[i].martiniVcEl.flags.flags.vcInfoLen,
8722 fecTlv->fecElArray[i].martiniVcEl.groupId);
8724 if (fecTlv->fecElArray[i].martiniVcEl.flags.flags.vcInfoLen)
8726 printf("\t\t\tVC id = %d :\n",
8727 fecTlv->fecElArray[i].martiniVcEl.vcId);
8728 for (j=0; j<fecTlv->fecElArray[i].martiniVcEl.vcIfParamsLen; j++)
8730 u_char *value = (u_char*)&fecTlv->fecElArray[i].martiniVcEl.vcIfParams[j].value;
8731 u_char id = fecTlv->fecElArray[i].martiniVcEl.vcIfParams[j].id;
8732 u_char len = fecTlv->fecElArray[i].martiniVcEl.vcIfParams[j].len;
8733 len -= MPLS_VCIFPARAM_HDR;
8735 switch (id)
8737 case MPLS_VCIFPARAM_MTU:
8739 u_short mtu;
8741 MEM_COPY (&mtu, value, len);
8742 printf("\t\t\t\tMTU = %d\n", ntohs(mtu));
8743 break;
8745 case MPLS_VCIFPARAM_INFO:
8747 char string[81];
8748 MEM_COPY (string, value, len);
8749 string[len] = '\0';
8750 printf("\t\t\t\tIntf info = %s\n",string);
8751 break;
8753 default:
8755 int max = 8;
8756 int k;
8758 printf("\t\t\t\tType = %d:\n", id);
8759 for (k = 0; k < len; k++)
8761 if (!(k % max))
8763 printf("\t\t\t\t\t");
8765 printf("0x%02x ", value[k]);
8766 if ((k % max) == (max - 1))
8768 printf("\n");
8771 printf("\n");
8772 break;
8780 printf("\n");
8781 printf("\tfecTlv.wcElemExists = %d\n", fecTlv->wcElemExists);
8785 void printLblMsgIdTlv(mplsLdpLblMsgIdTlv_t * lblMsgId)
8787 printf("\t lblMsgIdTlv:\n");
8788 printTlv(&(lblMsgId->baseTlv));
8789 printf("\t LblMsgId data: msgId = %d\n", lblMsgId->msgId);
8792 void printPathVecTlv(mplsLdpPathTlv_t* pathVec)
8794 u_int i, numlsrId;
8796 printf("\t pathVecTlv:\n");
8797 printTlv(&(pathVec->baseTlv));
8798 printf("\t PathVec data: " );
8800 numlsrId = pathVec->baseTlv.length / 4;
8802 for (i = 0; i< numlsrId; i++)
8804 if(i == 0)
8805 printf("lsrId[%d] = %x\n", i, pathVec->lsrId[i]);
8806 else
8807 printf("\t\t\tlsrId[%d] = %x\n", i, pathVec->lsrId[i]);
8809 printf("\n");
8812 void printHopTlv(mplsLdpHopTlv_t * hopCount)
8814 printf("\t hopCountTlv:\n");
8815 printTlv(&(hopCount->baseTlv));
8816 printf("\t hopCount data: hcValue = %d\n", hopCount->hcValue);
8819 void printFrLblTlv(mplsLdpFrLblTlv_t * fr)
8821 printf("\t frTlv :\n");
8822 printTlv(&(fr->baseTlv));
8823 printf("\t Fr flags: res = %d\n \t\t len = %d\n \t\tdlci = %d\n",
8824 fr->flags.flags.res, fr->flags.flags.len, fr->flags.flags.dlci);
8827 void printAtmLblTlv(mplsLdpAtmLblTlv_t * atm)
8829 printf("\t atmTlv :\n");
8830 printTlv(&(atm->baseTlv));
8831 printf("\t Atm flags: res = %d\n \t\t v = %d\n \t\tvpi = %d\n",
8832 atm->flags.flags.res, atm->flags.flags.v, atm->flags.flags.vpi);
8833 printf("\t Atm data : vci = %d\n", atm->vci);
8836 void printGenLblTlv(mplsLdpGenLblTlv_t * genLbl)
8838 printf("\t genLblTlv:\n");
8839 printTlv(&(genLbl->baseTlv));
8840 printf("\t genLbl data: label = %d\n", genLbl->label);
8844 void printLlbMapMsg(mplsLdpLblMapMsg_t *lblMapMsg)
8846 printf("LABEL MAPPING MSG ***START***:\n");
8847 printMsgBase(&(lblMapMsg->baseMsg));
8849 if (lblMapMsg->fecTlvExists)
8851 printFecListTlv(&(lblMapMsg->fecTlv));
8853 else
8855 printf("\tLabel mapping msg does not have fec Tlv\n");
8857 if (lblMapMsg->genLblTlvExists)
8859 printGenLblTlv(&(lblMapMsg->genLblTlv));
8861 else
8863 printf("\tLabel mapping msg does not have gen label Tlv\n");
8865 if (lblMapMsg->atmLblTlvExists)
8867 printAtmLblTlv(&(lblMapMsg->atmLblTlv));
8869 else
8871 printf("\tLabel mapping msg does not have atm label Tlv\n");
8873 if (lblMapMsg->frLblTlvExists)
8875 printFrLblTlv(&(lblMapMsg->frLblTlv));
8877 else
8879 printf("\tLabel mapping msg does not have fr label Tlv\n");
8881 if (lblMapMsg->hopCountTlvExists)
8883 printHopTlv(&(lblMapMsg->hopCountTlv));
8885 else
8887 printf("\tLabel mapping msg does not have hop count Tlv\n");
8889 if (lblMapMsg->pathVecTlvExists)
8891 printPathVecTlv(&(lblMapMsg->pathVecTlv));
8893 else
8895 printf("\tLabel mapping msg does not have path vector Tlv\n");
8897 if (lblMapMsg->lblMsgIdTlvExists)
8899 printLblMsgIdTlv(&(lblMapMsg->lblMsgIdTlv));
8901 else
8903 printf("\tLabel mapping msg does not have label messageId Tlv\n");
8905 if (lblMapMsg->lspidTlvExists)
8907 printLspIdTlv(&(lblMapMsg->lspidTlv));
8909 else
8911 printf("\tLabel mapping msg does not have LSPID Tlv\n");
8913 if (lblMapMsg->trafficTlvExists)
8915 printTrafficTlv(&(lblMapMsg->trafficTlv));
8917 else
8919 printf("\tLabel mapping msg does not have traffic Tlv\n");
8921 printf("LABEL MAPPING MSG ***END***:\n");
8924 void printErFlags(mplsLdpErFlag_t* flags)
8926 printf("\t\tER FLAGS: l = %d, res = %d\n",
8927 flags->l, flags->res);
8930 void printErIPFlags(mplsLdpErIPFlag_t* flags)
8932 printf("\t\tER IP FLAGS: l = %d, res = %d, preLen = %d\n",
8933 flags->l, flags->res, flags->preLen);
8937 void printErHop(mplsLdpErHop_t * erHop, u_short type)
8939 int i;
8940 switch(type)
8942 case MPLS_ERHOP_IPV4_TLVTYPE:
8944 printErIPFlags(&(erHop->erIpv4.flags.flags));
8945 printf("\t\t IPv4: address = %x\n", erHop->erIpv4.address);
8946 break;
8948 case MPLS_ERHOP_IPV6_TLVTYPE:
8950 printErIPFlags(&(erHop->erIpv6.flags.flags));
8951 printf("\t\t IPv6: address ");
8952 for (i = 0; i< MPLS_IPV6ADRLENGTH; i++)
8954 printf("\t\t a[%d] = %x\n", i, erHop->erIpv6.address[i]);
8956 break;
8958 case MPLS_ERHOP_AS_TLVTYPE:
8960 printErFlags(&(erHop->erAs.flags.flags));
8961 printf("\t\t ASnumber: asNumber = %d\n", erHop->erAs.asNumber);
8962 break;
8964 case MPLS_ERHOP_LSPID_TLVTYPE:
8966 printErFlags(&(erHop->erLspId.flags.flags));
8967 printf("\t\t LSPID: lspid = %d, routerId = %d\n",
8968 erHop->erLspId.lspid, erHop->erLspId.routerId);
8969 break;
8971 default:
8973 printf("UNKNWON ER HOP type = %d\n", type);
8978 void printErTlv(mplsLdpErTlv_t *erTlv)
8980 u_short i;
8981 printf("\t erTlv:\n");
8982 printTlv(&(erTlv->baseTlv));
8983 printf("\t erTlv has %d ErHops\n", erTlv->numberErHops);
8984 for (i = 0; i < erTlv->numberErHops; i++)
8986 printf("\tTYPE[%i] = %x\n", i, erTlv->erHopTypes[i]);
8987 printErHop(&(erTlv->erHopArray[i]), erTlv->erHopTypes[i]);
8991 void printTrafficFlags(mplsLdpTrafficFlag_t * flag)
8993 printf("\t\tTraffic flags: res = %d, F6 = %d, F5 = %d, F4 = %d, F3 = %d, F2 = %d, F1 = %d\n",
8994 flag->res, flag->f6Bit, flag->f5Bit, flag->f4Bit,
8995 flag->f3Bit,flag->f2Bit, flag->f1Bit);
8998 void printTrafficTlv(mplsLdpTrafficTlv_t *trafficTlv)
9000 printf("\t trafficTlv:\n");
9001 printTlv(&(trafficTlv->baseTlv));
9002 printTrafficFlags(&(trafficTlv->flags.flags));
9003 printf("\t trafficTlv data: freq = %d, res = %d, weight = %d\n",
9004 trafficTlv->freq, trafficTlv->res, trafficTlv->weight);
9005 printf("\t trafficTlv param: \n");
9006 printf("\t\t PDR = %f (%x)\n", trafficTlv->pdr.pdr, *(u_int *)&(trafficTlv->pdr.pdr));
9007 printf("\t\t PBS = %f (%x)\n", trafficTlv->pbs.pbs, *(u_int *)&(trafficTlv->pbs.pbs));
9008 printf("\t\t CDR = %f (%x)\n", trafficTlv->cdr.cdr, *(u_int *)&(trafficTlv->cdr.cdr));
9009 printf("\t\t CBS = %f (%x)\n", trafficTlv->cbs.cbs, *(u_int *)&(trafficTlv->cbs.cbs));
9010 printf("\t\t EBS = %f (%x)\n", trafficTlv->ebs.ebs, *(u_int *)&(trafficTlv->ebs.ebs));
9013 void printLlbReqMsg(mplsLdpLblReqMsg_t *lblReqMsg)
9015 printf("LABEL REQUEST MSG ***START***:\n");
9016 printMsgBase(&(lblReqMsg->baseMsg));
9018 if (lblReqMsg->fecTlvExists)
9020 printFecListTlv(&(lblReqMsg->fecTlv));
9022 else
9024 printf("\tLabel request msg does not have fec Tlv\n");
9026 if (lblReqMsg->hopCountTlvExists)
9028 printHopTlv(&(lblReqMsg->hopCountTlv));
9030 else
9032 printf("\tLabel request msg does not have hop count Tlv\n");
9034 if (lblReqMsg->pathVecTlvExists)
9036 printPathVecTlv(&(lblReqMsg->pathVecTlv));
9038 else
9040 printf("\tLabel request msg does not have path vector Tlv\n");
9042 if (lblReqMsg->lblMsgIdTlvExists)
9044 printTlv(&(lblReqMsg->lblMsgIdTlv.baseTlv));
9046 else
9048 printf("\tLabel request msg does not have return msgId Tlv\n");
9050 if (lblReqMsg->erTlvExists)
9052 printErTlv(&(lblReqMsg->erTlv));
9054 else
9056 printf("\tLabel request msg does not have cr Tlv\n");
9058 if (lblReqMsg->trafficTlvExists)
9060 printTrafficTlv(&(lblReqMsg->trafficTlv));
9062 else
9064 printf("\tLabel request msg does not have traffic Tlv\n");
9066 if (lblReqMsg->lspidTlvExists)
9068 printLspIdTlv(&(lblReqMsg->lspidTlv));
9070 else
9072 printf("\tLabel request msg does not have LSPID Tlv\n");
9074 if (lblReqMsg->pinningTlvExists)
9076 printPinningTlv(&(lblReqMsg->pinningTlv));
9078 else
9080 printf("\tLabel request msg does not have Pinning Tlv\n");
9082 if (lblReqMsg->recClassTlvExists)
9084 printResClsTlv(&(lblReqMsg->resClassTlv));
9086 else
9088 printf("\tLabel request msg does not have ResClass Tlv\n");
9090 if (lblReqMsg->preemptTlvExists)
9092 printPreemptTlv(&(lblReqMsg->preemptTlv));
9094 else
9096 printf("\tLabel request msg does not have Preempt Tlv\n");
9098 printf("LABEL REQUEST MSG ***END***:\n");
9101 void printLbl_W_R_Msg(mplsLdpLbl_W_R_Msg_t * msg)
9103 if (msg->baseMsg.flags.flags.msgType == MPLS_LBLWITH_MSGTYPE)
9104 printf("LABEL WITHDRAW MSG ***START***:\n");
9105 else if (msg->baseMsg.flags.flags.msgType == MPLS_LBLREL_MSGTYPE)
9106 printf("LABEL RELEASE MSG ***START***:\n");
9107 printMsgBase(&(msg->baseMsg));
9109 if (msg->fecTlvExists)
9111 printFecListTlv(&(msg->fecTlv));
9113 else
9115 printf("\tLabel msg does not have fec Tlv\n");
9117 if (msg->genLblTlvExists)
9119 printGenLblTlv(&(msg->genLblTlv));
9121 else
9123 printf("\tLabel msg does not have gen Tlv\n");
9125 if (msg->atmLblTlvExists)
9127 printAtmLblTlv(&(msg->atmLblTlv));
9129 else
9131 printf("\tLabel msg does not have atm Tlv\n");
9133 if (msg->frLblTlvExists)
9135 printFrLblTlv(&(msg->frLblTlv));
9137 else
9139 printf("\tLabel msg does not have fr Tlv\n");
9141 if (msg->lspidTlvExists)
9143 printLspIdTlv(&(msg->lspidTlv));
9145 else
9147 printf("\tLabel msg does not have LSPID Tlv\n");
9149 if (msg->baseMsg.flags.flags.msgType == MPLS_LBLWITH_MSGTYPE)
9150 printf("LABEL WITHDRAW MSG *** END ***:\n");
9151 else if (msg->baseMsg.flags.flags.msgType == MPLS_LBLREL_MSGTYPE)
9152 printf("LABEL RELEASE MSG *** END ***:\n");
9155 void printPreemptTlv(mplsLdpPreemptTlv_t *preemptTlv)
9157 printf("\t preemptTlv:\n");
9158 printTlv(&(preemptTlv->baseTlv));
9159 printf("\t preemptTlv data: setPrio = %d, holdPrio = %d, res = %d\n",
9160 preemptTlv->setPrio, preemptTlv->holdPrio, preemptTlv->res);
9163 void printResClsTlv(mplsLdpResClsTlv_t *tlv)
9165 printf("\t resClsTlv:\n");
9166 printTlv(&(tlv->baseTlv));
9167 printf("\t resClsTlv data: rsCls = %x\n", tlv->rsCls);
9170 void printLspIdTlv(mplsLdpLspIdTlv_t *tlv)
9172 printf("\t lspIdTlv:\n");
9173 printTlv(&(tlv->baseTlv));
9174 printf("\t lspIdTlv data: res = %d, localCrlspId = %d, routerId = %x\n",
9175 tlv->res, tlv->localCrlspId, tlv->routerId);
9178 void printPinningTlv(mplsLdpPinningTlv_t *tlv)
9180 printf("\t pinningTlv:\n");
9181 printTlv(&(tlv->baseTlv));
9182 printf("\t pinningTlv data: pBit = %d, res = %d\n", tlv->flags.flags.pBit,
9183 tlv->flags.flags.res);
9186 void printLlbAbortMsg(mplsLdpLblAbortMsg_t *lblMsg)
9188 printf("LABEL ABORT MSG ***START***:\n");
9189 printMsgBase(&(lblMsg->baseMsg));
9191 if (lblMsg->fecTlvExists)
9193 printFecListTlv(&(lblMsg->fecTlv));
9195 else
9197 printf("\tLabel abort msg does not have fec Tlv\n");
9199 if (lblMsg->lblMsgIdTlvExists)
9201 printLblMsgIdTlv(&(lblMsg->lblMsgIdTlv));
9203 else
9205 printf("\tLabel abort msg does not have label messageId Tlv\n");
9207 printf("LABEL ABORT MSG ***END***:\n");
9212 * Routine to convert hex string to ascii string
9215 int converHexToAscii(u_char *buffHex, int buffHexLen, u_char * buffAscii)
9217 /* convert the hexEncrypP hex string to a char sting*/
9218 int i = 0;
9219 int j = 0;
9220 char c, c1;
9221 u_char *p = buffHex;
9222 u_char *q = buffAscii;
9224 for (i = 0; i< buffHexLen; i+=2, j++)
9226 c = *p;
9227 p++;
9228 c1 = *p;
9229 p++;
9230 if (c >= '0' && c <= '9')
9231 c -= '0';
9232 else if (c >= 'A' && c <= 'F')
9233 c -= 'A' - 0xa;
9234 else if (c >= 'a' && c <= 'f')
9235 c -= 'a' - 0xa;
9236 else
9237 return 0;
9238 if (c1 >= '0' && c1 <= '9')
9239 c1 -= '0';
9240 else if (c1 >= 'A' && c1 <= 'F')
9241 c1 -= 'A' - 0xa;
9242 else if (c1 >= 'a' && c1 <= 'f')
9243 c1 -= 'a' - 0xa;
9244 else
9245 return 0;
9247 *q++ = (c<< 4) + (c1 & 0x0f);
9249 return j;
9251 } /* End : converHexToAscii */
9255 * Routine to convert ascii string to hex string
9257 int converAsciiToHex(u_char *buffHex, int buffAsciiLen, u_char * buffAscii)
9259 int i;
9260 u_char *p2 = buffHex;
9261 u_char *p1 = buffAscii;
9262 u_char buf[3];
9264 for (i = 0; i< buffAsciiLen; i++)
9266 bzero(buf, 3);
9267 sprintf((char *)buf, "%02x", *p1++);
9268 memcpy(p2, buf, 2);
9269 p2 += strlen((char *)buf);
9271 *p2 = '\0';
9273 p2 = buffHex;
9274 for (i = 0; i< 2*buffAsciiLen; i++)
9276 printf("%c",*p2++);
9278 printf("\n");
9279 return i;
9281 } /* End : converAsciiToHex */
9284 /*****************************************************************************
9285 * This section includes one example of hex buffers which contains encoding *
9286 * for a pdu header and a request message. *
9288 * the hex buffer for the request message contains (where q represents the end*
9289 * of the buffer): *
9291 * 0001009AC00003050002040100900000000806010000010000100200011B00194059030001 *
9292 * 042F7D308308210008000000013A1D65030800003008040008000000193A1D651708040008 *
9293 * 800000053A1D6503080400088000000F3A1D650D08040008000000233A1D65210810001824 *
9294 * 01000040e3333342c8000040e00000447a0000412000000823000480000000082200040ABC *
9295 * DEFF0820000407070000q *
9297 * Make sure that when copy and paste the buffer, there are no new line chars *
9298 * or blanks. *
9299 * When decoding the above buffer, the following debug output should show if *
9300 * the debug flag is defined and set: *
9302 *LPD Header : protocolVersion = 1 *
9303 * pduLength = 154 *
9304 * lsrAddress = c0000305 *
9305 * labelSpace = 2 *
9307 *LABEL REQUEST MSG ***START***: *
9308 * baseMsg : msgType = 401 *
9309 * msgLength = 144 *
9310 * msgId = 8 *
9311 * fecTlv: *
9312 * Tlv: *
9313 * BaseTlv: type = 100 *
9314 * length = 16 *
9315 * uBit = 0 *
9316 * fBit = 0 *
9317 * fecTlv->numberFecElements = 2 *
9318 * elem 0 type is 2 *
9319 * Fec Element : type = 2, addFam = 1, preLen = 27, *
9320 * address = 194059 *
9321 * elem 1 type is 3 *
9322 * Fec Element : type = 3, addFam = 1, preLen = 4, *
9323 * address = 2f7d3083 *
9324 * *
9325 * fecTlv.wcElemExists = 0 *
9326 * Label request msg does not have cos label Tlv *
9327 * Label request msg does not have hop count Tlv *
9328 * Label request msg does not have path vector Tlv *
9329 * Tlv: *
9330 * BaseTlv: type = 601 *
9331 * length = 0 *
9332 * uBit = 0 *
9333 * fBit = 0 *
9334 * erTlv: *
9335 * Tlv: *
9336 * BaseTlv: type = 800 *
9337 * length = 48 *
9338 * uBit = 0 *
9339 * fBit = 0 *
9340 * erTlv has 4 ErHops *
9341 * TYPE[0] = 804 *
9342 * ER FLAGS: l = 0, res = 0 *
9343 * LSPID: lspid = 25, routerId = 975004951 *
9344 * TYPE[1] = 804 *
9345 * ER FLAGS: l = 1, res = 0 *
9346 * LSPID: lspid = 5, routerId = 975004931 *
9347 * TYPE[2] = 804 *
9348 * ER FLAGS: l = 1, res = 0 *
9349 * LSPID: lspid = 15, routerId = 975004941 *
9350 * TYPE[3] = 804 *
9351 * ER FLAGS: l = 0, res = 0 *
9352 * LSPID: lspid = 35, routerId = 975004961 *
9353 * trafficTlv: *
9354 * Tlv: *
9355 * BaseTlv: type = 810 *
9356 * length = 24 *
9357 * uBit = 0 *
9358 * fBit = 0 *
9359 * Traffic flags: res = 0, F6 = 1, F5 = 0, F4 = 0, F3 = 1, *
9360 * F2 = 0, F1 = 0 *
9361 * trafficTlv data: freq = 1, res = 0, weight = 0 *
9362 * trafficTlv param: *
9363 * PDR = 7.1(40e33333) *
9364 * PBS = 100.0(42c80000) *
9365 * CDR = 7.0(40e00000) *
9366 * CBS = 1000.0(447a0000) *
9367 * EBS = 10.0(41200000) *
9368 * lspIdTlv: *
9369 * Tlv: *
9370 * BaseTlv: type = 821 *
9371 * length = 8 *
9372 * uBit = 0 *
9373 * fBit = 0 *
9374 * lspIdTlv data: res = 0, localCrlspId = 1, routerId = 3a1d6503 *
9375 * pinningTlv: *
9376 * Tlv: *
9377 * BaseTlv: type = 823 *
9378 * length = 4 *
9379 * uBit = 0 *
9380 * fBit = 0 *
9381 * pinningTlv data: pBit = 1, res = 0 *
9382 * resClsTlv: *
9383 * Tlv: *
9384 * BaseTlv: type = 822 *
9385 * length = 4 *
9386 * uBit = 0 *
9387 * fBit = 0 *
9388 * resClsTlv data: rsCls = abcdeff *
9389 * preemptTlv: *
9390 * Tlv: *
9391 * BaseTlv: type = 820 *
9392 * length = 4 *
9393 * uBit = 0 *
9394 * fBit = 0 *
9395 * preemptTlv data: setPrio = 7, holdPrio = 7, res = 0 *
9396 *LABEL REQUEST MSG ***END***: *
9397 *****************************************************************************/