8 #include <kea_version.h>
37 const uint32_t MAX_LEASE_ERRORS = 100;
48 const char* LFCController::lfc_app_name_ =
"DhcpLFC";
51 const char* LFCController::lfc_bin_name_ =
"kea-lfc";
53 LFCController::LFCController()
54 : protocol_version_(0), verbose_(false), config_file_(
""), previous_file_(
""),
55 copy_file_(
""), output_file_(
""), finish_file_(
""), pid_file_(
"") {
63 bool do_rotate =
true;
81 startLogger(test_mode);
89 if (pid_file.
check()) {
106 if (!lf_finish.
exists()) {
113 processLeases<Lease4, CSVLeaseFile4, Lease4Storage>();
115 processLeases<Lease6, CSVLeaseFile6, Lease6Storage>();
117 }
catch (
const std::exception& proc_ex) {
154 while ((ch = getopt(argc, argv,
":46dhvVWp:x:i:o:c:f:")) != -1) {
158 protocol_version_ = 4;
163 protocol_version_ = 6;
168 std::cout << getVersion(
false) << std::endl;
173 std::cout << getVersion(
true) << std::endl;
188 if (optarg == NULL) {
196 if (optarg == NULL) {
199 previous_file_ = optarg;
204 if (optarg == NULL) {
212 if (optarg == NULL) {
215 output_file_ = optarg;
220 if (optarg == NULL) {
223 finish_file_ = optarg;
228 if (optarg == NULL) {
231 config_file_ = optarg;
259 if (protocol_version_ == 0) {
263 if (pid_file_.empty()) {
267 if (previous_file_.empty()) {
271 if (copy_file_.empty()) {
275 if (output_file_.empty()) {
279 if (finish_file_.empty()) {
283 if (config_file_.empty()) {
289 std::cout <<
"Protocol version: DHCPv" << protocol_version_ << std::endl
290 <<
"Previous or ex lease file: " << previous_file_ << std::endl
291 <<
"Copy lease file: " << copy_file_ << std::endl
292 <<
"Output lease file: " << output_file_ << std::endl
293 <<
"Finish file: " << finish_file_ << std::endl
294 <<
"Config file: " << config_file_ << std::endl
295 <<
"PID file: " << pid_file_ << std::endl
301 LFCController::usage(
const std::string& text) {
303 std::cerr <<
"Usage error: " << text << std::endl;
307 <<
" [-4|-6] -p file -x file -i file -o file -f file -c file" << std::endl
308 <<
" -4 or -6 clean a set of v4 or v6 lease files" << std::endl
309 <<
" -p <file>: PID file" << std::endl
310 <<
" -x <file>: previous or ex lease file" << std::endl
311 <<
" -i <file>: copy of lease file" << std::endl
312 <<
" -o <file>: output lease file" << std::endl
313 <<
" -f <file>: finish file" << std::endl
314 <<
" -c <file>: configuration file" << std::endl
315 <<
" -v: print version number and exit" << std::endl
316 <<
" -V: print extended version information and exit" << std::endl
317 <<
" -d: optional, verbose output " << std::endl
318 <<
" -h: print this message " << std::endl
323 LFCController::getVersion(
const bool extended)
const{
324 std::stringstream version_stream;
326 version_stream << VERSION;
328 version_stream << std::endl << EXTENDED_VERSION << std::endl
332 return (version_stream.str());
335 template<
typename LeaseObjectType,
typename LeaseFileType,
typename StorageType>
337 LFCController::processLeases()
const {
342 if (lf_prev.exists()) {
343 LeaseFileLoader::load<LeaseObjectType>(lf_prev, storage,
349 if (lf_copy.exists()) {
350 LeaseFileLoader::load<LeaseObjectType>(lf_copy, storage,
356 LeaseFileLoader::write<LeaseObjectType>(lf_output, storage);
360 .arg(lf_prev.getReadLeases() + lf_copy.getReadLeases())
361 .arg(lf_prev.getReads() + lf_copy.getReads())
362 .arg(lf_prev.getReadErrs() + lf_copy.getReadErrs());
365 .arg(lf_output.getWriteLeases())
366 .arg(lf_output.getWrites())
367 .arg(lf_output.getWriteErrs());
371 isc_throw(RunTimeFail,
"Unable to move output (" << output_file_
372 <<
") to complete (" << finish_file_
373 <<
") error: " << strerror(errno));
383 << previous_file_ <<
"' error: " << strerror(errno));
390 << copy_file_ <<
"' error: " << strerror(errno));
394 if (rename(finish_file_.c_str(), previous_file_.c_str()) != 0) {
396 <<
") to previous (" << previous_file_
397 <<
") error: " << strerror(errno));
402 LFCController::startLogger(
const bool test_mode)
const {
429 spec.addOutputOption(option);