summaryrefslogtreecommitdiffstats
path: root/src/net
diff options
context:
space:
mode:
authorMichael Brown2011-03-22 17:56:35 +0100
committerMichael Brown2011-03-22 20:54:58 +0100
commitf5fd4dec3bab362a2ff7844859914e1f191fb905 (patch)
tree607eacef2f79c016a0c3c3031de2bb7d8aa7e331 /src/net
parent[forcedeth] Clear the MII link status register on link status changes (diff)
downloadipxe-f5fd4dec3bab362a2ff7844859914e1f191fb905.tar.gz
ipxe-f5fd4dec3bab362a2ff7844859914e1f191fb905.tar.xz
ipxe-f5fd4dec3bab362a2ff7844859914e1f191fb905.zip
[settings] Formalise notion of setting applicability
Expose a function setting_applies() to allow a caller to determine whether or not a particular setting is applicable to a particular settings block. Restrict DHCP-backed settings blocks to accepting only DHCP-based settings. Restrict network device settings blocks to accepting only DHCP-based settings and network device-specific settings such as "mac". Inspired-by: Glenn Brown <glenn@myri.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/net')
-rw-r--r--src/net/80211/net80211.c3
-rw-r--r--src/net/dhcpopts.c12
-rw-r--r--src/net/dhcppkt.c29
-rw-r--r--src/net/netdev_settings.c18
4 files changed, 62 insertions, 0 deletions
diff --git a/src/net/80211/net80211.c b/src/net/80211/net80211.c
index d39958ba7..c42928e8a 100644
--- a/src/net/80211/net80211.c
+++ b/src/net/80211/net80211.c
@@ -206,6 +206,7 @@ struct setting net80211_ssid_setting __setting = {
.name = "ssid",
.description = "802.11 SSID (network name)",
.type = &setting_type_string,
+ .tag = NET80211_SETTING_TAG_SSID,
};
/** Whether to use active scanning
@@ -218,6 +219,7 @@ struct setting net80211_active_setting __setting = {
.name = "active-scan",
.description = "Use an active scan during 802.11 association",
.type = &setting_type_int8,
+ .tag = NET80211_SETTING_TAG_ACTIVE_SCAN,
};
/** The cryptographic key to use
@@ -230,6 +232,7 @@ struct setting net80211_key_setting __setting = {
.name = "key",
.description = "Encryption key for protected 802.11 networks",
.type = &setting_type_string,
+ .tag = NET80211_SETTING_TAG_KEY,
};
/** @} */
diff --git a/src/net/dhcpopts.c b/src/net/dhcpopts.c
index f04b8e712..249fde151 100644
--- a/src/net/dhcpopts.c
+++ b/src/net/dhcpopts.c
@@ -348,6 +348,18 @@ static int set_dhcp_option ( struct dhcp_options *options, unsigned int tag,
}
/**
+ * Check applicability of DHCP option setting
+ *
+ * @v tag Setting tag number
+ * @ret applies Setting applies to this option block
+ */
+int dhcpopt_applies ( unsigned int tag ) {
+
+ return ( tag && ( tag <= DHCP_ENCAP_OPT ( DHCP_MAX_OPTION,
+ DHCP_MAX_OPTION ) ) );
+}
+
+/**
* Store value of DHCP option setting
*
* @v options DHCP option block
diff --git a/src/net/dhcppkt.c b/src/net/dhcppkt.c
index 237c3e2cf..0a0e458fc 100644
--- a/src/net/dhcppkt.c
+++ b/src/net/dhcppkt.c
@@ -135,6 +135,19 @@ find_dhcp_packet_field ( unsigned int tag ) {
}
/**
+ * Check applicability of DHCP setting
+ *
+ * @v dhcppkt DHCP packet
+ * @v tag Setting tag number
+ * @ret applies Setting applies within this settings block
+ */
+static int dhcppkt_applies ( struct dhcp_packet *dhcppkt __unused,
+ unsigned int tag ) {
+
+ return dhcpopt_applies ( tag );
+}
+
+/**
* Store value of DHCP packet setting
*
* @v dhcppkt DHCP packet
@@ -205,6 +218,21 @@ int dhcppkt_fetch ( struct dhcp_packet *dhcppkt, unsigned int tag,
*/
/**
+ * Check applicability of DHCP setting
+ *
+ * @v settings Settings block
+ * @v setting Setting
+ * @ret applies Setting applies within this settings block
+ */
+static int dhcppkt_settings_applies ( struct settings *settings,
+ struct setting *setting ) {
+ struct dhcp_packet *dhcppkt =
+ container_of ( settings, struct dhcp_packet, settings );
+
+ return dhcppkt_applies ( dhcppkt, setting->tag );
+}
+
+/**
* Store value of DHCP setting
*
* @v settings Settings block
@@ -242,6 +270,7 @@ static int dhcppkt_settings_fetch ( struct settings *settings,
/** DHCP settings operations */
static struct settings_operations dhcppkt_settings_operations = {
+ .applies = dhcppkt_settings_applies,
.store = dhcppkt_settings_store,
.fetch = dhcppkt_settings_fetch,
};
diff --git a/src/net/netdev_settings.c b/src/net/netdev_settings.c
index f641d3b21..2ff4ad3e3 100644
--- a/src/net/netdev_settings.c
+++ b/src/net/netdev_settings.c
@@ -22,6 +22,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <errno.h>
#include <byteswap.h>
#include <ipxe/dhcp.h>
+#include <ipxe/dhcpopts.h>
#include <ipxe/settings.h>
#include <ipxe/device.h>
#include <ipxe/netdevice.h>
@@ -37,14 +38,30 @@ struct setting mac_setting __setting = {
.name = "mac",
.description = "MAC address",
.type = &setting_type_hex,
+ .tag = NETDEV_SETTING_TAG_MAC,
};
struct setting busid_setting __setting = {
.name = "busid",
.description = "Bus ID",
.type = &setting_type_hex,
+ .tag = NETDEV_SETTING_TAG_BUS_ID,
};
/**
+ * Check applicability of network device setting
+ *
+ * @v settings Settings block
+ * @v setting Setting
+ * @ret applies Setting applies within this settings block
+ */
+static int netdev_applies ( struct settings *settings __unused,
+ struct setting *setting ) {
+
+ return ( IS_NETDEV_SETTING_TAG ( setting->tag ) ||
+ dhcpopt_applies ( setting->tag ) );
+}
+
+/**
* Store value of network device setting
*
* @v settings Settings block
@@ -114,6 +131,7 @@ static void netdev_clear ( struct settings *settings ) {
/** Network device configuration settings operations */
struct settings_operations netdev_settings_operations = {
+ .applies = netdev_applies,
.store = netdev_store,
.fetch = netdev_fetch,
.clear = netdev_clear,