Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated backport of #2543: Shortening datapath downtime for libreswan cable #2597

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
20 changes: 13 additions & 7 deletions pkg/cable/libreswan/libreswan.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type libreswan struct {

debug bool
forceUDPEncapsulation bool
plutoStarted bool
}

type specification struct {
Expand Down Expand Up @@ -133,6 +134,7 @@ func NewLibreswan(localEndpoint *types.SubmarinerEndpoint, localCluster *types.S
localEndpoint: *localEndpoint,
connections: []subv1.Connection{},
forceUDPEncapsulation: ipSecSpec.ForceEncaps,
plutoStarted: false,
}, nil
}

Expand All @@ -154,11 +156,6 @@ func (i *libreswan) Init() error {

fmt.Fprintf(file, "%%any %%any : PSK \"%s\"\n", i.secretKey)

// Ensure Pluto is started
if err := i.runPluto(); err != nil {
return errors.Wrap(err, "error starting Pluto")
}

return nil
}

Expand Down Expand Up @@ -334,6 +331,15 @@ func whack(args ...string) error {
// ConnectToEndpoint establishes a connection to the given endpoint and returns a string
// representation of the IP address of the target endpoint.
func (i *libreswan) ConnectToEndpoint(endpointInfo *natdiscovery.NATEndpointInfo) (string, error) {
if !i.plutoStarted {
// Ensure Pluto is started
if err := i.runPluto(); err != nil {
logger.FatalOnError(err, "Error running Pluto")
}

i.plutoStarted = true
}

// We'll panic if endpointInfo is nil, this is intentional
endpoint := &endpointInfo.Endpoint

Expand Down Expand Up @@ -599,7 +605,7 @@ func (i *libreswan) runPluto() error {
}()

// Wait up to 5s for the control socket.
for i := 0; i < 5; i++ {
for i := 0; i < 250; i++ {
_, err := os.Stat("/run/pluto/pluto.ctl")
if err == nil {
break
Expand All @@ -610,7 +616,7 @@ func (i *libreswan) runPluto() error {
break
}

time.Sleep(1 * time.Second)
time.Sleep(20 * time.Millisecond)
}

if i.debug {
Expand Down
Loading