nuttx/Documentation/os/networking/netlink.rst
Vinicius May f6ecf80ebb Documentation: brand new layout for NuttX documentation.
The documentation grew one page at a time, so the tree follows the
history of who wrote what and not the shape of NuttX. Scheduling is
spread over three places, a driver page can sit above the subsystem
that owns it, and the front page lists everything at the same level.
That is a lot to face when all you want to know is where the scheduler
lives.

This change files every page under the code it describes. It is a move,
not a rewrite: outside the ten pages named below, every page keeps the
text that is already in master, and no page's text is deleted.

What it does:

* Groups the table of contents into nine chapters.
* Moves the OS subsystems under os/: scheduling, memory, drivers,
  filesystem, networking, IPC, interrupts, libs, time.
* Renames the platform pages to the names the source tree uses, and
  derives their tags from the tree instead of by hand.
* Splits guides/ by subject.
* Adds Documentation/redirects.py, with a rule for every page that left
  its old path, so old URLs keep working. The redirect page also carries
  a link's #anchor across to the new page.

Ten pages have text that is new or rewritten. Nine of them are the
landing page of a chapter, which has to exist for the new structure:

    index                  the front page
    os/index               OS Design
    os/scheduling/index    Scheduling
    os/interrupts/index    Interrupts
    os/ipc/index           IPC
    os/time/index          Time and timers
    about/index            About
    developing/index       Developing NuttX
    ReleaseNotes/index     Release notes

The tenth is os/libs/libbuiltin, the only page here with technical
content: libs/libbuiltin/ had no page at all. Five SVG diagrams come
with these pages, hand-written XML with no editor metadata.

Nothing outside Documentation/ is touched.

How it was checked:

* Sphinx builds with -W: no warnings, and no document left outside a
  toctree.
* A script, offered in the PR, proves the narrow claim this rests on.
  For every page outside the ten named above it erases what a move
  touches -- link target, path, tag line, toctree block, table border --
  from the whole old text and the whole new text, and requires the two
  to be byte for byte identical. It also requires every sentence of a
  deleted page to turn up somewhere, and every page that left its old
  path to have a redirect, from a URL that existed, to where its content
  went. It exits non-zero and names the page if any of that is not true,
  and it tests added pages too, so forgetting to declare one cannot make
  it pass.
* An independent audit checked 133 factual claims on these ten pages
  against the tree, one shell command per claim: 130 confirmed, 1
  refuted and fixed here, 2 not checkable.
* tools/checkpatch.sh is clean over the range.

The diff is large because moving a page changes every link that points
to it. Most of it is pure renames, and board pages that gained one tag
line.

Assisted-by: Claude:claude-opus-5
2026-10-08 01:40:54 +08:00

137 lines
No EOL
3.5 KiB
ReStructuredText

=====================
Netlink Route support
=====================
Netlink Route (:c:macro:`NETLINK_ROUTE`) allow notifying msg when the network
changes. And then apps can obtain these changes by monitoring to netlink socket
messages.
NuttX supports Netlink Route groups
- RTMGRP_IPV4_ROUTE | RTMGRP_IPV6_ROUTE
- Notify when IPV4|IPV6 routing table changes.
- RTMGRP_NEIGH
- Notify when ARP (IPV4) or neighbors (IPV6) table changes.
- RTNLGRP_IPV6_PREFIX
- Notify when IPV6 prefix changes.
Messages content
================
1. RTMGRP_IPV4_ROUTE | RTMGRP_IPV6_ROUTE
``RTM_NEWROUTE``, ``RTM_DELROUTE``, ``RTM_GETROUTE``:
Create, remove or receive information about a network route. These
messages contain an rtmsg structure with 3 optional sequence of
rtattr structures following.
.. code-block:: c
struct getroute_recvfrom_ipv4addr_s
{
struct rtattr attr;
in_addr_t addr;
};
struct getroute_recvfrom_ipv4response_s
{
struct nlmsghdr hdr;
struct rtmsg rte;
struct getroute_recvfrom_ipv4addr_s dst;
struct getroute_recvfrom_ipv4addr_s genmask;
struct getroute_recvfrom_ipv4addr_s gateway;
};
struct getroute_recvfrom_ipv6addr_s
{
struct rtattr attr;
net_ipv6addr_t addr;
};
struct getroute_recvfrom_ipv6response_s
{
struct nlmsghdr hdr;
struct rtmsg rte;
struct getroute_recvfrom_ipv6addr_s dst;
struct getroute_recvfrom_ipv6addr_s genmask;
struct getroute_recvfrom_ipv6addr_s gateway;
};
2. RTMGRP_NEIGH
``RTM_NEWNEIGH``, ``RTM_DELNEIGH``, ``RTM_GETNEIGH``:
Add, remove or receive information about a neighbor table entry (e.g.,
an ARP entry). The message contains an ndmsg structure and optional
sequence of rtattr structures following. And the date will be ``struct arpreq``
in ``include/netinet/arp.h``or ``struct neighbor_entry_s`` in ``include/net/neighbor.h``
.. code-block:: c
struct getneigh_recvfrom_response_s
{
struct nlmsghdr hdr;
struct ndmsg msg;
struct rtattr attr;
uint8_t data[1];
};
3. RTNLGRP_IPV6_PREFIX
``RTM_NEWPREFIX``:
Receive information about IPV6 prefix. The message contains an prefixmsg structure
and two optional sequence of rtattr structures following. And the ``addr`` and
``prefix_cacheinfo`` are parsed from the RA message.
.. code-block:: c
struct getprefix_recvfrom_addr_s
{
struct rtattr attr;
net_ipv6addr_t addr;
};
struct getprefix_recvfrom_cache_s
{
struct rtattr attr;
struct prefix_cacheinfo pci;
};
struct getprefix_recvfrom_response_s
{
struct nlmsghdr hdr;
struct prefixmsg pmsg;
struct getprefix_recvfrom_addr_s prefix;
struct getprefix_recvfrom_cache_s pci;
};
Usage
=====
.. code-block:: c
struct sockaddr_nl addr;
struct nlmsghdr *hdr;
uint8_t buffer[BUFSIZE];
int sd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
addr.nl_family = AF_NETLINK;
addr.nl_groups = RTMGRP_IPV4_ROUTE | RTMGRP_IPV6_ROUTE |
RTMGRP_NEIGH | RTMGRP_IPV6_PREFIX;
bind(sd, (FAR struct sockaddr *)&addr, sizeof(addr)); /* Bind to device */
while (1)
{
recv(sd, buf, BUFSIZE, 0);
for (hdr = buf; NLMSG_OK(hdr, ret); hdr = NLMSG_NEXT(hdr, ret))
{
if (hdr->nlmsg_type == RTM_...)
{
/* Func parsed netlink msg*/
...
}
}
}
close(sd); /* Close the socket */