Kea 2.7.4
rcode.cc
Go to the documentation of this file.
1// Copyright (C) 2010-2015 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <string>
10#include <sstream>
11#include <ostream>
12
14
15#include <dns/rcode.h>
16
17using namespace std;
18
19namespace isc {
20namespace dns {
21namespace {
22// This diagram shows the wire-format representation of the 12-bit extended
23// form RCODEs and its relationship with implementation specific parameters.
24//
25// 0 3 11 15
26// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
27// |UNUSED | EXTENDED-RCODE | RCODE |
28// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29// <= EXTRCODE_SHIFT (4 bits)
30const unsigned int EXTRCODE_SHIFT = 4;
31const unsigned int RCODE_MASK = 0x000f;
32
33
34// EDNS-extended RCODEs are 12-bit unsigned integers. 0xfff is the highest.
35const uint16_t MAX_RCODE = 0xfff;
36
37const char* const rcodetext[] = {
38 "NOERROR",
39 "FORMERR",
40 "SERVFAIL",
41 "NXDOMAIN",
42 "NOTIMP",
43 "REFUSED",
44 "YXDOMAIN",
45 "YXRRSET",
46 "NXRRSET",
47 "NOTAUTH",
48 "NOTZONE",
49 "RESERVED11",
50 "RESERVED12",
51 "RESERVED13",
52 "RESERVED14",
53 "RESERVED15",
54 "BADVERS"
55};
56}
57
58Rcode::Rcode(const uint16_t code) : code_(code) {
59 if (code_ > MAX_RCODE) {
60 isc_throw(OutOfRange, "Rcode is too large to construct");
61 }
62}
63
64Rcode::Rcode(const uint8_t code, const uint8_t extended_code) :
65 code_((extended_code << EXTRCODE_SHIFT) | (code & RCODE_MASK))
66{
67 if (code > RCODE_MASK) {
69 "Base Rcode is too large to construct: "
70 << static_cast<unsigned int>(code));
71 }
72}
73
74uint8_t
76 return (code_ >> EXTRCODE_SHIFT);
77}
78
79string
81 if (code_ < sizeof(rcodetext) / sizeof (const char*)) {
82 return (rcodetext[code_]);
83 }
84
85 ostringstream oss;
86 oss << code_;
87 return (oss.str());
88}
89
90ostream&
91operator<<(std::ostream& os, const Rcode& rcode) {
92 return (os << rcode.toText());
93}
94}
95}
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
DNS Response Codes (RCODEs) class.
Definition rcode.h:40
Rcode(const uint16_t code)
Constructor from the code value.
Definition rcode.cc:58
std::string toText() const
Convert the Rcode to a string.
Definition rcode.cc:80
uint8_t getExtendedCode() const
Returns the upper 8-bit of the Rcode code value.
Definition rcode.cc:75
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition edns.cc:163
Defines the logger used by the top-level component of kea-lfc.
uint16_t code_