ldp.h revision 1.14
1/*	$OpenBSD: ldp.h,v 1.14 2013/10/15 16:47:24 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 AllRouters		"224.0.0.2"
31
32#define LDP_MAX_LEN		4096
33
34#define LINK_DFLT_HOLDTIME	15
35#define TARGETED_DFLT_HOLDTIME	45
36#define MIN_HOLDTIME		1
37#define MAX_HOLDTIME		0xffff
38#define	INFINITE_HOLDTIME	0xffff
39
40#define DEFAULT_KEEPALIVE	180
41#define MIN_KEEPALIVE		1
42#define MAX_KEEPALIVE		0xffff
43#define KEEPALIVE_PER_PERIOD	3
44
45#define	DEFAULT_HELLO_INTERVAL	5
46#define	MIN_HELLO_INTERVAL	1
47#define	MAX_HELLO_INTERVAL	0xffff
48
49#define	INIT_DELAY_TMR		15
50#define	MAX_DELAY_TMR		120
51
52/* LDP message types */
53#define MSG_TYPE_NOTIFICATION	0x0001
54#define MSG_TYPE_HELLO		0x0100
55#define MSG_TYPE_INIT		0x0200
56#define MSG_TYPE_KEEPALIVE	0x0201
57#define MSG_TYPE_ADDR		0x0300
58#define MSG_TYPE_ADDRWITHDRAW	0x0301
59#define MSG_TYPE_LABELMAPPING	0x0400
60#define MSG_TYPE_LABELREQUEST	0x0401
61#define MSG_TYPE_LABELWITHDRAW	0x0402
62#define MSG_TYPE_LABELRELEASE	0x0403
63#define MSG_TYPE_LABELABORTREQ	0x0404
64
65/* LDP TLV types */
66#define TLV_TYPE_FEC		0x0100
67#define TLV_TYPE_ADDRLIST	0x0101
68#define TLV_TYPE_HOPCOUNT	0x0103
69#define TLV_TYPE_PATHVECTOR	0x0104
70#define TLV_TYPE_GENERICLABEL	0x0200
71#define TLV_TYPE_ATMLABEL	0x0201
72#define TLV_TYPE_FRLABEL	0x0202
73#define TLV_TYPE_STATUS		0x0300
74#define TLV_TYPE_EXTSTATUS	0x0301
75#define TLV_TYPE_RETURNEDPDU	0x0302
76#define TLV_TYPE_RETURNEDMSG	0x0303
77#define TLV_TYPE_COMMONHELLO	0x0400
78#define TLV_TYPE_IPV4TRANSADDR	0x0401
79#define TLV_TYPE_CONFIG		0x0402
80#define TLV_TYPE_IPV6TRANSADDR	0x0403
81#define TLV_TYPE_COMMONSESSION	0x0500
82#define TLV_TYPE_ATMSESSIONPAR	0x0501
83#define TLV_TYPE_FRSESSION	0x0502
84#define TLV_TYPE_LABELREQUEST	0x0600
85
86/* LDP header */
87struct ldp_hdr {
88	u_int16_t		version;
89	u_int16_t		length;
90	u_int32_t		lsr_id;
91	u_int16_t		lspace_id;
92} __packed;
93
94#define	LDP_HDR_SIZE		10
95
96/* TLV record */
97struct tlv {
98	u_int16_t	type;
99	u_int16_t	length;
100};
101#define	TLV_HDR_LEN		4
102
103struct ldp_msg {
104	u_int16_t	type;
105	u_int16_t	length;
106	u_int32_t	msgid;
107	/* Mandatory Parameters */
108	/* Optional Parameters */
109} __packed;
110
111#define LDP_MSG_LEN		8
112
113#define	UNKNOWN_FLAG		0x8000
114#define	FORWARD_FLAG		0xc000
115
116#define TARGETED_HELLO		0x8000
117#define REQUEST_TARG_HELLO	0x4000
118
119struct hello_prms_tlv {
120	u_int16_t	type;
121	u_int16_t	length;
122	u_int16_t	holdtime;
123	u_int16_t	flags;
124};
125
126struct hello_prms_opt4_tlv {
127	u_int16_t	type;
128	u_int16_t	length;
129	u_int32_t	value;
130};
131
132#define HELLO_PRMS_SIZE		8
133
134#define	S_SUCCESS	0x00000000
135#define	S_BAD_LDP_ID	0x80000001
136#define	S_BAD_PROTO_VER	0x80000002
137#define	S_BAD_PDU_LEN	0x80000003
138#define	S_UNKNOWN_MSG	0x00000004
139#define	S_BAD_MSG_LEN	0x80000005
140#define	S_UNKNOWN_TLV	0x00000006
141#define	S_BAD_TLV_LEN	0x80000007
142#define	S_BAD_TLV_VAL	0x80000008
143#define	S_HOLDTIME_EXP	0x80000009
144#define	S_SHUTDOWN	0x8000000A
145#define	S_LOOP_DETECTED	0x0000000B
146#define	S_UNKNOWN_FEC	0x0000000C
147#define	S_NO_ROUTE	0x0000000D
148#define	S_NO_LABEL_RES	0x0000000E
149#define	S_AVAILABLE	0x0000000F
150#define	S_NO_HELLO	0x80000010
151#define	S_PARM_ADV_MODE	0x80000011
152#define	S_MAX_PDU_LEN	0x80000012
153#define	S_PARM_L_RANGE	0x80000013
154#define	S_KEEPALIVE_TMR	0x80000014
155#define	S_LAB_REQ_ABRT	0x00000015
156#define	S_MISS_MSG	0x00000016
157#define	S_UNSUP_ADDR	0x00000017
158#define	S_KEEPALIVE_BAD	0x80000018
159#define	S_INTERN_ERR	0x80000019
160
161struct sess_prms_tlv {
162	u_int16_t	type;
163	u_int16_t	length;
164	u_int16_t	proto_version;
165	u_int16_t	keepalive_time;
166	u_int8_t	reserved;
167	u_int8_t	pvlim;
168	u_int16_t	max_pdu_len;
169	u_int32_t	lsr_id;
170	u_int16_t	lspace_id;
171} __packed;
172
173#define SESS_PRMS_SIZE		18
174
175struct status_tlv {
176	u_int16_t	type;
177	u_int16_t	length;
178	u_int32_t	status_code;
179	u_int32_t	msg_id;
180	u_int16_t	msg_type;
181} __packed;
182
183#define STATUS_SIZE		14
184#define STATUS_TLV_LEN		10
185#define	STATUS_FATAL		0x80000000
186
187struct address_list_tlv {
188	u_int16_t	type;
189	u_int16_t	length;
190	u_int16_t	family;
191	/* address entries */
192} __packed;
193
194#define	BASIC_LABEL_MAP_LEN	24
195
196#define	ADDR_IPV4		0x1
197#define	ADDR_IPV6		0x2
198
199/* This struct is badly aligned so use two 32 bit fields */
200struct fec_elm {
201	u_int32_t	hdr;
202	u_int32_t	addr;
203};
204
205#define FEC_ELM_MIN_LEN		4
206#define	FEC_WILDCARD		0x01
207#define	FEC_PREFIX		0x02
208#define	FEC_IPV4		0x0001
209
210struct label_tlv {
211	u_int16_t	type;
212	u_int16_t	length;
213	u_int32_t	label;
214};
215
216#define LABEL_TLV_LEN		8
217
218struct reqid_tlv {
219	u_int16_t	type;
220	u_int16_t	length;
221	u_int32_t	reqid;
222};
223
224#define REQID_TLV_LEN		8
225
226#define	NO_LABEL		UINT_MAX
227
228#endif /* !_LDP_H_ */
229