src/confd: add support for ietf-ip:ipv4/forwarding

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-04-17 14:09:24 +02:00
parent a7306d0c06
commit 2e73d643ed
3 changed files with 24 additions and 0 deletions
+20
View File
@@ -3,6 +3,26 @@
#include <stdarg.h>
#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.
*/
+1
View File
@@ -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_ */
+3
View File
@@ -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);