mirror of
https://github.com/danderson/netboot.git
synced 2025-08-11 00:57:11 +02:00
Merged MakeMsgReplyWithNoAddrsAvailable and MakeMsgReply methods
This commit is contained in:
parent
c0ce892172
commit
794097f861
@ -38,12 +38,8 @@ func (b *PacketBuilder) BuildResponse(in *Packet) (*Packet, error) {
|
||||
return nil, err
|
||||
}
|
||||
associations, err := b.Addresses.ReserveAddresses(in.Options.ClientId(), in.Options.IaNaIds())
|
||||
if err != nil {
|
||||
return b.MakeMsgReplyWithNoAddrsAvailable(in.TransactionID, in.Options.ClientId(),
|
||||
in.Options.ClientArchType(), associations, iasWithoutAddesses(associations, in.Options.IaNaIds()), bootFileUrl, err), err
|
||||
}
|
||||
return b.MakeMsgReply(in.TransactionID, in.Options.ClientId(),
|
||||
in.Options.ClientArchType(), associations, bootFileUrl), nil
|
||||
in.Options.ClientArchType(), associations, iasWithoutAddesses(associations, in.Options.IaNaIds()), bootFileUrl, err), err
|
||||
case MsgInformationRequest:
|
||||
bootFileUrl, err := b.Configuration.GetBootUrl(b.ExtractLLAddressOrId(in.Options.ClientId()), in.Options.ClientArchType())
|
||||
if err != nil {
|
||||
@ -81,13 +77,17 @@ func (b *PacketBuilder) MakeMsgAdvertise(transactionId [3]byte, clientId []byte,
|
||||
}
|
||||
|
||||
func (b *PacketBuilder) MakeMsgReply(transactionId [3]byte, clientId []byte, clientArchType uint16,
|
||||
associations []*IdentityAssociation, bootFileUrl []byte) *Packet {
|
||||
associations []*IdentityAssociation, iasWithoutAddresses [][]byte, bootFileUrl []byte, err error) *Packet {
|
||||
ret_options := make(Options)
|
||||
ret_options.AddOption(MakeOption(OptClientId, clientId))
|
||||
for _, association := range(associations) {
|
||||
ret_options.AddOption(MakeIaNaOption(association.InterfaceId, b.calculateT1(), b.calculateT2(),
|
||||
MakeIaAddrOption(association.IpAddress, b.PreferredLifetime, b.ValidLifetime)))
|
||||
}
|
||||
for _, ia := range(iasWithoutAddresses) {
|
||||
ret_options.AddOption(MakeIaNaOption(ia, b.calculateT1(), b.calculateT2(),
|
||||
MakeStatusOption(2, err.Error())))
|
||||
}
|
||||
ret_options.AddOption(MakeOption(OptServerId, b.ServerDuid))
|
||||
if 0x10 == clientArchType { // HTTPClient
|
||||
ret_options.AddOption(MakeOption(OptVendorClass, []byte {0, 0, 0, 0, 0, 10, 72, 84, 84, 80, 67, 108, 105, 101, 110, 116})) // HTTPClient
|
||||
@ -130,27 +130,6 @@ func (b *PacketBuilder) MakeMsgAdvertiseWithNoAddrsAvailable(transactionId [3]by
|
||||
return &Packet{Type: MsgAdvertise, TransactionID: transactionId, Options: ret_options}
|
||||
}
|
||||
|
||||
func (b *PacketBuilder) MakeMsgReplyWithNoAddrsAvailable(transactionId [3]byte, clientId []byte, clientArchType uint16,
|
||||
associations []*IdentityAssociation, iasWithoutAddresses [][]byte, bootFileUrl []byte, err error) *Packet {
|
||||
ret_options := make(Options)
|
||||
ret_options.AddOption(MakeOption(OptClientId, clientId))
|
||||
for _, association := range(associations) {
|
||||
ret_options.AddOption(MakeIaNaOption(association.InterfaceId, b.calculateT1(), b.calculateT2(),
|
||||
MakeIaAddrOption(association.IpAddress, b.PreferredLifetime, b.ValidLifetime)))
|
||||
}
|
||||
for _, ia := range(iasWithoutAddresses) {
|
||||
ret_options.AddOption(MakeIaNaOption(ia, b.calculateT1(), b.calculateT2(),
|
||||
MakeStatusOption(2, err.Error())))
|
||||
}
|
||||
ret_options.AddOption(MakeOption(OptServerId, b.ServerDuid))
|
||||
if 0x10 == clientArchType { // HTTPClient
|
||||
ret_options.AddOption(MakeOption(OptVendorClass, []byte {0, 0, 0, 0, 0, 10, 72, 84, 84, 80, 67, 108, 105, 101, 110, 116})) // HTTPClient
|
||||
}
|
||||
ret_options.AddOption(MakeOption(OptBootfileUrl, bootFileUrl))
|
||||
|
||||
return &Packet{Type: MsgReply, TransactionID: transactionId, Options: ret_options}
|
||||
}
|
||||
|
||||
func (b *PacketBuilder) calculateT1() uint32 {
|
||||
return b.PreferredLifetime / 2
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ func TestMakeMsgReply(t *testing.T) {
|
||||
NewRandomAddressPool(net.ParseIP("2001:db8:f00f:cafe::1"), 1, 100))
|
||||
|
||||
msg := builder.MakeMsgReply(transactionId, expectedClientId, 0x11, []*IdentityAssociation{identityAssociation},
|
||||
expectedBootFileUrl)
|
||||
make([][]byte, 0), expectedBootFileUrl, nil)
|
||||
|
||||
if msg.Type != MsgReply {
|
||||
t.Fatalf("Expected message type %d, got %d", MsgAdvertise, msg.Type)
|
||||
@ -224,8 +224,9 @@ func TestMakeMsgReplyWithHttpClientArch(t *testing.T) {
|
||||
builder := MakePacketBuilder(expectedServerId, 90, 100, nil,
|
||||
NewRandomAddressPool(net.ParseIP("2001:db8:f00f:cafe::1"), 1, 100))
|
||||
|
||||
msg := builder.MakeMsgReply(transactionId, expectedClientId, 0x10, []*IdentityAssociation{identityAssociation},
|
||||
expectedBootFileUrl)
|
||||
msg := builder.MakeMsgReply(transactionId, expectedClientId, 0x10,
|
||||
[]*IdentityAssociation{identityAssociation}, make([][]byte, 0),
|
||||
expectedBootFileUrl, nil)
|
||||
|
||||
vendorClassOption := msg.Options[OptVendorClass]
|
||||
if vendorClassOption == nil {
|
||||
@ -253,7 +254,7 @@ func TestMakeMsgReplyWithNoAddrsAvailable(t *testing.T) {
|
||||
builder := MakePacketBuilder(expectedServerId, 90, 100, nil,
|
||||
NewRandomAddressPool(net.ParseIP("2001:db8:f00f:cafe::1"), 1, 100))
|
||||
|
||||
msg := builder.MakeMsgReplyWithNoAddrsAvailable(transactionId, expectedClientId, 0x10,
|
||||
msg := builder.MakeMsgReply(transactionId, expectedClientId, 0x10,
|
||||
[]*IdentityAssociation{identityAssociation}, [][]byte{[]byte("id-2")}, expectedBootFileUrl,
|
||||
fmt.Errorf(expectedErrorMessage))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user