Skip to content

Commit ff5b71b

Browse files
authored
Merge pull request #1019 from kernelkit/move-operational
statd: Move operational from confd to statd (yanger)
2 parents a4def13 + 2b5cf29 commit ff5b71b

20 files changed

+258
-181
lines changed

configs/aarch64_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ BR2_PACKAGE_ROUSETTE=y
166166
BR2_PACKAGE_RAUC_INSTALLATION_STATUS=y
167167
BR2_PACKAGE_HOST_PYTHON_YANGDOC=y
168168
BR2_DOWNLOAD_FORCE_CHECK_HASHES=y
169+
BR2_PACKAGE_GETENT=y
169170
TRUSTED_KEYS=y
170171
TRUSTED_KEYS_DEVELOPMENT=y
171172
DISK_IMAGE_BOOT_BIN=y

configs/aarch64_minimal_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ BR2_PACKAGE_LIBINPUT=y
139139
BR2_PACKAGE_ROUSETTE=y
140140
BR2_PACKAGE_RAUC_INSTALLATION_STATUS=y
141141
BR2_DOWNLOAD_FORCE_CHECK_HASHES=y
142+
BR2_PACKAGE_GETENT=y
142143
DISK_IMAGE_BOOT_BIN=y
143144
TRUSTED_KEYS=y
144145
TRUSTED_KEYS_DEVELOPMENT=y

configs/r2s_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ BR2_PACKAGE_ROUSETTE=y
203203
BR2_PACKAGE_RAUC_INSTALLATION_STATUS=y
204204
BR2_PACKAGE_HOST_PYTHON_YANGDOC=y
205205
BR2_DOWNLOAD_FORCE_CHECK_HASHES=y
206+
BR2_PACKAGE_GETENT=y
206207
TRUSTED_KEYS=y
207208
TRUSTED_KEYS_DEVELOPMENT=y
208209
# GNS3_APPLIANCE is not set

configs/riscv64_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ BR2_PACKAGE_ROUSETTE=y
196196
BR2_PACKAGE_HOST_PYTHON_YANGDOC=y
197197
BR2_PACKAGE_RAUC_INSTALLATION_STATUS=y
198198
BR2_DOWNLOAD_FORCE_CHECK_HASHES=y
199+
BR2_PACKAGE_GETENT=y
199200
TRUSTED_KEYS=y
200201
TRUSTED_KEYS_DEVELOPMENT=y
201202
# GNS3_APPLIANCE is not set

configs/x86_64_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ BR2_PACKAGE_ROUSETTE=y
168168
BR2_PACKAGE_RAUC_INSTALLATION_STATUS=y
169169
BR2_PACKAGE_HOST_PYTHON_YANGDOC=y
170170
BR2_DOWNLOAD_FORCE_CHECK_HASHES=y
171+
BR2_PACKAGE_GETENT=y
171172
TRUSTED_KEYS=y
172173
TRUSTED_KEYS_DEVELOPMENT=y
173174
GNS3_APPLIANCE_RAM=512

configs/x86_64_minimal_defconfig

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ BR2_CCACHE=y
77
BR2_CCACHE_DIR="${BR2_EXTERNAL_INFIX_PATH}/.ccache"
88
BR2_ENABLE_DEBUG=y
99
BR2_GLOBAL_PATCH_DIR="${BR2_EXTERNAL_INFIX_PATH}/patches"
10+
BR2_DOWNLOAD_FORCE_CHECK_HASHES=y
1011
BR2_TARGET_GENERIC_HOSTNAME="ix"
1112
BR2_TARGET_GENERIC_ISSUE="Infix by KernelKit"
1213
BR2_INIT_FINIT=y
1314
BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y
1415
BR2_ROOTFS_DEVICE_TABLE="system/device_table.txt ${BR2_EXTERNAL_INFIX_PATH}/board/common/xattrs"
15-
# BR2_TARGET_ENABLE_ROOT_LOGIN is not set
1616
BR2_ROOTFS_MERGED_USR=y
17+
# BR2_TARGET_ENABLE_ROOT_LOGIN is not set
1718
BR2_SYSTEM_BIN_SH_BASH=y
1819
BR2_TARGET_GENERIC_GETTY_PORT="@console"
1920
BR2_TARGET_GENERIC_GETTY_TERM="xterm"
@@ -50,10 +51,7 @@ BR2_PACKAGE_UBOOT_TOOLS_FIT_SIGNATURE_SUPPORT=y
5051
BR2_PACKAGE_UBOOT_TOOLS_FIT_CHECK_SIGN=y
5152
BR2_PACKAGE_UBOOT_TOOLS_MKENVIMAGE=y
5253
BR2_PACKAGE_PYTHON3=y
53-
BR2_PACKAGE_LIBSSH_OPENSSL=y
5454
BR2_PACKAGE_LIBSSH2=y
55-
BR2_PACKAGE_LIBSSH2_OPENSSL=y
56-
BR2_PACKAGE_LIBXCRYPT=y
5755
BR2_PACKAGE_LIBOPENSSL_BIN=y
5856
BR2_PACKAGE_LIBCURL_CURL=y
5957
BR2_PACKAGE_LIBMNL=y
@@ -83,6 +81,7 @@ BR2_PACKAGE_TCPDUMP=y
8381
BR2_PACKAGE_WHOIS=y
8482
BR2_PACKAGE_BASH_COMPLETION=y
8583
BR2_PACKAGE_SUDO=y
84+
BR2_PACKAGE_GETENT=y
8685
BR2_PACKAGE_KMOD_TOOLS=y
8786
BR2_PACKAGE_PWGEN=y
8887
BR2_PACKAGE_RAUC=y
@@ -123,7 +122,6 @@ BR2_PACKAGE_CONFD=y
123122
BR2_PACKAGE_CONFD_TEST_MODE=y
124123
BR2_PACKAGE_GENCERT=y
125124
BR2_PACKAGE_STATD=y
126-
BR2_PACKAGE_SHOW=y
127125
BR2_PACKAGE_FACTORY=y
128126
BR2_PACKAGE_FINIT_PLUGIN_HOTPLUG=y
129127
BR2_PACKAGE_FINIT_PLUGIN_HOOK_SCRIPTS=y
@@ -139,9 +137,9 @@ BR2_PACKAGE_KLISH_PLUGIN_INFIX=y
139137
BR2_PACKAGE_LOWDOWN=y
140138
BR2_PACKAGE_MCD=y
141139
BR2_PACKAGE_MDNS_ALIAS=y
140+
BR2_PACKAGE_SHOW=y
142141
BR2_PACKAGE_ROUSETTE=y
143142
BR2_PACKAGE_RAUC_INSTALLATION_STATUS=y
144-
BR2_DOWNLOAD_FORCE_CHECK_HASHES=y
145143
TRUSTED_KEYS=y
146144
TRUSTED_KEYS_DEVELOPMENT=y
147145
GNS3_APPLIANCE_RAM=512

src/confd/src/ietf-system.c

Lines changed: 0 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ struct sr_change {
3838
sr_val_t *new;
3939
};
4040

41-
static char *ver = NULL;
42-
static char *rel = NULL;
43-
static char *sys = NULL;
44-
static char *os = NULL;
4541
static char *nm = NULL;
4642
static char *id = NULL;
4743

@@ -90,17 +86,9 @@ static void setvar(const char *line, const char *key, char **var)
9086

