public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Asias He <asias.hejun@gmail.com>
Cc: Pekka Enberg <penberg@kernel.org>,
	Cyrill Gorcunov <gorcunov@gmail.com>,
	Sasha Levin <levinsasha928@gmail.com>,
	Prasad Joshi <prasadjoshi124@gmail.com>,
	kvm@vger.kernel.org
Subject: Re: [PATCH v2 12/31] kvm tools: Add UDP support for uip
Date: Fri, 1 Jul 2011 13:46:28 +0200	[thread overview]
Message-ID: <20110701114628.GI20990@elte.hu> (raw)
In-Reply-To: <1309423279-3093-13-git-send-email-asias.hejun@gmail.com>


* Asias He <asias.hejun@gmail.com> 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

  reply	other threads:[~2011-07-01 11:46 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-30  8:40 [PATCH v2 00/31] Implement user mode network for kvm tools Asias He
2011-06-30  8:40 ` [PATCH v2 01/31] kvm tools: Introduce ethernet frame buffer system for uip Asias He
2011-06-30  8:40 ` [PATCH v2 02/31] kvm tools: Add ARP support " Asias He
2011-06-30  8:40 ` [PATCH v2 03/31] kvm tools: Add IPV4 " Asias He
2011-06-30  8:40 ` [PATCH v2 04/31] kvm tools: Implement IP checksum " Asias He
2011-06-30  8:40 ` [PATCH v2 05/31] kvm tools: Add ICMP support " Asias He
2011-06-30  8:40 ` [PATCH v2 06/31] kvm tools: Introduce struct uip_udp to present UDP package Asias He
2011-06-30  8:40 ` [PATCH v2 07/31] kvm tools: Introduce struct uip_pseudo_hdr to present UDP pseudo header Asias He
2011-06-30  8:40 ` [PATCH v2 08/31] kvm tools: Introduce struct uip_udp_socket Asias He
2011-06-30  8:40 ` [PATCH v2 09/31] kvm tools: Add two helpers to return UDP {header, total} length Asias He
2011-06-30  8:40 ` [PATCH v2 10/31] kvm tools: Add helper to return ethernet header length Asias He
2011-06-30  8:40 ` [PATCH v2 11/31] kvm tools: Implement uip_csum_udp() to calculate UDP checksum Asias He
2011-06-30  8:41 ` [PATCH v2 12/31] kvm tools: Add UDP support for uip Asias He
2011-07-01 11:46   ` Ingo Molnar [this message]
2011-07-01 15:24     ` Asias He
2011-06-30  8:41 ` [PATCH v2 13/31] kvm tools: Introduce struct uip_tcp to present TCP package Asias He
2011-06-30  8:41 ` [PATCH v2 14/31] kvm tools: Introduce struct uip_tcp_socket Asias He
2011-06-30  8:41 ` [PATCH v2 15/31] kvm tools: Add helpers to return TCP {header, total, payload} length Asias He
2011-06-30  8:41 ` [PATCH v2 16/31] kvm tools: Add helper to return start address of TCP payload Asias He
2011-06-30  8:41 ` [PATCH v2 17/31] kvm tools: Add helpers to test whether SYN or FIN bit is set Asias He
2011-06-30  8:41 ` [PATCH v2 18/31] kvm tools: Add helper to allocate and get TCP initial sequence number Asias He
2011-06-30  8:41 ` [PATCH v2 19/31] kvm tools: Implement uip_csum_tcp() to calculate TCP checksum Asias He
2011-06-30  8:41 ` [PATCH v2 20/31] kvm tools: Add TCP support for uip Asias He
2011-06-30  8:41 ` [PATCH v2 21/31] kvm tools: Introduce uip_init() " Asias He
2011-06-30  8:41 ` [PATCH v2 22/31] kvm tools: Introduce uip_tx() " Asias He
2011-06-30  8:41 ` [PATCH v2 23/31] kvm tools: Introduce uip_rx() " Asias He
2011-06-30  8:41 ` [PATCH v2 24/31] kvm tools: Add MACRO for user and tap mode for virtio net Asias He
2011-06-30  8:41 ` [PATCH v2 25/31] kvm tools: Reanme net_device to net_dev Asias He
2011-06-30  8:41 ` [PATCH v2 26/31] kvm tools: Introduce -net {user, tap, none} options for virtio net Asias He
2011-06-30  8:41 ` [PATCH v2 27/31] kvm tools: Change default guest MAC address to 00:15:15:15:15:15 Asias He
2011-06-30  8:41 ` [PATCH v2 28/31] kvm tools: Make virtio net work with user mode network Asias He
2011-06-30  8:41 ` [PATCH v2 29/31] kvm tools: Make default network mode to user mode Asias He
2011-06-30  8:41 ` [PATCH v2 30/31] kvm tools: Make default host ip address to 192.168.33.1 Asias He
2011-06-30  8:41 ` [PATCH v2 31/31] kvm tools: Introduce struct net_dev_operations Asias He
2011-06-30  8:56 ` [PATCH v2 00/31] Implement user mode network for kvm tools Stefan Hajnoczi
2011-06-30 15:32   ` Anthony Liguori
2011-07-01  0:18     ` Asias He
2011-07-01 11:53       ` Ingo Molnar
2011-07-01 13:46         ` Alexander Graf
2011-07-02  9:45           ` Pekka Enberg
2011-07-02 10:30             ` Ingo Molnar
2011-07-02 11:19             ` Alexander Graf
2011-07-02 11:27               ` Pekka Enberg
2011-07-02 12:31                 ` Alexander Graf
2011-07-03 19:42           ` Ingo Molnar
2011-07-03 22:15             ` Alexander Graf
2011-07-04  9:11               ` Ingo Molnar
2011-07-04  9:30                 ` Alexander Graf
2011-07-04  9:43                   ` Ingo Molnar
2011-07-02  9:42         ` Pekka Enberg
2011-06-30 23:38   ` Asias He
2011-07-01 16:50     ` Stefan Hajnoczi
2011-07-01 20:36       ` Pekka Enberg
2011-07-02  3:49         ` Asias He
2011-07-02  9:02           ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110701114628.GI20990@elte.hu \
    --to=mingo@elte.hu \
    --cc=asias.hejun@gmail.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=penberg@kernel.org \
    --cc=prasadjoshi124@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox