Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port/portrange: syntax incompatibilities in edge cases with regards to libpcap #243

Open
kbara opened this issue Jul 6, 2015 · 2 comments

Comments

@kbara
Copy link
Contributor

kbara commented Jul 6, 2015

On the good side: pflua appears to have fairly good libpcap compatibility on this point. The only incompatible detail that has appeared is that pflua does not treat hexadecimal arguments to portrange as a 0.

libpcap version 1.5.3, pflua 5e2c56b

portrange x-y requires both x and y to be decimal numbers; if they are not, it has rather unintuitive behaviour. Numbers starting with an 0x cause a parse error in pflua and are treated as 0 by libpcap, in expressions like "portrange 1-0x3. Numbers starting with a 0 are treated as decimal, rather than octal:

% ./pflua-compile  "portrange 1-0151661"
luajit: ../src/pf/parse.lua:425: port 151661 out of range
% tcpdump -d "portrange 1-0151661"
tcpdump: illegal port number 151661 > 65535

Note that port can take octal and hexadecimal values. For instance, port 0151661 is tested against #0xd3b1 in libpcap, and 45523 in pflua on x86 (0xb1d3 - it's not abstracting away network byte order vs x86 byte order, but it gives the correct result).

@mpeterv
Copy link
Contributor

mpeterv commented Jul 6, 2015

It seems that libpcap does not accept hexadecimal numbers as the first port in portrange ("portrange 0x-1" gives "unknown port in range '0x-1'". On the other hand, for the second port it simply ignores any garbage after the number, e.g. "portrange 1-20" and "portrange 1-20foobar" produce same code.

For octal numbers, I personally think it makes sense to ignore leading zero in contexts where only decimal numbers are expected.

If you are looking for other incompatibilities, I noticed that libpcap accepts single number as portrange argument, so that "portrange N" is equivalent to "port N". Another thing is that pflua doesn't seem to support hexadecimal literals starting with 0X.

@kbara
Copy link
Contributor Author

kbara commented Jul 8, 2015

Good observations, thank you!

@kbara kbara added the bug label Jul 8, 2015
@kbara kbara changed the title Portrange numbers are treated as decimal (libpcap and pflua) Port/portrange: syntax incompatibilities in edge cases with regards to libpcap Jul 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants