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
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737 | // Copyright (C) 2022-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 <asiolink/addr_utilities.h>
#include <pgsql_cb_dhcp6.h><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <pgsql_cb_impl.h><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <pgsql_query_macros_dhcp.h><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <cc/data.h>
#include <config_backend/constants.h>
#include <database/database_connection.h>
#include <database/db_exceptions.h>
#include <dhcp/classify.h>
#include <dhcp/dhcp6.h>
#include <dhcp/libdhcp++.h>
#include <dhcp/option_data_types.h>
#include <dhcp/option_space.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/config_backend_dhcp6_mgr.h>
#include <dhcpsrv/network.h>
#include <dhcpsrv/pool.h>
#include <dhcpsrv/lease.h>
#include <dhcpsrv/timer_mgr.h>
#include <dhcpsrv/parsers/client_class_def_parser.h>
#include <util/buffer.h>
#include <util/boost_time_utils.h>
#include <util/dhcp_space.h>
#include <util/multi_threading_mgr.h>
#include <util/triplet.h>
#include <pgsql/pgsql_connection.h>
#include <boost/date_time/posix_time/posix_time.hpp><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <boost/lexical_cast.hpp><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <boost/pointer_cast.hpp><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <boost/scoped_ptr.hpp><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
using namespace isc::cb;
using namespace isc::db;
using namespace isc::data;
using namespace isc::asiolink;
using namespace isc::log;
using namespace isc::util;
namespace isc {
namespace dhcp {
/// @brief Implementation of the PostgreSQL Configuration Backend.
class PgSqlConfigBackendDHCPv6Impl : public PgSqlConfigBackendImpl {
public:
/// @brief Statement tags.
///
/// The contents of the enum are indexes into the list of SQL statements.
/// It is assumed that the order is such that the indices of statements
/// reading the database are less than those of statements modifying the
/// database.
enum StatementIndex {
CREATE_AUDIT_REVISION,
CHECK_CLIENT_CLASS_KNOWN_DEPENDENCY_CHANGE,
GET_GLOBAL_PARAMETER6,
GET_ALL_GLOBAL_PARAMETERS6,
GET_MODIFIED_GLOBAL_PARAMETERS6,
GET_SUBNET6_ID_NO_TAG,
GET_SUBNET6_ID_ANY,
GET_SUBNET6_ID_UNASSIGNED,
GET_SUBNET6_PREFIX_NO_TAG,
GET_SUBNET6_PREFIX_ANY,
GET_SUBNET6_PREFIX_UNASSIGNED,
GET_ALL_SUBNETS6,
GET_ALL_SUBNETS6_UNASSIGNED,
GET_MODIFIED_SUBNETS6,
GET_MODIFIED_SUBNETS6_UNASSIGNED,
GET_SHARED_NETWORK_SUBNETS6,
GET_POOL6_RANGE,
GET_POOL6_RANGE_ANY,
GET_PD_POOL,
GET_PD_POOL_ANY,
GET_SHARED_NETWORK6_NAME_NO_TAG,
GET_SHARED_NETWORK6_NAME_ANY,
GET_SHARED_NETWORK6_NAME_UNASSIGNED,
GET_ALL_SHARED_NETWORKS6,
GET_ALL_SHARED_NETWORKS6_UNASSIGNED,
GET_MODIFIED_SHARED_NETWORKS6,
GET_MODIFIED_SHARED_NETWORKS6_UNASSIGNED,
GET_OPTION_DEF6_CODE_SPACE,
GET_ALL_OPTION_DEFS6,
GET_MODIFIED_OPTION_DEFS6,
GET_OPTION6_CODE_SPACE,
GET_ALL_OPTIONS6,
GET_MODIFIED_OPTIONS6,
GET_OPTION6_SUBNET_ID_CODE_SPACE,
GET_OPTION6_POOL_ID_CODE_SPACE,
GET_OPTION6_PD_POOL_ID_CODE_SPACE,
GET_OPTION6_SHARED_NETWORK_CODE_SPACE,
GET_CLIENT_CLASS6_NAME,
GET_ALL_CLIENT_CLASSES6,
GET_ALL_CLIENT_CLASSES6_UNASSIGNED,
GET_MODIFIED_CLIENT_CLASSES6,
GET_MODIFIED_CLIENT_CLASSES6_UNASSIGNED,
GET_AUDIT_ENTRIES6_TIME,
GET_SERVER6,
GET_ALL_SERVERS6,
INSERT_GLOBAL_PARAMETER6,
INSERT_GLOBAL_PARAMETER6_SERVER,
INSERT_SUBNET6,
INSERT_SUBNET6_SERVER,
INSERT_POOL6,
INSERT_PD_POOL,
INSERT_SHARED_NETWORK6,
INSERT_SHARED_NETWORK6_SERVER,
INSERT_OPTION_DEF6,
INSERT_OPTION_DEF6_CLIENT_CLASS,
INSERT_OPTION_DEF6_SERVER,
INSERT_OPTION6,
INSERT_OPTION6_SERVER,
INSERT_CLIENT_CLASS6,
INSERT_CLIENT_CLASS6_SERVER,
INSERT_CLIENT_CLASS6_DEPENDENCY,
INSERT_SERVER6,
UPDATE_GLOBAL_PARAMETER6,
UPDATE_SUBNET6,
UPDATE_SHARED_NETWORK6,
UPDATE_OPTION_DEF6,
UPDATE_OPTION_DEF6_CLIENT_CLASS,
UPDATE_OPTION6,
UPDATE_OPTION6_SUBNET_ID,
UPDATE_OPTION6_POOL_ID,
UPDATE_OPTION6_PD_POOL_ID,
UPDATE_OPTION6_SHARED_NETWORK,
UPDATE_OPTION6_CLIENT_CLASS,
UPDATE_CLIENT_CLASS6,
UPDATE_CLIENT_CLASS6_SAME_POSITION,
UPDATE_SERVER6,
DELETE_GLOBAL_PARAMETER6,
DELETE_ALL_GLOBAL_PARAMETERS6,
DELETE_ALL_GLOBAL_PARAMETERS6_UNASSIGNED,
DELETE_SUBNET6_ID_WITH_TAG,
DELETE_SUBNET6_ID_ANY,
DELETE_SUBNET6_PREFIX_WITH_TAG,
DELETE_SUBNET6_PREFIX_ANY,
DELETE_ALL_SUBNETS6,
DELETE_ALL_SUBNETS6_UNASSIGNED,
DELETE_ALL_SUBNETS6_SHARED_NETWORK_NAME,
DELETE_SUBNET6_SERVER,
DELETE_POOLS6,
DELETE_PD_POOLS,
DELETE_SHARED_NETWORK6_NAME_WITH_TAG,
DELETE_SHARED_NETWORK6_NAME_ANY,
DELETE_ALL_SHARED_NETWORKS6,
DELETE_ALL_SHARED_NETWORKS6_UNASSIGNED,
DELETE_SHARED_NETWORK6_SERVER,
DELETE_OPTION_DEF6_CODE_NAME,
DELETE_ALL_OPTION_DEFS6,
DELETE_ALL_OPTION_DEFS6_UNASSIGNED,
DELETE_OPTION_DEFS6_CLIENT_CLASS,
DELETE_OPTION6,
DELETE_ALL_GLOBAL_OPTIONS6_UNASSIGNED,
DELETE_OPTION6_SUBNET_ID,
DELETE_OPTION6_POOL_RANGE,
DELETE_OPTION6_PD_POOL,
DELETE_OPTION6_SHARED_NETWORK,
DELETE_OPTIONS6_SUBNET_ID_PREFIX,
DELETE_OPTIONS6_SHARED_NETWORK,
DELETE_OPTIONS6_CLIENT_CLASS,
DELETE_CLIENT_CLASS6_DEPENDENCY,
DELETE_CLIENT_CLASS6_SERVER,
DELETE_ALL_CLIENT_CLASSES6,
DELETE_ALL_CLIENT_CLASSES6_UNASSIGNED,
DELETE_CLIENT_CLASS6,
DELETE_CLIENT_CLASS6_ANY,
DELETE_SERVER6,
DELETE_ALL_SERVERS6,
GET_LAST_INSERT_ID6,
NUM_STATEMENTS
};
/// @brief Constructor.
///
/// @param parameters A data structure relating keywords and values
/// concerned with the database.
explicit PgSqlConfigBackendDHCPv6Impl(const DatabaseConnection::ParameterMap&
parameters);
/// @brief Destructor.
~PgSqlConfigBackendDHCPv6Impl();
/// @brief Fetches the SQL statement for a given statement index.
///
/// @param index index of the desired statement.
/// @throw BadValue if there is no statement corresponding to
/// the index.
virtual PgSqlTaggedStatement& getStatement(size_t index) const;
/// @brief Sends query to retrieve global parameter.
///
/// @param server_selector Server selector.
/// @param name Name of the parameter to be retrieved.
///
/// @return Pointer to the retrieved value or null if such parameter
/// doesn't exist.
StampedValuePtr getGlobalParameter6(const ServerSelector& server_selector,
const std::string& name) {
StampedValueCollection parameters;
auto const& tags = server_selector.getTags();
for (auto const& tag : tags) {
PsqlBindArray in_bindings;
in_bindings.addTempString(tag.get());
in_bindings.add(name);
getGlobalParameters(GET_GLOBAL_PARAMETER6, in_bindings, parameters);
}
return (parameters.empty() ? StampedValuePtr() : *parameters.begin());
}
/// @brief Sends query to insert or update global parameter.
///
/// @param server_selector Server selector.
/// @param value StampedValue describing the parameter to create/update.
void createUpdateGlobalParameter6(const db::ServerSelector& server_selector,
const StampedValuePtr& value) {
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
" (unassigned) is unsupported at the moment");
}
auto tag = getServerTag(server_selector, "creating or updating global parameter");
PsqlBindArray in_bindings;
in_bindings.addTempString(value->getName());
in_bindings.addTempString(value->getValue());
in_bindings.add(value->getType()),
in_bindings.addTimestamp(value->getModificationTime()),
in_bindings.addTempString(tag);
in_bindings.addTempString(value->getName());
PgSqlTransaction transaction(conn_);
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision audit_revision(this,
PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
server_selector, "global parameter set",
false);
// Try to update the existing row.
if (updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::UPDATE_GLOBAL_PARAMETER6,
in_bindings) == 0) {
// No such parameter found, so let's insert it. We have to adjust the
// bindings collection to match the prepared statement for insert.
in_bindings.popBack();
in_bindings.popBack();
insertQuery(PgSqlConfigBackendDHCPv6Impl::INSERT_GLOBAL_PARAMETER6,
in_bindings);
// Successfully inserted global parameter. Now, we have to associate it
// with the server tag.
PsqlBindArray attach_bindings;
uint64_t pid = getLastInsertId("dhcp6_global_parameter", "id");
attach_bindings.add(pid); // id of newly inserted global.
attach_bindings.addTimestamp(value->getModificationTime());
attachElementToServers(PgSqlConfigBackendDHCPv6Impl::INSERT_GLOBAL_PARAMETER6_SERVER,
server_selector, attach_bindings);
}
transaction.commit();
}
/// @brief Sends query to the database to retrieve multiple subnets.
///
/// Query should order subnets by subnet_id.
///
/// @param index Index of the query to be used.
/// @param server_selector Server selector.
/// @param in_bindings Input bindings specifying selection criteria. The
/// size of the bindings collection must match the number of placeholders
/// in the prepared statement. The input bindings collection must be empty
/// if the query contains no WHERE clause.
/// @param [out] subnets Reference to the container where fetched subnets
/// will be inserted.
void getSubnets6(const StatementIndex& index,
const ServerSelector& server_selector,
const PsqlBindArray& in_bindings,
Subnet6Collection& subnets) {
uint64_t last_pool_id = 0;
uint64_t last_pd_pool_id = 0;
uint64_t last_pool_option_id = 0;
uint64_t last_pd_pool_option_id = 0;
uint64_t last_option_id = 0;
Pool6Ptr last_pool;
Pool6Ptr last_pd_pool;
std::string last_tag;
// Execute actual query.
selectQuery(index, in_bindings,
[this, &subnets, &last_pool, &last_pd_pool,
&last_pool_id, &last_pd_pool_id,
&last_pool_option_id, &last_pd_pool_option_id,
&last_option_id, &last_tag](PgSqlResult& r, int row) {
// Create a convenience worker for the row.
PgSqlResultRowWorker worker(r, row);
// Get pointer to the last subnet in the collection.
Subnet6Ptr last_subnet;
if (!subnets.empty()) {
last_subnet = *subnets.rbegin();
}
// Subnet_id is column 0.
SubnetID subnet_id = worker.getInt(0) ;
// Subnet has been returned. Assuming that subnets are ordered by
// subnet identifier, if the subnet identifier of the current row
// is different than the subnet identifier of the previously returned
// row, it means that we have to construct new subnet object.
if (!last_subnet || (last_subnet->getID() != subnet_id)) {
// Reset per subnet component tracking and server tag because
// we're now starting to process a new subnet.
last_pool_id = 0;
last_pd_pool_id = 0;
last_pool_option_id = 0;
last_pd_pool_option_id = 0;
last_option_id = 0;
last_pool.reset();
last_pd_pool.reset();
last_tag.clear();
// Get subnet parameters required by the constructor first.
// subnet_prefix at 1.
std::string subnet_prefix = worker.getString(1);
auto prefix_pair = Subnet6::parsePrefix(subnet_prefix);
// preferred_lifetime (5)
// min_preferred_lifetime (75)
// max_preferred_lifetime (76)
auto preferred_lifetime = worker.getTriplet(5, 75, 76);
// renew_timer at 9.
auto renew_timer = worker.getTriplet(9);
// rebind_timer at 7.
auto rebind_timer = worker.getTriplet(7);
// valid_lifetime at 14.
// min_valid_lifetime at 77.
// max_valid_lifetime at 78.
auto valid_lifetime = worker.getTriplet(14, 77, 78);
// Create subnet with basic settings.
last_subnet = Subnet6::create(prefix_pair.first, prefix_pair.second,
renew_timer, rebind_timer,
preferred_lifetime,
valid_lifetime, subnet_id);
// 0 and 1 are subnet_id and subnet_prefix
// client_class at 2.
if (!worker.isColumnNull(2)) {
last_subnet->allowClientClass(worker.getString(2));
}
// interface at 3.
if (!worker.isColumnNull(3)) {
last_subnet->setIface(worker.getString(3));
}
// modification_ts at 4.
last_subnet->setModificationTime(worker.getTimestamp(4));
// preferred_lifetime is 5.
if (!worker.isColumnNull(6)) {
last_subnet->setRapidCommit(worker.getBool(6));
}
// rebind_timer is 7.
// Relay addresses at 8.
setRelays(worker, 8, *last_subnet);
// renew_timer is 9.
// evaluate_additional_classes at 10.
clientClassesFromColumn(worker, 10, "evaluate_additional_classes",
last_subnet->getMutableAdditionalClasses());
// reservations_global at 11.
if (!worker.isColumnNull(11)) {
last_subnet->setReservationsGlobal(worker.getBool(11));
}
// shared_network_name at 12.
if (!worker.isColumnNull(12)) {
last_subnet->setSharedNetworkName(worker.getString(12));
}
// user_context at 13.
if (!worker.isColumnNull(13)) {
ElementPtr user_context = worker.getJSON(13);
if (user_context) {
last_subnet->setContext(user_context);
}
}
// valid_lifetime at 14.
// 15 to 19 are pool
// 20 to 25 are pd pool
// 26 to 40 are pool option
// 41 to 55 are pd pool option
// 56 to 70 are option
// calculate_tee_times at 71.
if (!worker.isColumnNull(71)) {
last_subnet->setCalculateTeeTimes(worker.getBool(71));
}
// t1_percent at 72.
if (!worker.isColumnNull(72)) {
last_subnet->setT1Percent(worker.getDouble(72));
}
// t2_percent at 73.
if (!worker.isColumnNull(73)) {
last_subnet->setT2Percent(worker.getDouble(73));
}
// interface_id at 74.
setInterfaceId(*last_subnet, worker, 74);
// 75 and 76 are {min,max}_preferred_lifetime
// 77 and 78 are {min,max}_valid_lifetime
// 79 is pool client_class
// 80 is pool evaluate_additional_classes
// 81 is pool user_context
// 82 is pd pool excluded_prefix
// 83 is pd pool excluded_prefix_length
// 84 is pd pool client_class
// 85 is pd pool evaluate_additional_classes
// 86 is pd pool user_context
// ddns_send_updates at 87.
if (!worker.isColumnNull(87)) {
last_subnet->setDdnsSendUpdates(worker.getBool(87));
}
// ddns_override_no_update at 88.
if (!worker.isColumnNull(88)) {
last_subnet->setDdnsOverrideNoUpdate(worker.getBool(88));
}
// ddns_override_client_update at 89.
if (!worker.isColumnNull(89)) {
last_subnet->setDdnsOverrideClientUpdate(worker.getBool(89));
}
// ddns_replace_client_name at 90.
if (!worker.isColumnNull(90)) {
last_subnet->setDdnsReplaceClientNameMode(
static_cast<D2ClientConfig::ReplaceClientNameMode>(worker.getSmallInt(90)));
}
// ddns_generated_prefix at 91.
if (!worker.isColumnNull(91)) {
last_subnet->setDdnsGeneratedPrefix(worker.getString(91));
}
// ddns_qualifying_suffix at 92.
if (!worker.isColumnNull(92)) {
last_subnet->setDdnsQualifyingSuffix(worker.getString(92));
}
// reservations_in_subnet at 93.
if (!worker.isColumnNull(93)) {
last_subnet->setReservationsInSubnet(worker.getBool(93));
}
// reservations_out_of_pool at 94.
if (!worker.isColumnNull(94)) {
last_subnet->setReservationsOutOfPool(worker.getBool(94));
}
// cache_threshold at 95.
if (!worker.isColumnNull(95)) {
last_subnet->setCacheThreshold(worker.getDouble(95));
}
// cache_max_age at 96.
if (!worker.isColumnNull(96)) {
last_subnet->setCacheMaxAge(worker.getInt(96));
}
// allocator at 97.
if (!worker.isColumnNull(97)) {
last_subnet->setAllocatorType(worker.getString(97));
}
// pd_allocator at 98.
if (!worker.isColumnNull(98)) {
last_subnet->setPdAllocatorType(worker.getString(98));
}
// server_tag at 99.
// Subnet ready. Add it to the list.
auto ret = subnets.insert(last_subnet);
// subnets is a multi index container with unique indexes
// but these indexes are unique too in the database,
// so this is for sanity only.
if (!ret.second) {
isc_throw(Unexpected, "add subnet failed");
}
}
// Check for new server tags at 99.
if (!worker.isColumnNull(99)) {
std::string new_tag = worker.getString(99);
if (last_tag != new_tag) {
if (!new_tag.empty() && !last_subnet->hasServerTag(ServerTag(new_tag))) {
last_subnet->setServerTag(new_tag);
}
last_tag = new_tag;
}
}
// Pool is between 15 and 19 with extra between 79 and 81
// If the row contains information about the pool and it
// appears to be new pool entry (checked by comparing pool
// id), let's create the new pool and add it to the
// subnet.
// pool id (15)
// pool start_address (16)
// pool end_address (17)
if (!worker.isColumnNull(15) &&
(worker.getInet6(16) != 0) &&
(worker.getInet6(17) != 0) &&
(worker.getBigInt(15) > last_pool_id)) {
last_pool_id = worker.getBigInt(15);
last_pool = Pool6::create(Lease::TYPE_NA,
IOAddress(worker.getInet6(16)),
IOAddress(worker.getInet6(17)));
// pool subnet_id at 18 (ignored)
// pool modification_ts at 19 (ignored)
// pool client_class at 79.
if (!worker.isColumnNull(79)) {
last_pool->allowClientClass(worker.getString(79));
}
// pool evaluate_additional_classes at 80.
clientClassesFromColumn(worker, 80, "evaluate_additional_classes",
last_pool->getMutableAdditionalClasses());
// pool user_context at 81.
if (!worker.isColumnNull(81)) {
ElementPtr user_context = worker.getJSON(81);
if (user_context) {
last_pool->setContext(user_context);
}
}
last_subnet->addPool(last_pool);
}
// Pd Pool is between 20 and 25 with extra between 82 and 86
// If the row contains information about the pd pool and
// it appears to be new pd pool entry (checked by
// comparing pd pool id), let's create the new pd pool and
// add it to the subnet.
// pd pool id (20)
// pd pool prefix (21)
// pd pool prefix_length (22)
// pd pool delegated_prefix_length (23)
if (!worker.isColumnNull(20) &&
(!worker.getString(21).empty()) &&
(worker.getSmallInt(22) != 0) &&
(worker.getSmallInt(23) != 0) &&
(worker.getBigInt(20) > last_pd_pool_id)) {
// 24 is pd pool subnet_id (ignored)
// 25 is pd pool modification_ts (ignored)
// excluded_prefix (82) and excluded_prefix_length (83)
IOAddress excluded_prefix = IOAddress::IPV6_ZERO_ADDRESS();
if (!worker.isColumnNull(82)) {
excluded_prefix = worker.getInet6(82);
}
last_pd_pool_id = worker.getBigInt(20);
last_pd_pool = Pool6::create(worker.getInet6(21),
static_cast<uint8_t>(worker.getSmallInt(22)),
static_cast<uint8_t>(worker.getSmallInt(23)),
excluded_prefix,
static_cast<uint8_t>(worker.getSmallInt(83)));
// pd pool client_class (84)
if (!worker.isColumnNull(84)) {
last_pd_pool->allowClientClass(worker.getString(84));
}
// pd pool evaluate_additional_classes at 85.
clientClassesFromColumn(worker, 85, "evaluate_additional_classes",
last_pd_pool->getMutableAdditionalClasses());
// pd pool user_context at 86.
if (!worker.isColumnNull(86)) {
ElementPtr user_context = worker.getJSON(86);
if (user_context) {
last_pd_pool->setContext(user_context);
}
}
last_subnet->addPool(last_pd_pool);
}
// Parse pool-specific option from 26 to 40.
if (last_pool && !worker.isColumnNull(26) &&
(last_pool_option_id < worker.getBigInt(26))) {
last_pool_option_id = worker.getBigInt(26);
OptionDescriptorPtr desc = processOptionRow(Option::V6, worker, 26);
if (desc) {
last_pool->getCfgOption()->add(*desc, desc->space_name_);
}
}
// Parse pd pool-specific option from 41 to 55.
if (last_pd_pool && !worker.isColumnNull(41) &&
(last_pd_pool_option_id < worker.getBigInt(41))) {
last_pd_pool_option_id = worker.getBigInt(41);
OptionDescriptorPtr desc = processOptionRow(Option::V6, worker, 41);
if (desc) {
last_pd_pool->getCfgOption()->add(*desc, desc->space_name_);
}
}
// Parse subnet-specific option from 56 to 70.
if (!worker.isColumnNull(56) &&
(last_option_id < worker.getBigInt(56))) {
last_option_id = worker.getBigInt(56);
OptionDescriptorPtr desc = processOptionRow(Option::V6, worker, 56);
if (desc) {
last_subnet->getCfgOption()->add(*desc, desc->space_name_);
}
}
});
// Now that we're done fetching the whole subnet, we have to
// check if it has matching server tags and toss it if it
// doesn't. We skip matching the server tags if we're asking
// for ANY subnet.
auto& subnet_index = subnets.get<SubnetSubnetIdIndexTag>();
tossNonMatchingElements(server_selector, subnet_index);
}
/// @brief Sends query to retrieve single subnet by id.
///
/// @param server_selector Server selector.
/// @param subnet_id Subnet identifier.
///
/// @return Pointer to the returned subnet or NULL if such subnet
/// doesn't exist.
Subnet6Ptr getSubnet6(const ServerSelector& server_selector,
const SubnetID& subnet_id) {
if (server_selector.hasMultipleTags()) {
isc_throw(InvalidOperation, "expected one server tag to be specified"
" while fetching a subnet. Got: "
<< getServerTagsAsText(server_selector));
}
PsqlBindArray in_bindings;
in_bindings.add(subnet_id);
auto index = GET_SUBNET6_ID_NO_TAG;
if (server_selector.amUnassigned()) {
index = GET_SUBNET6_ID_UNASSIGNED;
} else if (server_selector.amAny()) {
index = GET_SUBNET6_ID_ANY;
}
Subnet6Collection subnets;
getSubnets6(index, server_selector, in_bindings, subnets);
return (subnets.empty() ? Subnet6Ptr() : *subnets.begin());
}
/// @brief Sends query to retrieve single subnet by prefix.
///
/// The prefix should be in the following format: "2001:db8:1::/64".
///
/// @param server_selector Server selector.
/// @param subnet_id Subnet identifier.
///
/// @return Pointer to the returned subnet or NULL if such subnet
/// doesn't exist.
Subnet6Ptr getSubnet6(const ServerSelector& server_selector,
const std::string& subnet_prefix) {
if (server_selector.hasMultipleTags()) {
isc_throw(InvalidOperation, "expected one server tag to be specified"
" while fetching a subnet. Got: "
<< getServerTagsAsText(server_selector));
}
PsqlBindArray in_bindings;
in_bindings.add(subnet_prefix);
auto index = GET_SUBNET6_PREFIX_NO_TAG;
if (server_selector.amUnassigned()) {
index = GET_SUBNET6_PREFIX_UNASSIGNED;
} else if (server_selector.amAny()) {
index = GET_SUBNET6_PREFIX_ANY;
}
Subnet6Collection subnets;
getSubnets6(index, server_selector, in_bindings, subnets);
return (subnets.empty() ? Subnet6Ptr() : *subnets.begin());
}
/// @brief Sends query to retrieve all subnets.
///
/// @param server_selector Server selector.
/// @param [out] subnets Reference to the subnet collection structure where
/// subnets should be inserted.
void getAllSubnets6(const ServerSelector& server_selector,
Subnet6Collection& subnets) {
if (server_selector.amAny()) {
isc_throw(InvalidOperation, "fetching all subnets for ANY "
"server is not supported");
}
auto index = (server_selector.amUnassigned() ? GET_ALL_SUBNETS6_UNASSIGNED :
GET_ALL_SUBNETS6);
PsqlBindArray in_bindings;
getSubnets6(index, server_selector, in_bindings, subnets);
}
/// @brief Sends query to retrieve modified subnets.
///
/// @param server_selector Server selector.
/// @param modification_ts Lower bound modification timestamp.
/// @param [out] subnets Reference to the subnet collection structure where
/// subnets should be inserted.
void getModifiedSubnets6(const ServerSelector& server_selector,
const boost::posix_time::ptime& modification_ts,
Subnet6Collection& subnets) {
if (server_selector.amAny()) {
isc_throw(InvalidOperation, "fetching modified subnets for ANY "
"server is not supported");
}
PsqlBindArray in_bindings;
in_bindings.addTimestamp(modification_ts);
auto index = (server_selector.amUnassigned() ? GET_MODIFIED_SUBNETS6_UNASSIGNED :
GET_MODIFIED_SUBNETS6);
getSubnets6(index, server_selector, in_bindings, subnets);
}
/// @brief Sends query to retrieve all subnets belonging to a shared network.
///
/// @param server_selector Server selector.
/// @param shared_network_name Name of the shared network for which the
/// subnets should be retrieved.
/// @param [out] subnets Reference to the subnet collection structure where
/// subnets should be inserted.
void getSharedNetworkSubnets6(const ServerSelector& server_selector,
const std::string& shared_network_name,
Subnet6Collection& subnets) {
PsqlBindArray in_bindings;
in_bindings.add(shared_network_name);
getSubnets6(GET_SHARED_NETWORK_SUBNETS6, server_selector, in_bindings, subnets);
}
/// @brief Sends query to retrieve multiple pools.
///
/// Query should order pools by id.
///
/// @param index Index of the query to be used.
/// @param in_bindings Input bindings specifying selection criteria. The
/// size of the bindings collection must match the number of placeholders
/// in the prepared statement. The input bindings collection must be empty
/// if the query contains no WHERE clause.
/// @param [out] pools Reference to the container where fetched pools
/// will be inserted.
/// @param [out] pool_ids Identifiers of the pools returned in @c pools
/// argument.
void getPools(const StatementIndex& index,
const PsqlBindArray& in_bindings,
PoolCollection& pools,
std::vector<uint64_t>& pool_ids) {
uint64_t last_pool_id = 0;
uint64_t last_pool_option_id = 0;
Pool6Ptr last_pool;
selectQuery(index, in_bindings,
[this, &last_pool_id, &last_pool_option_id, &last_pool, &pools, &pool_ids]
(PgSqlResult& r, int row) {
// Create a convenience worker for the row.
PgSqlResultRowWorker worker(r, row);
// Pool id is column 0.
auto id = worker.getBigInt(0) ;
if (id > last_pool_id) {
// pool start_address (1)
// pool end_address (2)
last_pool_id = id;
last_pool = Pool6::create(Lease::TYPE_NA, worker.getInet6(1), worker.getInet6(2));
// pool subnet_id (3) (ignored)
// pool client_class (4)
if (!worker.isColumnNull(4)) {
last_pool->allowClientClass(worker.getString(4));
}
// pool evaluate_additional_classes (5)
clientClassesFromColumn(worker, 5, "evaluate_additional_classes",
last_pool->getMutableAdditionalClasses());
// pool user_context (6)
if (!worker.isColumnNull(6)) {
ElementPtr user_context = worker.getJSON(6);
if (user_context) {
last_pool->setContext(user_context);
}
}
// pool: modification_ts (7) (ignored)
pools.push_back(last_pool);
pool_ids.push_back(last_pool_id);
}
// Parse pool specific option (8).
if (last_pool && !worker.isColumnNull(8) &&
(last_pool_option_id < worker.getBigInt(8))) {
last_pool_option_id = worker.getBigInt(8);
OptionDescriptorPtr desc = processOptionRow(Option::V6, worker, 8);
if (desc) {
last_pool->getCfgOption()->add(*desc, desc->space_name_);
}
}
});
}
/// @brief Sends query to retrieve multiple pd pools.
///
/// Query should order pd pools by id.
///
/// @param index Index of the query to be used.
/// @param in_bindings Input bindings specifying selection criteria. The
/// size of the bindings collection must match the number of placeholders
/// in the prepared statement. The input bindings collection must be empty
/// if the query contains no WHERE clause.
/// @param [out] pd_pools Reference to the container where fetched pools
/// will be inserted.
/// @param [out] pd_pool_ids Identifiers of the pd pools returned in
/// @c pd_pools argument.
void getPdPools(const StatementIndex& index,
const PsqlBindArray& in_bindings,
PoolCollection& pd_pools,
std::vector<uint64_t>& pd_pool_ids) {
uint64_t last_pd_pool_id = 0;
uint64_t last_pd_pool_option_id = 0;
Pool6Ptr last_pd_pool;
selectQuery(index, in_bindings,
[this, &last_pd_pool_id, &last_pd_pool_option_id,
&last_pd_pool, &pd_pools, &pd_pool_ids]
(PgSqlResult& r, int row) {
// Create a convenience worker for the row.
PgSqlResultRowWorker worker(r, row);
// Pool id is column 0.
auto id = worker.getBigInt(0) ;
if (id > last_pd_pool_id) {
last_pd_pool_id = id;
// pd pool prefix (1)
// pd pool prefix_length (2)
// pd pool delegated_prefix_length (3)
// excluded_prefix (5) and excluded_prefix_length (6)
IOAddress excluded_prefix = IOAddress::IPV6_ZERO_ADDRESS();
if (!worker.isColumnNull(5)) {
excluded_prefix = worker.getInet6(5);
}
last_pd_pool = Pool6::create(worker.getInet6(1),
static_cast<uint8_t>(worker.getSmallInt(2)),
static_cast<uint8_t>(worker.getSmallInt(3)),
excluded_prefix,
static_cast<uint8_t>(worker.getSmallInt(6)));
// pd pool subnet_id (4) (ignored)
// pool client_class (7)
if (!worker.isColumnNull(7)) {
last_pd_pool->allowClientClass(worker.getString(7));
}
// pool evaluate_additional_classes (8)
clientClassesFromColumn(worker, 8, "evaluate_additional_classes",
last_pd_pool->getMutableAdditionalClasses());
// pd pool user_context (9)
if (!worker.isColumnNull(9)) {
ElementPtr user_context = worker.getJSON(9);
if (user_context) {
last_pd_pool->setContext(user_context);
}
}
// pd pool modification_ts (10) (ignored)
pd_pools.push_back(last_pd_pool);
pd_pool_ids.push_back(last_pd_pool_id);
}
// Parse pd pool specific option between 11 and 25.
if (last_pd_pool && !worker.isColumnNull(11) &&
(last_pd_pool_option_id < worker.getBigInt(11))) {
last_pd_pool_option_id = worker.getBigInt(11);
OptionDescriptorPtr desc = processOptionRow(Option::V6, worker, 11);
if (desc) {
last_pd_pool->getCfgOption()->add(*desc, desc->space_name_);
}
}
});
}
/// @brief Sends query to retrieve single pool by address range.
///
/// @param server_selector Server selector.
/// @param pool_start_address Lower bound pool address.
/// @param pool_end_address Upper bound pool address.
/// @param pool_id Pool identifier for the returned pool.
/// @return Pointer to the pool or null if no such pool found.
Pool6Ptr getPool6(const ServerSelector& server_selector,
const IOAddress& pool_start_address,
const IOAddress& pool_end_address,
uint64_t& pool_id) {
PoolCollection pools;
std::vector<uint64_t> pool_ids;
if (server_selector.amAny()) {
PsqlBindArray in_bindings;
in_bindings.addInet6(pool_start_address);
in_bindings.addInet6(pool_end_address);
getPools(GET_POOL6_RANGE_ANY, in_bindings, pools, pool_ids);
} else {
auto const& tags = server_selector.getTags();
for (auto const& tag : tags) {
PsqlBindArray in_bindings;
in_bindings.addTempString(tag.get());
in_bindings.addInet6(pool_start_address);
in_bindings.addInet6(pool_end_address);
getPools(GET_POOL6_RANGE, in_bindings, pools, pool_ids);
// Break if something is found?
}
}
// Return upon the first pool found.
if (!pools.empty()) {
pool_id = pool_ids[0];
return (boost::dynamic_pointer_cast<Pool6>(*pools.begin()));
}
pool_id = 0;
return (Pool6Ptr());
}
/// @brief Sends query to retrieve single pd pool.
///
/// @param server_selector Server selector.
/// @param pd_pool_prefix Address part of the pd pool prefix.
/// @param pd_pool_prefix_length Length of the pd pool prefix.
/// @param pd_pool_id Pool identifier for the returned pool.
/// @return Pointer to the pool or null if no such pool found.
Pool6Ptr getPdPool6(const ServerSelector& server_selector,
const asiolink::IOAddress& pd_pool_prefix,
const uint8_t pd_pool_prefix_length,
uint64_t& pd_pool_id) {
PoolCollection pd_pools;
std::vector<uint64_t> pd_pool_ids;
if (server_selector.amAny()) {
PsqlBindArray in_bindings;
in_bindings.addTempString(pd_pool_prefix.toText());
in_bindings.add(pd_pool_prefix_length);
getPdPools(GET_PD_POOL_ANY, in_bindings, pd_pools, pd_pool_ids);
} else {
auto const& tags = server_selector.getTags();
for (auto const& tag : tags) {
PsqlBindArray in_bindings;
in_bindings.addTempString(tag.get());
in_bindings.addTempString(pd_pool_prefix.toText());
in_bindings.add(pd_pool_prefix_length);
getPdPools(GET_PD_POOL, in_bindings, pd_pools, pd_pool_ids);
}
}
if (!pd_pools.empty()) {
pd_pool_id = pd_pool_ids[0];
return (boost::dynamic_pointer_cast<Pool6>(*pd_pools.begin()));
}
pd_pool_id = 0;
return (Pool6Ptr());
}
/// @brief Sends query to insert or update subnet.
///
/// @param server_selector Server selector.
/// @param subnet Pointer to the subnet to be inserted or updated.
void createUpdateSubnet6(const ServerSelector& server_selector,
const Subnet6Ptr& subnet) {
if (server_selector.amAny()) {
isc_throw(InvalidOperation, "creating or updating a subnet for ANY"
" server is not supported");
} else if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
" (unassigned) is unsupported at the moment");
}
// Create input bindings.
PsqlBindArray in_bindings;
in_bindings.add(subnet->getID());
in_bindings.addTempString(subnet->toText());
in_bindings.addOptional(subnet->getClientClass(Network::Inheritance::NONE));
in_bindings.addOptional(subnet->getIface(Network::Inheritance::NONE));
in_bindings.addTimestamp(subnet->getModificationTime());
in_bindings.add(subnet->getPreferred(Network::Inheritance::NONE));
in_bindings.addMin(subnet->getPreferred(Network::Inheritance::NONE));
in_bindings.addMax(subnet->getPreferred(Network::Inheritance::NONE));
in_bindings.addOptional(subnet->getRapidCommit(Network::Inheritance::NONE));
in_bindings.add(subnet->getT2(Network::Inheritance::NONE));
addRelayBinding(in_bindings, subnet);
in_bindings.add(subnet->getT1(Network::Inheritance::NONE));
addAdditionalClassesBinding(in_bindings, subnet);
in_bindings.addOptional(subnet->getReservationsGlobal(Network::Inheritance::NONE));
// Add shared network.
SharedNetwork6Ptr shared_network;
subnet->getSharedNetwork(shared_network);
// Check if the subnet is associated with a shared network instance.
// If it is, create the binding using the name of the shared network.
if (shared_network) {
in_bindings.addTempString(shared_network->getName());
// If the subnet is associated with a shared network by name (no
// shared network instance), use this name to create the binding.
// This may be the case if the subnet is added as a result of
// receiving a control command that merely specifies shared
// network name. In that case, it is expected that the shared
// network data is already stored in the database.
} else if (!subnet->getSharedNetworkName().empty()) {
in_bindings.addTempString(subnet->getSharedNetworkName());
// If the subnet is not associated with a shared network, create
// null binding.
} else {
in_bindings.addNull();
}
in_bindings.add(subnet->getContext());
in_bindings.add(subnet->getValid(Network::Inheritance::NONE));
in_bindings.addMin(subnet->getValid(Network::Inheritance::NONE));
in_bindings.addMax(subnet->getValid(Network::Inheritance::NONE));
in_bindings.addOptional(subnet->getCalculateTeeTimes(Network::Inheritance::NONE));
in_bindings.addOptional(subnet->getT1Percent(Network::Inheritance::NONE));
in_bindings.addOptional(subnet->getT2Percent(Network::Inheritance::NONE));
addInterfaceIdBinding(in_bindings, *subnet);
in_bindings.addOptional(subnet->getDdnsSendUpdates(Network::Inheritance::NONE));
in_bindings.addOptional(subnet->getDdnsOverrideNoUpdate(Network::Inheritance::NONE));
in_bindings.addOptional(subnet->getDdnsOverrideClientUpdate(Network::Inheritance::NONE));
addDdnsReplaceClientNameBinding(in_bindings, subnet);
in_bindings.addOptional(subnet->getDdnsGeneratedPrefix(Network::Inheritance::NONE));
in_bindings.addOptional(subnet->getDdnsQualifyingSuffix(Network::Inheritance::NONE));
in_bindings.addOptional(subnet->getReservationsInSubnet(Network::Inheritance::NONE));
in_bindings.addOptional(subnet->getReservationsOutOfPool(Network::Inheritance::NONE));
in_bindings.addOptional(subnet->getCacheThreshold(Network::Inheritance::NONE));
in_bindings.addOptional(subnet->getCacheMaxAge(Network::Inheritance::NONE));
in_bindings.addOptional(subnet->getAllocatorType(Network::Inheritance::NONE));
in_bindings.addOptional(subnet->getPdAllocatorType(Network::Inheritance::NONE));
// Start transaction.
PgSqlTransaction transaction(conn_);
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision audit_revision(this,
PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
server_selector, "subnet set", true);
// Create a savepoint in case we are called as part of larger
// transaction.
conn_.createSavepoint("createUpdateSubnet6");
try {
insertQuery(PgSqlConfigBackendDHCPv6Impl::INSERT_SUBNET6, in_bindings);
} catch (const DuplicateEntry&) {
// It already exists, rollback to the savepoint to preserve
// any prior work.
conn_.rollbackToSavepoint("createUpdateSubnet6");
// We're updating, so we need to remove any existing pools and options.
deletePools6(subnet);
deletePdPools6(subnet);
deleteOptions6(ServerSelector::ANY(), subnet);
// Now we need to add two more bindings for WHERE clause.
in_bindings.add(subnet->getID());
in_bindings.addTempString(subnet->toText());
// Attempt the update.
auto cnt = updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::UPDATE_SUBNET6,
in_bindings);
if (!cnt) {
// Possible only if someone deleted it since we tried to insert it
// or the query is broken.
isc_throw(Unexpected, "Update subnet failed to find subnet id: "
<< subnet->getID() << ", prefix: " << subnet->toText());
}
// Remove existing server association.
PsqlBindArray server_bindings;
server_bindings.add(subnet->getID());
updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::DELETE_SUBNET6_SERVER,
server_bindings);
}
// Subnet was successfully created/updated.
// Insert associations with the servers.
PsqlBindArray attach_bindings;
attach_bindings.add(subnet->getID());
attach_bindings.addTimestamp(subnet->getModificationTime());
attachElementToServers(PgSqlConfigBackendDHCPv6Impl::INSERT_SUBNET6_SERVER,
server_selector, attach_bindings);
// (Re)create pools.
for (auto const& pool : subnet->getPools(Lease::TYPE_NA)) {
createPool6(server_selector, boost::dynamic_pointer_cast<Pool6>(pool),
subnet);
}
// (Re)create pd pools.
for (auto const& pd_pool : subnet->getPools(Lease::TYPE_PD)) {
createPdPool6(server_selector, boost::dynamic_pointer_cast<Pool6>(pd_pool),
subnet);
}
// (Re)create options.
auto option_spaces = subnet->getCfgOption()->getOptionSpaceNames();
for (auto const& option_space : option_spaces) {
OptionContainerPtr options = subnet->getCfgOption()->getAll(option_space);
for (auto const& desc : *options) {
OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc);
desc_copy->space_name_ = option_space;
createUpdateOption6(server_selector, subnet->getID(), desc_copy,
true);
}
}
// Commit the work.
transaction.commit();
}
/// @brief Inserts new IPv6 pool to the database.
///
/// @param server_selector Server selector.
/// @param pool Pointer to the pool to be inserted.
/// @param subnet Pointer to the subnet that this pool belongs to.
void createPool6(const ServerSelector& server_selector,
const Pool6Ptr& pool,
const Subnet6Ptr& subnet) {
// Create the input bindings.
PsqlBindArray in_bindings;
in_bindings.addInet6(pool->getFirstAddress());
in_bindings.addInet6(pool->getLastAddress());
in_bindings.add(subnet->getID());
in_bindings.addOptional(pool->getClientClass());
addAdditionalClassesBinding(in_bindings, pool);
in_bindings.add(pool->getContext());
in_bindings.addTimestamp(subnet->getModificationTime());
// Attempt to INSERT the pool.
insertQuery(PgSqlConfigBackendDHCPv6Impl::INSERT_POOL6, in_bindings);
// Get the id of the newly inserted pool.
uint64_t pool_id = getLastInsertId("dhcp6_pool", "id");
// Add the pool's options.
auto option_spaces = pool->getCfgOption()->getOptionSpaceNames();
for (auto const& option_space : option_spaces) {
OptionContainerPtr options = pool->getCfgOption()->getAll(option_space);
for (auto const& desc : *options) {
OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc);
desc_copy->space_name_ = option_space;
createUpdateOption6(server_selector, Lease::TYPE_NA,
pool_id, desc_copy, true);
}
}
}
/// @brief Inserts new IPv6 pd pool to the database.
///
/// @param server_selector Server selector.
/// @param pd_pool Pointer to the pd pool to be inserted.
/// @param subnet Pointer to the subnet that this pd pool belongs to.
void createPdPool6(const ServerSelector& server_selector,
const Pool6Ptr& pd_pool,
const Subnet6Ptr& subnet) {
int plen = prefixLengthFromRange(pd_pool->getFirstAddress(),
pd_pool->getLastAddress());
// Extract excluded prefix components.
Optional<std::string> xprefix_txt;
uint8_t xlen = 0;
const Option6PDExcludePtr& xopt = pd_pool->getPrefixExcludeOption();
if (xopt) {
const IOAddress& prefix = pd_pool->getFirstAddress();
const IOAddress& xprefix = xopt->getExcludedPrefix(prefix, pd_pool->getLength());
xprefix_txt = xprefix.toText();
xlen = xopt->getExcludedPrefixLength();
}
// Create the input bindings.
PsqlBindArray in_bindings;
in_bindings.addInet6(pd_pool->getFirstAddress());
in_bindings.add(plen);
in_bindings.add(pd_pool->getLength());
in_bindings.add(subnet->getID());
in_bindings.addOptional(xprefix_txt);
in_bindings.add(xlen);
in_bindings.addOptional(pd_pool->getClientClass());
addAdditionalClassesBinding(in_bindings, pd_pool);
in_bindings.add(pd_pool->getContext());
in_bindings.addTimestamp(subnet->getModificationTime());
// Attempt to INSERT the pool.
insertQuery(PgSqlConfigBackendDHCPv6Impl::INSERT_PD_POOL, in_bindings);
// Get the id of the newly inserted pool.
uint64_t pd_pool_id = getLastInsertId("dhcp6_pd_pool", "id");
// Add the pool's options.
auto option_spaces = pd_pool->getCfgOption()->getOptionSpaceNames();
for (auto const& option_space : option_spaces) {
OptionContainerPtr options = pd_pool->getCfgOption()->getAll(option_space);
for (auto const& desc : *options) {
OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc);
desc_copy->space_name_ = option_space;
createUpdateOption6(server_selector, Lease::TYPE_PD,
pd_pool_id, desc_copy, true);
}
}
}
/// @brief Sends a query to delete data from a table.
///
/// If creates a new audit revision for this change if such audit
/// revision doesn't exist yet (using ScopedAuditRevision mechanism).
///
/// @tparam Args type of the arguments to be passed to one of the existing
/// @c deleteFromTable methods.
/// @param server_selector server selector.
/// @param operation operation which results in calling this function. This is
/// used for logging purposes.
/// @param log_message log message to be associated with the audit revision.
/// @param cascade_delete boolean flag indicating if we're performing
/// cascade delete. If set to true, the audit entries for the child
/// objects (e.g. DHCPoptions) won't be created.
/// @param keys arguments to be passed to one of the existing
/// @c deleteFromTable methods.
///
/// @return Number of deleted entries.
template<typename... Args>
uint64_t deleteTransactional(const int index,
const db::ServerSelector& server_selector,
const std::string& operation,
const std::string& log_message,
const bool cascade_delete,
Args&&... keys) {
PgSqlTransaction transaction(conn_);
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision
audit_revision(this,
PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
server_selector, log_message, cascade_delete);
auto count = deleteFromTable(index, server_selector, operation, keys...);
transaction.commit();
return (count);
}
/// @brief Sends query to delete subnet by id.
///
/// @param server_selector Server selector.
/// @param subnet_id Identifier of the subnet to be deleted.
/// @return Number of deleted subnets.
uint64_t deleteSubnet6(const ServerSelector& server_selector,
const SubnetID& subnet_id) {
int index = (server_selector.amAny() ?
PgSqlConfigBackendDHCPv6Impl::DELETE_SUBNET6_ID_ANY :
PgSqlConfigBackendDHCPv6Impl::DELETE_SUBNET6_ID_WITH_TAG);
return (deleteTransactional(index, server_selector,
"deleting a subnet", "subnet deleted",
true, static_cast<uint32_t>(subnet_id)));
}
/// @brief Sends query to delete subnet by id.
///
/// @param server_selector Server selector.
/// @param subnet_prefix Prefix of the subnet to be deleted.
/// @return Number of deleted subnets.
uint64_t deleteSubnet6(const ServerSelector& server_selector,
const std::string& subnet_prefix) {
int index = (server_selector.amAny() ?
PgSqlConfigBackendDHCPv6Impl::DELETE_SUBNET6_PREFIX_ANY :
PgSqlConfigBackendDHCPv6Impl::DELETE_SUBNET6_PREFIX_WITH_TAG);
return (deleteTransactional(index, server_selector,
"deleting a subnet", "subnet deleted",
true, subnet_prefix));
}
/// @brief Deletes pools belonging to a subnet from the database.
///
/// The query deletes all pools associated with the subnet's
/// identifier or prefix.
/// @param subnet Pointer to the subnet for which pools should be
/// deleted.
uint64_t deletePools6(const Subnet6Ptr& subnet) {
PsqlBindArray in_bindings;
in_bindings.add(subnet->getID());
in_bindings.addTempString(subnet->toText());
// Run DELETE.
return (updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::DELETE_POOLS6,
in_bindings));
}
/// @brief Deletes prefix delegation pools belonging to a subnet from
/// the database.
///
/// The query deletes all pd pools associated with the subnet's
/// identifier or prefix.
/// @param subnet Pointer to the subnet for which pd pools should be
/// deleted.
uint64_t deletePdPools6(const Subnet6Ptr& subnet) {
PsqlBindArray in_bindings;
in_bindings.add(subnet->getID());
in_bindings.addTempString(subnet->toText());
// Run DELETE.
return (updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::DELETE_PD_POOLS,
in_bindings));
}
/// @brief Sends query to the database to retrieve multiple shared
/// networks.
///
/// Query should order shared networks by id.
///
/// @param index Index of the query to be used.
/// @param server_selector Server selector.
/// @param in_bindings Input bindings specifying selection criteria. The
/// size of the bindings collection must match the number of placeholders
/// in the prepared statement. The input bindings collection must be empty
/// if the query contains no WHERE clause.
/// @param [out] shared_networks Reference to the container where fetched
/// shared networks will be inserted.
void getSharedNetworks6(const StatementIndex& index,
const ServerSelector& server_selector,
const PsqlBindArray& in_bindings,
SharedNetwork6Collection& shared_networks) {
uint64_t last_network_id = 0;
uint64_t last_option_id = 0;
std::string last_tag;
selectQuery(index, in_bindings,
[this, &shared_networks, &last_network_id, &last_option_id, &last_tag]
(PgSqlResult& r, int row) {
// Create a convenience worker for the row.
PgSqlResultRowWorker worker(r, row);
SharedNetwork6Ptr last_network;
if (!shared_networks.empty()) {
last_network = *shared_networks.rbegin();
}
// Network id is column 0.
auto network_id = worker.getBigInt(0) ;
// If this is the first shared network or the shared network id in this
// row points to the next shared network we use the data in the
// row to create the new shared network instance.
if (last_network_id != network_id) {
last_network_id = network_id;
// Reset per shared network component tracking and server tag because
// we're now starting to process a new shared network.
last_option_id = 0;
last_tag.clear();
// name at 1.
last_network = SharedNetwork6::create(worker.getString(1));
last_network->setId(last_network_id);
// client_class at 2.
if (!worker.isColumnNull(2)) {
last_network->allowClientClass(worker.getString(2));
}
// interface at 3.
if (!worker.isColumnNull(3)) {
last_network->setIface(worker.getString(3));
}
// modification_ts at 4.
last_network->setModificationTime(worker.getTimestamp(4));
// preferred_lifetime (5)
// min_preferred_lifetime (33)
// max_preferred_lifetime (34)
last_network->setPreferred(worker.getTriplet(5, 33, 34));
// rapid_commit at 6.
if (!worker.isColumnNull(6)) {
last_network->setRapidCommit(worker.getBool(6));
}
// rebind_timer at 7.
if (!worker.isColumnNull(7)) {
last_network->setT2(worker.getTriplet(7));
}
// Relay addresses at 8.
setRelays(worker, 8, *last_network);
// renew_timer at 9.
if (!worker.isColumnNull(9)) {
last_network->setT1(worker.getTriplet(9));
}
// evaluate_additional_classes at 10.
clientClassesFromColumn(worker, 10, "evaluate_additional_classes",
last_network->getMutableAdditionalClasses());
// reservations_global at 11.
if (!worker.isColumnNull(11)) {
last_network->setReservationsGlobal(worker.getBool(11));
}
// user_context at 12.
if (!worker.isColumnNull(12)) {
ElementPtr user_context = worker.getJSON(12);
if (user_context) {
last_network->setContext(user_context);
}
}
// valid_lifetime at 13.
// min_valid_lifetime at 35.
// max_valid_lifetime at 36.
if (!worker.isColumnNull(13)) {
last_network->setValid(worker.getTriplet(13, 35, 36));
}
// option from 14 to 28.
// calculate_tee_times at 29.
if (!worker.isColumnNull(29)) {
last_network->setCalculateTeeTimes(worker.getBool(29));
}
// t1_percent at 30.
if (!worker.isColumnNull(30)) {
last_network->setT1Percent(worker.getDouble(30));
}
// t2_percent at 31.
if (!worker.isColumnNull(31)) {
last_network->setT2Percent(worker.getDouble(31));
}
// interface_id at 32.
setInterfaceId(*last_network, worker, 32);
// min_preferred_lifetime at 33.
// max_preferred_lifetime at 34.
// min_valid_lifetime at 35.
// max_valid_lifetime at 36.
// ddns_send_updates at 37.
if (!worker.isColumnNull(37)) {
last_network->setDdnsSendUpdates(worker.getBool(37));
}
// ddns_override_no_update at 38.
if (!worker.isColumnNull(38)) {
last_network->setDdnsOverrideNoUpdate(worker.getBool(38));
}
// ddns_override_client_update at 39.
if (!worker.isColumnNull(39)) {
last_network->setDdnsOverrideClientUpdate(worker.getBool(39));
}
// ddns_replace_client_name at 40.
if (!worker.isColumnNull(40)) {
last_network->setDdnsReplaceClientNameMode(
static_cast<D2ClientConfig::ReplaceClientNameMode>(worker.getSmallInt(40)));
}
// ddns_generated_prefix at 41.
if (!worker.isColumnNull(41)) {
last_network->setDdnsGeneratedPrefix(worker.getString(41));
}
// ddns_qualifying_suffix at 42.
if (!worker.isColumnNull(42)) {
last_network->setDdnsQualifyingSuffix(worker.getString(42));
}
// reservations_in_subnet at 43.
if (!worker.isColumnNull(43)) {
last_network->setReservationsInSubnet(worker.getBool(43));
}
// reservations_in_subnet at 44.
if (!worker.isColumnNull(44)) {
last_network->setReservationsOutOfPool(worker.getBool(44));
}
// cache_threshold at 45.
if (!worker.isColumnNull(45)) {
last_network->setCacheThreshold(worker.getDouble(45));
}
// cache_max_age at 46.
if (!worker.isColumnNull(46)) {
last_network->setCacheMaxAge(worker.getInt(46));
}
// allocator at 47.
if (!worker.isColumnNull(47)) {
last_network->setAllocatorType(worker.getString(47));
}
// pd_allocator at 48.
if (!worker.isColumnNull(48)) {
last_network->setPdAllocatorType(worker.getString(48));
}
// server_tag at 49.
// Add the shared network.
auto ret = shared_networks.push_back(last_network);
// shared_networks is a multi index container with an unique
// index but this index is unique too in the database,
// so this is for sanity only.
if (!ret.second) {
isc_throw(Unexpected, "add shared network failed");
}
}
// Check for new server tags.
if (!worker.isColumnNull(49)) {
std::string new_tag = worker.getString(49);
if (last_tag != new_tag) {
if (!new_tag.empty() && !last_network->hasServerTag(ServerTag(new_tag))) {
last_network->setServerTag(new_tag);
}
last_tag = new_tag;
}
}
// Parse network-specific option from 14 to 28.
if (!worker.isColumnNull(14) &&
(last_option_id < worker.getBigInt(14))) {
last_option_id = worker.getBigInt(14);
OptionDescriptorPtr desc = processOptionRow(Option::V6, worker, 14);
if (desc) {
last_network->getCfgOption()->add(*desc, desc->space_name_);
}
}
});
// Now that we're done fetching the whole network, we have to
// check if it has matching server tags and toss it if it
// doesn't. We skip matching the server tags if we're asking
// for ANY shared network.
auto& sn_index = shared_networks.get<SharedNetworkRandomAccessIndexTag>();
tossNonMatchingElements(server_selector, sn_index);
}
/// @brief Sends query to retrieve single shared network by name.
///
/// @param server_selector Server selector.
/// @param name Shared network name.
///
/// @return Pointer to the returned shared network or NULL if such shared
/// network doesn't exist.
SharedNetwork6Ptr getSharedNetwork6(const ServerSelector& server_selector,
const std::string& name) {
if (server_selector.hasMultipleTags()) {
isc_throw(InvalidOperation, "expected one server tag to be specified"
" while fetching a shared network. Got: "
<< getServerTagsAsText(server_selector));
}
PsqlBindArray in_bindings;
in_bindings.add(name);
auto index = PgSqlConfigBackendDHCPv6Impl::GET_SHARED_NETWORK6_NAME_NO_TAG;
if (server_selector.amUnassigned()) {
index = PgSqlConfigBackendDHCPv6Impl::GET_SHARED_NETWORK6_NAME_UNASSIGNED;
} else if (server_selector.amAny()) {
index = PgSqlConfigBackendDHCPv6Impl::GET_SHARED_NETWORK6_NAME_ANY;
}
SharedNetwork6Collection shared_networks;
getSharedNetworks6(index, server_selector, in_bindings, shared_networks);
return (shared_networks.empty() ? SharedNetwork6Ptr() : *shared_networks.begin());
}
/// @brief Sends query to retrieve all shared networks.
///
/// @param server_selector Server selector.
/// @param [out] shared_networks Reference to the shared networks collection
/// structure where shared networks should be inserted.
void getAllSharedNetworks6(const ServerSelector& server_selector,
SharedNetwork6Collection& shared_networks) {
if (server_selector.amAny()) {
isc_throw(InvalidOperation, "fetching all shared networks for ANY "
"server is not supported");
}
auto index = (server_selector.amUnassigned() ?
PgSqlConfigBackendDHCPv6Impl::GET_ALL_SHARED_NETWORKS6_UNASSIGNED :
PgSqlConfigBackendDHCPv6Impl::GET_ALL_SHARED_NETWORKS6);
PsqlBindArray in_bindings;
getSharedNetworks6(index, server_selector, in_bindings, shared_networks);
}
/// @brief Sends query to retrieve modified shared networks.
///
/// @param server_selector Server selector.
/// @param modification_ts Lower bound modification timestamp.
/// @param [out] shared_networks Reference to the shared networks collection
/// structure where shared networks should be inserted.
void getModifiedSharedNetworks6(const ServerSelector& server_selector,
const boost::posix_time::ptime& modification_ts,
SharedNetwork6Collection& shared_networks) {
if (server_selector.amAny()) {
isc_throw(InvalidOperation, "fetching modified shared networks for ANY "
"server is not supported");
}
PsqlBindArray in_bindings;
in_bindings.addTimestamp(modification_ts);
auto index = (server_selector.amUnassigned() ?
PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_SHARED_NETWORKS6_UNASSIGNED :
PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_SHARED_NETWORKS6);
getSharedNetworks6(index, server_selector, in_bindings, shared_networks);
}
/// @brief Sends query to insert or update shared network.
///
/// @param server_selector Server selector.
/// @param subnet Pointer to the shared network to be inserted or updated.
void createUpdateSharedNetwork6(const ServerSelector& server_selector,
const SharedNetwork6Ptr& shared_network) {
if (server_selector.amAny()) {
isc_throw(InvalidOperation, "creating or updating a shared network for ANY"
" server is not supported");
} else if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
" (unassigned) is unsupported at the moment");
}
PsqlBindArray in_bindings;
in_bindings.addTempString(shared_network->getName());
in_bindings.addOptional(shared_network->getClientClass(Network::Inheritance::NONE));
in_bindings.addOptional(shared_network->getIface(Network::Inheritance::NONE));
in_bindings.addTimestamp(shared_network->getModificationTime());
in_bindings.add(shared_network->getPreferred(Network::Inheritance::NONE));
in_bindings.addMin(shared_network->getPreferred(Network::Inheritance::NONE));
in_bindings.addMax(shared_network->getPreferred(Network::Inheritance::NONE));
in_bindings.addOptional(shared_network->getRapidCommit(Network::Inheritance::NONE));
in_bindings.add(shared_network->getT2(Network::Inheritance::NONE));
addRelayBinding(in_bindings, shared_network);
in_bindings.add(shared_network->getT1(Network::Inheritance::NONE));
addAdditionalClassesBinding(in_bindings, shared_network);
in_bindings.addOptional(shared_network->getReservationsGlobal(Network::Inheritance::NONE));
in_bindings.add(shared_network->getContext());
in_bindings.add(shared_network->getValid(Network::Inheritance::NONE));
in_bindings.addMin(shared_network->getValid(Network::Inheritance::NONE));
in_bindings.addMax(shared_network->getValid(Network::Inheritance::NONE));
in_bindings.addOptional(shared_network->getCalculateTeeTimes(Network::Inheritance::NONE));
in_bindings.addOptional(shared_network->getT1Percent(Network::Inheritance::NONE));
in_bindings.addOptional(shared_network->getT2Percent(Network::Inheritance::NONE));
addInterfaceIdBinding(in_bindings, *shared_network);
in_bindings.addOptional(shared_network->getDdnsSendUpdates(Network::Inheritance::NONE));
in_bindings.addOptional(shared_network->getDdnsOverrideNoUpdate(Network::Inheritance::NONE));
in_bindings.addOptional(shared_network->getDdnsOverrideClientUpdate(Network::Inheritance::NONE));
addDdnsReplaceClientNameBinding(in_bindings, shared_network);
in_bindings.addOptional(shared_network->getDdnsGeneratedPrefix(Network::Inheritance::NONE));
in_bindings.addOptional(shared_network->getDdnsQualifyingSuffix(Network::Inheritance::NONE));
in_bindings.addOptional(shared_network->getReservationsInSubnet(Network::Inheritance::NONE));
in_bindings.addOptional(shared_network->getReservationsOutOfPool(Network::Inheritance::NONE));
in_bindings.addOptional(shared_network->getCacheThreshold(Network::Inheritance::NONE));
in_bindings.addOptional(shared_network->getCacheMaxAge(Network::Inheritance::NONE));
in_bindings.addOptional(shared_network->getAllocatorType(Network::Inheritance::NONE));
in_bindings.addOptional(shared_network->getPdAllocatorType(Network::Inheritance::NONE));
// Start transaction.
PgSqlTransaction transaction(conn_);
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision
audit_revision(this,
PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
server_selector, "shared network set", true);
// Create a savepoint in case we are called as part of larger
// transaction.
conn_.createSavepoint("createUpdateSharedNetwork6");
try {
// Try to insert shared network. The shared network name must be unique,
// so if inserting fails with DuplicateEntry exception we'll need to
// update existing shared network entry.
insertQuery(PgSqlConfigBackendDHCPv6Impl::INSERT_SHARED_NETWORK6,
in_bindings);
} catch (const DuplicateEntry&) {
// It already exists, rollback to the savepoint to preserve
// any prior work.
conn_.rollbackToSavepoint("createUpdateSharedNetwork6");
// We're updating, so we need to remove any options.
deleteOptions6(ServerSelector::ANY(), shared_network);
// Need to add one more binding for WHERE clause.
in_bindings.addTempString(shared_network->getName());
// Try the update.
updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::UPDATE_SHARED_NETWORK6,
in_bindings);
// Remove existing server association.
PsqlBindArray server_bindings;
server_bindings.addTempString(shared_network->getName());
updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::DELETE_SHARED_NETWORK6_SERVER,
server_bindings);
}
// Associate the shared network with the servers.
PsqlBindArray attach_bindings;
attach_bindings.addTempString(shared_network->getName());
attach_bindings.addTimestamp(shared_network->getModificationTime());
attachElementToServers(PgSqlConfigBackendDHCPv6Impl::INSERT_SHARED_NETWORK6_SERVER,
server_selector, attach_bindings);
// (Re)create options.
auto option_spaces = shared_network->getCfgOption()->getOptionSpaceNames();
for (auto const& option_space : option_spaces) {
OptionContainerPtr options = shared_network->getCfgOption()->getAll(option_space);
for (auto const& desc : *options) {
OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc);
desc_copy->space_name_ = option_space;
createUpdateOption6(server_selector, shared_network->getName(),
desc_copy, true);
}
}
// Commit the work.
transaction.commit();
}
/// @brief Sends query to insert DHCP option.
///
/// This method expects that the server selector contains exactly one
/// server tag. It is intended to be used within a transaction.
///
/// @param server_selector Server selector.
/// @param in_bindings Collection of bindings representing an option.
/// @param modification_ts option's modification timestamp
void insertOption6(const ServerSelector& server_selector,
const PsqlBindArray& in_bindings,
const boost::posix_time::ptime& modification_ts) {
// Attempt the insert.
insertQuery(PgSqlConfigBackendDHCPv6Impl::INSERT_OPTION6, in_bindings);
// Fetch primary key value of the inserted option. We will use it in the
// next INSERT statement to associate this option with the server.
auto option_id = getLastInsertId("dhcp6_options", "option_id");
PsqlBindArray attach_bindings;
attach_bindings.add(option_id); // id of newly inserted global.
attach_bindings.addTimestamp(modification_ts);
// Associate the option with the servers.
attachElementToServers(PgSqlConfigBackendDHCPv6Impl::INSERT_OPTION6_SERVER,
server_selector, attach_bindings);
}
/// @brief Sends query to insert or update global DHCP option.
///
/// @param server_selector Server selector.
/// @param option Pointer to the option descriptor encapsulating the option.
void createUpdateOption6(const ServerSelector& server_selector,
const OptionDescriptorPtr& option) {
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
" (unassigned) is unsupported at the moment");
}
auto tag = getServerTag(server_selector, "creating or updating global option");
// Create the input parameter bindings.
PsqlBindArray in_bindings;
in_bindings.add(option->option_->getType());
addOptionValueBinding(in_bindings, option);
in_bindings.addOptional(option->formatted_value_);
in_bindings.addOptional(option->space_name_);
in_bindings.add(option->persistent_);
in_bindings.add(option->cancelled_);
in_bindings.addNull();
in_bindings.addNull();
in_bindings.add(0);
in_bindings.add(option->getContext());
in_bindings.addNull();
in_bindings.addNull();
in_bindings.addTimestamp(option->getModificationTime());
addClientClassesBinding(in_bindings, option->client_classes_);
in_bindings.addNull();
// Remember the size before we add where clause arguments.
size_t pre_where_size = in_bindings.size();
// Now we add the update where clause parameters
in_bindings.add(tag);
in_bindings.add(option->option_->getType());
in_bindings.addOptional(option->space_name_);
// Start transaction.
PgSqlTransaction transaction(conn_);
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision
audit_revision(this,
PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
server_selector, "global option set", false);
// Try to update the option.
if (updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION6,
in_bindings) == 0) {
// The option doesn't exist, so we'll try to insert it.
// Remove the update where clause bindings.
while (in_bindings.size() > pre_where_size) {
in_bindings.popBack();
}
// Try to insert the option.
insertOption6(server_selector, in_bindings,
option->getModificationTime());
}
// Commit the work.
transaction.commit();
}
/// @brief Sends query to insert or update DHCP option in a subnet.
///
/// @param server_selector Server selector.
/// @param subnet_id Identifier of the subnet the option belongs to.
/// @param option Pointer to the option descriptor encapsulating the option.
/// @param cascade_update Boolean value indicating whether the update is
/// performed as part of the owning element, e.g. subnet.
void createUpdateOption6(const ServerSelector& server_selector,
const SubnetID& subnet_id,
const OptionDescriptorPtr& option,
const bool cascade_update) {
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
" (unassigned) is unsupported at the moment");
}
// Create input bindings.
PsqlBindArray in_bindings;
in_bindings.add(option->option_->getType());
addOptionValueBinding(in_bindings, option);
in_bindings.addOptional(option->formatted_value_);
in_bindings.addOptional(option->space_name_);
in_bindings.add(option->persistent_);
in_bindings.add(option->cancelled_);
in_bindings.addNull();
in_bindings.add(subnet_id);
in_bindings.add(1);
in_bindings.add(option->getContext());
in_bindings.addNull();
in_bindings.addNull();
in_bindings.addTimestamp(option->getModificationTime());
addClientClassesBinding(in_bindings, option->client_classes_);
in_bindings.addNull();
// Remember the size before we add where clause arguments.
size_t pre_where_size = in_bindings.size();
// Now we add the update where clause parameters
in_bindings.add(subnet_id);
in_bindings.add(option->option_->getType());
in_bindings.addOptional(option->space_name_);
// Start transaction.
PgSqlTransaction transaction(conn_);
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision
audit_revision(this,
PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
server_selector, "subnet specific option set",
cascade_update);
// Try to update the subnet option.
if (updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION6_SUBNET_ID,
in_bindings) == 0) {
// The option doesn't exist, so we'll try to insert it.
// Remove the update where clause bindings.
while (in_bindings.size() > pre_where_size) {
in_bindings.popBack();
}
// Try to insert the option.
insertOption6(server_selector, in_bindings,
option->getModificationTime());
}
// Commit the work.
transaction.commit();
}
/// @brief Sends query to insert or update DHCP option in a pool.
///
/// @param server_selector Server selector.
/// @param pool_start_address Lower bound address of the pool.
/// @param pool_end_address Upper bound address of the pool.
/// @param option Pointer to the option descriptor encapsulating the option.
void createUpdateOption6(const ServerSelector& server_selector,
const IOAddress& pool_start_address,
const IOAddress& pool_end_address,
const OptionDescriptorPtr& option) {
uint64_t pool_id = 0;
Pool6Ptr pool = getPool6(server_selector, pool_start_address, pool_end_address,
pool_id);
if (!pool) {
isc_throw(BadValue, "no pool found for range of "
<< pool_start_address << " : "
<< pool_end_address);
}
createUpdateOption6(server_selector, Lease::TYPE_NA,
pool_id, option, false);
}
/// @brief Sends query to insert or update DHCP option in a pd pool.
///
/// @param server_selector Server selector.
/// @param pd_pool_prefix Address part of the pd pool prefix.
/// @param pd_pool_prefix_length Length of the pd pool prefix.
/// @param option Pointer to the option descriptor encapsulating the option.
void createUpdateOption6(const ServerSelector& server_selector,
const asiolink::IOAddress& pd_pool_prefix,
const uint8_t pd_pool_prefix_length,
const OptionDescriptorPtr& option) {
uint64_t pd_pool_id = 0;
Pool6Ptr pd_pool = getPdPool6(server_selector,
pd_pool_prefix,
pd_pool_prefix_length,
pd_pool_id);
if (!pd_pool) {
isc_throw(BadValue, "no prefix delegation pool found for prefix "
<< "of " << pd_pool_prefix << "/"
<< static_cast<unsigned>(pd_pool_prefix_length));
}
createUpdateOption6(server_selector, Lease::TYPE_PD,
pd_pool_id, option, false);
}
/// @brief Sends query to insert or update DHCP option in an address
/// or prefix delegation pool.
///
/// @param selector Server selector.
/// @param pool_type Pool type (Lease::TYPE_NA or Lease::TYPE_PD).
/// @param pool_id Identifier of the address or prefix delegation pool
/// the option belongs to.
/// @param option Pointer to the option descriptor encapsulating the option.
/// @param cascade_update Boolean value indicating whether the update is
/// performed as part of the owning element, e.g. subnet.
void createUpdateOption6(const ServerSelector& server_selector,
const Lease::Type& pool_type,
const uint64_t pool_id,
const OptionDescriptorPtr& option,
const bool cascade_update) {
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
" (unassigned) is unsupported at the moment");
}
std::string msg = "creating or updating ";
if (pool_type == Lease::TYPE_PD) {
msg += "prefix delegation";
} else {
msg += "address";
}
msg += " pool level option";
PsqlBindArray in_bindings;
in_bindings.add(option->option_->getType());
addOptionValueBinding(in_bindings, option);
in_bindings.addOptional(option->formatted_value_);
in_bindings.addOptional(option->space_name_);
in_bindings.add(option->persistent_);
in_bindings.add(option->cancelled_);
in_bindings.addNull();
in_bindings.addNull();
// scope_id
if (pool_type == Lease::TYPE_NA) {
in_bindings.add(5);
} else {
in_bindings.add(6);
}
in_bindings.add(option->getContext());
in_bindings.addNull();
// pool_id
if (pool_type == Lease::TYPE_NA) {
in_bindings.add(pool_id);
} else {
in_bindings.addNull();
}
in_bindings.addTimestamp(option->getModificationTime());
addClientClassesBinding(in_bindings, option->client_classes_);
// pd_pool_id
if (pool_type == Lease::TYPE_PD) {
in_bindings.add(pool_id);
} else {
in_bindings.addNull();
}
// Remember the size before we add where clause arguments.
size_t pre_where_size = in_bindings.size();
// Now we add the update where clause parameters
in_bindings.add(pool_id);
in_bindings.add(option->option_->getType());
in_bindings.addOptional(option->space_name_);
// Start transaction.
PgSqlTransaction transaction(conn_);
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
if (pool_type == Lease::TYPE_PD) {
msg = "prefix delegation";
} else {
msg = "address";
}
msg += " pool specific option set";
ScopedAuditRevision
audit_revision(this,
PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
server_selector, msg, cascade_update);
auto index = (pool_type == Lease::TYPE_NA ?
PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION6_POOL_ID :
PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION6_PD_POOL_ID);
// Try to update the option.
if (updateDeleteQuery(index, in_bindings) == 0) {
// The option doesn't exist, so we'll try to insert it.
// Remove the update where clause bindings.
while (in_bindings.size() > pre_where_size) {
in_bindings.popBack();
}
// Try to insert the option.
insertOption6(server_selector, in_bindings,
option->getModificationTime());
}
// Commit the work.
transaction.commit();
}
/// @brief Sends query to insert or update DHCP option in a shared network.
///
/// @param selector Server selector.
/// @param shared_network_name Name of the shared network the option
/// belongs to.
/// @param option Pointer to the option descriptor encapsulating the option.
/// @param cascade_update Boolean value indicating whether the update is
/// performed as part of the owning element, e.g. shared network.
void createUpdateOption6(const ServerSelector& server_selector,
const std::string& shared_network_name,
const OptionDescriptorPtr& option,
const bool cascade_update) {
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
" (unassigned) is unsupported at the moment");
}
// Create input bindings.
PsqlBindArray in_bindings;
in_bindings.add(option->option_->getType());
addOptionValueBinding(in_bindings, option);
in_bindings.addOptional(option->formatted_value_);
in_bindings.addOptional(option->space_name_);
in_bindings.add(option->persistent_);
in_bindings.add(option->cancelled_);
in_bindings.addNull();
in_bindings.addNull();
in_bindings.add(4);
in_bindings.add(option->getContext());
in_bindings.add(shared_network_name);
in_bindings.addNull();
in_bindings.addTimestamp(option->getModificationTime());
addClientClassesBinding(in_bindings, option->client_classes_);
in_bindings.addNull();
// Remember the size before we add where clause arguments.
size_t pre_where_size = in_bindings.size();
// Now we add the update where clause parameters
in_bindings.add(shared_network_name);
in_bindings.add(option->option_->getType());
in_bindings.addOptional(option->space_name_);
// Start transaction.
PgSqlTransaction transaction(conn_);
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision
audit_revision(this,
PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
server_selector, "shared network specific option set",
cascade_update);
// Try to update the option.
if (updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION6_SHARED_NETWORK,
in_bindings) == 0) {
// The option doesn't exist, so we'll try to insert it.
// Remove the update where clause bindings.
while (in_bindings.size() > pre_where_size) {
in_bindings.popBack();
}
// Try to insert the option.
insertOption6(server_selector, in_bindings,
option->getModificationTime());
}
// Commit the work.
transaction.commit();
}
/// @brief Sends query to insert or update DHCP option in a client class.
///
/// @param selector Server selector.
/// @param client_class Pointer to the client_class the option belongs to.
/// @param option Pointer to the option descriptor encapsulating the option..
void createUpdateOption6(const ServerSelector& server_selector,
const ClientClassDefPtr& client_class,
const OptionDescriptorPtr& option) {
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
" (unassigned) is unsupported at the moment");
}
PsqlBindArray in_bindings;
std::string class_name = client_class->getName();
in_bindings.add(option->option_->getType());
addOptionValueBinding(in_bindings, option);
in_bindings.addOptional(option->formatted_value_);
in_bindings.addOptional(option->space_name_);
in_bindings.add(option->persistent_);
in_bindings.add(option->cancelled_);
in_bindings.add(class_name);
in_bindings.addNull();
in_bindings.add(2);
in_bindings.add(option->getContext());
in_bindings.addNull();
in_bindings.addNull();
in_bindings.addTimestamp(option->getModificationTime());
addClientClassesBinding(in_bindings, option->client_classes_);
in_bindings.addNull();
// Remember the size before we add where clause arguments.
size_t pre_where_size = in_bindings.size();
// Now we add the update where clause parameters
in_bindings.add(class_name);
in_bindings.add(option->option_->getType());
in_bindings.addOptional(option->space_name_);
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision
audit_revision(this,
PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
server_selector, "client class specific option set",
true);
if (updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION6_CLIENT_CLASS,
in_bindings) == 0) {
// The option doesn't exist, so we'll try to insert it.
// Remove the update where clause bindings.
while (in_bindings.size() > pre_where_size) {
in_bindings.popBack();
}
insertOption6(server_selector, in_bindings,
option->getModificationTime());
}
}
/// @brief Sends query to insert or update option definition.
///
/// @param server_selector Server selector.
/// @param option_def Pointer to the option definition to be inserted or updated.
void createUpdateOptionDef6(const ServerSelector& server_selector,
const OptionDefinitionPtr& option_def) {
createUpdateOptionDef(server_selector, Option::V6, option_def, DHCP6_OPTION_SPACE,
PgSqlConfigBackendDHCPv6Impl::GET_OPTION_DEF6_CODE_SPACE,
PgSqlConfigBackendDHCPv6Impl::INSERT_OPTION_DEF6,
PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION_DEF6,
PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
PgSqlConfigBackendDHCPv6Impl::INSERT_OPTION_DEF6_SERVER);
}
/// @brief Sends query to insert or update option definition
/// for a client class.
///
/// @param server_selector Server selector.
/// @param option_def Pointer to the option definition to be inserted or updated.
/// @param client_class Client class name.
void createUpdateOptionDef6(const ServerSelector& server_selector,
const OptionDefinitionPtr& option_def,
const std::string& client_class_name) {
createUpdateOptionDef(server_selector, Option::V6, option_def, DHCP6_OPTION_SPACE,
PgSqlConfigBackendDHCPv6Impl::GET_OPTION_DEF6_CODE_SPACE,
PgSqlConfigBackendDHCPv6Impl::INSERT_OPTION_DEF6_CLIENT_CLASS,
PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION_DEF6_CLIENT_CLASS,
PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
PgSqlConfigBackendDHCPv6Impl::INSERT_OPTION_DEF6_SERVER,
client_class_name);
}
/// @brief Sends query to delete option definition by code and
/// option space name.
///
/// @param server_selector Server selector.
/// @param code Option code.
/// @param name Option name.
/// @return Number of deleted option definitions.
uint64_t deleteOptionDef6(const ServerSelector& server_selector,
const uint16_t code,
const std::string& space) {
PsqlBindArray in_bindings;
in_bindings.add(code);
in_bindings.add(space);
// Run DELETE.
return (deleteTransactional(PgSqlConfigBackendDHCPv6Impl::DELETE_OPTION_DEF6_CODE_NAME,
server_selector,
"deleting option definition",
"option definition deleted",
false,
in_bindings));
}
/// @brief Sends query to delete option definitions for a client class.
///
/// @param server_selector Server selector.
/// @param client_class Pointer to the client class for which option
/// definitions should be deleted.
/// @return Number of deleted option definitions.
uint64_t deleteOptionDefs6(const ServerSelector& server_selector,
const ClientClassDefPtr& client_class) {
PsqlBindArray in_bindings;
in_bindings.addTempString(client_class->getName());
// Run DELETE.
return (deleteTransactional(PgSqlConfigBackendDHCPv6Impl::DELETE_OPTION_DEFS6_CLIENT_CLASS,
server_selector,
"deleting option definition for a client class",
"option definition deleted",
true,
in_bindings));
}
/// @brief Deletes global option.
///
/// @param server_selector Server selector.
/// @param code Code of the deleted option.
/// @param space Option space of the deleted option.
/// @return Number of deleted options.
uint64_t deleteOption6(const ServerSelector& server_selector,
const uint16_t code,
const std::string& space) {
PsqlBindArray in_bindings;
in_bindings.add(code);
in_bindings.add(space);
// Run DELETE.
return (deleteTransactional(PgSqlConfigBackendDHCPv6Impl::DELETE_OPTION6,
server_selector,
"deleting global option",
"global option deleted",
false,
in_bindings));
}
/// @brief Deletes subnet level option.
///
/// @param server_selector Server selector.
/// @param subnet_id Identifier of the subnet to which deleted option
/// belongs.
/// @param code Code of the deleted option.
/// @param space Option space of the deleted option.
/// @return Number of deleted options.
uint64_t deleteOption6(const ServerSelector& server_selector,
const SubnetID& subnet_id,
const uint16_t code,
const std::string& space) {
PsqlBindArray in_bindings;
in_bindings.add(subnet_id);
in_bindings.add(code);
in_bindings.add(space);
// Run DELETE.
return (deleteTransactional(PgSqlConfigBackendDHCPv6Impl::DELETE_OPTION6_SUBNET_ID,
server_selector,
"deleting option for a subnet",
"subnet specific option deleted",
false,
in_bindings));
}
/// @brief Deletes pool level option.
///
/// @param server_selector Server selector.
/// @param pool_start_address Lower bound pool address.
/// @param pool_end_address Upper bound pool address.
/// @param code Code of the deleted option.
/// @param space Option space of the deleted option.
/// @return Number of deleted options.
uint64_t deleteOption6(const db::ServerSelector& server_selector,
const IOAddress& pool_start_address,
const IOAddress& pool_end_address,
const uint16_t code,
const std::string& space) {
PsqlBindArray in_bindings;
in_bindings.addInet6(pool_start_address);
in_bindings.addInet6(pool_end_address);
in_bindings.add(code);
in_bindings.add(space);
// Run DELETE.
return (deleteTransactional(PgSqlConfigBackendDHCPv6Impl::DELETE_OPTION6_POOL_RANGE,
server_selector,
"deleting option for an address pool",
"address pool specific option deleted",
false,
in_bindings));
}
/// @brief Deletes pd pool level option.
///
/// @param server_selector Server selector.
/// @param pd_pool_prefix Address part of the pd pool prefix.
/// @param pd_pool_prefix_length Length of the pd pool prefix.
/// @param code Code of the deleted option.
/// @param space Option space of the deleted option.
/// @return Number of deleted options.
uint64_t deleteOption6(const db::ServerSelector& server_selector,
const asiolink::IOAddress& pd_pool_prefix,
const uint8_t pd_pool_prefix_length,
const uint16_t code,
const std::string& space) {
PsqlBindArray in_bindings;
in_bindings.addTempString(pd_pool_prefix.toText());
in_bindings.add(pd_pool_prefix_length);
in_bindings.add(code);
in_bindings.add(space);
// Run DELETE.
return (deleteTransactional(PgSqlConfigBackendDHCPv6Impl::DELETE_OPTION6_PD_POOL,
server_selector,
"deleting option for a prefix delegation pool",
"prefix delegation pool specific option deleted",
false,
in_bindings));
}
/// @brief Deletes shared network level option.
///
/// @param server_selector Server selector.
/// @param shared_network_name Name of the shared network which deleted
/// option belongs to
/// @param code Code of the deleted option.
/// @param space Option space of the deleted option.
/// @return Number of deleted options.
uint64_t deleteOption6(const db::ServerSelector& server_selector,
const std::string& shared_network_name,
const uint16_t code,
const std::string& space) {
PsqlBindArray in_bindings;
in_bindings.add(shared_network_name);
in_bindings.add(code);
in_bindings.add(space);
// Run DELETE.
return (deleteTransactional(PgSqlConfigBackendDHCPv6Impl::DELETE_OPTION6_SHARED_NETWORK,
server_selector,
"deleting option for a shared network",
"shared network specific option deleted",
false,
in_bindings));
}
/// @brief Deletes options belonging to a subnet from the database.
///
/// @param server_selector Server selector.
/// @param subnet Pointer to the subnet for which options should be
/// deleted.
/// @return Number of deleted options.
uint64_t deleteOptions6(const ServerSelector& server_selector,
const Subnet6Ptr& subnet) {
PsqlBindArray in_bindings;
in_bindings.add(subnet->getID());
in_bindings.addTempString(subnet->toText());
// Run DELETE.
return (deleteTransactional(PgSqlConfigBackendDHCPv6Impl::DELETE_OPTIONS6_SUBNET_ID_PREFIX,
server_selector,
"deleting options for a subnet",
"subnet specific options deleted",
true, in_bindings));
}
/// @brief Deletes options belonging to a shared network from the database.
///
/// @param server_selector Server selector.
/// @param subnet Pointer to the subnet for which options should be
/// deleted.
/// @return Number of deleted options.
uint64_t deleteOptions6(const ServerSelector& server_selector,
const SharedNetwork6Ptr& shared_network) {
PsqlBindArray in_bindings;
in_bindings.addTempString(shared_network->getName());
// Run DELETE.
return (deleteTransactional(PgSqlConfigBackendDHCPv6Impl::
DELETE_OPTIONS6_SHARED_NETWORK, server_selector,
"deleting options for a shared network",
"shared network specific options deleted",
true, in_bindings));
}
/// @brief Deletes options belonging to a client class from the database.
///
/// @param server_selector Server selector.
/// @param client_class Pointer to the client class for which options
/// should be deleted.
/// @return Number of deleted options.
uint64_t deleteOptions6(const ServerSelector& server_selector,
const ClientClassDefPtr& client_class) {
PsqlBindArray in_bindings;
in_bindings.addTempString(client_class->getName());
// Run DELETE.
return (deleteTransactional(PgSqlConfigBackendDHCPv6Impl::
DELETE_OPTIONS6_CLIENT_CLASS, server_selector,
"deleting options for a client class",
"client class specific options deleted",
true, in_bindings));
}
/// @brief Common function to retrieve client classes.
///
/// @param index Index of the query to be used.
/// @param server_selector Server selector.
/// @param in_bindings Input bindings specifying selection criteria. The
/// size of the bindings collection must match the number of placeholders
/// in the prepared statement. The input bindings collection must be empty
/// if the query contains no WHERE clause.
/// @param [out] client_classes Reference to a container where fetched client
/// classes will be inserted.
void getClientClasses6(const StatementIndex& index,
const ServerSelector& server_selector,
const PsqlBindArray& in_bindings,
ClientClassDictionary& client_classes) {
std::list<ClientClassDefPtr> class_list;
uint64_t last_option_id = 0;
uint64_t last_option_def_id = 0;
std::string last_tag;
selectQuery(index, in_bindings,
[this, &class_list, &last_option_id, &last_option_def_id, &last_tag]
(PgSqlResult& r, int row) {
// Create a convenience worker for the row.
PgSqlResultRowWorker worker(r, row);
ClientClassDefPtr last_client_class;
if (!class_list.empty()) {
last_client_class = *class_list.rbegin();
}
// Class ID is column 0.
uint64_t id = worker.getBigInt(0) ;
if (!last_client_class || (last_client_class->getId() != id)) {
last_option_id = 0;
last_option_def_id = 0;
last_tag.clear();
auto options = boost::make_shared<CfgOption>();
auto option_defs = boost::make_shared<CfgOptionDef>();
last_client_class = boost::make_shared<ClientClassDef>(worker.getString(1),
ExpressionPtr(), options);
last_client_class->setCfgOptionDef(option_defs);
// id
last_client_class->setId(id);
// name
last_client_class->setName(worker.getString(1));
// test
if (!worker.isColumnNull(2)) {
last_client_class->setTest(worker.getString(2));
}
// additional
if (!worker.isColumnNull(3)) {
last_client_class->setAdditional(worker.getBool(3));
}
// valid lifetime: default, min, max
last_client_class->setValid(worker.getTriplet(4, 5, 6));
// depend on known directly or indirectly
last_client_class->setDependOnKnown(worker.getBool(7) || worker.getBool(8));
// modification_ts
last_client_class->setModificationTime(worker.getTimestamp(9));
// user_context at 10.
if (!worker.isColumnNull(10)) {
ElementPtr user_context = worker.getJSON(10);
if (user_context) {
last_client_class->setContext(user_context);
}
}
// class specific option definition from 11 to 20.
// class specific option from 21 to 33.
// preferred lifetime: default, min, max
last_client_class->setPreferred(worker.getTriplet(36, 37, 38));
class_list.push_back(last_client_class);
}
// Check for new server tags at 35.
if (!worker.isColumnNull(35)) {
std::string new_tag = worker.getString(35);
if (last_tag != new_tag) {
if (!new_tag.empty() && !last_client_class->hasServerTag(ServerTag(new_tag))) {
last_client_class->setServerTag(new_tag);
}
last_tag = new_tag;
}
}
// Parse client class specific option definition from 11 to 20.
if (!worker.isColumnNull(11) &&
(last_option_def_id < worker.getBigInt(11))) {
last_option_def_id = worker.getBigInt(11);
auto def = processOptionDefRow(worker, 11);
if (def) {
last_client_class->getCfgOptionDef()->add(def);
}
}
// Parse client class specific option from 21 to 34.
if (!worker.isColumnNull(21) &&
(last_option_id < worker.getBigInt(21))) {
last_option_id = worker.getBigInt(21);
OptionDescriptorPtr desc = processOptionRow(Option::V6, worker, 21);
if (desc) {
last_client_class->getCfgOption()->add(*desc, desc->space_name_);
}
}
});
tossNonMatchingElements(server_selector, class_list);
for (auto const& c : class_list) {
client_classes.addClass(c);
}
}
/// @brief Sends query to retrieve a client class by name.
///
/// @param server_selector Server selector.
/// @param name Name of the class to be retrieved.
/// @return Pointer to the client class or null if the class is not found.
ClientClassDefPtr getClientClass6(const ServerSelector& server_selector,
const std::string& name) {
PsqlBindArray in_bindings;
in_bindings.add(name);
ClientClassDictionary client_classes;
getClientClasses6(PgSqlConfigBackendDHCPv6Impl::GET_CLIENT_CLASS6_NAME,
server_selector, in_bindings, client_classes);
return (client_classes.getClasses()->empty() ? ClientClassDefPtr() :
(*client_classes.getClasses()->begin()));
}
/// @brief Sends query to retrieve all client classes.
///
/// @param server_selector Server selector.
/// @param [out] client_classes Reference to the client classes collection
/// where retrieved classes will be stored.
void getAllClientClasses6(const ServerSelector& server_selector,
ClientClassDictionary& client_classes) {
PsqlBindArray in_bindings;
getClientClasses6(server_selector.amUnassigned() ?
PgSqlConfigBackendDHCPv6Impl::GET_ALL_CLIENT_CLASSES6_UNASSIGNED :
PgSqlConfigBackendDHCPv6Impl::GET_ALL_CLIENT_CLASSES6,
server_selector, in_bindings, client_classes);
}
/// @brief Sends query to retrieve modified client classes.
///
/// @param server_selector Server selector.
/// @param modification_ts Lower bound modification timestamp.
/// @param [out] client_classes Reference to the client classes collection
/// where retrieved classes will be stored.
void getModifiedClientClasses6(const ServerSelector& server_selector,
const boost::posix_time::ptime& modification_ts,
ClientClassDictionary& client_classes) {
if (server_selector.amAny()) {
isc_throw(InvalidOperation, "fetching modified client classes for ANY "
"server is not supported");
}
PsqlBindArray in_bindings;
in_bindings.addTimestamp(modification_ts);
getClientClasses6(server_selector.amUnassigned() ?
PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_CLIENT_CLASSES6_UNASSIGNED :
PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_CLIENT_CLASSES6,
server_selector, in_bindings, client_classes);
}
/// @brief Upserts client class.
///
/// @param server_selector Server selector.
/// @param client_class Pointer to the upserted client class.
/// @param follow_class_name name of the class after which the
/// new or updated class should be positioned. An empty value
/// causes the class to be appended at the end of the class
/// hierarchy.
void createUpdateClientClass6(const ServerSelector& server_selector,
const ClientClassDefPtr& client_class,
const std::string& follow_class_name) {
// We need to evaluate class expression to see if it references any
// other classes (dependencies). As part of this evaluation we will
// also check if the client class depends on KNOWN/UNKNOWN built-in
// classes.
std::list<std::string> dependencies;
auto depend_on_known = false;
if (!client_class->getTest().empty()) {
ExpressionPtr expression;
ExpressionParser parser;
// Parse the test expression. The callback function is normally used to
// interrupt config file parsing when one of the classes refers to a
// non-existing client class. It returns false in this case. Here,
// we use the callback to capture client classes referenced by the
// upserted client class and record whether this class depends on
// KNOWN/UNKNOWN built-ins. The callback always returns true to avoid
// reporting the parsing error. The dependency check is performed later
// at the database level.
parser.parse(expression, Element::create(client_class->getTest()), AF_INET6,
[&dependencies, &depend_on_known](const ClientClass& client_class) -> bool {
if (isClientClassBuiltIn(client_class)) {
if ((client_class == "KNOWN") || (client_class == "UNKNOWN")) {
depend_on_known = true;
}
} else {
dependencies.push_back(client_class);
}
return (true);
});
}
PsqlBindArray in_bindings;
std::string class_name = client_class->getName();
in_bindings.add(class_name);
in_bindings.addTempString(client_class->getTest());
in_bindings.add(client_class->getAdditional());
in_bindings.add(client_class->getValid());
in_bindings.add(client_class->getValid().getMin());
in_bindings.add(client_class->getValid().getMax());
in_bindings.add(depend_on_known);
// follow-class-name (8)
if (follow_class_name.empty()) {
in_bindings.addNull();
} else {
in_bindings.add(follow_class_name);
}
in_bindings.add(client_class->getPreferred());
in_bindings.add(client_class->getPreferred().getMin());
in_bindings.add(client_class->getPreferred().getMax());
in_bindings.addTimestamp(client_class->getModificationTime());
in_bindings.add(client_class->getContext());
PgSqlTransaction transaction(conn_);
ScopedAuditRevision audit_revision(this, PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
server_selector, "client class set", true);
// Create a savepoint in case we are called as part of larger
// transaction.
conn_.createSavepoint("createUpdateClass6");
// Keeps track of whether the client class is inserted or updated.
auto update = false;
try {
insertQuery(PgSqlConfigBackendDHCPv6Impl::INSERT_CLIENT_CLASS6, in_bindings);
} catch (const DuplicateEntry&) {
// It already exists, rollback to the savepoint to preserve
// any prior work.
conn_.rollbackToSavepoint("createUpdateClass6");
// Delete options and option definitions. They will be re-created from the new class
// instance.
deleteOptions6(ServerSelector::ANY(), client_class);
deleteOptionDefs6(ServerSelector::ANY(), client_class);
// Note: follow_class_name is left in the bindings even though it is
// not needed in both cases. This allows us to use one base query.
// Add the class name for the where clause.
in_bindings.add(class_name);
if (follow_class_name.empty()) {
// If position is not specified, leave the class at the same position.
updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::UPDATE_CLIENT_CLASS6_SAME_POSITION,
in_bindings);
} else {
// Update with follow_class_name specifying the position.
updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::UPDATE_CLIENT_CLASS6,
in_bindings);
}
// Delete class associations with the servers and dependencies. We will re-create
// them according to the new class specification.
PsqlBindArray in_assoc_bindings;
in_assoc_bindings.add(class_name);
updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::DELETE_CLIENT_CLASS6_DEPENDENCY,
in_assoc_bindings);
updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::DELETE_CLIENT_CLASS6_SERVER,
in_assoc_bindings);
update = true;
}
// Associate client class with the servers.
PsqlBindArray attach_bindings;
attach_bindings.add(class_name);
attach_bindings.addTimestamp(client_class->getModificationTime());
attachElementToServers(PgSqlConfigBackendDHCPv6Impl::INSERT_CLIENT_CLASS6_SERVER,
server_selector, attach_bindings);
// Iterate over the captured dependencies and try to insert them into the database.
for (auto const& dependency : dependencies) {
try {
PsqlBindArray in_dependency_bindings;
in_dependency_bindings.add(class_name);
in_dependency_bindings.add(dependency);
// We deleted earlier dependencies, so we can simply insert new ones.
insertQuery(PgSqlConfigBackendDHCPv6Impl::INSERT_CLIENT_CLASS6_DEPENDENCY,
in_dependency_bindings);
} catch (const std::exception& ex) {
isc_throw(InvalidOperation, "unmet dependency on client class: " << dependency);
}
}
// If we performed client class update we also have to verify that its dependency
// on KNOWN/UNKNOWN client classes hasn't changed.
if (update) {
PsqlBindArray in_check_bindings;
insertQuery(PgSqlConfigBackendDHCPv6Impl::CHECK_CLIENT_CLASS_KNOWN_DEPENDENCY_CHANGE,
in_check_bindings);
}
// (Re)create option definitions.
if (client_class->getCfgOptionDef()) {
auto option_defs = client_class->getCfgOptionDef()->getContainer();
auto option_spaces = option_defs.getOptionSpaceNames();
for (auto const& option_space : option_spaces) {
OptionDefContainerPtr defs = option_defs.getItems(option_space);
for (auto const& def : *defs) {
createUpdateOptionDef6(server_selector, def, client_class->getName());
}
}
}
// (Re)create options.
auto option_spaces = client_class->getCfgOption()->getOptionSpaceNames();
for (auto const& option_space : option_spaces) {
OptionContainerPtr options = client_class->getCfgOption()->getAll(option_space);
for (auto const& desc : *options) {
OptionDescriptorPtr desc_copy = OptionDescriptor::create(desc);
desc_copy->space_name_ = option_space;
createUpdateOption6(server_selector, client_class, desc_copy);
}
}
// All ok. Commit the transaction.
transaction.commit();
}
/// @brief Removes client class by name.
///
/// @param server_selector Server selector.
/// @param name Removed client class name.
/// @return Number of deleted client classes.
uint64_t deleteClientClass6(const ServerSelector& server_selector,
const std::string& name) {
int index = server_selector.amAny() ?
PgSqlConfigBackendDHCPv6Impl::DELETE_CLIENT_CLASS6_ANY :
PgSqlConfigBackendDHCPv6Impl::DELETE_CLIENT_CLASS6;
uint64_t result = deleteTransactional(index, server_selector,
"deleting client class",
"client class deleted",
true,
name);
return (result);
}
/// @brief Removes unassigned global parameters, global options and
/// option definitions.
///
/// This function is called when one or more servers are deleted and
/// it is likely that there are some orphaned configuration elements
/// left in the database. This method removes those elements.
void purgeUnassignedConfig() {
multipleUpdateDeleteQueries(DELETE_ALL_GLOBAL_PARAMETERS6_UNASSIGNED,
DELETE_ALL_GLOBAL_OPTIONS6_UNASSIGNED,
DELETE_ALL_OPTION_DEFS6_UNASSIGNED);
}
/// @brief Attempts to delete a server having a given tag.
///
/// @param server_tag Tag of the server to be deleted.
/// @return Number of deleted servers.
/// @throw isc::InvalidOperation when trying to delete the logical
/// server 'all'.
uint64_t deleteServer6(const data::ServerTag& server_tag) {
// It is not allowed to delete 'all' logical server.
if (server_tag.amAll()) {
isc_throw(InvalidOperation, "'all' is a name reserved for the server tag which"
" associates the configuration elements with all servers connecting"
" to the database and may not be deleted");
}
PgSqlTransaction transaction(conn_);
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision
audit_revision(this, PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
ServerSelector::ALL(), "deleting a server", false);
// Specify which server should be deleted.
PsqlBindArray in_bindings;
in_bindings.addTempString(server_tag.get());
// Attempt to delete the server.
auto count = updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::DELETE_SERVER6,
in_bindings);
// If we have deleted any servers we have to remove any dangling global
// parameters, options and option definitions.
if (count > 0) {
purgeUnassignedConfig();
}
transaction.commit();
return (count);
}
/// @brief Attempts to delete all servers.
///
/// This method deletes all servers added by the user. It does not
/// delete the logical server 'all'.
///
/// @return Number of deleted servers.
uint64_t deleteAllServers6() {
// Start transaction.
PgSqlTransaction transaction(conn_);
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision
audit_revision(this, PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
ServerSelector::ALL(), "deleting all servers",
false);
// No arguments, hence empty input bindings.
PsqlBindArray in_bindings;
// Attempt to delete the servers.
auto count = updateDeleteQuery(PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_SERVERS6,
in_bindings);
// If we have deleted any servers we have to remove any dangling global
// parameters, options and option definitions.
if (count > 0) {
purgeUnassignedConfig();
}
// Commit the transaction.
transaction.commit();
return (count);
}
/// @brief Attempts to reconnect the server to the config DB backend manager.
///
/// This is a self-rescheduling function that attempts to reconnect to the
/// server's config DB backends after connectivity to one or more have been
/// lost. Upon entry it will attempt to reconnect via
/// @ref ConfigBackendDHCPv6Mgr.addBackend.
/// If this is successful, DHCP servicing is re-enabled and server returns
/// to normal operation.
///
/// If reconnection fails and the maximum number of retries has not been
/// exhausted, it will schedule a call to itself to occur at the
/// configured retry interval. DHCP service remains disabled.
///
/// If the maximum number of retries has been exhausted an error is logged
/// and the server shuts down.
///
/// @param db_reconnect_ctl pointer to the ReconnectCtl containing the
/// configured reconnect parameters.
/// @return true if connection has been recovered, false otherwise.
static bool dbReconnect(ReconnectCtlPtr db_reconnect_ctl) {
MultiThreadingCriticalSection cs;
// Invoke application layer connection lost callback.
if (!DatabaseConnection::invokeDbLostCallback(db_reconnect_ctl)) {
return (false);
}
bool reopened = false;
bool do_exit = false;
const std::string timer_name = db_reconnect_ctl->timerName();
// At least one connection was lost.
try {
auto srv_cfg = CfgMgr::instance().getCurrentCfg();
auto config_ctl = srv_cfg->getConfigControlInfo();
// Something is definitely wrong. Did the configuration change
// somehow and there is no configuration for CB?
if (!config_ctl) {
do_exit = true;
isc_throw(Unexpected, "No CB configuration found!");
}
// Iterate over the configured DBs and instantiate them.
for (auto const& db : config_ctl->getConfigDatabases()) {
const std::string& access = db.getAccessString();
auto parameters = db.getParameters();
if (ConfigBackendDHCPv6Mgr::instance().delBackend(parameters["type"], access, true)) {
ConfigBackendDHCPv6Mgr::instance().addBackend(db.getAccessString());
}
}
reopened = true;
} catch (const std::exception& ex) {
LOG_ERROR(pgsql_cb_logger, PGSQL_CB_RECONNECT_ATTEMPT_FAILED6)
.arg(ex.what());
if (do_exit) {
return (true);
}
}
if (reopened) {
// Cancel the timer.
if (TimerMgr::instance()->isTimerRegistered(timer_name)) {
TimerMgr::instance()->unregisterTimer(timer_name);
}
// Invoke application layer connection recovered callback.
if (!DatabaseConnection::invokeDbRecoveredCallback(db_reconnect_ctl)) {
return (false);
}
} else {
if (!db_reconnect_ctl->checkRetries()) {
// We're out of retries, log it and initiate shutdown.
LOG_ERROR(pgsql_cb_logger, PGSQL_CB_RECONNECT_FAILED6)
.arg(db_reconnect_ctl->maxRetries());
// Cancel the timer.
if (TimerMgr::instance()->isTimerRegistered(timer_name)) {
TimerMgr::instance()->unregisterTimer(timer_name);
}
// Invoke application layer connection failed callback.
DatabaseConnection::invokeDbFailedCallback(db_reconnect_ctl);
return (false);
}
LOG_INFO(pgsql_cb_logger, PGSQL_CB_RECONNECT_ATTEMPT_SCHEDULE6)
.arg(db_reconnect_ctl->maxRetries() - db_reconnect_ctl->retriesLeft() + 1)
.arg(db_reconnect_ctl->maxRetries())
.arg(db_reconnect_ctl->retryInterval());
// Start the timer.
if (!TimerMgr::instance()->isTimerRegistered(timer_name)) {
TimerMgr::instance()->registerTimer(timer_name,
std::bind(&PgSqlConfigBackendDHCPv6Impl::dbReconnect, db_reconnect_ctl),
db_reconnect_ctl->retryInterval(),
asiolink::IntervalTimer::ONE_SHOT);
}
TimerMgr::instance()->setup(timer_name);
}
return (true);
}
/// @brief Sets a Network6 interface ID from result set col.
///
/// Sets the interface id of the Network6 to the value carried in the
/// given column in a result set row.
///
/// @param network shared network or subnet to receive the interface ID
/// @param worker result set row worker contain the database row
/// @param col column within the row from which to take the value
void setInterfaceId(Network6& network, PgSqlResultRowWorker& worker, size_t col) {
if (!worker.isColumnNull(col)) {
std::vector<uint8_t> iface_id_data;
worker.getBytes(col, iface_id_data);
if (!iface_id_data.empty()) {
OptionPtr opt_iface_id(new Option(Option::V6, D6O_INTERFACE_ID, iface_id_data));
network.setInterfaceId(opt_iface_id);
}
}
}
/// @brief Adds network interface ID to a bind array.
///
/// Adds the interface id to end of the given bind array as a vector of bytes.
///
/// @param bindings PsqlBindArray to which the ID should be added.
/// @param network Pointer to shared network or subnet for which ID binding
/// should be created.
void addInterfaceIdBinding(PsqlBindArray& bindings, const Network6& network) {
auto opt_iface_id = network.getInterfaceId(Network::Inheritance::NONE);
if (!opt_iface_id) {
bindings.addNull();
} else {
auto iface_id_data = opt_iface_id->getData();
if (iface_id_data.empty()) {
bindings.addNull();
} else {
bindings.addTempBinary(iface_id_data);
}
}
}
};
namespace {
/// @brief Array of tagged statements.
typedef std::array<PgSqlTaggedStatement, PgSqlConfigBackendDHCPv6Impl::NUM_STATEMENTS>
TaggedStatementArray;
/// @brief Prepared PgSQL statements used by the backend to insert and
/// retrieve data from the database. They must be in the same order as
/// PgSqlConfigBackendDHCPv6Impl::StatementIndex. The statement is
/// the corresponding enum name.
TaggedStatementArray tagged_statements = { {
{
// PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
4,
{
OID_TIMESTAMP, // 1 audit_ts
OID_VARCHAR, // 2 server_tag
OID_TEXT, // 3 audit_log_message
OID_BOOL // 4 cascade_transaction
},
"CREATE_AUDIT_REVISION",
"select createAuditRevisionDHCP6($1, $2, $3, $4)"
},
// Verify that dependency on KNOWN/UNKNOWN class has not changed.
{
// PgSqlConfigBackendDHCPv6Impl::CHECK_CLIENT_CLASS_KNOWN_DEPENDENCY_CHANGE,
0,
{
OID_NONE
},
"CHECK_CLIENT_CLASS_KNOWN_DEPENDENCY_CHANGE",
"select checkDHCPv6ClientClassKnownDependencyChange()"
},
// Select global parameter by name.
{
// PgSqlConfigBackendDHCPv6Impl::GET_GLOBAL_PARAMETER6,
2,
{
OID_VARCHAR, // 1 server_tag
OID_VARCHAR // 2 name
},
"GET_GLOBAL_PARAMETER6",
PGSQL_GET_GLOBAL_PARAMETER(dhcp6, AND g.name = $2)
},
// Select all global parameters.
{
// PgSqlConfigBackendDHCPv6Impl::GET_ALL_GLOBAL_PARAMETERS6,
1,
{
OID_VARCHAR // 1 server_tag
},
"GET_ALL_GLOBAL_PARAMETERS6",
PGSQL_GET_GLOBAL_PARAMETER(dhcp6)
},
// Select modified global parameters.
{
// PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_GLOBAL_PARAMETERS6,
2,
{
OID_VARCHAR, // 1 server_tag
OID_TIMESTAMP // 2 modification_ts
},
"GET_MODIFIED_GLOBAL_PARAMETERS6",
PGSQL_GET_GLOBAL_PARAMETER(dhcp6, AND g.modification_ts >= $2)
},
// Select subnet by id.
{
// PgSqlConfigBackendDHCPv6Impl::GET_SUBNET6_ID_NO_TAG,
1,
{
OID_INT8 // 1 subnet_id
},
"GET_SUBNET6_ID_NO_TAG",
PGSQL_GET_SUBNET6_NO_TAG(WHERE s.subnet_id = $1)
},
// Select subnet by id without specifying server tags.
{
// PgSqlConfigBackendDHCPv6Impl::GET_SUBNET6_ID_ANY,
1,
{
OID_INT8 // 1 subnet_id
},
"GET_SUBNET6_ID_ANY",
PGSQL_GET_SUBNET6_ANY(WHERE s.subnet_id = $1)
},
// Select unassigned subnet by id.
{
// PgSqlConfigBackendDHCPv6Impl::GET_SUBNET6_ID_UNASSIGNED,
1,
{
OID_INT8 // 1 subnet_id
},
"GET_SUBNET6_ID_UNASSIGNED",
PGSQL_GET_SUBNET6_UNASSIGNED(AND s.subnet_id = $1)
},
// Select subnet by prefix.
{
// PgSqlConfigBackendDHCPv6Impl::GET_SUBNET6_PREFIX_NO_TAG,
1,
{
OID_VARCHAR // 1 subnet_prefix
},
"GET_SUBNET6_PREFIX_NO_TAG",
PGSQL_GET_SUBNET6_NO_TAG(WHERE s.subnet_prefix = $1)
},
// Select subnet by prefix without specifying server tags.
{
// PgSqlConfigBackendDHCPv6Impl::GET_SUBNET6_PREFIX_ANY,
1,
{
OID_VARCHAR // 1 subnet_prefix
},
"GET_SUBNET6_PREFIX_ANY",
PGSQL_GET_SUBNET6_ANY(WHERE s.subnet_prefix = $1)
},
// Select unassigned subnet by prefix.
{
// PgSqlConfigBackendDHCPv6Impl::GET_SUBNET6_PREFIX_UNASSIGNED,
1,
{
OID_VARCHAR // 1 subnet_prefix
},
"GET_SUBNET6_PREFIX_UNASSIGNED",
PGSQL_GET_SUBNET6_UNASSIGNED(AND s.subnet_prefix = $1)
},
// Select all subnets.
{
// PgSqlConfigBackendDHCPv6Impl::GET_ALL_SUBNETS6,
0,
{
OID_NONE
},
"GET_ALL_SUBNETS6",
PGSQL_GET_SUBNET6_NO_TAG()
},
// Select all unassigned subnets.
{
// PgSqlConfigBackendDHCPv6Impl::GET_ALL_SUBNETS6_UNASSIGNED,
0,
{
OID_NONE
},
"GET_ALL_SUBNETS6_UNASSIGNED",
PGSQL_GET_SUBNET6_UNASSIGNED()
},
// Select subnets having modification time later than X.
{
// PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_SUBNETS6,
1,
{
OID_TIMESTAMP // 1 modification_ts
},
"GET_MODIFIED_SUBNETS6",
PGSQL_GET_SUBNET6_NO_TAG(WHERE s.modification_ts >= $1)
},
// Select modified and unassigned subnets.
{
// PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_SUBNETS6_UNASSIGNED,
1,
{
OID_TIMESTAMP // 1 modification_ts
},
"GET_MODIFIED_SUBNETS6_UNASSIGNED",
PGSQL_GET_SUBNET6_UNASSIGNED(AND s.modification_ts >= $1)
},
// Select subnets belonging to a shared network.
{
// PgSqlConfigBackendDHCPv6Impl::GET_SHARED_NETWORK_SUBNETS6,
1,
{
OID_VARCHAR // 1 share_network_name
},
"GET_SHARED_NETWORK_SUBNETS6",
PGSQL_GET_SUBNET6_ANY(WHERE s.shared_network_name = $1)
},
// Select pool by address range for a server.
{
// PgSqlConfigBackendDHCPv6Impl::GET_POOL6_RANGE,
3,
{
OID_VARCHAR, // 1 server_tag
OID_TEXT, // 2 start_address - cast as inet
OID_TEXT // 3 end_address - cast as inet
},
"GET_POOL6_RANGE",
PGSQL_GET_POOL6_RANGE_WITH_TAG(WHERE (srv.tag = $1 OR srv.id = 1) \
AND (p.start_address = cast($2 as inet)) \
AND (p.end_address = cast($3 as inet)))
},
// Select pool by address range for any server.
{
// PgSqlConfigBackendDHCPv6Impl::GET_POOL6_RANGE_ANY,
2,
{
OID_TEXT, // 1 start_address - cast as inet
OID_TEXT // 2 end_address - cast as inet
},
"GET_POOL6_RANGE_ANY",
PGSQL_GET_POOL6_RANGE_NO_TAG(WHERE (p.start_address = cast($1 as inet)) AND \
(p.end_address = cast($2 as inet)))
},
// Select prefix delegation pool for a server.
{
// PgSqlConfigBackendDHCPv6Impl::GET_PD_POOL,
3,
{
OID_VARCHAR, // 1 server_tag
OID_VARCHAR, // 2 pd pool prefix
OID_INT2 // 3 prefix length
},
"GET_PD_POOL",
PGSQL_GET_PD_POOL_WITH_TAG(WHERE (srv.tag = $1 OR srv.id = 1) AND p.prefix = $2 AND p.prefix_length = $3)<--- There is an unknown macro here somewhere. Configuration is required. If WHERE is a macro then please configure it.
},
// Select prefix delegation pool for any server.
{
// PgSqlConfigBackendDHCPv6Impl::GET_PD_POOL_ANY,
2,
{
OID_VARCHAR, // 1 prefix
OID_INT2 // 2 prefix length
},
"GET_PD_POOL_ANY",
PGSQL_GET_PD_POOL_NO_TAG(WHERE p.prefix = $1 AND p.prefix_length = $2)
},
// Select shared network by name.
{
// PgSqlConfigBackendDHCPv6Impl::GET_SHARED_NETWORK6_NAME_NO_TAG,
1,
{
OID_VARCHAR // name of network
},
"GET_SHARED_NETWORK6_NAME_NO_TAG",
PGSQL_GET_SHARED_NETWORK6_NO_TAG(WHERE n.name = $1)
},
// Select shared network by name without specifying server tags.
{
// PgSqlConfigBackendDHCPv6Impl::GET_SHARED_NETWORK6_NAME_ANY,
1,
{
OID_VARCHAR // name of network
},
"GET_SHARED_NETWORK6_NAME_ANY",
PGSQL_GET_SHARED_NETWORK6_ANY(WHERE n.name = $1)
},
// Select unassigned shared network by name.
{
// PgSqlConfigBackendDHCPv6Impl::GET_SHARED_NETWORK6_NAME_UNASSIGNED,
1,
{
OID_VARCHAR // name of network
},
"GET_SHARED_NETWORK6_NAME_UNASSIGNED",
PGSQL_GET_SHARED_NETWORK6_UNASSIGNED(AND n.name = $1)
},
// Select all shared networks.
{
// PgSqlConfigBackendDHCPv6Impl::GET_ALL_SHARED_NETWORKS6,
0,
{
OID_NONE
},
"GET_ALL_SHARED_NETWORKS6",
PGSQL_GET_SHARED_NETWORK6_NO_TAG()
},
// Select all unassigned shared networks.
{
// PgSqlConfigBackendDHCPv6Impl::GET_ALL_SHARED_NETWORKS6_UNASSIGNED,
0,
{
OID_NONE
},
"GET_ALL_SHARED_NETWORKS6_UNASSIGNED",
PGSQL_GET_SHARED_NETWORK6_UNASSIGNED()
},
// Select modified shared networks.
{
// PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_SHARED_NETWORKS6,
1,
{
OID_TIMESTAMP // 1 modification_ts
},
"GET_MODIFIED_SHARED_NETWORKS6",
PGSQL_GET_SHARED_NETWORK6_NO_TAG(WHERE n.modification_ts >= $1)
},
// Select modified and unassigned shared networks.
{
// PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_SHARED_NETWORKS6_UNASSIGNED,
1,
{
OID_TIMESTAMP // 1 modification_ts
},
"GET_MODIFIED_SHARED_NETWORKS6_UNASSIGNED",
PGSQL_GET_SHARED_NETWORK6_UNASSIGNED(AND n.modification_ts >= $1)
},
// Retrieves option definition by code and space.
{
// PgSqlConfigBackendDHCPv6Impl::GET_OPTION_DEF6_CODE_SPACE,
3,
{
OID_VARCHAR, // 1 server_tag
OID_INT2, // 2 code
OID_VARCHAR // 3 space
},
"GET_OPTION_DEF6_CODE_SPACE",
PGSQL_GET_OPTION_DEF(dhcp6, AND d.code = $2 AND d.space = $3)
},
// Retrieves all option definitions.
{
// PgSqlConfigBackendDHCPv6Impl::GET_ALL_OPTION_DEFS6,
1,
{
OID_VARCHAR // 1 server_tag
},
"GET_ALL_OPTION_DEFS6",
PGSQL_GET_OPTION_DEF(dhcp6)
},
// Retrieves modified option definitions.
{
// PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_OPTION_DEFS6,
2,
{
OID_VARCHAR, // 1 server_tag
OID_TIMESTAMP // 2 modification_ts
},
"GET_MODIFIED_OPTION_DEFS6",
PGSQL_GET_OPTION_DEF(dhcp6, AND d.modification_ts >= $2)
},
// Retrieves global option by code and space.
{
// PgSqlConfigBackendDHCPv6Impl::GET_OPTION6_CODE_SPACE,
3,
{
OID_VARCHAR, // 1 server_tag
OID_INT2, // 2 code
OID_VARCHAR // 3 space
},
"GET_OPTION6_CODE_SPACE",
PGSQL_GET_OPTION6(AND o.scope_id = 0 AND o.code = $2 AND o.space = $3)
},
// Retrieves all global options.
{
// PgSqlConfigBackendDHCPv6Impl::GET_ALL_OPTIONS6,
1,
{
OID_VARCHAR // 1 server_tag
},
"GET_ALL_OPTIONS6",
PGSQL_GET_OPTION6(AND o.scope_id = 0)
},
// Retrieves modified options.
{
// PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_OPTIONS6,
2,
{
OID_VARCHAR, // 1 server_tag
OID_TIMESTAMP // 2 modification_ts
},
"GET_MODIFIED_OPTIONS6",
PGSQL_GET_OPTION6(AND o.scope_id = 0 AND o.modification_ts >= $2)
},
// Retrieves an option for a given subnet, option code and space.
{
// PgSqlConfigBackendDHCPv6Impl::GET_OPTION6_SUBNET_ID_CODE_SPACE,
4,
{
OID_VARCHAR, // 1 server_tag
OID_INT8, // 2 subnet_id
OID_INT2, // 3 code
OID_VARCHAR // 4 space
},
"GET_OPTION6_SUBNET_ID_CODE_SPACE",
PGSQL_GET_OPTION6(AND o.scope_id = 1 AND o.dhcp6_subnet_id = $2 AND o.code = $3 AND o.space = $4)
},
// Retrieves an option for a given pool, option code and space.
{
// PgSqlConfigBackendDHCPv6Impl::GET_OPTION6_POOL_ID_CODE_SPACE,
4,
{
OID_VARCHAR, // 1 server_tag
OID_INT8, // 2 pool_id
OID_INT2, // 3 code
OID_VARCHAR // 4 space
},
"GET_OPTION6_POOL_ID_CODE_SPACE",
PGSQL_GET_OPTION6(AND o.scope_id = 5 AND o.pool_id = $2 AND o.code = $3 AND o.space = $4)
},
// Retrieves an option for a given pd pool, option code and space.
{
// PgSqlConfigBackendDHCPv6Impl::GET_OPTION6_PD_POOL_ID_CODE_SPACE,
4,
{
OID_VARCHAR, // 1 server_tag
OID_INT8, // 2 pd_pool_id
OID_INT2, // 3 code
OID_VARCHAR // 4 space
},
"GET_OPTION6_PD_POOL_ID_CODE_SPACE",
PGSQL_GET_OPTION6(AND o.scope_id = 6 AND o.pd_pool_id = $2 AND o.code = $3 AND o.space = $4)
},
// Retrieves an option for a given shared network, option code and space.
{
// PgSqlConfigBackendDHCPv6Impl::GET_OPTION6_SHARED_NETWORK_CODE_SPACE,
4,
{
OID_VARCHAR, // 1 server_tag
OID_VARCHAR, // 2 shared_network_name
OID_INT2, // 3 code
OID_VARCHAR // 4 space
},
"GET_OPTION6_SHARED_NETWORK_CODE_SPACE",
PGSQL_GET_OPTION6(AND o.scope_id = 4 AND o.shared_network_name = $2 AND o.code = $3 AND o.space = $4)
},
// Select a client class by name.
{
// PgSqlConfigBackendDHCPv6Impl::GET_CLIENT_CLASS6_NAME,
1,
{
OID_VARCHAR // name of class
},
"GET_CLIENT_CLASS6_NAME",
PGSQL_GET_CLIENT_CLASS6_WITH_TAG(WHERE c.name = $1)
},
// Select all client classes.
{
// PgSqlConfigBackendDHCPv6Impl::GET_ALL_CLIENT_CLASSES6,
0,
{
OID_NONE
},
"GET_ALL_CLIENT_CLASSES6",
PGSQL_GET_CLIENT_CLASS6_WITH_TAG()
},
// Select all unassigned client classes.
{
// PgSqlConfigBackendDHCPv6Impl::GET_ALL_CLIENT_CLASSES6_UNASSIGNED,
0,
{
OID_NONE
},
"GET_ALL_CLIENT_CLASSES6_UNASSIGNED",
PGSQL_GET_CLIENT_CLASS6_UNASSIGNED()
},
// Select modified client classes.
{
// PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_CLIENT_CLASSES6,
1,
{
OID_TIMESTAMP // 1 modification_ts
},
"GET_MODIFIED_CLIENT_CLASSES6",
PGSQL_GET_CLIENT_CLASS6_WITH_TAG(WHERE c.modification_ts >= $1)
},
// Select modified client classes.
{
// PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_CLIENT_CLASSES6_UNASSIGNED,
1,
{
OID_TIMESTAMP // 1 modification_ts
},
"GET_MODIFIED_CLIENT_CLASSES6_UNASSIGNED",
PGSQL_GET_CLIENT_CLASS6_UNASSIGNED(AND c.modification_ts >= $1)
},
// Retrieves the most recent audit entries.
{
// PgSqlConfigBackendDHCPv6Impl::GET_AUDIT_ENTRIES6_TIME,
3,
{
OID_VARCHAR, // 1 server_tag
OID_TIMESTAMP, // 2 modification_ts
OID_INT8 // 3 revision id
},
"GET_AUDIT_ENTRIES6_TIME",
PGSQL_GET_AUDIT_ENTRIES_TIME(dhcp6)
},
// Retrieves a server by tag.
{
// PgSqlConfigBackendDHCPv6Impl::GET_SERVER6,
1,
{
OID_VARCHAR // 1 server_tag
},
"GET_SERVER6",
PGSQL_GET_SERVER(dhcp6)
},
// Retrieves all servers.
{
// PgSqlConfigBackendDHCPv6Impl::GET_ALL_SERVERS6,
0,
{
OID_NONE
},
"GET_ALL_SERVERS6",
PGSQL_GET_ALL_SERVERS(dhcp6)
},
// Insert global parameter.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_GLOBAL_PARAMETER6,
4,
{
OID_VARCHAR, // 1 name
OID_TEXT, // 2 value
OID_INT2, // 3 parameter_type
OID_TIMESTAMP // 4 modification_ts
},
"INSERT_GLOBAL_PARAMETER6",
PGSQL_INSERT_GLOBAL_PARAMETER(dhcp6)
},
// Insert association of the global parameter with a server.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_GLOBAL_PARAMETER6_SERVER,
3,
{
OID_INT8, // 1 parameter_id
OID_TIMESTAMP, // 2 modification_ts
OID_VARCHAR // 3 server_tag
},
"INSERT_GLOBAL_PARAMETER6_SERVER",
PGSQL_INSERT_GLOBAL_PARAMETER_SERVER(dhcp6)
},
// Insert a subnet.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_SUBNET6,
35,
{
OID_INT8, // 1 subnet_id,
OID_VARCHAR, // 2 subnet_prefix
OID_VARCHAR, // 3 client_class
OID_VARCHAR, // 4 interface
OID_TIMESTAMP, // 5 modification_ts
OID_INT8, // 6 preferred_lifetime
OID_INT8, // 7 min_preferred_lifetime
OID_INT8, // 8 max_preferred_lifetime
OID_BOOL, // 9 rapid_commit
OID_INT8, // 10 rebind_timer
OID_TEXT, // 11 relay
OID_INT8, // 12 renew_timer
OID_TEXT, // 13 evaluate_additional_classes
OID_BOOL, // 14 reservations_global
OID_VARCHAR, // 15 shared_network_name
OID_TEXT, // 16 user_context - cast as json
OID_INT8, // 17 valid_lifetime
OID_INT8, // 18 min_valid_lifetime
OID_INT8, // 19 max_valid_lifetime
OID_BOOL, // 20 calculate_tee_times
OID_TEXT, // 21 t1_percent - cast as float
OID_TEXT, // 22 t2_percent - cast as float
OID_BYTEA, // 23 interface_id
OID_BOOL, // 24 ddns_send_updates
OID_BOOL, // 25 ddns_override_no_update
OID_BOOL, // 26 ddns_override_client_update
OID_INT8, // 27 ddns_replace_client_name
OID_VARCHAR, // 28 ddns_generated_prefix
OID_VARCHAR, // 29 ddns_qualifying_suffix
OID_BOOL, // 30 reservations_in_subnet
OID_BOOL, // 31 reservations_out_of_pool
OID_TEXT, // 32 cache_threshold - cast as float
OID_INT8, // 33 cache_max_age
OID_VARCHAR, // 34 allocator
OID_VARCHAR // 35 pd_allocator
},
"INSERT_SUBNET6",
"INSERT INTO dhcp6_subnet("
" subnet_id,"
" subnet_prefix,"
" client_class,"
" interface,"
" modification_ts,"
" preferred_lifetime,"
" min_preferred_lifetime,"
" max_preferred_lifetime,"
" rapid_commit,"
" rebind_timer,"
" relay,"
" renew_timer,"
" evaluate_additional_classes,"
" reservations_global,"
" shared_network_name,"
" user_context,"
" valid_lifetime,"
" min_valid_lifetime,"
" max_valid_lifetime,"
" calculate_tee_times,"
" t1_percent,"
" t2_percent,"
" interface_id,"
" ddns_send_updates,"
" ddns_override_no_update,"
" ddns_override_client_update,"
" ddns_replace_client_name,"
" ddns_generated_prefix,"
" ddns_qualifying_suffix,"
" reservations_in_subnet,"
" reservations_out_of_pool,"
" cache_threshold,"
" cache_max_age,"
" allocator,"
" pd_allocator"
") VALUES ("
" $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, "
" $11, $12, $13, $14, $15, cast($16 as json), $17, $18, $19, $20, "
" cast($21 as float), cast($22 as float), $23, $24, $25, $26, $27, $28, $29, $30, "
" $31, cast($32 as float), $33, $34, $35"
")"
},
// Insert association of the subnet with a server.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_SUBNET6_SERVER,
3,
{
OID_INT8, // 1 subnet_id
OID_TIMESTAMP, // 2 modification_ts
OID_VARCHAR // 3 server_tag
},
"INSERT_SUBNET6_SERVER",
PGSQL_INSERT_SUBNET_SERVER(dhcp6)
},
// Insert pool for a subnet.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_POOL6,
7,
{
OID_TEXT, // 1 start_address - cast as inet
OID_TEXT, // 2 end_address - cast as inet
OID_INT8, // 3 subnet_id
OID_VARCHAR, // 4 client_class
OID_TEXT, // 5 evaluate_additional_classes
OID_TEXT, // 6 user_context - cast as json
OID_TIMESTAMP // 7 modification_ts
},
"INSERT_POOL6",
PGSQL_INSERT_POOL(dhcp6)
},
// Insert pd pool for a subnet.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_PD_POOL,
10,
{
OID_VARCHAR, // 1 prefix
OID_INT2, // 2 prefix_length
OID_INT2, // 3 delegated_prefix_length
OID_INT8, // 4 subnet_id
OID_VARCHAR, // 5 excluded_prefix
OID_INT2, // 6 excluded_prefix_length
OID_VARCHAR, // 7 client_class
OID_TEXT, // 8 evaluate_additional_classes
OID_TEXT, // 9 user_context - cast as json
OID_TIMESTAMP, // 10 modification_ts
},
"INSERT_PD_POOL",
PGSQL_INSERT_PD_POOL()
},
// Insert a shared network.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_SHARED_NETWORK6,
33,
{
OID_VARCHAR, // 1 name
OID_VARCHAR, // 2 client_class
OID_VARCHAR, // 3 interface
OID_TIMESTAMP, // 4 modification_ts
OID_INT8, // 5 preferred_lifetime
OID_INT8, // 6 min_preferred_lifetime
OID_INT8, // 7 max_preferred_lifetime
OID_BOOL, // 8 rapid_commit
OID_INT8, // 9 rebind_timer
OID_TEXT, // 10 relay
OID_INT8, // 11 renew_timer
OID_TEXT, // 12 evaluate_additional_classes
OID_BOOL, // 13 reservations_global
OID_TEXT, // 14 user_context - cast as json
OID_INT8, // 15 valid_lifetime
OID_INT8, // 16 min_valid_lifetime
OID_INT8, // 17 max_valid_lifetime
OID_BOOL, // 18 calculate_tee_times
OID_TEXT, // 19 t1_percent - cast as float
OID_TEXT, // 20 t2_percent - cast as float
OID_BYTEA, // 21 interface-id
OID_BOOL, // 22 ddns_send_updates
OID_BOOL, // 23 ddns_override_no_update
OID_BOOL, // 24 ddns_override_client_update
OID_INT8, // 25 ddns_replace_client_name
OID_VARCHAR, // 26 ddns_generated_prefix
OID_VARCHAR, // 27 ddns_qualifying_suffix
OID_BOOL, // 28 reservations_in_subnet
OID_BOOL, // 29 reservations_out_of_pool
OID_TEXT, // 30 cache_threshold - cast as float
OID_INT8, // 31 cache_max_age
OID_VARCHAR, // 32 allocator
OID_VARCHAR // 33 pd_allocator
},
"INSERT_SHARED_NETWORK6",
"INSERT INTO dhcp6_shared_network("
" name,"
" client_class,"
" interface,"
" modification_ts,"
" preferred_lifetime,"
" min_preferred_lifetime,"
" max_preferred_lifetime,"
" rapid_commit,"
" rebind_timer,"
" relay,"
" renew_timer,"
" evaluate_additional_classes,"
" reservations_global,"
" user_context,"
" valid_lifetime,"
" min_valid_lifetime,"
" max_valid_lifetime,"
" calculate_tee_times,"
" t1_percent,"
" t2_percent,"
" interface_id,"
" ddns_send_updates,"
" ddns_override_no_update,"
" ddns_override_client_update,"
" ddns_replace_client_name,"
" ddns_generated_prefix,"
" ddns_qualifying_suffix,"
" reservations_in_subnet,"
" reservations_out_of_pool,"
" cache_threshold,"
" cache_max_age,"
" allocator,"
" pd_allocator"
") VALUES ("
" $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, "
" $11, $12, $13, cast($14 as json), $15, $16, $17, $18,"
" cast($19 as float), cast($20 as float), $21, $22, $23,"
" $24, $25, $26, $27, $28, $29, cast($30 as float), $31, $32, $33"
")"
},
// Insert association of the shared network with a server.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_SHARED_NETWORK6_SERVER,
3,
{
OID_VARCHAR, // 1 shared_network_name
OID_TIMESTAMP, // 2 modification_ts
OID_VARCHAR // 3 server_tag
},
"INSERT_SHARED_NETWORK6_SERVER",
PGSQL_INSERT_SHARED_NETWORK_SERVER(dhcp6)
},
// Insert option definition.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_OPTION_DEF6,
10,
{
OID_INT2, // 1 code
OID_VARCHAR, // 2 name
OID_VARCHAR, // 3 space
OID_INT2, // 4 type
OID_TIMESTAMP, // 5 modification_ts
OID_BOOL, // 6 is_array
OID_VARCHAR, // 7 encapsulate
OID_VARCHAR, // 8 record_types
OID_VARCHAR, // 9 user_context
OID_INT8 // 10 class_id
},
"INSERT_OPTION_DEF6",
PGSQL_INSERT_OPTION_DEF(dhcp6)
},
// Insert option definition for client class.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_OPTION_DEF6_CLIENT_CLASS,
10,
{
OID_INT2, // 1 code
OID_VARCHAR, // 2 name
OID_VARCHAR, // 3 space
OID_INT2, // 4 type
OID_TIMESTAMP, // 5 modification_ts
OID_BOOL, // 6 is_array
OID_VARCHAR, // 7 encapsulate
OID_VARCHAR, // 8 record_types
OID_VARCHAR, // 9 user_context
OID_VARCHAR // 10 class name for where clause
},
"INSERT_OPTION_DEF6_CLIENT_CLASS",
PGSQL_INSERT_OPTION_DEF_CLIENT_CLASS(dhcp6)
},
// Insert association of the option definition with a server.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_OPTION_DEF6_SERVER,
3,
{
OID_INT8, // 1 option_def_id
OID_TIMESTAMP, // 2 modification_ts
OID_VARCHAR // 3 server_tag
},
"INSERT_OPTION_DEF6_SERVER",
PGSQL_INSERT_OPTION_DEF_SERVER(dhcp6)
},
// Insert subnet specific option.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_OPTION6,
15,
{
OID_INT2, // 1 code
OID_BYTEA, // 2 value
OID_TEXT, // 3 formatted_value
OID_VARCHAR, // 4 space
OID_BOOL, // 5 persistent
OID_BOOL, // 6 cancelled
OID_VARCHAR, // 7 dhcp_client_class
OID_INT8, // 8 dhcp6_subnet_id
OID_INT2, // 9 scope_id
OID_TEXT, // 10 user_context
OID_VARCHAR, // 11 shared_network_name
OID_INT8, // 12 pool_id
OID_TIMESTAMP, // 13 modification_ts
OID_TEXT, // 14 client_classes
OID_INT8 // 15 pd_pool_id
},
"INSERT_OPTION6",
PGSQL_INSERT_OPTION6()
},
// Insert association of the DHCP option with a server.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_OPTION6_SERVER,
3,
{
OID_INT8, // 1 option_id
OID_TIMESTAMP, // 2 modification_ts
OID_VARCHAR // 3 server_tag
},
"INSERT_OPTION6_SERVER",
PGSQL_INSERT_OPTION_SERVER(dhcp6)
},
// Insert client class.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_CLIENT_CLASS6,
13,
{
OID_VARCHAR, // 1 name
OID_TEXT, // 2 test
OID_BOOL, // 3 only_in_additional_list
OID_INT8, // 4 valid_lifetime
OID_INT8, // 5 min_valid_lifetime
OID_INT8, // 6 max_valid_lifetime
OID_BOOL, // 7 depend_on_known_directly
OID_VARCHAR, // 8 follow_class_name
OID_INT8, // 9 preferred_lifetime
OID_INT8, // 10 min_preferred_lifetime
OID_INT8, // 11 max_preferred_lifetime
OID_TIMESTAMP, // 12 modification_ts
OID_TEXT // 13 user_context cast as JSON
},
"INSERT_CLIENT_CLASS6",
"INSERT INTO dhcp6_client_class("
" name,"
" test,"
" only_in_additional_list,"
" valid_lifetime,"
" min_valid_lifetime,"
" max_valid_lifetime,"
" depend_on_known_directly,"
" follow_class_name,"
" preferred_lifetime,"
" min_preferred_lifetime,"
" max_preferred_lifetime,"
" modification_ts,"
" user_context "
") VALUES ("
" $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, cast($13 as JSON)"
")"
},
// Insert association of a client class with a server.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_CLIENT_CLASS6_SERVER,
3,
{
OID_VARCHAR, // 1 class_name
OID_TIMESTAMP, // 2 modification_ts
OID_VARCHAR // 3 server_tag
},
"INSERT_CLIENT_CLASS6_SERVER",
PGSQL_INSERT_CLIENT_CLASS_SERVER(dhcp6)
},
// Insert client class dependency.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_CLIENT_CLASS6_DEPENDENCY,
2,
{
OID_VARCHAR, // class name
OID_VARCHAR // dependency class name
},
"INSERT_CLIENT_CLASS6_DEPENDENCY",
PGSQL_INSERT_CLIENT_CLASS_DEPENDENCY(dhcp6)
},
// Insert server with server tag and description.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_SERVER6,
3,
{
OID_VARCHAR, // 1 server_tag
OID_VARCHAR, // 2 description
OID_TIMESTAMP // 3 modification_ts
},
"INSERT_SERVER6",
PGSQL_INSERT_SERVER(dhcp6)
},
// Update existing global parameter.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_GLOBAL_PARAMETER6,
6,
{
OID_VARCHAR, // 1 name
OID_TEXT, // 2 value
OID_INT2, // 3 parameter_type
OID_TIMESTAMP, // 4 modification_ts
OID_VARCHAR, // 5 server_tag
OID_VARCHAR, // 6 name (of global to update)
},
"UPDATE_GLOBAL_PARAMETER6",
PGSQL_UPDATE_GLOBAL_PARAMETER(dhcp6)
},
// Update existing subnet.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_SUBNET6,
37,
{
OID_INT8, // 1 subnet_id,
OID_VARCHAR, // 2 subnet_prefix
OID_VARCHAR, // 3 client_class
OID_VARCHAR, // 4 interface
OID_TIMESTAMP, // 5 modification_ts
OID_INT8, // 6 preferred_lifetime
OID_INT8, // 7 min_preferred_lifetime
OID_INT8, // 8 max_preferred_lifetime
OID_BOOL, // 9 rapid_commit
OID_INT8, // 10 rebind_timer
OID_TEXT, // 11 relay
OID_INT8, // 12 renew_timer
OID_TEXT, // 13 evaluate_additional_classes
OID_BOOL, // 14 reservations_global
OID_VARCHAR, // 15 shared_network_name
OID_TEXT, // 16 user_context - cast as json
OID_INT8, // 17 valid_lifetime
OID_INT8, // 18 min_valid_lifetime
OID_INT8, // 19 max_valid_lifetime
OID_BOOL, // 20 calculate_tee_times
OID_TEXT, // 21 t1_percent - cast as float
OID_TEXT, // 22 t2_percent - cast as float
OID_BYTEA, // 23 interface_id
OID_BOOL, // 24 ddns_send_updates
OID_BOOL, // 25 ddns_override_no_update
OID_BOOL, // 26 ddns_override_client_update
OID_INT8, // 27 ddns_replace_client_name
OID_VARCHAR, // 28 ddns_generated_prefix
OID_VARCHAR, // 29 ddns_qualifying_suffix
OID_BOOL, // 30 reservations_in_subnet
OID_BOOL, // 31 reservations_out_of_pool
OID_TEXT, // 32 cache_threshold - cast as float
OID_INT8, // 33 cache_max_age
OID_VARCHAR, // 34 allocator
OID_VARCHAR // 35 pd_allocator
},
"UPDATE_SUBNET6",
"UPDATE dhcp6_subnet SET"
" subnet_id = $1,"
" subnet_prefix = $2,"
" client_class = $3,"
" interface = $4,"
" modification_ts = $5,"
" preferred_lifetime = $6,"
" min_preferred_lifetime = $7,"
" max_preferred_lifetime = $8,"
" rapid_commit = $9,"
" rebind_timer = $10,"
" relay = $11,"
" renew_timer = $12,"
" evaluate_additional_classes = $13,"
" reservations_global = $14,"
" shared_network_name = $15,"
" user_context = cast($16 as json),"
" valid_lifetime = $17,"
" min_valid_lifetime = $18,"
" max_valid_lifetime = $19,"
" calculate_tee_times = $20,"
" t1_percent = cast($21 as float),"
" t2_percent = cast($22 as float),"
" interface_id = $23,"
" ddns_send_updates = $24,"
" ddns_override_no_update = $25,"
" ddns_override_client_update = $26,"
" ddns_replace_client_name = $27,"
" ddns_generated_prefix = $28,"
" ddns_qualifying_suffix = $29,"
" reservations_in_subnet = $30,"
" reservations_out_of_pool = $31,"
" cache_threshold = cast($32 as float),"
" cache_max_age = $33,"
" allocator = $34,"
" pd_allocator = $35 "
"WHERE subnet_id = $36 OR subnet_prefix = $37"
},
// Update existing shared network.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_SHARED_NETWORK6,
34,
{
OID_VARCHAR, // 1 name
OID_VARCHAR, // 2 client_class
OID_VARCHAR, // 3 interface
OID_TIMESTAMP, // 4 modification_ts
OID_INT8, // 5 preferred_lifetime
OID_INT8, // 6 min_preferred_lifetime
OID_INT8, // 7 max_preferred_lifetime
OID_BOOL, // 8 rapid_commit
OID_INT8, // 9 rebind_timer
OID_TEXT, // 10 relay
OID_INT8, // 11 renew_timer
OID_TEXT, // 12 evaluate_additional_classes
OID_BOOL, // 13 reservations_global
OID_TEXT, // 14 user_context - cast as json
OID_INT8, // 15 valid_lifetime
OID_INT8, // 16 min_valid_lifetime
OID_INT8, // 17 max_valid_lifetime
OID_BOOL, // 18 calculate_tee_times
OID_TEXT, // 19 t1_percent - cast as float
OID_TEXT, // 20 t2_percent - cast as float
OID_BYTEA, // 21 interface-id
OID_BOOL, // 22 ddns_send_updates
OID_BOOL, // 23 ddns_override_no_update
OID_BOOL, // 24 ddns_override_client_update
OID_INT8, // 25 ddns_replace_client_name
OID_VARCHAR, // 26 ddns_generated_prefix
OID_VARCHAR, // 27 ddns_qualifying_suffix
OID_BOOL, // 28 reservations_in_subnet
OID_BOOL, // 29 reservations_out_of_pool
OID_TEXT, // 30 cache_threshold - cast as float
OID_INT8, // 31 cache_max_age
OID_VARCHAR, // 32 allocator
OID_VARCHAR // 33 pd_allocator
},
"UPDATE_SHARED_NETWORK6",
"UPDATE dhcp6_shared_network SET"
" name = $1,"
" client_class = $2,"
" interface = $3,"
" modification_ts = $4,"
" preferred_lifetime = $5,"
" min_preferred_lifetime = $6,"
" max_preferred_lifetime = $7,"
" rapid_commit = $8,"
" rebind_timer = $9,"
" relay = $10,"
" renew_timer = $11,"
" evaluate_additional_classes = $12,"
" reservations_global = $13,"
" user_context = cast($14 as json),"
" valid_lifetime = $15,"
" min_valid_lifetime = $16,"
" max_valid_lifetime = $17,"
" calculate_tee_times = $18,"
" t1_percent = cast($19 as float),"
" t2_percent = cast($20 as float),"
" interface_id = $21,"
" ddns_send_updates = $22,"
" ddns_override_no_update = $23,"
" ddns_override_client_update = $24,"
" ddns_replace_client_name = $25,"
" ddns_generated_prefix = $26,"
" ddns_qualifying_suffix = $27,"
" reservations_in_subnet = $28,"
" reservations_out_of_pool = $29,"
" cache_threshold = cast($30 as float),"
" cache_max_age = $31,"
" allocator = $32,"
" pd_allocator = $33 "
"WHERE name = $34"
},
// Update existing option definition.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION_DEF6,
13,
{
OID_INT2, // 1 code
OID_VARCHAR, // 2 name
OID_VARCHAR, // 3 space
OID_INT2, // 4 type
OID_TIMESTAMP, // 5 modification_ts
OID_BOOL, // 6 is_array
OID_VARCHAR, // 7 encapsulate
OID_VARCHAR, // 8 record_types
OID_TEXT, // 9 user_context
OID_INT2, // 10 class_id
OID_VARCHAR, // 11 server_tag
OID_INT2, // 12 code (of option to update)
OID_VARCHAR, // 13 space (of option to update)
},
"UPDATE_OPTION_DEF6",
PGSQL_UPDATE_OPTION_DEF(dhcp6)
},
// Update existing client class option definition.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION_DEF6_CLIENT_CLASS,
13,
{
OID_INT2, // 1 code
OID_VARCHAR, // 2 name
OID_VARCHAR, // 3 space
OID_INT2, // 4 type
OID_TIMESTAMP, // 5 modification_ts
OID_BOOL, // 6 is_array
OID_VARCHAR, // 7 encapsulate
OID_VARCHAR, // 8 record_types
OID_TEXT, // 9 user_context
OID_VARCHAR, // 10 name (of class option belongs to)
OID_VARCHAR, // 11 server_tag
OID_INT2, // 12 code (of option to update)
OID_VARCHAR, // 13 space (of option to update)
},
"UPDATE_OPTION_DEF6_CLIENT_CLASS",
PGSQL_UPDATE_OPTION_DEF_CLIENT_CLASS(dhcp6)
},
// Update existing global option.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION6,
18,
{
OID_INT2, // 1 code
OID_BYTEA, // 2 value
OID_TEXT, // 3 formatted_value
OID_VARCHAR, // 4 space
OID_BOOL, // 5 persistent
OID_BOOL, // 6 cancelled
OID_VARCHAR, // 7 dhcp_client_class
OID_INT8, // 8 dhcp6_subnet_id
OID_INT2, // 9 scope_id
OID_TEXT, // 10 user_context
OID_VARCHAR, // 11 shared_network_name
OID_INT8, // 12 pool_id
OID_TIMESTAMP, // 13 modification_ts
OID_TEXT, // 14 client_classes
OID_INT8, // 15 pd_pool_id
OID_VARCHAR, // 16 server_tag
OID_INT2, // 17 code (of option to update)
OID_VARCHAR, // 18 space (of option to update)
},
"UPDATE_OPTION6",
PGSQL_UPDATE_OPTION6_WITH_TAG(AND o.scope_id = 0 AND o.code = $17 AND o.space = $18)
},
// Update existing subnet level option.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION6_SUBNET_ID,
18,
{
OID_INT2, // 1 code
OID_BYTEA, // 2 value
OID_TEXT, // 3 formatted_value
OID_VARCHAR, // 4 space
OID_BOOL, // 5 persistent
OID_BOOL, // 6 cancelled
OID_VARCHAR, // 7 dhcp_client_class
OID_INT8, // 8 dhcp6_subnet_id
OID_INT2, // 9 scope_id
OID_TEXT, // 10 user_context
OID_VARCHAR, // 11 shared_network_name
OID_INT8, // 12 pool_id
OID_TIMESTAMP, // 13 modification_ts
OID_TEXT, // 14 client_classes
OID_INT8, // 15 pd_pool_id
OID_INT8, // 16 subnet_id (of option to update)
OID_INT2, // 17 code (of option to update)
OID_VARCHAR // 18 space (of option to update)
},
"UPDATE_OPTION6_SUBNET_ID",
PGSQL_UPDATE_OPTION6_NO_TAG(o.scope_id = 1 AND o.dhcp6_subnet_id = $16 AND o.code = $17 AND o.space = $18)
},
// Update existing pool level option.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION6_POOL_ID,
18,
{
OID_INT2, // 1 code
OID_BYTEA, // 2 value
OID_TEXT, // 3 formatted_value
OID_VARCHAR, // 4 space
OID_BOOL, // 5 persistent
OID_BOOL, // 6 cancelled
OID_VARCHAR, // 7 dhcp_client_class
OID_INT8, // 8 dhcp6_subnet_id
OID_INT2, // 9 scope_id
OID_TEXT, // 10 user_context
OID_VARCHAR, // 11 shared_network_name
OID_INT8, // 12 pool_id
OID_TIMESTAMP, // 13 modification_ts
OID_TEXT, // 14 client_classes
OID_INT8, // 15 pd_pool_id
OID_INT8, // 16 pool_id (of option to update)
OID_INT2, // 17 code (of option to update)
OID_VARCHAR // 18 space (of option to update)
},
"UPDATE_OPTION6_POOL_ID",
PGSQL_UPDATE_OPTION6_NO_TAG(o.scope_id = 5 AND o.pool_id = $16 AND o.code = $17 AND o.space = $18)
},
// Update existing pd pool level option.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION6_PD_POOL_ID,
18,
{
OID_INT2, // 1 code
OID_BYTEA, // 2 value
OID_TEXT, // 3 formatted_value
OID_VARCHAR, // 4 space
OID_BOOL, // 5 persistent
OID_BOOL, // 6 cancelled
OID_VARCHAR, // 7 dhcp_client_class
OID_INT8, // 8 dhcp6_subnet_id
OID_INT2, // 9 scope_id
OID_TEXT, // 10 user_context
OID_VARCHAR, // 11 shared_network_name
OID_INT8, // 12 pool_id
OID_TIMESTAMP, // 13 modification_ts
OID_TEXT, // 14 client_classes
OID_INT8, // 15 pd_pool_id
OID_INT8, // 16 pd_pool_id (of option to update)
OID_INT2, // 17 code (of option to update)
OID_VARCHAR // 18 space (of option to update)
},
"UPDATE_OPTION6_PD_POOL_ID",
PGSQL_UPDATE_OPTION6_NO_TAG(o.scope_id = 6 AND o.pd_pool_id = $16 AND o.code = $17 AND o.space = $18)
},
// Update existing shared network level option.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION6_SHARED_NETWORK,
18,
{
OID_INT2, // 1 code
OID_BYTEA, // 2 value
OID_TEXT, // 3 formatted_value
OID_VARCHAR, // 4 space
OID_BOOL, // 5 persistent
OID_BOOL, // 6 cancelled
OID_VARCHAR, // 7 dhcp_client_class
OID_INT8, // 8 dhcp6_subnet_id
OID_INT2, // 9 scope_id
OID_TEXT, // 10 user_context
OID_VARCHAR, // 11 shared_network_name
OID_INT8, // 12 pool_id
OID_TIMESTAMP, // 13 modification_ts
OID_TEXT, // 14 client_classes
OID_INT8, // 15 pd_pool_id
OID_VARCHAR, // 16 shared_network_name (of option to update)
OID_INT2, // 17 code (of option to update)
OID_VARCHAR // 18 space (of option to update)
},
"UPDATE_OPTION6_SHARED_NETWORK",
PGSQL_UPDATE_OPTION6_NO_TAG(o.scope_id = 4 AND o.shared_network_name = $16 AND o.code = $17 AND o.space = $18)
},
// Update existing client class level option.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_OPTION6_CLIENT_CLASS,
18,
{
OID_INT2, // 1 code
OID_BYTEA, // 2 value
OID_TEXT, // 3 formatted_value
OID_VARCHAR, // 4 space
OID_BOOL, // 5 persistent
OID_BOOL, // 6 cancelled
OID_VARCHAR, // 7 dhcp_client_class
OID_INT8, // 8 dhcp6_subnet_id
OID_INT2, // 9 scope_id
OID_TEXT, // 10 user_context
OID_VARCHAR, // 11 shared_network_name
OID_INT8, // 12 pool_id
OID_TIMESTAMP, // 13 modification_ts
OID_TEXT, // 14 client_classes
OID_INT8, // 15 pd_pool_id
OID_VARCHAR, // 16 client_class (of option to update)
OID_INT2, // 17 code (of option to update)
OID_VARCHAR // 18 space (of option to update)
},
"UPDATE_OPTION6_CLIENT_CLASS",
PGSQL_UPDATE_OPTION6_NO_TAG(o.scope_id = 2 AND o.dhcp_client_class = $16 AND o.code = $17 AND o.space = $18)
},
// Update existing client class with specifying its position.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_CLIENT_CLASS6,
14,
{
OID_VARCHAR, // 1 name
OID_TEXT, // 2 test
OID_BOOL, // 3 only_in_additional_list
OID_INT8, // 4 valid_lifetime
OID_INT8, // 5 min_valid_lifetime
OID_INT8, // 6 max_valid_lifetime
OID_BOOL, // 7 depend_on_known_directly
OID_VARCHAR, // 8 follow_class_name
OID_INT8, // 9 preferred_lifetime
OID_INT8, // 10 min_preferred_lifetime
OID_INT8, // 11 max_preferred_lifetime
OID_TIMESTAMP, // 12 modification_ts
OID_TEXT, // 13 user_context
OID_VARCHAR // 14 name (of class to update)
},
"UPDATE_CLIENT_CLASS6",
PGSQL_UPDATE_CLIENT_CLASS6("follow_class_name = $8,")
},
// Update existing client class without specifying its position.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_CLIENT_CLASS6_SAME_POSITION,
14,
{
OID_VARCHAR, // 1 name
OID_TEXT, // 2 test
OID_BOOL, // 3 only_in_additional_list
OID_INT8, // 4 valid_lifetime
OID_INT8, // 5 min_valid_lifetime
OID_INT8, // 6 max_valid_lifetime
OID_BOOL, // 7 depend_on_known_directly
OID_VARCHAR, // 8 follow_class_name
OID_INT8, // 9 preferred_lifetime
OID_INT8, // 10 min_preferred_lifetime
OID_INT8, // 11 max_preferred_lifetime
OID_TIMESTAMP, // 12 modification_ts
OID_TEXT, // 13 user_context
OID_VARCHAR // 14 name (of class to update)
},
"UPDATE_CLIENT_CLASS6_SAME_POSITION",
PGSQL_UPDATE_CLIENT_CLASS6("")
},
// Update existing server, e.g. server description.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_SERVER6,
4,
{
OID_VARCHAR, // 1 tag
OID_VARCHAR, // 2 description
OID_TIMESTAMP, // 3 modification_ts
OID_VARCHAR // 4 tag (of server to update)
},
"UPDATE_SERVER6",
PGSQL_UPDATE_SERVER(dhcp6)
},
// Delete global parameter by name.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_GLOBAL_PARAMETER6,
2,
{
OID_VARCHAR, // 1 server_tag
OID_VARCHAR // 2 name of parameter
},
"DELETE_GLOBAL_PARAMETER6",
PGSQL_DELETE_GLOBAL_PARAMETER(dhcp6, AND g.name = $2)
},
// Delete all global parameters.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_GLOBAL_PARAMETERS6,
1,
{
OID_VARCHAR // 1 server_tag
},
"DELETE_ALL_GLOBAL_PARAMETERS6",
PGSQL_DELETE_GLOBAL_PARAMETER(dhcp6)
},
// Delete all global parameters which are unassigned to any servers.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_GLOBAL_PARAMETERS6_UNASSIGNED,
0,
{
OID_NONE
},
"DELETE_ALL_GLOBAL_PARAMETERS6_UNASSIGNED",
PGSQL_DELETE_GLOBAL_PARAMETER_UNASSIGNED(dhcp6)
},
// Delete subnet by id with specifying server tag.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_SUBNET6_ID_WITH_TAG,
2,
{
OID_VARCHAR, // 1 server_tag
OID_INT8 // 2 subnet_id
},
"DELETE_SUBNET6_ID_WITH_TAG",
PGSQL_DELETE_SUBNET_WITH_TAG(dhcp6, AND s.subnet_id = $2)
},
// Delete subnet by id without specifying server tag.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_SUBNET6_ID_ANY,
1,
{
OID_INT8 // 1 subnet_id
},
"DELETE_SUBNET6_ID_ANY",
PGSQL_DELETE_SUBNET_ANY(dhcp6, WHERE s.subnet_id = $1)
},
// Delete subnet by prefix with specifying server tag.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_SUBNET6_PREFIX_WITH_TAG,
2,
{
OID_VARCHAR, // 1 server_tag
OID_VARCHAR // 2 subnet_prefix
},
"DELETE_SUBNET6_PREFIX_WITH_TAG",
PGSQL_DELETE_SUBNET_WITH_TAG(dhcp6, AND s.subnet_prefix = $2)
},
// Delete subnet by prefix without specifying server tag.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_SUBNET6_PREFIX_ANY,
1,
{
OID_VARCHAR // 1 subnet_prefix
},
"DELETE_SUBNET6_PREFIX_ANY",
PGSQL_DELETE_SUBNET_ANY(dhcp6, WHERE s.subnet_prefix = $1)
},
// Delete all subnets.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_SUBNETS6,
1,
{
OID_VARCHAR // 1 server_tag
},
"DELETE_ALL_SUBNETS6",
PGSQL_DELETE_SUBNET_WITH_TAG(dhcp6)
},
// Delete all unassigned subnets.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_SUBNETS6_UNASSIGNED,
0,
{
OID_NONE
},
"DELETE_ALL_SUBNETS6_UNASSIGNED",
PGSQL_DELETE_SUBNET_UNASSIGNED(dhcp6)
},
// Delete all subnets for a shared network.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_SUBNETS6_SHARED_NETWORK_NAME,
1,
{
OID_VARCHAR // 1 shared_network_name
},
"DELETE_ALL_SUBNETS6_SHARED_NETWORK_NAME",
PGSQL_DELETE_SUBNET_ANY(dhcp6, WHERE s.shared_network_name = $1)
},
// Delete associations of a subnet with server.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_SUBNET6_SERVER,
1,
{
OID_INT8 // 1 subnet_id
},
"DELETE_SUBNET6_SERVER",
PGSQL_DELETE_SUBNET_SERVER(dhcp6),
},
// Delete pools for a subnet.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_POOLS6,
2,
{
OID_INT8, // 1 subnet_id
OID_VARCHAR // 2 subnet_prefix
},
"DELETE_POOLS6",
PGSQL_DELETE_POOLS(dhcp6)
},
// Delete pd pools for a subnet.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_PD_POOLS,
2,
{
OID_INT8, // 1 subnet_id
OID_VARCHAR // 2 subnet_prefix
},
"DELETE_PD_POOLS",
PGSQL_DELETE_PD_POOLS()
},
// Delete shared network by name with specifying server tag.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_SHARED_NETWORK6_NAME_WITH_TAG,
2,
{
OID_VARCHAR, // 1 server_tag
OID_VARCHAR // 2 shared_network_name
},
"DELETE_SHARED_NETWORK6_NAME_WITH_TAG",
PGSQL_DELETE_SHARED_NETWORK_WITH_TAG(dhcp6, AND n.name = $2)
},
// Delete shared network by name without specifying server tag.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_SHARED_NETWORK6_NAME_ANY,
1,
{
OID_VARCHAR // 1 shared_network_name
},
"DELETE_SHARED_NETWORK6_NAME_ANY",
PGSQL_DELETE_SHARED_NETWORK_ANY(dhcp6, WHERE n.name = $1)
},
// Delete all shared networks.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_SHARED_NETWORKS6,
1,
{
OID_VARCHAR // 1 server_tag
},
"DELETE_ALL_SHARED_NETWORKS6",
PGSQL_DELETE_SHARED_NETWORK_WITH_TAG(dhcp6)
},
// Delete all unassigned shared networks.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_SHARED_NETWORKS6_UNASSIGNED,
0,
{
OID_NONE
},
"DELETE_ALL_SHARED_NETWORKS6_UNASSIGNED",
PGSQL_DELETE_SHARED_NETWORK_UNASSIGNED(dhcp6)
},
// Delete associations of a shared network with server.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_SHARED_NETWORK6_SERVER,
1,
{
OID_VARCHAR // 1 shared_network_name
},
"DELETE_SHARED_NETWORK6_SERVER",
PGSQL_DELETE_SHARED_NETWORK_SERVER(dhcp6)
},
// Delete option definition.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_OPTION_DEF6_CODE_NAME,
3,
{
OID_VARCHAR, // 1 server_tag
OID_INT2, // 2 code
OID_VARCHAR // 3 space
},
"DELETE_OPTION_DEF6_CODE_NAME",
PGSQL_DELETE_OPTION_DEF(dhcp6, AND code = $2 AND space = $3)
},
// Delete all option definitions.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_OPTION_DEFS6,
1,
{
OID_VARCHAR // 1 server_tag
},
"DELETE_ALL_OPTION_DEFS6",
PGSQL_DELETE_OPTION_DEF(dhcp6)
},
// Delete all option definitions which are assigned to no servers.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_OPTION_DEFS6_UNASSIGNED,
0,
{
OID_NONE
},
"DELETE_ALL_OPTION_DEFS6_UNASSIGNED",
PGSQL_DELETE_OPTION_DEF_UNASSIGNED(dhcp6)
},
// Delete client class specific option definitions.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_OPTION_DEFS6_CLIENT_CLASS,
1,
{
OID_VARCHAR // 1 class name
},
"DELETE_OPTION_DEFS6_CLIENT_CLASS",
PGSQL_DELETE_OPTION_DEFS_CLIENT_CLASS(dhcp6)
},
// Delete single global option.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_OPTION6,
3,
{
OID_VARCHAR, // 1 server_tag
OID_INT2, // 2 code
OID_VARCHAR // 3 space
},
"DELETE_OPTION6",
PGSQL_DELETE_OPTION_WITH_TAG(dhcp6, AND o.scope_id = 0 AND o.code = $2 AND o.space = $3)
},
// Delete all global options which are unassigned to any servers.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_GLOBAL_OPTIONS6_UNASSIGNED,
0,
{
OID_NONE
},
"DELETE_ALL_GLOBAL_OPTIONS6_UNASSIGNED",
PGSQL_DELETE_OPTION_UNASSIGNED(dhcp6, AND o.scope_id = 0)
},
// Delete single option from a subnet.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_OPTION6_SUBNET_ID,
3,
{
OID_INT8, // 1 subnet_id
OID_INT2, // 2 code
OID_VARCHAR // 3 space
},
"DELETE_OPTION6_SUBNET_ID",
PGSQL_DELETE_OPTION_NO_TAG(dhcp6,
WHERE o.scope_id = 1 AND o.dhcp6_subnet_id = $1 AND o.code = $2 AND o.space = $3)
},
// Delete single option from a pool.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_OPTION6_POOL_RANGE,
4,
{
OID_TEXT, // 1 start_address - cast as inet
OID_TEXT, // 2 start_address - cast as inet
OID_INT2, // 3 code
OID_VARCHAR // 4 space
},
"DELETE_OPTION6_POOL_RANGE",
PGSQL_DELETE_OPTION_POOL_RANGE(dhcp6, o.scope_id = 5 AND o.code = $3 AND o.space = $4)
},
// Delete single option from a pd pool.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_OPTION6_PD_POOL,
4,
{
OID_TEXT, // 1 prefix
OID_INT2, // 2 prefix_length
OID_INT2, // 3 code
OID_VARCHAR // 4 space
},
"DELETE_OPTION6_PD_POOL",
PGSQL_DELETE_OPTION_PD_POOL(o.scope_id = 6 AND o.code = $3 AND o.space = $4)
},
// Delete single option from a shared network.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_OPTION6_SHARED_NETWORK,
3,
{
OID_VARCHAR, // 1 shared_network_name
OID_INT2, // 2 code
OID_VARCHAR // 3 space
},
"DELETE_OPTION6_SHARED_NETWORK",
PGSQL_DELETE_OPTION_NO_TAG(dhcp6,
WHERE o.scope_id = 4 AND o.shared_network_name = $1 AND o.code = $2 AND o.space = $3)
},
// Delete options belonging to a subnet.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_OPTIONS6_SUBNET_ID_PREFIX,
2,
{
OID_INT8, // 1 subnet_id
OID_VARCHAR // 2 subnet_prefix
},
"DELETE_OPTIONS6_SUBNET_ID_PREFIX",
PGSQL_DELETE_OPTION_SUBNET_ID_PREFIX(dhcp6)
},
// Delete options belonging to a shared_network.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_OPTIONS6_SHARED_NETWORK,
1,
{
OID_VARCHAR // shared_network_name
},
"DELETE_OPTIONS6_SHARED_NETWORK",
PGSQL_DELETE_OPTION_NO_TAG(dhcp6, WHERE o.scope_id = 4 AND o.shared_network_name = $1)
},
// Delete options belonging to a client class.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_OPTIONS6_CLIENT_CLASS,
1,
{
OID_VARCHAR // dhcp_client_class
},
"DELETE_OPTIONS6_CLIENT_CLASS",
PGSQL_DELETE_OPTION_NO_TAG(dhcp6, WHERE o.scope_id = 2 AND o.dhcp_client_class = $1)
},
// Delete all dependencies of a client class.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_CLIENT_CLASS6_DEPENDENCY,
1,
{
OID_VARCHAR, // 1 class name
},
"DELETE_CLIENT_CLASS6_DEPENDENCY",
PGSQL_DELETE_CLIENT_CLASS_DEPENDENCY(dhcp6)
},
// Delete associations of a client class with server.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_CLIENT_CLASS6_SERVER,
1,
{
OID_VARCHAR // 1 class name
},
"DELETE_CLIENT_CLASS6_SERVER",
PGSQL_DELETE_CLIENT_CLASS_SERVER(dhcp6),
},
// Delete all client classes.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_CLIENT_CLASSES6,
1,
{
OID_VARCHAR // 1 server_tag
},
"DELETE_ALL_CLIENT_CLASSES6",
PGSQL_DELETE_CLIENT_CLASS_WITH_TAG(dhcp6)
},
// Delete all unassigned client classes.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_CLIENT_CLASSES6_UNASSIGNED,
0,
{
OID_NONE
},
"DELETE_ALL_CLIENT_CLASSES6_UNASSIGNED",
PGSQL_DELETE_CLIENT_CLASS_UNASSIGNED(dhcp6)
},
// Delete specified client class.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_CLIENT_CLASS6,
2,
{
OID_VARCHAR, // 1 server_tag
OID_VARCHAR // 2 name
},
"DELETE_CLIENT_CLASS6",
PGSQL_DELETE_CLIENT_CLASS_WITH_TAG(dhcp6, AND name = $2)
},
// Delete any client class with a given name.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_CLIENT_CLASS6_ANY,
1,
{
OID_VARCHAR // 1 name
},
"DELETE_CLIENT_CLASS6_ANY",
PGSQL_DELETE_CLIENT_CLASS_ANY(dhcp6, AND name = $1)
},
// Delete a server by tag.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_SERVER6,
1,
{
OID_VARCHAR // server_tag
},
"DELETE_SERVER6",
PGSQL_DELETE_SERVER(dhcp6)
},
// Deletes all servers except logical server 'all'.
{
// PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_SERVERS6,
0,
{
OID_NONE
},
"DELETE_ALL_SERVERS6",
PGSQL_DELETE_ALL_SERVERS(dhcp6)
},
// Fetches the last sequence id for the given table and column.
{
// PgSqlConfigBackendDHCPv6Impl::GET_LAST_INSERT_ID6,
// args are: table name, sequence column name
2,
{
OID_VARCHAR,
OID_VARCHAR
},
"GET_LAST_INSERT_ID6",
"SELECT CURRVAL(PG_GET_SERIAL_SEQUENCE($1, $2))"
}
}
};
} // end anonymous namespace
PgSqlConfigBackendDHCPv6Impl::PgSqlConfigBackendDHCPv6Impl(const DatabaseConnection::ParameterMap& parameters)
: PgSqlConfigBackendImpl(std::string(cStringDhcpSpace<DHCPv6>()), parameters,
&PgSqlConfigBackendDHCPv6Impl::dbReconnect,
PgSqlConfigBackendDHCPv6Impl::GET_LAST_INSERT_ID6) {
// Prepare query statements. Those are will be only used to retrieve
// information from the database, so they can be used even if the
// database is read only for the current user.
conn_.prepareStatements(tagged_statements.begin(),
tagged_statements.end());
// @todo As part of enabling read-only CB access, statements need to
// be limited:
// tagged_statements.begin() + WRITE_STMTS_BEGIN);
}
PgSqlConfigBackendDHCPv6Impl::~PgSqlConfigBackendDHCPv6Impl() {
}
PgSqlTaggedStatement&
PgSqlConfigBackendDHCPv6Impl::getStatement(size_t index) const {
if (index >= tagged_statements.size()) {
isc_throw(BadValue, "PgSqlConfigBackendDHCPv6Impl::getStatement index: "
<< index << ", is invalid");
}
return(tagged_statements[index]);
}
PgSqlConfigBackendDHCPv6::PgSqlConfigBackendDHCPv6(const DatabaseConnection::ParameterMap& parameters)
: impl_(new PgSqlConfigBackendDHCPv6Impl(parameters)), base_impl_(impl_) {
}
bool
PgSqlConfigBackendDHCPv6::isUnusable() {
return (impl_->conn_.isUnusable());
}
DatabaseConnection::ParameterMap
PgSqlConfigBackendDHCPv6::getParameters() const {
return (impl_->getParameters());
}
Subnet6Ptr
PgSqlConfigBackendDHCPv6::getSubnet6(const ServerSelector& server_selector,
const std::string& subnet_prefix) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_SUBNET6_BY_PREFIX)
.arg(subnet_prefix);
return (impl_->getSubnet6(server_selector, subnet_prefix));
}
Subnet6Ptr
PgSqlConfigBackendDHCPv6::getSubnet6(const ServerSelector& server_selector,
const SubnetID& subnet_id) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_SUBNET6_BY_SUBNET_ID)
.arg(subnet_id);
return (impl_->getSubnet6(server_selector, subnet_id));
}
Subnet6Collection
PgSqlConfigBackendDHCPv6::getAllSubnets6(const ServerSelector& server_selector) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_ALL_SUBNETS6);
Subnet6Collection subnets;
impl_->getAllSubnets6(server_selector, subnets);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_ALL_SUBNETS6_RESULT)
.arg(subnets.size());
return (subnets);
}
Subnet6Collection
PgSqlConfigBackendDHCPv6::getModifiedSubnets6(const ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_MODIFIED_SUBNETS6)
.arg(util::ptimeToText(modification_time));
Subnet6Collection subnets;
impl_->getModifiedSubnets6(server_selector, modification_time, subnets);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_MODIFIED_SUBNETS6_RESULT)
.arg(subnets.size());
return (subnets);
}
Subnet6Collection
PgSqlConfigBackendDHCPv6::getSharedNetworkSubnets6(const ServerSelector& /* server_selector */,
const std::string& shared_network_name) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_SHARED_NETWORK_SUBNETS6)
.arg(shared_network_name);
Subnet6Collection subnets;
impl_->getSharedNetworkSubnets6(ServerSelector::ANY(), shared_network_name, subnets);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_SHARED_NETWORK_SUBNETS6_RESULT)
.arg(subnets.size());
return (subnets);
}
SharedNetwork6Ptr
PgSqlConfigBackendDHCPv6::getSharedNetwork6(const ServerSelector& server_selector,
const std::string& name) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_SHARED_NETWORK6)
.arg(name);
return (impl_->getSharedNetwork6(server_selector, name));
}
SharedNetwork6Collection
PgSqlConfigBackendDHCPv6::getAllSharedNetworks6(const ServerSelector& server_selector) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_ALL_SHARED_NETWORKS6);
SharedNetwork6Collection shared_networks;
impl_->getAllSharedNetworks6(server_selector, shared_networks);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_ALL_SHARED_NETWORKS6_RESULT)
.arg(shared_networks.size());
return (shared_networks);
}
SharedNetwork6Collection
PgSqlConfigBackendDHCPv6::getModifiedSharedNetworks6(const ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_MODIFIED_SHARED_NETWORKS6)
.arg(util::ptimeToText(modification_time));
SharedNetwork6Collection shared_networks;
impl_->getModifiedSharedNetworks6(server_selector, modification_time, shared_networks);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_MODIFIED_SHARED_NETWORKS6_RESULT)
.arg(shared_networks.size());
return (shared_networks);
}
OptionDefinitionPtr
PgSqlConfigBackendDHCPv6::getOptionDef6(const ServerSelector& server_selector,
const uint16_t code,
const std::string& space) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_OPTION_DEF6)
.arg(code).arg(space);
return (impl_->getOptionDef(PgSqlConfigBackendDHCPv6Impl::GET_OPTION_DEF6_CODE_SPACE,
server_selector, code, space));
}
OptionDefContainer
PgSqlConfigBackendDHCPv6::getAllOptionDefs6(const ServerSelector& server_selector) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_ALL_OPTION_DEFS6);
OptionDefContainer option_defs;
impl_->getAllOptionDefs(PgSqlConfigBackendDHCPv6Impl::GET_ALL_OPTION_DEFS6,
server_selector, option_defs);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_ALL_OPTION_DEFS6_RESULT)
.arg(option_defs.size());
return (option_defs);
}
OptionDefContainer
PgSqlConfigBackendDHCPv6::getModifiedOptionDefs6(const ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_MODIFIED_OPTION_DEFS6)
.arg(util::ptimeToText(modification_time));
OptionDefContainer option_defs;
impl_->getModifiedOptionDefs(PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_OPTION_DEFS6,
server_selector, modification_time, option_defs);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_MODIFIED_OPTION_DEFS6_RESULT)
.arg(option_defs.size());
return (option_defs);
}
OptionDescriptorPtr
PgSqlConfigBackendDHCPv6::getOption6(const ServerSelector& server_selector,
const uint16_t code,
const std::string& space) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_OPTION6)
.arg(code).arg(space);
return (impl_->getOption(PgSqlConfigBackendDHCPv6Impl::GET_OPTION6_CODE_SPACE,
Option::V6, server_selector, code, space));
}
OptionContainer
PgSqlConfigBackendDHCPv6::getAllOptions6(const ServerSelector& server_selector) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_ALL_OPTIONS6);
OptionContainer options = impl_->getAllOptions(PgSqlConfigBackendDHCPv6Impl::GET_ALL_OPTIONS6,
Option::V6, server_selector);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_ALL_OPTIONS6_RESULT)
.arg(options.size());
return (options);
}
OptionContainer
PgSqlConfigBackendDHCPv6::getModifiedOptions6(const ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_MODIFIED_OPTIONS6)
.arg(util::ptimeToText(modification_time));
OptionContainer options = impl_->getModifiedOptions(PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_OPTIONS6,
Option::V6, server_selector, modification_time);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_MODIFIED_OPTIONS6_RESULT)
.arg(options.size());
return (options);
}
StampedValuePtr
PgSqlConfigBackendDHCPv6::getGlobalParameter6(const ServerSelector& server_selector,
const std::string& name) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_GLOBAL_PARAMETER6)
.arg(name);
return (impl_->getGlobalParameter6(server_selector, name));
}
StampedValueCollection
PgSqlConfigBackendDHCPv6::getAllGlobalParameters6(const ServerSelector& server_selector) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_ALL_GLOBAL_PARAMETERS6);
StampedValueCollection parameters;
auto const& tags = server_selector.getTags();
for (auto const& tag : tags) {
PsqlBindArray in_bindings;
in_bindings.addTempString(tag.get());
impl_->getGlobalParameters(PgSqlConfigBackendDHCPv6Impl::GET_ALL_GLOBAL_PARAMETERS6,
in_bindings, parameters);
}
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_ALL_GLOBAL_PARAMETERS6_RESULT)
.arg(parameters.size());
return (parameters);
}
StampedValueCollection
PgSqlConfigBackendDHCPv6::getModifiedGlobalParameters6(const db::ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_MODIFIED_GLOBAL_PARAMETERS6)
.arg(util::ptimeToText(modification_time));
StampedValueCollection parameters;
auto const& tags = server_selector.getTags();
for (auto const& tag : tags) {
PsqlBindArray in_bindings;
in_bindings.addTempString(tag.get());
in_bindings.addTimestamp(modification_time);
impl_->getGlobalParameters(PgSqlConfigBackendDHCPv6Impl::GET_MODIFIED_GLOBAL_PARAMETERS6,
in_bindings, parameters);
}
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_MODIFIED_GLOBAL_PARAMETERS6_RESULT)
.arg(parameters.size());
return (parameters);
}
ClientClassDefPtr
PgSqlConfigBackendDHCPv6::getClientClass6(const db::ServerSelector& server_selector,
const std::string& name) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_CLIENT_CLASS6)
.arg(name);
return (impl_->getClientClass6(server_selector, name));
}
ClientClassDictionary
PgSqlConfigBackendDHCPv6::getAllClientClasses6(const db::ServerSelector& server_selector) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_ALL_CLIENT_CLASSES6);
ClientClassDictionary client_classes;
impl_->getAllClientClasses6(server_selector, client_classes);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_ALL_CLIENT_CLASSES6_RESULT)
.arg(client_classes.getClasses()->size());
return (client_classes);
}
ClientClassDictionary
PgSqlConfigBackendDHCPv6::getModifiedClientClasses6(const db::ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_MODIFIED_CLIENT_CLASSES6)
.arg(util::ptimeToText(modification_time));
ClientClassDictionary client_classes;
impl_->getModifiedClientClasses6(server_selector, modification_time, client_classes);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_MODIFIED_CLIENT_CLASSES6_RESULT)
.arg(client_classes.getClasses()->size());
return (client_classes);
}
AuditEntryCollection
PgSqlConfigBackendDHCPv6::getRecentAuditEntries(const db::ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time,
const uint64_t& modification_id) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_RECENT_AUDIT_ENTRIES6)
.arg(util::ptimeToText(modification_time))
.arg(modification_id);
AuditEntryCollection audit_entries;
impl_->getRecentAuditEntries(PgSqlConfigBackendDHCPv6Impl::GET_AUDIT_ENTRIES6_TIME,
server_selector, modification_time,
modification_id, audit_entries);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_RECENT_AUDIT_ENTRIES6_RESULT)
.arg(audit_entries.size());
return (audit_entries);
}
ServerCollection
PgSqlConfigBackendDHCPv6::getAllServers6() const {
ServerCollection servers;
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_ALL_SERVERS6);
impl_->getAllServers(PgSqlConfigBackendDHCPv6Impl::GET_ALL_SERVERS6,
servers);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_ALL_SERVERS6_RESULT)
.arg(servers.size());
return (servers);
}
ServerPtr
PgSqlConfigBackendDHCPv6::getServer6(const data::ServerTag& server_tag) const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_SERVER6)
.arg(server_tag.get());
return (impl_->getServer(PgSqlConfigBackendDHCPv6Impl::GET_SERVER6, server_tag));
}
void
PgSqlConfigBackendDHCPv6::createUpdateSubnet6(const ServerSelector& server_selector,
const Subnet6Ptr& subnet) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_CREATE_UPDATE_SUBNET6)
.arg(subnet);
impl_->createUpdateSubnet6(server_selector, subnet);
}
void
PgSqlConfigBackendDHCPv6::createUpdateSharedNetwork6(const ServerSelector& server_selector,
const SharedNetwork6Ptr& shared_network) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_CREATE_UPDATE_SHARED_NETWORK6)
.arg(shared_network->getName());
impl_->createUpdateSharedNetwork6(server_selector, shared_network);
}
void
PgSqlConfigBackendDHCPv6::createUpdateOptionDef6(const ServerSelector& server_selector,
const OptionDefinitionPtr& option_def) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_CREATE_UPDATE_OPTION_DEF6)
.arg(option_def->getName()).arg(option_def->getCode());
impl_->createUpdateOptionDef6(server_selector, option_def);
}
void
PgSqlConfigBackendDHCPv6::createUpdateOption6(const ServerSelector& server_selector,
const OptionDescriptorPtr& option) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_CREATE_UPDATE_OPTION6);
impl_->createUpdateOption6(server_selector, option);
}
void
PgSqlConfigBackendDHCPv6::createUpdateOption6(const db::ServerSelector& server_selector,
const std::string& shared_network_name,
const OptionDescriptorPtr& option) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_CREATE_UPDATE_SHARED_NETWORK_OPTION6)
.arg(shared_network_name);
impl_->createUpdateOption6(server_selector, shared_network_name, option, false);
}
void
PgSqlConfigBackendDHCPv6::createUpdateOption6(const ServerSelector& server_selector,
const SubnetID& subnet_id,
const OptionDescriptorPtr& option) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_CREATE_UPDATE_BY_SUBNET_ID_OPTION6)
.arg(subnet_id);
impl_->createUpdateOption6(server_selector, subnet_id, option, false);
}
void
PgSqlConfigBackendDHCPv6::createUpdateOption6(const ServerSelector& server_selector,
const asiolink::IOAddress& pool_start_address,
const asiolink::IOAddress& pool_end_address,
const OptionDescriptorPtr& option) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_CREATE_UPDATE_BY_POOL_OPTION6)
.arg(pool_start_address.toText()).arg(pool_end_address.toText());
impl_->createUpdateOption6(server_selector, pool_start_address, pool_end_address,
option);
}
void
PgSqlConfigBackendDHCPv6::createUpdateOption6(const ServerSelector& server_selector,
const asiolink::IOAddress& pd_pool_prefix,
const uint8_t pd_pool_prefix_length,
const OptionDescriptorPtr& option) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_CREATE_UPDATE_BY_PREFIX_OPTION6)
.arg(pd_pool_prefix.toText()).arg(pd_pool_prefix_length);
impl_->createUpdateOption6(server_selector, pd_pool_prefix,
pd_pool_prefix_length, option);
}
void
PgSqlConfigBackendDHCPv6::createUpdateGlobalParameter6(const ServerSelector& server_selector,
const StampedValuePtr& value) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_CREATE_UPDATE_GLOBAL_PARAMETER6)
.arg(value->getName());
impl_->createUpdateGlobalParameter6(server_selector, value);
}
void
PgSqlConfigBackendDHCPv6::createUpdateClientClass6(const db::ServerSelector& server_selector,
const ClientClassDefPtr& client_class,
const std::string& follow_class_name) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_CREATE_UPDATE_CLIENT_CLASS6)
.arg(client_class->getName());
impl_->createUpdateClientClass6(server_selector, client_class, follow_class_name);
}
void
PgSqlConfigBackendDHCPv6::createUpdateServer6(const ServerPtr& server) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_CREATE_UPDATE_SERVER6)
.arg(server->getServerTagAsText());
impl_->createUpdateServer(PgSqlConfigBackendDHCPv6Impl::CREATE_AUDIT_REVISION,
PgSqlConfigBackendDHCPv6Impl::INSERT_SERVER6,
PgSqlConfigBackendDHCPv6Impl::UPDATE_SERVER6,
server);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteSubnet6(const ServerSelector& server_selector,
const std::string& subnet_prefix) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_BY_PREFIX_SUBNET6)
.arg(subnet_prefix);
uint64_t result = impl_->deleteSubnet6(server_selector, subnet_prefix);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_BY_PREFIX_SUBNET6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteSubnet6(const ServerSelector& server_selector,
const SubnetID& subnet_id) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_BY_SUBNET_ID_SUBNET6)
.arg(subnet_id);
uint64_t result = impl_->deleteSubnet6(server_selector, subnet_id);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_BY_SUBNET_ID_SUBNET6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteAllSubnets6(const ServerSelector& server_selector) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_ALL_SUBNETS6);
int index = (server_selector.amUnassigned() ?
PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_SUBNETS6_UNASSIGNED :
PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_SUBNETS6);
uint64_t result = impl_->deleteTransactional(index, server_selector, "deleting all subnets",
"deleted all subnets", true);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_ALL_SUBNETS6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteSharedNetworkSubnets6(const db::ServerSelector& server_selector,
const std::string& shared_network_name) {
if (!server_selector.amAny()) {
isc_throw(InvalidOperation, "deleting all subnets from a shared "
"network requires using ANY server selector");
}
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_SHARED_NETWORK_SUBNETS6)
.arg(shared_network_name);
uint64_t result = impl_->deleteTransactional(PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_SUBNETS6_SHARED_NETWORK_NAME,
server_selector,
"deleting all subnets for a shared network",
"deleted all subnets for a shared network",
true, shared_network_name);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_SHARED_NETWORK_SUBNETS6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteSharedNetwork6(const ServerSelector& server_selector,
const std::string& name) {
/// @todo Using UNASSIGNED selector is allowed by the CB API but we don't have
/// dedicated query for this at the moment. The user should use ANY to delete
/// the shared network by name.
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "deleting an unassigned shared network requires "
"an explicit server tag or using ANY server. The UNASSIGNED server "
"selector is currently not supported");
}
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_SHARED_NETWORK6)
.arg(name);
int index = (server_selector.amAny() ?
PgSqlConfigBackendDHCPv6Impl::DELETE_SHARED_NETWORK6_NAME_ANY :
PgSqlConfigBackendDHCPv6Impl::DELETE_SHARED_NETWORK6_NAME_WITH_TAG);
uint64_t result = impl_->deleteTransactional(index, server_selector,
"deleting a shared network",
"shared network deleted", true, name);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_SHARED_NETWORK6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteAllSharedNetworks6(const ServerSelector& server_selector) {
if (server_selector.amAny()) {
isc_throw(InvalidOperation, "deleting all shared networks for ANY server is not"
" supported");
}
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_ALL_SHARED_NETWORKS6);
int index = (server_selector.amUnassigned() ?
PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_SHARED_NETWORKS6_UNASSIGNED :
PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_SHARED_NETWORKS6);
uint64_t result = impl_->deleteTransactional(index, server_selector, "deleting all shared networks",
"deleted all shared networks", true);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_ALL_SHARED_NETWORKS6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteOptionDef6(const ServerSelector& server_selector,
const uint16_t code,
const std::string& space) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_OPTION_DEF6)
.arg(code).arg(space);
uint64_t result = impl_->deleteOptionDef6(server_selector, code, space);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_OPTION_DEF6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteAllOptionDefs6(const ServerSelector& server_selector) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_ALL_OPTION_DEFS6);
uint64_t result = impl_->deleteTransactional(PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_OPTION_DEFS6,
server_selector, "deleting all option definitions",
"deleted all option definitions", true);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_ALL_OPTION_DEFS6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteOption6(const ServerSelector& server_selector,
const uint16_t code,
const std::string& space) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_OPTION6)
.arg(code).arg(space);
uint64_t result = impl_->deleteOption6(server_selector, code, space);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_OPTION6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteOption6(const ServerSelector& /* server_selector */,
const std::string& shared_network_name,
const uint16_t code,
const std::string& space) {
/// @todo In the future we might use the server selector to make sure that the
/// option is only deleted if the pool belongs to a given server. For now, we
/// just delete it when there is a match with the parent object.
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_SHARED_NETWORK_OPTION6)
.arg(shared_network_name).arg(code).arg(space);
uint64_t result = impl_->deleteOption6(ServerSelector::ANY(), shared_network_name,
code, space);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_SHARED_NETWORK_OPTION6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteOption6(const ServerSelector& /* server_selector */,
const SubnetID& subnet_id,
const uint16_t code,
const std::string& space) {
/// @todo In the future we might use the server selector to make sure that the
/// option is only deleted if the pool belongs to a given server. For now, we
/// just delete it when there is a match with the parent object.
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_BY_SUBNET_ID_OPTION6)
.arg(subnet_id).arg(code).arg(space);
uint64_t result = impl_->deleteOption6(ServerSelector::ANY(), subnet_id, code, space);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_BY_SUBNET_ID_OPTION6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteOption6(const ServerSelector& /* server_selector */,
const asiolink::IOAddress& pool_start_address,
const asiolink::IOAddress& pool_end_address,
const uint16_t code,
const std::string& space) {
/// @todo In the future we might use the server selector to make sure that the
/// option is only deleted if the pool belongs to a given server. For now, we
/// just delete it when there is a match with the parent object.
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_BY_POOL_OPTION6)
.arg(pool_start_address.toText()).arg(pool_end_address.toText()).arg(code).arg(space);
uint64_t result = impl_->deleteOption6(ServerSelector::ANY(), pool_start_address,
pool_end_address, code, space);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_BY_POOL_OPTION6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteOption6(const ServerSelector& /* server_selector */,
const asiolink::IOAddress& pd_pool_prefix,
const uint8_t pd_pool_prefix_length,
const uint16_t code,
const std::string& space) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_BY_POOL_PREFIX_OPTION6)
.arg(pd_pool_prefix.toText()).arg(pd_pool_prefix_length).arg(code).arg(space);
uint64_t result = impl_->deleteOption6(ServerSelector::ANY(), pd_pool_prefix,
pd_pool_prefix_length, code, space);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_BY_POOL_PREFIX_OPTION6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteGlobalParameter6(const ServerSelector& server_selector,
const std::string& name) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_GLOBAL_PARAMETER6)
.arg(name);
uint64_t result = impl_->deleteTransactional(PgSqlConfigBackendDHCPv6Impl::DELETE_GLOBAL_PARAMETER6,
server_selector, "deleting global parameter",
"global parameter deleted", false, name);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_GLOBAL_PARAMETER6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteAllGlobalParameters6(const ServerSelector& server_selector) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_ALL_GLOBAL_PARAMETERS6);
uint64_t result = impl_->deleteTransactional(PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_GLOBAL_PARAMETERS6,
server_selector, "deleting all global parameters",
"all global parameters deleted", true);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_ALL_GLOBAL_PARAMETERS6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteClientClass6(const db::ServerSelector& server_selector,
const std::string& name) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_CLIENT_CLASS6)
.arg(name);
auto result = impl_->deleteClientClass6(server_selector, name);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_CLIENT_CLASS6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteAllClientClasses6(const db::ServerSelector& server_selector) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_ALL_CLIENT_CLASSES6);
int index = (server_selector.amUnassigned() ?
PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_CLIENT_CLASSES6_UNASSIGNED :
PgSqlConfigBackendDHCPv6Impl::DELETE_ALL_CLIENT_CLASSES6);
uint64_t result = impl_->deleteTransactional(index, server_selector, "deleting all client classes",
"deleted all client classes", true);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_ALL_CLIENT_CLASSES6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteServer6(const ServerTag& server_tag) {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_SERVER6)
.arg(server_tag.get());
uint64_t result = impl_->deleteServer6(server_tag);
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_SERVER6_RESULT)
.arg(result);
return (result);
}
uint64_t
PgSqlConfigBackendDHCPv6::deleteAllServers6() {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_ALL_SERVERS6);
uint64_t result = impl_->deleteAllServers6();
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_DELETE_ALL_SERVERS6_RESULT)
.arg(result);
return (result);
}
std::string
PgSqlConfigBackendDHCPv6::getType() const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_TYPE6);
return (impl_->getType());
}
std::string
PgSqlConfigBackendDHCPv6::getHost() const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_HOST6);
return (impl_->getHost());
}
uint16_t
PgSqlConfigBackendDHCPv6::getPort() const {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_GET_PORT6);
return (impl_->getPort());
}
bool
PgSqlConfigBackendDHCPv6::registerBackendType() {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_REGISTER_BACKEND_TYPE6);
return (
dhcp::ConfigBackendDHCPv6Mgr::instance().registerBackendFactory("postgresql",
[](const db::DatabaseConnection::ParameterMap& params) -> dhcp::ConfigBackendDHCPv6Ptr {
return (dhcp::PgSqlConfigBackendDHCPv6Ptr(new dhcp::PgSqlConfigBackendDHCPv6(params)));
})
);
}
void
PgSqlConfigBackendDHCPv6::unregisterBackendType() {
LOG_DEBUG(pgsql_cb_logger, DBGLVL_TRACE_BASIC, PGSQL_CB_UNREGISTER_BACKEND_TYPE6);
dhcp::ConfigBackendDHCPv6Mgr::instance().unregisterBackendFactory("postgresql");
}
} // end of namespace isc::dhcp
} // end of namespace isc
|