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