Don't react to adressed bootp packets unless in bootp transaction

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-07-02 20:11:29 +02:00
parent 0c51bb63c5
commit c4d038f632
5 changed files with 43 additions and 39 deletions

View file

@ -49,7 +49,7 @@
static jmp_buf main_env; static jmp_buf main_env;
/* Store the prefix specified by an argument. */ /* Store the prefix specified by an argument. */
static char *root_dev = NULL, *dir = DEFAULT_DIRECTORY; static char *root_dev = NULL, *dir = NULL;
int grub_no_autoload; int grub_no_autoload;
@ -139,14 +139,18 @@ main (int argc, char *argv[])
set_program_name (argv[0]); set_program_name (argv[0]);
dir = xstrdup (DEFAULT_DIRECTORY);
while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1) while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1)
switch (opt) switch (opt)
{ {
case 'r': case 'r':
root_dev = optarg; free (root_dev);
root_dev = xstrdup (optarg);
break; break;
case 'd': case 'd':
dir = optarg; free (dir);
dir = xstrdup (optarg);
break; break;
case 'm': case 'm':
dev_map = optarg; dev_map = optarg;

View file

@ -65,50 +65,49 @@ grub_net_recv_ip_packets (struct grub_net_buff * nb,
{ {
struct iphdr *iph = (struct iphdr *) nb->data; struct iphdr *iph = (struct iphdr *) nb->data;
grub_err_t err; grub_err_t err;
struct grub_net_network_level_interface *inf; struct grub_net_network_level_interface *inf = NULL;
err = grub_netbuff_pull (nb, sizeof (*iph)); err = grub_netbuff_pull (nb, sizeof (*iph));
if (err) if (err)
return err; return err;
FOR_NET_NETWORK_LEVEL_INTERFACES (inf) /* DHCP needs special treatment since we don't know IP yet. */
{ {
if (inf->card == card struct udphdr *udph;
&& inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 udph = (struct udphdr *) nb->data;
&& inf->address.ipv4 == iph->dest if (iph->protocol == IP_UDP && grub_be_to_cpu16 (udph->dst) == 68)
&& grub_net_hwaddr_cmp (&inf->hwaddress, hwaddress) == 0) {
break; FOR_NET_NETWORK_LEVEL_INTERFACES (inf)
if (inf->card == card
&& inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV
&& grub_net_hwaddr_cmp (&inf->hwaddress, hwaddress) == 0)
{
err = grub_netbuff_pull (nb, sizeof (*udph));
if (err)
return err;
grub_net_process_dhcp (nb, inf->card);
grub_netbuff_free (nb);
}
return GRUB_ERR_NONE;
}
} }
if (!inf) if (!inf)
{ {
FOR_NET_NETWORK_LEVEL_INTERFACES (inf) FOR_NET_NETWORK_LEVEL_INTERFACES (inf)
{
if (inf->card == card if (inf->card == card
&& inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC && inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4
&& inf->address.ipv4 == iph->dest
&& grub_net_hwaddr_cmp (&inf->hwaddress, hwaddress) == 0) && grub_net_hwaddr_cmp (&inf->hwaddress, hwaddress) == 0)
break; break;
} }
if (!inf)
{
if (iph->protocol == IP_UDP
&& grub_net_hwaddr_cmp (&card->default_address, hwaddress) == 0)
{
struct udphdr *udph;
udph = (struct udphdr *) nb->data;
err = grub_netbuff_pull (nb, sizeof (*udph));
if (err)
return err;
if (grub_be_to_cpu16 (udph->dst) == 68)
grub_net_process_dhcp (nb, card);
}
grub_netbuff_free (nb);
return GRUB_ERR_NONE;
} }
switch (iph->protocol) switch (iph->protocol)
{ {
case IP_UDP: case IP_UDP:
return grub_net_recv_udp_packet (nb, inf); return grub_net_recv_udp_packet (nb, inf);
break;
default: default:
grub_netbuff_free (nb); grub_netbuff_free (nb);
break; break;

View file

@ -119,7 +119,7 @@ match_net (const grub_net_network_level_netaddress_t *net,
return 0; return 0;
switch (net->type) switch (net->type)
{ {
case GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC: case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV:
return 0; return 0;
case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4:
{ {
@ -238,8 +238,8 @@ grub_net_addr_to_str (const grub_net_network_level_address_t *target, char *buf)
{ {
switch (target->type) switch (target->type)
{ {
case GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC: case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV:
grub_strcpy (buf, "promisc"); grub_strcpy (buf, "temporary");
return; return;
case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4:
{ {
@ -521,8 +521,8 @@ print_net_address (const grub_net_network_level_netaddress_t *target)
{ {
switch (target->type) switch (target->type)
{ {
case GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC: case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV:
grub_printf ("promisc\n"); grub_printf ("temporary\n");
break; break;
case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4: case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4:
{ {
@ -1257,7 +1257,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)),
grub_free (ifaces); grub_free (ifaces);
return grub_errno; return grub_errno;
} }
ifaces[j].address.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC; ifaces[j].address.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV;
grub_memcpy (&ifaces[j].hwaddress, &card->default_address, grub_memcpy (&ifaces[j].hwaddress, &card->default_address,
sizeof (ifaces[j].hwaddress)); sizeof (ifaces[j].hwaddress));
j++; j++;

View file

@ -32,8 +32,11 @@ grub_net_recv_udp_packet (struct grub_net_buff * nb,
{ {
struct udphdr *udph; struct udphdr *udph;
grub_net_socket_t sock; grub_net_socket_t sock;
grub_err_t err;
udph = (struct udphdr *) nb->data; udph = (struct udphdr *) nb->data;
grub_netbuff_pull (nb, sizeof (*udph)); err = grub_netbuff_pull (nb, sizeof (*udph));
if (err)
return err;
FOR_NET_SOCKETS (sock) FOR_NET_SOCKETS (sock)
{ {
@ -54,8 +57,6 @@ grub_net_recv_udp_packet (struct grub_net_buff * nb,
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
} }
if (grub_be_to_cpu16 (udph->dst) == 68)
grub_net_process_dhcp (nb, inf->card);
grub_netbuff_free (nb); grub_netbuff_free (nb);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }

View file

@ -123,7 +123,7 @@ struct grub_net_network_level_interface;
typedef enum grub_network_level_protocol_id typedef enum grub_network_level_protocol_id
{ {
GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC, GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV,
GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4
} grub_network_level_protocol_id_t; } grub_network_level_protocol_id_t;