[SLOF] [PATCH 5/7] net-snk: Make use of DHCPv6 transaction IDs
Stefan Berger
stefanb at linux.vnet.ibm.com
Tue Dec 22 02:55:54 AEDT 2015
On 12/17/2015 03:18 PM, Thomas Huth wrote:
> Generate a proper transaction ID before sending DHCPv6 packets
> and check whether the DHCPv6 replies contain that correct XID, too.
>
> Signed-off-by: Thomas Huth <thuth at redhat.com>
> ---
> clients/net-snk/app/netapps/netboot.c | 3 +++
> clients/net-snk/app/netlib/dhcpv6.c | 17 +++++++++--------
> clients/net-snk/app/netlib/dhcpv6.h | 1 +
> 3 files changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/clients/net-snk/app/netapps/netboot.c b/clients/net-snk/app/netapps/netboot.c
> index 51189c4..d51d5a8 100644
> --- a/clients/net-snk/app/netapps/netboot.c
> +++ b/clients/net-snk/app/netapps/netboot.c
> @@ -332,6 +332,9 @@ int dhcp(char *ret_buffer, filename_ip_t * fn_ip, unsigned int retries, int flag
> int i = (int) retries+1;
> int rc = -1;
>
> + if (flags != F_IPV4)
> + dhcpv6_generate_transaction_id();
Why not flags == F_IPV6 ? The rest of the function seems to test like
this as well.
> +
> printf(" ");
>
> do {
> diff --git a/clients/net-snk/app/netlib/dhcpv6.c b/clients/net-snk/app/netlib/dhcpv6.c
> index 4deef30..05e9fcd 100644
> --- a/clients/net-snk/app/netlib/dhcpv6.c
> +++ b/clients/net-snk/app/netlib/dhcpv6.c
> @@ -27,13 +27,13 @@ static uint8_t tid[3];
> static uint32_t dhcpv6_state = -1;
> static filename_ip_t *my_fn_ip;
>
> -static void
> -generate_transaction_id(void)
> +void
> +dhcpv6_generate_transaction_id(void)
> {
> - /* TODO: as per RFC 3315 transaction IDs should be generated randomly */
> - tid[0] = 1;
> - tid[1] = 2;
> - tid[2] = 4;
> + /* As per RFC 3315 transaction IDs should be generated randomly */
> + tid[0] = rand();
> + tid[1] = rand();
> + tid[2] = rand();
> }
>
> static void
> @@ -45,8 +45,6 @@ send_info_request(int fd)
>
> memset(ether_packet, 0, ETH_MTU_SIZE);
>
> - generate_transaction_id();
> -
> /* Get an IPv6 packet */
> payload_length = sizeof(struct udphdr) + sizeof(struct dhcp_message_header);
> fill_ip6hdr (ether_packet + sizeof(struct ethhdr),
> @@ -205,6 +203,9 @@ handle_dhcpv6(uint8_t * packet, int32_t packetsize)
> struct dhcp_message_reply *reply;
> reply = (struct dhcp_message_reply *) packet;
>
> + if (memcmp(reply->transaction_id, tid, 3))
> + return -1; /* Wrong transaction ID */
> +
> if (reply->type == 7)
> dhcpv6_state = DHCP_STATUSCODE_SUCCESS;
>
> diff --git a/clients/net-snk/app/netlib/dhcpv6.h b/clients/net-snk/app/netlib/dhcpv6.h
> index 078a9f1..dcda9b1 100644
> --- a/clients/net-snk/app/netlib/dhcpv6.h
> +++ b/clients/net-snk/app/netlib/dhcpv6.h
> @@ -77,6 +77,7 @@
> #define DUID_LL 3 /* DUID based on Link-layer Address */
>
> /* Prototypes */
> +void dhcpv6_generate_transaction_id(void);
> int32_t dhcpv6 ( char *ret_buffer, void *fn_ip);
> uint32_t handle_dhcpv6(uint8_t * , int32_t);
>
The rest looks good to me.
Stefan
More information about the SLOF
mailing list