Home | History | Annotate | Line # | Download | only in ans8
      1 """
      2 Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      3 
      4 SPDX-License-Identifier: MPL-2.0
      5 
      6 This Source Code Form is subject to the terms of the Mozilla Public
      7 License, v. 2.0.  If a copy of the MPL was not distributed with this
      8 file, you can obtain one at https://mozilla.org/MPL/2.0/.
      9 
     10 See the COPYRIGHT file distributed with this work for additional
     11 information regarding copyright ownership.
     12 """
     13 
     14 import dns.rcode
     15 
     16 from isctest.asyncserver import (
     17     ControllableAsyncDnsServer,
     18     QnameHandler,
     19     ResponseHandler,
     20     StaticResponseHandler,
     21     SwitchControlCommand,
     22 )
     23 
     24 from ..serve_stale_ans import (
     25     a_handler,
     26     fallback_handler,
     27     ns_handler,
     28     other_types_handler,
     29     soa_handler,
     30 )
     31 
     32 ANS8_ADDR = "10.53.0.8"
     33 
     34 
     35 class TargetStaleFallbackHandler(QnameHandler, StaticResponseHandler):
     36     qnames = ["target.stale."]
     37 
     38 
     39 def handlers(www_address: str) -> list[ResponseHandler]:
     40     return [
     41         soa_handler("TargetStale", "target.stale."),
     42         ns_handler(
     43             "TargetStale",
     44             "target.stale.",
     45             "ns.target.stale.",
     46             address=ANS8_ADDR,
     47             in_answer=True,
     48         ),
     49         TargetStaleFallbackHandler(),
     50         a_handler(
     51             "NsTargetStale",
     52             "ns.target.stale.",
     53             address=ANS8_ADDR,
     54         ),
     55         a_handler(
     56             "WwwTargetStale",
     57             "www.target.stale.",
     58             ttl=2,
     59             address=www_address,
     60         ),
     61         other_types_handler(
     62             "TargetStaleNodata",
     63             ["ns.target.stale.", "www.target.stale."],
     64             "target.stale.",
     65         ),
     66         fallback_handler("target.stale."),
     67     ]
     68 
     69 
     70 def main() -> None:
     71     server = ControllableAsyncDnsServer(
     72         default_aa=True, default_rcode=dns.rcode.NOERROR
     73     )
     74 
     75     restored = handlers("10.0.0.1")
     76     server.install_response_handlers(*restored)
     77     switch_command = SwitchControlCommand(
     78         {
     79             "restore": restored,
     80             "update": handlers("10.0.0.2"),
     81         }
     82     )
     83     server.install_control_command(switch_command)
     84     server.run()
     85 
     86 
     87 if __name__ == "__main__":
     88     main()
     89