/src/kea/src/lib/dhcp/option_vendor.h
Line | Count | Source |
1 | | // Copyright (C) 2013-2024 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 | | #ifndef OPTION_VENDOR_H |
8 | | #define OPTION_VENDOR_H |
9 | | |
10 | | #include <dhcp/libdhcp++.h> |
11 | | #include <dhcp/option.h> |
12 | | #include <dhcp/option_data_types.h> |
13 | | |
14 | | #include <stdint.h> |
15 | | |
16 | | namespace isc { |
17 | | namespace dhcp { |
18 | | |
19 | | /// Indexes for fields in vendor-class (17) DHCPv6 option |
20 | | const int VENDOR_CLASS_ENTERPRISE_ID_INDEX = 0; |
21 | | const int VENDOR_CLASS_DATA_LEN_INDEX = 1; |
22 | | const int VENDOR_CLASS_STRING_INDEX = 2; |
23 | | |
24 | | /// @brief This class represents vendor-specific information option. |
25 | | /// |
26 | | /// As specified in RFC3925, the option formatting is slightly different |
27 | | /// for DHCPv4 than DHCPv6. The DHCPv4 Option includes additional field |
28 | | /// holding vendor data length. |
29 | | class OptionVendor: public Option { |
30 | | public: |
31 | | /// @brief Constructor. |
32 | | /// |
33 | | /// @param u universe (V4 or V6) |
34 | | /// @param vendor_id vendor enterprise-id (unique 32 bit integer) |
35 | | OptionVendor(Option::Universe u, const uint32_t vendor_id); |
36 | | |
37 | | /// @brief Constructor. |
38 | | /// |
39 | | /// This constructor creates option from a buffer. This constructor |
40 | | /// may throw exception if \ref unpack function throws during buffer |
41 | | /// parsing. |
42 | | /// |
43 | | /// @param u universe (V4 or V6) |
44 | | /// @param begin iterator to first byte of option data. |
45 | | /// @param end iterator to end of option data (first byte after option end). |
46 | | /// @param rec_level recursion level. |
47 | | /// |
48 | | /// @Throw isc::OutOfRange if provided buffer is shorter than data size. |
49 | | /// @todo Extend constructor to set encapsulated option space name. |
50 | | OptionVendor(Option::Universe u, OptionBufferConstIter begin, |
51 | | OptionBufferConstIter end, size_t rec_level = 0); |
52 | | |
53 | | /// @brief Copies this option and returns a pointer to the copy. |
54 | | OptionPtr clone() const; |
55 | | |
56 | | /// @brief Writes option in wire-format to buf, returns pointer to first |
57 | | /// unused byte after stored option. |
58 | | /// |
59 | | /// @param [out] buf buffer (option will be stored here) |
60 | | /// @param check if set to false, allows options larger than 255 for v4 |
61 | | virtual void pack(isc::util::OutputBuffer& buf, bool check = true) const; |
62 | | |
63 | | /// @brief Parses received buffer |
64 | | /// |
65 | | /// Parses received buffer and returns offset to the first unused byte after |
66 | | /// parsed option. |
67 | | /// |
68 | | /// @param begin iterator to first byte of option data |
69 | | /// @param end iterator to end of option data (first byte after option end) |
70 | | /// |
71 | | /// @throw isc::SkipRemainingOptionsBuffer if an error is encountered |
72 | | /// unpacking the option. This exception is thrown to indicate to the |
73 | | /// caller that a: remaining options cannot be parsed and b: the packet |
74 | | /// should be considered for processing anyway. |
75 | | virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end); |
76 | | |
77 | | /// @brief Parses received buffer with limited recursion. |
78 | | /// |
79 | | /// @param begin iterator to first byte of option data |
80 | | /// @param end iterator to end of option data (first byte after option end) |
81 | | /// @param rec_level recursion level. |
82 | | void unpack(OptionBufferConstIter begin, OptionBufferConstIter end, |
83 | | size_t rec_level); |
84 | | |
85 | | /// @brief Sets enterprise identifier |
86 | | /// |
87 | | /// @param vendor_id vendor identifier |
88 | 0 | void setVendorId(const uint32_t vendor_id) { |
89 | 0 | vendor_id_ = vendor_id; |
90 | 0 | } |
91 | | |
92 | | /// @brief Returns enterprise identifier |
93 | | /// |
94 | | /// @return enterprise identifier |
95 | 24.1k | uint32_t getVendorId() const { |
96 | 24.1k | return (vendor_id_); |
97 | 24.1k | } |
98 | | |
99 | | /// @brief returns complete length of option |
100 | | /// |
101 | | /// Returns length of this option, including option header and suboptions |
102 | | /// |
103 | | /// @return length of this option |
104 | | virtual uint16_t len() const; |
105 | | |
106 | | /// @brief Returns the option in the textual format. |
107 | | /// |
108 | | /// @param indent Number of spaces to be inserted before the text. |
109 | | /// |
110 | | /// @return Vendor option in the textual format. |
111 | | virtual std::string toText(int indent = 0) const; |
112 | | |
113 | | private: |
114 | | |
115 | | /// @brief Enterprise-id |
116 | | uint32_t vendor_id_; |
117 | | }; |
118 | | |
119 | | /// Pointer to a vendor option |
120 | | typedef boost::shared_ptr<OptionVendor> OptionVendorPtr; |
121 | | |
122 | | } // isc::dhcp namespace |
123 | | } // isc namespace |
124 | | |
125 | | #endif // OPTION_VENDOR_H |