Changeset cc6fcee


Ignore:
Timestamp:
01/06/12 11:25:39 (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:
e224862
Parents:
29532e3
Message:
  • Added a function for parsing OSPF packets that contain LSA headers only, e.g. LS Acks, as we can't rely on the LSA length field to tell us how long the LSA in these packets is :(
Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/libtrace.h.in

    r29532e3 rcc6fcee  
    20092009 *
    20102010 * @note This function only works for OSPF version 2 packets.
    2011  * @note Use trace_get_first_ospf_lsa() and trace_get_next_ospf_lsa() to read the LSAs from Link State Request
    2012  * and Update packets.
     2011 * @note Use trace_get_first_ospf_lsa_v2_from_X() and trace_get_next_ospf_lsa_v2() to read the LSAs from Link State Update packets.
     2012 * @note Use trace_get_first_ospf_lsa_v2_from_X() and trace_get_next_ospf_lsa_header_v2() to read the LSA headers from Link State Ack packets.
    20132013 *
    20142014 */
     
    20452045                uint8_t *lsa_type,
    20462046                uint16_t *lsa_length);
     2047
     2048DLLEXPORT SIMPLE_FUNCTION
     2049int trace_get_next_ospf_lsa_header_v2(unsigned char **current,
     2050                libtrace_ospf_lsa_v2_t **lsa_hdr,
     2051                uint32_t *remaining,
     2052                uint8_t *lsa_type,
     2053                uint16_t *lsa_length);
     2054
    20472055
    20482056DLLEXPORT SIMPLE_FUNCTION
  • lib/protocols_transport.c

    r29532e3 rcc6fcee  
    353353}
    354354
     355DLLEXPORT int trace_get_next_ospf_lsa_header_v2(unsigned char **current,
     356                libtrace_ospf_lsa_v2_t **lsa_hdr,
     357                uint32_t *remaining,
     358                uint8_t *lsa_type,
     359                uint16_t *lsa_length) {
     360       
     361        int valid_lsa = 0;
     362
     363        if (*current == NULL || *remaining < sizeof(libtrace_ospf_lsa_v2_t)) {
     364                *lsa_hdr = NULL;
     365                *remaining = 0;
     366                return 0;
     367
     368        }
     369
     370        *lsa_hdr = (libtrace_ospf_lsa_v2_t *)(*current);
     371       
     372        /* Check that the LSA type is valid */
     373        switch ((*lsa_hdr)->lsa_type) {
     374                case TRACE_OSPF_LS_ROUTER:
     375                case TRACE_OSPF_LS_NETWORK:
     376                case TRACE_OSPF_LS_SUMMARY:
     377                case TRACE_OSPF_LS_ASBR_SUMMARY:
     378                case TRACE_OSPF_LS_EXTERNAL:
     379                        valid_lsa = 1;
     380                        break;
     381        }
     382       
     383        /* This function is for reading LSA headers only, e.g. those in DB desc
     384         * or LS Ack packets. As such, I'm going to set the type and length to
     385         * values that should prevent anyone from trying to treat subsequent
     386         * payload as an LSA body */
     387        *lsa_type = 0;
     388        *lsa_length = sizeof(libtrace_ospf_lsa_v2_t);
     389
     390        if (!valid_lsa) {
     391                *remaining = 0;
     392                return -1;
     393        }
     394       
     395        *remaining -= *lsa_length;
     396        *current += *lsa_length;
     397
     398        if (remaining == 0) {
     399                /* No more LSAs */
     400                return 0;
     401        }
     402
     403        return 1;
     404}
     405
    355406DLLEXPORT int trace_get_next_ospf_lsa_v2(unsigned char **current,
    356407                libtrace_ospf_lsa_v2_t **lsa_hdr,
     
    392443                 * that is NOT a legit LSA */
    393444                *remaining = 0;
     445                *lsa_body = NULL;
    394446                return -1;
    395447        }
Note: See TracChangeset for help on using the changeset viewer.