From 27e10b9e7f76b99dbdc0d8fd779b18ef322ed92c Mon Sep 17 00:00:00 2001 From: Pablo Mazzini Date: Fri, 3 Aug 2018 12:22:05 +0200 Subject: add IsRequested --- dhcpv6/utils.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'dhcpv6/utils.go') diff --git a/dhcpv6/utils.go b/dhcpv6/utils.go index 1681661..d1715da 100644 --- a/dhcpv6/utils.go +++ b/dhcpv6/utils.go @@ -11,16 +11,25 @@ import ( // if the "boot file" option is included in the packet, which is useful for // ADVERTISE/REPLY packet. func IsNetboot(msg DHCPv6) bool { + if IsRequested(msg, OptionBootfileURL) { + return true + } + if optbf := msg.GetOneOption(OptionBootfileURL); optbf != nil { + return true + } + return false +} + +// IsRequested function takes a DHCPv6 message and an OptionCode, and returns +// true if that option is within the requested options of the DHCPv6 message. +func IsRequested(msg DHCPv6, requested OptionCode) bool { for _, optoro := range msg.GetOption(OptionORO) { for _, o := range optoro.(*OptRequestedOption).RequestedOptions() { - if o == OptionBootfileURL { + if o == requested { return true } } } - if optbf := msg.GetOneOption(OptionBootfileURL); optbf != nil { - return true - } return false } -- cgit v1.2.3