pkt.h 21.1 KB
Newer Older
Tomek Mrugalski's avatar
Tomek Mrugalski committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

#ifndef PKT_H
#define PKT_H

#include <asiolink/io_address.h>
#include <util/buffer.h>
#include <dhcp/option.h>
21
#include <dhcp/hwaddr.h>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
22
23
24
25
26
27
28
29
#include <dhcp/classify.h>

#include <boost/date_time/posix_time/posix_time.hpp>

namespace isc {

namespace dhcp {

Tomek Mrugalski's avatar
Tomek Mrugalski committed
30
/// @brief Base class for classes representing DHCP messages.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
31
///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
32
33
34
35
36
37
38
/// This is a base class that holds common information (e.g. source
/// and destination ports) and operations (e.g. add, get, delete options)
/// for derived classes representing both DHCPv4 and DHCPv6 messages.
/// The @c Pkt4 and @c Pkt6 classes derive from it.
///
/// @note This is abstract class. Please instantiate derived classes
/// such as @c Pkt4 or @c Pkt6.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
39
class Pkt {
40
41
public:

Tomek Mrugalski's avatar
Tomek Mrugalski committed
42
    /// @defgroup mac_sources Specifies where a given MAC address was obtained.
43
    ///
44
45
46
47
48
49
    /// @brief The list covers all possible MAC sources.
    ///
    /// @note The uncommented ones are currently supported. When you implement
    /// a new method, please uncomment appropriate line here.
    ///
    /// @{
50

Tomek Mrugalski's avatar
Tomek Mrugalski committed
51
    /// Not really a type, only used in getMAC() calls.
52
    static const uint32_t MAC_SOURCE_ANY = 0xffff;
53

Tomek Mrugalski's avatar
Tomek Mrugalski committed
54
    /// Obtained first hand from raw socket (100% reliable).
55
    static const uint32_t MAC_SOURCE_RAW = 0x0001;
56

Tomek Mrugalski's avatar
Tomek Mrugalski committed
57
58
    /// Extracted from DUID-LL or DUID-LLT (not 100% reliable as the client
    /// can send fake DUID).
59
    //static const uint32_t MAC_SOURCE_DUID = 0x0002;
60

Tomek Mrugalski's avatar
Tomek Mrugalski committed
61
62
63
    /// Extracted from IPv6 link-local address. Not 100% reliable, as the
    /// client can use different IID other than EUI-64, e.g. Windows supports
    /// RFC4941 and uses random values instead of EUI-64.
64
    //static const uint32_t MAC_SOURCE_IPV6_LINK_LOCAL = 0x0004;
65

Tomek Mrugalski's avatar
Tomek Mrugalski committed
66
67
68
69
    /// Get it from RFC6939 option. (A relay agent can insert client link layer
    /// address option). Note that a skilled attacker can fake that by sending
    /// his request relayed, so the legitimate relay will think it's a second
    /// relay.
70
    //static const uint32_t MAC_SOURCE_CLIENT_ADDR_RELAY_OPTION = 0x0008;
71

72
    /// A relay can insert remote-id. In some deployments it contains a MAC
Tomek Mrugalski's avatar
Tomek Mrugalski committed
73
    /// address (RFC4649).
74
    //static const uint32_t MAC_SOURCE_REMOTE_ID = 0x0010;
75

76
    /// A relay can insert a subscriber-id option. In some deployments it
Tomek Mrugalski's avatar
Tomek Mrugalski committed
77
    /// contains a MAC address (RFC4580).
78
    //static const uint32_t MAC_SOURCE_SUBSCRIBER_ID = 0x0020;
79
80
81
82

    /// A CMTS (acting as DHCP relay agent) that supports DOCSIS standard
    /// can insert DOCSIS options that contain client's MAC address.
    /// Client in this context would be a cable modem.
83
    //static const uint32_t MAC_SOURCE_DOCSIS_OPTIONS = 0x0040;
84
85

    /// @}
86

Tomek Mrugalski's avatar
Tomek Mrugalski committed
87
protected:
Tomek Mrugalski's avatar
Tomek Mrugalski committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101

