summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
d6166b4)
This change moves the interface configuration into its own 'struct
interface_config'. We also remove the _config suffix from the network
and interface members.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-static const struct network_config *find_config_by_hwaddr(
+static const struct interface_config *find_config_by_hwaddr(
uint8_t *hwaddr)
{
const struct config *config;
uint8_t *hwaddr)
{
const struct config *config;
if (!config)
return NULL;
if (!config)
return NULL;
- for (i = 0; i < config->n_network_configs; i++) {
- struct network_config *netconf = config->network_configs[i];
+ for (i = 0; i < config->network.n_interfaces; i++) {
+ struct interface_config *ifconf = config->network.interfaces[i];
- if (!memcmp(netconf->hwaddr, hwaddr, HWADDR_SIZE))
- return netconf;
+ if (!memcmp(ifconf->hwaddr, hwaddr, HWADDR_SIZE))
+ return ifconf;
static void configure_interface_static(struct network *network,
struct interface *interface,
static void configure_interface_static(struct network *network,
struct interface *interface,
- const struct network_config *config)
+ const struct interface_config *config)
{
const char *addr_argv[] = {
pb_system_apps.ip,
{
const char *addr_argv[] = {
pb_system_apps.ip,
static void configure_interface(struct network *network,
struct interface *interface, bool up, bool link)
{
static void configure_interface(struct network *network,
struct interface *interface, bool up, bool link)
{
- const struct network_config *config = NULL;
+ const struct interface_config *config = NULL;
if (interface->state == IFSTATE_IGNORED)
return;
if (interface->state == IFSTATE_IGNORED)
return;
static void config_set_defaults(struct config *config)
{
config->autoboot_enabled = true;
static void config_set_defaults(struct config *config)
{
config->autoboot_enabled = true;
- config->network_configs = NULL;
- config->n_network_configs = 0;
+ config->network.interfaces = NULL;
+ config->network.n_interfaces = 0;
}
static void dump_config(struct config *config)
}
static void dump_config(struct config *config)
if (config->n_network_configs > 0)
pb_log(" network configuration:\n");
if (config->n_network_configs > 0)
pb_log(" network configuration:\n");
- for (i = 0; i < config->n_network_configs; i++) {
- struct network_config *netconf = config->network_configs[i];
+ for (i = 0; i < config->network.n_interfaces; i++) {
+ struct interface_config *ifconf =
+ config->network.interfaces[i];
pb_log(" interface %02x:%02x:%02x:%02x:%02x:%02x\n",
pb_log(" interface %02x:%02x:%02x:%02x:%02x:%02x\n",
- netconf->hwaddr[0], netconf->hwaddr[1],
- netconf->hwaddr[2], netconf->hwaddr[3],
- netconf->hwaddr[4], netconf->hwaddr[5]);
+ ifconf->hwaddr[0], ifconf->hwaddr[1],
+ ifconf->hwaddr[2], ifconf->hwaddr[3],
+ ifconf->hwaddr[4], ifconf->hwaddr[5]);
pb_log(" ignore\n");
continue;
}
pb_log(" ignore\n");
continue;
}
- if (netconf->method == CONFIG_METHOD_DHCP) {
+ if (ifconf->method == CONFIG_METHOD_DHCP) {
- } else if (netconf->method == CONFIG_METHOD_STATIC) {
+ } else if (ifconf->method == CONFIG_METHOD_STATIC) {
- pb_log(" ip: %s\n", netconf->static_config.address);
- pb_log(" gw: %s\n", netconf->static_config.gateway);
- pb_log(" dns: %s\n", netconf->static_config.dns);
+ pb_log(" ip: %s\n", ifconf->static_config.address);
+ pb_log(" gw: %s\n", ifconf->static_config.gateway);
+struct interface_config {
uint8_t hwaddr[HWADDR_SIZE];
bool ignore;
enum {
uint8_t hwaddr[HWADDR_SIZE];
bool ignore;
enum {
+struct network_config {
+ struct interface_config **interfaces;
+ int n_interfaces;
+};
+
struct config {
bool autoboot_enabled;
struct config {
bool autoboot_enabled;
- struct network_config **network_configs;
- int n_network_configs;
+ struct network_config network;
-static int parse_hwaddr(struct network_config *config, char *str)
+static int parse_hwaddr(struct interface_config *ifconf, char *str)
if (endp != byte + 2)
return -1;
if (endp != byte + 2)
return -1;
- config->hwaddr[i] = x & 0xff;
+ ifconf->hwaddr[i] = x & 0xff;
-static int parse_one_network_config(struct network_config *config,
+static int parse_one_interface_config(struct config *config,
+ struct interface_config *ifconf;
+ ifconf = talloc(config, struct interface_config);
+
if (!confstr || !strlen(confstr))
if (!confstr || !strlen(confstr))
/* first token should be the mac address */
tok = strtok_r(confstr, ",", &saveptr);
if (!tok)
/* first token should be the mac address */
tok = strtok_r(confstr, ",", &saveptr);
if (!tok)
- if (parse_hwaddr(config, tok))
- return -1;
+ if (parse_hwaddr(ifconf, tok))
+ goto out_err;
/* second token is the method */
tok = strtok_r(NULL, ",", &saveptr);
if (!tok || !strlen(tok) || !strcmp(tok, "ignore")) {
/* second token is the method */
tok = strtok_r(NULL, ",", &saveptr);
if (!tok || !strlen(tok) || !strcmp(tok, "ignore")) {
- config->ignore = true;
- return 0;
- }
- if (!strcmp(tok, "dhcp")) {
- config->method = CONFIG_METHOD_DHCP;
+ } else if (!strcmp(tok, "dhcp")) {
+ ifconf->method = CONFIG_METHOD_DHCP;
} else if (!strcmp(tok, "static")) {
} else if (!strcmp(tok, "static")) {
- config->method = CONFIG_METHOD_STATIC;
+ ifconf->method = CONFIG_METHOD_STATIC;
/* ip/mask, [optional] gateway, [optional] dns */
tok = strtok_r(NULL, ",", &saveptr);
if (!tok)
/* ip/mask, [optional] gateway, [optional] dns */
tok = strtok_r(NULL, ",", &saveptr);
if (!tok)
- return -1;
- config->static_config.address =
- talloc_strdup(config, tok);
+ goto out_err;
+ ifconf->static_config.address =
+ talloc_strdup(ifconf, tok);
tok = strtok_r(NULL, ",", &saveptr);
if (tok) {
tok = strtok_r(NULL, ",", &saveptr);
if (tok) {
- config->static_config.gateway =
- talloc_strdup(config, tok);
+ ifconf->static_config.gateway =
+ talloc_strdup(ifconf, tok);
tok = strtok_r(NULL, ",", &saveptr);
}
if (tok) {
tok = strtok_r(NULL, ",", &saveptr);
}
if (tok) {
- config->static_config.dns =
+ ifconf->static_config.dns =
talloc_strdup(config, tok);
}
} else {
pb_log("Unknown network configuration method %s\n", tok);
talloc_strdup(config, tok);
}
} else {
pb_log("Unknown network configuration method %s\n", tok);
+ config->network.interfaces = talloc_realloc(config,
+ config->network.interfaces,
+ struct interface_config *,
+ ++config->network.n_interfaces);
+
+ config->network.interfaces[config->network.n_interfaces - 1] = ifconf;
+
+out_err:
+ talloc_free(ifconf);
+ return -1;
}
static void populate_network_config(struct powerpc_nvram_storage *nv,
}
static void populate_network_config(struct powerpc_nvram_storage *nv,
val = talloc_strdup(config, cval);
for (i = 0; ; i++) {
val = talloc_strdup(config, cval);
for (i = 0; ; i++) {
- struct network_config *netconf;
tok = strtok_r(i == 0 ? val : NULL, " ", &saveptr);
if (!tok)
break;
tok = strtok_r(i == 0 ? val : NULL, " ", &saveptr);
if (!tok)
break;
- netconf = talloc(nv, struct network_config);
-
- rc = parse_one_network_config(netconf, tok);
- if (rc) {
- talloc_free(netconf);
- continue;
- }
-
- config->network_configs = talloc_realloc(nv,
- config->network_configs,
- struct network_config *,
- ++config->n_network_configs);
+ parse_one_interface_config(config, tok);
- config->network_configs[config->n_network_configs - 1] =
- netconf;
#include "pb-config.h"
#include "storage.h"
#include "pb-config.h"
#include "storage.h"
-struct network_config net1 = {
+struct interface_config net1 = {
.hwaddr = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
.method = CONFIG_METHOD_DHCP,
};
.hwaddr = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
.method = CONFIG_METHOD_DHCP,
};
-struct network_config net2 = {
+struct interface_config net2 = {
.hwaddr = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x56 },
.method = CONFIG_METHOD_STATIC,
.static_config = {
.hwaddr = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x56 },
.method = CONFIG_METHOD_STATIC,
.static_config = {
-struct network_config *network_configs[] = { &net1, &net2 };
+struct interface_config *interface_configs[] = { &net1, &net2 };
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
struct config test_config = {
.autoboot_enabled = true,
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
struct config test_config = {
.autoboot_enabled = true,
- .network_configs = network_configs,
- .n_network_configs = ARRAY_SIZE(network_configs),
+ .network = {
+ .interfaces = interface_configs,
+ .n_interfaces = ARRAY_SIZE(interface_configs),
+ }