Changeset 1453435


Ignore:
Timestamp:
01/06/12 16:43:16 (10 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
cb64286
Parents:
f46f7f4
Message:
  • Fixed bug where OSPF Hello packets did not support multiple neighbours
  • Updated OSPF Hello libpacketdump decoder to report all neighbours
  • Updated documentation to describe OSPF structures
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/libtrace.h.in

    rf46f7f4 r1453435  
    765765typedef struct libtrace_ospf_v2_t
    766766{
    767         uint8_t ospf_v;
    768         uint8_t type;
    769         uint16_t len;
    770         struct in_addr router;
    771         struct in_addr area;
    772         uint16_t sum;
    773         uint16_t au_type;
    774         uint16_t zero;
    775         uint8_t au_key_id;
    776         uint8_t au_data_len;
    777         uint32_t au_seq_num;
     767        uint8_t ospf_v;         /**< OSPF Version, should be 2 */
     768        uint8_t type;           /**< OSPF Packet Type */
     769        uint16_t len;           /**< Packet length, including OSPF header */
     770        struct in_addr router;  /**< Router ID of the packet source */
     771        struct in_addr area;    /**< Area the packet belongs to */
     772        uint16_t sum;           /**< Checksum */
     773        uint16_t au_type;       /**< Authentication procedure */
     774        uint16_t zero;          /**< Always zero */
     775        uint8_t au_key_id;      /**< Authentication Key ID */
     776        uint8_t au_data_len;    /**< Authentication Data Length */
     777        uint32_t au_seq_num;    /**< Cryptographic Sequence Number */
    778778} PACKED libtrace_ospf_v2_t;
    779779
     780/** Options Field present in some OSPFv2 packets */
    780781typedef struct libtrace_ospf_options_t {
    781782#if BYTE_ORDER == LITTLE_ENDIAN
     
    798799} PACKED libtrace_ospf_options_t;
    799800
     801/* LSA Header for OSPFv2 */
    800802typedef struct libtrace_ospf_lsa_v2_t
    801803{
    802         uint16_t age;
    803         libtrace_ospf_options_t lsa_options;
    804         uint8_t lsa_type;
    805         struct in_addr ls_id;
    806         struct in_addr adv_router;
    807         uint32_t seq;
    808         uint16_t checksum;
    809         uint16_t length;
     804        uint16_t age;           /**< Time in seconds since LSA originated */
     805        libtrace_ospf_options_t lsa_options;    /**< Options */
     806        uint8_t lsa_type;       /**< LSA type */
     807        struct in_addr ls_id;   /**< Link State ID */
     808        struct in_addr adv_router; /**< Router that originated this LSA */
     809        uint32_t seq;           /**< LS sequence number */
     810        uint16_t checksum;      /**< Checksum */
     811        uint16_t length;        /**< Length of the LSA including LSA header */
    810812} PACKED libtrace_ospf_lsa_v2_t;
    811813
     814/** OSPFv2 Hello Packet */
    812815typedef struct libtrace_ospf_hello_v2_t
    813816{
    814         struct in_addr mask;
    815         uint16_t interval;
    816         libtrace_ospf_options_t hello_options;
    817         uint8_t priority;
    818         uint32_t deadint;
    819         struct in_addr designated;
    820         struct in_addr backup;
    821         struct in_addr neighbor;
     817        struct in_addr mask;    /**< Network mask for this interface */
     818        uint16_t interval;      /**< Interval between Hello packets (secs) */
     819        libtrace_ospf_options_t hello_options;  /**< Options */
     820        uint8_t priority;       /**< Router Priority */
     821        uint32_t deadint;       /**< Interval before declaring a router down */
     822        struct in_addr designated;      /**< Designated router for the network */
     823        struct in_addr backup;  /**< Backup designated router */
     824
     825        /** Neighbors follow from here, but there can be anywhere from 1 to N
     826         * neighbors so I can't include that here */
    822827} PACKED libtrace_ospf_hello_v2_t;
    823828
     829/** OSPFv2 Database Description packet */
    824830typedef struct libtrace_ospf_db_desc_v2_t
    825831{
    826         uint16_t mtu;
    827         uint8_t db_desc_options;
     832        uint16_t mtu;           /**< Interface MTU */
     833        libtrace_ospf_options_t db_desc_options;        /**< Options */
    828834#if BYTE_ORDER == LITTLE_ENDIAN
    829         LT_BITFIELD8 db_desc_ms:1;
    830         LT_BITFIELD8 db_desc_m:1;
    831         LT_BITFIELD8 db_desc_i:1;
     835        LT_BITFIELD8 db_desc_ms:1;      /**< If set, this router is the master */
     836        LT_BITFIELD8 db_desc_m:1;       /**< If set, more packets to follow */
     837        LT_BITFIELD8 db_desc_i:1;       /**< If set, this is the first packet in sequence */
    832838        LT_BITFIELD8 zero:5;
    833839#elif BYTE_ORDER == BIG_ENDIAN
    834840        LT_BITFIELD8 zero:5;
    835         LT_BITFIELD8 db_desc_i:1;
    836         LT_BITFIELD8 db_desc_m:1;
    837         LT_BITFIELD8 db_desc_ms:1;
     841        LT_BITFIELD8 db_desc_i:1;       /**< If set, this is the first packet in sequence */
     842        LT_BITFIELD8 db_desc_m:1;       /**< If set, more packets to follow */
     843        LT_BITFIELD8 db_desc_ms:1;      /**< If set, this router is the master */
    838844#endif
    839         uint32_t seq;
     845        uint32_t seq;           /**< Sequence number for DD packets */
    840846} PACKED libtrace_ospf_db_desc_v2_t;
    841847
     848/** OSPF Link State Request Packet */
    842849typedef struct libtrace_ospf_ls_req_t
    843850{
    844         uint32_t ls_type;
    845         uint32_t ls_id;
    846         uint32_t advertising_router;
     851        uint32_t ls_type;       /**< Link State Type */
     852        uint32_t ls_id;         /**< Link State Id */
     853        uint32_t advertising_router;    /**< Advertising Router */
    847854} PACKED libtrace_ospf_ls_req_t;
    848855
     856/** OSPF Link State Update Packet */
    849857typedef struct libtrace_ospf_ls_update_t
    850858{
    851         uint32_t ls_num_adv;
     859        uint32_t ls_num_adv;    /**< Number of LSAs in this packet */
     860
     861        /* Followed by LSAs, use API functions to access these */
    852862} PACKED libtrace_ospf_ls_update_t;
    853863
     864/** OSPFv2 AS External LSA Body */
    854865typedef struct libtrace_ospf_as_external_lsa_t
    855866{
    856         struct in_addr netmask;
     867        struct in_addr netmask; /**< Netmask for the destination */
    857868#if BYTE_ORDER == LITTLE_ENDIAN
    858869        LT_BITFIELD8 tos:7;
    859         LT_BITFIELD8 e:1;
     870        LT_BITFIELD8 e:1;       /**< If set, metric is Type 2. Else, Type 1 */
    860871#elif BYTE_ORDER == BIG_ENDIAN
    861         LT_BITFIELD8 e:1;
     872        LT_BITFIELD8 e:1;       /**< If set, metric is Type 2. Else, Type 1 */
    862873        LT_BITFIELD8 tos:7;
    863874#endif
    864         uint8_t metric_a;
    865         uint8_t metric_b;
    866         uint8_t metric_c;       
    867         struct in_addr forwarding;
    868         uint32_t external_tag;
     875        uint8_t metric_a;       /**< Byte 1 of the Metric field */
     876        uint8_t metric_b;       /**< Byte 2 of the Metric field */
     877        uint8_t metric_c;       /**< Byte 3 of the Metric field */
     878        struct in_addr forwarding;      /**< Forwarding address */
     879        uint32_t external_tag;          /**< External Route Tag */
    869880} PACKED libtrace_ospf_as_external_lsa_v2_t;
    870881
     882/** OSPFv2 Summary LSA Body */
    871883typedef struct libtrace_ospf_summary_lsa
    872884{
    873         struct in_addr netmask;
    874         uint8_t zero;
    875         uint8_t metric_a;
    876         uint8_t metric_b;
    877         uint8_t metric_c;       
     885        struct in_addr netmask; /**< Netmask for the destination */
     886        uint8_t zero;           /**< Always zero */
     887        uint8_t metric_a;       /**< Byte 1 of the Metric field */
     888        uint8_t metric_b;       /**< Byte 2 of the Metric field */
     889        uint8_t metric_c;       /**< Byte 3 of the Metric field */
    878890       
    879891} PACKED libtrace_ospf_summary_lsa_v2_t;
    880892
     893/** OSPFv2 Network LSA Body */
    881894typedef struct libtrace_ospf_network_lsa_t
    882895{
    883         struct in_addr netmask;
     896        struct in_addr netmask; /**< Netmask for the network */
     897        /* Followed by IDs of attached routers */
    884898} PACKED libtrace_ospf_network_lsa_v2_t;
    885899
     900/** OSPFv2 Router Link structure */
    886901typedef struct libtrace_ospf_link_t
    887902{
    888         struct in_addr link_id;
    889         struct in_addr link_data;
    890         uint8_t type;
    891         uint8_t num_tos;
    892         uint16_t tos_metric;
     903        struct in_addr link_id;         /**< Object that link connects to */
     904        struct in_addr link_data;       /**< Link Data field */
     905        uint8_t type;                   /**< Link Type */
     906        uint8_t num_tos;                /**< Number of TOS metrics */
     907        uint16_t tos_metric;            /**< Cost of router link */
    893908} PACKED libtrace_ospf_link_v2_t;
    894909
     910/** OSPFv2 Router LSA */
    895911typedef struct libtrace_ospf_router_lsa_t
    896912{
    897913#if BYTE_ORDER == LITTLE_ENDIAN
    898         LT_BITFIELD8 b:1;
    899         LT_BITFIELD8 e:1;
    900         LT_BITFIELD8 v:1;
     914        LT_BITFIELD8 b:1;       /**< Area Border Router Flag */
     915        LT_BITFIELD8 e:1;       /**< External Router Flag */
     916        LT_BITFIELD8 v:1;       /**< Virtual Endpoint Flag */
    901917        LT_BITFIELD8 zero:5;
    902918#elif BYTE_ORDER == BIG_ENDIAN
    903919        LT_BITFIELD8 zero:5;
    904         LT_BITFIELD8 v:1;
    905         LT_BITFIELD8 e:1;
    906         LT_BITFIELD8 b:1;
     920        LT_BITFIELD8 v:1;       /**< Virtual Endpoint Flag */
     921        LT_BITFIELD8 e:1;       /**< External Router Flag */
     922        LT_BITFIELD8 b:1;       /**< Area Border Router Flag */
    907923#endif
    908         uint8_t zero2;
    909         uint16_t num_links;
     924        uint8_t zero2;          /**< Always zero */
     925        uint16_t num_links;     /**< Number of links in LSA */
    910926} PACKED libtrace_ospf_router_lsa_v2_t;
    911927
    912928typedef enum {
    913         TRACE_OSPF_HELLO = 1,
    914         TRACE_OSPF_DATADESC = 2,
    915         TRACE_OSPF_LSREQ = 3,
    916         TRACE_OSPF_LSUPDATE = 4,
    917         TRACE_OSPF_LSACK = 5
     929        TRACE_OSPF_HELLO = 1,           /**< OSPF Hello */
     930        TRACE_OSPF_DATADESC = 2,        /**< OSPF Database Description */
     931        TRACE_OSPF_LSREQ = 3,           /**< OSPF Link State Request */
     932        TRACE_OSPF_LSUPDATE = 4,        /**< OSPF Link State Update */
     933        TRACE_OSPF_LSACK = 5            /**< OSPF Link State Acknowledgement */
    918934} libtrace_ospf_types_t;
    919935
    920936typedef enum {
    921         TRACE_OSPF_LS_ROUTER = 1,
    922         TRACE_OSPF_LS_NETWORK = 2,
    923         TRACE_OSPF_LS_SUMMARY = 3,
    924         TRACE_OSPF_LS_ASBR_SUMMARY = 4,
    925         TRACE_OSPF_LS_EXTERNAL = 5
     937        TRACE_OSPF_LS_ROUTER = 1,       /**< OSPF Router LSA */
     938        TRACE_OSPF_LS_NETWORK = 2,      /**< OSPF Network LSA */
     939        TRACE_OSPF_LS_SUMMARY = 3,      /**< OSPF Summary LSA */
     940        TRACE_OSPF_LS_ASBR_SUMMARY = 4, /**< OSPF Summary LSA (ASBR) */
     941        TRACE_OSPF_LS_EXTERNAL = 5      /**< OSPF AS External LSA */
    926942} libtrace_ospf_ls_types_t;
    927943
  • libpacketdump/ospf2_1.c

    re224862 r1453435  
    1010
    1111        libtrace_ospf_hello_v2_t *hello = (libtrace_ospf_hello_v2_t *)packet;
    12        
     12        struct in_addr *neigh;
     13
    1314        if (len < 4)
    1415                return;
     
    5354                return;
    5455
    55         printf(" OSPF Hello: Designated Router: %s\n", inet_ntoa(hello->designated));
     56        printf(" OSPF Hello: Designated Router %s\n", inet_ntoa(hello->designated));
    5657
    5758        if (len < 20)
    5859                return;
    5960
    60         printf(" OSPF Hello: Backup Designated Router: %s\n", inet_ntoa(hello->backup));
     61        printf(" OSPF Hello: Backup Designated Router %s\n", inet_ntoa(hello->backup));
    6162
    62         if (len < 24)
    63                 return;
    64        
    65         printf(" OSPF Hello: Neighbour: %s\n", inet_ntoa(hello->backup));
     63        neigh = (struct in_addr *)(packet + sizeof(libtrace_ospf_hello_v2_t));
     64        len -= sizeof(libtrace_ospf_hello_v2_t);
     65        while (len >= 4) {
     66                printf(" OSPF Hello: Neighbour %s\n", inet_ntoa(*neigh));
     67                neigh++;
     68                len -= sizeof(struct in_addr);
     69        }
     70
     71
    6672
    6773        return;
Note: See TracChangeset for help on using the changeset viewer.