spamdyke: IP File Format

# spamdyke

## A drop-in connection-time spam filter for qmail

## IP address files

Some of spamdyke's options search files for IP addresses. In all those cases, the format of the files is the same. Blank lines and lines beginning with `#` are ignored. Every other line in the file is expected to contain a single entry.

NOTE: To protect against unknown dangers like programming errors, corrupted filesystems or incorrect file paths, spamdyke will only read the first 65536 lines of any file. If the file is any larger, spamdyke will printing an error message into its logs. If there is a legitimate reason to have more than 65536 lines in a file, the content should be separated into multiple files and spamdyke's option should be given multiple times to search each file.

Individual IP addresses may be given in dotted quad format. Those IP addresses will be matched literally. For example:

  `11.22.33.44`
  `23.34.45.56`

Two IP addresses will be matched by these entries, `11.22.33.44` and `23.34.45.56`. NOTE: In dotted quad format, leading zeroes are ignored, so the following is equivalent to the previous example:

  `011.022.033.044`
  `023.034.045.056`

IP address ranges may be given in one of four ways. First, one or more octets of an IP address may be given and will match any IP addresses with the same first few octets. For example, if the file contained the following entry:

  `11.22.33`

The IP addresses `11.22.33.14`, `11.22.33.25` and `11.22.33.236` will all match. A trailing dot is optional, so if the file contained the following entry:

  `11.22.`

The IP addresses `11.22.33.44`, `11.22.134.245` and `11.22.235.46` will all match.

Second, a full or partial IP address with ranges may be given an will match an IP addresses with octets that match the ranges given. For example, if the file contained the following entry:

  `11.22.33-44.55`

The IP addresses `11.22.34.55`, `11.22.38.55` and `11.22.41.55` will all match. If the file contained the following entry:

  `11.22-44`

The IP addresses `11.22.134.7`, `11.36.1.267` and `11.43.178.240` will all match.

Third, a full IP address may be given with a netmask, given as a number of bits. For example, if the file contained the following entry:

  `11.22.33.0/24`

The IP addresses `11.22.33.2`, `11.22.33.189` and `11.22.33.241` will all match. If the file contained the following entry:

  `11.22.0.0/16`

The IP addresses `11.22.165.98`, `11.22.8.135` and `11.22.0.254` will all match.

Fourth, a full IP address may be given with a netmask in dotted quad format. For example, if the file contained the following entry:

  `11.22.33.0/255.255.255.0`

The IP addresses `11.22.33.13`, `11.22.33.76` and `11.22.33.199` will all match. If the file contained the following entry:

  `11.22.0.0/255.255.0.0`

The IP addresses `11.22.59.111`, `11.22.7.189` and `11.22.83.213` will all match.

When a netmask is given, either as a number of bits or a dotted quad, ranges in the base IP address are ignored. If they're present, they don't cause errors but they have no effect.