mirror of
https://github.com/luscis/openlan.git
synced 2025-10-06 00:57:03 +08:00
fix: firewall: add comments for iptable rules
Signed-off-by: zhihui.ding <danieldin186@gmail.com>
This commit is contained in:
@@ -92,6 +92,9 @@ func (ru IpRule) Args() []string {
|
|||||||
if ru.Output != "" {
|
if ru.Output != "" {
|
||||||
args = append(args, "-o", ru.Output)
|
args = append(args, "-o", ru.Output)
|
||||||
}
|
}
|
||||||
|
if ru.Comment != "" {
|
||||||
|
args = append(args, "-m", "comment", "--comment", ru.Comment)
|
||||||
|
}
|
||||||
if ru.Jump != "" {
|
if ru.Jump != "" {
|
||||||
jump := strings.ToUpper(ru.Jump)
|
jump := strings.ToUpper(ru.Jump)
|
||||||
if jump == "DROP" || jump == "ACCEPT" {
|
if jump == "DROP" || jump == "ACCEPT" {
|
||||||
|
@@ -220,6 +220,7 @@ func (w *WorkerImpl) Start(v api.Switcher) {
|
|||||||
Source: cfg.Bridge.Address,
|
Source: cfg.Bridge.Address,
|
||||||
NoDest: cfg.Bridge.Address,
|
NoDest: cfg.Bridge.Address,
|
||||||
Jump: cn.CMasq,
|
Jump: cn.CMasq,
|
||||||
|
Comment: "Default Gateway for DHCP",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -51,17 +51,18 @@ func (w *OpenLANWorker) toACL(acl, input string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *OpenLANWorker) openPort(protocol, port string) {
|
func (w *OpenLANWorker) openPort(protocol, port, comment string) {
|
||||||
w.out.Info("OpenLANWorker.openPort %s %s", protocol, port)
|
w.out.Info("OpenLANWorker.openPort %s %s", protocol, port)
|
||||||
// allowed forward between source and prefix.
|
// allowed forward between source and prefix.
|
||||||
w.fire.Filter.In.AddRule(network.IpRule{
|
w.fire.Filter.In.AddRule(network.IpRule{
|
||||||
Proto: protocol,
|
Proto: protocol,
|
||||||
Match: "multiport",
|
Match: "multiport",
|
||||||
DstPort: port,
|
DstPort: port,
|
||||||
|
Comment: comment,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *OpenLANWorker) toForward(input, output, source, prefix string) {
|
func (w *OpenLANWorker) toForward(input, output, source, prefix, comment string) {
|
||||||
w.out.Debug("OpenLANWorker.toForward %s:%s %s:%s", input, output, source, prefix)
|
w.out.Debug("OpenLANWorker.toForward %s:%s %s:%s", input, output, source, prefix)
|
||||||
// Allowed forward between source and prefix.
|
// Allowed forward between source and prefix.
|
||||||
w.fire.Filter.For.AddRule(network.IpRule{
|
w.fire.Filter.For.AddRule(network.IpRule{
|
||||||
@@ -69,6 +70,7 @@ func (w *OpenLANWorker) toForward(input, output, source, prefix string) {
|
|||||||
Output: output,
|
Output: output,
|
||||||
Source: source,
|
Source: source,
|
||||||
Dest: prefix,
|
Dest: prefix,
|
||||||
|
Comment: comment,
|
||||||
})
|
})
|
||||||
if source != prefix {
|
if source != prefix {
|
||||||
w.fire.Filter.For.AddRule(network.IpRule{
|
w.fire.Filter.For.AddRule(network.IpRule{
|
||||||
@@ -76,11 +78,12 @@ func (w *OpenLANWorker) toForward(input, output, source, prefix string) {
|
|||||||
Input: output,
|
Input: output,
|
||||||
Source: prefix,
|
Source: prefix,
|
||||||
Dest: source,
|
Dest: source,
|
||||||
|
Comment: comment,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *OpenLANWorker) toMasq(input, output, source, prefix string) {
|
func (w *OpenLANWorker) toMasq(source, prefix, comment string) {
|
||||||
if source == prefix {
|
if source == prefix {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -90,17 +93,19 @@ func (w *OpenLANWorker) toMasq(input, output, source, prefix string) {
|
|||||||
Source: source,
|
Source: source,
|
||||||
NoDest: source,
|
NoDest: source,
|
||||||
Jump: network.CMasq,
|
Jump: network.CMasq,
|
||||||
|
Comment: comment,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
w.fire.Nat.Post.AddRule(network.IpRule{
|
w.fire.Nat.Post.AddRule(network.IpRule{
|
||||||
Source: source,
|
Source: source,
|
||||||
Dest: prefix,
|
Dest: prefix,
|
||||||
Jump: network.CMasq,
|
Jump: network.CMasq,
|
||||||
|
Comment: comment,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *OpenLANWorker) toSnat(input, output, source, prefix string) {
|
func (w *OpenLANWorker) toSnat(source, prefix, comment string) {
|
||||||
if source == prefix {
|
if source == prefix {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -109,6 +114,7 @@ func (w *OpenLANWorker) toSnat(input, output, source, prefix string) {
|
|||||||
ToSource: source,
|
ToSource: source,
|
||||||
Dest: prefix,
|
Dest: prefix,
|
||||||
Jump: network.CSnat,
|
Jump: network.CSnat,
|
||||||
|
Comment: comment,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,16 +152,16 @@ func (w *OpenLANWorker) allowedVPN() {
|
|||||||
|
|
||||||
_, port := libol.GetHostPort(vCfg.Listen)
|
_, port := libol.GetHostPort(vCfg.Listen)
|
||||||
if vCfg.Protocol == "udp" {
|
if vCfg.Protocol == "udp" {
|
||||||
w.openPort("udp", port)
|
w.openPort("udp", port, "Open VPN")
|
||||||
} else {
|
} else {
|
||||||
w.openPort("tcp", port)
|
w.openPort("tcp", port, "Open VPN")
|
||||||
}
|
}
|
||||||
|
|
||||||
devName := vCfg.Device
|
devName := vCfg.Device
|
||||||
w.toACL(cfg.Acl, devName)
|
w.toACL(cfg.Acl, devName)
|
||||||
for _, rt := range vCfg.Routes {
|
for _, rt := range vCfg.Routes {
|
||||||
w.toForward(devName, "", vCfg.Subnet, rt)
|
w.toForward(devName, "", vCfg.Subnet, rt, "From VPN")
|
||||||
w.toMasq(devName, "", vCfg.Subnet, rt)
|
w.toMasq(vCfg.Subnet, rt, "From VPN")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,15 +178,15 @@ func (w *OpenLANWorker) allowedSubnet() {
|
|||||||
// Enable MASQUERADE, and allowed forward.
|
// Enable MASQUERADE, and allowed forward.
|
||||||
for _, rt := range cfg.Routes {
|
for _, rt := range cfg.Routes {
|
||||||
if vCfg != nil {
|
if vCfg != nil {
|
||||||
w.toForward("", br.Name, vCfg.Subnet, rt.Prefix)
|
w.toForward("", br.Name, vCfg.Subnet, rt.Prefix, "To VPN")
|
||||||
w.toMasq("", br.Name, vCfg.Subnet, rt.Prefix)
|
w.toMasq(vCfg.Subnet, rt.Prefix, "To VPN")
|
||||||
}
|
}
|
||||||
|
|
||||||
w.toForward(br.Name, "", subnet, rt.Prefix)
|
w.toForward(br.Name, "", subnet, rt.Prefix, "To route")
|
||||||
if rt.MultiPath != nil {
|
if rt.MultiPath != nil {
|
||||||
w.toSnat(br.Name, "", ifAddr, rt.Prefix)
|
w.toSnat(ifAddr, rt.Prefix, "To SNAT")
|
||||||
} else if rt.Mode == "snat" {
|
} else if rt.Mode == "snat" {
|
||||||
w.toMasq(br.Name, "", subnet, rt.Prefix)
|
w.toMasq(subnet, rt.Prefix, "To Masq")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -129,6 +129,7 @@ func (v *Switch) enablePort(protocol, port string) {
|
|||||||
Proto: protocol,
|
Proto: protocol,
|
||||||
Match: "multiport",
|
Match: "multiport",
|
||||||
DstPort: port,
|
DstPort: port,
|
||||||
|
Comment: "Open Default Ports",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user