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 :(
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.