-
Notifications
You must be signed in to change notification settings - Fork 390
/
oper_dhcp_options.h
90 lines (79 loc) · 2.86 KB
/
oper_dhcp_options.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
/*
* Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
*/
#ifndef vnsw_agent_oper_dhcp_options_h_
#define vnsw_agent_oper_dhcp_options_h_
#include <vnc_cfg_types.h>
namespace autogen {
struct DhcpOptionType;
struct RouteType;
}
// DHCP options coming from config
class OperDhcpOptions {
public:
typedef std::vector<autogen::DhcpOptionType> DhcpOptionsList;
typedef std::vector<autogen::RouteType> HostOptionsList;
struct HostRoute {
Ip4Address prefix_;
uint32_t plen_;
Ip4Address gw_;
HostRoute() : prefix_(), plen_(0), gw_() {}
bool operator<(const HostRoute &rhs) const {
if (prefix_ != rhs.prefix_)
return prefix_ < rhs.prefix_;
if (plen_ != rhs.plen_)
return plen_ < rhs.plen_;
return gw_ < rhs.gw_;
}
bool operator==(const HostRoute &rhs) const {
return prefix_ == rhs.prefix_ && plen_ == rhs.plen_ &&
gw_ == rhs.gw_;
}
std::string ToString() const {
char len[32];
snprintf(len, sizeof(len), "%u", plen_);
return prefix_.to_string() + "/" + std::string(len) +
" -> " + gw_.to_string();
}
};
OperDhcpOptions() {}
OperDhcpOptions(const OperDhcpOptions &options) {
dhcp_options_ = options.dhcp_options_;
host_routes_ = options.host_routes_;
}
virtual ~OperDhcpOptions() {}
const DhcpOptionsList &dhcp_options() const { return dhcp_options_; }
const std::vector<HostRoute> &host_routes() const { return host_routes_; }
void set_options(const DhcpOptionsList &options) { dhcp_options_ = options; }
void set_host_routes(const HostOptionsList &host_routes) {
host_routes_.clear();
update_host_routes(host_routes);
}
void update_host_routes(const HostOptionsList &host_routes) {
host_routes_.clear();
for (unsigned int i = 0; i < host_routes.size(); ++i) {
HostRoute host_route;
boost::system::error_code ec = Ip4PrefixParse(host_routes[i].prefix,
&host_route.prefix_,
(int *)&host_route.plen_);
if (ec || host_route.plen_ > 32) {
continue;
}
host_route.gw_ = Ip4Address::from_string(host_routes[i].next_hop, ec);
if (ec) {
host_route.gw_ = Ip4Address();
}
host_routes_.push_back(host_route);
}
}
bool are_dhcp_options_set() const {
return dhcp_options_.size() > 0;
}
bool are_host_routes_set() const {
return host_routes_.size() > 0;
}
private:
DhcpOptionsList dhcp_options_;
std::vector<HostRoute> host_routes_;
};
#endif // vnsw_agent_oper_dhcp_options_h_