代码拉取完成,页面将自动刷新
package iptablesctrl
// legacyProxyRules creates all the proxy specific rules.
import (
"text/template"
"git.cloud.top/DSec/trireme-lib/common"
"git.cloud.top/DSec/trireme-lib/policy"
"go.uber.org/zap"
)
// This refers to the pu chain rules for pus in older distros like RH 6.9/Ubuntu 14.04. The rules
// consider source ports to identify packets from the process.
func (i *iptables) legacyPuChainRules(contextID, appChain string, netChain string, mark string, tcpPorts, udpPorts string, proxyPort string, proxyPortSetName string,
appSection, netSection string, puType common.PUType, dnsProxyPort string, dnsServerIP string) [][]string {
iptableCgroupSection := appSection
iptableNetSection := netSection
rules := [][]string{}
if tcpPorts != "0" {
rules = append(rules, [][]string{
{
appPacketIPTableContext,
iptableCgroupSection,
"-p", tcpProto,
"-m", "multiport",
"--source-ports", tcpPorts,
"-m", "comment", "--comment", "Server-specific-chain",
"-j", "MARK", "--set-mark", mark,
},
{
appPacketIPTableContext,
iptableCgroupSection,
"-p", tcpProto,
"-m", "multiport",
"--source-ports", tcpPorts,
"-m", "comment", "--comment", "Server-specific-chain",
"-j", appChain,
},
{
netPacketIPTableContext,
iptableNetSection,
"-p", tcpProto,
"-m", "multiport",
"--destination-ports", tcpPorts,
"-m", "comment", "--comment", "Container-specific-chain",
"-j", netChain,
}}...)
}
if udpPorts != "0" {
rules = append(rules, [][]string{
{
appPacketIPTableContext,
iptableCgroupSection,
"-p", udpProto,
"-m", "multiport",
"--source-ports", udpPorts,
"-m", "comment", "--comment", "Server-specific-chain",
"-j", "MARK", "--set-mark", mark,
},
{
appPacketIPTableContext,
iptableCgroupSection,
"-p", udpProto, "-m", "mark", "--mark", mark,
"-m", "addrtype", "--src-type", "LOCAL",
"-m", "addrtype", "--dst-type", "LOCAL",
"-m", "state", "--state", "NEW",
"-j", "NFLOG", "--nflog-group", "10",
"--nflog-prefix", policy.DefaultAcceptLogPrefix(contextID),
},
{
appPacketIPTableContext,
iptableCgroupSection,
"-m", "comment", "--comment", "traffic-same-pu",
"-p", udpProto, "-m", "mark", "--mark", mark,
"-m", "addrtype", "--src-type", "LOCAL",
"-m", "addrtype", "--dst-type", "LOCAL",
"-j", "ACCEPT",
},
{
appPacketIPTableContext,
iptableCgroupSection,
"-p", udpProto,
"-m", "multiport",
"--source-ports", udpPorts,
"-m", "comment", "--comment", "Server-specific-chain",
"-j", appChain,
},
{
netPacketIPTableContext,
iptableNetSection,
"-m", "comment", "--comment", "traffic-same-pu",
"-p", udpProto, "-m", "mark", "--mark", mark,
"-m", "addrtype", "--src-type", "LOCAL",
"-m", "addrtype", "--dst-type", "LOCAL",
"-j", "ACCEPT",
},
{
netPacketIPTableContext,
iptableNetSection,
"-p", udpProto,
"-m", "multiport",
"--destination-ports", udpPorts,
"-m", "comment", "--comment", "Container-specific-chain",
"-j", netChain,
}}...)
}
if puType == common.HostPU {
// Add a capture all traffic rule for host pu. This traps all traffic going out
// of the box.
rules = append(rules, []string{
appPacketIPTableContext,
iptableCgroupSection,
"-m", "comment", "--comment", "capture all outgoing traffic",
"-j", appChain,
})
}
return append(rules, i.legacyProxyRules(tcpPorts, proxyPort, proxyPortSetName, mark, dnsProxyPort, dnsServerIP)...)
}
func (i *iptables) legacyProxyRules(tcpPorts string, proxyPort string, proxyPortSetName string, cgroupMark string, dnsProxyPort string, dnsServerIP string) [][]string {
destSetName, srvSetName := i.getSetNames(proxyPortSetName)
aclInfo := ACLInfo{
MangleTable: appPacketIPTableContext,
NatTable: appProxyIPTableContext,
MangleProxyAppChain: proxyOutputChain,
MangleProxyNetChain: proxyInputChain,
NatProxyNetChain: natProxyInputChain,
NatProxyAppChain: natProxyOutputChain,
CgroupMark: cgroupMark,
DestIPSet: destSetName,
SrvIPSet: srvSetName,
ProxyPort: proxyPort,
ProxyMark: proxyMark,
TCPPorts: tcpPorts,
DNSProxyPort: dnsProxyPort,
DNSServerIP: dnsServerIP,
}
tmpl := template.Must(template.New(legacyProxyRules).Funcs(template.FuncMap{
"isCgroupSet": func() bool {
return cgroupMark != ""
},
"enableDNSProxy": func() bool {
return dnsServerIP != ""
},
}).Parse(legacyProxyRules))
rules, err := extractRulesFromTemplate(tmpl, aclInfo)
if err != nil {
zap.L().Warn("unable to extract rules", zap.Error(err))
}
return rules
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。