Add support for UDP routing in systemd socket activation
This commit is contained in:
parent
95dd17e020
commit
261e4395f3
9 changed files with 158 additions and 54 deletions
|
@ -25,19 +25,32 @@ type http3server struct {
|
|||
getter func(info *tls.ClientHelloInfo) (*tls.Config, error)
|
||||
}
|
||||
|
||||
func newHTTP3Server(ctx context.Context, configuration *static.EntryPoint, httpsServer *httpServer) (*http3server, error) {
|
||||
if configuration.HTTP3 == nil {
|
||||
func newHTTP3Server(ctx context.Context, name string, config *static.EntryPoint, httpsServer *httpServer) (*http3server, error) {
|
||||
var conn net.PacketConn
|
||||
var err error
|
||||
|
||||
if config.HTTP3 == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if configuration.HTTP3.AdvertisedPort < 0 {
|
||||
if config.HTTP3.AdvertisedPort < 0 {
|
||||
return nil, errors.New("advertised port must be greater than or equal to zero")
|
||||
}
|
||||
|
||||
listenConfig := newListenConfig(configuration)
|
||||
conn, err := listenConfig.ListenPacket(ctx, "udp", configuration.GetAddress())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("starting listener: %w", err)
|
||||
// if we have predefined connections from socket activation
|
||||
if socketActivation.isEnabled() {
|
||||
conn, err = socketActivation.getConn(name)
|
||||
if err != nil {
|
||||
log.Ctx(ctx).Warn().Err(err).Str("name", name).Msg("Unable to use socket activation for entrypoint")
|
||||
}
|
||||
}
|
||||
|
||||
if conn == nil {
|
||||
listenConfig := newListenConfig(config)
|
||||
conn, err = listenConfig.ListenPacket(ctx, "udp", config.GetAddress())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("starting listener: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
h3 := &http3server{
|
||||
|
@ -48,8 +61,8 @@ func newHTTP3Server(ctx context.Context, configuration *static.EntryPoint, https
|
|||
}
|
||||
|
||||
h3.Server = &http3.Server{
|
||||
Addr: configuration.GetAddress(),
|
||||
Port: configuration.HTTP3.AdvertisedPort,
|
||||
Addr: config.GetAddress(),
|
||||
Port: config.HTTP3.AdvertisedPort,
|
||||
Handler: httpsServer.Server.(*http.Server).Handler,
|
||||
TLSConfig: &tls.Config{GetConfigForClient: h3.getGetConfigForClient},
|
||||
QUICConfig: &quic.Config{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue