Added ARP protocol to network stack and fixed bug in grub_netbuff_alloc function.
* include/grub/net/arp.h: added arp header, arp cache entry and related constants and functions * net/arp.c: added functions arp_init_table, arp_find_entry, arp_resolve and arp_receive * net/ethernet.c (send_ethernet_packet): replaced hardcoded hardware address by parameter target_addr * net/ethernet.c (recv_ethernet_packet): added call to arp_receive when packet is of type 0x803 (ARP) and only return when packet is of type determined by parameter ethertype * net/ip.c (send_ip_packet): added call to arp_resolve to determine hardware address of destination * net/netbuff.c (grub_netbuff_alloc): fixed swapped parameters in call to grub_memalign
This commit is contained in:
parent
7c978f0690
commit
10830203a0
12 changed files with 335 additions and 56 deletions
|
@ -1,17 +1,42 @@
|
|||
#ifndef GRUB_NET_ARP_HEADER
|
||||
#define GRUB_NET_ARP_HEADER 1
|
||||
#include <grub/misc.h>
|
||||
#include <grub/net.h>
|
||||
#include <grub/net/protocol.h>
|
||||
|
||||
#include <grub/net/ethernet.h>
|
||||
struct arphdr{
|
||||
grub_int16_t hwtype; /* hardware type (must be ARPHRD_ETHER) */
|
||||
grub_int16_t protocol; /* protocol type (must be ETH_P_IP) */
|
||||
grub_int8_t hwlen; /* hardware address length (must be 6) */
|
||||
grub_int8_t protolen; /* protocol address length (must be 4) */
|
||||
grub_uint16_t opcode; /* ARP opcode */
|
||||
grub_uint8_t shwaddr[6]; /* sender's hardware address */
|
||||
grub_uint32_t sipaddr; /* sender's IP address */
|
||||
grub_uint8_t thwaddr[6]; /* target's hardware address */
|
||||
grub_uint32_t tipaddr; /* target's IP address */
|
||||
}__attribute__ ((packed));
|
||||
/* IANA ARP constant to define hardware type as ethernet */
|
||||
#define ARPHRD_ETHERNET 1
|
||||
/* IANA Ethertype */
|
||||
#define ARP_ETHERTYPE 0x806
|
||||
|
||||
/* Size for cache table */
|
||||
#define SIZE_ARP_TABLE 5
|
||||
|
||||
/* ARP header operation codes */
|
||||
#define ARP_REQUEST 1
|
||||
#define ARP_REPLY 2
|
||||
|
||||
struct arp_entry {
|
||||
grub_uint8_t avail;
|
||||
struct grub_net_network_layer_protocol *nl_protocol;
|
||||
struct grub_net_link_layer_protocol *ll_protocol;
|
||||
struct grub_net_addr nl_address;
|
||||
struct grub_net_addr ll_address;
|
||||
};
|
||||
|
||||
struct arphdr {
|
||||
grub_uint16_t hrd;
|
||||
grub_uint16_t pro;
|
||||
grub_uint8_t hln;
|
||||
grub_uint8_t pln;
|
||||
grub_uint16_t op;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
extern grub_err_t arp_receive(struct grub_net_network_layer_interface *inf __attribute__ ((unused)),
|
||||
struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb);
|
||||
|
||||
extern grub_err_t arp_resolve(struct grub_net_network_layer_interface *inf __attribute__ ((unused)),
|
||||
struct grub_net_network_link_interface *net_link_inf, struct grub_net_addr *proto_addr,
|
||||
struct grub_net_addr *hw_addr);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -37,7 +37,7 @@ struct grub_net_network_link_interface
|
|||
};
|
||||
|
||||
|
||||
extern struct grub_net_protocol_stack *grub_net_protocol_stacks;
|
||||
struct grub_net_protocol_stack *grub_net_protocol_stacks;
|
||||
static inline void
|
||||
grub_net_stack_register (struct grub_net_protocol_stack *stack)
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define GRUB_NET_IP_HEADER 1
|
||||
#include <grub/misc.h>
|
||||
|
||||
#define IP_ETHERTYPE 0x800 /* IANA Ethertype */
|
||||
|
||||
struct iphdr {
|
||||
grub_uint8_t verhdrlen;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
struct grub_net_protocol;
|
||||
struct grub_net_protocol_stack;
|
||||
struct grub_net_network_layer_interface;
|
||||
|
||||
struct grub_net_addr;
|
||||
|
||||
typedef enum grub_network_layer_protocol_id
|
||||
{
|
||||
|
@ -57,6 +57,7 @@ struct grub_net_network_layer_protocol
|
|||
struct grub_net_network_layer_protocol *next;
|
||||
char *name;
|
||||
grub_net_protocol_id_t id;
|
||||
grub_uint16_t type; /* IANA Ethertype */
|
||||
//grub_network_layer_protocol_id_t id;
|
||||
grub_err_t (*ntoa) (char *name, grub_net_network_layer_address_t *addr);
|
||||
char * (*aton) (union grub_net_network_layer_address addr);
|
||||
|
@ -76,11 +77,14 @@ struct grub_net_link_layer_protocol
|
|||
|
||||
struct grub_net_link_layer_protocol *next;
|
||||
char *name;
|
||||
grub_uint16_t type; /* ARP hardware type */
|
||||
grub_net_protocol_id_t id;
|
||||
grub_err_t (*send) (struct grub_net_network_layer_interface *inf ,
|
||||
struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb);
|
||||
struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb,
|
||||
struct grub_net_addr target_addr, grub_uint16_t ethertype);
|
||||
grub_err_t (*recv) (struct grub_net_network_layer_interface *inf ,
|
||||
struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb);
|
||||
struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb,
|
||||
grub_uint16_t ethertype);
|
||||
};
|
||||
|
||||
extern struct grub_net_network_layer_protocol *grub_net_network_layer_protocols;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue