2021-12-01 12:22:59 +01:00
|
|
|
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
2021-06-03 08:37:05 +02:00
|
|
|
#
|
2021-12-01 12:22:59 +01:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
#
|
|
|
|
# See the COPYRIGHT file distributed with this work for additional
|
|
|
|
# information regarding copyright ownership.
|
|
|
|
|
2025-07-03 14:27:33 +02:00
|
|
|
from typing import AsyncGenerator
|
2021-12-01 12:22:59 +01:00
|
|
|
|
2025-07-03 14:27:33 +02:00
|
|
|
import dns
|
2021-12-01 12:22:59 +01:00
|
|
|
|
2025-07-03 14:27:33 +02:00
|
|
|
from isctest.asyncserver import (
|
|
|
|
AsyncDnsServer,
|
|
|
|
ConnectionReset,
|
|
|
|
DnsProtocol,
|
|
|
|
DnsResponseSend,
|
|
|
|
QueryContext,
|
|
|
|
ResponseAction,
|
|
|
|
ResponseHandler,
|
|
|
|
)
|
2021-12-01 12:22:59 +01:00
|
|
|
|
|
|
|
|
2025-07-03 14:27:33 +02:00
|
|
|
class TruncateOnUdpHandler(ResponseHandler):
|
|
|
|
async def get_responses(
|
|
|
|
self, qctx: QueryContext
|
|
|
|
) -> AsyncGenerator[ResponseAction, None]:
|
|
|
|
assert qctx.protocol == DnsProtocol.UDP, "This server only supports UDP"
|
|
|
|
qctx.response.set_rcode(dns.rcode.NOERROR)
|
|
|
|
qctx.response.flags |= dns.flags.TC
|
|
|
|
yield DnsResponseSend(qctx.response)
|
2021-12-01 12:22:59 +01:00
|
|
|
|
|
|
|
|
2025-07-03 14:27:33 +02:00
|
|
|
def main() -> None:
|
|
|
|
server = AsyncDnsServer()
|
2025-07-23 12:16:25 +02:00
|
|
|
server.install_connection_handler(ConnectionReset(delay=1.0))
|
2025-07-03 14:27:33 +02:00
|
|
|
server.install_response_handler(TruncateOnUdpHandler())
|
|
|
|
server.run()
|
2021-12-01 12:22:59 +01:00
|
|
|
|
|
|
|
|
2025-07-03 14:27:33 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|