-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnet.go
43 lines (34 loc) · 891 Bytes
/
net.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package qemu
import (
"fmt"
)
type NetDev struct {
Type string // Netdev type (user, tap...)
ID string // Netdev ID
IfName string // TAP: interface name
MAC string // TAP: Interface hardware address
}
// NewNetworkDevice creates a QEMU network
// device
func NewNetworkDevice(t, id string) (NetDev, error) {
var netdev NetDev
if t != "user" && t != "tap" {
return netdev, fmt.Errorf("Unsupported netdev type")
}
if len(id) == 0 {
return netdev, fmt.Errorf("You must specify a netdev ID")
}
netdev.Type = t
netdev.ID = id
return netdev, nil
}
// SetHostInterfaceName sets the host interface name
// for the netdev (if supported by netdev type)
func (n *NetDev) SetHostInterfaceName(name string) {
n.IfName = name
}
// SetMacAddress sets the mac address of the
// netdev (if supported by netdev type)
func (n *NetDev) SetMacAddress(mac string) {
n.MAC = mac
}