File: libnet-ospf.h

package info (click to toggle)
libnet0 1.0.2a-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, sarge
  • size: 2,860 kB
  • ctags: 858
  • sloc: sh: 9,149; ansic: 9,055; makefile: 192
file content (394 lines) | stat: -rw-r--r-- 10,805 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/*
 *  $Id: libnet-ospf.h,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
 *
 *  libnet-ospf.h - Network routine library headers header file
 *
 *  Copyright (c) 1999 Andrew Reiter <areiter@bindview.com>
 *  Bindview Development
 *
 *  Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
 *  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */

#ifndef __LIBNET_OSPF_H
#define __LIBNET_OSPF_H

#include <sys/types.h>


/*
 *  Not all OSes define this in /etc/protocols.. ie, solaris...
 */
#ifndef IPPROTO_OSPF
#define IPPROTO_OSPF	    89
#endif
#define IPPROTO_OSPF_LSA    890         /* Made this up.  Hope it's unused */
#define OSPFVERSION         2
#define LIBNET_MODX                4102        /* Used in LSA checksum */


/*
 *  OSPF header lengths.
 */
#define LIBNET_OSPF_H       0x10    /* 16 bytes */
#define LIBNET_HELLO_H      0x18    /* 24 bytes */
#define LIBNET_DBD_H        0x8     /* 8 bytes */
#define LIBNET_LSR_H        0xc     /* 12 bytes */
#define LIBNET_LSU_H        0x4     /* 4 bytes */
#define LIBNET_LSA_H        0x14    /* 20 bytes */
#define LIBNET_AUTH_H       0x8     /* 8 bytes */
#define LIBNET_OSPF_CKSUM   0x10    /* 16 bytes */


/*
 *  Link State packet format lengths.
 */
#define LIBNET_LS_RTR_LEN   	0x10	        /* 16 bytes */
#define LIBNET_LS_NET_LEN	0x8	        /* 8 bytes */
#define LIBNET_LS_SUM_LEN	0xc             /* 12 bytes */	
#define LIBNET_LS_AS_EXT_LEN	0x10            /* 16 bytes */	


/*
 *  OSPFv2 Packet Header.
 */
struct libnet_ospf_hdr
{
    u_char ospf_v;                   /* version */
    u_char ospf_type;                /* type */
#define  LIBNET_OSPF_UMD       0     /* UMd monitoring packet */
#define  LIBNET_OSPF_HELLO     1     /* HELLO packet */
#define  LIBNET_OSPF_DBD       2     /* DataBase Description Packet */
#define  LIBNET_OSPF_LSR       3     /* Link State Request Packet */
#define  LIBNET_OSPF_LSU       4     /* Link State Update Packet */
#define  LIBNET_OSPF_LSA       5     /* Link State Acknowledgement Packet */
    u_short   ospf_len;              /* length */
    struct in_addr  ospf_rtr_id;     /* source router ID */ 
    struct in_addr  ospf_area_id;    /* roam ID */
    u_short ospf_cksum;              /* checksum */
    u_short ospf_auth_type;          /* authentication type */
#define LIBNET_OSPF_AUTH_NULL   0    /* Null password */
#define LIBNET_OSPF_AUTH_SIMPLE 1    /* Simple, plaintext, 8 char password */
#define LIBNET_OSPF_AUTH_MD5    2    /* MD5 */
};


/*
 *  OSPF authentication header.
 */
struct libnet_auth_hdr
{
    u_short ospf_auth_null;         /* NULL */
    u_char  ospf_auth_keyid;        /* Authentication Key ID */
    u_char  ospf_auth_len;          /* Auth data length */
    u_int   ospf_auth_seq;          /* Cryptographic sequence number */
};


/*
 *  Options used in multiple OSPF packets.
 *  More info can be found in section A.2 of RFC 2328.
 */
#define LIBNET_OPT_EBIT  0x02 /* Describes the way AS-external-LSAs are flooded */
#define LIBNET_OPT_MCBIT 0x04 /* Whether or not IP multicast dgrams are fwdd */
#define LIBNET_OPT_NPBIT 0x08 /* Describes handling of type-7 LSAs */
#define LIBNET_OPT_EABIT 0x10 /* rtr's willingness to send/recv EA-LSAs */
#define LIBNET_OPT_DCBIT 0x20 /* Describes handling of demand circuits */


/*
 *  OSPF HELLO Packet Header.
 */
struct libnet_ospf_hello_hdr
{
    struct in_addr hello_nmask; /* Netmask associated with the interface */
    u_short hello_intrvl;       /* Num of seconds between routers last packet */
    u_char hello_opts;          /* Options for HELLO packets (look above) */
    u_char hello_rtr_pri;       /* Router's priority (if 0, can't be backup) */
    u_int hello_dead_intvl;     /* # of secs a router is silent till deemed down */
    struct in_addr hello_des_rtr;   /* Designated router on the network */
    struct in_addr hello_bkup_rtr;  /* Backup router */
    struct in_addr hello_nbr;	    /* neighbor router, memcpy more as needed */
};


/*
 *  Database Description header.
 */
struct libnet_dbd_hdr
{
    u_short dbd_mtu_len;    /* Max length of IP dgram that this 'if' can use */
    u_char dbd_opts;        /* DBD packet options (look above) */
    u_char dbd_type;        /* Type of exchange occurring (look below) */
#define LIBNET_DBD_IBIT    0x01    /* Init Bit */
#define LIBNET_DBD_MBIT    0x02    /* Says more DBD packets are to come */
#define LIBNET_DBD_MSBIT   0x04  /* If 1, sender is the master in the exchnge */
    u_int  dbd_seq;         /* DBD sequence number */
};


/*
 *  Used for the LS type field in all LS* headers.
 */
#define LIBNET_LS_TYPE_RTR	1   /* Router-LSA */
#define LIBNET_LS_TYPE_NET	2   /* Network-LSA */
#define LIBNET_LS_TYPE_IP	3   /* Summary-LSA (IP Network) */
#define LIBNET_LS_TYPE_ASBR    4   /* Summary-LSA (ASBR) */
#define LIBNET_LS_TYPE_ASEXT	5   /* AS-External-LSA */


/*
 *  Link State Request header.
 */
struct libnet_lsr_hdr
{
    u_int lsr_type;             /* Type of LS being requested (see below) */
    u_int lsr_lsid;             /* Link State ID */
    struct in_addr lsr_adrtr;   /* advertising router (memcpy more as needed) */
};


/*
 *  Link State Update header.
 */
struct libnet_lsu_hdr
{
    u_int lsu_num;              /* Number of LSAs that will be broadcasted */
};


/*
 *  Link State Acknowledgement header.
 */
struct libnet_lsa_hdr
{
    u_short lsa_age;        /* Time in seconds since the LSA was originated */
    u_char lsa_opts;        /* Look above for OPTS_* */
    u_char lsa_type;        /* Look below for LS_TYPE_* */
    u_int lsa_id;           /* Link State ID */
    struct in_addr lsa_adv; /* Router ID of Advertising router */
    u_int lsa_seq;          /* LSA sequence number to detect old/bad ones */
    u_char lsa_cksum[2];    /* "Fletcher Checksum" of all fields minus age */
    u_short lsa_len;        /* Length in bytes including the 20 byte header */
};


/*
 *  Router LSA data format
 *
 *  Other stuff for TOS can be added for backward compatability, for this
 *  version, only OSPFv2 is being FULLY supported.
 */

