summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2019-07-10 01:47:15 -0700
committerDave Wallace <dwallacelf@gmail.com>2019-07-11 20:03:19 +0000
commit13a6ddf353261fd0439646b71c832f4f44c9de71 (patch)
tree17aacb3301d188a30cc5a6d4572ffa167e62b40d /src
parentf699d128bf83726ac13629ef0979a21af8149fc1 (diff)
ip: Punt node does not free iovecs
Type: fix Fixes: f7a55ad74c Change-Id: Ic3474e746887f880a8f6246bebc399715bac8e80 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/vnet/ip/punt.c22
-rw-r--r--src/vnet/ip/punt.h6
2 files changed, 19 insertions, 9 deletions
diff --git a/src/vnet/ip/punt.c b/src/vnet/ip/punt.c
index 743df1fef0b..705711795cc 100644
--- a/src/vnet/ip/punt.c
+++ b/src/vnet/ip/punt.c
@@ -317,11 +317,12 @@ udp46_punt_socket_inline (vlib_main_t * vm,
vlib_frame_t * frame, bool is_ip4)
{
u32 *buffers = vlib_frame_vector_args (frame);
+ u32 thread_index = vm->thread_index;
uword n_packets = frame->n_vectors;
- struct iovec *iovecs = 0;
punt_main_t *pm = &punt_main;
int i;
+ punt_thread_data_t *ptd = &pm->thread_data[thread_index];
u32 node_index = is_ip4 ? udp4_punt_socket_node.index :
udp6_punt_socket_node.index;
@@ -375,20 +376,19 @@ udp46_punt_socket_inline (vlib_main_t * vm,
clib_memcpy_fast (&t->client, c, sizeof (t->client));
}
- /* Re-set iovecs if present. */
- if (iovecs)
- _vec_len (iovecs) = 0;
+ /* Re-set iovecs */
+ vec_reset_length (ptd->iovecs);
/* Add packet descriptor */
packetdesc.sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
packetdesc.action = 0;
- vec_add2 (iovecs, iov, 1);
+ vec_add2 (ptd->iovecs, iov, 1);
iov->iov_base = &packetdesc;
iov->iov_len = sizeof (packetdesc);
/** VLIB buffer chain -> Unix iovec(s). */
vlib_buffer_advance (b, -(sizeof (ethernet_header_t)));
- vec_add2 (iovecs, iov, 1);
+ vec_add2 (ptd->iovecs, iov, 1);
iov->iov_base = b->data + b->current_data;
iov->iov_len = l = b->current_length;
@@ -409,7 +409,7 @@ udp46_punt_socket_inline (vlib_main_t * vm,
t->is_midchain = 1;
}
- vec_add2 (iovecs, iov, 1);
+ vec_add2 (ptd->iovecs, iov, 1);
iov->iov_base = b->data + b->current_data;
iov->iov_len = b->current_length;
@@ -421,8 +421,8 @@ udp46_punt_socket_inline (vlib_main_t * vm,
struct msghdr msg = {
.msg_name = caddr,
.msg_namelen = sizeof (*caddr),
- .msg_iov = iovecs,
- .msg_iovlen = vec_len (iovecs),
+ .msg_iov = ptd->iovecs,
+ .msg_iovlen = vec_len (ptd->iovecs),
};
if (sendmsg (pm->socket_fd, &msg, 0) < (ssize_t) l)
@@ -1062,6 +1062,7 @@ clib_error_t *
ip_punt_init (vlib_main_t * vm)
{
punt_main_t *pm = &punt_main;
+ vlib_thread_main_t *tm = vlib_get_thread_main ();
pm->clients_by_dst_port6 = sparse_vec_new
(sizeof (pm->clients_by_dst_port6[0]),
@@ -1074,6 +1075,9 @@ ip_punt_init (vlib_main_t * vm)
pm->interface_output_node = vlib_get_node_by_name (vm,
(u8 *)
"interface-output");
+
+ vec_validate_aligned (pm->thread_data, tm->n_vlib_mains,
+ CLIB_CACHE_LINE_BYTES);
return 0;
}
diff --git a/src/vnet/ip/punt.h b/src/vnet/ip/punt.h
index 0518b2b91ef..2d7a0f84665 100644
--- a/src/vnet/ip/punt.h
+++ b/src/vnet/ip/punt.h
@@ -69,6 +69,11 @@ typedef struct
struct sockaddr_un caddr;
} punt_client_t;
+typedef struct punt_thread_data_t_
+{
+ struct iovec *iovecs;
+} punt_thread_data_t;
+
typedef struct
{
int socket_fd;
@@ -80,6 +85,7 @@ typedef struct
vlib_node_t *interface_output_node;
u32 *ready_fds;
u32 *rx_buffers;
+ punt_thread_data_t *thread_data;
} punt_main_t;
extern punt_main_t punt_main;
n336'>336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
/*
 * 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.
 */
#include <vlib/vlib.h>
#include <vlib/unix/unix.h>
#include <math.h>

int
main (int argc, char *argv[])
{
  return vlib_unix_main (argc, argv);
}

static clib_error_t *
main_stub_init (vlib_main_t * vm)
{
  clib_error_t *error;

  if ((error = unix_physmem_init (vm)))
    return error;

  if ((error = vlib_call_init_function (vm, unix_cli_init)))
    return error;

  return error;
}

VLIB_INIT_FUNCTION (main_stub_init);

#if 0
/* Node test code. */
typedef struct
{
  int scalar;
  int vector[0];
} my_frame_t;

static u8 *
format_my_node_frame (u8 * s, va_list * va)
{
  vlib_frame_t *f = va_arg (*va, vlib_frame_t *);
  my_frame_t *g = vlib_frame_args (f);
  int i;

  s = format (s, "scalar %d, vector { ", g->scalar);
  for (i = 0; i < f->n_vectors; i++)
    s = format (s, "%d, ", g->vector[i]);
  s = format (s, " }");

  return s;
}

static uword
my_func (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
{
  vlib_node_t *node;
  my_frame_t *y;
  u32 i, n_left = 0;
  static int serial;
  int verbose;

  node = vlib_get_node (vm, rt->node_index);

  verbose = 0;

  if (verbose && f)
    vlib_cli_output (vm, "%v: call frame %p %U", node->name,
		     f, format_my_node_frame, f);

  if (rt->n_next_nodes > 0)
    {
      vlib_frame_t *next = vlib_get_next_frame (vm, rt, /* next index */ 0);
      n_left = VLIB_FRAME_SIZE - next->n_vectors;
      y = vlib_frame_args (next);
      y->scalar = serial++;
    }
  else
    y = 0;

  for (i = 0; i < 5; i++)
    {
      if (y)
	{
	  ASSERT (n_left > 0);
	  n_left--;
	  y->vector[i] = y->scalar + i;
	}
    }
  if (y)
    vlib_put_next_frame (vm, rt, /* next index */ 0, n_left);

  if (verbose)
    vlib_cli_output (vm, "%v: return frame %p", node->name, f);

  return i;
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (my_node1,static) = {
  .function = my_func,
  .type = VLIB_NODE_TYPE_INPUT,
  .name = "my-node1",
  .scalar_size = sizeof (my_frame_t),
  .vector_size = STRUCT_SIZE_OF (my_frame_t, vector[0]),
  .n_next_nodes = 1,
  .next_nodes = {
    [0] = "my-node2",
  },
};
/* *INDENT-ON* */

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (my_node2,static) = {
  .function = my_func,
  .name = "my-node2",
  .scalar_size = sizeof (my_frame_t),
  .vector_size = STRUCT_SIZE_OF (my_frame_t, vector[0]),
};
/* *INDENT-ON* */

#endif

#if 0

typedef enum
{
  MY_EVENT_TYPE1,
  MY_EVENT_TYPE2,
} my_process_completion_type_t;

typedef struct
{
  int a;
  f64 b;
} my_process_event_data_t;

static u8 *
format_my_process_event_data (u8 * s, va_list * va)
{
  my_process_event_data_t *d = va_arg (*va, my_process_event_data_t *);
  return format (s, "{ a %d b %.6f}", d->a, d->b);
}

static uword
my_proc (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
{
  vlib_node_t *node;
  u32 i;

  node = vlib_get_node (vm, rt->node_index);

  vlib_cli_output (vm, "%v: call frame %p", node->name, f);

  for (i = 0; i < 5; i++)
    {
      vlib_cli_output (vm, "%v: %d", node->name, i);
      vlib_process_suspend (vm, 1e0 /* secs */ );
    }

  vlib_cli_output (vm, "%v: return frame %p", node->name, f);

  if (0)
    {
      uword n_events_seen, type, *data = 0;

      for (n_events_seen = 0; n_events_seen < 2;)
	{
	  vlib_process_wait_for_event (vm);
	  type = vlib_process_get_events (vm, &data);
	  n_events_seen += vec_len (data);
	  vlib_cli_output (vm, "%U %v: completion #%d type %d data 0x%wx",
			   format_time_interval, "h:m:s:u",
			   vlib_time_now (vm), node->name, i, type, data[0]);
	  _vec_len (data) = 0;
	}

      vec_free (data);
    }
  else
    {
      uword n_events_seen, i, type;
      my_process_event_data_t *data;
      for (n_events_seen = 0; n_events_seen < 2;)
	{
	  vlib_process_wait_for_event (vm);
	  data = vlib_process_get_event_data (vm, &type);
	  vec_foreach_index (i, data)
	  {
	    vlib_cli_output (vm, "%U event type %d data %U",
			     format_time_interval, "h:m:s:u",
			     vlib_time_now (vm), type,
			     format_my_process_event_data, data);
	  }
	  n_events_seen += vec_len (data);
	  vlib_process_put_event_data (vm, data);
	}
    }

  return i;
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (my_proc_node,static) = {
  .function = my_proc,
  .type = VLIB_NODE_TYPE_PROCESS,
  .name = "my-proc",
};
/* *INDENT-ON* */

static uword
my_proc_input (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
{
  static int i;

  if (i++ < 2)
    {
      if (0)
	vlib_process_signal_event (vm, my_proc_node.index,
				   i == 1 ? MY_EVENT_TYPE1 : MY_EVENT_TYPE2,
				   0x12340000 + i);
      else
	{
	  my_process_event_data_t *d;
	  f64 dt = 5;
	  d = vlib_process_signal_event_at_time (vm,
						 i * dt,
						 my_proc_node.index,
						 i ==
						 1 ? MY_EVENT_TYPE1 :
						 MY_EVENT_TYPE2,
						 1 /* elts */ ,
						 sizeof (d[0]));
	  d->a = i;
	  d->b = vlib_time_now (vm);
	}
    }
  else
    vlib_node_set_state (vm, rt->node_index, VLIB_NODE_STATE_DISABLED);

  return 0;
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (my_proc_input_node,static) = {
  .function = my_proc_input,
  .type = VLIB_NODE_TYPE_INPUT,
  .name = "my-proc-input",
};
/* *INDENT-ON* */

static uword
_unformat_farith (unformat_input_t * i, va_list * args)
{
  u32 prec = va_arg (*args, u32);
  f64 *result = va_arg (*args, f64 *);
  f64 tmp[2];

  /* Binary operations in from lowest to highest precedence. */
  char *binops[] = {
    "+%U", "-%U", "/%U", "*%U", "^%U",
  };

  if (prec <= ARRAY_LEN (binops) - 1
      && unformat_user (i, _unformat_farith, prec + 1, &tmp[0]))
    {
      int p;
      for (p = prec; p < ARRAY_LEN (binops); p++)
	{
	  if (unformat (i, binops[p], _unformat_farith, prec + 0, &tmp[1]))
	    {
	      switch (binops[p][0])
		{
		case '+':
		  result[0] = tmp[0] + tmp[1];
		  break;
		case '-':
		  result[0] = tmp[0] - tmp[1];
		  break;
		case '/':
		  result[0] = tmp[0] / tmp[1];
		  break;
		case '*':
		  result[0] = tmp[0] * tmp[1];
		  break;
		case '^':
		  result[0] = pow (tmp[0], tmp[1]);
		  break;
		default:
		  abort ();
		}
	      return 1;
	    }
	}
      result[0] = tmp[0];
      return 1;
    }

  else if (unformat (i, "-%U", _unformat_farith, prec + 0, &tmp[0]))
    {
      result[0] = -tmp[0];
      return 1;
    }

  else if (unformat (i, "(%U)", _unformat_farith, 0, &tmp[0]))
    {
      result[0] = tmp[0];
      return 1;
    }

  else if (unformat (i, "%f", result))
    return 1;

  else
    return 0;
}

static uword
unformat_farith (unformat_input_t * i, va_list * args)
{
  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
  f64 *result = va_arg (*args, f64 *);
  return unformat_user (i, _unformat_farith, 0, result);
}

static uword
unformat_integer (unformat_input_t * i, va_list * args)
{
  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
  u32 *data = va_arg (*args, u32 *);
  return unformat (i, "%d", data);
}

static VLIB_CLI_PARSE_RULE (my_parse_rule1) =
{
.name = "decimal_integer",.short_help =
    "a decimal integer",.unformat_function = unformat_integer,.data_size =
    sizeof (u32),};

static VLIB_CLI_PARSE_RULE (my_parse_rule2) =
{
.name = "float_expression",.short_help =
    "floating point expression",.unformat_function =
    unformat_farith,.data_size = sizeof (f64),};

static clib_error_t *
bar_command (vlib_main_t * vm,
	     unformat_input_t * input, vlib_cli_command_t * cmd)
{
  switch (cmd->function_arg)
    {
    case 2:
      {
	u32 *d, *e;
	d = vlib_cli_get_parse_rule_result (vm, 0);
	e = vlib_cli_get_parse_rule_result (vm, 1);
	vlib_cli_output (vm, "bar2 %d %d", d[0], e[0]);
	break;
      }

    case 1:
      {
	u32 *d = vlib_cli_get_parse_rule_result (vm, 0);
	vlib_cli_output (vm, "bar1 %d", d[0]);
	break;
      }

    case 3:
      {
	f64 *d = vlib_cli_get_parse_rule_result (vm, 0);
	vlib_cli_output (vm, "expr %.6f", d[0]);
      }
    }

  return 0;
}

/* *INDENT-OFF* */
VLIB_CLI_COMMAND (bar_command2, static) = {
  .path = "bar %decimal_integer",
  .short_help = "bar1 command",
  .function = bar_command,
  .function_arg = 1,
};
VLIB_CLI_COMMAND (bar_command1, static) = {
  .path = "bar %decimal_integer %decimal_integer",
  .short_help = "bar2 command",
  .function = bar_command,
  .function_arg = 2,
};
VLIB_CLI_COMMAND (bar_command3, static) = {
  .path = "zap %float_expression",
  .short_help = "bar3 command",
  .function = bar_command,
  .function_arg = 3,
};
/* *INDENT-ON* */

#endif

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