return 0;
}
+const char* nw_config_get(struct nw_config* config, const char* key) {
+ struct nw_config_entry* entry = nw_config_find(config, key);
+
+ // Return the value if found and set
+ if (entry && *entry->value)
+ return entry->value;
+
+ // Otherwise return NULL
+ return NULL;
+}
+
int nw_config_set(struct nw_config* config, const char* key, const char* value) {
struct nw_config_entry* entry = NULL;
return nw_string_set(entry->value, value);
}
-const char* nw_config_get(struct nw_config* config, const char* key) {
- struct nw_config_entry* entry = nw_config_find(config, key);
-
- // Return the value if found and set
- if (entry && *entry->value)
- return entry->value;
-
- // Otherwise return NULL
- return NULL;
-}
-
-unsigned int nw_config_get_unsigned_int(struct nw_config* config, const char* key) {
+int nw_config_get_int(struct nw_config* config, const char* key, const int __default) {
const char* value = nw_config_get(config, key);
// Return zero if not set
if (!value)
- return 0;
+ return __default;
return strtoul(value, NULL, 10);
}
+
+int nw_config_set_int(struct nw_config* config, const char* key, const int value) {
+ char __value[1024];
+ int r;
+
+ // Format the value as string
+ r = nw_string_format(__value, "%d\n", value);
+ if (r)
+ return r;
+
+ return nw_config_set(config, key, __value);
+}
int nw_config_del(struct nw_config* config, const char* key);
+const char* nw_config_get(struct nw_config* config, const char* key);
int nw_config_set(struct nw_config* config, const char* key, const char* value);
-const char* nw_config_get(struct nw_config* config, const char* key);
-unsigned int nw_config_get_unsigned_int(struct nw_config* config, const char* key);
+int nw_config_get_int(struct nw_config* config, const char* key, const int __default);
+int nw_config_set_int(struct nw_config* config, const char* key, const int value);
#endif /* NETWORKD_CONFIG_H */
# #
#############################################################################*/
+#include <errno.h>
+
#include "bus.h"
#include "daemon.h"
#include "logging.h"
return 1;
}
+/*
+ MTU
+*/
+static int nw_zone_bus_get_mtu(sd_bus* bus, const char *path, const char *interface,
+ const char* property, sd_bus_message* reply, void* data, sd_bus_error *error) {
+ struct nw_zone* zone = (struct nw_zone*)data;
+
+ return sd_bus_message_append(reply, "u", nw_zone_mtu(zone));
+}
+
+static int nw_zone_bus_set_mtu(sd_bus* bus, const char* path, const char* interface,
+ const char* property, sd_bus_message* value, void* data, sd_bus_error* error) {
+ unsigned int mtu = 0;
+ int r;
+
+ struct nw_zone* zone = (struct nw_zone*)data;
+
+ // Parse the value
+ r = sd_bus_message_read(value, "u", &mtu);
+ if (r < 0)
+ return r;
+
+ if (!nw_zone_set_mtu(zone, mtu))
+ return -errno;
+
+ return 0;
+}
+
static const sd_bus_vtable zone_vtable[] = {
SD_BUS_VTABLE_START(0),
+ // MTU
+ SD_BUS_WRITABLE_PROPERTY("MTU", "u", nw_zone_bus_get_mtu, nw_zone_bus_set_mtu,
+ 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+
SD_BUS_VTABLE_END
};
#include <systemd/sd-bus.h>
#include "config.h"
+#include "logging.h"
#include "string.h"
#include "zone.h"
return p;
}
+
+/*
+ MTU
+*/
+unsigned int nw_zone_mtu(struct nw_zone* zone) {
+ return nw_config_get_int(zone->config, "MTU", NETWORK_ZONE_DEFAULT_MTU);
+}
+
+int nw_zone_set_mtu(struct nw_zone* zone, unsigned int mtu) {
+ DEBUG("Change MTU of %s to %u\n", zone->name, mtu);
+
+ return nw_config_set_int(zone->config, "MTU", mtu);
+}
#define NETWORKD_ZONE_H
#define NETWORK_ZONE_NAME_MAX_LENGTH 16
+#define NETWORK_ZONE_DEFAULT_MTU 1500
struct nw_zone;
char* nw_zone_bus_path(struct nw_zone* zone);
+/*
+ MTU
+*/
+unsigned int nw_zone_mtu(struct nw_zone* zone);
+int nw_zone_set_mtu(struct nw_zone* zone, unsigned int mtu);
+
#endif /* NETWORKD_ZONE_H */