summaryrefslogtreecommitdiff
path: root/src/test/test-parse-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-04-20 16:28:12 +0200
committerSven Eden <yamakuzure@gmx.net>2018-08-24 16:47:08 +0200
commit4c3d43ed2482df213a77abd68b17af149baf9a55 (patch)
tree657fe589b0927a5a667f8391bd9d834ec8807015 /src/test/test-parse-util.c
parent91723aa6753c9412b6640242c4afe058e999551d (diff)
parse-util: add explicit parsers for MTU values
We use MTUs all over the place, let's add a unified, strict parser for it, that takes MTU ranges into account. We already have parse_ifindex() close-by, hence this appears to be a natural addition, in particular as the range checking is not entirely trivial to do, as it depends on the protocol used.
Diffstat (limited to 'src/test/test-parse-util.c')
-rw-r--r--src/test/test-parse-util.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c
index e8c12710a..8f3cf671f 100644
--- a/src/test/test-parse-util.c
+++ b/src/test/test-parse-util.c
@@ -9,6 +9,7 @@
#include <errno.h>
#include <locale.h>
#include <math.h>
+//#include <sys/socket.h>
#include "alloc-util.h"
#include "errno-list.h"
@@ -764,6 +765,27 @@ static void test_parse_syscall_and_errno(void) {
assert_se(parse_syscall_and_errno("hoge:", &n, &e) == -EINVAL);
}
+static void test_parse_mtu(void) {
+ uint32_t mtu = 0;
+
+ assert_se(parse_mtu(AF_UNSPEC, "1500", &mtu) >= 0 && mtu == 1500);
+ assert_se(parse_mtu(AF_UNSPEC, "1400", &mtu) >= 0 && mtu == 1400);
+ assert_se(parse_mtu(AF_UNSPEC, "65535", &mtu) >= 0 && mtu == 65535);
+ assert_se(parse_mtu(AF_UNSPEC, "65536", &mtu) >= 0 && mtu == 65536);
+ assert_se(parse_mtu(AF_UNSPEC, "4294967295", &mtu) >= 0 && mtu == 4294967295);
+ assert_se(parse_mtu(AF_UNSPEC, "500", &mtu) >= 0 && mtu == 500);
+ assert_se(parse_mtu(AF_UNSPEC, "1280", &mtu) >= 0 && mtu == 1280);
+ assert_se(parse_mtu(AF_INET6, "1280", &mtu) >= 0 && mtu == 1280);
+ assert_se(parse_mtu(AF_INET6, "1279", &mtu) == -ERANGE);
+ assert_se(parse_mtu(AF_UNSPEC, "4294967296", &mtu) == -ERANGE);
+ assert_se(parse_mtu(AF_INET6, "4294967296", &mtu) == -ERANGE);
+ assert_se(parse_mtu(AF_INET6, "68", &mtu) == -ERANGE);
+ assert_se(parse_mtu(AF_UNSPEC, "68", &mtu) >= 0 && mtu == 68);
+ assert_se(parse_mtu(AF_UNSPEC, "67", &mtu) == -ERANGE);
+ assert_se(parse_mtu(AF_UNSPEC, "0", &mtu) == -ERANGE);
+ assert_se(parse_mtu(AF_UNSPEC, "", &mtu) == -EINVAL);
+}
+
int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
@@ -790,6 +812,7 @@ int main(int argc, char *argv[]) {
test_parse_dev();
test_parse_errno();
test_parse_syscall_and_errno();
+ test_parse_mtu();
return 0;
}