From 6dc14451f4769d68d96c40f66644fe52e5a29d39 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Fri, 1 Apr 2011 05:12:44 -0300 Subject: [PATCH] Iterate sockets to see if we expect this packet. Let the App layer to remove its own header. Add packet to socket list if it contains data. Undesired packets are freed. --- grub-core/net/udp.c | 62 ++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/grub-core/net/udp.c b/grub-core/net/udp.c index a73431f83..16b2011ff 100644 --- a/grub-core/net/udp.c +++ b/grub-core/net/udp.c @@ -5,63 +5,51 @@ #include grub_err_t -grub_net_send_udp_packet (const grub_net_network_level_address_t *target, - struct grub_net_buff *nb, grub_uint16_t srcport, - grub_uint16_t destport) +grub_net_send_udp_packet (const grub_net_socket_t socket , struct grub_net_buff *nb) { struct udphdr *udph; - struct grub_net_network_level_interface *inf; - grub_err_t err; - grub_net_network_level_address_t gateway; - - err = grub_net_route_address (*target, &gateway, &inf); - if (err) - return err; grub_netbuff_push (nb,sizeof(*udph)); udph = (struct udphdr *) nb->data; - udph->src = grub_cpu_to_be16 (srcport); - udph->dst = grub_cpu_to_be16 (destport); + udph->src = grub_cpu_to_be16 (socket->in_port); + udph->dst = grub_cpu_to_be16 (socket->out_port); /* No chechksum. */ udph->chksum = 0; udph->len = grub_cpu_to_be16 (nb->tail - nb->data); - return grub_net_send_ip_packet (inf, target, nb); + return grub_net_send_ip_packet (socket->inf, &(socket->out_nla), nb); } grub_err_t -grub_net_recv_udp_packet (const grub_net_network_level_address_t *target, - struct grub_net_buff *buf, - grub_uint16_t srcport, grub_uint16_t destport) +grub_net_recv_udp_packet (struct grub_net_buff *nb) { - grub_err_t err; - struct grub_net_packet *pkt; - struct grub_net_network_level_interface *inf; - grub_net_network_level_address_t gateway; + //grub_err_t err; + struct udphdr *udph; + grub_net_socket_t sock; + udph = (struct udphdr *) nb->data; + grub_netbuff_pull (nb, sizeof (*udph)); - err = grub_net_route_address (*target, &gateway, &inf); - if (err) - return err; - - (void) srcport; - - err = grub_net_recv_ip_packets (inf); - - FOR_NET_NL_PACKETS(inf, pkt) + FOR_NET_SOCKETS(sock) { - struct udphdr *udph; - struct grub_net_buff *nb = pkt->nb; - udph = (struct udphdr *) nb->data; - if (grub_be_to_cpu16 (udph->dst) == destport) + if (grub_be_to_cpu16 (udph->dst) == sock->in_port) { - grub_net_remove_packet (pkt); - grub_netbuff_pull (nb, sizeof(*udph)); - grub_memcpy (buf, nb, sizeof (buf)); - + if (sock->status == 0) + sock->out_port = udph->src; + + + /* App protocol remove its own reader. */ + sock->app->read (sock,nb); + + /* If there is data, puts packet in socket list */ + if ((nb->tail - nb->data) > 0) + grub_net_put_packet (sock->packs, nb); + else + grub_netbuff_free (nb); return GRUB_ERR_NONE; } } + grub_netbuff_free (nb); return GRUB_ERR_NONE; }