Don't react to adressed bootp packets unless in bootp transaction
This commit is contained in:
parent
0c51bb63c5
commit
c4d038f632
5 changed files with 43 additions and 39 deletions
|
@ -49,7 +49,7 @@
|
|||
static jmp_buf main_env;
|
||||
|
||||
/* 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;
|
||||
|
||||
|
@ -139,14 +139,18 @@ main (int argc, char *argv[])
|
|||
|
||||
set_program_name (argv[0]);
|
||||
|
||||
dir = xstrdup (DEFAULT_DIRECTORY);
|
||||
|
||||
while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1)
|
||||
switch (opt)
|
||||
{
|
||||
case 'r':
|
||||
root_dev = optarg;
|
||||
free (root_dev);
|
||||
root_dev = xstrdup (optarg);
|
||||
break;
|
||||
case 'd':
|
||||
dir = optarg;
|
||||
free (dir);
|
||||
dir = xstrdup (optarg);
|
||||
break;
|
||||
case 'm':
|
||||
dev_map = optarg;
|
||||
|
|
|
@ -65,50 +65,49 @@ grub_net_recv_ip_packets (struct grub_net_buff * nb,
|
|||
{
|
||||
struct iphdr *iph = (struct iphdr *) nb->data;
|
||||
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));
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
FOR_NET_NETWORK_LEVEL_INTERFACES (inf)
|
||||
/* DHCP needs special treatment since we don't know IP yet. */
|
||||
{
|
||||
if (inf->card == card
|
||||
&& inf->address.type == GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4
|
||||
&& inf->address.ipv4 == iph->dest
|
||||
&& grub_net_hwaddr_cmp (&inf->hwaddress, hwaddress) == 0)
|
||||
break;
|
||||
struct udphdr *udph;
|
||||
udph = (struct udphdr *) nb->data;
|
||||
if (iph->protocol == IP_UDP && grub_be_to_cpu16 (udph->dst) == 68)
|
||||
{
|
||||
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)
|
||||
{
|
||||
FOR_NET_NETWORK_LEVEL_INTERFACES (inf)
|
||||
{
|
||||
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)
|
||||
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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (iph->protocol)
|
||||
{
|
||||
case IP_UDP:
|
||||
return grub_net_recv_udp_packet (nb, inf);
|
||||
break;
|
||||
default:
|
||||
grub_netbuff_free (nb);
|
||||
break;
|
||||
|
|
|
@ -119,7 +119,7 @@ match_net (const grub_net_network_level_netaddress_t *net,
|
|||
return 0;
|
||||
switch (net->type)
|
||||
{
|
||||
case GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC:
|
||||
case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV:
|
||||
return 0;
|
||||
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)
|
||||
{
|
||||
case GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC:
|
||||
grub_strcpy (buf, "promisc");
|
||||
case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV:
|
||||
grub_strcpy (buf, "temporary");
|
||||
return;
|
||||
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)
|
||||
{
|
||||
case GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC:
|
||||
grub_printf ("promisc\n");
|
||||
case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV:
|
||||
grub_printf ("temporary\n");
|
||||
break;
|
||||
case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4:
|
||||
{
|
||||
|
@ -1257,7 +1257,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)),
|
|||
grub_free (ifaces);
|
||||
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,
|
||||
sizeof (ifaces[j].hwaddress));
|
||||
j++;
|
||||
|
|
|
@ -32,8 +32,11 @@ grub_net_recv_udp_packet (struct grub_net_buff * nb,
|
|||
{
|
||||
struct udphdr *udph;
|
||||
grub_net_socket_t sock;
|
||||
grub_err_t err;
|
||||
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)
|
||||
{
|
||||
|
@ -54,8 +57,6 @@ grub_net_recv_udp_packet (struct grub_net_buff * nb,
|
|||
return GRUB_ERR_NONE;
|
||||
}
|
||||
}
|
||||
if (grub_be_to_cpu16 (udph->dst) == 68)
|
||||
grub_net_process_dhcp (nb, inf->card);
|
||||
grub_netbuff_free (nb);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ struct grub_net_network_level_interface;
|
|||
|
||||
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_network_level_protocol_id_t;
|
||||
|
||||
|
|
Loading…
Reference in a new issue