summaryrefslogtreecommitdiffstats
path: root/src/pkg
AgeCommit message (Expand)AuthorFilesLines
2022-03-11tls: remove pkg dependencies on mbedtlsFlorin Coras1-3/+0
2021-11-02build: remove unnecessary executable bitsRay Kinsella1-0/+0
2021-10-06build: fix lib dir in debian packagingDamjan Marion1-1/+1
2021-10-05build: don't hardcode triplet, allow specifying custom lib dirDamjan Marion1-7/+0
2021-09-30misc: package the devtool pluginsAndrew Yourtchenko1-0/+8
2021-08-17build: remove dh-systemd from dependenciesAndrew Yourtchenko1-1/+0
2021-08-12build: consistent debhelper 10 supportNick Brown2-3/+1
2021-07-12papi: remove shared memory transportOle Troan1-1/+0
2021-04-30misc: experimental configure scriptDamjan Marion2-6/+6
2021-02-09papi: remove python2 vpp-api-python.debPaul Vinciguerra4-27/+4
2020-10-28build: explicitly stop vpp in vpp.preinstDave Barach1-0/+1
2020-10-21build: fix broken debian dependencies on ubuntu-18.04 & debian-9Dave Wallace1-2/+2
2020-10-16misc: bump debian compatibility level to 10Damjan Marion1-1/+1
2020-10-16build: Add missing debian dependenciesChuan Han1-0/+6
2020-06-17build: cmake cross-compilation fixesDamjan Marion1-0/+4
2020-05-15misc: fix ubuntu 20.04 python depsDamjan Marion3-9/+32
2020-04-09misc: add a nerd knob to skip a sysctl during the .deb installationAndrew Yourtchenko1-1/+5
2019-07-12docs: how to enable coredump with systemdBenoƮt Ganne1-0/+5
2019-03-15PAPI: Build python3 package for vpp_papiOle Troan2-5/+21
2019-01-23cmake: fix debian preinst scriptDamjan Marion1-1/+1
2019-01-22cmake: supress 'Set runtime path of' noise while generatig deb packagesDamjan Marion1-1/+2
2019-01-22cmake: fix debian package dependenciesDamjan Marion1-5/+4
2019-01-22cmake: place include/ and share/ in /usr (debian packages)Damjan Marion1-4/+9
2019-01-22cmake: don't set SONAME for pluginsDamjan Marion1-4/+0
2019-01-22cmake: package-deb target uses terminalDamjan Marion1-0/+1
2019-01-20Rework of debian packagingDamjan Marion9-0/+224
b74 } /* 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.
 */
/*
  Copyright (c) 2010 Eliot Dresselhaus

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <vppinfra/mhash.h>

always_inline u32
load_partial_u32 (void *d, uword n)
{
  if (n == 4)
    return ((u32 *) d)[0];
  if (n == 3)
    return ((u16 *) d)[0] | (((u8 *) d)[2] << 16);
  if (n == 2)
    return ((u16 *) d)[0];
  if (n == 1)
    return ((u8 *) d)[0];
  ASSERT (0);
  return 0;
}

always_inline u32
mhash_key_sum_inline (void *data, uword n_data_bytes, u32 seed)
{
  u32 *d32 = data;
  u32 a, b, c, n_left;

  a = b = c = seed;
  n_left = n_data_bytes;
  a ^= n_data_bytes;

  while (n_left > 12)
    {
      a += d32[0];
      b += d32[1];
      c += d32[2];
      hash_v3_mix32 (a, b, c);
      n_left -= 12;
      d32 += 3;
    }

  if (n_left > 8)
    {
      c += load_partial_u32 (d32 + 2, n_left - 8);
      n_left = 8;
    }
  if (n_left > 4)
    {
      b += load_partial_u32 (d32 + 1, n_left - 4);
      n_left = 4;
    }
  if (n_left > 0)
    a += load_partial_u32 (d32 + 0, n_left - 0);

  hash_v3_finalize32 (a, b, c);

  return c;
}

#define foreach_mhash_key_size			\
  _ (2) _ (3) _ (4) _ (5) _ (6) _ (7)		\
  _ (8) _ (12) _ (16) _ (20)			\
  _ (24) _ (28) _ (32) _ (36)			\
  _ (40) _ (44) _ (48) _ (52)			\
  _ (56) _ (60) _ (64)

#define _(N_KEY_BYTES)							\
  static uword								\
  mhash_key_sum_##N_KEY_BYTES (hash_t * h, uword key)			\
  {									\
    mhash_t * hv = uword_to_pointer (h->user, mhash_t *);		\
    return mhash_key_sum_inline (mhash_key_to_mem (hv, key),		\
				 (N_KEY_BYTES),				\
				 hv->hash_seed);			\
  }									\
									\
  static uword								\
  mhash_key_equal_##N_KEY_BYTES (hash_t * h, uword key1, uword key2)	\
  {									\
    mhash_t * hv = uword_to_pointer (h->user, mhash_t *);		\
    void * k1 = mhash_key_to_mem (hv, key1);				\
    void * k2 = mhash_key_to_mem (hv, key2);				\
    return ! memcmp (k1, k2, (N_KEY_BYTES));				\
  }

foreach_mhash_key_size
#undef _
static uword
mhash_key_sum_c_string (hash_t * h, uword key)
{
  mhash_t *hv = uword_to_pointer (h->user, mhash_t *);
  void *k = mhash_key_to_mem (hv, key);
  return mhash_key_sum_inline (k, strlen (k), hv->hash_seed);
}

static uword
mhash_key_equal_c_string (hash_t * h, uword key1, uword key2)
{
  mhash_t *hv = uword_to_pointer (h->user, mhash_t *);
  void *k1 = mhash_key_to_mem (hv, key1);
  void *k2 = mhash_key_to_mem (hv, key2);
  return strcmp (k1, k2) == 0;
}

static uword
mhash_key_sum_vec_string (hash_t * h, uword key)
{
  mhash_t *hv = uword_to_pointer (h->user, mhash_t *);
  void *k = mhash_key_to_mem (hv, key);
  return mhash_key_sum_inline (k, vec_len (k), hv->hash_seed);
}

static uword
mhash_key_equal_vec_string (hash_t * h, uword key1, uword key2)
{
  mhash_t *hv = uword_to_pointer (h->user, mhash_t *);
  void *k1 = mhash_key_to_mem (hv, key1);
  void *k2 = mhash_key_to_mem (hv, key2);
  return vec_len (k1) == vec_len (k2) && memcmp (k1, k2, vec_len (k1)) == 0;
}

/* The CLIB hash user pointer must always point to a valid mhash_t.
   Now, the address of mhash_t can change (think vec_resize).
   So we must always be careful that it points to the correct
   address. */
