Skip to content

Commit c6406ac

Browse files
farsonicdmacvicar
andauthored
Add ability to set mode=private to a macvlan interface. (#1154)
Co-authored-by: Duncan Mac-Vicar P. <duncan@mac-vicar.eu>
1 parent b9e4fb7 commit c6406ac

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

libvirt/domain.go

+7
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,13 @@ func setNetworkInterfaces(d *schema.ResourceData, domainDef *libvirtxml.Domain,
762762
Mode: "vepa",
763763
},
764764
}
765+
} else if devI, ok := d.GetOk(prefix + ".private"); ok {
766+
netIface.Source = &libvirtxml.DomainInterfaceSource{
767+
Direct: &libvirtxml.DomainInterfaceSourceDirect{
768+
Dev: devI.(string),
769+
Mode: "private",
770+
},
771+
}
765772
} else if devI, ok := d.GetOk(prefix + ".macvtap"); ok {
766773
netIface.Source = &libvirtxml.DomainInterfaceSource{
767774
Direct: &libvirtxml.DomainInterfaceSourceDirect{

libvirt/resource_libvirt_domain.go

+7
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ func resourceLibvirtDomain() *schema.Resource {
214214
Type: schema.TypeString,
215215
Optional: true,
216216
},
217+
"private": {
218+
Type: schema.TypeString,
219+
Optional: true,
220+
},
217221
"macvtap": {
218222
Type: schema.TypeString,
219223
Optional: true,
@@ -994,6 +998,7 @@ func resourceLibvirtDomainRead(ctx context.Context, d *schema.ResourceData, meta
994998
"network_name": "",
995999
"bridge": "",
9961000
"vepa": "",
1001+
"private": "",
9971002
"macvtap": "",
9981003
"passthrough": "",
9991004
"mac": mac,
@@ -1045,6 +1050,8 @@ func resourceLibvirtDomainRead(ctx context.Context, d *schema.ResourceData, meta
10451050
switch networkInterfaceDef.Source.Direct.Mode {
10461051
case "vepa":
10471052
netIface["vepa"] = networkInterfaceDef.Source.Direct.Dev
1053+
case "private":
1054+
netIface["private"] = networkInterfaceDef.Source.Direct.Dev
10481055
case "bridge":
10491056
netIface["macvtap"] = networkInterfaceDef.Source.Direct.Dev
10501057
case "passthrough":

website/docs/r/domain.html.markdown

+2
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ When connecting to a LAN, users can specify a target device with:
377377
sent to the VF/IF of the configured network device. Depending on the
378378
capabilities of the device additional prerequisites or limitations may apply;
379379
for example, on Linux this requires kernel 2.6.38 or newer.
380+
* `private` - All packets are sent to the external bridge and will only be delivered to a target VM on the same host if they are sent through an external router or gateway and that device sends them back to the host. This procedure is followed if either the source or destination device is in private mode.
381+
380382

381383
Example of a `macvtap` interface:
382384

0 commit comments

Comments
 (0)