Exemplo n.º 1
0
int
main(int argc,char *argv[])
{
  struct tapif tapif[NETIF_MAX];
  struct netif netif[NETIF_MAX];
  int ch;
  int n = 0;

  memset(tapif,0,sizeof(tapif));
  memset(netif,0,sizeof(netif));

  tcpip_init(NULL,NULL);

#ifdef LWIP_DEBUG
  while ((ch = getopt(argc,argv,"CEHdhi:")) != -1) {
#else
  while ((ch = getopt(argc,argv,"CEHhi:")) != -1) {
#endif
    switch (ch) {
    case 'C':
      chargen_init();
      break;
    case 'E':
      udpecho_init();
      tcpecho_init();
      break;
    case 'H':
      http_server_netconn_init();
      break;
#ifdef LWIP_DEBUG
    case 'd':
      debug_flags |= (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|
                      LWIP_DBG_FRESH|LWIP_DBG_HALT);
      break;
#endif
    case 'i':
      if (n >= NETIF_MAX)
        break;
      if (parse_interface(&tapif[n],optarg) != 0)
        help();
      netif_add(&netif[n],
                IP4_OR_NULL(tapif[n].ip_addr),
                IP4_OR_NULL(tapif[n].netmask),
                IP4_OR_NULL(tapif[n].gw),
                &tapif[n],
                tapif_init,
                tcpip_input);
      if (n == 0)
        netif_set_default(&netif[n]);
      netif_set_up(&netif[n]);
      if (IP4_OR_NULL(tapif[n].ip_addr) == 0 &&
          IP4_OR_NULL(tapif[n].netmask) == 0 &&
          IP4_OR_NULL(tapif[n].gw) == 0)
        dhcp_start(&netif[n]);
      n++;
      break;
    case 'h':
    default:
      help();
    }
  }
  argc -= optind;
  argv += optind;
  if (n <= 0)
    help();
  pause();
  return -1;
}
Exemplo n.º 2
0
static int
parse_args(int argc, char **argv)
{
	int ch;
	struct net_port *port;
	struct vxlan_peer peer;

#ifdef LWIP_DEBUG
	while ((ch = getopt(argc, argv, "P:V:e:k:d")) != -1) {
#else
	while ((ch = getopt(argc, argv, "P:V:e:k:")) != -1) {
#endif
	switch (ch) {
		case 'P':
			port = &BR0.plug.net_port;
			if (parse_port(&port->net, optarg))
				return -1;
			port->rte_port_type = RTE_PORT_TYPE_PLUG;
			break;
		case 'V':
			memset(&peer, 0, sizeof(peer));
			if (parse_vxlan(&peer, optarg))
				return -1;
			if (bridge_add_vxlan(&BR0, &peer) != 0)
				return -1;
			break;
		case 'e':
			if (nr_ports >= PORT_MAX)
				break;
			port = &ports[nr_ports];
			if (parse_port(&port->net, optarg))
				return -1;
			port->rte_port_type = RTE_PORT_TYPE_ETH;
			nr_ports++;
			break;
		case 'k':
			if (nr_ports >= PORT_MAX)
				break;
			port = &ports[nr_ports];
			if (parse_port(&port->net, optarg))
				return -1;
			port->rte_port_type = RTE_PORT_TYPE_KNI;
			nr_ports++;
			break;

#ifdef LWIP_DEBUG
		case 'd':
			debug_flags |= (LWIP_DBG_ON|
					LWIP_DBG_TRACE|
					LWIP_DBG_STATE|
					LWIP_DBG_FRESH|
					LWIP_DBG_HALT);
			break;
#endif
		default:
			return -1;
		}
	}
	argc -= optind;
	argv += optind;

	return 0;
}

#define IP4_OR_NULL(ip_addr) ((ip_addr).addr == IPADDR_ANY ? 0 : &(ip_addr))

static int
create_eth_port(struct net_port *net_port, int socket_id)
{
	RTE_VERIFY(net_port->rte_port_type == RTE_PORT_TYPE_ETH);

	struct net *net = &net_port->net;
	struct rte_port_eth_params params = {
		.port_id = net->port_id,
		.nb_rx_desc = RTE_TEST_RX_DESC_DEFAULT,
		.nb_tx_desc = RTE_TEST_TX_DESC_DEFAULT,
		.mempool = pktmbuf_pool,
	};

	if (!IP4_OR_NULL(net_port->net.ip_addr)) {
		struct rte_port_eth *eth_port;

		eth_port = rte_port_eth_create(&params, socket_id, net_port);
		if (!eth_port)
			rte_exit(EXIT_FAILURE, "Cannot alloc kni port\n");

		bridge_add_port(&BR0, net_port);
	} else {
		struct ethif *ethif;
		struct netif *netif;

		ethif = ethif_alloc(socket_id);
		if (ethif == NULL)
			rte_exit(EXIT_FAILURE, "Cannot alloc eth port\n");

		if (ethif_init(ethif, &params, socket_id, net_port) != ERR_OK)
			rte_exit(EXIT_FAILURE, "Cannot init eth port\n");

		netif = &ethif->netif;
		netif_add(netif,
			  IP4_OR_NULL(net->ip_addr),
			  IP4_OR_NULL(net->netmask),
			  IP4_OR_NULL(net->gw),
			  ethif,
			  ethif_added_cb,
			  ethernet_input);
		netif_set_up(netif);
	}

	return 0;
}

static int
create_kni_port(struct net_port *net_port, int socket_id)
{
	RTE_VERIFY(net_port->rte_port_type == RTE_PORT_TYPE_KNI);

	struct net *net = &net_port->net;
	struct rte_port_kni_params params = {
		.name = net->name,
		.mbuf_size = MAX_PACKET_SZ,
		.mempool = pktmbuf_pool,
	};

	if (!IP4_OR_NULL(net_port->net.ip_addr)) {
		struct rte_port_kni *kni_port;

		kni_port = rte_port_kni_create(&params, socket_id, net_port);
		if (!kni_port)
			rte_exit(EXIT_FAILURE, "Cannot alloc kni port\n");

		bridge_add_port(&BR0, net_port);
	} else {
		struct kniif *kniif;
		struct netif *netif;

		kniif = kniif_alloc(socket_id);
		if (kniif == NULL)
			rte_exit(EXIT_FAILURE, "Cannot alloc kni interface\n");

		if (kniif_init(kniif, &params, socket_id, net_port) != ERR_OK)
			rte_exit(EXIT_FAILURE, "Cannot init kni interface\n");

		netif = &kniif->netif;
		netif_add(netif,
			  IP4_OR_NULL(net->ip_addr),
			  IP4_OR_NULL(net->netmask),
			  IP4_OR_NULL(net->gw),
			  kniif,
			  kniif_added_cb,
			  ethernet_input);
		netif_set_up(netif);
	}

	return 0;
}

static int
create_plug_port(struct net_port *net_port, int socket_id)
{
	RTE_VERIFY(net_port->rte_port_type == RTE_PORT_TYPE_PLUG);

	struct net *net = &net_port->net;

	if (!IP4_OR_NULL(net_port->net.ip_addr)) {
		struct rte_port_plug *plug_port;
		struct rte_port_plug_params params = {
			.tx_burst     = bridge_tx_vxlan_burst,
			.private_data = &BR0,
		};

		plug_port = rte_port_plug_create(&params, socket_id, net_port);
		if (!plug_port)
			rte_exit(EXIT_FAILURE, "Cannot alloc plug port\n");

		if (bridge_add_port(&BR0, net_port) != 0)
			rte_exit(EXIT_FAILURE, "Cannot add bridge port\n");
	} else {