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.
This commit is contained in:
parent
50ee5d686d
commit
6dc14451f4
1 changed files with 25 additions and 37 deletions
|
@ -5,63 +5,51 @@
|
||||||
#include <grub/time.h>
|
#include <grub/time.h>
|
||||||
|
|
||||||
grub_err_t
|
grub_err_t
|
||||||
grub_net_send_udp_packet (const grub_net_network_level_address_t *target,
|
grub_net_send_udp_packet (const grub_net_socket_t socket , struct grub_net_buff *nb)
|
||||||
struct grub_net_buff *nb, grub_uint16_t srcport,
|
|
||||||
grub_uint16_t destport)
|
|
||||||
{
|
{
|
||||||
struct udphdr *udph;
|
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));
|
grub_netbuff_push (nb,sizeof(*udph));
|
||||||
|
|
||||||
udph = (struct udphdr *) nb->data;
|
udph = (struct udphdr *) nb->data;
|
||||||
udph->src = grub_cpu_to_be16 (srcport);
|
udph->src = grub_cpu_to_be16 (socket->in_port);
|
||||||
udph->dst = grub_cpu_to_be16 (destport);
|
udph->dst = grub_cpu_to_be16 (socket->out_port);
|
||||||
|
|
||||||
/* No chechksum. */
|
/* No chechksum. */
|
||||||
udph->chksum = 0;
|
udph->chksum = 0;
|
||||||
udph->len = grub_cpu_to_be16 (nb->tail - nb->data);
|
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_err_t
|
||||||
grub_net_recv_udp_packet (const grub_net_network_level_address_t *target,
|
grub_net_recv_udp_packet (struct grub_net_buff *nb)
|
||||||
struct grub_net_buff *buf,
|
|
||||||
grub_uint16_t srcport, grub_uint16_t destport)
|
|
||||||
{
|
|
||||||
grub_err_t err;
|
|
||||||
struct grub_net_packet *pkt;
|
|
||||||
struct grub_net_network_level_interface *inf;
|
|
||||||
grub_net_network_level_address_t gateway;
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
|
//grub_err_t err;
|
||||||
struct udphdr *udph;
|
struct udphdr *udph;
|
||||||
struct grub_net_buff *nb = pkt->nb;
|
grub_net_socket_t sock;
|
||||||
udph = (struct udphdr *) nb->data;
|
udph = (struct udphdr *) nb->data;
|
||||||
if (grub_be_to_cpu16 (udph->dst) == destport)
|
|
||||||
{
|
|
||||||
grub_net_remove_packet (pkt);
|
|
||||||
grub_netbuff_pull (nb, sizeof (*udph));
|
grub_netbuff_pull (nb, sizeof (*udph));
|
||||||
grub_memcpy (buf, nb, sizeof (buf));
|
|
||||||
|
|
||||||
|
FOR_NET_SOCKETS(sock)
|
||||||
|
{
|
||||||
|
if (grub_be_to_cpu16 (udph->dst) == sock->in_port)
|
||||||
|
{
|
||||||
|
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;
|
return GRUB_ERR_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
grub_netbuff_free (nb);
|
||||||
return GRUB_ERR_NONE;
|
return GRUB_ERR_NONE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue