Karta.SMTP.Relay.Range (Karta v1.0.0)

The address ranges a server may accept mail from without AUTH, and the limits every range must keep.

A range is written in CIDR notation (10.20.0.0/16, 203.0.113.7/32, 2001:db8::/48) and stored in the canonical form Karta.CIDR.format/1 gives: the network address with its host bits cleared, and the prefix length. A bare address is a host range (/32 or /128).

A range may not be wider than the instance's minimum prefix length: min_prefix_v4 (default /16) and min_prefix_v6 (default /48), set with KARTA_SMTP_IP_MIN_PREFIX_V4 and KARTA_SMTP_IP_MIN_PREFIX_V6 and checked when Karta starts (validate!/0). The whole address space (0.0.0.0/0, ::/0) is never accepted, whatever the setting says: a range that matches every client would be an open relay. An IPv4-mapped IPv6 range is refused too, because a connection's address is normalised to IPv4 before it is matched (Karta.CIDR.normalize/1), so such a range could never match.

This module is pure: the ranges are read and checked here, and matched against an address by Karta.SMTP.Relay.

Summary

Functions

Checks a range for a credential and returns its canonical text form.

Checks a range against the given minimums.

True when the range, in canonical text form, contains ip.

The narrowest prefix length a range may have, per address family.

The prefix length of a range in canonical text form.

Checks the configured minimums; called when the application starts.

Checks the given minimums; the arguments are a keyword list as configured.

Functions

check(value)

@spec check(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Checks a range for a credential and returns its canonical text form.

check(value, prefixes)

@spec check(String.t(), keyword()) :: {:ok, String.t()} | {:error, String.t()}

Checks a range against the given minimums.

contains?(cidr, ip)

@spec contains?(String.t(), :inet.ip_address()) :: boolean()

True when the range, in canonical text form, contains ip.

minimum_prefixes()

@spec minimum_prefixes() :: keyword()

The narrowest prefix length a range may have, per address family.

prefix_length(cidr)

@spec prefix_length(String.t()) :: 0..128

The prefix length of a range in canonical text form.

validate!()

@spec validate!() :: :ok

Checks the configured minimums; called when the application starts.

validate!(prefixes)

@spec validate!(keyword()) :: :ok

Checks the given minimums; the arguments are a keyword list as configured.