コード例 #1
0
ファイル: cli.c プロジェクト: Venkattk/vpp
static clib_error_t *
netmap_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
                             vlib_cli_command_t * cmd)
{
  unformat_input_t _line_input, * line_input = &_line_input;
  u8 * host_if_name = NULL;

  /* Get a line of input. */
  if (! unformat_user (input, unformat_line_input, line_input))
    return 0;

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "name %s", &host_if_name))
        ;
      else
        return clib_error_return (0, "unknown input `%U'", format_unformat_error, input);
    }
  unformat_free (line_input);

  if (host_if_name == NULL)
      return clib_error_return (0, "missing host interface name");

  netmap_delete_if(vm, host_if_name);

  return 0;
}
コード例 #2
0
static clib_error_t *
virtio_pci_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
			      vlib_cli_command_t * cmd)
{
  unformat_input_t _line_input, *line_input = &_line_input;
  virtio_pci_create_if_args_t args;
  u64 feature_mask = (u64) ~ (0ULL);

  /* Get a line of input. */
  if (!unformat_user (input, unformat_line_input, line_input))
    return 0;

  memset (&args, 0, sizeof (args));
  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "%U", unformat_vlib_pci_addr, &args.addr))
	;
      else if (unformat (line_input, "feature-mask 0x%llx", &feature_mask))
	args.features = feature_mask;
      else
	return clib_error_return (0, "unknown input `%U'",
				  format_unformat_error, input);
    }
  unformat_free (line_input);

  virtio_pci_create_if (vm, &args);

  return args.error;
}
コード例 #3
0
ファイル: cli.c プロジェクト: chrisy/vpp
static clib_error_t *
mrvl_pp2_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
			    vlib_cli_command_t * cmd)
{
  unformat_input_t _line_input, *line_input = &_line_input;
  mrvl_pp2_create_if_args_t args = { 0 };

  /* Get a line of input. */
  if (!unformat_user (input, unformat_line_input, line_input))
    return 0;

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "name %s", &args.name))
	;
      else
	return clib_error_return (0, "unknown input `%U'",
				  format_unformat_error, input);
    }
  unformat_free (line_input);


  mrvl_pp2_create_if (&args);

  vec_free (args.name);

  return args.error;
}
コード例 #4
0
ファイル: arp.c プロジェクト: jcsakai/vnet
static uword
unformat_ethernet_arp_opcode_host_byte_order (unformat_input_t * input,
					      va_list * args)
{
  int * result = va_arg (*args, int *);
  ethernet_arp_main_t * am = &ethernet_arp_main;
  int x, i;

  /* Numeric opcode. */
  if (unformat (input, "0x%x", &x)
      || unformat (input, "%d", &x))
    {
      if (x >= (1 << 16))
	return 0;
      *result = x;
      return 1;
    }

  /* Named type. */
  if (unformat_user (input, unformat_vlib_number_by_name,
		     am->opcode_by_name, &i))
    {
      *result = i;
      return 1;
    }

  return 0;
}
コード例 #5
0
ファイル: abf_policy.c プロジェクト: vpp-dev/vpp
static clib_error_t *
abf_policy_cmd (vlib_main_t * vm,
		unformat_input_t * main_input, vlib_cli_command_t * cmd)
{
  unformat_input_t _line_input, *line_input = &_line_input;
  u32 acl_index, policy_id;
  fib_route_path_t *rpaths = NULL, rpath;
  u32 is_del;

  is_del = 0;
  acl_index = INDEX_INVALID;
  policy_id = INDEX_INVALID;

  /* Get a line of input. */
  if (!unformat_user (main_input, unformat_line_input, line_input))
    return 0;

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "acl %d", &acl_index))
	;
      else if (unformat (line_input, "id %d", &policy_id))
	;
      else if (unformat (line_input, "del"))
	is_del = 1;
      else if (unformat (line_input, "add"))
	is_del = 0;
      else if (unformat (line_input, "via %U",
			 unformat_fib_route_path, &rpath))
	vec_add1 (rpaths, rpath);
      else
	return (clib_error_return (0, "unknown input '%U'",
				   format_unformat_error, line_input));
    }

  if (INDEX_INVALID == policy_id)
    {
      vlib_cli_output (vm, "Specify a Policy ID");
      return 0;
    }

  if (!is_del)
    {
      if (INDEX_INVALID == acl_index)
	{
	  vlib_cli_output (vm, "ACL index must be set");
	  return 0;
	}

      abf_policy_update (policy_id, acl_index, rpaths);
    }
  else
    {
      abf_policy_delete (policy_id, rpaths);
    }

  unformat_free (line_input);
  return (NULL);
}
コード例 #6
0
ファイル: arp.c プロジェクト: jcsakai/vnet
static uword
unformat_ethernet_arp_opcode_net_byte_order (unformat_input_t * input,
					     va_list * args)
{
  int * result = va_arg (*args, int *);
  if (! unformat_user (input, unformat_ethernet_arp_opcode_host_byte_order, result))
    return 0;

  *result = clib_host_to_net_u16 ((u16) *result);
  return 1;
}
コード例 #7
0
ファイル: cli.c プロジェクト: Venkattk/vpp
static clib_error_t *
netmap_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
			     vlib_cli_command_t * cmd)
{
  unformat_input_t _line_input, * line_input = &_line_input;
  u8 * host_if_name = NULL;
  u8 hwaddr [6];
  u8 * hw_addr_ptr = 0;
  int r;
  u8 is_pipe = 0;
  u8 is_master = 0;
  u32 sw_if_index = ~0;

  /* Get a line of input. */
  if (! unformat_user (input, unformat_line_input, line_input))
    return 0;

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "name %s", &host_if_name))
	;
      else if (unformat (line_input, "hw-addr %U", unformat_ethernet_address, hwaddr))
	hw_addr_ptr = hwaddr;
      else if (unformat (line_input, "pipe"))
	is_pipe = 1;
      else if (unformat (line_input, "master"))
	is_master = 1;
      else if (unformat (line_input, "slave"))
	is_master = 0;
      else
	return clib_error_return (0, "unknown input `%U'", format_unformat_error, input);
    }
  unformat_free (line_input);

  if (host_if_name == NULL)
      return clib_error_return (0, "missing host interface name");

  r = netmap_create_if(vm, host_if_name, hw_addr_ptr, is_pipe, is_master, &sw_if_index);

  if (r == VNET_API_ERROR_SYSCALL_ERROR_1)
    return clib_error_return(0, "%s (errno %d)", strerror (errno), errno);

  if (r == VNET_API_ERROR_INVALID_INTERFACE)
    return clib_error_return(0, "Invalid interface name");

  if (r == VNET_API_ERROR_SUBIF_ALREADY_EXISTS)
    return clib_error_return(0, "Interface already exists");

  vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
  return 0;
}
コード例 #8
0
static clib_error_t *
virtio_pci_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
			      vlib_cli_command_t * cmd)
{
  unformat_input_t _line_input, *line_input = &_line_input;
  u32 sw_if_index = ~0;
  vnet_hw_interface_t *hw;
  virtio_main_t *vim = &virtio_main;
  virtio_if_t *vif;
  vnet_main_t *vnm = vnet_get_main ();

  /* Get a line of input. */
  if (!unformat_user (input, unformat_line_input, line_input))
    return 0;

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "sw_if_index %d", &sw_if_index))
	;
      else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
			 vnm, &sw_if_index))
	;
      else
	return clib_error_return (0, "unknown input `%U'",
				  format_unformat_error, input);
    }
  unformat_free (line_input);

  if (sw_if_index == ~0)
    return clib_error_return (0,
			      "please specify interface name or sw_if_index");

  hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
  if (hw == NULL || virtio_device_class.index != hw->dev_class_index)
    return clib_error_return (0, "not a virtio interface");

  vif = pool_elt_at_index (vim->interfaces, hw->dev_instance);

  if (virtio_pci_delete_if (vm, vif) < 0)
    return clib_error_return (0, "not a virtio pci interface");

  return 0;
}
コード例 #9
0
ファイル: cj.c プロジェクト: chrisy/vpp
static clib_error_t *
cj_command_fn (vlib_main_t * vm,
	       unformat_input_t * input, vlib_cli_command_t * cmd)
{
  int is_enable = -1;
  int is_dump = -1;
  unformat_input_t _line_input, *line_input = &_line_input;
  clib_error_t *error = NULL;

  /* Get a line of input. */
  if (!unformat_user (input, unformat_line_input, line_input))
    return clib_error_return (0, "expected enable | disable | dump");

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "enable") || unformat (line_input, "on"))
	is_enable = 1;
      else if (unformat (line_input, "disable")
	       || unformat (line_input, "off"))
	is_enable = 0;
      else if (unformat (line_input, "dump"))
	is_dump = 1;
      else
	{
	  error = clib_error_return (0, "unknown input `%U'",
				     format_unformat_error, line_input);
	  goto done;
	}
    }

  if (is_enable >= 0)
    cj_enable_disable (is_enable);

  if (is_dump > 0)
    cj_dump ();

