-
Notifications
You must be signed in to change notification settings - Fork 10
ip-address: Add tests for ipv4_prefix2mask #5
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
Conversation
Add some tests that cover all the possible octet values in the mask, as well as invalid prefix lengths. While running the tests, it was discovered the function did not work on mksh at all: - that shell stores integers as int32_t in arith context, so numbers like 0x80000000 are < 0, and bit shift to the right has been observed to sign-extend; - that shell cannot left-shift an integer by 32 bits (and evaluate to a multiple of 4294967296), since the shift amount is considered modulo 32. We have to replace the algorithm to not rely on left shift by 32, or any right shift. We move it to a separate function to be used from more places in subsequent changes. Signed-off-by: Arseny Maslennikov <ar@cs.msu.ru>
|
There is a different micro-issue: the following has been failing for me since the last additions to master: with this error output: The I'm not sure it'd be appropriate or not-noisy to register this as a GH issue, so describing it here. |
Ah. Good catch! Builtin |
f95ce2c to
ab2e6d1
Compare
|
@bonktree merged. |
|
I am slowly coming to the conclusion that it is worth adding |
I didn't know that mksh doesn't support 64-bit numbers. I even started to think that this should be a blocker for mksh support. But it turns out that ash/hash from busybox is also 32-bit by default, and 64-bit support can only be enabled with a separate option. |
Sorry. Wrong again. 64-bit support enabled by default if POSIX math support enabled. |
That would definitely make sense if there were multiple use cases for such tools, either from inside the libshell project or described by users. So operations on IP addresses is one, and there would better be others. A small bit of bikeshedding on the file name: |
What lies on the surface, inside libshell is shell-cmdline, in which I used bitwise operations for parser states. In several other places, bitwise operations could also be useful when multiple flags are required. The kernel has convenient wrappers such as BIT, test_bit, and so on. This is much more declarative than in-place operations. I thought that this could also be useful for libshell.
I'm just lazy. In the kernel, such wrappers are located in |
|
@bonktree I wrote a short article researching the behavior of different shell implementations when parsing and calculating arithmetic values close to the maximum. The result surprised me. https://github.com/legionus/libshell/blob/master/Documentation/int64_max.md |
Add some tests that cover all the possible octet values in the mask, as well as invalid prefix lengths.
While running the tests, it was discovered the function did not work on mksh at all:
0x80000000are< 0, and bit shift to the right has been observed to sign-extend;4294967296), since the shift amount is considered modulo 32.We have to replace the algorithm to not rely on left shift by 32, or any right shift. We move it to a separate function to be used from more places in future patches.