As @jjohansson mentioned you seem to have a memory allocation problem with your “values”.
As a reference here’s a quick working hack to send a netconf config change notification:
$ pwd
/Users/tailf/confd-6.3/examples.confd/netconf_notifications
$ diff -u ../netconf_notifications-orig .
diff -u ../netconf_notifications-orig/Makefile ./Makefile
--- ../netconf_notifications-orig/Makefile 2017-04-25 16:15:41.000000000 +0200
+++ ./Makefile 2017-04-25 15:23:59.000000000 +0200
@@ -35,23 +35,26 @@
-all: notifier notifier_builtin_replay_store notif.fxs $(CDB_DIR) ssh-keydir
+all: notifier notifier_builtin_replay_store notif.fxs notifications.fxs ietf-netconf-notifications.h $(CDB_DIR) ssh-keydir
@echo "Build complete"
+ietf-netconf-notifications.h:
+ $(CONFDC) --emit-h ietf-netconf-notifications.h $(CONFD_DIR)/etc/confd/ietf-netconf-notifications.fxs
+
notifier: notifier.o
$(CC) notifier.o $(LIBS) $(CFLAGS) -ansi -pedantic -o $@
-notifier.o: notifier.c notif.h
+notifier.o: notifier.c notif.h ietf-netconf-notifications.h
notifier_builtin_replay_store: notifier_builtin_replay_store.o
$(CC) notifier_builtin_replay_store.o $(LIBS) $(CFLAGS) -o $@
-notifier_builtin_replay_store.o: notifier_builtin_replay_store.c notif.h
+notifier_builtin_replay_store.o: notifier_builtin_replay_store.c notif.h ietf-netconf-notifications.h
%.h: %.fxs
$(CONFDC) --emit-h $*.h $<
diff -u ../netconf_notifications-orig/notifier_builtin_replay_store.c ./notifier_builtin_replay_store.c
--- ../netconf_notifications-orig/notifier_builtin_replay_store.c 2017-04-25 16:15:41.000000000 +0200
+++ ./notifier_builtin_replay_store.c 2017-04-25 16:00:30.000000000 +0200
@@ -14,8 +14,10 @@
#include <confd_lib.h>
#include <confd_dp.h>
+#include <confd_maapi.h>
#include "notif.h"
+#include "ietf-netconf-notifications.h"
#define OK(val) (assert((val) == CONFD_OK))
@@ -81,6 +83,55 @@
OK(confd_notification_send(live_ctx, &eventTime, vals, nvals));
}
+static int maapi_socket(int *msock, struct sockaddr_in *addr)
+{
+ if ((*msock = socket(PF_INET, SOCK_STREAM, 0)) < 0 ) {
+ confd_fatal("failed to create socket");
+ return CONFD_ERR;
+ }
+ if (maapi_connect(*msock, (struct sockaddr*)addr, sizeof (struct sockaddr_in)) < 0) {
+ confd_fatal("failed to connect");
+ return CONFD_ERR;
+ }
+
+ return CONFD_OK;
+}
+
+static void send_cfg_change(void)
+{
+ confd_tag_value_t vals[11];
+ int i = 0;
+ struct in_addr in;
+ confd_hkeypath_t *kp;
+ int msock;
+ struct sockaddr_in addr;
+
+ addr.sin_addr.s_addr = inet_addr("127.0.0.1");
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(CONFD_PORT);
+
+ maapi_socket(&msock, &addr);
+ maapi_xpath2kpath(msock, "/interfaces/interface", &kp);
+ close(msock);
+
+ inet_pton(AF_INET, "160.160.160.160", &in);
+
+ CONFD_SET_TAG_XMLBEGIN(&vals[i], ncn_netconf_config_change, ncn__ns); i++;
+ CONFD_SET_TAG_XMLBEGIN(&vals[i], ncn_changed_by, ncn__ns); i++;
+ CONFD_SET_TAG_STR(&vals[i], ncn_username, "admin"); i++;
+ CONFD_SET_TAG_UINT32(&vals[i], ncn_session_id, 0); i++;
+ CONFD_SET_TAG_IPV4(&vals[i], ncn_source_host, in); i++;
+ CONFD_SET_TAG_XMLEND(&vals[i], ncn_changed_by, ncn__ns); i++;
+ CONFD_SET_TAG_ENUM_VALUE(&vals[i], ncn_datastore, ncn_running); i++;
+ CONFD_SET_TAG_XMLBEGIN(&vals[i], ncn_edit, ncn__ns); i++;
+ CONFD_SET_TAG_OBJECTREF(&vals[i], ncn_target, kp);i++;
+ CONFD_SET_TAG_XMLEND(&vals[i], ncn_edit, ncn__ns); i++;
+ CONFD_SET_TAG_XMLEND(&vals[i], ncn_netconf_config_change, ncn__ns); i++;
+
+ send_notification(vals, i);
+ confd_free_hkeypath(kp);
+}
+
static void send_notifup_1(int index, int flags1, int flags2)
{
confd_tag_value_t vals[9];
@@ -233,7 +284,7 @@
ncb.fd = workersock;
ncb.get_log_times = NULL;
ncb.replay = NULL;
- strcpy(ncb.streamname, "interface");
+ strcpy(ncb.streamname, "NETCONF");
ncb.cb_opaque = NULL;
if (confd_register_notification_stream(dctx, &ncb, &live_ctx) != CONFD_OK) {
confd_fatal("Couldn't register stream %s\n", ncb.streamname);
@@ -275,6 +326,10 @@
if (!read(0, &c, 1))
exit(0);
switch (c) {
+ case 'n':
+ printf("sending cfg change\n");
+ send_cfg_change();
+ break;
case 'u':
printf("sending linkUp notification\n");
send_notifup_1(1, 2112, 32);