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
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
// Copyright (C) 2012-2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <config.h>

#include <dhcp/libdhcp++.h>
#include <dhcp/option_custom.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/lease_mgr.h>
#include <exceptions/exceptions.h>
#include <stats/stats_mgr.h>
#include <util/encode/encode.h>
#include <util/str.h>

#include <boost/algorithm/string.hpp><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <algorithm><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <iostream><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <iterator><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <limits><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <map><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <sstream><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <string><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <time.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

using namespace isc::asiolink;
using namespace isc::data;
using namespace isc::db;
using namespace isc::dhcp;
using namespace isc::util;
using namespace std;

namespace isc {
namespace dhcp {

LeasePageSize::LeasePageSize(const size_t page_size)
    : page_size_(page_size) {

    if (page_size_ == 0) {
        isc_throw(OutOfRange, "page size of retrieved leases must not be 0");
    }

    if (page_size_ > std::numeric_limits<uint32_t>::max()) {
        isc_throw(OutOfRange, "page size of retrieved leases must not be greater than "
                  << std::numeric_limits<uint32_t>::max());
    }
}

Lease6Ptr
LeaseMgr::getLease6(Lease::Type type, const DUID& duid,
                    uint32_t iaid, SubnetID subnet_id) const {
    Lease6Collection col = getLeases6(type, duid, iaid, subnet_id);

    if (col.size() > 1) {
        isc_throw(MultipleRecords, "More than one lease found for type "
                  << static_cast<int>(type) << ", duid "
                  << duid.toText() << ", iaid " << iaid
                  << " and subnet-id " << subnet_id);
    }
    if (col.empty()) {
        return (Lease6Ptr());
    }
    return (*col.begin());
}

void
LeaseMgr::recountLeaseStats4() {
    using namespace stats;

    StatsMgr& stats_mgr = StatsMgr::instance();

    LeaseStatsQueryPtr query = startLeaseStatsQuery4();
    if (!query) {
        /// NULL means not backend does not support recounting.
        return;
    }

    // Zero out the global stats.
    // Cumulative counters ("reclaimed-declined-addresses", "reclaimed-leases",
    // "cumulative-assigned-addresses") never get zeroed.
    int64_t zero = 0;
    stats_mgr.setValue("declined-addresses", zero);

    // Create if it does not exit reclaimed declined leases global stats.
    if (!stats_mgr.getObservation("reclaimed-declined-addresses")) {
        stats_mgr.setValue("reclaimed-declined-addresses", zero);
    }

    // Create if it does not exit reclaimed leases global stats.
    if (!stats_mgr.getObservation("reclaimed-leases")) {
        stats_mgr.setValue("reclaimed-leases", zero);
    }

    // Create if it does not exit cumulative global stats.
    if (!stats_mgr.getObservation("cumulative-assigned-addresses")) {
        stats_mgr.setValue("cumulative-assigned-addresses", zero);
    }

    // Clear subnet level stats.  This ensures we don't end up with corner
    // cases that leave stale values in place.
    const Subnet4Collection* subnets =
        CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll();

    for (auto const& subnet : *subnets) {
        SubnetID subnet_id = subnet->getID();
        stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
                                                  "assigned-addresses"),
                           zero);

        stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
                                                  "declined-addresses"),
                           zero);

        const std::string name_rec_dec(StatsMgr::generateName("subnet", subnet_id,
                                                              "reclaimed-declined-addresses"));
        if (!stats_mgr.getObservation(name_rec_dec)) {
            stats_mgr.setValue(name_rec_dec, zero);
        }

        const std::string name_rec(StatsMgr::generateName("subnet", subnet_id,
                                                          "reclaimed-leases"));
        if (!stats_mgr.getObservation(name_rec)) {
            stats_mgr.setValue(name_rec, zero);
        }

        for (auto const& pool : subnet->getPools(Lease::TYPE_V4)) {
            const std::string name_aa(StatsMgr::generateName("subnet", subnet_id,
                                                             StatsMgr::generateName("pool", pool->getID(),
                                                                                    "assigned-addresses")));
            if (!stats_mgr.getObservation(name_aa)) {
                stats_mgr.setValue(name_aa, zero);
            }

            const std::string& name_da(StatsMgr::generateName("subnet", subnet_id,
                                                              StatsMgr::generateName("pool", pool->getID(),
                                                                                     "declined-addresses")));
            if (!stats_mgr.getObservation(name_da)) {
                stats_mgr.setValue(name_da, zero);
            }

            const std::string& pname_rec_dec(StatsMgr::generateName("subnet", subnet_id,
                                                                    StatsMgr::generateName("pool", pool->getID(),
                                                                                          "reclaimed-declined-addresses")));
            if (!stats_mgr.getObservation(pname_rec_dec)) {
                stats_mgr.setValue(pname_rec_dec, zero);
            }

            const std::string& pname_rec(StatsMgr::generateName("subnet", subnet_id,
                                                                StatsMgr::generateName("pool", pool->getID(),
                                                                                      "reclaimed-leases")));
            if (!stats_mgr.getObservation(pname_rec)) {
                stats_mgr.setValue(pname_rec, zero);
            }
        }
    }

    // Get counts per state per subnet. Iterate over the result set
    // updating the subnet and global values.
    LeaseStatsRow row;
    while (query->getNextRow(row)) {
        if (row.lease_state_ == Lease::STATE_DEFAULT) {
            // Add to subnet level value.
            stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
                                                      "assigned-addresses"),
                               row.state_count_);
        } else if (row.lease_state_ == Lease::STATE_DECLINED) {
            // Set subnet level value.
            stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
                                                      "declined-addresses"),
                               row.state_count_);

            // Add to the global value.
            stats_mgr.addValue("declined-addresses", row.state_count_);

            // Add to subnet level value.
            // Declined leases also count as assigned.
            stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
                                                      "assigned-addresses"),
                               row.state_count_);
        }
    }

    query = startPoolLeaseStatsQuery4();
    if (!query) {
        /// NULL means not backend does not support recounting.
        return;
    }

    // Get counts per state per subnet and pool. Iterate over the result set
    // updating the subnet and pool and global values.
    while (query->getNextRow(row)) {
        if (row.lease_state_ == Lease::STATE_DEFAULT) {
            // Add to subnet and pool level value.
            stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
                                                      StatsMgr::generateName("pool", row.pool_id_,
                                                      "assigned-addresses")),
                               row.state_count_);
        } else if (row.lease_state_ == Lease::STATE_DECLINED) {
            // Set subnet and pool level value.
            stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
                                                      StatsMgr::generateName("pool", row.pool_id_,
                                                      "declined-addresses")),
                               row.state_count_);

            // Add to subnet and pool level value.
            // Declined leases also count as assigned.
            stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
                                                      StatsMgr::generateName("pool", row.pool_id_,
                                                      "assigned-addresses")),
                               row.state_count_);
        }
    }
}

