From mboxrd@z Thu Jan 1 00:00:00 1970 From: Asias He Subject: Re: [PATCH v2 12/31] kvm tools: Add UDP support for uip Date: Fri, 01 Jul 2011 23:24:56 +0800 Message-ID: <4E0DE6C8.7000206@gmail.com> References: <1309423279-3093-1-git-send-email-asias.hejun@gmail.com> <1309423279-3093-13-git-send-email-asias.hejun@gmail.com> <20110701114628.GI20990@elte.hu> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: Pekka Enberg , Cyrill Gorcunov , Sasha Levin , Prasad Joshi , kvm@vger.kernel.org To: Ingo Molnar Return-path: Received: from mail-iw0-f174.google.com ([209.85.214.174]:34238 "EHLO mail-iw0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757063Ab1GAP0r (ORCPT ); Fri, 1 Jul 2011 11:26:47 -0400 Received: by iwn6 with SMTP id 6so2876245iwn.19 for ; Fri, 01 Jul 2011 08:26:47 -0700 (PDT) In-Reply-To: <20110701114628.GI20990@elte.hu> Sender: kvm-owner@vger.kernel.org List-ID: On 07/01/2011 07:46 PM, Ingo Molnar wrote: > > * Asias He 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. Will do. Thanks. -- Best Regards, Asias He