mirror of
https://github.com/MengMengCode/CLICD.git
synced 2026-08-04 21:31:23 +08:00
KVM的端口转发_ 失效修复
This commit is contained in:
@@ -252,6 +252,7 @@ func EnsureForwardRules(bridge string) {
|
||||
if bridge == "" {
|
||||
bridge = "lxcbr0"
|
||||
}
|
||||
ensureLibvirtForwardRules(bridge)
|
||||
rules := [][]string{
|
||||
{"-i", bridge, "-j", "ACCEPT"},
|
||||
{"-o", bridge, "-j", "ACCEPT"},
|
||||
@@ -269,6 +270,33 @@ func EnsureForwardRules(bridge string) {
|
||||
}
|
||||
}
|
||||
|
||||
func ensureLibvirtForwardRules(bridge string) {
|
||||
if bridge != "virbr0" || exec.Command("iptables", "-L", "LIBVIRT_FWI", "-n").Run() != nil {
|
||||
return
|
||||
}
|
||||
rules := []struct {
|
||||
chain string
|
||||
args []string
|
||||
}{
|
||||
{chain: "LIBVIRT_FWI", args: []string{"-o", bridge, "-j", "ACCEPT"}},
|
||||
{chain: "LIBVIRT_FWO", args: []string{"-i", bridge, "-j", "ACCEPT"}},
|
||||
{chain: "LIBVIRT_FWX", args: []string{"-i", bridge, "-o", bridge, "-j", "ACCEPT"}},
|
||||
}
|
||||
for _, rule := range rules {
|
||||
if exec.Command("iptables", "-L", rule.chain, "-n").Run() != nil {
|
||||
continue
|
||||
}
|
||||
for {
|
||||
deleteArgs := append([]string{"-D", rule.chain}, rule.args...)
|
||||
if exec.Command("iptables", deleteArgs...).Run() != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
insertArgs := append([]string{"-I", rule.chain, "1"}, rule.args...)
|
||||
exec.Command("iptables", insertArgs...).Run()
|
||||
}
|
||||
}
|
||||
|
||||
// CleanPortMappings removes all iptables rules for a container
|
||||
func (m *Manager) CleanPortMappings(id int) error {
|
||||
tag := clicdTag(id)
|
||||
|
||||
Reference in New Issue
Block a user