LeaseStatsQuery::LeaseStatsQuery(const SelectMode& select_mode)
    : first_subnet_id_(0), last_subnet_id_(0), select_mode_(select_mode) {
    if (select_mode != ALL_SUBNETS && select_mode != ALL_SUBNET_POOLS) {
        isc_throw(BadValue, "LeaseStatsQuery: mode must be either ALL_SUBNETS or ALL_SUBNET_POOLS");
    }
}

LeaseStatsQuery::LeaseStatsQuery(const SubnetID& subnet_id)
    : first_subnet_id_(subnet_id), last_subnet_id_(0),
    select_mode_(SINGLE_SUBNET) {

    if (first_subnet_id_ == 0) {
        isc_throw(BadValue, "LeaseStatsQuery: subnet_id_ must be > 0");
    }
}

LeaseStatsQuery::LeaseStatsQuery(const SubnetID& first_subnet_id,
                                 const SubnetID& last_subnet_id)
    : first_subnet_id_(first_subnet_id), last_subnet_id_(last_subnet_id),
    select_mode_(SUBNET_RANGE) {

    if (first_subnet_id_ == 0) {
        isc_throw(BadValue, "LeaseStatsQuery: first_subnet_id_ must be > 0");
    }

    if (last_subnet_id_ == 0) {
        isc_throw(BadValue, "LeaseStatsQuery: last_subnet_id_ must be > 0");
    }

    if (last_subnet_id_ <= first_subnet_id_) {
        isc_throw(BadValue,
                  "LeaseStatsQuery: last_subnet_id_must be > first_subnet_id_");
    }
}

LeaseStatsQueryPtr
LeaseMgr::startLeaseStatsQuery4() {
    return(LeaseStatsQueryPtr());
}

LeaseStatsQueryPtr
LeaseMgr::startPoolLeaseStatsQuery4() {
    return(LeaseStatsQueryPtr());
}

LeaseStatsQueryPtr
LeaseMgr::startSubnetLeaseStatsQuery4(const SubnetID& /* subnet_id */) {
    return(LeaseStatsQueryPtr());
}

LeaseStatsQueryPtr
LeaseMgr::startSubnetRangeLeaseStatsQuery4(const SubnetID& /* first_subnet_id */,
                                           const SubnetID& /* last_subnet_id */) {
    return(LeaseStatsQueryPtr());
}

bool
LeaseStatsQuery::getNextRow(LeaseStatsRow& /*row*/) {
    return (false);
}

