Adapt protocols to new network struct.

This commit is contained in:
Manoel Rebelo Abranches 2011-04-01 05:42:34 -03:00
parent 09375846b9
commit 25f1579b43
15 changed files with 296 additions and 208 deletions

View file

@ -37,6 +37,7 @@ library = {
common = grub-core/commands/extcmd.c;
common = grub-core/commands/ls.c;
common = grub-core/net/net.c;
common = grub-core/net/netbuff.c;
common = grub-core/disk/dmraid_nvidia.c;
common = grub-core/disk/loopback.c;
common = grub-core/disk/lvm.c;

View file

@ -20,10 +20,15 @@
#include <grub/misc.h>
#include <grub/err.h>
#include <grub/file.h>
#include <grub/net.h>
#include <grub/mm.h>
#include <grub/fs.h>
#include <grub/device.h>
grub_ssize_t (*grub_file_net_read) (grub_file_t file, void *buf, grub_size_t len) = NULL;
grub_err_t (*grub_file_net_open) (struct grub_file *file, const char *name) = NULL;
grub_err_t (*grub_file_net_seek) (struct grub_file *file, grub_off_t offset) = NULL;
grub_file_filter_t grub_file_filters_all[GRUB_FILE_FILTER_MAX];
grub_file_filter_t grub_file_filters_enabled[GRUB_FILE_FILTER_MAX];
@ -85,6 +90,13 @@ grub_file_open (const char *name)
file->device = device;
if (device->net && grub_file_net_open)
{
if (grub_file_net_open (file, file_name))
goto fail;
return file;
}
if (device->disk && file_name[0] != '/')
/* This is a block list. */
file->fs = &grub_fs_blocklist;
@ -130,7 +142,7 @@ grub_file_open (const char *name)
grub_ssize_t
grub_file_read (grub_file_t file, void *buf, grub_size_t len)
{
grub_ssize_t res;
grub_ssize_t res = 0;
if (file->offset > file->size)
{
@ -148,8 +160,12 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len)
if (len == 0)
return 0;
res = (file->fs->read) (file, buf, len);
if (file->device->disk)
res = (file->fs->read) (file, buf, len);
else
if (grub_file_net_read && file->device->net)
res = grub_file_net_read (file, buf, len);
if (res > 0)
file->offset += res;
@ -159,6 +175,9 @@ grub_file_read (grub_file_t file, void *buf, grub_size_t len)
grub_err_t
grub_file_close (grub_file_t file)
{
if (file->device->net)
return grub_errno;
if (file->fs->close)
(file->fs->close) (file);
@ -179,8 +198,12 @@ grub_file_seek (grub_file_t file, grub_off_t offset)
"attempt to seek outside of the file");
return -1;
}
if (file->device->net && grub_file_net_seek)
grub_file_net_seek (file, offset);
old = file->offset;
file->offset = offset;
return old;
}

View file

@ -95,7 +95,7 @@ grub_fs_probe (grub_device_t device)
}
}
else if (device->net)
return device->net->protocol;
return NULL;
grub_error (GRUB_ERR_UNKNOWN_FS, "unknown filesystem");
return 0;

View file

