Network Stack

From OSDev.wiki
Revision as of 03:47, 4 April 2009 by osdev>Pcmattman (copied from old page Networking, a little bit more relevant here... i'll probably rewrite this soon)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
This page is a stub.
You can help the wiki by accurately adding more contents to it.

TCP/IP

This article is about writing a TCP/IP stack, ie. a subsystem which uses a link layer (eg. ethernet card) to process packets of such protocols as IP,ARP,TCP,UDP.

What to focus on

The shape of the stack will vary on design decisions. These may include

  • whether or not a packet is passed between processing layers in one buffer or is copied to a new buffer when passing a layer boundary;
  • whether in and outbound frames are communicated with the link layer with the use of a dedicated thread, are fully contained in an interrupt handler or in a loop in a single-threaded environment;
  • whether frames (eg. ethernet frames) are processed immiedately or queued;
  • whether you want TCP support or just UDP or maybe only IP support; TCP is the most complex part of the stack, in the lwip implementation half of the code is specific to TCP.

As an example, a stack might

  • have the NIC's API provide three functions: setting up the NIC, poll for a frame and send a frame;
  • communicate in and outbound frames to the NIC in a one thread;
  • demultiplex inbound frames from a reception queue in another thread.

General considerations

  • When writing a stack over an ethernet, you may want to provide support for the ARP protocol and resolve functions.
  • For the sake of modularity, the station's IP would be better stored in an nic_info struct rather than as a global variable.
  • You may want to use Wireshark or another packet sniffer to inspect the communication and netcat which would dump debugging data sent from your os once you have udp or tcp support. Also, arping is useful when debugging arp code. You may code a trigger which for example reboots your system upon receipt of an ARP who-has for a chosen IP.
  • You may use a dedicated ethernet card on one computer connected with a crossedover cable to another computer (which runs your operating system) and use static IP. Other options include testing under bochs or qemu after implementing drivers for the network devices they provide.


See Also

External Links

A number of tcp/ip stacks come with a documentation of their implementations; it makes a good read.