From fdff1e6ed540f2a04792fb64e04b0c7862dc2b8c Mon Sep 17 00:00:00 2001 From: "Keith Burns (alagalah)" Date: Wed, 4 May 2016 16:11:38 -0700 Subject: VPP-39 - refactoring of NSH into own folder - common header files and structs used in both GRE and VXLAN-GPE Change-Id: I06d0b773e936fb011408817237059f24a4beb412 Signed-off-by: Keith Burns (alagalah) --- vnet/Makefile.am | 13 ++++- vnet/vnet/nsh-gre/decap.c | 22 ++++---- vnet/vnet/nsh-gre/nsh_gre.c | 97 +++++++++++++++++++-------------- vnet/vnet/nsh-gre/nsh_gre.h | 27 +++------ vnet/vnet/nsh-gre/nsh_gre_error.def | 17 ------ vnet/vnet/nsh-gre/nsh_gre_packet.h | 93 ------------------------------- vnet/vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.c | 76 +++++++++++++++----------- vnet/vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h | 20 +------ vnet/vnet/nsh/nsh_error.def | 17 ++++++ vnet/vnet/nsh/nsh_packet.h | 92 +++++++++++++++++++++++++++++++ 10 files changed, 239 insertions(+), 235 deletions(-) delete mode 100644 vnet/vnet/nsh-gre/nsh_gre_error.def delete mode 100644 vnet/vnet/nsh-gre/nsh_gre_packet.h create mode 100644 vnet/vnet/nsh/nsh_error.def create mode 100644 vnet/vnet/nsh/nsh_packet.h (limited to 'vnet') diff --git a/vnet/Makefile.am b/vnet/Makefile.am index a69734d1530..9393c1a8772 100644 --- a/vnet/Makefile.am +++ b/vnet/Makefile.am @@ -396,6 +396,15 @@ nobase_include_HEADERS += \ vnet/mpls-gre/error.def +######################################## +# NSH Map: nsh +######################################## + +nobase_include_HEADERS += \ + vnet/nsh/nsh_packet.h \ + vnet/nsh/nsh_error.def + + ######################################## # Tunnel protocol: nsh-gre ######################################## @@ -406,9 +415,7 @@ libvnet_la_SOURCES += \ vnet/nsh-gre/decap.c nobase_include_HEADERS += \ - vnet/nsh-gre/nsh_gre.h \ - vnet/nsh-gre/nsh_gre_packet.h \ - vnet/nsh-gre/nsh_gre_error.def + vnet/nsh-gre/nsh_gre.h ######################################## # Tunnel protocol: nsh-vxlan-gpe diff --git a/vnet/vnet/nsh-gre/decap.c b/vnet/vnet/nsh-gre/decap.c index 2b6ae9a7d4c..c10b11b3070 100644 --- a/vnet/vnet/nsh-gre/decap.c +++ b/vnet/vnet/nsh-gre/decap.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include vlib_node_registration_t nsh_input_node; @@ -42,10 +42,10 @@ u8 * format_nsh_header_with_length (u8 * s, va_list * args) s = format (s, "ver %d ", h->ver_o_c>>6); - if (h->ver_o_c & NSH_GRE_O_BIT) + if (h->ver_o_c & NSH_O_BIT) s = format (s, "O-set "); - if (h->ver_o_c & NSH_GRE_C_BIT) + if (h->ver_o_c & NSH_C_BIT) s = format (s, "C-set "); s = format (s, "len %d (%d bytes) md_type %d next_protocol %d\n", @@ -54,8 +54,8 @@ u8 * format_nsh_header_with_length (u8 * s, va_list * args) tmp = clib_net_to_host_u32 (h->spi_si); s = format (s, " spi %d si %d ", - (tmp>>NSH_GRE_SPI_SHIFT) & NSH_GRE_SPI_MASK, - tmp & NSH_GRE_SINDEX_MASK); + (tmp>>NSH_SPI_SHIFT) & NSH_SPI_MASK, + tmp & NSH_SINDEX_MASK); s = format (s, "c1 %u c2 %u c3 %u c4 %u", clib_net_to_host_u32 (h->c1), @@ -171,8 +171,8 @@ nsh_gre_input (vlib_main_t * vm, tunnel_index1 = ~0; error0 = 0; error1 = 0; - next0 = NSH_INPUT_NEXT_DROP; - next1 = NSH_INPUT_NEXT_DROP; + next0 = NSH_GRE_INPUT_NEXT_DROP; + next1 = NSH_GRE_INPUT_NEXT_DROP; if (PREDICT_FALSE(key0 != last_key)) { @@ -332,7 +332,7 @@ nsh_gre_input (vlib_main_t * vm, tunnel_index0 = ~0; error0 = 0; - next0 = NSH_INPUT_NEXT_DROP; + next0 = NSH_GRE_INPUT_NEXT_DROP; if (PREDICT_FALSE(key0 != last_key)) { @@ -418,7 +418,7 @@ nsh_gre_input (vlib_main_t * vm, static char * nsh_error_strings[] = { #define nsh_gre_error(n,s) s, -#include +#include #undef nsh_gre_error #undef _ }; @@ -432,9 +432,9 @@ VLIB_REGISTER_NODE (nsh_gre_input_node) = { .n_errors = NSH_GRE_N_ERROR, .error_strings = nsh_error_strings, - .n_next_nodes = NSH_INPUT_N_NEXT, + .n_next_nodes = NSH_GRE_INPUT_N_NEXT, .next_nodes = { -#define _(s,n) [NSH_INPUT_NEXT_##s] = n, +#define _(s,n) [NSH_GRE_INPUT_NEXT_##s] = n, foreach_nsh_gre_input_next #undef _ }, diff --git a/vnet/vnet/nsh-gre/nsh_gre.c b/vnet/vnet/nsh-gre/nsh_gre.c index be49e86bca3..e75ed9dd862 100644 --- a/vnet/vnet/nsh-gre/nsh_gre.c +++ b/vnet/vnet/nsh-gre/nsh_gre.c @@ -28,13 +28,13 @@ static u8 * format_decap_next (u8 * s, va_list * args) switch (next_index) { - case NSH_INPUT_NEXT_DROP: + case NSH_GRE_INPUT_NEXT_DROP: return format (s, "drop"); - case NSH_INPUT_NEXT_IP4_INPUT: + case NSH_GRE_INPUT_NEXT_IP4_INPUT: return format (s, "ip4"); - case NSH_INPUT_NEXT_IP6_INPUT: + case NSH_GRE_INPUT_NEXT_IP6_INPUT: return format (s, "ip6"); - case NSH_INPUT_NEXT_ETHERNET_INPUT: + case NSH_GRE_INPUT_NEXT_ETHERNET_INPUT: return format (s, "ethernet"); default: return format (s, "index %d", next_index); @@ -57,22 +57,22 @@ u8 * format_nsh_gre_tunnel (u8 * s, va_list * args) s = format (s, " decap-next %U\n", format_decap_next, t->decap_next_index); - s = format (s, " ver %d ", (t->ver_o_c>>6)); - if (t->ver_o_c & NSH_GRE_O_BIT) + s = format (s, " ver %d ", (t->nsh_hdr.ver_o_c>>6)); + if (t->nsh_hdr.ver_o_c & NSH_O_BIT) s = format (s, "O-set "); - if (t->ver_o_c & NSH_GRE_C_BIT) + if (t->nsh_hdr.ver_o_c & NSH_C_BIT) s = format (s, "C-set "); s = format (s, "len %d (%d bytes) md_type %d next_protocol %d\n", - t->length, t->length * 4, t->md_type, t->next_protocol); + t->nsh_hdr.length, t->nsh_hdr.length * 4, t->nsh_hdr.md_type, t->nsh_hdr.next_protocol); s = format (s, " service path %d service index %d\n", - (t->spi_si>>NSH_GRE_SPI_SHIFT) & NSH_GRE_SPI_MASK, - t->spi_si & NSH_GRE_SINDEX_MASK); + (t->nsh_hdr.spi_si>>NSH_SPI_SHIFT) & NSH_SPI_MASK, + t->nsh_hdr.spi_si & NSH_SINDEX_MASK); s = format (s, " c1 %d c2 %d c3 %d c4 %d\n", - t->c1, t->c2, t->c3, t->c4); + t->nsh_hdr.c1, t->nsh_hdr.c2, t->nsh_hdr.c3, t->nsh_hdr.c4); return s; } @@ -148,19 +148,22 @@ _(src.as_u32) \ _(dst.as_u32) \ _(encap_fib_index) \ _(decap_fib_index) \ -_(decap_next_index) \ -_(ver_o_c) \ -_(length) \ -_(md_type) \ -_(next_protocol) \ -_(spi_si) \ -_(c1) \ -_(c2) \ -_(c3) \ -_(c4) \ +_(decap_next_index) + + +#define foreach_copy_nshhdr_field \ +_(ver_o_c) \ +_(length) \ +_(md_type) \ +_(next_protocol) \ +_(spi_si) \ +_(c1) \ +_(c2) \ +_(c3) \ +_(c4) \ _(tlvs) -#define foreach_32bit_field \ +#define foreach_32bit_field \ _(spi_si) \ _(c1) \ _(c2) \ @@ -175,7 +178,7 @@ static int nsh_gre_rewrite (nsh_gre_tunnel_t * t) ip4_gre_and_nsh_header_t * h0; int len; - len = sizeof (*h0) + vec_len(t->tlvs)*4; + len = sizeof (*h0) + vec_len(t->nsh_hdr.tlvs)*4; vec_validate_aligned (rw, len-1, CLIB_CACHE_LINE_BYTES); @@ -196,14 +199,14 @@ static int nsh_gre_rewrite (nsh_gre_tunnel_t * t) /* NSH header */ nsh0 = &h0->nsh; - nsh0->ver_o_c = t->ver_o_c; - nsh0->md_type = t->md_type; - nsh0->next_protocol = t->next_protocol; - nsh0->spi_si = t->spi_si; - nsh0->c1 = t->c1; - nsh0->c2 = t->c2; - nsh0->c3 = t->c3; - nsh0->c4 = t->c4; + nsh0->ver_o_c = t->nsh_hdr.ver_o_c; + nsh0->md_type = t->nsh_hdr.md_type; + nsh0->next_protocol = t->nsh_hdr.next_protocol; + nsh0->spi_si = t->nsh_hdr.spi_si; + nsh0->c1 = t->nsh_hdr.c1; + nsh0->c2 = t->nsh_hdr.c2; + nsh0->c3 = t->nsh_hdr.c3; + nsh0->c4 = t->nsh_hdr.c4; /* Endian swap 32-bit fields */ #define _(x) nsh0->x = clib_host_to_net_u32(nsh0->x); @@ -211,12 +214,12 @@ static int nsh_gre_rewrite (nsh_gre_tunnel_t * t) #undef _ /* fix nsh header length */ - t->length = 6 + vec_len(t->tlvs); - nsh0->length = t->length; + t->nsh_hdr.length = 6 + vec_len(t->nsh_hdr.tlvs); + nsh0->length = t->nsh_hdr.length; /* Copy any TLVs */ - if (vec_len(t->tlvs)) - clib_memcpy (nsh0->tlvs, t->tlvs, 4*vec_len(t->tlvs)); + if (vec_len(t->nsh_hdr.tlvs)) + clib_memcpy (nsh0->tlvs, t->nsh_hdr.tlvs, 4*vec_len(t->nsh_hdr.tlvs)); t->rewrite = rw; return (0); @@ -236,7 +239,7 @@ int vnet_nsh_gre_add_del_tunnel (vnet_nsh_gre_add_del_tunnel_args_t *a, u64 key; u32 spi_si_net_byte_order; - spi_si_net_byte_order = clib_host_to_net_u32(a->spi_si); + spi_si_net_byte_order = clib_host_to_net_u32(a->nsh_hdr.spi_si); key = (((u64)(a->src.as_u32))<<32) | spi_si_net_byte_order; @@ -248,7 +251,7 @@ int vnet_nsh_gre_add_del_tunnel (vnet_nsh_gre_add_del_tunnel_args_t *a, if (p) return VNET_API_ERROR_INVALID_VALUE; - if (a->decap_next_index >= NSH_INPUT_N_NEXT) + if (a->decap_next_index >= NSH_GRE_INPUT_N_NEXT) return VNET_API_ERROR_INVALID_DECAP_NEXT; pool_get_aligned (ngm->tunnels, t, CLIB_CACHE_LINE_BYTES); @@ -259,6 +262,11 @@ int vnet_nsh_gre_add_del_tunnel (vnet_nsh_gre_add_del_tunnel_args_t *a, foreach_copy_field; #undef _ + /* copy from arg structure */ +#define _(x) t->nsh_hdr.x = a->nsh_hdr.x; + foreach_copy_nshhdr_field; +#undef _ + rv = nsh_gre_rewrite (t); if (rv) @@ -334,13 +342,13 @@ static uword unformat_decap_next (unformat_input_t * input, va_list * args) u32 tmp; if (unformat (input, "drop")) - *result = NSH_INPUT_NEXT_DROP; + *result = NSH_GRE_INPUT_NEXT_DROP; else if (unformat (input, "ip4")) - *result = NSH_INPUT_NEXT_IP4_INPUT; + *result = NSH_GRE_INPUT_NEXT_IP4_INPUT; else if (unformat (input, "ip6")) - *result = NSH_INPUT_NEXT_IP6_INPUT; + *result = NSH_GRE_INPUT_NEXT_IP6_INPUT; else if (unformat (input, "ethernet")) - *result = NSH_INPUT_NEXT_ETHERNET_INPUT; + *result = NSH_GRE_INPUT_NEXT_ETHERNET_INPUT; else if (unformat (input, "%d", &tmp)) *result = tmp; else @@ -463,7 +471,12 @@ nsh_gre_add_del_tunnel_command_fn (vlib_main_t * vm, #define _(x) a->x = x; foreach_copy_field; #undef _ - + + /* copy from arg structure */ +#define _(x) a->nsh_hdr.x = x; + foreach_copy_nshhdr_field; +#undef _ + rv = vnet_nsh_gre_add_del_tunnel (a, 0 /* hw_if_indexp */); switch(rv) diff --git a/vnet/vnet/nsh-gre/nsh_gre.h b/vnet/vnet/nsh-gre/nsh_gre.h index 580942f0f19..abe115580cb 100644 --- a/vnet/vnet/nsh-gre/nsh_gre.h +++ b/vnet/vnet/nsh-gre/nsh_gre.h @@ -17,7 +17,7 @@ #include #include -#include +#include #include typedef CLIB_PACKED (struct { @@ -46,15 +46,8 @@ typedef struct { u32 sw_if_index; /* NSH header fields in HOST byte order */ - u8 ver_o_c; - u8 length; - u8 md_type; - u8 next_protocol; - u32 spi_si; - - /* Context headers, always present, in HOST byte order */ - u32 c1, c2, c3, c4; - u32 * tlvs; + nsh_header_t nsh_hdr; + } nsh_gre_tunnel_t; #define foreach_nsh_gre_input_next \ @@ -64,15 +57,15 @@ typedef struct { _ (ETHERNET_INPUT, "ethernet-input") typedef enum { -#define _(s,n) NSH_INPUT_NEXT_##s, +#define _(s,n) NSH_GRE_INPUT_NEXT_##s, foreach_nsh_gre_input_next #undef _ - NSH_INPUT_N_NEXT, + NSH_GRE_INPUT_N_NEXT, } nsh_gre_input_next_t; typedef enum { #define nsh_gre_error(n,s) NSH_GRE_ERROR_##n, -#include +#include #undef nsh_gre_error NSH_GRE_N_ERROR, } nsh_gre_input_error_t; @@ -108,13 +101,7 @@ typedef struct { u32 encap_fib_index; u32 decap_fib_index; u32 decap_next_index; - u8 ver_o_c; - u8 length; - u8 md_type; - u8 next_protocol; - u32 spi_si; - u32 c1, c2, c3, c4; - u32 * tlvs; + nsh_header_t nsh_hdr; } vnet_nsh_gre_add_del_tunnel_args_t; int vnet_nsh_gre_add_del_tunnel (vnet_nsh_gre_add_del_tunnel_args_t *a, diff --git a/vnet/vnet/nsh-gre/nsh_gre_error.def b/vnet/vnet/nsh-gre/nsh_gre_error.def deleted file mode 100644 index 532b02a6e89..00000000000 --- a/vnet/vnet/nsh-gre/nsh_gre_error.def +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2015 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -nsh_gre_error (DECAPSULATED, "good packets decapsulated") -nsh_gre_error (NO_SUCH_TUNNEL, "no such tunnel packets") -nsh_gre_error (INVALID_NEXT_PROTOCOL, "invalid next protocol") diff --git a/vnet/vnet/nsh-gre/nsh_gre_packet.h b/vnet/vnet/nsh-gre/nsh_gre_packet.h deleted file mode 100644 index 0620f227b9f..00000000000 --- a/vnet/vnet/nsh-gre/nsh_gre_packet.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2015 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef included_vnet_nsh_gre_packet_h -#define included_vnet_nsh_gre_packet_h - -/* - * NSH_GRE packet format from draft-quinn-sfc-nsh-03.txt - * - * NSH Base Header - * 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 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * |Ver|O|C|R|R|R|R|R|R| Length | MD Type | Next Protocol | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - * - * Base Header Field Descriptions: - * - * Version: The version field is used to ensure backward compatibility - * going forward with future NSH updates. - * - * O bit: Indicates that this packet is an operations and management - * (OAM) packet. SFF and SFs nodes MUST examine the payload and take - * appropriate action (e.g. return status information). - * - * OAM message specifics and handling details are outside the scope of - * this document. - * - * C bit: Indicates that a critical metadata TLV is present (see section - * 7). This bit acts as an indication for hardware implementers to - * decide how to handle the presence of a critical TLV without - * necessarily needing to parse all TLVs present. The C bit MUST be set - * to 1 if one or more critical TLVs are present. - * - * All other flag fields are reserved. - * - * Length: total length, in 4 byte words, of the NSH header, including - * optional variable TLVs. Length must be equal or greater than 6. - * - * MD Type: indicates the format of NSH beyond the base header and the - * type of metadata being carried. This typing is used to describe the - * use for the metadata. A new registry will be requested from IANA for - * the MD Type. NSH defines one type, type = 0x1 which indicates that - * the format of the header is as per this draft. - * - * The format of the base header is invariant, and not described by MD - * Type. - * - * Next Protocol: indicates the protocol type of the original packet. A - * new IANA registry will be created for protocol type. - * - * This draft defines the following Next Protocol values: - * - * 0x1 : IPv4 - * 0x2 : IPv6 - * 0x3 : Ethernet - */ - -typedef CLIB_PACKED(struct { - u8 ver_o_c; - u8 length; - u8 md_type; - u8 next_protocol; - u32 spi_si; - /* Context headers, always present */ - u32 c1; u32 c2; u32 c3; u32 c4; - - /* Optional variable length metadata */ - u32 tlvs[0]; -}) nsh_header_t; - -#define NSH_GRE_VERSION (0<<6) -#define NSH_GRE_O_BIT (1<<5) -#define NSH_GRE_C_BIT (1<<4) - -/* Network byte order shift / mask */ -#define NSH_GRE_SINDEX_MASK 0xFF -#define NSH_GRE_SPI_MASK (0x00FFFFFF) -#define NSH_GRE_SPI_SHIFT 8 - -#endif /* included_vnet_nsh_gre_packet_h */ diff --git a/vnet/vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.c b/vnet/vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.c index d96ba57b1cf..88945cd8762 100644 --- a/vnet/vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.c +++ b/vnet/vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.c @@ -52,22 +52,22 @@ u8 * format_nsh_vxlan_gpe_tunnel (u8 * s, va_list * args) t->decap_fib_index); s = format (s, " decap next %U\n", format_decap_next, t->decap_next_index); s = format (s, " vxlan VNI %d ", t->vni); - s = format (s, "nsh ver %d ", (t->ver_o_c>>6)); - if (t->ver_o_c & NSH_GRE_O_BIT) + s = format (s, "nsh ver %d ", (t->nsh_hdr.ver_o_c>>6)); + if (t->nsh_hdr.ver_o_c & NSH_O_BIT) s = format (s, "O-set "); - if (t->ver_o_c & NSH_GRE_C_BIT) + if (t->nsh_hdr.ver_o_c & NSH_C_BIT) s = format (s, "C-set "); s = format (s, "len %d (%d bytes) md_type %d next_protocol %d\n", - t->length, t->length * 4, t->md_type, t->next_protocol); + t->nsh_hdr.length, t->nsh_hdr.length * 4, t->nsh_hdr.md_type, t->nsh_hdr.next_protocol); s = format (s, " service path %d service index %d\n", - (t->spi_si>>NSH_GRE_SPI_SHIFT) & NSH_GRE_SPI_MASK, - t->spi_si & NSH_GRE_SINDEX_MASK); + (t->nsh_hdr.spi_si>>NSH_SPI_SHIFT) & NSH_SPI_MASK, + t->nsh_hdr.spi_si & NSH_SINDEX_MASK); s = format (s, " c1 %d c2 %d c3 %d c4 %d\n", - t->c1, t->c2, t->c3, t->c4); + t->nsh_hdr.c1, t->nsh_hdr.c2, t->nsh_hdr.c3, t->nsh_hdr.c4); return s; } @@ -144,19 +144,22 @@ _(dst.as_u32) \ _(vni) \ _(encap_fib_index) \ _(decap_fib_index) \ -_(decap_next_index) \ -_(ver_o_c) \ -_(length) \ -_(md_type) \ -_(next_protocol) \ -_(spi_si) \ -_(c1) \ -_(c2) \ -_(c3) \ -_(c4) \ +_(decap_next_index) + + +#define foreach_copy_nshhdr_field \ +_(ver_o_c) \ +_(length) \ +_(md_type) \ +_(next_protocol) \ +_(spi_si) \ +_(c1) \ +_(c2) \ +_(c3) \ +_(c4) \ _(tlvs) -#define foreach_32bit_field \ +#define foreach_32bit_field \ _(spi_si) \ _(c1) \ _(c2) \ @@ -171,7 +174,7 @@ static int nsh_vxlan_gpe_rewrite (nsh_vxlan_gpe_tunnel_t * t) ip4_vxlan_gpe_and_nsh_header_t * h0; int len; - len = sizeof (*h0) + vec_len(t->tlvs)*4; + len = sizeof (*h0) + vec_len(t->nsh_hdr.tlvs)*4; vec_validate_aligned (rw, len-1, CLIB_CACHE_LINE_BYTES); @@ -200,14 +203,14 @@ static int nsh_vxlan_gpe_rewrite (nsh_vxlan_gpe_tunnel_t * t) /* NSH header */ nsh0 = &h0->nsh; - nsh0->ver_o_c = t->ver_o_c; - nsh0->md_type = t->md_type; - nsh0->next_protocol = t->next_protocol; - nsh0->spi_si = t->spi_si; - nsh0->c1 = t->c1; - nsh0->c2 = t->c2; - nsh0->c3 = t->c3; - nsh0->c4 = t->c4; + nsh0->ver_o_c = t->nsh_hdr.ver_o_c; + nsh0->md_type = t->nsh_hdr.md_type; + nsh0->next_protocol = t->nsh_hdr.next_protocol; + nsh0->spi_si = t->nsh_hdr.spi_si; + nsh0->c1 = t->nsh_hdr.c1; + nsh0->c2 = t->nsh_hdr.c2; + nsh0->c3 = t->nsh_hdr.c3; + nsh0->c4 = t->nsh_hdr.c4; /* Endian swap 32-bit fields */ #define _(x) nsh0->x = clib_host_to_net_u32(nsh0->x); @@ -215,12 +218,12 @@ static int nsh_vxlan_gpe_rewrite (nsh_vxlan_gpe_tunnel_t * t) #undef _ /* fix nsh header length */ - t->length = 6 + vec_len(t->tlvs); - nsh0->length = t->length; + t->nsh_hdr.length = 6 + vec_len(t->nsh_hdr.tlvs); + nsh0->length = t->nsh_hdr.length; /* Copy any TLVs */ - if (vec_len(t->tlvs)) - clib_memcpy (nsh0->tlvs, t->tlvs, 4*vec_len(t->tlvs)); + if (vec_len(t->nsh_hdr.tlvs)) + clib_memcpy (nsh0->tlvs, t->nsh_hdr.tlvs, 4*vec_len(t->nsh_hdr.tlvs)); t->rewrite = rw; return (0); @@ -242,7 +245,7 @@ int vnet_nsh_vxlan_gpe_add_del_tunnel key.src = a->dst.as_u32; /* decap src in key is encap dst in config */ key.vni = clib_host_to_net_u32 (a->vni << 8); - key.spi_si = clib_host_to_net_u32(a->spi_si); + key.spi_si = clib_host_to_net_u32(a->nsh_hdr.spi_si); key.pad = 0; p = hash_get_mem (ngm->nsh_vxlan_gpe_tunnel_by_key, &key); @@ -263,6 +266,11 @@ int vnet_nsh_vxlan_gpe_add_del_tunnel #define _(x) t->x = a->x; foreach_copy_field; #undef _ + + /* copy from arg structure */ +#define _(x) t->nsh_hdr.x = a->nsh_hdr.x; + foreach_copy_nshhdr_field; +#undef _ rv = nsh_vxlan_gpe_rewrite (t); @@ -487,6 +495,10 @@ nsh_vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm, #define _(x) a->x = x; foreach_copy_field; #undef _ + +#define _(x) a->nsh_hdr.x = x; + foreach_copy_nshhdr_field; +#undef _ rv = vnet_nsh_vxlan_gpe_add_del_tunnel (a, 0 /* hw_if_indexp */); diff --git a/vnet/vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h b/vnet/vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h index 99dc60001f6..3effd3318cb 100644 --- a/vnet/vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h +++ b/vnet/vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -73,15 +73,7 @@ typedef struct { u32 sw_if_index; /* NSH header fields in HOST byte order */ - u8 ver_o_c; - u8 length; - u8 md_type; - u8 next_protocol; - u32 spi_si; - - /* Context headers, always present, in HOST byte order */ - u32 c1, c2, c3, c4; - u32 * tlvs; + nsh_header_t nsh_hdr; } nsh_vxlan_gpe_tunnel_t; #define foreach_nsh_vxlan_gpe_input_next \ @@ -137,13 +129,7 @@ typedef struct { u32 decap_fib_index; u32 decap_next_index; u32 vni; - u8 ver_o_c; - u8 length; - u8 md_type; - u8 next_protocol; - u32 spi_si; - u32 c1, c2, c3, c4; - u32 * tlvs; + nsh_header_t nsh_hdr; } vnet_nsh_vxlan_gpe_add_del_tunnel_args_t; int vnet_nsh_vxlan_gpe_add_del_tunnel diff --git a/vnet/vnet/nsh/nsh_error.def b/vnet/vnet/nsh/nsh_error.def new file mode 100644 index 00000000000..532b02a6e89 --- /dev/null +++ b/vnet/vnet/nsh/nsh_error.def @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2015 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +nsh_gre_error (DECAPSULATED, "good packets decapsulated") +nsh_gre_error (NO_SUCH_TUNNEL, "no such tunnel packets") +nsh_gre_error (INVALID_NEXT_PROTOCOL, "invalid next protocol") diff --git a/vnet/vnet/nsh/nsh_packet.h b/vnet/vnet/nsh/nsh_packet.h new file mode 100644 index 00000000000..87d46a93b6d --- /dev/null +++ b/vnet/vnet/nsh/nsh_packet.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2015 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef included_vnet_nsh_packet_h +#define included_vnet_nsh_packet_h + +/* + * NSH packet format from draft-quinn-sfc-nsh-03.txt + * + * NSH Base Header + * 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |Ver|O|C|R|R|R|R|R|R| Length | MD Type | Next Protocol | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + * + * Base Header Field Descriptions: + * + * Version: The version field is used to ensure backward compatibility + * going forward with future NSH updates. + * + * O bit: Indicates that this packet is an operations and management + * (OAM) packet. SFF and SFs nodes MUST examine the payload and take + * appropriate action (e.g. return status information). + * + * OAM message specifics and handling details are outside the scope of + * this document. + * + * C bit: Indicates that a critical metadata TLV is present (see section + * 7). This bit acts as an indication for hardware implementers to + * decide how to handle the presence of a critical TLV without + * necessarily needing to parse all TLVs present. The C bit MUST be set + * to 1 if one or more critical TLVs are present. + * + * All other flag fields are reserved. + * + * Length: total length, in 4 byte words, of the NSH header, including + * optional variable TLVs. Length must be equal or greater than 6. + * + * MD Type: indicates the format of NSH beyond the base header and the + * type of metadata being carried. This typing is used to describe the + * use for the metadata. A new registry will be requested from IANA for + * the MD Type. NSH defines one type, type = 0x1 which indicates that + * the format of the header is as per this draft. + * + * The format of the base header is invariant, and not described by MD + * Type. + * + * Next Protocol: indicates the protocol type of the original packet. A + * new IANA registry will be created for protocol type. + * + * This draft defines the following Next Protocol values: + * + * 0x1 : IPv4 + * 0x2 : IPv6 + * 0x3 : Ethernet + */ + +typedef CLIB_PACKED(struct { + u8 ver_o_c; + u8 length; + u8 md_type; + u8 next_protocol; + u32 spi_si; + /* Context headers, always present */ + u32 c1; u32 c2; u32 c3; u32 c4; + + /* Optional variable length metadata */ + u32 * tlvs; +}) nsh_header_t; + +#define NSH_O_BIT (1<<5) +#define NSH_C_BIT (1<<4) + +/* Network byte order shift / mask */ +#define NSH_SINDEX_MASK 0xFF +#define NSH_SPI_MASK (0x00FFFFFF) +#define NSH_SPI_SHIFT 8 + +#endif /* included_vnet_nsh_packet_h */ -- cgit 1.2.3-korg