Ethernet support [PATCH]
Hi,
Here is what I had on my harddisk regarding ethernet support. I cleaned it up and wrote a changelog entry. Johan suggested some changes and these were incorporated.
If I do not get any comments within a week, I'll just commit the patch. Please note that a directory network/ is added with some files for ethernet and support functions in it. In util/tap.c I have added an example driver. When I send in the IPv4 patch, I will enable it fully and explain how to use this properly.
After this is committed, I'll send in a IPv4 patch soon. Please comment on my code, but please wait with hacking until it is all committed. Things changing before my nose will make it even more time consuming for me to get these patching into shape ;-). I will try to reserve some time every week, when I am not working, to get this done ASAP. So I think you can expect networking support before the end of the summer or so, minus the drivers. Sorry for the delay so far...
Thanks,
Marco
2007-08-02 Marco Gerards <[email protected]>
* conf/i386-pc.rmk (grub_emu_SOURCES): Add network/memstack.c', network/ethernet.c' and `util/tap.c'.
* include/grub/ethernet.h: New file.
* include/grub/memstack.h: Likewise.
* network/ethernet.c: Likewise.
* network/memstack.c: Likewise.
* util/tap.c: Likewise.
Index: conf/i386-pc.rmk
===================================================================
RCS file: /sources/grub/grub2/conf/i386-pc.rmk,v
retrieving revision 1.85
i386-pc.rmk +2 -1
@@ -110,7 +110,8 @@ grub_emu_SOURCES = commands/boot.c comma partmap/acorn.c partmap/gpt.c \ util/console.c util/hostfs.c util/grub-emu.c util/misc.c \ util/biosdisk.c util/getroot.c \ - util/i386/pc/misc.c grub_emu_init.c + util/i386/pc/misc.c grub_emu_init.c \ + network/memstack.c network/ethernet.c util/tap.c grub_emu_LDFLAGS = $(LIBCURSES)
Index: include/grub/ethernet.h
===================================================================
RCS file: include/grub/ethernet.h
grub/ethernet.h new file +102 -0
102 lines not on this page · raw message
Index: include/grub/memstack.h
===================================================================
RCS file: include/grub/memstack.h
grub/memstack.h new file +71 -0
71 lines not on this page · raw message
Index: network/ethernet.c
===================================================================
RCS file: network/ethernet.c
ethernet.c new file +151 -0
151 lines not on this page · raw message
Index: network/memstack.c
===================================================================
RCS file: network/memstack.c
memstack.c new file +199 -0
199 lines not on this page · raw message
Index: util/tap.c
===================================================================
RCS file: util/tap.c
tap.c new file +167 -0
167 lines not on this page · raw message
Quoted 2 lines · Marco Gerards
If I do not get any comments within a week, I'll just commit the patch. >
I have a few more comments;
grub/memstack.h line 34
Quoted 12 lines
grub/memstack.h new file +12
-0+#include <grub/types.h> +#include <grub/err.h> + +enum grub_memstack_type + { +GRUB_MEMSTACK_TYPE_ETHERNET , +GRUB_MEMSTACK_TYPE_IPV4 , +GRUB_MEMSTACK_TYPE_ARP , +GRUB_MEMSTACK_TYPE_UDP , +GRUB_MEMSTACK_TYPE_DATA /* XXX */ + }; +typedef enum grub_memstack_type grub_memstack_type_t ;
I do not see why this is needed at all? The data should be opaque.
Quoted 7 lines
grub/memstack.h new file +7
-0+grub_memstack_t grub_memstack_new (void ); + +void grub_memstack_free (grub_memstack_t stack); + +void *grub_memstack_push (grub_memstack_t stack, +grub_memstack_type_t type, +grub_size_t size);
grub/memstack.h line 70
Quoted 10 lines
grub/memstack.h new file +10
-0+ +void *grub_memstack_bottom (grub_memstack_t stack, +grub_memstack_type_t type, +grub_size_t size); + +void *grub_memstack_pop (grub_memstack_t stack,grub_size_t *size); + +grub_err_t grub_memstack_popall (grub_memstack_t stack, +char *buf,grub_size_t *size); +
The network component in a operating system is often seen as a stack, because packets travel up and down through a logical stack of functionality layers. That doesn't say that the data that is passed is really a stack. BSD uses a data structure called "mbufs", which really just is a linked list of small data chunks. There are operations to append, prepend and gather data from the "mbuf".
I suggest to remove the word "stack" from our data structure, and replace it with something more generic; "buf" maybe?
And since it is really a linked list, _push should become prepend, and _bottom append, respectively.
Also, I do not think that the read operation should be destructive. Maybe a _read function is in order?
If we do this, we have a shot at adding a data structure that could be used in other places than just our small network stack.
~j
Quoted 2 lines · Marco Gerards
If I do not get any comments within a week, I'll just commit the patch. >
I have a few more comments;
grub/memstack.h line 34
Quoted 12 lines
grub/memstack.h new file +12
-0+#include <grub/types.h> +#include <grub/err.h> + +enum grub_memstack_type + { +GRUB_MEMSTACK_TYPE_ETHERNET , +GRUB_MEMSTACK_TYPE_IPV4 , +GRUB_MEMSTACK_TYPE_ARP , +GRUB_MEMSTACK_TYPE_UDP , +GRUB_MEMSTACK_TYPE_DATA /* XXX */ + }; +typedef enum grub_memstack_type grub_memstack_type_t ;
I do not see why this is needed at all? The data should be opaque.
Quoted 7 lines
grub/memstack.h new file +7
-0+grub_memstack_t grub_memstack_new (void ); + +void grub_memstack_free (grub_memstack_t stack); + +void *grub_memstack_push (grub_memstack_t stack, +grub_memstack_type_t type, +grub_size_t size);
grub/memstack.h line 70
Quoted 10 lines
grub/memstack.h new file +10
-0+ +void *grub_memstack_bottom (grub_memstack_t stack, +grub_memstack_type_t type, +grub_size_t size); + +void *grub_memstack_pop (grub_memstack_t stack,grub_size_t *size); + +grub_err_t grub_memstack_popall (grub_memstack_t stack, +char *buf,grub_size_t *size); +
The network component in a operating system is often seen as a stack, because packets travel up and down through a logical stack of functionality layers. That doesn't say that the data that is passed is really a stack. BSD uses a data structure called "mbufs", which really just is a linked list of small data chunks. There are operations to append, prepend and gather data from the "mbuf".
I suggest to remove the word "stack" from our data structure, and replace it with something more generic; "buf" maybe?
And since it is really a linked list, _push should become prepend, and _bottom append, respectively.
Also, I do not think that the read operation should be destructive. Maybe a _read function is in order?
If we do this, we have a shot at adding a data structure that could be used in other places than just our small network stack.
~j