diff --git a/test/zdtm.sh b/test/zdtm.sh index 96aee834e..3d86dd23e 100644 --- a/test/zdtm.sh +++ b/test/zdtm.sh @@ -46,6 +46,7 @@ static/cmdlinenv00 static/socket_listen static/packet_sock static/socket_udp +static/sock_filter static/socket6_udp static/socket_udplite static/selfexe00 diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile index bc31148cc..0d93a4dd3 100644 --- a/test/zdtm/live/static/Makefile +++ b/test/zdtm/live/static/Makefile @@ -27,6 +27,7 @@ TST_NOFILE = \ socket_udplite \ socket_aio \ packet_sock \ + sock_filter \ msgque \ inotify_system \ inotify_system_nodel \ diff --git a/test/zdtm/live/static/sock_filter.c b/test/zdtm/live/static/sock_filter.c new file mode 100644 index 000000000..b377f932a --- /dev/null +++ b/test/zdtm/live/static/sock_filter.c @@ -0,0 +1,115 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "zdtmtst.h" + +const char *test_doc = "Check socket filter"; +const char *test_author = "Pavel Emelyanov "; + +#ifndef SO_GET_FILTER +#define SO_GET_FILTER SO_ATTACH_FILTER +#endif + +#define SFLEN 14 + +int main(int argc, char **argv) +{ + int sk; + struct sock_fprog p; + struct sock_filter f[SFLEN] = { + { 0x28, 0, 0, 0x0000000c }, + { 0x15, 0, 4, 0x00000800 }, + { 0x20, 0, 0, 0x0000001a }, + { 0x15, 8, 0, 0x7f000001 }, + { 0x20, 0, 0, 0x0000001e }, + { 0x15, 6, 7, 0x7f000001 }, + { 0x15, 1, 0, 0x00000806 }, + { 0x15, 0, 5, 0x00008035 }, + { 0x20, 0, 0, 0x0000001c }, + { 0x15, 2, 0, 0x7f000001 }, + { 0x20, 0, 0, 0x00000026 }, + { 0x15, 0, 1, 0x7f000001 }, + { 0x6, 0, 0, 0x0000ffff }, + { 0x6, 0, 0, 0x00000000 }, + }; + struct sock_filter f2[SFLEN], f3[SFLEN]; + socklen_t len; + + test_init(argc, argv); + + sk = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (sk < 0) { + err("No socket"); + return 1; + } + + p.len = SFLEN; + p.filter = f; + + if (setsockopt(sk, SOL_SOCKET, SO_ATTACH_FILTER, &p, sizeof(p))) { + err("No filter"); + return 1; + } + + len = 0; + if (getsockopt(sk, SOL_SOCKET, SO_GET_FILTER, NULL, &len)) { + err("No len"); + return 1; + } + + if (len != SFLEN) { + err("Len mismatch"); + return 1; + } + + memset(f2, 0, sizeof(f2)); + if (getsockopt(sk, SOL_SOCKET, SO_GET_FILTER, f2, &len)) { + perror("No filter"); + return 1; + } + + if (len != SFLEN) { + err("Len mismatch2"); + return 1; + } + + test_daemon(); + test_waitsig(); + + len = 0; + if (getsockopt(sk, SOL_SOCKET, SO_GET_FILTER, NULL, &len)) { + fail("No len"); + return 1; + } + + if (len != SFLEN) { + fail("Len mismatch"); + return 1; + } + + memset(f3, 0, sizeof(f3)); + if (getsockopt(sk, SOL_SOCKET, SO_GET_FILTER, f3, &len)) { + fail("No filter"); + return 1; + } + + if (len != SFLEN) { + fail("Len mismatch2"); + return 1; + } + + if (memcmp(f2, f3, sizeof(f2))) { + fail("Filters mismatch"); + return 1; + } + + pass(); + + return 0; +} +