-
Notifications
You must be signed in to change notification settings - Fork 861
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
6 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters