1 /* $OpenBSD: ospf.h,v 1.4 2005/02/02 19:47:20 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 1 36 #define MIN_METRIC 1 37 #define MAX_METRIC 65535 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 INIT_SEQ_NUM 0x80000001 95 #define MAX_SEQ_NUM 0x7fffffff 96 97 /* OSPF header */ 98 struct ospf_hdr { 99 u_int8_t version; 100 u_int8_t type; 101 u_int16_t len; 102 u_int32_t rtr_id; 103 u_int32_t area_id; 104 u_int16_t chksum; 105 u_int16_t auth_type; 106 union { 107 char simple[8]; 108 u_int64_t crypt; 109 } auth_key; 110 }; 111 112 /* Hello header (type 1) */ 113 struct hello_hdr { 114 u_int32_t mask; 115 u_int16_t hello_interval; 116 u_int8_t opts; 117 u_int8_t rtr_priority; 118 u_int32_t rtr_dead_interval; 119 u_int32_t d_rtr; 120 u_int32_t bd_rtr; 121 }; 122 123 /* Database Description header (type 2) */ 124 struct db_dscrp_hdr { 125 u_int16_t iface_mtu; 126 u_int8_t opts; 127 u_int8_t bits; 128 u_int32_t dd_seq_num; 129 }; 130 131 #define OSPF_DBD_MS 0x01 132 #define OSPF_DBD_M 0x02 133 #define OSPF_DBD_I 0x04 134 135 /* Link State Request header (type 3) */ 136 struct ls_req_hdr { 137 u_int32_t type; 138 u_int32_t ls_id; 139 u_int32_t adv_rtr; 140 }; 141 142 /* Link State Update header (type 4) */ 143 struct ls_upd_hdr { 144 u_int32_t num_lsa; 145 }; 146 147 #define LSA_TYPE_ROUTER 1 148 #define LSA_TYPE_NETWORK 2 149 #define LSA_TYPE_SUM_NETWORK 3 150 #define LSA_TYPE_SUM_ROUTER 4 151 #define LSA_TYPE_EXTERNAL 5 152 153 #define LINK_TYPE_POINTTOPOINT 1 154 #define LINK_TYPE_TRANSIT_NET 2 155 #define LINK_TYPE_STUB_NET 3 156 #define LINK_TYPE_VIRTUAL 4 157 158 /* LSA headers */ 159 struct lsa_rtr { 160 u_int8_t flags; 161 u_int8_t dummy; 162 u_int16_t nlinks; 163 }; 164 165 struct lsa_rtr_link { 166 u_int32_t id; 167 u_int32_t data; 168 u_int8_t type; 169 u_int8_t num_tos; 170 u_int16_t metric; 171 }; 172 173 struct lsa_net { 174 u_int32_t mask; 175 u_int32_t att_rtr[1]; 176 }; 177 178 struct lsa_sum { 179 u_int32_t mask; 180 u_int32_t metric; /* only lower 24 bit */ 181 }; 182 183 struct lsa_hdr { 184 u_int16_t age; 185 u_int8_t opts; 186 u_int8_t type; 187 u_int32_t ls_id; 188 u_int32_t adv_rtr; 189 int32_t seq_num; 190 u_int16_t ls_chksum; 191 u_int16_t len; 192 }; 193 194 #define LS_CKSUM_OFFSET ((u_int16_t)(&((struct lsa_hdr *)0)->ls_chksum)) 195 196 struct lsa { 197 struct lsa_hdr hdr; 198 union { 199 struct lsa_rtr rtr; 200 struct lsa_net net; 201 struct lsa_sum sum; 202 } data; 203 }; 204 205 #endif /* !_OSPF_H_ */ 206