    /// @brief Constructor.
    ///
    /// This constructor is typically used for transmitted messages as it
    /// creates an empty (no options) packet. The constructor is protected,
    /// so only derived classes can call it. Pkt class cannot be instantiated
    /// anyway, because it is an abstract class.
    ///
    /// @param transid transaction-id
    /// @param local_addr local IPv4 or IPv6 address
    /// @param remote_addr remote IPv4 or IPv6 address
    /// @param local_port local UDP (one day also TCP) port
    /// @param remote_port remote UDP (one day also TCP) port
    Pkt(uint32_t transid, const isc::asiolink::IOAddress& local_addr,
Tomek Mrugalski's avatar
Tomek Mrugalski committed
102
        const isc::asiolink::IOAddress& remote_addr, uint16_t local_port,
Tomek Mrugalski's avatar
Tomek Mrugalski committed
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
        uint16_t remote_port);

    /// @brief Constructor.
    ///
    /// This constructor is typically used for received messages as it takes
    /// a buffer that's going to be parsed as one of arguments. The constructor
    /// is protected, so only derived classes can call it. Pkt class cannot be
    /// instantiated anyway, because it is an abstract class.
    ///
    /// @param buf pointer to a buffer that contains on-wire data
    /// @param len length of the pointer specified in buf
    /// @param local_addr local IPv4 or IPv6 address
    /// @param remote_addr remote IPv4 or IPv6 address
    /// @param local_port local UDP (one day also TCP) port
    /// @param remote_port remote UDP (one day also TCP) port
    Pkt(const uint8_t* buf, uint32_t len,
        const isc::asiolink::IOAddress& local_addr,
        const isc::asiolink::IOAddress& remote_addr, uint16_t local_port,
        uint16_t remote_port);
Tomek Mrugalski's avatar
Tomek Mrugalski committed
122
123
124

public:

125
126
127
    /// @brief Prepares on-wire format of DHCP (either v4 or v6) packet.
    ///
    /// Prepares on-wire format of message and all its options.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
128
129
130
    /// A caller must ensure that options are stored in options_ field
    /// prior to calling this method.
    ///
131
    /// Output buffer will be stored in buffer_out_.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
132
133
    /// The buffer_out_ should be cleared before writting to the buffer
    /// in the derived classes.
134
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
135
136
137
    /// @note This is a pure virtual method and must be implemented in
    /// the derived classes. The @c Pkt4 and @c Pkt6 class have respective
    /// implementations of this method.
138
139
    ///
    /// @throw InvalidOperation if packing fails
Tomek Mrugalski's avatar
Tomek Mrugalski committed
140
    virtual void pack() = 0;
141
142
143

    /// @brief Parses on-wire form of DHCP (either v4 or v6) packet.
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
144
    /// Parses received packet, stored in on-wire format in data_.
145
146
147
148
    ///
    /// Will create a collection of option objects that will
    /// be stored in options_ container.
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
149
150
151
    /// @note This is a pure virtual method and must be implemented in
    /// the derived classes. The @c Pkt4 and @c Pkt6 class have respective
    /// implementations of this method.
152
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
153
    /// Method will throw exception if packet parsing fails.
154
    ///
155
156
    /// @throw tbd
    virtual void unpack() = 0;
Tomek Mrugalski's avatar
Tomek Mrugalski committed
157
158
159
160

