# openwrt/netifd architecture

> Architecture diagram of the GitHub repository openwrt/netifd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openwrt/netifd
- Repository: https://github.com/openwrt/netifd

## Overview

netifd is an OpenWrt network-interface daemon: it manages configured interfaces, protocol state, IP settings and Linux link devices, and exposes daemon control and notifications through ubus. The principal runtime path is interface lifecycle management, protocol-provided or configured IP state, then device/system operations; device types include bridges and bonding, while external devices and script/ucode handlers extend configuration and control. The excerpts directly show only selected calls, so other likely orchestration links are dashed and marked unverified rather than asserted.

Main entry points: [`interface.c`](https://github.com/openwrt/netifd/blob/master/interface.c) (Interface lifecycle), [`system.c`](https://github.com/openwrt/netifd/blob/master/system.c) (System abstraction), [`proto.c`](https://github.com/openwrt/netifd/blob/master/proto.c) (Protocol registry), [`ubus.c`](https://github.com/openwrt/netifd/blob/master/ubus.c) (Ubus API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Daemon runtime"]
  node_main["Daemon entry<br/>[main.c]"]
end

subgraph group_interfaces["Interfaces and IP"]
  node_iface["Interface lifecycle<br/>[interface.c]"]
  node_ip["IP settings<br/>[interface-ip.c]"]
  node_iprule["IP rules<br/>[iprule.c]"]
end

subgraph group_protocols["Protocols and configuration"]
  node_config["Config loading<br/>[config.c]"]
  node_proto["Protocol registry<br/>[proto.c]"]
  node_staticproto["Static protocol<br/>[proto-static.c]"]
  node_shellproto["Shell protocol<br/>[proto-shell.c]"]
  node_extproto["External protocol<br/>[proto-ext.c]"]
  node_ucodeproto["Ucode protocol<br/>[proto-ucode.c]"]
  node_ucode["Ucode runtime<br/>[ucode.c]"]
end

subgraph group_devices["Devices and system"]
  node_device["Device lifecycle<br/>[device.c]"]
  node_bridge["Bridge device<br/>[bridge.c]"]
  node_bonding["Bonding device<br/>[bonding.c]"]
  node_extdev["External devices<br/>[extdev.c]"]
  node_system["System abstraction<br/>[system.c]"]
  node_linux["Linux networking<br/>[system-linux.c]"]
end

subgraph group_control["Control and events"]
  node_handler["Script handlers<br/>[handler.c]"]
  node_ubus["Ubus API<br/>[ubus.c]"]
  node_events["Interface events<br/>[interface-event.c]"]
end

node_operator(("Network operator"))

node_operator -.->|"controls"| node_ubus
node_main -->|"initializes"| node_ubus
node_config -.->|"loads settings"| node_iface
node_iface -->|"initializes and updates"| node_ip
node_iface -->|"releases and configures"| node_device
node_iface -.->|"attaches protocol"| node_proto
node_proto -.->|"dispatches"| node_staticproto
node_proto -.->|"dispatches"| node_shellproto
node_proto -.->|"dispatches"| node_extproto
node_proto -.->|"dispatches"| node_ucodeproto
node_ucodeproto -.->|"uses runtime"| node_ucode
node_ip -->|"adds addresses"| node_system
node_iprule -.->|"applies rules"| node_system
node_device -.->|"manages links"| node_system
node_system -.->|"implements Linux ops"| node_linux
node_bridge -.->|"configures bridge"| node_system
node_bonding -.->|"configures bonding"| node_system
node_extdev -.->|"uses handlers"| node_handler
node_iface -.->|"emits lifecycle events"| node_events
node_iface -.->|"publishes interface state"| node_ubus

click node_main "https://github.com/openwrt/netifd/blob/master/main.c"
click node_config "https://github.com/openwrt/netifd/blob/master/config.c"
click node_iface "https://github.com/openwrt/netifd/blob/master/interface.c"
click node_ip "https://github.com/openwrt/netifd/blob/master/interface-ip.c"
click node_iprule "https://github.com/openwrt/netifd/blob/master/iprule.c"
click node_proto "https://github.com/openwrt/netifd/blob/master/proto.c"
click node_staticproto "https://github.com/openwrt/netifd/blob/master/proto-static.c"
click node_shellproto "https://github.com/openwrt/netifd/blob/master/proto-shell.c"
click node_extproto "https://github.com/openwrt/netifd/blob/master/proto-ext.c"
click node_ucodeproto "https://github.com/openwrt/netifd/blob/master/proto-ucode.c"
click node_ucode "https://github.com/openwrt/netifd/blob/master/ucode.c"
click node_device "https://github.com/openwrt/netifd/blob/master/device.c"
click node_bridge "https://github.com/openwrt/netifd/blob/master/bridge.c"
click node_bonding "https://github.com/openwrt/netifd/blob/master/bonding.c"
click node_extdev "https://github.com/openwrt/netifd/blob/master/extdev.c"
click node_system "https://github.com/openwrt/netifd/blob/master/system.c"
click node_linux "https://github.com/openwrt/netifd/blob/master/system-linux.c"
click node_handler "https://github.com/openwrt/netifd/blob/master/handler.c"
click node_ubus "https://github.com/openwrt/netifd/blob/master/ubus.c"
click node_events "https://github.com/openwrt/netifd/blob/master/interface-event.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main toneBlue
class node_iface,node_ip,node_iprule toneAmber
class node_config,node_proto,node_staticproto,node_shellproto,node_extproto,node_ucodeproto,node_ucode toneMint
class node_device,node_bridge,node_bonding,node_extdev,node_system,node_linux toneRose
class node_handler,node_ubus,node_events,node_operator toneIndigo
```

## Components

### Daemon runtime

- [Daemon entry](https://github.com/openwrt/netifd/blob/master/main.c): `main.c`

### Interfaces and IP

- [Interface lifecycle](https://github.com/openwrt/netifd/blob/master/interface.c): `interface.c`
- [IP settings](https://github.com/openwrt/netifd/blob/master/interface-ip.c): `interface-ip.c`
- [IP rules](https://github.com/openwrt/netifd/blob/master/iprule.c): `iprule.c`

### Protocols and configuration

- [Config loading](https://github.com/openwrt/netifd/blob/master/config.c): `config.c`
- [Protocol registry](https://github.com/openwrt/netifd/blob/master/proto.c): `proto.c`
- [Static protocol](https://github.com/openwrt/netifd/blob/master/proto-static.c): `proto-static.c`
- [Shell protocol](https://github.com/openwrt/netifd/blob/master/proto-shell.c): `proto-shell.c`
- [External protocol](https://github.com/openwrt/netifd/blob/master/proto-ext.c): `proto-ext.c`
- [Ucode protocol](https://github.com/openwrt/netifd/blob/master/proto-ucode.c): `proto-ucode.c`
- [Ucode runtime](https://github.com/openwrt/netifd/blob/master/ucode.c): `ucode.c`

### Devices and system

- [Device lifecycle](https://github.com/openwrt/netifd/blob/master/device.c): `device.c`
- [Bridge device](https://github.com/openwrt/netifd/blob/master/bridge.c): `bridge.c`
- [Bonding device](https://github.com/openwrt/netifd/blob/master/bonding.c): `bonding.c`
- [External devices](https://github.com/openwrt/netifd/blob/master/extdev.c): `extdev.c`
- [System abstraction](https://github.com/openwrt/netifd/blob/master/system.c): `system.c`
- [Linux networking](https://github.com/openwrt/netifd/blob/master/system-linux.c): `system-linux.c`

### Control and events

- [Script handlers](https://github.com/openwrt/netifd/blob/master/handler.c): `handler.c`
- [Ubus API](https://github.com/openwrt/netifd/blob/master/ubus.c): `ubus.c`
- [Interface events](https://github.com/openwrt/netifd/blob/master/interface-event.c): `interface-event.c`

### Other components

- **Network operator**

## Connections

- Network operator → Ubus API: controls
- Daemon entry → Ubus API: initializes (evidence: `main.c`)
- Config loading → Interface lifecycle: loads settings
- Interface lifecycle → IP settings: initializes and updates (evidence: `interface.c`)
- Interface lifecycle → Device lifecycle: releases and configures (evidence: `interface.c`)
- Interface lifecycle → Protocol registry: attaches protocol
- Protocol registry → Static protocol: dispatches
- Protocol registry → Shell protocol: dispatches
- Protocol registry → External protocol: dispatches
- Protocol registry → Ucode protocol: dispatches
- Ucode protocol → Ucode runtime: uses runtime
- IP settings → System abstraction: adds addresses (evidence: `interface-ip.c`)
- IP rules → System abstraction: applies rules
- Device lifecycle → System abstraction: manages links
- System abstraction → Linux networking: implements Linux ops
- Bridge device → System abstraction: configures bridge
- Bonding device → System abstraction: configures bonding
- External devices → Script handlers: uses handlers
- Interface lifecycle → Interface events: emits lifecycle events
- Interface lifecycle → Ubus API: publishes interface state
