From 2e73d643eddce0d90c8f37e91881e15d6fdfa66f Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 16 Apr 2023 12:22:37 +0200 Subject: [PATCH] src/confd: add support for ietf-ip:ipv4/forwarding Signed-off-by: Joachim Wiberg --- src/confd/src/helpers.c | 20 ++++++++++++++++++++ src/confd/src/helpers.h | 1 + src/confd/src/ietf-interfaces.c | 3 +++ 3 files changed, 24 insertions(+) diff --git a/src/confd/src/helpers.c b/src/confd/src/helpers.c index f08fd0bf..1338c731 100644 --- a/src/confd/src/helpers.c +++ b/src/confd/src/helpers.c @@ -3,6 +3,26 @@ #include #include "core.h" +/* + * Write interger value to a file composed from fmt and optional args. + */ +int writedf(int value, const char *fmt, ...) +{ + va_list ap; + int rc = -1; + FILE *fp; + + va_start(ap, fmt); + fp = fopenf("w", fmt, ap); + if (fp) { + fprintf(fp, "%d\n", value); + rc = fclose(fp); + } + va_end(ap); + + return rc; +} + /* * Write str to a file composed from fmt and optional args. */ diff --git a/src/confd/src/helpers.h b/src/confd/src/helpers.h index 05a2fa22..87ea93c6 100644 --- a/src/confd/src/helpers.h +++ b/src/confd/src/helpers.h @@ -3,6 +3,7 @@ #ifndef CONFD_HELPERS_H_ #define CONFD_HELPERS_H_ +int writedf(int value, const char *fmt, ...); int writesf(const char *str, const char *fmt, ...); #endif /* CONFD_HELPERS_H_ */ diff --git a/src/confd/src/ietf-interfaces.c b/src/confd/src/ietf-interfaces.c index a9802fff..5e8aab35 100644 --- a/src/confd/src/ietf-interfaces.c +++ b/src/confd/src/ietf-interfaces.c @@ -61,6 +61,9 @@ static int ifchange(sr_session_ctx_t *session, uint32_t sub_id, const char *modu writesf(ptr, "/sys/class/net/%s/ifalias", ifname); free(ptr); + writedf(srx_enabled(session, "%s/ietf-ip:ipv4/forwarding", xpath), + "/proc/sys/net/ipv4/conf/%s/forwarding", ifname); + systemf("ip addr flush dev %s", ifname); snprintf(path, sizeof(path), "%s/ietf-ip:ipv4/address", xpath);