Changeset 411666a for lib/protocols_l3.c


Ignore:
Timestamp:
12/19/07 11:17:58 (14 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:
a78665c
Parents:
287b2b4
Message:
  • Fixed get_payload_from_X functions not returning NULL in cases where they have a full X header but no subsequent payload (i.e. remaining would be exactly 0 upon return)
  • trace_get_layer3 should not be a SIMPLE_FUNCTION anymore
  • trace_get_ip now checks that at least a full IPv4 header is present
  • Calls to payload_from_ethernet functions inside trace_get_layer3 will now update remaining correctly
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/protocols_l3.c

    r75453c2 r411666a  
    1616                return NULL;
    1717
     18        /* Make sure we have at least a base IPv4 header */
     19        if (remaining < sizeof(libtrace_ip_t))
     20                return NULL;
     21       
    1822        /* Not an IPv4 packet */
    1923        if (((libtrace_ip_t*)ret)->ip_v != 4)
     
    5054
    5155        if (remaining) {
    52                 if (*remaining<(ipptr->ip_hl*4U)) {
     56                if (*remaining<=(ipptr->ip_hl*4U)) {
    5357                        return NULL;
    5458                }
     
    135139
    136140        link = trace_get_layer2(packet,&linktype,remaining);
    137 
    138141        iphdr = trace_get_payload_from_layer2(
    139142                        link,
     
    142145                        remaining);
    143146
    144         if (!iphdr)
    145                 return NULL;
    146 
     147        /* These should really update remaining */
    147148        for(;;) {
     149                if (!iphdr || *remaining == 0)
     150                        return NULL;
    148151                switch(*ethertype) {
    149152                case 0x8100: /* VLAN */
    150153                        iphdr=trace_get_vlan_payload_from_ethernet_payload(
    151                                           iphdr,ethertype,NULL);
     154                                          iphdr,ethertype,remaining);
    152155                        continue;
    153156                case 0x8847: /* MPLS */
    154157                        iphdr=trace_get_mpls_payload_from_ethernet_payload(
    155                                           iphdr,ethertype,NULL);
     158                                          iphdr,ethertype,remaining);
    156159
    157160                        if (iphdr && ethertype == 0x0) {
    158161                                iphdr=trace_get_payload_from_ethernet(
    159                                                 iphdr,ethertype,NULL);
     162                                                iphdr,ethertype,remaining);
    160163                        }
    161164                        continue;
     
    167170        }
    168171
     172        if (!iphdr || *remaining == 0)
     173                return NULL;
    169174        /* Store values in the cache for later */
    170175        /* Cast away constness, nasty, but this is just a cache */
    171176        ((libtrace_packet_t*)packet)->l3_ethertype = *ethertype;
    172177        ((libtrace_packet_t*)packet)->l3_header = iphdr;
    173 
    174178        return iphdr;
    175179}
Note: See TracChangeset for help on using the changeset viewer.