9187
static void os_init(void)
9288
{
93-
struct utsname uts;
9489
char line[80];
9590
FILE *fp;
9691

97-
if (!uname(&uts)) {
98-
os = strdup(uts.sysname);
99-
ver = strdup(uts.release);
100-
rel = strdup(uts.release);
101-
sys = strdup(uts.machine);
102-
}
103-
10492
fp = fopen("/etc/os-release", "r");
10593
if (!fp) {
10694
fp = fopen("/usr/lib/os-release", "r");
@@ -110,36 +98,12 @@ static void os_init(void)
11098

11199
while (fgets(line, sizeof(line), fp)) {
112100
line[strlen(line) - 1] = 0; /* drop \n */
113-
setvar(line, "NAME", &os);
114-
setvar(line, "VERSION_ID", &ver);
115-
setvar(line, "BUILD_ID", &rel);
116-
setvar(line, "ARCHITECTURE", &sys);
117101
setvar(line, "DEFAULT_HOSTNAME", &nm);
118102
setvar(line, "ID", &id);
119103
}
120104
fclose(fp);
121105
}
122106

123-
static char *fmtime(time_t t, char *buf, size_t len)
124-
{
125-
const char *isofmt = "%FT%T%z";
126-
struct tm tm;
127-
size_t i, n;
128-
129-
tzset();
130-
localtime_r(&t, &tm);
131-
n = strftime(buf, len, isofmt, &tm);
132-
i = n - 5;
133-
if (buf[i] == '+' || buf[i] == '-') {
134-
buf[i + 6] = buf[i + 5];
135-
buf[i + 5] = buf[i + 4];
136-
buf[i + 4] = buf[i + 3];
137-
buf[i + 3] = ':';
138-
}
139-
140-
return buf;
141-
}
142-
143107
static sr_error_t _sr_change_iter(sr_session_ctx_t *session, struct confd *confd, char *xpath,
144108
sr_error_t cb(sr_session_ctx_t *, struct confd *, struct sr_change *))
145109
{
@@ -165,71 +129,6 @@ static sr_error_t _sr_change_iter(sr_session_ctx_t *session, struct confd *confd
165129
return SR_ERR_OK;
166130
}
167131

168-
static int clock_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
169-
const char *path, const char *request_path, uint32_t request_id,
170-
struct lyd_node **parent, void *priv)
171-
{
172-
static char boottime[64] = { 0 };
173-
const struct ly_ctx *ctx;
174-
char curtime[64];
175-
time_t now, boot;
176-
int rc;
177-
178-
ctx = sr_acquire_context(sr_session_get_connection(session));
179-
180-
now = time(NULL);
181-
if (!boottime[0]) {
182-
struct sysinfo si;
183-
184-
sysinfo(&si);
185-
boot = now - si.uptime;
186-
fmtime(boot, boottime, sizeof(boottime));
187-
}
188-
fmtime(now, curtime, sizeof(curtime));
189-
190-
if ((rc = lydx_new_path(ctx, parent, CLOCK_PATH_, "boot-datetime", "%s", boottime)))
191-
goto fail;
192-
if ((rc = lydx_new_path(ctx, parent, CLOCK_PATH_, "current-datetime", "%s", curtime)))
193-
goto fail;
194-
195-
if (rc) {
196-
fail:
197-
ERROR("Failed building data tree, libyang error %d", rc);
198-
rc = SR_ERR_INTERNAL;
199-
}
200-
201-
sr_release_context(sr_session_get_connection(session));
202-
return rc;
203-
}
204-
205-
static int platform_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
206-
const char *path, const char *request_path, uint32_t request_id,
207-
struct lyd_node **parent, void *priv)
208-
{
209-
const struct ly_ctx *ctx;
210-
int rc;
211-
212-
ctx = sr_acquire_context(sr_session_get_connection(session));
213-
214-
if ((rc = lydx_new_path(ctx, parent, PLATFORM_PATH_, "os-name", "%s", os)))
215-
goto fail;
216-
if ((rc = lydx_new_path(ctx, parent, PLATFORM_PATH_, "os-release", "%s", rel)))
217-
goto fail;
218-
if ((rc = lydx_new_path(ctx, parent, PLATFORM_PATH_, "os-version", "%s", ver)))
219-
goto fail;
220-
if ((rc = lydx_new_path(ctx, parent, PLATFORM_PATH_, "machine", "%s", sys)))
221-
goto fail;
222-
223-
if (rc) {
224-
fail:
225-
ERROR("Failed building data tree, libyang error %d", rc);
226-
rc = SR_ERR_INTERNAL;
227-
}
228-
229-
sr_release_context(sr_session_get_connection(session));
230-
return rc;
231-
}
232-
233132
static int rpc_exec(sr_session_ctx_t *session, uint32_t sub_id, const char *path,
234133
const sr_val_t *input, const size_t input_cnt,
235134
sr_event_t event, unsigned request_id,
@@ -1408,30 +1307,6 @@ static int change_auth(sr_session_ctx_t *session, uint32_t sub_id, const char *m
14081307
return SR_ERR_OK;
14091308
}
14101309

1411-
static int auth_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
1412-
const char *path, const char *request_path, uint32_t request_id,
1413-
struct lyd_node **parent, void *priv)
1414-
{
1415-
const char *fmt = "/ietf-system:system/authentication/user[name='%s']/password";
1416-
struct spwd *spwd;
1417-
1418-
setspent();
1419-
while ((spwd = getspent())) {
1420-
char xpath[256];
1421-
1422-
/* Skip any records that do not pass YANG validation */
1423-
if (!spwd->sp_pwdp || spwd->sp_pwdp[0] == '0' ||
1424-
spwd->sp_pwdp[0] == '*' || spwd->sp_pwdp[0] == '!')
1425-
continue;
1426-
1427-
snprintf(xpath, sizeof(xpath), fmt, spwd->sp_namp);
1428-
lyd_new_path(*parent, NULL, xpath, spwd->sp_pwdp, 0, 0);
1429-
}
1430-
endspent();
1431-
1432-
return SR_ERR_OK;
1433-
}
1434-
14351310
static int change_nacm(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
14361311
const char *_, sr_event_t event, unsigned request_id, void *priv)
14371312
{
@@ -1773,46 +1648,24 @@ static int change_hostname(sr_session_ctx_t *session, uint32_t sub_id, const cha
17731648
return SR_ERR_OK;
17741649
}
17751650

1776-
static int hostname_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
1777-
const char *path, const char *request_path, uint32_t request_id,
1778-
struct lyd_node **parent, void *priv)
1779-
{
1780-
char hostname[128];
1781-
int rc;
1782-
1783-
gethostname(hostname, sizeof(hostname));
1784-
rc = lyd_new_path(*parent, NULL, path, hostname, 0, NULL);
1785-
if (rc) {
1786-
ERROR("Failed building data tree, libyang error %d", rc);
1787-
rc = SR_ERR_INTERNAL;
1788-
}
1789-
1790-
return rc;
1791-
}
1792-
17931651
int ietf_system_init(struct confd *confd)
17941652
{
17951653
int rc;
17961654

17971655
os_init();
17981656

17991657
REGISTER_CHANGE(confd->session, "ietf-system", XPATH_AUTH_, 0, change_auth, confd, &confd->sub);
1800-
REGISTER_OPER(confd->session, "ietf-system", PASSWORD_PATH, auth_cb, confd, 0, &confd->sub);
18011658
REGISTER_MONITOR(confd->session, "ietf-netconf-acm", "/ietf-netconf-acm:nacm//.",
18021659
0, change_nacm, confd, &confd->sub);
18031660

18041661
REGISTER_CHANGE(confd->session, "ietf-system", XPATH_BASE_"/hostname", 0, change_hostname, confd, &confd->sub);
1805-
REGISTER_OPER(confd->session, "ietf-system", XPATH_BASE_"/hostname", hostname_cb, confd, 0, &confd->sub);
18061662
REGISTER_CHANGE(confd->session, "ietf-system", XPATH_BASE_"/infix-system:motd", 0, change_motd, confd, &confd->sub);
18071663
REGISTER_CHANGE(confd->session, "ietf-system", XPATH_BASE_"/infix-system:motd-banner", 0, change_motd_banner, confd, &confd->sub);
18081664
REGISTER_CHANGE(confd->session, "ietf-system", XPATH_BASE_"/infix-system:text-editor", 0, change_editor, confd, &confd->sub);
18091665
REGISTER_CHANGE(confd->session, "ietf-system", XPATH_BASE_"/clock", 0, change_clock, confd, &confd->sub);
18101666
REGISTER_CHANGE(confd->session, "ietf-system", XPATH_BASE_"/ntp", 0, change_ntp, confd, &confd->sub);
18111667
REGISTER_CHANGE(confd->session, "ietf-system", XPATH_BASE_"/dns-resolver", 0, change_dns, confd, &confd->sub);
18121668

1813-
REGISTER_OPER(confd->session, "ietf-system", CLOCK_PATH_, clock_cb, NULL, 0, &confd->sub);
1814-
REGISTER_OPER(confd->session, "ietf-system", PLATFORM_PATH_, platform_cb, NULL, 0, &confd->sub);
1815-
18161669
REGISTER_RPC(confd->session, "/ietf-system:system-restart", rpc_exec, "reboot", &confd->sub);
18171670
REGISTER_RPC(confd->session, "/ietf-system:system-shutdown", rpc_exec, "poweroff", &confd->sub);
18181671
REGISTER_RPC(confd->session, "/ietf-system:set-current-datetime", rpc_set_datetime, NULL, &confd->sub);

src/statd/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Introduction
2+
Statd is designed to be integrated into Infix and supply the operational
3+
database with data. To do this it uses companion binaries written in
4+
python, these are located in the `python` directory.
5+
6+
7+
## Run outside Infix
8+
### Prerequisites
9+
There are some requirements set on your computer to run statd locally.
10+
11+
- An Ubuntu based system
12+
- lldpd
13+
- python3
14+
- [libite](https://github.com/troglobit/libite)
15+
- [libsrx](https://github.com/kernelkit/infix/tree/main/src/libsrx)
16+
- python-poetry
17+
- [sysrepo](https://github.com/sysrepo/sysrepo) (At least the same version as Infix)
18+
- [libyang](https://github.com/CESNET/libyang) (At least the same version as Infix)
19+
20+
21+
### Install YANG modules in local sysrepo
22+
This requires that you first build Infix, since netopeer2 and sysrepo are responsible
23+
for installing their own YANG files.
24+
25+
```bash
26+
user@host ~/infix$ export TARGET_DIR="output/target/"
27+
user@host ~/infix$ export NETOPEER2_SEARCHPATH=$TARGET_DIR/usr/share/yang/modules/netopeer2/
28+
user@host ~/infix$ export SYSREPO_SEARCHPATH=$TARGET_DIR/usr/share/yang/modules/sysrepo/
29+
user@host ~/infix$ export LIBNETCONF2_SEARCHPATH=$TARGET_DIR/usr/share/yang/modules/libnetconf2/
30+
user@host ~/infix$ export CONFD_SEARCHPATH=$TARGET_DIR/usr/share/yang/modules/confd/
31+
user@host ~/infix$ export TEST_MODE_SEARCHPATH=$TARGET_DIR/usr/share/yang/modules/test-mode/
32+
user@host ~/infix$ export ROUSETTE_SEARCHPATH=$TARGET_DIR/usr/share/yang/modules/rousette/
33+
user@host ~/infix$ export SEARCH_PATH="$NETOPEER2_SEARCHPATH $SYSREPO_SEARCHPATH $LIBNETCONF2_SEARCHPATH $CONFD_SEARCHPATH $TEST_MODE_SEARCHPATH $ROUSETTE_SEARCHPATH"
34+
35+
user@host ~/infix$ ./utils/srload src/confd/yang/sysrepo.inc
36+
user@host ~/infix$ ./utils/srload src/confd/yang/libnetconf2.inc
37+
user@host ~/infix$ ./utils/srload src/confd/yang/netopeer2.inc
38+
user@host ~/infix$ ./utils/srload src/confd/yang/confd.inc
39+
user@host ~/infix$ ./utils/srload src/confd/yang/rousette.inc
40+
user@host ~/infix$ ./utils/srload src/confd/yang/test-mode.inc
41+
```
42+
43+
### Build and install python companion binaries
44+
```bash
45+
user@host ~/infix/src/statd/python$ ./local_install.sh
46+
```
47+
This will install the binaries in ~/.local/bin
48+
49+
### Build and install statd
50+
51+
```bash
52+
user@host ~/infix/src/statd$ ./configure --with-yanger-dir=$HOME/.local/bin
53+
user@host ~/infix/src/statd$ make
54+
user@host ~/infix/src/statd$ sudo make install
55+
```
56+
57+
### Running statd
58+
Since the `yanger` binary, for example, reads the shadow database, you
59+
can expect different results if running `statd` as root or not.
60+
```bash
61+
user@host ~/infix/src/statd$ statd
62+
```

src/statd/configure.ac

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ AC_ARG_ENABLE(containers,
1717
AS_HELP_STRING([--enable-containers], [Enable support for containers]),,[
1818
enable_containers=no])
1919

20+
AC_ARG_WITH([yanger-dir],
21+
[AS_HELP_STRING([--with-yanger-dir=DIR],
22+
[specify the path to yanger])],
23+
[YANGER_DIR="$withval"],
24+
[YANGER_DIR="/usr/libexec/statd"])
25+
26+
# Define YANGER_DIR for use in C code
27+
AC_DEFINE_UNQUOTED([YANGER_DIR], ["$YANGER_DIR"], [Path to yanger])
28+
2029
# C defines
2130
AS_IF([test "x$enable_containers" = "xyes"], [
2231
AC_DEFINE(CONTAINERS, 1, [Built with container support])])
@@ -73,6 +82,7 @@ cat <<EOF
7382
Exec prefix...........: $eprefix
7483
Sysconfdir............: `eval echo $sysconfdir`
7584
Localstatedir.........: `eval echo $localstatedir`
85+
Yangerdir.............: $YANGER_DIR
7686
Default fstab.........: `eval echo $fstab`
7787
System environment....: ${sysconfig_path:-${sysconfig}}
7888
C Compiler............: $CC $CFLAGS $CPPFLAGS $LDFLAGS $LIBS

0 commit comments

Comments
 (0)