5 #include <boost/filesystem.hpp>
12 #include "services/services_types.h"
16 using namespace boost::asio;
17 using boost::asio::ip::udp;
20 bool run_with_vrouter) :
22 run_with_vrouter_(run_with_vrouter), ip_fabric_interface_(NULL),
23 ip_fabric_interface_index_(-1), pkt_interface_index_(-1),
24 dhcp_server_socket_(
io), dhcp_server_read_buf_(NULL),
25 gateway_delete_seqno_(0) {
32 boost::system::error_code ec;
37 DHCP_TRACE(Error,
"Error creating DHCP socket : " << ec);
65 boost::system::error_code ec;
68 DHCP_TRACE(Error,
"Error shutting down DHCP socket : " << ec);
72 DHCP_TRACE(Error,
"Error closing DHCP socket : " << ec);
88 boost::asio::placeholders::error,
89 boost::asio::placeholders::bytes_transferred));
97 DHCP_TRACE(Error,
"Error reading packet <" + error.message() +
">");
98 if (error == boost::system::errc::operation_canceled) {
114 boost::asio::io_context &
io) {
160 if (vmi->
vn() == NULL || subnet.to_ulong() == 0) {
162 DHCP_TRACE(
Trace,
"DHCP Lease DB not created - config not present : " <<
163 vmi->
subnet().to_string());
172 vmi->
subnet().to_string() <<
" - IPAM not available");
177 std::vector<Ip4Address> reserve_list;
182 reserve_list.push_back(vn_ipam->
default_gw.to_v4());
183 reserve_list.push_back(vn_ipam->
dns_server.to_v4());
184 res += vn_ipam->
default_gw.to_v4().to_string() +
", ";
185 res += vn_ipam->
dns_server.to_v4().to_string();
189 vmi->
name() <<
" " << vmi->
subnet().to_string() <<
"/" <<
199 vmi->
subnet().to_string() <<
"/" <<
217 for (std::set<VmInterface *>::iterator it =
gw_vmi_list_.begin();
238 boost::filesystem::path dir(
agent()->params()->agent_base_dir() +
"/dhcp");
239 boost::system::error_code ec;
240 if (!boost::filesystem::exists(dir, ec)) {
241 boost::filesystem::create_directory(dir, ec);
245 DHCP_TRACE(Error,
"Cannot create DHCP Lease directory : " << dir);
263 std::set<std::string> filelist;
264 for (std::set<VmInterface *>::const_iterator it =
gw_vmi_list_.begin();
270 boost::system::error_code ec;
271 boost::filesystem::path dir(
agent()->params()->agent_base_dir() +
273 if (boost::filesystem::exists(dir, ec) &&
274 boost::filesystem::is_directory(dir, ec)) {
275 for (boost::filesystem::directory_iterator it(dir);
276 it != boost::filesystem::directory_iterator(); ++it) {
277 std::string filename = it->path().string();
278 if (boost::filesystem::is_regular_file(it->status()) &&
279 filelist.find(filename) == filelist.end()) {
281 remove(filename.c_str());
boost::asio::ip::address IpAddress
boost::asio::ip::address_v4 Ip4Address
uint32_t services_queue_limit()
bool dhcp_relay_mode() const
InterfaceTable * interface_table() const
AgentParam * params() const
VnTable * vn_table() const
const std::string & fabric_interface_name() const
ListenerId Register(ChangeCallback callback, const std::string &name="unspecified")
void Unregister(ListenerId listener)
static const uint32_t kDhcpMaxPacketSize
void ItfNotify(DBEntryBase *entry)
void DeleteLeaseDb(VmInterface *vmi)
ProtoHandler * AllocProtoHandler(boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
uint32_t gateway_delete_seqno_
boost::asio::ip::udp::socket dhcp_server_socket_
LeaseManagerMap lease_manager_
Timer * lease_file_cleanup_timer_
void StartLeaseFileCleanupTimer()
DBTableBase::ListenerId vnid_
std::pair< Interface *, DhcpLeaseDb * > LeaseManagerPair
bool LeaseFileCleanupExpiry(uint32_t seqno)
DBTableBase::ListenerId iid_
void VnNotify(DBEntryBase *entry)
void ReadHandler(const boost::system::error_code &error, std::size_t len)
void set_ip_fabric_interface(Interface *itf)
uint8_t * dhcp_server_read_buf_
void set_ip_fabric_interface_mac(const MacAddress &mac)
DhcpLeaseDb * GetLeaseDb(Interface *intrface)
std::set< VmInterface * > gw_vmi_list_
boost::asio::ip::udp::endpoint remote_endpoint_
static const uint32_t kDhcpLeaseFileDeleteTimeout
void set_ip_fabric_interface_index(uint32_t ind)
DhcpProto(Agent *agent, boost::asio::io_context &io, bool run_with_vrouter)
std::string GetLeaseFileName(const VmInterface *vmi)
void SendDhcpIpc(uint8_t *dhcp, std::size_t len)
void set_pkt_interface_index(uint32_t ind)
void CreateLeaseDb(VmInterface *vmi)
const MacAddress & mac() const
const std::string & name() const
const boost::uuids::uuid & GetUuid() const
const uint32_t id() const
void SendMessage(PktModuleName mod, InterTaskMsg *msg)
PktHandler * pkt_handler() const
boost::asio::io_context & io_
ProtoWorkQueue work_queue_
static TaskScheduler * GetInstance()
static bool DeleteTimer(Timer *Timer)
static Timer * CreateTimer(boost::asio::io_context &service, const std::string &name, int task_id=Timer::GetTimerTaskId(), int task_instance=Timer::GetTimerInstanceId(), bool delete_on_completion=false)
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
VmInterface::VmiType vmi_type() const
const uint8_t subnet_plen() const
const VnEntry * vn() const
const Ip4Address & primary_ip_addr() const
const Ip4Address & subnet() const
const VnIpam * GetIpam(const IpAddress &ip) const
void SetBounded(bool bounded)
void SetSize(size_t size)
#define DHCP_TRACE(obj, arg)
static std::string UuidToString(const boost::uuids::uuid &id)