summaryrefslogtreecommitdiff
path: root/usr.sbin/ldpd/ldp.h
blob: a083038012457e955e045f2f0529e663de7f4291 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*	$OpenBSD: ldp.h,v 1.19 2015/07/21 04:52:29 renato Exp $ */

/*
 * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
 * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/* LDP protocol definitions */

#ifndef _LDP_H_
#define _LDP_H_

#include <netinet/in.h>

/* misc */
#define LDP_VERSION		1
#define LDP_PORT		646
#define AllRouters		"224.0.0.2"

#define LDP_MAX_LEN		4096

#define LINK_DFLT_HOLDTIME	15
#define TARGETED_DFLT_HOLDTIME	45
#define MIN_HOLDTIME		1
#define MAX_HOLDTIME		0xffff
#define	INFINITE_HOLDTIME	0xffff

#define DEFAULT_KEEPALIVE	180
#define MIN_KEEPALIVE		1
#define MAX_KEEPALIVE		0xffff
#define KEEPALIVE_PER_PERIOD	3

#define	DEFAULT_HELLO_INTERVAL	5
#define	MIN_HELLO_INTERVAL	1
#define	MAX_HELLO_INTERVAL	0xffff

#define	INIT_DELAY_TMR		15
#define	MAX_DELAY_TMR		120

#define	MIN_PWID_ID		1
#define	MAX_PWID_ID		0xffffffff

#define	DEFAULT_L2VPN_MTU	1500
#define	MIN_L2VPN_MTU		512
#define	MAX_L2VPN_MTU		0xffff

/* LDP message types */
#define MSG_TYPE_NOTIFICATION	0x0001
#define MSG_TYPE_HELLO		0x0100
#define MSG_TYPE_INIT		0x0200
#define MSG_TYPE_KEEPALIVE	0x0201
#define MSG_TYPE_ADDR		0x0300
#define MSG_TYPE_ADDRWITHDRAW	0x0301
#define MSG_TYPE_LABELMAPPING	0x0400
#define MSG_TYPE_LABELREQUEST	0x0401
#define MSG_TYPE_LABELWITHDRAW	0x0402
#define MSG_TYPE_LABELRELEASE	0x0403
#define MSG_TYPE_LABELABORTREQ	0x0404

/* LDP TLV types */
#define TLV_TYPE_FEC		0x0100
#define TLV_TYPE_ADDRLIST	0x0101
#define TLV_TYPE_HOPCOUNT	0x0103
#define TLV_TYPE_PATHVECTOR	0x0104
#define TLV_TYPE_GENERICLABEL	0x0200
#define TLV_TYPE_ATMLABEL	0x0201
#define TLV_TYPE_FRLABEL	0x0202
#define TLV_TYPE_STATUS		0x0300
#define TLV_TYPE_EXTSTATUS	0x0301
#define TLV_TYPE_RETURNEDPDU	0x0302
#define TLV_TYPE_RETURNEDMSG	0x0303
#define TLV_TYPE_COMMONHELLO	0x0400
#define TLV_TYPE_IPV4TRANSADDR	0x0401
#define TLV_TYPE_CONFIG		0x0402
#define TLV_TYPE_IPV6TRANSADDR	0x0403
#define TLV_TYPE_COMMONSESSION	0x0500
#define TLV_TYPE_ATMSESSIONPAR	0x0501
#define TLV_TYPE_FRSESSION	0x0502
#define TLV_TYPE_LABELREQUEST	0x0600
/* RFC 4447 */
#define TLV_TYPE_PW_STATUS	0x096A
#define TLV_TYPE_PW_IF_PARAM	0x096B
#define TLV_TYPE_PW_GROUP_ID	0x096C

/* LDP header */
struct ldp_hdr {
	u_int16_t		version;
	u_int16_t		length;
	u_int32_t		lsr_id;
	u_int16_t		lspace_id;
} __packed;

#define	LDP_HDR_SIZE		10
#define	LDP_HDR_PDU_LEN		6

/* TLV record */
struct tlv {
	u_int16_t	type;
	u_int16_t	length;
};
#define	TLV_HDR_LEN		4

struct ldp_msg {
	u_int16_t	type;
	u_int16_t	length;
	u_int32_t	msgid;
	/* Mandatory Parameters */
	/* Optional Parameters */
} __packed;

#define LDP_MSG_LEN		8

#define	UNKNOWN_FLAG		0x8000
#define	FORWARD_FLAG		0xc000

#define TARGETED_HELLO		0x8000
#define REQUEST_TARG_HELLO	0x4000

struct hello_prms_tlv {
	u_int16_t	type;
	u_int16_t	length;
	u_int16_t	holdtime;
	u_int16_t	flags;
};

struct hello_prms_opt4_tlv {
	u_int16_t	type;
	u_int16_t	length;
	u_int32_t	value;
};

