summaryrefslogtreecommitdiffstats
path: root/src/examples/sample-plugin
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2018-07-04 10:56:23 -0400
committerDamjan Marion <dmarion@me.com>2018-07-18 12:09:42 +0000
commit6a5adc369591fcac2447e9809deaa22f56b53911 (patch)
treec9a56b1ed0d5e8eb2f21a843552c6c0bc6df5597 /src/examples/sample-plugin
parent2a3fb1a28b170ac1d37815983611e83d148811d4 (diff)
Add config option to use dlmalloc instead of mheap
Configure w/ --enable-dlmalloc, see .../build-data/platforms/vpp.mk src/vppinfra/dlmalloc.[ch] are slightly modified versions of the well-known Doug Lea malloc. Main advantage: dlmalloc mspaces have no inherent size limit. Change-Id: I19b3f43f3c65bcfb82c1a265a97922d01912446e Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/examples/sample-plugin')
-rw-r--r--src/examples/sample-plugin/Makefile.am2
-rw-r--r--src/examples/sample-plugin/configure.ac13
2 files changed, 14 insertions, 1 deletions
diff --git a/src/examples/sample-plugin/Makefile.am b/src/examples/sample-plugin/Makefile.am
index 1825a8f111f..2622f4e69f9 100644
--- a/src/examples/sample-plugin/Makefile.am
+++ b/src/examples/sample-plugin/Makefile.am
@@ -13,7 +13,7 @@
AUTOMAKE_OPTIONS = foreign subdir-objects
-AM_CFLAGS = -Wall -I${top_srcdir} -I${top_builddir}
+AM_CFLAGS = -Wall -I${top_srcdir} -I${top_builddir} @DLMALLOC@
AM_LDFLAGS = -module -shared -avoid-version
AM_LIBTOOLFLAGS = --quiet
SUFFIXES = .api.h .api .api.json
diff --git a/src/examples/sample-plugin/configure.ac b/src/examples/sample-plugin/configure.ac
index 588e7dd16b9..57ec6ee02c1 100644
--- a/src/examples/sample-plugin/configure.ac
+++ b/src/examples/sample-plugin/configure.ac
@@ -22,6 +22,19 @@ AC_DEFUN([CC_CHECK_FLAG],
AC_LANG_POP([C])
])
+AC_DEFUN([ENABLE_ARG],
+[
+ AC_ARG_ENABLE($1,
+ AC_HELP_STRING(patsubst([--enable-$1],[_],[-]), $2),
+ [enable_$1=yes n_enable_$1=1],
+ [enable_$1=no n_enable_$1=0])
+ AM_CONDITIONAL(m4_toupper(ENABLE_$1), test "$enable_$1" = "yes")
+ m4_append([list_of_enabled], [$1], [, ])
+])
+
+ENABLE_ARG(dlmalloc, [Enable dlmalloc])
+AC_SUBST(DLMALLOC, [-DUSE_DLMALLOC=${n_enable_dlmalloc}])
+
CC_CHECK_FLAG("-Wno-address-of-packed-member")
AS_IF([test "$cc_flag_check" = yes],
[CFLAGS="${CFLAGS} -Wno-address-of-packed-member"], [])
.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #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) 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_ip_ip_source_and_port_range_check_h
#define included_ip_ip_source_and_port_range_check_h


typedef struct
{
  /* convenience */
  vlib_main_t *vlib_main;
  vnet_main_t *vnet_main;
} source_range_check_main_t;

extern source_range_check_main_t source_range_check_main;

typedef enum
{
  IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT,
  IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT,
  IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN,
  IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN,
  IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS,
} ip_source_and_port_range_check_protocol_t;

typedef struct
{
  u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS];
} ip_source_and_port_range_check_config_t;

#define IP_SOURCE_AND_PORT_RANGE_CHECK_RANGE_LIMIT VLIB_BUFFER_PRE_DATA_SIZE/(2*sizeof(u16x8));

typedef struct
{
  union
  {
    u16x8 as_u16x8;
    u16 as_u16[8];
  };
} u16x8vec_t;

typedef struct
{
  u16x8vec_t low;
  u16x8vec_t hi;
} protocol_port_range_t;

/**
 * @brief The number of supported ranges per-data path object.
 * If more ranges are required, bump this number.
 */
#define N_PORT_RANGES_PER_DPO  64
#define N_RANGES_PER_BLOCK (sizeof(u16x8vec_t)/2)
#define N_BLOCKS_PER_DPO (N_PORT_RANGES_PER_DPO/N_RANGES_PER_BLOCK)

/**
 * @brief
 *  The object that is in the data-path to perform the check.
 *
 * Some trade-offs here; memory vs performance.
 *
 * performance:
 *  the principle factor is d-cache line misses/hits.
 *  so we want the data layout to minimise the d-cache misses. This
 *  means not following dependent reads. i.e. not doing
 *
 *   struct B {
 *     u16 n_ranges;
 *     range_t *ranges; // vector of ranges.
 *   }
 *
 *   so to read ranges[0] we would first d-cache miss on the address
 *   of the object of type B, for which we would need to wait before we
 *   can get the address of B->ranges.
 *   So this layout is better:
 *
 *  struct B {
 *    u16 n_ranges;
 *    range_t ranges[N];
 *  }
 *
 * memory:
 *  the latter layout above is more memory hungry. And N needs to be:
 *   1 - sized for the maximum required
 *   2 - fixed, so that objects of type B can be pool allocated and so
 *       'get'-able using an index.
 *       An option over fixed might be to allocate contiguous chunk from
 *       the pool (like we used to do for multi-path adjs).
 */
typedef struct protocol_port_range_dpo_t_
{
  /**
   * Required for pool_get_aligned
   */
  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);

  /**
   * The number of blocks from the 'block' array below
   * that have ranges configured. We keep this count so that in the data-path
   * we can limit the loop to be only over the blocks we need
   */
  u16 n_used_blocks;

  /**
   * The total number of free ranges from all blocks.
   * Used to prevent overrun of the ranges available.
   */
  u16 n_free_ranges;

  /**
   * the fixed size array of ranges
   */
  protocol_port_range_t blocks[N_BLOCKS_PER_DPO];
} protocol_port_range_dpo_t;

int ip4_source_and_port_range_check_add_del (ip4_address_t * address,
					     u32 length,
					     u32 vrf_id,
					     u16 * low_ports,
					     u16 * hi_ports, int is_add);

// This will be moved to another file in another patch -- for API freeze
int ip6_source_and_port_range_check_add_del (ip6_address_t * address,
					     u32 length,
					     u32 vrf_id,
					     u16 * low_ports,
					     u16 * hi_ports, int is_add);

int set_ip_source_and_port_range_check (vlib_main_t * vm,
					u32 * fib_index,
					u32 sw_if_index, u32 is_add);

#endif /* included ip_source_and_port_range_check_h */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */