Changeset 17c5749 for lib


Ignore:
Timestamp:
07/22/14 12:57:50 (7 years ago)
Author:
Richard Sanger <rsangerarj@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, 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:
41148f2
Parents:
54834a1 (diff), a6c77b0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge remote-tracking branch 'upsteam/develop' into FixingDPDK

Conflicts:

README
lib/format_linux.c
test/Makefile

Location:
lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • lib/format_linux.c

    rbcfe4ea r17c5749  
    11091109        if (check_queue) {
    11101110                // Check for a packet - TODO only Linux has MSG_DONTWAIT should use fctl O_NONBLOCK
    1111                 hdr->wirelen = recvmsg(fd, &msghdr, MSG_DONTWAIT);
     1111                hdr->wirelen = recvmsg(fd, &msghdr, MSG_DONTWAIT | MSG_TRUNC);
    11121112                if ((int) hdr->wirelen == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
    11131113                        // Do message queue check or select
     
    11361136                }
    11371137        } else {
    1138                 hdr->wirelen = recvmsg(fd, &msghdr, 0);
     1138                hdr->wirelen = recvmsg(fd, &msghdr, MSG_TRUNC);
    11391139        }
    11401140       
  • lib/format_pcap.c

    rb13b939 r17c5749  
    578578static libtrace_direction_t pcap_set_direction(libtrace_packet_t *packet,
    579579                libtrace_direction_t dir) {
    580        
     580
     581        /* We only support tagging with IN or OUT return error for any others */
     582        if(!(dir == TRACE_DIR_OUTGOING || dir == TRACE_DIR_INCOMING))
     583                return -1;
     584
    581585        /* PCAP doesn't have a direction field in the header, so we need to
    582586         * promote to Linux SLL to tag it properly */
  • lib/libtrace.h.in

    r50ce607 r17c5749  
    883883        uint8_t ospf_v;         /**< OSPF Version, should be 2 */
    884884        uint8_t type;           /**< OSPF Packet Type */
    885         uint16_t len;           /**< Packet length, including OSPF header */
     885        uint16_t ospf_len;      /**< Packet length, including OSPF header */
    886886        struct in_addr router;  /**< Router ID of the packet source */
    887887        struct in_addr area;    /**< Area the packet belongs to */
     
    12551255        TRACE_OPTION_COMPRESSTYPE_BZ2  = 2, /**< BZip2 Compression */
    12561256        TRACE_OPTION_COMPRESSTYPE_LZO  = 3,  /**< LZO Compression */
     1257        TRACE_OPTION_COMPRESSTYPE_LZMA  = 4,  /**< LZO Compression */
    12571258        TRACE_OPTION_COMPRESSTYPE_LAST
    12581259} trace_option_compresstype_t;
     
    17951796DLLEXPORT uint16_t *trace_checksum_transport(libtrace_packet_t *packet,
    17961797                uint16_t *csum);
     1798
     1799/** Calculates the fragment offset in bytes for an IP packet
     1800 * @param packet        The libtrace packet to calculate the offset for
     1801 * @param[out] more     A boolean flag to indicate whether there are more
     1802 *                      fragments after the current packet.
     1803 * @return The fragment offset for the packet in bytes. If the packet is not
     1804 * an IP packet or the fragment offset is not present in packet, the return
     1805 * value will be 0.
     1806 *
     1807 * @note The value returned is in bytes, not 8-octet units as it is stored
     1808 * in the fragment offset field in the headers. In other words, libtrace
     1809 * automatically does the multiplication for you.
     1810 *
     1811 * The value passed in for 'more' does not matter; it will be overwritten
     1812 * with the value of the More Fragments flag from the IP header.
     1813 *
     1814 * New in libtrace 3.0.20
     1815 */
     1816DLLEXPORT uint16_t trace_get_fragment_offset(const libtrace_packet_t *packet,
     1817                uint8_t *more);
    17971818
    17981819/** Gets a pointer to the transport layer header (if any)
  • lib/protocols_l3.c

    r9ca1fce r7baa948  
    724724}
    725725
     726DLLEXPORT uint16_t trace_get_fragment_offset(const libtrace_packet_t *packet,
     727                uint8_t *more) {
     728
     729        void *l3;
     730        uint16_t ethertype;
     731        uint32_t remaining;
     732
     733        *more = 0;
     734
     735        l3 = trace_get_layer3(packet, &ethertype, &remaining);
     736        if (l3 == NULL)
     737                return 0;
     738
     739        if (ethertype == TRACE_ETHERTYPE_IP) {
     740                libtrace_ip_t *ip = (libtrace_ip_t *)l3;
     741                uint16_t offset = 0;
     742
     743                /* Fragment offset appears in 7th and 8th bytes */
     744                if (remaining < 8)
     745                        return 0;
     746                 
     747                offset = ntohs(ip->ip_off);
     748
     749                if ((offset & 0x2000) != 0)
     750                        *more = 1;
     751                return (offset & 0x1FFF) * 8;
     752        }
     753
     754        if (ethertype == TRACE_ETHERTYPE_IPV6) {
     755                libtrace_ip6_t *ip6 = (libtrace_ip6_t *)l3;
     756                void *payload = ip6++;
     757                uint8_t nxt = ip6->nxt;
     758                uint16_t len;
     759               
     760                /* First task, find a Fragment header if present */
     761                if (remaining < sizeof(libtrace_ip6_t))
     762                        return 0;
     763                remaining -= sizeof(libtrace_ip6_t);
     764
     765                /* Adapted from trace_get_payload_from_ip6 */
     766                while (1) {
     767                        switch (nxt) {
     768                        case 0:
     769                        case TRACE_IPPROTO_ROUTING:
     770                        case TRACE_IPPROTO_AH:
     771                        case TRACE_IPPROTO_DSTOPTS:
     772                        {
     773
     774                                /* Length does not include the first 8 bytes */
     775                                len=((libtrace_ip6_ext_t*)payload)->len * 8;
     776                                len += 8;
     777
     778                                if (remaining < len) {
     779                                        /* Snap too short */
     780                                        return 0;
     781                                }
     782                                remaining-=len;
     783
     784                                nxt=((libtrace_ip6_ext_t*)payload)->nxt;
     785                                continue;
     786                        }
     787                        case TRACE_IPPROTO_FRAGMENT:
     788                        {
     789                                libtrace_ip6_frag_t *frag = (libtrace_ip6_frag_t *)payload;
     790                                uint16_t offset;
     791                                len = sizeof(libtrace_ip6_frag_t);
     792                                if (remaining < len) {
     793                                        /* Snap too short */
     794                                        return 0;
     795                                }
     796                                remaining-=len;
     797
     798                                offset = ntohs(frag->frag_off);
     799                                if ((offset & 0x0001) != 0)
     800                                        *more = 1;
     801
     802                                return ((offset & 0xFFF8) >> 3) * 8;
     803                         }
     804                         default:
     805                                return 0;
     806                         }
     807                }
     808
     809        }
     810        return 0;
     811}
  • lib/protocols_transport.c

    r10f924c re0bea4e5  
    382382        uint32_t remaining;
    383383        uint8_t proto;
    384         const struct ports_t *port =
    385                 (const struct ports_t*)trace_get_transport((libtrace_packet_t*)packet,
     384        struct ports_t *port;
     385        uint16_t fragoff;
     386        uint8_t more;
     387
     388        fragoff = trace_get_fragment_offset(packet, &more);
     389
     390        /* If we're not the first fragment, we're unlikely to be able
     391         * to get any useful port numbers from this packet.
     392         */
     393        if (fragoff != 0)
     394                return 0;
     395       
     396       
     397        port = (struct ports_t*)trace_get_transport(
     398                        (libtrace_packet_t*)packet,
    386399                        &proto, &remaining);
    387400
     
    391404
    392405        /* ICMP *technically* doesn't have ports */
    393         if (proto == TRACE_IPPROTO_ICMP)
     406        if (proto == TRACE_IPPROTO_ICMP || proto == TRACE_IPPROTO_ICMPV6)
    394407                return 0;
    395408
     
    405418        uint32_t remaining;
    406419        uint8_t proto;
    407         struct ports_t *port =
    408                 (struct ports_t*)trace_get_transport((libtrace_packet_t*)packet,
     420        struct ports_t *port;
     421        uint16_t fragoff;
     422        uint8_t more;
     423
     424        fragoff = trace_get_fragment_offset(packet, &more);
     425
     426        /* If we're not the first fragment, we're unlikely to be able
     427         * to get any useful port numbers from this packet.
     428         */
     429        if (fragoff != 0)
     430                return 0;
     431       
     432       
     433        port = (struct ports_t*)trace_get_transport(
     434                        (libtrace_packet_t*)packet,
    409435                        &proto, &remaining);
    410436        /* Snapped too early */
     
    413439       
    414440        /* ICMP *technically* doesn't have ports */
    415         if (proto == TRACE_IPPROTO_ICMP)
     441        if (proto == TRACE_IPPROTO_ICMP || proto == TRACE_IPPROTO_ICMPV6)
    416442                return 0;
    417443
Note: See TracChangeset for help on using the changeset viewer.