void
LeaseMgr::recountLeaseStats6() {
    using namespace stats;

    StatsMgr& stats_mgr = StatsMgr::instance();

    LeaseStatsQueryPtr query = startLeaseStatsQuery6();
    if (!query) {
        /// NULL means not backend does not support recounting.
        return;
    }

    // Zero out the global stats.
    // Cumulative counters ("reclaimed-declined-addresses", "reclaimed-leases",
    // "cumulative-assigned-nas", "cumulative-assigned-pds") never get zeroed.
    int64_t zero = 0;
    stats_mgr.setValue("declined-addresses", zero);

    if (!stats_mgr.getObservation("reclaimed-declined-addresses")) {
        stats_mgr.setValue("reclaimed-declined-addresses", zero);
    }

    if (!stats_mgr.getObservation("reclaimed-leases")) {
        stats_mgr.setValue("reclaimed-leases", zero);
    }

    // Create if it does not exit cumulative nas global stats.
    if (!stats_mgr.getObservation("cumulative-assigned-nas")) {
        stats_mgr.setValue("cumulative-assigned-nas", zero);
    }

    // Create if it does not exit cumulative pds global stats.
    if (!stats_mgr.getObservation("cumulative-assigned-pds")) {
        stats_mgr.setValue("cumulative-assigned-pds", zero);
    }

    // Clear subnet level stats.  This ensures we don't end up with corner
    // cases that leave stale values in place.
    const Subnet6Collection* subnets =
        CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();

    for (auto const& subnet : *subnets) {
        SubnetID subnet_id = subnet->getID();
        stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
                                                  "assigned-nas"),
                           zero);

        stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
                                                  "assigned-pds"),
                           zero);

        stats_mgr.setValue(StatsMgr::generateName("subnet", subnet_id,
                                                  "declined-addresses"),
                           zero);

        if (!stats_mgr.getObservation(
                StatsMgr::generateName("subnet", subnet_id,
                                       "reclaimed-declined-addresses"))) {
            stats_mgr.setValue(
                StatsMgr::generateName("subnet", subnet_id,
                                       "reclaimed-declined-addresses"),
                zero);
        }

        if (!stats_mgr.getObservation(
                StatsMgr::generateName("subnet", subnet_id,
                                       "reclaimed-leases"))) {
            stats_mgr.setValue(
                StatsMgr::generateName("subnet", subnet_id,
                                       "reclaimed-leases"),
                zero);
        }

        for (auto const& pool : subnet->getPools(Lease::TYPE_NA)) {
            const std::string& name_anas(StatsMgr::generateName("subnet", subnet_id,
                                                                StatsMgr::generateName("pool", pool->getID(),
                                                                                       "assigned-nas")));
            if (!stats_mgr.getObservation(name_anas)) {
                stats_mgr.setValue(name_anas, zero);
            }

            const std::string& name_da(StatsMgr::generateName("subnet", subnet_id,
                                                              StatsMgr::generateName("pool", pool->getID(),
                                                                                     "declined-addresses")));
            if (!stats_mgr.getObservation(name_da)) {
                stats_mgr.setValue(name_da, zero);
            }

            const std::string name_rec_dec(StatsMgr::generateName("subnet", subnet_id,
                                                                  StatsMgr::generateName("pool", pool->getID(),
                                                                                         "reclaimed-declined-addresses")));
            if (!stats_mgr.getObservation(name_rec_dec)) {
                stats_mgr.setValue(name_rec_dec, zero);
            }

            const std::string& name_rec(StatsMgr::generateName("subnet", subnet_id,
                                                               StatsMgr::generateName("pool", pool->getID(),
                                                                                      "reclaimed-leases")));
            if (!stats_mgr.getObservation(name_rec)) {
                stats_mgr.setValue(name_rec, zero);
            }
        }

        for (auto const& pool : subnet->getPools(Lease::TYPE_PD)) {
            const std::string& name_apds(StatsMgr::generateName("subnet", subnet_id,
                                                                StatsMgr::generateName("pd-pool", pool->getID(),
                                                                                       "assigned-pds")));
            if (!stats_mgr.getObservation(name_apds)) {
                stats_mgr.setValue(name_apds, zero);
            }

            const std::string& name_rec(StatsMgr::generateName("subnet", subnet_id,
                                                               StatsMgr::generateName("pd-pool", pool->getID(),
                                                                                      "reclaimed-leases")));
            if (!stats_mgr.getObservation(name_rec)) {
                stats_mgr.setValue(name_rec, zero);
            }
        }
    }

    // Get counts per state per subnet. Iterate over the result set
    // updating the subnet and global values.
    LeaseStatsRow row;
    while (query->getNextRow(row)) {
        switch(row.lease_type_) {
            case Lease::TYPE_NA:
                if (row.lease_state_ == Lease::STATE_DEFAULT) {
                    // Add to subnet level value.
                    stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
                                                              "assigned-nas"),
                                       row.state_count_);
                } else if (row.lease_state_ == Lease::STATE_DECLINED) {
                    // Set subnet level value.
                    stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
                                                              "declined-addresses"),
                                       row.state_count_);

                    // Add to the global value.
                    stats_mgr.addValue("declined-addresses", row.state_count_);

                    // Add to subnet level value.
                    // Declined leases also count as assigned.
                    stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
                                                              "assigned-nas"),
                                       row.state_count_);
                }
                break;

            case Lease::TYPE_PD:
                if (row.lease_state_ == Lease::STATE_DEFAULT) {
                    // Set subnet level value.
                    stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
                                                              "assigned-pds"),
                                       row.state_count_);
                }
                break;

            default:
                // We don't support TYPE_TAs yet
                break;
        }
    }

    query = startPoolLeaseStatsQuery6();
    if (!query) {
        /// NULL means not backend does not support recounting.
        return;
    }

    // Get counts per state per subnet and pool. Iterate over the result set
    // updating the subnet and pool and global values.
    while (query->getNextRow(row)) {
        switch(row.lease_type_) {
            case Lease::TYPE_NA:
                if (row.lease_state_ == Lease::STATE_DEFAULT) {
                    // Add to subnet and pool level value.
                    stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
                                                              StatsMgr::generateName("pool", row.pool_id_,
                                                              "assigned-nas")),
                                       row.state_count_);
                } else if (row.lease_state_ == Lease::STATE_DECLINED) {
                    // Set subnet and pool level value.
                    stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
                                                              StatsMgr::generateName("pool", row.pool_id_,
                                                              "declined-addresses")),
                                       row.state_count_);

                    // Add to subnet and pool level value.
                    // Declined leases also count as assigned.
                    stats_mgr.addValue(StatsMgr::generateName("subnet", row.subnet_id_,
                                                              StatsMgr::generateName("pool", row.pool_id_,
                                                              "assigned-nas")),
                                       row.state_count_);
                }
                break;

            case Lease::TYPE_PD:
                if (row.lease_state_ == Lease::STATE_DEFAULT) {
                    // Set subnet and pool level value.
                    stats_mgr.setValue(StatsMgr::generateName("subnet", row.subnet_id_,
                                                              StatsMgr::generateName("pd-pool", row.pool_id_,
                                                              "assigned-pds")),
                                       row.state_count_);
                }
                break;

            default:
                // We don't support TYPE_TAs yet
                break;
        }
    }
}

