ldp.h revision 1.4
1/*	$OpenBSD: ldp.h,v 1.4 2010/04/15 14:55:12 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 */
89struct 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 */
100struct ldp_msg {
101	u_int16_t	type;
102	u_int16_t	length;
103	u_int32_t	msgid;
104	/* Mandatory Parameters */
105	/* Optional Parameters */
106};
107
108#define LDP_MSG_LEN		8
109#define	TLV_HDR_LEN		4
110
111#define	UNKNOWN_FLAGS_MASK	0xc000
112#define	UNKNOWN_FLAG		0x8000
113#define	FORWARD_FLAG		0xc000
114
115#define TARGETED_HELLO		0x8000
116#define REQUEST_TARG_HELLO	0x4000
117
118struct hello_prms_tlv {
119	u_int16_t	type;
120	u_int16_t	length;
121	u_int16_t	holdtime;
122	u_int16_t	reserved;
123};
124
125#define	S_SUCCESS	0x00000000
126#define	S_BAD_LDP_ID	0x80000001
127#define	S_BAD_PROTO_VER	0x80000002
128#define	S_BAD_PDU_LEN	0x80000003
129#define	S_UNKNOWN_MSG	0x00000004
130#define	S_BAD_MSG_LEN	0x80000005
131#define	S_UNKNOWN_TLV	0x00000006
132#define	S_BAD_TLV_LEN	0x80000007
133#define	S_BAD_TLV_VAL	0x80000008
134#define	S_HOLDTIME_EXP	0x80000009
135#define	S_SHUTDOWN	0x8000000A
136#define	S_LOOP_DETECTED	0x0000000B
137#define	S_UNKNOWN_FEC	0x0000000C
138#define	S_NO_ROUTE	0x0000000D
139#define	S_NO_LABEL_RES	0x0000000E
140#define	S_AVAILABLE	0x0000000F
141#define	S_NO_HELLO	0x80000010
142#define	S_PARM_ADV_MODE	0x80000011
143#define	S_MAX_PDU_LEN	0x80000012
144#define	S_PARM_L_RANGE	0x80000013
145#define	S_KEEPALIVE_TMR	0x80000014
146#define	S_LAB_REQ_ABRT	0x00000015
147#define	S_MISS_MSG	0x00000016
148#define	S_UNSUP_ADDR	0x00000017
149#define	S_KEEPALIVE_BAD	0x80000018
150#define	S_INTERN_ERR	0x80000019
151
152struct sess_prms_tlv {
153	u_int16_t	type;
154	u_int16_t	length;
155	u_int16_t	proto_version;
156	u_int16_t	keepalive_time;
157	u_int8_t	reserved;
158	u_int8_t	pvlim;
159	u_int16_t	max_pdu_len;
160	u_int32_t	lsr_id;
161	u_int16_t	lspace_id;
162};
163
164#define SESS_PRMS_SIZE		18
165
166struct status_tlv {
167	u_int16_t	type;
168	u_int16_t	length;
169	u_int32_t	status_code;
170	u_int32_t	msg_id;
171	u_int16_t	msg_type;
172};
173
174#define STATUS_SIZE		14
175#define STATUS_TLV_LEN		10
176#define	STATUS_FATAL		0x80000000
177
178struct address_list_tlv {
179	u_int16_t	type;
180	u_int16_t	length;
181	u_int16_t	family;
182	/* address entries */
183};
184
185#define	BASIC_LABEL_MAP_LEN	24
186
187#define	ADDR_IPV4		0x1
188#define	ADDR_IPV6		0x2
189
190struct fec_tlv {
191	u_int16_t	type;
192	u_int16_t	length;
193	/* fec elm entries */
194};
195
196/* This struct is badly aligned so use two 32 bit fields */
197struct fec_elm {
198	u_int32_t	hdr;
199	u_int32_t	addr;
200};
201
202#define FEC_ELM_MIN_LEN		4
203
204#define	FEC_WILDCARD		0x01
205#define	FEC_PREFIX		0x02
206#define	FEC_ADDRESS		0x03
207
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 hello_opt_parms_tlv {
219	u_int16_t	type;
220	u_int16_t	length;
221	u_int32_t	value;
222};
223
224#define	NO_LABEL		UINT_MAX
225
226#endif /* !_LDP_H_ */
227