1 /* $OpenBSD: ospf6.h,v 1.15 2009/04/09 19:00:40 stsp Exp $ */ 2 3 /* 4 * Copyright (c) 2004, 2005, 2007 Esben Norby <norby@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /* OSPF protocol definitions */ 20 21 #ifndef _OSPF_H_ 22 #define _OSPF_H_ 23 24 #include <netinet/in.h> 25 26 /* misc */ 27 #define OSPF6_VERSION 3 28 #define IPPROTO_OSPF 89 29 #define AllSPFRouters "ff02::5" 30 #define AllDRouters "ff02::6" 31 32 #define PACKET_HDR 100 /* XXX used to calculate the IP payload */ 33 34 #define DEFAULT_METRIC 10 35 #define DEFAULT_REDIST_METRIC 100 36 #define MIN_METRIC 1 37 #define MAX_METRIC 65535 /* sum & as-ext lsa use 24bit metrics */ 38 39 #define DEFAULT_PRIORITY 1 40 #define MIN_PRIORITY 0 41 #define MAX_PRIORITY 255 42 43 #define DEFAULT_HELLO_INTERVAL 10 44 #define MIN_HELLO_INTERVAL 1 45 #define MAX_HELLO_INTERVAL 65535 46 47 #define DEFAULT_RTR_DEAD_TIME 40 48 #define MIN_RTR_DEAD_TIME 2 49 #define MAX_RTR_DEAD_TIME 65535 50 51 #define DEFAULT_RXMT_INTERVAL 5 52 #define MIN_RXMT_INTERVAL 5 53 #define MAX_RXMT_INTERVAL 3600 54 55 #define DEFAULT_TRANSMIT_DELAY 1 56 #define MIN_TRANSMIT_DELAY 1 57 #define MAX_TRANSMIT_DELAY 3600 58 59 #define DEFAULT_ADJ_TMOUT 60 60 61 #define DEFAULT_NBR_TMOUT 86400 /* 24 hours */ 62 63 #define DEFAULT_SPF_DELAY 1 64 #define MIN_SPF_DELAY 1 65 #define MAX_SPF_DELAY 10 66 67 #define DEFAULT_SPF_HOLDTIME 5 68 #define MIN_SPF_HOLDTIME 1 69 #define MAX_SPF_HOLDTIME 5 70 71 #define MIN_MD_ID 0 72 #define MAX_MD_ID 255 73 74 #define DEFAULT_INSTANCE_ID 0 75 #define MIN_INSTANCE_ID 0 76 #define MAX_INSTANCE_ID 0 77 78 /* OSPF compatibility flags */ 79 #define OSPF_OPTION_V6 0x01 80 #define OSPF_OPTION_E 0x02 81 #define OSPF_OPTION_x 0x04 /* ignored, should be 0 */ 82 #define OSPF_OPTION_N 0x08 83 #define OSPF_OPTION_R 0x10 84 #define OSPF_OPTION_DC 0x20 85 86 /* OSPF packet types */ 87 #define PACKET_TYPE_HELLO 1 88 #define PACKET_TYPE_DD 2 89 #define PACKET_TYPE_LS_REQUEST 3 90 #define PACKET_TYPE_LS_UPDATE 4 91 #define PACKET_TYPE_LS_ACK 5 92 93 /* LSA */ 94 #define LS_REFRESH_TIME 1800 95 #define MIN_LS_INTERVAL 5 96 #define MIN_LS_ARRIVAL 1 97 #define DEFAULT_AGE 0 98 #define MAX_AGE 3600 99 #define CHECK_AGE 300 100 #define MAX_AGE_DIFF 900 101 #define LS_INFINITY 0xffffff 102 #define RESV_SEQ_NUM 0x80000000 /* reserved and "unused" */ 103 #define INIT_SEQ_NUM 0x80000001 104 #define MAX_SEQ_NUM 0x7fffffff 105 106 /* OSPF header */ 107 struct ospf_hdr { 108 u_int8_t version; 109 u_int8_t type; 110 u_int16_t len; 111 u_int32_t rtr_id; 112 u_int32_t area_id; 113 u_int16_t chksum; 114 u_int8_t instance; 115 u_int8_t zero; /* must be zero */ 116 }; 117 118 /* Hello header (type 1) */ 119 struct hello_hdr { 120 u_int32_t iface_id; 121 u_int32_t opts; /* 8bit rtr_priority + 24bits options */ 122 u_int16_t hello_interval; 123 u_int16_t rtr_dead_interval; 124 u_int32_t d_rtr; 125 u_int32_t bd_rtr; 126 }; 127 128 /* Database Description header (type 2) */ 129 struct db_dscrp_hdr { 130 u_int32_t opts; 131 u_int16_t iface_mtu; 132 u_int8_t zero; /* must be zero */ 133 u_int8_t bits; 134 u_int32_t dd_seq_num; 135 }; 136 137 #define OSPF_DBD_MS 0x01 138 #define OSPF_DBD_M 0x02 139 #define OSPF_DBD_I 0x04 140 141 /* Link State Request header (type 3) */ 142 struct ls_req_hdr { 143 u_int16_t zero; 144 u_int16_t type; 145 u_int32_t ls_id; 146 u_int32_t adv_rtr; 147 }; 148 149 /* Link State Update header (type 4) */ 150 struct ls_upd_hdr { 151 u_int32_t num_lsa; 152 }; 153 154 #define LSA_TYPE_LINK 0x0008 155 #define LSA_TYPE_ROUTER 0x2001 156 #define LSA_TYPE_NETWORK 0x2002 157 #define LSA_TYPE_INTER_A_PREFIX 0x2003 158 #define LSA_TYPE_INTER_A_ROUTER 0x2004 159 #define LSA_TYPE_INTRA_A_PREFIX 0x2009 160 #define LSA_TYPE_EXTERNAL 0x4005 161 162 #define LSA_TYPE_FLAG_U 0x8000 163 #define LSA_TYPE_FLAG_S2 0x4000 164 #define LSA_TYPE_FLAG_S1 0x2000 165 #define LSA_TYPE_SCOPE_MASK 0x6000 166 167 #define LSA_IS_SCOPE_LLOCAL(x) \ 168 (((x) & LSA_TYPE_SCOPE_MASK) == 0) 169 #define LSA_IS_SCOPE_AREA(x) \ 170 (((x) & LSA_TYPE_SCOPE_MASK) == LSA_TYPE_FLAG_S1) 171 #define LSA_IS_SCOPE_AS(x) \ 172 (((x) & LSA_TYPE_SCOPE_MASK) == LSA_TYPE_FLAG_S2) 173 174 #define LINK_TYPE_POINTTOPOINT 1 175 #define LINK_TYPE_TRANSIT_NET 2 176 #define LINK_TYPE_RESERVED 3 177 #define LINK_TYPE_VIRTUAL 4 178 179 /* for some reason they thought 24bit types are fun, make them less a hazard */ 180 #define LSA_24_MASK 0xffffff 181 #define LSA_24_GETHI(x) \ 182 ((x) >> 24) 183 #define LSA_24_GETLO(x) \ 184 ((x) & LSA_24_MASK) 185 #define LSA_24_SETHI(x, y) \ 186 ((x) = ((x) & LSA_24_MASK) | (((y) & 0xff) << 24)) 187 #define LSA_24_SETLO(x, y) \ 188 ((x) = ((y) & LSA_24_MASK) | ((x) & ~LSA_24_MASK)) 189 190 /* LSA headers */ 191 #define LSA_METRIC_MASK 0x00ffffff /* only for sum & as-ext */ 192 #define LSA_ASEXT_E_FLAG 0x80000000 193 194 #define OSPF_RTR_B 0x01 195 #define OSPF_RTR_E 0x02 196 #define OSPF_RTR_V 0x04 197 #define OSPF_RTR_x 0x08 /* ignored, should be 0 */ 198 #define OSPF_RTR_Nt 0x10 199 200 #define OSPF_PREFIX_NU 0x01 201 #define OSPF_PREFIX_LA 0x02 202 #define OSPF_PREFIX_x 0x04 /* ignored, should be 0 */ 203 #define OSPF_PREFIX_P 0x08 204 #define OSPF_PREFIX_DN 0x10 205 206 /* return encoded IPv6 prefix size in bytes depending on the prefixlen */ 207 #define LSA_PREFIXSIZE(x) (((x) + 31)/32 * 4) 208 209 struct lsa_prefix { 210 u_int8_t prefixlen; 211 u_int8_t options; 212 u_int16_t metric; 213 /* + an IPv6 prefix encoded in (prefixlen + 31)/32 words */ 214 }; 215 216 struct lsa_rtr { 217 u_int32_t opts; /* 8bit flags + 24bits options */ 218 }; 219 220 struct lsa_rtr_link { 221 u_int8_t type; 222 u_int8_t dummy; 223 u_int16_t metric; 224 u_int32_t iface_id; 225 u_int32_t nbr_iface_id; 226 u_int32_t nbr_rtr_id; 227 }; 228 229 struct lsa_net { 230 u_int32_t opts; /* 24bits options */ 231 }; 232 233 struct lsa_net_link { 234 u_int32_t att_rtr; 235 }; 236 237 struct lsa_prefix_sum { 238 u_int32_t metric; /* only lower 24 bit */ 239 /* + one prefix */ 240 }; 241 242 struct lsa_rtr_sum { 243 u_int32_t opts; /* lower 24bit options */ 244 u_int32_t metric; /* only lower 24 bit */ 245 u_int32_t dest_rtr_id; 246 }; 247 248 struct lsa_asext { 249 u_int32_t mask; 250 u_int32_t metric; /* lower 24 bit plus E bit */ 251 u_int32_t fw_addr; 252 u_int32_t ext_tag; 253 }; 254 255 struct lsa_link { 256 u_int32_t opts; /* rtr pri & 24bit options */ 257 struct in6_addr lladdr; 258 u_int32_t numprefix; 259 /* + numprefix * lsa_prefix */ 260 }; 261 262 struct lsa_intra_prefix { 263 u_int16_t numprefix; 264 u_int16_t ref_type; 265 u_int32_t ref_ls_id; 266 u_int32_t ref_adv_rtr; 267 /* + numprefix * lsa_prefix */ 268 }; 269 270 struct lsa_hdr { 271 u_int16_t age; 272 u_int16_t type; 273 u_int32_t ls_id; 274 u_int32_t adv_rtr; 275 u_int32_t seq_num; 276 u_int16_t ls_chksum; 277 u_int16_t len; 278 }; 279 280 #define LS_CKSUM_OFFSET ((u_int16_t)(&((struct lsa_hdr *)0)->ls_chksum)) 281 282 struct lsa { 283 struct lsa_hdr hdr; 284 union { 285 struct lsa_rtr rtr; 286 struct lsa_net net; 287 struct lsa_prefix_sum pref_sum; 288 struct lsa_rtr_sum rtr_sum; 289 struct lsa_asext asext; 290 struct lsa_link link; 291 struct lsa_intra_prefix pref_intra; 292 } data; 293 }; 294 295 #endif /* !_OSPF_H_ */ 296