1 /* $OpenBSD: ospf.h,v 1.7 2005/02/08 21:52:48 norby 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 <stdbool.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 PACKET_HDR 100 /* XXX used to calculate the IP payload */ 34 35 #define DEFAULT_METRIC 10 36 #define MIN_METRIC 1 37 #define MAX_METRIC 65535 /* sum & as-ext lsa use 24bit metrics */ 38 39 #define DEFAULT_PRIORITY 0 /* XXX force to 0 for now */ 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 /* XXX sane value? */ 60 61 #define DEFAULT_NBR_TMOUT 86400 /* 24 hours */ 62 63 /* OSPF compatibility flags */ 64 #define OSPF_OPTION_E 0x02 65 #define OSPF_OPTION_MC 0x04 66 #define OSPF_OPTION_NP 0x08 67 #define OSPF_OPTION_EA 0x10 68 #define OSPF_OPTION_DC 0x20 69 70 /* OSPF packet types */ 71 #define PACKET_TYPE_HELLO 1 72 #define PACKET_TYPE_DD 2 73 #define PACKET_TYPE_LS_REQUEST 3 74 #define PACKET_TYPE_LS_UPDATE 4 75 #define PACKET_TYPE_LS_ACK 5 76 77 /* OSPF auth types */ 78 #define AUTH_TYPE_NONE 0 79 #define AUTH_TYPE_SIMPLE 1 80 #define AUTH_TYPE_CRYPT 2 81 82 #define MIN_AUTHTYPE 0 83 #define MAX_AUTHTYPE 2 84 85 /* LSA */ 86 #define LS_REFRESH_TIME 1800 87 #define MIN_LS_INTERVAL 5 88 #define MIN_LS_ARRIVAL 1 89 #define DEFAULT_AGE 0 90 #define MAX_AGE 3600 91 #define CHECK_AGE 300 92 #define MAX_AGE_DIFF 900 93 #define LS_INFINITY 0xffffff 94 #define RESV_SEQ_NUM 0x80000000 /* reserved and "unused" */ 95 #define INIT_SEQ_NUM 0x80000001 96 #define MAX_SEQ_NUM 0x7fffffff 97 98 /* OSPF header */ 99 struct ospf_hdr { 100 u_int8_t version; 101 u_int8_t type; 102 u_int16_t len; 103 u_int32_t rtr_id; 104 u_int32_t area_id; 105 u_int16_t chksum; 106 u_int16_t auth_type; 107 union { 108 char simple[8]; 109 u_int64_t crypt; 110 } auth_key; 111 }; 112 113 /* Hello header (type 1) */ 114 struct hello_hdr { 115 u_int32_t mask; 116 u_int16_t hello_interval; 117 u_int8_t opts; 118 u_int8_t rtr_priority; 119 u_int32_t rtr_dead_interval; 120 u_int32_t d_rtr; 121 u_int32_t bd_rtr; 122 }; 123 124 /* Database Description header (type 2) */ 125 struct db_dscrp_hdr { 126 u_int16_t iface_mtu; 127 u_int8_t opts; 128 u_int8_t bits; 129 u_int32_t dd_seq_num; 130 }; 131 132 #define OSPF_DBD_MS 0x01 133 #define OSPF_DBD_M 0x02 134 #define OSPF_DBD_I 0x04 135 136 /* Link State Request header (type 3) */ 137 struct ls_req_hdr { 138 u_int32_t type; 139 u_int32_t ls_id; 140 u_int32_t adv_rtr; 141 }; 142 143 /* Link State Update header (type 4) */ 144 struct ls_upd_hdr { 145 u_int32_t num_lsa; 146 }; 147 148 #define LSA_TYPE_ROUTER 1 149 #define LSA_TYPE_NETWORK 2 150 #define LSA_TYPE_SUM_NETWORK 3 151 #define LSA_TYPE_SUM_ROUTER 4 152 #define LSA_TYPE_EXTERNAL 5 153 154 #define LINK_TYPE_POINTTOPOINT 1 155 #define LINK_TYPE_TRANSIT_NET 2 156 #define LINK_TYPE_STUB_NET 3 157 #define LINK_TYPE_VIRTUAL 4 158 159 /* LSA headers */ 160 #define LSA_METRIC_MASK 0x00ffffff /* only for sum & as-ext */ 161 #define LSA_ASEXT_E_FLAG 0x80000000 162 163 struct lsa_rtr { 164 u_int8_t flags; 165 u_int8_t dummy; 166 u_int16_t nlinks; 167 }; 168 169 struct lsa_rtr_link { 170 u_int32_t id; 171 u_int32_t data; 172 u_int8_t type; 173 u_int8_t num_tos; 174 u_int16_t metric; 175 }; 176 177 struct lsa_net { 178 u_int32_t mask; 179 u_int32_t att_rtr[1]; 180 }; 181 182 struct lsa_sum { 183 u_int32_t mask; 184 u_int32_t metric; /* only lower 24 bit */ 185 }; 186 187 struct lsa_asext { 188 u_int32_t mask; 189 u_int32_t metric; /* lower 24 bit plus E bit */ 190 u_int32_t fw_addr; 191 u_int32_t ext_tag; 192 }; 193 194 struct lsa_hdr { 195 u_int16_t age; 196 u_int8_t opts; 197 u_int8_t type; 198 u_int32_t ls_id; 199 u_int32_t adv_rtr; 200 u_int32_t seq_num; 201 u_int16_t ls_chksum; 202 u_int16_t len; 203 }; 204 205 #define LS_CKSUM_OFFSET ((u_int16_t)(&((struct lsa_hdr *)0)->ls_chksum)) 206 207 struct lsa { 208 struct lsa_hdr hdr; 209 union { 210 struct lsa_rtr rtr; 211 struct lsa_net net; 212 struct lsa_sum sum; 213 struct lsa_asext asext; 214 } data; 215 }; 216 217 #endif /* !_OSPF_H_ */ 218