2 * $Id: libnet-ospf.h,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
4 * libnet-ospf.h - Network routine library headers header file
6 * Copyright (c) 1999 Andrew Reiter <areiter@bindview.com>
9 * Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #ifndef __LIBNET_OSPF_H
36 #define __LIBNET_OSPF_H
38 #include <sys/types.h>
42 * Not all OSes define this in /etc/protocols.. ie, solaris...
45 #define IPPROTO_OSPF 89
47 #define IPPROTO_OSPF_LSA 890 /* Made this up. Hope it's unused */
49 #define LIBNET_MODX 4102 /* Used in LSA checksum */
53 * OSPF header lengths.
55 #define LIBNET_OSPF_H 0x10 /* 16 bytes */
56 #define LIBNET_HELLO_H 0x18 /* 24 bytes */
57 #define LIBNET_DBD_H 0x8 /* 8 bytes */
58 #define LIBNET_LSR_H 0xc /* 12 bytes */
59 #define LIBNET_LSU_H 0x4 /* 4 bytes */
60 #define LIBNET_LSA_H 0x14 /* 20 bytes */
61 #define LIBNET_AUTH_H 0x8 /* 8 bytes */
62 #define LIBNET_OSPF_CKSUM 0x10 /* 16 bytes */
66 * Link State packet format lengths.
68 #define LIBNET_LS_RTR_LEN 0x10 /* 16 bytes */
69 #define LIBNET_LS_NET_LEN 0x8 /* 8 bytes */
70 #define LIBNET_LS_SUM_LEN 0xc /* 12 bytes */
71 #define LIBNET_LS_AS_EXT_LEN 0x10 /* 16 bytes */
75 * OSPFv2 Packet Header.
77 struct libnet_ospf_hdr
79 u_char ospf_v; /* version */
80 u_char ospf_type; /* type */
81 #define LIBNET_OSPF_UMD 0 /* UMd monitoring packet */
82 #define LIBNET_OSPF_HELLO 1 /* HELLO packet */
83 #define LIBNET_OSPF_DBD 2 /* DataBase Description Packet */
84 #define LIBNET_OSPF_LSR 3 /* Link State Request Packet */
85 #define LIBNET_OSPF_LSU 4 /* Link State Update Packet */
86 #define LIBNET_OSPF_LSA 5 /* Link State Acknowledgement Packet */
87 u_short ospf_len; /* length */
88 struct in_addr ospf_rtr_id; /* source router ID */
89 struct in_addr ospf_area_id; /* roam ID */
90 u_short ospf_cksum; /* checksum */
91 u_short ospf_auth_type; /* authentication type */
92 #define LIBNET_OSPF_AUTH_NULL 0 /* Null password */
93 #define LIBNET_OSPF_AUTH_SIMPLE 1 /* Simple, plaintext, 8 char password */
94 #define LIBNET_OSPF_AUTH_MD5 2 /* MD5 */
99 * OSPF authentication header.
101 struct libnet_auth_hdr
103 u_short ospf_auth_null; /* NULL */
104 u_char ospf_auth_keyid; /* Authentication Key ID */
105 u_char ospf_auth_len; /* Auth data length */
106 u_int ospf_auth_seq; /* Cryptographic sequence number */
111 * Options used in multiple OSPF packets.
112 * More info can be found in section A.2 of RFC 2328.
114 #define LIBNET_OPT_EBIT 0x02 /* Describes the way AS-external-LSAs are flooded */
115 #define LIBNET_OPT_MCBIT 0x04 /* Whether or not IP multicast dgrams are fwdd */
116 #define LIBNET_OPT_NPBIT 0x08 /* Describes handling of type-7 LSAs */
117 #define LIBNET_OPT_EABIT 0x10 /* rtr's willingness to send/recv EA-LSAs */
118 #define LIBNET_OPT_DCBIT 0x20 /* Describes handling of demand circuits */
122 * OSPF HELLO Packet Header.
124 struct libnet_ospf_hello_hdr
126 struct in_addr hello_nmask; /* Netmask associated with the interface */
127 u_short hello_intrvl; /* Num of seconds between routers last packet */
128 u_char hello_opts; /* Options for HELLO packets (look above) */
129 u_char hello_rtr_pri; /* Router's priority (if 0, can't be backup) */
130 u_int hello_dead_intvl; /* # of secs a router is silent till deemed down */
131 struct in_addr hello_des_rtr; /* Designated router on the network */
132 struct in_addr hello_bkup_rtr; /* Backup router */
133 struct in_addr hello_nbr; /* neighbor router, memcpy more as needed */
138 * Database Description header.
140 struct libnet_dbd_hdr
142 u_short dbd_mtu_len; /* Max length of IP dgram that this 'if' can use */
143 u_char dbd_opts; /* DBD packet options (look above) */
144 u_char dbd_type; /* Type of exchange occurring (look below) */
145 #define LIBNET_DBD_IBIT 0x01 /* Init Bit */
146 #define LIBNET_DBD_MBIT 0x02 /* Says more DBD packets are to come */
147 #define LIBNET_DBD_MSBIT 0x04 /* If 1, sender is the master in the exchnge */
148 u_int dbd_seq; /* DBD sequence number */
153 * Used for the LS type field in all LS* headers.
155 #define LIBNET_LS_TYPE_RTR 1 /* Router-LSA */
156 #define LIBNET_LS_TYPE_NET 2 /* Network-LSA */
157 #define LIBNET_LS_TYPE_IP 3 /* Summary-LSA (IP Network) */
158 #define LIBNET_LS_TYPE_ASBR 4 /* Summary-LSA (ASBR) */
159 #define LIBNET_LS_TYPE_ASEXT 5 /* AS-External-LSA */
163 * Link State Request header.
165 struct libnet_lsr_hdr
167 u_int lsr_type; /* Type of LS being requested (see below) */
168 u_int lsr_lsid; /* Link State ID */
169 struct in_addr lsr_adrtr; /* advertising router (memcpy more as needed) */
174 * Link State Update header.
176 struct libnet_lsu_hdr
178 u_int lsu_num; /* Number of LSAs that will be broadcasted */
183 * Link State Acknowledgement header.
185 struct libnet_lsa_hdr
187 u_short lsa_age; /* Time in seconds since the LSA was originated */
188 u_char lsa_opts; /* Look above for OPTS_* */
189 u_char lsa_type; /* Look below for LS_TYPE_* */
190 u_int lsa_id; /* Link State ID */
191 struct in_addr lsa_adv; /* Router ID of Advertising router */
192 u_int lsa_seq; /* LSA sequence number to detect old/bad ones */
193 u_char lsa_cksum[2]; /* "Fletcher Checksum" of all fields minus age */
194 u_short lsa_len; /* Length in bytes including the 20 byte header */
199 * Router LSA data format
201 * Other stuff for TOS can be added for backward compatability, for this
202 * version, only OSPFv2 is being FULLY supported.
205 struct libnet_rtr_lsa_hdr
207 u_short rtr_flags; /* Set to help describe packet */
208 #define LIBNET_RTR_FLAGS_W 0x0100 /* W bit */
209 #define LIBNET_RTR_FLAGS_E 0x0200 /* E bit */
210 #define LIBNET_RTR_FLAGS_B 0x0400 /* B bit */
211 u_short rtr_num; /* Number of links within that packet */
212 u_int rtr_link_id; /* Describes link_data (look below) */
213 #define LIBNET_LINK_ID_NBR_ID 1 /* Neighbors router ID, also can be 4 */
214 #define LIBNET_LINK_ID_IP_DES 2 /* IP address of designated router */
215 #define LIBNET_LINK_ID_SUB 3 /* IP subnet number */
216 u_int rtr_link_data; /* Depending on link_id, info is here */
217 u_char rtr_type; /* Description of router link */
218 #define LIBNET_RTR_TYPE_PTP 1 /* Point-To-Point */
219 #define LIBNET_RTR_TYPE_TRANS 2 /* Connection to a "transit network" */
220 #define LIBNET_RTR_TYPE_STUB 3 /* Connectin to a "stub network" */
221 #define RTR_TYPE_VRTL 4 /* Connects to a "virtual link" */
222 u_char rtr_tos_num; /* Number of different TOS metrics for this link */
223 u_short rtr_metric; /* The "cost" of using this link */
228 * Network LSA data format.
230 struct libnet_net_lsa_hdr
232 struct in_addr net_nmask; /* Netmask for that network */
233 u_int net_rtr_id; /* ID of router attached to that network */
238 * Summary LSA data format.
240 struct libnet_sum_lsa_hdr
242 struct in_addr sum_nmask; /* Netmask of destination IP address */
243 u_int sum_metric; /* Same as in rtr_lsa (&0xfff to use last 24bit) */
244 u_int sum_tos_metric; /* first 8bits are TOS, 24bits are TOS Metric */
249 * AS External LSA data format.
250 * & 0xfff logic operator for as_metric to get last 24bits.
253 struct libnet_as_lsa_hdr
255 struct in_addr as_nmask; /* Netmask for advertised destination */
256 u_int as_metric; /* May have to set E bit in first 8bits */
257 #define LIBNET_AS_E_BIT_ON 0x80000000 /* as_metric */
258 struct in_addr as_fwd_addr; /* Forwarding address */
259 u_int as_rte_tag; /* External route tag */
277 libnet_build_ospf_hello(
293 libnet_build_ospf_dbd(
305 libnet_build_ospf_lsr(
316 libnet_build_ospf_lsu(
325 libnet_build_ospf_lsa(
340 libnet_build_ospf_lsa_rtr(
355 libnet_build_ospf_lsa_net(
365 libnet_build_ospf_lsa_sum(
376 libnet_build_ospf_lsa_as(
388 libnet_ospf_lsa_checksum(
394 #endif /* __LIBNET_OSPF_H */