LeaseStatsQueryPtr
LeaseMgr::startLeaseStatsQuery6() {
    return(LeaseStatsQueryPtr());
}

LeaseStatsQueryPtr
LeaseMgr::startPoolLeaseStatsQuery6() {
    return(LeaseStatsQueryPtr());
}

LeaseStatsQueryPtr
LeaseMgr::startSubnetLeaseStatsQuery6(const SubnetID& /* subnet_id */) {
    return(LeaseStatsQueryPtr());
}

LeaseStatsQueryPtr
LeaseMgr::startSubnetRangeLeaseStatsQuery6(const SubnetID& /* first_subnet_id */,
                                           const SubnetID& /* last_subnet_id */) {
    return(LeaseStatsQueryPtr());
}

std::string
LeaseMgr::getDBVersion() {
    isc_throw(NotImplemented, "LeaseMgr::getDBVersion() called");
}

void
LeaseMgr::setExtendedInfoTablesEnabled(const DatabaseConnection::ParameterMap& parameters) {
    std::string extended_info_tables;
    try {
        extended_info_tables = parameters.at("extended-info-tables");
    } catch (const exception&) {
        extended_info_tables = "false";
    }
    // If extended_info_tables is 'true' we will enable them.
    if (extended_info_tables == "true") {
        setExtendedInfoTablesEnabled(true);
    }
}

