1 #include "rsvpte_struct.h"
3 inline void htonl_nba(u_char
* buf
, u_int
* extra
) {
5 memcpy(&temp
, buf
, sizeof(u_int
));
7 memcpy(buf
, &temp
, sizeof(u_int
));
13 inline void ntohl_nba(u_char
* buf
, u_int
* extra
) {
15 memcpy(&temp
, buf
, sizeof(u_int
));
17 memcpy(buf
, &temp
, sizeof(u_int
));
23 inline void htons_nba(u_char
* buf
, u_short
* extra
) {
25 memcpy(&temp
, buf
, sizeof(u_short
));
27 memcpy(buf
, &temp
, sizeof(u_short
));
33 inline void ntohs_nba(u_char
* buf
, u_short
* extra
) {
35 memcpy(&temp
, buf
, sizeof(u_short
));
37 memcpy(buf
, &temp
, sizeof(u_short
));
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
;
53 headerCopy
.checksum
= htons(header
->checksum
);
54 headerCopy
.length
= htons(header
->length
);
56 memcpy(buf
, &headerCopy
, 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
;
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
;
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
;
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
) {
215 if (RSVP_OBJECT_HDRSIZE
> bufSize
) {
216 return MPLS_ENC_BUFFTOOSMALL
;
219 size
= RSVP_OBJECT_HDRSIZE
;
224 switch(session
->hdr
.cType
) {
225 case RSVP_SESSION_CTYPE_IPV4
:
226 size
= rsvpteEncodeSession4(&session
->u
.ipv4
, buf
, bufSize
);
228 case RSVP_SESSION_CTYPE_IPV6
:
229 size
= rsvpteEncodeSession6(&session
->u
.ipv6
, buf
, bufSize
);
231 case RSVP_SESSION_CTYPE_TUNNEL4
:
232 size
= rsvpteEncodeSessionTunnel4(&session
->u
.tunnel4
, buf
, bufSize
);
234 case RSVP_SESSION_CTYPE_TUNNEL6
:
235 size
= rsvpteEncodeSessionTunnel6(&session
->u
.tunnel6
, buf
, bufSize
);
238 return RSVP_ENC_OBJECTERROR
;
247 session
->hdr
.length
= encodeSize
;
248 session
->hdr
.class = RSVP_SESSION_CLASS
;
249 size
= rsvpteEncodeObjectHeader(&session
->hdr
, bufHdr
, RSVP_OBJECT_HDRSIZE
);
257 int rsvpteDecodeSessionObject(rsvpSessionObject_t
* session
, u_char
* buf
, int bufSize
) {
260 size
= rsvpteDecodeObjectHeader(&session
->hdr
, buf
, bufSize
);
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
);
280 case RSVP_SESSION_CTYPE_IPV6
:
281 size
= rsvpteDecodeSession6(&session
->u
.ipv6
, buf
, bufSize
);
283 case RSVP_SESSION_CTYPE_TUNNEL4
:
284 size
= rsvpteDecodeSessionTunnel4(&session
->u
.tunnel4
, buf
, bufSize
);
286 case RSVP_SESSION_CTYPE_TUNNEL6
:
287 size
= rsvpteDecodeSessionTunnel6(&session
->u
.tunnel6
, buf
, bufSize
);
290 return RSVP_DEC_OBJECTERROR
;
297 return decodeSize
+ size
;
300 int rsvpteEncodeHop4(rsvpHop4_t
* hop
, u_char
* buf
, int bufSize
) {
302 if (RSVP_HOP4_SIZE
> bufSize
) {
303 return MPLS_ENC_BUFFTOOSMALL
;
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
) {
328 if (RSVP_HOP6_SIZE
> bufSize
) {
329 return MPLS_ENC_BUFFTOOSMALL
;
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
) {
355 if (RSVP_OBJECT_HDRSIZE
> bufSize
) {
356 return MPLS_ENC_BUFFTOOSMALL
;
359 size
= RSVP_OBJECT_HDRSIZE
;
364 switch(hop
->hdr
.cType
) {
365 case RSVP_HOP_CTYPE_IPV4
:
366 size
= rsvpteEncodeHop4(&hop
->u
.ipv4
, buf
, bufSize
);
368 case RSVP_HOP_CTYPE_IPV6
:
369 size
= rsvpteEncodeHop6(&hop
->u
.ipv6
, buf
, bufSize
);
372 return RSVP_ENC_OBJECTERROR
;
381 session
->hdr
.length
= encodeSize
;
382 session
->hdr
.class = RSVP_HOP_CLASS
;
383 size
= rsvpteEncodeObjectHeader(&session
->hdr
, bufHdr
, RSVP_OBJECT_HDRSIZE
); if (size
< 0) {
390 int rsvpteDecodeHopObject(rsvpHopObject_t
* hop
, u_char
* buf
, int bufSize
) {
392 int size
= rsvpteDecodeObjectHeader(&session
->hdr
, buf
, bufSize
);
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
);
413 case RSVP_HOP_CTYPE_IPV6
:
414 size
= rsvpteDecodeHop4(&hop
->u
.ipv6
, buf
, bufSize
);
417 return RSVP_DEC_OBJECTERROR
;
424 return decodeSize
+ size
;
429 int rsvpteEncodeTimeObject(rsvpTimeObject_t
* time
, u_char
* buf
, int bufSize
) {
434 if (RSVP_OBJECT_HDRSIZE
> bufSize
) {
435 return MPLS_ENC_BUFFTOOSMALL
;
438 size
= RSVP_OBJECT_HDRSIZE
;
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
;
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) {
464 int rsvpteDecodeTimeObject(rsvpTimeObject_t
* time
, u_char
* buf
, int bufSize
) {
466 int size
= rsvpteDecodeObjectHeader(&session
->hdr
, buf
, bufSize
);
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
;
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
;
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
;
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
;
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
) {
587 if (RSVP_OBJECT_HDRSIZE
> bufSize
) {
588 return MPLS_ENC_BUFFTOOSMALL
;
591 size
= RSVP_OBJECT_HDRSIZE
;
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
);
602 case RSVP_ERO_TYPE_IPV6
:
603 size
= rsvpteEncodeExplicitRoute6(&er
->ero
[i
], buf
, bufSize
);
605 case RSVP_ERO_TYPE_ASN
:
606 size
= rsvpteEncodeExplicitRouteAsn(&er
->ero
[i
], buf
, bufSize
);
609 return RSVP_ENC_OBJECTERROR
;
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) {
631 int rsvpteDecodeExplicitRouteSubObjectHdr(rsvpExplicitRouteFlag_t
* hdr
, u_char
* buf
, int bufSize
) {
633 if (sizeof(u_short
) > bufSize
) {
634 return MPLS_DEC_BUFFTOOSMALL
;
637 memcpy(&temp
, buf
, sizeof(u_short
));
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
;
648 int size
= rsvpteDecodeObjectHeader(&session
->hdr
, buf
, bufSize
);
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
);
672 case RSVP_ERO_TYPE_IPV6
:
673 size
= rsvpteDecodeExplicitRoute6(&er
->ero
[i
], buf
, bufSize
);
675 case RSVP_ERO_TYPE_ASN
:
676 size
= rsvpteDecodeExplicitRouteAsn(&er
->ero
[i
], buf
, bufSize
);
679 return RSVP_DEC_OBJECTERROR
;
681 er
->eroType
[i
] = erFlag
.type
;
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
) {
799 if (RSVP_OBJECT_HDRSIZE
> bufSize
) {
800 return MPLS_ENC_BUFFTOOSMALL
;
803 size
= RSVP_OBJECT_HDRSIZE
;
808 switch(req
->hdr
.cType
) {
809 case RSVP_LABEL_REQUEST_CTYPE_GENERIC
:
810 size
= rsvpteEncodeLabelReqGeneric(&req
->u
.generic
, buf
, bufSize
);
812 case RSVP_LABEL_REQUEST_CTYPE_ATM
:
813 size
= rsvpteEncodeLabelReqAtm(&req
->u
.atm
, buf
, bufSize
);
815 case RSVP_LABEL_REQUEST_CTYPE_FR
:
816 size
= rsvpteEncodeLabelReqFr(&req
->u
.fr
, buf
, bufSize
);
819 return RSVP_DEC_OBJECTERROR
;
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) {
836 int rsvpteDecodeLabelRequestObject(rsvpLabelRequestObject_t
* req
, u_char
* buf
, int bufSize
) {
838 int size
= rsvpteDecodeObjectHeader(&req
->hdr
, buf
, bufSize
);
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
);
859 case RSVP_LABEL_REQUEST_CTYPE_ATM
:
860 size
= rsvpteDecodeLabelReqAtm(&req
->u
.atm
, buf
, bufSize
);
862 case RSVP_LABEL_REQUEST_CTYPE_FR
:
863 size
= rsvpteDecodeLabelReqFr(&req
->u
.fr
, buf
, bufSize
);
866 return RSVP_DEC_OBJECTERROR
;
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
);
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
;
914 lspCopy
.excludeAny
= htonl(lspCopy
.excludeAny
);
915 lspCopy
.includeAny
= htonl(lspCopy
.includeAny
);
916 lspCopy
.includeAll
= htonl(lspCopy
.includeAll
);
917 memcpy(buf
, &lspCopy
, 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
) {
946 if (RSVP_OBJECT_HDRSIZE
> bufSize
) {
947 return MPLS_ENC_BUFFTOOSMALL
;
950 size
= RSVP_OBJECT_HDRSIZE
;
955 switch(session
->hdr
.cType
) {
956 case RSVP_SESSION_ATTRIB_CTYPE_LSP_TUNNEL
:
957 size
= rsvpteEncodeSessionAttribLspTunnel(&session
->u
.tunnel
, buf
, bufSize
);
959 case RSVP_SESSION_ATTRIB_CLASS_LSP_TUNNEL_RA
:
960 size
= rsvpteEncodeSessionAttribLspTunnelRa(&session
->u
.tunnelRa
, buf
, bufSize
);
963 return RSVP_DEC_OBJECTERROR
;
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) {
981 int rsvpteDecodeSessionAttribObject(rsvpSessionAttibObject_t
* session
, u_char
* buf
, int bufSize
) {
983 int size
= rsvpteDecodeObjectHeader(&session
->hdr
, buf
, bufSize
);
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
);
1004 case RSVP_SESSION_ATTRIB_CLASS_LSP_TUNNEL_RA
:
1005 size
= rsvpteDecodeSessionAttribLspTunnelRa(&session
->u
.tunnelRa
, buf
, bufSize
);
1008 return RSVP_DEC_OBJECTERROR
;
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;
1108 if (RSVP_OBJECT_HDRSIZE
> bufSize
) {
1109 return MPLS_ENC_BUFFTOOSMALL
;
1112 size
= RSVP_OBJECT_HDRSIZE
;
1117 switch(filter
->hdr
.cType
) {
1118 case RSVP_FILTER_SPEC_CTYPE_IPV4
:
1119 size
= rsvpteEncodeFilterSpec4(&filter
->u
.ipv4
, buf
, bufSize
);
1121 case RSVP_FILTER_SPEC_CTYPE_IPV6
:
1122 size
= rsvpteEncodeFilterSpec6(&filter
->u
.ipv6
, buf
, bufSize
);
1124 case RSVP_FILTER_SPEC_CTYPE_FLOW
:
1125 size
= rsvpteEncodeFilterSpecFlow(&filter
->u
.flow
, buf
, bufSize
);
1128 return RSVP_DEC_OBJECTERROR
;
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) {
1145 int rsvpteDecodeFilterSpecObject(rsvpFilterSpec_t
* filter
, u_char
* buf
, int bufSize
) {
1146 int decodedSize
= 0;
1147 int size
= rsvpteDecodeObjectHeader(&filter
->hdr
, buf
, bufSize
);
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
);
1168 case RSVP_FILTER_SPEC_CTYPE_IPV6
:
1169 size
= rsvpteDecodeFilterSpec6(&filter
->u
.ipv6
, buf
, bufSize
);
1171 case RSVP_FILTER_SPEC_CTYPE_FLOW
:
1172 size
= rsvpteDecodeFilterSpecFlow(&filter
->u
.flow
, buf
, bufSize
);
1175 return RSVP_DEC_OBJECTERROR
;
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;
1247 if (RSVP_OBJECT_HDRSIZE
> bufSize
) {
1248 return MPLS_ENC_BUFFTOOSMALL
;
1251 size
= RSVP_OBJECT_HDRSIZE
;
1256 switch(sender
->hdr
.cType
) {
1257 case RSVP_SENDER_TEMPLATE_CTYPE_IPV4
:
1258 size
= rsvpteEncodeSenderTemplate4(&sender
->u
.ipv4
, buf
, bufSize
);
1260 case RSVP_SENDER_TEMPLATE_CTYPE_IPV6
:
1261 size
= rsvpteEncodeSenderTemplate6(&sender
->u
.ipv6
, buf
, bufSize
);
1263 case RSVP_SENDER_TEMPLATE_CTYPE_FLOW
:
1264 size
= rsvpteEncodeSenderTemplateFlow(&sender
->u
.flow
, buf
, bufSize
);
1266 case RSVP_SENDER_TEMPLATE_CTYPE_TUNNEL4
:
1267 size
= rsvpteEncodeSenderTemplateTunnel4(&sender
->u
.tunnel4
, buf
, bufSize
);
1269 case RSVP_SENDER_TEMPLATE_CTYPE_TUNNEL6
:
1270 size
= rsvpteEncodeSenderTemplateTunnel6(&sender
->u
.tunnel6
, buf
, bufSize
);
1273 return RSVP_DEC_OBJECTERROR
;
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) {
1290 int rsvpteDecodeSenderTemplateObject(rsvpSenderTemplate_t
* sender
, u_char
* buf
, int bufSize
) {
1291 int decodedSize
= 0;
1292 int size
= rsvpteDecodeObjectHeader(&sender
->hdr
, buf
, bufSize
);
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
);
1313 case RSVP_SENDER_TEMPLATE_CTYPE_IPV6
:
1314 size
= rsvpteDecodeSenderTemplate6(&sender
->u
.ipv6
, buf
, bufSize
);
1316 case RSVP_SENDER_TEMPLATE_CTYPE_FLOW
:
1317 size
= rsvpteDecodeSenderTemplateFlow(&sender
->u
.flow
, buf
, bufSize
);
1319 case RSVP_SENDER_TEMPLATE_CTYPE_TUNNEL4
:
1320 size
= rsvpteDecodeSenderTemplateTunnel4(&sender
->u
.tunnel4
, buf
, bufSize
);
1322 case RSVP_SENDER_TEMPLATE_CTYPE_TUNNEL6
:
1323 size
= rsvpteDecodeSenderTemplateTunnel6(&sender
->u
.tunnel6
, buf
, bufSize
);
1326 return RSVP_DEC_OBJECTERROR
;
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
;
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
;
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
;
1396 return MPLS_ENC_BUFFTOOSMALL
;
1399 if ((size
= rsvpteEncodeLabelObject(&rr
->label
, buf
+ 4, bufSize
- 4)) < 0) {
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);
1413 int rsvpteDecodeRecordRouteLabel(rsvpRecordRouteLabel_t
* sender
, u_char
* buf
, int bufSize
) {
1416 return MPLS_DEC_BUFFTOOSMALL
;
1420 size
= rsvpteDecodeLabelObject(&rr
->label
, buf
+ 4, bufSize
- 4;
1425 int rsvpteEncodeRecordRouteObject(rsvpRecordRouteObject_t
* rr
, char * bug
, int bufSize
) {
1426 int encodedSize
= 0;
1431 if (RSVP_OBJECT_HDRSIZE
> bufSize
) {
1432 return MPLS_ENC_BUFFTOOSMALL
;
1435 size
= RSVP_OBJECT_HDRSIZE
;
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
);
1445 case RSVP_RECORD_ROUTE_TYPE_IPV6
:
1446 size
= rsvpteEncodeRecordRoute6(&rr
->rr
[i
].ipv6
, buf
, bufSize
);
1448 case RSVP_RECORD_ROUTE_TYPE_LABEL
:
1449 size
= rsvpteEncodeRecordRouteLabel(&rr
->rr
[i
].label
, buf
, bufSize
);
1452 return RSVP_ENC_OBJECTERROR
;
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) {
1471 int rsvpteDecodeRecordRouteObject(rsvpRecordRouteObject_t
* rr
, char * bug
, int bufSize
) {
1472 int decodedSize
= 0;
1473 int size
= rsvpteDecodeObjectHeader(&rr
->hdr
, buf
, bufSize
);
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
) {
1493 case RSVP_RECORD_ROUTE_TYPE_IPV4
:
1494 size
= rsvpteDecodeRecordRoute4(&rr
->rr
[i
].ipv4
, buf
, bufSize
);
1496 case RSVP_RECORD_ROUTE_TYPE_IPV6
:
1497 size
= rsvpteDecodeRecordRoute6(&rr
->rr
[i
].ipv6
, buf
, bufSize
);
1499 case RSVP_RECORD_ROUTE_TYPE_LABEL
:
1500 size
= rsvpteDecodeRecordRouteLabel(&rr
->rr
[i
].label
, buf
, bufSize
);
1503 return RSVP_DEC_OBJECTERROR
;
1507 return RSVP_DEC_OBJECTERROR
;
1520 /* Sender TSpec Object */
1522 int rsvpteEncodeSenderTSpectObject(rsvpSenderTSpecObject_t
* sender
, char * bug
, int bufSize
) {
1524 int encodedSize
= 0;
1528 if (RSVP_OBJECT_HDRSIZE
> bufSize
) {
1529 return MPLS_ENC_BUFFTOOSMALL
;
1532 size
= RSVP_OBJECT_HDRSIZE
;
1537 /* need TSpec Definition */
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) {
1554 int rsvpteDecodeSenderTSpecObject(rsvpSenderTSpecObject_t
* req
, char * bug
, int bufSize
) {
1556 int decodedSize
= 0;
1557 int size
= rsvpteDecodeObjectHeader(&sender
->hdr
, buf
, bufSize
);
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 */
1579 return decodeSize
+ size
;