    /// @brief Returns reference to output buffer.
    ///
    /// Returned buffer will contain reasonable data only for
Tomek Mrugalski's avatar
Tomek Mrugalski committed
161
    /// output (TX) packet and after pack() was called.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
162
163
164
165
166
    ///
    /// RX packet or TX packet before pack() will return buffer with
    /// zero length. This buffer is returned as non-const, so hooks
    /// framework (and user's callouts) can modify them if needed
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
167
168
    /// @note This buffer is only valid till object that returned it exists.
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
169
170
171
    /// @return reference to output buffer
    isc::util::OutputBuffer& getBuffer() { return (buffer_out_); };

Tomek Mrugalski's avatar
Tomek Mrugalski committed
172
173
    /// @brief Adds an option to this packet.
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
174
175
176
    /// Derived classes may provide more specialized implementations.
    /// In particular @c Pkt4 provides one that checks if option is
    /// unique.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
177
178
    ///
    /// @param opt option to be added.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
179
    virtual void addOption(const OptionPtr& opt);
Tomek Mrugalski's avatar
Tomek Mrugalski committed
180

Tomek Mrugalski's avatar
Tomek Mrugalski committed
181
    /// @brief Attempts to delete first suboption of requested type.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
182
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
183
184
185
    /// If there are several options of the same type present, only
    /// the first option will be deleted.
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
186
187
188
189
190
    /// @param type Type of option to be deleted.
    ///
    /// @return true if option was deleted, false if no such option existed
    bool delOption(uint16_t type);

191
192
193
194
    /// @brief Returns text representation of the packet.
    ///
    /// This function is useful mainly for debugging.
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
195
196
197
    /// @note This is a pure virtual method and must be implemented in
    /// the derived classes. The @c Pkt4 and @c Pkt6 class have respective
    /// implementations of this method.
198
199
    ///
    /// @return string with text representation
Tomek Mrugalski's avatar
Tomek Mrugalski committed
200
201
    virtual std::string toText() = 0;

Tomek Mrugalski's avatar
Tomek Mrugalski committed
202
    /// @brief Returns packet size in binary format.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
203
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
204
205
206
207
208
209
210
211
    /// Returns size of the packet in on-wire format or size needed to store
    /// it in on-wire format.
    ///
    /// @note This is a pure virtual method and must be implemented in
    /// the derived classes. The @c Pkt4 and @c Pkt6 class have respective
    /// implementations of this method.
    ///
    /// @return packet size in bytes
Tomek Mrugalski's avatar
Tomek Mrugalski committed
212
213
    virtual size_t len() = 0;

Tomek Mrugalski's avatar
Tomek Mrugalski committed
214
    /// @brief Returns message type (e.g. 1 = SOLICIT).
Tomek Mrugalski's avatar
Tomek Mrugalski committed
215
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
216
217
218
    /// @note This is a pure virtual method and must be implemented in
    /// the derived classes. The @c Pkt4 and @c Pkt6 class have respective
    /// implementations of this method.
219
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
220
221
222
    /// @return message type
    virtual uint8_t getType() const = 0;

Tomek Mrugalski's avatar
Tomek Mrugalski committed
223
    /// @brief Sets message type (e.g. 1 = SOLICIT).
Tomek Mrugalski's avatar
Tomek Mrugalski committed
224
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
225
226
227
    /// @note This is a pure virtual method and must be implemented in
    /// the derived classes. The @c Pkt4 and @c Pkt6 class have respective
    /// implementations of this method.
228
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
229
230
231
    /// @param type message type to be set
    virtual void setType(uint8_t type) = 0;

Tomek Mrugalski's avatar
Tomek Mrugalski committed
232
    /// @brief Sets transaction-id value.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
233
234
235
236
    ///
    /// @param transid transaction-id to be set.
    void setTransid(uint32_t transid) { transid_ = transid; }

Tomek Mrugalski's avatar
Tomek Mrugalski committed
237
    /// @brief Returns value of transaction-id field.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
238
239
240
241
    ///
    /// @return transaction-id
    uint32_t getTransid() const { return (transid_); };

Tomek Mrugalski's avatar
Tomek Mrugalski committed
242
    /// @brief Checks whether a client belongs to a given class.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
243
244
245
246
247
    ///
    /// @param client_class name of the class
    /// @return true if belongs
    bool inClass(const isc::dhcp::ClientClass& client_class);

Tomek Mrugalski's avatar
Tomek Mrugalski committed
248
    /// @brief Adds packet to a specified class.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
    ///
    /// A packet can be added to the same class repeatedly. Any additional
    /// attempts to add to a class the packet already belongs to, will be
    /// ignored silently.
    ///
    /// @note It is a matter of naming convention. Conceptually, the server
    /// processes a stream of packets, with some packets belonging to given
    /// classes. From that perspective, this method adds a packet to specifed
    /// class. Implementation wise, it looks the opposite - the class name
    /// is added to the packet. Perhaps the most appropriate name for this
    /// method would be associateWithClass()? But that seems overly long,
    /// so I decided to stick with addClass().
    ///
    /// @param client_class name of the class to be added
    void addClass(const isc::dhcp::ClientClass& client_class);

Tomek Mrugalski's avatar
Tomek Mrugalski committed
265
    /// @brief Unparsed data (in received packets).
Tomek Mrugalski's avatar
Tomek Mrugalski committed
266
267
268
269
270
271
272
273
274
    ///
    /// @warning This public member is accessed by derived
    /// classes directly. One of such derived classes is
    /// @ref perfdhcp::PerfPkt6. The impact on derived clasess'
    /// behavior must be taken into consideration before making
    /// changes to this member such as access scope restriction or
    /// data format change etc.
    OptionBuffer data_;

275
276
277
278
    /// @brief Returns the first option of specified type.
    ///
    /// Returns the first option of specified type. Note that in DHCPv6 several
    /// instances of the same option are allowed (and frequently used).
Tomek Mrugalski's avatar
Tomek Mrugalski committed
279
280
281
    /// Also see \ref Pkt6::getOptions().
    ///
    /// The options will be only returned after unpack() is called.
282
283
284
285
286
287
288
289
290
291
292
293
294
295
    ///
    /// @param type option type we are looking for
    ///
    /// @return pointer to found option (or NULL)
    OptionPtr getOption(uint16_t type) const;