@ -35,36 +35,40 @@ grub_net_arp_resolve(struct grub_net_network_level_interface *inf,
grub_net_link_level_address_t *hw_addr)
{
struct arp_entry *entry;
struct grub_net_buff *nb;
struct grub_net_buff nb;
struct arphdr *arp_header;
grub_net_link_level_address_t target_hw_addr;
grub_uint8_t *aux, i;
char *aux, arp_data[128];
int i;
/* Check cache table */
/* Check cache table. */
entry = arp_find_entry (proto_addr);
if (entry)
{
*hw_addr = entry->ll_address;
return GRUB_ERR_NONE;
}
/* Build a request packet */
nb = grub_netbuff_alloc (2048);
if (!nb)
return grub_errno;
grub_netbuff_reserve(nb, 2048);
grub_netbuff_push(nb, sizeof(*arp_header) + 2 * (6 + 6));
arp_header = (struct arphdr *)nb->data;
/* Build a request packet. */
nb.head = arp_data;
nb.end = arp_data + sizeof (arp_data);
grub_netbuff_clear (&nb);
grub_netbuff_reserve (&nb,128);
grub_netbuff_push (&nb, sizeof(*arp_header) + 2 * (6 + 4));
arp_header = (struct arphdr *) nb.data;
arp_header->hrd = grub_cpu_to_be16 (GRUB_NET_ARPHRD_ETHERNET);
arp_header->pro = grub_cpu_to_be16 (GRUB_NET_ETHERTYPE_IP);
/* FIXME Add support to ipv6 address. */
arp_header->hln = 6;
arp_header->pln = 4;
arp_header->op = grub_cpu_to_be16 (ARP_REQUEST);
aux = (grub_uint8_t *)arp_header + sizeof(*arp_header);
/* Sender hardware address */
grub_memcpy(aux, &inf->hwaddress.mac, 6);
aux = (char *) arp_header + sizeof (*arp_header);
/* Sender hardware address. */
grub_memcpy (aux, &inf->hwaddress.mac, 6);
aux += 6;
/* Sender protocol address */
grub_memcpy(aux, &inf->address.ipv4, 4);
grub_memcpy (aux, &inf->address.ipv4, 4);
aux += 4;
/* Target hardware address */
for(i = 0; i < 6; i++)
@ -72,49 +76,40 @@ grub_net_arp_resolve(struct grub_net_network_level_interface *inf,
aux += 6;
/* Target protocol address */
grub_memcpy(aux, &proto_addr->ipv4, 4);
grub_memset (&target_hw_addr.mac, 0xff, 6);
send_ethernet_packet (inf, nb, target_hw_addr, GRUB_NET_ETHERTYPE_ARP);
grub_netbuff_clear(nb);
grub_netbuff_reserve(nb, 2048);
grub_uint64_t start_time, current_time;
start_time = grub_get_time_ms();
do
send_ethernet_packet (inf, &nb, target_hw_addr, GRUB_NET_ETHERTYPE_ARP);
for (i = 0; i < 3; i++)
{
grub_net_recv_ethernet_packet (inf, nb, GRUB_NET_ETHERTYPE_ARP);
/* Now check cache table again */
entry = arp_find_entry(proto_addr);
entry = arp_find_entry (proto_addr);
if (entry)
{
grub_memcpy(hw_addr, &entry->ll_address, sizeof (*hw_addr));
grub_netbuff_clear(nb);
return GRUB_ERR_NONE;
}
current_time = grub_get_time_ms();
if (current_time - start_time > 3000)
break;
} while (! entry);
grub_netbuff_clear(nb);
{
grub_memcpy (hw_addr, &entry->ll_address, sizeof (*hw_addr));
return GRUB_ERR_NONE;
}
grub_net_pool_cards (200);
}
return grub_error (GRUB_ERR_TIMEOUT, "Timeout: could not resolve hardware address.");
}
grub_err_t
grub_net_arp_receive (struct grub_net_network_level_interface *inf,
struct grub_net_buff *nb)
grub_net_arp_receive (struct grub_net_buff *nb)
{
struct arphdr *arp_header = (struct arphdr *)nb->data;
struct arp_entry *entry;
grub_uint8_t *sender_hardware_address, *sender_protocol_address;
grub_uint8_t *target_hardware_address, *target_protocol_address;
grub_net_network_level_address_t hwaddress;
struct grub_net_network_level_interface *inf;
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;
grub_memcpy (&hwaddress.ipv4, sender_protocol_address, 4);
/* Check if the sender is in the cache table */
entry = arp_find_entry(&hwaddress);
/* Update sender hardware address */
@ -134,21 +129,24 @@ grub_net_arp_receive (struct grub_net_network_level_interface *inf,
new_table_entry = 0;
}
/* Am I the protocol address target? */
if (grub_memcmp(target_protocol_address, inf->hwaddress.mac, 6) == 0
&& grub_be_to_cpu16 (arp_header->op) == ARP_REQUEST)
FOR_NET_NETWORK_LEVEL_INTERFACES(inf)
{
grub_net_link_level_address_t aux;
/* Swap hardware fields */
grub_memcpy(target_hardware_address, sender_hardware_address, arp_header->hln);
grub_memcpy(sender_hardware_address, inf->hwaddress.mac, 6);
grub_memcpy(aux.mac, sender_protocol_address, 6);
grub_memcpy(sender_protocol_address, target_protocol_address, arp_header->pln);
grub_memcpy(target_protocol_address, aux.mac, arp_header->pln);
/* Change operation to REPLY and send packet */
arp_header->op = grub_be_to_cpu16 (ARP_REPLY);
grub_memcpy (aux.mac, target_hardware_address, 6);
send_ethernet_packet (inf, nb, aux, GRUB_NET_ETHERTYPE_ARP);
/* Am I the protocol address target? */
if (grub_memcmp (target_protocol_address, &inf->address.ipv4, 6) == 0
&& grub_be_to_cpu16 (arp_header->op) == ARP_REQUEST)
{
grub_net_link_level_address_t aux;
/* Swap hardware fields */
grub_memcpy (target_hardware_address, sender_hardware_address, arp_header->hln);
grub_memcpy (sender_hardware_address, inf->hwaddress.mac, 6);
grub_memcpy (aux.mac, sender_protocol_address, 6);
grub_memcpy (sender_protocol_address, target_protocol_address, arp_header->pln);
grub_memcpy (target_protocol_address, aux.mac, arp_header->pln);
/* Change operation to REPLY and send packet */
arp_header->op = grub_be_to_cpu16 (ARP_REPLY);
grub_memcpy (aux.mac, target_hardware_address, 6);
send_ethernet_packet (inf, nb, aux, GRUB_NET_ETHERTYPE_ARP);
}
}
return GRUB_ERR_NONE;
}

