--- /dev/null
+/*#############################################################################
+# #
+# IPFire.org - A linux based firewall #
+# Copyright (C) 2023 IPFire Network Development Team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#ifndef NETWORKD_ADDRESS_H
+#define NETWORKD_ADDRESS_H
+
+#include <netinet/ether.h>
+#include <string.h>
+
+typedef struct ether_addr nw_address_t;
+
+static inline int nw_address_from_string(nw_address_t* addr, const char* s) {
+ struct ether_addr* p = ether_aton_r(s, addr);
+ if (!p)
+ return 1;
+
+ return 0;
+}
+
+static inline char* nw_address_to_string(const nw_address_t* addr) {
+ char buffer[ETH_ALEN];
+
+ char* p = ether_ntoa_r(addr, buffer);
+ if (!p)
+ return NULL;
+
+ return strdup(buffer);
+}
+
+#endif /* NETWORKD_ADDRESS_H */
#include <limits.h>
#include <net/if.h>
+#include <stdint.h>
#include <stdlib.h>
+#include "address.h"
#include "config.h"
#include "logging.h"
#include "string.h"
// Configuration
struct nw_config *config;
+
+ // Common attributes
+ nw_address_t address;
};
static const struct nw_port_type_map {
free(port);
}
+static int nw_port_setup_address(struct nw_port* port) {
+ int r;
+
+ // Read ADDRESS from configuration
+ const char* s = nw_config_get(port->config, "ADDRESS");
+ if (!s) {
+ ERROR("Port %s: Address isn't set\n", port->name);
+ return 1;
+ }
+
+ // Parse the address
+ r = nw_address_from_string(&port->address, s);
+ if (r) {
+ ERROR("Port %s: Could not parse address: %m\n", port->name);
+ return r;
+ }
+
+ // XXX Do we need to check for multicast here?
+
+ return 0;
+}
+
static int nw_port_setup_common(struct nw_port* port) {
- return 0; // XXX TODO
+ int r;
+
+ // Address
+ r = nw_port_setup_address(port);
+ if (r)
+ return r;
+
+ return 0;
}
static nw_port_type_t nw_port_setup_type(struct nw_port* port) {