Skip to content

AROSTCP

Nick Andrews edited this page Jul 29, 2026 · 12 revisions

AROSTCP -- Core Network Stack

This document covers the AmiTCP-derived core network stack: protocols, kernel infrastructure, BSD socket API (slots 1-50), IPv6 support, configuration services, and command-line utilities.

Related pages: Roadshow extensions · Miami compatibility library

Last updated against codebase: July 2026.


Core Protocol Support

Protocol Status Key Files
IPv4 Complete netinet/ip_input.c, ip_output.c, in.c, in_pcb.c
IPv6 Complete netinet6/ip6_input.c, ip6_output.c, in6.c, in6_pcb.c
TCP (v4+v6) Complete netinet/tcp_input.c (2166), tcp_output.c (769), tcp_usrreq.c
UDP (v4+v6) Complete netinet/udp_usrreq.c, netinet6/udp6_usrreq.c
ICMP Complete netinet/ip_icmp.c
ICMPv6 Complete (incl. PMTUD, RFC 8201) netinet6/icmp6.c (676 lines)
IGMP IGMPv2 host (RFC 2236) netinet/igmp.c (398 lines)
MLD MLDv1 (RFC 2710) + MLDv2 (RFC 3810), host netinet6/mld6.c (551 lines)
Raw IP (v4+v6) Complete netinet/raw_ip.c
ARP Complete net/sana2arp.c

TCP Congestion Control & Modern Extensions

TCP uses a pluggable congestion-control framework (netinet/tcp_cc.h): a struct tcp_cc_algo vtable (on_ack/on_loss/on_rto/on_ecn) selected per connection via t_cc_algo, with two built-in algorithms. Half-open connections are held in a SYN cache with stateless SYN-cookie overflow (tcp_syncache.c).

Feature RFC Default Details
CUBIC RFC 8312 on (default algo) tcp_cc_cubic.c; tcp_cc_default = TCP_CC_CUBIC
NewReno RFC 5681/6582 on (fallback) tcp_cc_newreno.c; tcp_do_newreno = 1
SACK negotiation RFC 2018 on TF_SACK_PERMIT, block parse/generate, tcp_do_sack = 1
SYN cache + cookies RFC 4987 on tcp_syncache.c; tcp_syncookies = 1
Initial window (IW10) RFC 6928 on MIN(10·mss, MAX(2·mss, 14600))
ECN RFC 3168 off negotiated (TF_ECN_PERMIT); tcp_do_ecn = 0
PRR RFC 6937 off tcp_do_prr = 0
SACK-based loss recovery RFC 6675 off per-connection scoreboard; gated by tcp_do_prr

Defaults (tcp_subr.c): CUBIC congestion control, SACK negotiation, NewReno recovery and SYN cookies are enabled. ECN, PRR and SACK-based loss recovery are implemented but off by default pending end-to-end validation — with tcp_do_ecn/tcp_do_prr at 0 the classic NewReno/CUBIC fast recovery path runs unchanged.

Key implementation points:

  • SACK negotiation occurs during SYN exchange; SACK blocks are generated from the reassembly queue.
  • The out-of-order reassembly queue is length-bounded to resist memory-exhaustion from a gapped stream.
  • When enabled, ECN marks ECT(0) only on freshly transmitted data and reacts once per window; PRR paces the fast-recovery send rate toward snd_ssthresh; SACK recovery drives pipe estimation and next-segment selection from the scoreboard.

Network Interface Layer

Feature Status Key Files
SANA-II device integration Complete net/if_sana.c, sana2config.c (see note below)
Loopback interface Complete net/if_loop.c
Interface management Complete net/if.c
Routing table (radix tree) Complete net/route.c (611 lines), net/radix.c (710 lines)
PF_ROUTE routing socket Complete net/rtsock.c (886 lines)
BPF (packet capture/filter) Complete net/bpf.c (493 lines), net/bpf_filter.c (401 lines)
Packet filter framework Complete net/pfil.c (147 lines, conditional on ENABLE_PACKET_FILTER)
IP Filter / firewall Complete net/ipfilter.c (566 lines, rule engine, NAT support)

SANA-II Request Allocation: By default, sana2config.c allocates 16 I/O requests per interface (the original AmiTCP value). On non-m68k architectures, SANA2_LARGEREQALLOCS is automatically defined, enabling larger request pools for higher throughput.


BSD Socket API (Slots 1-50)

The core bsdsocket.library function table provides 50 slots for standard AmiTCP BSD socket operations. All are fully implemented.

Slot Function Slot Function
1 socket 26 ReleaseCopyOfSocket
2 bind 27 Errno
3 listen 28 SetErrnoPtr
4 accept 29 Inet_NtoA
5 connect 30 inet_addr
6 sendto 31 Inet_LnaOf
7 send 32 Inet_NetOf
8 recvfrom 33 Inet_MakeAddr
9 recv 34 inet_network
10 shutdown 35 gethostbyname
11 setsockopt 36 gethostbyaddr
12 getsockopt 37 getnetbyname
13 getsockname 38 getnetbyaddr
14 getpeername 39 getservbyname
15 IoctlSocket 40 getservbyport
16 CloseSocket 41 getprotobyname
17 WaitSelect 42 getprotobynumber
18 SetSocketSignals 43 Syslog
19 getdtablesize 44 Dup2Socket
20 ObtainSocket 45 sendmsg
21 ReleaseSocket 46 recvmsg
22 ReleaseCopyOfSocket 47 gethostname
23 Errno 48 gethostid
24 SetErrnoPtr 49 SocketBaseTagList
25 ObtainSocket 50 GetSocketEvents

Implementation files: api/amiga_libcalls.c (address conversion), api/gethostnamadr.c (name resolution) with api/dns_cache.c (TTL-aware DNS response cache), api/getxbyy.c (service/protocol/network lookups), kern/uipc_socket.c + uipc_socket2.c (socket core).

SO_REUSEPORT vs SO_REUSEADDR Semantics

BSD-standard behavior is implemented in netinet/in_pcb.c:

  • Multicast addresses: SO_REUSEADDR is treated as SO_REUSEPORT (allows full duplication)
  • Unicast addresses: SO_REUSEPORT required on both sockets for shared binds
  • This matches FreeBSD/macOS semantics; differs from Linux where SO_REUSEADDR alone enables UDP port sharing

IPv4 Multicast

Host-side IPv4 group membership with IGMPv2, mirroring the IPv6 multicast path.

  • Per-socket group membership options (struct ip_moptions, max 20 groups) via IP_ADD_MEMBERSHIP / IP_DROP_MEMBERSHIP / IP_MULTICAST_IF / IP_MULTICAST_TTL / IP_MULTICAST_LOOP (ip_setmoptions/ip_getmoptions in netinet/ip_output.c)
  • Per-interface group table (struct in_multi linked list, in_multihead) with reference counting (in_addmulti/in_delmulti in netinet/in.c)
  • SANA-II multicast MAC registration -- RFC 1112 class-D → 01:00:5e:XX:XX:XX mapping programmed into the NIC filter via S2_ADDMULTICASTADDRESS/S2_DELMULTICASTADDRESS (sana_add_mcast/sana_del_mcast)
  • IGMPv2 host protocol (RFC 2236, netinet/igmp.c)
    • Unsolicited Membership Report on join; Leave Group on last-reporter drop
    • Membership Query handling (general and group-specific) with randomized report delay
    • Report suppression on hearing another host's report
    • Per-membership state machine (IGMP_OTHERMEMBER / IGMP_IREPORTEDLAST); fast/slow timers
    • Router Alert (RFC 2113) IP option on outgoing messages
    • 224.0.0.1 (all-hosts) exemption
  • IGMP protocol switch entry (IPPROTO_IGMP) wired in netinet/in_proto.c

The stack is a host (group member) only: there is no IGMP querier/router role and no multicast routing (mrouted). Built under -DENABLE_MULTICAST.


IPv6 Control Plane

IPPROTO_IPV6 Socket Options

