Example #1
0
static int set_ipv4(struct sk_buff *skb, const struct ovs_key_ipv4 *ipv4_key)
{
	struct iphdr *nh;
	int err;

	err = make_writable(skb, skb_network_offset(skb) +
				 sizeof(struct iphdr));
	if (unlikely(err))
		return err;

	nh = ip_hdr(skb);

	if (ipv4_key->ipv4_src != nh->saddr)
		set_ip_addr(skb, nh, &nh->saddr, ipv4_key->ipv4_src);

	if (ipv4_key->ipv4_dst != nh->daddr)
		set_ip_addr(skb, nh, &nh->daddr, ipv4_key->ipv4_dst);

	if (ipv4_key->ipv4_tos != nh->tos)
		ipv4_change_dsfield(nh, 0, ipv4_key->ipv4_tos);

	if (ipv4_key->ipv4_ttl != nh->ttl)
		set_ip_ttl(skb, nh, ipv4_key->ipv4_ttl);

	return 0;
}
Example #2
0
File: txrx_uhd.c Project: GREO/uhd
static void handle_inp_packet(uint32_t *buff, size_t num_lines){

  //test if its an ip recovery packet
  typedef struct{
      padded_eth_hdr_t eth_hdr;
      char code[4];
      union {
        struct ip_addr ip_addr;
      } data;
  }recovery_packet_t;
  recovery_packet_t *recovery_packet = (recovery_packet_t *)buff;
  if (recovery_packet->eth_hdr.ethertype == 0xbeee && strncmp(recovery_packet->code, "addr", 4) == 0){
      printf("Got ip recovery packet: "); print_ip_addr(&recovery_packet->data.ip_addr); newline();
      set_ip_addr(&recovery_packet->data.ip_addr);
      return;
  }

  //pass it to the slow-path handler
  handle_eth_packet(buff, num_lines);
}
Example #3
0
int WirelessNetworkInit()
{
	int ret = -1;
	int nDhcpFlag = -1;
	SYS_INFO sysInfo;
	WIFI_PARAM wifiParam;
	NET_PARAM netParam;
	char ip[16];
	char mac_addr[32] = {0};
	char command_buffer[256]= {0};
	char buffer_cache[128]= {0};
	
	ret = getWifiParam(&wifiParam);
	if (ret < 0)
	{
		return -1;
	}
			
	ret = getNetParam(&netParam);
	if (ret < 0)
	{
		return -1;
	}

	system("ifconfig ra0 192.168.5.5 up");
	memset(mac_addr, 0, 32);
	if (get_net_phyaddr_ext(ETH_WIRELESS_DEV, mac_addr) == 0)
	{
		memcpy(wifiParam.strPhyAddr, mac_addr, 6);
	}
	ret = setWifiParam(&wifiParam);
	if (ret < 0)
	{
		return -1;
	}
	
	if (wifiParam.nOnFlag == 1) 	// 启用无线
	{
		//增加wifi 状态指示
		if(wifi_setup(wifiParam) == 0)
		{
			wifiParam.Reserve = 1;
			ret = setWifiParam(&wifiParam);
			if (ret < 0)
			{
				return -1;
			}
		}
		
#if 1		
		// DHCP设置
		if (wifiParam.nDhcpOnFlag == 1)
		{
			getSysInfoParam(&sysInfo);
			nDhcpFlag = dhcp_setup(ETH_WIRELESS_DEV, sysInfo.strDeviceName);
		}
		else
		{
			nDhcpFlag = -1;
		}
		
		// 固定IP设置
		memset(ip, 0, 16);
		get_ip_addr(ETH_WIRELESS_DEV, ip);
		
		printf("dhcp_setup(WIRELESS): %d %s\n", nDhcpFlag, ip);

		if (nDhcpFlag != 0 || strlen(ip)<=0 || wifiParam.nDhcpOnFlag==0)
		{
			// Add the code by lvjh, 2008-03-22
			unsigned int add1 = 0;
			unsigned int add2 = 0;
			unsigned int add3 = 0;
			unsigned int add4 = 0;
	
			unsigned int add5 = 0;
			unsigned int add6 = 0;
			unsigned int add7 = 0;
			unsigned int add8 = 0;
				
			//判断是不是用户输入的wifi
			sleep(10);
			printf("wifiParam.pReserve[0]  = %d\n", wifiParam.pReserve[0]);
			if(wifiParam.pReserve[0] == 1){
				strcpy(wifiParam.byServerIp, netParam.byServerIp);
				strcpy(wifiParam.byDnsAddr, netParam.byDnsAddr);
				strcpy(wifiParam.byGateway, netParam.byGateway);
				strcpy(wifiParam.byServerMask, netParam.byServerMask);
				
				ret = setWifiParam(&wifiParam);
				if (ret < 0)
				{
					return -1;
				}
			}
			
			printf("DVS IP(WIRELESS): %s\n", wifiParam.byServerIp);
			

			#if 0
			if (set_ip_addr(ETH_WIRELESS_DEV, wifiParam.byServerIp) < 0)
			{
				printf("set_ip_addr(%s) Failed!\n", wifiParam.byServerIp);
	
				set_ip_addr(ETH_WIRELESS_DEV, DEFAULT_WIRELESS_IP);
				set_mask_addr(ETH_WIRELESS_DEV, DEFAULT_WIRELESS_MASK);
				//set_gateway_addr(DEFAULT_WIRELESS_GATEWAY);
				set_gateway_addr_ext(ETH_WIRELESS_DEV, DEFAULT_WIRELESS_GATEWAY);
				//return -1;
			}
			#endif
			
			sprintf(buffer_cache, "%s %s %s", "ifconfig",  ETH_WIRELESS_DEV, wifiParam.byServerIp);
			system(buffer_cache);
			
		
			if (set_mask_addr(ETH_WIRELESS_DEV, wifiParam.byServerMask) < 0)
			{
				printf("set_mask_addr(%s) Failed!\n", wifiParam.byServerMask);
		
				set_mask_addr(ETH_WIRELESS_DEV, DEFAULT_WIRELESS_MASK);
				//set_gateway_addr(DEFAULT_WIRELESS_GATEWAY);
				set_gateway_addr_ext(ETH_WIRELESS_DEV, DEFAULT_WIRELESS_GATEWAY);
				//return -1;
			}
	
			//printf("Old GateWay: %s\n", wifiParam.byGateway);
			//sscanf(wifiParam.byServerIp, "%d.%d.%d.%d", &add1, &add2, &add3, &add4);
			//sscanf(wifiParam.byGateway, "%d.%d.%d.%d", &add5, &add6, &add7, &add8);
			//sprintf(wifiParam.byGateway, "%d.%d.%d.%d", add1, add2, add3, add8);
			//printf("New GateWay: %s\n", wifiParam.byGateway);
				
			//if (set_gateway_addr(wifiParam.byGateway) < 0)
			if (set_gateway_addr_ext(ETH_WIRELESS_DEV, wifiParam.byGateway) < 0)
			{
				printf("set_gateway_addr(%s) Failed!\n", wifiParam.byGateway);
				//set_gateway_addr(DEFAULT_WIRELESS_GATEWAY);
				set_gateway_addr_ext(ETH_WIRELESS_DEV, DEFAULT_WIRELESS_GATEWAY);
				//return -1;
			}
		}

		// DNS设置
		if (wifiParam.nDhcpOnFlag == 1)
		{
			char localIP[16];
			char gateway[16];
			
			memset(localIP, 0, 16);
			memset(gateway, 0, 16);
	
			//ret = get_gateway_addr(gateway);
			ret = get_gateway_addr_ext(ETH_WIRELESS_DEV, gateway);
			if (ret == 0)
			{
				printf("GateWay(WIRELESS): %s\n", gateway);

				set_dns_addr(gateway);
				//add_dns_addr(gateway);
				
				strcpy(wifiParam.byGateway, gateway);
				strcpy(wifiParam.byDnsAddr, gateway);
			}
			ret = get_ip_addr(ETH_WIRELESS_DEV, localIP);
			if (ret == 0)
			{
				printf("DHCP: get_ip_addr: %s\n", localIP);
				strcpy(wifiParam.byServerIp, localIP);
			}
			printf("DHCP: %s %s\n", ETH_WIRELESS_DEV, localIP);
			
		
			wifiParam.Reserve = 1;
			setWifiParam(&wifiParam);
		}
		else
		{
			wifiParam.Reserve = 1;
			set_dns_addr(wifiParam.byGateway);
			
			
			//add_dns_addr(wifiParam.byGateway);
		}
#endif	
	}
	else
	{
		wifiParam.Reserve = 1;
		setWifiParam(&wifiParam);
	}
	return 0;
}
Example #4
0
int WireNetworkInit()
{
	int ret = -1;
	int nDhcpFlag = -1;
	SYS_INFO sysInfo;
	NET_PARAM netParam;
	char ip[16];
	char mac_addr[32] = {0};
	char buffer_cache[128] ={0};
	
	ret = getNetParam(&netParam);
	if (ret < 0)
	{
		return -1;
	}
	
	// 自动生成多播地址
	generateMultiAddr(netParam.byMultiAddr);
	
	ifconfig_up_down(ETH_WIRE_DEV, "down");
	
	memset(mac_addr, 0, 32);
	if (get_net_phyaddr_ext(ETH_WIRE_DEV, mac_addr) == 0)
	{
		if (strcmp(netParam.strPhyAddr, mac_addr) != 0)
		{
			sprintf(mac_addr, "%02x:%02x:%02x:%02x:%02x:%02x", netParam.strPhyAddr[0], netParam.strPhyAddr[1], netParam.strPhyAddr[2], netParam.strPhyAddr[3], netParam.strPhyAddr[4], netParam.strPhyAddr[5]);
			ret = set_net_phyaddr(ETH_WIRE_DEV, mac_addr);
			printf("set_net_phyaddr: (WIRE: %s) %d\n", mac_addr, ret);
		}
	}
	
	ifconfig_up_down(ETH_WIRE_DEV, "up");

	if (netParam.nDhcpOnFlag == 1)
	{
		getSysInfoParam(&sysInfo);
		nDhcpFlag = dhcp_setup(ETH_WIRE_DEV, sysInfo.strDeviceName);
	}
	else
	{
		nDhcpFlag = -1;
	}

	memset(ip, 0, 16);
	ret = get_ip_addr(ETH_WIRE_DEV, ip);

	printf("dhcp_setup(WIRE): %d %s\n", nDhcpFlag, ip);

	if (nDhcpFlag != 0 || strlen(ip)<=0 || netParam.nDhcpOnFlag==0)
	{
		// Add the code by lvjh, 2008-03-22
		unsigned int add1 = 0;
		unsigned int add2 = 0;
		unsigned int add3 = 0;
		unsigned int add4 = 0;

		unsigned int add5 = 0;
		unsigned int add6 = 0;
		unsigned int add7 = 0;
		unsigned int add8 = 0;
			
		printf("DVS IP(WIRE): %s\n", netParam.byServerIp);


	#if 0
		if (set_ip_addr(ETH_WIRE_DEV, netParam.byServerIp) < 0)
		{
			printf("set_ip_addr(%s) Failed!\n", netParam.byServerIp);

			set_ip_addr(ETH_WIRE_DEV, DEFAULT_WIRE_IP);
			set_mask_addr(ETH_WIRE_DEV, DEFAULT_WIRE_MASK);
			//set_gateway_addr(DEFAULT_WIRE_GATEWAY);
			set_gateway_addr_ext(ETH_WIRE_DEV, DEFAULT_WIRE_GATEWAY);
			//return -1;
		}
	#endif
	

		sprintf(buffer_cache, "%s %s %s", "ifconfig",  ETH_WIRE_DEV, netParam.byServerIp);
		system(buffer_cache);

		if (set_mask_addr(ETH_WIRE_DEV, netParam.byServerMask) < 0)
		{
    	   	printf("set_mask_addr(%s) Failed!\n", netParam.byServerMask);
	
			set_mask_addr(ETH_WIRE_DEV, DEFAULT_WIRE_MASK);
			//set_gateway_addr(DEFAULT_WIRE_GATEWAY);
			set_gateway_addr_ext(ETH_WIRE_DEV, DEFAULT_WIRE_GATEWAY);
			//return -1;
		}

		//printf("Old GateWay: %s\n", netParam.byGateway);
		//sscanf(netParam.byServerIp, "%d.%d.%d.%d", &add1, &add2, &add3, &add4);
		//sscanf(netParam.byGateway, "%d.%d.%d.%d", &add5, &add6, &add7, &add8);
		//sprintf(netParam.byGateway, "%d.%d.%d.%d", add1, add2, add3, add8);
		//printf("New GateWay: %s\n", netParam.byGateway);
			
		//if (set_gateway_addr(netParam.byGateway) < 0)
		if (set_gateway_addr_ext(ETH_WIRE_DEV, netParam.byGateway) < 0)
		{
			printf("set_gateway_addr(%s) Failed!\n", netParam.byGateway);
			//set_gateway_addr(DEFAULT_WIRE_GATEWAY);
			set_gateway_addr_ext(ETH_WIRE_DEV, DEFAULT_WIRE_GATEWAY);
			//return -1;
		}
	}

	// DNS
	if (netParam.nDhcpOnFlag == 1)
	{
		char localIP[16];
		char gateway[16];
		
		memset(localIP, 0, 16);
		memset(gateway, 0, 16);

		//ret = get_gateway_addr(gateway);
		ret = get_gateway_addr_ext(ETH_WIRE_DEV, gateway);
		if (ret == 0)
		{
			printf("GateWay(WIRE): %s\n", gateway);

			set_dns_addr(gateway);
			
			strcpy(netParam.byGateway, gateway);
			strcpy(netParam.byDnsAddr, gateway);
		}
		ret = get_ip_addr(ETH_WIRE_DEV, localIP);
		if (ret == 0)
		{
			printf("DHCP: get_ip_addr: %s\n", localIP);
			strcpy(netParam.byServerIp, localIP);
		}
		printf("DHCP: %s %s\n", ETH_WIRE_DEV, localIP);
	
		setNetParam(&netParam);
	}
	else
	{
		set_dns_addr(netParam.byGateway);
	}
	
	return 0;
}
Example #5
0
File: vport.c Project: apanda/bess
static struct snobj *init_port(struct port *p, struct snobj *conf)
{
	struct vport_priv *priv = get_port_priv(p);

