Skip to content

Commit

Permalink
Add printing function for Generic Protocol Extension for VXLAN
Browse files Browse the repository at this point in the history
and Network Service Header.

This code stands for following internet drafts:

- VXLAN GPE: draft-ietf-nvo3-vxlan-gpe-01
- NSH: draft-ietf-sfc-nsh-01
  • Loading branch information
bugyo committed Nov 16, 2015
1 parent 255a101 commit f823638
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ LIBNETDISSECT_SRC=\
print-vrrp.c \
print-vtp.c \
print-vxlan.c \
print-vxlan-gpe.c \
print-nsh.c \
print-wb.c \
print-zephyr.c \
print-zeromq.c \
Expand Down
2 changes: 2 additions & 0 deletions netdissect.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,12 @@ extern void vqp_print(netdissect_options *, register const u_char *, register u_
extern void vrrp_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
extern void vtp_print(netdissect_options *, const u_char *, u_int);
extern void vxlan_print(netdissect_options *, const u_char *, u_int);
extern void vxlan_gpe_print(netdissect_options *ndo, const u_char *bp, u_int len);
extern void wb_print(netdissect_options *, const void *, u_int);
extern void zephyr_print(netdissect_options *, const u_char *, int);
extern void zmtp1_print(netdissect_options *, const u_char *, u_int);
extern void zmtp1_print_datagram(netdissect_options *, const u_char *, const u_int);
extern void nsh_print(netdissect_options *ndo, const u_char *bp, u_int len);

/* checksum routines */
extern void init_checksum(void);
Expand Down
113 changes: 113 additions & 0 deletions print-nsh.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* Copyright (c) 2015, bugyo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <netdissect-stdinc.h>

#include "netdissect.h"
#include "extract.h"

/*
* NSH, draft-ietf-sfc-nsh-01 Network Service Header
*/

void
nsh_print(netdissect_options *ndo, const u_char *bp, u_int len)
{
uint16_t tmp16;
uint8_t ver;
uint8_t flag_o;
uint8_t flag_c;
uint8_t length;
uint8_t md_type;
uint8_t next_protocol;
uint32_t service_path_id;
uint8_t service_index;
uint32_t net_plt_ctx;
uint32_t net_shd_ctx;
uint32_t svc_plt_ctx;
uint32_t svc_shd_ctx;

if (len < 24) {
ND_PRINT((ndo, "[|NSH]"));
return;
}

ver = (uint8_t)(*bp >> 6);
flag_o = *bp & 0x20;
flag_c = *bp & 0x10;
bp += 1;
length = *bp;
bp += 1;
md_type = *bp;
bp += 1;
next_protocol = *bp;
bp += 1;
service_path_id = EXTRACT_24BITS(bp);
bp += 3;
service_index = *bp;
bp += 1;
net_plt_ctx = EXTRACT_32BITS(bp);
bp += 4;
net_shd_ctx = EXTRACT_32BITS(bp);
bp += 4;
svc_plt_ctx = EXTRACT_32BITS(bp);
bp += 4;
svc_shd_ctx = EXTRACT_32BITS(bp);
bp += 4;

ND_PRINT((ndo, "NSH, "));
if (1 < ndo->ndo_vflag) {
ND_PRINT((ndo, "ver %d, ", ver));
}
ND_PRINT((ndo, "flags [%s%s], ", flag_o ? "O" : "", flag_c ? "C" : ""));
if (1 < ndo->ndo_vflag) {
ND_PRINT((ndo, "MD Type 0x%x, ", md_type));
}
if (1 < ndo->ndo_vflag) {
ND_PRINT((ndo, "Next Protocol 0x%x, ", next_protocol));
}
ND_PRINT((ndo, "Service Path ID 0x%08x, ", service_path_id));
ND_PRINT((ndo, "Service Index 0x%x", service_index));
ND_PRINT((ndo, ndo->ndo_vflag ? "\n " : ": "));

switch (next_protocol) {
case 0x1:
ip_print(ndo, bp, len - 24);
break;
case 0x2:
ip6_print(ndo, bp, len - 24);
break;
case 0x3:
ether_print(ndo, bp, len - 24, len - 24, NULL, NULL);
break;
default:
ND_PRINT((ndo, "[|NSH]"));
return;
}
}

2 changes: 2 additions & 0 deletions print-udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
otv_print(ndo, (const u_char *)(up + 1), length);
else if (ISPORT(VXLAN_PORT))
vxlan_print(ndo, (const u_char *)(up + 1), length);
else if (ISPORT(VXLAN_GPE_PORT))
vxlan_gpe_print(ndo, (const u_char *)(up + 1), length);
else if (ISPORT(GENEVE_PORT))
geneve_print(ndo, (const u_char *)(up + 1), length);
else if (ISPORT(LISP_CONTROL_PORT))
Expand Down
96 changes: 96 additions & 0 deletions print-vxlan-gpe.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* Copyright (c) 2015, bugyo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <netdissect-stdinc.h>

#include "netdissect.h"
#include "extract.h"

/*
* VXLAN GPE header, draft-ietf-nvo3-vxlan-gpe-01
* Generic Protocol Extension for VXLAN
*
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |R|R|Ver|I|P|R|O| Reserved |Next Protocol |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | VXLAN Network Identifier (VNI) | Reserved |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/

void
vxlan_gpe_print(netdissect_options *ndo, const u_char *bp, u_int len)
{
uint8_t flags;
uint8_t next_protocol;
uint32_t vni;

if (len < 8) {
ND_PRINT((ndo, "[|VXLAN-GPE]"));
return;
}

flags = *bp;
bp += 3;

next_protocol = *bp;
bp += 1;

vni = EXTRACT_24BITS(bp);
bp += 4;

ND_PRINT((ndo, "VXLAN-GPE, "));
ND_PRINT((ndo, "flags [%s%s%s], ",
flags & 0x08 ? "I" : "",
flags & 0x04 ? "P" : "",
flags & 0x01 ? "O" : ""));
ND_PRINT((ndo, "vni %u", vni));
ND_PRINT((ndo, ndo->ndo_vflag ? "\n " : ": "));

switch (next_protocol) {
case 0x1:
ip_print(ndo, bp, len - 8);
break;
case 0x2:
ip6_print(ndo, bp, len - 8);
break;
case 0x3:
ether_print(ndo, bp, len - 8, len - 8, NULL, NULL);
break;
case 0x4:
nsh_print(ndo, bp, len - 8);
break;
case 0x5:
mpls_print(ndo, bp, len - 8);
break;
default:
ND_PRINT((ndo, "[|VXLAN-GPE]"));
return;
}
}
3 changes: 3 additions & 0 deletions udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ struct udphdr {
#ifndef VXLAN_PORT
#define VXLAN_PORT 4789 /* RFC 7348 */
#endif
#ifndef VXLAN_GPE_PORT
#define VXLAN_GPE_PORT 4790 /* draft-quinn-vxlan-gpe-04 */
#endif
#ifndef SIP_DS_PORT
#define SIP_DS_PORT 5059 /*XXX*/
#endif
Expand Down

0 comments on commit f823638

Please sign in to comment.