From 5062bfae598f68ed7c57b3c14259d1a1ca6476fa Mon Sep 17 00:00:00 2001 From: insomniac Date: Thu, 5 Jul 2018 14:04:03 +0100 Subject: DHCPv6.Exchange now applies modifiers correctly for both solicit and request (#75) --- dhcpv6/client.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/dhcpv6/client.go b/dhcpv6/client.go index 6edf798..7896976 100644 --- a/dhcpv6/client.go +++ b/dhcpv6/client.go @@ -45,22 +45,23 @@ func (c *Client) Exchange(ifname string, solicit DHCPv6, modifiers ...Modifier) var err error // Solicit - solicit, advertise, err := c.Solicit(ifname, solicit) - if solicit != nil { - conversation = append(conversation, solicit) + if solicit == nil { + solicit, err = NewSolicitForInterface(ifname) + if err != nil { + return conversation, err + } } + solicit, advertise, err := c.Solicit(ifname, solicit, modifiers...) + conversation = append(conversation, solicit) if err != nil { return conversation, err } conversation = append(conversation, advertise) - request, reply, err := c.Request(ifname, advertise, nil) + request, reply, err := c.Request(ifname, advertise, nil, modifiers...) if request != nil { conversation = append(conversation, request) } - for _, mod := range modifiers { - request = mod(request) - } if err != nil { return conversation, err } @@ -170,7 +171,7 @@ func (c *Client) sendReceive(ifname string, packet DHCPv6, expectedType MessageT // Solicit sends a SOLICIT, return the solicit, an ADVERTISE (if not nil), and // an error if any -func (c *Client) Solicit(ifname string, solicit DHCPv6) (DHCPv6, DHCPv6, error) { +func (c *Client) Solicit(ifname string, solicit DHCPv6, modifiers ...Modifier) (DHCPv6, DHCPv6, error) { var err error if solicit == nil { solicit, err = NewSolicitForInterface(ifname) @@ -178,13 +179,16 @@ func (c *Client) Solicit(ifname string, solicit DHCPv6) (DHCPv6, DHCPv6, error) return nil, nil, err } } + for _, mod := range modifiers { + solicit = mod(solicit) + } advertise, err := c.sendReceive(ifname, solicit, MSGTYPE_NONE) return solicit, advertise, err } // Request sends a REQUEST built from an ADVERTISE if no REQUEST is specified. // It returns the request, a reply if not nil, and an error if any -func (c *Client) Request(ifname string, advertise, request DHCPv6) (DHCPv6, DHCPv6, error) { +func (c *Client) Request(ifname string, advertise, request DHCPv6, modifiers ...Modifier) (DHCPv6, DHCPv6, error) { if request == nil { var err error request, err = NewRequestFromAdvertise(advertise) @@ -192,6 +196,9 @@ func (c *Client) Request(ifname string, advertise, request DHCPv6) (DHCPv6, DHCP return nil, nil, err } } + for _, mod := range modifiers { + request = mod(request) + } reply, err := c.sendReceive(ifname, request, MSGTYPE_NONE) return request, reply, err } -- cgit v1.2.3