diff options
author | Michael Brown | 2008-03-21 23:15:31 +0100 |
---|---|---|
committer | Michael Brown | 2008-03-21 23:15:31 +0100 |
commit | 8afb36c3bc08ff0c9bdf0a8496cb08a8bfe287f3 (patch) | |
tree | 4369c087ca4c75593fe6d287fca658516d20a9d8 /src/include | |
parent | [DHCP] Kill off some no-longer-used DHCP functions (diff) | |
download | ipxe-8afb36c3bc08ff0c9bdf0a8496cb08a8bfe287f3.tar.gz ipxe-8afb36c3bc08ff0c9bdf0a8496cb08a8bfe287f3.tar.xz ipxe-8afb36c3bc08ff0c9bdf0a8496cb08a8bfe287f3.zip |
[Settings] Migrate DHCP and NVO code to the new settings API (untested)
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/gpxe/dhcp.h | 123 | ||||
-rw-r--r-- | src/include/gpxe/dhcpopts.h | 32 | ||||
-rw-r--r-- | src/include/gpxe/dhcppkt.h | 34 | ||||
-rw-r--r-- | src/include/gpxe/errfile.h | 1 | ||||
-rw-r--r-- | src/include/gpxe/nvo.h | 22 | ||||
-rw-r--r-- | src/include/gpxe/settings.h | 5 |
6 files changed, 102 insertions, 115 deletions
diff --git a/src/include/gpxe/dhcp.h b/src/include/gpxe/dhcp.h index fe9c3e38..c00f9f05 100644 --- a/src/include/gpxe/dhcp.h +++ b/src/include/gpxe/dhcp.h @@ -8,13 +8,15 @@ */ #include <stdint.h> -#include <gpxe/list.h> #include <gpxe/in.h> +#include <gpxe/list.h> #include <gpxe/refcnt.h> #include <gpxe/tables.h> struct net_device; struct job_interface; +struct dhcp_packet; +struct settings; /** BOOTP/DHCP server port */ #define BOOTPS_PORT 67 @@ -294,7 +296,7 @@ struct job_interface; /** Construct a word-valued DHCP option */ #define DHCP_WORD( value ) DHCP_OPTION ( ( ( (value) >> 8 ) & 0xff ), \ - ( ( (value) >> 0 ) & 0xff ) ) + ( ( (value) >> 0 ) & 0xff ) ) /** Construct a dword-valued DHCP option */ #define DHCP_DWORD( value ) DHCP_OPTION ( ( ( (value) >> 24 ) & 0xff ), \ @@ -327,21 +329,8 @@ struct dhcp_option { * byte in length. */ uint8_t len; - /** Option data - * - * Interpretation of the content is entirely dependent upon - * the tag. For fields containing a multi-byte integer, the - * field is defined to be in network-endian order (unless you - * are Intel and feel like violating the spec for fun). - */ - union { - uint8_t byte; - uint16_t word; - uint32_t dword; - struct in_addr in; - uint8_t bytes[0]; - char string[0]; - } data; + /** Option data */ + uint8_t data[0]; } __attribute__ (( packed )); /** @@ -355,27 +344,6 @@ struct dhcp_option { /** Maximum length for a single DHCP option */ #define DHCP_MAX_LEN 0xff -/** A DHCP options block */ -struct dhcp_option_block { - /** Reference counter */ - struct refcnt refcnt; - /** List of option blocks */ - struct list_head list; - /** Option block raw data */ - void *data; - /** Option block length */ - size_t len; - /** Option block maximum length */ - size_t max_len; - /** Block priority - * - * This is determined at the time of the call to - * register_options() by searching for the @c DHCP_EB_PRIORITY - * option. - */ - signed int priority; -}; - /** * A DHCP header * @@ -448,7 +416,7 @@ struct dhcphdr { * length (for the sake of sanity) is 1, to allow for a single * @c DHCP_END tag. */ - uint8_t options[1]; + uint8_t options[0]; }; /** Opcode for a request from client to server */ @@ -474,74 +442,17 @@ struct dhcphdr { */ #define DHCP_MIN_LEN 552 -/** - * A DHCP packet - * - */ -struct dhcp_packet { - /** The DHCP packet contents */ - struct dhcphdr *dhcphdr; - /** Maximum length of the DHCP packet buffer */ - size_t max_len; - /** Used length of the DHCP packet buffer */ - size_t len; - /** DHCP options */ - struct dhcp_option_block options; -}; - -/** - * Get reference to DHCP options block - * - * @v options DHCP options block - * @ret options DHCP options block - */ -static inline __attribute__ (( always_inline )) struct dhcp_option_block * -dhcpopt_get ( struct dhcp_option_block *options ) { - ref_get ( &options->refcnt ); - return options; -} - -/** - * Drop reference to DHCP options block - * - * @v options DHCP options block, or NULL - */ -static inline __attribute__ (( always_inline )) void -dhcpopt_put ( struct dhcp_option_block *options ) { - ref_put ( &options->refcnt ); -} - /** Maximum time that we will wait for ProxyDHCP offers */ #define PROXYDHCP_WAIT_TIME ( TICKS_PER_SEC * 1 ) -extern struct list_head dhcp_option_blocks; - -extern unsigned long dhcp_num_option ( struct dhcp_option *option ); -extern struct dhcp_option * -find_dhcp_option ( struct dhcp_option_block *options, unsigned int tag ); -extern void register_dhcp_options ( struct dhcp_option_block *options ); -extern void unregister_dhcp_options ( struct dhcp_option_block *options ); -extern void init_dhcp_options ( struct dhcp_option_block *options, - void *data, size_t max_len ); -extern struct dhcp_option_block * __malloc alloc_dhcp_options ( size_t max_len ); -extern struct dhcp_option * -set_dhcp_option ( struct dhcp_option_block *options, unsigned int tag, - const void *data, size_t len ); -extern unsigned long find_dhcp_num_option ( struct dhcp_option_block *options, - unsigned int tag ); -extern void delete_dhcp_option ( struct dhcp_option_block *options, - unsigned int tag ); - -extern int create_dhcp_request ( struct net_device *netdev, int msgtype, - struct dhcp_option_block *options, - void *data, size_t max_len, - struct dhcp_packet *dhcppkt ); -extern int create_dhcp_response ( struct net_device *netdev, int msgtype, - struct dhcp_option_block *options, - void *data, size_t max_len, - struct dhcp_packet *dhcppkt ); - -extern int start_dhcp ( struct job_interface *job, struct net_device *netdev, - int (*register_options) ( struct net_device *, - struct dhcp_option_block * )); +extern int create_dhcp_request ( struct dhcp_packet *dhcppkt, + struct net_device *netdev, int msgtype, + struct settings *offer_settings, + void *data, size_t max_len ); +extern int create_dhcp_response ( struct dhcp_packet *dhcppkt, + struct net_device *netdev, int msgtype, + struct settings *settings, + void *data, size_t max_len ); +extern int start_dhcp ( struct job_interface *job, struct net_device *netdev ); + #endif /* _GPXE_DHCP_H */ diff --git a/src/include/gpxe/dhcpopts.h b/src/include/gpxe/dhcpopts.h new file mode 100644 index 00000000..b16c5f22 --- /dev/null +++ b/src/include/gpxe/dhcpopts.h @@ -0,0 +1,32 @@ +#ifndef _GPXE_DHCPOPTS_H +#define _GPXE_DHCPOPTS_H + +/** @file + * + * DHCP options + * + */ + +#include <gpxe/dhcp.h> + +/** A DHCP options block */ +struct dhcp_options { + /** Option block raw data */ + void *data; + /** Option block length */ + size_t len; + /** Option block maximum length */ + size_t max_len; +}; + +extern int dhcpopt_store ( struct dhcp_options *options, unsigned int tag, + const void *data, size_t len ); +extern int dhcpopt_extensible_store ( struct dhcp_options *options, + unsigned int tag, + const void *data, size_t len ); +extern int dhcpopt_fetch ( struct dhcp_options *options, unsigned int tag, + void *data, size_t len ); +extern void dhcpopt_init ( struct dhcp_options *options, + void *data, size_t max_len ); + +#endif /* _GPXE_DHCPOPTS_H */ diff --git a/src/include/gpxe/dhcppkt.h b/src/include/gpxe/dhcppkt.h new file mode 100644 index 00000000..98b8dad8 --- /dev/null +++ b/src/include/gpxe/dhcppkt.h @@ -0,0 +1,34 @@ +#ifndef _GPXE_DHCPPKT_H +#define _GPXE_DHCPPKT_H + +/** @file + * + * DHCP packets + * + */ + +#include <gpxe/dhcp.h> +#include <gpxe/dhcpopts.h> +#include <gpxe/settings.h> + +/** + * A DHCP packet + * + */ +struct dhcp_packet { + /** Settings block */ + struct settings settings; + /** The DHCP packet contents */ + struct dhcphdr *dhcphdr; + /** Maximum length of the DHCP packet buffer */ + size_t max_len; + /** Used length of the DHCP packet buffer */ + size_t len; + /** DHCP option blocks */ + struct dhcp_options options; +}; + +extern void dhcppkt_init ( struct dhcp_packet *dhcppkt, struct refcnt *refcnt, + void *data, size_t len ); + +#endif /* _GPXE_DHCPPKT_H */ diff --git a/src/include/gpxe/errfile.h b/src/include/gpxe/errfile.h index 0b3b6c42..ae8b1480 100644 --- a/src/include/gpxe/errfile.h +++ b/src/include/gpxe/errfile.h @@ -130,6 +130,7 @@ #define ERRFILE_tftp ( ERRFILE_NET | 0x00120000 ) #define ERRFILE_infiniband ( ERRFILE_NET | 0x00130000 ) #define ERRFILE_netdev_settings ( ERRFILE_NET | 0x00140000 ) +#define ERRFILE_dhcppkt ( ERRFILE_NET | 0x00150000 ) #define ERRFILE_image ( ERRFILE_IMAGE | 0x00000000 ) #define ERRFILE_elf ( ERRFILE_IMAGE | 0x00010000 ) diff --git a/src/include/gpxe/nvo.h b/src/include/gpxe/nvo.h index 90d4ff9b..28068f4b 100644 --- a/src/include/gpxe/nvo.h +++ b/src/include/gpxe/nvo.h @@ -8,9 +8,11 @@ */ #include <stdint.h> +#include <gpxe/dhcpopts.h> +#include <gpxe/settings.h> struct nvs_device; -struct dhcp_option_block; +struct refcnt; /** * A fragment of a non-volatile storage device used for stored options @@ -26,6 +28,8 @@ struct nvo_fragment { * A block of non-volatile stored options */ struct nvo_block { + /** Settings block */ + struct settings settings; /** Underlying non-volatile storage device */ struct nvs_device *nvs; /** List of option-containing fragments @@ -33,17 +37,17 @@ struct nvo_block { * The list is terminated by a fragment with a length of zero. */ struct nvo_fragment *fragments; - /** Total length of all fragments - * - * This field is filled in by nvo_register(). - */ + /** Total length of option-containing fragments */ size_t total_len; + /** Option-containing data */ + void *data; /** DHCP options block */ - struct dhcp_option_block *options; + struct dhcp_options dhcpopts; }; -extern int nvo_register ( struct nvo_block *nvo ); -extern int nvo_save ( struct nvo_block *nvo ); -extern void nvo_unregister ( struct nvo_block *nvo ); +extern void nvo_init ( struct nvo_block *nvo, struct nvs_device *nvs, + struct nvo_fragment *fragments, struct refcnt *refcnt ); +extern int register_nvo ( struct nvo_block *nvo, struct settings *parent ); +extern void unregister_nvo ( struct nvo_block *nvo ); #endif /* _GPXE_NVO_H */ diff --git a/src/include/gpxe/settings.h b/src/include/gpxe/settings.h index b79ce508..f20c412b 100644 --- a/src/include/gpxe/settings.h +++ b/src/include/gpxe/settings.h @@ -151,6 +151,9 @@ extern int store_setting ( struct settings *settings, unsigned int tag, const void *data, size_t len ); extern int fetch_setting ( struct settings *settings, unsigned int tag, void *data, size_t len ); +extern int copy_setting ( struct settings *dest, unsigned int dest_tag, + struct settings *source, unsigned int source_tag ); +extern int copy_settings ( struct settings *dest, struct settings *source ); extern int fetch_setting_len ( struct settings *settings, unsigned int tag ); extern int fetch_string_setting ( struct settings *settings, unsigned int tag, char *data, size_t len ); @@ -163,6 +166,8 @@ extern int fetch_uint_setting ( struct settings *settings, unsigned int tag, extern long fetch_intz_setting ( struct settings *settings, unsigned int tag ); extern unsigned long fetch_uintz_setting ( struct settings *settings, unsigned int tag ); +extern struct settings * find_child_settings ( struct settings *parent, + const char *name ); extern struct settings * find_settings ( const char *name ); extern int store_typed_setting ( struct settings *settings, unsigned int tag, struct setting_type *type, |