Hook network protocols
This commit is contained in:
parent
975cffff74
commit
9a9852df79
6 changed files with 87 additions and 16 deletions
|
@ -74,6 +74,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h
|
|||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/boot.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h
|
||||
|
||||
if COND_i386_pc
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h
|
||||
|
|
|
@ -269,6 +269,37 @@ grub_cmd_addroute (struct grub_command *cmd __attribute__ ((unused)),
|
|||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_net_app_level_t grub_net_app_level_list;
|
||||
|
||||
static grub_net_t
|
||||
grub_net_open_real (const char *name)
|
||||
{
|
||||
const char *comma = grub_strchr (name, ',');
|
||||
grub_net_app_level_t proto;
|
||||
|
||||
if (!comma)
|
||||
comma = name + grub_strlen (name);
|
||||
FOR_NET_APP_LEVEL (proto)
|
||||
{
|
||||
if (comma - name == (grub_ssize_t) grub_strlen (proto->name)
|
||||
&& grub_memcmp (proto->name, name, comma - name) == 0)
|
||||
{
|
||||
grub_net_t ret = grub_malloc (sizeof (*ret));
|
||||
if (!ret)
|
||||
return NULL;
|
||||
ret->protocol = proto;
|
||||
ret->name = grub_strdup (name);
|
||||
if (!ret->name)
|
||||
{
|
||||
grub_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static grub_command_t cmd_addaddr, cmd_deladdr, cmd_addroute, cmd_delroute;
|
||||
|
||||
GRUB_MOD_INIT(net)
|
||||
|
@ -285,6 +316,7 @@ GRUB_MOD_INIT(net)
|
|||
cmd_delroute = grub_register_command ("net_del_route", grub_cmd_delroute,
|
||||
"SHORTNAME",
|
||||
N_("Delete a network route."));
|
||||
grub_net_open = grub_net_open_real;
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(net)
|
||||
|
@ -293,4 +325,5 @@ GRUB_MOD_FINI(net)
|
|||
grub_unregister_command (cmd_deladdr);
|
||||
grub_unregister_command (cmd_addroute);
|
||||
grub_unregister_command (cmd_delroute);
|
||||
grub_net_open = NULL;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <grub/env.h>
|
||||
#include <grub/partition.h>
|
||||
|
||||
grub_net_t (*grub_net_open) (const char *name) = NULL;
|
||||
|
||||
grub_device_t
|
||||
grub_device_open (const char *name)
|
||||
{
|
||||
|
@ -46,14 +48,15 @@ grub_device_open (const char *name)
|
|||
if (! dev)
|
||||
goto fail;
|
||||
|
||||
dev->net = NULL;
|
||||
/* Try to open a disk. */
|
||||
disk = grub_disk_open (name);
|
||||
if (! disk)
|
||||
goto fail;
|
||||
|
||||
dev->disk = disk;
|
||||
dev->net = 0; /* FIXME */
|
||||
dev->disk = grub_disk_open (name);
|
||||
if (dev->disk)
|
||||
return dev;
|
||||
if (grub_net_open)
|
||||
dev->net = grub_net_open (name);
|
||||
|
||||
if (dev->net)
|
||||
return dev;
|
||||
|
||||
fail:
|
||||
|
@ -71,6 +74,12 @@ grub_device_close (grub_device_t device)
|
|||
if (device->disk)
|
||||
grub_disk_close (device->disk);
|
||||
|
||||
if (device->net)
|
||||
{
|
||||
grub_free (device->net->name);
|
||||
grub_free (device->net);
|
||||
}
|
||||
|
||||
grub_free (device);
|
||||
|
||||
return grub_errno;
|
||||
|
|
|
@ -95,7 +95,7 @@ grub_fs_probe (grub_device_t device)
|
|||
}
|
||||
}
|
||||
else if (device->net)
|
||||
return device->net->fs;
|
||||
return device->net->protocol;
|
||||
|
||||
grub_error (GRUB_ERR_UNKNOWN_FS, "unknown filesystem");
|
||||
return 0;
|
||||
|
|
|
@ -24,12 +24,7 @@
|
|||
#include <grub/err.h>
|
||||
|
||||
struct grub_disk;
|
||||
struct grub_fs;
|
||||
struct grub_net
|
||||
{
|
||||
char *name;
|
||||
struct grub_fs *fs;
|
||||
};
|
||||
struct grub_net;
|
||||
|
||||
struct grub_device
|
||||
{
|
||||
|
|
|
@ -22,6 +22,17 @@
|
|||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/list.h>
|
||||
#include <grub/fs.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);
|
||||
|
||||
struct grub_net_card;
|
||||
|
||||
|
@ -46,7 +57,7 @@ struct grub_net_network_level_interface;
|
|||
typedef union grub_net_network_level_address
|
||||
{
|
||||
grub_uint32_t ipv4;
|
||||
} grub_net_network_level_netaddress_t;
|
||||
} grub_net_network_level_address_t;
|
||||
|
||||
typedef union grub_net_network_level_netaddress
|
||||
{
|
||||
|
@ -54,7 +65,7 @@ typedef union grub_net_network_level_netaddress
|
|||
grub_uint32_t base;
|
||||
int masksize;
|
||||
} ipv4;
|
||||
} grub_net_network_level_address_t;
|
||||
} grub_net_network_level_netaddress_t;
|
||||
|
||||
typedef enum grub_network_level_protocol_id
|
||||
{
|
||||
|
@ -163,6 +174,28 @@ grub_net_network_level_interface_unregister (struct grub_net_network_level_inter
|
|||
|
||||
#define FOR_NET_NETWORK_LEVEL_INTERFACES(var) for (var = grub_net_network_level_interfaces; var; var = var->next)
|
||||
|
||||
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_route *grub_net_routes;
|
||||
|
||||
static inline void
|
||||
|
|
Loading…
Reference in a new issue