summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2019-05-26 11:34:27 -0700
committerOle Trøan <otroan@employees.org>2019-05-27 13:18:05 +0000
commitcbd0824d6cec24ea2502ffdcdb1666d090f848cf (patch)
tree488c969f7c7429e07d159cdec229e8f362ad1fdc /src
parentbbd6b746e09cc4ae4239173081d95349e0263759 (diff)
IPIP tunnel: use address types on API
Change-Id: Ida6a8f96bd858246e993250087bed45e7084ede1 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/vnet/ipip/ipip.api34
-rw-r--r--src/vnet/ipip/ipip_api.c60
2 files changed, 48 insertions, 46 deletions
diff --git a/src/vnet/ipip/ipip.api b/src/vnet/ipip/ipip.api
index 3dc087c954f..e8051fde7f8 100644
--- a/src/vnet/ipip/ipip.api
+++ b/src/vnet/ipip/ipip.api
@@ -1,3 +1,4 @@
+/* Hey Emacs use -*- mode: C -*- */
/*
* Copyright (c) 2018 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -48,8 +49,23 @@
*
*/
-option version = "1.1.0";
+option version = "1.2.0";
import "vnet/interface_types.api";
+import "vnet/ip/ip_types.api";
+
+/**
+ * An IP{v4,v6} over IP{v4,v6} tunnel.
+ */
+typedef ipip_tunnel
+{
+ u32 instance; /* If non-~0, specifies a custom dev instance */
+ vl_api_address_t src;
+ vl_api_address_t dst;
+ u32 sw_if_index; /* ignored on create, set in details/dump */
+u32 table_id;
+ u8 tc_tos; /* If ~0, the TOS/TC value is copied from
+ inner packet, otherwise set to value */
+};
/**
* Create an IP{v4,v6} over IP{v4,v6} tunnel.
@@ -58,13 +74,7 @@ define ipip_add_tunnel
{
u32 client_index;
u32 context;
- u8 is_ipv6;
- u32 instance; /* If non-~0, specifies a custom dev instance */
- u8 src_address[16];
- u8 dst_address[16];
- u32 table_id;
- u8 tc_tos; /* If ~0, the TOS/TC value is copied from
- inner packet, otherwise set to value */
+ vl_api_ipip_tunnel_t tunnel;
};
define ipip_add_tunnel_reply
@@ -133,13 +143,7 @@ define ipip_tunnel_dump
define ipip_tunnel_details
{
u32 context;
- vl_api_interface_index_t sw_if_index;
- u32 instance;
- u8 is_ipv6;
- u8 src_address[16];
- u8 dst_address[16];
- u32 fib_index;
- u8 tc_tos;
+ vl_api_ipip_tunnel_t tunnel;
};
/*
diff --git a/src/vnet/ipip/ipip_api.c b/src/vnet/ipip/ipip_api.c
index 2abac0b9772..f97aaf78bd4 100644
--- a/src/vnet/ipip/ipip_api.c
+++ b/src/vnet/ipip/ipip_api.c
@@ -22,6 +22,7 @@
#include <vnet/ipip/ipip.h>
#include <vnet/vnet.h>
#include <vnet/vnet_msg_enum.h>
+#include <vnet/ip/ip_types_api.h>
#define vl_typedefs /* define message structures */
#include <vnet/vnet_all_api_h.h>
@@ -52,23 +53,26 @@ vl_api_ipip_add_tunnel_t_handler (vl_api_ipip_add_tunnel_t * mp)
vl_api_ipip_add_tunnel_reply_t *rmp;
int rv = 0;
u32 fib_index, sw_if_index = ~0;
- ip46_address_t src = ip46_address_initializer, dst =
- ip46_address_initializer;
+ ip46_address_t src, dst;
+ ip46_type_t itype[2];
- /* ip addresses sent in network byte order */
- if (mp->is_ipv6)
+ itype[0] = ip_address_decode (&mp->tunnel.src, &src);
+ itype[1] = ip_address_decode (&mp->tunnel.dst, &dst);
+
+ if (itype[0] != itype[1])
{
- clib_memcpy (&src.ip6, mp->src_address, 16);
- clib_memcpy (&dst.ip6, mp->dst_address, 16);
+ rv = VNET_API_ERROR_INVALID_PROTOCOL;
+ goto out;
}
- else
+
+ if (ip46_address_is_equal (&src, &dst))
{
- clib_memcpy (&src.ip4, mp->src_address, 4);
- clib_memcpy (&dst.ip4, mp->dst_address, 4);
+ rv = VNET_API_ERROR_SAME_SRC_DST;
+ goto out;
}
- fib_index =
- fib_table_find (fib_ip_proto (mp->is_ipv6), ntohl (mp->table_id));
+ fib_index = fib_table_find (fib_proto_from_ip46 (itype[0]),
+ ntohl (mp->tunnel.table_id));
if (~0 == fib_index)
{
@@ -76,13 +80,14 @@ vl_api_ipip_add_tunnel_t_handler (vl_api_ipip_add_tunnel_t * mp)
}
else
{
- rv = ipip_add_tunnel ((mp->is_ipv6 ?
+ rv = ipip_add_tunnel ((itype[0] == IP46_TYPE_IP6 ?
IPIP_TRANSPORT_IP6 :
IPIP_TRANSPORT_IP4),
- ntohl (mp->instance), &src, &dst,
- fib_index, mp->tc_tos, &sw_if_index);
+ ntohl (mp->tunnel.instance), &src, &dst,
+ fib_index, mp->tunnel.tc_tos, &sw_if_index);
}
+out:
/* *INDENT-OFF* */
REPLY_MACRO2(VL_API_IPIP_ADD_TUNNEL_REPLY,
({
@@ -112,24 +117,17 @@ send_ipip_tunnel_details (ipip_tunnel_t * t,
rmp = vl_msg_api_alloc (sizeof (*rmp));
clib_memset (rmp, 0, sizeof (*rmp));
rmp->_vl_msg_id = htons (VL_API_IPIP_TUNNEL_DETAILS);
- if (is_ipv6)
- {
- clib_memcpy (rmp->src_address, &t->tunnel_src.ip6.as_u8, 16);
- clib_memcpy (rmp->dst_address, &t->tunnel_dst.ip6.as_u8, 16);
- ft = fib_table_get (t->fib_index, FIB_PROTOCOL_IP6);
- rmp->fib_index = htonl (ft->ft_table_id);
- }
- else
- {
- clib_memcpy (rmp->src_address, &t->tunnel_src.ip4.as_u8, 4);
- clib_memcpy (rmp->dst_address, &t->tunnel_dst.ip4.as_u8, 4);
- ft = fib_table_get (t->fib_index, FIB_PROTOCOL_IP4);
- rmp->fib_index = htonl (ft->ft_table_id);
- }
- rmp->instance = htonl (t->user_instance);
- rmp->sw_if_index = htonl (t->sw_if_index);
+
+ ip_address_encode (&t->tunnel_src, IP46_TYPE_ANY, &rmp->tunnel.src);
+ ip_address_encode (&t->tunnel_dst, IP46_TYPE_ANY, &rmp->tunnel.dst);
+
+ ft = fib_table_get (t->fib_index, (is_ipv6 ? FIB_PROTOCOL_IP6 :
+ FIB_PROTOCOL_IP4));
+
+ rmp->tunnel.table_id = htonl (ft->ft_table_id);
+ rmp->tunnel.instance = htonl (t->user_instance);
+ rmp->tunnel.sw_if_index = htonl (t->sw_if_index);
rmp->context = context;
- rmp->is_ipv6 = is_ipv6;
vl_api_send_msg (reg, (u8 *) rmp);
}
lor: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
# Copyright (c) 2018 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.

enable_language(ASM)

##############################################################################
# Generate vppinfra/config.h
##############################################################################
set(LOG2_CACHE_LINE_BYTES ${VPP_LOG2_CACHE_LINE_SIZE})

option(VPP_VECTOR_GROW_BY_ONE "Vectors grow by one, instead of 3/2" OFF)
if(VPP_VECTOR_GROW_BY_ONE)
  set(VECTOR_GROW_BY_ONE 1)
else(VPP_VECTOR_GROW_BY_ONE)
  set(VECTOR_GROW_BY_ONE 0)
endif(VPP_VECTOR_GROW_BY_ONE)

configure_file(
  ${CMAKE_SOURCE_DIR}/vppinfra/config.h.in
  ${CMAKE_CURRENT_BINARY_DIR}/config.h
)

install(
  FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h
  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vppinfra
  COMPONENT vpp-dev
)

add_definitions(-fvisibility=hidden)

# Ensure symbols from cJSON are exported
set_source_files_properties( cJSON.c jsonformat.c PROPERTIES
  COMPILE_DEFINITIONS " CJSON_API_VISIBILITY " )


##############################################################################
# vppinfra sources
##############################################################################
set(VPPINFRA_SRCS
  backtrace.c
  bitmap.c
  bihash_all_vector.c
  cpu.c
  dlmalloc.c
  elf.c
  elog.c
  error.c
  fifo.c
  format.c
  format_table.c
  hash.c
  heap.c
  interrupt.c
  jsonformat.c
  longjmp.S
  macros.c
  maplog.c
  mem.c
  mem_bulk.c
  mem_dlmalloc.c
  mhash.c
  mpcap.c
  pcap.c
  pmalloc.c
  pool.c
  ptclosure.c
  random_buffer.c
  random.c
  random_isaac.c
  rbtree.c
  sanitizer.c
  serialize.c
  socket.c
  std-formats.c
  string.c
  time.c
  time_range.c
  timing_wheel.c
  tw_timer_2t_2w_512sl.c
  tw_timer_16t_1w_2048sl.c
  tw_timer_16t_2w_512sl.c
  tw_timer_1t_3w_1024sl_ov.c
  tw_timer_2t_1w_2048sl.c
  tw_timer_4t_3w_256sl.c
  unformat.c
  unix-formats.c
  unix-misc.c
  valloc.c
  vec.c
  vector.c
  vector/toeplitz.c
  cJSON.c
)

set(VPPINFRA_HEADERS
  sanitizer.h
  bihash_12_4.h
  bihash_16_8.h
  bihash_24_8.h
  bihash_32_8.h
  bihash_40_8.h
  bihash_48_8.h
  bihash_8_8.h
  bihash_8_16.h
  bihash_24_16.h
  bihash_template.c
  bihash_template.h
  bihash_vec8_8.h
  bitmap.h
  bitops.h
  byte_order.h
  cache.h
  callback.h
  callback_data.h
  cJSON.h
  clib_error.h
  clib.h
  cpu.h
  crc32.h
  dlist.h
  dlmalloc.h
  elf_clib.h
  elf.h
  elog.h
  error_bootstrap.h
  error.h
  fifo.h
  file.h
  format.h
  format_table.h
  hash.h
  heap.h
  interrupt.h
  jsonformat.h
  lb_hash_hash.h
  llist.h
  lock.h
  longjmp.h
  macros.h
  maplog.h
  math.h
  memcpy.h
  memcpy_x86_64.h
  mem.h
  mhash.h
  mpcap.h
  os.h
  pcap.h
  pcap_funcs.h
  pmalloc.h
  pool.h
  ptclosure.h
  random_buffer.h
  random.h
  random_isaac.h
  rbtree.h
  serialize.h
  sha2.h
  smp.h
  socket.h
  sparse_vec.h
  string.h
  time.h
  time_range.h
  timing_wheel.h
  tw_timer_2t_2w_512sl.h
  tw_timer_16t_1w_2048sl.h
  tw_timer_16t_2w_512sl.h
  tw_timer_1t_3w_1024sl_ov.h
  tw_timer_2t_1w_2048sl.h
  tw_timer_4t_3w_256sl.h
  tw_timer_template.c
  tw_timer_template.h
  types.h
  atomics.h
  unix.h
  valloc.h
  vec_bootstrap.h
  vec.h
  vector_altivec.h
  vector_avx2.h
  vector_avx512.h
  vector/array_mask.h
  vector/compress.h
  vector/count_equal.h
  vector/index_to_ptr.h
  vector/ip_csum.h
  vector/mask_compare.h
  vector/toeplitz.h
  vector.h
  vector_neon.h
  vector_sse42.h
  warnings.h
  xxhash.h
  linux/sysfs.h
)

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
  list(APPEND VPPINFRA_SRCS
    elf_clib.c
    linux/mem.c
    linux/sysfs.c
    linux/netns.c
   )
endif()

option(VPP_USE_EXTERNAL_LIBEXECINFO "Use external libexecinfo (useful for non-glibc targets)." OFF)
if(VPP_USE_EXTERNAL_LIBEXECINFO)
  set(EXECINFO_LIB execinfo)
endif()
add_vpp_library(vppinfra
  SOURCES ${VPPINFRA_SRCS}
  LINK_LIBRARIES m ${EXECINFO_LIB}
  INSTALL_HEADERS ${VPPINFRA_HEADERS}
  COMPONENT libvppinfra
  LTO
)

##############################################################################
# vppinfra headers
##############################################################################
option(VPP_BUILD_VPPINFRA_TESTS "Build vppinfra tests." OFF)
if(VPP_BUILD_VPPINFRA_TESTS)
  foreach(test
    bihash_vec88
    dlist
    elf
    elog
    fifo
    format
    fpool
    hash
    heap
    longjmp
    macros
    maplog
    pmalloc
    pool_iterate
    ptclosure
    random
    random_isaac
    rwlock
    serialize
    socket
    spinlock
    time
    time_range
    tw_timer
    valloc
    vec
  )
    add_vpp_executable(test_${test}
      SOURCES test_${test}.c
      LINK_LIBRARIES vppinfra pthread
      )
  endforeach()

  foreach(test bihash_template)
    add_vpp_executable(test_${test}
      SOURCES test_${test}.c
      LINK_LIBRARIES vppinfra Threads::Threads
      )
  endforeach()

set(test_files
  vector/test/array_mask.c
  vector/test/compress.c
  vector/test/count_equal.c
  vector/test/index_to_ptr.c
  vector/test/ip_csum.c
  vector/test/mask_compare.c
  vector/test/memcpy_x86_64.c
  vector/test/sha2.c
  vector/test/toeplitz.c
)

add_vpp_executable(test_vector_funcs
  SOURCES
  vector/test/test.c
  ${test_files}
  LINK_LIBRARIES vppinfra
)

vpp_library_set_multiarch_sources(test_vector_funcs
  SOURCES
  ${test_files}
)

endif(VPP_BUILD_VPPINFRA_TESTS)