bool
LeaseMgr::upgradeLease4ExtendedInfo(const Lease4Ptr& lease,
                                    CfgConsistency::ExtendedInfoSanity check) {
    const OptionDefinition& rai_def = LibDHCP::DHO_DHCP_AGENT_OPTIONS_DEF();

    bool changed = false;
    if (!lease) {
        return (changed);
    }

    if (check == CfgConsistency::EXTENDED_INFO_CHECK_NONE) {
        return (changed);
    }

    ConstElementPtr user_context = lease->getContext();
    if (!user_context) {
        return (changed);
    }

    ConstElementPtr isc;
    ConstElementPtr extended_info;
    ElementPtr mutable_user_context;
    ElementPtr mutable_isc;
    string verifying = "";
    bool removed_extended_info = false;

    try {
        verifying = "user context";
        if (user_context->getType() != Element::map) {
            isc_throw(BadValue, "user context is not a map");
        }
        if (user_context->empty()) {
            changed = true;
            lease->setContext(ConstElementPtr());
            return (changed);
        }

        verifying = "isc";
        isc = user_context->get("ISC");
        if (!isc) {
            return (changed);
        }
        mutable_user_context =
            boost::const_pointer_cast<Element>(user_context);
        if (!mutable_user_context) {
            // Should not happen...
            mutable_user_context = copy(user_context, 0);
            lease->setContext(mutable_user_context);
        }

        if (isc->getType() != Element::map) {
            isc_throw(BadValue, "ISC entry is not a map");
        }
        if (isc->empty()) {
            changed = true;
            mutable_user_context->remove("ISC");
            if (mutable_user_context->empty()) {
                lease->setContext(ConstElementPtr());
            }
            return (changed);
        }

        verifying = "relay-agent-info";
        extended_info = isc->get("relay-agent-info");
        if (!extended_info) {
            return (changed);
        }
        mutable_isc = boost::const_pointer_cast<Element>(isc);
        if (!mutable_isc) {
            // Should not happen...
            mutable_isc = copy(isc, 0);
            mutable_user_context->set("ISC", mutable_isc);
        }

        if (extended_info->getType() == Element::string) {
            // Upgrade
            changed = true;
            ElementPtr upgraded = Element::createMap();
            upgraded->set("sub-options", extended_info);
            mutable_isc->set("relay-agent-info", upgraded);

            // Try to decode sub-options.
            verifying = "rai";
            string rai_hex = extended_info->stringValue();
            vector<uint8_t> rai_data;
            str::decodeFormattedHexString(rai_hex, rai_data);
            OptionCustomPtr rai(new OptionCustom(rai_def, Option::V4, rai_data));
            if (!rai) {
                isc_throw(BadValue, "can't create RAI option");
            }

            OptionPtr remote_id = rai->getOption(RAI_OPTION_REMOTE_ID);
            if (remote_id) {
                vector<uint8_t> bytes = remote_id->toBinary();
                if (bytes.size() > 0) {
                    upgraded->set("remote-id",
                                  Element::create(encode::encodeHex(bytes)));
                }
            }

            OptionPtr relay_id = rai->getOption(RAI_OPTION_RELAY_ID);
            if (relay_id) {
                vector<uint8_t> bytes = relay_id->toBinary(false);
                if (bytes.size() > 0) {
                    upgraded->set("relay-id",
                                  Element::create(encode::encodeHex(bytes)));
                }
            }

            LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
                      DHCPSRV_LEASE4_EXTENDED_INFO_UPGRADED)
                .arg(lease->addr_.toText());
            return (changed);
        } else if (extended_info->getType() != Element::map) {
            mutable_isc->remove("relay-agent-info");
            removed_extended_info = true;
            isc_throw(BadValue, "relay-agent-info is not a map or a string");
        }

        if (check == CfgConsistency::EXTENDED_INFO_CHECK_FIX) {
            return (changed);
        }

        // Try to decode sub-options.
        ConstElementPtr sub_options = extended_info->get("sub-options");
        if (sub_options) {
            verifying = "sub-options";
            if (sub_options->getType() != Element::string) {
                mutable_isc->remove("relay-agent-info");
                removed_extended_info = true;
                isc_throw(BadValue, "sub-options is not a string");
            }
            string rai_hex = sub_options->stringValue();
            vector<uint8_t> rai_data;
            str::decodeFormattedHexString(rai_hex, rai_data);
        }

        ConstElementPtr remote_id = extended_info->get("remote-id");
        if (remote_id) {
            verifying = "remote-id";
            if (remote_id->getType() != Element::string) {
                mutable_isc->remove("relay-agent-info");
                removed_extended_info = true;
                isc_throw(BadValue, "remote-id is not a string");
            }
            string remote_id_hex = remote_id->stringValue();
            vector<uint8_t> remote_id_data;
            encode::decodeHex(remote_id_hex, remote_id_data);
            if (remote_id_data.empty()) {
                mutable_isc->remove("relay-agent-info");
                removed_extended_info = true;
                isc_throw(BadValue, "remote-id is empty");
            }
        }

        ConstElementPtr relay_id = extended_info->get("relay-id");
        if (relay_id) {
            verifying = "relay-id";
            if (relay_id->getType() != Element::string) {
                mutable_isc->remove("relay-agent-info");
                removed_extended_info = true;
                isc_throw(BadValue, "relay-id is not a string");
            }
            string relay_id_hex = relay_id->stringValue();
            vector<uint8_t> relay_id_data;
            encode::decodeHex(relay_id_hex, relay_id_data);
            if (relay_id_data.empty()) {
                mutable_isc->remove("relay-agent-info");
                removed_extended_info = true;
                isc_throw(BadValue, "relay-id is empty");
            }
        }

        if (check != CfgConsistency::EXTENDED_INFO_CHECK_PEDANTIC) {
            return (changed);
        }

        verifying = "relay-agent-info";
        for (auto const& elem : extended_info->mapValue()) {
            if ((elem.first != "sub-options") &&
                (elem.first != "remote-id") &&
                (elem.first != "relay-id") &&
                (elem.first != "comment")) {
                mutable_isc->remove("relay-agent-info");
                removed_extended_info = true;
                isc_throw(BadValue, "spurious '" << elem.first <<
                          "' entry in relay-agent-info");
            }
        }

        return (changed);
    } catch (const exception& ex) {
        ostringstream err;
        err << "in " << verifying << " a problem was found: " << ex.what();
        LOG_ERROR(dhcpsrv_logger, DHCPSRV_LEASE4_EXTENDED_INFO_SANITY_FAIL)
            .arg(lease->addr_.toText())
            .arg(err.str());

        changed = true;
        if (verifying == "user context") {
            lease->setContext(ConstElementPtr());
        } else if (verifying == "isc") {
            mutable_user_context->remove("ISC");
            if (mutable_user_context->empty()) {
                lease->setContext(ConstElementPtr());
            }
        } else {
            if (!removed_extended_info) {
                mutable_isc->remove("relay-agent-info");
            }
            if (mutable_isc->empty()) {
                mutable_user_context->remove("ISC");
                if (mutable_user_context->empty()) {
                    lease->setContext(ConstElementPtr());
                }
            }
        }
        return (changed);
    }
}

