Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions board/common/rootfs/etc/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ http {
1 $binary_remote_addr;
}
include /etc/nginx/restconf-rate-zone.conf;
limit_conn_zone $restconf_limit_key zone=restconf_streams:32k;

include /etc/nginx/enabled/*.conf;

Expand Down
9 changes: 9 additions & 0 deletions board/common/rootfs/etc/nginx/restconf-proxy.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
grpc_pass grpc://[::1]:10080;
grpc_set_header Host $host;
grpc_set_header X-Real-IP $remote_addr;
grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
grpc_set_header X-Forwarded-Proto $scheme;
grpc_set_header Forward "proto=$scheme;host=$host";

# Any error_page here stops the inherited one, 599 is never sent
error_page 599 /50x.html;
17 changes: 10 additions & 7 deletions board/common/rootfs/etc/nginx/restconf.app
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
location ~ ^/(restconf|yang|.well-known)/ {
include /etc/nginx/restconf-access.conf;
include /etc/nginx/restconf-rate-limit.conf;
grpc_pass grpc://[::1]:10080;
grpc_set_header Host $host;
grpc_set_header X-Real-IP $remote_addr;
grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
grpc_set_header X-Forwarded-Proto $scheme;

# A little longer than the RESTCONF server waits, see /etc/default/confd
grpc_read_timeout 130s;
include /etc/nginx/restconf-proxy.conf;
}

# Any error_page here stops the inherited one, 599 is never sent
error_page 599 /50x.html;
# Event streams stay open, rousette sends a keep-alive every 55 s
location /streams/ {
include /etc/nginx/restconf-access.conf;
include /etc/nginx/restconf-rate-limit.conf;
limit_conn restconf_streams 16;
limit_conn_status 429;
grpc_read_timeout 120s;
include /etc/nginx/restconf-proxy.conf;
}
7 changes: 7 additions & 0 deletions doc/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ All notable changes to the project are documented in this file.
control list's cycle each probe left and arrived
- NETCONF and RESTCONF requests now get 120 seconds to complete, up from
60. A large change can take more than a minute on a small device
- RESTCONF clients can now subscribe to notifications and read them as
an event stream, see [Notifications][restconf-notif]
- On-change subscriptions to the operational datastore, over NETCONF
and RESTCONF, now report when an interface, its addresses, the LLDP
neighbors or the alarm list change, see [Subscribe to Changes][on-change]

### Fixes

Expand Down Expand Up @@ -420,6 +425,8 @@ All notable changes to the project are documented in this file.
[pppoe]: https://www.kernelkit.org/infix/latest/pppoe/
[modem]: https://www.kernelkit.org/infix/latest/modem/
[alarms]: https://www.kernelkit.org/infix/latest/alarms/
[restconf-notif]: https://www.kernelkit.org/infix/latest/scripting-restconf/#notifications
[on-change]: https://www.kernelkit.org/infix/latest/scripting-restconf/#subscribe-to-changes
[vpd]: https://www.kernelkit.org/infix/latest/vpd/#vpd-file-on-the-aux-partition
[usb]: https://www.kernelkit.org/infix/latest/hardware/#usb-ports
[gps]: https://www.kernelkit.org/infix/latest/hardware/#anchor-a-gps-receiver-to-a-usb-port
Expand Down
134 changes: 134 additions & 0 deletions doc/scripting-restconf.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,140 @@ Verify the change with SSH:
Wed Apr 17 14:48:12 UTC 2024
```

## Notifications

A client can subscribe to notifications and read them as a stream of
server-sent events, instead of polling. Subscribing is an RPC, and the
reply has the address of the stream:

```bash
~$ curl -sk -u admin:admin -X POST \
-H 'Content-Type: application/yang-data+json' \
-d '{"ietf-subscribed-notifications:input":{"stream":"NETCONF","encoding":"encode-json"}}' \
https://example.local/restconf/operations/ietf-subscribed-notifications:establish-subscription
{
"ietf-subscribed-notifications:output": {
"id": 1,
"ietf-restconf-subscribed-notifications:uri": "https://example.local/streams/subscribed/5c7d0cfb-93a1-4a31-9cb4-1ee3c8b4a6f4"
}
}
```

Open the stream within a minute, or the device removes the subscription:

```bash
~$ curl -sk -N -u admin:admin -H 'Accept: text/event-stream' \
https://example.local/streams/subscribed/5c7d0cfb-93a1-4a31-9cb4-1ee3c8b4a6f4
```

The stream stays open until the client closes it. One client address
can have up to 16 streams open at a time. The device answers the next
one with 429 Too Many Requests.

The address in the reply has the same host name or IP address as the
request. If you used an IPv6 link-local address, the reply has it
without the zone. Add the zone again, e.g. `%25eth0`, before you open
the stream.

### Lost Connections

The device sends every event once, to the client that has the stream
open at the time, and keeps no history of them. A client has to cope
with a stream that breaks:

- When nothing happens the device sends a comment line, starting with
a colon, every 55 seconds. If the stream has been silent for two
minutes, treat it as lost and open it again
- Events have no `id`, and the device ignores `Last-Event-ID`. A
browser `EventSource` reconnects by itself, but it does not get the
events it missed
- A subscription has one reader. If the stream is already open, a
second request for it gets 409 Conflict
- The device keeps the subscription for a minute after the stream
closes. Open the same address again within that time to continue.
Later the address answers 404 Not Found, and you have to subscribe
again
- Only the user who subscribed can open the stream
- A subscription does not survive a reboot, or a restart of the web
services
- Do not count on events from the time the stream was closed. The
device cannot replay them, and answers a request with `start-time`
with 400 Bad Request

A client that goes away without closing its connection keeps its
stream, and its place among the 16, until the device notices. That
can take up to 15 minutes. Close the stream, or end the subscription
with `delete-subscription` and the `id` from the reply, when you are
done.

### Subscribe to Changes

To be told when operational data changes, subscribe with `on-change`
and a filter for the data you want. This subscription reports when an
interface goes up or down:

```bash
~$ curl -sk -u admin:admin -X POST \
-H 'Content-Type: application/yang-data+json' \
-d '{"ietf-subscribed-notifications:input":{
"ietf-yang-push:datastore":"ietf-datastores:operational",
"ietf-yang-push:datastore-xpath-filter":"/ietf-interfaces:interfaces/interface/oper-status",
"ietf-yang-push:on-change":{},
"encoding":"encode-json"}}' \
https://example.local/restconf/operations/ietf-subscribed-notifications:establish-subscription
```

The stream starts with the current values in a `push-update`, followed
by a `push-change-update` for every change:

```json
{
"ietf-restconf:notification": {
"ietf-yang-push:push-change-update": {
"id": 2,
"datastore-changes": {
"yang-patch": {
"patch-id": "patch-1",
"edit": [
{
"edit-id": "edit-1",
"operation": "replace",
"target": "/ietf-interfaces:interfaces/interface[name='e2']/oper-status",
"value": {
"ietf-interfaces:oper-status": "down"
}
}
]
}
}
},
"eventTime": "2026-11-19T09:39:39.286415871+00:00"
}
}
```

The device reports changes to the interfaces and their addresses, the
LLDP neighbors and the alarm list. It does not report counters, read
them with a GET.

The `push-update` holds the values as they are when you subscribe. An
interface that went down and came back before that is only shown as
up. Set `"sync-on-start": false` inside `on-change` to skip the
`push-update` and only get the changes.

The device then reports every change by itself, in the order they
happened. The `patch-id` counts up from `patch-1` in each
subscription, so a missing number means a change was lost.

To get back in step after a lost connection, subscribe again and start
over from the new `push-update`. Opening the old stream again within
the minute gives no new `push-update`, so changes from the time it was
closed can be missing.

A NETCONF client can make the same subscription. Its notifications
arrive on the session that subscribed, so there is no stream to open,
and the subscription ends when the session does.

## Advanced Examples

### Makefile for Common Operations
Expand Down
4 changes: 2 additions & 2 deletions package/landing/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ server {
}

server {
listen 443 ssl;
listen [::]:443 ssl;
listen 443 ssl so_keepalive=10s:3s:3;
listen [::]:443 ssl so_keepalive=10s:3s:3;
server_name _;
include ssl.conf;

Expand Down
1 change: 1 addition & 0 deletions package/statd/statd.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#set DEBUG=1
service name:statd [12345] <pid/confd> statd -- Status daemon
service name:statd-push [12345] <pid/confd> statd-push -- Status change publisher
4 changes: 2 additions & 2 deletions package/webui/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ server {
}

server {
listen 443 ssl;
listen [::]:443 ssl;
listen 443 ssl so_keepalive=10s:3s:3;
listen [::]:443 ssl so_keepalive=10s:3s:3;
server_name _;
include ssl.conf;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From e782a940ce959c3b9f6b5486184f585c075db515 Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Sun, 28 Sep 2025 06:04:12 +0200
Subject: [PATCH 1/7] Add '--log-level LEVEL' command line option
Subject: [PATCH 1/8] Add '--log-level LEVEL' command line option
Organization: Wires

The default 'trace' log level is quite verbose for production systems.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 3e0bcaf51aed96ad1e374ef89337defa84686fef Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Thu, 19 Mar 2026 17:21:20 +0100
Subject: [PATCH 2/7] sr: lower log message severity to debug
Subject: [PATCH 2/8] sr: lower log message severity to debug
Organization: Wires

On non-CzechLight hardware this message fires on every startup. It is
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From ca34c1a4adac35eca3a950abf4ae6fa62e614fe6 Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Thu, 19 Mar 2026 17:21:25 +0100
Subject: [PATCH 3/7] restconf: add audit trail for datastore write operations
Subject: [PATCH 3/8] restconf: add audit trail for datastore write operations
Organization: Wires

Log an info message before and after committing changes to sysrepo,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 1850bb1c0e7ed7fe4599a69e9b383521a0cc900a Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Thu, 19 Mar 2026 17:54:11 +0100
Subject: [PATCH 4/7] restconf: strip redundant fields from syslog/journald log
Subject: [PATCH 4/8] restconf: strip redundant fields from syslog/journald log
messages
Organization: Wires

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From b3bcfd9ec22d4a50481912fdf4ca4b19cf615078 Mon Sep 17 00:00:00 2001
From: Mattias Walström <mattias.walstrom@wires.se>
Date: Sat, 24 Oct 2026 09:40:25 +0200
Subject: [PATCH 5/7] restconf: YANG Patch delete/remove of a typed leaf
Subject: [PATCH 5/8] restconf: YANG Patch delete/remove of a typed leaf
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From ad38833e880f9aff486de4dba8918268c9cd7831 Mon Sep 17 00:00:00 2001
From: Mattias Walström <lazzer@gmail.com>
Date: Tue, 3 Nov 2026 23:24:17 +0100
Subject: [PATCH 6/7] auth: name the sysrepo session after the authenticated
Subject: [PATCH 6/8] auth: name the sysrepo session after the authenticated
user
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 070f95df623400c5c36304f5b4e09b137fabcad6 Mon Sep 17 00:00:00 2001
From: Mattias Walström <lazzer@gmail.com>
Date: Mon, 9 Nov 2026 09:24:58 +0100
Subject: [PATCH 7/7] restconf: name the failing node on validation errors
Subject: [PATCH 7/8] restconf: name the failing node on validation errors
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
From f31d9a20b510ba3aeabcc388c328df2e6571dfd9 Mon Sep 17 00:00:00 2001
From: Mattias Walström <lazzer@gmail.com>
Date: Mon, 23 Nov 2026 14:25:39 +0100
Subject: [PATCH 8/8] restconf: reject start-time when replay is not supported
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Organization: Wires

RFC 8040 section 4.8.7 requires 400 Bad Request here. The stream was
opened anyway and never replayed anything, so a client could not tell
that it had missed events.

Signed-off-by: Mattias Walström <lazzer@gmail.com>
---
src/restconf/NotificationStream.cpp | 2 ++
tests/restconf-notifications.cpp | 1 +
2 files changed, 3 insertions(+)

diff --git a/src/restconf/NotificationStream.cpp b/src/restconf/NotificationStream.cpp
index 63f26ba..5b993aa 100644
--- a/src/restconf/NotificationStream.cpp
+++ b/src/restconf/NotificationStream.cpp
@@ -77,6 +77,8 @@ NotificationStream::NotificationStream(
throw ErrorResponse(400, "application", "invalid-argument", "start-time is in the future");
} else if (!startTime && stopTime) {
throw ErrorResponse(400, "application", "invalid-argument", "stop-time must be used with start-time");
+ } else if (startTime && !sysrepoReplayInfo(m_session).enabled) {
+ throw ErrorResponse(400, "application", "invalid-argument", "start-time requires replay support");
}
}

diff --git a/tests/restconf-notifications.cpp b/tests/restconf-notifications.cpp
index 399392c..d81375d 100644
--- a/tests/restconf-notifications.cpp
+++ b/tests/restconf-notifications.cpp
@@ -176,6 +176,7 @@ TEST_CASE("NETCONF notification streams")
REQUIRE(get("/streams/NETCONF/XML?start-time=2000-01-01T00:00:00+00:00&stop-time=1990-01-01T00:00:00+00:00", {}) == Response{400, plaintextHeaders, "stop-time must be greater than start-time"});
REQUIRE(get("/streams/NETCONF/XML?stop-time=1990-01-01T00:00:00+00:00", {}) == Response{400, plaintextHeaders, "stop-time must be used with start-time"});
REQUIRE(get("/streams/NETCONF/XML?start-time=" + libyang::yangTimeFormat(std::chrono::system_clock::now() + std::chrono::hours(1), libyang::TimezoneInterpretation::Local), {}) == Response{400, plaintextHeaders, "start-time is in the future"});
+ REQUIRE(get("/streams/NETCONF/XML?start-time=2000-01-01T00:00:00+00:00", {}) == Response{400, plaintextHeaders, "start-time requires replay support"});
}

SECTION("Replays")
Loading