	int container_pid = 0;
	int cpu;
	int rxq;

	int ret;

	if (strlen(p->name) >= IFNAMSIZ)
		return snobj_err(EINVAL, "Linux interface name should be " \
				"shorter than %d characters", IFNAMSIZ);

	if (snobj_eval_exists(conf, "docker")) {
		struct snobj *err = docker_container_pid(
				snobj_eval_str(conf, "docker"), 
				&container_pid);

		if (err)
			return err;
	}

	priv->fd = open("/dev/softnic", O_RDONLY);
	if (priv->fd == -1)
		return snobj_err(ENODEV, "the kernel module is not loaded");

	priv->bar = alloc_bar(p, container_pid);
	ret = ioctl(priv->fd, SN_IOC_CREATE_HOSTNIC, 
			rte_malloc_virt2phy(priv->bar));
	if (ret < 0) {
		close(priv->fd);
		return snobj_errno_details(-ret, 
				snobj_str("SN_IOC_CREATE_HOSTNIC failure"));
	}

	if (snobj_eval_exists(conf, "ip_addr")) {
		struct snobj *err = set_ip_addr(p, container_pid,
				snobj_eval(conf, "ip_addr"));
		
		if (err) {
			deinit_port(p);
			return err;
		}
	}

	for (cpu = 0; cpu < SN_MAX_CPU; cpu++)
		priv->map.cpu_to_txq[cpu] = cpu % p->num_queues[PACKET_DIR_INC];