#define HELLO_PRMS_SIZE		8

#define	S_SUCCESS	0x00000000
#define	S_BAD_LDP_ID	0x80000001
#define	S_BAD_PROTO_VER	0x80000002
#define	S_BAD_PDU_LEN	0x80000003
#define	S_UNKNOWN_MSG	0x00000004
#define	S_BAD_MSG_LEN	0x80000005
#define	S_UNKNOWN_TLV	0x00000006
#define	S_BAD_TLV_LEN	0x80000007
#define	S_BAD_TLV_VAL	0x80000008
#define	S_HOLDTIME_EXP	0x80000009
#define	S_SHUTDOWN	0x8000000A
#define	S_LOOP_DETECTED	0x0000000B
#define	S_UNKNOWN_FEC	0x0000000C
#define	S_NO_ROUTE	0x0000000D
#define	S_NO_LABEL_RES	0x0000000E
#define	S_AVAILABLE	0x0000000F
#define	S_NO_HELLO	0x80000010
#define	S_PARM_ADV_MODE	0x80000011
#define	S_MAX_PDU_LEN	0x80000012
#define	S_PARM_L_RANGE	0x80000013
#define	S_KEEPALIVE_TMR	0x80000014
#define	S_LAB_REQ_ABRT	0x00000015
#define	S_MISS_MSG	0x00000016
#define	S_UNSUP_ADDR	0x00000017
#define	S_KEEPALIVE_BAD	0x80000018
#define	S_INTERN_ERR	0x80000019
/* RFC 4447 */
#define S_ILLEGAL_CBIT	0x00000024
#define S_WRONG_CBIT	0x00000025
#define S_INCPT_BITRATE	0x00000026
#define S_CEP_MISCONF	0x00000027
#define S_PW_STATUS	0x00000028
#define S_UNASSIGN_TAI	0x00000029
#define S_MISCONF_ERR	0x0000002A
#define S_WITHDRAW_MTHD	0x0000002B

struct sess_prms_tlv {
	u_int16_t	type;
	u_int16_t	length;
	u_int16_t	proto_version;
	u_int16_t	keepalive_time;
	u_int8_t	reserved;
	u_int8_t	pvlim;
	u_int16_t	max_pdu_len;
	u_int32_t	lsr_id;
	u_int16_t	lspace_id;
} __packed;

#define SESS_PRMS_SIZE		18

struct status_tlv {
	u_int16_t	type;
	u_int16_t	length;
	u_int32_t	status_code;
	u_int32_t	msg_id;
	u_int16_t	msg_type;
} __packed;

#define STATUS_SIZE		14
#define STATUS_TLV_LEN		10
#define	STATUS_FATAL		0x80000000

#define	AF_IPV4			0x1
#define	AF_IPV6			0x2

struct address_list_tlv {
	u_int16_t	type;
	u_int16_t	length;
	u_int16_t	family;
	/* address entries */
} __packed;

#define FEC_ELM_WCARD_LEN	1
#define FEC_ELM_PREFIX_MIN_LEN	4
#define FEC_PWID_ELM_MIN_LEN	8
#define	FEC_WILDCARD		0x01
#define	FEC_PREFIX		0x02
#define	FEC_PWID		0x80
#define	FEC_GENPWID		0x81

#define CONTROL_WORD_FLAG	0x8000
#define PW_TYPE_ETHERNET_TAGGED	0x0004
#define PW_TYPE_ETHERNET	0x0005

/* RFC 4447 Sub-TLV record */
struct subtlv {
	u_int8_t	type;
	u_int8_t	length;
};
#define	SUBTLV_HDR_LEN		2

#define SUBTLV_IFMTU		0x01
#define SUBTLV_VLANID		0x06

#define FEC_SUBTLV_IFMTU_LEN	4
#define FEC_SUBTLV_VLANID_LEN	4

struct label_tlv {
	u_int16_t	type;
	u_int16_t	length;
	u_int32_t	label;
};

#define LABEL_TLV_LEN		8

struct reqid_tlv {
	u_int16_t	type;
	u_int16_t	length;
	u_int32_t	reqid;
};

#define REQID_TLV_LEN		8

struct pw_status_tlv {
	u_int16_t	type;
	u_int16_t	length;
	u_int32_t	value;
};

#define PW_STATUS_TLV_LEN	8

#define PW_FORWARDING		0
#define PW_NOT_FORWARDING	(1 << 0)
#define PW_LOCAL_RX_FAULT	(1 << 1)
#define PW_LOCAL_TX_FAULT	(1 << 2)
#define PW_PSN_RX_FAULT		(1 << 3)
#define PW_PSN_TX_FAULT		(1 << 4)

#define	NO_LABEL		UINT_MAX

#endif /* !_LDP_H_ */