xref: /netbsd/usr.sbin/ldpd/tlv.h (revision 6550d01e)
1 /* $NetBSD: tlv.h,v 1.1 2010/12/08 07:20:15 kefren Exp $ */
2 
3 /*-
4  * Copyright (c) 2010 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Mihai Chelaru <kefren@NetBSD.org>
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _TLV_H_
33 #define _TLV_H_
34 
35 /* TLV messages */
36 #define	TLV_FEC			0x0100
37 #define	TLV_ADDRESS_LIST	0x0101
38 #define	TLV_HOP_COUNT		0x0103
39 #define	TLV_PATH_VECTOR		0x0104
40 #define	TLV_GENERIC_LABEL	0x0200
41 #define	TLV_ATM_LABEL		0x0201
42 #define	TLV_FR_LABEL		0x0202
43 #define	TLV_STATUS		0x0300
44 #define	TLV_EXTENDED_STATUS	0x0301
45 #define	TLV_RETURNED_PDU	0x0302
46 #define	TLV_RETURNED_MESSAGE	0x0303
47 #define	TLV_COMMON_HELLO	0x0400
48 #define	TLV_IPV4_TRANSPORT	0x0401
49 #define	TLV_CONFIGURATION_SEQ	0x0402
50 #define	TLV_IPV6_TRANSPORT	0x0403
51 #define	TLV_COMMON_SESSION	0x0500
52 #define	TLV_ATM_SESSION		0x0501
53 #define	TLV_FR_SESSION		0x0502
54 #define	TLV_LABEL_REQUEST	0x0600
55 
56 /* Some common lengths in order to avoid writing them every time */
57 #define	TLV_TYPE_LENGTH (sizeof(uint16_t) + sizeof(uint16_t))
58 #define	MSGID_SIZE (sizeof(uint32_t))
59 
60 /* General TLV structure */
61 struct tlv {
62 	uint16_t       type;
63 	uint16_t       length;
64 	uint32_t       messageid;
65 	void           *value;
66 	struct ldp_pdu *pdu;
67 }               __packed;
68 
69 /* Common Hello TLV structure */
70 struct common_hello_tlv {
71 	uint16_t       type;
72 	uint16_t       length;
73 	uint16_t       holdtime;
74 	union {
75 		/* XXX: Endianness ?! */
76 		uint8_t        tr:2;
77 		uint16_t       res;
78 	};
79 }               __packed;
80 
81 /* Hello TLV structure */
82 struct hello_tlv {
83 	uint16_t       type;
84 	uint16_t       length;
85 	uint32_t       messageid;
86 	struct common_hello_tlv ch;
87 	/* XXX: optional parameters */
88 }               __packed;
89 
90 /* IPv4 Transport address TLV */
91 struct transport_address_tlv {
92 	uint16_t       type;
93 	uint16_t       length;
94 	struct in_addr  address;
95 }               __packed;
96 
97 
98 #define CS_LEN (sizeof(struct init_tlv) - TLV_TYPE_LENGTH - MSGID_SIZE - \
99 		sizeof(uint32_t))
100 
101 /* Initialization TLV structure */
102 struct init_tlv {
103 	uint16_t       type;
104 	uint16_t       length;
105 	uint32_t       messageid;
106 	/*
107 	 * Common Session Parameters
108 	 */
109 	uint16_t       cs_type;
110 	uint16_t       cs_len;
111 	uint16_t       cs_version;
112 	uint16_t       cs_keepalive;
113 	uint16_t       cs_adpvlim;	/* XXX */
114 	uint16_t       cs_maxpdulen;
115 	struct in_addr  cs_peeraddress;
116 	uint16_t       cs_peeraddrspace;
117 }               __packed;
118 
119 /* Keepalive TLV */
120 struct ka_tlv {			/* Keepalive message */
121 	uint16_t       type;
122 	uint16_t       length;
123 	uint32_t       messageid;
124 }               __packed;
125 
126 /* Notification TLV */
127 struct notification_tlv {
128 	uint16_t       type;
129 	uint16_t       length;
130 	uint32_t       messageid;
131 	uint16_t       status;
132 	uint16_t       st_len;
133 	uint32_t       st_code;
134 	uint32_t       msg_id;
135 	uint32_t       msg_type;
136 }               __packed;
137 
138 /* Address LIST TLV for SEND */
139 struct address_list_tlv {
140 	uint16_t       type;
141 	uint16_t       length;
142 	uint32_t       messageid;
143 	uint16_t       a_type;
144 	uint16_t       a_length;
145 	uint16_t       a_af;
146 	struct in_addr  a_address;
147 }               __packed;
148 
149 /* Real AL TLV used for RCV for now */
150 struct al_tlv {
151 	uint16_t       type;
152 	uint16_t       length;
153 	uint16_t       af;
154 	struct in_addr  address;
155 }               __packed;
156 
157 struct address_tlv {
158 	uint16_t       type;
159 	uint16_t       length;
160 	uint32_t       messageid;
161 }               __packed;
162 
163 /* Label map TLV */
164 struct label_map_tlv {
165 	uint16_t       type;
166 	uint16_t       length;
167 	uint32_t       messageid;
168 }               __packed;
169 
170 /* FEC TLV */
171 struct fec_tlv {
172 	uint16_t       type;
173 	uint16_t       length;
174 }               __packed;
175 
176 struct prefix_tlv {
177 	uint8_t        type;
178 	uint16_t       af;
179 	uint8_t        prelen;
180 	struct in_addr  prefix;
181 }               __packed;
182 
183 struct host_tlv {
184 	uint8_t        type;
185 	uint16_t       af;
186 	uint8_t        length;
187 	struct in_addr  address;
188 }               __packed;
189 
190 struct label_tlv {
191 	uint16_t       type;
192 	uint16_t       length;
193 	uint32_t       label;
194 }               __packed;
195 
196 /* Label Request Message ID TLV */
197 struct label_request_tlv {
198 	uint16_t	type;
199 	uint16_t	length;	/* 4 */
200 	uint32_t	messageid;
201 }		__packed;
202 
203 struct hello_tlv *	get_hello_tlv(unsigned char *, uint);
204 void			debug_tlv(struct tlv *);
205 
206 #endif	/* !_TLV_H_ */
207