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