Beispiel #1
0
void
grub_net_remove_dns_server (const struct grub_net_network_level_address *s)
{
  grub_size_t i;
  for (i = 0; i < dns_nservers; i++)
    if (grub_net_addr_cmp (s, &dns_servers[i]) == 0)
      break;
  if (i < dns_nservers)
    {
      dns_servers[i] = dns_servers[dns_nservers - 1];
      dns_nservers--;
    }
}
Beispiel #2
0
static struct grub_net_link_layer_entry *
link_layer_find_entry (const grub_net_network_level_address_t *proto,
		       const struct grub_net_card *card)
{
  unsigned i;
  if (!card->link_layer_table)
    return NULL;
  for (i = 0; i < LINK_LAYER_CACHE_SIZE; i++)
    {
      if (card->link_layer_table[i].avail == 1 
	  && grub_net_addr_cmp (&card->link_layer_table[i].nl_address,
				proto) == 0)
	return &card->link_layer_table[i];
    }
  return NULL;
}
Beispiel #3
0
grub_err_t
grub_net_arp_receive (struct grub_net_buff *nb,
		      struct grub_net_card *card)
{
  struct arphdr *arp_header = (struct arphdr *) nb->data;
  grub_uint8_t *sender_hardware_address;
  grub_uint8_t *target_hardware_address;
  grub_net_network_level_address_t sender_addr, target_addr;
  grub_net_link_level_address_t sender_hw_addr;
  struct grub_net_network_level_interface *inf;
  grub_uint8_t *sender_protocol_address, *target_protocol_address;

  sender_hardware_address =
    (grub_uint8_t *) arp_header + sizeof (*arp_header);
  sender_protocol_address = sender_hardware_address + arp_header->hln;
  target_hardware_address = sender_protocol_address + arp_header->pln;
  target_protocol_address = target_hardware_address + arp_header->hln;
  if (grub_be_to_cpu16 (arp_header->pro) == GRUB_NET_ETHERTYPE_IP
      && arp_header->pln == 4)
    {
      sender_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
      target_addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
      grub_memcpy (&sender_addr.ipv4, sender_protocol_address, 4);
      grub_memcpy (&target_addr.ipv4, target_protocol_address, 4);
      if (grub_memcmp (sender_protocol_address, &pending_req, 4) == 0)
	have_pending = 1;
    }
  else
    return GRUB_ERR_NONE;

  sender_hw_addr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
  grub_memcpy (sender_hw_addr.mac, sender_hardware_address,
	       sizeof (sender_hw_addr.mac));
  grub_net_link_layer_add_address (card, &sender_addr, &sender_hw_addr, 1);

  FOR_NET_NETWORK_LEVEL_INTERFACES (inf)
  {
    /* Am I the protocol address target? */
    if (grub_net_addr_cmp (&inf->address, &target_addr) == 0
	&& grub_be_to_cpu16 (arp_header->op) == ARP_REQUEST)
      {
	grub_net_link_level_address_t target;
	/* We've already checked that pln is either 4 or 16.  */
	char tmp[arp_header->pln];

	target.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
	grub_memcpy (target.mac, sender_hardware_address, 6);
	grub_memcpy (target_hardware_address, target.mac, 6);
	grub_memcpy (sender_hardware_address, inf->hwaddress.mac, 6);

	grub_memcpy (tmp, sender_protocol_address, arp_header->pln);
	grub_memcpy (sender_protocol_address, target_protocol_address,
		     arp_header->pln);
	grub_memcpy (target_protocol_address, tmp, arp_header->pln);

	/* Change operation to REPLY and send packet */
	arp_header->op = grub_be_to_cpu16 (ARP_REPLY);
	send_ethernet_packet (inf, nb, target, GRUB_NET_ETHERTYPE_ARP);
      }
  }
  return GRUB_ERR_NONE;
}