bool
LeaseMgr::upgradeLease6ExtendedInfo(const Lease6Ptr& lease,
                                    CfgConsistency::ExtendedInfoSanity check) {
    bool changed = false;
    if (!lease) {
        return (changed);
    }

    if (check == CfgConsistency::EXTENDED_INFO_CHECK_NONE) {
        return (changed);
    }

    ConstElementPtr user_context = lease->getContext();
    if (!user_context) {
        return (changed);
    }

    ConstElementPtr isc;
    ConstElementPtr relay_info;
    ElementPtr mutable_user_context;
    ElementPtr mutable_isc;
    string verifying = "";
    bool removed_relay_info = false;
    bool upgraded = false;
    bool have_both = false;
    int i = -1;<--- Assignment 'i=-1', assigned value is -1

    try {
        verifying = "user context";
        if (user_context->getType() != Element::map) {
            isc_throw(BadValue, "user context is not a map");
        }
        if (user_context->empty()) {
            changed = true;
            lease->setContext(ConstElementPtr());
            return (changed);
        }

        verifying = "isc";
        isc = user_context->get("ISC");
        if (!isc) {
            return (changed);
        }
        mutable_user_context =
            boost::const_pointer_cast<Element>(user_context);
        if (!mutable_user_context) {
            // Should not happen...
            mutable_user_context = copy(user_context, 0);
            lease->setContext(mutable_user_context);
        }

        if (isc->getType() != Element::map) {
            isc_throw(BadValue, "ISC entry is not a map");
        }
        if (isc->empty()) {
            changed = true;
            mutable_user_context->remove("ISC");
            if (mutable_user_context->empty()) {
                lease->setContext(ConstElementPtr());
            }
            return (changed);
        }
        mutable_isc = boost::const_pointer_cast<Element>(isc);
        if (!mutable_isc) {
            // Should not happen...
            mutable_isc = copy(isc, 0);
            mutable_user_context->set("ISC", mutable_isc);
        }

        relay_info = mutable_isc->get("relays");
        if (relay_info && isc->contains("relay-info")) {
            changed = true;
            mutable_isc->remove("relays");
            have_both = true;
            relay_info.reset();
        }
        if (relay_info) {
            // Upgrade
            changed = true;
            upgraded = true;
            verifying = "relays";
            mutable_isc->set("relay-info", relay_info);
            mutable_isc->remove("relays");

            if (relay_info->getType() != Element::list) {
                mutable_isc->remove("relay-info");
                removed_relay_info = true;
                isc_throw(BadValue, "relays is not a list");
            }
            if (relay_info->empty()) {
                mutable_isc->remove("relay-info");
                removed_relay_info = true;
                isc_throw(BadValue, "relays is empty");
            }

            verifying = "relay";
            for (i = 0; i < relay_info->size(); ++i) {
                ElementPtr relay = relay_info->getNonConst(i);
                if (!relay) {
                    mutable_isc->remove("relay-info");
                    removed_relay_info = true;
                    isc_throw(BadValue, "null relay#" << i);
                }
                if (relay->getType() != Element::map) {
                    mutable_isc->remove("relay-info");
                    removed_relay_info = true;
                    isc_throw(BadValue, "relay#" << i << " is not a map");
                }

                // Try to decode options.
                ConstElementPtr options = relay->get("options");
                if (!options) {
                    continue;
                }

                verifying = "options";
                if (options->getType() != Element::string) {
                    mutable_isc->remove("relay-info");
                    removed_relay_info = true;
                    isc_throw(BadValue, "options is not a string");
                }
                string options_hex = options->stringValue();
                vector<uint8_t> options_data;
                str::decodeFormattedHexString(options_hex, options_data);
                OptionCollection opts;
                LibDHCP::unpackOptions6(options_data, DHCP6_OPTION_SPACE, opts);

                auto remote_id_it = opts.find(D6O_REMOTE_ID);
                if (remote_id_it != opts.end()) {
                    OptionPtr remote_id = remote_id_it->second;
                    if (remote_id) {
                        vector<uint8_t> bytes = remote_id->toBinary();
                        if (bytes.size() > 0) {
                            relay->set("remote-id",
                                       Element::create(encode::encodeHex(bytes)));
                        }
                    }
                }

                auto relay_id_it = opts.find(D6O_RELAY_ID);
                if (relay_id_it != opts.end()) {
                    OptionPtr relay_id = relay_id_it->second;
                    if (relay_id) {
                        vector<uint8_t> bytes = relay_id->toBinary(false);
                        if (bytes.size() > 0) {
                            relay->set("relay-id",
                                       Element::create(encode::encodeHex(bytes)));
                        }
                    }
                }
            }
        }

        verifying = (upgraded ? "relays" : "relay-info");
        i = -1;
        relay_info = mutable_isc->get("relay-info");
        if (!relay_info) {
            return (changed);
        }
        if (!upgraded && (relay_info->getType() != Element::list)) {
            mutable_isc->remove("relay-info");
            removed_relay_info = true;
            isc_throw(BadValue, "relay-info is not a list");
        }
        if (!upgraded && relay_info->empty()) {
            mutable_isc->remove("relay-info");
            removed_relay_info = true;
            isc_throw(BadValue, "relay-info is empty");
        }

        verifying = "relay";
        for (i = 0; i < relay_info->size(); ++i) {
            ElementPtr relay = relay_info->getNonConst(i);
            if (!upgraded && !relay) {
                mutable_isc->remove("relay-info");
                removed_relay_info = true;
                isc_throw(BadValue, "null relay#" << i);
            }
            if (!upgraded && (relay->getType() != Element::map)) {
                mutable_isc->remove("relay-info");
                removed_relay_info = true;
                isc_throw(BadValue, "relay#" << i << " is not a map");
            }

            ConstElementPtr options = relay->get("options");
            if (!upgraded && options) {
                // Try to decode options.
                verifying = "options";
                if (options->getType() != Element::string) {
                    mutable_isc->remove("relay-info");
                    removed_relay_info = true;
                    isc_throw(BadValue, "options is not a string");
                }
                string options_hex = options->stringValue();
                vector<uint8_t> options_data;
                str::decodeFormattedHexString(options_hex, options_data);
                OptionCollection opts;
                LibDHCP::unpackOptions6(options_data, DHCP6_OPTION_SPACE, opts);
            }
            if (check == CfgConsistency::EXTENDED_INFO_CHECK_FIX) {
                continue;
            }

            verifying = "link";
            ConstElementPtr link_addr = relay->get("link");
            if (!link_addr) {
                mutable_isc->remove("relay-info");
                removed_relay_info = true;
                isc_throw(BadValue, "no link");
            }
            if (link_addr->getType() != Element::string) {
                mutable_isc->remove("relay-info");
                removed_relay_info = true;
                isc_throw(BadValue, "link is not a string");
            }
            IOAddress laddr(link_addr->stringValue());
            if (!laddr.isV6()) {
                mutable_isc->remove("relay-info");
                removed_relay_info = true;
                isc_throw(BadValue, "link is not an IPv6 address");
            }

            ConstElementPtr remote_id = relay->get("remote-id");
            if (!upgraded && remote_id) {
                verifying = "remote-id";
                if (remote_id->getType() != Element::string) {
                    mutable_isc->remove("relay-info");
                    removed_relay_info = true;
                    isc_throw(BadValue, "remote-id is not a string");
                }
                string remote_id_hex = remote_id->stringValue();
                vector<uint8_t> remote_id_data;
                encode::decodeHex(remote_id_hex, remote_id_data);
                if (remote_id_data.empty()) {
                    mutable_isc->remove("relay-info");
                    removed_relay_info = true;
                    isc_throw(BadValue, "remote-id is empty");
                }
            }

            ConstElementPtr relay_id = relay->get("relay-id");
            if (!upgraded && relay_id) {
                verifying = "relay-id";
                if (relay_id->getType() != Element::string) {
                    mutable_isc->remove("relay-info");
                    removed_relay_info = true;
                    isc_throw(BadValue, "relay-id is not a string");
                }
                string relay_id_hex = relay_id->stringValue();
                vector<uint8_t> relay_id_data;
                encode::decodeHex(relay_id_hex, relay_id_data);
                if (relay_id_data.empty()) {
                    mutable_isc->remove("relay-info");
                    removed_relay_info = true;
                    isc_throw(BadValue, "relay-id is empty");
                }
            }

            if (check != CfgConsistency::EXTENDED_INFO_CHECK_PEDANTIC) {
                continue;
            }

            verifying = "peer";
            ConstElementPtr peer_addr = relay->get("peer");
            if (!peer_addr) {
                mutable_isc->remove("relay-info");
                removed_relay_info = true;
                isc_throw(BadValue, "no peer");
            }
            if (peer_addr->getType() != Element::string) {
                mutable_isc->remove("relay-info");
                removed_relay_info = true;
                isc_throw(BadValue, "peer is not a string");
            }
            IOAddress paddr(peer_addr->stringValue());
            if (!paddr.isV6()) {
                mutable_isc->remove("relay-info");
                removed_relay_info = true;
                isc_throw(BadValue, "peer is not an IPv6 address");
            }

            verifying = "hop";
            ConstElementPtr hop = relay->get("hop");
            if (!hop) {
                mutable_isc->remove("relay-info");
                removed_relay_info = true;
                isc_throw(BadValue, "no hop");
            }
            if (hop->getType() != Element::integer) {
                mutable_isc->remove("relay-info");
                removed_relay_info = true;
                isc_throw(BadValue, "hop is not an integer");
            }

            verifying = (upgraded ? "relays" : "relay-info");
            for (auto const& elem : relay->mapValue()) {
                if ((elem.first != "hop") &&
                    (elem.first != "link") &&
                    (elem.first != "peer") &&
                    (elem.first != "options") &&
                    (elem.first != "remote-id") &&
                    (elem.first != "relay-id") &&
                    (elem.first != "comment")) {
                    mutable_isc->remove("relay-info");
                    removed_relay_info = true;
                    isc_throw(BadValue, "spurious '" << elem.first << "' entry");
                }
            }
        }

        if (upgraded) {
            LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
                      DHCPSRV_LEASE6_EXTENDED_INFO_UPGRADED)
                .arg(lease->addr_.toText());
        }

        return (changed);
    } catch (const exception& ex) {
        ostringstream err;
        err << "in " << verifying;
        if (i >= 0) {<--- Condition 'i>=0' is always false
            err << " [relay#" << i << "]";
        }
        err << " a problem was found: " << ex.what();
        LOG_ERROR(dhcpsrv_logger, DHCPSRV_LEASE6_EXTENDED_INFO_SANITY_FAIL)
            .arg(lease->addr_.toText())
            .arg(err.str());

        changed = true;
        have_both = !have_both;<--- Variable 'have_both' is assigned a value that is never used.
        if (verifying == "user context") {
            lease->setContext(ConstElementPtr());
        } else if (verifying == "isc") {
            mutable_user_context->remove("ISC");
            if (mutable_user_context->empty()) {
                lease->setContext(ConstElementPtr());
            }
        } else {
            if (!removed_relay_info) {
                mutable_isc->remove("relay-info");
            }
            if (mutable_isc->empty()) {
                mutable_user_context->remove("ISC");
                if (mutable_user_context->empty()) {
                    lease->setContext(ConstElementPtr());
                }
            }
        }
        return (changed);
    }
}

