xref: /openbsd-src/usr.sbin/ldpd/ldp.h (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1 /*	$OpenBSD: ldp.h,v 1.9 2011/01/10 11:58:39 claudio Exp $ */
2 
3 /*
4  * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
5  * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /* LDP protocol definitions */
21 
22 #ifndef _LDP_H_
23 #define _LDP_H_
24 
25 #include <netinet/in.h>
26 
27 /* misc */
28 #define LDP_VERSION		1
29 #define LDP_PORT		646
30 #define AllRouters		"224.0.0.2"
31 
32 #define LDP_MAX_LEN		4096
33 
34 #define INFINITE_TMR		(-1)
35 #define LINK_DFLT_HOLDTIME	15
36 #define TARGETED_DFLT_HOLDTIME	45
37 
38 #define DEFAULT_HOLDTIME	15
39 #define MIN_HOLDTIME		1
40 #define MAX_HOLDTIME		0xffff
41 
42 #define DEFAULT_KEEPALIVE	180
43 #define MIN_KEEPALIVE		1
44 #define MAX_KEEPALIVE		0xffff
45 #define KEEPALIVE_PER_PERIOD	3
46 
47 #define	DEFAULT_HELLO_INTERVAL	5
48 #define	MIN_HELLO_INTERVAL	1
49 #define	MAX_HELLO_INTERVAL	0xffff	/* XXX */
50 
51 #define	INIT_DELAY_TMR		15
52 #define DEFAULT_NBR_TMOUT	86400	/* 24 hours */
53 
54 /* LDP message types */
55 #define MSG_TYPE_NOTIFICATION	0x0001
56 #define MSG_TYPE_HELLO		0x0100
57 #define MSG_TYPE_INIT		0x0200
58 #define MSG_TYPE_KEEPALIVE	0x0201
59 #define MSG_TYPE_ADDR		0x0300
60 #define MSG_TYPE_ADDRWITHDRAW	0x0301
61 #define MSG_TYPE_LABELMAPPING	0x0400
62 #define MSG_TYPE_LABELREQUEST	0x0401
63 #define MSG_TYPE_LABELWITHDRAW	0x0402
64 #define MSG_TYPE_LABELRELEASE	0x0403
65 #define MSG_TYPE_LABELABORTREQ	0x0404
66 
67 /* LDP TLV types */
68 #define TLV_TYPE_FEC		0x0100
69 #define TLV_TYPE_ADDRLIST	0x0101
70 #define TLV_TYPE_HOPCOUNT	0x0103
71 #define TLV_TYPE_PATHVECTOR	0x0104
72 #define TLV_TYPE_GENERICLABEL	0x0200
73 #define TLV_TYPE_ATMLABEL	0x0201
74 #define TLV_TYPE_FRLABEL	0x0202
75 #define TLV_TYPE_STATUS		0x0300
76 #define TLV_TYPE_EXTSTATUS	0x0301
77 #define TLV_TYPE_RETURNEDPDU	0x0302
78 #define TLV_TYPE_RETURNEDMSG	0x0303
79 #define TLV_TYPE_COMMONHELLO	0x0400
80 #define TLV_TYPE_IPV4TRANSADDR	0x0401
81 #define TLV_TYPE_CONFIG		0x0402
82 #define TLV_TYPE_IPV6TRANSADDR	0x0403
83 #define TLV_TYPE_COMMONSESSION	0x0500
84 #define TLV_TYPE_ATMSESSIONPAR	0x0501
85 #define TLV_TYPE_FRSESSION	0x0502
86 #define TLV_TYPE_LABELREQUEST	0x0600
87 
88 /* LDP header */
89 struct ldp_hdr {
90 	u_int16_t		version;
91 	u_int16_t		length;
92 	u_int32_t		lsr_id;
93 	u_int16_t		lspace_id;
94 } __packed;
95 
96 #define	LDP_HDR_SIZE		10
97 #define	INFINITE_HOLDTIME	0xffff
98 
99 /* TLV record */
100 struct tlv {
101 	u_int16_t	type;
102 	u_int16_t	length;
103 };
104 #define	TLV_HDR_LEN		4
105 
106 struct ldp_msg {
107 	u_int16_t	type;
108 	u_int16_t	length;
109 	u_int32_t	msgid;
110 	/* Mandatory Parameters */
111 	/* Optional Parameters */
112 } __packed;
113 
114 #define LDP_MSG_LEN		8
115 
116 #define	UNKNOWN_FLAGS_MASK	0xc000
117 #define	UNKNOWN_FLAG		0x8000
118 #define	FORWARD_FLAG		0xc000
119 
120 #define TARGETED_HELLO		0x8000
121 #define REQUEST_TARG_HELLO	0x4000
122 
123 struct hello_prms_tlv {
124 	u_int16_t	type;
125 	u_int16_t	length;
126 	u_int16_t	holdtime;
127 	u_int16_t	flags;
128 };
129 
130 #define HELLO_PRMS_SIZE		8
131 
132 #define	S_SUCCESS	0x00000000
133 #define	S_BAD_LDP_ID	0x80000001
134 #define	S_BAD_PROTO_VER	0x80000002
135 #define	S_BAD_PDU_LEN	0x80000003
136 #define	S_UNKNOWN_MSG	0x00000004
137 #define	S_BAD_MSG_LEN	0x80000005
138 #define	S_UNKNOWN_TLV	0x00000006
139 #define	S_BAD_TLV_LEN	0x80000007
140 #define	S_BAD_TLV_VAL	0x80000008
141 #define	S_HOLDTIME_EXP	0x80000009
142 #define	S_SHUTDOWN	0x8000000A
143 #define	S_LOOP_DETECTED	0x0000000B
144 #define	S_UNKNOWN_FEC	0x0000000C
145 #define	S_NO_ROUTE	0x0000000D
146 #define	S_NO_LABEL_RES	0x0000000E
147 #define	S_AVAILABLE	0x0000000F
148 #define	S_NO_HELLO	0x80000010
149 #define	S_PARM_ADV_MODE	0x80000011
150 #define	S_MAX_PDU_LEN	0x80000012
151 #define	S_PARM_L_RANGE	0x80000013
152 #define	S_KEEPALIVE_TMR	0x80000014
153 #define	S_LAB_REQ_ABRT	0x00000015
154 #define	S_MISS_MSG	0x00000016
155 #define	S_UNSUP_ADDR	0x00000017
156 #define	S_KEEPALIVE_BAD	0x80000018
157 #define	S_INTERN_ERR	0x80000019
158 
159 struct sess_prms_tlv {
160 	u_int16_t	type;
161 	u_int16_t	length;
162 	u_int16_t	proto_version;
163 	u_int16_t	keepalive_time;
164 	u_int8_t	reserved;
165 	u_int8_t	pvlim;
166 	u_int16_t	max_pdu_len;
167 	u_int32_t	lsr_id;
168 	u_int16_t	lspace_id;
169 } __packed;
170 
171 #define SESS_PRMS_SIZE		18
172 
173 struct status_tlv {
174 	u_int16_t	type;
175 	u_int16_t	length;
176 	u_int32_t	status_code;
177 	u_int32_t	msg_id;
178 	u_int16_t	msg_type;
179 } __packed;
180 
181 #define STATUS_SIZE		14
182 #define STATUS_TLV_LEN		10
183 #define	STATUS_FATAL		0x80000000
184 
185 struct address_list_tlv {
186 	u_int16_t	type;
187 	u_int16_t	length;
188 	u_int16_t	family;
189 	/* address entries */
190 } __packed;
191 
192 #define	BASIC_LABEL_MAP_LEN	24
193 
194 #define	ADDR_IPV4		0x1
195 #define	ADDR_IPV6		0x2
196 
197 /* This struct is badly aligned so use two 32 bit fields */
198 struct fec_elm {
199 	u_int32_t	hdr;
200 	u_int32_t	addr;
201 };
202 
203 #define FEC_ELM_MIN_LEN		4
204 #define	FEC_WILDCARD		0x01
205 #define	FEC_PREFIX		0x02
206 #define	FEC_IPV4		0x0001
207 
208 struct label_tlv {
209 	u_int16_t	type;
210 	u_int16_t	length;
211 	u_int32_t	label;
212 };
213 
214 #define LABEL_TLV_LEN		8
215 
216 struct reqid_tlv {
217 	u_int16_t	type;
218 	u_int16_t	length;
219 	u_int32_t	reqid;
220 };
221 
222 #define REQID_TLV_LEN		8
223 
224 #define	NO_LABEL		UINT_MAX
225 
226 #endif /* !_LDP_H_ */
227