CIDR_TABLE(5)

πŸ’– cidr_table β€” the vibe of Postfix CIDR tables πŸ’–

okay so bestie. welcome to cidr_table, aka the File Formats Manual page about how Postfix does CIDR lookup tables. it's giving "networking but make it cute" and honestly? we're obsessed. let's get into it ✨


🌸 SYNOPSIS 🌸

postmap -q "string" cidr:/etc/postfix/filename

postmap -q - cidr:/etc/postfix/filename <inputfile

that's it. that's the whole vibe. two commands and you're that girl πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so the Postfix mail system uses optional lookup tables, right? and normally those tables are in lmdb:, cdb:, hash:, or dbm: format. classic. love that for them.

but β€” and this is the main character moment β€” lookup tables can also be specified in CIDR form, which stands for Classless Inter-Domain Routing. in that case, every input gets compared against a list of patterns. the moment a match is found, the corresponding result gets returned and the search is terminated. no further searching, we said what we said, periodt πŸ’…

wanna know what types of lookup tables your Postfix system supports? run the "postconf -m" command, bestie.

and to actually test lookup tables, use the "postmap -q" command, exactly like the SYNOPSIS above shows you. easy peasy πŸ“


✨ TABLE FORMAT ✨

the general form of a Postfix CIDR table goes a lil something like this:

  • pattern result β€” when a search string matches the specified pattern, use the corresponding result value. the pattern must be in network/prefix or network_address form (peep ADDRESS PATTERN SYNTAX below for the deets).
  • !pattern result β€” when a search string does not match the specified pattern, use the specified result value. the pattern must be in network/prefix or network_address form (again, see ADDRESS PATTERN SYNTAX below).

this feature is available in Postfix 3.2 and later.

  • if pattern / endif β€” when a search string matches the specified pattern, match that search string against the patterns between if and endif. the pattern must be in network/prefix or network_address form (yep, ADDRESS PATTERN SYNTAX). and the if..endif blocks can nest. πŸͺ†
Note: do not prepend whitespace to text between if..endif. i'm so serious, bestie. do not. πŸ™ˆ

this feature is available in Postfix 3.2 and later.

  • if !pattern / endif β€” when a search string does not match the specified pattern, match that search string against the patterns between if and endif. the pattern must be in network/prefix or network_address form (you know the drill β€” ADDRESS PATTERN SYNTAX). the if..endif can nest. πŸ’«
Note: do not prepend whitespace to text between if..endif. same rule, still iconic, still non-negotiable. 😭

this feature is available in Postfix 3.2 and later.

  • blank lines and comments β€” empty lines and whitespace-only lines are ignored, and so are lines whose first non-whitespace character is a #. live your truth, leave comments, we support you. πŸ’œ
  • multi-line text β€” a logical line starts with non-whitespace text. a line that starts with whitespace continues a logical line. that's the rule, no cap. 🧚

πŸ”₯ TABLE SEARCH ORDER πŸ”₯

patterns are applied in the order as specified in the table, until a pattern is found that matches the search string. so basically: order matters, bestie. first match wins, and then we're done. πŸ‘‘


πŸ‘‘ ADDRESS PATTERN SYNTAX πŸ‘‘

Postfix CIDR tables are pattern-based. a pattern is either:

  • a network_address, which requires an exact match, or
  • a network_address/prefix_length, where the prefix_length part specifies the length of the network_address prefix that must be matched β€” and the other bits in the network_address part must be zero.

an IPv4 network address is a sequence of four decimal octets separated by ".", and an IPv6 network address is a sequence of three to eight hexadecimal octet pairs separated by ":" or "::", where the latter is short-hand for a sequence of one or more all-zero octet pairs. the pattern 0.0.0.0/0 matches every IPv4 address, and ::/0 matches every IPv6 address. IPv6 support is available in Postfix 2.2 and later. 🌈

before comparisons are made, lookup keys and table entries are converted from string to binary. therefore, IPv6 patterns will be matched regardless of leading zeros (a leading zero in an IPv4 address octet indicates octal notation). fun fact, keep it in your back pocket. πŸŽ€

Note: address information may be enclosed inside "[]" but this form is not required. do with that what you will. πŸ’…

πŸŽ€ INLINE SPECIFICATION πŸŽ€

the contents of a table may be specified in the table name (Postfix 3.7 and later). the basic syntax is:

main.cf:
    parameter = .. cidr:{ { rule-1 }, { rule-2 } .. } ..

master.cf:
    .. -o { parameter = .. cidr:{ { rule-1 }, { rule-2 } .. } .. } ..

Postfix recursively expands any $parametername instances in the above parameter value, ignores whitespace after '{' and before '}', and writes each rule as one text line to an in-memory file:

in-memory file:
    rule-1
    rule-2
    ..

Postfix then parses the result as if it is a file in /etc/postfix. iconic behaviour honestly. 🌸

Note: if a rule contains $, specify $$ to keep Postfix from trying to do $name expansion as it evaluates a parameter value. don't skip this one bestie, it'll getcha. 😭

πŸ’œ EXAMPLE SMTPD ACCESS MAP πŸ’œ

/etc/postfix/main.cf:
    smtpd_client_restrictions = ... cidr:/etc/postfix/client.cidr ...

/etc/postfix/client.cidr:
    # Rule order matters. Put more specific allowlist entries
    # before more general denylist entries.
    192.168.1.1             OK
    192.168.0.0/16          REJECT
    2001:db8::1             OK
    2001:db8::/32           REJECT

see how the specific stuff goes first? that's the whole trick. main character energy from the allowlist. πŸ”₯


πŸ¦‹ SEE ALSO πŸ¦‹


πŸ“š README FILES πŸ“š

use "postconf readme_directory" or "postconf html_directory" to locate this information.

  • DATABASE_README, Postfix lookup table overview

⭐ HISTORY ⭐

CIDR table support was introduced with Postfix version 2.1. a classic. a pioneer. we stan. 🫢


πŸ’– AUTHOR(S) πŸ’–

the CIDR table lookup code was originally written by:

Jozsef Kadlecsik
KFKI Research Institute for Particle and Nuclear Physics
POB. 49
1525 Budapest, Hungary

Adopted and adapted by:

Wietse Venema
IBM T.J. Watson Research
P.O. Box 704
Yorktown Heights, NY 10598, USA

Wietse Venema
Google, Inc.
111 8th Avenue
New York, NY 10011, USA

and that's the whole page bestie!! this was the cidr_table(5) page from the File Formats Manual, and you absolutely ate it. go forth and CIDR responsibly. no cap. πŸ’…βœ¨πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from