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