Skip to content

Commit 7c7dc13

Browse files
committed
Fix #985 - Handle -V prefix even for IRRD commands
1 parent e20c5ed commit 7c7dc13

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

docs/releases/4.4.0.rst

+3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ Other changes
140140
* The deployment documentation now also suggests pipx for
141141
installing IRRD, which can be easier than managing the virtualenv
142142
manually.
143+
* All IRRD style queries may be prepended with ``-V <user-agent>``,
144+
even though that is a RIPE style flag, for backwards compatibility
145+
with whois clients that always prepend this to the user's query.
143146

144147
Upgrading to IRRd 4.4.0 from 4.3.x
145148
----------------------------------

docs/spelling_wordlist.txt

+1
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,4 @@ whois
110110
dummified
111111
dummify
112112
dummification
113+
prepended

docs/users/queries/whois.rst

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ IRRd supports two styles of queries:
4141
The two styles can not be combined in a single query, but can be mixed in
4242
a single TCP connection.
4343

44+
There is one special case: if a query starts
45+
with the RIPE style flag ``-V <user-agent>``, followed by an IRRD style query,
46+
the IRRD style query will be processed, e.g. ``-V my-client !aAS-EXAMPLE``.
47+
This is for backward compatibility with whois clients that assume only
48+
RIPE style queries exist, and always prepend this flag to the user's query.
49+
4450
IRRd style queries
4551
------------------
4652
* ``!!`` activates multiple command mode for raw TCP sockets. The connection

irrd/server/whois/query_parser.py

+11
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ def handle_query(self, query: str) -> WhoisQueryResponse:
7373
result="Queries may not contain null bytes",
7474
)
7575

76+
if query.startswith("-V "):
77+
# Special case for https://github.com/irrdnet/irrd/issues/985 - strip the user agent,
78+
# then process remainder as normal.
79+
try:
80+
_, user_agent, remainder = query.split(" ", 2)
81+
if remainder.startswith("!"):
82+
query = remainder
83+
self.handle_user_agent(user_agent)
84+
except ValueError:
85+
pass
86+
7687
if query.startswith("!"):
7788
try:
7889
return self.handle_irrd_command(query[1:])

irrd/server/whois/tests/test_query_parser.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ def test_sources_list(self, prepare_parser):
246246
mock_query_resolver, mock_dh, parser = prepare_parser
247247
mock_query_resolver.set_query_sources = Mock()
248248

249-
response = parser.handle_query("-s test1")
249+
# Includes user-agent for variation
250+
response = parser.handle_query("-V user-agent -s test1")
250251
assert response.response_type == WhoisQueryResponseType.SUCCESS
251252
assert response.mode == WhoisQueryResponseMode.RIPE
252253
assert not response.result
@@ -952,6 +953,17 @@ def test_irrd_version(self, prepare_parser):
952953
assert response.mode == WhoisQueryResponseMode.IRRD
953954
assert response.result.startswith("IRRd")
954955

956+
def test_irrd_command_prefixed_V(self, prepare_parser):
957+
# https://github.com/irrdnet/irrd/issues/985
958+
# Note that -V is for communicating the user-agent, but !v is to ask the server version.
959+
# We just use !v here as it's the simplest command.
960+
mock_query_resolver, mock_dh, parser = prepare_parser
961+
962+
response = parser.handle_query("-V user-agent !v")
963+
assert response.response_type == WhoisQueryResponseType.SUCCESS
964+
assert response.mode == WhoisQueryResponseMode.IRRD
965+
assert response.result.startswith("IRRd")
966+
955967
def test_disable_filters(self, prepare_parser):
956968
mock_query_resolver, mock_dh, parser = prepare_parser
957969

0 commit comments

Comments
 (0)