@@ -2764,6 +2764,46 @@ static void windivert_update_checksums(void *header, size_t len,
2764
2764
}
2765
2765
}
2766
2766
2767
+ /*
2768
+ * Big number comparison.
2769
+ */
2770
+ static int windivert_big_num_compare (const UINT32 * a , const UINT32 * b )
2771
+ {
2772
+ if (a [3 ] < b [3 ])
2773
+ {
2774
+ return -1 ;
2775
+ }
2776
+ if (a [3 ] > b [3 ])
2777
+ {
2778
+ return 1 ;
2779
+ }
2780
+ if (a [2 ] < b [2 ])
2781
+ {
2782
+ return -1 ;
2783
+ }
2784
+ if (a [2 ] > b [2 ])
2785
+ {
2786
+ return 1 ;
2787
+ }
2788
+ if (a [1 ] < b [1 ])
2789
+ {
2790
+ return -1 ;
2791
+ }
2792
+ if (a [1 ] > b [1 ])
2793
+ {
2794
+ return 1 ;
2795
+ }
2796
+ if (a [0 ] < b [0 ])
2797
+ {
2798
+ return -1 ;
2799
+ }
2800
+ if (a [0 ] > b [0 ])
2801
+ {
2802
+ return 1 ;
2803
+ }
2804
+ return 0 ;
2805
+ }
2806
+
2767
2807
/*
2768
2808
* Checks if the given packet is of interest.
2769
2809
*/
@@ -2926,6 +2966,7 @@ static BOOL windivert_filter(PNET_BUFFER buffer, UINT32 if_idx,
2926
2966
while (ttl -- != 0 )
2927
2967
{
2928
2968
BOOL result ;
2969
+ int cmp ;
2929
2970
UINT32 field [4 ];
2930
2971
field [1 ] = 0 ;
2931
2972
field [2 ] = 0 ;
@@ -2998,7 +3039,7 @@ static BOOL windivert_filter(PNET_BUFFER buffer, UINT32 if_idx,
2998
3039
field [0 ] = (UINT32 )ip_header -> HdrLength ;
2999
3040
break ;
3000
3041
case WINDIVERT_FILTER_FIELD_IP_TOS :
3001
- field [0 ] = (UINT32 )RtlUshortByteSwap ( ip_header -> TOS ) ;
3042
+ field [0 ] = (UINT32 )ip_header -> TOS ;
3002
3043
break ;
3003
3044
case WINDIVERT_FILTER_FIELD_IP_LENGTH :
3004
3045
field [0 ] = (UINT32 )RtlUshortByteSwap (ip_header -> Length );
@@ -3160,55 +3201,26 @@ static BOOL windivert_filter(PNET_BUFFER buffer, UINT32 if_idx,
3160
3201
field [0 ] = 0 ;
3161
3202
break ;
3162
3203
}
3204
+ cmp = windivert_big_num_compare (field , filter [ip ].arg );
3163
3205
switch (filter [ip ].test )
3164
3206
{
3165
3207
case WINDIVERT_FILTER_TEST_EQ :
3166
- result = (field [0 ] == filter [ip ].arg [0 ] &&
3167
- field [1 ] == filter [ip ].arg [1 ] &&
3168
- field [2 ] == filter [ip ].arg [2 ] &&
3169
- field [3 ] == filter [ip ].arg [3 ]);
3208
+ result = (cmp == 0 );
3170
3209
break ;
3171
3210
case WINDIVERT_FILTER_TEST_NEQ :
3172
- result = (field [0 ] != filter [ip ].arg [0 ] ||
3173
- field [1 ] != filter [ip ].arg [1 ] ||
3174
- field [2 ] != filter [ip ].arg [2 ] ||
3175
- field [3 ] != filter [ip ].arg [3 ]);
3211
+ result = (cmp != 0 );
3176
3212
break ;
3177
3213
case WINDIVERT_FILTER_TEST_LT :
3178
- result = (field [3 ] < filter [ip ].arg [3 ] ||
3179
- (field [3 ] == filter [ip ].arg [3 ] &&
3180
- field [2 ] < filter [ip ].arg [2 ] ||
3181
- (field [2 ] == filter [ip ].arg [2 ] &&
3182
- field [1 ] < filter [ip ].arg [1 ] ||
3183
- (field [1 ] == filter [ip ].arg [1 ] &&
3184
- field [0 ] < filter [ip ].arg [0 ]))));
3214
+ result = (cmp < 0 );
3185
3215
break ;
3186
3216
case WINDIVERT_FILTER_TEST_LEQ :
3187
- result = (field [3 ] < filter [ip ].arg [3 ] ||
3188
- (field [3 ] == filter [ip ].arg [3 ] &&
3189
- field [2 ] < filter [ip ].arg [2 ] ||
3190
- (field [2 ] == filter [ip ].arg [2 ] &&
3191
- field [1 ] < filter [ip ].arg [1 ] ||
3192
- (field [1 ] == filter [ip ].arg [1 ] &&
3193
- field [0 ] <= filter [ip ].arg [0 ]))));
3217
+ result = (cmp <= 0 );
3194
3218
break ;
3195
3219
case WINDIVERT_FILTER_TEST_GT :
3196
- result = (field [3 ] > filter [ip ].arg [3 ] ||
3197
- (field [3 ] == filter [ip ].arg [3 ] &&
3198
- field [2 ] > filter [ip ].arg [2 ] ||
3199
- (field [2 ] == filter [ip ].arg [2 ] &&
3200
- field [1 ] > filter [ip ].arg [1 ] ||
3201
- (field [1 ] == filter [ip ].arg [1 ] &&
3202
- field [0 ] > filter [ip ].arg [0 ]))));
3220
+ result = (cmp > 0 );
3203
3221
break ;
3204
3222
case WINDIVERT_FILTER_TEST_GEQ :
3205
- result = (field [3 ] > filter [ip ].arg [3 ] ||
3206
- (field [3 ] == filter [ip ].arg [3 ] &&
3207
- field [2 ] > filter [ip ].arg [2 ] ||
3208
- (field [2 ] == filter [ip ].arg [2 ] &&
3209
- field [1 ] > filter [ip ].arg [1 ] ||
3210
- (field [1 ] == filter [ip ].arg [1 ] &&
3211
- field [0 ] >= filter [ip ].arg [0 ]))));
3223
+ result = (cmp >= 0 );
3212
3224
break ;
3213
3225
default :
3214
3226
result = FALSE;
@@ -3465,6 +3477,7 @@ static filter_t windivert_filter_compile(windivert_ioctl_filter_t ioctl_filter,
3465
3477
goto windivert_filter_compile_exit ;
3466
3478
}
3467
3479
break ;
3480
+ case WINDIVERT_FILTER_FIELD_IP_TOS :
3468
3481
case WINDIVERT_FILTER_FIELD_IP_TTL :
3469
3482
case WINDIVERT_FILTER_FIELD_IP_PROTOCOL :
3470
3483
case WINDIVERT_FILTER_FIELD_IPV6_TRAFFICCLASS :
@@ -3485,7 +3498,6 @@ static filter_t windivert_filter_compile(windivert_ioctl_filter_t ioctl_filter,
3485
3498
goto windivert_filter_compile_exit ;
3486
3499
}
3487
3500
break ;
3488
- case WINDIVERT_FILTER_FIELD_IP_TOS :
3489
3501
case WINDIVERT_FILTER_FIELD_IP_LENGTH :
3490
3502
case WINDIVERT_FILTER_FIELD_IP_ID :
3491
3503
case WINDIVERT_FILTER_FIELD_IP_CHECKSUM :
0 commit comments