cfg_mac_source.h 2.95 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
// 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 CFG_MAC_SOURCE_H
#define CFG_MAC_SOURCE_H

18
#include <stdint.h>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
19
#include <vector>
20
#include <string>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

namespace isc {
namespace dhcp {

/// @brief Container for defined MAC/hardware address sources
typedef std::vector<uint32_t> CfgMACSources;

/// @brief Wrapper class that holds MAC/hardware address sources
///
/// It's a simple wrapper around a vector of uint32_t, with each entry
/// holding one MAC source.
class CfgMACSource {

 public:
    /// @brief Default constructor.
    ///
    /// Sets source to 'any'.
    CfgMACSource();

    /// @brief Attempts to convert known hardware address sources to uint32_t
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
42
43
44
45
46
47
48
49
50
51
    /// Supported strings are: \li any => 0xffffffff
    ///                        \li raw => 0x00000001
    ///                        \li duid => 0x00000002
    ///                        \li ipv6-link-local 0x00000004
    ///                        \li client-link-addr-option, rfc6939 => 0x00000008
    ///                        \li remote-id, rfc4649 => 0x00000010
    ///                        \li subscriber-id, rfc4580 => 0x00000020
    ///                        \li docsis => 0x00000040
    ///
    /// For specific constants, see @ref isc::dhcp::HWAddr class.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
52
53
54
55
56
57
58
59
60
61
62
    ///
    /// @throw BadValue if specified string is unknown
    /// @return bitmask version of a given method
    static uint32_t MACSourceFromText(const std::string& name);


    /// @brief Adds additional MAC/hardware address aquisition.
    ///
    /// @param source MAC source (see constants in Pkt::HWADDR_SOURCE_*)
    ///
    /// Specified source is being added to the mac_sources_ array.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
63
    /// @todo implement add(string) version of this method.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
    void add(uint32_t source) {
        mac_sources_.push_back(source);
    }

    /// @brief Provides access to the configure MAC/Hardware address sources.
    ///
    /// @note The const reference returned is only valid as long as the
    /// object that returned it.
    const CfgMACSources& get() const {
        return mac_sources_;
    }

    /// @brief Removes any configured MAC/Hardware address sources.
    void clear() {
        mac_sources_.clear();
    }

 protected:
    /// @brief Actual MAC sources storage
    CfgMACSources mac_sources_;

};

};
};

#endif