This repository has been archived by the owner on Mar 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pfMIBObjects.c
1664 lines (1409 loc) · 47.7 KB
/
pfMIBObjects.c
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
/*
* $jwk$
*
*
* Copyright (c) 2004-2008 Joel Knight <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <net/pfvar.h>
#include <arpa/inet.h>
#include <net/if_pfsync.h>
#include <errno.h>
#include <fcntl.h>
#include <time.h>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "pfMIBObjects.h"
#define PFRB_FOREACH(var, buf) \
for ((var) = pfr_buf_next((buf), NULL); \
(var) != NULL; \
(var) = pfr_buf_next((buf), (var)))
int dev = -1;
char *pfi_table[255][IFNAMSIZ];
unsigned int pfi_count;
unsigned int pft_count;
unsigned int pfl_count;
time_t pfi_table_age;
size_t buf_esize[PFRB_MAX] = { 0,
sizeof(struct pfr_tstats),
sizeof(struct pfr_astats),
sizeof(struct pfi_kif)
};
oid pfMIBObjects_variables_oid[] = { 1,3,6,1,4,1,64512,1 };
struct variable4 pfMIBObjects_variables[] = {
/* magic number , variable type , ro/rw , callback fn , L, oidsuffix */
{ RUNNING , ASN_INTEGER , RONLY , var_pfMIBObjects, 2, { 1,1 } },
{ RUNTIME , ASN_TIMETICKS , RONLY , var_pfMIBObjects, 2, { 1,2 } },
{ DEBUG , ASN_INTEGER , RONLY , var_pfMIBObjects, 2, { 1,3 } },
{ HOSTID , ASN_OCTET_STR , RONLY , var_pfMIBObjects, 2, { 1,4 } },
{ MATCH , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,1 } },
{ BADOFFSET , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,2 } },
{ FRAGMENT , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,3 } },
{ SHORT , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,4 } },
{ NORMALIZE , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,5 } },
{ MEMORY , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,6 } },
{ TIMESTAMP , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,7 } },
{ CONGEST , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,8 } },
{ IPOPTIONS , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,9 } },
{ PROTCKSUM , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,10 } },
{ BADSTATE , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,11 } },
{ STATEINS , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,12 } },
{ MAXSTATES , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,13 } },
{ SRCLIMIT , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,14 } },
{ SYNPROXY , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 2,15 } },
{ STATES_COUNT , ASN_UNSIGNED , RONLY , var_pfMIBObjects, 2, { 3,1 } },
{ STATES_SEARCHES , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 3,2 } },
{ STATES_INSERTS , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 3,3 } },
{ STATES_REMOVALS , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 3,4 } },
{ PF_LOGIF_NAME , ASN_OCTET_STR , RONLY , var_pfMIBObjects, 2, { 4,1 } },
{ IPBYTESIN , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 4,2 } },
{ IPBYTESOUT , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 4,3 } },
{ IPPKTSINPASS , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 4,4 } },
{ IPPKTSINDROP , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 4,5 } },
{ IPPKTSOUTPASS , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 4,6 } },
{ IPPKTSOUTDROP , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 4,7 } },
{ IP6BYTESIN , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 4,8 } },
{ IP6BYTESOUT , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 4,9 } },
{ IP6PKTSINPASS , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 4,10 } },
{ IP6PKTSINDROP , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 4,11 } },
{ IP6PKTSOUTPASS , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 4,12 } },
{ IP6PKTSOUTDROP , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 4,13 } },
{ SRCTRACK_COUNT , ASN_UNSIGNED , RONLY , var_pfMIBObjects, 2, { 5,1 } },
{ SRCTRACK_SEARCHES , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 5,2 } },
{ SRCTRACK_INSERTS , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 5,3 } },
{ SRCTRACK_REMOVALS , ASN_COUNTER64 , RONLY , var_pfMIBObjects, 2, { 5,4 } },
{ LIMIT_STATES , ASN_UNSIGNED , RONLY , var_limits, 2, { 6,1 } },
{ LIMIT_SRC_NODES , ASN_UNSIGNED , RONLY , var_limits, 2, { 6,2 } },
{ LIMIT_FRAGS , ASN_UNSIGNED , RONLY , var_limits, 2, { 6,3 } },
{ TM_TCP_FIRST , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,1 } },
{ TM_TCP_OPENING , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,2 } },
{ TM_TCP_ESTAB , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,3 } },
{ TM_TCP_CLOSING , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,4 } },
{ TM_TCP_FINWAIT , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,5 } },
{ TM_TCP_CLOSED , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,6 } },
{ TM_UDP_FIRST , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,7 } },
{ TM_UDP_SINGLE , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,8 } },
{ TM_UDP_MULTIPLE , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,9 } },
{ TM_ICMP_FIRST , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,10 } },
{ TM_ICMP_ERROR , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,11 } },
{ TM_OTHER_FIRST , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,12 } },
{ TM_OTHER_SINGLE , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,13 } },
{ TM_OTHER_MULTIPLE , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,14 } },
{ TM_FRAGMENT , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,15 } },
{ TM_INTERVAL , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,16 } },
{ TM_ADAPT_START , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,17 } },
{ TM_ADAPT_END , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,18 } },
{ TM_SRC_TRACK , ASN_INTEGER , RONLY , var_timeouts, 2, { 7,19 } },
{ PF_IFNUMBER , ASN_INTEGER , RONLY , var_table_number, 2, { 8,1 } },
{ PF_IFINDEX , ASN_INTEGER , RONLY , var_if_table, 4, { 8,128,1,1 } },
{ PF_IFNAME , ASN_OCTET_STR , RONLY , var_if_table, 4, { 8,128,1,2 } },
{ PF_IFTYPE , ASN_INTEGER , RONLY , var_if_table, 4, { 8,128,1,3 } },
{ PF_IFREF , ASN_UNSIGNED , RONLY , var_if_table, 4, { 8,128,1,4 } },
{ PF_IFRULES , ASN_UNSIGNED , RONLY , var_if_table, 4, { 8,128,1,5 } },
{ PF_IFIN4PASSPKTS , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,6 } },
{ PF_IFIN4PASSBYTES , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,7 } },
{ PF_IFIN4BLOCKPKTS , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,8 } },
{ PF_IFIN4BLOCKBYTES , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,9 } },
{ PF_IFOUT4PASSPKTS , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,10 } },
{ PF_IFOUT4PASSBYTES , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,11 } },
{ PF_IFOUT4BLOCKPKTS , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,12 } },
{ PF_IFOUT4BLOCKBYTES , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,13 } },
{ PF_IFIN6PASSPKTS , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,14 } },
{ PF_IFIN6PASSBYTES , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,15 } },
{ PF_IFIN6BLOCKPKTS , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,16 } },
{ PF_IFIN6BLOCKBYTES , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,17 } },
{ PF_IFOUT6PASSPKTS , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,18 } },
{ PF_IFOUT6PASSBYTES , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,19 } },
{ PF_IFOUT6BLOCKPKTS , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,20 } },
{ PF_IFOUT6BLOCKBYTES , ASN_COUNTER64 , RONLY , var_if_table, 4, { 8,128,1,21 } },
{ PF_TANUMBER , ASN_INTEGER , RONLY , var_table_number, 2, { 9,1 } },
{ PF_TAINDEX , ASN_INTEGER , RONLY , var_tables_table, 4, { 9,128,1,1 } },
{ PF_TANAME , ASN_OCTET_STR , RONLY , var_tables_table, 4, { 9,128,1,2 } },
{ PF_TAADDRESSES , ASN_INTEGER , RONLY , var_tables_table, 4, { 9,128,1,3 } },
{ PF_TAANCHORREFS , ASN_INTEGER , RONLY , var_tables_table, 4, { 9,128,1,4 } },
{ PF_TARULEREFS , ASN_INTEGER , RONLY , var_tables_table, 4, { 9,128,1,5 } },
{ PF_TAEVALSMATCH , ASN_COUNTER64 , RONLY , var_tables_table, 4, { 9,128,1,6 } },
{ PF_TAEVALSNOMATCH , ASN_COUNTER64 , RONLY , var_tables_table, 4, { 9,128,1,7 } },
{ PF_TAINPASSPKTS , ASN_COUNTER64 , RONLY , var_tables_table, 4, { 9,128,1,8 } },
{ PF_TAINPASSBYTES , ASN_COUNTER64 , RONLY , var_tables_table, 4, { 9,128,1,9 } },
{ PF_TAINBLOCKPKTS , ASN_COUNTER64 , RONLY , var_tables_table, 4, { 9,128,1,10 } },
{ PF_TAINBLOCKBYTES , ASN_COUNTER64 , RONLY , var_tables_table, 4, { 9,128,1,11 } },
{ PF_TAINXPASSPKTS , ASN_COUNTER64 , RONLY , var_tables_table, 4, { 9,128,1,12 } },
{ PF_TAINXPASSBYTES , ASN_COUNTER64 , RONLY , var_tables_table, 4, { 9,128,1,13 } },
{ PF_TAOUTPASSPKTS , ASN_COUNTER64 , RONLY , var_tables_table, 4, { 9,128,1,14 } },
{ PF_TAOUTPASSBYTES , ASN_COUNTER64 , RONLY , var_tables_table, 4, { 9,128,1,15 } },
{ PF_TAOUTBLOCKPKTS , ASN_COUNTER64 , RONLY , var_tables_table, 4, { 9,128,1,16 } },
{ PF_TAOUTBLOCKBYTES , ASN_COUNTER64 , RONLY , var_tables_table, 4, { 9,128,1,17 } },
{ PF_TAOUTXPASSPKTS , ASN_COUNTER64 , RONLY , var_tables_table, 4, { 9,128,1,18 } },
{ PF_TAOUTXPASSBYTES , ASN_COUNTER64 , RONLY , var_tables_table, 4, { 9,128,1,19 } },
{ PF_TASTATSCLEARED , ASN_TIMETICKS , RONLY , var_tables_table, 4, { 9,128,1,20 } },
{ PF_TADDRTABLEINDEX , ASN_INTEGER , RONLY , var_tbl_addr_table, 4, { 9,129,1,1 } },
{ PF_TADDRNET , ASN_IPADDRESS , RONLY , var_tbl_addr_table, 4, { 9,129,1,2 } },
{ PF_TADDRMASK , ASN_INTEGER , RONLY , var_tbl_addr_table, 4, { 9,129,1,3 } },
{ PF_TADDRCLEARED , ASN_TIMETICKS , RONLY , var_tbl_addr_table, 4, { 9,129,1,4 } },
{ PF_TADDRINBLOCKPKTS , ASN_COUNTER64 , RONLY , var_tbl_addr_table, 4, { 9,129,1,5 } },
{ PF_TADDRINBLOCKBYTES, ASN_COUNTER64 , RONLY , var_tbl_addr_table, 4, { 9,129,1,6 } },
{ PF_TADDRINPASSPKTS , ASN_COUNTER64 , RONLY , var_tbl_addr_table, 4, { 9,129,1,7 } },
{ PF_TADDRINPASSBYTES , ASN_COUNTER64 , RONLY , var_tbl_addr_table, 4, { 9,129,1,8 } },
{ PF_TADDROUTBLOCKPKTS, ASN_COUNTER64 , RONLY , var_tbl_addr_table, 4, { 9,129,1,9 } },
{ PF_TADDROUTBLOCKBYTES,ASN_COUNTER64 , RONLY , var_tbl_addr_table, 4, { 9,129,1,10 } },
{ PF_TADDROUTPASSPKTS , ASN_COUNTER64 , RONLY , var_tbl_addr_table, 4, { 9,129,1,11 } },
{ PF_TADDROUTPASSBYTES, ASN_COUNTER64 , RONLY , var_tbl_addr_table, 4, { 9,129,1,12 } },
{ PF_LANUMBER , ASN_INTEGER , RONLY , var_table_number, 2, { 10,1 } },
{ PF_LAINDEX , ASN_INTEGER , RONLY , var_labels_table, 4, { 10,128,1,1 } },
{ PF_LANAME , ASN_OCTET_STR , RONLY , var_labels_table, 4, { 10,128,1,2 } },
{ PF_LAEVALS , ASN_COUNTER64 , RONLY , var_labels_table, 4, { 10,128,1,3 } },
{ PF_LAPKTS , ASN_COUNTER64 , RONLY , var_labels_table, 4, { 10,128,1,4 } },
{ PF_LABYTES , ASN_COUNTER64 , RONLY , var_labels_table, 4, { 10,128,1,5 } },
{ PF_LAINPKTS , ASN_COUNTER64 , RONLY , var_labels_table, 4, { 10,128,1,6 } },
{ PF_LAINBYTES , ASN_COUNTER64 , RONLY , var_labels_table, 4, { 10,128,1,7 } },
{ PF_LAOUTPKTS , ASN_COUNTER64 , RONLY , var_labels_table, 4, { 10,128,1,8 } },
{ PF_LAOUTBYTES , ASN_COUNTER64 , RONLY , var_labels_table, 4, { 10,128,1,9 } },
{ PFSYNC_IPRECV , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,1 } },
{ PFSYNC_IP6RECV , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,2 } },
{ PFSYNC_BADIF , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,3 } },
{ PFSYNC_BADTTL , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,4 } },
{ PFSYNC_HDROPS , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,5 } },
{ PFSYNC_BADVER , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,6 } },
{ PFSYNC_BADACT , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,7 } },
{ PFSYNC_BADLEN , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,8 } },
{ PFSYNC_BADAUTH , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,9 } },
{ PFSYNC_STALE , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,10 } },
{ PFSYNC_BADVAL , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,11 } },
{ PFSYNC_BADSTATE , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,12 } },
{ PFSYNC_IPSENT , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,13 } },
{ PFSYNC_IP6SENT , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,14 } },
{ PFSYNC_NOMEM , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,15 } },
{ PFSYNC_OERR , ASN_COUNTER64 , RONLY , var_pfsync_stats, 2, { 11,16 } }
};
void init_pfMIBObjects(void) {
REGISTER_MIB("pfMIBObjects", pfMIBObjects_variables, variable4,
pfMIBObjects_variables_oid);
if ((dev = open("/dev/pf", O_RDONLY)) == -1) {
snmp_log(LOG_CRIT, "unable to open /dev/pf: %s\n", strerror(errno));
return;
}
bzero(&pfi_table, sizeof(pfi_table));
pfi_count = 0;
pfi_refresh();
pft_refresh();
}
unsigned char *
var_limits(struct variable *vp, oid *name, size_t *length, int exact,
size_t *var_len, WriteMethod **write_method)
{
struct pfioc_limit pl;
static u_long ulong_ret;
if (header_generic(vp, name, length, exact, var_len, write_method)
== MATCH_FAILED)
return (NULL);
if (dev == -1)
return (NULL);
memset(&pl, 0, sizeof(pl));
switch(vp->magic) {
case LIMIT_STATES:
pl.index = PF_LIMIT_STATES;
break;
case LIMIT_SRC_NODES:
pl.index = PF_LIMIT_SRC_NODES;
break;
case LIMIT_FRAGS:
pl.index = PF_LIMIT_FRAGS;
break;
default:
return (NULL);
}
if (ioctl(dev, DIOCGETLIMIT, &pl)) {
snmp_log(LOG_ERR, "var_limits: ioctl: %s\n", strerror(errno));
return (NULL);
}
ulong_ret = pl.limit;
return ((unsigned char *) &ulong_ret);
}
unsigned char *
var_pfMIBObjects(struct variable *vp, oid *name, size_t *length, int exact,
size_t *var_len, WriteMethod **write_method)
{
struct pf_status s;
time_t runtime;
static long long_ret;
static u_long ulong_ret;
static unsigned char string[SPRINT_MAX_LEN];
static struct counter64 c64;
if (header_generic(vp, name, length, exact, var_len, write_method)
== MATCH_FAILED )
return (NULL);
if (dev == -1)
return (NULL);
memset(&s, 0, sizeof(s));
if (ioctl(dev, DIOCGETSTATUS, &s)) {
snmp_log(LOG_ERR, "var_pfMIBObjects: ioctl: %s\n",
strerror(errno));
return (NULL);
}
switch(vp->magic) {
case RUNNING:
long_ret = (long) s.running;
return ((unsigned char *) &long_ret);
case RUNTIME:
if (s.since > 0)
runtime = time(NULL) - s.since;
else
runtime = 0;
long_ret = (long) runtime * 100;
return ((unsigned char *) &long_ret);
case DEBUG:
long_ret = (long) s.debug;
return ((unsigned char *) &long_ret);
case HOSTID:
sprintf(string, "0x%08x", ntohl(s.hostid));
*var_len = strlen(string);
return ((unsigned char *) string);
case MATCH:
c64.high = s.counters[PFRES_MATCH] >> 32;
c64.low = s.counters[PFRES_MATCH] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case BADOFFSET:
c64.high = s.counters[PFRES_BADOFF] >> 32;
c64.low = s.counters[PFRES_BADOFF] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case FRAGMENT:
c64.high = s.counters[PFRES_FRAG] >> 32;
c64.low = s.counters[PFRES_FRAG] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case SHORT:
c64.high = s.counters[PFRES_SHORT] >> 32;
c64.low = s.counters[PFRES_SHORT] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case NORMALIZE:
c64.high = s.counters[PFRES_NORM] >> 32;
c64.low = s.counters[PFRES_NORM] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case MEMORY:
c64.high = s.counters[PFRES_MEMORY] >> 32;
c64.low = s.counters[PFRES_MEMORY] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case TIMESTAMP:
c64.high = s.counters[PFRES_TS] >> 32;
c64.low = s.counters[PFRES_TS] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case CONGEST:
c64.high = s.counters[PFRES_CONGEST] >> 32;
c64.low = s.counters[PFRES_CONGEST] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case IPOPTIONS:
c64.high = s.counters[PFRES_IPOPTIONS] >> 32;
c64.low = s.counters[PFRES_IPOPTIONS] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case PROTCKSUM:
c64.high = s.counters[PFRES_PROTCKSUM] >> 32;
c64.low = s.counters[PFRES_PROTCKSUM] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case BADSTATE:
c64.high = s.counters[PFRES_BADSTATE] >> 32;
c64.low = s.counters[PFRES_BADSTATE] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case STATEINS:
c64.high = s.counters[PFRES_STATEINS] >> 32;
c64.low = s.counters[PFRES_STATEINS] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case MAXSTATES:
c64.high = s.counters[PFRES_MAXSTATES] >> 32;
c64.low = s.counters[PFRES_MAXSTATES] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case SRCLIMIT:
c64.high = s.counters[PFRES_SRCLIMIT] >> 32;
c64.low = s.counters[PFRES_SRCLIMIT] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case SYNPROXY:
c64.high = s.counters[PFRES_SYNPROXY] >> 32;
c64.low = s.counters[PFRES_SYNPROXY] & 0xffffffff;
*var_len = sizeof(c64);
return (unsigned char *) &c64;
case STATES_COUNT:
ulong_ret = (long) s.states;
return ((unsigned char *) &ulong_ret);
case STATES_SEARCHES:
c64.high = s.fcounters[FCNT_STATE_SEARCH] >> 32;
c64.low = s.fcounters[FCNT_STATE_SEARCH] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case STATES_INSERTS:
c64.high = s.fcounters[FCNT_STATE_INSERT] >> 32;
c64.low = s.fcounters[FCNT_STATE_INSERT] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case STATES_REMOVALS:
c64.high = s.fcounters[FCNT_STATE_REMOVALS] >> 32;
c64.low = s.fcounters[FCNT_STATE_REMOVALS] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case PF_LOGIF_NAME:
strlcpy(string, s.ifname, sizeof(string));
*var_len = strlen(string);
return ((unsigned char *) string);
case IPBYTESIN:
c64.high = s.bcounters[IPV4][IN] >> 32;
c64.low = s.bcounters[IPV4][IN] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case IPBYTESOUT:
c64.high = s.bcounters[IPV4][OUT] >> 32;
c64.low = s.bcounters[IPV4][OUT] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case IPPKTSINPASS:
c64.high = s.pcounters[IPV4][IN][PF_PASS] >> 32;
c64.low = s.pcounters[IPV4][IN][PF_PASS] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case IPPKTSINDROP:
c64.high = s.pcounters[IPV4][IN][PF_DROP] >> 32;
c64.low = s.pcounters[IPV4][IN][PF_DROP] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case IPPKTSOUTPASS:
c64.high = s.pcounters[IPV4][OUT][PF_PASS] >> 32;
c64.low = s.pcounters[IPV4][OUT][PF_PASS] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case IPPKTSOUTDROP:
c64.high = s.pcounters[IPV4][OUT][PF_DROP] >> 32;
c64.low = s.pcounters[IPV4][OUT][PF_DROP] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case IP6BYTESIN:
c64.high = s.bcounters[IPV6][IN] >> 32;
c64.low = s.bcounters[IPV6][IN] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case IP6BYTESOUT:
c64.high = s.bcounters[IPV6][OUT] >> 32;
c64.low = s.bcounters[IPV6][OUT] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case IP6PKTSINPASS:
c64.high = s.pcounters[IPV6][IN][PF_PASS] >> 32;
c64.low = s.pcounters[IPV6][IN][PF_PASS] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case IP6PKTSINDROP:
c64.high = s.pcounters[IPV6][IN][PF_DROP] >> 32;
c64.low = s.pcounters[IPV6][IN][PF_DROP] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case IP6PKTSOUTPASS:
c64.high = s.pcounters[IPV6][OUT][PF_PASS] >> 32;
c64.low = s.pcounters[IPV6][OUT][PF_PASS] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case IP6PKTSOUTDROP:
c64.high = s.pcounters[IPV6][OUT][PF_DROP] >> 32;
c64.low = s.pcounters[IPV6][OUT][PF_DROP] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case SRCTRACK_COUNT:
ulong_ret = (long) s.src_nodes;
return ((unsigned char *) &ulong_ret);
case SRCTRACK_SEARCHES:
c64.high = s.scounters[SCNT_SRC_NODE_SEARCH] >> 32;
c64.low = s.scounters[SCNT_SRC_NODE_SEARCH] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case SRCTRACK_INSERTS:
c64.high = s.scounters[SCNT_SRC_NODE_INSERT] >> 32;
c64.low = s.scounters[SCNT_SRC_NODE_INSERT] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case SRCTRACK_REMOVALS:
c64.high = s.scounters[SCNT_SRC_NODE_REMOVALS] >> 32;
c64.low = s.scounters[SCNT_SRC_NODE_REMOVALS] & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
default:
return (NULL);
}
/* NOTREACHED */
}
unsigned char *
var_pfsync_stats(struct variable *vp, oid *name, size_t *length, int exact,
size_t *var_len, WriteMethod **write_method)
{
int mib[4] = { CTL_NET, AF_INET, IPPROTO_PFSYNC, PFSYNCCTL_STATS };
size_t len;
struct pfsyncstats pfsyncstat;
static struct counter64 c64;
if (header_generic(vp, name, length, exact, var_len, write_method)
== MATCH_FAILED)
return (NULL);
len = sizeof(pfsyncstat);
if (sysctl(mib, 4, &pfsyncstat, &len, NULL, 0) == -1) {
snmp_log(LOG_ERR, "var_pfsync_stats: sysctl: %s\n",
strerror(errno));
return (NULL);
}
switch(vp->magic) {
case PFSYNC_IPRECV:
c64.high = pfsyncstat.pfsyncs_ipackets >> 32;
c64.low = pfsyncstat.pfsyncs_ipackets & 0xffffffff;
break;
case PFSYNC_IP6RECV:
c64.high = pfsyncstat.pfsyncs_ipackets6 >> 32;
c64.low = pfsyncstat.pfsyncs_ipackets6 & 0xffffffff;
break;
case PFSYNC_BADIF:
c64.high = pfsyncstat.pfsyncs_badif >> 32;
c64.low = pfsyncstat.pfsyncs_badif & 0xffffffff;
break;
case PFSYNC_BADTTL:
c64.high = pfsyncstat.pfsyncs_badttl >> 32;
c64.low = pfsyncstat.pfsyncs_badttl & 0xffffffff;
break;
case PFSYNC_HDROPS:
c64.high = pfsyncstat.pfsyncs_hdrops >> 32;
c64.low = pfsyncstat.pfsyncs_hdrops & 0xffffffff;
break;
case PFSYNC_BADVER:
c64.high = pfsyncstat.pfsyncs_badver >> 32;
c64.low = pfsyncstat.pfsyncs_badver & 0xffffffff;
break;
case PFSYNC_BADACT:
c64.high = pfsyncstat.pfsyncs_badact >> 32;
c64.low = pfsyncstat.pfsyncs_badact & 0xffffffff;
break;
case PFSYNC_BADLEN:
c64.high = pfsyncstat.pfsyncs_badlen >> 32;
c64.low = pfsyncstat.pfsyncs_badlen & 0xffffffff;
break;
case PFSYNC_BADAUTH:
c64.high = pfsyncstat.pfsyncs_badauth >> 32;
c64.low = pfsyncstat.pfsyncs_badauth & 0xffffffff;
break;
case PFSYNC_STALE:
c64.high = pfsyncstat.pfsyncs_stale >> 32;
c64.low = pfsyncstat.pfsyncs_stale & 0xffffffff;
break;
case PFSYNC_BADVAL:
c64.high = pfsyncstat.pfsyncs_badval >> 32;
c64.low = pfsyncstat.pfsyncs_badval & 0xffffffff;
break;
case PFSYNC_BADSTATE:
c64.high = pfsyncstat.pfsyncs_badstate >> 32;
c64.low = pfsyncstat.pfsyncs_badstate & 0xffffffff;
break;
case PFSYNC_IPSENT:
c64.high = pfsyncstat.pfsyncs_opackets >> 32;
c64.low = pfsyncstat.pfsyncs_opackets & 0xffffffff;
break;
case PFSYNC_IP6SENT:
c64.high = pfsyncstat.pfsyncs_opackets6 >> 32;
c64.low = pfsyncstat.pfsyncs_opackets6 & 0xffffffff;
break;
case PFSYNC_NOMEM:
c64.high = pfsyncstat.pfsyncs_onomem >> 32;
c64.low = pfsyncstat.pfsyncs_onomem & 0xffffffff;
break;
case PFSYNC_OERR:
c64.high = pfsyncstat.pfsyncs_oerrors >> 32;
c64.low = pfsyncstat.pfsyncs_oerrors & 0xffffffff;
break;
default:
snmp_log(LOG_ERR,
"var_pfsync_stats: can't find magic %u\n",
vp->magic);
return (NULL);
}
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
}
unsigned char *
var_timeouts(struct variable *vp, oid *name, size_t *length, int exact,
size_t *var_len, WriteMethod **write_method)
{
struct pfioc_tm pt;
static long long_ret;
if (header_generic(vp, name, length, exact, var_len, write_method)
== MATCH_FAILED)
return (NULL);
if (dev == -1)
return (NULL);
memset(&pt, 0, sizeof(pt));
switch(vp->magic) {
case TM_TCP_FIRST:
pt.timeout = PFTM_TCP_FIRST_PACKET;
break;
case TM_TCP_OPENING:
pt.timeout = PFTM_TCP_OPENING;
break;
case TM_TCP_ESTAB:
pt.timeout = PFTM_TCP_ESTABLISHED;
break;
case TM_TCP_CLOSING:
pt.timeout = PFTM_TCP_CLOSING;
break;
case TM_TCP_FINWAIT:
pt.timeout = PFTM_TCP_FIN_WAIT;
break;
case TM_TCP_CLOSED:
pt.timeout = PFTM_TCP_CLOSED;
break;
case TM_UDP_FIRST:
pt.timeout = PFTM_UDP_FIRST_PACKET;
break;
case TM_UDP_SINGLE:
pt.timeout = PFTM_UDP_SINGLE;
break;
case TM_UDP_MULTIPLE:
pt.timeout = PFTM_UDP_MULTIPLE;
break;
case TM_ICMP_FIRST:
pt.timeout = PFTM_ICMP_FIRST_PACKET;
break;
case TM_ICMP_ERROR:
pt.timeout = PFTM_ICMP_ERROR_REPLY;
break;
case TM_OTHER_FIRST:
pt.timeout = PFTM_OTHER_FIRST_PACKET;
break;
case TM_OTHER_SINGLE:
pt.timeout = PFTM_OTHER_SINGLE;
break;
case TM_OTHER_MULTIPLE:
pt.timeout = PFTM_OTHER_MULTIPLE;
break;
case TM_FRAGMENT:
pt.timeout = PFTM_FRAG;
break;
case TM_INTERVAL:
pt.timeout = PFTM_INTERVAL;
break;
case TM_ADAPT_START:
pt.timeout = PFTM_ADAPTIVE_START;
break;
case TM_ADAPT_END:
pt.timeout = PFTM_ADAPTIVE_END;
break;
case TM_SRC_TRACK:
pt.timeout = PFTM_SRC_NODE;
break;
default:
return (NULL);
}
if (ioctl(dev, DIOCGETTIMEOUT, &pt)) {
snmp_log(LOG_ERR, "var_timeouts: ioctl: %s\n", strerror(errno));
return (NULL);
}
long_ret = pt.seconds;
return ((unsigned char *) &long_ret);
}
unsigned char *
var_table_number(struct variable *vp, oid *name, size_t *length, int exact,
size_t *var_len, WriteMethod **write_method)
{
static u_long ulong_ret;
if (header_generic(vp, name, length, exact, var_len, write_method)
== MATCH_FAILED)
return (NULL);
if (dev == -1)
return (NULL);
if ((time(NULL) - pfi_table_age) > PFI_TABLE_MAXAGE)
pfi_refresh();
switch (vp->magic) {
case PF_IFNUMBER:
ulong_ret = pfi_count;
return ((unsigned char *) &ulong_ret);
case PF_TANUMBER:
pft_refresh();
ulong_ret = pft_count;
return ((unsigned char *) &ulong_ret);
case PF_LANUMBER:
pfl_refresh();
ulong_ret = pfl_count;
return ((unsigned char *) &ulong_ret);
default:
return (NULL);
}
}
unsigned char *
var_if_table(struct variable *vp, oid *name, size_t *length, int exact,
size_t *var_len, WriteMethod **write_method)
{
struct pfr_buffer b;
struct pfi_kif *p;
int index;
static struct counter64 c64;
static u_long ulong_ret;
if (header_simple_table(vp, name, length, exact, var_len, write_method, pfi_count)
== MATCH_FAILED)
return (NULL);
if (dev == -1)
return (NULL);
if ((time(NULL) - pfi_table_age) > PFI_TABLE_MAXAGE)
pfi_refresh();
index = name[*length-1]-1;
if (!pfi_table[index])
return (NULL);
if (pfi_get(&b, (const char *)&pfi_table[index])
|| b.pfrb_size == 0) {
free(b.pfrb_caddr);
return (NULL);
}
/* we only ask for 1 interface from pfi_get() */
p = b.pfrb_caddr;
switch (vp->magic) {
case PF_IFINDEX:
ulong_ret = index + 1;
free(b.pfrb_caddr);
return ((unsigned char *) &ulong_ret);
case PF_IFNAME:
*var_len = strlen(&pfi_table[index]);
free(b.pfrb_caddr);
return ((unsigned char *) pfi_table[index]);
case PF_IFTYPE:
/* XXX weak test; group names can end in digits */
ulong_ret = isdigit(p->pfik_name[strlen(p->pfik_name)-1]) ?
PFI_IFTYPE_INSTANCE : PFI_IFTYPE_GROUP;
free(b.pfrb_caddr);
return ((unsigned char *) &ulong_ret);
case PF_IFREF:
ulong_ret = p->pfik_states;
free(b.pfrb_caddr);
return ((unsigned char *) &ulong_ret);
case PF_IFRULES:
ulong_ret = p->pfik_rules;
free(b.pfrb_caddr);
return ((unsigned char *) &ulong_ret);
case PF_IFIN4PASSPKTS:
c64.high = p->pfik_packets[IPV4][IN][PASS] >> 32;
c64.low = p->pfik_packets[IPV4][IN][PASS] & 0xffffffff;
break;
case PF_IFIN4PASSBYTES:
c64.high = p->pfik_bytes[IPV4][IN][PASS] >> 32;
c64.low = p->pfik_bytes[IPV4][IN][PASS] & 0xffffffff;
break;
case PF_IFIN4BLOCKPKTS:
c64.high = p->pfik_packets[IPV4][IN][BLOCK] >> 32;
c64.low = p->pfik_packets[IPV4][IN][BLOCK] & 0xffffffff;
break;
case PF_IFIN4BLOCKBYTES:
c64.high = p->pfik_bytes[IPV4][IN][BLOCK] >> 32;
c64.low = p->pfik_bytes[IPV4][IN][BLOCK] & 0xffffffff;
break;
case PF_IFOUT4PASSPKTS:
c64.high = p->pfik_packets[IPV4][OUT][PASS] >> 32;
c64.low = p->pfik_packets[IPV4][OUT][PASS] & 0xffffffff;
break;
case PF_IFOUT4PASSBYTES:
c64.high = p->pfik_bytes[IPV4][OUT][PASS] >> 32;
c64.low = p->pfik_bytes[IPV4][OUT][PASS] & 0xffffffff;
break;
case PF_IFOUT4BLOCKPKTS:
c64.high = p->pfik_packets[IPV4][OUT][BLOCK] >> 32;
c64.low = p->pfik_packets[IPV4][OUT][BLOCK] & 0xffffffff;
break;
case PF_IFOUT4BLOCKBYTES:
c64.high = p->pfik_bytes[IPV4][OUT][BLOCK] >> 32;
c64.low = p->pfik_bytes[IPV4][OUT][BLOCK] & 0xffffffff;
break;
case PF_IFIN6PASSPKTS:
c64.high = p->pfik_packets[IPV6][IN][PASS] >> 32;
c64.low = p->pfik_packets[IPV6][IN][PASS] & 0xffffffff;
break;
case PF_IFIN6PASSBYTES:
c64.high = p->pfik_bytes[IPV6][IN][PASS] >> 32;
c64.low = p->pfik_bytes[IPV6][IN][PASS] & 0xffffffff;
break;
case PF_IFIN6BLOCKPKTS:
c64.high = p->pfik_packets[IPV6][IN][BLOCK] >> 32;
c64.low = p->pfik_packets[IPV6][IN][BLOCK] & 0xffffffff;
break;
case PF_IFIN6BLOCKBYTES:
c64.high = p->pfik_bytes[IPV6][IN][BLOCK] >> 32;
c64.low = p->pfik_bytes[IPV6][IN][BLOCK] & 0xffffffff;
break;
case PF_IFOUT6PASSPKTS:
c64.high = p->pfik_packets[IPV6][OUT][PASS] >> 32;
c64.low = p->pfik_packets[IPV6][OUT][PASS] & 0xffffffff;
break;
case PF_IFOUT6PASSBYTES:
c64.high = p->pfik_bytes[IPV6][OUT][PASS] >> 32;
c64.low = p->pfik_bytes[IPV6][OUT][PASS] & 0xffffffff;
break;
case PF_IFOUT6BLOCKPKTS:
c64.high = p->pfik_packets[IPV6][OUT][BLOCK] >> 32;
c64.low = p->pfik_packets[IPV6][OUT][BLOCK] & 0xffffffff;
break;
case PF_IFOUT6BLOCKBYTES:
c64.high = p->pfik_bytes[IPV6][OUT][BLOCK] >> 32;
c64.low = p->pfik_bytes[IPV6][OUT][BLOCK] & 0xffffffff;
break;
default:
free(b.pfrb_caddr);
return (NULL);
}
free(b.pfrb_caddr);
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
}
unsigned char *
var_labels_table(struct variable *vp, oid *name, size_t *length, int exact,
size_t *var_len, WriteMethod **write_method)
{
u_long nr, mnr, lnr;
struct pfioc_rule pr;
static struct counter64 c64;
static u_long ulong_ret;
static char lname[PF_RULE_LABEL_SIZE];
int index;
int got_match = 0;
if (dev == -1)
return (NULL);
pfl_refresh();
if (header_simple_table(vp, name, length, exact, var_len, write_method, pfl_count)
== MATCH_FAILED) {
return (NULL);
}
index = name[*length-1];
memset(&pr, 0, sizeof(pr));
if (ioctl(dev, DIOCGETRULES, &pr)) {
snmp_log(LOG_ERR, "var_labels_table: ioctl: %s\n",
strerror(errno));
return (NULL);
}
mnr = pr.nr;
lnr = 0;
for (nr = 0; nr < mnr; ++nr) {
pr.nr = nr;
if (ioctl(dev, DIOCGETRULE, &pr)) {
snmp_log(LOG_ERR, "var_labels_table: ioctl: %s\n",
strerror(errno));
return (NULL);
}
if (pr.rule.label[0]) {
lnr++;
if (lnr == index) {
got_match++;
break;
}
}
}
if (!got_match)
return (NULL);
switch (vp->magic) {
case PF_LAINDEX:
ulong_ret = index;
return ((unsigned char *) &ulong_ret);
case PF_LANAME:
*var_len = strlen(pr.rule.label);
strlcpy(lname, pr.rule.label, sizeof(lname));
return ((unsigned char *) lname);
case PF_LAEVALS:
c64.high = pr.rule.evaluations >> 32;
c64.low = pr.rule.evaluations & 0xffffffff;
*var_len = sizeof(c64);
return ((unsigned char *) &c64);
case PF_LAPKTS:
c64.high = (pr.rule.packets[IN] >> 32)
+ (pr.rule.packets[OUT] >> 32);
c64.low = (pr.rule.packets[IN] & 0xffffffff)
+ (pr.rule.packets[OUT] & 0xffffffff);
*var_len = sizeof(c64);