Re: [PATCH v2 12/31] kvm tools: Add UDP support for uip

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Asias He <asias.hejun@xxxxxxxxx> wrote:

> +static void *uip_udp_socket_thread(void *p)
> +{
> +	struct epoll_event events[UIP_UDP_MAX_EVENTS];
> +	struct uip_udp_socket *sk;
> +	struct uip_info *info;
> +	struct uip_eth *eth2;
> +	struct uip_udp *udp2;
> +	struct uip_buf *buf;
> +	struct uip_ip *ip2;
> +	u8 *payload;
> +	int nfds;
> +	int ret;
> +	int i;
> +
> +	info = p;
> +
> +	do {
> +		payload = malloc(UIP_MAX_UDP_PAYLOAD);
> +	} while (!payload);
> +
> +	while (1) {
> +		nfds = epoll_wait(info->udp_epollfd, events, UIP_UDP_MAX_EVENTS, -1);
> +
> +		if (nfds == -1)
> +			continue;
> +
> +		for (i = 0; i < nfds; i++) {
> +
> +			sk = events[i].data.ptr;
> +			ret = recvfrom(sk->fd, payload, UIP_MAX_UDP_PAYLOAD, 0, NULL, NULL);
> +			if (ret < 0)
> +				continue;
> +
> +			/*
> +			 * Get free buffer to send data to guest
> +			 */
> +			buf		= uip_buf_get_free(info);
> +
> +			/*
> +			 * Cook a ethernet frame
> +			 */
> +			udp2		= (struct uip_udp *)(buf->eth);
> +			eth2		= (struct uip_eth *)buf->eth;
> +			ip2		= (struct uip_ip *)(buf->eth);
> +
> +			eth2->src	= info->host_mac;
> +			eth2->dst	= info->guest_mac;
> +			eth2->type	= htons(UIP_ETH_P_IP);
> +
> +			ip2->vhl	= UIP_IP_VER_4 | UIP_IP_HDR_LEN;
> +			ip2->tos	= 0;
> +			ip2->id		= 0;
> +			ip2->flgfrag	= 0;
> +			ip2->ttl	= UIP_IP_TTL;
> +			ip2->proto	= UIP_IP_P_UDP;
> +			ip2->csum	= 0;
> +			ip2->sip	= sk->dip;
> +			ip2->dip	= sk->sip;
> +
> +			udp2->sport	= sk->dport;
> +			udp2->dport	= sk->sport;
> +			udp2->len	= htons(ret + uip_udp_hdrlen(udp2));
> +			udp2->csum	= 0;
> +
> +			memcpy(udp2->payload, payload, ret);
> +
> +			ip2->len	= udp2->len + htons(uip_ip_hdrlen(ip2));
> +			ip2->csum	= uip_csum_ip(ip2);
> +			udp2->csum	= uip_csum_udp(udp2);
> +
> +			/*
> +			 * virtio_net_hdr
> +			 */
> +			buf->vnet_len	= sizeof(struct virtio_net_hdr);
> +			memset(buf->vnet, 0, buf->vnet_len);
> +
> +			buf->eth_len	= ntohs(ip2->len) + uip_eth_hdrlen(&ip2->eth);
> +
> +			/*
> +			 * Send data received from socket to guest
> +			 */
> +			uip_buf_set_used(info, buf);
> +		}
> +	}
> +
> +	free(payload);
> +	pthread_exit(NULL);
> +	return NULL;
> +}

This function is way too large, please split out the meat of it into 
a separate helper inline.

Thanks,

	Ingo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux