3.9 SLIP Initialization
The SLIP interface relies on a standard asynchronous serial device initialized within the call to cpu_startup. The SLIP pseudo-device is initialized when main calls slattach indirectly through the pdev_attach pointer in SLIP'S pdevinit structure.
Each SLIP interface is described by an sl_softc structure shown in Figure 3.28.
Figure 3.28. sl_softc structure.
As with all interface structures, sl_softc starts with an ifnet structure followed by device-specific information.
In addition to the output queue found in the ifnet structure, a SLIP device maintains a separate queue, sc_fastq, for packets requesting low-delay service—typically generated by interactive applications.
sc_ttyp points to the associated terminal device. The two pointers sc_buf and sc_ep point to the first and last bytes of the buffer for an incoming SLIP packet. sc_mp points to the location for the next incoming byte and is advanced as additional bytes arrive.
The four flags defined by the SLIP driver are shown in Figure 3.29.
Figure 3.29. SLIP if_flags and sc_flags values.
SLIP defines the three interface flags reserved for the device driver in the ifnet structure and one additional flag defined in the sl_softc structure.
sc_escape is used by the IP encapsulation mechanism for serial lines (Section 5.3), while TCP header compression (Section 29.13) information is kept in sc_comp.
The BPF information for the SLIP device is pointed to by sc_bpf.
The sl_softc structure is initialized by slattach, shown in Figure 3.30.
Figure 3.30. slattach function.
Unlike leattach, which initializes only one interface at a time, the kernel calls slattach once and slattach initializes all the SLIP interfaces. Hardware devices are initialized as they are discovered by the kernel during cpu_startup, while pseudo-devices are initialized all at once when main calls the pdev_attach function for the device. if_mtu for a SLIP device is 296 bytes (SLMTU). This accommodates the standard 20-byte IP header, the standard 20-byte TCP header, and 256 bytes of user data (Section 5.3).
A SLIP network consists of two interfaces at each end of a serial communication line. slattach turns on IFF_POINTOPOINT, SC_AUTOCOMP, and IFF_MULTICAST in if_flags.
The SLIP interface limits the length of its output packet queue, if_snd, to 50 and its own internal queue, sc_fastq, to 32. Figure 3.42 shows that the length of the if_snd queue defaults to 50 (ifqmaxlen) if the driver does not select a length, so the initialization here is redundant.
The Ethernet driver doesn't set its output queue length explicitly and relies on ifinit (Figure 3.42) to set it to the system default.
if_attach expects a pointer to an ifnet structure so slattach passes the address of sc_if, an ifnet structure and the first member of the sl_softc structure.
A special program, slattach, is run (from the /etc/netstart initialization file) after the kernel has been initialized and joins the SLIP interface and an asynchronous serial device by opening the serial device and issuing ioctl commands (Section 5.3).
For each SLIP device, slattach calls bpfattach to register the interface with BPF.