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>
146 lines
4.3 KiB
Go
146 lines
4.3 KiB
Go
package dnsserver
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/coredns/caddy"
|
|
"github.com/coredns/coredns/plugin"
|
|
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
func TestKeyForConfig(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
blockIndex int
|
|
blockKeyIndex int
|
|
expected string
|
|
}{
|
|
{"zero_indices", 0, 0, "0:0"},
|
|
{"positive_indices", 1, 2, "1:2"},
|
|
{"larger_indices", 10, 5, "10:5"},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
result := keyForConfig(tc.blockIndex, tc.blockKeyIndex)
|
|
if result != tc.expected {
|
|
t.Errorf("Expected %s, got %s for blockIndex %d and blockKeyIndex %d",
|
|
tc.expected, result, tc.blockIndex, tc.blockKeyIndex)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetConfig(t *testing.T) {
|
|
controller := caddy.NewTestController("dns", "")
|
|
initialCtx := controller.Context()
|
|
dnsCtx, ok := initialCtx.(*dnsContext)
|
|
if !ok {
|
|
t.Fatalf("controller.Context() did not return a *dnsContext, got %T", initialCtx)
|
|
}
|
|
if dnsCtx.keysToConfigs == nil {
|
|
t.Fatal("dnsCtx.keysToConfigs is nil; it should have been initialized by newContext")
|
|
}
|
|
|
|
t.Run("returns and saves default config when config missing", func(t *testing.T) {
|
|
controller.ServerBlockIndex = 0
|
|
controller.ServerBlockKeyIndex = 0
|
|
key := keyForConfig(controller.ServerBlockIndex, controller.ServerBlockKeyIndex)
|
|
|
|
// Ensure config doesn't exist initially for this specific key
|
|
delete(dnsCtx.keysToConfigs, key)
|
|
|
|
cfg := GetConfig(controller)
|
|
if cfg == nil {
|
|
t.Fatal("GetConfig returned nil (should create and return a default)")
|
|
}
|
|
if len(cfg.ListenHosts) != 1 || cfg.ListenHosts[0] != "" {
|
|
t.Errorf("Expected default ListenHosts [\"\"] for auto-created config, got %v", cfg.ListenHosts)
|
|
}
|
|
|
|
savedCfg, found := dnsCtx.keysToConfigs[key]
|
|
if !found {
|
|
t.Fatal("fallback did not save the default config into the context")
|
|
}
|
|
if savedCfg != cfg {
|
|
t.Fatal("config is not the same instance as the one saved in the context")
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestAddPluginToAllServerBlocks(t *testing.T) {
|
|
c := caddy.NewTestController("dns", "")
|
|
ctx := c.Context().(*dnsContext)
|
|
first := &Config{}
|
|
secondZone := &Config{firstConfigInBlock: first}
|
|
third := &Config{}
|
|
first.firstConfigInBlock = first
|
|
third.firstConfigInBlock = third
|
|
ctx.configs = []*Config{first, secondZone, third}
|
|
|
|
AddPluginToAllServerBlocks(c, func(next plugin.Handler) plugin.Handler { return next })
|
|
|
|
if got := len(first.Plugin); got != 1 {
|
|
t.Fatalf("first server block has %d plugins, want 1", got)
|
|
}
|
|
if got := len(secondZone.Plugin); got != 0 {
|
|
t.Fatalf("secondary zone has %d plugins before propagation, want 0", got)
|
|
}
|
|
if got := len(third.Plugin); got != 1 {
|
|
t.Fatalf("second server block has %d plugins, want 1", got)
|
|
}
|
|
}
|
|
|
|
func TestPropagateConfigParamsMaxTCPQueries(t *testing.T) {
|
|
n := 128
|
|
first := &Config{MaxTCPQueries: &n}
|
|
first.firstConfigInBlock = first
|
|
second := &Config{firstConfigInBlock: first}
|
|
|
|
propagateConfigParams([]*Config{first, second})
|
|
|
|
if second.MaxTCPQueries == nil || *second.MaxTCPQueries != n {
|
|
t.Fatalf("expected MaxTCPQueries to propagate to second config as %d, got %v", n, second.MaxTCPQueries)
|
|
}
|
|
}
|
|
|
|
func TestPropagateConfigParamsMaxHTTPSStreams(t *testing.T) {
|
|
n := 7
|
|
first := &Config{MaxHTTPSStreams: &n}
|
|
first.firstConfigInBlock = first
|
|
second := &Config{firstConfigInBlock: first}
|
|
|
|
propagateConfigParams([]*Config{first, second})
|
|
|
|
if second.MaxHTTPSStreams == nil || *second.MaxHTTPSStreams != n {
|
|
t.Fatalf("expected MaxHTTPSStreams to propagate to second config as %d, got %v", n, second.MaxHTTPSStreams)
|
|
}
|
|
}
|
|
|
|
func TestPropagateConfigParamsMaxQUICConnections(t *testing.T) {
|
|
n := 7
|
|
first := &Config{MaxQUICConnections: &n}
|
|
first.firstConfigInBlock = first
|
|
second := &Config{firstConfigInBlock: first}
|
|
|
|
propagateConfigParams([]*Config{first, second})
|
|
|
|
if second.MaxQUICConnections == nil || *second.MaxQUICConnections != n {
|
|
t.Fatalf("expected MaxQUICConnections to propagate to second config as %d, got %v", n, second.MaxQUICConnections)
|
|
}
|
|
}
|
|
|
|
func TestPropagateConfigParamsAllowedOpcodes(t *testing.T) {
|
|
first := &Config{}
|
|
first.firstConfigInBlock = first
|
|
first.AllowOpcode(dns.OpcodeUpdate)
|
|
second := &Config{firstConfigInBlock: first}
|
|
|
|
propagateConfigParams([]*Config{first, second})
|
|
|
|
if !second.acceptsOpcode(dns.OpcodeUpdate) {
|
|
t.Fatal("expected UPDATE admission to propagate to every zone in the server block")
|
|
}
|
|
}
|