struct libnet_rtr_lsa_hdr
{
    u_short rtr_flags;      /* Set to help describe packet */
#define LIBNET_RTR_FLAGS_W     0x0100  /* W bit */
#define LIBNET_RTR_FLAGS_E     0x0200  /* E bit */
#define LIBNET_RTR_FLAGS_B     0x0400  /* B bit */
    u_short rtr_num;        /* Number of links within that packet */
    u_int rtr_link_id;      /* Describes link_data (look below) */
#define LIBNET_LINK_ID_NBR_ID  1       /* Neighbors router ID, also can be 4 */
#define LIBNET_LINK_ID_IP_DES  2       /* IP address of designated router */
#define LIBNET_LINK_ID_SUB     3       /* IP subnet number */
    u_int rtr_link_data;    /* Depending on link_id, info is here */
    u_char rtr_type;        /* Description of router link */
#define LIBNET_RTR_TYPE_PTP    1   /* Point-To-Point */
#define LIBNET_RTR_TYPE_TRANS  2   /* Connection to a "transit network" */
#define LIBNET_RTR_TYPE_STUB   3   /* Connectin to a "stub network" */
#define RTR_TYPE_VRTL   4   /* Connects to a "virtual link" */
    u_char rtr_tos_num;     /* Number of different TOS metrics for this link */
    u_short rtr_metric;     /* The "cost" of using this link */
};


/*
 *  Network LSA data format.
 */
struct libnet_net_lsa_hdr
{
    struct in_addr net_nmask;   /* Netmask for that network */
    u_int  net_rtr_id;          /* ID of router attached to that network */
};


/*
 *  Summary LSA data format.
 */
struct libnet_sum_lsa_hdr
{
    struct in_addr sum_nmask;   /* Netmask of destination IP address */
    u_int  sum_metric;          /* Same as in rtr_lsa (&0xfff to use last 24bit) */
    u_int  sum_tos_metric;      /* first 8bits are TOS, 24bits are TOS Metric */
};


/*
 *  AS External LSA data format.
 *  & 0xfff logic operator for as_metric to get last 24bits.
 */

struct libnet_as_lsa_hdr
{
    struct in_addr as_nmask;    /* Netmask for advertised destination */
    u_int  as_metric;           /* May have to set E bit in first 8bits */
#define LIBNET_AS_E_BIT_ON 0x80000000  /* as_metric */
    struct in_addr as_fwd_addr; /* Forwarding address */
    u_int  as_rte_tag;          /* External route tag */
};


int
libnet_build_ospf(
    u_short,
    u_char,
    u_long,
    u_long,
    u_short,
    const char *,
    int,
    u_char *
    );     


int
libnet_build_ospf_hello(
    u_long,
    u_short,
    u_char,
    u_char,
    u_int,
    u_long,
    u_long,
    u_long,
    const char *,
    int,
    u_char *
    );


int
libnet_build_ospf_dbd(
    u_short,
    u_char,
    u_char,
    u_int,
    const char *,
    int,
    u_char *
    );


int
libnet_build_ospf_lsr(
    u_int,
    u_int,
    u_long,
    const char *,
    int,
    u_char *
    );


int
libnet_build_ospf_lsu(
    u_int,
    const char *,
    int,
    u_char *
    );


int
libnet_build_ospf_lsa(
    u_short,
    u_char,
    u_char,
    u_int,
    u_long,
    u_int,
    u_short,
    const char *,
    int,
    u_char *
    );


int
libnet_build_ospf_lsa_rtr(
    u_short,
    u_short,
    u_int,
    u_int,
    u_char,
    u_char,
    u_short,
    const char *,
    int,
    u_char *
    );


int
libnet_build_ospf_lsa_net(
    u_long,
    u_int,
    const char *,
    int,
    u_char *
    );


int
libnet_build_ospf_lsa_sum(
    u_long,
    u_int,
    u_int,
    const char *,
    int,
    u_char *
    );


int
libnet_build_ospf_lsa_as(
    u_long,
    u_int,
    u_long, 
    u_int,
    const char *,
    int,
    u_char *
    );


void
libnet_ospf_lsa_checksum(
    u_char *,
    int
    );


#endif /* __LIBNET_OSPF_H */