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

Method UnmarshalCaddyfile

modules/caddytls/matchers.go:401–434  ·  view source on GitHub ↗

UnmarshalCaddyfile sets up the MatchRemoteIP from Caddyfile tokens. Syntax: remote_ip <ranges...> Note: IPs and CIDRs prefixed with ! symbol are treated as not_ranges

(d *caddyfile.Dispenser)

Source from the content-addressed store, hash-verified

399//
400// Note: IPs and CIDRs prefixed with ! symbol are treated as not_ranges
401func (m *MatchRemoteIP) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
402 for d.Next() {
403 wrapper := d.Val()
404
405 // At least one same-line option must be provided
406 if d.CountRemainingArgs() == 0 {
407 return d.ArgErr()
408 }
409
410 for d.NextArg() {
411 val := d.Val()
412 var exclamation bool
413 if len(val) > 1 && val[0] == '!' {
414 exclamation, val = true, val[1:]
415 }
416 ranges := []string{val}
417 if val == "private_ranges" {
418 ranges = internal.PrivateRangesCIDR()
419 }
420 if exclamation {
421 m.NotRanges = append(m.NotRanges, ranges...)
422 } else {
423 m.Ranges = append(m.Ranges, ranges...)
424 }
425 }
426
427 // No blocks are supported
428 if d.NextBlock(d.Nesting()) {
429 return d.Errf("malformed TLS handshake matcher '%s': blocks are not supported", wrapper)
430 }
431 }
432
433 return nil
434}
435
436// MatchLocalIP matches based on the IP address of the interface
437// receiving the connection. Specific IPs or CIDR ranges can be specified.

Callers

nothing calls this directly

Calls 9

PrivateRangesCIDRFunction · 0.92
ValMethod · 0.80
CountRemainingArgsMethod · 0.80
ArgErrMethod · 0.80
NextArgMethod · 0.80
NextBlockMethod · 0.80
NestingMethod · 0.80
ErrfMethod · 0.80
NextMethod · 0.65

Tested by

no test coverage detected