This commit is contained in:
tamilmani1989 2020-04-01 13:21:47 -07:00 коммит произвёл GitHub
Родитель 47f6d8f3d9
Коммит dc1ecbfd95
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 29 добавлений и 5 удалений

Просмотреть файл

@ -3,5 +3,6 @@ RUN apt -y update
RUN apt-get -y upgrade
RUN apt install -y ebtables
RUN apt install -y net-tools
COPY networkmonitor /usr/bin/networkmonitor
CMD ["/usr/bin/networkmonitor"]
COPY azure-cnms /usr/bin/azure-cnms
RUN chmod +x /usr/bin/azure-cnms
CMD ["/usr/bin/azure-cnms"]

Просмотреть файл

@ -8,6 +8,10 @@ import (
"github.com/Azure/azure-container-networking/log"
)
const (
ipv6Mask = "/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
)
// monitorNetworkState compares current ebtable nat rules with state rules and matches state.
func (nm *networkManager) monitorNetworkState(networkMonitor *cnms.NetworkMonitor) error {
currentEbtableRulesMap, err := cnms.GetEbTableRulesInMap()
@ -34,13 +38,32 @@ func (nm *networkManager) AddStateRulesToMap() map[string]string {
snatKey := fmt.Sprintf("-s Unicast -o %s -j snat --to-src %s --snat-arp --snat-target ACCEPT", extIf.Name, extIf.MacAddress.String())
rulesMap[snatKey] = ebtables.PostRouting
for _, extIP := range extIf.IPAddresses {
if extIP.IP.To4() != nil {
arpReplyKey := fmt.Sprintf("-p ARP --arp-op Request --arp-ip-dst %s -j arpreply --arpreply-mac %s", extIP.IP.String(), extIf.MacAddress.String())
rulesMap[arpReplyKey] = ebtables.PreRouting
}
}
for _, nw := range extIf.Networks {
for _, ep := range nw.Endpoints {
for _, ipAddr := range ep.IPAddresses {
arpReplyKey := fmt.Sprintf("-p ARP --arp-op Request --arp-ip-dst %s -j arpreply --arpreply-mac %s", ipAddr.IP.String(), ep.MacAddress.String())
rulesMap[arpReplyKey] = ebtables.PreRouting
if ipAddr.IP.To4() != nil {
arpReplyKey := fmt.Sprintf("-p ARP --arp-op Request --arp-ip-dst %s -j arpreply --arpreply-mac %s", ipAddr.IP.String(), ep.MacAddress.String())
rulesMap[arpReplyKey] = ebtables.PreRouting
}
dnatMacKey := fmt.Sprintf("-p IPv4 -i %s --ip-dst %s -j dnat --to-dst %s --dnat-target ACCEPT", extIf.Name, ipAddr.IP.String(), ep.MacAddress.String())
dst := "--ip-dst"
proto := "IPv4"
ipAddress := ipAddr.IP.String()
if ipAddr.IP.To4() == nil {
dst = "--ip6-dst"
proto = "IPv6"
ipAddress = ipAddr.IP.String() + ipv6Mask
}
dnatMacKey := fmt.Sprintf("-p %s -i %s %s %s -j dnat --to-dst %s --dnat-target ACCEPT",
proto, extIf.Name, dst, ipAddress, ep.MacAddress.String())
rulesMap[dnatMacKey] = ebtables.PreRouting
}
}