Changeset 6d082e6


Ignore:
Timestamp:
02/02/15 16:28:37 (6 years ago)
Author:
Perry Lorier <git@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, master, ndag_format, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
3fe009c
Parents:
ea602cd
git-author:
Perry Lorier <git@…> (02/02/15 13:40:23)
git-committer:
Perry Lorier <git@…> (02/02/15 16:28:37)
Message:

Add support for VXLAN and GRE.

Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • lib/Makefile.am

    re5dedd5 r6d082e6  
    2121
    2222if HAVE_LLVM
    23 BPFJITSOURCE=bpf-jit/bpf-jit.cc 
     23BPFJITSOURCE=bpf-jit/bpf-jit.cc
    2424else
    2525BPFJITSOURCE=
     
    5454                protocols_pktmeta.c protocols_l2.c protocols_l3.c \
    5555                protocols_transport.c protocols.h protocols_ospf.c \
     56                protocols_application.c \
    5657                $(DAGSOURCE) format_erf.h \
    5758                $(BPFJITSOURCE) \
  • lib/libtrace.h.in

    r17f954f r6d082e6  
    808808} PACKED libtrace_pppoe_t;
    809809
     810/** Libtrace local definition of GRE (Generalised Routing Protocol) header
     811 * RFC2890
     812 */
     813typedef struct libtrace_gre_t
     814{
     815    uint16_t flags;         /**< Flags and version */
     816    uint16_t ethertype;     /**< Payload ethertype */
     817    uint16_t checksum;      /**< Optional checksum */
     818    uint16_t reserved1;     /**< Optional reserved */
     819    uint16_t key;           /**< Optional key (or Tenant Network ID) */
     820    uint16_t seq;           /**< Optional sequence number */
     821} PACKED libtrace_gre_t;
     822
     823#define LIBTRACE_GRE_FLAG_CHECKSUM 0x8000
     824#define LIBTRACE_GRE_FLAG_KEY      0x2000
     825#define LIBTRACE_GRE_FLAG_SEQ      0x1000
     826#define LIBTRACE_GRE_FLAG_VERMASK  0x0007
     827
     828/** Libtrace local definition of VXLAN Header
     829 * (draft-mahalingam-dutt-dcops-vxlan)
     830 */
     831typedef struct libtrace_vxlan_t
     832{
     833    uint8_t flags;          /**< Flags */
     834    uint8_t reserved1[3];   /**< Reserved */
     835    uint8_t vni[3];         /**< VXLAN Network Identifier (VNI) */
     836    uint8_t reserved2;
     837} PACKED libtrace_vxlan_t;
     838
    810839/** 802.11 header */
    811840typedef struct libtrace_80211_t {
     
    20712100                uint32_t *remaining);
    20722101
     2102/** Gets a pointer to the payload following a GRE header
     2103 * @param         gre       A pointer to the beginning of the GRE header.
     2104 * @param[in,out] remaining Updated with the number of captured bytes remaining.
     2105 *
     2106 * @return A pointer to the GRE payload, or NULL if the GRE header is truncated.
     2107 *
     2108 * When calling this function, remaining must contain the number of captured
     2109 * bytes remaining in the packet starting from the GRE header (including the
     2110 * GRE header itself). remaining will be updated to contain the number of
     2111 * bytes remaining after the GRE header has been skipped.
     2112 *
     2113 * If the GRE header is complete but there are zero bytes of payload after
     2114 * the header, a pointer to where the payload would be is returned and
     2115 * remaining will be set to 0.  If the GRE header is incomplete, NULL will be
     2116 * returned and remaining will be set to 0. Therefore, it is important to check
     2117 * the value of remaining after calling this function.
     2118 */
     2119DLLEXPORT void *trace_get_payload_from_gre(libtrace_gre_t *gre,
     2120                uint32_t *remaining);
     2121
     2122/** Gets a pointer to the payload following a VXLAN header
     2123 * @param         udp       A pointer to the beginning of the UDP header.
     2124 * @param[in,out] remaining Updated with the number of captured bytes remaining.
     2125 *
     2126 * @return A pointer to the beginning of the VXLAN header, or NULL if the UDP
     2127 * header is truncated, or this is not a VXLAN packet.
     2128 *
     2129 */
     2130DLLEXPORT libtrace_vxlan_t *trace_get_vxlan_from_udp(libtrace_udp_t *udp,
     2131                uint32_t *remaining);
     2132
     2133/** Gets a pointer to the payload following a VXLAN header
     2134 * @param         vxlan       A pointer to the beginning of the VXLAN header.
     2135 * @param[in,out] remaining Updated with the number of captured bytes remaining.
     2136 *
     2137 * @return A pointer to the VXLAN payload, or NULL if the VXLAN header is
     2138 * truncated.
     2139 *
     2140 * When calling this function, remaining must contain the number of captured
     2141 * bytes remaining in the packet starting from the VXLAN header (including the
     2142 * VXLAN header itself). remaining will be updated to contain the number of
     2143 * bytes remaining after the VXLAN header has been skipped.
     2144 *
     2145 * If the VXLAN header is complete but there are zero bytes of payload after
     2146 * the header, a pointer to where the payload would be is returned and
     2147 * remaining will be set to 0.  If the VXLAN header is incomplete, NULL will be
     2148 * returned and remaining will be set to 0. Therefore, it is important to check
     2149 * the value of remaining after calling this function.
     2150 */
     2151DLLEXPORT void *trace_get_payload_from_vxlan(libtrace_vxlan_t *vxlan,
     2152                uint32_t *remaining);
     2153
    20732154/** Get a pointer to the TCP header (if present)
    20742155 * @param packet        The packet to get the TCP header from
  • lib/protocols_transport.c

    re0bea4e5 r6d082e6  
    553553        return csum_ptr;
    554554}
     555
     556DLLEXPORT void *trace_get_payload_from_gre(libtrace_gre_t *gre,
     557        uint32_t *remaining)
     558{
     559    uint32_t size = 4; /* GRE is 4 bytes long by default */
     560    if (remaining && *remaining < size) {
     561        *remaining = 0;
     562        return NULL;
     563    }
     564
     565    if ((ntohs(gre->flags) & LIBTRACE_GRE_FLAG_CHECKSUM) != 0) {
     566        size += 4;  /* An extra 4 bytes. */
     567    }
     568
     569    if ((ntohs(gre->flags) & LIBTRACE_GRE_FLAG_KEY) != 0) {
     570        size += 4;  /* An extra 4 bytes. */
     571    }
     572
     573    if ((ntohs(gre->flags) & LIBTRACE_GRE_FLAG_SEQ) != 0) {
     574        size += 4;  /* An extra 4 bytes. */
     575    }
     576
     577    if (remaining) {
     578        if (*remaining < size) {
     579            *remaining = 0;
     580            return NULL;
     581        }
     582        *remaining -= size;
     583    }
     584    return (char*)gre+size;
     585}
  • test/Makefile

    r262a093 r6d082e6  
    99CFLAGS += $(INCLUDE)
    1010libdir = $(PREFIX)/lib/.libs:$(PREFIX)/libpacketdump/.libs
    11 LDLIBS = -L$(PREFIX)/lib/.libs -L$(PREFIX)/libpacketdump/.libs -ltrace -lpacketdump 
     11LDLIBS = -L$(PREFIX)/lib/.libs -L$(PREFIX)/libpacketdump/.libs -ltrace -lpacketdump
    1212
    1313BINS = test-pcap-bpf test-event test-time test-dir test-wireless test-errors \
    14         test-plen test-autodetect test-ports test-fragment test-live test-live-snaplen
     14        test-plen test-autodetect test-ports test-fragment test-live \
     15        test-live-snaplen test-vxlan
    1516
    1617.PHONY: all clean distclean install depend test
  • test/do-tests.sh

    r95b6218 r6d082e6  
    230230do_test ./test-autodetect traces/5_packets.erf.xz
    231231
     232echo " * VXLan decode"
     233do_test ./test-vxlan
     234
    232235echo
    233236echo "Tests passed: $OK"
Note: See TracChangeset for help on using the changeset viewer.