This change adds all the kernel parts of a network stack. The network stack is partial but implements many of the important parts. Add if(4) network interface abstraction. Network interfaces are registered in a global list that can be iterated and each assigned an unique integer identifier. Add reference counted packets with a cache that recycles recent packets. Add support for lo(4) loopback and ether(4) ethernet network interfaces. The /dev/lo0 loopback device is created automatically on boot. Add arp(4) address resolution protocol driver for translation of inet(4) network layer addresses into ether(4) link layer addresses. arp(4) entries are cached and evicted from the cache when needed or when the entry has not been used for a while. The cache is limited to 256 entries for now. Add ip(4) internet protocol version 4 support. IP fragmentation and options are not implemented yet. Add tcp(4) transmission control protocol sockets for a reliable transport layer protocol that provides a reliable byte stream connection between two hosts. The implementation is incomplete and does not yet implement out of band data, options, and high performance extensions. Add udp(4) user datagram protocol sockets for a connectionless transport layer that provides best-effort delivery of datagrams. Add ping(4) sockets for a best-effort delivery of echo datagrams. Change type of sa_family_t from unsigned short to uint16_t. Add --disable-network-drivers to the kernel(7) options and expose it with a bootloader menu. tix-iso-bootconfig can set this option by default. Import CRC32 code from libz for the Ethernet checksum. This is a compatible ABI change that adds features to socket(2) (AF_INET, IPPROTO_TCP, IPPROTO_UDP, IPPROTO_PING), the ioctls for if(4), socket options, and the lo0 loopback interface. This commit is based on work by Meisaka Yukara contributed as the commit bbf7f1e8a5238a2bd1fe8eb1d2cc5c9c2421e2c4. Almost no lines of this work remains in this final commit as it has been rewritten or refactored away over the years, see the individual file headers for which files contain remnants of this work. Co-authored-by: Meisaka Yukara <Meisaka.Yukara@gmail.com>
136 lines
4.6 KiB
Groff
136 lines
4.6 KiB
Groff
.Dd June 3, 2017
|
|
.Dt IP 4
|
|
.Os
|
|
.Sh NAME
|
|
.Nm ip
|
|
.Nd internet protocol
|
|
.Sh SYNOPSIS
|
|
.In sys/socket.h
|
|
.In netinet/in.h
|
|
.Ft int
|
|
.Fn socket AF_INET type protocol
|
|
.Sh DESCRIPTION
|
|
The Internet Protocol version 4 is the original network layer protocol of the
|
|
Internet and provides best-effort delivery of datagrams between hosts.
|
|
It provides for addressing of hosts, routing over packet-switched networks,
|
|
fragmentation and reassembly of datagrams across networks with small maximum
|
|
transmission unit sizes; but it does not provide guarantee of delivery,
|
|
avoidance of delivering multiple times, ordering, flow control, nor data
|
|
integrity.
|
|
Its protocol family
|
|
.Xr inet 4
|
|
can be layered on top of the Internet Protocol to provide the enhanced service
|
|
of the transport layer.
|
|
For instance, the Transmission Control Protocol
|
|
.Xr tcp 4
|
|
can be used to provide multiplexed reliable communication across the Internet,
|
|
while the User Datagram Protocol
|
|
.Xr udp 4
|
|
can be used to provide low-overhead multiplexed unreliable communication across
|
|
the Internet.
|
|
.Pp
|
|
Datagrams contain a header followed by a datagram of the above protocol layer.
|
|
The header contains the Internet Protocol version (4), the header size, the
|
|
desired type of service, the datagram size, information for the reassembly of
|
|
fragmented datagrams, the remaining time this datagram has left to live, the
|
|
protocol number of the above protocol layer, a checksum of the header, the
|
|
address of the source host and the address of the destination host, and an
|
|
optional set of options.
|
|
.Pp
|
|
An incoming datagram on a network interface will be received and passed to the
|
|
higher level protocol if the following conditions hold:
|
|
.Pp
|
|
.Bl -bullet -compact
|
|
.It
|
|
The checksum is valid.
|
|
.It
|
|
The protocol is Internet Protocol version 4 and the packet is well-formed.
|
|
.It
|
|
The source address is neither the broadcast address
|
|
.Pq 255.255.255.255
|
|
or the subnet's broadcast address.
|
|
.It
|
|
If the network interface is not the loopback network interface
|
|
.Xr lo 4 ,
|
|
neither the source nor the destination belong to the loopback subnet
|
|
.Pq 127.0.0.0/24
|
|
.It
|
|
The destination address is either the local address (and the link layer
|
|
destination address was not a broadcast address) of the network interface, the
|
|
broadcast address of the network interface, or the broadcast address
|
|
.Pq 255.255.255.255 .
|
|
.El
|
|
.Sh ERRORS
|
|
Socket operations can fail due to these error conditions, in addition to the
|
|
error conditions of link layer and the error conditions of the invoked function.
|
|
.Bl -tag -width [EADDRNOTAVAIL]
|
|
.It Bq Er EACCES
|
|
A datagram was sent to a broadcast address, but
|
|
.Dv SO_BROADCAST
|
|
is turned off.
|
|
.It Bq Er EADDRNOTAVAIL
|
|
The socket cannot be bound to the requested address because no network interface
|
|
had that address or broadcast address.
|
|
.It Bq Er ECONNREFUSED
|
|
The destination host of a datagram was not listening on the port.
|
|
.It Bq Er EHOSTDOWN
|
|
The destination host of a datagram is not up.
|
|
.It Bq Er EHOSTUNREACH
|
|
The destination host of a datagram was unreachable.
|
|
.It Bq Er EMSGSIZE
|
|
The datagram was too large to be sent because it exceeded the maximum
|
|
transmission unit (MTU) on the path between the local and remote address.
|
|
.It Bq Er ENETDOWN
|
|
The network interface used to deliver a datagram isn't up.
|
|
.It Bq Er ENETUNREACH
|
|
The destination network of a datagram was unreachable.
|
|
.It Bq Er ENOBUFS
|
|
There was not enough memory available for network packets.
|
|
.El
|
|
.Sh SEE ALSO
|
|
.Xr arp 4 ,
|
|
.Xr icmp 4 ,
|
|
.Xr inet 4 ,
|
|
.Xr ping 4 ,
|
|
.Xr tcp 4 ,
|
|
.Xr udp 4 ,
|
|
.Xr kernel 7
|
|
.Sh STANDARDS
|
|
.Rs
|
|
.%A J. Postel (ed.)
|
|
.%D September 1981
|
|
.%R STD 5
|
|
.%R RFC 791
|
|
.%T Internet Protocol - DARPA Internet Program Protocol Specification
|
|
.%Q USC/Information Sciences Institute
|
|
.Re
|
|
.Pp
|
|
.Rs
|
|
.%A Internet Engineering Task Force
|
|
.%A R. Braden (ed.)
|
|
.%D October 1989
|
|
.%R STD 3
|
|
.%R RFC 1122
|
|
.%T Requirements for Internet Hosts -- Communication Layers
|
|
.%Q USC/Information Sciences Institute
|
|
.Re
|
|
.Sh BUGS
|
|
The implementation is incomplete and has known bugs.
|
|
.Pp
|
|
Fragmented datagrams are not yet supported and are discarded on receipt.
|
|
The fragment identification field is always set to 0, preventing the proper
|
|
reassembly of multiple datagrams that became fragmented around the same time.
|
|
.Pp
|
|
Options are not yet supported and are ignored.
|
|
.Pp
|
|
The 4-byte address space allows only a maximum of 4294967296 addresses and is
|
|
being exhausted.
|
|
The Internet Protocol version 6 replaces version 4 and provides a 16-byte
|
|
address space instead.
|
|
.Pp
|
|
There is no routing table that can be configured.
|
|
Routing happens by searching for the first appropriate network interface that
|
|
can transmit the datagram.
|
|
If multiple network interfaces have a default route, the packet is sent using
|
|
the default route of the network interface with the lowest index number.
|