1 /* $OpenBSD: ldp.h,v 1.24 2016/05/23 16:12:28 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 3 37 #define MAX_HOLDTIME 0xffff 38 #define INFINITE_HOLDTIME 0xffff 39 40 #define DEFAULT_KEEPALIVE 180 41 #define MIN_KEEPALIVE 3 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 #define MIN_PWID_ID 1 53 #define MAX_PWID_ID 0xffffffff 54 55 #define DEFAULT_L2VPN_MTU 1500 56 #define MIN_L2VPN_MTU 512 57 #define MAX_L2VPN_MTU 0xffff 58 59 /* LDP message types */ 60 #define MSG_TYPE_NOTIFICATION 0x0001 61 #define MSG_TYPE_HELLO 0x0100 62 #define MSG_TYPE_INIT 0x0200 63 #define MSG_TYPE_KEEPALIVE 0x0201 64 #define MSG_TYPE_ADDR 0x0300 65 #define MSG_TYPE_ADDRWITHDRAW 0x0301 66 #define MSG_TYPE_LABELMAPPING 0x0400 67 #define MSG_TYPE_LABELREQUEST 0x0401 68 #define MSG_TYPE_LABELWITHDRAW 0x0402 69 #define MSG_TYPE_LABELRELEASE 0x0403 70 #define MSG_TYPE_LABELABORTREQ 0x0404 71 72 /* LDP TLV types */ 73 #define TLV_TYPE_FEC 0x0100 74 #define TLV_TYPE_ADDRLIST 0x0101 75 #define TLV_TYPE_HOPCOUNT 0x0103 76 #define TLV_TYPE_PATHVECTOR 0x0104 77 #define TLV_TYPE_GENERICLABEL 0x0200 78 #define TLV_TYPE_ATMLABEL 0x0201 79 #define TLV_TYPE_FRLABEL 0x0202 80 #define TLV_TYPE_STATUS 0x0300 81 #define TLV_TYPE_EXTSTATUS 0x0301 82 #define TLV_TYPE_RETURNEDPDU 0x0302 83 #define TLV_TYPE_RETURNEDMSG 0x0303 84 #define TLV_TYPE_COMMONHELLO 0x0400 85 #define TLV_TYPE_IPV4TRANSADDR 0x0401 86 #define TLV_TYPE_CONFIG 0x0402 87 #define TLV_TYPE_IPV6TRANSADDR 0x0403 88 #define TLV_TYPE_COMMONSESSION 0x0500 89 #define TLV_TYPE_ATMSESSIONPAR 0x0501 90 #define TLV_TYPE_FRSESSION 0x0502 91 #define TLV_TYPE_LABELREQUEST 0x0600 92 /* RFC 4447 */ 93 #define TLV_TYPE_PW_STATUS 0x096A 94 #define TLV_TYPE_PW_IF_PARAM 0x096B 95 #define TLV_TYPE_PW_GROUP_ID 0x096C 96 97 /* LDP header */ 98 struct ldp_hdr { 99 u_int16_t version; 100 u_int16_t length; 101 u_int32_t lsr_id; 102 u_int16_t lspace_id; 103 } __packed; 104 105 #define LDP_HDR_SIZE 10 /* actual size of the LDP header */ 106 #define LDP_HDR_PDU_LEN 6 /* minimum "PDU Length" */ 107 #define LDP_HDR_DEAD_LEN 4 108 109 /* TLV record */ 110 struct tlv { 111 u_int16_t type; 112 u_int16_t length; 113 }; 114 #define TLV_HDR_LEN 4 115 116 struct ldp_msg { 117 u_int16_t type; 118 u_int16_t length; 119 u_int32_t msgid; 120 /* Mandatory Parameters */ 121 /* Optional Parameters */ 122 } __packed; 123 124 #define LDP_MSG_SIZE 8 /* minimum size of LDP message */ 125 #define LDP_MSG_LEN 4 /* minimum "Message Length" */ 126 #define LDP_MSG_DEAD_LEN 4 127 128 #define UNKNOWN_FLAG 0x8000 129 #define FORWARD_FLAG 0xc000 130 131 struct hello_prms_tlv { 132 u_int16_t type; 133 u_int16_t length; 134 u_int16_t holdtime; 135 u_int16_t flags; 136 }; 137 138 #define TARGETED_HELLO 0x8000 139 #define REQUEST_TARG_HELLO 0x4000 140 141 struct hello_prms_opt4_tlv { 142 u_int16_t type; 143 u_int16_t length; 144 u_int32_t value; 145 }; 146 147 148 #define S_SUCCESS 0x00000000 149 #define S_BAD_LDP_ID 0x80000001 150 #define S_BAD_PROTO_VER 0x80000002 151 #define S_BAD_PDU_LEN 0x80000003 152 #define S_UNKNOWN_MSG 0x00000004 153 #define S_BAD_MSG_LEN 0x80000005 154 #define S_UNKNOWN_TLV 0x00000006 155 #define S_BAD_TLV_LEN 0x80000007 156 #define S_BAD_TLV_VAL 0x80000008 157 #define S_HOLDTIME_EXP 0x80000009 158 #define S_SHUTDOWN 0x8000000A 159 #define S_LOOP_DETECTED 0x0000000B 160 #define S_UNKNOWN_FEC 0x0000000C 161 #define S_NO_ROUTE 0x0000000D 162 #define S_NO_LABEL_RES 0x0000000E 163 #define S_AVAILABLE 0x0000000F 164 #define S_NO_HELLO 0x80000010 165 #define S_PARM_ADV_MODE 0x80000011 166 #define S_MAX_PDU_LEN 0x80000012 167 #define S_PARM_L_RANGE 0x80000013 168 #define S_KEEPALIVE_TMR 0x80000014 169 #define S_LAB_REQ_ABRT 0x00000015 170 #define S_MISS_MSG 0x00000016 171 #define S_UNSUP_ADDR 0x00000017 172 #define S_KEEPALIVE_BAD 0x80000018 173 #define S_INTERN_ERR 0x80000019 174 /* RFC 4447 */ 175 #define S_ILLEGAL_CBIT 0x00000024 176 #define S_WRONG_CBIT 0x00000025 177 #define S_INCPT_BITRATE 0x00000026 178 #define S_CEP_MISCONF 0x00000027 179 #define S_PW_STATUS 0x00000028 180 #define S_UNASSIGN_TAI 0x00000029 181 #define S_MISCONF_ERR 0x0000002A 182 #define S_WITHDRAW_MTHD 0x0000002B 183 184 struct sess_prms_tlv { 185 u_int16_t type; 186 u_int16_t length; 187 u_int16_t proto_version; 188 u_int16_t keepalive_time; 189 u_int8_t reserved; 190 u_int8_t pvlim; 191 u_int16_t max_pdu_len; 192 u_int32_t lsr_id; 193 u_int16_t lspace_id; 194 } __packed; 195 196 #define SESS_PRMS_SIZE 18 197 198 struct status_tlv { 199 u_int16_t type; 200 u_int16_t length; 201 u_int32_t status_code; 202 u_int32_t msg_id; 203 u_int16_t msg_type; 204 } __packed; 205 206 #define STATUS_SIZE 14 207 #define STATUS_TLV_LEN 10 208 #define STATUS_FATAL 0x80000000 209 210 #define AF_IPV4 0x1 211 #define AF_IPV6 0x2 212 213 struct address_list_tlv { 214 u_int16_t type; 215 u_int16_t length; 216 u_int16_t family; 217 /* address entries */ 218 } __packed; 219 220 #define FEC_ELM_WCARD_LEN 1 221 #define FEC_ELM_PREFIX_MIN_LEN 4 222 #define FEC_PWID_ELM_MIN_LEN 8 223 224 #define MAP_TYPE_WILDCARD 0x01 225 #define MAP_TYPE_PREFIX 0x02 226 #define MAP_TYPE_PWID 0x80 227 #define MAP_TYPE_GENPWID 0x81 228 229 #define CONTROL_WORD_FLAG 0x8000 230 #define PW_TYPE_ETHERNET_TAGGED 0x0004 231 #define PW_TYPE_ETHERNET 0x0005 232 233 /* RFC 4447 Sub-TLV record */ 234 struct subtlv { 235 u_int8_t type; 236 u_int8_t length; 237 }; 238 #define SUBTLV_HDR_LEN 2 239 240 #define SUBTLV_IFMTU 0x01 241 #define SUBTLV_VLANID 0x06 242 243 #define FEC_SUBTLV_IFMTU_LEN 4 244 #define FEC_SUBTLV_VLANID_LEN 4 245 246 struct label_tlv { 247 u_int16_t type; 248 u_int16_t length; 249 u_int32_t label; 250 }; 251 252 #define LABEL_TLV_LEN 8 253 254 struct reqid_tlv { 255 u_int16_t type; 256 u_int16_t length; 257 u_int32_t reqid; 258 }; 259 260 #define REQID_TLV_LEN 8 261 262 struct pw_status_tlv { 263 u_int16_t type; 264 u_int16_t length; 265 u_int32_t value; 266 }; 267 268 #define PW_STATUS_TLV_LEN 8 269 270 #define PW_FORWARDING 0 271 #define PW_NOT_FORWARDING (1 << 0) 272 #define PW_LOCAL_RX_FAULT (1 << 1) 273 #define PW_LOCAL_TX_FAULT (1 << 2) 274 #define PW_PSN_RX_FAULT (1 << 3) 275 #define PW_PSN_TX_FAULT (1 << 4) 276 277 #define NO_LABEL UINT_MAX 278 279 #endif /* !_LDP_H_ */ 280