26 dhcp_client::state_t::state_t(
int v,
const std::string& s)
31 const dhcp_client::state_t&
43 std::weak_ptr<dhcp_client_cmds::events_cmd> dhcp_client::m_s_event_cmd;
44 dhcp_client::dhcp_client_listener dhcp_client::m_listener;
60 , m_event_cmd(get_event_cmd())
70 : m_itf(itf.singular())
72 , m_client_id(client_id)
77 , m_event_cmd(get_event_cmd())
83 , m_hostname(o.m_hostname)
84 , m_client_id(o.m_client_id)
85 , m_set_broadcast_flag(o.m_set_broadcast_flag)
89 , m_event_cmd(o.m_event_cmd)
98 m_db.release(m_itf->key(),
this);
104 return ((
key() == l.
key()) && (m_hostname == l.m_hostname) &&
105 (m_client_id == l.m_client_id && m_dscp == l.m_dscp));
111 return (m_itf->key());
131 dhcp_client::replay()
135 m_binding, m_itf->handle(), m_hostname, m_client_id,
false, m_dscp));
142 std::ostringstream s;
143 s <<
"DHCP-client: " << m_itf->to_string() <<
" hostname:" << m_hostname
144 <<
" client_id:[" << m_client_id <<
"] "
147 s <<
" " << m_lease->to_string();
162 m_binding, m_itf->handle(), m_hostname, m_client_id,
false, m_dscp));
166 m_lease = desired.m_lease;
167 if (m_evl != desired.m_evl) {
168 m_evl = desired.m_evl;
172 const std::shared_ptr<dhcp_client::lease_t>
184 std::shared_ptr<dhcp_client>
187 return (m_db.find_or_add(temp.m_itf->key(), temp));
190 std::shared_ptr<dhcp_client>
193 return (m_db.find(k));
196 std::shared_ptr<dhcp_client>
199 return find_or_add(*
this);
209 std::shared_ptr<interface> itf,
217 , host_prefix(host_prefix)
226 std::stringstream ss;
228 ss <<
"lease:[" << itf->to_string() <<
" state: " <<
state.to_string()
229 <<
" host: " << host_prefix.to_string() <<
" router: " <<
router_address
230 <<
" mac: " <<
mac.to_string() <<
"]";
236 : m_status(
rc_t::NOOP)
253 dhcp_client::event_handler::handle_replay()
261 std::shared_ptr<dhcp_client_cmds::dump_cmd> cmd =
262 std::make_shared<dhcp_client_cmds::dump_cmd>();
267 for (
auto& record : *cmd) {
268 auto& payload = record.get_payload();
270 std::shared_ptr<interface> itf =
275 <<
" itf:" << payload.client.sw_if_index;
279 const dhcp_client::state_t& s =
281 route::prefix_t pfx(payload.lease.is_ipv6,
282 (uint8_t*)&payload.lease.host_address.un,
283 payload.lease.mask_width);
285 reinterpret_cast<const char*
>(payload.lease.hostname);
286 l2_address_t l2(payload.client.id + 1);
289 dc.lease(std::make_shared<dhcp_client::lease_t>(
290 s, itf,
from_bytes(0, (uint8_t*)&payload.lease.router_address.un), pfx,
297 dhcp_client::event_handler::order()
const
308 std::shared_ptr<dhcp_client_cmds::events_cmd>
309 dhcp_client::get_event_cmd()
311 if (m_s_event_cmd.expired()) {
312 std::shared_ptr<dhcp_client_cmds::events_cmd>
c =
313 std::make_shared<dhcp_client_cmds::events_cmd>(m_listener);
323 return (m_s_event_cmd.lock());
327 dhcp_client::handle_dhcp_event(std::shared_ptr<lease_t>
lease)
335 dhcp_client::dhcp_client_listener::handle_dhcp_event(std::shared_ptr<lease_t> e)
340 std::shared_ptr<dhcp_client> client =
find(e->itf->key());
343 client->handle_dhcp_event(e);