ip6_ctloutput() in netinet6/in6_proto.c (lines 261-508) implements real option handling with backing kernel state for both PRCO_SETOPT and PRCO_GETOPT.

  • IPV6_JOIN_GROUP -- calls in6_joingroup_inp() -> in6_addmulti() -> MLD report
  • IPV6_LEAVE_GROUP -- calls in6_leavegroup_inp() -> in6_delmulti() -> MLD done
  • IPV6_MULTICAST_IF -- sets im6o->im6o_multicast_ifp
  • IPV6_MULTICAST_HOPS -- sets im6o->im6o_multicast_hlim (validated 0-255 or -1)
  • IPV6_MULTICAST_LOOP -- sets im6o->im6o_multicast_loop
  • IPV6_V6ONLY -- sets inp->in6p_v6only
  • IPV6_RECVPKTINFO -- sets/clears IN6P_PKTINFO flag
  • IPV6_TCLASS -- sets inp->in6p_tclass
  • IPV6_UNICAST_HOPS -- sets inp->in6p_hops
  • IPV6_HOPLIMIT -- sets/clears IN6P_HOPLIMIT; received hop limit delivered as an ancillary cmsg on UDP/IPv6 receive (RFC 3542, udp6_saveopt in netinet6/udp6_usrreq.c)

NDP (Neighbor Discovery Protocol)

Feature Status Key Files
Neighbor Discovery Complete netinet6/nd6.c (1007 lines), nd6_nbr.c (750), nd6_rtr.c (906)
DAD (Duplicate Address Detection) Complete netinet6/nd6.c (nd6_dad_start/timer)
SLAAC (Stateless Auto-config) Complete netinet6/nd6_rtr.c (RA processing, prefix handling)
Router Discovery Complete netinet6/nd6_rtr.c (RS/RA)

IPv6 Multicast

Full multicast stack with MLD protocol support.

  • Per-socket IPv6 group membership list (struct ip6_moptions, max 20 groups)
  • Per-interface multicast group table (struct in6_multi linked list, in6_multihead)
  • MLD (Multicast Listener Discovery) -- MLDv1 (RFC 2710) + MLDv2 (RFC 3810), host role (netinet6/mld6.c, 551 lines)
    • Query/Report/Done message handling
    • Per-group state machine (IDLE/LAZY/SLEEPING/AWAKENING)
    • Report timer with random delay
    • Report suppression on hearing other reports
    • Unsolicited reports on join, Done on leave
    • ff02::1 (all-nodes) exemption per RFC 2710 Section 6
    • MLDv2: query recognised by length, floating-point Max Response Code decoded, answered with a type-143 Report (single MODE_IS_EXCLUDE record, no sources) to ff02::16; MLDv1 queriers still receive MLDv1 Reports (RFC 3810 §8 backward compatibility)
  • SANA-II multicast MAC registration (sana_add_mcast6 / sana_del_mcast6)
  • IPv6 multicast output (ip6_output.c -- interface selection, hop limit, loopback)

IoctlSocket() -- IPv6 Ioctls

IPv6 address management ioctls are handled in in6_control():

  • SIOCGIFADDR_IN6 -- get IPv6 interface address
  • SIOCAIFADDR_IN6 -- add/configure IPv6 interface address
  • SIOCDIFADDR_IN6 -- delete IPv6 interface address
  • SIOCGIFDSTADDR_IN6 -- get destination address (point-to-point)
  • SIOCGIFNETMASK_IN6 -- get network mask
  • SIOCGLIFADDR -- enumerate addresses (used by getifaddrs)

IPv6 Datagram Processing

Feature RFC Details
Path MTU Discovery RFC 8201 ICMPv6 Packet Too Big records the reported next-hop MTU on the destination route (icmp6_update_pmtu in netinet6/icmp6.c, clamped to IPV6_MMTU, lowered only); ip6_output.c sizes datagrams to the discovered PMTU so packets are not black-holed
Extension-header conformance RFC 8200 Hop-by-Hop / Destination Options TLVs are walked with Pad1/PadN recognition and unknown-option handling by the two high-order type bits (skip / discard / discard + ICMPv6 Parameter Problem, the last suppressed for multicast destinations); the Routing header is processed by Segments Left (skipped when 0, else Parameter Problem on the type field) -- netinet6/ip6_input.c

Configuration & Services