done:
  unformat_free (line_input);
  return error;
}
コード例 #10
0
ファイル: cli.c プロジェクト: chrisy/vpp
static clib_error_t *
rdma_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
			vlib_cli_command_t * cmd)
{
  unformat_input_t _line_input, *line_input = &_line_input;
  rdma_create_if_args_t args;

  /* Get a line of input. */
  if (!unformat_user (input, unformat_line_input, line_input))
    return 0;

  clib_memset (&args, 0, sizeof (rdma_create_if_args_t));

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "host-if %s", &args.ifname))
	;
      else if (unformat (line_input, "name %s", &args.name))
	;
      else if (unformat (line_input, "rx-queue-size %u", &args.rxq_size))
	;
      else if (unformat (line_input, "tx-queue-size %u", &args.txq_size))
	;
      else if (unformat (line_input, "num-rx-queues %u", &args.rxq_num))
	;
      else
	return clib_error_return (0, "unknown input `%U'",
				  format_unformat_error, input);
    }
  unformat_free (line_input);

  rdma_create_if (vm, &args);

  vec_free (args.ifname);
  vec_free (args.name);

  return args.error;
}
コード例 #11
0
ファイル: interface.c プロジェクト: chrisy/vpp
static clib_error_t *
mpls_interface_enable_disable (vlib_main_t * vm,
                               unformat_input_t * input,
                               vlib_cli_command_t * cmd)
{
  vnet_main_t * vnm = vnet_get_main();
  clib_error_t * error = 0;
  u32 sw_if_index, enable;
  int rv;

  sw_if_index = ~0;

  if (! unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
    {
      error = clib_error_return (0, "unknown interface `%U'",
				 format_unformat_error, input);
      goto done;
    }

  if (unformat (input, "enable"))
      enable = 1;
  else if (unformat (input, "disable"))
      enable = 0;
  else
    {
      error = clib_error_return (0, "expected 'enable' or 'disable'",
				 format_unformat_error, input);
      goto done;
    }

  rv = mpls_sw_interface_enable_disable(&mpls_main, sw_if_index, enable, 0);

  if (VNET_API_ERROR_NO_SUCH_FIB == rv)
      error = clib_error_return (0, "default MPLS table must be created first");

 done:
  return error;
}
コード例 #12
0
ファイル: vpe_cli.c プロジェクト: Venkattk/vpp
static clib_error_t *
virtual_ip_cmd_fn_command_fn (vlib_main_t * vm,
		 unformat_input_t * input,
		 vlib_cli_command_t * cmd)
{
    unformat_input_t _line_input, * line_input = &_line_input;
    vnet_main_t * vnm = vnet_get_main();
    ip4_main_t * im = &ip4_main;
    ip_lookup_main_t * lm = &im->lookup_main;
    ip4_address_t ip_addr, next_hop;
    u8 mac_addr[6];
    mac_addr_t *mac_addrs = 0;
    u32 sw_if_index;
    u32 i, f;

    /* Get a line of input. */
    if (! unformat_user (input, unformat_line_input, line_input))
        return 0;

    if (!unformat(line_input, "%U %U", 
                  unformat_ip4_address, &ip_addr,
                  unformat_vnet_sw_interface, vnm, &sw_if_index))
        goto barf;

    while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
	if (unformat (line_input, "mac %U", 
                      unformat_ethernet_address, 
                      &mac_addr))
        {
            mac_addr_t *ma;
            vec_add2 (mac_addrs, ma, 1);
            clib_memcpy(ma, mac_addr, sizeof (mac_addr));
        } else {
        barf:
	    return clib_error_return (0, "unknown input `%U'",
				      format_unformat_error, input);
        }
    }
    if (vec_len (mac_addrs) == 0)
        goto barf;

    /* Create / delete special interface route /32's */
    next_hop.as_u32 = 0;

    for (i = 0; i < vec_len(mac_addrs); i++) {
        ip_adjacency_t adj;
        u32 adj_index;
        
        adj.lookup_next_index = IP_LOOKUP_NEXT_REWRITE;
        
        vnet_rewrite_for_sw_interface
            (vnm,
             VNET_L3_PACKET_TYPE_IP4,
             sw_if_index,
             ip4_rewrite_node.index,
             &mac_addrs[i],     /* destination address */
             &adj.rewrite_header,
             sizeof (adj.rewrite_data));

        ip_add_adjacency (lm, &adj, 1 /* one adj */,
                          &adj_index);
        
        f = (i + 1 < vec_len(mac_addrs)) ? IP4_ROUTE_FLAG_NOT_LAST_IN_GROUP : 0;
        ip4_add_del_route_next_hop (im,
                                    IP4_ROUTE_FLAG_ADD | f,
                                    &ip_addr,
                                    32 /* insert /32's */,
                                    &next_hop,
                                    sw_if_index,
                                    1 /* weight */, 
                                    adj_index, 
                                    (u32)~0 /* explicit fib index */);
    }

    vec_free (mac_addrs);

    return 0;
}
コード例 #13
0
ファイル: nsim.c プロジェクト: chrisy/vpp
/*
 * enable or disable the output_feature
 */