void
LeaseMgr::extractLease4ExtendedInfo(const Lease4Ptr& lease,
                                    bool ignore_errors) {
    if (!lease) {
        return;
    }

    ConstElementPtr user_context = lease->getContext();
    if (!user_context) {
        return;
    }
    if (user_context->getType() != Element::map) {
        if (ignore_errors) {
            return;
        }
        isc_throw(BadValue, "user context is not a map");
    }
    if (user_context->empty()) {
        return;
    }

    ConstElementPtr isc = user_context->get("ISC");
    if (!isc) {
        return;
    }
    if (isc->getType() != Element::map) {
        if (ignore_errors) {
            return;
        }
        isc_throw(BadValue, "ISC entry is not a map");
    }
    if (isc->empty()) {
        return;
    }

    ConstElementPtr extended_info = isc->get("relay-agent-info");
    if (!extended_info) {
        return;
    }
    if (extended_info->getType() != Element::map) {
        if (ignore_errors) {
            return;
        }
        isc_throw(BadValue, "relay-agent-info is not a map");
    }
    if (extended_info->empty()) {
        return;
    }

    ConstElementPtr relay_id = extended_info->get("relay-id");
    if (relay_id) {
        if (relay_id->getType() == Element::string) {
            vector<uint8_t> bytes;
            try {
                encode::decodeHex(relay_id->stringValue(), bytes);
            } catch (...) {
                // Decode failed
                if (!ignore_errors) {
                    throw;
                }
            }
            lease->relay_id_ = bytes;
        } else if (!ignore_errors) {
            isc_throw(BadValue, "relay-id entry is not a string");
        }
    }

    ConstElementPtr remote_id = extended_info->get("remote-id");
    if (remote_id) {
        if (remote_id->getType() == Element::string) {
            vector<uint8_t> bytes;
            try {
                encode::decodeHex(remote_id->stringValue(), bytes);
            } catch (...) {
                // Decode failed
                if (!ignore_errors) {
                    throw;
                }
            }
            lease->remote_id_ = bytes;
        } else if (!ignore_errors) {
            isc_throw(BadValue, "remote-id entry is not a string");
        }
    }
}

