Add printing function for Generic Protocol Extension for VXLAN

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
This commit is contained in:
bugyo 2015-11-15 16:24:19 +00:00 committed by Francois-Xavier Le Bail
parent c66320c670
commit ba8a8cd5a3
12 changed files with 318 additions and 0 deletions

View File

@ -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 \

View File

@ -585,10 +585,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);

174
print-nsh.c Normal file
View File

@ -0,0 +1,174 @@
/* 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"
static const char tstr[] = " [|NSH]";
static const struct tok nsh_flags [] = {
{ 0x20, "O" },
{ 0x10, "C" },
{ 0, NULL }
};
#define NSH_BASE_HDR_LEN 4
#define NSH_SERVICE_PATH_HDR_LEN 4
#define NSH_HDR_WORD_SIZE 4
/*
* NSH, draft-ietf-sfc-nsh-01 Network Service Header
*/
void
nsh_print(netdissect_options *ndo, const u_char *bp, u_int len)
{
int n, vn;
uint8_t ver;
uint8_t flags;
uint8_t length;
uint8_t md_type;
uint8_t next_protocol;
uint32_t service_path_id;
uint8_t service_index;
uint32_t ctx;
uint16_t tlv_class;
uint8_t tlv_type;
uint8_t tlv_len;
u_int next_len;
/* print Base Header and Service Path Header */
if (len < NSH_BASE_HDR_LEN + NSH_SERVICE_PATH_HDR_LEN)
goto trunc;
ND_TCHECK2(*bp, NSH_BASE_HDR_LEN + NSH_SERVICE_PATH_HDR_LEN);
ver = (uint8_t)(*bp >> 6);
flags = *bp;
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;
ND_PRINT((ndo, "NSH, "));
if (ndo->ndo_vflag > 1) {
ND_PRINT((ndo, "ver %d, ", ver));
}
ND_PRINT((ndo, "flags [%s], ", bittok2str_nosep(nsh_flags, "none", flags)));
if (ndo->ndo_vflag > 2) {
ND_PRINT((ndo, "length %d, ", length));
ND_PRINT((ndo, "md type 0x%x, ", md_type));
}
if (ndo->ndo_vflag > 1) {
ND_PRINT((ndo, "next-protocol 0x%x, ", next_protocol));
}
ND_PRINT((ndo, "service-path-id 0x%06x, ", service_path_id));
ND_PRINT((ndo, "service-index 0x%x", service_index));
/* print Context Headers */
if (len < length * NSH_HDR_WORD_SIZE)
goto trunc;
ND_TCHECK2(*bp, length * NSH_HDR_WORD_SIZE);
if (ndo->ndo_vflag > 2) {
if (md_type == 0x01) {
for (n = 0; n < length - 2; n++) {
ctx = EXTRACT_32BITS(bp);
bp += NSH_HDR_WORD_SIZE;
ND_PRINT((ndo, "\n Context[%02d]: 0x%08x", n, ctx));
}
}
else if (md_type == 0x02) {
n = 0;
while (n < length - 2) {
tlv_class = EXTRACT_16BITS(bp);
bp += 2;
tlv_type = *bp;
bp += 1;
tlv_len = *bp;
bp += 1;
ND_PRINT((ndo, "\n TLV Class %d, Type %d, Len %d",
tlv_class, tlv_type, tlv_len));
n += 1;
if (length - 2 < n + tlv_len) {
ND_PRINT((ndo, " ERROR: invalid-tlv-length"));
return;
}
for (vn = 0; vn < tlv_len; vn++) {
ctx = EXTRACT_32BITS(bp);
bp += NSH_HDR_WORD_SIZE;
ND_PRINT((ndo, "\n Value[%02d]: 0x%08x", vn, ctx));
}
n += tlv_len;
}
}
else {
ND_PRINT((ndo, "ERROR: unknown-next-protocol"));
return;
}
}
else {
bp += (length - 2) * NSH_HDR_WORD_SIZE;
}
ND_PRINT((ndo, ndo->ndo_vflag ? "\n " : ": "));
/* print Next Protocol */
next_len = len - length * NSH_HDR_WORD_SIZE;
switch (next_protocol) {
case 0x1:
ip_print(ndo, bp, next_len);
break;
case 0x2:
ip6_print(ndo, bp, next_len);
break;
case 0x3:
ether_print(ndo, bp, next_len, next_len, NULL, NULL);
break;
default:
ND_PRINT((ndo, "ERROR: unknown-next-protocol"));
return;
}
return;
trunc:
ND_PRINT((ndo, "%s", tstr));
}

View File

