Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Mask calculator

Generate masks for a set of numbers

Algorithms

qmm.cpp

greedy_merge.cpp

  • A simple & recurisve greedy algorithm which aggressively try to generate a new mask by combining two numbers whenever possible
  • Very fast but sometimes give non-optimal solution

Features

  • Maximum number of variables supported: 32
  • Accept don't care terms

Example

Suppose we want to calculate the port mask when filtering Stream UDP ports ranging from [27000, 27015]

Run the program as follow:

$ ./mask_calc 27000-27015

The program then output the results, first pair is value 27000 masked by 0xfffffff8, second pair is value 27008 masked by 0xfffffff8.

value(dec) / mask(hex)
1: 27000 / fffffff8
2: 27008 / fffffff8

Additionaly, you can check the result by another program I wrote, see Notes.

Compiler Requirements

License

This program is licensed under GPLv3

Notes

  • There is another program Mask Enumerator, which was created at the same time to verify the solution of this program.

  • This program was created to help me generate the port mask when writing traffic shaping rules. When doing traffic shaping by utilizing u32 filter, the filter could only match multiple ports by specifying a mask.

    At the time writing the filtering rules, I couldn't find any suitable tool for this task, so I started my own.

About

Generate masks for a set of numbers

Resources

License

Releases

No releases published

Packages

No packages published