Changeset 3fc3267


Ignore:
Timestamp:
02/02/15 16:59:34 (6 years ago)
Author:
Shane Alcock <salcock@…>
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:
3440627
Parents:
68d3308
Message:

Add protocol decoder functions for GRE and VXLAN

Many thanks to Perry Lorier for providing this patch.

Includes a test-case for VXLAN parsing.

Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • lib/Makefile.am

    re5dedd5 r3fc3267  
    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

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

    re0bea4e5 r3fc3267  
    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 r3fc3267  
    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 r3fc3267  
    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.