Skip to content

Commit

Permalink
[vnet] run os config on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
nklaassen committed Feb 5, 2025
1 parent b8ace08 commit d646d38
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions lib/vnet/admin_process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,37 @@ func runWindowsAdminProcess(ctx context.Context, cfg *windowsAdminProcessConfig)
return trace.Wrap(err, "creating network stack")
}

ctx, cancel := context.WithCancel(ctx)
defer cancel()
errCh := make(chan error)
go func() {
errCh <- trace.Wrap(networkStack.run(ctx), "running network stack")
}()
loop:
for {
select {
case <-time.After(time.Second):
if err := clt.Ping(ctx); err != nil {
log.InfoContext(ctx, "Failed to ping client application, it may have exited, shutting down", "error", err)
break loop
osConfigProvider := newRemoteOSConfigProvider(clt, tunName,
networkStackConfig.ipv6Prefix.String(), networkStackConfig.dnsIPv6.String())
osConfigurator := newOSConfigurator(osConfigProvider)

g, ctx := errgroup.WithContext(ctx)
g.Go(func() error {
if err := networkStack.run(ctx); err != nil {
return trace.Wrap(err, "running network stack")
}
return errors.New("network stack terminated")
})
g.Go(func() error {
if err := osConfigurator.runOSConfigurationLoop(ctx); err != nil {
return trace.Wrap(err, "running OS configuration loop")
}
return errors.New("OS configuration loop terminated")
})
g.Go(func() error {
tick := time.Tick(time.Second)
for {
select {
case <-tick:
if err := clt.Ping(ctx); err != nil {
return trace.Wrap(err, "failed to ping client application, it may have exited, shutting down")
}
case <-ctx.Done():
return ctx.Err()
}
case <-ctx.Done():
log.InfoContext(ctx, "Context canceled, shutting down", "error", err)
break loop
}
}
// Cancel the context and wait for networkStack.run to terminate.
cancel()
err = <-errCh
return trace.Wrap(err, "running VNet network stack")
})
return trace.Wrap(g.Wait(), "running VNet admin process")
}

func newWindowsNetworkStackConfig(tun tunDevice, clt *clientApplicationServiceClient) (*networkStackConfig, error) {
Expand Down

0 comments on commit d646d38

Please sign in to comment.