ldp.h revision 1.27
1/*	$OpenBSD: ldp.h,v 1.27 2016/05/23 18:58:48 renato 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 LDP_MAX_LEN		4096
31
32/* All Routers on this Subnet group multicast addresses */
33#define AllRouters_v4		"224.0.0.2"
34#define AllRouters_v6		"ff02::2"
35
36#define LINK_DFLT_HOLDTIME	15
37#define TARGETED_DFLT_HOLDTIME	45
38#define MIN_HOLDTIME		3
39#define MAX_HOLDTIME		0xffff
40#define	INFINITE_HOLDTIME	0xffff
41
42#define DEFAULT_KEEPALIVE	180
43#define MIN_KEEPALIVE		3
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
50
51#define	INIT_DELAY_TMR		15
52#define	MAX_DELAY_TMR		120
53
54#define	MIN_PWID_ID		1
55#define	MAX_PWID_ID		0xffffffff
56
57#define	DEFAULT_L2VPN_MTU	1500
58#define	MIN_L2VPN_MTU		512
59#define	MAX_L2VPN_MTU		0xffff
60
61/* LDP message types */
62#define MSG_TYPE_NOTIFICATION	0x0001
63#define MSG_TYPE_HELLO		0x0100
64#define MSG_TYPE_INIT		0x0200
65#define MSG_TYPE_KEEPALIVE	0x0201
66#define MSG_TYPE_ADDR		0x0300
67#define MSG_TYPE_ADDRWITHDRAW	0x0301
68#define MSG_TYPE_LABELMAPPING	0x0400
69#define MSG_TYPE_LABELREQUEST	0x0401
70#define MSG_TYPE_LABELWITHDRAW	0x0402
71#define MSG_TYPE_LABELRELEASE	0x0403
72#define MSG_TYPE_LABELABORTREQ	0x0404
73
74/* LDP TLV types */
75#define TLV_TYPE_FEC		0x0100
76#define TLV_TYPE_ADDRLIST	0x0101
77#define TLV_TYPE_HOPCOUNT	0x0103
78#define TLV_TYPE_PATHVECTOR	0x0104
79#define TLV_TYPE_GENERICLABEL	0x0200
80#define TLV_TYPE_ATMLABEL	0x0201
81#define TLV_TYPE_FRLABEL	0x0202
82#define TLV_TYPE_STATUS		0x0300
83#define TLV_TYPE_EXTSTATUS	0x0301
84#define TLV_TYPE_RETURNEDPDU	0x0302
85#define TLV_TYPE_RETURNEDMSG	0x0303
86#define TLV_TYPE_COMMONHELLO	0x0400
87#define TLV_TYPE_IPV4TRANSADDR	0x0401
88#define TLV_TYPE_CONFIG		0x0402
89#define TLV_TYPE_IPV6TRANSADDR	0x0403
90#define TLV_TYPE_COMMONSESSION	0x0500
91#define TLV_TYPE_ATMSESSIONPAR	0x0501
92#define TLV_TYPE_FRSESSION	0x0502
93#define TLV_TYPE_LABELREQUEST	0x0600
94/* RFC 4447 */
95#define TLV_TYPE_PW_STATUS	0x096A
96#define TLV_TYPE_PW_IF_PARAM	0x096B
97#define TLV_TYPE_PW_GROUP_ID	0x096C
98/* RFC 7552 */
99#define TLV_TYPE_DUALSTACK	0x8701
100
101/* LDP header */
102struct ldp_hdr {
103	uint16_t	version;
104	uint16_t	length;
105	uint32_t	lsr_id;
106	uint16_t	lspace_id;
107} __packed;
108
109#define	LDP_HDR_SIZE		10	/* actual size of the LDP header */
110#define	LDP_HDR_PDU_LEN		6	/* minimum "PDU Length" */
111#define LDP_HDR_DEAD_LEN	4
112
113/* TLV record */
114struct tlv {
115	uint16_t	type;
116	uint16_t	length;
117};
118#define	TLV_HDR_LEN		4
119
120struct ldp_msg {
121	uint16_t	type;
122	uint16_t	length;
123	uint32_t	msgid;
124	/* Mandatory Parameters */
125	/* Optional Parameters */
126} __packed;
127
128#define LDP_MSG_SIZE		8	/* minimum size of LDP message */
129#define LDP_MSG_LEN		4	/* minimum "Message Length" */
130#define LDP_MSG_DEAD_LEN	4
131
132#define	UNKNOWN_FLAG		0x8000
133#define	FORWARD_FLAG		0xc000
134
135struct hello_prms_tlv {
136	uint16_t	type;
137	uint16_t	length;
138	uint16_t	holdtime;
139	uint16_t	flags;
140};
141
142#define TARGETED_HELLO		0x8000
143#define REQUEST_TARG_HELLO	0x4000
144
145struct hello_prms_opt4_tlv {
146	uint16_t	type;
147	uint16_t	length;
148	uint32_t	value;
149};
150
151struct hello_prms_opt16_tlv {
152	uint16_t	type;
153	uint16_t	length;
154	uint8_t		value[16];
155};
156
157#define DUAL_STACK_LDPOV4	4
158#define DUAL_STACK_LDPOV6	6
159
160#define F_HELLO_TLV_RCVD_ADDR	0x01
161#define F_HELLO_TLV_RCVD_CONF	0x02
162#define F_HELLO_TLV_RCVD_DS	0x04
163
164#define	S_SUCCESS	0x00000000
165#define	S_BAD_LDP_ID	0x80000001
166#define	S_BAD_PROTO_VER	0x80000002
167#define	S_BAD_PDU_LEN	0x80000003
168#define	S_UNKNOWN_MSG	0x00000004
169#define	S_BAD_MSG_LEN	0x80000005
170#define	S_UNKNOWN_TLV	0x00000006
171#define	S_BAD_TLV_LEN	0x80000007
172#define	S_BAD_TLV_VAL	0x80000008
173#define	S_HOLDTIME_EXP	0x80000009
174#define	S_SHUTDOWN	0x8000000A
175#define	S_LOOP_DETECTED	0x0000000B
176#define	S_UNKNOWN_FEC	0x0000000C
177#define	S_NO_ROUTE	0x0000000D
178#define	S_NO_LABEL_RES	0x0000000E
179#define	S_AVAILABLE	0x0000000F
180#define	S_NO_HELLO	0x80000010
181#define	S_PARM_ADV_MODE	0x80000011
182#define	S_MAX_PDU_LEN	0x80000012
183#define	S_PARM_L_RANGE	0x80000013
184#define	S_KEEPALIVE_TMR	0x80000014
185#define	S_LAB_REQ_ABRT	0x00000015
186#define	S_MISS_MSG	0x00000016
187#define	S_UNSUP_ADDR	0x00000017
188#define	S_KEEPALIVE_BAD	0x80000018
189#define	S_INTERN_ERR	0x80000019
190/* RFC 4447 */
191#define S_ILLEGAL_CBIT	0x00000024
192#define S_WRONG_CBIT	0x00000025
193#define S_INCPT_BITRATE	0x00000026
194#define S_CEP_MISCONF	0x00000027
195#define S_PW_STATUS	0x00000028
196#define S_UNASSIGN_TAI	0x00000029
197#define S_MISCONF_ERR	0x0000002A
198#define S_WITHDRAW_MTHD	0x0000002B
199/* RFC 7552 */
200#define	S_TRANS_MISMTCH	0x80000032
201#define	S_DS_NONCMPLNCE	0x80000033
202
203struct sess_prms_tlv {
204	uint16_t	type;
205	uint16_t	length;
206	uint16_t	proto_version;
207	uint16_t	keepalive_time;
208	uint8_t		reserved;
209	uint8_t		pvlim;
210	uint16_t	max_pdu_len;
211	uint32_t	lsr_id;
212	uint16_t	lspace_id;
213} __packed;
214
215#define SESS_PRMS_SIZE		18
216
217struct status_tlv {
218	uint16_t	type;
219	uint16_t	length;
220	uint32_t	status_code;
221	uint32_t	msg_id;
222	uint16_t	msg_type;
223} __packed;
224
225#define STATUS_SIZE		14
226#define STATUS_TLV_LEN		10
227#define	STATUS_FATAL		0x80000000
228
229#define	AF_IPV4			0x1
230#define	AF_IPV6			0x2
231
232struct address_list_tlv {
233	uint16_t	type;
234	uint16_t	length;
235	uint16_t	family;
236	/* address entries */
237} __packed;
238
239#define FEC_ELM_WCARD_LEN	1
240#define FEC_ELM_PREFIX_MIN_LEN	4
241#define FEC_PWID_ELM_MIN_LEN	8
242
243#define	MAP_TYPE_WILDCARD	0x01
244#define	MAP_TYPE_PREFIX		0x02
245#define	MAP_TYPE_PWID		0x80
246#define	MAP_TYPE_GENPWID	0x81
247
248#define CONTROL_WORD_FLAG	0x8000
249#define PW_TYPE_ETHERNET_TAGGED	0x0004
250#define PW_TYPE_ETHERNET	0x0005
251#define DEFAULT_PW_TYPE		PW_TYPE_ETHERNET
252
253/* RFC 4447 Sub-TLV record */
254struct subtlv {
255	uint8_t		type;
256	uint8_t		length;
257};
258#define	SUBTLV_HDR_LEN		2
259
260#define SUBTLV_IFMTU		0x01
261#define SUBTLV_VLANID		0x06
262
263#define FEC_SUBTLV_IFMTU_LEN	4
264#define FEC_SUBTLV_VLANID_LEN	4
265
266struct label_tlv {
267	uint16_t	type;
268	uint16_t	length;
269	uint32_t	label;
270};
271
272#define LABEL_TLV_LEN		8
273
274struct reqid_tlv {
275	uint16_t	type;
276	uint16_t	length;
277	uint32_t	reqid;
278};
279
280#define REQID_TLV_LEN		8
281
282struct pw_status_tlv {
283	uint16_t	type;
284	uint16_t	length;
285	uint32_t	value;
286};
287
288#define PW_STATUS_TLV_LEN	8
289
290#define PW_FORWARDING		0
291#define PW_NOT_FORWARDING	(1 << 0)
292#define PW_LOCAL_RX_FAULT	(1 << 1)
293#define PW_LOCAL_TX_FAULT	(1 << 2)
294#define PW_PSN_RX_FAULT		(1 << 3)
295#define PW_PSN_TX_FAULT		(1 << 4)
296
297#define	NO_LABEL		UINT_MAX
298
299#endif /* !_LDP_H_ */
300