@ -646,6 +646,8 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
geneve_print(ndo, (const u_char *)(up + 1), length);
else if (IS_SRC_OR_DST_PORT(LISP_CONTROL_PORT))
lisp_print(ndo, (const u_char *)(up + 1), length);
else if (IS_SRC_OR_DST_PORT(VXLAN_GPE_PORT))
vxlan_gpe_print(ndo, (const u_char *)(up + 1), length);
else if (ND_TTEST(((const struct LAP *)cp)->type) &&
((const struct LAP *)cp)->type == lapDDP &&
(atalk_port(sport) || atalk_port(dport))) {

109
print-vxlan-gpe.c Normal file
View File

@ -0,0 +1,109 @@
/* 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"
static const char tstr[] = " [|VXLAN-GPE]";
static const struct tok vxlan_gpe_flags [] = {
{ 0x08, "I" },
{ 0x04, "P" },
{ 0x01, "O" },
{ 0, NULL }
};
#define VXLAN_GPE_HDR_LEN 8
/*
* 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 < VXLAN_GPE_HDR_LEN)
goto trunc;
ND_TCHECK2(*bp, VXLAN_GPE_HDR_LEN);
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], ",
bittok2str_nosep(vxlan_gpe_flags, "none", flags)));
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, "ERROR: unknown-next-protocol"));
return;
}
return;
trunc:
ND_PRINT((ndo, "%s", tstr));
}

View File

@ -336,3 +336,9 @@ pcap-invalid-version-2 pcap-invalid-version-2.pcap pcap-invalid-version-2.out -t
# pcap-ng invalid version (first: version = 0.1 ; second: version = 1.1)
pcap-ng-invalid-vers-1 pcap-ng-invalid-vers-1.pcap pcap-ng-invalid-vers-1.out -t
pcap-ng-invalid-vers-2 pcap-ng-invalid-vers-2.pcap pcap-ng-invalid-vers-2.out -t
# NSH over VxLAN-GPE
nsh-over-vxlan-gpe nsh-over-vxlan-gpe.pcap nsh-over-vxlan-gpe.out -t
nsh-over-vxlan-gpe-v nsh-over-vxlan-gpe.pcap nsh-over-vxlan-gpe-v.out -t -v
nsh-over-vxlan-gpe-vv nsh-over-vxlan-gpe.pcap nsh-over-vxlan-gpe-vv.out -t -vv
nsh-over-vxlan-gpe-vvv nsh-over-vxlan-gpe.pcap nsh-over-vxlan-gpe-vvv.out -t -vvv

View File

@ -0,0 +1,5 @@
IP (tos 0x0, ttl 64, id 16419, offset 0, flags [DF], proto UDP (17), length 92)
127.0.0.1.4790 > 127.0.0.1.4790: VXLAN-GPE, flags [IP], vni 16777215
NSH, flags [OC], service-path-id 0xffffff, service-index 0xff
IP (tos 0x0, ttl 255, id 54321, offset 0, flags [none], proto UDP (17), length 32)
192.168.0.1.10000 > 192.168.0.2.20000: UDP, length 4

View File

@ -0,0 +1,5 @@
IP (tos 0x0, ttl 64, id 16419, offset 0, flags [DF], proto UDP (17), length 92)
127.0.0.1.4790 > 127.0.0.1.4790: [udp sum ok] VXLAN-GPE, flags [IP], vni 16777215
NSH, ver 0, flags [OC], next-protocol 0x1, service-path-id 0xffffff, service-index 0xff
IP (tos 0x0, ttl 255, id 54321, offset 0, flags [none], proto UDP (17), length 32)
192.168.0.1.10000 > 192.168.0.2.20000: [udp sum ok] UDP, length 4

View File

@ -0,0 +1,9 @@
IP (tos 0x0, ttl 64, id 16419, offset 0, flags [DF], proto UDP (17), length 92)
127.0.0.1.4790 > 127.0.0.1.4790: [udp sum ok] VXLAN-GPE, flags [IP], vni 16777215
NSH, ver 0, flags [OC], length 6, md type 0x2, next-protocol 0x1, service-path-id 0xffffff, service-index 0xff
TLV Class 1, Type 2, Len 1
Value[00]: 0x12345678
TLV Class 2, Type 3, Len 1
Value[00]: 0x12345678
IP (tos 0x0, ttl 255, id 54321, offset 0, flags [none], proto UDP (17), length 32)
192.168.0.1.10000 > 192.168.0.2.20000: [udp sum ok] UDP, length 4

View File

@ -0,0 +1 @@
IP 127.0.0.1.4790 > 127.0.0.1.4790: VXLAN-GPE, flags [IP], vni 16777215: NSH, flags [OC], service-path-id 0xffffff, service-index 0xff: IP 192.168.0.1.10000 > 192.168.0.2.20000: UDP, length 4

Binary file not shown.

3
udp.h
View File

@ -263,6 +263,9 @@ struct udphdr {
#ifndef VXLAN_PORT
#define VXLAN_PORT 4789 /* RFC 7348 */
#endif
#ifndef VXLAN_GPE_PORT
#define VXLAN_GPE_PORT 4790 /* draft-ietf-nvo3-vxlan-gpe-01 */
#endif
#ifndef SIP_DS_PORT
#define SIP_DS_PORT 5059 /*XXX*/
#endif