Network infrastructure.
The ARP protocol was made by Paulo Pinatti <ppinatti@br.ibm.com> * include/grub/net/arp.h: New file. * include/grub/net/device.h: Likewise. * include/grub/net/ethernet.h: Likewise. * include/grub/net/ip.h: Likewise. * include/grub/net/netbuff.h: Likewise. * include/grub/net/tftp.h: Likewise. * include/grub/net/udp.h: Likewise. * include/grub/ieee1275/ofnet.h: Likewise. * include/grub/emu/export.h: Likewise. * include/grub/net.h: Likewise. * grub-core/net/arp.c: Likewise. * grub-core/net/ethernet.c: Likewise. * grub-core/net/ip.c: Likewise. * grub-core/net/udp.c: Likewise. * grub-core/net/tftp.c: Likewise. * grub-core/net/netbuff.c: Likewise. * grub-core/net/net.c: Likewise. * grub-core/net/drivers/emu/emunet.c: Likewise. * grub-core/net/drivers/ieee1275/ofnet.c: Likewise. * grub-core/Makefile.am (KERNEL_HEADER_FILES): Add net.h, ofnet.h and export.h. * grub-core/Makefile.core.def (net): New module. (tftp): Likewise. (ofnet): Likewise. (emunet): Likewise. * grub-core/commands/ls.c (grub_ls_list_devices) [!GRUB_UTIL]: List network protocols. * grub-core/kern/device.c (grub_net_open) : New variable. (grub_device_open): Handle network device. (grub_device_close): Likewise. * grub-core/kern/file.c (grub_file_net_seek) : New variable. (grub_grubnet_fini): Likewise. (grub_file_seek): Seek in network device. * grub-core/kern/fs.c (grub_fs_probe): Handle network devices. * grub-core/kern/ieee1275/init.c (grub_machine_set_prefix): Handle network root. (grub_machine_fini): Call grub_grubnet_fini. * grub-core/kern/ieee1275/openfw.c (grub_ieee1275_parse_args): Handle network. (grub_ieee1275_get_aliasdevname): New function. * grub-core/loader/i386/multiboot_mbi.c (grub_multiboot_get_mbi_size): Add unofficial Solaris network info. (grub_multiboot_make_mbi): Likewise. * grub-core/fs/i386/pc/pxe.c: Moved from here ... * grub-core/net/i386/pc/pxe.c: ...here. Adapted for new design. * include/grub/device.h (grub_fs): Removed. * include/grub/err.h (grub_err_t): Add network-related values. * include/grub/i386/pc/pxe.h: Removed bootp parts. * include/grub/ieee1275/ieee1275.h (grub_ofnetcard_data): New struct. (grub_ieee1275_get_aliasdevname): New proto. * include/grub/net.h: Rewritten. Also-By: Paulo Pinatti <ppinatti@br.ibm.com> Also-By: Vladimir Serbinenko <phcoder@gmail.com>
This commit is contained in:
commit
90162423e9
35 changed files with 3447 additions and 399 deletions
|
@ -25,7 +25,6 @@
|
|||
|
||||
struct grub_disk;
|
||||
struct grub_net;
|
||||
struct grub_fs;
|
||||
|
||||
struct grub_device
|
||||
{
|
||||
|
|
6
include/grub/emu/export.h
Normal file
6
include/grub/emu/export.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
void EXPORT_FUNC (open64) (void);
|
||||
void EXPORT_FUNC (close) (void);
|
||||
void EXPORT_FUNC (read) (void);
|
||||
void EXPORT_FUNC (write) (void);
|
||||
void EXPORT_FUNC (ioctl) (void);
|
||||
|
|
@ -56,6 +56,10 @@ typedef enum
|
|||
GRUB_ERR_IO,
|
||||
GRUB_ERR_ACCESS_DENIED,
|
||||
GRUB_ERR_EXTRACTOR,
|
||||
GRUB_ERR_NET_BAD_ADDRESS,
|
||||
GRUB_ERR_NET_ROUTE_LOOP,
|
||||
GRUB_ERR_NET_NO_ROUTE,
|
||||
GRUB_ERR_WAIT,
|
||||
GRUB_ERR_BUG
|
||||
}
|
||||
grub_err_t;
|
||||
|
|
|
@ -152,9 +152,9 @@
|
|||
#define GRUB_PXE_BOOTP_BCAST 0x8000
|
||||
|
||||
#if 1
|
||||
#define GRUB_PXE_BOOTP_DHCPVEND 1024 /* DHCP extended vendor field size. */
|
||||
#define GRUB_PXE_BOOTP_SIZE (1024 + 236) /* DHCP extended vendor field size. */
|
||||
#else
|
||||
#define GRUB_PXE_BOOTP_DHCPVEND 312 /* DHCP standard vendor field size. */
|
||||
#define GRUB_PXE_BOOTP_SIZE (312 + 236) /* DHCP standard vendor field size. */
|
||||
#endif
|
||||
|
||||
#define GRUB_PXE_MIN_BLKSIZE 512
|
||||
|
@ -162,8 +162,6 @@
|
|||
|
||||
#define GRUB_PXE_TFTP_PORT 69
|
||||
|
||||
#define GRUB_PXE_VM_RFC1048 0x63825363L
|
||||
|
||||
#define GRUB_PXE_ERR_LEN 0xFFFFFFFF
|
||||
|
||||
#ifndef ASM_FILE
|
||||
|
@ -214,38 +212,6 @@ struct grub_pxenv_get_cached_info
|
|||
grub_uint16_t buffer_limit;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#define GRUB_PXE_MAC_ADDR_LEN 16
|
||||
|
||||
typedef grub_uint8_t grub_pxe_mac_addr_t[GRUB_PXE_MAC_ADDR_LEN];
|
||||
|
||||
struct grub_pxenv_boot_player
|
||||
{
|
||||
grub_uint8_t opcode;
|
||||
grub_uint8_t hw_type; /* hardware type. */
|
||||
grub_uint8_t hw_len; /* hardware addr len. */
|
||||
grub_uint8_t gate_hops; /* zero it. */
|
||||
grub_uint32_t ident; /* random number chosen by client. */
|
||||
grub_uint16_t seconds; /* seconds since did initial bootstrap. */
|
||||
grub_uint16_t flags;
|
||||
grub_uint32_t client_ip;
|
||||
grub_uint32_t your_ip;
|
||||
grub_uint32_t server_ip;
|
||||
grub_uint32_t gateway_ip;
|
||||
grub_pxe_mac_addr_t mac_addr;
|
||||
grub_uint8_t server_name[64];
|
||||
grub_uint8_t boot_file[128];
|
||||
union
|
||||
{
|
||||
grub_uint8_t d[GRUB_PXE_BOOTP_DHCPVEND]; /* raw array of vendor/dhcp options. */
|
||||
struct
|
||||
{
|
||||
grub_uint32_t magic; /* DHCP magic cookie. */
|
||||
grub_uint32_t flags; /* bootp flags/opcodes. */
|
||||
grub_uint8_t padding[56];
|
||||
} v;
|
||||
} vendor;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_pxenv_tftp_open
|
||||
{
|
||||
grub_uint16_t status;
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include <grub/types.h>
|
||||
#include <grub/machine/ieee1275.h>
|
||||
|
||||
/* Maps a device alias to a pathname. */
|
||||
struct grub_ieee1275_devalias
|
||||
{
|
||||
char *name;
|
||||
|
@ -65,6 +64,14 @@ struct grub_ieee1275_common_hdr
|
|||
typedef grub_uint32_t grub_ieee1275_ihandle_t;
|
||||
typedef grub_uint32_t grub_ieee1275_phandle_t;
|
||||
|
||||
struct grub_ofnetcard_data
|
||||
{
|
||||
char *path;
|
||||
grub_ieee1275_ihandle_t handle;
|
||||
grub_uint32_t mtu;
|
||||
};
|
||||
|
||||
/* Maps a device alias to a pathname. */
|
||||
extern grub_ieee1275_phandle_t EXPORT_VAR(grub_ieee1275_chosen);
|
||||
extern grub_ieee1275_ihandle_t EXPORT_VAR(grub_ieee1275_mmu);
|
||||
extern int (* EXPORT_VAR(grub_ieee1275_entry_fn)) (void *);
|
||||
|
@ -191,11 +198,10 @@ EXPORT_FUNC(grub_ieee1275_map) (grub_addr_t phys, grub_addr_t virt,
|
|||
|
||||
char *EXPORT_FUNC(grub_ieee1275_encode_devname) (const char *path);
|
||||
char *EXPORT_FUNC(grub_ieee1275_get_filename) (const char *path);
|
||||
|
||||
int EXPORT_FUNC(grub_ieee1275_devices_iterate) (int (*hook)
|
||||
(struct grub_ieee1275_devalias *
|
||||
alias));
|
||||
|
||||
char *EXPORT_FUNC(grub_ieee1275_get_aliasdevname) (const char *path);
|
||||
char *EXPORT_FUNC(grub_ieee1275_canonicalise_devname) (const char *path);
|
||||
|
||||
#endif /* ! GRUB_IEEE1275_HEADER */
|
||||
|
|
66
include/grub/ieee1275/ofnet.h
Normal file
66
include/grub/ieee1275/ofnet.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2007 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_OFNET_HEADER
|
||||
#define GRUB_OFNET_HEADER 1
|
||||
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/types.h>
|
||||
|
||||
struct grub_ofnet
|
||||
{
|
||||
/* The net name. */
|
||||
const char *name;
|
||||
|
||||
/* The OF device string. */
|
||||
char *dev;
|
||||
/*server ip*/
|
||||
char *sip;
|
||||
/*client ip*/
|
||||
char *cip;
|
||||
/*gateway*/
|
||||
char *gat;
|
||||
/**/
|
||||
int type;
|
||||
};
|
||||
|
||||
typedef struct grub_ofnet *grub_ofnet_t;
|
||||
|
||||
struct grub_bootp {
|
||||
grub_uint8_t op; /* 1 = BOOTREQUEST, 2 = BOOTREPLY */
|
||||
grub_uint8_t htype; /* Hardware address type. */
|
||||
grub_uint8_t hlen; /* Hardware address length */
|
||||
grub_uint8_t hops; /* Used by gateways in cross-gateway booting. */
|
||||
grub_uint32_t xid; /* Transaction ID */
|
||||
grub_uint16_t secs; /* Seconds elapsed. */
|
||||
grub_uint16_t unused; /* Unused. */
|
||||
grub_uint32_t ciaddr; /* Client IP address, */
|
||||
grub_uint32_t yiaddr; /* Client IP address filled by server. */
|
||||
grub_uint32_t siaddr; /* Server IP address. */
|
||||
grub_uint32_t giaddr; /* Gateway IP address. */
|
||||
unsigned char chaddr [16]; /* Client hardware address */
|
||||
char sname [64]; /* Server name */
|
||||
char file [128]; /* Boot filename */
|
||||
unsigned char vend [64];
|
||||
};
|
||||
|
||||
typedef struct grub_bootp* grub_bootp_t;
|
||||
|
||||
extern grub_bootp_t (*EXPORT_VAR (grub_getbootp)) (void);
|
||||
#endif /* ! GRUB_NET_HEADER */
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2007 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -19,54 +19,437 @@
|
|||
#ifndef GRUB_NET_HEADER
|
||||
#define GRUB_NET_HEADER 1
|
||||
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/types.h>
|
||||
#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>
|
||||
|
||||
struct grub_net;
|
||||
|
||||
struct grub_net_dev
|
||||
typedef enum grub_link_level_protocol_id
|
||||
{
|
||||
/* The device name. */
|
||||
const char *name;
|
||||
GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET
|
||||
} grub_link_level_protocol_id_t;
|
||||
|
||||
/* FIXME: Just a template. */
|
||||
int (*probe) (struct grub_net *net, const void *addr);
|
||||
void (*reset) (struct grub_net *net);
|
||||
int (*poll) (struct grub_net *net);
|
||||
void (*transmit) (struct grub_net *net, const void *destip,
|
||||
unsigned srcsock, unsigned destsock, const void *packet);
|
||||
void (*disable) (struct grub_net *net);
|
||||
typedef struct grub_net_link_level_address
|
||||
{
|
||||
grub_link_level_protocol_id_t type;
|
||||
union
|
||||
{
|
||||
grub_uint8_t mac[6];
|
||||
};
|
||||
} grub_net_link_level_address_t;
|
||||
|
||||
/* The next net device. */
|
||||
struct grub_net_dev *next;
|
||||
typedef enum grub_net_interface_flags
|
||||
{
|
||||
GRUB_NET_INTERFACE_HWADDRESS_IMMUTABLE = 1,
|
||||
GRUB_NET_INTERFACE_ADDRESS_IMMUTABLE = 2,
|
||||
GRUB_NET_INTERFACE_PERMANENT = 4
|
||||
} grub_net_interface_flags_t;
|
||||
|
||||
typedef enum grub_net_card_flags
|
||||
{
|
||||
GRUB_NET_CARD_HWADDRESS_IMMUTABLE = 1,
|
||||
GRUB_NET_CARD_NO_MANUAL_INTERFACES = 2
|
||||
} grub_net_card_flags_t;
|
||||
|
||||
struct grub_net_card;
|
||||
|
||||
struct grub_net_card_driver
|
||||
{
|
||||
struct grub_net_card_driver *next;
|
||||
char *name;
|
||||
grub_err_t (*init) (struct grub_net_card *dev);
|
||||
grub_err_t (*fini) (struct grub_net_card *dev);
|
||||
grub_err_t (*send) (const struct grub_net_card *dev,
|
||||
struct grub_net_buff *buf);
|
||||
grub_ssize_t (*recv) (const struct grub_net_card *dev,
|
||||
struct grub_net_buff *buf);
|
||||
};
|
||||
typedef struct grub_net_dev *grub_net_dev_t;
|
||||
|
||||
struct grub_fs;
|
||||
extern struct grub_net_card_driver *grub_net_card_drivers;
|
||||
|
||||
struct grub_net
|
||||
static inline void
|
||||
grub_net_card_driver_register (struct grub_net_card_driver *driver)
|
||||
{
|
||||
/* The net name. */
|
||||
const char *name;
|
||||
grub_list_push (GRUB_AS_LIST_P (&grub_net_card_drivers),
|
||||
GRUB_AS_LIST (driver));
|
||||
}
|
||||
|
||||
/* The underlying disk device. */
|
||||
grub_net_dev_t dev;
|
||||
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));
|
||||
}
|
||||
|
||||
/* The binding filesystem. */
|
||||
struct grub_fs *fs;
|
||||
#define FOR_NET_CARD_DRIVERS(var) for (var = grub_net_card_drivers; var; var = var->next)
|
||||
|
||||
/* FIXME: More data would be required, such as an IP address, a mask,
|
||||
a gateway, etc. */
|
||||
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;
|
||||
|
||||
/* Device-specific data. */
|
||||
typedef struct grub_net_packets
|
||||
{
|
||||
grub_net_packet_t *first;
|
||||
grub_net_packet_t *last;
|
||||
} grub_net_packets_t;
|
||||
|
||||
struct grub_net_card
|
||||
{
|
||||
struct grub_net_card *next;
|
||||
char *name;
|
||||
struct grub_net_card_driver *driver;
|
||||
grub_net_link_level_address_t default_address;
|
||||
grub_net_card_flags_t flags;
|
||||
union
|
||||
{
|
||||
void *data;
|
||||
int data_num;
|
||||
};
|
||||
};
|
||||
|
||||
struct grub_net_network_level_interface;
|
||||
|
||||
typedef enum grub_network_level_protocol_id
|
||||
{
|
||||
GRUB_NET_NETWORK_LEVEL_PROTOCOL_PROMISC,
|
||||
GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4
|
||||
} grub_network_level_protocol_id_t;
|
||||
|
||||
typedef struct grub_net_network_level_address
|
||||
{
|
||||
grub_network_level_protocol_id_t type;
|
||||
union
|
||||
{
|
||||
grub_uint32_t ipv4;
|
||||
};
|
||||
} grub_net_network_level_address_t;
|
||||
|
||||
typedef struct grub_net_network_level_netaddress
|
||||
{
|
||||
grub_network_level_protocol_id_t type;
|
||||
union
|
||||
{
|
||||
struct {
|
||||
grub_uint32_t base;
|
||||
int masksize;
|
||||
} ipv4;
|
||||
};
|
||||
} grub_net_network_level_netaddress_t;
|
||||
|
||||
#define FOR_PACKETS(cont,var) for (var = (cont).first; var; var = var->next)
|
||||
|
||||
static inline grub_err_t
|
||||
grub_net_put_packet (grub_net_packets_t *pkts, struct grub_net_buff *nb)
|
||||
{
|
||||
struct grub_net_packet *n;
|
||||
|
||||
n = grub_malloc (sizeof (*n));
|
||||
if (!n)
|
||||
return grub_errno;
|
||||
|
||||
n->nb = nb;
|
||||
n->next = NULL;
|
||||
n->prev = NULL;
|
||||
n->up = pkts;
|
||||
if (pkts->first)
|
||||
{
|
||||
pkts->last->next = n;
|
||||
pkts->last = n;
|
||||
n->prev = pkts->last;
|
||||
}
|
||||
else
|
||||
pkts->first = pkts->last = n;
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_net_remove_packet (grub_net_packet_t *pkt)
|
||||
{
|
||||
if (pkt->prev)
|
||||
pkt->prev->next = pkt->next;
|
||||
else
|
||||
pkt->up->first = pkt->next;
|
||||
if (pkt->next)
|
||||
pkt->next->prev = pkt->prev;
|
||||
else
|
||||
pkt->up->last = pkt->prev;
|
||||
grub_free (pkt);
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
typedef struct grub_net *grub_net_t;
|
||||
|
||||
/* FIXME: How to abstract networks? More consideration is necessary. */
|
||||
extern struct grub_net_socket *grub_net_sockets;
|
||||
|
||||
/* Note: Networks are very different from disks, because networks must
|
||||
be initialized before used, and the status is persistent. */
|
||||
static inline void
|
||||
grub_net_socket_register (grub_net_socket_t sock)
|
||||
{
|
||||
grub_list_push (GRUB_AS_LIST_P (&grub_net_sockets),
|
||||
GRUB_AS_LIST (sock));
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_net_socket_unregister (grub_net_socket_t sock)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST_P (&grub_net_sockets),
|
||||
GRUB_AS_LIST (sock));
|
||||
}
|
||||
|
||||
#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_fs_t fs;
|
||||
} *grub_net_t;
|
||||
|
||||
extern grub_net_t (*EXPORT_VAR (grub_net_open)) (const char *name);
|
||||
extern grub_err_t (*EXPORT_VAR (grub_file_net_seek)) (struct grub_file *file, grub_off_t offset);
|
||||
extern void (*EXPORT_VAR (grub_grubnet_fini)) (void);
|
||||
|
||||
struct grub_net_network_level_interface
|
||||
{
|
||||
struct grub_net_network_level_interface *next;
|
||||
struct grub_net_network_level_interface **prev;
|
||||
char *name;
|
||||
const struct grub_net_card *card;
|
||||
grub_net_network_level_address_t address;
|
||||
grub_net_link_level_address_t hwaddress;
|
||||
grub_net_interface_flags_t flags;
|
||||
struct grub_net_bootp_packet *dhcp_ack;
|
||||
grub_size_t dhcp_acklen;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct grub_net_session;
|
||||
|
||||
struct grub_net_session_level_protocol
|
||||
{
|
||||
void (*close) (struct grub_net_session *session);
|
||||
grub_ssize_t (*recv) (struct grub_net_session *session, void *buf,
|
||||
grub_size_t size);
|
||||
grub_err_t (*send) (struct grub_net_session *session, void *buf,
|
||||
grub_size_t size);
|
||||
};
|
||||
|
||||
struct grub_net_session
|
||||
{
|
||||
struct grub_net_session_level_protocol *protocol;
|
||||
void *data;
|
||||
};
|
||||
|
||||
static inline void
|
||||
grub_net_session_close (struct grub_net_session *session)
|
||||
{
|
||||
session->protocol->close (session);
|
||||
}
|
||||
|
||||
static inline grub_err_t
|
||||
grub_net_session_send (struct grub_net_session *session, void *buf,
|
||||
grub_size_t size)
|
||||
{
|
||||
return session->protocol->send (session, buf, size);
|
||||
}
|
||||
|
||||
static inline grub_ssize_t
|
||||
grub_net_session_recv (struct grub_net_session *session, void *buf,
|
||||
grub_size_t size)
|
||||
{
|
||||
return session->protocol->recv (session, buf, size);
|
||||
}
|
||||
|
||||
struct grub_net_network_level_interface *
|
||||
grub_net_add_addr (const char *name,
|
||||
const struct grub_net_card *card,
|
||||
grub_net_network_level_address_t addr,
|
||||
grub_net_link_level_address_t hwaddress,
|
||||
grub_net_interface_flags_t flags);
|
||||
|
||||
extern struct grub_net_network_level_interface *grub_net_network_level_interfaces;
|
||||
|
||||
extern grub_net_app_level_t grub_net_app_level_list;
|
||||
|
||||
#ifndef GRUB_LST_GENERATOR
|
||||
static inline void
|
||||
grub_net_app_level_register (grub_net_app_level_t proto)
|
||||
{
|
||||
grub_list_push (GRUB_AS_LIST_P (&grub_net_app_level_list),
|
||||
GRUB_AS_LIST (proto));
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
grub_net_app_level_unregister (grub_net_app_level_t proto)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST_P (&grub_net_app_level_list),
|
||||
GRUB_AS_LIST (proto));
|
||||
}
|
||||
|
||||
#define FOR_NET_APP_LEVEL(var) FOR_LIST_ELEMENTS((var), \
|
||||
(grub_net_app_level_list))
|
||||
|
||||
extern struct grub_net_card *grub_net_cards;
|
||||
|
||||
static inline void
|
||||
grub_net_card_register (struct grub_net_card *card)
|
||||
{
|
||||
grub_list_push (GRUB_AS_LIST_P (&grub_net_cards),
|
||||
GRUB_AS_LIST (card));
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_net_card_unregister (struct grub_net_card *card)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST_P (&grub_net_cards),
|
||||
GRUB_AS_LIST (card));
|
||||
}
|
||||
|
||||
#define FOR_NET_CARDS(var) for (var = grub_net_cards; var; var = var->next)
|
||||
|
||||
struct grub_net_session *
|
||||
grub_net_open_tcp (char *address, grub_uint16_t port);
|
||||
|
||||
grub_err_t
|
||||
grub_net_resolve_address (const char *name,
|
||||
grub_net_network_level_address_t *addr);
|
||||
|
||||
grub_err_t
|
||||
grub_net_resolve_net_address (const char *name,
|
||||
grub_net_network_level_netaddress_t *addr);
|
||||
|
||||
grub_err_t
|
||||
grub_net_route_address (grub_net_network_level_address_t addr,
|
||||
grub_net_network_level_address_t *gateway,
|
||||
struct grub_net_network_level_interface **interf);
|
||||
|
||||
|
||||
grub_err_t
|
||||
grub_net_add_route (const char *name,
|
||||
grub_net_network_level_netaddress_t target,
|
||||
struct grub_net_network_level_interface *inter);
|
||||
|
||||
grub_err_t
|
||||
grub_net_add_route_gw (const char *name,
|
||||
grub_net_network_level_netaddress_t target,
|
||||
grub_net_network_level_address_t gw);
|
||||
|
||||
|
||||
#define GRUB_NET_BOOTP_MAC_ADDR_LEN 16
|
||||
|
||||
typedef grub_uint8_t grub_net_bootp_mac_addr_t[GRUB_NET_BOOTP_MAC_ADDR_LEN];
|
||||
|
||||
struct grub_net_bootp_packet
|
||||
{
|
||||
grub_uint8_t opcode;
|
||||
grub_uint8_t hw_type; /* hardware type. */
|
||||
grub_uint8_t hw_len; /* hardware addr len. */
|
||||
grub_uint8_t gate_hops; /* zero it. */
|
||||
grub_uint32_t ident; /* random number chosen by client. */
|
||||
grub_uint16_t seconds; /* seconds since did initial bootstrap. */
|
||||
grub_uint16_t flags;
|
||||
grub_uint32_t client_ip;
|
||||
grub_uint32_t your_ip;
|
||||
grub_uint32_t server_ip;
|
||||
grub_uint32_t gateway_ip;
|
||||
grub_net_bootp_mac_addr_t mac_addr;
|
||||
grub_uint8_t server_name[64];
|
||||
grub_uint8_t boot_file[128];
|
||||
grub_uint8_t vendor[0];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#define GRUB_NET_BOOTP_RFC1048_MAGIC 0x63825363L
|
||||
|
||||
struct grub_net_network_level_interface *
|
||||
grub_net_configure_by_dhcp_ack (const char *name,
|
||||
const struct grub_net_card *card,
|
||||
grub_net_interface_flags_t flags,
|
||||
const struct grub_net_bootp_packet *bp,
|
||||
grub_size_t size);
|
||||
|
||||
void
|
||||
grub_net_process_dhcp (struct grub_net_buff *nb,
|
||||
const struct grub_net_card *card);
|
||||
|
||||
int
|
||||
grub_net_hwaddr_cmp (const grub_net_link_level_address_t *a,
|
||||
const grub_net_link_level_address_t *b);
|
||||
|
||||
|
||||
/*
|
||||
Currently suppoerted adresses:
|
||||
IPv4: XXX.XXX.XXX.XXX
|
||||
*/
|
||||
#define GRUB_NET_MAX_STR_ADDR_LEN sizeof ("XXX.XXX.XXX.XXX")
|
||||
|
||||
void
|
||||
grub_net_addr_to_str (const grub_net_network_level_address_t *target,
|
||||
char *buf);
|
||||
|
||||
extern struct grub_net_network_level_interface *grub_net_network_level_interfaces;
|
||||
#define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_level_interfaces; var; var = var->next)
|
||||
|
||||
grub_err_t grub_net_send_link_layer (struct grub_net_network_level_interface *inf,
|
||||
struct grub_net_buff *nb,
|
||||
grub_net_link_level_address_t *target);
|
||||
|
||||
typedef int
|
||||
(*grub_net_packet_handler_t) (struct grub_net_buff *nb,
|
||||
struct grub_net_network_level_interface *inf);
|
||||
|
||||
grub_err_t grub_net_recv_link_layer (struct grub_net_network_level_interface *inf,
|
||||
grub_net_packet_handler_t handler);
|
||||
|
||||
|
||||
grub_err_t
|
||||
grub_net_recv_ip_packets (struct grub_net_buff *nb,
|
||||
const struct grub_net_card *card,
|
||||
const grub_net_link_level_address_t *hwaddress);
|
||||
|
||||
grub_err_t
|
||||
grub_net_send_ip_packet (struct grub_net_network_level_interface *inf,
|
||||
const grub_net_network_level_address_t *target,
|
||||
struct grub_net_buff *nb);
|
||||
|
||||
#define FOR_NET_NL_PACKETS(inf, var) FOR_PACKETS(inf->nl_pending, var)
|
||||
|
||||
void
|
||||
grub_net_poll_cards (unsigned time);
|
||||
|
||||
#endif /* ! GRUB_NET_HEADER */
|
||||
|
|
36
include/grub/net/arp.h
Normal file
36
include/grub/net/arp.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#ifndef GRUB_NET_ARP_HEADER
|
||||
#define GRUB_NET_ARP_HEADER 1
|
||||
#include <grub/misc.h>
|
||||
#include <grub/net.h>
|
||||
|
||||
enum
|
||||
{
|
||||
/* IANA ARP constant to define hardware type as ethernet. */
|
||||
GRUB_NET_ARPHRD_ETHERNET = 1
|
||||
};
|
||||
|
||||
/* ARP header operation codes */
|
||||
#define ARP_REQUEST 1
|
||||
#define ARP_REPLY 2
|
||||
|
||||
struct arp_entry {
|
||||
int avail;
|
||||
grub_net_network_level_address_t nl_address;
|
||||
grub_net_link_level_address_t 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 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,
|
||||
grub_net_link_level_address_t *hw_addr);
|
||||
|
||||
#endif
|
0
include/grub/net/device.h
Normal file
0
include/grub/net/device.h
Normal file
45
include/grub/net/ethernet.h
Normal file
45
include/grub/net/ethernet.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#ifndef GRUB_NET_ETHERNET_HEADER
|
||||
#define GRUB_NET_ETHERNET_HEADER 1
|
||||
#include <grub/types.h>
|
||||
#include <grub/net.h>
|
||||
|
||||
#define LLCADDRMASK 0x7f
|
||||
|
||||
struct etherhdr
|
||||
{
|
||||
grub_uint8_t dst[6];
|
||||
grub_uint8_t src[6];
|
||||
grub_uint16_t type;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct llchdr
|
||||
{
|
||||
grub_uint8_t dsap;
|
||||
grub_uint8_t ssap;
|
||||
grub_uint8_t ctrl;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct snaphdr
|
||||
{
|
||||
grub_uint8_t oui[3];
|
||||
grub_uint16_t type;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/* IANA Ethertype */
|
||||
enum
|
||||
{
|
||||
GRUB_NET_ETHERTYPE_IP = 0x0800,
|
||||
GRUB_NET_ETHERTYPE_ARP = 0x0806
|
||||
};
|
||||
|
||||
|
||||
grub_err_t
|
||||
send_ethernet_packet (struct grub_net_network_level_interface *inf,
|
||||
struct grub_net_buff *nb,
|
||||
grub_net_link_level_address_t target_addr,
|
||||
grub_uint16_t ethertype);
|
||||
grub_err_t
|
||||
grub_net_recv_ethernet_packet (struct grub_net_buff *nb,
|
||||
const struct grub_net_card *card);
|
||||
|
||||
#endif
|
35
include/grub/net/ip.h
Normal file
35
include/grub/net/ip.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef GRUB_NET_IP_HEADER
|
||||
#define GRUB_NET_IP_HEADER 1
|
||||
#include <grub/misc.h>
|
||||
|
||||
struct iphdr {
|
||||
grub_uint8_t verhdrlen;
|
||||
grub_uint8_t service;
|
||||
grub_uint16_t len;
|
||||
grub_uint16_t ident;
|
||||
grub_uint16_t frags;
|
||||
grub_uint8_t ttl;
|
||||
grub_uint8_t protocol;
|
||||
grub_uint16_t chksum;
|
||||
grub_uint32_t src;
|
||||
grub_uint32_t dest;
|
||||
} __attribute__ ((packed)) ;
|
||||
|
||||
struct ip6hdr
|
||||
{
|
||||
grub_uint8_t version:4, priority:4;
|
||||
grub_uint8_t flow_lbl[3];
|
||||
grub_uint16_t payload_len;
|
||||
grub_uint8_t nexthdr;
|
||||
grub_uint8_t hop_limit;
|
||||
grub_uint8_t saddr[16];
|
||||
grub_uint8_t daddr[16];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#define IP_UDP 0x11 /* UDP protocol */
|
||||
#define IP_BROADCAST 0xFFFFFFFF
|
||||
|
||||
grub_uint16_t ipchksum(void *ipv, int len);
|
||||
void ipv4_ini(void);
|
||||
void ipv4_fini(void);
|
||||
#endif
|
30
include/grub/net/netbuff.h
Normal file
30
include/grub/net/netbuff.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
#ifndef GRUB_NETBUFF_HEADER
|
||||
#define GRUB_NETBUFF_HEADER
|
||||
|
||||
#include <grub/misc.h>
|
||||
|
||||
#define NETBUFF_ALIGN 2048
|
||||
#define NETBUFFMINLEN 64
|
||||
|
||||
struct grub_net_buff
|
||||
{
|
||||
/*Pointer to the start of the buffer*/
|
||||
char *head;
|
||||
/*Pointer to the data */
|
||||
char *data;
|
||||
/*Pointer to the tail */
|
||||
char *tail;
|
||||
/*Pointer to the end of the buffer*/
|
||||
char *end;
|
||||
};
|
||||
|
||||
grub_err_t grub_netbuff_put (struct grub_net_buff *net_buff ,grub_size_t len);
|
||||
grub_err_t grub_netbuff_unput (struct grub_net_buff *net_buff ,grub_size_t len);
|
||||
grub_err_t grub_netbuff_push (struct grub_net_buff *net_buff ,grub_size_t len);
|
||||
grub_err_t grub_netbuff_pull (struct grub_net_buff *net_buff ,grub_size_t len);
|
||||
grub_err_t grub_netbuff_reserve (struct grub_net_buff *net_buff ,grub_size_t len);
|
||||
grub_err_t grub_netbuff_clear (struct grub_net_buff *net_buff);
|
||||
struct grub_net_buff * grub_netbuff_alloc ( grub_size_t len );
|
||||
grub_err_t grub_netbuff_free (struct grub_net_buff *net_buff);
|
||||
|
||||
#endif
|
74
include/grub/net/tftp.h
Normal file
74
include/grub/net/tftp.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
#ifndef GRUB_NET_TFTP_HEADER
|
||||
#define GRUB_NET_TFTP_HEADER 1
|
||||
|
||||
#include <grub/misc.h>
|
||||
#include <grub/net/ethernet.h>
|
||||
#include <grub/net/udp.h>
|
||||
|
||||
/* IP port for the MTFTP server used for Intel's PXE */
|
||||
#define MTFTP_SERVER_PORT 75
|
||||
#define MTFTP_CLIENT_PORT 76
|
||||
|
||||
#define TFTP_DEFAULTSIZE_PACKET 512
|
||||
#define TFTP_MAX_PACKET 1432
|
||||
|
||||
/* IP port for the TFTP server */
|
||||
#define TFTP_SERVER_PORT 69
|
||||
|
||||
|
||||
/* We define these based on what's in arpa/tftp.h. We just like our
|
||||
* names better, cause they're clearer */
|
||||
#define TFTP_RRQ 1
|
||||
#define TFTP_WRQ 2
|
||||
#define TFTP_DATA 3
|
||||
#define TFTP_ACK 4
|
||||
#define TFTP_ERROR 5
|
||||
#define TFTP_OACK 6
|
||||
|
||||
#define TFTP_CODE_EOF 1
|
||||
#define TFTP_CODE_MORE 2
|
||||
#define TFTP_CODE_ERROR 3
|
||||
#define TFTP_CODE_BOOT 4
|
||||
#define TFTP_CODE_CFG 5
|
||||
|
||||
#define TFTP_EUNDEF 0 /* not defined */
|
||||
#define TFTP_ENOTFOUND 1 /* file not found */
|
||||
#define TFTP_EACCESS 2 /* access violation */
|
||||
#define TFTP_ENOSPACE 3 /* disk full or allocation exceeded */
|
||||
#define TFTP_EBADOP 4 /* illegal TFTP operation */
|
||||
#define TFTP_EBADID 5 /* unknown transfer ID */
|
||||
#define TFTP_EEXISTS 6 /* file already exists */
|
||||
#define TFTP_ENOUSER 7 /* no such user */
|
||||
|
||||
/* * 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 {
|
||||
grub_int8_t rrq[TFTP_DEFAULTSIZE_PACKET];
|
||||
struct {
|
||||
grub_uint16_t block;
|
||||
grub_int8_t download[TFTP_MAX_PACKET];
|
||||
} data;
|
||||
struct {
|
||||
grub_uint16_t block;
|
||||
} ack;
|
||||
struct {
|
||||
grub_uint16_t errcode;
|
||||
grub_int8_t errmsg[TFTP_DEFAULTSIZE_PACKET];
|
||||
} err;
|
||||
struct {
|
||||
grub_int8_t data[TFTP_DEFAULTSIZE_PACKET+2];
|
||||
} oack;
|
||||
} u;
|
||||
} __attribute__ ((packed)) ;
|
||||
|
||||
#endif
|
24
include/grub/net/udp.h
Normal file
24
include/grub/net/udp.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#ifndef GRUB_NET_UDP_HEADER
|
||||
#define GRUB_NET_UDP_HEADER 1
|
||||
#include <grub/types.h>
|
||||
#include <grub/net.h>
|
||||
|
||||
struct udphdr
|
||||
{
|
||||
grub_uint16_t src;
|
||||
grub_uint16_t dst;
|
||||
grub_uint16_t len;
|
||||
grub_uint16_t chksum;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
grub_err_t
|
||||
grub_net_send_udp_packet (const grub_net_socket_t socket , struct grub_net_buff *nb);
|
||||
|
||||
grub_err_t
|
||||
grub_net_recv_udp_packet (struct grub_net_buff *nb,
|
||||
struct grub_net_network_level_interface *inf);
|
||||
|
||||
|
||||
#define FOR_NET_UDP_PACKETS(inf, var) FOR_PACKETS(inf->udp_pending, var)
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue