Make a message which is a response for the specified query. The message returned is really a response skeleton; it has all of the infrastructure required of a response, but none of the content. Response section(s) which are copied are shallow copies of the matching section(s) in the
(
query: Message,
recursion_available: bool = False,
our_payload: int = 8192,
fudge: int = 300,
tsig_error: int = 0,
pad: int | None = None,
copy_mode: CopyMode | None = None,
)
| 1856 | |
| 1857 | |
| 1858 | def make_response( |
| 1859 | query: Message, |
| 1860 | recursion_available: bool = False, |
| 1861 | our_payload: int = 8192, |
| 1862 | fudge: int = 300, |
| 1863 | tsig_error: int = 0, |
| 1864 | pad: int | None = None, |
| 1865 | copy_mode: CopyMode | None = None, |
| 1866 | ) -> Message: |
| 1867 | """Make a message which is a response for the specified query. |
| 1868 | The message returned is really a response skeleton; it has all of the infrastructure |
| 1869 | required of a response, but none of the content. |
| 1870 | |
| 1871 | Response section(s) which are copied are shallow copies of the matching section(s) |
| 1872 | in the query, so the query's RRsets should not be changed. |
| 1873 | |
| 1874 | *query*, a ``dns.message.Message``, the query to respond to. |
| 1875 | |
| 1876 | *recursion_available*, a ``bool``, should RA be set in the response? |
| 1877 | |
| 1878 | *our_payload*, an ``int``, the payload size to advertise in EDNS responses. |
| 1879 | |
| 1880 | *fudge*, an ``int``, the TSIG time fudge. |
| 1881 | |
| 1882 | *tsig_error*, an ``int``, the TSIG error. |
| 1883 | |
| 1884 | *pad*, a non-negative ``int`` or ``None``. If 0, the default, do not pad; otherwise |
| 1885 | if not ``None`` add padding bytes to make the message size a multiple of *pad*. Note |
| 1886 | that if padding is non-zero, an EDNS PADDING option will always be added to the |
| 1887 | message. If ``None``, add padding following RFC 8467, namely if the request is |
| 1888 | padded, pad the response to 468 otherwise do not pad. |
| 1889 | |
| 1890 | *copy_mode*, a ``dns.message.CopyMode`` or ``None``, determines how sections are |
| 1891 | copied. The default, ``None`` copies sections according to the default for the |
| 1892 | message's opcode, which is currently ``dns.message.CopyMode.QUESTION`` for all |
| 1893 | opcodes. ``dns.message.CopyMode.QUESTION`` copies only the question section. |
| 1894 | ``dns.message.CopyMode.EVERYTHING`` copies all sections other than OPT or TSIG |
| 1895 | records, which are created appropriately if needed. ``dns.message.CopyMode.NOTHING`` |
| 1896 | copies no sections; note that this mode is for server testing purposes and is |
| 1897 | otherwise not recommended for use. In particular, ``dns.message.is_response()`` |
| 1898 | will be ``False`` if you create a response this way and the rcode is not |
| 1899 | ``FORMERR``, ``SERVFAIL``, ``NOTIMP``, or ``REFUSED``. |
| 1900 | |
| 1901 | Returns a ``dns.message.Message`` object whose specific class is appropriate for the |
| 1902 | query. For example, if query is a ``dns.update.UpdateMessage``, the response will |
| 1903 | be one too. |
| 1904 | """ |
| 1905 | |
| 1906 | if query.flags & dns.flags.QR: |
| 1907 | raise dns.exception.FormError("specified query message is not a query") |
| 1908 | opcode = query.opcode() |
| 1909 | factory = _message_factory_from_opcode(opcode) |
| 1910 | response = factory(id=query.id) |
| 1911 | response.flags = dns.flags.QR | (query.flags & dns.flags.RD) |
| 1912 | if recursion_available: |
| 1913 | response.flags |= dns.flags.RA |
| 1914 | response.set_opcode(opcode) |
| 1915 | if copy_mode is None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…