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 @@ -113,6 +113,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 @@ -417,6 +422,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
87 changes: 87 additions & 0 deletions doc/scripting-restconf.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,93 @@ 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 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.

### 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.

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

## Advanced Examples

### Makefile for Common Operations
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
From ce9193012b5e521ea4de52a872201e3506354ef7 Mon Sep 17 00:00:00 2001
From: Mattias Walström <lazzer@gmail.com>
Date: Thu, 19 Nov 2026 15:06:39 +0100
Subject: [PATCH] yang-push: find the previous edit of a target without XPath
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The target was put in an XPath literal to look up an earlier edit of
the same node. A list key that is itself an instance-identifier makes
the path hold both kinds of quotes, the expression then fails to parse
and the whole on-change notification is dropped without a trace.

Signed-off-by: Mattias Walström <lazzer@gmail.com>
---
src/utils/sn_yang_push.c | 34 ++++++++++++----------------------
1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/src/utils/sn_yang_push.c b/src/utils/sn_yang_push.c
index 65b1d4d8..caeda676 100644
--- a/src/utils/sn_yang_push.c
+++ b/src/utils/sn_yang_push.c
@@ -407,31 +407,21 @@ srsn_yp_op2str(srsn_yp_change_t op)
static sr_error_info_t *
srsn_yp_ntf_change_edit_clear_target(struct lyd_node *ly_yp, const char *target)
{
- sr_error_info_t *err_info = NULL;
- struct ly_set *set = NULL;
- char quot, *xpath = NULL;
-
- /* find the edit of this target, be careful with the quotes in the XPath */
- quot = strchr(target, '\'') ? '\"' : '\'';
- if (asprintf(&xpath, "/ietf-yang-push:push-change-update/datastore-changes/yang-patch/edit[target=%c%s%c]",
- quot, target, quot) == -1) {
- SR_ERRINFO_MEM(&err_info);
- goto cleanup;
- }
- if ((err_info = sr_lyd_find_xpath(ly_yp, xpath, &set))) {
- goto cleanup;
- }
- assert((set->count == 0) || (set->count == 1));
+ struct lyd_node *edit, *leaf;

- /* remove the previous change of this target */
- if (set->count) {
- lyd_free_tree(set->dnodes[0]);
+ /* compare the values, a target with both kinds of quotes cannot be an XPath literal */
+ LY_LIST_FOR(lyd_child(ly_yp), edit) {
+ if (strcmp(LYD_NAME(edit), "edit") || lyd_find_path(edit, "target", 0, &leaf)) {
+ continue;
+ }
+ if (!strcmp(lyd_get_value(leaf), target)) {
+ /* remove the previous change of this target */
+ lyd_free_tree(edit);
+ break;
+ }
}

-cleanup:
- free(xpath);
- ly_set_free(set, NULL);
- return err_info;
+ return NULL;
}

/**
10 changes: 9 additions & 1 deletion src/statd/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DISTCLEANFILES = *~ *.d
ACLOCAL_AMFLAGS = -I m4

sbin_PROGRAMS = statd
sbin_PROGRAMS = statd statd-push
statd_SOURCES = statd.c shared.c shared.h journal.c journal_retention.c journal.h avahi.c avahi.h yangerd.c yangerd.h
statd_CPPFLAGS = -D_DEFAULT_SOURCE -D_GNU_SOURCE
statd_CPPFLAGS += -DSTATD_VERSION=\"$(PACKAGE_VERSION)\"
Expand All @@ -13,6 +13,14 @@ statd_LDADD = $(jansson_LIBS) $(libyang_LIBS) $(sysrepo_LIBS)
statd_LDADD += $(libsrx_LIBS) $(libite_LIBS) $(EV_LIBS) -lz
statd_LDADD += $(avahi_client_LIBS)

statd_push_SOURCES = push.c yangerd.c yangerd.h
statd_push_CPPFLAGS = -D_DEFAULT_SOURCE -D_GNU_SOURCE
statd_push_CFLAGS = -W -Wall -Wextra
statd_push_CFLAGS += $(jansson_CFLAGS) $(libyang_CFLAGS) $(sysrepo_CFLAGS)
statd_push_CFLAGS += $(libsrx_CFLAGS) $(libite_CFLAGS)
statd_push_LDADD = $(jansson_LIBS) $(libyang_LIBS) $(sysrepo_LIBS)
statd_push_LDADD += $(libsrx_LIBS) $(libite_LIBS) $(EV_LIBS)

# Test stub for journal retention policy (no dependencies, standalone)
noinst_PROGRAMS = journal_retention_stub
journal_retention_stub_SOURCES = journal_retention_stub.c journal_retention.c journal.h
Expand Down
Loading
Loading