Writing a good, modular network stack
Posted: Tue Jun 13, 2023 11:32 am
Hi all,
I recently made my kernel suck less by making it be able to load modules at runtime and be able to build them into the kernel. Basically, Linux's and FreeBSD's module system had a Frankenstein child.
I am now on a somewhat modular kernel binge and want to make the kernel a little more modular and make components be loadable only when needed.
Enter my problem: the network stack I'm planning to build. I've made a nice little e1000 driver and have it as a loadable module but now comes the issue of the rest of the stack. I'm finding it somewhat hard to figure out how I should structure the rest of the network stack as modules as the different layers of a network stack seem to intermingle a little more than I expected. For example, it seems as though ARP has different headers depending on what device they came over (Ethernet and the like) and I'm not exactly sure how to structure the modules such that my network stack is completely modular. Furthermore, I need to be able to get the MAC address/IP address and whatever other protocols's information of a certain card. I can't hardcode the ioctls because the protocol in question that the ioctl queries might not be loaded so I need some dynamic way of testing if the protocol is loaded (not hard) and then going to it to get the ioctl for the card but something about that seems somewhat like a kludge.
I've tried checking out a few kernel's source code but I am not really familiar with any of the ones I checked (Linux, FreeBSD, NetBSD) so I didn't really understand much of what was going on in each of their network stacks and of the 2 OSDEV projects I checked, both weren't very modular by design in their network stacks so I didn't really learn anything out of them either.
So I guess I'm asking, how would one go about designing a really good, modular network stack? Is this something that is even desirable or am I wasting my time?
To clarify, I'm not having an issue implementing the protocols in question. I'm just struggling to link them together neatly, modularly and expendably. This is more of a design question than it is a "How do I do IPv4?" question.
If someone could talk me through how a half decent network stack should look, has a decent article or 2 about how Linux or someone does it or has a few relevant files to check out in any kernel, it'd be greatly appreciated.
Thanks in advance for any advice/code/ideas/articles given
- CaydendW
P.S: Sorry if this is a stupid question/Incomprehensible mess. I'm a little bit at my wits' end with designing.
I recently made my kernel suck less by making it be able to load modules at runtime and be able to build them into the kernel. Basically, Linux's and FreeBSD's module system had a Frankenstein child.
I am now on a somewhat modular kernel binge and want to make the kernel a little more modular and make components be loadable only when needed.
Enter my problem: the network stack I'm planning to build. I've made a nice little e1000 driver and have it as a loadable module but now comes the issue of the rest of the stack. I'm finding it somewhat hard to figure out how I should structure the rest of the network stack as modules as the different layers of a network stack seem to intermingle a little more than I expected. For example, it seems as though ARP has different headers depending on what device they came over (Ethernet and the like) and I'm not exactly sure how to structure the modules such that my network stack is completely modular. Furthermore, I need to be able to get the MAC address/IP address and whatever other protocols's information of a certain card. I can't hardcode the ioctls because the protocol in question that the ioctl queries might not be loaded so I need some dynamic way of testing if the protocol is loaded (not hard) and then going to it to get the ioctl for the card but something about that seems somewhat like a kludge.
I've tried checking out a few kernel's source code but I am not really familiar with any of the ones I checked (Linux, FreeBSD, NetBSD) so I didn't really understand much of what was going on in each of their network stacks and of the 2 OSDEV projects I checked, both weren't very modular by design in their network stacks so I didn't really learn anything out of them either.
So I guess I'm asking, how would one go about designing a really good, modular network stack? Is this something that is even desirable or am I wasting my time?
To clarify, I'm not having an issue implementing the protocols in question. I'm just struggling to link them together neatly, modularly and expendably. This is more of a design question than it is a "How do I do IPv4?" question.
If someone could talk me through how a half decent network stack should look, has a decent article or 2 about how Linux or someone does it or has a few relevant files to check out in any kernel, it'd be greatly appreciated.
Thanks in advance for any advice/code/ideas/articles given
- CaydendW
P.S: Sorry if this is a stupid question/Incomprehensible mess. I'm a little bit at my wits' end with designing.