Skip to content

Optimize specifing port range with binary mask  #885

@hengyoush

Description

@hengyoush

Issue Description

bug report
In network scenarios, when you specify a port range for remote-port or local-port, an error occured if the port range is large, for example, 1 to 10000.
Using the bitmask of the tc command can solve the problem, and the fault injection speed is faster。

Describe what happened (or what feature you want)

Describe what you expected to happen

log:
log is too large, I truncate to the last :

filter add dev eth0 parent 1: prio 4 protocol ip u32 match ip dst 192.168.1.231 match ip dport 10000 0xffff flowid 1:4`: cmd exec failed, err:  fork/exec /bin/sh: argument list too long"}

problem is the command too long exceed limit of shell.
current implementation:
Each port corresponds to one command, resulting in an excessive number of commands

My Optimization :
tc support use binary mask,example:
represent [25 , 10000] with mark:
value: 25, mask: 11111111111111111111111111111111
value: 26, mask: 11111111111111111111111111111110
value: 28, mask: 11111111111111111111111111111100
value: 32, mask: 11111111111111111111111111100000
value: 64, mask: 11111111111111111111111111000000
value: 128, mask: 11111111111111111111111110000000
value: 256, mask: 11111111111111111111111100000000
value: 512, mask: 11111111111111111111111000000000
value: 1024, mask: 11111111111111111111110000000000
value: 2048, mask: 11111111111111111111100000000000
value: 4096, mask: 11111111111111111111000000000000
value: 8192, mask: 11111111111111111111110000000000
value: 9216, mask: 11111111111111111111111000000000
value: 9728, mask: 11111111111111111111111100000000
value: 9984, mask: 11111111111111111111111111110000
value: 10000, mask: 11111111111111111111111111111111
combine all above can represent [25,10000] ports range, which only consisting of 16 commands instead of 10000 commands

How to reproduce it (as minimally and precisely as possible)

Tell us your environment

Anything else we need to know?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions