cloudflareips

package
v1.5.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cloudflareips holds Cloudflare's published proxy ranges: an embedded snapshot that is always usable, refreshed from the official endpoint.

Index

Constants

View Source
const (
	SourceEmbedded = "embedded"
	SourceFetched  = "fetched"
)

Source names where the active list came from.

View Source
const Endpoint = "https://api.cloudflare.com/client/v4/ips"

Endpoint is the only URL ever fetched; it is fixed so no setting can turn the refresh into an SSRF.

Variables

This section is empty.

Functions

func Parse

func Parse(body []byte, minRanges int) ([]netip.Prefix, error)

Parse validates an API body and returns its ranges; fewer than minRanges is rejected so a truncated answer can never shrink the trusted set.

Types

type Limits

type Limits struct {
	Timeout   time.Duration
	MaxBytes  int64
	MinRanges int
}

Limits bound one refresh.

type List

type List struct {
	// contains filtered or unexported fields
}

List is a concurrency-safe set of Cloudflare ranges.

func Default

func Default() *List

Default is the process-wide list shared by the ingress, Shield and the API.

func New

func New() *List

New returns a list seeded with the embedded snapshot.

func (*List) CIDRs

func (l *List) CIDRs() []string

CIDRs returns the current ranges as strings.

func (*List) Contains

func (l *List) Contains(ip netip.Addr) bool

Contains reports whether ip is inside the current ranges.

func (*List) Refresh

func (l *List) Refresh(ctx context.Context, lim Limits, now time.Time) (bool, error)

Refresh fetches the official list once and keeps the previous list on any failure. It reports whether the active ranges changed.

func (*List) Run

func (l *List) Run(ctx context.Context, limits func(context.Context) Limits, next func(context.Context) time.Duration, onChange func())

Run refreshes at once, then on the interval returned by next (read again each round so a stored change applies live) until ctx ends. A failed attempt retries after a quarter of the interval so a boot-time network blip does not cost a whole day. onChange runs when the active ranges changed.

func (*List) Status

func (l *List) Status() Status

Status reports the source, size and last refresh outcome.

type Status

type Status struct {
	Source      string    `json:"source"`
	Ranges      int       `json:"ranges"`
	LastRefresh time.Time `json:"last_refresh,omitempty"`
	LastAttempt time.Time `json:"last_attempt,omitempty"`
	LastError   string    `json:"last_error,omitempty"`
}

Status is the read-only state shown in settings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL