Merge grub_net into net. Compiles but is broken right now.

This commit is contained in:
Manoel R. Abranches 2010-09-16 21:57:31 +02:00 committed by Vladimir 'phcoder' Serbinenko
commit 7bb47706c9
30 changed files with 1544 additions and 24 deletions

View file

@ -42,7 +42,8 @@ enum grub_disk_dev_id
GRUB_DISK_DEVICE_PXE_ID,
GRUB_DISK_DEVICE_SCSI_ID,
GRUB_DISK_DEVICE_FILE_ID,
GRUB_DISK_DEVICE_LUKS_ID
GRUB_DISK_DEVICE_LUKS_ID,
GRUB_DISK_DEVICE_OFNET_ID
};
struct grub_disk;
@ -118,6 +119,23 @@ struct grub_disk
};
typedef struct grub_disk *grub_disk_t;
/* Net Disk */
enum grub_netdisk_protocol
{
GRUB_NETDISK_PROTOCOL_TFTP
};
typedef enum grub_netdisk_protocol grub_netdisk_protocol_t;
struct grub_netdisk_data
{
grub_netdisk_protocol_t protocol;
grub_uint32_t server_ip;
grub_uint32_t port;
char *username;
char *password;
};
typedef struct grub_netdisk_data *grub_netdisk_data_t;
#ifdef GRUB_UTIL
struct grub_disk_memberlist
{

View file

@ -57,7 +57,8 @@ typedef enum
GRUB_ERR_ACCESS_DENIED,
GRUB_ERR_NET_BAD_ADDRESS,
GRUB_ERR_NET_ROUTE_LOOP,
GRUB_ERR_NET_NO_ROUTE
GRUB_ERR_NET_NO_ROUTE,
GRUB_ERR_WAIT
}
grub_err_t;

View file

@ -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,13 @@ 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;
};
/* 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 *);
@ -182,9 +188,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);
void EXPORT_FUNC(grub_ofnet_findcards) (void);
void EXPORT_FUNC(grub_ofnet_probecards) (void);
#endif /* ! GRUB_IEEE1275_HEADER */

View file

@ -0,0 +1,73 @@
/*
* 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>
void grub_ofnet_init(void);
void grub_ofnet_fini(void);
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 */
// grub_uint32_t filesize ; /*File size (testing)*/
unsigned char vend [64];
};
typedef struct grub_bootp* grub_bootp_t;
char * grub_get_filestr(const char * );
char * grub_ip2str (grub_uint32_t ip);
void grub_get_netinfo (grub_ofnet_t netinfo,grub_bootp_t packet);
grub_bootp_t grub_getbootp (void);
#endif /* ! GRUB_NET_HEADER */

View file

@ -23,6 +23,9 @@
#include <grub/err.h>
#include <grub/list.h>
#include <grub/fs.h>
#include <grub/net/netbuff.h>
#include <grub/net/type_net.h>
#include <grub/net/protocol.h>
typedef struct grub_fs *grub_net_app_level_t;
@ -65,12 +68,15 @@ struct grub_net_card;
struct grub_net_card_driver
{
grub_err_t (*send) (struct grub_net_card *dev, void *buf,
grub_size_t buflen);
grub_size_t (*recv) (struct grub_net_card *dev, void *buf,
grub_size_t buflen);
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) (struct grub_net_card *dev, struct grub_net_buff *buf);
grub_size_t (*recv) (struct grub_net_card *dev, struct grub_net_buff *buf);
};
struct grub_net_card
{
struct grub_net_card *next;
@ -109,7 +115,59 @@ typedef struct grub_net_network_level_netaddress
};
} grub_net_network_level_netaddress_t;
struct grub_net_network_level_interface;
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
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;
}
struct grub_net_network_level_interface
{
@ -121,6 +179,7 @@ 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;
};
@ -280,5 +339,25 @@ grub_net_addr_to_str (const grub_net_network_level_address_t *target,
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_network_level_interface *inf);
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)
#endif /* ! GRUB_NET_HEADER */

40
include/grub/net/arp.h Normal file
View file

@ -0,0 +1,40 @@
#ifndef GRUB_NET_ARP_HEADER
#define GRUB_NET_ARP_HEADER 1
#include <grub/misc.h>
#include <grub/net.h>
#include <grub/net/protocol.h>
/* 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 {
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_network_level_interface *inf,
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

View file

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

View file

@ -0,0 +1,5 @@
#ifndef GRUB_DISKNET_HEADER
#define GRUB_DISKNET_HEADER 1
void grub_disknet_init(void);
void grub_disknet_fini(void);
#endif /* ! GRUB_NET_HEADER */

View file

@ -0,0 +1,51 @@
#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));
#define PCP(x) x & 0xe000
#define CFI(x) x & 0x1000
#define VID(x) x & 0x0fff
#define PRINT_ETH_ADDR(name,addr) grub_printf("%s %x:%x:%x:%x:%x:%x\n",\
name,\
addr[0],\
addr[1],\
addr[2],\
addr[3],\
addr[4],\
addr[5]\
)
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));
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_network_level_interface *inf,
struct grub_net_buff *nb,
grub_uint16_t ethertype);
#endif

View file

@ -0,0 +1,10 @@
#ifndef GRUB_IEEE1275_INTERFACE_HEADER
#define GRUB_IEEE1275_INTERFACE_HEADER 1
#include <grub/misc.h>
#include <grub/ieee1275/ieee1275.h>
#include <grub/ieee1275/ofnet.h>
#include <grub/net/netbuff.h>
grub_bootp_t bootp_pckt;
#endif