View file

@ -23,23 +23,20 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf,
eth->type = grub_cpu_to_be16 (ethertype);
return inf->card->driver->send (inf->card,nb);
return inf->card->driver->send (inf->card, nb);
}
grub_err_t
grub_net_recv_ethernet_packet (struct grub_net_network_level_interface *inf,
struct grub_net_buff *nb,
grub_uint16_t ethertype)
grub_net_recv_ethernet_packet (struct grub_net_buff *nb)
{
struct etherhdr *eth;
struct llchdr *llch;
struct snaphdr *snaph;
grub_uint16_t type;
inf->card->driver->recv (inf->card, nb);
eth = (struct etherhdr *) nb->data;
type = grub_be_to_cpu16 (eth->type);
grub_netbuff_pull(nb,sizeof (*eth));
grub_netbuff_pull (nb, sizeof (*eth));
if (type <= 1500)
{
@ -56,10 +53,13 @@ grub_net_recv_ethernet_packet (struct grub_net_network_level_interface *inf,
/* ARP packet */
if (type == GRUB_NET_ETHERTYPE_ARP)
grub_net_arp_receive(inf, nb);
{
grub_net_arp_receive (nb);
grub_netbuff_free (nb);
}
/* IP packet */
if(type == GRUB_NET_ETHERTYPE_IP && ethertype == GRUB_NET_ETHERTYPE_IP)
return GRUB_ERR_NONE;
if (type == GRUB_NET_ETHERTYPE_IP)
grub_net_recv_ip_packets (nb);
return GRUB_ERR_NONE;
}

View file

@ -292,7 +292,7 @@ grub_pxefs_label (grub_device_t device __attribute ((unused)),
return GRUB_ERR_NONE;
}
static struct grub_fs grub_pxefs_fs =
static struct grub_net_app_protocol grub_pxefs_fs =
{
.name = "pxe",
.dir = grub_pxefs_dir,

View file

@ -1,6 +1,7 @@
#include <grub/net/ip.h>
#include <grub/misc.h>
#include <grub/net/arp.h>
#include <grub/net/udp.h>
#include <grub/net/ethernet.h>
#include <grub/net.h>
#include <grub/net/netbuff.h>
@ -33,7 +34,7 @@ grub_net_send_ip_packet (struct grub_net_network_level_interface *inf,
grub_net_link_level_address_t ll_target_addr;
grub_err_t err;
grub_netbuff_push(nb,sizeof(*iph));
grub_netbuff_push (nb, sizeof(*iph));
iph = (struct iphdr *) nb->data;
iph->verhdrlen = ((4 << 4) | 5);
@ -49,17 +50,15 @@ grub_net_send_ip_packet (struct grub_net_network_level_interface *inf,
iph->chksum = 0 ;
iph->chksum = ipchksum((void *)nb->data, sizeof(*iph));
/* Determine link layer target address via ARP */
err = grub_net_arp_resolve(inf, target, &ll_target_addr);
/* Determine link layer target address via ARP. */
err = grub_net_arp_resolve (inf, target, &ll_target_addr);
if (err)
return err;
return send_ethernet_packet (inf, nb, ll_target_addr, GRUB_NET_ETHERTYPE_IP);
}
/*
static int
ip_filter (struct grub_net_buff *nb,
struct grub_net_network_level_interface *inf)
ip_filter (struct grub_net_buff *nb)
{
struct iphdr *iph = (struct iphdr *) nb->data;
grub_err_t err;
@ -80,15 +79,22 @@ ip_filter (struct grub_net_buff *nb,
}
return 1;
}
*/
grub_err_t
grub_net_recv_ip_packets (struct grub_net_network_level_interface *inf)
grub_net_recv_ip_packets (struct grub_net_buff *nb)
{
struct grub_net_buff *nb;
nb = grub_netbuff_alloc (2048);
if (!nb)
return grub_errno;
grub_net_recv_ethernet_packet (inf, nb, GRUB_NET_ETHERTYPE_IP);
ip_filter (nb, inf);
struct iphdr *iph = (struct iphdr *) nb->data;
grub_netbuff_pull (nb, sizeof (*iph));
switch (iph->protocol)
{
case IP_UDP:
return grub_net_recv_udp_packet (nb);
break;
default:
grub_netbuff_free (nb);
break;
}
return GRUB_ERR_NONE;
}

View file

@ -14,26 +14,23 @@ tftp_open (struct grub_file *file, const char *filename)
{
struct tftphdr *tftph;
char *rrq;
char *ptr;
int i;
int rrqlen;
int hdrlen;
struct grub_net_buff *nb;
grub_net_network_level_address_t addr;
int hdrlen;
char open_data[1500];
struct grub_net_buff nb;
tftp_data_t data = grub_malloc (sizeof *data);
grub_err_t err;
file->device->net->socket->data = (void *) data;
nb.head = open_data;
nb.end = open_data + sizeof (open_data);
grub_netbuff_clear (&nb);
err = grub_net_resolve_address (file->device->net->name
+ sizeof ("tftp,") - 1, &addr);
if (err)
return err;
grub_netbuff_reserve (&nb,1500);
grub_netbuff_push (&nb,sizeof (*tftph));
nb = grub_netbuff_alloc (2048);
if (!nb)
return grub_errno;
grub_netbuff_reserve (nb,2048);
grub_netbuff_push (nb,sizeof (*tftph));
tftph = (struct tftphdr *) nb->data;
tftph = (struct tftphdr *) nb.data;
rrq = (char *) tftph->u.rrq;
rrqlen = 0;
@ -64,89 +61,93 @@ tftp_open (struct grub_file *file, const char *filename)
rrq += grub_strlen ("0") + 1;
hdrlen = sizeof (tftph->opcode) + rrqlen;
grub_netbuff_unput (nb,nb->tail - (nb->data+hdrlen));
grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen));
err = grub_net_send_udp_packet (&addr,
nb, TFTP_CLIENT_PORT, TFTP_SERVER_PORT);
file->device->net->socket->out_port = TFTP_SERVER_PORT;
err = grub_net_send_udp_packet (file->device->net->socket, &nb);
if (err)
return err;
/* Receive OACK. */
grub_netbuff_clear (nb);
grub_netbuff_reserve (nb,2048);
do
/* Receive OACK packet. */
for ( i = 0; i < 3; i++)
{
err = grub_net_recv_udp_packet (&addr, nb,
TFTP_CLIENT_PORT, TFTP_SERVER_PORT);
if (err)
return err;
grub_net_pool_cards (100);
if (grub_errno)
return grub_errno;
if (file->device->net->socket->status != 0)
break;
/* Retry. */
//err = grub_net_send_udp_packet (file->device->net->socket, &nb);
// if (err)
// return err;
}
while (nb->tail == nb->data);
file->size = 0;
if (file->device->net->socket->status == 0)
return grub_error (GRUB_ERR_TIMEOUT,"Time out opening tftp.");
file->size = data->file_size;
for (ptr = nb->data; ptr < nb->tail; )
grub_printf ("%02x ", *ptr);
for (ptr = nb->data; ptr < nb->tail; )
{
if (grub_memcmp (ptr, "tsize\0=", sizeof ("tsize\0=") - 1) == 0)
{
file->size = grub_strtoul (ptr + sizeof ("tsize\0=") - 1, 0, 0);
grub_errno = GRUB_ERR_NONE;
}
while (ptr < nb->tail && *ptr)
ptr++;
ptr++;
}
return GRUB_ERR_NONE;
}
static grub_ssize_t
tftp_receive (struct grub_file *file, char *buf, grub_size_t len)
static grub_err_t
tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb)
{
struct tftphdr *tftph;
// char *token,*value,*temp;
char nbdata[128];
tftp_data_t data = sock->data;
grub_err_t err;
grub_net_network_level_address_t addr;
struct grub_net_buff nb;
char *ptr;
struct grub_net_buff nb_ack;
err = grub_net_resolve_address (file->device->net->name
+ sizeof ("tftp,") - 1, &addr);
if (err)
return err;
nb_ack.head = nbdata;
nb_ack.end = nbdata + sizeof (nbdata);
grub_net_recv_udp_packet (&addr, &nb,
TFTP_CLIENT_PORT, TFTP_SERVER_PORT);
tftph = (struct tftphdr *) nb.data;
tftph = (struct tftphdr *) nb->data;
switch (grub_be_to_cpu16 (tftph->opcode))
{
case TFTP_OACK:
for (ptr = nb->data; ptr < nb->tail; )
{
if (grub_memcmp (ptr, "tsize\0", sizeof ("tsize\0") - 1) == 0)
data->file_size = grub_strtoul (ptr + sizeof ("tsize\0") - 1, 0, 0);
while (ptr < nb->tail && *ptr)
ptr++;
ptr++;
}
sock->status = 1;
data->block = 0;
grub_netbuff_clear(nb);
break;
case TFTP_DATA:
grub_netbuff_pull (&nb,sizeof (tftph->opcode) + sizeof (tftph->u.data.block));
// if (tftph->u.data.block == block + 1)
//{
// block = tftph->u.data.block;
grub_memcpy (buf, nb.data, len);
//}
//else
//grub_netbuff_clear(&nb);
break;
grub_netbuff_pull (nb,sizeof (tftph->opcode) + sizeof (tftph->u.data.block));
if (grub_be_to_cpu16 (tftph->u.data.block) == data->block + 1)
{
data->block++;
if (nb->tail - nb->data < 1024)
sock->status = 2;
}
else
grub_netbuff_clear(nb);
break;
case TFTP_ERROR:
grub_netbuff_clear (&nb);
grub_netbuff_clear (nb);
return grub_error (GRUB_ERR_IO, (char *)tftph->u.err.errmsg);
break;
}
grub_netbuff_clear (&nb_ack);
grub_netbuff_reserve (&nb_ack,128);
grub_netbuff_push (&nb_ack,sizeof (tftph->opcode) + sizeof (tftph->u.ack.block));
nb.data = nb.tail = nb.end;
grub_netbuff_push (&nb,sizeof (tftph->opcode) + sizeof (tftph->u.ack.block));
tftph = (struct tftphdr *) nb.data;
tftph = (struct tftphdr *) nb_ack.data;
tftph->opcode = grub_cpu_to_be16 (TFTP_ACK);
// tftph->u.ack.block = block;
tftph->u.ack.block = data->block;
return grub_net_send_udp_packet (&addr, &nb, TFTP_CLIENT_PORT, TFTP_SERVER_PORT);
err = grub_net_send_udp_packet (sock, &nb_ack);
return err;
}
static grub_err_t
@ -155,7 +156,7 @@ tftp_close (struct grub_file *file __attribute__ ((unused)))
return 0;
}
static struct grub_fs grub_tftp_protocol =
static struct grub_net_app_protocol grub_tftp_protocol =
{
.name = "tftp",
.open = tftp_open,

View file

@ -23,19 +23,10 @@
#include <grub/err.h>
#include <grub/list.h>
#include <grub/fs.h>
#include <grub/file.h>
#include <grub/mm.h>
#include <grub/net/netbuff.h>
typedef struct grub_fs *grub_net_app_level_t;
typedef struct grub_net
{
char *name;
grub_net_app_level_t protocol;
} *grub_net_t;
extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name);
typedef enum grub_link_level_protocol_id
{
GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET
@ -75,6 +66,37 @@ struct grub_net_card_driver
grub_size_t (*recv) (struct grub_net_card *dev, struct grub_net_buff *buf);
};
extern struct grub_net_card_driver *grub_net_card_drivers;
static inline void
grub_net_card_driver_register (struct grub_net_card_driver *driver)
{
grub_list_push (GRUB_AS_LIST_P (&grub_net_card_drivers),
GRUB_AS_LIST (driver));
}
static inline void
grub_net_card_driver_unregister (struct grub_net_card_driver *driver)
{
grub_list_remove (GRUB_AS_LIST_P (&grub_net_card_drivers),
GRUB_AS_LIST (driver));
}
#define FOR_NET_CARD_DRIVERS(var) for (var = grub_net_card_drivers; var; var = var->next)
typedef struct grub_net_packet
{
struct grub_net_packet *next;
struct grub_net_packet *prev;
struct grub_net_packets *up;
struct grub_net_buff *nb;
} grub_net_packet_t;
typedef struct grub_net_packets
{
grub_net_packet_t *first;
grub_net_packet_t *last;
} grub_net_packets_t;
struct grub_net_card
{
@ -118,20 +140,6 @@ typedef struct grub_net_network_level_netaddress
};
} grub_net_network_level_netaddress_t;
typedef struct grub_net_packet
{
struct grub_net_packet *next;
struct grub_net_packet *prev;
struct grub_net_packets *up;
struct grub_net_buff *nb;
} grub_net_packet_t;
typedef struct grub_net_packets
{
struct grub_net_packet *first;
struct grub_net_packet *last;
} grub_net_packets_t;
#define FOR_PACKETS(cont,var) for (var = (cont).first; var; var = var->next)
static inline grub_err_t
@ -172,6 +180,66 @@ grub_net_remove_packet (grub_net_packet_t *pkt)
pkt->up->last = pkt->prev;
}
typedef struct grub_net_app_protocol *grub_net_app_level_t;
typedef struct grub_net_socket *grub_net_socket_t;
struct grub_net_app_protocol
{
struct grub_net_app_protocol *next;
char *name;
grub_err_t (*dir) (grub_device_t device, const char *path,
int (*hook) (const char *filename,
const struct grub_dirhook_info *info));
grub_err_t (*open) (struct grub_file *file, const char *filename);
grub_err_t (*read) (grub_net_socket_t sock, struct grub_net_buff *nb);
grub_err_t (*close) (struct grub_file *file);
grub_err_t (*label) (grub_device_t device, char **label);
};
struct grub_net_socket
{
struct grub_net_socket *next;
int status;
int in_port;
int out_port;
grub_net_app_level_t app;
grub_net_network_level_address_t out_nla;
struct grub_net_network_level_interface *inf;
grub_net_packets_t *packs;
void *data;
};
extern struct grub_net_socket *grub_net_sockets;
static inline void
grub_net_socket_register (grub_net_socket_t socket)
{
grub_list_push (GRUB_AS_LIST_P (&grub_net_sockets),
GRUB_AS_LIST (socket));
}
static inline void
grub_net_socket_unregister (grub_net_socket_t socket)
{
grub_list_remove (GRUB_AS_LIST_P (&grub_net_sockets),
GRUB_AS_LIST (socket));
}
#define FOR_NET_SOCKETS(var) for (var = grub_net_sockets; var; var = var->next)
typedef struct grub_net
{
char *name;
grub_net_app_level_t protocol;
grub_net_socket_t socket;
} *grub_net_t;
extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name);
extern grub_ssize_t (*EXPORT_VAR (grub_file_net_read)) (grub_file_t file, void *buf, grub_size_t len);
extern grub_err_t (*EXPORT_VAR (grub_file_net_open)) (struct grub_file *file, const char *name);
extern grub_err_t (*EXPORT_VAR (grub_file_net_seek)) (struct grub_file *file, grub_off_t offset);
struct grub_net_network_level_interface
{
struct grub_net_network_level_interface *next;
@ -182,7 +250,6 @@ struct grub_net_network_level_interface
grub_net_interface_flags_t flags;
struct grub_net_bootp_ack *dhcp_ack;
grub_size_t dhcp_acklen;
grub_net_packets_t nl_pending;
void *data;
};
@ -354,7 +421,7 @@ grub_err_t grub_net_recv_link_layer (struct grub_net_network_level_interface *in
grub_net_packet_handler_t handler);
grub_err_t
grub_net_recv_ip_packets (struct grub_net_network_level_interface *inf);
grub_net_recv_ip_packets (struct grub_net_buff *nb);
grub_err_t
grub_net_send_ip_packet (struct grub_net_network_level_interface *inf,
@ -363,4 +430,10 @@ grub_net_send_ip_packet (struct grub_net_network_level_interface *inf,
#define FOR_NET_NL_PACKETS(inf, var) FOR_PACKETS(inf->nl_pending, var)
void
grub_net_pool_cards (unsigned time);
void
hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str);
#endif /* ! GRUB_NET_HEADER */

View file

@ -27,8 +27,7 @@ struct arphdr {
grub_uint16_t op;
} __attribute__ ((packed));
extern grub_err_t grub_net_arp_receive(struct grub_net_network_level_interface *inf,
struct grub_net_buff *nb);
extern grub_err_t grub_net_arp_receive(struct grub_net_buff *nb);
extern grub_err_t grub_net_arp_resolve(struct grub_net_network_level_interface *inf,
const grub_net_network_level_address_t *addr,

View file

@ -1,7 +0,0 @@
struct grub_net_card
{
struct grub_net_card *next;
char *name;
struct grub_net_card_driver *driver;
void *data;
};

View file

@ -52,8 +52,6 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf,
grub_net_link_level_address_t target_addr,
grub_uint16_t ethertype);
grub_err_t
grub_net_recv_ethernet_packet (struct grub_net_network_level_interface *inf,
struct grub_net_buff *nb,
grub_uint16_t ethertype);
grub_net_recv_ethernet_packet (struct grub_net_buff *nb);
#endif

View file

@ -26,7 +26,7 @@ struct ip6hdr
grub_uint8_t daddr[16];
} __attribute__ ((packed));
#define IP_UDP 17 /* UDP protocol */
#define IP_UDP 0x11 /* UDP protocol */
#define IP_BROADCAST 0xFFFFFFFF
grub_uint16_t ipchksum(void *ipv, int len);

