Skip to content

Commit 4a8ce2c

Browse files
committed
Add support for CNI-configured network interfaces.
Signed-off-by: Erik Sipsma <[email protected]>
1 parent 922c3a7 commit 4a8ce2c

17 files changed

+1426
-80
lines changed

.buildkite/pipeline.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ steps:
3434
- wait
3535

3636
- label: 'build'
37-
command: 'make'
37+
commands:
38+
- 'make'
39+
- 'make -C cni'
3840
agents:
3941
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"
4042

4143
- label: ':hammer: tests'
4244
commands:
4345
- 'ln -s /var/lib/fc-ci/vmlinux.bin testdata/vmlinux'
46+
- 'ln -s /var/lib/fc-ci/rootfs.ext4 testdata/root-drive.img'
4447
- 'ln -s /usr/local/bin/firecracker-v0.17.0 testdata/firecracker'
4548
- 'ln -s /usr/local/bin/jailer-v0.17.0 testdata/jailer'
4649
- "DISABLE_ROOT_TESTS=true FC_TEST_TAP=fc-test-tap${BUILDKITE_BUILD_NUMBER} make test EXTRAGOARGS='-v -count=1'"
@@ -50,8 +53,10 @@ steps:
5053
- label: ':hammer: root tests'
5154
commands:
5255
- 'ln -s /var/lib/fc-ci/vmlinux.bin testdata/vmlinux'
56+
- 'ln -s /var/lib/fc-ci/rootfs.ext4 testdata/root-drive.img'
5357
- 'cp /usr/local/bin/firecracker-v0.17.0 testdata/firecracker'
5458
- 'cp /usr/local/bin/jailer-v0.17.0 testdata/jailer'
59+
- 'make -C cni install CNI_BIN_ROOT=$(pwd)/testdata/bin'
5560
- "sudo FC_TEST_TAP=fc-root-tap${BUILDKITE_BUILD_NUMBER} make test EXTRAGOARGS='-v -count=1'"
5661
agents:
5762
queue: "${BUILDKITE_AGENT_META_DATA_QUEUE:-default}"

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 0.18.0
2+
* Adds support for configuring Network Interfaces via CNI (#126)
3+
* Moves NetworkInterface.HostDevName and NetworkInterface.MacAddress fields to
4+
NetworkInterface.StaticConfiguration.HostDevName and NetworkInterface.StaticConfiguration.MacAddress
5+
fields, respectively. This is a backwards incompatible change, users will need
6+
to update the location of these fields. (#126)
7+
18
# 0.17.0
29

310
* Fixes a bug where fifos were not working properly with jailer enabled (#96)

README.md

+104-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,110 @@ Network configuration
3535
---
3636

3737
Firecracker, by design, only supports Linux tap devices. The SDK
38-
provides facilities to attach a tap device to the Firecracker VM, but
39-
the client is responsible for further configuration.
38+
provides facilities to:
39+
* Attach a pre-created tap device, optionally with static IP configuration, to
40+
the VM. This is referred to as a "static network interface".
41+
* Create a tap device via [CNI](https://github.com/containernetworking/cni) plugins,
42+
which will then be attached to the VM automatically by the SDK. This is referred
43+
to as a "CNI-configured network interface"
44+
45+
### CNI
46+
If a VM is configured with a CNI-configured network interface, by default CNI configuration
47+
files will be sought from `/etc/cni/conf.d` and CNI plugins will be sought under
48+
`/opt/cni/bin` (both of these values can be overridden via API fields). CNI network lists
49+
must be specified in a configuration file at this time.
50+
51+
It's currently highly recommended to use CNI configuration that includes
52+
[tc-redirect-tap](cni/Makefile) as a chained plugin. This will allow you to
53+
adapt pre-existing CNI plugins/configuration to a tap device usable by a
54+
Firecracker VM.
55+
56+
#### Example
57+
58+
With the following file at `/etc/cni/conf.d/fcnet.conflist`:
59+
```
60+
{
61+
"name": "fcnet",
62+
"cniVersion": "0.3.1",
63+
"plugins"": [
64+
{
65+
"type": "ptp",
66+
"ipMasq": true,
67+
"ipam": {
68+
"type": "host-local",
69+
"subnet": "192.168.127.0/24",
70+
"resolvConf": "/etc/resolv.conf"
71+
}
72+
},
73+
{
74+
"type": "tc-redirect-tap"
75+
}
76+
]
77+
}
78+
```
79+
80+
and the
81+
[`ptp`](https://github.com/containernetworking/plugins/tree/master/plugins/main/ptp),
82+
[`host-local`](https://github.com/containernetworking/plugins/tree/master/plugins/ipam/host-local)
83+
and [`tc-redirect-tap`](cni/Makefile)
84+
CNI plugin binaries installed under `/opt/cni/bin`, you can specify, in the Go SDK API,
85+
a `Machine` with the following `NetworkInterface`:
86+
```go
87+
{
88+
NetworkInterfaces: []firecracker.NetworkInterface{{
89+
CNIConfiguration: &firecracker.CNIConfiguration{
90+
NetworkName: "fcnet",
91+
IfName: "veth0",
92+
},
93+
}}
94+
}
95+
```
96+
97+
Note that `NetworkName` in the `CNIConfiguration` of the API matches the `name` field
98+
specified inside the `/etc/cni/conf.d/fcnet.conflist` file.
99+
100+
With the above configuration, when the Firecracker VM is started the SDK will invoke
101+
CNI and place the final VM inside the resultant network namespace. The end result being:
102+
* Outside the network namespace, a single veth endpoint created by the `ptp` plugin will
103+
exist with a static IP from the `host-local` plugin (i.e. `192.168.127.1`)
104+
* Inside the VM's network namespace:
105+
* The other side of the veth device will exist with name `veth0`, as specified by the
106+
`IfName` parameter above, and a different IP (i.e. `192.168.127.2`)
107+
* The tap device created by `tc-redirect-tap`, which will not have an IP but will have
108+
all of its traffic mirrored with the `veth0` device
109+
* Inside the actual Firecracker VM guest:
110+
* A network interface with the same IP as that of `veth0` (i.e. `192.168.127.2`)
111+
* Traffic sent on this device will be mirrored with the external `veth0` device,
112+
so from a practical perspective the VM's internal network interface will externally
113+
appear the same as `veth0`
114+
* The internal name of the interface is determined by the Guest OS, not the Firecracker
115+
Go SDK.
116+
117+
Note that the `ptp` and `host-local` plugins are not required, they are just used in this
118+
example. The `tc-redirect-tap` plugin can be chained after any CNI plugin that creates a
119+
network interface. It will setup the tap device to be mirrored with the `IfName` device
120+
created by any previous plugin. Any IP configuration on that `IfName` device will be
121+
applied statically to the VM's internal network interface on boot.
122+
123+
Also note that use of CNI-configured network interfaces will require the SDK to be running with at least
124+
`CAP_SYS_ADMIN` and `CAP_NET_ADMIN` Linux capabilities (in order to have the
125+
ability to create and configure network namespaces).
126+
127+
### Network Setup Limitations
128+
These limitations are a result of the current implementation and may be lifted in the future:
129+
* For a given VM, if a CNI-configured network interface is specified or a static interface
130+
that includes IP configuration is specified, the VM can only have a single
131+
network interface, not multiple.
132+
* Users can specify multiple static interfaces as long as none of them
133+
include IP configuration.
134+
* DNS nameserver settings will only be effective if the VM's rootfs makes
135+
`/etc/resolv.conf` be a symlink to `/proc/net/pnp`.
136+
* Only up to 2 DNS nameservers can be configured within the VM internally.
137+
* If a static network interface specifies more than 2, an error will be
138+
returned.
139+
* If a CNI-configured network interface receives more than 2 nameservers from the CNI
140+
invocation result, the nameservers after the second will be ignored without
141+
error (in order to be compatible with pre-existing CNI plugins/configuration).
40142

41143
Questions?
42144
---

cni/Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ SOURCES:=$(shell find . -name '*.go' ! -name '*_test.go')
1818
GOMOD := $(shell go env GOMOD)
1919
GOSUM := $(GOMOD:.mod=.sum)
2020

21+
# Set this to override the directory in which the tc-redirect-tap plugin is
22+
# installed by the "install" target
23+
CNI_BIN_ROOT?=/opt/cni/bin
2124

2225
.PHONY: all
2326
all: tc-redirect-tap
@@ -26,7 +29,8 @@ tc-redirect-tap: $(SOURCES) $(GOMOD) $(GOSUM)
2629
go build -o tc-redirect-tap $(CURDIR)/cmd/tc-redirect-tap
2730

2831
.PHONY: install
29-
install:
32+
install: tc-redirect-tap
33+
install -D -m755 -t $(CNI_BIN_ROOT) tc-redirect-tap
3034

3135
.PHONY: test
3236
test:

example_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ func ExampleNetworkInterface_rateLimiting() {
180180
// create the outbound rate limiter
181181
outbound := firecracker.NewRateLimiter(bandwidthBuilder.Build(), opsBuilder.Build())
182182

183-
networkIfaces := []firecracker.NetworkInterface{
184-
{
185-
MacAddress: "01-23-45-67-89-AB-CD-EF",
186-
HostDevName: "tap-name",
187-
InRateLimiter: inbound,
188-
OutRateLimiter: outbound,
183+
networkIfaces := []firecracker.NetworkInterface{{
184+
StaticConfiguration: &firecracker.StaticNetworkConfiguration{
185+
MacAddress: "01-23-45-67-89-AB-CD-EF",
186+
HostDevName: "tap-name",
189187
},
190-
}
188+
InRateLimiter: inbound,
189+
OutRateLimiter: outbound,
190+
}}
191191

192192
cfg := firecracker.Config{
193193
SocketPath: "/path/to/socket",

go.mod

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
module github.com/firecracker-microvm/firecracker-go-sdk
22

3+
go 1.11
4+
35
require (
4-
github.com/containernetworking/cni v0.7.1
6+
github.com/containernetworking/cni v0.7.2-0.20190807151350-8c6c47d1c7fc
57
github.com/containernetworking/plugins v0.8.2
68
github.com/go-openapi/errors v0.17.1
79
github.com/go-openapi/runtime v0.17.1
810
github.com/go-openapi/strfmt v0.17.1
911
github.com/go-openapi/swag v0.17.1
1012
github.com/go-openapi/validate v0.17.1
13+
github.com/gofrs/uuid v3.2.0+incompatible
1114
github.com/hashicorp/go-multierror v1.0.0
1215
github.com/pkg/errors v0.8.1
1316
github.com/sirupsen/logrus v1.1.1
17+
github.com/sparrc/go-ping v0.0.0-20190613174326-4e5b6552494c
1418
github.com/stretchr/testify v1.3.0
15-
github.com/vishvananda/netlink v1.0.0
19+
github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf
1620
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f
1721
)

go.sum

+7-11
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf h1:eg0MeVzs
99
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
1010
github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
1111
github.com/containernetworking/cni v0.7.0/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
12-
github.com/containernetworking/cni v0.7.1 h1:fE3r16wpSEyaqY4Z4oFrLMmIGfBYIKpPrHK31EJ9FzE=
13-
github.com/containernetworking/cni v0.7.1/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
12+
github.com/containernetworking/cni v0.7.2-0.20190807151350-8c6c47d1c7fc h1:zUNdrf9w09mWodVhZ9hX4Yk4Uu84n/OgdfPattAwwt8=
13+
github.com/containernetworking/cni v0.7.2-0.20190807151350-8c6c47d1c7fc/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
1414
github.com/containernetworking/plugins v0.8.2 h1:5lnwfsAYO+V7yXhysJKy3E1A2Gy9oVut031zfdOzI9w=
1515
github.com/containernetworking/plugins v0.8.2/go.mod h1:TxALKWZpWL79BC3GOYKJzzXr7U8R23PdhwaLp6F3adc=
1616
github.com/coreos/go-iptables v0.4.2/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmekav8Dbxlm1MU=
@@ -52,6 +52,8 @@ github.com/go-openapi/validate v0.17.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+
5252
github.com/go-openapi/validate v0.17.1 h1:RfQTLHm/gEu0oSUmbTOy0PMufjkE5/pPfnqYpor3WLc=
5353
github.com/go-openapi/validate v0.17.1/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4=
5454
github.com/godbus/dbus v0.0.0-20180201030542-885f9cc04c9c/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
55+
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
56+
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
5557
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
5658
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
5759
github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA=
@@ -90,39 +92,33 @@ github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiB
9092
github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
9193
github.com/sirupsen/logrus v1.1.1 h1:VzGj7lhU7KEB9e9gMpAV/v5XT2NVSvLJhJLCWbnkgXg=
9294
github.com/sirupsen/logrus v1.1.1/go.mod h1:zrgwTnHtNr00buQ1vSptGe8m1f/BbgsPukg8qsT7A+A=
93-
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
95+
github.com/sparrc/go-ping v0.0.0-20190613174326-4e5b6552494c h1:gqEdF4VwBu3lTKGHS9rXE9x1/pEaSwCXRLOZRF6qtlw=
96+
github.com/sparrc/go-ping v0.0.0-20190613174326-4e5b6552494c/go.mod h1:eMyUVp6f/5jnzM+3zahzl7q6UXLbgSc3MKg/+ow9QW0=
9497
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
95-
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
9698
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
9799
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
98100
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
101+
github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf h1:3J37+NPjNyGW/dbfXtj3yWuF9OEepIdGOXRaJGbORV8=
99102
github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk=
100-
github.com/vishvananda/netlink v1.0.0 h1:bqNY2lgheFIu1meHUFSH3d7vG93AFyqg3oGbJCOJgSM=
101-
github.com/vishvananda/netlink v1.0.0/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk=
102103
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc h1:R83G5ikgLMxrBvLh22JhdfI8K6YXEPHx5P03Uu3DRs4=
103104
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc/go.mod h1:ZjcWmFBXmLKZu9Nxj3WKYEafiSqer2rnvPr0en9UNpI=
104-
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
105105
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
106106
golang.org/x/crypto v0.0.0-20181009213950-7c1a557ab941 h1:qBTHLajHecfu+xzRI9PqVDcqx7SdHj9d4B+EzSn3tAc=
107107
golang.org/x/crypto v0.0.0-20181009213950-7c1a557ab941/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
108-
golang.org/x/net v0.0.0-20181005035420-146acd28ed58 h1:otZG8yDCO4LVps5+9bxOeNiCvgmOyt96J3roHTYs7oE=
109108
golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
110109
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 h1:Y/KGZSOdz/2r0WJ9Mkmz6NJBusp0kiNx1Cn82lzJQ6w=
111110
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
112-
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
113111
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
114112
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f h1:25KHgbfyiSm6vwQLbM3zZIe1v9p/3ea4Rz+nnM5K/i4=
115113
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
116114
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
117115
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
118116
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
119-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
120117
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
121118
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
122119
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
123120
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo=
124121
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
125-
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
126122
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
127123
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
128124
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

handlers.go

+41-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ const (
3030
AddVsocksHandlerName = "fcinit.AddVsocks"
3131
SetMetadataHandlerName = "fcinit.SetMetadata"
3232
LinkFilesToRootFSHandlerName = "fcinit.LinkFilesToRootFS"
33+
SetupNetworkHandlerName = "fcinit.SetupNetwork"
34+
SetupKernelArgsHandlerName = "fcinit.SetupKernelArgs"
3335

34-
ValidateCfgHandlerName = "validate.Cfg"
35-
ValidateJailerCfgHandlerName = "validate.JailerCfg"
36+
ValidateCfgHandlerName = "validate.Cfg"
37+
ValidateJailerCfgHandlerName = "validate.JailerCfg"
38+
ValidateNetworkCfgHandlerName = "validate.NetworkCfg"
3639
)
3740

3841
// HandlersAdapter is an interface used to modify a given set of handlers.
@@ -99,6 +102,13 @@ var JailerConfigValidationHandler = Handler{
99102
},
100103
}
101104

105+
var NetworkConfigValidationHandler = Handler{
106+
Name: ValidateNetworkCfgHandlerName,
107+
Fn: func(ctx context.Context, m *Machine) error {
108+
return m.Cfg.ValidateNetwork()
109+
},
110+
}
111+
102112
// StartVMMHandler is a named handler that will handle starting of the VMM.
103113
// This handler will also set the exit channel on completion.
104114
var StartVMMHandler = Handler{
@@ -173,15 +183,34 @@ var AttachDrivesHandler = Handler{
173183
},
174184
}
175185

176-
// CreateNetworkInterfacesHandler is a named handler that sets up network
177-
// interfaces to the firecracker process.
186+
// CreateNetworkInterfacesHandler is a named handler that registers network
187+
// interfaces with the Firecracker VMM.
178188
var CreateNetworkInterfacesHandler = Handler{
179189
Name: CreateNetworkInterfacesHandlerName,
180190
Fn: func(ctx context.Context, m *Machine) error {
181191
return m.createNetworkInterfaces(ctx, m.Cfg.NetworkInterfaces...)
182192
},
183193
}
184194

195+
// SetupNetworkHandler is a named handler that will setup the network namespace
196+
// and network interface configuration prior to the Firecracker VMM starting.
197+
var SetupNetworkHandler = Handler{
198+
Name: SetupNetworkHandlerName,
199+
Fn: func(ctx context.Context, m *Machine) error {
200+
return m.setupNetwork(ctx)
201+
},
202+
}
203+
204+
// SetupKernelArgsHandler is a named handler that will update any kernel boot
205+
// args being provided to the VM based on the other configuration provided, if
206+
// needed.
207+
var SetupKernelArgsHandler = Handler{
208+
Name: SetupKernelArgsHandlerName,
209+
Fn: func(ctx context.Context, m *Machine) error {
210+
return m.setupKernelArgs(ctx)
211+
},
212+
}
213+
185214
// AddVsocksHandler is a named handler that adds vsocks to the firecracker
186215
// process.
187216
var AddVsocksHandler = Handler{
@@ -203,6 +232,8 @@ func NewSetMetadataHandler(metadata interface{}) Handler {
203232
}
204233

205234
var defaultFcInitHandlerList = HandlerList{}.Append(
235+
SetupNetworkHandler,
236+
SetupKernelArgsHandler,
206237
StartVMMHandler,
207238
CreateLogFilesHandler,
208239
BootstrapLoggingHandler,
@@ -213,8 +244,13 @@ var defaultFcInitHandlerList = HandlerList{}.Append(
213244
AddVsocksHandler,
214245
)
215246

247+
var defaultValidationHandlerList = HandlerList{}.Append(
248+
NetworkConfigValidationHandler,
249+
)
250+
216251
var defaultHandlers = Handlers{
217-
FcInit: defaultFcInitHandlerList,
252+
Validation: defaultValidationHandlerList,
253+
FcInit: defaultFcInitHandlerList,
218254
}
219255

220256
// Handler represents a named handler that contains a name and a function which

handlers_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,12 @@ func TestHandlers(t *testing.T) {
581581
},
582582
},
583583
Config: Config{
584-
NetworkInterfaces: []NetworkInterface{
585-
{
584+
NetworkInterfaces: []NetworkInterface{{
585+
StaticConfiguration: &StaticNetworkConfiguration{
586586
MacAddress: "macaddress",
587587
HostDevName: "host",
588588
},
589-
},
589+
}},
590590
},
591591
},
592592
{

0 commit comments

Comments
 (0)