Skip to content

Commit 1aca174

Browse files
committed
Add network namespace parameter to run snapshot loaded VMs in a custom network namespace
Signed-off-by: Amory Hoste <[email protected]>
1 parent e7aa4ce commit 1aca174

File tree

4 files changed

+228
-111
lines changed

4 files changed

+228
-111
lines changed

proto/firecracker.pb.go

Lines changed: 80 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/firecracker.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ message LoadSnapshotRequest {
118118
string SnapshotFilePath = 2;
119119
string MemFilePath = 3;
120120
bool EnableUserPF = 4;
121+
string NetworkNamespace = 5;
121122
}
122123

123124
message LoadResponse {

runtime/helpers.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package main
1515

1616
import (
17+
"github.com/containernetworking/plugins/pkg/ns"
1718
"net"
1819
"time"
1920

@@ -118,14 +119,34 @@ func networkConfigFromProto(nwIface *proto.FirecrackerNetworkInterface, vmID str
118119
return result, nil
119120
}
120121

121-
// netNSFromProto returns the network namespace set, if any in the protobuf
122+
// netNSFromProto returns the name and handle of the network namespace set, if any in the protobuf
122123
// message.
123-
func netNSFromProto(request *proto.CreateVMRequest) string {
124+
func netNSFromProto(request *proto.CreateVMRequest) (string, ns.NetNS) {
124125
if request != nil {
125-
return request.NetworkNamespace
126+
netNS, err := ns.GetNS(request.NetworkNamespace)
127+
if err != nil {
128+
return "", nil
129+
}
130+
131+
return request.NetworkNamespace, netNS
132+
}
133+
134+
return "", nil
135+
}
136+
137+
// netNSFromProto returns the name and handle of the network namespace set, if any in the protobuf
138+
// message.
139+
func netNSFromSnapRequest(request *proto.LoadSnapshotRequest) (string, ns.NetNS) {
140+
if request != nil {
141+
netNS, err := ns.GetNS(request.NetworkNamespace)
142+
if err != nil {
143+
return "", nil
144+
}
145+
146+
return request.NetworkNamespace, netNS
126147
}
127148

128-
return ""
149+
return "", nil
129150
}
130151

131152
// rateLimiterFromProto creates a firecracker RateLimiter object from the

0 commit comments

Comments
 (0)