always_inline void
mhash_sanitize_hash_user (mhash_t * mh)
{
  uword *hash = mh->hash;
  hash_t *h = hash_header (hash);
  h->user = pointer_to_uword (mh);
}

void
mhash_init (mhash_t * h, uword n_value_bytes, uword n_key_bytes)
{
  static struct
  {
    hash_key_sum_function_t *key_sum;
    hash_key_equal_function_t *key_equal;
  } t[] =
  {
#define _(N_KEY_BYTES)					\
    [N_KEY_BYTES] = {					\
      .key_sum = mhash_key_sum_##N_KEY_BYTES,		\
      .key_equal = mhash_key_equal_##N_KEY_BYTES,	\
    },

    foreach_mhash_key_size
#undef _
      [MHASH_C_STRING_KEY] =
    {
    .key_sum = mhash_key_sum_c_string,.key_equal = mhash_key_equal_c_string,},
      [MHASH_VEC_STRING_KEY] =
    {
  .key_sum = mhash_key_sum_vec_string,.key_equal =
	mhash_key_equal_vec_string,},};

  if (mhash_key_vector_is_heap (h))
    heap_free (h->key_vector_or_heap);
  else
    vec_free (h->key_vector_or_heap);
  vec_free (h->key_vector_free_indices);
  {
    int i;
    for (i = 0; i < vec_len (h->key_tmps); i++)
      vec_free (h->key_tmps[i]);
  }
  vec_free (h->key_tmps);
  hash_free (h->hash);

  clib_memset (h, 0, sizeof (h[0]));
  h->n_key_bytes = n_key_bytes;

  vec_validate (h->key_tmps, os_get_nthreads () - 1);

  ASSERT (n_key_bytes < ARRAY_LEN (t));
  h->hash = hash_create2 ( /* elts */ 0,
			  /* user */ pointer_to_uword (h),
			  /* value_bytes */ n_value_bytes,
			  t[n_key_bytes].key_sum, t[n_key_bytes].key_equal,
			  /* format pair/arg */
			  0, 0);
}

static uword
mhash_set_tmp_key (mhash_t * h, const void *key)
{
  u8 *key_tmp;
  int my_cpu = os_get_thread_index ();

  key_tmp = h->key_tmps[my_cpu];

  vec_reset_length (key_tmp);

  if (mhash_key_vector_is_heap (h))
    {
      uword is_c_string = h->n_key_bytes == MHASH_C_STRING_KEY;

      if (is_c_string)
	vec_add (key_tmp, key, strlen (key) + 1);
      else
	vec_add (key_tmp, key, vec_len (key));
    }
  else
    vec_add (key_tmp, key, h->n_key_bytes);

  h->key_tmps[my_cpu] = key_tmp;

  return ~0;
}

