ldp.h revision 1.31
1/*	$OpenBSD: ldp.h,v 1.31 2016/07/01 23:18:24 renato Exp $ */
2
3/*
4 * Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
5 * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
6 * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/* LDP protocol definitions */
22
23#ifndef _LDP_H_
24#define _LDP_H_
25
26#include <sys/types.h>
27
28/* misc */
29#define LDP_VERSION		1
30#define LDP_PORT		646
31#define LDP_MAX_LEN		4096
32
33/* All Routers on this Subnet group multicast addresses */
34#define AllRouters_v4		"224.0.0.2"
35#define AllRouters_v6		"ff02::2"
36
37#define LINK_DFLT_HOLDTIME	15
38#define TARGETED_DFLT_HOLDTIME	45
39#define MIN_HOLDTIME		3
40#define MAX_HOLDTIME		0xffff
41#define	INFINITE_HOLDTIME	0xffff
42
43#define DEFAULT_KEEPALIVE	180
44#define MIN_KEEPALIVE		3
45#define MAX_KEEPALIVE		0xffff
46#define KEEPALIVE_PER_PERIOD	3
47
48#define	DEFAULT_HELLO_INTERVAL	5
49#define	MIN_HELLO_INTERVAL	1
50#define	MAX_HELLO_INTERVAL	0xffff
51
52#define	INIT_DELAY_TMR		15
53#define	MAX_DELAY_TMR		120
54
55#define	MIN_PWID_ID		1
56#define	MAX_PWID_ID		0xffffffff
57
58#define	DEFAULT_L2VPN_MTU	1500
59#define	MIN_L2VPN_MTU		512
60#define	MAX_L2VPN_MTU		0xffff
61
62/* LDP message types */
63#define MSG_TYPE_NOTIFICATION	0x0001
64#define MSG_TYPE_HELLO		0x0100
65#define MSG_TYPE_INIT		0x0200
66#define MSG_TYPE_KEEPALIVE	0x0201
67#define MSG_TYPE_ADDR		0x0300
68#define MSG_TYPE_ADDRWITHDRAW	0x0301
69#define MSG_TYPE_LABELMAPPING	0x0400
70#define MSG_TYPE_LABELREQUEST	0x0401
71#define MSG_TYPE_LABELWITHDRAW	0x0402
72#define MSG_TYPE_LABELRELEASE	0x0403
73#define MSG_TYPE_LABELABORTREQ	0x0404
74
75/* LDP TLV types */
76#define TLV_TYPE_FEC		0x0100
77#define TLV_TYPE_ADDRLIST	0x0101
78#define TLV_TYPE_HOPCOUNT	0x0103
79#define TLV_TYPE_PATHVECTOR	0x0104
80#define TLV_TYPE_GENERICLABEL	0x0200
81#define TLV_TYPE_ATMLABEL	0x0201
82#define TLV_TYPE_FRLABEL	0x0202
83#define TLV_TYPE_STATUS		0x0300
84#define TLV_TYPE_EXTSTATUS	0x0301
85#define TLV_TYPE_RETURNEDPDU	0x0302
86#define TLV_TYPE_RETURNEDMSG	0x0303
87#define TLV_TYPE_COMMONHELLO	0x0400
88#define TLV_TYPE_IPV4TRANSADDR	0x0401
89#define TLV_TYPE_CONFIG		0x0402
90#define TLV_TYPE_IPV6TRANSADDR	0x0403
91#define TLV_TYPE_COMMONSESSION	0x0500
92#define TLV_TYPE_ATMSESSIONPAR	0x0501
93#define TLV_TYPE_FRSESSION	0x0502
94#define TLV_TYPE_LABELREQUEST	0x0600
95/* RFC 4447 */
96#define TLV_TYPE_PW_STATUS	0x096A
97#define TLV_TYPE_PW_IF_PARAM	0x096B
98#define TLV_TYPE_PW_GROUP_ID	0x096C
99/* RFC 7552 */
100#define TLV_TYPE_DUALSTACK	0x8701
101
102/* LDP header */
103struct ldp_hdr {
104	uint16_t	version;
105	uint16_t	length;
106	uint32_t	lsr_id;
107	uint16_t	lspace_id;
108} __packed;
109
110#define	LDP_HDR_SIZE		10	/* actual size of the LDP header */
111#define	LDP_HDR_PDU_LEN		6	/* minimum "PDU Length" */
112#define LDP_HDR_DEAD_LEN	4
113
114/* TLV record */
115struct tlv {
116	uint16_t	type;
117	uint16_t	length;
118};
119#define	TLV_HDR_LEN		4
120
121struct ldp_msg {
122	uint16_t	type;
123	uint16_t	length;
124	uint32_t	msgid;
125	/* Mandatory Parameters */
126	/* Optional Parameters */
127} __packed;
128
129#define LDP_MSG_SIZE		8	/* minimum size of LDP message */
130#define LDP_MSG_LEN		4	/* minimum "Message Length" */
131#define LDP_MSG_DEAD_LEN	4
132
133#define	UNKNOWN_FLAG		0x8000
134#define	FORWARD_FLAG		0xc000
135
136struct hello_prms_tlv {
137	uint16_t	type;
138	uint16_t	length;
139	uint16_t	holdtime;
140	uint16_t	flags;
141};
142
143#define F_HELLO_TARGETED	0x8000
144#define F_HELLO_REQ_TARG	0x4000
145#define F_HELLO_GTSM		0x2000
146
147struct hello_prms_opt4_tlv {
148	uint16_t	type;
149	uint16_t	length;
150	uint32_t	value;
151};
152
153struct hello_prms_opt16_tlv {
154	uint16_t	type;
155	uint16_t	length;
156	uint8_t		value[16];
157};
158
159#define DUAL_STACK_LDPOV4	4
160#define DUAL_STACK_LDPOV6	6
161
162#define F_HELLO_TLV_RCVD_ADDR	0x01
163#define F_HELLO_TLV_RCVD_CONF	0x02
164#define F_HELLO_TLV_RCVD_DS	0x04
165
166#define	S_SUCCESS	0x00000000
167#define	S_BAD_LDP_ID	0x80000001
168#define	S_BAD_PROTO_VER	0x80000002
169#define	S_BAD_PDU_LEN	0x80000003
170#define	S_UNKNOWN_MSG	0x00000004
171#define	S_BAD_MSG_LEN	0x80000005
172#define	S_UNKNOWN_TLV	0x00000006
173#define	S_BAD_TLV_LEN	0x80000007
174#define	S_BAD_TLV_VAL	0x80000008
175#define	S_HOLDTIME_EXP	0x80000009
176#define	S_SHUTDOWN	0x8000000A
177#define	S_LOOP_DETECTED	0x0000000B
178#define	S_UNKNOWN_FEC	0x0000000C
179#define	S_NO_ROUTE	0x0000000D
180#define	S_NO_LABEL_RES	0x0000000E
181#define	S_AVAILABLE	0x0000000F
182#define	S_NO_HELLO	0x80000010
183#define	S_PARM_ADV_MODE	0x80000011
184#define	S_MAX_PDU_LEN	0x80000012
185#define	S_PARM_L_RANGE	0x80000013
186#define	S_KEEPALIVE_TMR	0x80000014
187#define	S_LAB_REQ_ABRT	0x00000015
188#define	S_MISS_MSG	0x00000016
189#define	S_UNSUP_ADDR	0x00000017
190#define	S_KEEPALIVE_BAD	0x80000018
191#define	S_INTERN_ERR	0x80000019
192/* RFC 4447 */
193#define S_ILLEGAL_CBIT	0x00000024
194#define S_WRONG_CBIT	0x00000025
195#define S_INCPT_BITRATE	0x00000026
196#define S_CEP_MISCONF	0x00000027
197#define S_PW_STATUS	0x00000028
198#define S_UNASSIGN_TAI	0x00000029
199#define S_MISCONF_ERR	0x0000002A
200#define S_WITHDRAW_MTHD	0x0000002B
201/* RFC 7552 */
202#define	S_TRANS_MISMTCH	0x80000032
203#define	S_DS_NONCMPLNCE	0x80000033
204
205struct sess_prms_tlv {
206	uint16_t	type;
207	uint16_t	length;
208	uint16_t	proto_version;
209	uint16_t	keepalive_time;
210	uint8_t		reserved;
211	uint8_t		pvlim;
212	uint16_t	max_pdu_len;
213	uint32_t	lsr_id;
214	uint16_t	lspace_id;
215} __packed;
216
217#define SESS_PRMS_SIZE		18
218
219struct status_tlv {
220	uint16_t	type;
221	uint16_t	length;
222	uint32_t	status_code;
223	uint32_t	msg_id;
224	uint16_t	msg_type;
225} __packed;
226
227#define STATUS_SIZE		14
228#define STATUS_TLV_LEN		10
229#define	STATUS_FATAL		0x80000000
230
231#define	AF_IPV4			0x1
232#define	AF_IPV6			0x2
233
234struct address_list_tlv {
235	uint16_t	type;
236	uint16_t	length;
237	uint16_t	family;
238	/* address entries */
239} __packed;
240
241#define FEC_ELM_WCARD_LEN	1
242#define FEC_ELM_PREFIX_MIN_LEN	4
243#define FEC_PWID_ELM_MIN_LEN	8
244
245#define	MAP_TYPE_WILDCARD	0x01
246#define	MAP_TYPE_PREFIX		0x02
247#define	MAP_TYPE_PWID		0x80
248#define	MAP_TYPE_GENPWID	0x81
249
250#define CONTROL_WORD_FLAG	0x8000
251#define PW_TYPE_ETHERNET_TAGGED	0x0004
252#define PW_TYPE_ETHERNET	0x0005
253#define DEFAULT_PW_TYPE		PW_TYPE_ETHERNET
254
255/* RFC 4447 Sub-TLV record */
256struct subtlv {
257	uint8_t		type;
258	uint8_t		length;
259};
260#define	SUBTLV_HDR_LEN		2
261
262#define SUBTLV_IFMTU		0x01
263#define SUBTLV_VLANID		0x06
264
265#define FEC_SUBTLV_IFMTU_LEN	4
266#define FEC_SUBTLV_VLANID_LEN	4
267
268struct label_tlv {
269	uint16_t	type;
270	uint16_t	length;
271	uint32_t	label;
272};
273
274#define LABEL_TLV_LEN		8
275
276struct reqid_tlv {
277	uint16_t	type;
278	uint16_t	length;
279	uint32_t	reqid;
280};
281
282#define REQID_TLV_LEN		8
283
284struct pw_status_tlv {
285	uint16_t	type;
286	uint16_t	length;
287	uint32_t	value;
288};
289
290#define PW_STATUS_TLV_LEN	8
291
292#define PW_FORWARDING		0
293#define PW_NOT_FORWARDING	(1 << 0)
294#define PW_LOCAL_RX_FAULT	(1 << 1)
295#define PW_LOCAL_TX_FAULT	(1 << 2)
296#define PW_PSN_RX_FAULT		(1 << 3)
297#define PW_PSN_TX_FAULT		(1 << 4)
298
299#define	NO_LABEL		UINT_MAX
300
301#endif /* !_LDP_H_ */
302