summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2020-02-25 22:28:27 +0000
committerDave Barach <openvpp@barachs.net>2020-02-26 15:28:45 +0000
commit8c79a4ebb1f349b9bf1058c2e0511c0ea75b8552 (patch)
tree3a7f286b74aabcda89dbbbf48bf92d30a10686d6
parenteb89b9093bc5c7b0b1511cf3d59454e15f9e4d92 (diff)
svm: fix coverity warnings
Type: fix Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I2d5cb7cccb67a3193ce5a25323e70bc05737e023
-rw-r--r--src/svm/fifo_segment.c1
-rw-r--r--src/vnet/session/segment_manager.c3
2 files changed, 1 insertions, 3 deletions
diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c
index ec6f082398e..e19113fd449 100644
--- a/src/svm/fifo_segment.c
+++ b/src/svm/fifo_segment.c
@@ -75,7 +75,6 @@ static inline uword
fsh_n_cached_bytes (fifo_segment_header_t * fsh)
{
uword n_cached = clib_atomic_load_relax_n (&fsh->n_cached_bytes);
- ASSERT (n_cached >= 0);
return n_cached;
}
diff --git a/src/vnet/session/segment_manager.c b/src/vnet/session/segment_manager.c
index db38097602c..cbd44432e8a 100644
--- a/src/vnet/session/segment_manager.c
+++ b/src/vnet/session/segment_manager.c
@@ -981,8 +981,7 @@ void
segment_manager_set_watermarks (segment_manager_t * sm,
u8 high_watermark, u8 low_watermark)
{
- ASSERT (high_watermark >= 0 && high_watermark <= 100 &&
- low_watermark >= 0 && low_watermark <= 100 &&
+ ASSERT (high_watermark <= 100 && low_watermark <= 100 &&
low_watermark <= high_watermark);
sm->high_watermark = high_watermark;
/a> 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
/*
 * tunnel.h: shared definitions for tunnels.
 *
 * Copyright (c) 2019 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.
 */

#include <vnet/tunnel/tunnel.h>
#include <vnet/fib/fib_table.h>
#include <vnet/fib/fib_entry_track.h>

#include <vnet/ip/ip6_inlines.h>

const u8 TUNNEL_ENCAP_DECAP_FLAG_MASK = (
#define _(a, b, c) TUNNEL_ENCAP_DECAP_FLAG_##a |
  foreach_tunnel_encap_decap_flag
#undef _
  0);
const u8 TUNNEL_FLAG_MASK = (
#define _(a, b, c) TUNNEL_FLAG_##a |
  foreach_tunnel_flag
#undef _
  0);

u8 *
format_tunnel_mode (u8 * s, va_list * args)
{
  tunnel_mode_t mode = va_arg (*args, int);

  switch (mode)
    {
#define _(n, v) case TUNNEL_MODE_##n:       \
        s = format (s, "%s", v);            \
        break;
      foreach_tunnel_mode
#undef _
    }

  return (s);
}

uword
unformat_tunnel_mode (unformat_input_t * input, va_list * args)
{
  tunnel_mode_t *m = va_arg (*args, tunnel_mode_t *);

  if (unformat (input, "p2p"))
    *m = TUNNEL_MODE_P2P;
  else if (unformat (input, "p2mp") || unformat (input, "mp"))
    *m = TUNNEL_MODE_MP;
  else
    return 0;
  return 1;
}

u8 *
format_tunnel_encap_decap_flags (u8 * s, va_list * args)
{
  tunnel_encap_decap_flags_t f = va_arg (*args, int);

  if (f == TUNNEL_ENCAP_DECAP_FLAG_NONE)
    s = format (s, "none");

#define _(a, b, c)                                                            \
  else if (f & TUNNEL_ENCAP_DECAP_FLAG_##a) s = format (s, "%s ", b);
  foreach_tunnel_encap_decap_flag
#undef _
    return (s);
}

uword
unformat_tunnel_encap_decap_flags (unformat_input_t * input, va_list * args)
{
  tunnel_encap_decap_flags_t *f =
    va_arg (*args, tunnel_encap_decap_flags_t *);
#define _(a,b,c) if (unformat(input, b)) {\
  *f |= TUNNEL_ENCAP_DECAP_FLAG_##a;\
  return 1;\
  }
  foreach_tunnel_encap_decap_flag;
#undef _
  return 0;
}

u8 *
format_tunnel_flags (u8 *s, va_list *args)
{
  tunnel_flags_t f = va_arg (*args, int);

  if (f == TUNNEL_FLAG_NONE)
    s = format (s, "none");

#define _(a, b, c) else if (f & TUNNEL_FLAG_##a) s = format (s, "%s ", c);
  foreach_tunnel_flag
#undef _
    return (s);
}

uword
unformat_tunnel_flags (unformat_input_t *input, va_list *args)
{
  tunnel_flags_t *f = va_arg (*args, tunnel_flags_t *);
#define _(a, b, c)                                                            \
  if (unformat (input, c))                                                    \
    {                                                                         \
      *f |= TUNNEL_FLAG_##a;                                                  \
      return 1;                                                               \
    }
  foreach_tunnel_flag;
#undef _
  return 0;
}

ip_address_family_t
tunnel_get_af (const tunnel_t *t)
{
  return (ip_addr_version (&t->t_src));
}

void
tunnel_copy (const tunnel_t *src, tunnel_t *dst)
{
  ip_address_copy (&dst->t_dst, &src->t_dst);
  ip_address_copy (&dst->t_src, &src->t_src);

  dst->t_encap_decap_flags = src->t_encap_decap_flags;
  dst->t_flags = src->t_flags;
  dst->t_mode = src->t_mode;
  dst->t_table_id = src->t_table_id;
  dst->t_dscp = src->t_dscp;
  dst->t_hop_limit = src->t_hop_limit;
  dst->t_fib_index = src->t_fib_index;

  dst->t_flags &= ~TUNNEL_FLAG_RESOLVED;
  dst->t_fib_entry_index = FIB_NODE_INDEX_INVALID;
  dst->t_sibling = ~0;
}

u8 *
format_tunnel (u8 *s, va_list *args)
{
  const tunnel_t *t = va_arg (*args, tunnel_t *);
  u32 indent = va_arg (*args, u32);

  s = format (s, "%Utable-ID:%d [%U->%U] hop-limit:%d %U %U [%U] [%U]",
	      format_white_space, indent, t->t_table_id, format_ip_address,
	      &t->t_src, format_ip_address, &t->t_dst, t->t_hop_limit,
	      format_tunnel_mode, t->t_mode, format_ip_dscp, t->t_dscp,
	      format_tunnel_flags, t->t_flags, format_tunnel_encap_decap_flags,
	      t->t_encap_decap_flags);
  if (t->t_flags & TUNNEL_FLAG_RESOLVED)
    s = format (s, " [resolved via fib-entry: %d]", t->t_fib_entry_index);

  return (s);
}

uword
unformat_tunnel (unformat_input_t *input, va_list *args)
{
  tunnel_t *t = va_arg (*args, tunnel_t *);

  if (!unformat (input, "tunnel"))
    return (0);

  unformat (input, "src %U", unformat_ip_address, &t->t_src);
  unformat (input, "dst %U", unformat_ip_address, &t->t_dst);
  unformat (input, "table-id %d", &t->t_table_id);
  unformat (input, "hop-limit %d", &t->t_hop_limit);
  unformat (input, "%U", unformat_ip_dscp, &t->t_dscp);
  unformat (input, "%U", unformat_tunnel_encap_decap_flags,
	    &t->t_encap_decap_flags);
  unformat (input, "%U", unformat_tunnel_flags, &t->t_flags);
  unformat (input, "%U", unformat_tunnel_mode, &t->t_mode);

  return (1);
}

int
tunnel_resolve (tunnel_t *t, fib_node_type_t child_type, index_t child_index)
{
  fib_prefix_t pfx;

  ip_address_to_fib_prefix (&t->t_dst, &pfx);

  t->t_fib_index = fib_table_find (pfx.fp_proto, t->t_table_id);

  if (t->t_fib_index == ~((u32) 0))
    return VNET_API_ERROR_NO_SUCH_FIB;

  t->t_fib_entry_index = fib_entry_track (t->t_fib_index, &pfx, child_type,
					  child_index, &t->t_sibling);

  t->t_flags |= TUNNEL_FLAG_RESOLVED;

  return (0);
}

void
tunnel_unresolve (tunnel_t *t)
{
  if (t->t_flags & TUNNEL_FLAG_RESOLVED)
    fib_entry_untrack (t->t_fib_entry_index, t->t_sibling);

  t->t_flags &= ~TUNNEL_FLAG_RESOLVED;
}

void
tunnel_contribute_forwarding (const tunnel_t *t, dpo_id_t *dpo)
{
  fib_forward_chain_type_t fct;

  fct = fib_forw_chain_type_from_fib_proto (
    ip_address_family_to_fib_proto (ip_addr_version (&t->t_src)));

  fib_entry_contribute_forwarding (t->t_fib_entry_index, fct, dpo);
}

void
tunnel_build_v6_hdr (const tunnel_t *t, ip_protocol_t next_proto,
		     ip6_header_t *ip)
{
  ip->ip_version_traffic_class_and_flow_label =
    clib_host_to_net_u32 (0x60000000);
  ip6_set_dscp_network_order (ip, t->t_dscp);

  ip->hop_limit = 254;
  ip6_address_copy (&ip->src_address, &ip_addr_v6 (&t->t_src));
  ip6_address_copy (&ip->dst_address, &ip_addr_v6 (&t->t_dst));

  ip->protocol = next_proto;
  ip->hop_limit = (t->t_hop_limit == 0 ? 254 : t->t_hop_limit);
  ip6_set_flow_label_network_order (
    ip, ip6_compute_flow_hash (ip, IP_FLOW_HASH_DEFAULT));
}

void
tunnel_build_v4_hdr (const tunnel_t *t, ip_protocol_t next_proto,
		     ip4_header_t *ip)
{
  ip->ip_version_and_header_length = 0x45;
  ip->ttl = (t->t_hop_limit == 0 ? 254 : t->t_hop_limit);
  ip->src_address.as_u32 = t->t_src.ip.ip4.as_u32;
  ip->dst_address.as_u32 = t->t_dst.ip.ip4.as_u32;
  ip->tos = t->t_dscp << 2;
  ip->protocol = next_proto;
  ip->checksum = ip4_header_checksum (ip);
}

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