[systemd-devel] [PATCH 15/24] sd-dhcp6-client: Add IA Address option parsing

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Wed Jun 18 07:08:08 PDT 2014


On Fri, Jun 13, 2014 at 04:45:05PM +0300, Patrik Flykt wrote:
> Add functionality to parse DHCPv6 Identity Association for
> Non-temporary (IA_NA) and Temporary Addresses (IA_TA) options.
> Both of them contain one or more IA Address (IAADDR) options
> and optinally a status code option. Only the IA_NA option
> contains lease lifetimes. See RFC 3315, sections 22.4., 22.5.,
> 22.6., 22.13. and appendix B. for details. If the lease
> timeouts are not set, use the ones recommended for servers in
> section 22.4.
> 
> Factor out common code in the form of an option header parsing
> helper function.
> ---
>  src/libsystemd-network/dhcp6-internal.h |   2 +
>  src/libsystemd-network/dhcp6-option.c   | 182 ++++++++++++++++++++++++++++++--
>  2 files changed, 175 insertions(+), 9 deletions(-)
> 
> diff --git a/src/libsystemd-network/dhcp6-internal.h b/src/libsystemd-network/dhcp6-internal.h
> index 31f5bd2..ec1d82a 100644
> --- a/src/libsystemd-network/dhcp6-internal.h
> +++ b/src/libsystemd-network/dhcp6-internal.h
> @@ -66,6 +66,8 @@ int dhcp6_option_append(uint8_t **buf, size_t *buflen, uint16_t code,
>  int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, DHCP6IA *ia);
>  int dhcp6_option_parse(uint8_t **buf, size_t *buflen, uint16_t *optcode,
>                         size_t *optlen, uint8_t **optvalue);
> +int dhcp6_option_parse_ia(uint8_t **buf, size_t *buflen, uint16_t iatype,
> +                          DHCP6IA *ia);
>  
>  int dhcp6_network_bind_udp_socket(int index, struct in6_addr *address);
>  int dhcp6_network_send_udp_socket(int s, struct in6_addr *address,
> diff --git a/src/libsystemd-network/dhcp6-option.c b/src/libsystemd-network/dhcp6-option.c
> index cc4d261..55fd872 100644
> --- a/src/libsystemd-network/dhcp6-option.c
> +++ b/src/libsystemd-network/dhcp6-option.c
> @@ -129,22 +129,186 @@ int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, DHCP6IA *ia) {
>          return 0;
>  }
>  
> +
> +static int option_parse_hdr(uint8_t **buf, size_t *buflen, uint16_t *opt,
> +                            size_t *optlen) {
> +        uint16_t len;
> +
> +        assert_return(buf, -EINVAL);
> +        assert_return(opt, -EINVAL);
> +        assert_return(optlen, -EINVAL);
> +
> +        if (*buflen < 4)
> +                return -ENOMSG;
> +
> +        len = (*buf)[2] << 8 | (*buf)[3];
> +
> +        if (len > *buflen)
> +                return -ENOMSG;
> +
> +        *opt = (*buf)[0] << 8 | (*buf)[1];
> +        *optlen = len;
> +
> +        (*buf) += 4;
> +        (*buflen) -= 4;
Unnecessary parens?

> -        *optvalue = &(*buf)[4];
> -        *buflen -= (*optlen + 4);
> -        (*buf) += (*optlen + 4);
> +        *optvalue = *buf;
> +        *buflen -= *optlen;
> +        (*buf) += *optlen;

Zbyszek


More information about the systemd-devel mailing list