    /// @brief Update packet timestamp.
    ///
    /// Updates packet timestamp. This method is invoked
    /// by interface manager just before sending or
    /// just after receiving it.
    /// @throw isc::Unexpected if timestamp update failed
    void updateTimestamp();

296
297
298
299
300
301
302
303
304
305
    /// @brief Returns packet timestamp.
    ///
    /// Returns packet timestamp value updated when
    /// packet is received or send.
    ///
    /// @return packet timestamp.
    const boost::posix_time::ptime& getTimestamp() const {
        return timestamp_;
    }

306
307
308
    /// @brief Copies content of input buffer to output buffer.
    ///
    /// This is mostly a diagnostic function. It is being used for sending
Tomek Mrugalski's avatar
Tomek Mrugalski committed
309
    /// received packet. Received packet is stored in data_, but
310
311
312
313
    /// transmitted data is stored in buffer_out_. If we want to send packet
    /// that we just received, a copy between those two buffers is necessary.
    void repack();

314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
    /// @brief Set callback function to be used to parse options.
    ///
    /// @param callback An instance of the callback function or NULL to
    /// uninstall callback.
    void setCallback(UnpackOptionsCallback callback) {
        callback_ = callback;
    }

    /// @brief Sets remote IP address.
    ///
    /// @param remote specifies remote address
    void setRemoteAddr(const isc::asiolink::IOAddress& remote) {
        remote_addr_ = remote;
    }

Tomek Mrugalski's avatar
Tomek Mrugalski committed
329
    /// @brief Returns remote IP address.
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
    ///
    /// @return remote address
    const isc::asiolink::IOAddress& getRemoteAddr() const {
        return (remote_addr_);
    }

    /// @brief Sets local IP address.
    ///
    /// @param local specifies local address
    void setLocalAddr(const isc::asiolink::IOAddress& local) {
        local_addr_ = local;
    }

    /// @brief Returns local IP address.
    ///
    /// @return local address
    const isc::asiolink::IOAddress& getLocalAddr() const {
        return (local_addr_);
    }

Tomek Mrugalski's avatar
Tomek Mrugalski committed
350
351
352
353
    /// @brief Sets local UDP (and soon TCP) port.
    ///
    /// This sets a local port, i.e. destination port for recently received
    /// packet or a source port for to be transmitted packet.
354
355
356
357
358
359
    ///
    /// @param local specifies local port
    void setLocalPort(uint16_t local) {
        local_port_ = local;
    }

Tomek Mrugalski's avatar
Tomek Mrugalski committed
360
361
362
363
    /// @brief Returns local UDP (and soon TCP) port.
    ///
    /// This sets a local port, i.e. destination port for recently received
    /// packet or a source port for to be transmitted packet.
364
365
366
367
368
369
    ///
    /// @return local port
    uint16_t getLocalPort() const {
        return (local_port_);
    }

Tomek Mrugalski's avatar
Tomek Mrugalski committed
370
371
372
373
    /// @brief Sets remote UDP (and soon TCP) port.
    ///
    /// This sets a remote port, i.e. source port for recently received
    /// packet or a destination port for to be transmitted packet.
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
    ///
    /// @param remote specifies remote port
    void setRemotePort(uint16_t remote) {
        remote_port_ = remote;
    }

    /// @brief Returns remote port.
    ///
    /// @return remote port
    uint16_t getRemotePort() const {
        return (remote_port_);
    }

