summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/dhcpv6message.go
diff options
context:
space:
mode:
authorAndrea Barberio <insomniac@slackware.it>2019-04-23 23:09:44 +0100
committerinsomniac <insomniacslk@users.noreply.github.com>2019-04-24 21:37:02 +0100
commit8166b9a9db9b180c02622ebf3dcff01ff2b2e0a6 (patch)
tree31d3044177cebed28784b1b282a9ea73fc9b65a6 /dhcpv6/dhcpv6message.go
parentebf43962e121b9c5c982d6a647a29fa4ae9b6a14 (diff)
[dhcpv6] Solicit messages derive default IAID from MAC address
IAID must be set by the client. This patch generates the IAID from the MAC address of the interface. To do so, a new WithIAID modifier is added, the interface of NewSolicitWithCID now requires a hwaddr parameter, and NewAdvertiseFromSolicit copies the IA_NA option from the solicit if present. Signed-off-by: Andrea Barberio <insomniac@slackware.it>
Diffstat (limited to 'dhcpv6/dhcpv6message.go')
-rw-r--r--dhcpv6/dhcpv6message.go36
1 files changed, 16 insertions, 20 deletions
diff --git a/dhcpv6/dhcpv6message.go b/dhcpv6/dhcpv6message.go
index 9237c1b..707a65d 100644
--- a/dhcpv6/dhcpv6message.go
+++ b/dhcpv6/dhcpv6message.go
@@ -42,8 +42,15 @@ func GetTime() uint32 {
return uint32((now.Nanoseconds() / 1000000000) % 0xffffffff)
}
-// NewSolicitWithCID creates a new SOLICIT message with CID.
-func NewSolicitWithCID(duid Duid, modifiers ...Modifier) (*Message, error) {
+// NewSolicit creates a new SOLICIT message, using the given hardware address to
+// derive the IAID in the IA_NA option.
+func NewSolicit(hwaddr net.HardwareAddr, modifiers ...Modifier) (*Message, error) {
+ duid := Duid{
+ Type: DUID_LLT,
+ HwType: iana.HWTypeEthernet,
+ Time: GetTime(),
+ LinkLayerAddr: hwaddr,
+ }
m, err := NewMessage()
if err != nil {
return nil, err
@@ -57,12 +64,13 @@ func NewSolicitWithCID(duid Duid, modifiers ...Modifier) (*Message, error) {
})
m.AddOption(oro)
m.AddOption(&OptElapsedTime{})
- // FIXME use real values for IA_NA
- iaNa := &OptIANA{}
- iaNa.IaId = [4]byte{0xfa, 0xce, 0xb0, 0x0c}
- iaNa.T1 = 0xe10
- iaNa.T2 = 0x1518
- m.AddOption(iaNa)
+ if len(hwaddr) < 4 {
+ return nil, errors.New("short hardware addrss: less than 4 bytes")
+ }
+ l := len(hwaddr)
+ var iaid [4]byte
+ copy(iaid[:], hwaddr[l-4:l])
+ modifiers = append([]Modifier{WithIAID(iaid)}, modifiers...)
// Apply modifiers
for _, mod := range modifiers {
mod(m)
@@ -70,18 +78,6 @@ func NewSolicitWithCID(duid Duid, modifiers ...Modifier) (*Message, error) {
return m, nil
}
-// NewSolicit creates a new SOLICIT message with DUID-LLT, using the
-// given network interface's hardware address and current time
-func NewSolicit(ifaceHWAddr net.HardwareAddr, modifiers ...Modifier) (*Message, error) {
- duid := Duid{
- Type: DUID_LLT,
- HwType: iana.HWTypeEthernet,
- Time: GetTime(),
- LinkLayerAddr: ifaceHWAddr,
- }
- return NewSolicitWithCID(duid, modifiers...)
-}
-
// NewAdvertiseFromSolicit creates a new ADVERTISE packet based on an SOLICIT packet.
func NewAdvertiseFromSolicit(sol *Message, modifiers ...Modifier) (*Message, error) {
if sol == nil {