Debian Codegraph @

serve_mux.go

raw symbols SCIP
1 package dnsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/
2
3 import (
4 "syncscip-go gomod github.com/golang/go/src go1.25.0 sync/"
5 )
6
7 // ServeMux is an DNS request multiplexer. It matches the zone name of
8 // each incoming request against a list of registered patterns add calls
9 // the handler for the pattern that most closely matches the zone name.
10 //
11 // ServeMux is DNSSEC aware, meaning that queries for the DS record are
12 // redirected to the parent zone (if that is also registered), otherwise
13 // the child gets the query.
14 //
15 // ServeMux is also safe for concurrent access from multiple goroutines.
16 //
17 // The zero ServeMux is empty and ready for use.
18 type ServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux# struct {
19 zscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#z. map[string]Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler#
20 mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#m. syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.RWMutexscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#
21 }
22
23 // NewServeMux allocates and returns a new ServeMux.
24 func NewServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewServeMux().() *ServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux# {
25 return new(ServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#)
26 }
27
28 // DefaultServeMux is the default ServeMux used by Serve.
29 var DefaultServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DefaultServeMux. = NewServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewServeMux().()
30
31 func (mux *ServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#) matchscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#match().(q string, t uint16) Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler# {
32 mux.mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#m..RLockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RLock().()
33 defer mux.mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#m..RUnlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RUnlock().()
34 if mux.zscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#z. == nil {
35 return nil
36 }
37
38 q = CanonicalNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CanonicalName().(q)
39
40 var handler Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler#
41 for off, end := 0, false; !end; off, end = NextLabelscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NextLabel().(q, off) {
42 if h, ok := mux.zscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#z.[q[off:]]; ok {
43 if t != TypeDSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TypeDS. {
44 return h
45 }
46 // Continue for DS to see if we have a parent too, if so delegate to the parent
47 handler = h
48 }
49 }
50
51 // Wildcard match, if we have found nothing try the root zone as a last resort.
52 if h, ok := mux.zscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#z.["."]; ok {
53 return h
54 }
55
56 return handler
57 }
58
59 // Handle adds a handler to the ServeMux for pattern.
60 func (mux *ServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#) Handlescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#Handle().(pattern string, handler Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler#) {
61 if pattern == "" {
62 panic("dns: invalid pattern " + pattern)
63 }
64 mux.mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#m..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().()
65 if mux.zscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#z. == nil {
66 mux.zscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#z. = make(map[string]Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler#)
67 }
68 mux.zscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#z.[CanonicalNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CanonicalName().(pattern)] = handler
69 mux.mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#m..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Unlock().()
70 }
71
72 // HandleFunc adds a handler function to the ServeMux for pattern.
73 func (mux *ServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#) HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#HandleFunc().(pattern string, handler func(ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#)) {
74 mux.Handlescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#Handle().(pattern, HandlerFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandlerFunc#(handler))
75 }
76
77 // HandleRemove deregisters the handler specific for pattern from the ServeMux.
78 func (mux *ServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#) HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#HandleRemove().(pattern string) {
79 if pattern == "" {
80 panic("dns: invalid pattern " + pattern)
81 }
82 mux.mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#m..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().()
83 delete(mux.zscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#z., CanonicalNamescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/CanonicalName().(pattern))
84 mux.mscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#m..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Unlock().()
85 }
86
87 // ServeDNS dispatches the request to the handler whose pattern most
88 // closely matches the request message.
89 //
90 // ServeDNS is DNSSEC aware, meaning that queries for the DS record
91 // are redirected to the parent zone (if that is also registered),
92 // otherwise the child gets the query.
93 //
94 // If no handler is found, or there is no question, a standard REFUSED
95 // message is returned
96 func (mux *ServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#) ServeDNSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#ServeDNS().(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, req *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) {
97 var h Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler#
98 if len(req.Questionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Question.) >= 1 { // allow more than one question
99 h = mux.matchscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#match().(req.Questionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Question.[0].Namescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Question#Name., req.Questionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Question.[0].Qtypescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Question#Qtype.)
100 }
101
102 if h != nil {
103 h.ServeDNSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler#ServeDNS.(w, req)
104 } else {
105 handleRefusedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/handleRefused().(w, req)
106 }
107 }
108
109 // Handle registers the handler with the given pattern
110 // in the DefaultServeMux. The documentation for
111 // ServeMux explains how patterns are matched.
112 func Handlescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handle().(pattern string, handler Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler#) { DefaultServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DefaultServeMux..Handlescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#Handle().(pattern, handler) }
113
114 // HandleRemove deregisters the handle with the given pattern
115 // in the DefaultServeMux.
116 func HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleRemove().(pattern string) { DefaultServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DefaultServeMux..HandleRemovescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#HandleRemove().(pattern) }
117
118 // HandleFunc registers the handler function with the given pattern
119 // in the DefaultServeMux.
120 func HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFunc().(pattern string, handler func(ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#)) {
121 DefaultServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DefaultServeMux..HandleFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ServeMux#HandleFunc().(pattern, handler)
122 }