isis_tlv.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /*
  2. * IS-IS Rout(e)ing protocol - isis_tlv.h
  3. * IS-IS TLV related routines
  4. *
  5. * Copyright (C) 2001,2002 Sampo Saaristo
  6. * Tampere University of Technology
  7. * Institute of Communications Engineering
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public Licenseas published by the Free
  11. * Software Foundation; either version 2 of the License, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. #ifndef _ZEBRA_ISIS_TLV_H
  24. #define _ZEBRA_ISIS_TLV_H
  25. /*
  26. * The list of TLVs we (should) support.
  27. * ____________________________________________________________________________
  28. * Name Value IIH LSP SNP Status
  29. * LAN
  30. * ____________________________________________________________________________
  31. *
  32. * Area Addresses 1 y y n ISO10589
  33. * IIS Neighbors 2 n y n ISO10589
  34. * ES Neighbors 3 n y n ISO10589
  35. * IIS Neighbors 6 y n n ISO10589
  36. * Padding 8 y n n ISO10589
  37. * LSP Entries 9 n n y ISO10589
  38. * Authentication 10 y y y ISO10589, RFC3567
  39. * Checksum 12 y n y RFC3358
  40. * Extended IS Reachability 22 n y n RFC5305
  41. * IS Alias 24 n y n RFC3786
  42. * IP Int. Reachability 128 n y n RFC1195
  43. * Protocols Supported 129 y y n RFC1195
  44. * IP Ext. Reachability 130 n y n RFC1195
  45. * IDRPI 131 n y y RFC1195
  46. * IP Interface Address 132 y y n RFC1195
  47. * TE Router ID 134 n y n RFC5305
  48. * Extended IP Reachability 135 n y n RFC5305
  49. * Dynamic Hostname 137 n y n RFC2763
  50. * Shared Risk Link Group 138 n y y RFC5307
  51. * Inter-AS Reachability 141 n y n RFC5316
  52. * Restart TLV 211 y n n RFC3847
  53. * MT IS Reachability 222 n y n RFC5120
  54. * MT Supported 229 y y n RFC5120
  55. * IPv6 Interface Address 232 y y n RFC5308
  56. * MT IP Reachability 235 n y n RFC5120
  57. * IPv6 IP Reachability 236 n y n RFC5308
  58. * MT IPv6 IP Reachability 237 n y n RFC5120
  59. * P2P Adjacency State 240 y n n RFC3373
  60. * IIH Sequence Number 241 y n n draft-shen-isis-iih-sequence
  61. * Router Capability 242 n y n RFC4971
  62. *
  63. *
  64. * IS Reachability sub-TLVs we support (See isis_te.[c,h])
  65. * ____________________________________________________________________________
  66. * Name Value Status
  67. * ____________________________________________________________________________
  68. * Administartive group (color) 3 RFC5305
  69. * Link Local/Remote Identifiers 4 RFC5307
  70. * IPv4 interface address 6 RFC5305
  71. * IPv4 neighbor address 8 RFC5305
  72. * Maximum link bandwidth 9 RFC5305
  73. * Reservable link bandwidth 10 RFC5305
  74. * Unreserved bandwidth 11 RFC5305
  75. * TE Default metric 18 RFC5305
  76. * Link Protection Type 20 RFC5307
  77. * Interface Switching Capability 21 RFC5307
  78. * Remote AS number 24 RFC5316
  79. * IPv4 Remote ASBR identifier 25 RFC5316
  80. *
  81. *
  82. * IP Reachability sub-TLVs we (should) support.
  83. * ____________________________________________________________________________
  84. * Name Value Status
  85. * ____________________________________________________________________________
  86. * 32bit administrative tag 1 RFC5130
  87. * 64bit administrative tag 2 RFC5130
  88. * Management prefix color 117 RFC5120
  89. */
  90. #define AREA_ADDRESSES 1
  91. #define IS_NEIGHBOURS 2
  92. #define ES_NEIGHBOURS 3
  93. #define LAN_NEIGHBOURS 6
  94. #define PADDING 8
  95. #define LSP_ENTRIES 9
  96. #define AUTH_INFO 10
  97. #define CHECKSUM 12
  98. #define TE_IS_NEIGHBOURS 22
  99. #define IS_ALIAS 24
  100. #define IPV4_INT_REACHABILITY 128
  101. #define PROTOCOLS_SUPPORTED 129
  102. #define IPV4_EXT_REACHABILITY 130
  103. #define IDRP_INFO 131
  104. #define IPV4_ADDR 132
  105. #define TE_ROUTER_ID 134
  106. #define TE_IPV4_REACHABILITY 135
  107. #define DYNAMIC_HOSTNAME 137
  108. #define GRACEFUL_RESTART 211
  109. #define IPV6_ADDR 232
  110. #define IPV6_REACHABILITY 236
  111. #define WAY3_HELLO 240
  112. #define ROUTER_INFORMATION 242
  113. #define AUTH_INFO_HDRLEN 3
  114. #define MAX_TLV_LEN 255
  115. #define IS_NEIGHBOURS_LEN (ISIS_SYS_ID_LEN + 5)
  116. #define LAN_NEIGHBOURS_LEN 6
  117. #define LSP_ENTRIES_LEN (10 + ISIS_SYS_ID_LEN) /* FIXME: should be entry */
  118. #define IPV4_REACH_LEN 12
  119. #define IPV6_REACH_LEN 22
  120. #define TE_IPV4_REACH_LEN 9
  121. #define MAX_SUBTLV_SIZE 256
  122. /* struct for neighbor */
  123. struct is_neigh
  124. {
  125. struct metric metrics;
  126. u_char neigh_id[ISIS_SYS_ID_LEN + 1];
  127. };
  128. /* struct for te metric */
  129. struct te_is_neigh
  130. {
  131. u_char neigh_id[ISIS_SYS_ID_LEN + 1];
  132. u_char te_metric[3];
  133. u_char sub_tlvs_length;
  134. /* Theorical Maximum SubTLVs is 256 because the sub_tlvs_length is 8 bits */
  135. /* Practically, 118 bytes are necessary to store all supported TE parameters */
  136. /* FIXME: A pointer will use less memory, but need to be free */
  137. /* which is hard to fix, especially within free_tlvs() function */
  138. /* and malloc() / free() as a CPU cost compared to the memory usage */
  139. u_char sub_tlvs[MAX_SUBTLV_SIZE]; /* SUB TLVs storage */
  140. };
  141. /* Decode and encode three-octet metric into host byte order integer */
  142. #define GET_TE_METRIC(t) \
  143. (((unsigned)(t)->te_metric[0]<<16) | ((t)->te_metric[1]<<8) | \
  144. (t)->te_metric[2])
  145. #define SET_TE_METRIC(t, m) \
  146. (((t)->te_metric[0] = (m) >> 16), \
  147. ((t)->te_metric[1] = (m) >> 8), \
  148. ((t)->te_metric[2] = (m)))
  149. /* struct for es neighbors */
  150. struct es_neigh
  151. {
  152. struct metric metrics;
  153. /* approximate position of first, we use the
  154. * length ((uchar*)metric-1) to know all */
  155. u_char first_es_neigh[ISIS_SYS_ID_LEN];
  156. };
  157. struct partition_desig_level2_is
  158. {
  159. struct list *isis_system_ids;
  160. };
  161. /* struct for lan neighbors */
  162. struct lan_neigh
  163. {
  164. u_char LAN_addr[6];
  165. };
  166. #ifdef __SUNPRO_C
  167. #pragma pack(1)
  168. #endif
  169. /* struct for LSP entry */
  170. struct lsp_entry
  171. {
  172. u_int16_t rem_lifetime;
  173. u_char lsp_id[ISIS_SYS_ID_LEN + 2];
  174. u_int32_t seq_num;
  175. u_int16_t checksum;
  176. } __attribute__ ((packed));
  177. #ifdef __SUNPRO_C
  178. #pragma pack()
  179. #endif
  180. /* struct for checksum */
  181. struct checksum
  182. {
  183. u_int16_t checksum;
  184. };
  185. /* ipv4 reachability */
  186. struct ipv4_reachability
  187. {
  188. struct metric metrics;
  189. struct in_addr prefix;
  190. struct in_addr mask;
  191. };
  192. /* te router id */
  193. struct te_router_id
  194. {
  195. struct in_addr id;
  196. };
  197. /* te ipv4 reachability */
  198. struct te_ipv4_reachability
  199. {
  200. u_int32_t te_metric;
  201. u_char control;
  202. u_char prefix_start; /* since this is variable length by nature it only */
  203. }; /* points to an approximate location */
  204. struct idrp_info
  205. {
  206. u_char len;
  207. u_char *value;
  208. };
  209. #ifdef HAVE_IPV6
  210. struct ipv6_reachability
  211. {
  212. u_int32_t metric;
  213. u_char control_info;
  214. u_char prefix_len;
  215. u_char prefix[16];
  216. };
  217. /* bits in control_info */
  218. #define CTRL_INFO_DIRECTION 0x80
  219. #define DIRECTION_UP 0x00
  220. #define DIRECTION_DOWN 0x80
  221. #define CTRL_INFO_DISTRIBUTION 0x40
  222. #define DISTRIBUTION_INTERNAL 0x00
  223. #define DISTRIBUTION_EXTERNAL 0x40
  224. #define CTRL_INFO_SUBTLVS 0x20
  225. #endif /* HAVE_IPV6 */
  226. /*
  227. * Pointer to each tlv type, filled by parse_tlvs()
  228. */
  229. struct tlvs
  230. {
  231. struct checksum *checksum;
  232. struct hostname *hostname;
  233. struct nlpids *nlpids;
  234. struct te_router_id *router_id;
  235. struct list *area_addrs;
  236. struct list *is_neighs;
  237. struct list *te_is_neighs;
  238. struct list *es_neighs;
  239. struct list *lsp_entries;
  240. struct list *prefix_neighs;
  241. struct list *lan_neighs;
  242. struct list *ipv4_addrs;
  243. struct list *ipv4_int_reachs;
  244. struct list *ipv4_ext_reachs;
  245. struct list *te_ipv4_reachs;
  246. #ifdef HAVE_IPV6
  247. struct list *ipv6_addrs;
  248. struct list *ipv6_reachs;
  249. #endif
  250. struct isis_passwd auth_info;
  251. };
  252. /*
  253. * Own definitions - used to bitmask found and expected
  254. */
  255. #define TLVFLAG_AREA_ADDRS (1<<0)
  256. #define TLVFLAG_IS_NEIGHS (1<<1)
  257. #define TLVFLAG_ES_NEIGHS (1<<2)
  258. #define TLVFLAG_PARTITION_DESIG_LEVEL2_IS (1<<3)
  259. #define TLVFLAG_PREFIX_NEIGHS (1<<4)
  260. #define TLVFLAG_LAN_NEIGHS (1<<5)
  261. #define TLVFLAG_LSP_ENTRIES (1<<6)
  262. #define TLVFLAG_PADDING (1<<7)
  263. #define TLVFLAG_AUTH_INFO (1<<8)
  264. #define TLVFLAG_IPV4_INT_REACHABILITY (1<<9)
  265. #define TLVFLAG_NLPID (1<<10)
  266. #define TLVFLAG_IPV4_EXT_REACHABILITY (1<<11)
  267. #define TLVFLAG_IPV4_ADDR (1<<12)
  268. #define TLVFLAG_DYN_HOSTNAME (1<<13)
  269. #define TLVFLAG_IPV6_ADDR (1<<14)
  270. #define TLVFLAG_IPV6_REACHABILITY (1<<15)
  271. #define TLVFLAG_TE_IS_NEIGHS (1<<16)
  272. #define TLVFLAG_TE_IPV4_REACHABILITY (1<<17)
  273. #define TLVFLAG_3WAY_HELLO (1<<18)
  274. #define TLVFLAG_TE_ROUTER_ID (1<<19)
  275. #define TLVFLAG_CHECKSUM (1<<20)
  276. #define TLVFLAG_GRACEFUL_RESTART (1<<21)
  277. void init_tlvs (struct tlvs *tlvs, uint32_t expected);
  278. void free_tlvs (struct tlvs *tlvs);
  279. int parse_tlvs (char *areatag, u_char * stream, int size,
  280. u_int32_t * expected, u_int32_t * found, struct tlvs *tlvs,
  281. u_int32_t * auth_tlv_offset);
  282. int add_tlv (u_char, u_char, u_char *, struct stream *);
  283. void free_tlv (void *val);
  284. int tlv_add_area_addrs (struct list *area_addrs, struct stream *stream);
  285. int tlv_add_is_neighs (struct list *is_neighs, struct stream *stream);
  286. int tlv_add_te_is_neighs (struct list *te_is_neighs, struct stream *stream);
  287. int tlv_add_lan_neighs (struct list *lan_neighs, struct stream *stream);
  288. int tlv_add_nlpid (struct nlpids *nlpids, struct stream *stream);
  289. int tlv_add_checksum (struct checksum *checksum, struct stream *stream);
  290. int tlv_add_authinfo (u_char auth_type, u_char authlen, u_char *auth_value,
  291. struct stream *stream);
  292. int tlv_add_ip_addrs (struct list *ip_addrs, struct stream *stream);
  293. int tlv_add_in_addr (struct in_addr *, struct stream *stream, u_char tag);
  294. int tlv_add_dynamic_hostname (struct hostname *hostname,
  295. struct stream *stream);
  296. int tlv_add_lsp_entries (struct list *lsps, struct stream *stream);
  297. int tlv_add_ipv4_int_reachs (struct list *ipv4_reachs, struct stream *stream);
  298. int tlv_add_ipv4_ext_reachs (struct list *ipv4_reachs, struct stream *stream);
  299. int tlv_add_te_ipv4_reachs (struct list *te_ipv4_reachs, struct stream *stream);
  300. #ifdef HAVE_IPV6
  301. int tlv_add_ipv6_addrs (struct list *ipv6_addrs, struct stream *stream);
  302. int tlv_add_ipv6_reachs (struct list *ipv6_reachs, struct stream *stream);
  303. #endif /* HAVE_IPV6 */
  304. int tlv_add_padding (struct stream *stream);
  305. #endif /* _ZEBRA_ISIS_TLV_H */