    /// @brief Sets interface index.
    ///
    /// @param ifindex specifies interface index.
    void setIndex(uint32_t ifindex) {
        ifindex_ = ifindex;
    };

    /// @brief Returns interface index.
    ///
    /// @return interface index
    uint32_t getIndex() const {
        return (ifindex_);
    };

    /// @brief Returns interface name.
    ///
    /// Returns interface name over which packet was received or is
    /// going to be transmitted.
    ///
    /// @return interface name
Tomek Mrugalski's avatar
Tomek Mrugalski committed
407
    std::string getIface() const { return (iface_); };
408
409
410
411
412
413
414
415
416

    /// @brief Sets interface name.
    ///
    /// Sets interface name over which packet was received or is
    /// going to be transmitted.
    ///
    /// @return interface name
    void setIface(const std::string& iface ) { iface_ = iface; };

Tomek Mrugalski's avatar
Tomek Mrugalski committed
417
    /// @brief Sets remote hardware address.
418
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
419
    /// Sets hardware address (MAC) from an existing HWAddr structure.
420
421
422
423
424
    /// The remote address is a destination address for outgoing
    /// packet and source address for incoming packet. When this
    /// is an outgoing packet, this address will be used to
    /// construct the link layer header.
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
425
    /// @param hw_addr structure representing HW address.
426
427
    ///
    /// @throw BadValue if addr is null
Tomek Mrugalski's avatar
Tomek Mrugalski committed
428
    void setRemoteHWAddr(const HWAddrPtr& hw_addr);
429

Tomek Mrugalski's avatar
Tomek Mrugalski committed
430
    /// @brief Sets remote hardware address.
431
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
432
    /// Sets the destination hardware (MAC) address for the outgoing packet
433
434
435
436
437
438
    /// or source HW address for the incoming packet. When this
    /// is an outgoing packet this address will be used to construct
    /// the link layer header.
    ///
    /// @note mac_addr must be a buffer of at least hlen bytes.
    ///
439
440
441
442
443
444
    /// In a typical case, hlen field would be redundant, as it could
    /// be extracted from mac_addr.size(). However, the difference is
    /// when running on exotic hardware, like Infiniband, that had
    /// MAC addresses 20 bytes long. In that case, hlen is set to zero
    /// in DHCPv4.
    ///
445
446
    /// @param htype hardware type (will be sent in htype field)
    /// @param hlen hardware length (will be sent in hlen field)
Tomek Mrugalski's avatar
Tomek Mrugalski committed
447
    /// @param hw_addr pointer to hardware address
448
    void setRemoteHWAddr(const uint8_t htype, const uint8_t hlen,
Tomek Mrugalski's avatar
Tomek Mrugalski committed
449
                         const std::vector<uint8_t>& hw_addr);
450

451
    /// @brief Returns the remote HW address obtained from raw sockets.
452
453
454
455
456
457
    ///
    /// @return remote HW address.
    HWAddrPtr getRemoteHWAddr() const {
        return (remote_hwaddr_);
    }

458
459
460
461
462
463
464
    /// @brief Returns MAC address.
    ///
    /// The difference between this method and getRemoteHWAddr() is that
    /// getRemoteHWAddr() returns only what was obtained from raw sockets.
    /// This method is more generic and can attempt to obtain MAC from
    /// varied sources: raw sockets, client-id, link-local IPv6 address,
    /// and various relay options.
465
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
466
467
468
469
470
    /// @note Technically the proper term for this information is a link layer
    /// address, but it is frequently referred to MAC or hardware address.
    /// Since we're calling the feature "MAC addresses in DHCPv6", we decided
    /// to keep the name of getMAC().
    ///
471
472
473
474
475
    /// hw_addr_src takes a combination of bit values specified in
    /// MAC_SOURCE_* constants.
    ///
    /// @param hw_addr_src a bitmask that specifies hardware address source
    HWAddrPtr getMAC(uint32_t hw_addr_src);
476

Tomek Mrugalski's avatar
Tomek Mrugalski committed
477
    /// @brief Virtual desctructor.
478
479
480
481
482
483
    ///
    /// There is nothing to clean up here, but since there are virtual methods,
    /// we define virtual destructor to ensure that derived classes will have
    /// a virtual one, too.
    virtual ~Pkt() {
    }
Tomek Mrugalski's avatar
Tomek Mrugalski committed
484

Tomek Mrugalski's avatar
Tomek Mrugalski committed
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
    /// @brief Classes this packet belongs to.
    ///
    /// This field is public, so the code outside of Pkt4 or Pkt6 class can
    /// iterate over existing classes. Having it public also solves the problem
    /// of returned reference lifetime. It is preferred to use @ref inClass and
    /// @ref addClass should be used to operate on this field.
    ClientClasses classes_;

