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
|
/*
* Copyright (c) 2007-2012 Patrick McHardy <kaber@trash.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Development of this code funded by Astaro AG (http://www.astaro.com/)
*/
%{
#include <stddef.h>
#include <stdio.h>
#include <inttypes.h>
#include <syslog.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/if_ether.h>
#include <linux/netfilter.h>
#include <linux/netfilter/nf_tables.h>
#include <linux/netfilter/nf_conntrack_tuple_common.h>
#include <linux/netfilter/nf_nat.h>
#include <linux/netfilter/nf_log.h>
#include <linux/netfilter/nfnetlink_osf.h>
#include <linux/netfilter/nf_synproxy.h>
#include <linux/xfrm.h>
#include <netinet/ip_icmp.h>
#include <netinet/icmp6.h>
#include <libnftnl/common.h>
#include <libnftnl/set.h>
#include <libnftnl/udata.h>
#include <rule.h>
#include <statement.h>
#include <expression.h>
#include <headers.h>
#include <utils.h>
#include <parser.h>
#include <erec.h>
#include "parser_bison.h"
void parser_init(struct nft_ctx *nft, struct parser_state *state,
struct list_head *msgs, struct list_head *cmds,
struct scope *top_scope)
{
memset(state, 0, sizeof(*state));
state->msgs = msgs;
state->cmds = cmds;
state->scopes[0] = scope_init(top_scope, NULL);
init_list_head(&state->indesc_list);
}
static void yyerror(struct location *loc, struct nft_ctx *nft, void *scanner,
struct parser_state *state, const char *s)
{
erec_queue(error(loc, "%s", s), state->msgs);
}
static struct scope *current_scope(const struct parser_state *state)
{
return state->scopes[state->scope];
}
static void open_scope(struct parser_state *state, struct scope *scope)
{
assert(state->scope < array_size(state->scopes) - 1);
scope_init(scope, current_scope(state));
state->scopes[++state->scope] = scope;
}
static void close_scope(struct parser_state *state)
{
assert(state->scope > 0);
state->scope--;
}
static void location_init(void *scanner, struct parser_state *state,
struct location *loc)
{
memset(loc, 0, sizeof(*loc));
loc->indesc = state->indesc;
}
static void location_update(struct location *loc, struct location *rhs, int n)
{
if (n) {
loc->indesc = rhs[n].indesc;
loc->token_offset = rhs[1].token_offset;
loc->line_offset = rhs[1].line_offset;
loc->first_line = rhs[1].first_line;
loc->first_column = rhs[1].first_column;
loc->last_line = rhs[n].last_line;
loc->last_column = rhs[n].last_column;
} else {
loc->indesc = rhs[0].indesc;
loc->token_offset = rhs[0].token_offset;
loc->line_offset = rhs[0].line_offset;
loc->first_line = loc->last_line = rhs[0].last_line;
loc->first_column = loc->last_column = rhs[0].last_column;
}
}
static struct expr *handle_concat_expr(const struct location *loc,
struct expr *expr,
struct expr *expr_l, struct expr *expr_r,
struct location loc_rhs[3])
{
if (expr->etype != EXPR_CONCAT) {
expr = concat_expr_alloc(loc);
compound_expr_add(expr, expr_l);
} else {
location_update(&expr_r->location, loc_rhs, 2);
expr = expr_l;
expr->location = *loc;
}
compound_expr_add(expr, expr_r);
return expr;
}
#define YYLLOC_DEFAULT(Current, Rhs, N) location_update(&Current, Rhs, N)
#define symbol_value(loc, str) \
symbol_expr_alloc(loc, SYMBOL_VALUE, current_scope(state), str)
/* Declare those here to avoid compiler warnings */
void nft_set_debug(int, void *);
int nft_lex(void *, void *, void *);
%}
/* Declaration section */
%name-prefix "nft_"
%debug
%define api.pure
%parse-param { struct nft_ctx *nft }
%parse-param { void *scanner }
%parse-param { struct parser_state *state }
%lex-param { scanner }
%define parse.error verbose
%locations
%initial-action {
location_init(scanner, state, &yylloc);
if (nft->debug_mask & NFT_DEBUG_SCANNER)
nft_set_debug(1, scanner);
if (nft->debug_mask & NFT_DEBUG_PARSER)
yydebug = 1;
}
%union {
uint64_t val;
uint32_t val32;
uint8_t val8;
const char * string;
struct list_head *list;
struct cmd *cmd;
struct handle handle;
struct table *table;
struct chain *chain;
struct rule *rule;
struct stmt *stmt;
struct expr *expr;
struct set *set;
struct obj *obj;
struct flowtable *flowtable;
struct ct *ct;
const struct datatype *datatype;
struct handle_spec handle_spec;
struct position_spec position_spec;
struct prio_spec prio_spec;
const struct exthdr_desc *exthdr_desc;
}
%token TOKEN_EOF 0 "end of file"
%token JUNK "junk"
%token NEWLINE "newline"
%token COLON "colon"
%token SEMICOLON "semicolon"
%token COMMA "comma"
%token DOT "."
%token EQ "=="
%token NEQ "!="
%token LT "<"
%token GT ">"
%token GTE ">="
%token LTE "<="
%token LSHIFT "<<"
%token RSHIFT ">>"
%token AMPERSAND "&"
%token CARET "^"
%token NOT "!"
%token SLASH "/"
%token ASTERISK "*"
%token DASH "-"
%token AT "@"
%token VMAP "vmap"
%token PLUS "+"
%token INCLUDE "include"
%token DEFINE "define"
%token REDEFINE "redefine"
%token UNDEFINE "undefine"
%token FIB "fib"
%token SOCKET "socket"
%token TRANSPARENT "transparent"
%token TPROXY "tproxy"
%token OSF "osf"
%token SYNPROXY "synproxy"
%token MSS "mss"
%token WSCALE "wscale"
%token SACKPERM "sack-perm"
%token TYPEOF "typeof"
%token HOOK "hook"
%token DEVICE "device"
%token DEVICES "devices"
%token TABLE "table"
%token TABLES "tables"
%token CHAIN "chain"
%token CHAINS "chains"
%token RULE "rule"
%token RULES "rules"
%token SETS "sets"
%token SET "set"
%token ELEMENT "element"
%token MAP "map"
%token MAPS "maps"
%token FLOWTABLE "flowtable"
%token HANDLE "handle"
%token RULESET "ruleset"
%token TRACE "trace"
%token INET "inet"
%token NETDEV "netdev"
%token ADD "add"
%token UPDATE "update"
%token REPLACE "replace"
%token CREATE "create"
%token INSERT "insert"
%token DELETE "delete"
%token GET "get"
%token LIST "list"
%token RESET "reset"
%token FLUSH "flush"
%token RENAME "rename"
%token DESCRIBE "describe"
%token IMPORT "import"
%token EXPORT "export"
%token MONITOR "monitor"
%token ALL "all"
%token ACCEPT "accept"
%token DROP "drop"
%token CONTINUE "continue"
%token JUMP "jump"
%token GOTO "goto"
%token RETURN "return"
%token TO "to"
%token CONSTANT "constant"
%token INTERVAL "interval"
%token DYNAMIC "dynamic"
%token AUTOMERGE "auto-merge"
%token TIMEOUT "timeout"
%token GC_INTERVAL "gc-interval"
%token ELEMENTS "elements"
%token EXPIRES "expires"
%token POLICY "policy"
%token MEMORY "memory"
%token PERFORMANCE "performance"
%token SIZE "size"
%token FLOW "flow"
%token OFFLOAD "offload"
%token METER "meter"
%token METERS "meters"
%token FLOWTABLES "flowtables"
%token <val> NUM "number"
%token <string> STRING "string"
%token <string> QUOTED_STRING "quoted string"
%token <string> ASTERISK_STRING "string with a trailing asterisk"
%destructor { xfree($$); } STRING QUOTED_STRING ASTERISK_STRING
%token LL_HDR "ll"
%token NETWORK_HDR "nh"
%token TRANSPORT_HDR "th"
%token BRIDGE "bridge"
%token ETHER "ether"
%token SADDR "saddr"
%token DADDR "daddr"
%token TYPE "type"
%token VLAN "vlan"
%token ID "id"
%token CFI "cfi"
%token PCP "pcp"
%token ARP "arp"
%token HTYPE "htype"
%token PTYPE "ptype"
%token HLEN "hlen"
%token PLEN "plen"
%token OPERATION "operation"
%token IP "ip"
%token HDRVERSION "version"
%token HDRLENGTH "hdrlength"
%token DSCP "dscp"
%token ECN "ecn"
%token LENGTH "length"
%token FRAG_OFF "frag-off"
%token TTL "ttl"
%token PROTOCOL "protocol"
%token CHECKSUM "checksum"
%token PTR "ptr"
%token VALUE "value"
%token LSRR "lsrr"
%token RR "rr"
%token SSRR "ssrr"
%token RA "ra"
%token ICMP "icmp"
%token CODE "code"
%token SEQUENCE "seq"
%token GATEWAY "gateway"
%token MTU "mtu"
%token IGMP "igmp"
%token MRT "mrt"
%token OPTIONS "options"
%token IP6 "ip6"
%token PRIORITY "priority"
%token FLOWLABEL "flowlabel"
%token NEXTHDR "nexthdr"
%token HOPLIMIT "hoplimit"
%token ICMP6 "icmpv6"
%token PPTR "param-problem"
%token MAXDELAY "max-delay"
%token AH "ah"
%token RESERVED "reserved"
%token SPI "spi"
%token ESP "esp"
%token COMP "comp"
%token FLAGS "flags"
%token CPI "cpi"
%token PORT "port"
%token UDP "udp"
%token SPORT "sport"
%token DPORT "dport"
%token UDPLITE "udplite"
%token CSUMCOV "csumcov"
%token TCP "tcp"
%token ACKSEQ "ackseq"
%token DOFF "doff"
%token WINDOW "window"
%token URGPTR "urgptr"
%token OPTION "option"
%token ECHO "echo"
%token EOL "eol"
%token MAXSEG "maxseg"
%token NOOP "noop"
%token SACK "sack"
%token SACK0 "sack0"
%token SACK1 "sack1"
%token SACK2 "sack2"
%token SACK3 "sack3"
%token SACK_PERMITTED "sack-permitted"
%token TIMESTAMP "timestamp"
%token KIND "kind"
%token COUNT "count"
%token LEFT "left"
%token RIGHT "right"
%token TSVAL "tsval"
%token TSECR "tsecr"
%token DCCP "dccp"
%token SCTP "sctp"
%token VTAG "vtag"
%token RT "rt"
%token RT0 "rt0"
%token RT2 "rt2"
%token RT4 "srh"
%token SEG_LEFT "seg-left"
%token ADDR "addr"
%token LAST_ENT "last-entry"
%token TAG "tag"
%token SID "sid"
%token HBH "hbh"
%token FRAG "frag"
%token RESERVED2 "reserved2"
%token MORE_FRAGMENTS "more-fragments"
%token DST "dst"
%token MH "mh"
%token META "meta"
%token MARK "mark"
%token IIF "iif"
%token IIFNAME "iifname"
%token IIFTYPE "iiftype"
%token OIF "oif"
%token OIFNAME "oifname"
%token OIFTYPE "oiftype"
%token SKUID "skuid"
%token SKGID "skgid"
%token NFTRACE "nftrace"
%token RTCLASSID "rtclassid"
%token IBRIPORT "ibriport"
%token OBRIPORT "obriport"
%token IBRIDGENAME "ibrname"
%token OBRIDGENAME "obrname"
%token PKTTYPE "pkttype"
%token CPU "cpu"
%token IIFGROUP "iifgroup"
%token OIFGROUP "oifgroup"
%token CGROUP "cgroup"
%token TIME "time"
%token CLASSID "classid"
%token NEXTHOP "nexthop"
%token CT "ct"
%token L3PROTOCOL "l3proto"
%token PROTO_SRC "proto-src"
%token PROTO_DST "proto-dst"
%token ZONE "zone"
%token DIRECTION "direction"
%token EVENT "event"
%token EXPECTATION "expectation"
%token EXPIRATION "expiration"
%token HELPER "helper"
%token LABEL "label"
%token STATE "state"
%token STATUS "status"
%token ORIGINAL "original"
%token REPLY "reply"
%token COUNTER "counter"
%token NAME "name"
%token PACKETS "packets"
%token BYTES "bytes"
%token AVGPKT "avgpkt"
%token COUNTERS "counters"
%token QUOTAS "quotas"
%token LIMITS "limits"
%token SYNPROXYS "synproxys"
%token HELPERS "helpers"
%token LOG "log"
%token PREFIX "prefix"
%token GROUP "group"
%token SNAPLEN "snaplen"
%token QUEUE_THRESHOLD "queue-threshold"
%token LEVEL "level"
%token LIMIT "limit"
%token RATE "rate"
%token BURST "burst"
%token OVER "over"
%token UNTIL "until"
%token QUOTA "quota"
%token USED "used"
%token SECMARK "secmark"
%token SECMARKS "secmarks"
%token NANOSECOND "nanosecond"
%token MICROSECOND "microsecond"
%token MILLISECOND "millisecond"
%token SECOND "second"
%token MINUTE "minute"
%token HOUR "hour"
%token DAY "day"
%token WEEK "week"
%token _REJECT "reject"
%token WITH "with"
%token ICMPX "icmpx"
%token SNAT "snat"
%token DNAT "dnat"
%token MASQUERADE "masquerade"
%token REDIRECT "redirect"
%token RANDOM "random"
%token FULLY_RANDOM "fully-random"
%token PERSISTENT "persistent"
%token QUEUE "queue"
%token QUEUENUM "num"
%token BYPASS "bypass"
%token FANOUT "fanout"
%token DUP "dup"
%token FWD "fwd"
%token NUMGEN "numgen"
%token INC "inc"
%token MOD "mod"
%token OFFSET "offset"
%token JHASH "jhash"
%token SYMHASH "symhash"
%token SEED "seed"
%token POSITION "position"
%token INDEX "index"
%token COMMENT "comment"
%token XML "xml"
%token JSON "json"
%token VM "vm"
%token NOTRACK "notrack"
%token EXISTS "exists"
%token MISSING "missing"
%token EXTHDR "exthdr"
%token IPSEC "ipsec"
%token MODE "mode"
%token REQID "reqid"
%token SPNUM "spnum"
%token TRANSPORT "transport"
%token TUNNEL "tunnel"
%token IN "in"
%token OUT "out"
%type <string> identifier type_identifier string comment_spec
%destructor { xfree($$); } identifier type_identifier string comment_spec
%type <val> time_spec quota_used
%type <expr> data_type_expr data_type_atom_expr
%destructor { expr_free($$); } data_type_expr data_type_atom_expr
%type <cmd> line
%destructor { cmd_free($$); } line
%type <cmd> base_cmd add_cmd replace_cmd create_cmd insert_cmd delete_cmd get_cmd list_cmd reset_cmd flush_cmd rename_cmd export_cmd monitor_cmd describe_cmd import_cmd
%destructor { cmd_free($$); } base_cmd add_cmd replace_cmd create_cmd insert_cmd delete_cmd get_cmd list_cmd reset_cmd flush_cmd rename_cmd export_cmd monitor_cmd describe_cmd import_cmd
%type <handle> table_spec tableid_spec chain_spec chainid_spec flowtable_spec chain_identifier ruleid_spec handle_spec position_spec rule_position ruleset_spec index_spec
%destructor { handle_free(&$$); } table_spec tableid_spec chain_spec chainid_spec flowtable_spec chain_identifier ruleid_spec handle_spec position_spec rule_position ruleset_spec index_spec
%type <handle> set_spec setid_spec set_identifier flowtableid_spec flowtable_identifier obj_spec objid_spec obj_identifier
%destructor { handle_free(&$$); } set_spec setid_spec set_identifier flowtableid_spec obj_spec objid_spec obj_identifier
%type <val> family_spec family_spec_explicit
%type <val32> int_num chain_policy
%type <prio_spec> extended_prio_spec prio_spec
%type <string> extended_prio_name quota_unit
%destructor { xfree($$); } extended_prio_name quota_unit
%type <expr> dev_spec
%destructor { xfree($$); } dev_spec
%type <table> table_block_alloc table_block
%destructor { close_scope(state); table_free($$); } table_block_alloc
%type <chain> chain_block_alloc chain_block subchain_block
%destructor { close_scope(state); chain_free($$); } chain_block_alloc subchain_block
%type <rule> rule rule_alloc
%destructor { rule_free($$); } rule
%type <val> set_flag_list set_flag
%type <val> set_policy_spec
%type <set> set_block_alloc set_block
%destructor { set_free($$); } set_block_alloc
%type <set> map_block_alloc map_block
%destructor { set_free($$); } map_block_alloc
%type <flowtable> flowtable_block_alloc flowtable_block
%destructor { flowtable_free($$); } flowtable_block_alloc
%type <obj> obj_block_alloc counter_block quota_block ct_helper_block ct_timeout_block ct_expect_block limit_block secmark_block synproxy_block
%destructor { obj_free($$); } obj_block_alloc
%type <list> stmt_list
%destructor { stmt_list_free($$); xfree($$); } stmt_list
%type <stmt> stmt match_stmt verdict_stmt
%destructor { stmt_free($$); } stmt match_stmt verdict_stmt
%type <stmt> counter_stmt counter_stmt_alloc stateful_stmt
%destructor { stmt_free($$); } counter_stmt counter_stmt_alloc stateful_stmt
%type <stmt> payload_stmt
%destructor { stmt_free($$); } payload_stmt
%type <stmt> ct_stmt
%destructor { stmt_free($$); } ct_stmt
%type <stmt> meta_stmt
%destructor { stmt_free($$); } meta_stmt
%type <stmt> log_stmt log_stmt_alloc
%destructor { stmt_free($$); } log_stmt log_stmt_alloc
%type <val> level_type log_flags log_flags_tcp log_flag_tcp
%type <stmt> limit_stmt quota_stmt connlimit_stmt
%destructor { stmt_free($$); } limit_stmt quota_stmt connlimit_stmt
%type <val> limit_burst_pkts limit_burst_bytes limit_mode time_unit quota_mode
%type <stmt> reject_stmt reject_stmt_alloc
%destructor { stmt_free($$); } reject_stmt reject_stmt_alloc
%type <stmt> nat_stmt nat_stmt_alloc masq_stmt masq_stmt_alloc redir_stmt redir_stmt_alloc
%destructor { stmt_free($$); } nat_stmt nat_stmt_alloc masq_stmt masq_stmt_alloc redir_stmt redir_stmt_alloc
%type <val> nf_nat_flags nf_nat_flag offset_opt
%type <stmt> tproxy_stmt
%destructor { stmt_free($$); } tproxy_stmt
%type <stmt> synproxy_stmt synproxy_stmt_alloc
%destructor { stmt_free($$); } synproxy_stmt synproxy_stmt_alloc
%type <stmt> chain_stmt
%destructor { stmt_free($$); } chain_stmt
%type <val> chain_stmt_type
%type <stmt> queue_stmt queue_stmt_alloc
%destructor { stmt_free($$); } queue_stmt queue_stmt_alloc
%type <val> queue_stmt_flags queue_stmt_flag
%type <stmt> dup_stmt
%destructor { stmt_free($$); } dup_stmt
%type <stmt> fwd_stmt
%destructor { stmt_free($$); } fwd_stmt
%type <stmt> set_stmt
%destructor { stmt_free($$); } set_stmt
%type <val> set_stmt_op
%type <stmt> map_stmt
%destructor { stmt_free($$); } map_stmt
%type <stmt> meter_stmt meter_stmt_alloc flow_stmt_legacy_alloc
%destructor { stmt_free($$); } meter_stmt meter_stmt_alloc flow_stmt_legacy_alloc
%type <expr> symbol_expr verdict_expr integer_expr variable_expr chain_expr policy_expr
%destructor { expr_free($$); } symbol_expr verdict_expr integer_expr variable_expr chain_expr policy_expr
%type <expr> primary_expr shift_expr and_expr typeof_expr
%destructor { expr_free($$); } primary_expr shift_expr and_expr typeof_expr
%type <expr> exclusive_or_expr inclusive_or_expr
%destructor { expr_free($$); } exclusive_or_expr inclusive_or_expr
%type <expr> basic_expr
%destructor { expr_free($$); } basic_expr
%type <expr> set_ref_expr set_ref_symbol_expr
%destructor { expr_free($$); } set_ref_expr set_ref_symbol_expr
%type <expr> multiton_rhs_expr
%destructor { expr_free($$); } multiton_rhs_expr
%type <expr> prefix_rhs_expr range_rhs_expr
%destructor { expr_free($$); } prefix_rhs_expr range_rhs_expr
%type <expr> stmt_expr concat_stmt_expr map_stmt_expr map_stmt_expr_set
%destructor { expr_free($$); } stmt_expr concat_stmt_expr map_stmt_expr map_stmt_expr_set
%type <expr> multiton_stmt_expr
%destructor { expr_free($$); } multiton_stmt_expr
%type <expr> prefix_stmt_expr range_stmt_expr wildcard_expr
%destructor { expr_free($$); } prefix_stmt_expr range_stmt_expr wildcard_expr
%type <expr> primary_stmt_expr basic_stmt_expr
%destructor { expr_free($$); } primary_stmt_expr basic_stmt_expr
%type <expr> list_stmt_expr shift_stmt_expr
%destructor { expr_free($$); } list_stmt_expr shift_stmt_expr
%type <expr> and_stmt_expr exclusive_or_stmt_expr inclusive_or_stmt_expr
%destructor { expr_free($$); } and_stmt_expr exclusive_or_stmt_expr inclusive_or_stmt_expr
%type <expr> concat_expr
%destructor { expr_free($$); } concat_expr
%type <expr> map_expr
%destructor { expr_free($$); } map_expr
%type <expr> verdict_map_stmt
%destructor { expr_free($$); } verdict_map_stmt
%type <expr> verdict_map_expr verdict_map_list_expr verdict_map_list_member_expr
%destructor { expr_free($$); } verdict_map_expr verdict_map_list_expr verdict_map_list_member_expr
%type <expr> set_expr set_block_expr set_list_expr set_list_member_expr flowtable_expr flowtable_list_expr flowtable_expr_member
%destructor { expr_free($$); } set_expr set_block_expr set_list_expr set_list_member_expr flowtable_expr flowtable_list_expr flowtable_expr_member
%type <expr> set_elem_expr set_elem_expr_alloc set_lhs_expr set_rhs_expr
%destructor { expr_free($$); } set_elem_expr set_elem_expr_alloc set_lhs_expr set_rhs_expr
%type <expr> set_elem_expr_stmt set_elem_expr_stmt_alloc
%destructor { expr_free($$); } set_elem_expr_stmt set_elem_expr_stmt_alloc
%type <expr> meter_key_expr meter_key_expr_alloc
%destructor { expr_free($$); } meter_key_expr meter_key_expr_alloc
%type <expr> expr initializer_expr keyword_expr
%destructor { expr_free($$); } expr initializer_expr keyword_expr
%type <expr> rhs_expr concat_rhs_expr basic_rhs_expr
%destructor { expr_free($$); } rhs_expr concat_rhs_expr basic_rhs_expr
%type <expr> primary_rhs_expr list_rhs_expr shift_rhs_expr symbol_stmt_expr
%destructor { expr_free($$); } primary_rhs_expr list_rhs_expr shift_rhs_expr symbol_stmt_expr
%type <expr> and_rhs_expr exclusive_or_rhs_expr inclusive_or_rhs_expr
%destructor { expr_free($$); } and_rhs_expr exclusive_or_rhs_expr inclusive_or_rhs_expr
%type <obj> counter_obj quota_obj ct_obj_alloc limit_obj secmark_obj synproxy_obj
%destructor { obj_free($$); } counter_obj quota_obj ct_obj_alloc limit_obj secmark_obj synproxy_obj
%type <expr> relational_expr
%destructor { expr_free($$); } relational_expr
%type <val> relational_op
%type <expr> payload_expr payload_raw_expr
%destructor { expr_free($$); } payload_expr payload_raw_expr
%type <val> payload_base_spec
%type <expr> eth_hdr_expr vlan_hdr_expr
%destructor { expr_free($$); } eth_hdr_expr vlan_hdr_expr
%type <val> eth_hdr_field vlan_hdr_field
%type <expr> arp_hdr_expr
%destructor { expr_free($$); } arp_hdr_expr
%type <val> arp_hdr_field
%type <expr> ip_hdr_expr icmp_hdr_expr igmp_hdr_expr numgen_expr hash_expr
%destructor { expr_free($$); } ip_hdr_expr icmp_hdr_expr igmp_hdr_expr numgen_expr hash_expr
%type <val> ip_hdr_field icmp_hdr_field igmp_hdr_field
%type <val> ip_option_type ip_option_field
%type <expr> ip6_hdr_expr icmp6_hdr_expr
%destructor { expr_free($$); } ip6_hdr_expr icmp6_hdr_expr
%type <val> ip6_hdr_field icmp6_hdr_field
%type <expr> auth_hdr_expr esp_hdr_expr comp_hdr_expr
%destructor { expr_free($$); } auth_hdr_expr esp_hdr_expr comp_hdr_expr
%type <val> auth_hdr_field esp_hdr_field comp_hdr_field
%type <expr> udp_hdr_expr udplite_hdr_expr
%destructor { expr_free($$); } udp_hdr_expr udplite_hdr_expr
%type <val> udp_hdr_field udplite_hdr_field
%type <expr> dccp_hdr_expr sctp_hdr_expr
%destructor { expr_free($$); } dccp_hdr_expr sctp_hdr_expr
%type <val> dccp_hdr_field sctp_hdr_field
%type <expr> th_hdr_expr
%destructor { expr_free($$); } th_hdr_expr
%type <val> th_hdr_field
%type <expr> exthdr_expr
%destructor { expr_free($$); } exthdr_expr
%type <expr> hbh_hdr_expr frag_hdr_expr dst_hdr_expr
%destructor { expr_free($$); } hbh_hdr_expr frag_hdr_expr dst_hdr_expr
%type <val> hbh_hdr_field frag_hdr_field dst_hdr_field
%type <expr> rt_hdr_expr rt0_hdr_expr rt2_hdr_expr rt4_hdr_expr
%destructor { expr_free($$); } rt_hdr_expr rt0_hdr_expr rt2_hdr_expr rt4_hdr_expr
%type <val> rt_hdr_field rt0_hdr_field rt2_hdr_field rt4_hdr_field
%type <expr> mh_hdr_expr
%destructor { expr_free($$); } mh_hdr_expr
%type <val> mh_hdr_field
%type <expr> meta_expr
%destructor { expr_free($$); } meta_expr
%type <val> meta_key meta_key_qualified meta_key_unqualified numgen_type
%type <expr> socket_expr
%destructor { expr_free($$); } socket_expr
%type<val> socket_key
%type <val> nf_key_proto
%type <expr> rt_expr
%destructor { expr_free($$); } rt_expr
%type <val> rt_key
%type <expr> ct_expr
%destructor { expr_free($$); } ct_expr
%type <val> ct_key ct_dir ct_key_dir_optional ct_key_dir ct_key_proto_field
%type <expr> fib_expr
%destructor { expr_free($$); } fib_expr
%type <val> fib_tuple fib_result fib_flag
%type <expr> osf_expr
%type <val> osf_ttl
%destructor { expr_free($$); } osf_expr
%type <val> markup_format
%type <string> monitor_event
%destructor { xfree($$); } monitor_event
%type <val> monitor_object monitor_format
%type <val> synproxy_ts synproxy_sack
%type <expr> tcp_hdr_expr
%destructor { expr_free($$); } tcp_hdr_expr
%type <val> tcp_hdr_field
%type <val> tcp_hdr_option_type tcp_hdr_option_field
%type <expr> boolean_expr
%destructor { expr_free($$); } boolean_expr
%type <val8> boolean_keys
%type <expr> exthdr_exists_expr
%destructor { expr_free($$); } exthdr_exists_expr
%type <val> exthdr_key
%type <val> ct_l4protoname ct_obj_type
%type <list> timeout_states timeout_state
%destructor { xfree($$); } timeout_states timeout_state
%type <val> xfrm_state_key xfrm_state_proto_key xfrm_dir xfrm_spnum
%type <expr> xfrm_expr
%destructor { expr_free($$); } xfrm_expr
%%
input : /* empty */
| input line
{
if ($2 != NULL) {
$2->location = @2;
list_add_tail(&$2->list, state->cmds);
}
}
;
stmt_separator : NEWLINE
| SEMICOLON
;
opt_newline : NEWLINE
| /* empty */
;
common_block : INCLUDE QUOTED_STRING stmt_separator
{
if (scanner_include_file(nft, scanner, $2, &@$) < 0) {
xfree($2);
YYERROR;
}
xfree($2);
}
| DEFINE identifier '=' initializer_expr stmt_separator
{
struct scope *scope = current_scope(state);
if (symbol_lookup(scope, $2) != NULL) {
erec_queue(error(&@2, "redefinition of symbol '%s'", $2),
state->msgs);
expr_free($4);
xfree($2);
YYERROR;
}
symbol_bind(scope, $2, $4);
xfree($2);
}
| REDEFINE identifier '=' initializer_expr stmt_separator
{
struct scope *scope = current_scope(state);
symbol_bind(scope, $2, $4);
xfree($2);
}
| UNDEFINE identifier stmt_separator
{
struct scope *scope = current_scope(state);
if (symbol_unbind(scope, $2) < 0) {
erec_queue(error(&@2, "undefined symbol '%s'", $2),
state->msgs);
YYERROR;
}
xfree($2);
}
| error stmt_separator
{
if (++state->nerrs == nft->parser_max_errors)
YYABORT;
yyerrok;
}
;
line : common_block { $$ = NULL; }
| stmt_separator { $$ = NULL; }
| base_cmd stmt_separator { $$ = $1; }
| base_cmd TOKEN_EOF
{
/*
* Very hackish workaround for bison >= 2.4: previous versions
* terminated parsing after EOF, 2.4+ tries to get further input
* in 'input' and calls the scanner again, causing a crash when
* the final input buffer has been popped. Terminate manually to
* avoid this. The correct fix should be to adjust the grammar
* to accept EOF in input, but for unknown reasons it does not
* work.
*/
if ($1 != NULL) {
$1->location = @1;
list_add_tail(&$1->list, state->cmds);
}
$$ = NULL;
YYACCEPT;
}
;
base_cmd : /* empty */ add_cmd { $$ = $1; }
| ADD add_cmd { $$ = $2; }
| REPLACE replace_cmd { $$ = $2; }
| CREATE create_cmd { $$ = $2; }
| INSERT insert_cmd { $$ = $2; }
| DELETE delete_cmd { $$ = $2; }
| GET get_cmd { $$ = $2; }
| LIST list_cmd { $$ = $2; }
| RESET reset_cmd { $$ = $2; }
| FLUSH flush_cmd { $$ = $2; }
| RENAME rename_cmd { $$ = $2; }
| IMPORT import_cmd { $$ = $2; }
| EXPORT export_cmd { $$ = $2; }
| MONITOR monitor_cmd { $$ = $2; }
| DESCRIBE describe_cmd { $$ = $2; }
;
add_cmd : TABLE table_spec
{
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_TABLE, &$2, &@$, NULL);
}
| TABLE table_spec table_block_alloc
'{' table_block '}'
{
handle_merge(&$3->handle, &$2);
close_scope(state);
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_TABLE, &$2, &@$, $5);
}
| CHAIN chain_spec
{
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_CHAIN, &$2, &@$, NULL);
}
| CHAIN chain_spec chain_block_alloc
'{' chain_block '}'
{
$5->location = @5;
handle_merge(&$3->handle, &$2);
close_scope(state);
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_CHAIN, &$2, &@$, $5);
}
| RULE rule_position rule
{
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_RULE, &$2, &@$, $3);
}
| /* empty */ rule_position rule
{
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_RULE, &$1, &@$, $2);
}
| SET set_spec set_block_alloc
'{' set_block '}'
{
$5->location = @5;
handle_merge(&$3->handle, &$2);
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_SET, &$2, &@$, $5);
}
| MAP set_spec map_block_alloc
'{' map_block '}'
{
$5->location = @5;
handle_merge(&$3->handle, &$2);
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_SET, &$2, &@$, $5);
}
| ELEMENT set_spec set_block_expr
{
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_ELEMENTS, &$2, &@$, $3);
}
| FLOWTABLE flowtable_spec flowtable_block_alloc
'{' flowtable_block '}'
{
$5->location = @5;
handle_merge(&$3->handle, &$2);
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_FLOWTABLE, &$2, &@$, $5);
}
| COUNTER obj_spec
{
struct obj *obj;
obj = obj_alloc(&@$);
obj->type = NFT_OBJECT_COUNTER;
handle_merge(&obj->handle, &$2);
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_COUNTER, &$2, &@$, obj);
}
| COUNTER obj_spec counter_obj counter_config
{
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_COUNTER, &$2, &@$, $3);
}
| QUOTA obj_spec quota_obj quota_config
{
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_QUOTA, &$2, &@$, $3);
}
| CT HELPER obj_spec ct_obj_alloc '{' ct_helper_block '}'
{
$$ = cmd_alloc_obj_ct(CMD_ADD, NFT_OBJECT_CT_HELPER, &$3, &@$, $4);
}
| CT TIMEOUT obj_spec ct_obj_alloc '{' ct_timeout_block '}'
{
$$ = cmd_alloc_obj_ct(CMD_ADD, NFT_OBJECT_CT_TIMEOUT, &$3, &@$, $4);
}
| CT EXPECTATION obj_spec ct_obj_alloc '{' ct_expect_block '}'
{
$$ = cmd_alloc_obj_ct(CMD_ADD, NFT_OBJECT_CT_EXPECT, &$3, &@$, $4);
}
| LIMIT obj_spec limit_obj limit_config
{
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_LIMIT, &$2, &@$, $3);
}
| SECMARK obj_spec secmark_obj secmark_config
{
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_SECMARK, &$2, &@$, $3);
}
| SYNPROXY obj_spec synproxy_obj synproxy_config
{
$$ = cmd_alloc(CMD_ADD, CMD_OBJ_SYNPROXY, &$2, &@$, $3);
}
;
replace_cmd : RULE ruleid_spec rule
{
$$ = cmd_alloc(CMD_REPLACE, CMD_OBJ_RULE, &$2, &@$, $3);
}
;
create_cmd : TABLE table_spec
{
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_TABLE, &$2, &@$, NULL);
}
| TABLE table_spec table_block_alloc
'{' table_block '}'
{
handle_merge(&$3->handle, &$2);
close_scope(state);
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_TABLE, &$2, &@$, $5);
}
| CHAIN chain_spec
{
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_CHAIN, &$2, &@$, NULL);
}
| CHAIN chain_spec chain_block_alloc
'{' chain_block '}'
{
$5->location = @5;
handle_merge(&$3->handle, &$2);
close_scope(state);
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_CHAIN, &$2, &@$, $5);
}
| SET set_spec set_block_alloc
'{' set_block '}'
{
$5->location = @5;
handle_merge(&$3->handle, &$2);
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_SET, &$2, &@$, $5);
}
| MAP set_spec map_block_alloc
'{' map_block '}'
{
$5->location = @5;
handle_merge(&$3->handle, &$2);
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_SET, &$2, &@$, $5);
}
| ELEMENT set_spec set_block_expr
{
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_ELEMENTS, &$2, &@$, $3);
}
| FLOWTABLE flowtable_spec flowtable_block_alloc
'{' flowtable_block '}'
{
$5->location = @5;
handle_merge(&$3->handle, &$2);
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_FLOWTABLE, &$2, &@$, $5);
}
| COUNTER obj_spec
{
struct obj *obj;
obj = obj_alloc(&@$);
obj->type = NFT_OBJECT_COUNTER;
handle_merge(&obj->handle, &$2);
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_COUNTER, &$2, &@$, obj);
}
| COUNTER obj_spec counter_obj counter_config
{
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_COUNTER, &$2, &@$, $3);
}
| QUOTA obj_spec quota_obj quota_config
{
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_QUOTA, &$2, &@$, $3);
}
| CT HELPER obj_spec ct_obj_alloc '{' ct_helper_block '}'
{
$$ = cmd_alloc_obj_ct(CMD_CREATE, NFT_OBJECT_CT_HELPER, &$3, &@$, $4);
}
| CT TIMEOUT obj_spec ct_obj_alloc '{' ct_timeout_block '}'
{
$$ = cmd_alloc_obj_ct(CMD_CREATE, NFT_OBJECT_CT_TIMEOUT, &$3, &@$, $4);
}
| CT EXPECTATION obj_spec ct_obj_alloc '{' ct_expect_block '}'
{
$$ = cmd_alloc_obj_ct(CMD_CREATE, NFT_OBJECT_CT_EXPECT, &$3, &@$, $4);
}
| LIMIT obj_spec limit_obj limit_config
{
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_LIMIT, &$2, &@$, $3);
}
| SECMARK obj_spec secmark_obj secmark_config
{
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_SECMARK, &$2, &@$, $3);
}
| SYNPROXY obj_spec synproxy_obj synproxy_config
{
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_SYNPROXY, &$2, &@$, $3);
}
;
insert_cmd : RULE rule_position rule
{
$$ = cmd_alloc(CMD_INSERT, CMD_OBJ_RULE, &$2, &@$, $3);
}
;
delete_cmd : TABLE table_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_TABLE, &$2, &@$, NULL);
}
| TABLE tableid_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_TABLE, &$2, &@$, NULL);
}
| CHAIN chain_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_CHAIN, &$2, &@$, NULL);
}
| CHAIN chainid_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_CHAIN, &$2, &@$, NULL);
}
| RULE ruleid_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_RULE, &$2, &@$, NULL);
}
| SET set_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SET, &$2, &@$, NULL);
}
| SET setid_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SET, &$2, &@$, NULL);
}
| MAP set_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SET, &$2, &@$, NULL);
}
| ELEMENT set_spec set_block_expr
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_ELEMENTS, &$2, &@$, $3);
}
| FLOWTABLE flowtable_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_FLOWTABLE, &$2, &@$, NULL);
}
| FLOWTABLE flowtableid_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_FLOWTABLE, &$2, &@$, NULL);
}
| FLOWTABLE flowtable_spec flowtable_block_alloc
'{' flowtable_block '}'
{
$5->location = @5;
handle_merge(&$3->handle, &$2);
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_FLOWTABLE, &$2, &@$, $5);
}
| COUNTER obj_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_COUNTER, &$2, &@$, NULL);
}
| COUNTER objid_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_COUNTER, &$2, &@$, NULL);
}
| QUOTA obj_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_QUOTA, &$2, &@$, NULL);
}
| QUOTA objid_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_QUOTA, &$2, &@$, NULL);
}
| CT ct_obj_type obj_spec ct_obj_alloc
{
$$ = cmd_alloc_obj_ct(CMD_DELETE, $2, &$3, &@$, $4);
}
| LIMIT obj_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_LIMIT, &$2, &@$, NULL);
}
| LIMIT objid_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_LIMIT, &$2, &@$, NULL);
}
| SECMARK obj_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SECMARK, &$2, &@$, NULL);
}
| SECMARK objid_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SECMARK, &$2, &@$, NULL);
}
| SYNPROXY obj_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SYNPROXY, &$2, &@$, NULL);
}
| SYNPROXY objid_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SYNPROXY, &$2, &@$, NULL);
}
;
get_cmd : ELEMENT set_spec set_block_expr
{
$$ = cmd_alloc(CMD_GET, CMD_OBJ_ELEMENTS, &$2, &@$, $3);
}
;
list_cmd : TABLE table_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_TABLE, &$2, &@$, NULL);
}
| TABLES ruleset_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_TABLE, &$2, &@$, NULL);
}
| CHAIN chain_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_CHAIN, &$2, &@$, NULL);
}
| CHAINS ruleset_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_CHAINS, &$2, &@$, NULL);
}
| SETS ruleset_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$2, &@$, NULL);
}
| SETS TABLE table_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$3, &@$, NULL);
}
| SET set_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_SET, &$2, &@$, NULL);
}
| COUNTERS ruleset_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_COUNTERS, &$2, &@$, NULL);
}
| COUNTERS TABLE table_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_COUNTERS, &$3, &@$, NULL);
}
| COUNTER obj_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_COUNTER, &$2, &@$, NULL);
}
| QUOTAS ruleset_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_QUOTAS, &$2, &@$, NULL);
}
| QUOTAS TABLE table_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_QUOTAS, &$3, &@$, NULL);
}
| QUOTA obj_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_QUOTA, &$2, &@$, NULL);
}
| LIMITS ruleset_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_LIMITS, &$2, &@$, NULL);
}
| LIMITS TABLE table_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_LIMITS, &$3, &@$, NULL);
}
| LIMIT obj_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_LIMIT, &$2, &@$, NULL);
}
| SECMARKS ruleset_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_SECMARKS, &$2, &@$, NULL);
}
| SECMARKS TABLE table_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_SECMARKS, &$3, &@$, NULL);
}
| SECMARK obj_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_SECMARK, &$2, &@$, NULL);
}
| SYNPROXYS ruleset_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_SYNPROXYS, &$2, &@$, NULL);
}
| SYNPROXYS TABLE table_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_SYNPROXYS, &$3, &@$, NULL);
}
| SYNPROXY obj_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_SYNPROXY, &$2, &@$, NULL);
}
| RULESET ruleset_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_RULESET, &$2, &@$, NULL);
}
| FLOW TABLES ruleset_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_METERS, &$3, &@$, NULL);
}
| FLOW TABLE set_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_METER, &$3, &@$, NULL);
}
| METERS ruleset_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_METERS, &$2, &@$, NULL);
}
| METER set_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_METER, &$2, &@$, NULL);
}
| FLOWTABLES ruleset_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_FLOWTABLES, &$2, &@$, NULL);
}
| FLOWTABLE flowtable_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_FLOWTABLE, &$2, &@$, NULL);
}
| MAPS ruleset_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_MAPS, &$2, &@$, NULL);
}
| MAP set_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_MAP, &$2, &@$, NULL);
}
| CT ct_obj_type obj_spec
{
$$ = cmd_alloc_obj_ct(CMD_LIST, $2, &$3, &@$, NULL);
}
| CT HELPERS TABLE table_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_CT_HELPERS, &$4, &@$, NULL);
}
| CT TIMEOUT TABLE table_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_CT_TIMEOUT, &$4, &@$, NULL);
}
| CT EXPECTATION TABLE table_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_CT_EXPECT, &$4, &@$, NULL);
}
;
reset_cmd : COUNTERS ruleset_spec
{
$$ = cmd_alloc(CMD_RESET, CMD_OBJ_COUNTERS, &$2, &@$, NULL);
}
| COUNTERS TABLE table_spec
{
$$ = cmd_alloc(CMD_RESET, CMD_OBJ_COUNTERS, &$3, &@$, NULL);
}
| COUNTER obj_spec
{
$$ = cmd_alloc(CMD_RESET, CMD_OBJ_COUNTER, &$2,&@$, NULL);
}
| QUOTAS ruleset_spec
{
$$ = cmd_alloc(CMD_RESET, CMD_OBJ_QUOTAS, &$2, &@$, NULL);
}
| QUOTAS TABLE table_spec
{
$$ = cmd_alloc(CMD_RESET, CMD_OBJ_QUOTAS, &$3, &@$, NULL);
}
| QUOTA obj_spec
{
$$ = cmd_alloc(CMD_RESET, CMD_OBJ_QUOTA, &$2, &@$, NULL);
}
;
flush_cmd : TABLE table_spec
{
$$ = cmd_alloc(CMD_FLUSH, CMD_OBJ_TABLE, &$2, &@$, NULL);
}
| CHAIN chain_spec
{
$$ = cmd_alloc(CMD_FLUSH, CMD_OBJ_CHAIN, &$2, &@$, NULL);
}
| SET set_spec
{
$$ = cmd_alloc(CMD_FLUSH, CMD_OBJ_SET, &$2, &@$, NULL);
}
| MAP set_spec
{
$$ = cmd_alloc(CMD_FLUSH, CMD_OBJ_MAP, &$2, &@$, NULL);
}
| FLOW TABLE set_spec
{
$$ = cmd_alloc(CMD_FLUSH, CMD_OBJ_METER, &$3, &@$, NULL);
}
| METER set_spec
{
$$ = cmd_alloc(CMD_FLUSH, CMD_OBJ_METER, &$2, &@$, NULL);
}
| RULESET ruleset_spec
{
$$ = cmd_alloc(CMD_FLUSH, CMD_OBJ_RULESET, &$2, &@$, NULL);
}
;
rename_cmd : CHAIN chain_spec identifier
{
$$ = cmd_alloc(CMD_RENAME, CMD_OBJ_CHAIN, &$2, &@$, NULL);
$$->arg = $3;
}
;
import_cmd : RULESET markup_format
{
struct handle h = { .family = NFPROTO_UNSPEC };
struct markup *markup = markup_alloc($2);
$$ = cmd_alloc(CMD_IMPORT, CMD_OBJ_MARKUP, &h, &@$, markup);
}
| markup_format
{
struct handle h = { .family = NFPROTO_UNSPEC };
struct markup *markup = markup_alloc($1);
$$ = cmd_alloc(CMD_IMPORT, CMD_OBJ_MARKUP, &h, &@$, markup);
}
;
export_cmd : RULESET markup_format
{
struct handle h = { .family = NFPROTO_UNSPEC };
struct markup *markup = markup_alloc($2);
$$ = cmd_alloc(CMD_EXPORT, CMD_OBJ_MARKUP, &h, &@$, markup);
}
| markup_format
{
struct handle h = { .family = NFPROTO_UNSPEC };
struct markup *markup = markup_alloc($1);
$$ = cmd_alloc(CMD_EXPORT, CMD_OBJ_MARKUP, &h, &@$, markup);
}
;
monitor_cmd : monitor_event monitor_object monitor_format
{
struct handle h = { .family = NFPROTO_UNSPEC };
struct monitor *m = monitor_alloc($3, $2, $1);
m->location = @1;
$$ = cmd_alloc(CMD_MONITOR, CMD_OBJ_MONITOR, &h, &@$, m);
}
;
monitor_event : /* empty */ { $$ = NULL; }
| STRING { $$ = $1; }
;
monitor_object : /* empty */ { $$ = CMD_MONITOR_OBJ_ANY; }
| TABLES { $$ = CMD_MONITOR_OBJ_TABLES; }
| CHAINS { $$ = CMD_MONITOR_OBJ_CHAINS; }
| SETS { $$ = CMD_MONITOR_OBJ_SETS; }
| RULES { $$ = CMD_MONITOR_OBJ_RULES; }
| ELEMENTS { $$ = CMD_MONITOR_OBJ_ELEMS; }
| RULESET { $$ = CMD_MONITOR_OBJ_RULESET; }
| TRACE { $$ = CMD_MONITOR_OBJ_TRACE; }
;
monitor_format : /* empty */ { $$ = NFTNL_OUTPUT_DEFAULT; }
| markup_format
;
markup_format : XML { $$ = __NFT_OUTPUT_NOTSUPP; }
| JSON { $$ = NFTNL_OUTPUT_JSON; }
| VM JSON { $$ = NFTNL_OUTPUT_JSON; }
;
describe_cmd : primary_expr
{
struct handle h = { .family = NFPROTO_UNSPEC };
$$ = cmd_alloc(CMD_DESCRIBE, CMD_OBJ_EXPR, &h, &@$, NULL);
$$->expr = $1;
}
;
table_block_alloc : /* empty */
{
$$ = table_alloc();
open_scope(state, &$$->scope);
}
;
table_options : FLAGS STRING
{
if (strcmp($2, "dormant") == 0) {
$<table>0->flags = TABLE_F_DORMANT;
xfree($2);
} else {
erec_queue(error(&@2, "unknown table option %s", $2),
state->msgs);
xfree($2);
YYERROR;
}
}
;
table_block : /* empty */ { $$ = $<table>-1; }
| table_block common_block
| table_block stmt_separator
| table_block table_options stmt_separator
| table_block CHAIN chain_identifier
chain_block_alloc '{' chain_block '}'
stmt_separator
{
$4->location = @3;
handle_merge(&$4->handle, &$3);
handle_free(&$3);
close_scope(state);
list_add_tail(&$4->list, &$1->chains);
$$ = $1;
}
| table_block SET set_identifier
set_block_alloc '{' set_block '}'
stmt_separator
{
$4->location = @3;
handle_merge(&$4->handle, &$3);
handle_free(&$3);
list_add_tail(&$4->list, &$1->sets);
$$ = $1;
}
| table_block MAP set_identifier
map_block_alloc '{' map_block '}'
stmt_separator
{
$4->location = @3;
handle_merge(&$4->handle, &$3);
handle_free(&$3);
list_add_tail(&$4->list, &$1->sets);
$$ = $1;
}
| table_block FLOWTABLE flowtable_identifier
flowtable_block_alloc '{' flowtable_block '}'
stmt_separator
{
$4->location = @3;
handle_merge(&$4->handle, &$3);
handle_free(&$3);
list_add_tail(&$4->list, &$1->flowtables);
$$ = $1;
}
| table_block COUNTER obj_identifier
obj_block_alloc '{' counter_block '}'
stmt_separator
{
$4->location = @3;
$4->type = NFT_OBJECT_COUNTER;
handle_merge(&$4->handle, &$3);
handle_free(&$3);
list_add_tail(&$4->list, &$1->objs);
$$ = $1;
}
| table_block QUOTA obj_identifier
obj_block_alloc '{' quota_block '}'
stmt_separator
{
$4->location = @3;
$4->type = NFT_OBJECT_QUOTA;
handle_merge(&$4->handle, &$3);
handle_free(&$3);
list_add_tail(&$4->list, &$1->objs);
$$ = $1;
}
| table_block CT HELPER obj_identifier obj_block_alloc '{' ct_helper_block '}' stmt_separator
{
$5->location = @4;
$5->type = NFT_OBJECT_CT_HELPER;
handle_merge(&$5->handle, &$4);
handle_free(&$4);
list_add_tail(&$5->list, &$1->objs);
$$ = $1;
}
| table_block CT TIMEOUT obj_identifier obj_block_alloc '{' ct_timeout_block '}' stmt_separator
{
$5->location = @4;
$5->type = NFT_OBJECT_CT_TIMEOUT;
handle_merge(&$5->handle, &$4);
handle_free(&$4);
list_add_tail(&$5->list, &$1->objs);
$$ = $1;
}
| table_block CT EXPECTATION obj_identifier obj_block_alloc '{' ct_expect_block '}' stmt_separator
{
$5->location = @4;
$5->type = NFT_OBJECT_CT_EXPECT;
handle_merge(&$5->handle, &$4);
handle_free(&$4);
list_add_tail(&$5->list, &$1->objs);
$$ = $1;
}
| table_block LIMIT obj_identifier
obj_block_alloc '{' limit_block '}'
stmt_separator
{
$4->location = @3;
$4->type = NFT_OBJECT_LIMIT;
handle_merge(&$4->handle, &$3);
handle_free(&$3);
list_add_tail(&$4->list, &$1->objs);
$$ = $1;
}
| table_block SECMARK obj_identifier
obj_block_alloc '{' secmark_block '}'
stmt_separator
{
$4->location = @3;
$4->type = NFT_OBJECT_SECMARK;
handle_merge(&$4->handle, &$3);
handle_free(&$3);
list_add_tail(&$4->list, &$1->objs);
$$ = $1;
}
| table_block SYNPROXY obj_identifier
obj_block_alloc '{' synproxy_block '}'
stmt_separator
{
$4->location = @3;
$4->type = NFT_OBJECT_SYNPROXY;
handle_merge(&$4->handle, &$3);
handle_free(&$3);
list_add_tail(&$4->list, &$1->objs);
$$ = $1;
}
;
chain_block_alloc : /* empty */
{
$$ = chain_alloc(NULL);
open_scope(state, &$$->scope);
}
;
chain_block : /* empty */ { $$ = $<chain>-1; }
| chain_block common_block
| chain_block stmt_separator
| chain_block hook_spec stmt_separator
| chain_block policy_spec stmt_separator
| chain_block flags_spec stmt_separator
| chain_block rule stmt_separator
{
list_add_tail(&$2->list, &$1->rules);
$$ = $1;
}
;
subchain_block : /* empty */ { $$ = $<chain>-1; }
| subchain_block stmt_separator
| subchain_block rule stmt_separator
{
list_add_tail(&$2->list, &$1->rules);
$$ = $1;
}
;
typeof_expr : primary_expr
{
if (expr_ops($1)->build_udata == NULL) {
erec_queue(error(&@1, "primary expression type '%s' lacks typeof serialization", expr_ops($1)->name),
state->msgs);
expr_free($1);
YYERROR;
}
$$ = $1;
}
| typeof_expr DOT primary_expr
{
struct location rhs[] = {
[1] = @2,
[2] = @3,
};
$$ = handle_concat_expr(&@$, $$, $1, $3, rhs);
}
;
set_block_alloc : /* empty */
{
$$ = set_alloc(NULL);
}
;
set_block : /* empty */ { $$ = $<set>-1; }
| set_block common_block
| set_block stmt_separator
| set_block TYPE data_type_expr stmt_separator
{
$1->key = $3;
$$ = $1;
}
| set_block TYPEOF typeof_expr stmt_separator
{
$1->key = $3;
datatype_set($1->key, $3->dtype);
$$ = $1;
}
| set_block FLAGS set_flag_list stmt_separator
{
$1->flags = $3;
$$ = $1;
}
| set_block TIMEOUT time_spec stmt_separator
{
$1->timeout = $3;
$$ = $1;
}
| set_block GC_INTERVAL time_spec stmt_separator
{
$1->gc_int = $3;
$$ = $1;
}
| set_block COUNTER stmt_separator
{
$1->stmt = counter_stmt_alloc(&@$);
$$ = $1;
}
| set_block ELEMENTS '=' set_block_expr
{
$1->init = $4;
$$ = $1;
}
| set_block AUTOMERGE
{
$1->automerge = true;
$$ = $1;
}
| set_block set_mechanism stmt_separator
;
set_block_expr : set_expr
| variable_expr
;
set_flag_list : set_flag_list COMMA set_flag
{
$$ = $1 | $3;
}
| set_flag
;
set_flag : CONSTANT { $$ = NFT_SET_CONSTANT; }
| INTERVAL { $$ = NFT_SET_INTERVAL; }
| TIMEOUT { $$ = NFT_SET_TIMEOUT; }
| DYNAMIC { $$ = NFT_SET_EVAL; }
;
map_block_alloc : /* empty */
{
$$ = set_alloc(NULL);
}
;
map_block : /* empty */ { $$ = $<set>-1; }
| map_block common_block
| map_block stmt_separator
| map_block TIMEOUT time_spec stmt_separator
{
$1->timeout = $3;
$$ = $1;
}
| map_block TYPE
data_type_expr COLON data_type_expr
stmt_separator
{
$1->key = $3;
$1->data = $5;
$1->flags |= NFT_SET_MAP;
$$ = $1;
}
| map_block TYPE
data_type_expr COLON INTERVAL data_type_expr
stmt_separator
{
$1->key = $3;
$1->data = $6;
$1->data->flags |= EXPR_F_INTERVAL;
$1->flags |= NFT_SET_MAP;
$$ = $1;
}
| map_block TYPEOF
typeof_expr COLON typeof_expr
stmt_separator
{
$1->key = $3;
datatype_set($1->key, $3->dtype);
$1->data = $5;
$1->flags |= NFT_SET_MAP;
$$ = $1;
}
| map_block TYPEOF
typeof_expr COLON INTERVAL typeof_expr
stmt_separator
{
$1->key = $3;
datatype_set($1->key, $3->dtype);
$1->data = $6;
$1->data->flags |= EXPR_F_INTERVAL;
$1->flags |= NFT_SET_MAP;
$$ = $1;
}
| map_block TYPE
data_type_expr COLON COUNTER
stmt_separator
{
$1->key = $3;
$1->objtype = NFT_OBJECT_COUNTER;
$1->flags |= NFT_SET_OBJECT;
$$ = $1;
}
| map_block TYPE
data_type_expr COLON QUOTA
stmt_separator
{
$1->key = $3;
$1->objtype = NFT_OBJECT_QUOTA;
$1->flags |= NFT_SET_OBJECT;
$$ = $1;
}
| map_block TYPE
data_type_expr COLON LIMIT
stmt_separator
{
$1->key = $3;
$1->objtype = NFT_OBJECT_LIMIT;
$1->flags |= NFT_SET_OBJECT;
$$ = $1;
}
| map_block TYPE
data_type_expr COLON SECMARK
stmt_separator
{
$1->key = $3;
$1->objtype = NFT_OBJECT_SECMARK;
$1->flags |= NFT_SET_OBJECT;
$$ = $1;
}
| map_block FLAGS set_flag_list stmt_separator
{
$1->flags |= $3;
$$ = $1;
}
| map_block ELEMENTS '=' set_block_expr
{
$1->init = $4;
$$ = $1;
}
| map_block set_mechanism stmt_separator
;
set_mechanism : POLICY set_policy_spec
{
$<set>0->policy = $2;
}
| SIZE NUM
{
$<set>0->desc.size = $2;
}
;
set_policy_spec : PERFORMANCE { $$ = NFT_SET_POL_PERFORMANCE; }
| MEMORY { $$ = NFT_SET_POL_MEMORY; }
;
flowtable_block_alloc : /* empty */
{
$$ = flowtable_alloc(NULL);
}
;
flowtable_block : /* empty */ { $$ = $<flowtable>-1; }
| flowtable_block common_block
| flowtable_block stmt_separator
| flowtable_block HOOK STRING prio_spec stmt_separator
{
$$->hook.loc = @3;
$$->hook.name = chain_hookname_lookup($3);
if ($$->hook.name == NULL) {
erec_queue(error(&@3, "unknown chain hook"),
state->msgs);
xfree($3);
YYERROR;
}
xfree($3);
$$->priority = $4;
}
| flowtable_block DEVICES '=' flowtable_expr stmt_separator
{
$$->dev_expr = $4;
}
| flowtable_block COUNTER
{
$$->flags |= NFT_FLOWTABLE_COUNTER;
}
;
flowtable_expr : '{' flowtable_list_expr '}'
{
$2->location = @$;
$$ = $2;
}
| variable_expr
{
$1->location = @$;
$$ = $1;
}
;
flowtable_list_expr : flowtable_expr_member
{
$$ = compound_expr_alloc(&@$, EXPR_LIST);
compound_expr_add($$, $1);
}
| flowtable_list_expr COMMA flowtable_expr_member
{
compound_expr_add($1, $3);
$$ = $1;
}
| flowtable_list_expr COMMA opt_newline
;
flowtable_expr_member : STRING
{
$$ = constant_expr_alloc(&@$, &string_type,
BYTEORDER_HOST_ENDIAN,
strlen($1) * BITS_PER_BYTE, $1);
xfree($1);
}
| variable_expr
{
datatype_set($1->sym->expr, &ifname_type);
$$ = $1;
}
;
data_type_atom_expr : type_identifier
{
const struct datatype *dtype = datatype_lookup_byname($1);
if (dtype == NULL) {
erec_queue(error(&@1, "unknown datatype %s", $1),
state->msgs);
YYERROR;
}
$$ = constant_expr_alloc(&@1, dtype, dtype->byteorder,
dtype->size, NULL);
xfree($1);
}
| TIME
{
$$ = constant_expr_alloc(&@1, &time_type, time_type.byteorder,
time_type.size, NULL);
}
;
data_type_expr : data_type_atom_expr
| data_type_expr DOT data_type_atom_expr
{
struct location rhs[] = {
[1] = @2,
[2] = @3,
};
$$ = handle_concat_expr(&@$, $$, $1, $3, rhs);
}
;
obj_block_alloc : /* empty */
{
$$ = obj_alloc(NULL);
}
;
counter_block : /* empty */ { $$ = $<obj>-1; }
| counter_block common_block
| counter_block stmt_separator
| counter_block counter_config
{
$$ = $1;
}
;
quota_block : /* empty */ { $$ = $<obj>-1; }
| quota_block common_block
| quota_block stmt_separator
| quota_block quota_config
{
$$ = $1;
}
;
ct_helper_block : /* empty */ { $$ = $<obj>-1; }
| ct_helper_block common_block
| ct_helper_block stmt_separator
| ct_helper_block ct_helper_config
{
$$ = $1;
}
;
ct_timeout_block : /*empty */
{
$$ = $<obj>-1;
init_list_head(&$$->ct_timeout.timeout_list);
}
| ct_timeout_block common_block
| ct_timeout_block stmt_separator
| ct_timeout_block ct_timeout_config
{
$$ = $1;
}
;
ct_expect_block : /*empty */ { $$ = $<obj>-1; }
| ct_expect_block common_block
| ct_expect_block stmt_separator
| ct_expect_block ct_expect_config
{
$$ = $1;
}
;
limit_block : /* empty */ { $$ = $<obj>-1; }
| limit_block common_block
| limit_block stmt_separator
| limit_block limit_config
{
$$ = $1;
}
;
secmark_block : /* empty */ { $$ = $<obj>-1; }
| secmark_block common_block
| secmark_block stmt_separator
| secmark_block secmark_config
{
$$ = $1;
}
;
synproxy_block : /* empty */ { $$ = $<obj>-1; }
| synproxy_block common_block
| synproxy_block stmt_separator
| synproxy_block synproxy_config
{
$$ = $1;
}
;
type_identifier : STRING { $$ = $1; }
| MARK { $$ = xstrdup("mark"); }
| DSCP { $$ = xstrdup("dscp"); }
| ECN { $$ = xstrdup("ecn"); }
| CLASSID { $$ = xstrdup("classid"); }
;
hook_spec : TYPE STRING HOOK STRING dev_spec prio_spec
{
const char *chain_type = chain_type_name_lookup($2);
if (chain_type == NULL) {
erec_queue(error(&@2, "unknown chain type"),
state->msgs);
xfree($2);
YYERROR;
}
$<chain>0->type = xstrdup(chain_type);
xfree($2);
$<chain>0->loc = @$;
$<chain>0->hook.loc = @4;
$<chain>0->hook.name = chain_hookname_lookup($4);
if ($<chain>0->hook.name == NULL) {
erec_queue(error(&@4, "unknown chain hook"),
state->msgs);
xfree($4);
YYERROR;
}
xfree($4);
$<chain>0->dev_expr = $5;
$<chain>0->priority = $6;
$<chain>0->flags |= CHAIN_F_BASECHAIN;
}
;
prio_spec : PRIORITY extended_prio_spec
{
$$ = $2;
$$.loc = @$;
}
;
extended_prio_name : OUT
{
$$ = strdup("out");
}
| STRING
;
extended_prio_spec : int_num
{
struct prio_spec spec = {0};
spec.expr = constant_expr_alloc(&@$, &integer_type,
BYTEORDER_HOST_ENDIAN,
sizeof(int) *
BITS_PER_BYTE, &$1);
$$ = spec;
}
| variable_expr
{
struct prio_spec spec = {0};
spec.expr = $1;
$$ = spec;
}
| extended_prio_name
{
struct prio_spec spec = {0};
spec.expr = constant_expr_alloc(&@$, &string_type,
BYTEORDER_HOST_ENDIAN,
strlen($1) * BITS_PER_BYTE,
$1);
xfree($1);
$$ = spec;
}
| extended_prio_name PLUS NUM
{
struct prio_spec spec = {0};
char str[NFT_NAME_MAXLEN];
snprintf(str, sizeof(str), "%s + %" PRIu64, $1, $3);
spec.expr = constant_expr_alloc(&@$, &string_type,
BYTEORDER_HOST_ENDIAN,
strlen(str) * BITS_PER_BYTE,
str);
xfree($1);
$$ = spec;
}
| extended_prio_name DASH NUM
{
struct prio_spec spec = {0};
char str[NFT_NAME_MAXLEN];
snprintf(str, sizeof(str), "%s - %" PRIu64, $1, $3);
spec.expr = constant_expr_alloc(&@$, &string_type,
BYTEORDER_HOST_ENDIAN,
strlen(str) * BITS_PER_BYTE,
str);
xfree($1);
$$ = spec;
}
;
int_num : NUM { $$ = $1; }
| DASH NUM { $$ = -$2; }
;
dev_spec : DEVICE string
{
struct expr *expr;
expr = constant_expr_alloc(&@$, &string_type,
BYTEORDER_HOST_ENDIAN,
strlen($2) * BITS_PER_BYTE, $2);
xfree($2);
$$ = compound_expr_alloc(&@$, EXPR_LIST);
compound_expr_add($$, expr);
}
| DEVICE variable_expr
{
datatype_set($2->sym->expr, &ifname_type);
$$ = compound_expr_alloc(&@$, EXPR_LIST);
compound_expr_add($$, $2);
}
| DEVICES '=' flowtable_expr
{
$$ = $3;
}
| /* empty */ { $$ = NULL; }
;
flags_spec : FLAGS OFFLOAD
{
$<chain>0->flags |= CHAIN_F_HW_OFFLOAD;
}
;
policy_spec : POLICY policy_expr
{
if ($<chain>0->policy) {
erec_queue(error(&@$, "you cannot set chain policy twice"),
state->msgs);
expr_free($2);
YYERROR;
}
$<chain>0->policy = $2;
$<chain>0->policy->location = @$;
}
;
policy_expr : variable_expr
{
datatype_set($1->sym->expr, &policy_type);
$$ = $1;
}
| chain_policy
{
$$ = constant_expr_alloc(&@$, &integer_type,
BYTEORDER_HOST_ENDIAN,
sizeof(int) *
BITS_PER_BYTE, &$1);
}
;
chain_policy : ACCEPT { $$ = NF_ACCEPT; }
| DROP { $$ = NF_DROP; }
;
identifier : STRING
;
string : STRING
| QUOTED_STRING
| ASTERISK_STRING
;
time_spec : STRING
{
struct error_record *erec;
uint64_t res;
erec = time_parse(&@1, $1, &res);
xfree($1);
if (erec != NULL) {
erec_queue(erec, state->msgs);
YYERROR;
}
$$ = res;
}
;
family_spec : /* empty */ { $$ = NFPROTO_IPV4; }
| family_spec_explicit
;
family_spec_explicit : IP { $$ = NFPROTO_IPV4; }
| IP6 { $$ = NFPROTO_IPV6; }
| INET { $$ = NFPROTO_INET; }
| ARP { $$ = NFPROTO_ARP; }
| BRIDGE { $$ = NFPROTO_BRIDGE; }
| NETDEV { $$ = NFPROTO_NETDEV; }
;
table_spec : family_spec identifier
{
memset(&$$, 0, sizeof($$));
$$.family = $1;
$$.table.location = @2;
$$.table.name = $2;
}
;
tableid_spec : family_spec HANDLE NUM
{
memset(&$$, 0, sizeof($$));
$$.family = $1;
$$.handle.id = $3;
$$.handle.location = @3;
}
;
chain_spec : table_spec identifier
{
$$ = $1;
$$.chain.name = $2;
$$.chain.location = @2;
}
;
chainid_spec : table_spec HANDLE NUM
{
$$ = $1;
$$.handle.location = @3;
$$.handle.id = $3;
}
;
chain_identifier : identifier
{
memset(&$$, 0, sizeof($$));
$$.chain.name = $1;
$$.chain.location = @1;
}
;
set_spec : table_spec identifier
{
$$ = $1;
$$.set.name = $2;
$$.set.location = @2;
}
;
setid_spec : table_spec HANDLE NUM
{
$$ = $1;
$$.handle.location = @3;
$$.handle.id = $3;
}
;
set_identifier : identifier
{
memset(&$$, 0, sizeof($$));
$$.set.name = $1;
$$.set.location = @1;
}
;
flowtable_spec : table_spec identifier
{
$$ = $1;
$$.flowtable.name = $2;
$$.flowtable.location = @2;
}
;
flowtableid_spec : table_spec HANDLE NUM
{
$$ = $1;
$$.handle.location = @3;
$$.handle.id = $3;
}
;
flowtable_identifier : identifier
{
memset(&$$, 0, sizeof($$));
$$.flowtable.name = $1;
$$.flowtable.location = @1;
}
;
obj_spec : table_spec identifier
{
$$ = $1;
$$.obj.name = $2;
$$.obj.location = @2;
}
;
objid_spec : table_spec HANDLE NUM
{
$$ = $1;
$$.handle.location = @3;
$$.handle.id = $3;
}
;
obj_identifier : identifier
{
memset(&$$, 0, sizeof($$));
$$.obj.name = $1;
$$.obj.location = @1;
}
;
handle_spec : HANDLE NUM
{
memset(&$$, 0, sizeof($$));
$$.handle.location = @2;
$$.handle.id = $2;
}
;
position_spec : POSITION NUM
{
memset(&$$, 0, sizeof($$));
$$.position.location = @$;
$$.position.id = $2;
}
;
index_spec : INDEX NUM
{
memset(&$$, 0, sizeof($$));
$$.index.location = @$;
$$.index.id = $2 + 1;
}
;
rule_position : chain_spec
{
$$ = $1;
}
| chain_spec position_spec
{
handle_merge(&$1, &$2);
$$ = $1;
}
| chain_spec handle_spec
{
$2.position.location = $2.handle.location;
$2.position.id = $2.handle.id;
$2.handle.id = 0;
handle_merge(&$1, &$2);
$$ = $1;
}
| chain_spec index_spec
{
handle_merge(&$1, &$2);
$$ = $1;
}
;
ruleid_spec : chain_spec handle_spec
{
handle_merge(&$1, &$2);
$$ = $1;
}
;
comment_spec : COMMENT string
{
if (strlen($2) > NFTNL_UDATA_COMMENT_MAXLEN) {
erec_queue(error(&@2, "comment too long, %d characters maximum allowed",
NFTNL_UDATA_COMMENT_MAXLEN),
state->msgs);
YYERROR;
}
$$ = $2;
}
;
ruleset_spec : /* empty */
{
memset(&$$, 0, sizeof($$));
$$.family = NFPROTO_UNSPEC;
}
| family_spec_explicit
{
memset(&$$, 0, sizeof($$));
$$.family = $1;
}
;
rule : rule_alloc
{
$$->comment = NULL;
}
| rule_alloc comment_spec
{
$$->comment = $2;
}
;
rule_alloc : stmt_list
{
struct stmt *i;
$$ = rule_alloc(&@$, NULL);
list_for_each_entry(i, $1, list)
$$->num_stmts++;
list_splice_tail($1, &$$->stmts);
xfree($1);
}
;
stmt_list : stmt
{
$$ = xmalloc(sizeof(*$$));
init_list_head($$);
list_add_tail(&$1->list, $$);
}
| stmt_list stmt
{
$$ = $1;
list_add_tail(&$2->list, $1);
}
;
stateful_stmt : counter_stmt
| limit_stmt
| quota_stmt
| connlimit_stmt
;
stmt : verdict_stmt
| match_stmt
| meter_stmt
| payload_stmt
| stateful_stmt
| meta_stmt
| log_stmt
| reject_stmt
| nat_stmt
| tproxy_stmt
| queue_stmt
| ct_stmt
| masq_stmt
| redir_stmt
| dup_stmt
| fwd_stmt
| set_stmt
| map_stmt
| synproxy_stmt
| chain_stmt
;
chain_stmt_type : JUMP { $$ = NFT_JUMP; }
| GOTO { $$ = NFT_GOTO; }
;
chain_stmt : chain_stmt_type chain_block_alloc '{' subchain_block '}'
{
$2->location = @2;
close_scope(state);
$4->location = @4;
$$ = chain_stmt_alloc(&@$, $4, $1);
}
;
verdict_stmt : verdict_expr
{
$$ = verdict_stmt_alloc(&@$, $1);
}
| verdict_map_stmt
{
$$ = verdict_stmt_alloc(&@$, $1);
}
;
verdict_map_stmt : concat_expr VMAP verdict_map_expr
{
$$ = map_expr_alloc(&@$, $1, $3);
}
;
verdict_map_expr : '{' verdict_map_list_expr '}'
{
$2->location = @$;
$$ = $2;
}
| set_ref_expr
;
verdict_map_list_expr : verdict_map_list_member_expr
{
$$ = set_expr_alloc(&@$, NULL);
compound_expr_add($$, $1);
}
| verdict_map_list_expr COMMA verdict_map_list_member_expr
{
compound_expr_add($1, $3);
$$ = $1;
}
| verdict_map_list_expr COMMA opt_newline
;
verdict_map_list_member_expr: opt_newline set_elem_expr COLON verdict_expr opt_newline
{
$$ = mapping_expr_alloc(&@$, $2, $4);
}
;
connlimit_stmt : CT COUNT NUM
{
$$ = connlimit_stmt_alloc(&@$);
$$->connlimit.count = $3;
}
| CT COUNT OVER NUM
{
$$ = connlimit_stmt_alloc(&@$);
$$->connlimit.count = $4;
$$->connlimit.flags = NFT_CONNLIMIT_F_INV;
}
;
counter_stmt : counter_stmt_alloc
| counter_stmt_alloc counter_args
counter_stmt_alloc : COUNTER
{
$$ = counter_stmt_alloc(&@$);
}
| COUNTER NAME stmt_expr
{
$$ = objref_stmt_alloc(&@$);
$$->objref.type = NFT_OBJECT_COUNTER;
$$->objref.expr = $3;
}
;
counter_args : counter_arg
{
$<stmt>$ = $<stmt>0;
}
| counter_args counter_arg
;
counter_arg : PACKETS NUM
{
$<stmt>0->counter.packets = $2;
}
| BYTES NUM
{
$<stmt>0->counter.bytes = $2;
}
;
log_stmt : log_stmt_alloc
| log_stmt_alloc log_args
;
log_stmt_alloc : LOG
{
$$ = log_stmt_alloc(&@$);
}
;
log_args : log_arg
{
$<stmt>$ = $<stmt>0;
}
| log_args log_arg
;
log_arg : PREFIX string
{
struct scope *scope = current_scope(state);
bool done = false, another_var = false;
char *start, *end, scratch = '\0';
struct expr *expr, *item;
struct symbol *sym;
enum {
PARSE_TEXT,
PARSE_VAR,
} prefix_state;
/* No variables in log prefix, skip. */
if (!strchr($2, '$')) {
expr = constant_expr_alloc(&@$, &string_type,
BYTEORDER_HOST_ENDIAN,
(strlen($2) + 1) * BITS_PER_BYTE, $2);
xfree($2);
$<stmt>0->log.prefix = expr;
$<stmt>0->log.flags |= STMT_LOG_PREFIX;
break;
}
/* Parse variables in log prefix string using a
* state machine parser with two states. This
* parser creates list of expressions composed
* of constant and variable expressions.
*/
expr = compound_expr_alloc(&@$, EXPR_LIST);
start = (char *)$2;
if (*start != '$') {
prefix_state = PARSE_TEXT;
} else {
prefix_state = PARSE_VAR;
start++;
}
end = start;
/* Not nice, but works. */
while (!done) {
switch (prefix_state) {
case PARSE_TEXT:
while (*end != '\0' && *end != '$')
end++;
if (*end == '\0')
done = true;
*end = '\0';
item = constant_expr_alloc(&@$, &string_type,
BYTEORDER_HOST_ENDIAN,
(strlen(start) + 1) * BITS_PER_BYTE,
start);
compound_expr_add(expr, item);
if (done)
break;
start = end + 1;
end = start;
/* fall through */
case PARSE_VAR:
while (isalnum(*end) || *end == '_')
end++;
if (*end == '\0')
done = true;
else if (*end == '$')
another_var = true;
else
scratch = *end;
*end = '\0';
sym = symbol_get(scope, start);
if (!sym) {
sym = symbol_lookup_fuzzy(scope, start);
if (sym) {
erec_queue(error(&@2, "unknown identifier '%s'; "
"did you mean identifier ‘%s’?",
start, sym->identifier),
state->msgs);
} else {
erec_queue(error(&@2, "unknown identifier '%s'",
start),
state->msgs);
}
expr_free(expr);
xfree($2);
YYERROR;
}
item = variable_expr_alloc(&@$, scope, sym);
compound_expr_add(expr, item);
if (done)
break;
/* Restore original byte after
* symbol lookup.
*/
if (scratch) {
*end = scratch;
scratch = '\0';
}
start = end;
if (another_var) {
another_var = false;
start++;
prefix_state = PARSE_VAR;
} else {
prefix_state = PARSE_TEXT;
}
end = start;
break;
}
}
xfree($2);
$<stmt>0->log.prefix = expr;
$<stmt>0->log.flags |= STMT_LOG_PREFIX;
}
| GROUP NUM
{
$<stmt>0->log.group = $2;
$<stmt>0->log.flags |= STMT_LOG_GROUP;
}
| SNAPLEN NUM
{
$<stmt>0->log.snaplen = $2;
$<stmt>0->log.flags |= STMT_LOG_SNAPLEN;
}
| QUEUE_THRESHOLD NUM
{
$<stmt>0->log.qthreshold = $2;
$<stmt>0->log.flags |= STMT_LOG_QTHRESHOLD;
}
| LEVEL level_type
{
$<stmt>0->log.level = $2;
$<stmt>0->log.flags |= STMT_LOG_LEVEL;
}
| FLAGS log_flags
{
$<stmt>0->log.logflags |= $2;
}
;
level_type : string
{
if (!strcmp("emerg", $1))
$$ = NFT_LOGLEVEL_EMERG;
else if (!strcmp("alert", $1))
$$ = NFT_LOGLEVEL_ALERT;
else if (!strcmp("crit", $1))
$$ = NFT_LOGLEVEL_CRIT;
else if (!strcmp("err", $1))
$$ = NFT_LOGLEVEL_ERR;
else if (!strcmp("warn", $1))
$$ = NFT_LOGLEVEL_WARNING;
else if (!strcmp("notice", $1))
$$ = NFT_LOGLEVEL_NOTICE;
else if (!strcmp("info", $1))
$$ = NFT_LOGLEVEL_INFO;
else if (!strcmp("debug", $1))
$$ = NFT_LOGLEVEL_DEBUG;
else if (!strcmp("audit", $1))
$$ = NFT_LOGLEVEL_AUDIT;
else {
erec_queue(error(&@1, "invalid log level"),
state->msgs);
xfree($1);
YYERROR;
}
xfree($1);
}
;
log_flags : TCP log_flags_tcp
{
$$ = $2;
}
| IP OPTIONS
{
$$ = NF_LOG_IPOPT;
}
| SKUID
{
$$ = NF_LOG_UID;
}
| ETHER
{
$$ = NF_LOG_MACDECODE;
}
| ALL
{
$$ = NF_LOG_MASK;
}
;
log_flags_tcp : log_flags_tcp COMMA log_flag_tcp
{
$$ = $1 | $3;
}
| log_flag_tcp
;
log_flag_tcp : SEQUENCE
{
$$ = NF_LOG_TCPSEQ;
}
| OPTIONS
{
$$ = NF_LOG_TCPOPT;
}
;
limit_stmt : LIMIT RATE limit_mode NUM SLASH time_unit limit_burst_pkts
{
$$ = limit_stmt_alloc(&@$);
$$->limit.rate = $4;
$$->limit.unit = $6;
$$->limit.burst = $7;
$$->limit.type = NFT_LIMIT_PKTS;
$$->limit.flags = $3;
}
| LIMIT RATE limit_mode NUM STRING limit_burst_bytes
{
struct error_record *erec;
uint64_t rate, unit;
erec = rate_parse(&@$, $5, &rate, &unit);
xfree($5);
if (erec != NULL) {
erec_queue(erec, state->msgs);
YYERROR;
}
$$ = limit_stmt_alloc(&@$);
$$->limit.rate = rate * $4;
$$->limit.unit = unit;
$$->limit.burst = $6;
$$->limit.type = NFT_LIMIT_PKT_BYTES;
$$->limit.flags = $3;
}
| LIMIT NAME stmt_expr
{
$$ = objref_stmt_alloc(&@$);
$$->objref.type = NFT_OBJECT_LIMIT;
$$->objref.expr = $3;
}
;
quota_mode : OVER { $$ = NFT_QUOTA_F_INV; }
| UNTIL { $$ = 0; }
| /* empty */ { $$ = 0; }
;
quota_unit : BYTES { $$ = xstrdup("bytes"); }
| STRING { $$ = $1; }
;
quota_used : /* empty */ { $$ = 0; }
| USED NUM quota_unit
{
struct error_record *erec;
uint64_t rate;
erec = data_unit_parse(&@$, $3, &rate);
xfree($3);
if (erec != NULL) {
erec_queue(erec, state->msgs);
YYERROR;
}
$$ = $2 * rate;
}
;
quota_stmt : QUOTA quota_mode NUM quota_unit quota_used
{
struct error_record *erec;
uint64_t rate;
erec = data_unit_parse(&@$, $4, &rate);
xfree($4);
if (erec != NULL) {
erec_queue(erec, state->msgs);
YYERROR;
}
$$ = quota_stmt_alloc(&@$);
$$->quota.bytes = $3 * rate;
$$->quota.used = $5;
$$->quota.flags = $2;
}
| QUOTA NAME stmt_expr
{
$$ = objref_stmt_alloc(&@$);
$$->objref.type = NFT_OBJECT_QUOTA;
$$->objref.expr = $3;
}
;
limit_mode : OVER { $$ = NFT_LIMIT_F_INV; }
| UNTIL { $$ = 0; }
| /* empty */ { $$ = 0; }
;
limit_burst_pkts : /* empty */ { $$ = 0; }
| BURST NUM PACKETS { $$ = $2; }
;
limit_burst_bytes : /* empty */ { $$ = 0; }
| BURST NUM BYTES { $$ = $2; }
| BURST NUM STRING
{
struct error_record *erec;
uint64_t rate;
erec = data_unit_parse(&@$, $3, &rate);
xfree($3);
if (erec != NULL) {
erec_queue(erec, state->msgs);
YYERROR;
}
$$ = $2 * rate;
}
;
time_unit : SECOND { $$ = 1ULL; }
| MINUTE { $$ = 1ULL * 60; }
| HOUR { $$ = 1ULL * 60 * 60; }
| DAY { $$ = 1ULL * 60 * 60 * 24; }
| WEEK { $$ = 1ULL * 60 * 60 * 24 * 7; }
;
reject_stmt : reject_stmt_alloc reject_opts
;
reject_stmt_alloc : _REJECT
{
$$ = reject_stmt_alloc(&@$);
}
;
reject_opts : /* empty */
{
$<stmt>0->reject.type = -1;
$<stmt>0->reject.icmp_code = -1;
}
| WITH ICMP TYPE STRING
{
$<stmt>0->reject.family = NFPROTO_IPV4;
$<stmt>0->reject.type = NFT_REJECT_ICMP_UNREACH;
$<stmt>0->reject.expr =
symbol_expr_alloc(&@$, SYMBOL_VALUE,
current_scope(state),
$4);
datatype_set($<stmt>0->reject.expr, &icmp_code_type);
xfree($4);
}
| WITH ICMP6 TYPE STRING
{
$<stmt>0->reject.family = NFPROTO_IPV6;
$<stmt>0->reject.type = NFT_REJECT_ICMP_UNREACH;
$<stmt>0->reject.expr =
symbol_expr_alloc(&@$, SYMBOL_VALUE,
current_scope(state),
$4);
datatype_set($<stmt>0->reject.expr, &icmpv6_code_type);
xfree($4);
}
| WITH ICMPX TYPE STRING
{
$<stmt>0->reject.type = NFT_REJECT_ICMPX_UNREACH;
$<stmt>0->reject.expr =
symbol_expr_alloc(&@$, SYMBOL_VALUE,
current_scope(state),
$4);
datatype_set($<stmt>0->reject.expr, &icmpx_code_type);
xfree($4);
}
| WITH TCP RESET
{
$<stmt>0->reject.type = NFT_REJECT_TCP_RST;
}
;
nat_stmt : nat_stmt_alloc nat_stmt_args
;
nat_stmt_alloc : SNAT { $$ = nat_stmt_alloc(&@$, NFT_NAT_SNAT); }
| DNAT { $$ = nat_stmt_alloc(&@$, NFT_NAT_DNAT); }
;
tproxy_stmt : TPROXY TO stmt_expr
{
$$ = tproxy_stmt_alloc(&@$);
$$->tproxy.family = NFPROTO_UNSPEC;
$$->tproxy.addr = $3;
}
| TPROXY nf_key_proto TO stmt_expr
{
$$ = tproxy_stmt_alloc(&@$);
$$->tproxy.family = $2;
$$->tproxy.addr = $4;
}
| TPROXY TO COLON stmt_expr
{
$$ = tproxy_stmt_alloc(&@$);
$$->tproxy.family = NFPROTO_UNSPEC;
$$->tproxy.port = $4;
}
| TPROXY TO stmt_expr COLON stmt_expr
{
$$ = tproxy_stmt_alloc(&@$);
$$->tproxy.family = NFPROTO_UNSPEC;
$$->tproxy.addr = $3;
$$->tproxy.port = $5;
}
| TPROXY nf_key_proto TO stmt_expr COLON stmt_expr
{
$$ = tproxy_stmt_alloc(&@$);
$$->tproxy.family = $2;
$$->tproxy.addr = $4;
$$->tproxy.port = $6;
}
| TPROXY nf_key_proto TO COLON stmt_expr
{
$$ = tproxy_stmt_alloc(&@$);
$$->tproxy.family = $2;
$$->tproxy.port = $5;
}
;
synproxy_stmt : synproxy_stmt_alloc
| synproxy_stmt_alloc synproxy_args
;
synproxy_stmt_alloc : SYNPROXY
{
$$ = synproxy_stmt_alloc(&@$);
}
| SYNPROXY NAME stmt_expr
{
$$ = objref_stmt_alloc(&@$);
$$->objref.type = NFT_OBJECT_SYNPROXY;
$$->objref.expr = $3;
}
;
synproxy_args : synproxy_arg
{
$<stmt>$ = $<stmt>0;
}
| synproxy_args synproxy_arg
;
synproxy_arg : MSS NUM
{
$<stmt>0->synproxy.mss = $2;
$<stmt>0->synproxy.flags |= NF_SYNPROXY_OPT_MSS;
}
| WSCALE NUM
{
$<stmt>0->synproxy.wscale = $2;
$<stmt>0->synproxy.flags |= NF_SYNPROXY_OPT_WSCALE;
}
| TIMESTAMP
{
$<stmt>0->synproxy.flags |= NF_SYNPROXY_OPT_TIMESTAMP;
}
| SACKPERM
{
$<stmt>0->synproxy.flags |= NF_SYNPROXY_OPT_SACK_PERM;
}
;
synproxy_config : MSS NUM WSCALE NUM synproxy_ts synproxy_sack
{
struct synproxy *synproxy;
uint32_t flags = 0;
synproxy = &$<obj>0->synproxy;
synproxy->mss = $2;
flags |= NF_SYNPROXY_OPT_MSS;
synproxy->wscale = $4;
flags |= NF_SYNPROXY_OPT_WSCALE;
if ($5)
flags |= $5;
if ($6)
flags |= $6;
synproxy->flags = flags;
}
| MSS NUM stmt_separator WSCALE NUM stmt_separator synproxy_ts synproxy_sack
{
struct synproxy *synproxy;
uint32_t flags = 0;
synproxy = &$<obj>0->synproxy;
synproxy->mss = $2;
flags |= NF_SYNPROXY_OPT_MSS;
synproxy->wscale = $5;
flags |= NF_SYNPROXY_OPT_WSCALE;
if ($7)
flags |= $7;
if ($8)
flags |= $8;
synproxy->flags = flags;
}
;
synproxy_obj : /* empty */
{
$$ = obj_alloc(&@$);
$$->type = NFT_OBJECT_SYNPROXY;
}
;
synproxy_ts : /* empty */ { $$ = 0; }
| TIMESTAMP
{
$$ = NF_SYNPROXY_OPT_TIMESTAMP;
}
;
synproxy_sack : /* empty */ { $$ = 0; }
| SACKPERM
{
$$ = NF_SYNPROXY_OPT_SACK_PERM;
}
;
primary_stmt_expr : symbol_expr { $$ = $1; }
| integer_expr { $$ = $1; }
| boolean_expr { $$ = $1; }
| meta_expr { $$ = $1; }
| rt_expr { $$ = $1; }
| ct_expr { $$ = $1; }
| numgen_expr { $$ = $1; }
| hash_expr { $$ = $1; }
| payload_expr { $$ = $1; }
| keyword_expr { $$ = $1; }
| socket_expr { $$ = $1; }
| osf_expr { $$ = $1; }
| '(' basic_stmt_expr ')' { $$ = $2; }
;
shift_stmt_expr : primary_stmt_expr
| shift_stmt_expr LSHIFT primary_stmt_expr
{
$$ = binop_expr_alloc(&@$, OP_LSHIFT, $1, $3);
}
| shift_stmt_expr RSHIFT primary_stmt_expr
{
$$ = binop_expr_alloc(&@$, OP_RSHIFT, $1, $3);
}
;
and_stmt_expr : shift_stmt_expr
| and_stmt_expr AMPERSAND shift_stmt_expr
{
$$ = binop_expr_alloc(&@$, OP_AND, $1, $3);
}
;
exclusive_or_stmt_expr : and_stmt_expr
| exclusive_or_stmt_expr CARET and_stmt_expr
{
$$ = binop_expr_alloc(&@$, OP_XOR, $1, $3);
}
;
inclusive_or_stmt_expr : exclusive_or_stmt_expr
| inclusive_or_stmt_expr '|' exclusive_or_stmt_expr
{
$$ = binop_expr_alloc(&@$, OP_OR, $1, $3);
}
;
basic_stmt_expr : inclusive_or_stmt_expr
;
concat_stmt_expr : basic_stmt_expr
| concat_stmt_expr DOT primary_stmt_expr
{
struct location rhs[] = {
[1] = @2,
[2] = @3,
};
$$ = handle_concat_expr(&@$, $$, $1, $3, rhs);
}
;
map_stmt_expr_set : set_expr
| set_ref_expr
;
map_stmt_expr : concat_stmt_expr MAP map_stmt_expr_set
{
$$ = map_expr_alloc(&@$, $1, $3);
}
| concat_stmt_expr { $$ = $1; }
;
prefix_stmt_expr : basic_stmt_expr SLASH NUM
{
$$ = prefix_expr_alloc(&@$, $1, $3);
}
;
range_stmt_expr : basic_stmt_expr DASH basic_stmt_expr
{
$$ = range_expr_alloc(&@$, $1, $3);
}
;
wildcard_expr : ASTERISK
{
struct expr *expr;
expr = constant_expr_alloc(&@$, &integer_type,
BYTEORDER_HOST_ENDIAN,
0, NULL);
$$ = prefix_expr_alloc(&@$, expr, 0);
}
;
multiton_stmt_expr : prefix_stmt_expr
| range_stmt_expr
| wildcard_expr
;
stmt_expr : map_stmt_expr
| multiton_stmt_expr
| list_stmt_expr
;
nat_stmt_args : stmt_expr
{
$<stmt>0->nat.addr = $1;
}
| TO stmt_expr
{
$<stmt>0->nat.addr = $2;
}
| nf_key_proto TO stmt_expr
{
$<stmt>0->nat.family = $1;
$<stmt>0->nat.addr = $3;
}
| stmt_expr COLON stmt_expr
{
$<stmt>0->nat.addr = $1;
$<stmt>0->nat.proto = $3;
}
| TO stmt_expr COLON stmt_expr
{
$<stmt>0->nat.addr = $2;
$<stmt>0->nat.proto = $4;
}
| nf_key_proto TO stmt_expr COLON stmt_expr
{
$<stmt>0->nat.family = $1;
$<stmt>0->nat.addr = $3;
$<stmt>0->nat.proto = $5;
}
| COLON stmt_expr
{
$<stmt>0->nat.proto = $2;
}
| TO COLON stmt_expr
{
$<stmt>0->nat.proto = $3;
}
| nat_stmt_args nf_nat_flags
{
$<stmt>0->nat.flags = $2;
}
| nf_key_proto ADDR DOT PORT TO stmt_expr
{
$<stmt>0->nat.family = $1;
$<stmt>0->nat.addr = $6;
$<stmt>0->nat.type_flags = STMT_NAT_F_CONCAT;
}
| nf_key_proto INTERVAL TO stmt_expr
{
$<stmt>0->nat.family = $1;
$<stmt>0->nat.addr = $4;
$<stmt>0->nat.type_flags = STMT_NAT_F_INTERVAL;
}
| INTERVAL TO stmt_expr
{
$<stmt>0->nat.addr = $3;
$<stmt>0->nat.type_flags = STMT_NAT_F_INTERVAL;
}
| nf_key_proto PREFIX TO stmt_expr
{
$<stmt>0->nat.family = $1;
$<stmt>0->nat.addr = $4;
$<stmt>0->nat.type_flags =
STMT_NAT_F_PREFIX |
STMT_NAT_F_INTERVAL;
$<stmt>0->nat.flags |= NF_NAT_RANGE_NETMAP;
}
| PREFIX TO stmt_expr
{
$<stmt>0->nat.addr = $3;
$<stmt>0->nat.type_flags =
STMT_NAT_F_PREFIX |
STMT_NAT_F_INTERVAL;
$<stmt>0->nat.flags |= NF_NAT_RANGE_NETMAP;
}
;
masq_stmt : masq_stmt_alloc masq_stmt_args
| masq_stmt_alloc
;
masq_stmt_alloc : MASQUERADE { $$ = nat_stmt_alloc(&@$, NFT_NAT_MASQ); }
;
masq_stmt_args : TO COLON stmt_expr
{
$<stmt>0->nat.proto = $3;
}
| TO COLON stmt_expr nf_nat_flags
{
$<stmt>0->nat.proto = $3;
$<stmt>0->nat.flags = $4;
}
| nf_nat_flags
{
$<stmt>0->nat.flags = $1;
}
;
redir_stmt : redir_stmt_alloc redir_stmt_arg
| redir_stmt_alloc
;
redir_stmt_alloc : REDIRECT { $$ = nat_stmt_alloc(&@$, NFT_NAT_REDIR); }
;
redir_stmt_arg : TO stmt_expr
{
$<stmt>0->nat.proto = $2;
}
| TO COLON stmt_expr
{
$<stmt>0->nat.proto = $3;
}
| nf_nat_flags
{
$<stmt>0->nat.flags = $1;
}
| TO stmt_expr nf_nat_flags
{
$<stmt>0->nat.proto = $2;
$<stmt>0->nat.flags = $3;
}
| TO COLON stmt_expr nf_nat_flags
{
$<stmt>0->nat.proto = $3;
$<stmt>0->nat.flags = $4;
}
;
dup_stmt : DUP TO stmt_expr
{
$$ = dup_stmt_alloc(&@$);
$$->dup.to = $3;
}
| DUP TO stmt_expr DEVICE stmt_expr
{
$$ = dup_stmt_alloc(&@$);
$$->dup.to = $3;
$$->dup.dev = $5;
}
;
fwd_stmt : FWD TO stmt_expr
{
$$ = fwd_stmt_alloc(&@$);
$$->fwd.dev = $3;
}
| FWD nf_key_proto TO stmt_expr DEVICE stmt_expr
{
$$ = fwd_stmt_alloc(&@$);
$$->fwd.family = $2;
$$->fwd.addr = $4;
$$->fwd.dev = $6;
}
;
nf_nat_flags : nf_nat_flag
| nf_nat_flags COMMA nf_nat_flag
{
$$ = $1 | $3;
}
;
nf_nat_flag : RANDOM { $$ = NF_NAT_RANGE_PROTO_RANDOM; }
| FULLY_RANDOM { $$ = NF_NAT_RANGE_PROTO_RANDOM_FULLY; }
| PERSISTENT { $$ = NF_NAT_RANGE_PERSISTENT; }
;
queue_stmt : queue_stmt_alloc
| queue_stmt_alloc queue_stmt_args
;
queue_stmt_alloc : QUEUE
{
$$ = queue_stmt_alloc(&@$);
}
;
queue_stmt_args : queue_stmt_arg
{
$<stmt>$ = $<stmt>0;
}
| queue_stmt_args queue_stmt_arg
;
queue_stmt_arg : QUEUENUM stmt_expr
{
$<stmt>0->queue.queue = $2;
$<stmt>0->queue.queue->location = @$;
}
| queue_stmt_flags
{
$<stmt>0->queue.flags |= $1;
}
;
queue_stmt_flags : queue_stmt_flag
| queue_stmt_flags COMMA queue_stmt_flag
{
$$ = $1 | $3;
}
;
queue_stmt_flag : BYPASS { $$ = NFT_QUEUE_FLAG_BYPASS; }
| FANOUT { $$ = NFT_QUEUE_FLAG_CPU_FANOUT; }
;
set_elem_expr_stmt : set_elem_expr_stmt_alloc
| set_elem_expr_stmt_alloc set_elem_options
;
set_elem_expr_stmt_alloc: concat_expr
{
$$ = set_elem_expr_alloc(&@1, $1);
}
;
set_stmt : SET set_stmt_op set_elem_expr_stmt set_ref_expr
{
$$ = set_stmt_alloc(&@$);
$$->set.op = $2;
$$->set.key = $3;
$$->set.set = $4;
}
| set_stmt_op set_ref_expr '{' set_elem_expr_stmt '}'
{
$$ = set_stmt_alloc(&@$);
$$->set.op = $1;
$$->set.key = $4;
$$->set.set = $2;
}
| set_stmt_op set_ref_expr '{' set_elem_expr_stmt stateful_stmt '}'
{
$$ = set_stmt_alloc(&@$);
$$->set.op = $1;
$$->set.key = $4;
$$->set.set = $2;
$$->set.stmt = $5;
}
;
set_stmt_op : ADD { $$ = NFT_DYNSET_OP_ADD; }
| UPDATE { $$ = NFT_DYNSET_OP_UPDATE; }
| DELETE { $$ = NFT_DYNSET_OP_DELETE; }
;
map_stmt : set_stmt_op set_ref_expr '{' set_elem_expr_stmt COLON set_elem_expr_stmt '}'
{
$$ = map_stmt_alloc(&@$);
$$->map.op = $1;
$$->map.key = $4;
$$->map.data = $6;
$$->map.set = $2;
}
| set_stmt_op set_ref_expr '{' set_elem_expr_stmt stateful_stmt COLON set_elem_expr_stmt '}'
{
$$ = map_stmt_alloc(&@$);
$$->map.op = $1;
$$->map.key = $4;
$$->map.data = $7;
$$->map.stmt = $5;
$$->map.set = $2;
}
;
meter_stmt : flow_stmt_legacy_alloc flow_stmt_opts '{' meter_key_expr stmt '}'
{
$1->meter.key = $4;
$1->meter.stmt = $5;
$$->location = @$;
$$ = $1;
}
| meter_stmt_alloc { $$ = $1; }
;
flow_stmt_legacy_alloc : FLOW
{
$$ = meter_stmt_alloc(&@$);
}
;
flow_stmt_opts : flow_stmt_opt
{
$<stmt>$ = $<stmt>0;
}
| flow_stmt_opts flow_stmt_opt
;
flow_stmt_opt : TABLE identifier
{
$<stmt>0->meter.name = $2;
}
;
meter_stmt_alloc : METER identifier '{' meter_key_expr stmt '}'
{
$$ = meter_stmt_alloc(&@$);
$$->meter.name = $2;
$$->meter.size = 0;
$$->meter.key = $4;
$$->meter.stmt = $5;
$$->location = @$;
}
| METER identifier SIZE NUM '{' meter_key_expr stmt '}'
{
$$ = meter_stmt_alloc(&@$);
$$->meter.name = $2;
$$->meter.size = $4;
$$->meter.key = $6;
$$->meter.stmt = $7;
$$->location = @$;
}
;
match_stmt : relational_expr
{
$$ = expr_stmt_alloc(&@$, $1);
}
;
variable_expr : '$' identifier
{
struct scope *scope = current_scope(state);
struct symbol *sym;
sym = symbol_get(scope, $2);
if (!sym) {
sym = symbol_lookup_fuzzy(scope, $2);
if (sym) {
erec_queue(error(&@2, "unknown identifier '%s'; "
"did you mean identifier ‘%s’?",
$2, sym->identifier),
state->msgs);
} else {
erec_queue(error(&@2, "unknown identifier '%s'", $2),
state->msgs);
}
xfree($2);
YYERROR;
}
$$ = variable_expr_alloc(&@$, scope, sym);
xfree($2);
}
;
symbol_expr : variable_expr
| string
{
$$ = symbol_expr_alloc(&@$, SYMBOL_VALUE,
current_scope(state),
$1);
xfree($1);
}
;
set_ref_expr : set_ref_symbol_expr
| variable_expr
;
set_ref_symbol_expr : AT identifier
{
$$ = symbol_expr_alloc(&@$, SYMBOL_SET,
current_scope(state),
$2);
xfree($2);
}
;
integer_expr : NUM
{
char str[64];
snprintf(str, sizeof(str), "%" PRIu64, $1);
$$ = symbol_expr_alloc(&@$, SYMBOL_VALUE,
current_scope(state),
str);
}
;
primary_expr : symbol_expr { $$ = $1; }
| integer_expr { $$ = $1; }
| payload_expr { $$ = $1; }
| exthdr_expr { $$ = $1; }
| exthdr_exists_expr { $$ = $1; }
| meta_expr { $$ = $1; }
| socket_expr { $$ = $1; }
| rt_expr { $$ = $1; }
| ct_expr { $$ = $1; }
| numgen_expr { $$ = $1; }
| hash_expr { $$ = $1; }
| fib_expr { $$ = $1; }
| osf_expr { $$ = $1; }
| xfrm_expr { $$ = $1; }
| '(' basic_expr ')' { $$ = $2; }
;
fib_expr : FIB fib_tuple fib_result
{
if (($2 & (NFTA_FIB_F_SADDR|NFTA_FIB_F_DADDR)) == 0) {
erec_queue(error(&@2, "fib: need either saddr or daddr"), state->msgs);
YYERROR;
}
if (($2 & (NFTA_FIB_F_SADDR|NFTA_FIB_F_DADDR)) ==
(NFTA_FIB_F_SADDR|NFTA_FIB_F_DADDR)) {
erec_queue(error(&@2, "fib: saddr and daddr are mutually exclusive"), state->msgs);
YYERROR;
}
if (($2 & (NFTA_FIB_F_IIF|NFTA_FIB_F_OIF)) ==
(NFTA_FIB_F_IIF|NFTA_FIB_F_OIF)) {
erec_queue(error(&@2, "fib: iif and oif are mutually exclusive"), state->msgs);
YYERROR;
}
$$ = fib_expr_alloc(&@$, $2, $3);
}
;
fib_result : OIF { $$ =NFT_FIB_RESULT_OIF; }
| OIFNAME { $$ =NFT_FIB_RESULT_OIFNAME; }
| TYPE { $$ =NFT_FIB_RESULT_ADDRTYPE; }
;
fib_flag : SADDR { $$ = NFTA_FIB_F_SADDR; }
| DADDR { $$ = NFTA_FIB_F_DADDR; }
| MARK { $$ = NFTA_FIB_F_MARK; }
| IIF { $$ = NFTA_FIB_F_IIF; }
| OIF { $$ = NFTA_FIB_F_OIF; }
;
fib_tuple : fib_flag DOT fib_tuple
{
$$ = $1 | $3;
}
| fib_flag
;
osf_expr : OSF osf_ttl HDRVERSION
{
$$ = osf_expr_alloc(&@$, $2, NFT_OSF_F_VERSION);
}
| OSF osf_ttl NAME
{
$$ = osf_expr_alloc(&@$, $2, 0);
}
;
osf_ttl : /* empty */
{
$$ = NF_OSF_TTL_TRUE;
}
| TTL STRING
{
if (!strcmp($2, "loose"))
$$ = NF_OSF_TTL_LESS;
else if (!strcmp($2, "skip"))
$$ = NF_OSF_TTL_NOCHECK;
else {
erec_queue(error(&@2, "invalid ttl option"),
state->msgs);
YYERROR;
}
}
;
shift_expr : primary_expr
| shift_expr LSHIFT primary_rhs_expr
{
$$ = binop_expr_alloc(&@$, OP_LSHIFT, $1, $3);
}
| shift_expr RSHIFT primary_rhs_expr
{
$$ = binop_expr_alloc(&@$, OP_RSHIFT, $1, $3);
}
;
and_expr : shift_expr
| and_expr AMPERSAND shift_rhs_expr
{
$$ = binop_expr_alloc(&@$, OP_AND, $1, $3);
}
;
exclusive_or_expr : and_expr
| exclusive_or_expr CARET and_rhs_expr
{
$$ = binop_expr_alloc(&@$, OP_XOR, $1, $3);
}
;
inclusive_or_expr : exclusive_or_expr
| inclusive_or_expr '|' exclusive_or_rhs_expr
{
$$ = binop_expr_alloc(&@$, OP_OR, $1, $3);
}
;
basic_expr : inclusive_or_expr
;
concat_expr : basic_expr
| concat_expr DOT basic_expr
{
struct location rhs[] = {
[1] = @2,
[2] = @3,
};
$$ = handle_concat_expr(&@$, $$, $1, $3, rhs);
}
;
prefix_rhs_expr : basic_rhs_expr SLASH NUM
{
$$ = prefix_expr_alloc(&@$, $1, $3);
}
;
range_rhs_expr : basic_rhs_expr DASH basic_rhs_expr
{
$$ = range_expr_alloc(&@$, $1, $3);
}
;
multiton_rhs_expr : prefix_rhs_expr
| range_rhs_expr
;
map_expr : concat_expr MAP rhs_expr
{
$$ = map_expr_alloc(&@$, $1, $3);
}
;
expr : concat_expr
| set_expr
| map_expr
;
set_expr : '{' set_list_expr '}'
{
$2->location = @$;
$$ = $2;
}
;
set_list_expr : set_list_member_expr
{
$$ = set_expr_alloc(&@$, NULL);
compound_expr_add($$, $1);
}
| set_list_expr COMMA set_list_member_expr
{
compound_expr_add($1, $3);
$$ = $1;
}
| set_list_expr COMMA opt_newline
;
set_list_member_expr : opt_newline set_expr opt_newline
{
$$ = $2;
}
| opt_newline set_elem_expr opt_newline
{
$$ = $2;
}
| opt_newline set_elem_expr COLON set_rhs_expr opt_newline
{
$$ = mapping_expr_alloc(&@$, $2, $4);
}
;
meter_key_expr : meter_key_expr_alloc
| meter_key_expr_alloc set_elem_options
{
$$->location = @$;
$$ = $1;
}
;
meter_key_expr_alloc : concat_expr
{
$$ = set_elem_expr_alloc(&@1, $1);
}
;
set_elem_expr : set_elem_expr_alloc
| set_elem_expr_alloc set_elem_expr_options
;
set_elem_expr_alloc : set_lhs_expr
{
$$ = set_elem_expr_alloc(&@1, $1);
}
;
set_elem_options : set_elem_option
{
$<expr>$ = $<expr>0;
}
| set_elem_options set_elem_option
;
set_elem_option : TIMEOUT time_spec
{
$<expr>0->timeout = $2;
}
| EXPIRES time_spec
{
$<expr>0->expiration = $2;
}
| comment_spec
{
$<expr>0->comment = $1;
}
;
set_elem_expr_options : set_elem_expr_option
{
$<expr>$ = $<expr>0;
}
| set_elem_expr_options set_elem_expr_option
;
set_elem_expr_option : TIMEOUT time_spec
{
$<expr>0->timeout = $2;
}
| EXPIRES time_spec
{
$<expr>0->expiration = $2;
}
| COUNTER
{
$<expr>0->stmt = counter_stmt_alloc(&@$);
}
| COUNTER PACKETS NUM BYTES NUM
{
struct stmt *stmt;
stmt = counter_stmt_alloc(&@$);
stmt->counter.packets = $3;
stmt->counter.bytes = $5;
$<expr>0->stmt = stmt;
}
| comment_spec
{
$<expr>0->comment = $1;
}
;
set_lhs_expr : concat_rhs_expr
| wildcard_expr
;
set_rhs_expr : concat_rhs_expr
| verdict_expr
;
initializer_expr : rhs_expr
| list_rhs_expr
| '{' '}' { $$ = compound_expr_alloc(&@$, EXPR_SET); }
| DASH NUM
{
int32_t num = -$2;
$$ = constant_expr_alloc(&@$, &integer_type,
BYTEORDER_HOST_ENDIAN,
sizeof(num) * BITS_PER_BYTE,
&num);
}
;
counter_config : PACKETS NUM BYTES NUM
{
struct counter *counter;
counter = &$<obj>0->counter;
counter->packets = $2;
counter->bytes = $4;
}
;
counter_obj : /* empty */
{
$$ = obj_alloc(&@$);
$$->type = NFT_OBJECT_COUNTER;
}
;
quota_config : quota_mode NUM quota_unit quota_used
{
struct error_record *erec;
struct quota *quota;
uint64_t rate;
erec = data_unit_parse(&@$, $3, &rate);
xfree($3);
if (erec != NULL) {
erec_queue(erec, state->msgs);
YYERROR;
}
quota = &$<obj>0->quota;
quota->bytes = $2 * rate;
quota->used = $4;
quota->flags = $1;
}
;
quota_obj : /* empty */
{
$$ = obj_alloc(&@$);
$$->type = NFT_OBJECT_QUOTA;
}
;
secmark_config : string
{
int ret;
struct secmark *secmark;
secmark = &$<obj>0->secmark;
ret = snprintf(secmark->ctx, sizeof(secmark->ctx), "%s", $1);
if (ret <= 0 || ret >= (int)sizeof(secmark->ctx)) {
erec_queue(error(&@1, "invalid context '%s', max length is %u\n", $1, (int)sizeof(secmark->ctx)), state->msgs);
xfree($1);
YYERROR;
}
xfree($1);
}
;
secmark_obj : /* empty */
{
$$ = obj_alloc(&@$);
$$->type = NFT_OBJECT_SECMARK;
}
;
ct_obj_type : HELPER { $$ = NFT_OBJECT_CT_HELPER; }
| TIMEOUT { $$ = NFT_OBJECT_CT_TIMEOUT; }
| EXPECTATION { $$ = NFT_OBJECT_CT_EXPECT; }
;
ct_l4protoname : TCP { $$ = IPPROTO_TCP; }
| UDP { $$ = IPPROTO_UDP; }
;
ct_helper_config : TYPE QUOTED_STRING PROTOCOL ct_l4protoname stmt_separator
{
struct ct_helper *ct;
int ret;
ct = &$<obj>0->ct_helper;
ret = snprintf(ct->name, sizeof(ct->name), "%s", $2);
if (ret <= 0 || ret >= (int)sizeof(ct->name)) {
erec_queue(error(&@2, "invalid name '%s', max length is %u\n", $2, (int)sizeof(ct->name)), state->msgs);
YYERROR;
}
xfree($2);
ct->l4proto = $4;
}
| L3PROTOCOL family_spec_explicit stmt_separator
{
$<obj>0->ct_helper.l3proto = $2;
}
;
timeout_states : timeout_state
{
$$ = xmalloc(sizeof(*$$));
init_list_head($$);
list_add_tail($1, $$);
}
| timeout_states COMMA timeout_state
{
list_add_tail($3, $1);
$$ = $1;
}
;
timeout_state : STRING COLON NUM
{
struct timeout_state *ts;
ts = xzalloc(sizeof(*ts));
ts->timeout_str = $1;
ts->timeout_value = $3;
ts->location = @1;
init_list_head(&ts->head);
$$ = &ts->head;
}
;
ct_timeout_config : PROTOCOL ct_l4protoname stmt_separator
{
struct ct_timeout *ct;
int l4proto = $2;
ct = &$<obj>0->ct_timeout;
ct->l4proto = l4proto;
}
| POLICY '=' '{' timeout_states '}' stmt_separator
{
struct ct_timeout *ct;
ct = &$<obj>0->ct_timeout;
list_splice_tail($4, &ct->timeout_list);
xfree($4);
}
| L3PROTOCOL family_spec_explicit stmt_separator
{
$<obj>0->ct_timeout.l3proto = $2;
}
;
ct_expect_config : PROTOCOL ct_l4protoname stmt_separator
{
$<obj>0->ct_expect.l4proto = $2;
}
| DPORT NUM stmt_separator
{
$<obj>0->ct_expect.dport = $2;
}
| TIMEOUT time_spec stmt_separator
{
$<obj>0->ct_expect.timeout = $2;
}
| SIZE NUM stmt_separator
{
$<obj>0->ct_expect.size = $2;
}
| L3PROTOCOL family_spec_explicit stmt_separator
{
$<obj>0->ct_expect.l3proto = $2;
}
;
ct_obj_alloc : /* empty */
{
$$ = obj_alloc(&@$);
}
;
limit_config : RATE limit_mode NUM SLASH time_unit limit_burst_pkts
{
struct limit *limit;
limit = &$<obj>0->limit;
limit->rate = $3;
limit->unit = $5;
limit->burst = $6;
limit->type = NFT_LIMIT_PKTS;
limit->flags = $2;
}
| RATE limit_mode NUM STRING limit_burst_bytes
{
struct limit *limit;
struct error_record *erec;
uint64_t rate, unit;
erec = rate_parse(&@$, $4, &rate, &unit);
if (erec != NULL) {
erec_queue(erec, state->msgs);
YYERROR;
}
limit = &$<obj>0->limit;
limit->rate = rate * $3;
limit->unit = unit;
limit->burst = $5;
limit->type = NFT_LIMIT_PKT_BYTES;
limit->flags = $2;
}
;
limit_obj : /* empty */
{
$$ = obj_alloc(&@$);
$$->type = NFT_OBJECT_LIMIT;
}
;
relational_expr : expr /* implicit */ rhs_expr
{
$$ = relational_expr_alloc(&@$, OP_IMPLICIT, $1, $2);
}
| expr /* implicit */ list_rhs_expr
{
$$ = relational_expr_alloc(&@$, OP_IMPLICIT, $1, $2);
}
| expr relational_op rhs_expr
{
$$ = relational_expr_alloc(&@2, $2, $1, $3);
}
;
list_rhs_expr : basic_rhs_expr COMMA basic_rhs_expr
{
$$ = list_expr_alloc(&@$);
compound_expr_add($$, $1);
compound_expr_add($$, $3);
}
| list_rhs_expr COMMA basic_rhs_expr
{
$1->location = @$;
compound_expr_add($1, $3);
$$ = $1;
}
;
rhs_expr : concat_rhs_expr { $$ = $1; }
| wildcard_expr { $$ = $1; }
| set_expr { $$ = $1; }
| set_ref_symbol_expr { $$ = $1; }
;
shift_rhs_expr : primary_rhs_expr
| shift_rhs_expr LSHIFT primary_rhs_expr
{
$$ = binop_expr_alloc(&@$, OP_LSHIFT, $1, $3);
}
| shift_rhs_expr RSHIFT primary_rhs_expr
{
$$ = binop_expr_alloc(&@$, OP_RSHIFT, $1, $3);
}
;
and_rhs_expr : shift_rhs_expr
| and_rhs_expr AMPERSAND shift_rhs_expr
{
$$ = binop_expr_alloc(&@$, OP_AND, $1, $3);
}
;
exclusive_or_rhs_expr : and_rhs_expr
| exclusive_or_rhs_expr CARET and_rhs_expr
{
$$ = binop_expr_alloc(&@$, OP_XOR, $1, $3);
}
;
inclusive_or_rhs_expr : exclusive_or_rhs_expr
| inclusive_or_rhs_expr '|' exclusive_or_rhs_expr
{
$$ = binop_expr_alloc(&@$, OP_OR, $1, $3);
}
;
basic_rhs_expr : inclusive_or_rhs_expr
;
concat_rhs_expr : basic_rhs_expr
| multiton_rhs_expr
| concat_rhs_expr DOT multiton_rhs_expr
{
struct location rhs[] = {
[1] = @2,
[2] = @3,
};
$$ = handle_concat_expr(&@$, $$, $1, $3, rhs);
}
| concat_rhs_expr DOT basic_rhs_expr
{
struct location rhs[] = {
[1] = @2,
[2] = @3,
};
$$ = handle_concat_expr(&@$, $$, $1, $3, rhs);
}
;
boolean_keys : EXISTS { $$ = true; }
| MISSING { $$ = false; }
;
boolean_expr : boolean_keys
{
$$ = constant_expr_alloc(&@$, &boolean_type,
BYTEORDER_HOST_ENDIAN,
sizeof($1) * BITS_PER_BYTE, &$1);
}
;
keyword_expr : ETHER { $$ = symbol_value(&@$, "ether"); }
| IP { $$ = symbol_value(&@$, "ip"); }
| IP6 { $$ = symbol_value(&@$, "ip6"); }
| VLAN { $$ = symbol_value(&@$, "vlan"); }
| ARP { $$ = symbol_value(&@$, "arp"); }
| DNAT { $$ = symbol_value(&@$, "dnat"); }
| SNAT { $$ = symbol_value(&@$, "snat"); }
| ECN { $$ = symbol_value(&@$, "ecn"); }
| RESET { $$ = symbol_value(&@$, "reset"); }
| ORIGINAL { $$ = symbol_value(&@$, "original"); }
| REPLY { $$ = symbol_value(&@$, "reply"); }
| LABEL { $$ = symbol_value(&@$, "label"); }
;
primary_rhs_expr : symbol_expr { $$ = $1; }
| integer_expr { $$ = $1; }
| boolean_expr { $$ = $1; }
| keyword_expr { $$ = $1; }
| TCP
{
uint8_t data = IPPROTO_TCP;
$$ = constant_expr_alloc(&@$, &inet_protocol_type,
BYTEORDER_HOST_ENDIAN,
sizeof(data) * BITS_PER_BYTE, &data);
}
| UDP
{
uint8_t data = IPPROTO_UDP;
$$ = constant_expr_alloc(&@$, &inet_protocol_type,
BYTEORDER_HOST_ENDIAN,
sizeof(data) * BITS_PER_BYTE, &data);
}
| UDPLITE
{
uint8_t data = IPPROTO_UDPLITE;
$$ = constant_expr_alloc(&@$, &inet_protocol_type,
BYTEORDER_HOST_ENDIAN,
sizeof(data) * BITS_PER_BYTE, &data);
}
| ESP
{
uint8_t data = IPPROTO_ESP;
$$ = constant_expr_alloc(&@$, &inet_protocol_type,
BYTEORDER_HOST_ENDIAN,
sizeof(data) * BITS_PER_BYTE, &data);
}
| AH
{
uint8_t data = IPPROTO_AH;
$$ = constant_expr_alloc(&@$, &inet_protocol_type,
BYTEORDER_HOST_ENDIAN,
sizeof(data) * BITS_PER_BYTE, &data);
}
| ICMP
{
uint8_t data = IPPROTO_ICMP;
$$ = constant_expr_alloc(&@$, &inet_protocol_type,
BYTEORDER_HOST_ENDIAN,
sizeof(data) * BITS_PER_BYTE, &data);
}
| IGMP
{
uint8_t data = IPPROTO_IGMP;
$$ = constant_expr_alloc(&@$, &inet_protocol_type,
BYTEORDER_HOST_ENDIAN,
sizeof(data) * BITS_PER_BYTE, &data);
}
| ICMP6
{
uint8_t data = IPPROTO_ICMPV6;
$$ = constant_expr_alloc(&@$, &inet_protocol_type,
BYTEORDER_HOST_ENDIAN,
sizeof(data) * BITS_PER_BYTE, &data);
}
| COMP
{
uint8_t data = IPPROTO_COMP;
$$ = constant_expr_alloc(&@$, &inet_protocol_type,
BYTEORDER_HOST_ENDIAN,
sizeof(data) * BITS_PER_BYTE, &data);
}
| DCCP
{
uint8_t data = IPPROTO_DCCP;
$$ = constant_expr_alloc(&@$, &inet_protocol_type,
BYTEORDER_HOST_ENDIAN,
sizeof(data) * BITS_PER_BYTE, &data);
}
| SCTP
{
uint8_t data = IPPROTO_SCTP;
$$ = constant_expr_alloc(&@$, &inet_protocol_type,
BYTEORDER_HOST_ENDIAN,
sizeof(data) * BITS_PER_BYTE, &data);
}
| REDIRECT
{
uint8_t data = ICMP_REDIRECT;
$$ = constant_expr_alloc(&@$, &icmp_type_type,
BYTEORDER_HOST_ENDIAN,
sizeof(data) * BITS_PER_BYTE, &data);
}
| '(' basic_rhs_expr ')' { $$ = $2; }
;
relational_op : EQ { $$ = OP_EQ; }
| NEQ { $$ = OP_NEQ; }
| LT { $$ = OP_LT; }
| GT { $$ = OP_GT; }
| GTE { $$ = OP_GTE; }
| LTE { $$ = OP_LTE; }
;
verdict_expr : ACCEPT
{
$$ = verdict_expr_alloc(&@$, NF_ACCEPT, NULL);
}
| DROP
{
$$ = verdict_expr_alloc(&@$, NF_DROP, NULL);
}
| CONTINUE
{
$$ = verdict_expr_alloc(&@$, NFT_CONTINUE, NULL);
}
| JUMP chain_expr
{
$$ = verdict_expr_alloc(&@$, NFT_JUMP, $2);
}
| GOTO chain_expr
{
$$ = verdict_expr_alloc(&@$, NFT_GOTO, $2);
}
| RETURN
{
$$ = verdict_expr_alloc(&@$, NFT_RETURN, NULL);
}
;
chain_expr : variable_expr
| identifier
{
$$ = constant_expr_alloc(&@$, &string_type,
BYTEORDER_HOST_ENDIAN,
strlen($1) * BITS_PER_BYTE,
$1);
xfree($1);
}
;
meta_expr : META meta_key
{
$$ = meta_expr_alloc(&@$, $2);
}
| meta_key_unqualified
{
$$ = meta_expr_alloc(&@$, $1);
}
| META STRING
{
struct error_record *erec;
unsigned int key;
erec = meta_key_parse(&@$, $2, &key);
xfree($2);
if (erec != NULL) {
erec_queue(erec, state->msgs);
YYERROR;
}
$$ = meta_expr_alloc(&@$, key);
}
;
meta_key : meta_key_qualified
| meta_key_unqualified
;
meta_key_qualified : LENGTH { $$ = NFT_META_LEN; }
| PROTOCOL { $$ = NFT_META_PROTOCOL; }
| PRIORITY { $$ = NFT_META_PRIORITY; }
| RANDOM { $$ = NFT_META_PRANDOM; }
| SECMARK { $$ = NFT_META_SECMARK; }
;
meta_key_unqualified : MARK { $$ = NFT_META_MARK; }
| IIF { $$ = NFT_META_IIF; }
| IIFNAME { $$ = NFT_META_IIFNAME; }
| IIFTYPE { $$ = NFT_META_IIFTYPE; }
| OIF { $$ = NFT_META_OIF; }
| OIFNAME { $$ = NFT_META_OIFNAME; }
| OIFTYPE { $$ = NFT_META_OIFTYPE; }
| SKUID { $$ = NFT_META_SKUID; }
| SKGID { $$ = NFT_META_SKGID; }
| NFTRACE { $$ = NFT_META_NFTRACE; }
| RTCLASSID { $$ = NFT_META_RTCLASSID; }
| IBRIPORT { $$ = NFT_META_BRI_IIFNAME; }
| OBRIPORT { $$ = NFT_META_BRI_OIFNAME; }
| IBRIDGENAME { $$ = NFT_META_BRI_IIFNAME; }
| OBRIDGENAME { $$ = NFT_META_BRI_OIFNAME; }
| PKTTYPE { $$ = NFT_META_PKTTYPE; }
| CPU { $$ = NFT_META_CPU; }
| IIFGROUP { $$ = NFT_META_IIFGROUP; }
| OIFGROUP { $$ = NFT_META_OIFGROUP; }
| CGROUP { $$ = NFT_META_CGROUP; }
| IPSEC { $$ = NFT_META_SECPATH; }
| TIME { $$ = NFT_META_TIME_NS; }
| DAY { $$ = NFT_META_TIME_DAY; }
| HOUR { $$ = NFT_META_TIME_HOUR; }
;
meta_stmt : META meta_key SET stmt_expr
{
switch ($2) {
case NFT_META_SECMARK:
switch ($4->etype) {
case EXPR_CT:
$$ = meta_stmt_alloc(&@$, $2, $4);
break;
default:
$$ = objref_stmt_alloc(&@$);
$$->objref.type = NFT_OBJECT_SECMARK;
$$->objref.expr = $4;
break;
}
break;
default:
$$ = meta_stmt_alloc(&@$, $2, $4);
break;
}
}
| meta_key_unqualified SET stmt_expr
{
$$ = meta_stmt_alloc(&@$, $1, $3);
}
| META STRING SET stmt_expr
{
struct error_record *erec;
unsigned int key;
erec = meta_key_parse(&@$, $2, &key);
xfree($2);
if (erec != NULL) {
erec_queue(erec, state->msgs);
YYERROR;
}
$$ = meta_stmt_alloc(&@$, key, $4);
}
| NOTRACK
{
$$ = notrack_stmt_alloc(&@$);
}
| FLOW OFFLOAD AT string
{
$$ = flow_offload_stmt_alloc(&@$, $4);
}
| FLOW ADD AT string
{
$$ = flow_offload_stmt_alloc(&@$, $4);
}
;
socket_expr : SOCKET socket_key
{
$$ = socket_expr_alloc(&@$, $2);
}
;
socket_key : TRANSPARENT { $$ = NFT_SOCKET_TRANSPARENT; }
| MARK { $$ = NFT_SOCKET_MARK; }
;
offset_opt : /* empty */ { $$ = 0; }
| OFFSET NUM { $$ = $2; }
;
numgen_type : INC { $$ = NFT_NG_INCREMENTAL; }
| RANDOM { $$ = NFT_NG_RANDOM; }
;
numgen_expr : NUMGEN numgen_type MOD NUM offset_opt
{
$$ = numgen_expr_alloc(&@$, $2, $4, $5);
}
;
xfrm_spnum : SPNUM NUM { $$ = $2; }
| { $$ = 0; }
;
xfrm_dir : IN { $$ = XFRM_POLICY_IN; }
| OUT { $$ = XFRM_POLICY_OUT; }
;
xfrm_state_key : SPI { $$ = NFT_XFRM_KEY_SPI; }
| REQID { $$ = NFT_XFRM_KEY_REQID; }
;
xfrm_state_proto_key : DADDR { $$ = NFT_XFRM_KEY_DADDR_IP4; }
| SADDR { $$ = NFT_XFRM_KEY_SADDR_IP4; }
;
xfrm_expr : IPSEC xfrm_dir xfrm_spnum xfrm_state_key
{
if ($3 > 255) {
erec_queue(error(&@3, "value too large"), state->msgs);
YYERROR;
}
$$ = xfrm_expr_alloc(&@$, $2, $3, $4);
}
| IPSEC xfrm_dir xfrm_spnum nf_key_proto xfrm_state_proto_key
{
enum nft_xfrm_keys xfrmk = $5;
switch ($4) {
case NFPROTO_IPV4:
break;
case NFPROTO_IPV6:
if ($5 == NFT_XFRM_KEY_SADDR_IP4)
xfrmk = NFT_XFRM_KEY_SADDR_IP6;
else if ($5 == NFT_XFRM_KEY_DADDR_IP4)
xfrmk = NFT_XFRM_KEY_DADDR_IP6;
break;
default:
YYERROR;
break;
}
if ($3 > 255) {
erec_queue(error(&@3, "value too large"), state->msgs);
YYERROR;
}
$$ = xfrm_expr_alloc(&@$, $2, $3, xfrmk);
}
;
hash_expr : JHASH expr MOD NUM SEED NUM offset_opt
{
$$ = hash_expr_alloc(&@$, $4, true, $6, $7, NFT_HASH_JENKINS);
$$->hash.expr = $2;
}
| JHASH expr MOD NUM offset_opt
{
$$ = hash_expr_alloc(&@$, $4, false, 0, $5, NFT_HASH_JENKINS);
$$->hash.expr = $2;
}
| SYMHASH MOD NUM offset_opt
{
$$ = hash_expr_alloc(&@$, $3, false, 0, $4, NFT_HASH_SYM);
}
;
nf_key_proto : IP { $$ = NFPROTO_IPV4; }
| IP6 { $$ = NFPROTO_IPV6; }
;
rt_expr : RT rt_key
{
$$ = rt_expr_alloc(&@$, $2, true);
}
| RT nf_key_proto rt_key
{
enum nft_rt_keys rtk = $3;
switch ($2) {
case NFPROTO_IPV4:
break;
case NFPROTO_IPV6:
if ($3 == NFT_RT_NEXTHOP4)
rtk = NFT_RT_NEXTHOP6;
break;
default:
YYERROR;
break;
}
$$ = rt_expr_alloc(&@$, rtk, false);
}
;
rt_key : CLASSID { $$ = NFT_RT_CLASSID; }
| NEXTHOP { $$ = NFT_RT_NEXTHOP4; }
| MTU { $$ = NFT_RT_TCPMSS; }
| IPSEC { $$ = NFT_RT_XFRM; }
;
ct_expr : CT ct_key
{
$$ = ct_expr_alloc(&@$, $2, -1);
}
| CT ct_dir ct_key_dir
{
$$ = ct_expr_alloc(&@$, $3, $2);
}
| CT ct_dir ct_key_proto_field
{
$$ = ct_expr_alloc(&@$, $3, $2);
}
;
ct_dir : ORIGINAL { $$ = IP_CT_DIR_ORIGINAL; }
| REPLY { $$ = IP_CT_DIR_REPLY; }
;
ct_key : L3PROTOCOL { $$ = NFT_CT_L3PROTOCOL; }
| PROTOCOL { $$ = NFT_CT_PROTOCOL; }
| MARK { $$ = NFT_CT_MARK; }
| STATE { $$ = NFT_CT_STATE; }
| DIRECTION { $$ = NFT_CT_DIRECTION; }
| STATUS { $$ = NFT_CT_STATUS; }
| EXPIRATION { $$ = NFT_CT_EXPIRATION; }
| HELPER { $$ = NFT_CT_HELPER; }
| SADDR { $$ = NFT_CT_SRC; }
| DADDR { $$ = NFT_CT_DST; }
| PROTO_SRC { $$ = NFT_CT_PROTO_SRC; }
| PROTO_DST { $$ = NFT_CT_PROTO_DST; }
| LABEL { $$ = NFT_CT_LABELS; }
| EVENT { $$ = NFT_CT_EVENTMASK; }
| SECMARK { $$ = NFT_CT_SECMARK; }
| ID { $$ = NFT_CT_ID; }
| ct_key_dir_optional
;
ct_key_dir : SADDR { $$ = NFT_CT_SRC; }
| DADDR { $$ = NFT_CT_DST; }
| L3PROTOCOL { $$ = NFT_CT_L3PROTOCOL; }
| PROTOCOL { $$ = NFT_CT_PROTOCOL; }
| PROTO_SRC { $$ = NFT_CT_PROTO_SRC; }
| PROTO_DST { $$ = NFT_CT_PROTO_DST; }
| ct_key_dir_optional
;
ct_key_proto_field : IP SADDR { $$ = NFT_CT_SRC_IP; }
| IP DADDR { $$ = NFT_CT_DST_IP; }
| IP6 SADDR { $$ = NFT_CT_SRC_IP6; }
| IP6 DADDR { $$ = NFT_CT_DST_IP6; }
;
ct_key_dir_optional : BYTES { $$ = NFT_CT_BYTES; }
| PACKETS { $$ = NFT_CT_PKTS; }
| AVGPKT { $$ = NFT_CT_AVGPKT; }
| ZONE { $$ = NFT_CT_ZONE; }
;
symbol_stmt_expr : symbol_expr
| keyword_expr
;
list_stmt_expr : symbol_stmt_expr COMMA symbol_stmt_expr
{
$$ = list_expr_alloc(&@$);
compound_expr_add($$, $1);
compound_expr_add($$, $3);
}
| list_stmt_expr COMMA symbol_stmt_expr
{
$1->location = @$;
compound_expr_add($1, $3);
$$ = $1;
}
;
ct_stmt : CT ct_key SET stmt_expr
{
switch ($2) {
case NFT_CT_HELPER:
$$ = objref_stmt_alloc(&@$);
$$->objref.type = NFT_OBJECT_CT_HELPER;
$$->objref.expr = $4;
break;
default:
$$ = ct_stmt_alloc(&@$, $2, -1, $4);
break;
}
}
| CT TIMEOUT SET stmt_expr
{
$$ = objref_stmt_alloc(&@$);
$$->objref.type = NFT_OBJECT_CT_TIMEOUT;
$$->objref.expr = $4;
}
| CT EXPECTATION SET stmt_expr
{
$$ = objref_stmt_alloc(&@$);
$$->objref.type = NFT_OBJECT_CT_EXPECT;
$$->objref.expr = $4;
}
| CT ct_dir ct_key_dir_optional SET stmt_expr
{
$$ = ct_stmt_alloc(&@$, $3, $2, $5);
}
;
payload_stmt : payload_expr SET stmt_expr
{
if ($1->etype == EXPR_EXTHDR)
$$ = exthdr_stmt_alloc(&@$, $1, $3);
else
$$ = payload_stmt_alloc(&@$, $1, $3);
}
;
payload_expr : payload_raw_expr
| eth_hdr_expr
| vlan_hdr_expr
| arp_hdr_expr
| ip_hdr_expr
| icmp_hdr_expr
| igmp_hdr_expr
| ip6_hdr_expr
| icmp6_hdr_expr
| auth_hdr_expr
| esp_hdr_expr
| comp_hdr_expr
| udp_hdr_expr
| udplite_hdr_expr
| tcp_hdr_expr
| dccp_hdr_expr
| sctp_hdr_expr
| th_hdr_expr
;
payload_raw_expr : AT payload_base_spec COMMA NUM COMMA NUM
{
$$ = payload_expr_alloc(&@$, NULL, 0);
payload_init_raw($$, $2, $4, $6);
$$->byteorder = BYTEORDER_BIG_ENDIAN;
$$->payload.is_raw = true;
}
;
payload_base_spec : LL_HDR { $$ = PROTO_BASE_LL_HDR; }
| NETWORK_HDR { $$ = PROTO_BASE_NETWORK_HDR; }
| TRANSPORT_HDR { $$ = PROTO_BASE_TRANSPORT_HDR; }
;
eth_hdr_expr : ETHER eth_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_eth, $2);
}
;
eth_hdr_field : SADDR { $$ = ETHHDR_SADDR; }
| DADDR { $$ = ETHHDR_DADDR; }
| TYPE { $$ = ETHHDR_TYPE; }
;
vlan_hdr_expr : VLAN vlan_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_vlan, $2);
}
;
vlan_hdr_field : ID { $$ = VLANHDR_VID; }
| CFI { $$ = VLANHDR_CFI; }
| PCP { $$ = VLANHDR_PCP; }
| TYPE { $$ = VLANHDR_TYPE; }
;
arp_hdr_expr : ARP arp_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_arp, $2);
}
;
arp_hdr_field : HTYPE { $$ = ARPHDR_HRD; }
| PTYPE { $$ = ARPHDR_PRO; }
| HLEN { $$ = ARPHDR_HLN; }
| PLEN { $$ = ARPHDR_PLN; }
| OPERATION { $$ = ARPHDR_OP; }
| SADDR ETHER { $$ = ARPHDR_SADDR_ETHER; }
| DADDR ETHER { $$ = ARPHDR_DADDR_ETHER; }
| SADDR IP { $$ = ARPHDR_SADDR_IP; }
| DADDR IP { $$ = ARPHDR_DADDR_IP; }
;
ip_hdr_expr : IP ip_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_ip, $2);
}
| IP OPTION ip_option_type ip_option_field
{
$$ = ipopt_expr_alloc(&@$, $3, $4, 0);
}
| IP OPTION ip_option_type
{
$$ = ipopt_expr_alloc(&@$, $3, IPOPT_FIELD_TYPE, 0);
$$->exthdr.flags = NFT_EXTHDR_F_PRESENT;
}
;
ip_hdr_field : HDRVERSION { $$ = IPHDR_VERSION; }
| HDRLENGTH { $$ = IPHDR_HDRLENGTH; }
| DSCP { $$ = IPHDR_DSCP; }
| ECN { $$ = IPHDR_ECN; }
| LENGTH { $$ = IPHDR_LENGTH; }
| ID { $$ = IPHDR_ID; }
| FRAG_OFF { $$ = IPHDR_FRAG_OFF; }
| TTL { $$ = IPHDR_TTL; }
| PROTOCOL { $$ = IPHDR_PROTOCOL; }
| CHECKSUM { $$ = IPHDR_CHECKSUM; }
| SADDR { $$ = IPHDR_SADDR; }
| DADDR { $$ = IPHDR_DADDR; }
;
ip_option_type : LSRR { $$ = IPOPT_LSRR; }
| RR { $$ = IPOPT_RR; }
| SSRR { $$ = IPOPT_SSRR; }
| RA { $$ = IPOPT_RA; }
;
ip_option_field : TYPE { $$ = IPOPT_FIELD_TYPE; }
| LENGTH { $$ = IPOPT_FIELD_LENGTH; }
| VALUE { $$ = IPOPT_FIELD_VALUE; }
| PTR { $$ = IPOPT_FIELD_PTR; }
| ADDR { $$ = IPOPT_FIELD_ADDR_0; }
;
icmp_hdr_expr : ICMP icmp_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_icmp, $2);
}
;
icmp_hdr_field : TYPE { $$ = ICMPHDR_TYPE; }
| CODE { $$ = ICMPHDR_CODE; }
| CHECKSUM { $$ = ICMPHDR_CHECKSUM; }
| ID { $$ = ICMPHDR_ID; }
| SEQUENCE { $$ = ICMPHDR_SEQ; }
| GATEWAY { $$ = ICMPHDR_GATEWAY; }
| MTU { $$ = ICMPHDR_MTU; }
;
igmp_hdr_expr : IGMP igmp_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_igmp, $2);
}
;
igmp_hdr_field : TYPE { $$ = IGMPHDR_TYPE; }
| CHECKSUM { $$ = IGMPHDR_CHECKSUM; }
| MRT { $$ = IGMPHDR_MRT; }
| GROUP { $$ = IGMPHDR_GROUP; }
;
ip6_hdr_expr : IP6 ip6_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_ip6, $2);
}
;
ip6_hdr_field : HDRVERSION { $$ = IP6HDR_VERSION; }
| DSCP { $$ = IP6HDR_DSCP; }
| ECN { $$ = IP6HDR_ECN; }
| FLOWLABEL { $$ = IP6HDR_FLOWLABEL; }
| LENGTH { $$ = IP6HDR_LENGTH; }
| NEXTHDR { $$ = IP6HDR_NEXTHDR; }
| HOPLIMIT { $$ = IP6HDR_HOPLIMIT; }
| SADDR { $$ = IP6HDR_SADDR; }
| DADDR { $$ = IP6HDR_DADDR; }
;
icmp6_hdr_expr : ICMP6 icmp6_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_icmp6, $2);
}
;
icmp6_hdr_field : TYPE { $$ = ICMP6HDR_TYPE; }
| CODE { $$ = ICMP6HDR_CODE; }
| CHECKSUM { $$ = ICMP6HDR_CHECKSUM; }
| PPTR { $$ = ICMP6HDR_PPTR; }
| MTU { $$ = ICMP6HDR_MTU; }
| ID { $$ = ICMP6HDR_ID; }
| SEQUENCE { $$ = ICMP6HDR_SEQ; }
| MAXDELAY { $$ = ICMP6HDR_MAXDELAY; }
;
auth_hdr_expr : AH auth_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_ah, $2);
}
;
auth_hdr_field : NEXTHDR { $$ = AHHDR_NEXTHDR; }
| HDRLENGTH { $$ = AHHDR_HDRLENGTH; }
| RESERVED { $$ = AHHDR_RESERVED; }
| SPI { $$ = AHHDR_SPI; }
| SEQUENCE { $$ = AHHDR_SEQUENCE; }
;
esp_hdr_expr : ESP esp_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_esp, $2);
}
;
esp_hdr_field : SPI { $$ = ESPHDR_SPI; }
| SEQUENCE { $$ = ESPHDR_SEQUENCE; }
;
comp_hdr_expr : COMP comp_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_comp, $2);
}
;
comp_hdr_field : NEXTHDR { $$ = COMPHDR_NEXTHDR; }
| FLAGS { $$ = COMPHDR_FLAGS; }
| CPI { $$ = COMPHDR_CPI; }
;
udp_hdr_expr : UDP udp_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_udp, $2);
}
;
udp_hdr_field : SPORT { $$ = UDPHDR_SPORT; }
| DPORT { $$ = UDPHDR_DPORT; }
| LENGTH { $$ = UDPHDR_LENGTH; }
| CHECKSUM { $$ = UDPHDR_CHECKSUM; }
;
udplite_hdr_expr : UDPLITE udplite_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_udplite, $2);
}
;
udplite_hdr_field : SPORT { $$ = UDPHDR_SPORT; }
| DPORT { $$ = UDPHDR_DPORT; }
| CSUMCOV { $$ = UDPHDR_LENGTH; }
| CHECKSUM { $$ = UDPHDR_CHECKSUM; }
;
tcp_hdr_expr : TCP tcp_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_tcp, $2);
}
| TCP OPTION tcp_hdr_option_type tcp_hdr_option_field
{
$$ = tcpopt_expr_alloc(&@$, $3, $4);
}
| TCP OPTION tcp_hdr_option_type
{
$$ = tcpopt_expr_alloc(&@$, $3, TCPOPTHDR_FIELD_KIND);
$$->exthdr.flags = NFT_EXTHDR_F_PRESENT;
}
;
tcp_hdr_field : SPORT { $$ = TCPHDR_SPORT; }
| DPORT { $$ = TCPHDR_DPORT; }
| SEQUENCE { $$ = TCPHDR_SEQ; }
| ACKSEQ { $$ = TCPHDR_ACKSEQ; }
| DOFF { $$ = TCPHDR_DOFF; }
| RESERVED { $$ = TCPHDR_RESERVED; }
| FLAGS { $$ = TCPHDR_FLAGS; }
| WINDOW { $$ = TCPHDR_WINDOW; }
| CHECKSUM { $$ = TCPHDR_CHECKSUM; }
| URGPTR { $$ = TCPHDR_URGPTR; }
;
tcp_hdr_option_type : EOL { $$ = TCPOPTHDR_EOL; }
| NOOP { $$ = TCPOPTHDR_NOOP; }
| MAXSEG { $$ = TCPOPTHDR_MAXSEG; }
| WINDOW { $$ = TCPOPTHDR_WINDOW; }
| SACK_PERMITTED { $$ = TCPOPTHDR_SACK_PERMITTED; }
| SACK { $$ = TCPOPTHDR_SACK0; }
| SACK0 { $$ = TCPOPTHDR_SACK0; }
| SACK1 { $$ = TCPOPTHDR_SACK1; }
| SACK2 { $$ = TCPOPTHDR_SACK2; }
| SACK3 { $$ = TCPOPTHDR_SACK3; }
| ECHO { $$ = TCPOPTHDR_ECHO; }
| TIMESTAMP { $$ = TCPOPTHDR_TIMESTAMP; }
;
tcp_hdr_option_field : KIND { $$ = TCPOPTHDR_FIELD_KIND; }
| LENGTH { $$ = TCPOPTHDR_FIELD_LENGTH; }
| SIZE { $$ = TCPOPTHDR_FIELD_SIZE; }
| COUNT { $$ = TCPOPTHDR_FIELD_COUNT; }
| LEFT { $$ = TCPOPTHDR_FIELD_LEFT; }
| RIGHT { $$ = TCPOPTHDR_FIELD_RIGHT; }
| TSVAL { $$ = TCPOPTHDR_FIELD_TSVAL; }
| TSECR { $$ = TCPOPTHDR_FIELD_TSECR; }
;
dccp_hdr_expr : DCCP dccp_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_dccp, $2);
}
;
dccp_hdr_field : SPORT { $$ = DCCPHDR_SPORT; }
| DPORT { $$ = DCCPHDR_DPORT; }
| TYPE { $$ = DCCPHDR_TYPE; }
;
sctp_hdr_expr : SCTP sctp_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_sctp, $2);
}
;
sctp_hdr_field : SPORT { $$ = SCTPHDR_SPORT; }
| DPORT { $$ = SCTPHDR_DPORT; }
| VTAG { $$ = SCTPHDR_VTAG; }
| CHECKSUM { $$ = SCTPHDR_CHECKSUM; }
;
th_hdr_expr : TRANSPORT_HDR th_hdr_field
{
$$ = payload_expr_alloc(&@$, &proto_th, $2);
if ($$)
$$->payload.is_raw = true;
}
;
th_hdr_field : SPORT { $$ = THDR_SPORT; }
| DPORT { $$ = THDR_DPORT; }
;
exthdr_expr : hbh_hdr_expr
| rt_hdr_expr
| rt0_hdr_expr
| rt2_hdr_expr
| rt4_hdr_expr
| frag_hdr_expr
| dst_hdr_expr
| mh_hdr_expr
;
hbh_hdr_expr : HBH hbh_hdr_field
{
$$ = exthdr_expr_alloc(&@$, &exthdr_hbh, $2);
}
;
hbh_hdr_field : NEXTHDR { $$ = HBHHDR_NEXTHDR; }
| HDRLENGTH { $$ = HBHHDR_HDRLENGTH; }
;
rt_hdr_expr : RT rt_hdr_field
{
$$ = exthdr_expr_alloc(&@$, &exthdr_rt, $2);
}
;
rt_hdr_field : NEXTHDR { $$ = RTHDR_NEXTHDR; }
| HDRLENGTH { $$ = RTHDR_HDRLENGTH; }
| TYPE { $$ = RTHDR_TYPE; }
| SEG_LEFT { $$ = RTHDR_SEG_LEFT; }
;
rt0_hdr_expr : RT0 rt0_hdr_field
{
$$ = exthdr_expr_alloc(&@$, &exthdr_rt0, $2);
}
;
rt0_hdr_field : ADDR '[' NUM ']'
{
$$ = RT0HDR_ADDR_1 + $3 - 1;
}
;
rt2_hdr_expr : RT2 rt2_hdr_field
{
$$ = exthdr_expr_alloc(&@$, &exthdr_rt2, $2);
}
;
rt2_hdr_field : ADDR { $$ = RT2HDR_ADDR; }
;
rt4_hdr_expr : RT4 rt4_hdr_field
{
$$ = exthdr_expr_alloc(&@$, &exthdr_rt4, $2);
}
;
rt4_hdr_field : LAST_ENT { $$ = RT4HDR_LASTENT; }
| FLAGS { $$ = RT4HDR_FLAGS; }
| TAG { $$ = RT4HDR_TAG; }
| SID '[' NUM ']'
{
$$ = RT4HDR_SID_1 + $3 - 1;
}
;
frag_hdr_expr : FRAG frag_hdr_field
{
$$ = exthdr_expr_alloc(&@$, &exthdr_frag, $2);
}
;
frag_hdr_field : NEXTHDR { $$ = FRAGHDR_NEXTHDR; }
| RESERVED { $$ = FRAGHDR_RESERVED; }
| FRAG_OFF { $$ = FRAGHDR_FRAG_OFF; }
| RESERVED2 { $$ = FRAGHDR_RESERVED2; }
| MORE_FRAGMENTS { $$ = FRAGHDR_MFRAGS; }
| ID { $$ = FRAGHDR_ID; }
;
dst_hdr_expr : DST dst_hdr_field
{
$$ = exthdr_expr_alloc(&@$, &exthdr_dst, $2);
}
;
dst_hdr_field : NEXTHDR { $$ = DSTHDR_NEXTHDR; }
| HDRLENGTH { $$ = DSTHDR_HDRLENGTH; }
;
mh_hdr_expr : MH mh_hdr_field
{
$$ = exthdr_expr_alloc(&@$, &exthdr_mh, $2);
}
;
mh_hdr_field : NEXTHDR { $$ = MHHDR_NEXTHDR; }
| HDRLENGTH { $$ = MHHDR_HDRLENGTH; }
| TYPE { $$ = MHHDR_TYPE; }
| RESERVED { $$ = MHHDR_RESERVED; }
| CHECKSUM { $$ = MHHDR_CHECKSUM; }
;
exthdr_exists_expr : EXTHDR exthdr_key
{
const struct exthdr_desc *desc;
desc = exthdr_find_proto($2);
/* Assume that NEXTHDR template is always
* the fist one in list of templates.
*/
$$ = exthdr_expr_alloc(&@$, desc, 1);
$$->exthdr.flags = NFT_EXTHDR_F_PRESENT;
}
;
exthdr_key : HBH { $$ = IPPROTO_HOPOPTS; }
| RT { $$ = IPPROTO_ROUTING; }
| FRAG { $$ = IPPROTO_FRAGMENT; }
| DST { $$ = IPPROTO_DSTOPTS; }
| MH { $$ = IPPROTO_MH; }
;
%%
|