2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Copyright (c) 2009 Mojatatu Networks, Inc
38 * Per draft-ietf-forces-protocol-22
41 #define ForCES_HDRL 24
47 #define TOM_ASSNSETUP 0x1
48 #define TOM_ASSNTEARD 0x2
49 #define TOM_CONFIG 0x3
51 #define TOM_EVENTNOT 0x5
52 #define TOM_PKTREDIR 0x6
53 #define TOM_HEARTBT 0x0F
54 #define TOM_ASSNSETREP 0x11
55 #define TOM_CONFIGREP 0x13
56 #define TOM_QUERYREP 0x14
59 * tom_h Flags: resv1(8b):maxtlvs(4b):resv2(2b):mintlv(2b)
61 #define ZERO_TTLV 0x01
62 #define ZERO_MORE_TTLV 0x02
63 #define ONE_MORE_TTLV 0x04
69 #define TTLV_T1 (ONE_MORE_TTLV|ONE_TLV)
70 #define TTLV_T2 (ONE_MORE_TTLV|MAX_TLV)
77 int (*print
) (register const u_char
* pptr
, register u_int len
,
78 u_int16_t op_msk
, int indent
);
95 #define TOM_MAX_IND (_TOM_RSV_MAX - 1)
97 int lfbselect_print(register const u_char
* pptr
, register u_int len
,
98 u_int16_t op_msk
, int indent
);
99 int redirect_print(register const u_char
* pptr
, register u_int len
,
100 u_int16_t op_msk
, int indent
);
101 int asrtlv_print(register const u_char
* pptr
, register u_int len
,
102 u_int16_t op_msk
, int indent
);
103 int asttlv_print(register const u_char
* pptr
, register u_int len
,
104 u_int16_t op_msk
, int indent
);
105 int gentltlv_print(register const u_char
* pptr
, register u_int len
,
106 u_int16_t op_msk
, int indent
);
108 static inline tom_valid(u_int8_t tom
)
111 if (tom
>= 0x7 && tom
<= 0xe)
122 static inline const char *ForCES_node(u_int32_t node
)
124 if (node
>= 0 && node
<= 0x3FFFFFFF)
126 if (node
>= 0x40000000 && node
<= 0x7FFFFFFF)
128 if (node
>= 0xC0000000 && node
<= 0xFFFFFFEF)
129 return "AllMulticast";
130 if (node
== 0xFFFFFFFD)
131 return "AllCEsBroadcast";
132 if (node
== 0xFFFFFFFE)
133 return "AllFEsBroadcast";
134 if (node
== 0xFFFFFFFF)
135 return "AllBroadcast";
137 return "ForCESreserved";
141 static inline const char *ForCES_ACKp(u_int32_t flg
)
154 static inline const char *ForCES_EMp(u_int32_t flg
)
159 return "execute-all-or-none";
161 return "execute-until-failure";
163 return "continue-execute-on-failure";
167 static inline const char *ForCES_ATp(u_int32_t flg
)
172 return "2PCtransaction";
176 static inline const char *ForCES_TPp(u_int32_t flg
)
179 return "StartofTransaction";
181 return "MiddleofTransaction";
183 return "EndofTransaction";
190 * Structure of forces header, naked of TLVs.
193 #if BYTE_ORDER == LITTLE_ENDIAN
194 u_int8_t fm_rsvd
:4, fm_version
:4;
195 #elif BYTE_ORDER == BIG_ENDIAN
196 u_int8_t fm_version
:4, fm_rsvd
:4;
199 #define ForCES_V(forcesh) (forcesh)->fm_version
200 u_int8_t fm_tom
; /* type of message */
201 u_int16_t fm_len
; /* total length * 4 bytes */
202 #define ForCES_BLN(forcesh) ntohs((forcesh)->fm_len) << 2
203 u_int32_t fm_sid
; /* Source ID */
204 #define ForCES_SID(forcesh) ntohl((forcesh)->fm_sid)
205 u_int32_t fm_did
; /* Destination ID */
206 #define ForCES_DID(forcesh) ntohl((forcesh)->fm_did)
207 u_int8_t fm_cor
[8]; /* correlator */
208 #if BYTE_ORDER == LITTLE_ENDIAN
209 u_int16_t f_rs1
:3, f_pri
:3, f_ack
:2, f_rs2
:3, f_tp
:2, f_at
:1, f_em
:2;
210 #elif BYTE_ORDER == BIG_ENDIAN
211 u_int16_t f_ack
:2, f_pri
:3, f_rs1
:3, f_em
:2, f_at
:1, f_tp
:2, f_rs2
:3;
217 #define ForCES_HLN_VALID(fhl,tlen) ((tlen) >= (int)sizeof(struct forcesh) && \
218 (fhl) >= sizeof(struct forcesh) && \
221 #define F_LFB_RSVD 0x0
222 #define F_LFB_FEO 0x1
223 #define F_LFB_FEPO 0x2
224 struct tok ForCES_LFBs
[] = {
225 {F_LFB_RSVD
, "Invalid TLV"},
226 {F_LFB_FEO
, "FEObj LFB"},
227 {F_LFB_FEPO
, "FEProtoObj LFB"},
250 #define F_OP_MAX (_F_OP_MAX - 1)
252 B_OP_SET
= 1 << (F_OP_SET
- 1),
253 B_OP_SETPROP
= 1 << (F_OP_SETPROP
- 1),
254 B_OP_SETRESP
= 1 << (F_OP_SETRESP
- 1),
255 B_OP_SETPRESP
= 1 << (F_OP_SETPRESP
- 1),
256 B_OP_DEL
= 1 << (F_OP_DEL
- 1),
257 B_OP_DELRESP
= 1 << (F_OP_DELRESP
- 1),
258 B_OP_GET
= 1 << (F_OP_GET
- 1),
259 B_OP_GETPROP
= 1 << (F_OP_GETPROP
- 1),
260 B_OP_GETRESP
= 1 << (F_OP_GETRESP
- 1),
261 B_OP_GETPRESP
= 1 << (F_OP_GETPRESP
- 1),
262 B_OP_REPORT
= 1 << (F_OP_REPORT
- 1),
263 B_OP_COMMIT
= 1 << (F_OP_COMMIT
- 1),
264 B_OP_RCOMMIT
= 1 << (F_OP_RCOMMIT
- 1),
265 B_OP_RTRCOMP
= 1 << (F_OP_RTRCOMP
- 1),
272 int (*print
) (register const u_char
* pptr
, register u_int len
,
273 u_int16_t op_msk
, int indent
);
276 int genoptlv_print(register const u_char
* pptr
, register u_int len
,
277 u_int16_t op_msk
, int indent
);
278 int recpdoptlv_print(register const u_char
* pptr
, register u_int len
,
279 u_int16_t op_msk
, int indent
);
280 int invoptlv_print(register const u_char
* pptr
, register u_int len
,
281 u_int16_t op_msk
, int indent
);
294 static struct optlv_h OPTLV_msg
[F_OP_MAX
+ 1] = {
295 [F_OP_RSV
] = {ZERO_TTLV
, 0, "Invalid OPTLV", invoptlv_print
},
296 [F_OP_SET
] = {TTLV_T2
, B_FULLD
| B_SPARD
, " Set", recpdoptlv_print
},
298 {TTLV_T2
, B_FULLD
| B_SPARD
, " SetProp", recpdoptlv_print
},
299 [F_OP_SETRESP
] = {TTLV_T2
, B_RESTV
, " SetResp", recpdoptlv_print
},
300 [F_OP_SETPRESP
] = {TTLV_T2
, B_RESTV
, " SetPropResp", recpdoptlv_print
},
301 [F_OP_DEL
] = {ZERO_TTLV
, 0, " Del", recpdoptlv_print
},
302 [F_OP_DELRESP
] = {TTLV_T2
, B_RESTV
, " DelResp", recpdoptlv_print
},
303 [F_OP_GET
] = {ZERO_TTLV
, 0, " Get", recpdoptlv_print
},
304 [F_OP_GETPROP
] = {ZERO_TTLV
, 0, " GetProp", recpdoptlv_print
},
306 {TTLV_T2
, B_FULLD
| B_RESTV
, " GetResp", recpdoptlv_print
},
308 {TTLV_T2
, B_FULLD
| B_RESTV
, " GetPropResp", recpdoptlv_print
},
310 {TTLV_T2
, B_FULLD
| B_SPARD
, " Report", recpdoptlv_print
},
311 [F_OP_COMMIT
] = {ZERO_TTLV
, 0, " Commit", NULL
},
312 [F_OP_RCOMMIT
] = {TTLV_T1
, B_RESTV
, " RCommit", genoptlv_print
},
313 [F_OP_RTRCOMP
] = {ZERO_TTLV
, 0, " RTRCOMP", NULL
},
316 static inline struct optlv_h
*get_forces_optlv_h(u_int16_t opt
)
318 if (opt
> F_OP_MAX
|| opt
<= F_OP_RSV
)
319 return &OPTLV_msg
[F_OP_RSV
];
321 return &OPTLV_msg
[opt
];
326 #define IND_PREF '\n'
328 char ind_buf
[IND_SIZE
];
330 static inline char *indent_pr(int indent
, int nlpref
)
335 if (indent
> (IND_SIZE
- 1))
336 indent
= IND_SIZE
- 1;
344 while (--indent
>= 0)
351 static inline op_valid(u_int16_t op
, u_int16_t mask
)
353 int opb
= 1 << (op
- 1);
359 // I guess we should allow vendor operations?
365 #define F_TLV_RSVD 0x0000
366 #define F_TLV_REDR 0x0001
367 #define F_TLV_ASRS 0x0010
368 #define F_TLV_ASRT 0x0011
369 #define F_TLV_LFBS 0x1000
370 #define F_TLV_PDAT 0x0110
371 #define F_TLV_KEYI 0x0111
372 #define F_TLV_FULD 0x0112
373 #define F_TLV_SPAD 0x0113
374 #define F_TLV_REST 0x0114
375 #define F_TLV_METD 0x0115
376 #define F_TLV_REDD 0x0116
377 #define F_TLV_VNST 0x8000
379 static struct tok ForCES_TLV
[] = {
380 {F_TLV_RSVD
, "Invalid TLV"},
381 {F_TLV_REDR
, "REDIRECT TLV"},
382 {F_TLV_ASRS
, "ASResult TLV"},
383 {F_TLV_ASRT
, "ASTreason TLV"},
384 {F_TLV_LFBS
, "LFBselect TLV"},
385 {F_TLV_PDAT
, "PATH-DATA TLV"},
386 {F_TLV_KEYI
, "KEYINFO TLV"},
387 {F_TLV_FULD
, "FULLDATA TLV"},
388 {F_TLV_SPAD
, "SPARSEDATA TLV"},
389 {F_TLV_REST
, "RESULT TLV"},
390 {F_TLV_METD
, "METADATA TLV"},
391 {F_TLV_REDD
, "REDIRECTDATA TLV"},
396 static inline int ttlv_valid(u_int16_t ttlv
)
399 if (ttlv
== 1 || ttlv
== 0x1000)
401 if (ttlv
>= 0x10 && ttlv
<= 0x11)
403 if (ttlv
>= 0x110 && ttlv
<= 0x116)
422 #define F_ALN_LEN(len) ( ((len)+ForCES_ALNL-1) & ~(ForCES_ALNL-1) )
423 #define GET_TOP_TLV(fhdr) ((struct forces_tlv *)((fhdr) + sizeof (struct forcesh)))
424 #define TLV_SET_LEN(len) (F_ALN_LEN(sizeof(struct forces_tlv)) + (len))
425 #define TLV_ALN_LEN(len) F_ALN_LEN(TLV_SET_LEN(len))
426 #define TLV_RDAT_LEN(tlv) ((int)(ntohs((tlv)->length)) - TLV_SET_LEN(0))
427 #define TLV_DATA(tlvp) ((void*)(((char*)(tlvp)) + TLV_SET_LEN(0)))
428 #define GO_NXT_TLV(tlv,rlen) ((rlen) -= F_ALN_LEN(ntohs((tlv)->length)), \
429 (struct forces_tlv*)(((char*)(tlv)) \
430 + F_ALN_LEN(ntohs((tlv)->length))))
431 #define ILV_SET_LEN(len) (F_ALN_LEN(sizeof(struct forces_ilv)) + (len))
432 #define ILV_ALN_LEN(len) F_ALN_LEN(ILV_SET_LEN(len))
433 #define ILV_RDAT_LEN(ilv) ((int)(ntohl((ilv)->length)) - ILV_SET_LEN(0))
434 #define ILV_DATA(ilvp) ((void*)(((char*)(ilvp)) + ILV_SET_LEN(0)))
435 #define GO_NXT_ILV(ilv,rlen) ((rlen) -= F_ALN_LEN(ntohl((ilv)->length)), \
436 (struct forces_ilv *)(((char*)(ilv)) \
437 + F_ALN_LEN(ntohl((ilv)->length))))
438 #define INVALID_RLEN -1
439 #define INVALID_STLN -2
440 #define INVALID_LTLN -3
441 #define INVALID_ALEN -4
443 static struct tok ForCES_TLV_err
[] = {
444 {INVALID_RLEN
, "Invalid total length"},
445 {INVALID_STLN
, "xLV too short"},
446 {INVALID_LTLN
, "xLV too long"},
447 {INVALID_ALEN
, "data padding missing"},
451 static inline int tlv_valid(struct forces_tlv
*tlv
, int rlen
)
453 if (rlen
< sizeof(struct forces_tlv
))
455 if (ntohs(tlv
->length
) < sizeof(struct forces_tlv
))
457 if (ntohs(tlv
->length
) > rlen
)
459 if (rlen
< F_ALN_LEN(ntohs(tlv
->length
)))
465 static inline int ilv_valid(struct forces_ilv
*ilv
, int rlen
)
467 if (rlen
< sizeof(struct forces_ilv
))
469 if (ntohl(ilv
->length
) < sizeof(struct forces_ilv
))
471 if (ntohl(ilv
->length
) > rlen
)
473 if (rlen
< F_ALN_LEN(ntohl(ilv
->length
)))
479 struct forces_lfbsh
{
484 #define ASSNS_OPS (B_OP_REPORT)
485 #define CFG_OPS (B_OP_SET|B_OP_SETPROP|B_OP_DEL|B_OP_COMMIT|B_OP_RTRCOMP)
486 #define CFG_ROPS (B_OP_SETRESP|B_OP_SETPRESP|B_OP_DELRESP|B_OP_RCOMMIT)
487 #define CFG_QY (B_OP_GET|B_OP_GETPROP)
488 #define CFG_QYR (B_OP_GETRESP|B_OP_GETPRESP)
489 #define CFG_EVN (B_OP_REPORT)
491 static struct tom_h ForCES_msg
[TOM_MAX_IND
+ 1] = {
492 [TOM_RSV_I
] = {TOM_RSVD
, ZERO_TTLV
, 0, "Invalid message", NULL
},
493 [TOM_ASS_I
] = {TOM_ASSNSETUP
, ZERO_MORE_TTLV
| TWO_TLV
, ASSNS_OPS
,
494 "Association Setup", lfbselect_print
},
496 {TOM_ASSNTEARD
, TTLV_T1
, 0, "Association TearDown", asttlv_print
},
497 [TOM_CFG_I
] = {TOM_CONFIG
, TTLV_T2
, CFG_OPS
, "Config", lfbselect_print
},
498 [TOM_QRY_I
] = {TOM_QUERY
, TTLV_T2
, CFG_QY
, "Query", lfbselect_print
},
499 [TOM_EVN_I
] = {TOM_EVENTNOT
, TTLV_T1
, CFG_EVN
, "Event Notification",
502 {TOM_PKTREDIR
, TTLV_T2
, 0, "Packet Redirect", redirect_print
},
503 [TOM_HBT_I
] = {TOM_HEARTBT
, ZERO_TTLV
, 0, "HeartBeat", NULL
},
505 {TOM_ASSNSETREP
, TTLV_T1
, 0, "Association Response", asrtlv_print
},
506 [TOM_CNR_I
] = {TOM_CONFIGREP
, TTLV_T2
, CFG_ROPS
, "Config Response",
509 {TOM_QUERYREP
, TTLV_T2
, CFG_QYR
, "Query Response", lfbselect_print
},
512 static inline struct tom_h
*get_forces_tom(u_int8_t tom
)
515 for (i
= TOM_RSV_I
; i
<= TOM_MAX_IND
; i
++) {
516 struct tom_h
*th
= &ForCES_msg
[i
];
520 return &ForCES_msg
[TOM_RSV_I
];
528 int (*print
) (register const u_char
* pptr
, register u_int len
,
529 u_int16_t op_msk
, int indent
);
541 #define PD_MAX_IND (_TOM_RSV_MAX - 1)
543 static inline int pd_valid(u_int16_t pd
)
546 if (pd
>= F_TLV_PDAT
&& pd
<= F_TLV_REST
)
552 static inline int chk_op_type(u_int16_t type
, u_int16_t msk
, u_int16_t omsk
)
554 if (type
!= F_TLV_PDAT
) {
556 if (type
!= F_TLV_KEYI
) {
558 ("Based on flags expected KEYINFO TLV!\n");
563 ("Illegal DATA encoding for type 0x%x programmed %x got %x \n",
571 int fdatatlv_print(register const u_char
* pptr
, register u_int len
,
572 u_int16_t op_msk
, int indent
);
573 int sdatatlv_print(register const u_char
* pptr
, register u_int len
,
574 u_int16_t op_msk
, int indent
);
575 int pdatatlv_print(register const u_char
* pptr
, register u_int len
,
576 u_int16_t op_msk
, int indent
);
577 int pkeyitlv_print(register const u_char
* pptr
, register u_int len
,
578 u_int16_t op_msk
, int indent
);
580 int prestlv_print(register const u_char
* pptr
, register u_int len
,
581 u_int16_t op_msk
, int indent
);
590 static struct pdata_ops ForCES_pdata
[PD_MAX_IND
+ 1] = {
591 [PD_RSV_I
] = {0, 0, 0, "Invalid message", NULL
},
592 [PD_SEL_I
] = {F_TLV_KEYI
, 0, 0, "KEYINFO TLV", pkeyitlv_print
},
593 [PD_FDT_I
] = {F_TLV_FULD
, 0, B_FULLD
, "FULLDATA TLV", fdatatlv_print
},
594 [PD_SDT_I
] = {F_TLV_SPAD
, 0, B_SPARD
, "SPARSEDATA TLV", sdatatlv_print
},
595 [PD_RES_I
] = {F_TLV_REST
, 0, B_RESTV
, "RESULT TLV", prestlv_print
},
597 {F_TLV_PDAT
, 0, 0, "Inner PATH-DATA TLV", recpdoptlv_print
},
600 static inline struct pdata_ops
*get_forces_pd(u_int16_t pd
)
603 for (i
= PD_RSV_I
+ 1; i
<= PD_MAX_IND
; i
++) {
604 struct pdata_ops
*pdo
= &ForCES_pdata
[i
];
608 return &ForCES_pdata
[TOM_RSV_I
];
616 E_INVALID_DESTINATION_PID
,
619 E_LFB_INSTANCE_ID_NOT_FOUND
,
621 E_COMPONENT_DOES_NOT_EXIST
,
625 E_INVALID_ARRAY_CREATION
,
626 E_VALUE_OUT_OF_RANGE
,
628 E_INVALID_PARAMETERS
,
629 E_INVALID_MESSAGE_TYPE
,
636 // 0x18-0xFE are reserved ..
637 E_UNSPECIFIED_ERROR
= 0XFF
640 struct tok ForCES_errs
[] = {
641 {E_SUCCESS
, "SUCCESS"},
642 {E_INVALID_HEADER
, "INVALID HEADER"},
643 {E_LENGTH_MISMATCH
, "LENGTH MISMATCH"},
644 {E_VERSION_MISMATCH
, "VERSION MISMATCH"},
645 {E_INVALID_DESTINATION_PID
, "INVALID DESTINATION PID"},
646 {E_LFB_UNKNOWN
, "LFB UNKNOWN"},
647 {E_LFB_NOT_FOUND
, "LFB NOT FOUND"},
648 {E_LFB_INSTANCE_ID_NOT_FOUND
, "LFB INSTANCE ID NOT FOUND"},
649 {E_INVALID_PATH
, "INVALID PATH"},
650 {E_COMPONENT_DOES_NOT_EXIST
, "COMPONENT DOES NOT EXIST"},
651 {E_EXISTS
, "EXISTS ALREADY"},
652 {E_NOT_FOUND
, "NOT FOUND"},
653 {E_READ_ONLY
, "READ ONLY"},
654 {E_INVALID_ARRAY_CREATION
, "INVALID ARRAY CREATION"},
655 {E_VALUE_OUT_OF_RANGE
, "VALUE OUT OF RANGE"},
656 {E_CONTENTS_TOO_LONG
, "CONTENTS TOO LONG"},
657 {E_INVALID_PARAMETERS
, "INVALID PARAMETERS"},
658 {E_INVALID_MESSAGE_TYPE
, "INVALID MESSAGE TYPE"},
659 {E_INVALID_FLAGS
, "INVALID FLAGS"},
660 {E_INVALID_TLV
, "INVALID TLV"},
661 {E_EVENT_ERROR
, "EVENT ERROR"},
662 {E_NOT_SUPPORTED
, "NOT SUPPORTED"},
663 {E_MEMORY_ERROR
, "MEMORY ERROR"},
664 {E_INTERNAL_ERROR
, "INTERNAL ERROR"},
665 {E_UNSPECIFIED_ERROR
, "UNSPECIFIED ERROR"},