Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to set mode=private to a macvlan interface. #1154

Merged
merged 4 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libvirt/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,13 @@ func setNetworkInterfaces(d *schema.ResourceData, domainDef *libvirtxml.Domain,
Mode: "vepa",
},
}
} else if devI, ok := d.GetOk(prefix + ".private"); ok {
netIface.Source = &libvirtxml.DomainInterfaceSource{
Direct: &libvirtxml.DomainInterfaceSourceDirect{
Dev: devI.(string),
Mode: "private",
},
}
} else if devI, ok := d.GetOk(prefix + ".macvtap"); ok {
netIface.Source = &libvirtxml.DomainInterfaceSource{
Direct: &libvirtxml.DomainInterfaceSourceDirect{
Expand Down
7 changes: 7 additions & 0 deletions libvirt/resource_libvirt_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ func resourceLibvirtDomain() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"private": {
Type: schema.TypeString,
Optional: true,
},
"macvtap": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -994,6 +998,7 @@ func resourceLibvirtDomainRead(ctx context.Context, d *schema.ResourceData, meta
"network_name": "",
"bridge": "",
"vepa": "",
"private": "",
"macvtap": "",
"passthrough": "",
"mac": mac,
Expand Down Expand Up @@ -1045,6 +1050,8 @@ func resourceLibvirtDomainRead(ctx context.Context, d *schema.ResourceData, meta
switch networkInterfaceDef.Source.Direct.Mode {
case "vepa":
netIface["vepa"] = networkInterfaceDef.Source.Direct.Dev
case "private":
netIface["private"] = networkInterfaceDef.Source.Direct.Dev
case "bridge":
netIface["macvtap"] = networkInterfaceDef.Source.Direct.Dev
case "passthrough":
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/domain.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ When connecting to a LAN, users can specify a target device with:
sent to the VF/IF of the configured network device. Depending on the
capabilities of the device additional prerequisites or limitations may apply;
for example, on Linux this requires kernel 2.6.38 or newer.
* `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.


Example of a `macvtap` interface:

Expand Down
Loading