OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / Libnet / include / libnet / libnet-ospf.h
1 /*
2  *  $Id: libnet-ospf.h,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
3  *
4  *  libnet-ospf.h - Network routine library headers header file
5  *
6  *  Copyright (c) 1999 Andrew Reiter <areiter@bindview.com>
7  *  Bindview Development
8  *
9  *  Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
10  *  All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
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.
20  *
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
31  * SUCH DAMAGE.
32  *
33  */
34
35 #ifndef __LIBNET_OSPF_H
36 #define __LIBNET_OSPF_H
37
38 #include <sys/types.h>
39
40
41 /*
42  *  Not all OSes define this in /etc/protocols.. ie, solaris...
43  */
44 #ifndef IPPROTO_OSPF
45 #define IPPROTO_OSPF        89
46 #endif
47 #define IPPROTO_OSPF_LSA    890         /* Made this up.  Hope it's unused */
48 #define OSPFVERSION         2
49 #define LIBNET_MODX                4102        /* Used in LSA checksum */
50
51
52 /*
53  *  OSPF header lengths.
54  */
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 */
63
64
65 /*
66  *  Link State packet format lengths.
67  */
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 */  
72
73
74 /*
75  *  OSPFv2 Packet Header.
76  */
77 struct libnet_ospf_hdr
78 {
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 */
95 };
96
97
98 /*
99  *  OSPF authentication header.
100  */
101 struct libnet_auth_hdr
102 {
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 */
107 };
108
109
110 /*
111  *  Options used in multiple OSPF packets.
112  *  More info can be found in section A.2 of RFC 2328.
113  */
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 */
119
120
121 /*
122  *  OSPF HELLO Packet Header.
123  */
124 struct libnet_ospf_hello_hdr
125 {
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 */
134 };
135
136
137 /*
138  *  Database Description header.
139  */
140 struct libnet_dbd_hdr
141 {
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 */
149 };
150
151
152 /*
153  *  Used for the LS type field in all LS* headers.
154  */
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 */
160
161
162 /*
163  *  Link State Request header.
164  */
165 struct libnet_lsr_hdr
166 {
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) */
170 };
171
172
173 /*
174  *  Link State Update header.
175  */
176 struct libnet_lsu_hdr
177 {
178     u_int lsu_num;              /* Number of LSAs that will be broadcasted */
179 };
180
181
182 /*
183  *  Link State Acknowledgement header.
184  */
185 struct libnet_lsa_hdr
186 {
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 */
195 };
196
197
198 /*
199  *  Router LSA data format
200  *
201  *  Other stuff for TOS can be added for backward compatability, for this
202  *  version, only OSPFv2 is being FULLY supported.
203  */
204
205 struct libnet_rtr_lsa_hdr
206 {
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 */
224 };
225
226
227 /*
228  *  Network LSA data format.
229  */
230 struct libnet_net_lsa_hdr
231 {
232     struct in_addr net_nmask;   /* Netmask for that network */
233     u_int  net_rtr_id;          /* ID of router attached to that network */
234 };
235
236
237 /*
238  *  Summary LSA data format.
239  */
240 struct libnet_sum_lsa_hdr
241 {
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 */
245 };
246
247
248 /*
249  *  AS External LSA data format.
250  *  & 0xfff logic operator for as_metric to get last 24bits.
251  */
252
253 struct libnet_as_lsa_hdr
254 {
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 */
260 };
261
262
263 int
264 libnet_build_ospf(
265     u_short,
266     u_char,
267     u_long,
268     u_long,
269     u_short,
270     const char *,
271     int,
272     u_char *
273     );     
274
275
276 int
277 libnet_build_ospf_hello(
278     u_long,
279     u_short,
280     u_char,
281     u_char,
282     u_int,
283     u_long,
284     u_long,
285     u_long,
286     const char *,
287     int,
288     u_char *
289     );
290
291
292 int
293 libnet_build_ospf_dbd(
294     u_short,
295     u_char,
296     u_char,
297     u_int,
298     const char *,
299     int,
300     u_char *
301     );
302
303
304 int
305 libnet_build_ospf_lsr(
306     u_int,
307     u_int,
308     u_long,
309     const char *,
310     int,
311     u_char *
312     );
313
314
315 int
316 libnet_build_ospf_lsu(
317     u_int,
318     const char *,
319     int,
320     u_char *
321     );
322
323
324 int
325 libnet_build_ospf_lsa(
326     u_short,
327     u_char,
328     u_char,
329     u_int,
330     u_long,
331     u_int,
332     u_short,
333     const char *,
334     int,
335     u_char *
336     );
337
338
339 int
340 libnet_build_ospf_lsa_rtr(
341     u_short,
342     u_short,
343     u_int,
344     u_int,
345     u_char,
346     u_char,
347     u_short,
348     const char *,
349     int,
350     u_char *
351     );
352
353
354 int
355 libnet_build_ospf_lsa_net(
356     u_long,
357     u_int,
358     const char *,
359     int,
360     u_char *
361     );
362
363
364 int
365 libnet_build_ospf_lsa_sum(
366     u_long,
367     u_int,
368     u_int,
369     const char *,
370     int,
371     u_char *
372     );
373
374
375 int
376 libnet_build_ospf_lsa_as(
377     u_long,
378     u_int,
379     u_long, 
380     u_int,
381     const char *,
382     int,
383     u_char *
384     );
385
386
387 void
388 libnet_ospf_lsa_checksum(
389     u_char *,
390     int
391     );
392
393
394 #endif /* __LIBNET_OSPF_H */