diff options
author | Michael Brown <mcb30@ipxe.org> | 2013-12-04 22:06:10 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2013-12-05 00:41:49 +0000 |
commit | 17451b53e2fc696730586edb9d0a858bcc0b2ec8 (patch) | |
tree | e885da23313491fc49f6fcefaef6ac34107c146b /src/net | |
parent | 22001cb206c1320aee27f679a63d2171d35e99c5 (diff) | |
download | ipxe-17451b53e2fc696730586edb9d0a858bcc0b2ec8.tar.gz |
[settings] Allow for IPv6 setting types in non-IPv6 builds
Allow for the existence of references to IPv6 setting types without
dragging in the whole IPv6 stack, by placing the definition of
setting_type_ipv6 in core/settings.c and providing weak stub methods
for parse_ipv6_setting() and format_ipv6_setting().
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/ipv4.c | 45 | ||||
-rw-r--r-- | src/net/ipv6.c | 17 | ||||
-rw-r--r-- | src/net/udp/dhcpv6.c | 7 |
3 files changed, 52 insertions, 17 deletions
diff --git a/src/net/ipv4.c b/src/net/ipv4.c index f0a2e4d6..5d5c3f75 100644 --- a/src/net/ipv4.c +++ b/src/net/ipv4.c @@ -590,6 +590,51 @@ struct sockaddr_converter ipv4_sockaddr_converter __sockaddr_converter = { ****************************************************************************** */ +/** + * Parse IPv4 address setting value + * + * @v type Setting type + * @v value Formatted setting value + * @v buf Buffer to contain raw value + * @v len Length of buffer + * @ret len Length of raw value, or negative error + */ +int parse_ipv4_setting ( const struct setting_type *type __unused, + const char *value, void *buf, size_t len ) { + struct in_addr ipv4; + + /* Parse IPv4 address */ + if ( inet_aton ( value, &ipv4 ) == 0 ) + return -EINVAL; + + /* Copy to buffer */ + if ( len > sizeof ( ipv4 ) ) + len = sizeof ( ipv4 ); + memcpy ( buf, &ipv4, len ); + + return ( sizeof ( ipv4 ) ); +} + +/** + * Format IPv4 address setting value + * + * @v type Setting type + * @v raw Raw setting value + * @v raw_len Length of raw setting value + * @v buf Buffer to contain formatted value + * @v len Length of buffer + * @ret len Length of formatted value, or negative error + */ +int format_ipv4_setting ( const struct setting_type *type __unused, + const void *raw, size_t raw_len, char *buf, + size_t len ) { + const struct in_addr *ipv4 = raw; + + if ( raw_len < sizeof ( *ipv4 ) ) + return -EINVAL; + return snprintf ( buf, len, "%s", inet_ntoa ( *ipv4 ) ); +} + /** IPv4 address setting */ const struct setting ip_setting __setting ( SETTING_IPv4 ) = { .name = "ip", diff --git a/src/net/ipv6.c b/src/net/ipv6.c index 68a0c89b..621b4ff1 100644 --- a/src/net/ipv6.c +++ b/src/net/ipv6.c @@ -954,8 +954,8 @@ struct sockaddr_converter ipv6_sockaddr_converter __sockaddr_converter = { * @v len Length of buffer * @ret len Length of raw value, or negative error */ -static int parse_ipv6_setting ( const struct setting_type *type __unused, - const char *value, void *buf, size_t len ) { +int parse_ipv6_setting ( const struct setting_type *type __unused, + const char *value, void *buf, size_t len ) { struct in6_addr ipv6; int rc; @@ -981,9 +981,9 @@ static int parse_ipv6_setting ( const struct setting_type *type __unused, * @v len Length of buffer * @ret len Length of formatted value, or negative error */ -static int format_ipv6_setting ( const struct setting_type *type __unused, - const void *raw, size_t raw_len, char *buf, - size_t len ) { +int format_ipv6_setting ( const struct setting_type *type __unused, + const void *raw, size_t raw_len, char *buf, + size_t len ) { const struct in6_addr *ipv6 = raw; if ( raw_len < sizeof ( *ipv6 ) ) @@ -991,13 +991,6 @@ static int format_ipv6_setting ( const struct setting_type *type __unused, return snprintf ( buf, len, "%s", inet6_ntoa ( ipv6 ) ); } -/** An IPv6 address setting type */ -const struct setting_type setting_type_ipv6 __setting_type = { - .name = "ipv6", - .parse = parse_ipv6_setting, - .format = format_ipv6_setting, -}; - /** * Create IPv6 network device * diff --git a/src/net/udp/dhcpv6.c b/src/net/udp/dhcpv6.c index 7bed83d9..668974ca 100644 --- a/src/net/udp/dhcpv6.c +++ b/src/net/udp/dhcpv6.c @@ -255,9 +255,6 @@ static int dhcpv6_iaaddr ( struct dhcpv6_option_list *options, uint32_t iaid, * */ -/** DHCPv6 settings scope */ -static const struct settings_scope dhcpv6_settings_scope; - /** A DHCPv6 settings block */ struct dhcpv6_settings { /** Reference count */ @@ -278,7 +275,7 @@ struct dhcpv6_settings { static int dhcpv6_applies ( struct settings *settings __unused, const struct setting *setting ) { - return ( setting->scope == &dhcpv6_settings_scope ); + return ( setting->scope == &ipv6_scope ); } /** @@ -339,7 +336,7 @@ static int dhcpv6_register ( struct dhcpv6_option_list *options, } ref_init ( &dhcpv6set->refcnt, NULL ); settings_init ( &dhcpv6set->settings, &dhcpv6_settings_operations, - &dhcpv6set->refcnt, &dhcpv6_settings_scope ); + &dhcpv6set->refcnt, &ipv6_scope ); data = ( ( ( void * ) dhcpv6set ) + sizeof ( *dhcpv6set ) ); len = options->len; memcpy ( data, options->data, len ); |