mirror of
https://github.com/coredns/coredns.git
synced 2026-10-08 19:45:21 -04:00
* plugin/quic: add max_connections directive Brings quic to parity with https and https3, which both already expose max_connections. The server-side plumbing already exists and is already wired up: core/dnsserver/config.go declares MaxQUICConnections *int, and server_quic.go already consumes it (DefaultQUICMaxConnections = 200, gates accepted connections on a semaphore sized from it). It was just never parsed from a Corefile directive for the quic plugin itself, so setting it today fails with "unknown property 'max_connections'". Adds the max_connections case to parseQuic, mirroring https3's exact validation (non-negative integer, 0 disables the limit, duplicate definition rejected) since the two share a config field. #8187 did the same shaped fix for https3 reaching parity with https; this does the equivalent for quic, the one remaining sibling without it. Extends TestQuicSetup with max_connections coverage (valid value, 0, missing arg, non-numeric, negative, duplicate definition, extra arg). Verified it fails without the setup.go change (unknown property error) and passes with it. Signed-off-by: stackedbyaradhya <aradhyaj736@gmail.com> * core/dnsserver: propagate MaxQUICConnections across server block keys Addresses review feedback on this PR: Caddy only runs directive setup for the first key in a server block, and the QUIC server reads MaxQUICConnections from group[0]. propagateConfigParams copies listener-wide settings from the first config in a block to the others, but it did not propagate this field. In a multi-transport block where the quic key isn't first, e.g.: .:53 quic://.:8853 { quic { max_connections 1 } } the value was stored on the first (DNS) config while the QUIC config kept MaxQUICConnections nil, so NewServerQUIC silently fell back to the default limit of 200 instead of the configured one. Adds the propagation line, mirroring the existing MaxHTTPSStreams entry (and its comment) added for the equivalent key-order issue on https. Added TestPropagateConfigParamsMaxQUICConnections, mirroring the existing TestPropagateConfigParamsMaxHTTPSStreams. Verified it fails without the register.go change and passes with it. Signed-off-by: stackedbyaradhya <aradhyaj736@gmail.com> --------- Signed-off-by: stackedbyaradhya <aradhyaj736@gmail.com>
96 lines
2.2 KiB
Go
96 lines
2.2 KiB
Go
package quic
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/coredns/caddy"
|
|
"github.com/coredns/coredns/core/dnsserver"
|
|
"github.com/coredns/coredns/plugin"
|
|
)
|
|
|
|
func init() {
|
|
caddy.RegisterPlugin("quic", caddy.Plugin{
|
|
ServerType: "dns",
|
|
Action: setup,
|
|
})
|
|
}
|
|
|
|
func setup(c *caddy.Controller) error {
|
|
err := parseQuic(c)
|
|
if err != nil {
|
|
return plugin.Error("quic", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func parseQuic(c *caddy.Controller) error {
|
|
config := dnsserver.GetConfig(c)
|
|
|
|
// Skip the "quic" directive itself
|
|
c.Next()
|
|
|
|
// Get any arguments on the "quic" line
|
|
args := c.RemainingArgs()
|
|
if len(args) > 0 {
|
|
return c.ArgErr()
|
|
}
|
|
|
|
// Process all nested directives in the block
|
|
for c.NextBlock() {
|
|
switch c.Val() {
|
|
case "max_streams":
|
|
args := c.RemainingArgs()
|
|
if len(args) != 1 {
|
|
return c.ArgErr()
|
|
}
|
|
val, err := strconv.Atoi(args[0])
|
|
if err != nil {
|
|
return c.Errf("invalid max_streams value '%s': %v", args[0], err)
|
|
}
|
|
if val <= 0 {
|
|
return c.Errf("max_streams must be a positive integer: %d", val)
|
|
}
|
|
if config.MaxQUICStreams != nil {
|
|
return c.Err("max_streams already defined for this server block")
|
|
}
|
|
config.MaxQUICStreams = &val
|
|
case "max_connections":
|
|
args := c.RemainingArgs()
|
|
if len(args) != 1 {
|
|
return c.ArgErr()
|
|
}
|
|
val, err := strconv.Atoi(args[0])
|
|
if err != nil {
|
|
return c.Errf("invalid max_connections value '%s': %v", args[0], err)
|
|
}
|
|
if val < 0 {
|
|
return c.Errf("max_connections must be a non-negative integer: %d", val)
|
|
}
|
|
if config.MaxQUICConnections != nil {
|
|
return c.Err("max_connections already defined for this server block")
|
|
}
|
|
config.MaxQUICConnections = &val
|
|
case "worker_pool_size":
|
|
args := c.RemainingArgs()
|
|
if len(args) != 1 {
|
|
return c.ArgErr()
|
|
}
|
|
val, err := strconv.Atoi(args[0])
|
|
if err != nil {
|
|
return c.Errf("invalid worker_pool_size value '%s': %v", args[0], err)
|
|
}
|
|
if val <= 0 {
|
|
return c.Errf("worker_pool_size must be a positive integer: %d", val)
|
|
}
|
|
if config.MaxQUICWorkerPoolSize != nil {
|
|
return c.Err("worker_pool_size already defined for this server block")
|
|
}
|
|
config.MaxQUICWorkerPoolSize = &val
|
|
default:
|
|
return c.Errf("unknown property '%s'", c.Val())
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|