hash_pair_t *
mhash_get_pair (mhash_t * h, const void *key)
{
  uword ikey;
  mhash_sanitize_hash_user (h);
  ikey = mhash_set_tmp_key (h, key);
  return hash_get_pair (h->hash, ikey);
}

typedef struct
{
  u32 heap_handle;

  /* Must coincide with vec_header. */
  vec_header_t vec;
} mhash_string_key_t;

uword
mhash_set_mem (mhash_t * h, void *key, uword * new_value, uword * old_value)
{
  u8 *k;
  uword ikey, i, l = 0, n_key_bytes, old_n_elts, key_alloc_from_free_list = 0;

  mhash_sanitize_hash_user (h);

  if (mhash_key_vector_is_heap (h))
    {
      mhash_string_key_t *sk;
      uword is_c_string = h->n_key_bytes == MHASH_C_STRING_KEY;
      uword handle;

      n_key_bytes = is_c_string ? (strlen (key) + 1) : vec_len (key);
      i =
	heap_alloc (h->key_vector_or_heap, n_key_bytes + sizeof (sk[0]),
		    handle);

      sk = (void *) (h->key_vector_or_heap + i);
      sk->heap_handle = handle;
      sk->vec.len = n_key_bytes;
      clib_memcpy_fast (sk->vec.vector_data, key, n_key_bytes);

      /* Advance key past vector header. */
      i += sizeof (sk[0]);
    }
  else
    {
      key_alloc_from_free_list = (l =
				  vec_len (h->key_vector_free_indices)) > 0;
      if (key_alloc_from_free_list)
	{
	  i = h->key_vector_free_indices[l - 1];
	  k = vec_elt_at_index (h->key_vector_or_heap, i);
	  _vec_len (h->key_vector_free_indices) = l - 1;
	}
      else
	{
	  vec_add2 (h->key_vector_or_heap, k, h->n_key_bytes);
	  i = k - h->key_vector_or_heap;
	}

      n_key_bytes = h->n_key_bytes;
      clib_memcpy_fast (k, key, n_key_bytes);
    }
  ikey = i;

  old_n_elts = hash_elts (h->hash);
  h->hash = _hash_set3 (h->hash, ikey, new_value, old_value);

  /* If element already existed remove duplicate key. */
  if (hash_elts (h->hash) == old_n_elts)
    {
      hash_pair_t *p;

      /* Fetch old key for return value. */
      p = hash_get_pair (h->hash, ikey);
      ikey = p->key;

      /* Remove duplicate key. */
      if (mhash_key_vector_is_heap (h))
	{
	  mhash_string_key_t *sk;
	  sk = (void *) (h->key_vector_or_heap + i - sizeof (sk[0]));
	  heap_dealloc (h->key_vector_or_heap, sk->heap_handle);
	}
      else
	{
	  if (key_alloc_from_free_list)
	    {
	      h->key_vector_free_indices[l] = i;
	      _vec_len (h->key_vector_free_indices) = l + 1;
	    }
	  else
	    _vec_len (h->key_vector_or_heap) -= h->n_key_bytes;
	}
    }

  return ikey;
}

uword
mhash_unset (mhash_t * h, void *key, uword * old_value)
{
  hash_pair_t *p;
  uword i;

  mhash_sanitize_hash_user (h);
  i = mhash_set_tmp_key (h, key);

  p = hash_get_pair (h->hash, i);
  if (!p)
    return 0;

  ASSERT (p->key != ~0);
  i = p->key;

  if (mhash_key_vector_is_heap (h))
    {
      mhash_string_key_t *sk;
      sk = (void *) (h->key_vector_or_heap + i) - sizeof (sk[0]);
      heap_dealloc (h->key_vector_or_heap, sk->heap_handle);
    }
  else
    vec_add1 (h->key_vector_free_indices, i);

  hash_unset3 (h->hash, i, old_value);
  return 1;
}

u8 *
format_mhash_key (u8 * s, va_list * va)
{
  mhash_t *h = va_arg (*va, mhash_t *);
  u32 ki = va_arg (*va, u32);
  void *k = mhash_key_to_mem (h, ki);

  if (mhash_key_vector_is_heap (h))
    {
      uword is_c_string = h->n_key_bytes == MHASH_C_STRING_KEY;
      u32 l = is_c_string ? strlen (k) : vec_len (k);
      vec_add (s, k, l);
    }
  else if (h->format_key)
    s = format (s, "%U", h->format_key, k);
  else
    s = format (s, "%U", format_hex_bytes, k, h->n_key_bytes);

  return s;
}

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