MCPcopy
hub / github.com/caddyserver/caddy / Match

Method Match

modules/caddytls/matchers.go:470–484  ·  view source on GitHub ↗

Match matches hello based on the connection's remote IP.

(hello *tls.ClientHelloInfo)

Source from the content-addressed store, hash-verified

468
469// Match matches hello based on the connection's remote IP.
470func (m MatchLocalIP) Match(hello *tls.ClientHelloInfo) bool {
471 localAddr := hello.Conn.LocalAddr().String()
472 ipStr, _, err := net.SplitHostPort(localAddr)
473 if err != nil {
474 ipStr = localAddr // weird; maybe no port?
475 }
476 ipAddr, err := netip.ParseAddr(ipStr)
477 if err != nil {
478 if c := m.logger.Check(zapcore.ErrorLevel, "invalid local IP address"); c != nil {
479 c.Write(zap.String("ip", ipStr))
480 }
481 return false
482 }
483 return (len(m.cidrs) == 0 || m.matches(ipAddr, m.cidrs))
484}
485
486func (MatchLocalIP) parseIPRange(str string) ([]netip.Prefix, error) {
487 var cidrs []netip.Prefix

Callers 1

TestLocalIPMatcherFunction · 0.95

Calls 5

matchesMethod · 0.95
LocalAddrMethod · 0.80
StringMethod · 0.45
CheckMethod · 0.45
WriteMethod · 0.45

Tested by 1

TestLocalIPMatcherFunction · 0.76