From: Vasu Dasari <vdasari@gmail.com>
[mpls-ldp-portable.git] / rsvpte / rsvpte_packet.c
blob7d326bfcc0af3e327943a91527ff11d5a2f8c436
1 #include "rsvpte_struct.h"
3 inline void htonl_nba(u_char * buf, u_int * extra) {
4 u_int temp;
5 memcpy(&temp, buf, sizeof(u_int));
6 temp = htonl(temp);
7 memcpy(buf, &temp, sizeof(u_int));
8 if (extra) {
9 (*extra) = temp;
13 inline void ntohl_nba(u_char * buf, u_int * extra) {
14 u_int temp;
15 memcpy(&temp, buf, sizeof(u_int));
16 temp = ntohl(temp);
17 memcpy(buf, &temp, sizeof(u_int));
18 if (extra) {
19 (*extra) = temp;
23 inline void htons_nba(u_char * buf, u_short * extra) {
24 u_short temp;
25 memcpy(&temp, buf, sizeof(u_short));
26 temp = htons(temp);
27 memcpy(buf, &temp, sizeof(u_short));
28 if (extra) {
29 (*extra) = temp;
33 inline void ntohs_nba(u_char * buf, u_short * extra) {
34 u_int temp;
35 memcpy(&temp, buf, sizeof(u_short));
36 temp = ntohs(temp);
37 memcpy(buf, &temp, sizeof(u_short));
38 if (extra) {
39 (*extra) = temp;
43 /* Message Header */
45 int rsvpteEncodeMsgHeader(rsvpHeader_t * header, u_char * buf, int bufSize) {
46 rsvpHeader_t headerCopy;
48 if (RSVP_HDRSIZE > bufSize) {
49 return MPLS_ENC_BUFFTOOSMALL;
52 headerCopy = *header;
53 headerCopy.checksum = htons(header->checksum);
54 headerCopy.length = htons(header->length);
56 memcpy(buf, &headerCopy, RSVP_HDRSIZE);
57 return RSVP_HDRSIZE;
60 int rsvpteDecodeMsgHeader(rsvpHeader_t * header, u_char * buf, int bufSize) {
61 if (RSVP_HDRSIZE > bufSize) {
62 return MPLS_DEC_BUFFTOOSMALL;
65 memcpy((u_char*)header, buf, RSVP_HDRSIZE);
66 header->checksum = ntohs(header->checksum);
67 header->length = ntohs(header->length);
69 if (header->length > RSVP_PDUMAXLEN) {
70 return MPLS_PDU_LENGTH_ERROR;
72 return RSVP_HDRSIZE;
75 /* Object Header */
77 int rsvpteEncodeObjectHeader(rsvpObjectHeader_t * header, u_char * buf, int bufSize) {
78 rsvpObjectHeader_t headerCopy;
80 if (RSVP_OBJECT_HDRSIZE > bufSize) {
81 return MPLS_ENC_BUFFTOOSMALL;
84 headerCopy = *header;
85 headerCopy.length = htons(header->length);
87 memcpy(buf, &headerCopy, RSVP_OBJECT_HDRSIZE);
88 return RSVP_OBJECT_HDRSIZE;
91 int rsvpteDecodeObjectHeader(rsvpObjectHeader_t * header, u_char * buf, int bufSize) {
92 if (RSVP_OBJECT_HDRSIZE > bufSize) {
93 return MPLS_DEC_BUFFTOOSMALL;
96 memcpy(header, buf, RSVP_OBJECT_HDRSIZE);
97 header->length = ntohs(header->length);
98 return RSVP_OBJECT_HDRSIZE;
101 /* Session Object */
103 int rsvpteEncodeSession4(rsvpSession4_t * session, u_char * buf, int bufSize) {
104 rsvpSession4_t sessionCopy;
106 if (RSVP_SESSION4_SIZE > bufSize) {
107 return MPLS_ENC_BUFFTOOSMALL;
109 sessionCopy = *session;
111 sessionCopy.destAddr = htonl(session->destAddr);
112 sessionCopy.destPort = htons(session->destPort);
114 memcpy(buf, &sessionCopy, RSVP_SESSION4_SIZE);
115 return RSVP_SESSION4_SIZE;
118 int rsvpteDecodeSession4(rsvpSession4_t * session, u_char * buf, int bufSize) {
119 if (RSVP_SESSION4_SIZE > bufSize) {
120 return MPLS_DEC_BUFFTOOSMALL;
123 memcpy(session, buf, RSVP_SESSION4_SIZE);
124 session->destAddr = nthol(session->destAddr);
125 session->destPort = nthos(session->destPort);
127 return RSVP_SESSION4_SIZE;
130 int rsvpteEncodeSession6(rsvpSession6_t * session, u_char * buf, int bufSize) {
131 rsvpSession6_t sessionCopy;
132 if (RSVP_SESSION6_SIZE > bufSize) {
133 return MPLS_ENC_BUFFTOOSMALL;
135 sessionCopy = *session;
137 sessionCopy.destPort = htons(session->destPort);
139 memcpy(buf, &sessionCopy, RSVP_SESSION4_SIZE);
140 return RSVP_SESSION4_SIZE;
143 int rsvpteDecodeSession6(rsvpSession6_t * session, u_char * buf, int bufSize) {
144 if (RSVP_SESSION6_SIZE > bufSize) {
145 return MPLS_DEC_BUFFTOOSMALL;
148 memcpy(session, buf, RSVP_SESSION4_SIZE);
149 session->destPort = nthos(session->destPort);
151 return RSVP_SESSION4_SIZE;
154 int rsvpteEncodeSessionTunnel4(rsvpSessionTunnel4_t * session, u_char * buf, int bufSize) {
155 rsvpSessionTunnel4_t sessionCopy;
156 if (RSVP_SESSION_TUNNEL4_SIZE > bufSize) {
157 return MPLS_ENC_BUFFTOOSMALL;
159 sessionCopy = *session;
161 sessionCopy.endPointAddress = htonl(session->endPointAddress);
162 sessionCopy.reserved = 0;
163 sessionCopy.tunnelId = htons(session->tunnelId);
164 sessionCopy.extentedTunnelId = htonl(session->destPort);
166 memcpy(buf, &sessionCopy, RSVP_SESSION_TUNNEL4_SIZE);
167 return RSVP_SESSION_TUNNEL4_SIZE;
170 int rsvpteDecodeSessionTunnel4(rsvpSessionTunnel4_t * session, u_char * buf, int bufSize) {
171 if (RSVP_SESSION_TUNNEL4_SIZE > bufSize) {
172 return MPLS_DEC_BUFFTOOSMALL;
175 memcpy(session, buf, RSVP_SESSION_TUNNEL4_SIZE);
176 session->endPointAddress = nthol(session->endPointAddress);
177 session->reserved = nthos(session->reserved);
178 session->tunnelId = nthos(session->tunnelId);
179 session->extentedTunnelId = nthol(session->extentedTunnelId);
181 return RSVP_SESSION_TUNNEL4_SIZE;
184 int rsvpteEncodeSessionTunnel6(rsvpSessionTunnel6_t * session, u_char * buf, int bufSize) {
185 rsvpSessionTunnel6_t sessionCopy;
186 if (RSVP_SESSION_TUNNEL6_SIZE > bufSize) {
187 return MPLS_ENC_BUFFTOOSMALL;
189 sessionCopy = *session;
191 sessionCopy.reserved = 0;
192 sessionCopy.tunnelId = htons(session->tunnelId);
194 memcpy(buf, &sessionCopy, RSVP_SESSION_TUNNEL6_SIZE);
195 return RSVP_SESSION_TUNNEL6_SIZE;
198 int rsvpteDecodeSessionTunnel6(rsvpSessionTunnel6_t * session, u_char * buf, int bufSize) {
199 if (RSVP_SESSION_TUNNEL6_SIZE > bufSize) {
200 return MPLS_DEC_BUFFTOOSMALL;
203 memcpy(session, buf, RSVP_SESSION_TUNNEL6_SIZE);
204 session->reserved = nthos(session->reserved);
205 session->tunnelId = nthos(session->tunnelId);
207 return RSVP_SESSION_TUNNEL6_SIZE;
210 int rsvpteEncodeSessionObject(rsvpSessionObject_t * session, u_char * buf, int bufSize) {
211 int encodedSize = 0;
212 char *bufHdr = buf;
213 int size;
215 if (RSVP_OBJECT_HDRSIZE > bufSize) {
216 return MPLS_ENC_BUFFTOOSMALL;
219 size = RSVP_OBJECT_HDRSIZE;
220 encodeSize += size;
221 bufSize -= size;
222 buf += size;
224 switch(session->hdr.cType) {
225 case RSVP_SESSION_CTYPE_IPV4:
226 size = rsvpteEncodeSession4(&session->u.ipv4, buf, bufSize);
227 break;
228 case RSVP_SESSION_CTYPE_IPV6:
229 size = rsvpteEncodeSession6(&session->u.ipv6, buf, bufSize);
230 break;
231 case RSVP_SESSION_CTYPE_TUNNEL4:
232 size = rsvpteEncodeSessionTunnel4(&session->u.tunnel4, buf, bufSize);
233 break;
234 case RSVP_SESSION_CTYPE_TUNNEL6:
235 size = rsvpteEncodeSessionTunnel6(&session->u.tunnel6, buf, bufSize);
236 break;
237 default:
238 return RSVP_ENC_OBJECTERROR;
241 if (size < 0) {
242 return size;
245 encodeSize += size;
247 session->hdr.length = encodeSize;
248 session->hdr.class = RSVP_SESSION_CLASS;
249 size = rsvpteEncodeObjectHeader(&session->hdr, bufHdr, RSVP_OBJECT_HDRSIZE);
250 if (size < 0) {
251 return size;
254 return encodeSize;
257 int rsvpteDecodeSessionObject(rsvpSessionObject_t * session, u_char * buf, int bufSize) {
258 int decodedSize = 0;
260 size = rsvpteDecodeObjectHeader(&session->hdr, buf, bufSize);
261 if (size < 0) {
262 return size;
264 decodeSize += size;
265 bufSize -= size;
266 buf += size;
268 if (session->hdr.length > bufSize) {
269 return MPLS_DEC_BUFFTOOSMALL;
272 if (session->hdr.class != RSVP_SESSION_CLASS) {
273 return RSVP_DEC_OBJECTERROR;
276 switch(session->hdr.cType) {
277 case RSVP_SESSION_CTYPE_IPV4:
278 size = rsvpteDecodeSession4(&session->u.ipv4, buf, bufSize);
279 break;
280 case RSVP_SESSION_CTYPE_IPV6:
281 size = rsvpteDecodeSession6(&session->u.ipv6, buf, bufSize);
282 break;
283 case RSVP_SESSION_CTYPE_TUNNEL4:
284 size = rsvpteDecodeSessionTunnel4(&session->u.tunnel4, buf, bufSize);
285 break;
286 case RSVP_SESSION_CTYPE_TUNNEL6:
287 size = rsvpteDecodeSessionTunnel6(&session->u.tunnel6, buf, bufSize);
288 break;
289 default:
290 return RSVP_DEC_OBJECTERROR;
293 if (size < 0) {
294 return size;
297 return decodeSize + size;
300 int rsvpteEncodeHop4(rsvpHop4_t * hop, u_char * buf, int bufSize) {
301 rsvpHop4_t hopCopy;
302 if (RSVP_HOP4_SIZE > bufSize) {
303 return MPLS_ENC_BUFFTOOSMALL;
305 hopCopy = *hop;
307 hopCopy.hopAddr = htonl(hop->hopAddr);
308 hopCopy.logicalIfHandle = htonl(hop->logicalIfHandle);
309 memcpy(buf, &hopCopy, RSVP_HOP4_SIZE);
311 return RSVP_HOP4_SIZE;
314 int rsvpteDecodeHop4(rsvpHop4_t * hop, u_char * buf, int bufSize) {
315 if (RSVP_HOP4_SIZE > bufSize) {
316 return MPLS_DEC_BUFFTOOSMALL;
319 memcpy(hop, buf, RSVP_HOP4_SIZE);
320 hop->hopAddr = nthol(hop->hopAddr);
321 hop->logicalIfHandle = nthol(hop->logicalIfHandle);
323 return RSVP_HOP4_SIZE;
326 int rsvpteEncodeHop6(rsvpHop6_t * hop, u_char * buf, int bufSize) {
327 rsvpHop6_t hopCopy;
328 if (RSVP_HOP6_SIZE > bufSize) {
329 return MPLS_ENC_BUFFTOOSMALL;
331 hopCopy = *hop;
333 hopCopy.logicalIfHandle = htonl(hop->logicalIfHandle);
334 memcpy(buf, &hopCopy, RSVP_HOP6_SIZE);
336 return RSVP_HOP6_SIZE;
339 int rsvpteDecodeHop6(rsvpHop6_t * hop, u_char * buf, int bufSize) {
340 if (RSVP_HOP6_SIZE > bufSize) {
341 return MPLS_DEC_BUFFTOOSMALL;
344 memcpy(hop, buf, RSVP_HOP6_SIZE);
345 hop->logicalIfHandle = nthol(hop->logicalIfHandle);
347 return RSVP_HOP6_SIZE;
350 int rsvpteEncodeHopObject(rsvpHopObject_t * hop, u_char * buf, int bufSize) {
351 int encodedSize = 0;
352 char *bufHdr = buf;
353 int size;
355 if (RSVP_OBJECT_HDRSIZE > bufSize) {
356 return MPLS_ENC_BUFFTOOSMALL;
359 size = RSVP_OBJECT_HDRSIZE;
360 encodeSize += size;
361 bufSize -= size;
362 buf += size;
364 switch(hop->hdr.cType) {
365 case RSVP_HOP_CTYPE_IPV4:
366 size = rsvpteEncodeHop4(&hop->u.ipv4, buf, bufSize);
367 break;
368 case RSVP_HOP_CTYPE_IPV6:
369 size = rsvpteEncodeHop6(&hop->u.ipv6, buf, bufSize);
370 break;
371 default:
372 return RSVP_ENC_OBJECTERROR;
375 if (size < 0) {
376 return size;
379 encodeSize += size;
381 session->hdr.length = encodeSize;
382 session->hdr.class = RSVP_HOP_CLASS;
383 size = rsvpteEncodeObjectHeader(&session->hdr, bufHdr, RSVP_OBJECT_HDRSIZE); if (size < 0) {
384 return size;
387 return encodeSize;
390 int rsvpteDecodeHopObject(rsvpHopObject_t * hop, u_char * buf, int bufSize) {
391 int decodedSize = 0;
392 int size = rsvpteDecodeObjectHeader(&session->hdr, buf, bufSize);
394 if (size < 0) {
395 return size;
397 decodeSize += size;
398 bufSize -= size;
399 buf += size;
401 if (session->hdr.length > bufSize) {
402 return MPLS_DEC_BUFFTOOSMALL;
405 if (session->hdr.class != RSVP_HOP_CLASS) {
406 return RSVP_DEC_OBJECTERROR;
409 switch(session->hdr.cType) {
410 case RSVP_HOP_CTYPE_IPV4:
411 size = rsvpteDecodeHop4(&hop->u.ipv4, buf, bufSize);
412 break;
413 case RSVP_HOP_CTYPE_IPV6:
414 size = rsvpteDecodeHop4(&hop->u.ipv6, buf, bufSize);
415 break;
416 default:
417 return RSVP_DEC_OBJECTERROR;
420 if (size < 0) {
421 return size;
424 return decodeSize + size;
427 /* Time Object */
429 int rsvpteEncodeTimeObject(rsvpTimeObject_t * time, u_char * buf, int bufSize) {
430 int encodedSize = 0;
431 char *bufHdr = buf;
432 int size;
434 if (RSVP_OBJECT_HDRSIZE > bufSize) {
435 return MPLS_ENC_BUFFTOOSMALL;
438 size = RSVP_OBJECT_HDRSIZE;
439 encodeSize += size;
440 bufSize -= size;
441 buf += size;
444 u_int refresh = htonl(time->refresh);
445 if (RSVP_TIME_SIZE > bufSize) {
446 return MPLS_DEC_BUFFTOOSMALL;
448 memcpy(buf, &refresh, RSVP_TIME_SIZE);
449 size = RSVP_TIME_SIZE;
451 encodeSize += size;
453 session->hdr.length = encodeSize;
454 session->hdr.class = RSVP_TIME_CLASS;
455 session->hdr.cType = RSVP_TIME_CTYPE;
457 size = rsvpteEncodeObjectHeader(&session->hdr, bufHdr, RSVP_OBJECT_HDRSIZE); if (size < 0) {
458 return size;
461 return encodeSize;
464 int rsvpteDecodeTimeObject(rsvpTimeObject_t * time, u_char * buf, int bufSize) {
465 int decodedSize = 0;
466 int size = rsvpteDecodeObjectHeader(&session->hdr, buf, bufSize);
468 if (size < 0) {
469 return size;
471 decodeSize += size;
472 bufSize -= size;
473 buf += size;
475 if (session->hdr.length > bufSize) {
476 return MPLS_DEC_BUFFTOOSMALL;
479 if (session->hdr.class != RSVP_TIME_CLASS) {
480 return RSVP_DEC_OBJECTERROR;
483 switch(time->hdr.cType) {
484 case RSVP_TIME_CTYPE:
485 if (RSVP_TIME_SIZE > bufSize) {
486 return MPLS_DEC_BUFFTOOSMALL;
488 memcpy(&time->refresh, buf, RSVP_TIME_SIZE);
489 time->refresh = ntohl(time->refresh);
490 size = RSVP_TIME_SIZE;
491 break;
492 default:
493 return RSVP_DEC_OBJECTERROR;
496 return decodeSize + size;
499 /* Explicit Route Object */
501 int rsvpteEncodeExplicitRoute4(rsvpExplicitRoute4_t * er, u_char * buf, int bufSize) {
502 rsvpExplicitRoute4_t erCopy;
504 if (RSVP_ER4_SIZE > bufSize) {
505 return MPLS_ENC_BUFFTOOSMALL;
507 erCopy = *er;
509 erCopy.flags.mark = htons(er->flags.mark);
510 htonl_nba(erCopy.address, &erCopy.uIntAddress);
512 memcpy(buf, &erCopy, RSVP_ER4_SIZE);
514 return RSVP_ER4_SIZE;
517 int rsvpteDecodeExplicitRoute4(rsvpExplicitRoute4_t * er, u_char * buf, int bufSize) {
518 if (RSVP_ER4_SIZE > bufSize) {
519 return MPLS_DEC_BUFFTOOSMALL;
522 memcpy(er, buf, RSVP_ER4_SIZE);
523 er->flags.mark = ntohs(er->flags.mark);
524 ntohl_nba(er->address, &er->uIntAddress);
526 return RSVP_ER4_SIZE;
529 int rsvpteEncodeExplicitRoute6(rsvpExplicitRoute6_t * er, u_char * buf, int bufSize) {
530 rsvpExplicitRoute6_t erCopy;
532 if (RSVP_ER6_SIZE > bufSize) {
533 return MPLS_ENC_BUFFTOOSMALL;
535 erCopy = *er;
537 erCopy.flags.mark = htons(er->flags.mark);
539 memcpy(buf, &erCopy, RSVP_ER6_SIZE);
541 return RSVP_ER6_SIZE;
544 int rsvpteDecodeExplicitRoute6(rsvpExplicitRoute6_t * er, u_char * buf, int bufSize) {
545 if (RSVP_ER6_SIZE > bufSize) {
546 return MPLS_DEC_BUFFTOOSMALL;
549 memcpy(er, buf, RSVP_ER6_SIZE);
550 er->flags.mark = ntohs(er->flags.mark);
552 return RSVP_ER6_SIZE;
555 int rsvpteEncodeExplicitRouteAsn(rsvpExplicitRouteAsn_t * er, u_char * buf, int bufSize) {
556 rsvpExplicitRouteAsn_t erCopy;
558 if (RSVP_ERASN_SIZE > bufSize) {
559 return MPLS_ENC_BUFFTOOSMALL;
561 erCopy = *er;
563 erCopy.flags.mark = htons(er->flags.mark);
565 memcpy(buf, &erCopy, RSVP_ER6_SIZE);
567 return RSVP_ERASN_SIZE;
570 int rsvpteDecodeExplicitRouteAsn(rsvpExplicitRouteAsn_t * er, u_char * buf, int bufSize) {
571 if (RSVP_ERASN_SIZE > bufSize) {
572 return MPLS_DEC_BUFFTOOSMALL;
575 memcpy(er, buf, RSVP_ERASN_SIZE);
576 er->flags.mark = ntohs(er->flags.mark);
578 return RSVP_ERASN_SIZE;
581 int rsvpteEncodeExplicitRouteObject(rsvpExplicitRouteObject_t * er, u_char * buf, int bufSize) {
583 int encodedSize = 0;
584 char *bufHdr = buf;
585 int size;
587 if (RSVP_OBJECT_HDRSIZE > bufSize) {
588 return MPLS_ENC_BUFFTOOSMALL;
591 size = RSVP_OBJECT_HDRSIZE;
592 encodeSize += size;
593 bufSize -= size;
594 buf += size;
596 for (i = 0;i < er->eroLength;i++) {
598 switch(er->eroType[i]) {
599 case RSVP_ERO_TYPE_IPV4:
600 size = rsvpteEncodeExplicitRoute4(&er->ero[i], buf, bufSize);
601 break;
602 case RSVP_ERO_TYPE_IPV6:
603 size = rsvpteEncodeExplicitRoute6(&er->ero[i], buf, bufSize);
604 break;
605 case RSVP_ERO_TYPE_ASN:
606 size = rsvpteEncodeExplicitRouteAsn(&er->ero[i], buf, bufSize);
607 break;
608 default:
609 return RSVP_ENC_OBJECTERROR;
612 if (size < 0) {
613 return size;
616 encodeSize += size;
617 bufSize -= size;
618 buf += size;
621 session->hdr.length = encodeSize;
622 session->hdr.class = RSVP_EXPLICIT_ROUTE_CLASS;
623 session->hdr.cType = RSVP_EXPLICIT_ROUTE_CTYPE;
624 size = rsvpteEncodeObjectHeader(&session->hdr, bufHdr, RSVP_OBJECT_HDRSIZE); if (size < 0) {
625 return size;
628 return encodeSize;
631 int rsvpteDecodeExplicitRouteSubObjectHdr(rsvpExplicitRouteFlag_t * hdr, u_char * buf, int bufSize) {
632 u_short temp;
633 if (sizeof(u_short) > bufSize) {
634 return MPLS_DEC_BUFFTOOSMALL;
637 memcpy(&temp, buf, sizeof(u_short));
638 temp = ntohs(temp);
639 memcpy(hdr, &temp, sizeof(u_short));
641 return sizeof(u_short);
644 int rsvpteDecodeExplicitRouteObject(rsvpExplicitRouteObject_t * er, u_char * buf, int bufSize) {
645 rsvpExplicitRouteFlag_t erFlag;
647 int decodedSize = 0;
648 int size = rsvpteDecodeObjectHeader(&session->hdr, buf, bufSize);
650 if (size < 0) {
651 return size;
653 decodeSize += size;
654 bufSize -= size;
655 buf += size;
657 if (session->hdr.length > bufSize) {
658 return MPLS_DEC_BUFFTOOSMALL;
661 if (session->hdr.class != RSVP_EXPLICIT_ROUTE_CLASS) {
662 return RSVP_DEC_OBJECTERROR;
665 while (decodeSize < session->hdr.length) {
666 result = rsvpteDecodeExplicitRouteSubObjectHdr(&erFlag, buf, bufSize);
668 switch(erFlag.type) {
669 case RSVP_ERO_TYPE_IPV4:
670 size = rsvpteDecodeExplicitRoute4(&er->ero[i], buf, bufSize);
671 break;
672 case RSVP_ERO_TYPE_IPV6:
673 size = rsvpteDecodeExplicitRoute6(&er->ero[i], buf, bufSize);
674 break;
675 case RSVP_ERO_TYPE_ASN:
676 size = rsvpteDecodeExplicitRouteAsn(&er->ero[i], buf, bufSize);
677 break;
678 default:
679 return RSVP_DEC_OBJECTERROR;
681 er->eroType[i] = erFlag.type;
683 if (size < 0) {
684 return size;
687 decodeSize += size;
688 bufSize -= size;
689 buf += size;
690 i++;
692 er->erLength = i;
694 return decodeSize;
697 /* Label Request Object */
699 int rsvpteEncodeLabelReqGeneric(rsvpLabelReqGeneric_t * gen, u_char * buf, int bufSize) {
700 rsvpLabelReqGeneric_t genCopy;
701 if (RSVP_LABELREQ_GENERIC_SIZE > bufSize) {
702 return MPLS_ENC_BUFFTOOSMALL;
704 genCopy.reserved = htons(gen->reserved);
705 genCopy.l3pid = htons(gen->l3pid);
707 memcpy(buf, &genCopy, RSVP_LABELREQ_GENERIC_SIZE);
709 return RSVP_LABELREQ_GENERIC_SIZE;
712 int rsvpteDecodeLabelReqGeneric(rsvpLabelReqGeneric_t * gen, u_char * buf, int bufSize) {
713 if (RSVP_LABELREQ_GENERIC_SIZE > bufSize) {
714 return MPLS_DEC_BUFFTOOSMALL;
717 memcpy(er, buf, RSVP_LABELREQ_GENERIC_SIZE);
718 gen->genCopy.reserved = ntohs(gen->genCopy.reserved);
719 gen->genCopy.l3pid = ntohs(gen->genCopy.l3pid);
721 return RSVP_LABELREQ_GENERIC_SIZE;
724 int rsvpteEncodeLabelReqAtm(rsvpLabelReqAtm_t * atm, u_char * buf, int bufSize) {
725 rsvpLabelReqAtm_t atmCopy;
726 if (RSVP_LABELREQ_ATM_SIZE > bufSize) {
727 return MPLS_ENC_BUFFTOOSMALL;
729 atmCopy.reserved = htons(atm->reserved);
730 atmCopy.l3pid = htons(atm->l3pid);
732 atmCopy.minFlags.mark = htons(atm->minFlags.mark);
733 atmCopy.minVci = htons(atm->minVci);
735 atmCopy.maxFlags.mark = htons(atm->maxFlags.mark);
736 atmCopy.maxVci = htons(atm->maxVci);
738 memcpy(buf, &atmCopy, RSVP_LABELREQ_ATM_SIZE);
740 return RSVP_LABELREQ_ATM_SIZE;
743 int rsvpteDecodeLabelReqAtm(rsvpLabelReqAtm_t * atm, u_char * buf, int bufSize) {
744 if (RSVP_LABELREQ_ATM_SIZE > bufSize) {
745 return MPLS_DEC_BUFFTOOSMALL;
748 memcpy(atm, buf, RSVP_LABELREQ_ATM_SIZE);
750 atm->reserved = htons(atm->reserved);
751 atm->l3pid = htons(atm->l3pid);
753 atm->minFlags.mark = htons(atm->minFlags.mark);
754 atm->minVci = htons(atm->minVci);
756 atm->maxFlags.mark = htons(atm->maxFlags.mark);
757 atm->maxVci = htons(atm->maxVci);
759 return RSVP_LABELREQ_ATM_SIZE;
762 int rsvpteEncodeLabelReqFr(rsvpLabelReqFr_t * fr, u_char * buf, int bufSize) {
763 rsvpLabelReqFr_t frCopy;
764 if (RSVP_LABELREQ_FR_SIZE > bufSize) {
765 return MPLS_ENC_BUFFTOOSMALL;
767 frCopy.reserved = htons(fr->reserved);
768 frCopy.l3pid = htons(fr->l3pid);
770 frCopy.minFlags.mark = htons(fr->minFlags.mark);
771 frCopy.maxFlags.mark = htons(fr->maxFlags.mark);
773 memcpy(buf, &frCopy, RSVP_LABELREQ_FR_SIZE);
775 return RSVP_LABELREQ_FR_SIZE;
778 int rsvpteDecodeLabelReqFr(rsvpLabelReqFr_t * fr, u_char * buf, int bufSize) {
779 if (RSVP_LABELREQ_FR_SIZE > bufSize) {
780 return MPLS_DEC_BUFFTOOSMALL;
783 memcpy(fr, buf, RSVP_LABELREQ_FR_SIZE);
785 fr->reserved = htons(fr->reserved);
786 fr->l3pid = htons(fr->l3pid);
788 fr->minFlags.mark = htons(fr->minFlags.mark);
789 fr->maxFlags.mark = htons(fr->maxFlags.mark);
791 return RSVP_LABELREQ_FR_SIZE;
794 int rsvpteEncodeLabelRequestObject(rsvpLabelRequestObject_t * req, u_char * buf, int bufSize) {
795 int encodedSize = 0;
796 char *bufHdr = buf;
797 int size;
799 if (RSVP_OBJECT_HDRSIZE > bufSize) {
800 return MPLS_ENC_BUFFTOOSMALL;
803 size = RSVP_OBJECT_HDRSIZE;
804 encodeSize += size;
805 bufSize -= size;
806 buf += size;
808 switch(req->hdr.cType) {
809 case RSVP_LABEL_REQUEST_CTYPE_GENERIC:
810 size = rsvpteEncodeLabelReqGeneric(&req->u.generic, buf, bufSize);
811 break;
812 case RSVP_LABEL_REQUEST_CTYPE_ATM:
813 size = rsvpteEncodeLabelReqAtm(&req->u.atm, buf, bufSize);
814 break;
815 case RSVP_LABEL_REQUEST_CTYPE_FR:
816 size = rsvpteEncodeLabelReqFr(&req->u.fr, buf, bufSize);
817 break;
818 default:
819 return RSVP_DEC_OBJECTERROR;
821 if (size < 0) {
822 return size;
825 encodeSize += size;
827 req->hdr.length = encodeSize;
828 req->hdr.class = RSVP_LABEL_REQUEST_CLASS;
829 size = rsvpteEncodeObjectHeader(&req->hdr, bufHdr, RSVP_OBJECT_HDRSIZE); if (size < 0) {
830 return size;
833 return encodeSize;
836 int rsvpteDecodeLabelRequestObject(rsvpLabelRequestObject_t * req, u_char * buf, int bufSize) {
837 int decodedSize = 0;
838 int size = rsvpteDecodeObjectHeader(&req->hdr, buf, bufSize);
840 if (size < 0) {
841 return size;
843 decodeSize += size;
844 bufSize -= size;
845 buf += size;
847 if (req->hdr.length > bufSize) {
848 return MPLS_DEC_BUFFTOOSMALL;
851 if (req->hdr.class != RSVP_LABEL_REQUEST_CLASS) {
852 return RSVP_DEC_OBJECTERROR;
855 switch(req->hdr.cType) {
856 case RSVP_LABEL_REQUEST_CTYPE_GENERIC:
857 size = rsvpteDecodeLabelReqGeneric(&req->u.generic, buf, bufSize);
858 break;
859 case RSVP_LABEL_REQUEST_CTYPE_ATM:
860 size = rsvpteDecodeLabelReqAtm(&req->u.atm, buf, bufSize);
861 break;
862 case RSVP_LABEL_REQUEST_CTYPE_FR:
863 size = rsvpteDecodeLabelReqFr(&req->u.fr, buf, bufSize);
864 break;
865 default:
866 return RSVP_DEC_OBJECTERROR;
869 if (size < 0) {
870 return size;
873 return decodeSize + size;
876 /* Session Attribute Object */
878 int rsvpteEncodeSessionAttribLspTunnel(rsvpSessionAttribLspTunnel_t * lsp, u_char * buf, int bufSize) {
879 int size = RSVP_SESSION_ATTRIB_LSP_TUNNEL_BASE_SIZE + lsp->nameLen;
881 if (size > bufSize) {
882 return MPLS_ENC_BUFFTOOSMALL;
885 memcpy(buf, lsp, size);
887 return size;
890 int rsvpteDecodeSessionAttribLspTunnel(rsvpSessionAttribLspTunnel_t * lsp, u_char * buf, int bufSize) {
891 if (RSVP_SESSION_ATTRIB_LSP_TUNNEL_BASE_SIZE > bufSize) {
892 return MPLS_DEC_BUFFTOOSMALL;
895 memcpy(lsp, buf, RSVP_SESSION_ATTRIB_LSP_TUNNEL_BASE_SIZE);
896 if (lsp->nameLen > bufSize) {
897 return MPLS_DEC_BUFFTOOSMALL;
900 memcpy(lsp->name, buf, lsp->nameLen);
902 return RSVP_SESSION_ATTRIB_LSP_TUNNEL_BASE_SIZE + lsp->nameLen;
905 int rsvpteEncodeSessionAttribLspTunnelRa(rsvpSessionAttribLspTunnelRa_t * lsp, u_char * buf, int bufSize) {
906 rsvpSessionAttribLspTunnelRa_t lspCopy;
907 int size = RSVP_SESSION_ATTRIB_LSP_TUNNEL_RA_BASE_SIZE + lsp->nameLen;
909 if (size > bufSize) {
910 return MPLS_ENC_BUFFTOOSMALL;
913 lspCopy = *lsp;
914 lspCopy.excludeAny = htonl(lspCopy.excludeAny);
915 lspCopy.includeAny = htonl(lspCopy.includeAny);
916 lspCopy.includeAll = htonl(lspCopy.includeAll);
917 memcpy(buf, &lspCopy, size);
919 return size;
922 int rsvpteDecodeSessionAttribLspTunnelRa(rsvpSessionAttribLspTunnelRa_t * lsp, u_char * buf, int bufSize) {
923 if (RSVP_SESSION_ATTRIB_LSP_TUNNEL_RA_BASE_SIZE > bufSize) {
924 return MPLS_DEC_BUFFTOOSMALL;
926 memcpy(lsp, buf, RSVP_SESSION_ATTRIB_LSP_TUNNEL_RA_BASE_SIZE);
928 if (lsp->nameLen > bufSize) {
929 return MPLS_DEC_BUFFTOOSMALL;
931 memcpy(lsp->name, buf, lsp->nameLen);
933 lsp->excludeAny = ntohl(lsp->excludeAny);
934 lsp->includeAny = ntohl(lsp->includeAny);
935 lsp->includeAll = ntohl(lsp->includeAll);
937 return RSVP_SESSION_ATTRIB_LSP_TUNNEL_BASE_SIZE + lsp->nameLen;
940 int rsvpteEncodeSessionAttribObject(rsvpSessionAttibObject_t * session, u_char * buf, int bufSize) {
942 int encodedSize = 0;
943 char *bufHdr = buf;
944 int size;
946 if (RSVP_OBJECT_HDRSIZE > bufSize) {
947 return MPLS_ENC_BUFFTOOSMALL;
950 size = RSVP_OBJECT_HDRSIZE;
951 encodeSize += size;
952 bufSize -= size;
953 buf += size;
955 switch(session->hdr.cType) {
956 case RSVP_SESSION_ATTRIB_CTYPE_LSP_TUNNEL:
957 size = rsvpteEncodeSessionAttribLspTunnel(&session->u.tunnel, buf, bufSize);
958 break;
959 case RSVP_SESSION_ATTRIB_CLASS_LSP_TUNNEL_RA:
960 size = rsvpteEncodeSessionAttribLspTunnelRa(&session->u.tunnelRa, buf, bufSize);
961 break;
962 default:
963 return RSVP_DEC_OBJECTERROR;
966 if (size < 0) {
967 return size;
970 encodeSize += size;
972 session->hdr.length = encodeSize;
973 session->hdr.class = RSVP_SESSION_ATTRIB_CLASS;
974 size = rsvpteEncodeObjectHeader(&session->hdr, bufHdr, RSVP_OBJECT_HDRSIZE); if (size < 0) {
975 return size;
978 return encodeSize;
981 int rsvpteDecodeSessionAttribObject(rsvpSessionAttibObject_t * session, u_char * buf, int bufSize) {
982 int decodedSize = 0;
983 int size = rsvpteDecodeObjectHeader(&session->hdr, buf, bufSize);
985 if (size < 0) {
986 return size;
988 decodeSize += size;
989 bufSize -= size;
990 buf += size;
992 if (session->hdr.length > bufSize) {
993 return MPLS_DEC_BUFFTOOSMALL;
996 if (session->hdr.class != RSVP_SESSION_ATTRIB_CLASS) {
997 return RSVP_DEC_OBJECTERROR;
1000 switch(session->hdr.cType) {
1001 case RSVP_SESSION_ATTRIB_CTYPE_LSP_TUNNEL:
1002 size = rsvpteDecodeSessionAttribLspTunnel(&session->u.tunnel, buf, bufSize);
1003 break;
1004 case RSVP_SESSION_ATTRIB_CLASS_LSP_TUNNEL_RA:
1005 size = rsvpteDecodeSessionAttribLspTunnelRa(&session->u.tunnelRa, buf, bufSize);
1006 break;
1007 default:
1008 return RSVP_DEC_OBJECTERROR;
1010 if (size < 0) {
1011 return size;
1014 return decodeSize + size;
1017 /* Filter Spec Object */
1019 int rsvpteEncodeFilterSpec4(rsvpFilterSpec4_t * filter, u_char * buf, int bufSize) {
1020 rsvpFilterSpec4_t filterCopy;
1022 if (RSVP_FILTER_SPEC4_SIZE > bufSize) {
1023 return MPLS_ENC_BUFFTOOSMALL;
1026 filterCopy.sourceAddr = htonl(filter->sourceAddr);
1027 filterCopy.sourcePort = htons(filter->sourcePort);
1028 filterCopy.reserved = filter->reserved = 0;
1030 memcpy(buf, &filterCopy, RSVP_FILTER_SPEC4_SIZE);
1032 return RSVP_FILTER_SPEC4_SIZE;
1035 int rsvpteDecodeFilterSpec4(rsvpFilterSpec4_t * filter, u_char * buf, int bufSize) {
1036 if (RSVP_FILTER_SPEC4_SIZE > bufSize) {
1037 return MPLS_DEC_BUFFTOOSMALL;
1040 memcpy(filter, buf, RSVP_FILTER_SPEC4_SIZE);
1041 filter->sourceAddr = ntohl(filter->sourceAddr);
1042 filter->sourcePort = ntohs(filter->sourcePort);
1043 filter->reserved = 0;
1045 return RSVP_FILTER_SPEC4_SIZE;
1048 int rsvpteEncodeFilterSpec6(rsvpFilterSpec6_t * filter, u_char * buf, int bufSize) {
1049 rsvpFilterSpec6_t filterCopy;
1051 if (RSVP_FILTER_SPEC6_SIZE > bufSize) {
1052 return MPLS_ENC_BUFFTOOSMALL;
1055 memcpy(filterCopy.sourceAddr, filter->sourceAddr, RSVP_IPV6_ADDR_LEN);
1056 filterCopy.sourcePort = htons(filter->sourcePort);
1057 filterCopy.reserved = filter->reserved = 0;
1059 memcpy(buf, &filterCopy, RSVP_FILTER_SPEC6_SIZE);
1061 return RSVP_FILTER_SPEC6_SIZE;
1064 int rsvpteDecodeFilterSpec6(rsvpFilterSpec6_t * filter, u_char * buf, int bufSize) {
1065 if (RSVP_FILTER_SPEC6_SIZE > bufSize) {
1066 return MPLS_DEC_BUFFTOOSMALL;
1069 memcpy(filter, buf, RSVP_FILTER_SPEC6_SIZE);
1070 filter->sourcePort = ntohs(filter->sourcePort);
1071 filter->reserved = 0;
1073 return RSVP_FILTER_SPEC6_SIZE;
1076 int rsvpteEncodeFilterSpecFlow(rsvpFilterSpecFlow_t * filter, u_char * buf, int bufSize) {
1077 rsvpFilterSpecFlow_t filterCopy;
1079 if (RSVP_FILTER_SPEC_FLOW_SIZE > bufSize) {
1080 return MPLS_ENC_BUFFTOOSMALL;
1083 memcpy(filterCopy.sourceAddr, filter->sourceAddr, RSVP_IPV6_ADDR_LEN);
1084 filterCopy.flag.mark = htonl(filter->flag.mark);
1086 memcpy(buf, &filterCopy, RSVP_FILTER_SPEC_FLOW_SIZE);
1088 return RSVP_FILTER_SPEC_FLOW_SIZE;
1091 int rsvpteDecodeFilterSpecFlow(rsvpFilterSpecFlow_t * filter, u_char * buf, int bufSize) {
1092 if (RSVP_FILTER_SPEC_FLOW_SIZE > bufSize) {
1093 return MPLS_DEC_BUFFTOOSMALL;
1096 memcpy(filter, buf, RSVP_FILTER_SPEC_FLOW_SIZE);
1097 filter->flag.mark = ntohl(filter->flag.mark);
1099 return RSVP_FILTER_SPEC_FLOW_SIZE;
1102 int rsvpteEncodeFilterSpecObject(rsvpFilterSpec_t * filter, u_char * buf, int bufSize) {
1104 int encodedSize = 0;
1105 char *bufHdr = buf;
1106 int size;
1108 if (RSVP_OBJECT_HDRSIZE > bufSize) {
1109 return MPLS_ENC_BUFFTOOSMALL;
1112 size = RSVP_OBJECT_HDRSIZE;
1113 encodeSize += size;
1114 bufSize -= size;
1115 buf += size;
1117 switch(filter->hdr.cType) {
1118 case RSVP_FILTER_SPEC_CTYPE_IPV4:
1119 size = rsvpteEncodeFilterSpec4(&filter->u.ipv4, buf, bufSize);
1120 break;
1121 case RSVP_FILTER_SPEC_CTYPE_IPV6:
1122 size = rsvpteEncodeFilterSpec6(&filter->u.ipv6, buf, bufSize);
1123 break;
1124 case RSVP_FILTER_SPEC_CTYPE_FLOW:
1125 size = rsvpteEncodeFilterSpecFlow(&filter->u.flow, buf, bufSize);
1126 break;
1127 default:
1128 return RSVP_DEC_OBJECTERROR;
1130 if (size < 0) {
1131 return size;
1134 encodeSize += size;
1136 filter->hdr.length = encodeSize;
1137 filter->hdr.class = RSVP_FILTER_SPEC_CLASS;
1138 size = rsvpteEncodeObjectHeader(&filter->hdr, bufHdr, RSVP_OBJECT_HDRSIZE); if (size < 0) {
1139 return size;
1142 return encodeSize;
1145 int rsvpteDecodeFilterSpecObject(rsvpFilterSpec_t * filter, u_char * buf, int bufSize) {
1146 int decodedSize = 0;
1147 int size = rsvpteDecodeObjectHeader(&filter->hdr, buf, bufSize);
1149 if (size < 0) {
1150 return size;
1152 decodeSize += size;
1153 bufSize -= size;
1154 buf += size;
1156 if (filter->hdr.length > bufSize) {
1157 return MPLS_DEC_BUFFTOOSMALL;
1160 if (filter->hdr.class != RSVP_FILTER_SPEC_CLASS) {
1161 return RSVP_DEC_OBJECTERROR;
1164 switch(filter->hdr.cType) {
1165 case RSVP_FILTER_SPEC_CTYPE_IPV4:
1166 size = rsvpteDecodeFilterSpec4(&filter->u.ipv4, buf, bufSize);
1167 break;
1168 case RSVP_FILTER_SPEC_CTYPE_IPV6:
1169 size = rsvpteDecodeFilterSpec6(&filter->u.ipv6, buf, bufSize);
1170 break;
1171 case RSVP_FILTER_SPEC_CTYPE_FLOW:
1172 size = rsvpteDecodeFilterSpecFlow(&filter->u.flow, buf, bufSize);
1173 break;
1174 default:
1175 return RSVP_DEC_OBJECTERROR;
1177 if (size < 0) {
1178 return size;
1181 return decodeSize + size;
1184 /* Sender Template Object */
1186 int rsvpteEncodeSenderTemplateTunnel4(rsvpSenderTemplateTunnel4_t * sender, u_char * buf, int bufSize) {
1187 rsvpSenderTemplateTunnel4_t senderCopy;
1189 if (RSVP_SENDER_TEMPLATE_TUNNEL4_SIZE > bufSize) {
1190 return MPLS_ENC_BUFFTOOSMALL;
1193 senderCopy.sender = htonl(sender->sender);
1194 senderCopy.reserved = 0;
1195 senderCopy.lspId = htons(sender->lspId);
1197 memcpy(buf, &senderCopy, RSVP_SENDER_TEMPLATE_TUNNEL4_SIZE);
1199 return RSVP_SENDER_TEMPLATE_TUNNEL4_SIZE;
1202 int rsvpteDecodeSenderTemplateTunnel4(rsvpSenderTemplateTunnel4_t * sender, u_char * buf, int bufSize) {
1203 if (RSVP_SENDER_TEMPLATE_TUNNEL4_SIZE > bufSize) {
1204 return MPLS_DEC_BUFFTOOSMALL;
1207 memcpy(sender, buf, RSVP_SENDER_TEMPLATE_TUNNEL4_SIZE);
1208 sender->sender = ntohl(sender->sender);
1209 sender->reserved = 0;
1210 sender->lspId = ntohs(sender->lspId);
1212 return RSVP_SENDER_TEMPLATE_TUNNEL4_SIZE;
1215 int rsvpteEncodeSenderTemplateTunnel6(rsvpSenderTemplateTunnel4 * sender, u_char * buf, int bufSize) {
1216 rsvpSenderTemplateTunnel6_t senderCopy;
1218 if (RSVP_SENDER_TEMPLATE_TUNNEL6_SIZE > bufSize) {
1219 return MPLS_ENC_BUFFTOOSMALL;
1222 memcpy(senderCopy.sender, sender->sender, RSVP_IPV6_ADDR_LEN);
1223 senderCopy.reserved = 0;
1224 senderCopy.lspId = htons(sender->lspId);
1226 memcpy(buf, &senderCopy, RSVP_SENDER_TEMPLATE_TUNNEL6_SIZE);
1228 return RSVP_SENDER_TEMPLATE_TUNNEL6_SIZE;
1231 int rsvpteDecodeSenderTemplateTunnel6(rsvpFilterSpecFlow_t * sender, u_char * buf, int bufSize) {
1232 if (RSVP_SENDER_TEMPLATE_TUNNEL6_SIZE > bufSize) {
1233 return MPLS_DEC_BUFFTOOSMALL;
1236 memcpy(sender, buf, RSVP_SENDER_TEMPLATE_TUNNEL6_SIZE);
1237 sender->lspId = ntohs(sender->lspId);
1239 return RSVP_SENDER_TEMPLATE_TUNNEL6_SIZE;
1242 int rsvpteEncodeSenderTemplateObject(rsvpSenderTemplate_t * sender, u_char * buf, int bufSize) {
1243 int encodedSize = 0;
1244 char *bufHdr = buf;
1245 int size;
1247 if (RSVP_OBJECT_HDRSIZE > bufSize) {
1248 return MPLS_ENC_BUFFTOOSMALL;
1251 size = RSVP_OBJECT_HDRSIZE;
1252 encodeSize += size;
1253 bufSize -= size;
1254 buf += size;
1256 switch(sender->hdr.cType) {
1257 case RSVP_SENDER_TEMPLATE_CTYPE_IPV4:
1258 size = rsvpteEncodeSenderTemplate4(&sender->u.ipv4, buf, bufSize);
1259 break;
1260 case RSVP_SENDER_TEMPLATE_CTYPE_IPV6:
1261 size = rsvpteEncodeSenderTemplate6(&sender->u.ipv6, buf, bufSize);
1262 break;
1263 case RSVP_SENDER_TEMPLATE_CTYPE_FLOW:
1264 size = rsvpteEncodeSenderTemplateFlow(&sender->u.flow, buf, bufSize);
1265 break;
1266 case RSVP_SENDER_TEMPLATE_CTYPE_TUNNEL4:
1267 size = rsvpteEncodeSenderTemplateTunnel4(&sender->u.tunnel4, buf, bufSize);
1268 break;
1269 case RSVP_SENDER_TEMPLATE_CTYPE_TUNNEL6:
1270 size = rsvpteEncodeSenderTemplateTunnel6(&sender->u.tunnel6, buf, bufSize);
1271 break;
1272 default:
1273 return RSVP_DEC_OBJECTERROR;
1275 if (size < 0) {
1276 return size;
1279 encodeSize += size;
1281 sender->hdr.length = encodeSize;
1282 sender->hdr.class = RSVP_SENDER_TEMPLATE_CLASS;
1283 size = rsvpteEncodeObjectHeader(&sender->hdr, bufHdr, RSVP_OBJECT_HDRSIZE); if (size < 0) {
1284 return size;
1287 return encodeSize;
1290 int rsvpteDecodeSenderTemplateObject(rsvpSenderTemplate_t * sender, u_char * buf, int bufSize) {
1291 int decodedSize = 0;
1292 int size = rsvpteDecodeObjectHeader(&sender->hdr, buf, bufSize);
1294 if (size < 0) {
1295 return size;
1297 decodeSize += size;
1298 bufSize -= size;
1299 buf += size;
1301 if (sender->hdr.length > bufSize) {
1302 return MPLS_DEC_BUFFTOOSMALL;
1305 if (sender->hdr.class != RSVP_SENDER_TEMPLATE_CLASS) {
1306 return RSVP_DEC_OBJECTERROR;
1309 switch(sender->hdr.cType) {
1310 case RSVP_SENDER_TEMPLATE_CTYPE_IPV4:
1311 size = rsvpteDecodeSenderTemplate4(&sender->u.ipv4, buf, bufSize);
1312 break;
1313 case RSVP_SENDER_TEMPLATE_CTYPE_IPV6:
1314 size = rsvpteDecodeSenderTemplate6(&sender->u.ipv6, buf, bufSize);
1315 break;
1316 case RSVP_SENDER_TEMPLATE_CTYPE_FLOW:
1317 size = rsvpteDecodeSenderTemplateFlow(&sender->u.flow, buf, bufSize);
1318 break;
1319 case RSVP_SENDER_TEMPLATE_CTYPE_TUNNEL4:
1320 size = rsvpteDecodeSenderTemplateTunnel4(&sender->u.tunnel4, buf, bufSize);
1321 break;
1322 case RSVP_SENDER_TEMPLATE_CTYPE_TUNNEL6:
1323 size = rsvpteDecodeSenderTemplateTunnel6(&sender->u.tunnel6, buf, bufSize);
1324 break;
1325 default:
1326 return RSVP_DEC_OBJECTERROR;
1328 if (size < 0) {
1329 return size;
1332 return decodeSize + size;
1335 /* Record Route Object */
1337 int rsvpteEncodeRecordRoute4(rsvpRecordRoute4_t * rr, u_char * buf, int bufSize) {
1338 rsvpRecordRoute4_t rrCopy;
1340 if (RSVP_RECORD_ROUTE4_SIZE > bufSize) {
1341 return MPLS_ENC_BUFFTOOSMALL;
1344 rrCopy = *rr;
1345 rrCopy.type = RSVP_RECORD_ROUTE_TYPE_IPV4;
1346 rrCopy.length = RSVP_RECORD_ROUTE4_SIZE;
1347 htonl_nba(&rrCopy.addressMsb, NULL);
1349 memcpy(buf, &rrCopy, RSVP_RECORD_ROUTE4_SIZE);
1351 return RSVP_RECORD_ROUTE4_SIZE;
1354 int rsvpteDecodeRecordRoute4(rsvpRecordRoute4_t * sender, u_char * buf, int bufSize) {
1355 if (RSVP_RECORD_ROUTE4_SIZE > bufSize) {
1356 return MPLS_DEC_BUFFTOOSMALL;
1359 memcpy(rr, buf, RSVP_RECORD_ROUTE4_SIZE);
1360 ntohl_nba(rr->addressMsb, NULL);
1362 return RSVP_RECORD_ROUTE4_SIZE;
1365 int rsvpteEncodeRecordRoute6(rsvpRecordRoute6_t * rr, u_char * buf, int bufSize) {
1366 rsvpRecordRoute6_t rrCopy;
1368 if (RSVP_RECORD_ROUTE6_SIZE > bufSize) {
1369 return MPLS_ENC_BUFFTOOSMALL;
1372 rrCopy = *rr;
1373 rrCopy.type = RSVP_RECORD_ROUTE_TYPE_IPV6;
1374 rrCopy.length = RSVP_RECORD_ROUTE6_SIZE;
1376 memcpy(buf, &rrCopy, RSVP_RECORD_ROUTE6_SIZE);
1378 return RSVP_RECORD_ROUTE6_SIZE;
1381 int rsvpteDecodeRecordRoute6(rsvpRecordRoute6_t * sender, u_char * buf, int bufSize) {
1382 if (RSVP_RECORD_ROUTE6_SIZE > bufSize) {
1383 return MPLS_DEC_BUFFTOOSMALL;
1386 memcpy(rr, buf, RSVP_RECORD_ROUTE6_SIZE);
1388 return RSVP_RECORD_ROUTE6_SIZE;
1391 int rsvpteEncodeRecordRouteLabel(rsvpRecordRouteLabel_t * rr, u_char * buf, int bufSize) {
1392 rsvpRecordRouteLabel_t rrCopy;
1393 int size;
1395 if (4 > bufSize) {
1396 return MPLS_ENC_BUFFTOOSMALL;
1399 if ((size = rsvpteEncodeLabelObject(&rr->label, buf + 4, bufSize - 4)) < 0) {
1400 return size;
1403 rrCopy = *rr;
1404 rrCopy.type = RSVP_RECORD_ROUTE_TYPE_LABEL;
1405 rrCopy.length = 4 + size;
1406 rrCopy.cType = rr->label.hdr.cType;
1408 memcpy(buf, &rrCopy, 4);
1410 return 4 + size;
1413 int rsvpteDecodeRecordRouteLabel(rsvpRecordRouteLabel_t * sender, u_char * buf, int bufSize) {
1414 int size;
1415 if (4 > bufSize) {
1416 return MPLS_DEC_BUFFTOOSMALL;
1419 memcpy(rr, buf, 4);
1420 size = rsvpteDecodeLabelObject(&rr->label, buf + 4, bufSize - 4;
1422 return 4 + size;
1425 int rsvpteEncodeRecordRouteObject(rsvpRecordRouteObject_t * rr, char * bug, int bufSize) {
1426 int encodedSize = 0;
1427 char *bufHdr = buf;
1428 int size;
1429 in i;
1431 if (RSVP_OBJECT_HDRSIZE > bufSize) {
1432 return MPLS_ENC_BUFFTOOSMALL;
1435 size = RSVP_OBJECT_HDRSIZE;
1436 encodeSize += size;
1437 bufSize -= size;
1438 buf += size;
1440 for (i = 0, i < = rr->rrLen, i++) {
1441 switch(rr->rrType[i]) {
1442 case RSVP_RECORD_ROUTE_TYPE_IPV4:
1443 size = rsvpteEncodeRecordRoute4(&rr->rr[i].ipv4, buf, bufSize);
1444 break;
1445 case RSVP_RECORD_ROUTE_TYPE_IPV6:
1446 size = rsvpteEncodeRecordRoute6(&rr->rr[i].ipv6, buf, bufSize);
1447 break;
1448 case RSVP_RECORD_ROUTE_TYPE_LABEL:
1449 size = rsvpteEncodeRecordRouteLabel(&rr->rr[i].label, buf, bufSize);
1450 break;
1451 default:
1452 return RSVP_ENC_OBJECTERROR;
1454 if (size < 0) {
1455 return size;
1457 encodeSize += size;
1458 bufSize -= size;
1459 buf += size;
1462 rr->hdr.length = encodeSize;
1463 rr->hdr.class = RSVP_RECORD_ROUTE_CLASS;
1464 size = rsvpteEncodeObjectHeader(&rr->hdr, bufHdr, RSVP_OBJECT_HDRSIZE); if (size < 0) {
1465 return size;
1468 return encodeSize;
1471 int rsvpteDecodeRecordRouteObject(rsvpRecordRouteObject_t * rr, char * bug, int bufSize) {
1472 int decodedSize = 0;
1473 int size = rsvpteDecodeObjectHeader(&rr->hdr, buf, bufSize);
1474 int i;
1476 if (size < 0) {
1477 return size;
1479 decodeSize += size;
1480 bufSize -= size;
1481 buf += size;
1483 if (rr->hdr.length > bufSize) {
1484 return MPLS_DEC_BUFFTOOSMALL;
1487 if (rr->hdr.class != RSVP_RECORD_ROUTE_CLASS) {
1488 return RSVP_DEC_OBJECTERROR;
1491 while (decodeSize < rr->hdr.length) {
1492 switch(buf[0]) {
1493 case RSVP_RECORD_ROUTE_TYPE_IPV4:
1494 size = rsvpteDecodeRecordRoute4(&rr->rr[i].ipv4, buf, bufSize);
1495 break;
1496 case RSVP_RECORD_ROUTE_TYPE_IPV6:
1497 size = rsvpteDecodeRecordRoute6(&rr->rr[i].ipv6, buf, bufSize);
1498 break;
1499 case RSVP_RECORD_ROUTE_TYPE_LABEL:
1500 size = rsvpteDecodeRecordRouteLabel(&rr->rr[i].label, buf, bufSize);
1501 break;
1502 default:
1503 return RSVP_DEC_OBJECTERROR;
1506 if (size < 0) {
1507 return RSVP_DEC_OBJECTERROR;
1510 decodeSize += size;
1511 bufSize -= size;
1512 buf += size;
1513 i++;
1515 rr->rrLen = i;
1517 return decodeSize;
1520 /* Sender TSpec Object */
1522 int rsvpteEncodeSenderTSpectObject(rsvpSenderTSpecObject_t * sender, char * bug, int bufSize) {
1524 int encodedSize = 0;
1525 char *bufHdr = buf;
1526 int size;
1528 if (RSVP_OBJECT_HDRSIZE > bufSize) {
1529 return MPLS_ENC_BUFFTOOSMALL;
1532 size = RSVP_OBJECT_HDRSIZE;
1533 encodeSize += size;
1534 bufSize -= size;
1535 buf += size;
1537 /* need TSpec Definition */
1539 if (size < 0) {
1540 return size;
1543 encodeSize += size;
1545 sender->hdr.length = encodeSize;
1546 sender->hdr.class = RSVP_SENDER_TSPEC_CLASS;
1547 size = rsvpteEncodeObjectHeader(&sender->hdr, bufHdr, RSVP_OBJECT_HDRSIZE); if (size < 0) {
1548 return size;
1551 return encodeSize;
1554 int rsvpteDecodeSenderTSpecObject(rsvpSenderTSpecObject_t * req, char * bug, int bufSize) {
1556 int decodedSize = 0;
1557 int size = rsvpteDecodeObjectHeader(&sender->hdr, buf, bufSize);
1559 if (size < 0) {
1560 return size;
1562 decodeSize += size;
1563 bufSize -= size;
1564 buf += size;
1566 if (sender->hdr.length > bufSize) {
1567 return MPLS_DEC_BUFFTOOSMALL;
1570 if (sender->hdr.class != RSVP_SENDER_TSPEC_CLASS) {
1571 return RSVP_DEC_OBJECTERROR;
1573 /* need TSpec definitiion */
1575 if (size < 0) {
1576 return size;
1579 return decodeSize + size;