View file

@ -0,0 +1,70 @@
#ifndef GRUB_INTERFACE_HEADER
#define GRUB_INTERFACE_HEADER
//#include <grub/net.h>
#include <grub/net/type_net.h>
#include <grub/list.h>
#include <grub/misc.h>
struct grub_net_protocol_stack
{
struct grub_net_protocol_stack *next;
char *name;
grub_net_protocol_id_t id;
void *interface;
};
struct grub_net_application_transport_interface
{
struct grub_net_transport_network_interface *inner_layer;
void *data;
struct grub_net_application_layer_protocol *app_prot;
struct grub_net_transport_layer_protocol *trans_prot;
};
struct grub_net_transport_network_interface
{
struct grub_net_network_link_interface *inner_layer;
void *data;
struct grub_net_transport_layer_protocol *trans_prot;
struct grub_net_network_layer_protocol *net_prot;
};
struct grub_net_network_link_interface
{
void *data;
struct grub_net_network_layer_protocol *net_prot;
struct grub_net_link_layer_protocol *link_prot;
};
struct grub_net_protocol_stack *grub_net_protocol_stacks;
static inline void
grub_net_stack_register (struct grub_net_protocol_stack *stack)
{
grub_list_push (GRUB_AS_LIST_P (&grub_net_protocol_stacks),
GRUB_AS_LIST (stack));
}
/*
void grub_net_stack_unregister (struct grub_net_protocol_stack *stack)
{
grub_list_remove (GRUB_AS_LIST_P (&grub_net_protocol_stacks),
GRUB_AS_LIST (stack));
}*/
struct grub_net_protocol_stack *grub_net_protocol_stack_get (char *name);
/*
static inline void
grub_net_interface_application_transport_register (struct grub_net_application_transport_interface);
static inline void
grub_net_interface_application_transport_unregister (struct grub_net_application_transport_interface);
static inline void
grub_net_interface_transport_network_register (struct grub_net_transport_network_interface);
static inline void
grub_net_interface_transport_network_unregister (struct grub_net_transport_network_interface);
static inline void
grub_net_interface_network_link_register (struct grub_net_network_link_interface);
static inline void
grub_net_interface_network_link_unregister (struct grub_net_network_link_interface);*/
#endif

37
include/grub/net/ip.h Normal file
View file

@ -0,0 +1,37 @@
#ifndef GRUB_NET_IP_HEADER
#define GRUB_NET_IP_HEADER 1
#include <grub/misc.h>
#define IP_ETHERTYPE 0x800 /* IANA Ethertype */
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 17 /* UDP protocol */
#define IP_BROADCAST 0xFFFFFFFF
grub_uint16_t ipchksum(void *ipv, int len);
void ipv4_ini(void);
void ipv4_fini(void);
#endif

9
include/grub/net/mem.h Normal file
View file

@ -0,0 +1,9 @@
#ifndef GRUB_NETMM_H
#define GRUB_NETMM_H 1
#include <grub/types.h>
#include <grub/symbol.h>
void *EXPORT_FUNC(grub_net_malloc) (grub_size_t size);
#endif /* ! GRUB_MM_H */

View 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);
grub_err_t grub_netbuff_clear (struct grub_net_buff *net_buff);
#endif

View file

@ -0,0 +1,9 @@
#ifndef GRUB_PROTOCOL_HEADER
#define GRUB_PROTOCOL_HEADER
#include <grub/err.h>
#include <grub/mm.h>
#include <grub/net/interface.h>
#include <grub/net/netbuff.h>
#include <grub/net/type_net.h>
#endif

70
include/grub/net/tftp.h Normal file
View file

@ -0,0 +1,70 @@
#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
#define TFTP_CLIENT_PORT 26300
/* 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 */
#define TFTP_DEFAULT_FILENAME "kernel"
/* * own here because this is cleaner, and maps to the same data layout.
* */
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)) ;
void tftp_ini(void);
void tftp_fini(void);
#endif

View file

@ -0,0 +1,33 @@
#ifndef GRUB_TYPES_NET_HEADER
#define GRUB_TYPES_NET_HEADER 1
#include <grub/misc.h>
#define UDP_PCKT 0x11
#define IP_PCKT 0x0800
#define TIMEOUT_TIME_MS 3*1000
typedef enum
{
GRUB_NET_TFTP_ID,
GRUB_NET_UDP_ID,
GRUB_NET_IPV4_ID,
GRUB_NET_IPV6_ID,
GRUB_NET_ETHERNET_ID,
GRUB_NET_ARP_ID,
GRUB_NET_DHCP_ID
}grub_net_protocol_id_t;
typedef union grub_net_network_layer_netaddress
{
grub_uint32_t ipv4;
} grub_net_network_layer_address_t;
typedef union grub_net_network_layer_address
{
struct {
grub_uint32_t base;
int masksize;
} ipv4;
} grub_net_network_layer_netaddress_t;
#endif

31
include/grub/net/udp.h Normal file
View file

@ -0,0 +1,31 @@
#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_network_level_address_t *target,
struct grub_net_buff *nb, grub_uint16_t srcport,
grub_uint16_t destport);
grub_err_t
grub_net_recv_udp_packets (struct grub_net_network_level_interface *inf);
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