Feature Status Key Files
DHCPv4 client Complete kern/amiga_dhcp.c (external dhclient launcher)
DHCPv6 client Complete kern/amiga_dhcp.c (conditional on INET6 && DHCP6)
Network database Complete kern/amiga_netdb.c
ARexx interface Complete kern/amiga_rexx.c
GUI configuration Complete kern/amiga_gui.c
Logging / debug Complete kern/amiga_log.c, kern/subr_prf.c
RC file configuration Complete kern/amiga_rc.c, amiga_config.c

Firewall Preferences Application

A Zune/MUI preferences application at AROS/workbench/prefs/firewall/ provides a GUI for managing IP filter and NAT rules.

Feature Description
Filter rules editor Add, edit, remove, reorder IP filter rules (ipf.rules)
NAT rules editor Add, edit, remove NAT/redirect rules (ipnat.rules)
Sub-window editing Rule parameters edited in separate pop-up windows with Use/Cancel
Theme-aware buttons Probes for THEME:Images/Gadgets/ icons; falls back to text buttons
Locale support Full FlexCat catalog localization (49 string entries)
PrefsEditor subclass Integrates with AROS Prefs framework (Save/Use/Cancel semantics)

Configuration files: Reads/writes ENV:AROSTCP/ipf.rules and ENV:AROSTCP/ipnat.rules, with ENVARC copies for persistence.

Source files: main.c, fweditor.c (MUI editor class), filter.c (filter rule I/O), nat.c (NAT rule I/O), prefsdata.c (orchestration), locale.c, args.c.

Utility Location
arp common/C/arp.c
ifconfig common/C/ifconfig.c
ping common/C/ping.c
route common/C/route.c
netstat common/C/netstat/ (inet, inet6, route, if, mbuf stats)
traceroute common/C/traceroute/
nslookup common/C/nslookup/ (interactive mode)
hostname common/C/hostname.c
resolve common/C/resolve.c
logger common/C/logger.c
whoami common/C/whoami.c
ipf common/C/ipf/ (IP Filter rule management)
ipnat common/C/ipnat/ (NAT rule management)
ip common/C/ip/ (iproute2-style network tool, see below)

The ip Command

The ip utility (v1.0) provides a Linux iproute2-inspired command-line interface for network management on AROS, adapted to the BSD/SANA-II kernel APIs.

Usage: ip [-V] [-s] [-d] [-r] [-f family] [-4|-6|-0] OBJECT [COMMAND]

Object Aliases Description
link l Display/manage network interfaces (flags, MTU, state, link-layer addresses)
addr address, a Display/manage interface addresses (IPv4 + IPv6 with prefix lengths)
route r Display routing tables (parsed from kernel routing messages)
neigh neighbor, n Display neighbor cache (ARP for IPv4, NDP for IPv6)
maddr maddress Display multicast group memberships
mroute Display multicast routing cache
rule ru Policy routing rules (stub -- AROS lacks RPDB)
netns Network namespaces (stub -- AROS lacks namespaces)

Source files: ip.c (main dispatcher), ip_link.c, ip_addr.c, ip_route.c, ip_neigh.c, ip_maddr.c, ip_stub.c, ip_util.c (formatting helpers).


Kernel Source File Reference

kern/ (Core Kernel)

File Description
amiga_main.c Stack initialization & main event loop
uipc_socket.c Socket creation/management core logic
uipc_socket2.c Socket additional operations & queuing
uipc_domain.c Protocol domain/family registration
uipc_mbuf.c Memory buffer (mbuf) allocation & manipulation
kern_malloc.c Kernel memory allocator
kern_subr.c Kernel subroutines (sleep, wakeup, etc.)
kern_synch.c Amiga-specific synchronization primitives
amiga_config.c Configuration file parsing for network setup
amiga_netdb.c Name database (hosts, services) caching
amiga_time.c Time management & timers
amiga_log.c Logging subsystem
amiga_rexx.c ARexx command interface
amiga_dhcp.c DHCP client implementation (v4 + v6)
amiga_cx.c Commodities Exchange interface
amiga_gui.c GUI components for configuration
accesscontrol.c Access control lists
subr_prf.c Printf-style formatting utilities

netinet/ (IPv4 Core)

