00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198 #ifdef HAVE_CONFIG_H
00199 #include "config.h"
00200 #endif
00201
00202 #include <stdio.h>
00203 #include <stdlib.h>
00204 #include <string.h>
00205
00206 #include "pcrm.h"
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 PORT_RULE_MAP * prmNewMap( )
00224 {
00225 PORT_RULE_MAP * p;
00226
00227 p = (PORT_RULE_MAP *)calloc(1, sizeof(PORT_RULE_MAP) );
00228
00229 return p;
00230 }
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 BYTE_RULE_MAP * prmNewByteMap( )
00248 {
00249 BYTE_RULE_MAP * p;
00250
00251 p = (BYTE_RULE_MAP *)calloc(1, sizeof(BYTE_RULE_MAP) );
00252
00253 return p;
00254 }
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 static void prmxFreeGroup(PORT_GROUP *pg)
00273 {
00274 RULE_NODE * rn, *rx;
00275
00276 rn = pg->pgHead;
00277
00278 while( rn )
00279 {
00280 rx = rn->rnNext;
00281 free( rn );
00282 rn = rx;
00283 }
00284 }
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 void prmFreeMap( PORT_RULE_MAP * p )
00302 {
00303 int i;
00304
00305 if( p )
00306 {
00307 for(i=0;i<MAX_PORTS;i++)
00308 {
00309 if(p->prmSrcPort[i])
00310 {
00311 prmxFreeGroup( p->prmSrcPort[i] );
00312 free(p->prmSrcPort[i]);
00313 }
00314 }
00315
00316 for(i=0;i<MAX_PORTS;i++)
00317 {
00318 if(p->prmDstPort[i])
00319 {
00320 prmxFreeGroup( p->prmDstPort[i] );
00321 free(p->prmDstPort[i]);
00322 }
00323 }
00324
00325 if(p->prmGeneric)
00326 {
00327 prmxFreeGroup( p->prmGeneric );
00328 free(p->prmGeneric);
00329 }
00330
00331 free( p );
00332 }
00333 }
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350 void prmFreeByteMap( BYTE_RULE_MAP * p )
00351 {
00352 int i;
00353
00354 if( p )
00355 {
00356 for(i=0;i<256;i++)
00357 {
00358 prmxFreeGroup( &p->prmByteGroup[i] );
00359 }
00360
00361 prmxFreeGroup( &p->prmGeneric );
00362
00363 free( p );
00364 }
00365 }
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394 static int prmxAddPortRule( PORT_GROUP *p, RULE_PTR rd )
00395 {
00396 if( !p->pgHead )
00397 {
00398 p->pgHead = (RULE_NODE*) malloc( sizeof(RULE_NODE) );
00399 if( !p->pgHead )return 1;
00400
00401 p->pgHead->rnNext = 0;
00402 p->pgHead->rnRuleData = rd;
00403 p->pgTail = p->pgHead;
00404 }
00405 else
00406 {
00407 p->pgTail->rnNext = (RULE_NODE*)malloc( sizeof(RULE_NODE) );
00408 if(!p->pgTail->rnNext)return 1;
00409
00410 p->pgTail = p->pgTail->rnNext;
00411 p->pgTail->rnNext = 0;
00412 p->pgTail->rnRuleData = rd;
00413 }
00414
00415
00416
00417
00418 p->pgTail->iRuleNodeID = p->pgCount;
00419
00420
00421
00422
00423 p->pgCount++;
00424
00425 p->pgContentCount++;
00426
00427 return 0;
00428 }
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 static int prmxAddPortRuleUri( PORT_GROUP *p, RULE_PTR rd )
00458 {
00459 if( !p->pgUriHead )
00460 {
00461 p->pgUriHead = (RULE_NODE*) malloc( sizeof(RULE_NODE) );
00462 if( !p->pgUriHead ) return 1;
00463
00464 p->pgUriTail = p->pgUriHead;
00465 p->pgUriHead->rnNext = 0;
00466 p->pgUriHead->rnRuleData = rd;
00467 }
00468 else
00469 {
00470 p->pgUriTail->rnNext = (RULE_NODE*)malloc( sizeof(RULE_NODE) );
00471 if( !p->pgUriTail->rnNext) return 1;
00472
00473 p->pgUriTail = p->pgUriTail->rnNext;
00474 p->pgUriTail->rnNext = 0;
00475 p->pgUriTail->rnRuleData = rd;
00476 }
00477
00478
00479
00480
00481 p->pgUriTail->iRuleNodeID = p->pgCount;
00482
00483
00484
00485
00486 p->pgCount++;
00487
00488 p->pgUriContentCount++;
00489
00490 return 0;
00491 }
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521 static int prmxAddPortRuleNC( PORT_GROUP *p, RULE_PTR rd )
00522 {
00523 if( !p->pgHeadNC )
00524 {
00525 p->pgHeadNC = (RULE_NODE*) malloc( sizeof(RULE_NODE) );
00526 if( !p->pgHeadNC )return 1;
00527
00528 p->pgTailNC = p->pgHeadNC;
00529 p->pgHeadNC->rnNext = 0;
00530 p->pgHeadNC->rnRuleData = rd;
00531 }
00532 else
00533 {
00534 p->pgTailNC->rnNext = (RULE_NODE*)malloc( sizeof(RULE_NODE) );
00535 if(!p->pgTailNC->rnNext)return 1;
00536
00537 p->pgTailNC = p->pgTailNC->rnNext;
00538 p->pgTailNC->rnNext = 0;
00539 p->pgTailNC->rnRuleData = rd;
00540 }
00541
00542
00543
00544
00545 p->pgTailNC->iRuleNodeID = p->pgCount;
00546
00547
00548
00549
00550 p->pgCount++;
00551
00552 p->pgNoContentCount++;
00553
00554 return 0;
00555 }
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567 void prmAddNotNode( PORT_GROUP * pg, int id )
00568 {
00569 NOT_RULE_NODE * p = malloc(sizeof( NOT_RULE_NODE));
00570
00571 if( !p ) return ;
00572
00573 p->iPos = id;
00574
00575 if( !pg->pgNotRuleList )
00576 {
00577 pg->pgNotRuleList = p;
00578 p->next = 0;
00579 }
00580 else
00581 {
00582 p->next = pg->pgNotRuleList;
00583 pg->pgNotRuleList = p;
00584 }
00585 }
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604 RULE_PTR prmGetFirstRule( PORT_GROUP * pg )
00605 {
00606 pg->pgCur = pg->pgHead;
00607
00608 if( !pg->pgCur )
00609 return 0;
00610
00611 return pg->pgCur->rnRuleData;
00612 }
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630 RULE_PTR prmGetNextRule( PORT_GROUP * pg )
00631 {
00632 if( pg->pgCur )
00633 pg->pgCur = pg->pgCur->rnNext;
00634
00635 if( !pg->pgCur )
00636 return 0;
00637
00638 return pg->pgCur->rnRuleData;
00639 }
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657 RULE_PTR prmGetFirstRuleUri( PORT_GROUP * pg )
00658 {
00659 pg->pgUriCur = pg->pgUriHead;
00660
00661 if( !pg->pgUriCur )
00662 return 0;
00663
00664 return pg->pgUriCur->rnRuleData;
00665 }
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683 RULE_PTR prmGetNextRuleUri( PORT_GROUP * pg )
00684 {
00685 if( pg->pgUriCur )
00686 pg->pgUriCur = pg->pgUriCur->rnNext;
00687
00688 if( !pg->pgUriCur )
00689 return 0;
00690
00691 return pg->pgUriCur->rnRuleData;
00692 }
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710 RULE_PTR prmGetFirstRuleNC( PORT_GROUP * pg )
00711 {
00712 pg->pgCurNC = pg->pgHeadNC;
00713
00714 if( !pg->pgCurNC )
00715 return 0;
00716
00717 return pg->pgCurNC->rnRuleData;
00718 }
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736 RULE_PTR prmGetNextRuleNC( PORT_GROUP * pg )
00737 {
00738 if( pg->pgCurNC )
00739 pg->pgCurNC = pg->pgCurNC->rnNext;
00740
00741 if( !pg->pgCurNC )
00742 return 0;
00743
00744 return pg->pgCurNC->rnRuleData;
00745 }
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777 int prmAddRule( PORT_RULE_MAP * p, int dport, int sport, RULE_PTR rd )
00778 {
00779 if( dport != ANYPORT && dport < MAX_PORTS )
00780 {
00781 p->prmNumDstRules++;
00782
00783
00784
00785
00786 if(p->prmDstPort[dport] == NULL)
00787 {
00788 p->prmDstPort[dport] = (PORT_GROUP *)calloc(1, sizeof(PORT_GROUP));
00789 if(p->prmDstPort[dport] == NULL)
00790 {
00791 return 1;
00792 }
00793 }
00794
00795 if(p->prmDstPort[dport]->pgCount==0) p->prmNumDstGroups++;
00796
00797 prmxAddPortRule( p->prmDstPort[ dport ], rd );
00798 }
00799
00800 if( sport != ANYPORT && sport < MAX_PORTS)
00801 {
00802 p->prmNumSrcRules++;
00803
00804
00805
00806
00807 if(p->prmSrcPort[sport] == NULL)
00808 {
00809 p->prmSrcPort[sport] = (PORT_GROUP *)calloc(1, sizeof(PORT_GROUP));
00810 if(p->prmSrcPort[sport] == NULL)
00811 {
00812 return 1;
00813 }
00814 }
00815
00816 if(p->prmSrcPort[sport]->pgCount==0) p->prmNumSrcGroups++;
00817
00818 prmxAddPortRule( p->prmSrcPort[ sport ], rd );
00819 }
00820
00821 if( sport == ANYPORT && dport == ANYPORT)
00822 {
00823 p->prmNumGenericRules++;
00824
00825
00826
00827
00828 if(p->prmGeneric == NULL)
00829 {
00830 p->prmGeneric = (PORT_GROUP *)calloc(1, sizeof(PORT_GROUP));
00831 if(p->prmGeneric == NULL)
00832 {
00833 return 1;
00834 }
00835 }
00836
00837 prmxAddPortRule( p->prmGeneric, rd );
00838 }
00839
00840 return 0;
00841 }
00842
00843 int prmAddByteRule( BYTE_RULE_MAP * p, int dport, RULE_PTR rd )
00844 {
00845 if( dport != ANYPORT && dport < 256 )
00846 {
00847 p->prmNumRules++;
00848 if( p->prmByteGroup[dport].pgCount==0 ) p->prmNumGroups++;
00849
00850 prmxAddPortRule( &(p->prmByteGroup[ dport ]), rd );
00851 }
00852
00853 else if( dport == ANYPORT )
00854 {
00855 p->prmNumGenericRules++;
00856
00857 prmxAddPortRule( &(p->prmGeneric), rd );
00858 }
00859
00860 return 0;
00861 }
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893 int prmAddRuleUri( PORT_RULE_MAP * p, int dport, int sport, RULE_PTR rd )
00894 {
00895 if( dport != ANYPORT && dport < MAX_PORTS )
00896 {
00897 p->prmNumDstRules++;
00898
00899
00900
00901
00902 if(p->prmDstPort[dport] == NULL)
00903 {
00904 p->prmDstPort[dport] = (PORT_GROUP *)calloc(1, sizeof(PORT_GROUP));
00905 if(p->prmDstPort[dport] == NULL)
00906 {
00907 return 1;
00908 }
00909 }
00910
00911 if(p->prmDstPort[dport]->pgCount==0) p->prmNumDstGroups++;
00912
00913 prmxAddPortRuleUri( p->prmDstPort[ dport ], rd );
00914 }
00915
00916 if( sport != ANYPORT && sport < MAX_PORTS)
00917 {
00918 p->prmNumSrcRules++;
00919
00920
00921
00922
00923 if(p->prmSrcPort[sport] == NULL)
00924 {
00925 p->prmSrcPort[sport] = (PORT_GROUP *)calloc(1, sizeof(PORT_GROUP));
00926 if(p->prmSrcPort[sport] == NULL)
00927 {
00928 return 1;
00929 }
00930 }
00931
00932 if(p->prmSrcPort[sport]->pgCount==0) p->prmNumSrcGroups++;
00933
00934 prmxAddPortRuleUri( p->prmSrcPort[ sport ], rd );
00935 }
00936
00937 if( sport == ANYPORT && dport == ANYPORT)
00938 {
00939 p->prmNumGenericRules++;
00940
00941
00942
00943
00944 if(p->prmGeneric == NULL)
00945 {
00946 p->prmGeneric = (PORT_GROUP *)calloc(1, sizeof(PORT_GROUP));
00947 if(p->prmGeneric == NULL)
00948 {
00949 return 1;
00950 }
00951 }
00952
00953 prmxAddPortRuleUri( p->prmGeneric, rd );
00954 }
00955
00956 return 0;
00957 }
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989 int prmAddRuleNC( PORT_RULE_MAP * p, int dport, int sport, RULE_PTR rd )
00990 {
00991 if( dport != ANYPORT && dport < MAX_PORTS )
00992 {
00993 p->prmNumDstRules++;
00994
00995
00996
00997
00998 if(p->prmDstPort[dport] == NULL)
00999 {
01000 p->prmDstPort[dport] = (PORT_GROUP *)calloc(1, sizeof(PORT_GROUP));
01001 if(p->prmDstPort[dport] == NULL)
01002 {
01003 return 1;
01004 }
01005 }
01006
01007 if(p->prmDstPort[dport]->pgCount==0) p->prmNumDstGroups++;
01008
01009 prmxAddPortRuleNC( p->prmDstPort[ dport ], rd );
01010 }
01011
01012 if( sport != ANYPORT && sport < MAX_PORTS)
01013 {
01014 p->prmNumSrcRules++;
01015
01016
01017
01018
01019 if(p->prmSrcPort[sport] == NULL)
01020 {
01021 p->prmSrcPort[sport] = (PORT_GROUP *)calloc(1, sizeof(PORT_GROUP));
01022 if(p->prmSrcPort[sport] == NULL)
01023 {
01024 return 1;
01025 }
01026 }
01027
01028 if(p->prmSrcPort[sport]->pgCount==0) p->prmNumSrcGroups++;
01029
01030 prmxAddPortRuleNC( p->prmSrcPort[ sport ], rd );
01031 }
01032
01033 if( sport == ANYPORT && dport == ANYPORT)
01034 {
01035 p->prmNumGenericRules++;
01036
01037
01038
01039
01040 if(p->prmGeneric == NULL)
01041 {
01042 p->prmGeneric = (PORT_GROUP *)calloc(1, sizeof(PORT_GROUP));
01043 if(p->prmGeneric == NULL)
01044 {
01045 return 1;
01046 }
01047 }
01048
01049 prmxAddPortRuleNC( p->prmGeneric, rd );
01050 }
01051
01052 return 0;
01053 }
01054
01055
01056 int prmAddByteRuleNC( BYTE_RULE_MAP * p, int dport, RULE_PTR rd )
01057 {
01058 if( dport != ANYPORT && dport < 256 )
01059 {
01060 p->prmNumRules++;
01061 if(p->prmByteGroup[dport].pgCount==0) p->prmNumGroups++;
01062
01063 prmxAddPortRuleNC( &(p->prmByteGroup[ dport ]), rd );
01064 }
01065
01066 else if( dport == ANYPORT)
01067 {
01068 p->prmNumGenericRules++;
01069
01070 prmxAddPortRuleNC( &(p->prmGeneric), rd );
01071 }
01072
01073 return 0;
01074 }
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116 int prmFindRuleGroup( PORT_RULE_MAP * p, int dport, int sport, PORT_GROUP ** src, PORT_GROUP **dst , PORT_GROUP ** gen)
01117 {
01118 int stat= 0;
01119
01120 if( (dport != ANYPORT && dport < MAX_PORTS) && p->prmDstPort[dport] )
01121 {
01122 *dst = p->prmDstPort[dport];
01123 stat = 1;
01124
01125 }else{
01126
01127 *dst=NULL;
01128 }
01129
01130 if( (sport != ANYPORT && sport < MAX_PORTS ) && p->prmSrcPort[sport])
01131 {
01132 *src = p->prmSrcPort[sport];
01133 stat |= 2;
01134
01135 }else{
01136 *src = NULL;
01137 }
01138
01139
01140 if( !stat && (p->prmGeneric > 0) )
01141 {
01142 *gen = p->prmGeneric;
01143 stat = 4;
01144
01145 }else{
01146
01147 *gen = NULL;
01148 }
01149
01150
01151 return stat;
01152 }
01153
01154
01155
01156
01157 int prmFindByteRuleGroup( BYTE_RULE_MAP * p, int dport, PORT_GROUP **dst , PORT_GROUP ** gen)
01158 {
01159 int stat= 0;
01160
01161 if( (dport != ANYPORT && dport < 256 ) && p->prmByteGroup[dport].pgCount )
01162 {
01163 *dst = &p->prmByteGroup[dport];
01164 stat = 1;
01165
01166 }else{
01167
01168 *dst=0;
01169 }
01170
01171
01172 if( !stat && (p->prmGeneric.pgCount > 0) )
01173 {
01174 *gen = &p->prmGeneric;
01175 stat = 4;
01176
01177 }else{
01178
01179 *gen = 0;
01180 }
01181
01182
01183 return stat;
01184 }
01185
01186
01187
01188
01189 PORT_GROUP * prmFindDstRuleGroup( PORT_RULE_MAP * p, int port )
01190 {
01191 if( port < 0 || port >= MAX_PORTS ) return 0;
01192
01193 if( p->prmDstPort[port])
01194 return p->prmDstPort[port];
01195
01196 return 0;
01197 }
01198
01199
01200
01201
01202 PORT_GROUP * prmFindSrcRuleGroup( PORT_RULE_MAP * p, int port )
01203 {
01204 if( port < 0 || port >= MAX_PORTS ) return 0;
01205
01206 if( p->prmSrcPort[port])
01207 return p->prmSrcPort[port];
01208
01209 return 0;
01210 }
01211
01212
01213
01214
01215 PORT_GROUP * prmFindByteRuleGroupUnique( BYTE_RULE_MAP * p, int port )
01216 {
01217 if( port < 0 || port >= MAX_PORTS ) return 0;
01218
01219 if( p->prmByteGroup[port].pgCount )
01220 return &p->prmByteGroup[port];
01221
01222 return 0;
01223 }
01224
01225
01226
01227
01228
01229 int prmSetGroupPatData( PORT_GROUP * pg, void * data )
01230 {
01231 pg->pgPatData = data;
01232 return 0;
01233 }
01234
01235
01236
01237
01238 void * prmGetGroupPatData( PORT_GROUP * pg )
01239 {
01240 return pg->pgPatData;
01241 }
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264 int prmCompileGroups( PORT_RULE_MAP * p )
01265 {
01266 PORT_GROUP *pgGen, *pgSrc, *pgDst;
01267 RULE_PTR *prule;
01268 int i;
01269
01270
01271
01272
01273 pgGen = p->prmGeneric;
01274
01275 if(!pgGen)
01276 return 0;
01277
01278 for(i=0;i<MAX_PORTS;i++)
01279 {
01280
01281
01282
01283
01284
01285
01286 if(p->prmSrcPort[i])
01287 {
01288 pgSrc = p->prmSrcPort[i];
01289
01290 prule = prmGetFirstRule( pgGen );
01291 while( prule )
01292 {
01293 prmxAddPortRule( pgSrc, prule );
01294 prule = prmGetNextRule( pgGen );
01295 }
01296
01297 prule = prmGetFirstRuleUri( pgGen );
01298 while( prule )
01299 {
01300 prmxAddPortRuleUri( pgSrc, prule );
01301 prule = prmGetNextRuleUri( pgGen );
01302 }
01303
01304 prule = prmGetFirstRuleNC( pgGen );
01305 while( prule )
01306 {
01307 prmxAddPortRuleNC( pgSrc, prule );
01308 prule = prmGetNextRuleNC( pgGen );
01309 }
01310 }
01311
01312 if(p->prmDstPort[i])
01313 {
01314 pgDst = p->prmDstPort[i];
01315
01316 prule = prmGetFirstRule( pgGen );
01317 while( prule )
01318 {
01319 prmxAddPortRule( pgDst, prule );
01320 prule = prmGetNextRule( pgGen );
01321 }
01322
01323 prule = prmGetFirstRuleUri( pgGen );
01324 while( prule )
01325 {
01326 prmxAddPortRuleUri( pgDst, prule );
01327 prule = prmGetNextRuleUri( pgGen );
01328 }
01329
01330 prule = prmGetFirstRuleNC( pgGen );
01331 while( prule )
01332 {
01333 prmxAddPortRuleNC( pgDst, prule );
01334 prule = prmGetNextRuleNC( pgGen );
01335 }
01336 }
01337
01338 }
01339
01340 return 0;
01341 }
01342
01343
01344
01345
01346
01347
01348 int prmCompileByteGroups( BYTE_RULE_MAP * p )
01349 {
01350 PORT_GROUP *pgGen, *pgByte;
01351 RULE_PTR *prule;
01352 int i;
01353
01354
01355
01356
01357 pgGen = &p->prmGeneric;
01358
01359 if( !pgGen->pgCount )
01360 return 0;
01361
01362 for(i=0;i<256;i++)
01363 {
01364 if(p->prmByteGroup[i].pgCount)
01365 {
01366 pgByte = &p->prmByteGroup[i];
01367
01368 prule = prmGetFirstRule( pgGen );
01369 while( prule )
01370 {
01371 prmxAddPortRule( pgByte, prule );
01372 prule = prmGetNextRule( pgGen );
01373 }
01374
01375 prule = prmGetFirstRuleNC( pgGen );
01376 while( prule )
01377 {
01378 prmxAddPortRuleNC( pgByte, prule );
01379 prule = prmGetNextRuleNC( pgGen );
01380 }
01381 }
01382 }
01383
01384 return 0;
01385 }
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405 int prmShowStats( PORT_RULE_MAP * p )
01406 {
01407 int i;
01408 PORT_GROUP * pg;
01409
01410 printf("Packet Classification Rule Manager Stats ----\n");
01411 printf("NumDstGroups : %d\n",p->prmNumDstGroups);
01412 printf("NumSrcGroups : %d\n",p->prmNumSrcGroups);
01413 printf("\n");
01414 printf("NumDstRules : %d\n",p->prmNumDstRules);
01415 printf("NumSrcRules : %d\n",p->prmNumSrcRules);
01416 printf("NumGenericRules: %d\n",p->prmNumGenericRules);
01417 printf("\n");
01418
01419 printf("%d Dst Groups In Use, %d Unique Rules, includes generic\n",p->prmNumDstGroups,p->prmNumDstRules);
01420 for(i=0;i<MAX_PORTS;i++)
01421 {
01422 pg = prmFindDstRuleGroup( p, i );
01423 if(pg)
01424 {
01425 printf(" Dst Port %5d : %d uricontent, %d content, %d nocontent \n",i,
01426 pg->pgUriContentCount,pg->pgContentCount,pg->pgNoContentCount);
01427 if( pg->avgLen )
01428 {
01429 printf("MinLen=%d MaxLen=%d AvgLen=%d",pg->minLen,pg->maxLen,pg->avgLen);
01430 if(pg->c1)printf(" [1]=%d",pg->c1);
01431 if(pg->c2)printf(" [2]=%d",pg->c2);
01432 if(pg->c3)printf(" [3]=%d",pg->c3);
01433 if(pg->c4)printf(" [4]=%d",pg->c4);
01434 printf("\n");
01435 }
01436 }
01437 }
01438
01439 printf("%d Src Groups In Use, %d Unique Rules, includes generic\n",p->prmNumSrcGroups,p->prmNumSrcRules);
01440 for(i=0;i<MAX_PORTS;i++)
01441 {
01442 pg = prmFindSrcRuleGroup( p, i );
01443 if(pg){
01444 printf(" Src Port %5d : %d uricontent, %d content, %d nocontent \n",i,
01445 pg->pgUriContentCount,pg->pgContentCount,pg->pgNoContentCount);
01446 if( pg->avgLen )
01447 {
01448 printf("MinLen=%d MaxLen=%d AvgLen=%d",pg->minLen,pg->maxLen,pg->avgLen);
01449 if(pg->c1)printf(" [1]=%d",pg->c1);
01450 if(pg->c2)printf(" [2]=%d",pg->c2);
01451 if(pg->c3)printf(" [3]=%d",pg->c3);
01452 if(pg->c4)printf(" [4]=%d",pg->c4);
01453 printf("\n");
01454 }
01455 }
01456 }
01457
01458 pg = p->prmGeneric;
01459 if(pg){
01460 printf(" Generic Rules : %d uricontent, %d content, %d nocontent \n",
01461 pg->pgUriContentCount,pg->pgContentCount,pg->pgNoContentCount);
01462 if( pg->avgLen )
01463 {
01464 printf("MinLen=%d MaxLen=%d AvgLen=%d",pg->minLen,pg->maxLen,pg->avgLen);
01465 if(pg->c1)printf(" [1]=%d",pg->c1);
01466 if(pg->c2)printf(" [2]=%d",pg->c2);
01467 if(pg->c3)printf(" [3]=%d",pg->c3);
01468 if(pg->c4)printf(" [4]=%d",pg->c4);
01469 printf("\n");
01470 }
01471 }
01472
01473 return 0;
01474 }
01475
01476
01477 int prmShowByteStats( BYTE_RULE_MAP * p )
01478 {
01479 int i;
01480 PORT_GROUP * pg;
01481
01482 printf("Packet Classification Rule Manager Stats ----\n");
01483 printf("NumGroups : %d\n",p->prmNumGroups);
01484 printf("\n");
01485 printf("NumRules : %d\n",p->prmNumRules);
01486 printf("NumGenericRules: %d\n",p->prmNumGenericRules);
01487 printf("\n");
01488
01489 printf("%d Byte Groups In Use, %d Unique Rules, includes generic\n",p->prmNumGroups,p->prmNumRules);
01490 for(i=0;i<256;i++)
01491 {
01492 pg = prmFindByteRuleGroupUnique( p, i );
01493 if(pg)
01494 {
01495 printf(" Proto/Type %5d : %d content, %d nocontent \n",i,
01496 pg->pgContentCount,pg->pgNoContentCount);
01497 if( pg->avgLen )
01498 {
01499 printf("MinLen=%d MaxLen=%d AvgLen=%d",pg->minLen,pg->maxLen,pg->avgLen);
01500 if(pg->c1)printf(" [1]=%d",pg->c1);
01501 if(pg->c2)printf(" [2]=%d",pg->c2);
01502 if(pg->c3)printf(" [3]=%d",pg->c3);
01503 if(pg->c4)printf(" [4]=%d",pg->c4);
01504 printf("\n");
01505 }
01506 }
01507 }
01508
01509
01510 pg = &p->prmGeneric;
01511 if(pg){
01512 printf(" Generic Rules : %d content, %d nocontent \n",
01513 pg->pgContentCount,pg->pgNoContentCount);
01514 if( pg->avgLen )
01515 {
01516 printf("MinLen=%d MaxLen=%d AvgLen=%d",pg->minLen,pg->maxLen,pg->avgLen);
01517 if(pg->c1)printf(" [1]=%d",pg->c1);
01518 if(pg->c2)printf(" [2]=%d",pg->c2);
01519 if(pg->c3)printf(" [3]=%d",pg->c3);
01520 if(pg->c4)printf(" [4]=%d",pg->c4);
01521 printf("\n");
01522 }
01523 }
01524
01525 return 0;
01526 }
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559 int prmShowEventStats( PORT_RULE_MAP * p )
01560 {
01561 int i;
01562 PORT_GROUP * pg;
01563
01564 int NQEvents = 0;
01565 int QEvents = 0;
01566
01567 printf("Packet Classification Rule Manager Stats ----\n");
01568 printf("NumDstGroups : %d\n",p->prmNumDstGroups);
01569 printf("NumSrcGroups : %d\n",p->prmNumSrcGroups);
01570 printf("\n");
01571 printf("NumDstRules : %d\n",p->prmNumDstRules);
01572 printf("NumSrcRules : %d\n",p->prmNumSrcRules);
01573 printf("NumGenericRules: %d\n",p->prmNumGenericRules);
01574 printf("\n");
01575
01576 printf("%d Dst Groups In Use, %d Unique Rules, includes generic\n",p->prmNumDstGroups,p->prmNumDstRules);
01577 for(i=0;i<MAX_PORTS;i++)
01578 {
01579 pg = prmFindDstRuleGroup( p, i );
01580 if(pg)
01581 {
01582 NQEvents += pg->pgNQEvents;
01583 QEvents += pg->pgQEvents;
01584
01585 if( pg->pgNQEvents + pg->pgQEvents )
01586 {
01587 printf(" Dst Port %5d : %d group entries \n",i, pg->pgCount);
01588 printf(" NQ Events : %d\n", pg->pgNQEvents);
01589 printf(" Q Events : %d\n", pg->pgQEvents);
01590 }
01591 }
01592 }
01593
01594 printf("%d Src Groups In Use, %d Unique Rules, includes generic\n",p->prmNumSrcGroups,p->prmNumSrcRules);
01595 for(i=0;i<MAX_PORTS;i++)
01596 {
01597 pg = prmFindSrcRuleGroup( p, i );
01598 if(pg)
01599 {
01600
01601 NQEvents += pg->pgNQEvents;
01602 QEvents += pg->pgQEvents;
01603
01604 if( pg->pgNQEvents + pg->pgQEvents )
01605 {
01606 printf(" Src Port %5d : %d group entries \n",i, pg->pgCount);
01607 printf(" NQ Events : %d\n", pg->pgNQEvents);
01608 printf(" Q Events : %d\n", pg->pgQEvents);
01609 }
01610 }
01611 }
01612
01613 pg = p->prmGeneric;
01614 if(pg)
01615 {
01616 NQEvents += pg->pgNQEvents;
01617 QEvents += pg->pgQEvents;
01618
01619 if( pg->pgNQEvents + pg->pgQEvents )
01620 {
01621 printf(" Generic Rules : %d group entries\n", pg->pgCount);
01622 printf(" NQ Events : %d\n", pg->pgNQEvents);
01623 printf(" Q Events : %d\n", pg->pgQEvents);
01624 }
01625 }
01626
01627 printf("Total NQ Events : %d\n", NQEvents);
01628 printf("Total Q Events : %d\n", QEvents);
01629
01630 return 0;
01631 }
01632
01633 int prmShowEventByteStats( BYTE_RULE_MAP * p )
01634 {
01635 int i;
01636 PORT_GROUP * pg;
01637
01638 int NQEvents = 0;
01639 int QEvents = 0;
01640
01641 printf("Packet Classification Rule Manager Stats ----\n");
01642 printf("NumGroups : %d\n",p->prmNumGroups);
01643 printf("\n");
01644 printf("NumRules : %d\n",p->prmNumRules);
01645 printf("NumGenericRules: %d\n",p->prmNumGenericRules);
01646 printf("\n");
01647
01648 printf("%d Byte Groups In Use, %d Unique Rules, includes generic\n",p->prmNumGroups,p->prmNumRules);
01649 for(i=0;i<256;i++)
01650 {
01651 pg = prmFindByteRuleGroupUnique( p, i );
01652 if(pg)
01653 {
01654 NQEvents += pg->pgNQEvents;
01655 QEvents += pg->pgQEvents;
01656
01657 if( pg->pgNQEvents + pg->pgQEvents )
01658 {
01659 printf(" Proto/Type %5d : %d group entries \n",i, pg->pgCount);
01660 printf(" NQ Events : %d\n", pg->pgNQEvents);
01661 printf(" Q Events : %d\n", pg->pgQEvents);
01662 }
01663 }
01664 }
01665
01666 pg = &p->prmGeneric;
01667 if(pg)
01668 {
01669 NQEvents += pg->pgNQEvents;
01670 QEvents += pg->pgQEvents;
01671
01672 if( pg->pgNQEvents + pg->pgQEvents )
01673 {
01674 printf(" Generic Rules : %d group entries\n", pg->pgCount);
01675 printf(" NQ Events : %d\n", pg->pgNQEvents);
01676 printf(" Q Events : %d\n", pg->pgQEvents);
01677 }
01678 }
01679
01680 printf("Total NQ Events : %d\n", NQEvents);
01681 printf("Total Q Events : %d\n", QEvents);
01682
01683 return 0;
01684 }