Skip to content

Commit 31b61fa

Browse files
committed
Use the MmdsAddress of the Config struct instead of the argument of the handler.
Signed-off-by: Yutaka Juba <[email protected]>
1 parent 8626a34 commit 31b61fa

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

handlers.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package firecracker
1616
import (
1717
"context"
1818
"fmt"
19-
"net"
2019
"os"
2120
)
2221

@@ -260,15 +259,13 @@ func NewSetMetadataHandler(metadata interface{}) Handler {
260259
}
261260
}
262261

263-
// NewConfigMmdsHandler is a named handler that puts the MMDS config into the
262+
// ConfigMmdsHandler is a named handler that puts the MMDS config into the
264263
// firecracker process.
265-
func NewConfigMmdsHandler(address net.IP) Handler {
266-
return Handler{
267-
Name: ConfigMmdsHandlerName,
268-
Fn: func(ctx context.Context, m *Machine) error {
269-
return m.setMmdsConfig(ctx, address)
270-
},
271-
}
264+
var ConfigMmdsHandler = Handler{
265+
Name: ConfigMmdsHandlerName,
266+
Fn: func(ctx context.Context, m *Machine) error {
267+
return m.setMmdsConfig(ctx, m.Cfg.MmdsAddress)
268+
},
272269
}
273270

274271
var defaultFcInitHandlerList = HandlerList{}.Append(

handlers_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ func TestHandlers(t *testing.T) {
623623
Config: Config{},
624624
},
625625
{
626-
Handler: NewConfigMmdsHandler(mmdsAddress),
626+
Handler: ConfigMmdsHandler,
627627
Client: fctesting.MockClient{
628628
PutMmdsConfigFn: func(params *ops.PutMmdsConfigParams) (*ops.PutMmdsConfigNoContent, error) {
629629
called = ConfigMmdsHandlerName
@@ -633,7 +633,9 @@ func TestHandlers(t *testing.T) {
633633
return &ops.PutMmdsConfigNoContent{}, nil
634634
},
635635
},
636-
Config: Config{},
636+
Config: Config{
637+
MmdsAddress: mmdsAddress,
638+
},
637639
},
638640
}
639641

machine.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ type Config struct {
159159
// 2 : advanced filtering. This adds further checks on some of the
160160
// parameters of the allowed syscalls.
161161
SeccompLevel SeccompLevelValue
162+
163+
// MmdsAddress is IPv4 address used by guest applications when issuing requests to MMDS.
164+
// It is possible to use a valid IPv4 link-local address (169.254.0.0/16).
165+
// If not provided, the default address (169.254.169.254) will be used.
166+
MmdsAddress net.IP
162167
}
163168

164169
// Validate will ensure that the required fields are set and that

0 commit comments

Comments
 (0)