Skip to content

Commit

Permalink
Alert for blocked ESP protocol as part of diagnose
Browse files Browse the repository at this point in the history
When there is no NAT between the Gateway nodes and Libreswan
cable-driver is used, IPsec protocol uses UDP/4500 port for
exchanging the keys and ESP for data transfer. As part of
subctl diagnose command, this PR now validates if there is
a potential issue with ESP and returns appropriate error
message.

Related to: submariner-io/submariner#2658
Signed-off-by: Sridhar Gaddam <[email protected]>
  • Loading branch information
sridhargaddam committed Aug 28, 2023
1 parent 64d82fd commit e745bc9
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions pkg/diagnose/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ const (
NatDiscoveryPort
)

const (
Libreswan = "libreswan"
Wireguard = "wireguard"
VxLAN = "vxlan"
)

const (
clientSourcePort = "9898"
loadBalancerName = "submariner-gateway"
Expand Down Expand Up @@ -245,22 +251,48 @@ func verifyConnectivity(localClusterInfo, remoteClusterInfo *cluster.Info, names

defer cPod.Delete()

if err = cPod.AwaitCompletion(); err != nil {
err = awaitPodCompletion(cPod, sPod, status)
if err != nil {
return err
}

if options.VerboseOutput {
status.Success("tcpdump output from sniffer pod on Gateway node:\n%s", sPod.PodOutput)
}

var espNeeded bool
if gatewayPodIP == localEndpoint.Spec.PrivateIP && localEndpoint.Spec.Backend == Libreswan {
espNeeded = true
}

return validateOutput(sPod, clientMessage, localEndpoint.Spec.Hostname, destPort, espNeeded, status)
}

func awaitPodCompletion(cPod, sPod *pods.Scheduled, status reporter.Interface) error {
if err := cPod.AwaitCompletion(); err != nil {
return status.Error(err, "Error waiting for the client pod to finish its execution")
}

if err = sPod.AwaitCompletion(); err != nil {
if err := sPod.AwaitCompletion(); err != nil {
return status.Error(err, "Error waiting for the sniffer pod to finish its execution")
}

if options.VerboseOutput {
status.Success("tcpdump output from sniffer pod on Gateway node:\n%s", sPod.PodOutput)
}
return nil
}

func validateOutput(sPod *pods.Scheduled, clientMessage, hostname string, destPort int32,
espNeeded bool, status reporter.Interface,
) error {
if !strings.Contains(sPod.PodOutput, clientMessage) {
espMsg := ""

if espNeeded {
espMsg = " and ESP traffic"
}

return status.Error(fmt.Errorf("the tcpdump output from the sniffer pod does not include the message"+
" sent from client pod. Please check that your firewall configuration allows UDP/%d traffic"+
" on the %q node. Actual pod output: \n%s", destPort, localEndpoint.Spec.Hostname, truncate(sPod.PodOutput)), "")
"%s on the %q node. Actual pod output: \n%s", destPort, espMsg, hostname, truncate(sPod.PodOutput)), "")
}

return nil
Expand Down Expand Up @@ -301,7 +333,7 @@ func getTargetPort(submariner *v1alpha1.Submariner, endpoint *subv1.Endpoint, tg
var err error

switch endpoint.Spec.Backend {
case "libreswan", "wireguard", "vxlan":
case Libreswan, Wireguard, VxLAN:
if tgtport == TunnelPort {
targetPort, err = endpoint.Spec.GetBackendPort(subv1.UDPPortConfig, int32(submariner.Spec.CeIPSecNATTPort))
if err != nil {
Expand Down

0 comments on commit e745bc9

Please sign in to comment.