    /// @brief Collection of options present in this message.
    ///
    /// @warning This public member is accessed by derived
    /// classes directly. One of such derived classes is
    /// @ref perfdhcp::PerfPkt6. The impact on derived clasess'
    /// behavior must be taken into consideration before making
    /// changes to this member such as access scope restriction or
    /// data format change etc.
    isc::dhcp::OptionCollection options_;

Tomek Mrugalski's avatar
Tomek Mrugalski committed
503
504
protected:

Tomek Mrugalski's avatar
Tomek Mrugalski committed
505
    /// Transaction-id (32 bits for v4, 24 bits for v6)
Tomek Mrugalski's avatar
Tomek Mrugalski committed
506
507
    uint32_t transid_;

Tomek Mrugalski's avatar
Tomek Mrugalski committed
508
    /// Name of the network interface the packet was received/to be sent over.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
509
    std::string iface_;
Tomek Mrugalski's avatar
Tomek Mrugalski committed
510
511

    /// @brief Interface index.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
512
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
513
514
515
    /// Each network interface has assigned an unique ifindex.
    /// It is a functional equivalent of a name, but sometimes more useful, e.g.
    /// when using odd systems that allow spaces in interface names.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
516
517
    int ifindex_;

Tomek Mrugalski's avatar
Tomek Mrugalski committed
518
519
520
    /// @brief Local IP (v4 or v6) address.
    ///
    /// Specifies local IPv4 or IPv6 address. It is a destination address for
Marcin Siodelski's avatar
Marcin Siodelski committed
521
    /// received packet, and a source address if it packet is being transmitted.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
522
523
    isc::asiolink::IOAddress local_addr_;

Tomek Mrugalski's avatar
Tomek Mrugalski committed
524
525
526
527
    /// @brief Remote IP address.
    ///
    /// Specifies local IPv4 or IPv6 address. It is source address for received
    /// packet and a destination address for packet being transmitted.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
    isc::asiolink::IOAddress remote_addr_;

    /// local TDP or UDP port
    uint16_t local_port_;

    /// remote TCP or UDP port
    uint16_t remote_port_;

    /// Output buffer (used during message transmission)
    ///
    /// @warning This protected member is accessed by derived
    /// classes directly. One of such derived classes is
    /// @ref perfdhcp::PerfPkt6. The impact on derived clasess'
    /// behavior must be taken into consideration before making
    /// changes to this member such as access scope restriction or
    /// data format change etc.
    isc::util::OutputBuffer buffer_out_;

    /// packet timestamp
    boost::posix_time::ptime timestamp_;

549
550
551
    // remote HW address (src if receiving packet, dst if sending packet)
    HWAddrPtr remote_hwaddr_;

Tomek Mrugalski's avatar
Tomek Mrugalski committed
552
553
    /// A callback to be called to unpack options from the packet.
    UnpackOptionsCallback callback_;
554
555
556
557
558
559
560
561
562
563

private:

    /// @brief Generic method that validates and sets HW address.
    ///
    /// This is a generic method used by all modifiers of this class
    /// which set class members representing HW address.
    ///
    /// @param htype hardware type.
    /// @param hlen hardware length.
564
565
    /// @param hw_addr pointer to actual hardware address.
    /// @param [out] storage pointer to a class member to be modified.
566
567
568
    ///
    /// @trow isc::OutOfRange if invalid HW address specified.
    virtual void setHWAddrMember(const uint8_t htype, const uint8_t hlen,
569
570
                                 const std::vector<uint8_t>& hw_addr,
                                 HWAddrPtr& storage);
Tomek Mrugalski's avatar
Tomek Mrugalski committed
571
572
573
574
575
576
};

}; // namespace isc::dhcp
}; // namespace isc

#endif