Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

libnet-ospf.h

Go to the documentation of this file.
00001 /*
00002  *  $Id$
00003  *
00004  *  libnet-ospf.h - Network routine library headers header file
00005  *
00006  *  Copyright (c) 1999 Andrew Reiter <areiter@bindview.com>
00007  *  Bindview Development
00008  *
00009  *  Copyright (c) 1998, 1999, 2000 Mike D. Schiffman <mike@infonexus.com>
00010  *  All rights reserved.
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions
00014  * are met:
00015  * 1. Redistributions of source code must retain the above copyright
00016  *    notice, this list of conditions and the following disclaimer.
00017  * 2. Redistributions in binary form must reproduce the above copyright
00018  *    notice, this list of conditions and the following disclaimer in the
00019  *    documentation and/or other materials provided with the distribution.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  */
00034 
00035 #ifndef __LIBNET_OSPF_H
00036 #define __LIBNET_OSPF_H
00037 
00038 #include <sys/types.h>
00039 
00040 
00041 /*
00042  *  Not all OSes define this in /etc/protocols.. ie, solaris...
00043  */
00044 #ifndef IPPROTO_OSPF
00045 #define IPPROTO_OSPF        89
00046 #endif
00047 #define IPPROTO_OSPF_LSA    890         /* Made this up.  Hope it's unused */
00048 #define OSPFVERSION         2
00049 #define LIBNET_MODX                4102        /* Used in LSA checksum */
00050 
00051 
00052 /*
00053  *  OSPF header lengths.
00054  */
00055 #define LIBNET_OSPF_H       0x10    /* 16 bytes */
00056 #define LIBNET_HELLO_H      0x18    /* 24 bytes */
00057 #define LIBNET_DBD_H        0x8     /* 8 bytes */
00058 #define LIBNET_LSR_H        0xc     /* 12 bytes */
00059 #define LIBNET_LSU_H        0x4     /* 4 bytes */
00060 #define LIBNET_LSA_H        0x14    /* 20 bytes */
00061 #define LIBNET_AUTH_H       0x8     /* 8 bytes */
00062 #define LIBNET_OSPF_CKSUM   0x10    /* 16 bytes */
00063 
00064 
00065 /*
00066  *  Link State packet format lengths.
00067  */
00068 #define LIBNET_LS_RTR_LEN       0x10            /* 16 bytes */
00069 #define LIBNET_LS_NET_LEN       0x8             /* 8 bytes */
00070 #define LIBNET_LS_SUM_LEN       0xc             /* 12 bytes */  
00071 #define LIBNET_LS_AS_EXT_LEN    0x10            /* 16 bytes */  
00072 
00073 
00074 /*
00075  *  OSPFv2 Packet Header.
00076  */
00077 struct libnet_ospf_hdr
00078 {
00079     u_char ospf_v;                   /* version */
00080     u_char ospf_type;                /* type */
00081 #define  LIBNET_OSPF_UMD       0     /* UMd monitoring packet */
00082 #define  LIBNET_OSPF_HELLO     1     /* HELLO packet */
00083 #define  LIBNET_OSPF_DBD       2     /* DataBase Description Packet */
00084 #define  LIBNET_OSPF_LSR       3     /* Link State Request Packet */
00085 #define  LIBNET_OSPF_LSU       4     /* Link State Update Packet */
00086 #define  LIBNET_OSPF_LSA       5     /* Link State Acknowledgement Packet */
00087     u_short   ospf_len;              /* length */
00088     struct in_addr  ospf_rtr_id;     /* source router ID */ 
00089     struct in_addr  ospf_area_id;    /* roam ID */
00090     u_short ospf_cksum;              /* checksum */
00091     u_short ospf_auth_type;          /* authentication type */
00092 #define LIBNET_OSPF_AUTH_NULL   0    /* Null password */
00093 #define LIBNET_OSPF_AUTH_SIMPLE 1    /* Simple, plaintext, 8 char password */
00094 #define LIBNET_OSPF_AUTH_MD5    2    /* MD5 */
00095 };
00096 
00097 
00098 /*
00099  *  OSPF authentication header.
00100  */
00101 struct libnet_auth_hdr
00102 {
00103     u_short ospf_auth_null;         /* NULL */
00104     u_char  ospf_auth_keyid;        /* Authentication Key ID */
00105     u_char  ospf_auth_len;          /* Auth data length */
00106     u_int   ospf_auth_seq;          /* Cryptographic sequence number */
00107 };
00108 
00109 
00110 /*
00111  *  Options used in multiple OSPF packets.
00112  *  More info can be found in section A.2 of RFC 2328.
00113  */
00114 #define LIBNET_OPT_EBIT  0x02 /* Describes the way AS-external-LSAs are flooded */
00115 #define LIBNET_OPT_MCBIT 0x04 /* Whether or not IP multicast dgrams are fwdd */
00116 #define LIBNET_OPT_NPBIT 0x08 /* Describes handling of type-7 LSAs */
00117 #define LIBNET_OPT_EABIT 0x10 /* rtr's willingness to send/recv EA-LSAs */
00118 #define LIBNET_OPT_DCBIT 0x20 /* Describes handling of demand circuits */
00119 
00120 
00121 /*
00122  *  OSPF HELLO Packet Header.
00123  */
00124 struct libnet_ospf_hello_hdr
00125 {
00126     struct in_addr hello_nmask; /* Netmask associated with the interface */
00127     u_short hello_intrvl;       /* Num of seconds between routers last packet */
00128     u_char hello_opts;          /* Options for HELLO packets (look above) */
00129     u_char hello_rtr_pri;       /* Router's priority (if 0, can't be backup) */
00130     u_int hello_dead_intvl;     /* # of secs a router is silent till deemed down */
00131     struct in_addr hello_des_rtr;   /* Designated router on the network */
00132     struct in_addr hello_bkup_rtr;  /* Backup router */
00133     struct in_addr hello_nbr;       /* neighbor router, memcpy more as needed */
00134 };
00135 
00136 
00137 /*
00138  *  Database Description header.
00139  */
00140 struct libnet_dbd_hdr
00141 {
00142     u_short dbd_mtu_len;    /* Max length of IP dgram that this 'if' can use */
00143     u_char dbd_opts;        /* DBD packet options (look above) */
00144     u_char dbd_type;        /* Type of exchange occurring (look below) */
00145 #define LIBNET_DBD_IBIT    0x01    /* Init Bit */
00146 #define LIBNET_DBD_MBIT    0x02    /* Says more DBD packets are to come */
00147 #define LIBNET_DBD_MSBIT   0x04  /* If 1, sender is the master in the exchnge */
00148     u_int  dbd_seq;         /* DBD sequence number */
00149 };
00150 
00151 
00152 /*
00153  *  Used for the LS type field in all LS* headers.
00154  */
00155 #define LIBNET_LS_TYPE_RTR      1   /* Router-LSA */
00156 #define LIBNET_LS_TYPE_NET      2   /* Network-LSA */
00157 #define LIBNET_LS_TYPE_IP       3   /* Summary-LSA (IP Network) */
00158 #define LIBNET_LS_TYPE_ASBR    4   /* Summary-LSA (ASBR) */
00159 #define LIBNET_LS_TYPE_ASEXT    5   /* AS-External-LSA */
00160 
00161 
00162 /*
00163  *  Link State Request header.
00164  */
00165 struct libnet_lsr_hdr
00166 {
00167     u_int lsr_type;             /* Type of LS being requested (see below) */
00168     u_int lsr_lsid;             /* Link State ID */
00169     struct in_addr lsr_adrtr;   /* advertising router (memcpy more as needed) */
00170 };
00171 
00172 
00173 /*
00174  *  Link State Update header.
00175  */
00176 struct libnet_lsu_hdr
00177 {
00178     u_int lsu_num;              /* Number of LSAs that will be broadcasted */
00179 };
00180 
00181 
00182 /*
00183  *  Link State Acknowledgement header.
00184  */
00185 struct libnet_lsa_hdr
00186 {
00187     u_short lsa_age;        /* Time in seconds since the LSA was originated */
00188     u_char lsa_opts;        /* Look above for OPTS_* */
00189     u_char lsa_type;        /* Look below for LS_TYPE_* */
00190     u_int lsa_id;           /* Link State ID */
00191     struct in_addr lsa_adv; /* Router ID of Advertising router */
00192     u_int lsa_seq;          /* LSA sequence number to detect old/bad ones */
00193     u_char lsa_cksum[2];    /* "Fletcher Checksum" of all fields minus age */
00194     u_short lsa_len;        /* Length in bytes including the 20 byte header */
00195 };
00196 
00197 
00198 /*
00199  *  Router LSA data format
00200  *
00201  *  Other stuff for TOS can be added for backward compatability, for this
00202  *  version, only OSPFv2 is being FULLY supported.
00203  */
00204 
00205 struct libnet_rtr_lsa_hdr
00206 {
00207     u_short rtr_flags;      /* Set to help describe packet */
00208 #define LIBNET_RTR_FLAGS_W     0x0100  /* W bit */
00209 #define LIBNET_RTR_FLAGS_E     0x0200  /* E bit */
00210 #define LIBNET_RTR_FLAGS_B     0x0400  /* B bit */
00211     u_short rtr_num;        /* Number of links within that packet */
00212     u_int rtr_link_id;      /* Describes link_data (look below) */
00213 #define LIBNET_LINK_ID_NBR_ID  1       /* Neighbors router ID, also can be 4 */
00214 #define LIBNET_LINK_ID_IP_DES  2       /* IP address of designated router */
00215 #define LIBNET_LINK_ID_SUB     3       /* IP subnet number */
00216     u_int rtr_link_data;    /* Depending on link_id, info is here */
00217     u_char rtr_type;        /* Description of router link */
00218 #define LIBNET_RTR_TYPE_PTP    1   /* Point-To-Point */
00219 #define LIBNET_RTR_TYPE_TRANS  2   /* Connection to a "transit network" */
00220 #define LIBNET_RTR_TYPE_STUB   3   /* Connectin to a "stub network" */
00221 #define RTR_TYPE_VRTL   4   /* Connects to a "virtual link" */
00222     u_char rtr_tos_num;     /* Number of different TOS metrics for this link */
00223     u_short rtr_metric;     /* The "cost" of using this link */
00224 };
00225 
00226 
00227 /*
00228  *  Network LSA data format.
00229  */
00230 struct libnet_net_lsa_hdr
00231 {
00232     struct in_addr net_nmask;   /* Netmask for that network */
00233     u_int  net_rtr_id;          /* ID of router attached to that network */
00234 };
00235 
00236 
00237 /*
00238  *  Summary LSA data format.
00239  */
00240 struct libnet_sum_lsa_hdr
00241 {
00242     struct in_addr sum_nmask;   /* Netmask of destination IP address */
00243     u_int  sum_metric;          /* Same as in rtr_lsa (&0xfff to use last 24bit) */
00244     u_int  sum_tos_metric;      /* first 8bits are TOS, 24bits are TOS Metric */
00245 };
00246 
00247 
00248 /*
00249  *  AS External LSA data format.
00250  *  & 0xfff logic operator for as_metric to get last 24bits.
00251  */
00252 
00253 struct libnet_as_lsa_hdr
00254 {
00255     struct in_addr as_nmask;    /* Netmask for advertised destination */
00256     u_int  as_metric;           /* May have to set E bit in first 8bits */
00257 #define LIBNET_AS_E_BIT_ON 0x80000000  /* as_metric */
00258     struct in_addr as_fwd_addr; /* Forwarding address */
00259     u_int  as_rte_tag;          /* External route tag */
00260 };
00261 
00262 
00263 int
00264 libnet_build_ospf(
00265     u_short,
00266     u_char,
00267     u_long,
00268     u_long,
00269     u_short,
00270     const char *,
00271     int,
00272     u_char *
00273     );     
00274 
00275 
00276 int
00277 libnet_build_ospf_hello(
00278     u_long,
00279     u_short,
00280     u_char,
00281     u_char,
00282     u_int,
00283     u_long,
00284     u_long,
00285     u_long,
00286     const char *,
00287     int,
00288     u_char *
00289     );
00290 
00291 
00292 int
00293 libnet_build_ospf_dbd(
00294     u_short,
00295     u_char,
00296     u_char,
00297     u_int,
00298     const char *,
00299     int,
00300     u_char *
00301     );
00302 
00303 
00304 int
00305 libnet_build_ospf_lsr(
00306     u_int,
00307     u_int,
00308     u_long,
00309     const char *,
00310     int,
00311     u_char *
00312     );
00313 
00314 
00315 int
00316 libnet_build_ospf_lsu(
00317     u_int,
00318     const char *,
00319     int,
00320     u_char *
00321     );
00322 
00323 
00324 int
00325 libnet_build_ospf_lsa(
00326     u_short,
00327     u_char,
00328     u_char,
00329     u_int,
00330     u_long,
00331     u_int,
00332     u_short,
00333     const char *,
00334     int,
00335     u_char *
00336     );
00337 
00338 
00339 int
00340 libnet_build_ospf_lsa_rtr(
00341     u_short,
00342     u_short,
00343     u_int,
00344     u_int,
00345     u_char,
00346     u_char,
00347     u_short,
00348     const char *,
00349     int,
00350     u_char *
00351     );
00352 
00353 
00354 int
00355 libnet_build_ospf_lsa_net(
00356     u_long,
00357     u_int,
00358     const char *,
00359     int,
00360     u_char *
00361     );
00362 
00363 
00364 int
00365 libnet_build_ospf_lsa_sum(
00366     u_long,
00367     u_int,
00368     u_int,
00369     const char *,
00370     int,
00371     u_char *
00372     );
00373 
00374 
00375 int
00376 libnet_build_ospf_lsa_as(
00377     u_long,
00378     u_int,
00379     u_long, 
00380     u_int,
00381     const char *,
00382     int,
00383     u_char *
00384     );
00385 
00386 
00387 void
00388 libnet_ospf_lsa_checksum(
00389     u_char *,
00390     int
00391     );
00392 
00393 
00394 #endif /* __LIBNET_OSPF_H */

Generated on Sun May 14 14:51:19 2006 by  doxygen 1.4.2