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