static clib_error_t *
nsim_output_feature_enable_disable_command_fn (vlib_main_t * vm,
					       unformat_input_t * input,
					       vlib_cli_command_t * cmd)
{
  nsim_main_t *nsm = &nsim_main;
  unformat_input_t _line_input, *line_input = &_line_input;
  u32 sw_if_index = ~0;
  int enable_disable = 1;
  int rv;

  /* Get a line of input. */
  if (!unformat_user (input, unformat_line_input, line_input))
    return 0;

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "disable"))
	enable_disable = 0;
      else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
			 nsm->vnet_main, &sw_if_index))
	;
      else
	{
	  clib_error_t *error = clib_error_return (0, "unknown input `%U'",
						   format_unformat_error,
						   line_input);
	  unformat_free (line_input);
	  return error;
	}
    }

  unformat_free (line_input);

  if (sw_if_index == ~0)
    return clib_error_return (0, "Please specify one interface...");

  rv = nsim_output_feature_enable_disable (nsm, sw_if_index, enable_disable);

  switch (rv)
    {
    case 0:
      break;

    case VNET_API_ERROR_CANNOT_ENABLE_DISABLE_FEATURE:
      return clib_error_return (0, "Not configured, please 'set nsim' first");

    case VNET_API_ERROR_INVALID_SW_IF_INDEX:
      return clib_error_return
	(0, "Invalid interface, only works on physical ports");
      break;

    case VNET_API_ERROR_UNIMPLEMENTED:
      return clib_error_return (0,
				"Device driver doesn't support redirection");
      break;

    default:
      return clib_error_return
	(0, "nsim_output_feature_enable_disable returned %d", rv);
    }
  return 0;
}
コード例 #14
0
ファイル: lisp_gpe.c プロジェクト: Venkattk/vpp
static clib_error_t *
lisp_gpe_add_del_fwd_entry_command_fn (vlib_main_t * vm,
                                       unformat_input_t * input,
                                       vlib_cli_command_t * cmd)
{
  unformat_input_t _line_input, * line_input = &_line_input;
  u8 is_add = 1;
  ip_address_t lloc, rloc, *llocs = 0, *rlocs = 0;
  clib_error_t * error = 0;
  gid_address_t _reid, * reid = &_reid, _leid, * leid = &_leid;
  u8 reid_set = 0, leid_set = 0, is_negative = 0, vrf_set = 0, vni_set = 0;
  u32 vni, vrf, action = ~0;
  int rv;

  /* Get a line of input. */
  if (! unformat_user (input, unformat_line_input, line_input))
    return 0;

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "del"))
        is_add = 0;
      else if (unformat (line_input, "add"))
        is_add = 1;
      else if (unformat (line_input, "leid %U",
                         unformat_gid_address, leid))
        {
          leid_set = 1;
        }
      else if (unformat (line_input, "reid %U",
                         unformat_gid_address, reid))
        {
          reid_set = 1;
        }
      else if (unformat (line_input, "vni %u", &vni))
        {
          gid_address_vni (leid) = vni;
          gid_address_vni (reid) = vni;
          vni_set = 1;
        }
      else if (unformat (line_input, "vrf %u", &vrf))
        {
          vrf_set = 1;
        }
      else if (unformat (line_input, "negative action %U",
                         unformat_negative_mapping_action, &action))
        {
          is_negative = 1;
        }
      else if (unformat (line_input, "lloc %U rloc %U",
                         unformat_ip_address, &lloc,
                         unformat_ip_address, &rloc))
        {
          /* TODO: support p and w */
          vec_add1 (llocs, lloc);
          vec_add1 (rlocs, rloc);
        }
      else
        {
          error = unformat_parse_error (line_input);
          goto done;
        }
    }
  unformat_free (line_input);

  if (!vni_set || !vrf_set)
    {
      error = clib_error_return(0, "vni and vrf must be set!");
      goto done;
    }

  if (!reid_set)
    {
      error = clib_error_return(0, "remote eid must be set!");
      goto done;
    }

  if (is_negative)
    {
      if (~0 == action)
        {
          error = clib_error_return(0, "no action set for negative tunnel!");
          goto done;
        }
    }
  else
    {
      if (vec_len (llocs) == 0)
        {
          error = clib_error_return (0, "expected ip4/ip6 locators.");
          goto done;
        }

      if (vec_len (llocs) != 1)
        {
          error = clib_error_return (0, "multihoming not supported for now!");
          goto done;
        }
    }



  if (!leid_set)
    {
      /* if leid not set, make sure it's the same AFI like reid */
      gid_address_type(leid) = gid_address_type(reid);
      if (GID_ADDR_IP_PREFIX == gid_address_type (reid))
        gid_address_ip_version(leid) = gid_address_ip_version(reid);
    }

  /* add fwd entry */
  vnet_lisp_gpe_add_del_fwd_entry_args_t _a, * a = &_a;
  memset (a, 0, sizeof(a[0]));

  a->is_add = is_add;
  a->vni = vni;
  a->table_id = vrf;
  gid_address_copy(&a->seid, leid);
  gid_address_copy(&a->deid, reid);

  if (!is_negative)
    {
      a->slocator = llocs[0];
      a->dlocator = rlocs[0];
    }

  rv = vnet_lisp_gpe_add_del_fwd_entry (a, 0);
  if (0 != rv)
    {
      error = clib_error_return(0, "failed to %s gpe tunnel!",
                                is_add ? "add" : "delete");
    }

 done:
  vec_free(llocs);
  vec_free(rlocs);
  return error;
}