Skip to content

Commit

Permalink
Allow reachability across services on different networks in the same …
Browse files Browse the repository at this point in the history
…host

This also allows pubslied services to be accessible from containers on bridge
networks on the same host

Signed-off-by: Santhosh Manohar <[email protected]>
  • Loading branch information
Santhosh Manohar committed Aug 15, 2016
1 parent 82fb373 commit 638ef31
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions service_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,31 @@ func programIngress(gwIP net.IP, ingressPorts []*PortConfig, isDelete bool) erro
}
}

// Filter table rules to allow a published service to be accessible in the local node from..
// 1) service tasks attached to other networks
// 2) unmanaged containers on bridge networks
rule := strings.Fields(fmt.Sprintf("%s FORWARD -m state -p %s --sport %d --state ESTABLISHED,RELATED -j ACCEPT",
addDelOpt, strings.ToLower(PortConfig_Protocol_name[int32(iPort.Protocol)]), iPort.PublishedPort))
if err := iptables.RawCombinedOutput(rule...); err != nil {
errStr := fmt.Sprintf("setting up rule failed, %v: %v", rule, err)
if !isDelete {
return fmt.Errorf("%s", errStr)
}

logrus.Infof("%s", errStr)
}

rule = strings.Fields(fmt.Sprintf("%s FORWARD -p %s --dport %d -j ACCEPT",
addDelOpt, strings.ToLower(PortConfig_Protocol_name[int32(iPort.Protocol)]), iPort.PublishedPort))
if err := iptables.RawCombinedOutput(rule...); err != nil {
errStr := fmt.Sprintf("setting up rule failed, %v: %v", rule, err)
if !isDelete {
return fmt.Errorf("%s", errStr)
}

logrus.Infof("%s", errStr)
}

if err := plumbProxy(iPort, isDelete); err != nil {
logrus.Warnf("failed to create proxy for port %d: %v", iPort.PublishedPort, err)
}
Expand Down

0 comments on commit 638ef31

Please sign in to comment.