Skip to content

Commit 047db58

Browse files
eybergIan Eyberg
and
Ian Eyberg
authored
enabling virtio-net-pci if opsD is set (nanovms#1414)
* initial mac bridge support * mm --------- Co-authored-by: Ian Eyberg <[email protected]>
1 parent b75f279 commit 047db58

File tree

9 files changed

+850
-29
lines changed

9 files changed

+850
-29
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
*.dmg
2+
*.zip
13
*.md5
24
/.staging
35
/image

cmd/cmd_daemon.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
// DaemonizeCommand turns ops into a daemon
9+
func DaemonizeCommand() *cobra.Command {
10+
var cmdDaemonize = &cobra.Command{
11+
Use: "daemonize",
12+
Short: "Daemonize OPS",
13+
Run: daemonizeCommandHandler,
14+
}
15+
16+
return cmdDaemonize
17+
}
18+
19+
func daemonizeCommandHandler(cmd *cobra.Command, args []string) {
20+
fmt.Println("Note: If on a mac this expects ops to have suid bit set for networking.")
21+
fmt.Println("if you used the installer you are set otherwise run the following command\n" +
22+
"\tsudo chown -R root /usr/local/bin/qemu-system-x86_64\n" +
23+
"\tsudo chmod u+s /usr/local/bin/qemu-system-x86_64")
24+
fmt.Println("daemonizing")
25+
}

cmd/cmd_root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func GetRootCommand() *cobra.Command {
4545
// persist flags transversal to every command
4646
PersistGlobalCommandFlags(rootCmd.PersistentFlags())
4747

48+
rootCmd.AddCommand(DaemonizeCommand())
4849
rootCmd.AddCommand(BuildCommand())
4950
rootCmd.AddCommand(EnvCommand())
5051
rootCmd.AddCommand(ImageCommands())

qemu/qemu_components.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ func (dv device) String() string {
5555
sb.WriteString(fmt.Sprintf("-device %s,%s=%s", dv.driver, dv.devtype, dv.devid))
5656
}
5757

58+
} else if dv.driver == "virtio-net-pci" {
59+
sb.WriteString(fmt.Sprintf("-device %s,%s", dv.driver, dv.devtype))
60+
5861
} else {
5962
sb.WriteString(fmt.Sprintf("-device %s,%s=%s", dv.driver, dv.devtype, dv.devid))
6063
}
@@ -80,7 +83,7 @@ func (nd netdev) String() string {
8083
if len(nd.ifname) > 0 {
8184
sb.WriteString(fmt.Sprintf(",ifname=%s", nd.ifname))
8285
}
83-
if nd.nettype != "user" {
86+
if nd.nettype != "user" && nd.nettype != "vmnet-bridged" {
8487
if len(nd.script) > 0 {
8588
sb.WriteString(fmt.Sprintf(",script=%s", nd.script))
8689
} else {

qemu/qemu_unix.go

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -117,48 +117,71 @@ func (q *qemu) addSerial(serialType string) {
117117
q.serial = serial{serialtype: serialType}
118118
}
119119

120+
// we inject at release build time to enable virtio-net-pci
121+
// this is only for a packaged macos release
122+
var opsD = ""
123+
120124
// addDevice adds a device to the qemu for rendering to string arguments. If the
121125
// devType is "user" then the ifaceName is ignored and host forward ports are
122126
// added. If the mac address is empty then a random mac address is chosen.
123127
// Backend interface are created for each device and their ids are auto
124128
// incremented.
125129
func (q *qemu) addNetDevice(devType, ifaceName, mac string, hostPorts []string, udpPorts []string) {
126-
i := len(q.ifaces)
127-
si := strconv.Itoa(i)
130+
if opsD != "" {
131+
dv := device{
132+
driver: "virtio-net-pci",
133+
devtype: "netdev=vmnet",
134+
}
128135

129-
id := "n" + si
130-
dv := device{
131-
driver: "virtio-net",
132-
devtype: "netdev",
133-
devid: id,
134-
addr: "0x" + si,
135-
}
136-
ndv := netdev{
137-
nettype: devType,
138-
id: id,
139-
}
136+
ndv := netdev{
137+
nettype: "vmnet-bridged",
138+
id: "vmnet",
139+
}
140140

141-
if mac == "" {
142141
dv.mac = generateMac()
143-
}
142+
ndv.ifname = "en0"
143+
144+
q.devices = append(q.devices, dv)
145+
q.ifaces = append(q.ifaces, ndv)
144146

145-
if devType != "user" {
146-
ndv.ifname = ifaceName
147147
} else {
148-
// hack - FIXME
149-
// this is user-mode
150-
if i == 0 {
151-
for _, p := range hostPorts {
152-
ndv.hports = append(ndv.hports, portfwd{port: p, proto: "tcp"})
153-
}
154-
for _, p := range udpPorts {
155-
ndv.hports = append(ndv.hports, portfwd{port: p, proto: "udp"})
148+
i := len(q.ifaces)
149+
si := strconv.Itoa(i)
150+
151+
id := fmt.Sprintf("n%d", i)
152+
dv := device{
153+
driver: "virtio-net",
154+
devtype: "netdev",
155+
devid: id,
156+
addr: "0x" + si,
157+
}
158+
ndv := netdev{
159+
nettype: devType,
160+
id: id,
161+
}
162+
163+
if mac == "" {
164+
dv.mac = generateMac()
165+
}
166+
167+
if devType != "user" {
168+
ndv.ifname = ifaceName
169+
} else {
170+
// hack - FIXME
171+
// this is user-mode
172+
if i == 0 {
173+
for _, p := range hostPorts {
174+
ndv.hports = append(ndv.hports, portfwd{port: p, proto: "tcp"})
175+
}
176+
for _, p := range udpPorts {
177+
ndv.hports = append(ndv.hports, portfwd{port: p, proto: "udp"})
178+
}
156179
}
157180
}
158-
}
159181

160-
q.devices = append(q.devices, dv)
161-
q.ifaces = append(q.ifaces, ndv)
182+
q.devices = append(q.devices, dv)
183+
q.ifaces = append(q.ifaces, ndv)
184+
}
162185
}
163186

164187
func (q *qemu) addDiskDevice(id, driver string) {

release.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ gsutil setacl public-read gs://cli/linux/release/"$VERSION"/ops
2727
gsutil cp "$hash" gs://cli/linux/release/"$VERSION"/"$hash"
2828
gsutil setacl public-read gs://cli/linux/release/"$VERSION"/"$hash"
2929

30+
# TODO:
31+
# flag here with "-X github.com/nanovms/ops/qemu.opsD=true" for signed/packaged mac binaries
3032
GO111MODULE=on GOOS=darwin go build -ldflags "-w -X github.com/nanovms/ops/lepton.Version=$VERSION"
3133
gsutil cp ops gs://cli/darwin
3234

@@ -45,6 +47,12 @@ gsutil setacl public-read gs://cli/darwin/release/"$VERSION"/ops
4547
gsutil cp "$hash" gs://cli/darwin/release/"$VERSION"/"$hash"
4648
gsutil setacl public-read gs://cli/darwin/release/"$VERSION"/"$hash"
4749

50+
# export AC_PASSWORD=
51+
# export AC_EMAIL=
52+
# gon config.hcl
53+
# /usr/local/bin/packagesbuild -v ops-d/ops-d.pkgproj
54+
# scp ~/ops-d/build/ops-d.pkg
55+
4856
GO111MODULE=on GOOS=linux GOARCH=arm64 go build -ldflags "-X github.com/nanovms/ops/lepton.Version=$VERSION"
4957
gsutil cp ops gs://cli/linux/aarch64/
5058

scripts/config.hcl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// export AC_EMAIL && AC_PASSWORD && APP_IDENTITY
2+
3+
source = ["./ops"]
4+
bundle_id = "com.nanovms.ops"
5+
6+
apple_id {
7+
username = "@env:AC_EMAIL"
8+
password = "@env:AC_PASSWORD"
9+
}
10+
11+
sign {
12+
application_identity = "@env:APP_IDENTITY"
13+
}
14+
15+
dmg {
16+
output_path = "ops.dmg"
17+
volume_name = "OPS"
18+
}
19+
20+
zip {
21+
output_path = "ops.zip"
22+
}

0 commit comments

Comments
 (0)