Mail::SpamAssassin::Plugin::ASN(3p)

NAME
Mail::SpamAssassin::Plugin::ASN - SpamAssassin plugin to look up the Autonomous System Number (ASN) of the connecting IP address.

SYNOPSIS
 loadplugin Mail::SpamAssassin::Plugin::ASN

 # Default / recommended settings
 asn_use_geodb 1
 asn_use_dns 1
 asn_prefer_geodb 1

 # Do lookups and add tags / X-Spam-ASN header
 asn_lookup asn.routeviews.org _ASN_ _ASNCIDR_
 asn_lookup_ipv6 origin6.asn.cymru.com _ASN_ _ASNCIDR_
 add_header all ASN _ASN_ _ASNCIDR_

 # Rules to test ASN or Organization
 # NOTE: Do not use rules that check metadata X-ASN header,
 # only check_asn() eval function works correctly.
 # Rule argument is full regexp to match.

 # ASN Number: GeoIP ASN or DNS
 # Matched string includes asn_prefix if defined, and normally
 # looks like "AS1234" (DNS) or "AS1234 Google LLC" (GeoIP)
 header AS_1234 eval:check_asn('/^AS1234\b/')

 # ASN Organisation: GeoIP ASN has, DNS lists might not have
 # Note the second parameter which checks MYASN tag (default is ASN)
 asn_lookup myview.example.com _MYASN_ _MYASNCIDR_
 header AS_GOOGLE eval:check_asn('/\bGoogle\b/i', 'MYASN')

DESCRIPTION
This plugin uses DNS lookups to the services of an external DNS zone such as at "http://www.routeviews.org/" to do the actual work. Please make sure that your use of the plugin does not overload their infrastructure - this generally means that you should not use this plugin in a high-volume environment or that you should use a local mirror of the zone (see "ftp://ftp.routeviews.org/dnszones/"). Other similar zones may also be used.

GeoDB (GeoIP ASN) database lookups are supported since SpamAssassin 4.0 and it's recommended to use them instead of DNS queries, unless "_ASNCIDR_" is needed.

TEMPLATE TAGS
This plugin allows you to create template tags containing the connecting IP's AS number and route info for that AS number.

If you use add_header as documented in the example before, a header field is added that looks like this:

 X-Spam-ASN: AS24940 213.239.192.0/18

where "24940" is the ASN and "213.239.192.0/18" is the route announced by that ASN where the connecting IP address came from. If the AS announces multiple networks (more/less specific), they will all be added to the "_ASNCIDR_" tag, separated by spaces, eg:

 X-Spam-ASN: AS1680 89.138.0.0/15 89.139.0.0/16

Note that the literal "AS" before the ASN in the _ASN_ tag is configurable through the asn_prefix directive and may be set to an empty string.

"_ASNCIDR_" is not available with local GeoDB ASN lookups.

BAYES
The bayes tokenizer will use ASN data for bayes calculations, and thus affect which BAYES_* rule will trigger for a particular message. No in-depth analysis of the usefulness of bayes tokenization of ASN data has been performed.

SEE ALSO
http://www.routeviews.org/ - all data regarding routing, ASNs, etc....

ADMINISTRATOR SETTINGS

asn_lookup asn-zone.example.com [ _ASNTAG_ _ASNCIDRTAG_ ]
    Use this to lookup the ASN info in the specified zone for the first external IPv4 address and add the AS number to the first specified tag and routing info to the second specified tag.

    If no tags are specified the AS number will be added to the _ASN_ tag and the routing info will be added to the _ASNCIDR_ tag. You must specify either none or both of the tag names. Tag names must start and end with an underscore.

    If two or more asn_lookups use the same set of template tags, the results of their lookups will be appended to each other in the template tag values in no particular order. Duplicate results will be omitted when combining results. In a similar fashion, you can also use the same template tag for both the AS number tag and the routing info tag.

    Examples:

      asn_lookup asn.routeviews.org

      asn_lookup asn.routeviews.org _ASN_ _ASNCIDR_
      asn_lookup myview.example.com _MYASN_ _MYASNCIDR_

      asn_lookup asn.routeviews.org _COMBINEDASN_ _COMBINEDASNCIDR_
      asn_lookup myview.example.com _COMBINEDASN_ _COMBINEDASNCIDR_

      asn_lookup in1tag.example.net _ASNDATA_ _ASNDATA_

asn_lookup_ipv6 asn-zone6.example.com [_ASN_ _ASNCIDR_]
    Use specified zone for lookups of IPv6 addresses. If zone supports both IPv4 and IPv6 queries, use both asn_lookup and asn_lookup_ipv6 for the same zone.

clear_asn_lookups
    Removes any previously declared asn_lookup entries from a list of queries.

asn_prefix 'prefix_string'       (default: 'AS')
    The string specified in the argument is prepended to each ASN when storing it as a tag. This prefix is rather redundant, but its default value 'AS' is kept for backward compatibility with versions of SpamAssassin earlier than 3.4.0. A sensible setting is an empty string. The argument may be (but need not be) enclosed in single or double quotes for clarity.

asn_use_geodb ( 0 / 1 )          (default: 1)
    Use Mail::SpamAssassin::GeoDB module to lookup ASN numbers. You need suitable supported module like GeoIP2 or GeoIP with ISP or ASN database installed (for example, add EditionIDs GeoLite2-ASN in GeoIP.conf for geoipupdate program).

    GeoDB can only set _ASN_ tag, it has no data for _ASNCIDR_. If you need both, then set asn_prefer_geodb 0 so DNS rules are tried.

asn_prefer_geodb ( 0 / 1 )       (default: 1)
    If set, DNS lookups (asn_lookup rules) will not be run if GeoDB successfully finds ASN. Set this to 0 to get _ASNCIDR_ even if GeoDB finds _ASN_.

asn_use_dns ( 0 / 1 )            (default: 1)
    Set to 0 to never allow DNS queries.