bool
LeaseMgr::addExtendedInfo6(const Lease6Ptr& lease) {

    bool added = false;
    if (!lease) {
        return (added);
    }

    ConstElementPtr user_context = lease->getContext();
    if (!user_context || (user_context->getType() != Element::map) ||
        user_context->empty()) {
        return (added);
    }

    ConstElementPtr isc = user_context->get("ISC");
    if (!isc || (isc->getType() != Element::map) || isc->empty()) {
        return (added);
    }

    ConstElementPtr relay_info = isc->get("relay-info");
    if (!relay_info || (relay_info->getType() != Element::list) ||
        relay_info->empty()) {
        return (added);
    }

    for (int i = 0; i < relay_info->size(); ++i) {
        ConstElementPtr relay = relay_info->get(i);
        if (!relay || (relay->getType() != Element::map) || relay->empty()) {
            continue;
        }
        try {
            ConstElementPtr relay_id = relay->get("relay-id");
            if (relay_id) {
                string relay_id_hex = relay_id->stringValue();
                vector<uint8_t> relay_id_data;
                encode::decodeHex(relay_id_hex, relay_id_data);
                if (relay_id_data.empty()) {
                    continue;
                }
                addRelayId6(lease->addr_, relay_id_data);
                added = true;
            }

            ConstElementPtr remote_id = relay->get("remote-id");
            if (remote_id) {
                string remote_id_hex = remote_id->stringValue();
                vector<uint8_t> remote_id_data;
                encode::decodeHex(remote_id_hex, remote_id_data);
                if (remote_id_data.empty()) {
                    continue;
                }
                addRemoteId6(lease->addr_, remote_id_data);
                added = true;
            }
        } catch (const exception&) {
            continue;
        }
    }
    return (added);
}

size_t
LeaseMgr::byRelayId6size() const {
    return (0);
}

size_t
LeaseMgr::byRemoteId6size() const {
    return (0);
}

} // namespace isc::dhcp
} // namespace isc