Skip to content

Commit 66b7834

Browse files
authored
Release v2.0.5 (#27)
- skip lookups if they've already succeeded (IE, DNS after MM) - emit only one log entry after successful lookups - return an appropriate (empty) exit code after DNS lookups - maxmind: switch to lookup_rdns hook (same as DNS)
1 parent d491eae commit 66b7834

File tree

6 files changed

+43
-28
lines changed

6 files changed

+43
-28
lines changed

.release

Submodule .release updated 1 file

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
44

55
### Unreleased
66

7+
### [2.0.5] - 2025-02-09
8+
9+
- skip lookups if they've already succeeded (IE, DNS after MM)
10+
- emit only one log entry after successful lookups
11+
- return an appropriate (empty) exit code after DNS lookups
12+
- maxmind: switch to lookup_rdns hook (same as DNS)
13+
714
### [2.0.4] - 2025-01-26
815

916
- dep(eslint): upgrade to v9
@@ -77,3 +84,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
7784
[2.0.2]: https://github.com/haraka/haraka-plugin-asn/releases/tag/v2.0.2
7885
[2.0.3]: https://github.com/haraka/haraka-plugin-asn/releases/tag/v2.0.3
7986
[2.0.4]: https://github.com/haraka/haraka-plugin-asn/releases/tag/v2.0.4
87+
[2.0.5]: https://github.com/haraka/haraka-plugin-asn/releases/tag/v2.0.5

CONTRIBUTORS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This handcrafted artisinal software is brought to you by:
44

5-
| <img height="80" src="https://avatars.githubusercontent.com/u/261635?v=4"><br><a href="https://github.com/msimerson">msimerson</a> (<a href="https://github.com/haraka/haraka-plugin-asn/commits?author=msimerson">27</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/934254?v=4"><br><a href="https://github.com/analogic">analogic</a> (<a href="https://github.com/haraka/haraka-plugin-asn/commits?author=analogic">1</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/203240?v=4"><br><a href="https://github.com/lnedry">lnedry</a> (<a href="https://github.com/haraka/haraka-plugin-asn/commits?author=lnedry">1</a>) |
5+
| <img height="80" src="https://avatars.githubusercontent.com/u/261635?v=4"><br><a href="https://github.com/msimerson">msimerson</a> (<a href="https://github.com/haraka/haraka-plugin-asn/commits?author=msimerson">28</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/934254?v=4"><br><a href="https://github.com/analogic">analogic</a> (<a href="https://github.com/haraka/haraka-plugin-asn/commits?author=analogic">1</a>) | <img height="80" src="https://avatars.githubusercontent.com/u/203240?v=4"><br><a href="https://github.com/lnedry">lnedry</a> (<a href="https://github.com/haraka/haraka-plugin-asn/commits?author=lnedry">1</a>) |
66
| :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
77

88
<sub>this file is generated by [.release](https://github.com/msimerson/.release).

index.js

+26-23
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ exports.register = async function () {
1717

1818
this.load_asn_ini()
1919

20-
await this.test_and_register_dns_providers()
2120
await this.test_and_register_geoip()
21+
await this.test_and_register_dns_providers()
2222

2323
if (this.cfg.header.asn) {
2424
this.register_hook('data_post', 'add_header_asn')
@@ -133,41 +133,40 @@ exports.get_result = function (zone, first) {
133133
exports.lookup_via_dns = function (next, connection) {
134134
if (connection.remote.is_private) return next()
135135

136+
if (connection.results.get(this)?.asn) return next() // already set, skip
137+
136138
const promises = []
137139

138140
for (const zone of providers) {
139141
promises.push(
140142
new Promise((resolve) => {
141-
// connection.logdebug(plugin, `zone: ${zone}`);
143+
// connection.loginfo(plugin, `zone: ${zone}`);
142144

143145
try {
144146
this.get_dns_results(zone, connection.remote.ip).then((r) => {
145147
if (!r) return resolve()
146148

147-
const results = { emit: true }
148-
149149
// store asn & net from any source
150-
if (r.asn) results.asn = r.asn
151-
if (r.net) results.net = r.net
150+
if (r.asn) connection.results.add(this, { asn: r.asn })
151+
if (r.net) connection.results.add(this, { net: r.net })
152152

153153
// store provider specific results
154154
switch (zone) {
155155
case 'origin.asn.cymru.com':
156-
results.cymru = r
156+
connection.results.add(this, { cymru: r })
157157
break
158158
case 'asn.routeviews.org':
159-
results.routeviews = r
159+
connection.results.add(this, { routeviews: r })
160160
break
161161
case 'origin.asn.spameatingmonkey.net':
162-
results.monkey = r
162+
connection.results.add(this, { monkey: r })
163163
break
164164
case 'asn.rspamd.com':
165-
results.rspamd = r
165+
connection.results.add(this, { rspamd: r })
166166
break
167167
}
168168

169-
connection.results.add(this, results)
170-
resolve(results)
169+
resolve()
171170
})
172171
} catch (err) {
173172
connection.results.add(this, { err })
@@ -177,7 +176,11 @@ exports.lookup_via_dns = function (next, connection) {
177176
)
178177
}
179178

180-
Promise.all(promises).then(next)
179+
Promise.all(promises)
180+
.then(() => {
181+
connection.results.add(this, {emit: true})
182+
next()
183+
})
181184
}
182185

183186
exports.parse_routeviews = function (thing) {
@@ -300,7 +303,7 @@ exports.test_and_register_geoip = async function () {
300303
try {
301304
this.maxmind = require('maxmind')
302305
if (await this.load_dbs()) {
303-
this.register_hook('connect', 'lookup_via_maxmind')
306+
this.register_hook('lookup_rdns', 'lookup_via_maxmind')
304307
}
305308
} catch (e) {
306309
this.logerror(e)
@@ -340,17 +343,17 @@ exports.load_dbs = async function () {
340343
exports.lookup_via_maxmind = function (next, connection) {
341344
if (!this.maxmind || !this.dbsLoaded) return next()
342345

346+
if (connection.results.get(this)?.asn) return next() // already set, skip
347+
343348
const asn = this.lookup.get(connection.remote.ip)
344-
if (asn?.autonomous_system_number || asn?.autonomous_system_organization) {
345-
connection.results.add(this, {
346-
...(asn.autonomous_system_number
347-
? { asn: asn.autonomous_system_number }
348-
: {}),
349-
...(asn.autonomous_system_organization
350-
? { org: asn.autonomous_system_organization }
351-
: {}),
352-
})
349+
350+
if (asn?.autonomous_system_number) {
351+
connection.results.add(this, { asn: asn.autonomous_system_number })
352+
}
353+
if (asn?.autonomous_system_organization) {
354+
connection.results.add(this, { org: asn.autonomous_system_organization })
353355
}
356+
connection.results.add(this, { emit: true })
354357

355358
next()
356359
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "haraka-plugin-asn",
3-
"version": "2.0.4",
3+
"version": "2.0.5",
44
"description": "look up ASN of remote MTA",
55
"main": "index.js",
66
"files": [

test/asn.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,12 @@ describe('lookup_via_dns', function () {
177177
connection.remote.ip = '66.128.51.163'
178178

179179
asn.test_and_register_dns_providers().then((providers) => {
180-
asn.lookup_via_dns((r) => {
181-
assert.ok(r.length)
180+
asn.lookup_via_dns((rc, hosts) => {
181+
assert.equal(rc, undefined)
182+
assert.equal(hosts, undefined)
183+
const r = connection.results.get(asn)
184+
assert.ok(r.asn)
185+
assert.ok(r.net)
182186
done()
183187
}, connection)
184188
})

0 commit comments

Comments
 (0)