From 78b117a1466dc17b81361199c79d620e083c04d4 Mon Sep 17 00:00:00 2001 From: Hu Jun Date: Sat, 18 Jul 2020 10:57:57 -0700 Subject: move NewReleaseFromAck to where all NewXXFromYY are Signed-off-by: Hu Jun --- dhcpv4/dhcpv4.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'dhcpv4/dhcpv4.go') diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go index 14b0d9f..344e889 100644 --- a/dhcpv4/dhcpv4.go +++ b/dhcpv4/dhcpv4.go @@ -271,6 +271,23 @@ func NewReplyFromRequest(request *DHCPv4, modifiers ...Modifier) (*DHCPv4, error )...) } +// NewReleaseFromACK creates a DHCPv4 Release message from ACK. +// default Release message without any Modifer is created as following: +// - option Message Type is Release +// - ClientIP is set to ack.YourIPAddr +// - ClientHWAddr is set to ack.ClientHWAddr +// - Unicast +// - option Server Identifier is set to ack's ServerIdentifier +func NewReleaseFromACK(ack *DHCPv4, modifiers ...Modifier) (*DHCPv4, error) { + return New(PrependModifiers(modifiers, + WithMessageType(MessageTypeRelease), + WithClientIP(ack.YourIPAddr), + WithHwAddr(ack.ClientHWAddr), + WithBroadcast(false), + WithOption(OptServerIdentifier(ack.ServerIdentifier())), + )...) +} + // FromBytes encodes the DHCPv4 packet into a sequence of bytes, and returns an // error if the packet is not valid. func FromBytes(q []byte) (*DHCPv4, error) { @@ -790,20 +807,3 @@ func (d *DHCPv4) VIVC() VIVCIdentifiers { } return ids } - -// NewReleaseFromACK creates a DHCPv4 Release message from ACK. -// default Release message without any Modifer is created as following: -// - option Message Type is Release -// - ClientIP is set to ack.YourIPAddr -// - ClientHWAddr is set to ack.ClientHWAddr -// - Unicast -// - option Server Identifier is set to ack's ServerIdentifier -func NewReleaseFromACK(ack *DHCPv4, modifiers ...Modifier) (*DHCPv4, error) { - return New(PrependModifiers(modifiers, - WithMessageType(MessageTypeRelease), - WithClientIP(ack.YourIPAddr), - WithHwAddr(ack.ClientHWAddr), - WithBroadcast(false), - WithOption(OptServerIdentifier(ack.ServerIdentifier())), - )...) -} -- cgit v1.2.3