	cpu = 0;
	for (rxq = 0; rxq < p->num_queues[PACKET_DIR_OUT]; rxq++) {
		while (is_worker_core(cpu))
			cpu = (cpu + 1) % sysconf(_SC_NPROCESSORS_ONLN);

		priv->map.rxq_to_cpu[rxq] = cpu;
		cpu = (cpu + 1) % sysconf(_SC_NPROCESSORS_ONLN);
	}

	ret = ioctl(priv->fd, SN_IOC_SET_QUEUE_MAPPING, &priv->map);
	if (ret < 0)
		perror("SN_IOC_SET_QUEUE_MAPPING");	

	return NULL;
}
Example #6
0
//
// Initialize lwIP for simple (single-threaded) mode.
//
void
cyg_lwip_simple_init(void)
{
    static int initialized;

    // Only initialize once
    if (initialized)
        return;
    initialized = 1;

    // Initialize the lwIP stack
    lwip_init();

#if LWIP_HAVE_LOOPIF && defined(CYGIMP_LWIP_LOOPIF_INSTANCE)
    {
        struct ip_addr addr, netmask, gateway;

        // Setup default loopback device instance
        set_ip_addr(&addr, CYGDAT_LWIP_LOOPIF_ADDR);
        set_ip_addr(&netmask, CYGDAT_LWIP_LOOPIF_NETMASK);
        set_ip_addr(&gateway, CYGDAT_LWIP_LOOPIF_GATEWAY);
        netif_add(&loopif, &addr, &netmask, &gateway, NULL,
                  loopif_init, simple_input);
#ifdef CYGDAT_LWIP_LOOPIF_DEFAULT
        netif_set_default(&loopif);
#endif
#ifdef CYGFUN_LWIP_SHOW_NETIF_CONFIG
        netif_set_status_callback(&loopif, netif_status_callback);
#endif
        netif_set_up(&loopif);
    }
#endif

#if LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE)
    {
        struct ip_addr addr, netmask, gateway;

        // Setup default SLIP device instance
        set_ip_addr(&addr, CYGDAT_LWIP_SLIPIF_ADDR);
        set_ip_addr(&netmask, CYGDAT_LWIP_SLIPIF_NETMASK);
        set_ip_addr(&gateway, CYGDAT_LWIP_SLIPIF_GATEWAY);
        netif_add(&slipif, &addr, &netmask, &gateway, NULL,
                  slipif_init, simple_input);
#ifdef CYGDAT_LWIP_SLIPIF_DEFAULT
        netif_set_default(&slipif);
#endif
#ifdef CYGFUN_LWIP_SHOW_NETIF_CONFIG
        netif_set_status_callback(&slipif, netif_status_callback);
#endif
        netif_set_up(&slipif);
    }
#endif

#if PPP_SUPPORT
    {
        // Setup PPP instance
    }
#endif

#ifdef CYGPKG_LWIP_ETH
    {
        cyg_netdevtab_entry_t *t;

        // Initialize network devices
        for (t = &__NETDEVTAB__[0]; t != &__NETDEVTAB_END__; t++) {
            if (t->init(t)) {
                t->status = CYG_NETDEVTAB_STATUS_AVAIL;
            } else {
                // Device not [currently] available
                t->status = 0;
            }
        }
    }
#endif
    
    cyg_lwip_simple_restart();
}