1 /* $OpenBSD: ospf.h,v 1.23 2013/01/17 09:14:15 markus Exp $ */ 2 3 /* 4 * Copyright (c) 2004, 2005 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 #include <stddef.h> 26 27 /* misc */ 28 #define OSPF_VERSION 2 29 #define IPPROTO_OSPF 89 30 #define AllSPFRouters "224.0.0.5" 31 #define AllDRouters "224.0.0.6" 32 33 #define DEFAULT_METRIC 10 34 #define DEFAULT_REDIST_METRIC 100 35 #define MIN_METRIC 1 36 #define MAX_METRIC 65535 /* sum & as-ext lsa use 24bit metrics */ 37 38 #define DEFAULT_PRIORITY 1 39 #define MIN_PRIORITY 0 40 #define MAX_PRIORITY 255 41 42 #define DEFAULT_HELLO_INTERVAL 10 43 #define MIN_HELLO_INTERVAL 1 44 #define MAX_HELLO_INTERVAL 65535 45 46 /* msec */ 47 #define DEFAULT_FAST_INTERVAL 333 48 #define MIN_FAST_INTERVAL 50 49 #define MAX_FAST_INTERVAL 333 50 51 #define DEFAULT_RTR_DEAD_TIME 40 52 #define FAST_RTR_DEAD_TIME 1 53 #define MIN_RTR_DEAD_TIME 2 54 #define MAX_RTR_DEAD_TIME 2147483647 55 56 #define DEFAULT_RXMT_INTERVAL 5 57 #define MIN_RXMT_INTERVAL 5 58 #define MAX_RXMT_INTERVAL 3600 59 60 #define DEFAULT_TRANSMIT_DELAY 1 61 #define MIN_TRANSMIT_DELAY 1 62 #define MAX_TRANSMIT_DELAY 3600 63 64 #define DEFAULT_ADJ_TMOUT 120 65 66 #define DEFAULT_NBR_TMOUT 86400 /* 24 hours */ 67 68 /* msec */ 69 #define DEFAULT_SPF_DELAY 1000 70 #define MIN_SPF_DELAY 10 71 #define MAX_SPF_DELAY 10000 72 73 /* msec */ 74 #define DEFAULT_SPF_HOLDTIME 5000 75 #define MIN_SPF_HOLDTIME 10 76 #define MAX_SPF_HOLDTIME 5000 77 78 /* msec */ 79 #define KR_RELOAD_TIMER 250 80 #define KR_RELOAD_HOLD_TIMER 5000 81 82 #define MIN_MD_ID 0 83 #define MAX_MD_ID 255 84 85 #define MAX_SIMPLE_AUTH_LEN 8 86 87 /* OSPF compatibility flags */ 88 #define OSPF_OPTION_MT 0x01 89 #define OSPF_OPTION_E 0x02 90 #define OSPF_OPTION_MC 0x04 91 #define OSPF_OPTION_NP 0x08 92 #define OSPF_OPTION_EA 0x10 93 #define OSPF_OPTION_DC 0x20 94 #define OSPF_OPTION_O 0x40 /* only on DD options */ 95 #define OSPF_OPTION_DN 0x80 /* only on LSA options */ 96 97 /* OSPF packet types */ 98 #define PACKET_TYPE_HELLO 1 99 #define PACKET_TYPE_DD 2 100 #define PACKET_TYPE_LS_REQUEST 3 101 #define PACKET_TYPE_LS_UPDATE 4 102 #define PACKET_TYPE_LS_ACK 5 103 104 /* OSPF auth types */ 105 #define AUTH_TYPE_NONE 0 106 #define AUTH_TYPE_SIMPLE 1 107 #define AUTH_TYPE_CRYPT 2 108 109 #define MIN_AUTHTYPE 0 110 #define MAX_AUTHTYPE 2 111 112 /* LSA */ 113 #define LS_REFRESH_TIME 1800 114 #define MIN_LS_INTERVAL 5 115 #define MIN_LS_ARRIVAL 1 116 #define DEFAULT_AGE 0 117 #define MAX_AGE 3600 118 #define CHECK_AGE 300 119 #define MAX_AGE_DIFF 900 120 #define LS_INFINITY 0xffffff 121 #define RESV_SEQ_NUM 0x80000000 /* reserved and "unused" */ 122 #define INIT_SEQ_NUM 0x80000001 123 #define MAX_SEQ_NUM 0x7fffffff 124 125 /* OSPF header */ 126 struct crypt { 127 u_int16_t dummy; 128 u_int8_t keyid; 129 u_int8_t len; 130 u_int32_t seq_num; 131 }; 132 133 struct ospf_hdr { 134 u_int8_t version; 135 u_int8_t type; 136 u_int16_t len; 137 u_int32_t rtr_id; 138 u_int32_t area_id; 139 u_int16_t chksum; 140 u_int16_t auth_type; 141 union { 142 char simple[MAX_SIMPLE_AUTH_LEN]; 143 struct crypt crypt; 144 } auth_key; 145 }; 146 147 /* Hello header (type 1) */ 148 struct hello_hdr { 149 u_int32_t mask; 150 u_int16_t hello_interval; 151 u_int8_t opts; 152 u_int8_t rtr_priority; 153 u_int32_t rtr_dead_interval; 154 u_int32_t d_rtr; 155 u_int32_t bd_rtr; 156 }; 157 158 /* Database Description header (type 2) */ 159 struct db_dscrp_hdr { 160 u_int16_t iface_mtu; 161 u_int8_t opts; 162 u_int8_t bits; 163 u_int32_t dd_seq_num; 164 }; 165 166 #define OSPF_DBD_MS 0x01 167 #define OSPF_DBD_M 0x02 168 #define OSPF_DBD_I 0x04 169 170 /* Link State Request header (type 3) */ 171 struct ls_req_hdr { 172 u_int32_t type; 173 u_int32_t ls_id; 174 u_int32_t adv_rtr; 175 }; 176 177 /* Link State Update header (type 4) */ 178 struct ls_upd_hdr { 179 u_int32_t num_lsa; 180 }; 181 182 #define LSA_TYPE_ROUTER 1 183 #define LSA_TYPE_NETWORK 2 184 #define LSA_TYPE_SUM_NETWORK 3 185 #define LSA_TYPE_SUM_ROUTER 4 186 #define LSA_TYPE_EXTERNAL 5 187 #define LSA_TYPE_LINK_OPAQ 9 188 #define LSA_TYPE_AREA_OPAQ 10 189 #define LSA_TYPE_AS_OPAQ 11 190 191 #define LINK_TYPE_POINTTOPOINT 1 192 #define LINK_TYPE_TRANSIT_NET 2 193 #define LINK_TYPE_STUB_NET 3 194 #define LINK_TYPE_VIRTUAL 4 195 196 /* LSA headers */ 197 #define LSA_METRIC_MASK 0x00ffffff /* only for sum & as-ext */ 198 #define LSA_ASEXT_E_FLAG 0x80000000 199 200 /* for some reason they thought 24bit types are fun, make them less a hazard */ 201 #define LSA_24_MASK 0xffffff 202 #define LSA_24_GETHI(x) \ 203 ((x) >> 24) 204 #define LSA_24_GETLO(x) \ 205 ((x) & LSA_24_MASK) 206 #define LSA_24_SETHI(x, y) \ 207 ((x) = ((x) & LSA_24_MASK) | (((y) & 0xff) << 24)) 208 #define LSA_24_SETLO(x, y) \ 209 ((x) = ((y) & LSA_24_MASK) | ((x) & ~LSA_24_MASK)) 210 211 212 #define OSPF_RTR_B 0x01 213 #define OSPF_RTR_E 0x02 214 #define OSPF_RTR_V 0x04 215 216 struct lsa_rtr { 217 u_int8_t flags; 218 u_int8_t dummy; 219 u_int16_t nlinks; 220 }; 221 222 struct lsa_rtr_link { 223 u_int32_t id; 224 u_int32_t data; 225 u_int8_t type; 226 u_int8_t num_tos; 227 u_int16_t metric; 228 }; 229 230 struct lsa_net { 231 u_int32_t mask; 232 u_int32_t att_rtr[1]; 233 }; 234 235 struct lsa_net_link { 236 u_int32_t att_rtr; 237 }; 238 239 struct lsa_sum { 240 u_int32_t mask; 241 u_int32_t metric; /* only lower 24 bit */ 242 }; 243 244 struct lsa_asext { 245 u_int32_t mask; 246 u_int32_t metric; /* lower 24 bit plus E bit */ 247 u_int32_t fw_addr; 248 u_int32_t ext_tag; 249 }; 250 251 struct lsa_hdr { 252 u_int16_t age; 253 u_int8_t opts; 254 u_int8_t type; 255 u_int32_t ls_id; 256 u_int32_t adv_rtr; 257 u_int32_t seq_num; 258 u_int16_t ls_chksum; 259 u_int16_t len; 260 }; 261 262 #define LS_CKSUM_OFFSET offsetof(struct lsa_hdr, ls_chksum) 263 264 struct lsa { 265 struct lsa_hdr hdr; 266 union { 267 struct lsa_rtr rtr; 268 struct lsa_net net; 269 struct lsa_sum sum; 270 struct lsa_asext asext; 271 } data; 272 }; 273 274 #endif /* !_OSPF_H_ */ 275