File Description
in_proto.c IPv4 protocol family/domain initialization (incl. IPPROTO_IGMP protosw)
ip_input.c IPv4 packet reception & routing
ip_output.c IPv4 packet transmission & fragmentation; multicast options (ip_setmoptions)
igmp.c IGMPv2 host membership (RFC 2236): reports, query response, leave, timers
ip_icmp.c ICMP (ping, error messages; token-bucket error rate limiting)
in_pcb.c Protocol control blocks (TCP/UDP connection state)
in_cksum.c IPv4/TCP checksum calculation
in_cksum_sse2.c Optimized SSE2 checksum (x86_64)
in_cksum_neon.c Optimized NEON checksum (AArch64)
in.c IPv4 address utilities & interface configuration; multicast membership (in_addmulti/in_delmulti, SANA-II MAC registration)
tcp_input.c TCP segment reception & state machine (pluggable CC, SACK, ECN)
tcp_output.c TCP segment transmission (SACK option generation, ECN marking)
tcp_usrreq.c TCP user request processing
tcp_subr.c TCP support routines; congestion-control defaults, SYN cookies, ISN generation
tcp_cc_newreno.c / tcp_cc_cubic.c Pluggable congestion control (NewReno; CUBIC, default)
tcp_syncache.c SYN cache and stateless SYN cookies
tcp_timer.c TCP retransmit & keepalive timers (314 lines)
tcp_debug.c TCP debug tracing
udp_usrreq.c UDP datagram handling
raw_ip.c Raw IPv4 socket support

netinet6/ (IPv6)

File Description
ip6_input.c IPv6 packet reception & routing; RFC 8200 extension-header conformance (782 lines)
ip6_output.c IPv6 packet transmission, multicast output, RFC 8201 PMTU honouring (305 lines)
in6.c IPv6 address management, ioctls, multicast (788 lines)
in6_pcb.c IPv6 PCB bind/connect/lookup (223 lines)
in6_proto.c IPv6 protocol switch, ip6_ctloutput (incl. IPV6_HOPLIMIT) (541 lines)
in6_cksum.c IPv6 checksum calculation
in6_cksum_sse2.c Optimized SSE2 IPv6 checksum (x86_64)
in6_cksum_neon.c Optimized NEON IPv6 checksum (AArch64)
icmp6.c ICMPv6 echo, parameter problem, time exceeded, Packet Too Big / PMTU update (676 lines)
nd6.c Neighbor cache, NUD, ND option parsing (1007 lines)
nd6_nbr.c NS/NA processing, DAD (750 lines)
nd6_rtr.c RS/RA processing, SLAAC, prefix management (906 lines)
mld6.c MLDv1 + MLDv2 multicast listener discovery, host role (551 lines)
udp6_usrreq.c UDP over IPv6; IPV6_HOPLIMIT ancillary delivery (udp6_saveopt)

net/ (Generic Network Layer)

File Description
if.c Network interface management
if_sana.c SANA-II device driver integration
if_loop.c Loopback interface
route.c Routing table management (611 lines)
rtsock.c PF_ROUTE routing socket (886 lines)
radix.c Radix tree for route lookups (710 lines)
raw_cb.c Raw socket control blocks
raw_usrreq.c Raw socket user requests
netisr.c Network interrupt scheduler
sana2arp.c ARP (Address Resolution Protocol)
sana2config.c SANA-II device configuration (16 reqs default; larger with SANA2_LARGEREQALLOCS)
sana2copybuff.c Buffer copying utilities
sana2perror.c SANA-II error reporting
bpf.c Berkeley Packet Filter, packet capture (493 lines)
bpf_filter.c BPF packet filtering VM/interpreter (401 lines)
pfil.c Packet filter hooks framework (147 lines)
ipfilter.c IP packet filtering rules engine (566 lines)

Core Stack Remaining Backlog

  1. Deliver IPV6_PKTINFO as ancillary data on UDP/IPv6 receive (IPV6_HOPLIMIT is done; udp6_input has the hook)
  2. Prepend a Hop-by-Hop Router Alert option to MLDv1/MLDv2 reports (IGMP already carries one)
  3. IGMP/MLD querier (router) role and multicast routing (mrouted) -- host membership only today

Clone this wiki locally