The parsing correctly handles SMTPUTF8 Unicode in the string.
-.vitem &*${mask:*&<&'IP&~address'&>&*/*&<&'bit&~count'&>&*}*&
+.vitem &*${mask:*&<&'IP&~address'&>&*/*&<&'bit&~count'&>&*}*& &&&
+ &*${mask_n:*&<&'IP&~address'&>&*/*&<&'bit&~count'&>&*}*&
.cindex "masked IP address"
.cindex "IP address" "masking"
.cindex "CIDR notation"
.code
${mask:10.111.131.206/28}
.endd
-returns the string &"10.111.131.192/28"&. Since this operation is expected to
-be mostly used for looking up masked addresses in files, the result for an IPv6
+returns the string &"10.111.131.192/28"&.
+
+Since this operation is expected to
+be mostly used for looking up masked addresses in files, the
+.new
+normal
+.wen
+result for an IPv6
address uses dots to separate components instead of colons, because colon
terminates a key string in lsearch files. So, for example,
.code
.code
3ffe.ffff.836f.0a00.000a.0800.2000.0000/99
.endd
+.new
+If the optional form &*mask_n*& is used, IPv6 address result are instead
+returned in normailsed form, using colons and with zero-compression.
+.wen
Letters in IPv6 addresses are always output in lower case.
1. A new ACL condition: seen. Records/tests a timestamp against a key.
+ 2. A variant of the "mask" expansion operator to give normalised IPv6.
+
Version 4.95
------------
int count;
uschar *endptr;
int binary[4];
- int mask, maskoffset;
- int type = string_is_ip_address(sub, &maskoffset);
+ int type, mask, maskoffset;
+ BOOL normalised;
uschar buffer[64];
- if (type == 0)
+ if ((type = string_is_ip_address(sub, &maskoffset)) == 0)
{
expand_string_message = string_sprintf("\"%s\" is not an IP address",
sub);
mask = Ustrtol(sub + maskoffset + 1, &endptr, 10);
- if (*endptr != 0 || mask < 0 || mask > ((type == 4)? 32 : 128))
+ if (*endptr || mask < 0 || mask > (type == 4 ? 32 : 128))
{
expand_string_message = string_sprintf("mask value too big in \"%s\"",
sub);
goto EXPAND_FAILED;
}
+ /* If an optional 'n' was given, ipv6 gets normalised output:
+ colons rather than dots, and zero-compressed. */
+
+ normalised = arg && *arg == 'n';
+
/* Convert the address to binary integer(s) and apply the mask */
sub[maskoffset] = 0;
/* Convert to masked textual format and add to output. */
- yield = string_catn(yield, buffer,
- host_nmtoa(count, binary, mask, buffer, '.'));
+ if (type == 4 || !normalised)
+ yield = string_catn(yield, buffer,
+ host_nmtoa(count, binary, mask, buffer, '.'));
+ else
+ {
+ ipv6_nmtoa(binary, buffer);
+ yield = string_fmt_append(yield, "%s/%d", buffer, mask);
+ }
continue;
}
mask: ${mask:192.168.10.206/0}
mask: ${mask:192.168.10.206}
mask: ${mask:a.b.c.d}
+mask: ${mask:2a00:2:3:4:5:6:7:8/79}
+mask_n: ${mask_n:2a00:2:3:4:5:6:7:8/79}
ipv6denorm: ${ipv6denorm:::1}
ipv6denorm: ${ipv6denorm:fe00::1}
ipv6denorm: ${ipv6denorm:192.168.0.1}
> mask: 0.0.0.0/0
> Failed: missing mask value in "192.168.10.206"
> Failed: "a.b.c.d" is not an IP address
+> mask: 2a00.0002.0003.0004.0004.0000.0000.0000/79
+> mask_n: 2a00:2:3:4:4::/79
> ipv6denorm: 0000:0000:0000:0000:0000:0000:0000:0001
> ipv6denorm: fe00:0000:0000:0000:0000:0000:0000:0001
> ipv6denorm: 0000:0000:0000:0000:0000:ffff:c0a8:0001