Skip to content
Merged
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
35 changes: 30 additions & 5 deletions pkg/controllers/proxy/network_services_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,19 @@ func (nsc *NetworkServicesController) sync() error {
return nil
}

// Lookup service ip, protocol, port by given fwmark value (reverse of generateFwmark)
func (nsc *NetworkServicesController) lookupServiceByFWMark(FWMark uint32) (string, string, int) {
for _, svc := range nsc.serviceMap {
for _, externalIP := range svc.externalIPs {
gfwmark := generateFwmark(externalIP, svc.protocol, fmt.Sprint(svc.port))
if FWMark == gfwmark {
return externalIP, svc.protocol, svc.port
}
}
}
return "", "", 0
}

func getIpvsFirewallInputChainRule() []string {
// The iptables rule for use in {setup,cleanup}IpvsFirewall.
return []string{
Expand Down Expand Up @@ -579,15 +592,27 @@ func (nsc *NetworkServicesController) syncIpvsFirewall() error {
ipvsServicesSets := make([]string, 0, len(ipvsServices))

for _, ipvsService := range ipvsServices {
protocol := "udp"
if ipvsService.Protocol == syscall.IPPROTO_TCP {
protocol = "tcp"
var address, protocol string
var port int
if ipvsService.Address != nil {
address = ipvsService.Address.String()
if ipvsService.Protocol == syscall.IPPROTO_TCP {
protocol = "tcp"
} else {
protocol = "udp"
}
port = int(ipvsService.Port)
} else if ipvsService.FWMark != 0 {
address, protocol, port = nsc.lookupServiceByFWMark(ipvsService.FWMark)
if address == "" {
continue
}
}

serviceIPsSet := ipvsService.Address.String()
serviceIPsSet := address
serviceIPsSets = append(serviceIPsSets, serviceIPsSet)

ipvsServicesSet := fmt.Sprintf("%s,%s:%d", ipvsService.Address.String(), protocol, ipvsService.Port)
ipvsServicesSet := fmt.Sprintf("%s,%s:%d", address, protocol, port)
ipvsServicesSets = append(ipvsServicesSets, ipvsServicesSet)

}
Expand Down