xref: /netbsd-src/usr.sbin/ldpd/tlv.h (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /* $NetBSD: tlv.h,v 1.4 2013/07/11 18:02:03 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 }               __packed;
66 
67 /* Common Hello TLV structure */
68 struct common_hello_tlv {
69 	uint16_t       type;
70 	uint16_t       length;
71 	uint16_t       holdtime;
72 	union {
73 		/* XXX: Endianness ?! */
74 		uint8_t        tr:2;
75 		uint16_t       res;
76 	};
77 }               __packed;
78 
79 /* Hello TLV structure */
80 struct hello_tlv {
81 	uint16_t       type;
82 	uint16_t       length;
83 	uint32_t       messageid;
84 	struct common_hello_tlv ch;
85 	/* XXX: optional parameters */
86 }               __packed;
87 
88 /* Transport address TLV */
89 struct transport_address_tlv {
90 	uint16_t       type;
91 	uint16_t       length;
92 	union {
93 		struct in_addr  ip4addr;
94 		struct in6_addr ip6addr;
95 	} address;
96 }               __packed;
97 
98 
99 #define CS_LEN (sizeof(struct init_tlv) - TLV_TYPE_LENGTH - MSGID_SIZE - \
100 		sizeof(uint32_t))
101 
102 /* Initialization TLV structure */
103 struct init_tlv {
104 	uint16_t       type;
105 	uint16_t       length;
106 	uint32_t       messageid;
107 	/*
108 	 * Common Session Parameters
109 	 */
110 	uint16_t       cs_type;
111 	uint16_t       cs_len;
112 	uint16_t       cs_version;
113 	uint16_t       cs_keepalive;
114 	uint16_t       cs_adpvlim;	/* XXX */
115 	uint16_t       cs_maxpdulen;
116 	struct in_addr  cs_peeraddress;
117 	uint16_t       cs_peeraddrspace;
118 }               __packed;
119 
120 /* Keepalive TLV */
121 struct ka_tlv {			/* Keepalive message */
122 	uint16_t       type;
123 	uint16_t       length;
124 	uint32_t       messageid;
125 }               __packed;
126 
127 /* Notification TLV */
128 struct notification_tlv {
129 	uint16_t       type;
130 	uint16_t       length;
131 	uint32_t       messageid;
132 	uint16_t       status;
133 	uint16_t       st_len;
134 	uint32_t       st_code;
135 	uint32_t       msg_id;
136 	uint32_t       msg_type;
137 }               __packed;
138 
139 /* Address LIST TLV for SEND */
140 struct address_list_tlv {
141 	uint16_t       type;
142 	uint16_t       length;
143 	uint32_t       messageid;
144 	uint16_t       a_type;
145 	uint16_t       a_length;
146 	uint16_t       a_af;
147 	struct in_addr  a_address;
148 }               __packed;
149 
150 /* Real AL TLV used for RCV for now */
151 struct al_tlv {
152 	uint16_t       type;
153 	uint16_t       length;
154 	uint16_t       af;
155 	struct in_addr  address;
156 }               __packed;
157 
158 struct address_tlv {
159 	uint16_t       type;
160 	uint16_t       length;
161 	uint32_t       messageid;
162 }               __packed;
163 
164 /* Label map TLV */
165 struct label_map_tlv {
166 	uint16_t       type;
167 	uint16_t       length;
168 	uint32_t       messageid;
169 }               __packed;
170 
171 /* FEC TLV */
172 struct fec_tlv {
173 	uint16_t       type;
174 	uint16_t       length;
175 }               __packed;
176 
177 struct prefix_tlv {
178 	uint8_t        type;
179 	uint16_t       af;
180 	uint8_t        prelen;
181 	struct in_addr  prefix;
182 }               __packed;
183 
184 struct host_tlv {
185 	uint8_t        type;
186 	uint16_t       af;
187 	uint8_t        length;
188 	struct in_addr  address;
189 }               __packed;
190 
191 struct label_tlv {
192 	uint16_t       type;
193 	uint16_t       length;
194 	uint32_t       label;
195 }               __packed;
196 
197 /* Label Request Message ID TLV */
198 struct label_request_tlv {
199 	uint16_t	type;
200 	uint16_t	length;	/* 4 */
201 	uint32_t	messageid;
202 }		__packed;
203 
204 struct hello_tlv *	get_hello_tlv(unsigned char *, uint);
205 void			debug_tlv(struct tlv *);
206 
207 #endif	/* !_TLV_H_ */
208