core-ix wrote:
In the context of microkernel I plan to make each OSI layer separate process and a network manager to coordinate them all. My idea is: upon registering a new interface (when the network driver is loaded) user supports (as a command line parameters) what protocols should be loaded for that interface. In the network manager we have a struct of linked lists with communication points to the layers. When packet is processed we simply pass it to each (or some) layer (identified by a process).
well, you're of course free to follow that way, but i wouldn't recommend it. For speed purposes (and yes, you always come to speed issues when dealing with networks), you wouldn't like the TCP/IP packets carrying the 4GB of DVD from FutureOs distro to be slowed down due to invoking 'NIC server', then slowed down again by NIC-to-IP messaging, then again by IP-to-TCP messaging and finally by TCP-to-app data delivery. Instead, you might want to have TCP/IP a library and several 'network drivers', each one bound to a given NIC device and implementing TCP/IP stuff, then delivering stuff to the app.
Yet, that wouldn't quite be the way i would try to follow. I'd rather try to have NIC drivers at kernel level (at least, enough code at kernel level so that an incoming packet can be retrieved on main memory and a 'responsible component' gets notified). The 'responsible component' would be defined by looking at packets headers, matching the packet against 'filters' that acts as 'guardian' for the packet. For instance, when you request a TCP socket with megatokyo.com:80, the network server would first resolve the name into some IP address, initiate the connection (e.g. hooking "syn+ack" packets coming back from megatokyo) and then sets up a new filter that will make packets belonging to that TCP connection to be delivered straight to the application.
Yet, with that model, it would be up to application software to send requested duplicatas ... so you still might want to have the network server to handle TCP for you instead and only deliver payload bytes.
As you can see, there's no loss of flexibility here: all depends on how you set up those 'filters'. Another server could for instance receive all the ICMP traffic, etc.
When i said "avoiding to copy the data here and there" i meant that: copying, not 'passing'. If you manage to have your data in a neat "packet buffer" so that you can write new headers when needed, etc. you could very well just write data when they arrive at a NIC, and then just pass along the "descriptor" of the packet buffer to the different components involved (TCP/IP stack, application code, packet filters, network monitoring, routing tables ... ) without doing additional copies. When considering the NIC bandwidth and the memory bandwidth, it will be decisive, especially if you plan to build a router from your OS.