Match matches hello based on the connection's remote IP.
(hello *tls.ClientHelloInfo)
| 468 | |
| 469 | // Match matches hello based on the connection's remote IP. |
| 470 | func (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 | |
| 486 | func (MatchLocalIP) parseIPRange(str string) ([]netip.Prefix, error) { |
| 487 | var cidrs []netip.Prefix |