View file

@ -14,7 +14,6 @@
/* IP port for the TFTP server */
#define TFTP_SERVER_PORT 69
#define TFTP_CLIENT_PORT 26300
/* We define these based on what's in arpa/tftp.h. We just like our
@ -40,10 +39,17 @@
#define TFTP_EBADID 5 /* unknown transfer ID */
#define TFTP_EEXISTS 6 /* file already exists */
#define TFTP_ENOUSER 7 /* no such user */
#define TFTP_DEFAULT_FILENAME "kernel"
/* * own here because this is cleaner, and maps to the same data layout.
* */
typedef struct tftp_data
{
int file_size;
int block;
} *tftp_data_t;
struct tftphdr {
grub_uint16_t opcode;
union {
@ -65,6 +71,4 @@ struct tftphdr {
} u;
} __attribute__ ((packed)) ;
void tftp_ini(void);
void tftp_fini(void);
#endif

View file

@ -12,20 +12,12 @@ struct udphdr
} __attribute__ ((packed));
grub_err_t
grub_net_send_udp_packet (const grub_net_network_level_address_t *target,
struct grub_net_buff *nb, grub_uint16_t srcport,
grub_uint16_t destport);
grub_net_send_udp_packet (const grub_net_socket_t socket , struct grub_net_buff *nb);
grub_err_t
grub_net_recv_udp_packets (struct grub_net_network_level_interface *inf);
grub_net_recv_udp_packet (struct grub_net_buff *nb);
grub_err_t
grub_net_recv_udp_packet (const grub_net_network_level_address_t *target,
struct grub_net_buff *buf,
grub_uint16_t srcport, grub_uint16_t destport);
#define FOR_NET_UDP_PACKETS(inf, var) FOR_PACKETS(inf->udp_pending, var)
#endif