Skip to content

Commit

Permalink
Fix #985 - Handle -V prefix even for IRRD commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsasha committed Feb 13, 2025
1 parent e20c5ed commit 4c38ccf
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/releases/4.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ Other changes
* The deployment documentation now also suggests pipx for
installing IRRD, which can be easier than managing the virtualenv
manually.
* All IRRD style queries may be prepended with ``-V <user-agent>``,
even though that is a RIPE style flag, for backwards compatibility
with whois clients that always prepend this to the user's query.

Upgrading to IRRd 4.4.0 from 4.3.x
----------------------------------
Expand Down
1 change: 1 addition & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,4 @@ whois
dummified
dummify
dummification
prepended
6 changes: 6 additions & 0 deletions docs/users/queries/whois.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ IRRd supports two styles of queries:
The two styles can not be combined in a single query, but can be mixed in
a single TCP connection.

There is one special case: if a query starts
with the RIPE style flag ``-V <user-agent>``, followed by an IRRD style query,
the IRRD style query will be processed, e.g. ``-V my-client !aAS-EXAMPLE``.
This is for backward compatibility with whois clients that assume only
RIPE style queries exist, and always prepend this flag to the user's query.

IRRd style queries
------------------
* ``!!`` activates multiple command mode for raw TCP sockets. The connection
Expand Down
11 changes: 11 additions & 0 deletions irrd/server/whois/query_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ def handle_query(self, query: str) -> WhoisQueryResponse:
result="Queries may not contain null bytes",
)

if query.startswith("-V "):
# Special case for https://github.com/irrdnet/irrd/issues/985 - strip the user agent,
# then process remainder as normal.
try:
_, user_agent, remainder = query.split(" ", 2)
if remainder.startswith("!"):
query = remainder
self.handle_user_agent(user_agent)
except ValueError:
pass

if query.startswith("!"):
try:
return self.handle_irrd_command(query[1:])
Expand Down
14 changes: 13 additions & 1 deletion irrd/server/whois/tests/test_query_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ def test_sources_list(self, prepare_parser):
mock_query_resolver, mock_dh, parser = prepare_parser
mock_query_resolver.set_query_sources = Mock()

response = parser.handle_query("-s test1")
# Includes user-agent for variation
response = parser.handle_query("-V user-agent -s test1")
assert response.response_type == WhoisQueryResponseType.SUCCESS
assert response.mode == WhoisQueryResponseMode.RIPE
assert not response.result
Expand Down Expand Up @@ -952,6 +953,17 @@ def test_irrd_version(self, prepare_parser):
assert response.mode == WhoisQueryResponseMode.IRRD
assert response.result.startswith("IRRd")

def test_irrd_command_prefixed_V(self, prepare_parser):
# https://github.com/irrdnet/irrd/issues/985
# Note that -V is for communicating the user-agent, but !v is to ask the server version.
# We just use !v here as it's the simplest command.
mock_query_resolver, mock_dh, parser = prepare_parser

response = parser.handle_query("-V user-agent !v")
assert response.response_type == WhoisQueryResponseType.SUCCESS
assert response.mode == WhoisQueryResponseMode.IRRD
assert response.result.startswith("IRRd")

def test_disable_filters(self, prepare_parser):
mock_query_resolver, mock_dh, parser = prepare_parser

Expand Down

0 comments on commit 4c38ccf

Please sign in to comment.