You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(6) |
Jun
(12) |
Jul
(46) |
Aug
(8) |
Sep
(27) |
Oct
(73) |
Nov
(56) |
Dec
(34) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(36) |
Feb
(33) |
Mar
(50) |
Apr
(66) |
May
(76) |
Jun
(63) |
Jul
(63) |
Aug
(26) |
Sep
(35) |
Oct
(34) |
Nov
(82) |
Dec
(99) |
2003 |
Jan
(152) |
Feb
(76) |
Mar
(146) |
Apr
(156) |
May
(71) |
Jun
(46) |
Jul
(42) |
Aug
(34) |
Sep
(32) |
Oct
(49) |
Nov
(66) |
Dec
(78) |
2004 |
Jan
(76) |
Feb
(48) |
Mar
(25) |
Apr
(78) |
May
(76) |
Jun
(71) |
Jul
(39) |
Aug
(53) |
Sep
(27) |
Oct
(26) |
Nov
(23) |
Dec
(29) |
2005 |
Jan
(53) |
Feb
(41) |
Mar
(48) |
Apr
(36) |
May
(29) |
Jun
(71) |
Jul
(61) |
Aug
(77) |
Sep
(49) |
Oct
(32) |
Nov
(27) |
Dec
(40) |
2006 |
Jan
(23) |
Feb
(48) |
Mar
(24) |
Apr
(31) |
May
(50) |
Jun
(42) |
Jul
(24) |
Aug
(140) |
Sep
(55) |
Oct
(43) |
Nov
(11) |
Dec
(18) |
2007 |
Jan
(15) |
Feb
(20) |
Mar
(99) |
Apr
(110) |
May
(140) |
Jun
(98) |
Jul
(90) |
Aug
(58) |
Sep
(86) |
Oct
(79) |
Nov
(137) |
Dec
(129) |
2008 |
Jan
(277) |
Feb
(321) |
Mar
(285) |
Apr
(373) |
May
(415) |
Jun
(328) |
Jul
(288) |
Aug
(469) |
Sep
(334) |
Oct
(570) |
Nov
(368) |
Dec
(376) |
2009 |
Jan
(401) |
Feb
(317) |
Mar
(373) |
Apr
(309) |
May
(280) |
Jun
(371) |
Jul
(504) |
Aug
(465) |
Sep
(231) |
Oct
(295) |
Nov
(271) |
Dec
(222) |
2010 |
Jan
(313) |
Feb
(231) |
Mar
(251) |
Apr
(166) |
May
(124) |
Jun
(83) |
Jul
(141) |
Aug
(195) |
Sep
(160) |
Oct
(204) |
Nov
(295) |
Dec
(206) |
2011 |
Jan
(262) |
Feb
(176) |
Mar
(168) |
Apr
(217) |
May
(70) |
Jun
(65) |
Jul
(89) |
Aug
(169) |
Sep
(125) |
Oct
(64) |
Nov
(116) |
Dec
(148) |
2012 |
Jan
(343) |
Feb
(352) |
Mar
(205) |
Apr
(151) |
May
(140) |
Jun
(103) |
Jul
(156) |
Aug
(221) |
Sep
(55) |
Oct
(150) |
Nov
(79) |
Dec
(77) |
2013 |
Jan
(95) |
Feb
(78) |
Mar
(157) |
Apr
(213) |
May
(220) |
Jun
(227) |
Jul
(275) |
Aug
(224) |
Sep
(156) |
Oct
(248) |
Nov
(338) |
Dec
(181) |
2014 |
Jan
(165) |
Feb
(299) |
Mar
(338) |
Apr
(315) |
May
(277) |
Jun
(186) |
Jul
(204) |
Aug
(212) |
Sep
(231) |
Oct
(152) |
Nov
(107) |
Dec
(167) |
2015 |
Jan
(197) |
Feb
(182) |
Mar
(135) |
Apr
(167) |
May
(192) |
Jun
(326) |
Jul
(311) |
Aug
(198) |
Sep
(84) |
Oct
(11) |
Nov
(3) |
Dec
(4) |
2016 |
Jan
(1) |
Feb
(1) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
(3) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(5) |
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2021 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
From: Zeng L. <zen...@cn...> - 2015-08-31 10:15:44
|
* Add 'static' before some functions and global variables. * Remove cleanup() function. * Remove useless comments. * In every test function, using TINFO instead of TPASS marks the success of each inner test. * Some cleanup. Signed-off-by: Zeng Linggang <zen...@cn...> Signed-off-by: Alexey Kodanev <ale...@or...> Signed-off-by: Cyril Hrubis <ch...@su...> --- testcases/network/lib6/getaddrinfo_01.c | 503 ++++++++++++++++++-------------- 1 file changed, 281 insertions(+), 222 deletions(-) diff --git a/testcases/network/lib6/getaddrinfo_01.c b/testcases/network/lib6/getaddrinfo_01.c index ec29b5d..a812e77 100644 --- a/testcases/network/lib6/getaddrinfo_01.c +++ b/testcases/network/lib6/getaddrinfo_01.c @@ -1,43 +1,21 @@ /* + * Copyright (c) 2015 Fujitsu Ltd. + * Copyright (c) International Business Machines Corp., 2001 * - * Copyright (c) International Business Machines Corp., 2001 + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - * Test Name: getaddrinfo_01 - * - * Test Description: - * Tests for getaddrinfo library function - * - * Usage: <for command-line> - * getaddrinfo_01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2004 written by David L Stevens - * - * RESTRICTIONS: - * None. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + * Author: David L Stevens */ #include <unistd.h> @@ -53,40 +31,38 @@ #define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */ #endif -char *TCID = "getaddrinfo_01"; /* Test program identifier. */ -int testno; +static void setup(void); +static void gaiv4(void); +static void gaiv6(void); -void setup(void), cleanup(void); - -int TST_TOTAL = 1; - -/* a host that isn't where LTP is running */ -#define REMOTEHOSTNAME "www.ibm.com" - -void gaiv4(void), gaiv6(void); -void dumpres(struct addrinfo *); +char *TCID = "getaddrinfo_01"; +int TST_TOTAL = 2; int main(int argc, char *argv[]) { int lc; - /* Parse standard options given to run the test. */ tst_parse_opts(argc, argv, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); ++lc) { + tst_count = 0; + gaiv4(); gaiv6(); } - cleanup(); - return (0); + tst_exit(); } -/* getaddrinfo tests (v4) */ +static void setup(void) +{ + TEST_PAUSE; +} -void gaiv4(void) +/* getaddrinfo tests (v4) */ +static void gaiv4(void) { struct addrinfo *aires, hints, *pai; char hostname[MAXHOSTNAMELEN + 1]; @@ -132,13 +108,18 @@ void gaiv4(void) psin ? psin->sin_family : 0, psin ? psin->sin_port : 0, psin ? htons(psin->sin_port) : 0); - } else - tst_resm(TPASS, "getaddrinfo IPv4 basic lookup"); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 basic " + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv4 basic lookup"); + freeaddrinfo(aires); + } + } else { + tst_resm(TFAIL, "getaddrinfo IPv4 basic " "lookup (\"%s\") returns %ld (\"%s\")", hostname, TEST_RETURN, gai_strerror(TEST_RETURN)); + return; + } /* test 2, IPv4 canonical name */ memset(&hints, 0, sizeof(hints)); @@ -152,20 +133,26 @@ void gaiv4(void) if (!pai) { tst_resm(TFAIL, "getaddrinfo IPv4 canonical name: no " "entries with canonical name set"); + freeaddrinfo(aires); + return; } else if (strcasecmp(hostname, pai->ai_canonname)) { tst_resm(TFAIL, "getaddrinfo IPv4 canonical name " "(\"%s\") doesn't match hostname (\"%s\")", pai->ai_canonname, hostname); - } else - tst_resm(TPASS, "getaddrinfo IPv4 canonical name"); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 " + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv4 canonical name"); + freeaddrinfo(aires); + } + } else { + tst_resm(TFAIL, "getaddrinfo IPv4 " "canonical name (\"%s\") returns %ld (\"%s\")", shortname, TEST_RETURN, gai_strerror(TEST_RETURN)); + return; + } /* test 3, IPv4 host+service name */ - memset(&hints, 0, sizeof(hints)); /* * These are hard-coded for echo/7 to avoid using getservbyname(), @@ -200,13 +187,18 @@ void gaiv4(void) psin ? psin->sin_family : 0, psin ? psin->sin_port : 0, psin ? htons(psin->sin_port) : 0); - } else - tst_resm(TPASS, "getaddrinfo IPv4 host+service"); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 host+" + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv4 host+service"); + freeaddrinfo(aires); + } + } else { + tst_resm(TFAIL, "getaddrinfo IPv4 host+" "service returns %ld (\"%s\")", TEST_RETURN, gai_strerror(TEST_RETURN)); + return; + } /* test 4, IPv4 hostname+service, AI_PASSIVE */ memset(&hints, 0, sizeof(hints)); @@ -244,18 +236,22 @@ void gaiv4(void) psin ? psin->sin_family : 0, psin ? psin->sin_port : 0, psin ? htons(psin->sin_port) : 0); - } else - tst_resm(TPASS, + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv4 host+service PASSIVE"); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 host+" + freeaddrinfo(aires); + } + } else { + tst_resm(TFAIL, "getaddrinfo IPv4 host+" "service, PASSIVE (\"%s\", \"%s\") returns %ld (\"%s\")", hostname, service, TEST_RETURN, gai_strerror(TEST_RETURN)); + return; + } /* test 5, IPv4 host+service w/ AI_NUMERICHOST */ - memset(&hints, 0, sizeof(hints)); strcpy(service, "echo"); servnum = 7; @@ -266,8 +262,11 @@ void gaiv4(void) tst_resm(TFAIL, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname: " "returns %ld expected %d (EAI_NONAME)", TEST_RETURN, EAI_NONAME); + if (!TEST_RETURN) + freeaddrinfo(aires); + return; } else - tst_resm(TPASS, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname"); + tst_resm(TINFO, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname"); if (!TEST_RETURN) freeaddrinfo(aires); @@ -306,17 +305,28 @@ void gaiv4(void) psin ? psin->sin_family : 0, psin ? psin->sin_port : 0, psin ? htons(psin->sin_port) : 0); - } else - tst_resm(TPASS, "getaddrinfo IPv4 0+service, PASSIVE"); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL, - "getaddrinfo IPv4 0+service, PASSIVE (\"\", \"%s\") " - "returns %ld (\"%s\")", service, TEST_RETURN, - gai_strerror(TEST_RETURN)); + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv4 0+service, PASSIVE"); + freeaddrinfo(aires); + } + } else { + if (TEST_RETURN == EAI_BADFLAGS) { + tst_resm(TINFO, "getaddrinfo IPv4 0+service," + " PASSIVE (\"\", \"%s\") returns %ld (\"%s\")", + service, TEST_RETURN, + gai_strerror(TEST_RETURN)); + } else { + tst_resm(TFAIL, "getaddrinfo IPv4 0+service,i" + " PASSIVE (\"\", \"%s\") returns %ld (\"%s\")", + service, TEST_RETURN, + gai_strerror(TEST_RETURN)); + return; + } + } /* test 7, IPv4 0+service */ - memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; @@ -350,19 +360,30 @@ void gaiv4(void) psin ? psin->sin_family : 0, psin ? psin->sin_port : 0, psin ? htons(psin->sin_port) : 0); - } else - tst_resm(TPASS, "getaddrinfo IPv4 0+service"); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL, - "getaddrinfo IPv4 0+service (\"\", \"%s\") returns %ld " - "(\"%s\")", service, TEST_RETURN, - gai_strerror(TEST_RETURN)); + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv4 0+service"); + freeaddrinfo(aires); + } + } else { + if (TEST_RETURN == EAI_BADFLAGS) { + tst_resm(TINFO, "getaddrinfo IPv4 " + "0+service (\"\", \"%s\") returns %ld (\"%s\")", + service, TEST_RETURN, + gai_strerror(TEST_RETURN)); + } else { + tst_resm(TFAIL, "getaddrinfo IPv4 " + "0+service (\"\", \"%s\") returns %ld (\"%s\")", + service, TEST_RETURN, + gai_strerror(TEST_RETURN)); + return; + } + } /* test 8, IPv4 host+service, AI_NUMERICSERV */ - #ifndef AI_NUMERICSERV - tst_resm(TFAIL, "getaddrinfo IPv4 host+service, AI_NUMERICSERV: flag " + tst_resm(TCONF, "getaddrinfo IPv4 host+service, AI_NUMERICSERV: flag " "not implemented"); #else memset(&hints, 0, sizeof(hints)); @@ -376,15 +397,18 @@ void gaiv4(void) "getaddrinfo IPv4 host+service, AI_NUMERICSERV: " "returns %ld (\"%s\") expected %d (EAI_NONAME)", TEST_RETURN, gai_strerror(TEST_RETURN), EAI_NONAME); - } else - tst_resm(TPASS, + if (!TEST_RETURN) + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv4 host+service, AI_NUMERICSERV"); + } if (!TEST_RETURN) freeaddrinfo(aires); #endif /* AI_NUMERICSERV */ /* test 9, IPv4 SOCK_STREAM/IPPROTO_UDP hints */ - memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; @@ -396,12 +420,13 @@ void gaiv4(void) tst_resm(TFAIL, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP " "hints"); freeaddrinfo(aires); - } else - tst_resm(TPASS, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP " + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP " "hints"); + } /* test 10, IPv4 socktype 0, 513 */ - memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = 0; @@ -439,20 +464,31 @@ void gaiv4(void) psin ? psin->sin_family : 0, psin ? psin->sin_port : 0, psin ? htons(psin->sin_port) : 0); - } else if (got_tcp && got_udp) - tst_resm(TPASS, "getaddrinfo IPv4 socktype 0,513"); - else + freeaddrinfo(aires); + return; + } else if (got_tcp && got_udp) { + tst_resm(TINFO, "getaddrinfo IPv4 socktype 0,513"); + freeaddrinfo(aires); + } else { tst_resm(TFAIL, "getaddrinfo IPv4 socktype 0,513 TCP %d" " UDP %d", got_tcp, got_udp); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL, - "getaddrinfo IPv4 socktype 0,513 (\"\", \"%s\") returns" - " %ld (\"%s\")", service, TEST_RETURN, - gai_strerror(TEST_RETURN)); + freeaddrinfo(aires); + return; + } + } else { + if (TEST_RETURN == EAI_BADFLAGS) { + tst_resm(TINFO, "getaddrinfo IPv4 socktype 0,513" + " (\"\", \"%s\") returns %ld (\"%s\")", service, + TEST_RETURN, gai_strerror(TEST_RETURN)); + } else { + tst_resm(TFAIL, "getaddrinfo IPv4 socktype 0,513" + " (\"\", \"%s\") returns %ld (\"%s\")", service, + TEST_RETURN, gai_strerror(TEST_RETURN)); + return; + } + } /* test 11, IPv4 AI_V4MAPPED */ - /* AI_V4MAPPED should be ignored because family != AF_INET6 */ memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; @@ -482,18 +518,25 @@ void gaiv4(void) psin ? psin->sin_family : 0, psin ? psin->sin_port : 0, psin ? htons(psin->sin_port) : 0); - } else - tst_resm(TPASS, "getaddrinfo IPv4 AI_V4MAPPED"); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 " + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv4 AI_V4MAPPED"); + freeaddrinfo(aires); + } + } else { + tst_resm(TFAIL, "getaddrinfo IPv4 " "AI_V4MAPPED (\"%s\") returns %ld (\"%s\")", hostname, TEST_RETURN, gai_strerror(TEST_RETURN)); + return; + } + + + tst_resm(TPASS, "getaddrinfo tests (v4) succeed"); } /* getaddrinfo tests (v6) */ - -void gaiv6(void) +static void gaiv6(void) { struct addrinfo *aires, hints, *pai; char hostname[MAXHOSTNAMELEN + 1]; @@ -539,13 +582,18 @@ void gaiv6(void) psin6 ? psin6->sin6_family : 0, psin6 ? psin6->sin6_port : 0, psin6 ? htons(psin6->sin6_port) : 0); - } else - tst_resm(TPASS, "getaddrinfo IPv6 basic lookup"); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 basic " + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv6 basic lookup"); + freeaddrinfo(aires); + } + } else { + tst_resm(TFAIL, "getaddrinfo IPv6 basic " "lookup (\"%s\") returns %ld (\"%s\")", hostname, TEST_RETURN, gai_strerror(TEST_RETURN)); + return; + } /* test 13, IPv6 canonical name */ memset(&hints, 0, sizeof(hints)); @@ -559,20 +607,26 @@ void gaiv6(void) if (!pai) { tst_resm(TFAIL, "getaddrinfo IPv6 canonical name: no " "entries with canonical name set"); + freeaddrinfo(aires); + return; } else if (strcasecmp(hostname, pai->ai_canonname)) { tst_resm(TFAIL, "getaddrinfo IPv6 canonical name " "(\"%s\") doesn't match hostname (\"%s\")", pai->ai_canonname, hostname); - } else - tst_resm(TPASS, "getaddrinfo IPv6 canonical name"); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 " + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv6 canonical name"); + freeaddrinfo(aires); + } + } else { + tst_resm(TFAIL, "getaddrinfo IPv6 " "canonical name (\"%s\") returns %ld (\"%s\")", shortname, TEST_RETURN, gai_strerror(TEST_RETURN)); + return; + } /* test 14, IPv6 host+service name */ - memset(&hints, 0, sizeof(hints)); /* * These are hard-coded for echo/7 to avoid using getservbyname(), @@ -607,13 +661,18 @@ void gaiv6(void) psin6 ? psin6->sin6_family : 0, psin6 ? psin6->sin6_port : 0, psin6 ? htons(psin6->sin6_port) : 0); - } else - tst_resm(TPASS, "getaddrinfo IPv6 host+service"); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 host+" + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv6 host+service"); + freeaddrinfo(aires); + } + } else { + tst_resm(TFAIL, "getaddrinfo IPv6 host+" "service returns %ld (\"%s\")", TEST_RETURN, gai_strerror(TEST_RETURN)); + return; + } /* test 15, IPv6 hostname+service, AI_PASSIVE */ memset(&hints, 0, sizeof(hints)); @@ -652,18 +711,22 @@ void gaiv6(void) psin6 ? psin6->sin6_family : 0, psin6 ? psin6->sin6_port : 0, psin6 ? htons(psin6->sin6_port) : 0); - } else - tst_resm(TPASS, + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv6 host+service PASSIVE"); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 host+" + freeaddrinfo(aires); + } + } else { + tst_resm(TFAIL, "getaddrinfo IPv6 host+" "service, PASSIVE (\"%s\", \"%s\") returns %ld (\"%s\")", hostname, service, TEST_RETURN, gai_strerror(TEST_RETURN)); + return; + } /* test 16, IPv6 host+service w/ AI_NUMERICHOST */ - memset(&hints, 0, sizeof(hints)); strcpy(service, "echo"); servnum = 7; @@ -674,8 +737,11 @@ void gaiv6(void) tst_resm(TFAIL, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname: " "returns %ld expected %d (EAI_NONAME)", TEST_RETURN, EAI_NONAME); + if (!TEST_RETURN) + freeaddrinfo(aires); + return; } else - tst_resm(TPASS, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname"); + tst_resm(TINFO, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname"); if (!TEST_RETURN) freeaddrinfo(aires); @@ -715,17 +781,26 @@ void gaiv6(void) psin6 ? psin6->sin6_family : 0, psin6 ? psin6->sin6_port : 0, psin6 ? htons(psin6->sin6_port) : 0); - } else - tst_resm(TPASS, "getaddrinfo IPv6 0+service, PASSIVE"); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL, - "getaddrinfo IPv6 0+service, PASSIVE (\"\", \"%s\") " - "returns %ld (\"%s\")", service, TEST_RETURN, - gai_strerror(TEST_RETURN)); + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv6 0+service, PASSIVE"); + freeaddrinfo(aires); + } + } else { + if (TEST_RETURN == EAI_BADFLAGS) { + tst_resm(TINFO, "getaddrinfo IPv6 0+service, PASSIVE" + " (\"\", \"%s\") returns %ld (\"%s\")", service, + TEST_RETURN, gai_strerror(TEST_RETURN)); + } else { + tst_resm(TFAIL, "getaddrinfo IPv6 0+service, PASSIVE" + " (\"\", \"%s\") returns %ld (\"%s\")", service, + TEST_RETURN, gai_strerror(TEST_RETURN)); + return; + } + } /* test 18, IPv6 0+service */ - memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET6; hints.ai_socktype = SOCK_STREAM; @@ -760,19 +835,28 @@ void gaiv6(void) psin6 ? psin6->sin6_family : 0, psin6 ? psin6->sin6_port : 0, psin6 ? htons(psin6->sin6_port) : 0); - } else - tst_resm(TPASS, "getaddrinfo IPv6 0+service"); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL, - "getaddrinfo IPv6 0+service (\"\", \"%s\") returns %ld " - "(\"%s\")", service, TEST_RETURN, - gai_strerror(TEST_RETURN)); + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv6 0+service"); + freeaddrinfo(aires); + } + } else { + if (TEST_RETURN == EAI_BADFLAGS) { + tst_resm(TINFO, "getaddrinfo IPv6 0+service" + " (\"\", \"%s\") returns %ld (\"%s\")", service, + TEST_RETURN, gai_strerror(TEST_RETURN)); + } else { + tst_resm(TFAIL, "getaddrinfo IPv6 0+service" + " (\"\", \"%s\") returns %ld (\"%s\")", service, + TEST_RETURN, gai_strerror(TEST_RETURN)); + return; + } + } /* test 19, IPv6 host+service, AI_NUMERICSERV */ - #ifndef AI_NUMERICSERV - tst_resm(TFAIL, "getaddrinfo IPv6 host+service, AI_NUMERICSERV: flag " + tst_resm(TCONF, "getaddrinfo IPv6 host+service, AI_NUMERICSERV: flag " "not implemented"); #else memset(&hints, 0, sizeof(hints)); @@ -786,15 +870,17 @@ void gaiv6(void) "getaddrinfo IPv6 host+service, AI_NUMERICSERV: " "returns %ld (\"%s\") expected %d (EAI_NONAME)", TEST_RETURN, gai_strerror(TEST_RETURN), EAI_NONAME); + if (!TEST_RETURN) + freeaddrinfo(aires); + return; } else - tst_resm(TPASS, + tst_resm(TINFO, "getaddrinfo IPv6 host+service, AI_NUMERICSERV"); if (!TEST_RETURN) freeaddrinfo(aires); #endif /* AI_NUMERICSERV */ /* test 20, IPv6 SOCK_STREAM/IPPROTO_UDP hints */ - memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET6; hints.ai_socktype = SOCK_STREAM; @@ -806,12 +892,13 @@ void gaiv6(void) tst_resm(TFAIL, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP " "hints"); freeaddrinfo(aires); - } else - tst_resm(TPASS, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP " + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP " "hints"); + } /* test 21, IPv6 socktype 0, 513 */ - memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET6; hints.ai_socktype = 0; @@ -850,20 +937,31 @@ void gaiv6(void) psin6 ? psin6->sin6_family : 0, psin6 ? psin6->sin6_port : 0, psin6 ? htons(psin6->sin6_port) : 0); - } else if (got_tcp && got_udp) - tst_resm(TPASS, "getaddrinfo IPv6 socktype 0,513"); - else + freeaddrinfo(aires); + return; + } else if (got_tcp && got_udp) { + tst_resm(TINFO, "getaddrinfo IPv6 socktype 0,513"); + freeaddrinfo(aires); + } else { tst_resm(TFAIL, "getaddrinfo IPv6 socktype 0,513 TCP %d" " UDP %d", got_tcp, got_udp); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN == EAI_BADFLAGS ? TPASS : TFAIL, - "getaddrinfo IPv6 socktype 0,513 (\"\", \"%s\") returns" - " %ld (\"%s\")", service, TEST_RETURN, - gai_strerror(TEST_RETURN)); + freeaddrinfo(aires); + return; + } + } else { + if (TEST_RETURN == EAI_BADFLAGS) { + tst_resm(TINFO, "getaddrinfo IPv6 socktype 0,513" + " (\"\", \"%s\") returns %ld (\"%s\")", service, + TEST_RETURN, gai_strerror(TEST_RETURN)); + } else { + tst_resm(TFAIL, "getaddrinfo IPv6 socktype 0,513" + " (\"\", \"%s\") returns %ld (\"%s\")", service, + TEST_RETURN, gai_strerror(TEST_RETURN)); + return; + } + } /* test 22, IPv6 AI_V4MAPPED */ - memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET6; hints.ai_flags = AI_V4MAPPED; @@ -892,57 +990,18 @@ void gaiv6(void) psin6 ? psin6->sin6_family : 0, psin6 ? psin6->sin6_port : 0, psin6 ? htons(psin6->sin6_port) : 0); - } else - tst_resm(TPASS, "getaddrinfo IPv6 AI_V4MAPPED"); - freeaddrinfo(aires); - } else - tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 " + freeaddrinfo(aires); + return; + } else { + tst_resm(TINFO, "getaddrinfo IPv6 AI_V4MAPPED"); + freeaddrinfo(aires); + } + } else { + tst_resm(TFAIL, "getaddrinfo IPv6 " "AI_V4MAPPED (\"%s\") returns %ld (\"%s\")", hostname, TEST_RETURN, gai_strerror(TEST_RETURN)); -} - -/* this prints an addrinfo list; useful for debugging */ -void dumpres(struct addrinfo *pai) -{ - int count = 1; - for (; pai; pai = pai->ai_next, count++) { - printf("result %d [0x%p]\n", count, pai); - printf("\tai_flags %x\n", pai->ai_flags); - printf("\tai_family %d\n", pai->ai_family); - printf("\tai_socktype %d\n", pai->ai_socktype); - printf("\tai_protocol %d\n", pai->ai_protocol); - printf("\tai_addrlen %d\n", pai->ai_addrlen); - printf("\tai_canonname \"%s\"\n", pai->ai_canonname); - printf("\tai_addr.sa_family %x\n", pai->ai_addr->sa_family); - if (pai->ai_addr->sa_family == AF_INET) { - char buf[1024]; - struct sockaddr_in *psin = - (struct sockaddr_in *)pai->ai_addr; - - if (!inet_ntop(AF_INET, &psin->sin_addr, buf, - sizeof(buf))) - buf[0] = '\0'; - printf("\tai_addr.sin_addr \"%s\"\n", buf); - } else if (pai->ai_addr->sa_family == AF_INET6) { - char buf[1024]; - - struct sockaddr_in6 *psin6 = - (struct sockaddr_in6 *)pai->ai_addr; - if (!inet_ntop(AF_INET6, &psin6->sin6_addr, buf, - sizeof(buf))) - buf[0] = '\0'; - printf("\tai_addr.sin6_addr \"%s\"\n", buf); - - } - printf("\tai_next %p\n", pai->ai_next); + return; } -} -void setup(void) -{ - TEST_PAUSE; /* if -P option specified */ -} - -void cleanup(void) -{ + tst_resm(TPASS, "getaddrinfo tests (v6) succeed"); } -- 1.9.3 |
From: Zeng L. <zen...@cn...> - 2015-08-31 10:15:44
|
Signed-off-by: Zeng Linggang <zen...@cn...> Signed-off-by: Alexey Kodanev <ale...@or...> Signed-off-by: Cyril Hrubis <ch...@su...> --- runtest/ipv6_lib | 4 - testcases/network/.gitignore | 4 - testcases/network/lib6/Makefile | 4 - testcases/network/lib6/asapi_01.c | 251 ---------------------------- testcases/network/lib6/asapi_02.c | 338 -------------------------------------- testcases/network/lib6/asapi_03.c | 234 -------------------------- testcases/network/lib6/asapi_05.c | 119 +------------- testcases/network/lib6/asapi_07.c | 144 ---------------- testcases/network/lib6/runcc.c | 209 ----------------------- testcases/network/lib6/runcc.h | 30 ---- 10 files changed, 1 insertion(+), 1336 deletions(-) delete mode 100644 testcases/network/lib6/asapi_01.c delete mode 100644 testcases/network/lib6/asapi_02.c delete mode 100644 testcases/network/lib6/asapi_03.c delete mode 100644 testcases/network/lib6/asapi_07.c delete mode 100644 testcases/network/lib6/runcc.c delete mode 100644 testcases/network/lib6/runcc.h diff --git a/runtest/ipv6_lib b/runtest/ipv6_lib index 75614fb..203e275 100644 --- a/runtest/ipv6_lib +++ b/runtest/ipv6_lib @@ -2,10 +2,6 @@ in6_01 in6_01 in6_02 in6_02 getaddrinfo_01 getaddrinfo_01 -asapi_01 asapi_01 -asapi_02 asapi_02 -asapi_03 asapi_03 asapi_04 asapi_04 asapi_05 asapi_05 asapi_06 asapi_06 -asapi_07 asapi_07 diff --git a/testcases/network/.gitignore b/testcases/network/.gitignore index aa6d4da..18b0203 100644 --- a/testcases/network/.gitignore +++ b/testcases/network/.gitignore @@ -1,13 +1,9 @@ /can/filter-tests/can_filter /can/filter-tests/can_rcv_own_msgs /datafiles/ -/lib6/asapi_01 -/lib6/asapi_02 -/lib6/asapi_03 /lib6/asapi_04 /lib6/asapi_05 /lib6/asapi_06 -/lib6/asapi_07 /lib6/getaddrinfo_01 /lib6/in6_01 /lib6/in6_02 diff --git a/testcases/network/lib6/Makefile b/testcases/network/lib6/Makefile index e337938..e9fde3b 100644 --- a/testcases/network/lib6/Makefile +++ b/testcases/network/lib6/Makefile @@ -31,8 +31,4 @@ LDLIBS += -lpthread CLEAN_TARGETS += $(LIB) -FILTER_OUT_MAKE_TARGETS := runcc - include $(top_srcdir)/include/mk/generic_leaf_target.mk - -$(MAKE_TARGETS): %: %.o runcc.o diff --git a/testcases/network/lib6/asapi_01.c b/testcases/network/lib6/asapi_01.c deleted file mode 100644 index 5d8bdc7..0000000 --- a/testcases/network/lib6/asapi_01.c +++ /dev/null @@ -1,251 +0,0 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * Author: David L Stevens - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* - * Description: - * These tests are for the "Advanced Sockets API" (RFC 3542) - * Verify that in6 and sockaddr fields are present. - */ - -#include <stdio.h> -#include <unistd.h> -#include <errno.h> - -#include <sys/wait.h> - -#include <netinet/ip6.h> - -#include "test.h" -#include "runcc.h" - -enum ttype { EXISTS, ALIAS, VALUE }; - -static struct ftent { - char *ft_tname; /* test name */ - int ft_type; /* test type */ - char *ft_incl; /* include file list */ - char *ft_struct; /* structure name */ - char *ft_field; /* field name */ - char *ft_offset; /* field offset */ - union { - char *fu_value; /* field size or value */ - char *fu_dname; /* #define name */ - } ftun; -#define ft_value ftun.fu_value -#define ft_dname ftun.fu_dname -} ftab[] = { - /* section 2.1 structure & field definitions */ - { "ip6_hdr un1_flow", EXISTS, IP6_H, "ip6_hdr", - "ip6_ctlun.ip6_un1.ip6_un1_flow", "0", {"4"} }, - { "ip6_hdr ip6_flow", ALIAS, IP6_H, "ip6_hdr", - "ip6_ctlun.ip6_un1.ip6_un1_flow", NULL, {"ip6_flow"} }, - { "ip6_hdr un1_plen", EXISTS, IP6_H, "ip6_hdr", - "ip6_ctlun.ip6_un1.ip6_un1_plen", "4", {"2"} }, - { "ip6_hdr ip6_plen", ALIAS, IP6_H, "ip6_hdr", - "ip6_ctlun.ip6_un1.ip6_un1_plen", "4", {"ip6_plen"} }, - { "ip6_hdr un1_nxt", EXISTS, IP6_H, "ip6_hdr", - "ip6_ctlun.ip6_un1.ip6_un1_nxt", "6", {"1"} }, - { "ip6_hdr ip6_nxt", ALIAS, IP6_H, "ip6_hdr", - "ip6_ctlun.ip6_un1.ip6_un1_nxt", NULL, {"ip6_nxt"} }, - { "ip6_hdr un1_hlim", EXISTS, IP6_H, "ip6_hdr", - "ip6_ctlun.ip6_un1.ip6_un1_hlim", "7", {"1"} }, - { "ip6_hdr ip6_hlim", ALIAS, IP6_H, "ip6_hdr", - "ip6_ctlun.ip6_un1.ip6_un1_hlim", NULL, {"ip6_hlim"} }, - { "ip6_hdr un1_vfc", EXISTS, IP6_H, "ip6_hdr", - "ip6_ctlun.ip6_un2_vfc", "0", {"1"} }, - { "ip6_hdr ip6_src", EXISTS, IP6_H, "ip6_hdr", - "ip6_src", "sizeof(struct ip6_hdrctl)", - {"sizeof(struct in6_addr)"} }, - { "ip6_hdr ip6_dst", EXISTS, IP6_H, "ip6_hdr", "ip6_dst", - "(sizeof(struct ip6_hdrctl)+sizeof(struct in6_addr))", - {"sizeof(struct in6_addr)"} }, - /* section 2.2 structure and field definitions */ - { "IPPROTO_HOPOPTS", VALUE, IN_H, "IPPROTO_HOPOPTS", - NULL, NULL, {"0"} }, - { "IPPROTO_IPV6", VALUE, IN_H, "IPPROTO_IPV6", - NULL, NULL, {"41"} }, - { "IPPROTO_ROUTING", VALUE, IN_H, "IPPROTO_ROUTING", - NULL, NULL, {"43"} }, - { "IPPROTO_FRAGMENT", VALUE, IN_H, "IPPROTO_FRAGMENT", - NULL, NULL, {"44"} }, - { "IPPROTO_ESP", VALUE, IN_H, "IPPROTO_ESP", - NULL, NULL, {"50"} }, - { "IPPROTO_AH", VALUE, IN_H, "IPPROTO_AH", - NULL, NULL, {"51"} }, - { "IPPROTO_ICMPV6", VALUE, IN_H, "IPPROTO_ICMPV6", - NULL, NULL, {"58"} }, - { "IPPROTO_NONE", VALUE, IN_H, "IPPROTO_NONE", - NULL, NULL, {"59"} }, - { "IPPROTO_DSTOPTS", VALUE, IN_H, "IPPROTO_DSTOPTS", - NULL, NULL, {"60"} }, - /* ip6_hbh */ - { "ip6_hbh ip6h_nxt", EXISTS, IP6_H, "ip6_hbh", - "ip6h_nxt", "0", {"1"} }, - { "ip6_hbh ip6h_nxt", EXISTS, IP6_H, "ip6_hbh", - "ip6h_len", "1", {"1"} }, - /* ip6_dest */ - { "ip6_dest ip6d_nxt", EXISTS, IP6_H, "ip6_dest", - "ip6d_nxt", "0", {"1"} }, - { "ip6_dest ip6d_nxt", EXISTS, IP6_H, "ip6_dest", - "ip6d_len", "1", {"1"} }, - /* ip6_rthdr0 */ - { "ip6_rthdr0 ip6r0_nxt", EXISTS, IP6_H, "ip6_rthdr0", - "ip6r0_nxt", "0", {"1"} }, - { "ip6_rthdr0 ip6r0_len", EXISTS, IP6_H, "ip6_rthdr0", - "ip6r0_len", "1", {"1"} }, - { "ip6_rthdr0 ip6r0_type", EXISTS, IP6_H, "ip6_rthdr0", - "ip6r0_type", "2", {"1"} }, - { "ip6_rthdr0 ip6r0_segleft", EXISTS, IP6_H, "ip6_rthdr0", - "ip6r0_segleft", "3", {"1"} }, - { "ip6_rthdr0 ip6r0_reserved", EXISTS, IP6_H, "ip6_rthdr0", - "ip6r0_reserved", "4", {"1"} }, - /* ip6_frag */ - { "ip6_frag ip6f_nxt", EXISTS, IP6_H, "ip6_frag", - "ip6f_nxt", "0", {"1"} }, - { "ip6_frag ip6f_reserved", EXISTS, IP6_H, "ip6_frag", - "ip6f_reserved", "1", {"1"} }, - { "ip6_frag ip6f_offlg", EXISTS, IP6_H, "ip6_frag", - "ip6f_offlg", "2", {"2"} }, - { "ip6_frag ip6f_ident", EXISTS, IP6_H, "ip6_frag", - "ip6f_ident", "4", {"4"} }, - { "IP6F_OFF_MASK", VALUE, IP6_H, "IP6F_OFF_MASK", - NULL, NULL, {"htons(0xfff8)"} }, - { "IP6F_RESERVED_MASK", VALUE, IP6_H, "IP6F_RESERVED_MASK", - NULL, NULL, {"htons(0x0006)"} }, - { "IP6F_MORE_FRAG", VALUE, IP6_H, "IP6F_MORE_FRAG", - NULL, NULL, {"htons(0x0001)"} }, - { "IP6OPT_TYPE", VALUE, IP6_H, "IP6OPT_TYPE(0xff)", - NULL, NULL, {"0xc0"} }, - { "IP6OPT_TYPE_SKIP", VALUE, IP6_H, "IP6OPT_TYPE_SKIP", - NULL, NULL, {"0x00"} }, - { "IP6OPT_TYPE_DISCARD", VALUE, IP6_H, "IP6OPT_TYPE_DISCARD", - NULL, NULL, {"0x40"} }, - { "IP6OPT_TYPE_FORCEICMP", VALUE, IP6_H, "IP6OPT_TYPE_FORCEICMP", - NULL, NULL, {"0x80"} }, - { "IP6OPT_TYPE_ICMP", VALUE, IP6_H, "IP6OPT_TYPE_ICMP", - NULL, NULL, {"0xc0"} }, - { "IP6OPT_TYPE_MUTABLE", VALUE, IP6_H, "IP6OPT_TYPE_MUTABLE", - NULL, NULL, {"0x20"} }, - { "IP6OPT_PAD1", VALUE, IP6_H, "IP6OPT_PAD1", - NULL, NULL, {"0x00"} }, - { "IP6OPT_PADN", VALUE, IP6_H, "IP6OPT_PADN", - NULL, NULL, {"0x01"} }, - { "IP6OPT_JUMBO", VALUE, IP6_H, "IP6OPT_JUMBO", - NULL, NULL, {"0xc2"} }, - { "IP6OPT_NSAP_ADDR", VALUE, IP6_H, "IP6OPT_NSAP_ADDR", - NULL, NULL, {"0xc3"} }, - { "IP6OPT_TUNNEL_LIMIT", VALUE, IP6_H, "IP6OPT_TUNNEL_LIMIT", - NULL, NULL, {"0x04"} }, - { "IP6OPT_ROUTER_ALERT", VALUE, IP6_H, "IP6OPT_ROUTER_ALERT", - NULL, NULL, {"0x05"} }, - /* ip6_opt_jumbo */ - { "ip6_opt_jumbo ip6oj_type", EXISTS, IP6_H, "ip6_opt_jumbo", - "ip6oj_type", "0", {"1"} }, - { "ip6_opt_jumbo ip6oj_len", EXISTS, IP6_H, "ip6_opt_jumbo", - "ip6oj_len", "1", {"1"} }, - { "ip6_opt_jumbo ip6oj_jumbo_len element", EXISTS, IP6_H, - "ip6_opt_jumbo", "ip6oj_jumbo_len[0]", "2", {"1"} }, - { "ip6_opt_jumbo ip6oj_jumbo_len array", EXISTS, IP6_H, - "ip6_opt_jumbo", "ip6oj_jumbo_len", "2", {"4"} }, - /* ip6_opt_nsap */ - { "ip6_opt_nsap ip6on_type", EXISTS, IP6_H, "ip6_opt_nsap", - "ip6on_type", "0", {"1"} }, - { "ip6_opt_nsap ip6on_len", EXISTS, IP6_H, "ip6_opt_nsap", - "ip6on_len", "1", {"1"} }, - { "ip6_opt_nsap ip6on_src_nsap_len", EXISTS, IP6_H, - "ip6_opt_nsap", "ip6on_src_nsap_len", "2", {"1"} }, - { "ip6_opt_nsap ip6on_dst_nsap_len", EXISTS, IP6_H, - "ip6_opt_nsap", "ip6on_dst_nsap_len", "3", {"1"} }, - /* ip6_opt_tunnel */ - { "ip6_opt_tunnel ip6ot_type", EXISTS, IP6_H, - "ip6_opt_tunnel", "ip6ot_type", "0", {"1"} }, - { "ip6_opt_tunnel ip6ot_len", EXISTS, IP6_H, - "ip6_opt_tunnel", "ip6ot_len", "1", {"1"} }, - { "ip6_opt_tunnel ip6ot_encap_limit", EXISTS, IP6_H, - "ip6_opt_tunnel", "ip6ot_encap_limit", "2", {"1"} }, - /* ip6_opt_router */ - { "ip6_opt_router ip6or_type", EXISTS, IP6_H, - "ip6_opt_router", "ip6or_type", "0", {"1"} }, - { "ip6_opt_router ip6or_len", EXISTS, IP6_H, - "ip6_opt_router", "ip6or_len", "1", {"1"} }, - { "ip6_opt_router ip6or_value element", EXISTS, IP6_H, - "ip6_opt_router", "ip6or_value[0]", "2", {"1"} }, - { "ip6_opt_router ip6or_value array", EXISTS, IP6_H, - "ip6_opt_router", "ip6or_value", "2", {"2"} }, - /* IP6_ALERT_* definitions */ - { "IP6_ALERT_MLD", VALUE, IP6_H, "IP6_ALERT_MLD", - NULL, NULL, {"0"} }, - { "IP6_ALERT_RSVP", VALUE, IP6_H, "IP6_ALERT_RSVP", - NULL, NULL, {"htons(1)"} }, - { "IP6_ALERT_AN", VALUE, IP6_H, "IP6_ALERT_AN", - NULL, NULL, {"htons(2)"} }, -}; - -static void setup(void); -static void do_test(const struct ftent *); - -char *TCID = "asapi_01"; -int TST_TOTAL = ARRAY_SIZE(ftab); - -int main(int argc, char *argv[]) -{ - int i, lc; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); ++lc) { - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) - do_test(&ftab[i]); - } - - tst_exit(); -} - -void setup(void) -{ - TEST_PAUSE; -} - -void do_test(const struct ftent *ftptr) -{ - switch (ftptr->ft_type) { - case EXISTS: - structcheck(ftptr->ft_tname, ftptr->ft_incl, - ftptr->ft_struct, ftptr->ft_field, - ftptr->ft_offset, ftptr->ft_value); - break; - case ALIAS: - aliascheck(ftptr->ft_tname, ftptr->ft_incl, - ftptr->ft_struct, ftptr->ft_field, - ftptr->ft_dname); - break; - case VALUE: - valuecheck(ftptr->ft_tname, ftptr->ft_incl, - ftptr->ft_struct, ftptr->ft_dname); - break; - default: - tst_resm(TBROK, "invalid type %d", - ftptr->ft_type); - break; - } -} diff --git a/testcases/network/lib6/asapi_02.c b/testcases/network/lib6/asapi_02.c deleted file mode 100644 index 01bee37..0000000 --- a/testcases/network/lib6/asapi_02.c +++ /dev/null @@ -1,338 +0,0 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * Author: David L Stevens - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* - * Description: - * These tests are for the "Advanced Sockets API" (RFC 3542) - * Verify that in6 and sockaddr fields are present. - */ - -#include <stdio.h> -#include <unistd.h> -#include <errno.h> - -#include <sys/wait.h> - -#include <netinet/ip6.h> - -#include "test.h" -#include "runcc.h" - -enum ttype { EXISTS, ALIAS, VALUE }; - -static struct ftent { - char *ft_tname; /* test name */ - int ft_type; /* test type */ - char *ft_incl; /* include file list */ - char *ft_struct; /* structure name */ - char *ft_field; /* field name */ - char *ft_offset; /* field offset */ - union { - char *fu_value; /* field size or value */ - char *fu_dname; /* #define name */ - } ftun; -#define ft_value ftun.fu_value -#define ft_dname ftun.fu_dname -} ftab[] = { - /* Section 2.2, icmp6_hdr & defines */ - { "icmp6_hdr icmp6_type", EXISTS, ICMP6_H, "icmp6_hdr", - "icmp6_type", "0", {"1"} }, - { "icmp6_hdr icmp6_code", EXISTS, ICMP6_H, "icmp6_hdr", - "icmp6_code", "1", {"1"} }, - { "icmp6_hdr icmp6_cksum", EXISTS, ICMP6_H, "icmp6_hdr", - "icmp6_cksum", "2", {"2"} }, - { "icmp6_hdr icmp6_un_data32 element", EXISTS, ICMP6_H, - "icmp6_hdr", "icmp6_dataun.icmp6_un_data32[0]", "4", {"4"} }, - { "icmp6_hdr icmp6_un_data32 array", EXISTS, ICMP6_H, - "icmp6_hdr", "icmp6_dataun.icmp6_un_data32", "4", {"4"} }, - { "icmp6_hdr icmp6_un_data16 element", EXISTS, ICMP6_H, - "icmp6_hdr", "icmp6_dataun.icmp6_un_data16[0]", "4", {"2"} }, - { "icmp6_hdr icmp6_un_data16 array", EXISTS, ICMP6_H, - "icmp6_hdr", "icmp6_dataun.icmp6_un_data16", "4", {"4"} }, - { "icmp6_hdr icmp6_un_data8 element", EXISTS, ICMP6_H, - "icmp6_hdr", "icmp6_dataun.icmp6_un_data8[0]", "4", {"1"} }, - { "icmp6_hdr icmp6_un_data8 array", EXISTS, ICMP6_H, - "icmp6_hdr", "icmp6_dataun.icmp6_un_data8", "4", {"4"} }, - /* icmp6_hdr definitions */ - { "icmp6_hdr icmp6_data32 define", ALIAS, ICMP6_H, "icmp6_hdr", - "icmp6_dataun.icmp6_un_data32", NULL, {"icmp6_data32"} }, - { "icmp6_hdr icmp6_data16 define", ALIAS, ICMP6_H, "icmp6_hdr", - "icmp6_dataun.icmp6_un_data16", NULL, {"icmp6_data16"} }, - { "icmp6_hdr icmp6_data8 define", ALIAS, ICMP6_H, "icmp6_hdr", - "icmp6_dataun.icmp6_un_data8", NULL, {"icmp6_data8"} }, - { "icmp6_hdr icmp6_pptr define", ALIAS, ICMP6_H, "icmp6_hdr", - "icmp6_dataun.icmp6_un_data32[0]", NULL, {"icmp6_pptr"} }, - { "icmp6_hdr icmp6_mtu define", ALIAS, ICMP6_H, "icmp6_hdr", - "icmp6_dataun.icmp6_un_data32[0]", NULL, {"icmp6_mtu"} }, - { "icmp6_hdr icmp6_id define", ALIAS, ICMP6_H, "icmp6_hdr", - "icmp6_dataun.icmp6_un_data16[0]", NULL, {"icmp6_id"} }, - { "icmp6_hdr icmp6_seq define", ALIAS, ICMP6_H, "icmp6_hdr", - "icmp6_dataun.icmp6_un_data16[1]", NULL, {"icmp6_seq"} }, - { "icmp6_hdr icmp6_maxdelay define", ALIAS, ICMP6_H, "icmp6_hdr", - "icmp6_dataun.icmp6_un_data16[0]", NULL, {"icmp6_maxdelay"} }, - /* Section 2.2.1 ICMPv6 Type and Code Values */ - { "ICMP6_DST_UNREACH", VALUE, ICMP6_H, "ICMP6_DST_UNREACH", - NULL, NULL, {"1"} }, - { "ICMP6_PACKET_TOO_BIG", VALUE, ICMP6_H, "ICMP6_PACKET_TOO_BIG", - NULL, NULL, {"2"} }, - { "ICMP6_TIME_EXCEEDED", VALUE, ICMP6_H, "ICMP6_TIME_EXCEEDED", - NULL, NULL, {"3"} }, - { "ICMP6_PARAM_PROB", VALUE, ICMP6_H, "ICMP6_PARAM_PROB", - NULL, NULL, {"4"} }, - { "ICMP6_INFOMSG_MASK", VALUE, ICMP6_H, "ICMP6_INFOMSG_MASK", - NULL, NULL, {"0x80"} }, - { "ICMP6_ECHO_REQUEST", VALUE, ICMP6_H, "ICMP6_ECHO_REQUEST", - NULL, NULL, {"128"} }, - { "ICMP6_ECHO_REPLY", VALUE, ICMP6_H, "ICMP6_ECHO_REPLY", - NULL, NULL, {"129"} }, - { "ICMP6_DST_UNREACH_NOROUTE", VALUE, ICMP6_H, - "ICMP6_DST_UNREACH_NOROUTE", NULL, NULL, {"0"} }, - { "ICMP6_DST_UNREACH_ADMIN", VALUE, ICMP6_H, - "ICMP6_DST_UNREACH_ADMIN", NULL, NULL, {"1"} }, - { "ICMP6_DST_UNREACH_BEYONDSCOPE", VALUE, ICMP6_H, - "ICMP6_DST_UNREACH_BEYONDSCOPE", NULL, NULL, {"2"} }, - { "ICMP6_DST_UNREACH_ADDR", VALUE, ICMP6_H, - "ICMP6_DST_UNREACH_ADDR", NULL, NULL, {"3"} }, - { "ICMP6_DST_UNREACH_NOPORT", VALUE, ICMP6_H, - "ICMP6_DST_UNREACH_NOPORT", NULL, NULL, {"4"} }, - { "ICMP6_TIME_EXCEED_TRANSIT", VALUE, ICMP6_H, - "ICMP6_TIME_EXCEED_TRANSIT", NULL, NULL, {"0"} }, - { "ICMP6_TIME_EXCEED_REASSEMBLY", VALUE, ICMP6_H, - "ICMP6_TIME_EXCEED_REASSEMBLY", NULL, NULL, {"1"} }, - { "ICMP6_PARAMPROB_HEADER", VALUE, ICMP6_H, - "ICMP6_PARAMPROB_HEADER", NULL, NULL, {"0"} }, - { "ICMP6_PARAMPROB_NEXTHEADER", VALUE, ICMP6_H, - "ICMP6_PARAMPROB_NEXTHEADER", NULL, NULL, {"1"} }, - { "ICMP6_PARAMPROB_OPTION", VALUE, ICMP6_H, - "ICMP6_PARAMPROB_OPTION", NULL, NULL, {"2"} }, - /* section 2.2.2, Neighbor Discovery */ - { "ND_ROUTER_SOLICIT", VALUE, ICMP6_H, - "ND_ROUTER_SOLICIT", NULL, NULL, {"133"} }, - { "ND_ROUTER_ADVERT", VALUE, ICMP6_H, - "ND_ROUTER_ADVERT", NULL, NULL, {"134"} }, - { "ND_NEIGHBOR_SOLICIT", VALUE, ICMP6_H, - "ND_NEIGHBOR_SOLICIT", NULL, NULL, {"135"} }, - { "ND_NEIGHBOR_ADVERT", VALUE, ICMP6_H, - "ND_NEIGHBOR_ADVERT", NULL, NULL, {"136"} }, - { "ND_REDIRECT", VALUE, ICMP6_H, - "ND_REDIRECT", NULL, NULL, {"137"} }, - { "nd_router_solicit nd_rs_hdr", EXISTS, ICMP6_H, - "nd_router_solicit", "nd_rs_hdr", "0", - {"sizeof(struct icmp6_hdr)"} }, - { "nd_router_solicit nd_rs_type define", ALIAS, ICMP6_H, - "nd_router_solicit", "nd_rs_hdr.icmp6_type", - NULL, {"nd_rs_type"} }, - { "nd_router_solicit nd_rs_code define", ALIAS, ICMP6_H, - "nd_router_solicit", "nd_rs_hdr.icmp6_code", - NULL, {"nd_rs_code"} }, - { "nd_router_solicit nd_rs_cksum define", ALIAS, ICMP6_H, - "nd_router_solicit", "nd_rs_hdr.icmp6_cksum", - NULL, {"nd_rs_cksum"} }, - { "nd_router_solicit nd_rs_reserved define", ALIAS, ICMP6_H, - "nd_router_solicit", "nd_rs_hdr.icmp6_data32[0]", - NULL, {"nd_rs_reserved"} }, - { "nd_router_advert nd_ra_hdr", EXISTS, ICMP6_H, - "nd_router_advert", "nd_ra_hdr", "0", - {"sizeof(struct icmp6_hdr)"} }, - { "nd_router_advert nd_ra_reachable", EXISTS, ICMP6_H, - "nd_router_advert", "nd_ra_reachable", - "sizeof(struct icmp6_hdr)", {"4"} }, - { "nd_router_advert nd_ra_retransmit", EXISTS, ICMP6_H, - "nd_router_advert", "nd_ra_retransmit", - "sizeof(struct icmp6_hdr)+4", {"4"} }, - { "nd_router_advert nd_ra_type define", ALIAS, ICMP6_H, - "nd_router_advert", "nd_ra_hdr.icmp6_type", - NULL, {"nd_ra_type"} }, - { "nd_router_advert nd_ra_code define", ALIAS, ICMP6_H, - "nd_router_advert", "nd_ra_hdr.icmp6_code", - NULL, {"nd_ra_code"} }, - { "nd_router_advert nd_ra_cksum define", ALIAS, ICMP6_H, - "nd_router_advert", "nd_ra_hdr.icmp6_cksum", - NULL, {"nd_ra_cksum"} }, - { "nd_router_advert nd_ra_curhoplimit define", ALIAS, ICMP6_H, - "nd_router_advert", "nd_ra_hdr.icmp6_data8[0]", - NULL, {"nd_ra_curhoplimit"} }, - { "nd_router_advert nd_ra_flags_reserved define", ALIAS, ICMP6_H, - "nd_router_advert", "nd_ra_hdr.icmp6_data8[1]", - NULL, {"nd_ra_flags_reserved"} }, - { "ND_RA_FLAG_MANAGED", VALUE, ICMP6_H, - "ND_RA_FLAG_MANAGED", NULL, NULL, {"0x80"} }, - { "ND_RA_FLAG_OTHER", VALUE, ICMP6_H, - "ND_RA_FLAG_OTHER", NULL, NULL, {"0x40"} }, - { "nd_router_advert nd_ra_router_lifetime define", ALIAS, ICMP6_H, - "nd_router_advert", "nd_ra_hdr.icmp6_data16[1]", - NULL, {"nd_ra_router_lifetime"} }, - { "nd_neighbor_solicit nd_ns_hdr", EXISTS, ICMP6_H, - "nd_neighbor_solicit", "nd_ns_hdr", - "0", {"sizeof(struct icmp6_hdr)"} }, - { "nd_neighbor_solicit nd_ns_target", EXISTS, ICMP6_H, - "nd_neighbor_solicit", "nd_ns_target", - "sizeof(struct icmp6_hdr)", {"sizeof(struct in6_addr)"} }, - { "nd_neighbor_solicit nd_ns_type define", ALIAS, ICMP6_H, - "nd_neighbor_solicit", "nd_ns_hdr.icmp6_type", - NULL, {"nd_ns_type"} }, - { "nd_neighbor_solicit nd_ns_code define", ALIAS, ICMP6_H, - "nd_neighbor_solicit", "nd_ns_hdr.icmp6_code", - NULL, {"nd_ns_code"} }, - { "nd_neighbor_solicit nd_ns_cksum define", ALIAS, ICMP6_H, - "nd_neighbor_solicit", "nd_ns_hdr.icmp6_cksum", - NULL, {"nd_ns_cksum"} }, - { "nd_neighbor_solicit nd_ns_reserved define", ALIAS, ICMP6_H, - "nd_neighbor_solicit", "nd_ns_hdr.icmp6_data32[0]", - NULL, {"nd_ns_reserved"} }, - { "nd_neighbor_advert nd_na_hdr", EXISTS, ICMP6_H, - "nd_neighbor_advert", "nd_na_hdr", - "0", {"sizeof(struct icmp6_hdr)"} }, - { "nd_neighbor_advert nd_na_target", EXISTS, ICMP6_H, - "nd_neighbor_advert", "nd_na_target", - "sizeof(struct icmp6_hdr)", {"sizeof(struct in6_addr)"} }, - { "nd_neighbor_advert nd_na_type define", ALIAS, ICMP6_H, - "nd_neighbor_advert", "nd_na_hdr.icmp6_type", - NULL, {"nd_na_type"} }, - { "nd_neighbor_advert nd_na_code define", ALIAS, ICMP6_H, - "nd_neighbor_advert", "nd_na_hdr.icmp6_code", - NULL, {"nd_na_code"} }, - { "nd_neighbor_advert nd_na_cksum define", ALIAS, ICMP6_H, - "nd_neighbor_advert", "nd_na_hdr.icmp6_cksum", - NULL, {"nd_na_cksum"} }, - { "nd_neighbor_advert nd_na_flags_reserved define", ALIAS, - ICMP6_H, "nd_neighbor_advert", "nd_na_hdr.icmp6_data32[0]", - NULL, {"nd_na_flags_reserved"} }, - { "ND_NA_FLAG_ROUTER", VALUE, ICMP6_H, "ND_NA_FLAG_ROUTER", - NULL, NULL, {"htonl(0x80000000)"} }, - { "ND_NA_FLAG_SOLICITED", VALUE, ICMP6_H, "ND_NA_FLAG_SOLICITED", - NULL, NULL, {"htonl(0x40000000)"} }, - { "ND_NA_FLAG_OVERRIDE", VALUE, ICMP6_H, "ND_NA_FLAG_OVERRIDE", - NULL, NULL, {"htonl(0x20000000)"} }, - { "nd_redirect nd_rd_hdr", EXISTS, ICMP6_H, "nd_redirect", - "nd_rd_hdr", "0", {"sizeof(struct icmp6_hdr)"} }, - { "nd_redirect nd_rd_target", EXISTS, ICMP6_H, - "nd_redirect", "nd_rd_target", - "sizeof(struct icmp6_hdr)", {"sizeof(struct in6_addr)"} }, - { "nd_redirect nd_rd_dst", EXISTS, ICMP6_H, "nd_redirect", - "nd_rd_dst", "sizeof(struct icmp6_hdr)+sizeof(struct in6_addr)", - {"sizeof(struct in6_addr)"} }, - { "nd_redirect nd_rd_type define", ALIAS, ICMP6_H, - "nd_neighbor_advert", "nd_na_hdr.icmp6_data32[0]", - NULL, {"nd_na_flags_reserved"} }, - { "nd_opt_hdr nd_rd_hdr", EXISTS, ICMP6_H, "nd_opt_hdr", - "nd_opt_type", "0", {"1"} }, - { "nd_opt_hdr nd_rd_hdr", EXISTS, ICMP6_H, "nd_opt_hdr", - "nd_opt_len", "1", {"1"} }, - { "ND_OPT_SOURCE_LINKADDR", VALUE, ICMP6_H, - "ND_OPT_SOURCE_LINKADDR", NULL, NULL, {"1"} }, - { "ND_OPT_TARGET_LINKADDR", VALUE, ICMP6_H, - "ND_OPT_TARGET_LINKADDR", NULL, NULL, {"2"} }, - { "ND_OPT_PREFIX_INFORMATION", VALUE, ICMP6_H, - "ND_OPT_PREFIX_INFORMATION", NULL, NULL, {"3"} }, - { "ND_OPT_REDIRECTED_HEADER", VALUE, ICMP6_H, - "ND_OPT_REDIRECTED_HEADER", NULL, NULL, {"4"} }, - { "ND_OPT_MTU", VALUE, ICMP6_H, "ND_OPT_MTU", - NULL, NULL, {"5"} }, - { "nd_opt_prefix_info nd_opt_pi_type", EXISTS, ICMP6_H, - "nd_opt_prefix_info", "nd_opt_pi_type", "0", {"1"} }, - { "nd_opt_prefix_info nd_opt_pi_len", EXISTS, ICMP6_H, - "nd_opt_prefix_info", "nd_opt_pi_len", "1", {"1"} }, - { "nd_opt_prefix_info nd_opt_pi_prefix_len", EXISTS, ICMP6_H, - "nd_opt_prefix_info", "nd_opt_pi_prefix_len", "2", {"1"} }, - { "nd_opt_prefix_info nd_opt_pi_flags_reserved", EXISTS, ICMP6_H, - "nd_opt_prefix_info", "nd_opt_pi_flags_reserved", "3", {"1"} }, - { "nd_opt_prefix_info nd_opt_pi_valid_time", EXISTS, ICMP6_H, - "nd_opt_prefix_info", "nd_opt_pi_valid_time", "4", {"4"} }, - { "nd_opt_prefix_info nd_opt_pi_preferred_time", EXISTS, ICMP6_H, - "nd_opt_prefix_info", "nd_opt_pi_preferred_time", "8", {"4"} }, - { "nd_opt_prefix_info nd_opt_pi_reserved2", EXISTS, ICMP6_H, - "nd_opt_prefix_info", "nd_opt_pi_reserved2", "12", {"4"} }, - { "nd_opt_prefix_info nd_opt_pi_prefix", EXISTS, ICMP6_H, - "nd_opt_prefix_info", "nd_opt_pi_prefix", - "16", {"sizeof(struct in6_addr)"} }, - { "ND_OPT_PI_FLAG_ONLINK", VALUE, ICMP6_H, - "ND_OPT_PI_FLAG_ONLINK", NULL, NULL, {"0x80"} }, - { "ND_OPT_PI_FLAG_AUTO", VALUE, ICMP6_H, - "ND_OPT_PI_FLAG_AUTO", NULL, NULL, {"0x40"} }, - { "nd_opt_rd_hdr nd_opt_rh_type", EXISTS, ICMP6_H, - "nd_opt_rd_hdr", "nd_opt_rh_type", "0", {"1"} }, - { "nd_opt_rd_hdr nd_opt_rh_len", EXISTS, ICMP6_H, - "nd_opt_rd_hdr", "nd_opt_rh_len", "1", {"1"} }, - { "nd_opt_rd_hdr nd_opt_rh_reserved1", EXISTS, ICMP6_H, - "nd_opt_rd_hdr", "nd_opt_rh_reserved1", "2", {"2"} }, - { "nd_opt_rd_hdr nd_opt_rh_reserved2", EXISTS, ICMP6_H, - "nd_opt_rd_hdr", "nd_opt_rh_reserved2", "4", {"4"} }, - { "nd_opt_mtu nd_opt_mtu_type", EXISTS, ICMP6_H, - "nd_opt_mtu", "nd_opt_mtu_type", "0", {"1"} }, - { "nd_opt_mtu nd_opt_mtu_len", EXISTS, ICMP6_H, - "nd_opt_mtu", "nd_opt_mtu_len", "1", {"1"} }, - { "nd_opt_mtu nd_opt_mtu_reserved", EXISTS, ICMP6_H, - "nd_opt_mtu", "nd_opt_mtu_reserved", "2", {"2"} }, - { "nd_opt_mtu nd_opt_mtu_mtu", EXISTS, ICMP6_H, - "nd_opt_mtu", "nd_opt_mtu_mtu", "4", {"4"} }, -}; - -static void setup(void); -static void do_test(const struct ftent *); - -char *TCID = "asapi_02"; -int TST_TOTAL = ARRAY_SIZE(ftab); - -int main(int argc, char *argv[]) -{ - int i, lc; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); ++lc) { - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) - do_test(&ftab[i]); - } - - tst_exit(); -} - -void setup(void) -{ - TEST_PAUSE; -} - -void do_test(const struct ftent *ftptr) -{ - switch (ftptr->ft_type) { - case EXISTS: - structcheck(ftptr->ft_tname, ftptr->ft_incl, - ftptr->ft_struct, ftptr->ft_field, - ftptr->ft_offset, ftptr->ft_value); - break; - case ALIAS: - aliascheck(ftptr->ft_tname, ftptr->ft_incl, - ftptr->ft_struct, ftptr->ft_field, - ftptr->ft_dname); - break; - case VALUE: - valuecheck(ftptr->ft_tname, ftptr->ft_incl, - ftptr->ft_struct, ftptr->ft_dname); - break; - default: - tst_resm(TBROK, "invalid type %d", - ftptr->ft_type); - break; - } -} diff --git a/testcases/network/lib6/asapi_03.c b/testcases/network/lib6/asapi_03.c deleted file mode 100644 index f458d7d..0000000 --- a/testcases/network/lib6/asapi_03.c +++ /dev/null @@ -1,234 +0,0 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * Author: David L Stevens - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* - * Description: - * These tests are for the "Advanced Sockets API" (RFC 3542) - * Verify that in6 and sockaddr fields are present. - */ - -#include <stdio.h> -#include <unistd.h> -#include <errno.h> - -#include <sys/wait.h> - -#include <netinet/ip6.h> - -#include "test.h" -#include "runcc.h" - -enum ttype { EXISTS, ALIAS, VALUE }; - -static struct ftent { - char *ft_tname; /* test name */ - int ft_type; /* test type */ - char *ft_incl; /* include file list */ - char *ft_struct; /* structure name */ - char *ft_field; /* field name */ - char *ft_offset; /* field offset */ - union { - char *fu_value; /* field size or value */ - char *fu_dname; /* #define name */ - } ftun; -#define ft_value ftun.fu_value -#define ft_dname ftun.fu_dname -} ftab[] = { - /* section 2.2.3, MLDv1 */ - { "MLD_LISTENER_QUERY", VALUE, ICMP6_H, - "MLD_LISTENER_QUERY", NULL, NULL, {"130"} }, - { "MLD_LISTENER_REPORT", VALUE, ICMP6_H, - "MLD_LISTENER_REPORT", NULL, NULL, {"131"} }, - { "MLD_LISTENER_REDUCTION", VALUE, ICMP6_H, - "MLD_LISTENER_REDUCTION", NULL, NULL, {"132"} }, - { "mld_hdr mld_icmp6_hdr", EXISTS, ICMP6_H, - "mld_hdr", "mld_icmp6_hdr", "0", - {"sizeof(struct icmp6_hdr)"} }, - { "mld_hdr mld_addr", EXISTS, ICMP6_H, "mld_hdr", - "mld_addr", "sizeof(struct icmp6_hdr)", - {"sizeof(struct in6_addr)"} }, - { "mld_hdr mld_type define", ALIAS, ICMP6_H, "mld_hdr", - "mld_icmp6_hdr.icmp6_type", NULL, {"mld_type"} }, - { "mld_hdr mld_code define", ALIAS, ICMP6_H, "mld_hdr", - "mld_icmp6_hdr.icmp6_code", NULL, {"mld_code"} }, - { "mld_hdr mld_cksum define", ALIAS, ICMP6_H, "mld_hdr", - "mld_icmp6_hdr.icmp6_cksum", NULL, {"mld_cksum"} }, - { "mld_hdr mld_maxdelay define", ALIAS, ICMP6_H, "mld_hdr", - "mld_icmp6_hdr.icmp6_data16[0]", NULL, {"mld_maxdelay"} }, - { "mld_hdr mld_reserved define", ALIAS, ICMP6_H, "mld_hdr", - "mld_icmp6_hdr.icmp6_data16[1]", NULL, {"mld_reserved"} }, - /* section 2.2.4, Router renumbering */ - { "ICMP6_ROUTER_RENUMBERING", VALUE, ICMP6_H, - "ICMP6_ROUTER_RENUMBERING", NULL, NULL, {"138"} }, - { "icmp6_router_renum rr_hdr", EXISTS, ICMP6_H, - "icmp6_router_renum", "rr_hdr", "0", - {"sizeof(struct icmp6_hdr)"} }, - { "icmp6_router_renum rr_segnum", EXISTS, ICMP6_H, - "icmp6_router_renum", "rr_segnum", - "sizeof(struct icmp6_hdr)", {"1"} }, - { "icmp6_router_renum rr_flags", EXISTS, ICMP6_H, - "icmp6_router_renum", "rr_flags", - "sizeof(struct icmp6_hdr)+1", {"1"} }, - { "icmp6_router_renum rr_maxdelay", EXISTS, ICMP6_H, - "icmp6_router_renum", "rr_maxdelay", - "sizeof(struct icmp6_hdr)+2", {"2"} }, - { "icmp6_router_renum rr_reserved", EXISTS, ICMP6_H, - "icmp6_router_renum", "rr_reserved", - "sizeof(struct icmp6_hdr)+4", {"4"} }, - { "icmp6_router_renum rr_type define", ALIAS, ICMP6_H, - "icmp6_router_renum", "rr_hdr.icmp6_type", - NULL, {"rr_type"} }, - { "icmp6_router_renum rr_code define", ALIAS, ICMP6_H, - "icmp6_router_renum", "rr_hdr.icmp6_code", - NULL, {"rr_code"} }, - { "icmp6_router_renum rr_cksum define", ALIAS, ICMP6_H, - "icmp6_router_renum", "rr_hdr.icmp6_cksum", - NULL, {"rr_cksum"} }, - { "icmp6_router_renum rr_seqnum define", ALIAS, ICMP6_H, - "icmp6_router_renum", "rr_hdr.icmp6_data32[0]", - NULL, {"rr_seqnum"} }, - { "ICMP6_RR_FLAGS_TEST", VALUE, ICMP6_H, - "ICMP6_RR_FLAGS_TEST", NULL, NULL, {"0x80"} }, - { "ICMP6_RR_FLAGS_REQRESULT", VALUE, ICMP6_H, - "ICMP6_RR_FLAGS_REQRESULT", NULL, NULL, {"0x40"} }, - { "ICMP6_RR_FLAGS_FORCEAPPLY", VALUE, ICMP6_H, - "ICMP6_RR_FLAGS_FORCEAPPLY", NULL, NULL, {"0x20"} }, - { "ICMP6_RR_FLAGS_SPECSITE", VALUE, ICMP6_H, - "ICMP6_RR_FLAGS_SPECSITE", NULL, NULL, {"0x10"} }, - { "ICMP6_RR_FLAGS_PREVDONE", VALUE, ICMP6_H, - "ICMP6_RR_FLAGS_PREVDONE", NULL, NULL, {"0x08"} }, - { "rr_pco_match rpm_code", EXISTS, ICMP6_H, - "rr_pco_match", "rpm_code", "0", {"1"} }, - { "rr_pco_match rpm_len", EXISTS, ICMP6_H, - "rr_pco_match", "rpm_len", "1", {"1"} }, - { "rr_pco_match rpm_ordinal", EXISTS, ICMP6_H, - "rr_pco_match", "rpm_ordinal", "2", {"1"} }, - { "rr_pco_match rpm_matchlen", EXISTS, ICMP6_H, - "rr_pco_match", "rpm_matchlen", "3", {"1"} }, - { "rr_pco_match rpm_minlen", EXISTS, ICMP6_H, - "rr_pco_match", "rpm_minlen", "4", {"1"} }, - { "rr_pco_match rpm_maxlen", EXISTS, ICMP6_H, - "rr_pco_match", "rpm_maxlen", "5", {"1"} }, - { "rr_pco_match rpm_reserved", EXISTS, ICMP6_H, - "rr_pco_match", "rpm_reserved", "6", {"2"} }, - { "rr_pco_match rpm_prefix", EXISTS, ICMP6_H, - "rr_pco_match", "rpm_prefix", "8", - {"sizeof(struct in6_addr)"} }, - { "RPM_PCO_ADD", VALUE, ICMP6_H, "RPM_PCO_ADD", - NULL, NULL, {"1"} }, - { "RPM_PCO_CHANGE", VALUE, ICMP6_H, "RPM_PCO_CHANGE", - NULL, NULL, {"2"} }, - { "RPM_PCO_SETGLOBAL", VALUE, ICMP6_H, "RPM_PCO_SETGLOBAL", - NULL, NULL, {"3"} }, - { "rr_pco_use rpu_uselen", EXISTS, ICMP6_H, "rr_pco_use", - "rpu_uselen", "0", {"1"} }, - { "rr_pco_use rpu_keeplen", EXISTS, ICMP6_H, "rr_pco_use", - "rpu_keeplen", "1", {"1"} }, - { "rr_pco_use rpu_ramask", EXISTS, ICMP6_H, "rr_pco_use", - "rpu_ramask", "2", {"1"} }, - { "rr_pco_use rpu_raflags", EXISTS, ICMP6_H, "rr_pco_use", - "rpu_raflags", "3", {"1"} }, - { "rr_pco_use rpu_vltime", EXISTS, ICMP6_H, "rr_pco_use", - "rpu_vltime", "4", {"4"} }, - { "rr_pco_use rpu_pltime", EXISTS, ICMP6_H, "rr_pco_use", - "rpu_pltime", "8", {"4"} }, - { "rr_pco_use rpu_flags", EXISTS, ICMP6_H, "rr_pco_use", - "rpu_flags", "12", {"4"} }, - { "rr_pco_use rpu_prefix", EXISTS, ICMP6_H, "rr_pco_use", - "rpu_prefix", "16", {"sizeof(struct in6_addr)"} }, - { "ICMP6_RR_PCOUSE_RAFLAGS_ONLINK", VALUE, ICMP6_H, - "ICMP6_RR_PCOUSE_RAFLAGS_ONLINK", NULL, NULL, {"0x20"} }, - { "ICMP6_RR_PCOUSE_RAFLAGS_AUTO", VALUE, ICMP6_H, - "ICMP6_RR_PCOUSE_RAFLAGS_AUTO", NULL, NULL, {"0x10"} }, - { "ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME", VALUE, ICMP6_H, - "ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME", NULL, NULL, - {"htonl(0x80000000)"} }, - { "ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME", VALUE, ICMP6_H, - "ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME", NULL, NULL, - {"htonl(0x40000000)"} }, - { "rr_result rrr_flags", EXISTS, ICMP6_H, "rr_result", - "rrr_flags", "0", {"2"} }, - { "rr_result rrr_ordinal", EXISTS, ICMP6_H, "rr_result", - "rrr_ordinal", "2", {"1"} }, - { "rr_result rrr_matchedlen", EXISTS, ICMP6_H, "rr_result", - "rrr_matchedlen", "3", {"1"} }, - { "rr_result rrr_ifid", EXISTS, ICMP6_H, "rr_result", - "rrr_ifid", "4", {"4"} }, - { "rr_result rrr_prefix", EXISTS, ICMP6_H, "rr_result", - "rrr_prefix", "8", {"sizeof(struct in6_addr)"} }, - { "ICMP6_RR_RESULT_FLAGS_OOB", VALUE, ICMP6_H, - "ICMP6_RR_RESULT_FLAGS_OOB", NULL, NULL, - {"htons(0x0002)"} }, - { "ICMP6_RR_RESULT_FLAGS_FORBIDDEN", VALUE, ICMP6_H, - "ICMP6_RR_RESULT_FLAGS_FORBIDDEN", NULL, NULL, - {"htons(0x0001)"} }, -}; - -static void setup(void); -static void do_test(const struct ftent *); - -char *TCID = "asapi_03"; -int TST_TOTAL = ARRAY_SIZE(ftab); - -int main(int argc, char *argv[]) -{ - int i, lc; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); ++lc) { - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) - do_test(&ftab[i]); - } - - tst_exit(); -} - -void setup(void) -{ - TEST_PAUSE; -} - -void do_test(const struct ftent *ftptr) -{ - switch (ftptr->ft_type) { - case EXISTS: - structcheck(ftptr->ft_tname, ftptr->ft_incl, - ftptr->ft_struct, ftptr->ft_field, - ftptr->ft_offset, ftptr->ft_value); - break; - case ALIAS: - aliascheck(ftptr->ft_tname, ftptr->ft_incl, - ftptr->ft_struct, ftptr->ft_field, - ftptr->ft_dname); - break; - case VALUE: - valuecheck(ftptr->ft_tname, ftptr->ft_incl, - ftptr->ft_struct, ftptr->ft_dname); - break; - default: - tst_resm(TBROK, "invalid type %d", - ftptr->ft_type); - break; - } -} diff --git a/testcases/network/lib6/asapi_05.c b/testcases/network/lib6/asapi_05.c index b2e7d2a..e251eee 100644 --- a/testcases/network/lib6/asapi_05.c +++ b/testcases/network/lib6/asapi_05.c @@ -47,14 +47,12 @@ #include <netinet/icmp6.h> #include "test.h" -#include "runcc.h" char *TCID = "asapi_05"; /* Test program identifier. */ void setup(void); void cleanup(void); -void icmp6_et(void); void icmp6_ft(void); int main(int argc, char *argv[]) @@ -67,7 +65,6 @@ int main(int argc, char *argv[]) setup(); for (lc = 0; TEST_LOOPING(lc); ++lc) { - icmp6_et(); icmp6_ft(); } @@ -76,120 +73,6 @@ int main(int argc, char *argv[]) tst_exit(); } -enum ttype { EXISTS, ALIAS, VALUE, DEFINED }; - -struct etent { - char *et_tname; /* test name */ - int et_type; /* test type */ - char *et_incl; /* include file list */ - char *et_struct; /* structure name */ - char *et_field; /* field name */ - char *et_offset; /* field offset */ - union { - char *fu_value; /* field size or value */ - char *fu_dname; /* #define name */ - } ftun; -#define et_value ftun.fu_value -#define et_dname ftun.fu_dname -} etab[] = { -/* existence checks, RFC 3542 section 3 */ - { - "icmp6_filter icmp6_filt", EXISTS, ICMP6_H, "icmp6_filter", - "icmp6_filt", "0", { - "32"}}, { - "icmp6_filter icmp6_filt[0]", EXISTS, ICMP6_H, "icmp6_filter", - "icmp6_filt[0]", "0", { - "4"}}, { - "ICMP6_FILTER_WILLPASS", DEFINED, ICMP6_H, - "ICMP6_FILTER_WILLPASS", NULL, NULL, { - 0}}, { - "ICMP6_FILTER_WILLBLOCK", DEFINED, ICMP6_H, - "ICMP6_FILTER_WILLBLOCK", NULL, NULL, { - 0}}, { - "ICMP6_FILTER_SETPASS", DEFINED, ICMP6_H, - "ICMP6_FILTER_SETPASS", NULL, NULL, { - 0}}, { - "ICMP6_FILTER_SETBLOCK", DEFINED, ICMP6_H, - "ICMP6_FILTER_SETBLOCK", NULL, NULL, { - 0}}, { - "ICMP6_FILTER_SETPASSALL", DEFINED, ICMP6_H, - "ICMP6_FILTER_SETPASSALL", NULL, NULL, { - 0}}, { - "ICMP6_FILTER_SETBLOCKALL", DEFINED, ICMP6_H, - "ICMP6_FILTER_SETBLOCKALL", NULL, NULL, { - 0}}, { - "ICMP6_FILTER", DEFINED, ICMP6_H, "ICMP6_FILTER", NULL, NULL, { - 0}}, -/* existence checks, RFC 3542 section 4 */ -/* socket options */ - { - "IPV6_RECVPKTINFO", VALUE, IN_H, "IPV6_RECVPKTINFO", NULL, NULL, { - "IPV6_RECVPKTINFO"}}, { - "IPV6_RECVHOPLIMIT", VALUE, IN_H, "IPV6_RECVHOPLIMIT", NULL, - NULL, { - "IPV6_RECVHOPLIMIT"}}, { - "IPV6_RECVRTHDR", VALUE, IN_H, "IPV6_RECVRTHDR", NULL, NULL, { - "IPV6_RECVRTHDR"}}, { - "IPV6_RECVHOPOPTS", VALUE, IN_H, "IPV6_RECVHOPOPTS", NULL, NULL, { - "IPV6_RECVHOPOPTS"}}, { - "IPV6_RECVDSTOPTS", VALUE, IN_H, "IPV6_RECVDSTOPTS", NULL, NULL, { - "IPV6_RECVDSTOPTS"}}, { - "IPV6_RECVTCLASS", VALUE, IN_H, "IPV6_RECVTCLASS", NULL, NULL, { - "IPV6_RECVTCLASS"}}, -/* cmsg types */ - { - "IPV6_PKTINFO", DEFINED, IN_H, "IPV6_PKTINFO", NULL, NULL, { - 0}}, { - "IPV6_HOPLIMIT", DEFINED, IN_H, "IPV6_HOPLIMIT", NULL, NULL, { - 0}}, { - "IPV6_NEXTHOP", DEFINED, IN_H, "IPV6_NEXTHOP", NULL, NULL, { - 0}}, { - "IPV6_RTHDR", DEFINED, IN_H, "IPV6_RTHDR", NULL, NULL, { - 0}}, { - "IPV6_HOPOPTS", DEFINED, IN_H, "IPV6_HOPOPTS", NULL, NULL, { - 0}}, { - "IPV6_DSTOPTS", DEFINED, IN_H, "IPV6_DSTOPTS", NULL, NULL, { - 0}}, { - "IPV6_RTHDRDSTOPTS", DEFINED, IN_H, "IPV6_RTHDRDSTOPTS", NULL, - NULL, { - 0}}, { - "IPV6_TCLASS", DEFINED, IN_H, "IPV6_TCLASS", NULL, NULL, { -0}},}; - -#define ETCOUNT (sizeof(etab)/sizeof(etab[0])) - -/* existence tests */ -void icmp6_et(void) -{ - int i; - - for (i = 0; i < ETCOUNT; ++i) { - switch (etab[i].et_type) { - case EXISTS: - structcheck(etab[i].et_tname, etab[i].et_incl, - etab[i].et_struct, etab[i].et_field, - etab[i].et_offset, etab[i].et_value); - break; - case ALIAS: - aliascheck(etab[i].et_tname, etab[i].et_incl, - etab[i].et_struct, etab[i].et_field, - etab[i].et_dname); - break; - case VALUE: - valuecheck(etab[i].et_tname, etab[i].et_incl, - etab[i].et_struct, etab[i].et_dname); - break; - case DEFINED: - funccheck(etab[i].et_tname, etab[i].et_incl, - etab[i].et_struct); - break; - default: - tst_resm(TBROK, "invalid type %d", etab[i].et_type); - break; - } - } -} - void setup(void) { TEST_PAUSE; /* if -P option specified */ @@ -414,4 +297,4 @@ void icmp6_ft(void) } } -int TST_TOTAL = ETCOUNT; +int TST_TOTAL = FTCOUNT; diff --git a/testcases/network/lib6/asapi_07.c b/testcases/network/lib6/asapi_07.c deleted file mode 100644 index 826cea6..0000000 --- a/testcases/network/lib6/asapi_07.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * Author: David L Stevens - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* - * Description: - * These tests are for the "Advanced Sockets API" (RFC 3542) - * Section 20, ancillary data macros and structure definitions - */ - -#include <stdio.h> -#include <unistd.h> -#include <errno.h> - -#include <sys/wait.h> - -#include <netinet/in.h> -#include <netinet/ip6.h> -#include <netinet/icmp6.h> - -#include "test.h" -#include "runcc.h" - -enum ttype { EXISTS, ALIAS, VALUE, DEFINED }; - -static struct etent { - char *et_tname; /* test name */ - int et_type; /* test type */ - char *et_incl; /* include file list */ - char *et_struct; /* structure name */ - char *et_field; /* field name */ - char *et_offset; /* field offset */ - union { - char *fu_value; /* field size or value */ - char *fu_dname; /* #define name */ - } ftun; -#define et_value ftun.fu_value -#define et_dname ftun.fu_dname -} etab[] = { - /* existence checks, RFC 3542 sections 5, 20 */ - { "msghdr msg_name", EXISTS, SOCKET_H, "msghdr", - "msg_name", NULL, {"sizeof(void *)"} }, - { "msghdr msg_namelen", EXISTS, SOCKET_H, "msghdr", - "msg_namelen", NULL, {"sizeof(socklen_t)"} }, - { "msghdr msg_iov", EXISTS, SOCKET_H, "msghdr", - "msg_iov", NULL, {"sizeof(struct iovec *)"} }, - { "msghdr msg_iovlen", EXISTS, SOCKET_H, "msghdr", - "msg_iovlen", NULL, {"sizeof(size_t)"} }, - { "msghdr msg_control", EXISTS, SOCKET_H, "msghdr", - "msg_control", NULL, {"sizeof(void *)"} }, - { "msghdr msg_controllen", EXISTS, SOCKET_H, "msghdr", - "msg_controllen", NULL, {"sizeof(size_t)"} }, - { "msghdr msg_flags", EXISTS, SOCKET_H, "msghdr", - "msg_flags", NULL, {"sizeof(int)"} }, - { "cmsghdr cmsg_len", EXISTS, SOCKET_H, "cmsghdr", - "cmsg_len", NULL, {"sizeof(size_t)"} }, - { "cmsghdr cmsg_level", EXISTS, SOCKET_H, "cmsghdr", - "cmsg_level", NULL, {"sizeof(int)"} }, - { "cmsghdr cmsg_type", EXISTS, SOCKET_H, "cmsghdr", - "cmsg_type", NULL, {"sizeof(int)"} }, - { "CMSG_DATA", DEFINED, SOCKET_H, "CMSG_DATA", - NULL, NULL, {0} }, - { "CMSG_NXTHDR", DEFINED, SOCKET_H, "CMSG_NXTHDR", - NULL, NULL, {0} }, - { "CMSG_FIRSTHDR", DEFINED, SOCKET_H, "CMSG_FIRSTHDR", - NULL, NULL, {0} }, - { "CMSG_SPACE", DEFINED, SOCKET_H, "CMSG_SPACE", - NULL, NULL, {0} }, - { "CMSG_LEN", DEFINED, SOCKET_H, "CMSG_LEN", - NULL, NULL, {0} }, -}; - -static void setup(void); -static void adatet(const struct etent *etptr); - -char *TCID = "asapi_07"; -int TST_TOTAL = ARRAY_SIZE(etab); - -int main(int argc, char *argv[]) -{ - int i, lc; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); ++lc) { - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) - adatet(&etab[i]); - } - - tst_exit(); -} - -void setup(void) -{ - TEST_PAUSE; -} - -/* existence tests */ -void adatet(const struct etent *etptr) -{ - switch (etptr->et_type) { - case EXISTS: - structcheck(etptr->et_tname, etptr->et_incl, - etptr->et_struct, etptr->et_field, - etptr->et_offset, etptr->et_value); - break; - case ALIAS: - aliascheck(etptr->et_tname, etptr->et_incl, - etptr->et_struct, etptr->et_field, - etptr->et_dname); - break; - case VALUE: - valuecheck(etptr->et_tname, etptr->et_incl, - etptr->et_struct, etptr->et_dname); - break; - case DEFINED: - funccheck(etptr->et_tname, etptr->et_incl, - etptr->et_struct); - break; - default: - tst_resm(TBROK, "invalid type %d", - etptr->et_type); - break; - } -} diff --git a/testcases/network/lib6/runcc.c b/testcases/network/lib6/runcc.c deleted file mode 100644 index 91a0b16..0000000 --- a/testcases/network/lib6/runcc.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - * runcc.a - common functions for lib6 testing - * - * HISTORY - * 05/2005 written by David L Stevens - * - * RESTRICTIONS: - * None. - * - */ - -#include <stdio.h> -#include <unistd.h> -#include <errno.h> -#include <ctype.h> - -#include <sys/wait.h> - -#include "test.h" - -char fieldref[1024]; -char program[8192]; - -char *filetmpl = "/tmp/%.*s_XXXXXX"; - -char cmd[1024]; - -/* - * like strspn, with ASCII, numbers and underscore only - */ -int strfpn(char *name) -{ - int i; - - for (i = 0; *name; ++name, ++i) - if (!(isalnum(*name) || *name == '_')) - break; - return i; -} - -int runcc(char *tname, char *filename0, char *program) -{ - static char filename[1024]; - int fd, es, saved_errno; - char *cflags = ""; - - fd = mkstemp(filename0); - if (fd < 0) { - perror("mkstemp"); - return -1; - } - strncpy(filename, filename0, sizeof(filename) - 1); - filename[sizeof(filename) - 1] = '\0'; - strncat(filename, ".c", sizeof(filename) - strlen(filename) - 1); - if (rename(filename0, filename) < 0) { - perror("rename"); - unlink(filename0); - return -1; - } - if (write(fd, program, strlen(program)) < 0) { - perror("write"); - unlink(filename); - return -1; - } - (void)close(fd); - - cflags = getenv("CFLAGS"); - if (cflags == NULL) { - tst_resm(TINFO, "CFLAGS not found, using default cc arch."); - cflags = ""; - } - - snprintf(cmd, sizeof(cmd), "%s %s -o %s %s > /tmp/test 2>&1", "cc", - cflags, filename0, filename); - es = system(cmd); - if (WEXITSTATUS(es) == 127) { - tst_resm(TBROK, "can't run C compiler: \"%s\"", cmd); - if (unlink(filename) < 0) - tst_resm(TWARN, "%s; unlink \"%s\" failed: %s", tname, - filename, strerror(errno)); - return -1; - } - if (unlink(filename) < 0) - tst_resm(TWARN, "%s: unlink \"%s\" failed: %s", tname, - filename, strerror(errno)); - - if (WIFSIGNALED(es) && - (WTERMSIG(es) == SIGINT || WTERMSIG(es) == SIGQUIT)) - exit(1); - - if (WEXITSTATUS(es)) { - tst_resm(TFAIL, "%s: not present", tname); - return -1; - } - /* run the test */ - - es = system(filename0); - saved_errno = errno; - if (unlink(filename0) < 0) - tst_resm(TWARN, "%s: unlink \"%s\" failed: %s", tname, - filename0, strerror(errno)); - - if (WIFSIGNALED(es) && - (WTERMSIG(es) == SIGINT || WTERMSIG(es) == SIGQUIT)) - exit(1); - - if (WEXITSTATUS(es) == 127) - tst_resm(TBROK, "%s: can't run \"%s\": %s", tname, filename0, - strerror(saved_errno)); - if (WEXITSTATUS(es)) - tst_resm(TFAIL, "%s: present, but incorrect", tname); - else - tst_resm(TPASS, "%s present and correct", tname); - return 0; -} - -char *field_fmt = "\n\texit((offsetof(struct %s, %s) != %s) || " - "sizeof(tst.%s) != (%s));\n"; -/* no offset check */ -char *field_fmt2 = "\n\texit(sizeof(tst.%s) != (%s));\n"; - -const char *stmpl = - "%s\n#ifndef offsetof\n" - "#define offsetof(dtype, dfield) ((int)&((dtype *)0)->dfield)\n" - "#endif\n\nstruct %s tst;\n\nmain(int argc, char *argv[])\n{\n\t%s\n}\n"; - -int -structcheck(char *tname, char *incl, char *structure, char *field, - char *offset, char *size) -{ - int rv; - static char filename[1024]; - - if (offset) - sprintf(fieldref, field_fmt, structure, field, offset, field, - size); - else - sprintf(fieldref, field_fmt2, field, size); - sprintf(program, stmpl, incl, structure, fieldref); - snprintf(filename, sizeof(filename), filetmpl, strfpn(structure), - structure); - rv = runcc(tname, filename, program); - return rv; -} - -char *aliasfmt = - "exit(&tst.%s != &tst.%s || sizeof(tst.%s) != sizeof(tst.%s));"; - -int -aliascheck(char *tname, char *incl, char *structure, char *field, char *dname) -{ - int rv; - static char filename[1024]; - - sprintf(fieldref, aliasfmt, field, dname, field, dname); - sprintf(program, stmpl, incl, structure, fieldref); - snprintf(filename, sizeof(filename), filetmpl, strfpn(structure), - structure); - rv = runcc(tname, filename, program); - return rv; -} - -const char *dtmpl = - "%s\n\nmain(int argc, char *argv[])\n{\n\texit((%s) != (%s));\n}\n"; - -int valuecheck(char *tname, char *incl, char *dname, char *dval) -{ - int rv; - static char filename[1024]; - - sprintf(program, dtmpl, incl, dname, dval); - snprintf(filename, sizeof(filename), filetmpl, strfpn(dname), dname); - rv = runcc(tname, filename, program); - return rv; -} - -const char *ftmpl = - "%s\n\nmain(int argc, char *argv[])\n{\n#ifdef %s\n\texit(0);\n#else\n" - "\tsyntax error;\n#endif\n}\n"; - -int funccheck(char *tname, char *incl, char *fname) -{ - int rv; - static char filename[1024]; - - sprintf(program, ftmpl, incl, fname); - snprintf(filename, sizeof(filename), filetmpl, strfpn(fname), fname); - rv = runcc(tname, filename, program); - return rv; -} diff --git a/testcases/network/lib6/runcc.h b/testcases/network/lib6/runcc.h deleted file mode 100644 index 4e2a0d5..0000000 --- a/testcases/network/lib6/runcc.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -int aliascheck(char *tname, char *incl, char *structure, char *field, - char *dname); -int funccheck(char *tname, char *incl, char *fname); -int structcheck(char *tname, char *incl, char *structure, char *field, - char *offset, char *size); -int valuecheck(char *tname, char *incl, char *dname, char *dval); - -#define IP6_H "#include <netinet/ip6.h>\n" -#define IN_H "#include <netinet/in.h>\n" -#define ICMP6_H "#include <netinet/icmp6.h>\n" -#define SOCKET_H "#include <sys/types.h>\n#include <sys/socket.h>\n" -- 1.9.3 |
From: Zeng L. <zen...@cn...> - 2015-08-31 10:15:43
|
* Add 'static' before some functions and global variables. * Use 'tst_tmpdir' and 'tst_rmdir'. * Remove useless comments. * Use SAFE_XXX(). * Remove unused variables. * Modify the format of sotab[] and cmtab[]. * Modify the initialization of sotab[]. * Some cleanup. Signed-off-by: Zeng Linggang <zen...@cn...> Signed-off-by: Alexey Kodanev <ale...@or...> Signed-off-by: Cyril Hrubis <ch...@su...> --- testcases/network/lib6/asapi_06.c | 317 +++++++++++++++----------------------- 1 file changed, 120 insertions(+), 197 deletions(-) diff --git a/testcases/network/lib6/asapi_06.c b/testcases/network/lib6/asapi_06.c index 960ebb5..204bf23 100644 --- a/testcases/network/lib6/asapi_06.c +++ b/testcases/network/lib6/asapi_06.c @@ -1,37 +1,21 @@ /* + * Copyright (c) 2015 Fujitsu Ltd. + * Copyright (c) International Business Machines Corp., 2001 * - * Copyright (c) International Business Machines Corp., 2001 + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - * Test Name: asapi_06 - * - * Test Description: - * Tests for RFC 3542 section 4 socket options and ancillary data - * - * Usage: <for command-line> - * asapi_06 - * - * HISTORY - * 05/2005 written by David L Stevens - * - * RESTRICTIONS: - * None. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + * Author: David L Stevens */ #include "config.h" @@ -57,25 +41,19 @@ #include <arpa/inet.h> #include "test.h" +#include "safe_macros.h" -char *TCID = "asapi_06"; /* Test program identifier. */ +char *TCID = "asapi_06"; int TST_TOTAL = 1; -pid_t pid; - -struct { - char *prt_name; - int prt_value; -} ptab[] = { -}; - -#define PTCOUNT (sizeof(ptab)/sizeof(ptab[0])) +static pid_t pid; #define READ_TIMEOUT 5 /* secs */ -void do_tests(void); -void setup(void), cleanup(void); +static void do_tests(void); +static void setup(void); +static void cleanup(void); int main(int argc, char *argv[]) { @@ -97,40 +75,40 @@ int main(int argc, char *argv[]) #define NH_TEST 0x9f #ifndef IPV6_RECVPKTINFO -#define IPV6_RECVPKTINFO -1 +# define IPV6_RECVPKTINFO -1 #endif #ifndef IPV6_RECVHOPLIMIT -#define IPV6_RECVHOPLIMIT -1 +# define IPV6_RECVHOPLIMIT -1 #endif #ifndef IPV6_RECVRTHDR -#define IPV6_RECVRTHDR -1 +# define IPV6_RECVRTHDR -1 #endif #ifndef IPV6_RECVHOPOPTS -#define IPV6_RECVHOPOPTS -1 +# define IPV6_RECVHOPOPTS -1 #endif #ifndef IPV6_RECVDSTOPTS -#define IPV6_RECVDSTOPTS -1 +# define IPV6_RECVDSTOPTS -1 #endif #ifndef IPV6_RECVTCLASS -#define IPV6_RECVTCLASS -1 +# define IPV6_RECVTCLASS -1 #endif #ifndef IPV6_TCLASS -#define IPV6_TCLASS -1 +# define IPV6_TCLASS -1 #endif #ifndef IPV6_2292PKTINFO -#define IPV6_2292PKTINFO -1 +# define IPV6_2292PKTINFO -1 #endif #ifndef IPV6_2292HOPLIMIT -#define IPV6_2292HOPLIMIT -1 +# define IPV6_2292HOPLIMIT -1 #endif #ifndef IPV6_2292RTHDR -#define IPV6_2292RTHDR -1 +# define IPV6_2292RTHDR -1 #endif #ifndef IPV6_2292HOPOPTS -#define IPV6_2292HOPOPTS -1 +# define IPV6_2292HOPOPTS -1 #endif #ifndef IPV6_2292DSTOPTS -#define IPV6_2292DSTOPTS -1 +# define IPV6_2292DSTOPTS -1 #endif union soval { @@ -150,7 +128,7 @@ union soval { #define IN6_ANY {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* so_clrval and so_setval members are initilized in the body */ -struct soent { +static struct soent { char *so_tname; int so_opt; int so_dorecv; /* do receive test? */ @@ -160,73 +138,52 @@ struct soent { union soval so_setval; socklen_t so_valsize; } sotab[] = { -/* RFC 3542, Section 4 */ - { - "IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, 1, IPV6_PKTINFO, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, 1, IPV6_HOPLIMIT, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_RECVRTHDR", IPV6_RECVRTHDR, 0, IPV6_RTHDR, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, 0, IPV6_HOPOPTS, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, 0, IPV6_DSTOPTS, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_RECVTCLASS", IPV6_RECVTCLASS, 1, IPV6_TCLASS, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, -/* make sure TCLASS stays when setting another opt */ - { - "IPV6_RECVTCLASS (2)", IPV6_RECVHOPLIMIT, 1, IPV6_TCLASS, 0, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, -/* OLD values */ - { - "IPV6_2292PKTINFO", IPV6_2292PKTINFO, 1, IPV6_2292PKTINFO, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_2292HOPLIMIT", IPV6_2292HOPLIMIT, 1, IPV6_2292HOPLIMIT, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_2292RTHDR", IPV6_2292RTHDR, 0, IPV6_2292RTHDR, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_2292HOPOPTS", IPV6_2292HOPOPTS, 0, IPV6_2292HOPOPTS, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_2292DSTOPTS", IPV6_2292DSTOPTS, 0, IPV6_2292DSTOPTS, 1, { { { { { - 0}}}}}, { { { { { -0}}}}}, sizeof(int)},}; - -#define SOCOUNT (sizeof(sotab)/sizeof(sotab[0])) + /* RFC 3542, Section 4 */ + {"IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, 1, IPV6_PKTINFO, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, 1, IPV6_HOPLIMIT, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_RECVRTHDR", IPV6_RECVRTHDR, 0, IPV6_RTHDR, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, 0, IPV6_HOPOPTS, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, 0, IPV6_DSTOPTS, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_RECVTCLASS", IPV6_RECVTCLASS, 1, IPV6_TCLASS, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + /* make sure TCLASS stays when setting another opt */ + {"IPV6_RECVTCLASS (2)", IPV6_RECVHOPLIMIT, 1, IPV6_TCLASS, 0, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + /* OLD values */ + {"IPV6_2292PKTINFO", IPV6_2292PKTINFO, 1, IPV6_2292PKTINFO, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_2292HOPLIMIT", IPV6_2292HOPLIMIT, 1, IPV6_2292HOPLIMIT, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_2292RTHDR", IPV6_2292RTHDR, 0, IPV6_2292RTHDR, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_2292HOPOPTS", IPV6_2292HOPOPTS, 0, IPV6_2292HOPOPTS, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_2292DSTOPTS", IPV6_2292DSTOPTS, 0, IPV6_2292DSTOPTS, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, +}; + +#define SOCOUNT ARRAY_SIZE(sotab) struct soprot { - int sop_pid; /* sender PID */ - int sop_seq; /* sequence # */ - int sop_dlen; /* tp_dat length */ + int sop_pid; /* sender PID */ + int sop_seq; /* sequence # */ + int sop_dlen; /* tp_dat length */ unsigned char sop_dat[0]; /* user data */ }; -unsigned char tpbuf[sizeof(struct soprot) + 2048]; -unsigned char rpbuf[sizeof(struct soprot) + 2048]; +static unsigned char tpbuf[sizeof(struct soprot) + 2048]; +static unsigned char rpbuf[sizeof(struct soprot) + 2048]; -unsigned char control[2048]; -int clen; +static unsigned char control[2048]; -int seq; +static int seq; -int setupso(void) -{ -/* add routing headers, other ancillary data here */ - return 0; -} - -struct cme { +static struct cme { int cm_len; int cm_level; int cm_type; @@ -235,26 +192,21 @@ struct cme { uint32_t cmu_hops; } cmu; } cmtab[] = { - { - sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, { - 0x12} - } - , { - sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, { - 0x21} - } -,}; + {sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {0x12} }, + {sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {0x21} }, +}; -#define CMCOUNT (sizeof(cmtab)/sizeof(cmtab[0])) +#define CMCOUNT ARRAY_SIZE(cmtab) -ssize_t sendall(int st) +static ssize_t sendall(int st) { struct sockaddr_in6 sin6; struct msghdr msg; struct iovec iov; struct soprot *psop; unsigned char *pd; - int i, ctotal; + unsigned int i; + int ctotal; psop = (struct soprot *)tpbuf; psop->sop_pid = htonl(getpid()); @@ -291,7 +243,7 @@ ssize_t sendall(int st) return sendmsg(st, &msg, 0); } -void so_test(struct soent *psoe) +static void so_test(struct soent *psoe) { struct sockaddr_in6 sin6; union soval sobuf; @@ -317,10 +269,9 @@ void so_test(struct soent *psoe) memset(&sin6, 0, sizeof(sin6)); sin6.sin6_family = AF_INET6; sin6.sin6_addr = in6addr_loopback; - if (bind(sr, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) { - tst_resm(TBROK, "%s: bind: %s", psoe->so_tname, - strerror(errno)); - } + + SAFE_BIND(NULL, sr, (struct sockaddr *)&sin6, sizeof(sin6)); + if (setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_clrval, psoe->so_valsize) < 0) { tst_resm(TBROK, "%s: setsockopt: %s", psoe->so_tname, @@ -345,12 +296,8 @@ void so_test(struct soent *psoe) else tst_resm(TPASS, "%s set-get", psoe->so_tname); - st = socket(PF_INET6, SOCK_RAW, NH_TEST); - if (st < 0) { - tst_resm(TBROK, "%s transmit socket: %s", psoe->so_tname, - strerror(errno)); - return; - } + st = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST); + if (sendall(st) < 0) { tst_resm(TBROK, "%s transmit sendto: %s", psoe->so_tname, strerror(errno)); @@ -409,7 +356,7 @@ void so_test(struct soent *psoe) psoe->so_tname, strerror(errno)); return; } -/* check pid & seq here */ + /* check pid & seq here */ break; } gotone = 0; @@ -429,7 +376,7 @@ void so_test(struct soent *psoe) return; } } -/* check contents here */ + /* check contents here */ if (psoe->so_dorecv) tst_resm(gotone ? TPASS : TFAIL, "%s receive", psoe->so_tname); @@ -451,20 +398,18 @@ static int ipv6_addr_scope(struct in6_addr *pin6) } #endif /* HAVE_IFADDRS_H */ -int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope) +static int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope) { #ifdef HAVE_IFADDRS_H static struct ifaddrs *pifa_head; struct ifaddrs *pifa; struct sockaddr_in6 *psin6; - char strbuf[128]; int ifindex = 0; int s; - if (!pifa_head && getifaddrs(&pifa_head)) { - tst_resm(TBROK, "%s: getifaddrs failed", tname); - return -1; - } + if (!pifa_head && getifaddrs(&pifa_head)) + tst_brkm(TBROK, NULL, "%s: getifaddrs failed", tname); + if (psin6_arg) ifindex = psin6_arg->sin6_scope_id; @@ -483,21 +428,16 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope) (this_scope > 0 && this_scope != scope))) continue; psin6->sin6_scope_id = if_nametoindex(pifa->ifa_name); - if ((ifindex < 0 && -ifindex == psin6->sin6_scope_id) || - (ifindex > 0 && ifindex != psin6->sin6_scope_id)) + if ((ifindex < 0 && + -(unsigned int)ifindex == psin6->sin6_scope_id) || + (ifindex > 0 && + (unsigned int)ifindex != psin6->sin6_scope_id)) continue; - s = socket(PF_INET6, SOCK_DGRAM, 0); - if (s < 0) { - tst_resm(TBROK, "%s: socket %s", tname, - strerror(errno)); - return -1; - } - if (bind(s, pifa->ifa_addr, sizeof(struct sockaddr_in6)) < 0) { - tst_resm(TBROK, "%s: bind \"%s\": %s", tname, - inet_ntop(AF_INET6, &psin6->sin6_addr, strbuf, - sizeof(strbuf)), strerror(errno)); - return -1; - } + + s = SAFE_SOCKET(NULL, PF_INET6, SOCK_DGRAM, 0); + + SAFE_BIND(NULL, s, pifa->ifa_addr, sizeof(struct sockaddr_in6)); + if (psin6_arg) { *psin6_arg = *psin6; psin6_arg->sin6_scope_id = @@ -539,7 +479,10 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope) } return -1; #else /* HAVE_IFADDRS_H */ +/* return -1; +*/ + tst_brkm(TBROK, NULL, "HAVE_IFADDRS_H is not defined"); #endif } @@ -548,46 +491,28 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope) * RFC 3542 IPV6_PKTINFO not in mainline yet (as of 2.6.15). The get/set * tests are below, and comments for some further tests to be added later */ -void test_pktinfo(void) +static void test_pktinfo(void) { - int s_snd, s_rcv[3] = { -1, -1, -1 }; + int s_snd; struct sockaddr_in6 sa_rcv[3]; - int s, i; - struct ifaddrs *pifa_head, *pifa; - struct sockaddr_in6 *psin6; char strbuf[128]; char *tname = "IPV6_PKTINFO"; struct in6_pktinfo pi, pi_tmp; - int sinlen; - int optlen; + socklen_t optlen; s_snd = getsock(tname, 0, IPV6_ADDR_GLOBAL); - if (s_snd < 0) { - tst_resm(TBROK, "%s: can't create send socket", tname); - return; - } + /* global-scope address, interface X */ sa_rcv[0].sin6_scope_id = 0; - s_rcv[0] = getsock(tname, &sa_rcv[0], IPV6_ADDR_GLOBAL); - if (s_rcv[0] == -1) { - tst_resm(TBROK, "%s: only link-scope addresses", tname); - return; - } + getsock(tname, &sa_rcv[0], IPV6_ADDR_GLOBAL); + /* link-local-scope address, interface X */ sa_rcv[1].sin6_scope_id = sa_rcv[0].sin6_scope_id; - s_rcv[1] = getsock(tname, &sa_rcv[1], IPV6_ADDR_LINK); - if (s_rcv[1] < 0) { - tst_resm(TBROK, "%s: no link-local address on ifindex %d", - tname, sa_rcv[0].sin6_scope_id); - return; - } + + getsock(tname, &sa_rcv[1], IPV6_ADDR_LINK); /* link-local-scope address, interface Y */ sa_rcv[2].sin6_scope_id = -sa_rcv[0].sin6_scope_id; - s_rcv[2] = getsock(tname, &sa_rcv[2], IPV6_ADDR_LINK); - if (s_rcv[2] < 0) { - tst_resm(TBROK, "%s: only one interface?", tname); - return; - } + getsock(tname, &sa_rcv[2], IPV6_ADDR_LINK); /* send to rcv1 to verify communication */ /* force to rcv2 w/ PKTINFO */ /* TESTS: */ @@ -615,8 +540,8 @@ void test_pktinfo(void) sizeof(strbuf2)), pi.ipi6_ifindex); } else tst_resm(TPASS, "%s", tname); -/* ancillary data override */ -/* link-local, wrong interface */ + /* ancillary data override */ + /* link-local, wrong interface */ tname = "IPV6_PKTINFO invalid {lladdr, intf}"; pi.ipi6_addr = sa_rcv[1].sin6_addr; pi.ipi6_ifindex = sa_rcv[2].sin6_scope_id; @@ -628,17 +553,12 @@ void test_pktinfo(void) tst_resm(TFAIL, "%s errno %d != %d", tname, TEST_ERRNO, EINVAL); else tst_resm(TPASS, "%s", tname); -/* nonexistent interface */ -/* non-local address */ -/* clear address */ -/* clear interface */ -/* sendmsg() sin6_scope differs with ancillary data interface */ } #endif /* notyet */ -void do_tests(void) +static void do_tests(void) { - int i; + unsigned int i; for (i = 0; i < SOCOUNT; ++i) { sotab[i].so_clrval.sou_bool = 0; @@ -650,11 +570,14 @@ void do_tests(void) #endif /* notyet - see test_pktinfo() comment above */ } -void setup(void) +static void setup(void) { - TEST_PAUSE; /* if -P option specified */ + TEST_PAUSE; + + tst_tmpdir(); } -void cleanup(void) +static void cleanup(void) { + tst_rmdir(); } -- 1.9.3 |
From: Zeng L. <zen...@cn...> - 2015-08-31 10:15:41
|
* Add 'static' before some functions and global variables. * Use 'tst_tmpdir' and 'tst_rmdir'. * Remove useless comments. * Use SAFE_XXX(). * Modify the format of etab[] and ftab[]. * Some cleanup. Signed-off-by: Zeng Linggang <zen...@cn...> Signed-off-by: Alexey Kodanev <ale...@or...> Signed-off-by: Cyril Hrubis <ch...@su...> --- testcases/network/lib6/asapi_05.c | 157 +++++++++++++++----------------------- 1 file changed, 63 insertions(+), 94 deletions(-) diff --git a/testcases/network/lib6/asapi_05.c b/testcases/network/lib6/asapi_05.c index e251eee..c19cd82 100644 --- a/testcases/network/lib6/asapi_05.c +++ b/testcases/network/lib6/asapi_05.c @@ -1,38 +1,21 @@ /* + * Copyright (c) 2015 Fujitsu Ltd. + * Copyright (c) International Business Machines Corp., 2001 * - * Copyright (c) International Business Machines Corp., 2001 + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - * Test Name: asapi_05 - * - * Test Description: - * These tests are for the "Advanced Sockets API" (RFC 3542) - * Verify that in6 and sockaddr fields are present. - * - * Usage: <for command-line> - * asapi_05 - * - * HISTORY - * 04/2005 written by David L Stevens - * - * RESTRICTIONS: - * None. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + * Author: David L Stevens */ #include <stdio.h> @@ -47,86 +30,83 @@ #include <netinet/icmp6.h> #include "test.h" +#include "safe_macros.h" -char *TCID = "asapi_05"; /* Test program identifier. */ +char *TCID = "asapi_05"; -void setup(void); -void cleanup(void); +static void setup(void); +static void cleanup(void); -void icmp6_ft(void); +static void icmp6_ft(void); int main(int argc, char *argv[]) { int lc; - /* Parse standard options given to run the test. */ tst_parse_opts(argc, argv, NULL, NULL); setup(); - for (lc = 0; TEST_LOOPING(lc); ++lc) { + for (lc = 0; TEST_LOOPING(lc); ++lc) icmp6_ft(); - } cleanup(); - tst_exit(); } -void setup(void) +static void setup(void) { - TEST_PAUSE; /* if -P option specified */ + TEST_PAUSE; tst_require_root(); + + tst_tmpdir(); } -void cleanup(void) +static void cleanup(void) { + tst_rmdir(); } -/* - * This is for old, broken glibc-header icmp6_filter structure definitions. - * If icmp6.h has struct icmp6_filter with field named "data" instead - * of the standard "icmp_filt", uncomment this line. - */ -/*#define icmp_filt data */ - -enum tt { T_WILLPASS, T_WILLBLOCK, T_SETPASS, T_SETBLOCK, T_SETPASSALL, +enum tt { + T_WILLPASS, + T_WILLBLOCK, + T_SETPASS, + T_SETBLOCK, + T_SETPASSALL, T_SETBLOCKALL }; -struct ftent { - char *ft_tname; /* test name, for logging */ + +static struct ftent { + char *ft_tname; /* test name, for logging */ unsigned char ft_sndtype; /* send type field */ unsigned char ft_flttype; /* filter type field */ - enum tt ft_test; /* what macro to test */ - int ft_expected; /* packet should pass? */ + enum tt ft_test; /* what macro to test */ + int ft_expected; /* packet should pass? */ } ftab[] = { - { - "ICMP6_FILTER_SETPASS s 20 f 20", 20, 20, T_SETPASS, 1}, { - "ICMP6_FILTER_SETPASS s 20 f 21", 20, 21, T_SETPASS, 0}, { - "ICMP6_FILTER_SETBLOCK s 20 f 20", 20, 20, T_SETBLOCK, 0}, { - "ICMP6_FILTER_SETBLOCK s 20 f 21", 20, 21, T_SETBLOCK, 1}, { - "ICMP6_FILTER_PASSALL s 20", 20, 0, T_SETPASSALL, 1}, { - "ICMP6_FILTER_PASSALL s 20", 21, 0, T_SETPASSALL, 1}, { - "ICMP6_FILTER_BLOCKALL s 20", 20, 0, T_SETBLOCKALL, 0}, { - "ICMP6_FILTER_BLOCKALL s 20", 21, 0, T_SETBLOCKALL, 0}, { - "ICMP6_FILTER_WILLBLOCK s 20 f 21", 20, 21, T_WILLBLOCK, 0}, { - "ICMP6_FILTER_WILLBLOCK s 20 f 20", 20, 20, T_WILLBLOCK, 1}, { - "ICMP6_FILTER_WILLPASS s 20 f 21", 20, 21, T_WILLPASS, 0}, { -"ICMP6_FILTER_WILLPASS s 22 f 22", 22, 22, T_WILLPASS, 1},}; - -#define FTCOUNT (sizeof(ftab)/sizeof(ftab[0])) - -int ic6_send1(char *tname, unsigned char type) + {"ICMP6_FILTER_SETPASS s 20 f 20", 20, 20, T_SETPASS, 1}, + {"ICMP6_FILTER_SETPASS s 20 f 21", 20, 21, T_SETPASS, 0}, + {"ICMP6_FILTER_SETBLOCK s 20 f 20", 20, 20, T_SETBLOCK, 0}, + {"ICMP6_FILTER_SETBLOCK s 20 f 21", 20, 21, T_SETBLOCK, 1}, + {"ICMP6_FILTER_PASSALL s 20", 20, 0, T_SETPASSALL, 1}, + {"ICMP6_FILTER_PASSALL s 20", 21, 0, T_SETPASSALL, 1}, + {"ICMP6_FILTER_BLOCKALL s 20", 20, 0, T_SETBLOCKALL, 0}, + {"ICMP6_FILTER_BLOCKALL s 20", 21, 0, T_SETBLOCKALL, 0}, + {"ICMP6_FILTER_WILLBLOCK s 20 f 21", 20, 21, T_WILLBLOCK, 0}, + {"ICMP6_FILTER_WILLBLOCK s 20 f 20", 20, 20, T_WILLBLOCK, 1}, + {"ICMP6_FILTER_WILLPASS s 20 f 21", 20, 21, T_WILLPASS, 0}, + {"ICMP6_FILTER_WILLPASS s 22 f 22", 22, 22, T_WILLPASS, 1}, +}; + +#define FTCOUNT ARRAY_SIZE(ftab) + +static int ic6_send1(char *tname, unsigned char type) { struct sockaddr_in6 sin6; struct icmp6_hdr ic6; int s; - s = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); - if (s == -1) { - tst_resm(TBROK, "%s: socket failed", tname); - return 1; - } + s = SAFE_SOCKET(NULL, AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); + memset(&ic6, 0, sizeof(ic6)); ic6.icmp6_type = type; ic6.icmp6_data32[0] = htonl(getpid()); @@ -142,7 +122,7 @@ int ic6_send1(char *tname, unsigned char type) return 0; } -int ic6_recv1(char *tname, int sall, int sf) +static int ic6_recv1(char *tname, int sall, int sf) { fd_set readfds, readfds_saved; struct timeval tv; @@ -185,7 +165,7 @@ int ic6_recv1(char *tname, int sall, int sf) return -1; } /* if packet check succeeds... */ - if (htonl(pic6->icmp6_data32[0]) == getpid()) + if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid()) gotall = 1; } if (FD_ISSET(sf, &readfds)) { @@ -196,7 +176,7 @@ int ic6_recv1(char *tname, int sall, int sf) return -1; } /* if packet check succeeds... */ - if (htonl(pic6->icmp6_data32[0]) == getpid()) + if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid()) gotone = 1; } memcpy(&readfds, &readfds_saved, sizeof(readfds)); @@ -211,18 +191,14 @@ int ic6_recv1(char *tname, int sall, int sf) } /* functional tests */ -void icmp6_ft(void) +static void icmp6_ft(void) { struct icmp6_filter i6f; int sall, sf; - int i; + unsigned int i; + + sall = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6); - sall = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6); - if (sall < 0) { - tst_resm(TBROK | TERRNO, - "icmp6_ft socket: can't create sall socket"); - return; - } ICMP6_FILTER_SETPASSALL(&i6f); if (setsockopt(sall, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f, sizeof(i6f)) < 0) { @@ -230,12 +206,7 @@ void icmp6_ft(void) "setsockopt pass all ICMP6_FILTER failed"); } - sf = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6); - if (sf < 0) { - tst_resm(TBROK | TERRNO, - "icmp6_ft socket: can't create test socket"); - return; - } + sf = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6); int rv; @@ -296,5 +267,3 @@ void icmp6_ft(void) tst_resm(TPASS, "%s", ftab[i].ft_tname); } } - -int TST_TOTAL = FTCOUNT; -- 1.9.3 |
From: Zeng L. <zen...@cn...> - 2015-08-31 10:15:39
|
* Add 'static' before some functions and global variables. * Remove useless comments. * Use SAFE_XXX(). * Modify the format of ptab[] and cstab[]. * Rewrite 'csum_test()' and 'isocketpair()'. * Use 'tst_tmpdir' and 'tst_rmdir'. * Some cleanup. Signed-off-by: Zeng Linggang <zen...@cn...> Signed-off-by: Alexey Kodanev <ale...@or...> Signed-off-by: Cyril Hrubis <ch...@su...> --- testcases/network/lib6/asapi_04.c | 287 ++++++++++++++++---------------------- 1 file changed, 122 insertions(+), 165 deletions(-) diff --git a/testcases/network/lib6/asapi_04.c b/testcases/network/lib6/asapi_04.c index 76de26b..76e8f8e 100644 --- a/testcases/network/lib6/asapi_04.c +++ b/testcases/network/lib6/asapi_04.c @@ -1,38 +1,21 @@ /* + * Copyright (c) 2015 Fujitsu Ltd. + * Copyright (c) International Business Machines Corp., 2001 * - * Copyright (c) International Business Machines Corp., 2001 + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - * Test Name: asapi_04 - * - * Test Description: - * Verify that in6 and sockaddr fields are present. Most of these are - * "PASS" if they just compile. - * - * Usage: <for command-line> - * asapi_04 - * - * HISTORY - * 04/2005 written by David L Stevens - * - * RESTRICTIONS: - * None. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + * Author: David L Stevens */ #include <stdio.h> @@ -48,33 +31,35 @@ #include <netinet/in.h> #include "test.h" +#include "safe_macros.h" -char *TCID = "asapi_04"; /* Test program identifier. */ +char *TCID = "asapi_04"; -pid_t pid; +static pid_t pid; -struct { +static struct { char *prt_name; int prt_value; } ptab[] = { - { - "hopopt", 0}, { - "ipv6", 41}, { - "ipv6-route", 43}, { - "ipv6-frag", 44}, { - "esp", 50}, { - "ah", 51}, { - "ipv6-icmp", 58}, { - "ipv6-nonxt", 59}, { -"ipv6-opts", 60},}; - -#define PTCOUNT (sizeof(ptab)/sizeof(ptab[0])) + {"hopopt", 0}, + {"ipv6", 41}, + {"ipv6-route", 43}, + {"ipv6-frag", 44}, + {"esp", 50}, + {"ah", 51}, + {"ipv6-icmp", 58}, + {"ipv6-nonxt", 59}, + {"ipv6-opts", 60}, +}; + +#define PTCOUNT ARRAY_SIZE(ptab) #define READ_TIMEOUT 5 /* secs */ -void do_tests(void); -void setup(void), cleanup(void); -int csum_test(char *rhost); +static void do_tests(void); +static void setup(void); +static void cleanup(void); +static int csum_test(void); int main(int argc, char *argv[]) { @@ -90,44 +75,41 @@ int main(int argc, char *argv[]) do_tests(); cleanup(); - tst_exit(); } -void do_tests(void) +static void do_tests(void) { - int i; + unsigned int i; /* RFC 3542, Section 2.3 */ #ifndef IN6_ARE_ADDR_EQUAL - tst_resm(TBROK, "IN6_ARE_ADDR_EQUAL not present"); + tst_resm(TCONF, "IN6_ARE_ADDR_EQUAL not present"); #else /* IN6_ARE_ADDR_EQUAL */ /* * set each bit in an address and check for unequal; then set * in the second address and check for equal. Covers all bits, all * combinations. */ - { - struct in6_addr a1, a2; - int word, bit; - int rv = 1; + struct in6_addr a1, a2; + int word, bit; + int rv = 1; - memset(&a1, 0, sizeof(a1)); - memset(&a2, 0, sizeof(a2)); + memset(&a1, 0, sizeof(a1)); + memset(&a2, 0, sizeof(a2)); - rv = IN6_ARE_ADDR_EQUAL(&a1, &a2); + rv = IN6_ARE_ADDR_EQUAL(&a1, &a2); - for (word = 0; word < 4; ++word) - for (bit = 0; bit < 32; ++bit) { - uint32_t newbit = 1 << bit; + for (word = 0; word < 4; ++word) + for (bit = 0; bit < 32; ++bit) { + uint32_t newbit = 1U << bit; - a1.s6_addr32[word] |= newbit; /* unequal */ - rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2); - a2.s6_addr32[word] |= newbit; /* equal */ - rv &= IN6_ARE_ADDR_EQUAL(&a1, &a2); - } - tst_resm(rv ? TPASS : TFAIL, "IN6_ARE_ADDR_EQUAL"); - } + a1.s6_addr32[word] |= newbit; /* unequal */ + rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2); + a2.s6_addr32[word] |= newbit; /* equal */ + rv &= IN6_ARE_ADDR_EQUAL(&a1, &a2); + } + tst_resm(rv ? TPASS : TFAIL, "IN6_ARE_ADDR_EQUAL"); #endif /* IN6_ARE_ADDR_EQUAL */ /* RFC 3542, Section 2.4 */ @@ -141,7 +123,7 @@ void do_tests(void) ptab[i].prt_name); } /* RFC 3542, Section 3.1 */ - csum_test("::1"); + csum_test(); } /* @@ -162,10 +144,10 @@ struct tprot { unsigned char tp_dat[0]; /* user data */ }; -unsigned char tpbuf[sizeof(struct tprot) + 2048]; -unsigned char rpbuf[sizeof(struct tprot) + 2048]; +static unsigned char tpbuf[sizeof(struct tprot) + 2048]; +static unsigned char rpbuf[sizeof(struct tprot) + 2048]; -struct csent { +static struct csent { int cs_offset; int cs_dlen; int cs_setresult; /* setsockopt expected result */ @@ -173,25 +155,24 @@ struct csent { int cs_sndresult; /* send expected result */ int cs_snderrno; /* send expected errno */ } cstab[] = { - { - 0, 5, 0, 0, 0, 0}, { - 6, 30, 0, 0, 0, 0}, { - 3, 20, -1, EINVAL, -1, -1}, /* non-aligned offset */ - { - 4, 5, 0, 0, -1, EINVAL}, /* not enough space */ - { - 50, 5, 0, 0, -1, EINVAL}, /* outside of packet */ - { - 22, 30, 0, 0, 0, 0}, { - 2000, 2004, 0, 0, 0, 0}, /* in a fragment (over Ethernet) */ + {0, 5, 0, 0, 0, 0}, + {6, 30, 0, 0, 0, 0}, + {3, 20, -1, EINVAL, -1, -1}, /* non-aligned offset */ + {4, 5, 0, 0, -1, EINVAL}, /* not enough space */ + {50, 5, 0, 0, -1, EINVAL}, /* outside of packet */ + {22, 30, 0, 0, 0, 0}, + {2000, 2004, 0, 0, 0, 0}, /* in a fragment (over Ethernet) */ }; -#define CSCOUNT (sizeof(cstab)/sizeof(cstab[0])) +#define CSCOUNT ARRAY_SIZE(cstab) + +int TST_TOTAL = PTCOUNT + CSCOUNT; -static int recvtprot(int sd, unsigned char *packet, int psize) +static int recvtprot(int sd, unsigned char *packet) { struct tprot *tpt; - int cc, total, expected; + int cc; + unsigned int total, expected; int gothead; tpt = (struct tprot *)packet; @@ -218,7 +199,8 @@ static int recvtprot(int sd, unsigned char *packet, int psize) return total; } -unsigned short csum(unsigned short partial, unsigned char *packet, int len) +static unsigned short csum(unsigned short partial, unsigned char *packet, + int len) { unsigned long sum = partial; unsigned short *ps; @@ -234,7 +216,7 @@ unsigned short csum(unsigned short partial, unsigned char *packet, int len) return ~sum; } -struct ph { +static struct ph { struct in6_addr ph_sa; struct in6_addr ph_da; uint32_t ph_len; @@ -242,13 +224,14 @@ struct ph { uint8_t ph_nh; } ph; -static int client(int prot, int sfd) +static int client(int sfd) { struct tprot *pttp = (struct tprot *)tpbuf; struct tprot *prtp = (struct tprot *)rpbuf; struct sockaddr_in6 rsin6; static int seq; - int i, sd, cc, cs; + unsigned int i; + int sd, cc, cs; memset(&rsin6, 0, sizeof(rsin6)); rsin6.sin6_family = AF_INET6; @@ -259,11 +242,8 @@ static int client(int prot, int sfd) ph.ph_da = rsin6.sin6_addr; ph.ph_nh = NH_TEST; - sd = socket(PF_INET6, SOCK_RAW, NH_TEST); - if (sd < 0) { - tst_resm(TBROK, "can't create raw socket: %s", strerror(errno)); - return -1; - } + sd = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST); + for (i = 0; i < CSCOUNT; ++i) { int offset, len, xlen; int rv; @@ -289,17 +269,20 @@ static int client(int prot, int sfd) cstab[i].cs_setresult); continue; } + if (TEST_RETURN < 0) { tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d", offset, len); continue; } + if (TEST_RETURN && TEST_ERRNO != cstab[i].cs_seterrno) { tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d " "- errno %d != %d", offset, len, TEST_ERRNO, cstab[i].cs_seterrno); continue; } + /* send packet */ TEST(sendto(sd, pttp, len, 0, (struct sockaddr *)&rsin6, sizeof(rsin6))); @@ -311,20 +294,23 @@ static int client(int prot, int sfd) TEST_RETURN, xlen); continue; } + if (TEST_RETURN < 0 && TEST_ERRNO != cstab[i].cs_snderrno) { tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d " "- snderrno %d != %d", offset, len, TEST_ERRNO, cstab[i].cs_snderrno); continue; } + if (TEST_RETURN < 0) { tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d", offset, len); continue; } - while ((cc = recvtprot(sfd, rpbuf, sizeof(rpbuf)))) { - if (htonl(prtp->tp_pid) == pid && - htonl(prtp->tp_seq) == seq) + + while ((cc = recvtprot(sfd, rpbuf))) { + if (htonl(prtp->tp_pid) == (uint32_t)pid && + htonl(prtp->tp_seq) == (uint32_t)seq) break; } rv = 1; @@ -334,7 +320,7 @@ static int client(int prot, int sfd) continue; if (*p != 0xa5) { tst_resm(TFAIL, "IPV6_CHECKSUM corrupt data " - "0x%02x != 0xa5 at offset %d in packet", + "0x%02x != 0xa5 at offset %zd in packet", *p, p - rpbuf); rv = 0; break; @@ -358,7 +344,7 @@ static int client(int prot, int sfd) static int listen_fd, connect_fd; sem_t ilsem; -void *ilistener(void *arg) +static void *ilistener(void *arg LTP_ATTRIBUTE_UNUSED) { connect_fd = accept(listen_fd, 0, 0); close(listen_fd); @@ -366,7 +352,7 @@ void *ilistener(void *arg) return NULL; } -int isocketpair(int pf, int type, int proto, int fd[2]) +static void isocketpair(int pf, int type, int proto, int fd[2]) { pthread_t thid; struct sockaddr_in sin4; @@ -375,80 +361,51 @@ int isocketpair(int pf, int type, int proto, int fd[2]) /* restrict to PF_INET for now */ if (pf != PF_INET) { errno = EOPNOTSUPP; - return -1; + return; } + sem_init(&ilsem, 0, 0); - listen_fd = socket(pf, type, proto); - if (listen_fd < 0) { - perror("socket"); - return -1; - } + + listen_fd = SAFE_SOCKET(NULL, pf, type, proto); + memset(&sin4, 0, sizeof(sin4)); - if (bind(listen_fd, (struct sockaddr *)&sin4, sizeof(sin4)) < 0) { - perror("bind"); - return -1; - } - if (listen(listen_fd, 10) < 0) { - perror("listen"); - return -1; - } + + SAFE_BIND(NULL, listen_fd, (struct sockaddr *)&sin4, sizeof(sin4)); + + SAFE_LISTEN(NULL, listen_fd, 10); + namelen = sizeof(sin4); - if (getsockname(listen_fd, (struct sockaddr *)&sin4, &namelen) < 0) { - perror("getsockname"); - return -1; - } - if (pthread_create(&thid, 0, ilistener, 0) < 0) { - perror("pthread_create"); - return -1; - } + SAFE_GETSOCKNAME(NULL, listen_fd, (struct sockaddr *)&sin4, &namelen); + + if (pthread_create(&thid, 0, ilistener, 0) < 0) + tst_brkm(TBROK | TERRNO, NULL, "pthread_create error"); + + fd[0] = SAFE_SOCKET(NULL, pf, type, proto); - fd[0] = socket(pf, type, proto); - if (fd[0] < 0) { - perror("socket"); - return -1; - } sin4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - if (connect(fd[0], (struct sockaddr *)&sin4, sizeof(sin4)) < 0) { - perror("connect"); - return -1; - } + + SAFE_CONNECT(NULL, fd[0], (struct sockaddr *)&sin4, sizeof(sin4)); + sem_wait(&ilsem); fd[1] = connect_fd; sem_destroy(&ilsem); - return 0; } #ifndef MAX #define MAX(a, b) ((a) >= (b) ? (a) : (b)) #endif /* MAX */ -int csum_test(char *rhost) +static int csum_test(void) { fd_set rset, rset_save; int csd[2]; /* control sockets */ int sd, nfds, maxfd, cc; struct timeval tv; -/* rhost == loopback, for now */ - if (strcmp(rhost, "::1")) { - tst_resm(TBROK, "invalid rhost \"%s\"", rhost); - return -1; - } - if (isocketpair(PF_INET, SOCK_STREAM, 0, csd) < 0) { - tst_resm(TBROK, "socketpair: %s", strerror(errno)); - return -1; - } - sd = socket(PF_INET6, SOCK_RAW, NH_TEST); - if (sd < 0) { - int saved_errno = errno; - - if (errno == EPERM && geteuid()) - tst_resm(TBROK, "IPV6_CHECKSUM tests must run as root"); - else - tst_resm(TBROK, "All IPv6_CHECKSUM tests broken: " - "socket: %s", strerror(saved_errno)); - return -1; - } + isocketpair(PF_INET, SOCK_STREAM, 0, csd); + + sd = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST); + FD_ZERO(&rset_save); FD_SET(sd, &rset_save); FD_SET(csd[1], &rset_save); @@ -457,16 +414,15 @@ int csum_test(char *rhost) /* server socket set; now start the client */ switch (fork()) { - case 0: /* child */ + case 0: close(csd[0]); break; case -1: - tst_resm(TBROK, "can't fork rserver"); - return -1; - default: /* parent */ + tst_brkm(TBROK, NULL, "can't fork rserver"); + default: close(sd); close(csd[1]); - return client(pid, csd[0]); + return client(csd[0]); } tv.tv_sec = READ_TIMEOUT; @@ -515,13 +471,14 @@ int csum_test(char *rhost) return 0; } -void setup(void) +static void setup(void) { - TEST_PAUSE; /* if -P option specified */ + TEST_PAUSE; + + tst_tmpdir(); } -void cleanup(void) +static void cleanup(void) { + tst_rmdir(); } - -int TST_TOTAL = PTCOUNT + CSCOUNT; -- 1.9.3 |
From: Zeng L. <zen...@cn...> - 2015-08-31 10:15:38
|
Signed-off-by: Zeng Linggang <zen...@cn...> Signed-off-by: Alexey Kodanev <ale...@or...> Signed-off-by: Cyril Hrubis <ch...@su...> --- include/safe_macros.h | 1 + include/safe_net.h | 59 +++++++++++++++++++++++++ lib/safe_net.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 include/safe_net.h create mode 100644 lib/safe_net.c diff --git a/include/safe_macros.h b/include/safe_macros.h index cd86931..e938f17 100644 --- a/include/safe_macros.h +++ b/include/safe_macros.h @@ -28,6 +28,7 @@ #include <dirent.h> #include "safe_stdio.h" +#include "safe_net.h" char* safe_basename(const char *file, const int lineno, void (*cleanup_fn)(void), char *path); diff --git a/include/safe_net.h b/include/safe_net.h new file mode 100644 index 0000000..f9ce040 --- /dev/null +++ b/include/safe_net.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015 Fujitsu Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef __SAFE_NET_H__ +#define __SAFE_NET_H__ + +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> + +#define GET_ADDR(sock_addr) \ + (inet_ntoa(((struct sockaddr_in *)sock_addr)->sin_addr)) + +int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void), + int domain, int type, int protocol); +#define SAFE_SOCKET(cleanup_fn, domain, type, protocol) \ + safe_socket(__FILE__, __LINE__, (cleanup_fn), domain, type, protocol) + +int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void), + int socket, const struct sockaddr *address, + socklen_t address_len); +#define SAFE_BIND(cleanup_fn, socket, address, address_len) \ + safe_bind(__FILE__, __LINE__, (cleanup_fn), socket, address, \ + address_len) + +int safe_listen(const char *file, const int lineno, void (cleanup_fn)(void), + int socket, int backlog); +#define SAFE_LISTEN(cleanup_fn, socket, backlog) \ + safe_listen(__FILE__, __LINE__, (cleanup_fn), socket, backlog) + +int safe_connect(const char *file, const int lineno, void (cleanup_fn)(void), + int sockfd, const struct sockaddr *addr, socklen_t addrlen); +#define SAFE_CONNECT(cleanup_fn, sockfd, addr, addrlen) \ + safe_connect(__FILE__, __LINE__, (cleanup_fn), sockfd, addr, addrlen) + +int safe_getsockname(const char *file, const int lineno, + void (cleanup_fn)(void), int sockfd, struct sockaddr *addr, + socklen_t *addrlen); +#define SAFE_GETSOCKNAME(cleanup_fn, sockfd, addr, addrlen) \ + safe_getsockname(__FILE__, __LINE__, (cleanup_fn), sockfd, addr, \ + addrlen) + +#endif /* __SAFE_NET_H__ */ diff --git a/lib/safe_net.c b/lib/safe_net.c new file mode 100644 index 0000000..5130fac --- /dev/null +++ b/lib/safe_net.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2015 Fujitsu Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <errno.h> +#include "test.h" +#include "safe_net.h" + +int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void), + int domain, int type, int protocol) +{ + int rval; + + rval = socket(domain, type, protocol); + + if (rval < 0) { + tst_brkm(TBROK | TERRNO, cleanup_fn, + "%s:%d: socket(%d, %d, %d) failed", file, lineno, + domain, type, protocol); + } + + return rval; +} + +int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void), + int socket, const struct sockaddr *address, + socklen_t address_len) +{ + int i; + + for (i = 0; i < 120; i++) { + if (!bind(socket, address, address_len)) { + tst_resm(TINFO, "bind is OK now"); + return 0; + } + + if (errno != EADDRINUSE) { + tst_brkm(TBROK | TERRNO, cleanup_fn, + "%s:%d: bind(%d, %s, %d) failed", file, lineno, + socket, GET_ADDR(address), address_len); + } + + if ((i + 1) % 10 == 1) { + tst_resm(TINFO, "address is in use, waited %3i sec", + i + 1); + } + + sleep(1); + } + + tst_brkm(TBROK | TERRNO, cleanup_fn, + "%s:%d: Failed to bind(%d, %p, %d) after 30 retries", file, + lineno, socket, GET_ADDR(address), address_len); +} + +int safe_listen(const char *file, const int lineno, void (cleanup_fn)(void), + int socket, int backlog) +{ + int rval; + + rval = listen(socket, backlog); + + if (rval < 0) { + tst_brkm(TBROK | TERRNO, cleanup_fn, + "%s:%d: listen(%d, %d) failed", file, lineno, socket, + backlog); + } + + return rval; +} + +int safe_connect(const char *file, const int lineno, void (cleanup_fn)(void), + int sockfd, const struct sockaddr *addr, socklen_t addrlen) +{ + int rval; + + rval = connect(sockfd, addr, addrlen); + + if (rval < 0) { + tst_brkm(TBROK | TERRNO, cleanup_fn, + "%s:%d: connect(%d, %s, %d) failed", file, lineno, + sockfd, GET_ADDR(addr), addrlen); + } + + return rval; +} + +int safe_getsockname(const char *file, const int lineno, + void (cleanup_fn)(void), int sockfd, struct sockaddr *addr, + socklen_t *addrlen) +{ + int rval; + + rval = getsockname(sockfd, addr, addrlen); + + if (rval < 0) { + tst_brkm(TBROK | TERRNO, cleanup_fn, + "%s:%d: getsockname(%d, %s, %p) failed", file, lineno, + sockfd, GET_ADDR(addr), addrlen); + } + + return rval; +} -- 1.9.3 |
From: <dw...@fi...> - 2015-08-29 23:47:50
|
Hi, I read your January 2015 article where someone asked if TAP test output would be supported. It sounded like you were going to look into it. Did you make any progress? The reason I asked if because I was wanting the same feature and I was going to review the LTP code to see how hard it would be to add it, but I wouldn't want to start if someone else has already done it. I did see anything in the git history tho. Thanks for any information. Daniel |
From: Cyril H. <ch...@su...> - 2015-08-27 14:27:18
|
Hi! > ./ns_exec 1234 mnt pid uts ls / > > seems a bit confusing to me. Maybe use just $2 and comma-separate the > names? (Also for ns_create, for consistency.) > > pid=$(./ns_create pid,mnt,uts,net) > ./ns_exec $pid mnt,pid ls / That's a bit harder to parse but you have the point. -- Cyril Hrubis ch...@su... |
From: Jiri J. <jja...@re...> - 2015-08-27 14:23:38
|
On 08/27/2015 04:13 PM, Cyril Hrubis wrote: > Hi! >>>> In addition, there are probably going to be some problems with >>>> capability bits when calling execve(2) after doing setns on user ns >>>> (see capabilities(7), "Thread capability sets"). >>>> >>>> Yes, user namespaces are even bigger PITA than pid namespaces. :) >>> >>> Looks like that. >>> >> >> Maybe the best solution would be explicit getopt-like switches, telling >> exec_ns which namespaces and in which order to setns. > > I came to this conclusion as well. It does not need to be getopt-like, > maybe just list of namespaces to join, the important part is that the > order would be preserved. ./ns_exec 1234 mnt pid uts ls / seems a bit confusing to me. Maybe use just $2 and comma-separate the names? (Also for ns_create, for consistency.) pid=$(./ns_create pid,mnt,uts,net) ./ns_exec $pid mnt,pid ls / > > I would just accept the parameters the same way as the ns_create does, > i.e. list of argv parameters. And handle them in two passes, first one > would check that the parameters are correct and the second pass would > actually call the setns() one by one in the order they were specified. The first pass would be checking by open(2)-ing already, which needs to be done due to mount (ie. old /proc not available in the new ns) and pid (old pid invalid) namespaces. > |
From: Cyril H. <ch...@su...> - 2015-08-27 14:14:14
|
Hi! > >> In addition, there are probably going to be some problems with > >> capability bits when calling execve(2) after doing setns on user ns > >> (see capabilities(7), "Thread capability sets"). > >> > >> Yes, user namespaces are even bigger PITA than pid namespaces. :) > > > > Looks like that. > > > > Maybe the best solution would be explicit getopt-like switches, telling > exec_ns which namespaces and in which order to setns. I came to this conclusion as well. It does not need to be getopt-like, maybe just list of namespaces to join, the important part is that the order would be preserved. I would just accept the parameters the same way as the ns_create does, i.e. list of argv parameters. And handle them in two passes, first one would check that the parameters are correct and the second pass would actually call the setns() one by one in the order they were specified. -- Cyril Hrubis ch...@su... |
From: Jiri J. <jja...@re...> - 2015-08-27 14:09:10
|
On 08/27/2015 03:47 PM, Cyril Hrubis wrote: > Hi! >>> Since the ns_create only creates a new network namespace the rest of the >>> namespaces are inherited. At least when I change the ns_create that >>> creates the handle to create new user namespace as well it can >>> succesfully join it. >>> >>> Why do we attempt to join all namespaces in the ns_exec? I guess that we >>> will have to change it to get a list of namespaces to join the same way >>> the ns_create does it. >> >> The original idea was to simply join all NSs of the target to avoid >> passing the ns type, which is a nice idea and works for any other ns, >> but unfortunately not for user ns. >> The simple fix for that would be readlink() on the file and if the id >> (dentry) matches the one in /proc/self/ns/, don't open it. > > Or we may ignore EINVAL for the user namespace. But shouldn't be joining > only the net namespace enough for the testing? That way we are sure that > other namespaces does not cause unexpected side effects. For testing only specific single-namespace features, yes. However I get the impression that the functions were meant to be more generic, for inter-namespace testing as well (since they essentially create "namespace sets"). In this case, opening only different namespace ids from exec_ns is the most generic solution IMHO - if you create_ns only net ns, only that one namespace will be setns'd. > >> However I fear there may be other considerations at hand, ie. user ns >> interactions with other NSs - the functions (from what I can see) can >> create/unshare multiple namespaces on a single process. If one specifies >> ie. CLONE_NEWNS | CLONE_NEWUSER | CLONE_NEWNET, the user ns is always >> created first. This theoretically means (haven't tested it myself) that >> an unprivileged user can create non-user namespaces if it has UID 0 in >> the new user namespace as well as a privileged user being unable to >> create the other namespaces if it doesn't have the capabilities to do so >> in the new user namespace (according to uid/gid maps). > > Hmm, kind of makes sense... > >> This also implies possible complications of calling setns() multiple >> times for multiple different namespace types - it may be necessary to >> call it first on the user ns fd (or the other way around?). > > The setns() with user ns should be last if we want to join more > namespaces, otherwise I get EPERM since the process is no longer > capable, but that happen only in case I've actually created new user > namespace. See - that depends on the viewpoint and the test case. If you're privileged prior to user ns switch, it makes sense to setns the other namespaces first. If you're unprivileged, it makes sense to change user ns first, hoping to become privileged in the new namespace. nsenter(1), for example, always does setns on user namespace first. > >> In addition, there are probably going to be some problems with >> capability bits when calling execve(2) after doing setns on user ns >> (see capabilities(7), "Thread capability sets"). >> >> Yes, user namespaces are even bigger PITA than pid namespaces. :) > > Looks like that. > Maybe the best solution would be explicit getopt-like switches, telling exec_ns which namespaces and in which order to setns. Jiri |
From: Cyril H. <ch...@su...> - 2015-08-27 13:48:32
|
Hi! > > Since the ns_create only creates a new network namespace the rest of the > > namespaces are inherited. At least when I change the ns_create that > > creates the handle to create new user namespace as well it can > > succesfully join it. > > > > Why do we attempt to join all namespaces in the ns_exec? I guess that we > > will have to change it to get a list of namespaces to join the same way > > the ns_create does it. > > The original idea was to simply join all NSs of the target to avoid > passing the ns type, which is a nice idea and works for any other ns, > but unfortunately not for user ns. > The simple fix for that would be readlink() on the file and if the id > (dentry) matches the one in /proc/self/ns/, don't open it. Or we may ignore EINVAL for the user namespace. But shouldn't be joining only the net namespace enough for the testing? That way we are sure that other namespaces does not cause unexpected side effects. > However I fear there may be other considerations at hand, ie. user ns > interactions with other NSs - the functions (from what I can see) can > create/unshare multiple namespaces on a single process. If one specifies > ie. CLONE_NEWNS | CLONE_NEWUSER | CLONE_NEWNET, the user ns is always > created first. This theoretically means (haven't tested it myself) that > an unprivileged user can create non-user namespaces if it has UID 0 in > the new user namespace as well as a privileged user being unable to > create the other namespaces if it doesn't have the capabilities to do so > in the new user namespace (according to uid/gid maps). Hmm, kind of makes sense... > This also implies possible complications of calling setns() multiple > times for multiple different namespace types - it may be necessary to > call it first on the user ns fd (or the other way around?). The setns() with user ns should be last if we want to join more namespaces, otherwise I get EPERM since the process is no longer capable, but that happen only in case I've actually created new user namespace. > In addition, there are probably going to be some problems with > capability bits when calling execve(2) after doing setns on user ns > (see capabilities(7), "Thread capability sets"). > > Yes, user namespaces are even bigger PITA than pid namespaces. :) Looks like that. -- Cyril Hrubis ch...@su... |
From: Jiri J. <jja...@re...> - 2015-08-27 13:37:17
|
On 08/27/2015 01:55 PM, Cyril Hrubis wrote: > Hi! >> On SLES12 (kernel 3.12.28) setns() fails for the fd opened from "user" >> namespace. I'm getting EINVAL here. Everything seems to work fine if I >> comment the rf |= open_ns_fd(argv[1], "user"); line above. User namespaces are very problematic (even in upstream) and generally disabled on enterprise distros (so far) due to their comparatively high risk of introducing security issues. The way of disablement differs between distros, ie. one could simply build with CONFIG_NS_USER=n, but RHEL 7 has =y with /proc/<pid>/ns/user missing. SLES12 might go one step further of actually showing up the file, but rendering the functionality non-working, exactly by returning something like EINVAL or ENOSYS. (I'm not saying it's your case, just pointing it out.) >> >> Unfortunately EINVAL seems to be catch-all error for setns(), any idea >> what is wrong here? EINVAL is a catch-all when returning errors from the Linux kernel on user action (call). > > And it seems to be the case of: > > EINVAL The caller attempted to join the user namespace in which > it is already a member. While this doesn't apply to other namespaces, it does apply to the user namespaces, if you look at SYSCALL_DEFINE2(setns, in kernel/nsproxy.c and then at userns_install() in kernel/user_namespace.c, it becomes obvious. /* Don't allow gaining capabilities by reentering * the same user namespace. */ if (user_ns == current_user_ns()) return -EINVAL; > > Since the ns_create only creates a new network namespace the rest of the > namespaces are inherited. At least when I change the ns_create that > creates the handle to create new user namespace as well it can > succesfully join it. > > Why do we attempt to join all namespaces in the ns_exec? I guess that we > will have to change it to get a list of namespaces to join the same way > the ns_create does it. The original idea was to simply join all NSs of the target to avoid passing the ns type, which is a nice idea and works for any other ns, but unfortunately not for user ns. The simple fix for that would be readlink() on the file and if the id (dentry) matches the one in /proc/self/ns/, don't open it. However I fear there may be other considerations at hand, ie. user ns interactions with other NSs - the functions (from what I can see) can create/unshare multiple namespaces on a single process. If one specifies ie. CLONE_NEWNS | CLONE_NEWUSER | CLONE_NEWNET, the user ns is always created first. This theoretically means (haven't tested it myself) that an unprivileged user can create non-user namespaces if it has UID 0 in the new user namespace as well as a privileged user being unable to create the other namespaces if it doesn't have the capabilities to do so in the new user namespace (according to uid/gid maps). This also implies possible complications of calling setns() multiple times for multiple different namespace types - it may be necessary to call it first on the user ns fd (or the other way around?). In addition, there are probably going to be some problems with capability bits when calling execve(2) after doing setns on user ns (see capabilities(7), "Thread capability sets"). > Yes, user namespaces are even bigger PITA than pid namespaces. :) Jiri |
From: Cyril H. <ch...@su...> - 2015-08-27 11:56:20
|
Hi! > On SLES12 (kernel 3.12.28) setns() fails for the fd opened from "user" > namespace. I'm getting EINVAL here. Everything seems to work fine if I > comment the rf |= open_ns_fd(argv[1], "user"); line above. > > Unfortunately EINVAL seems to be catch-all error for setns(), any idea > what is wrong here? And it seems to be the case of: EINVAL The caller attempted to join the user namespace in which it is already a member. Since the ns_create only creates a new network namespace the rest of the namespaces are inherited. At least when I change the ns_create that creates the handle to create new user namespace as well it can succesfully join it. Why do we attempt to join all namespaces in the ns_exec? I guess that we will have to change it to get a list of namespaces to join the same way the ns_create does it. -- Cyril Hrubis ch...@su... |
From: 大漠之鹰 <qia...@12...> - 2015-08-27 11:07:48
|
hello dear: Does ltp support Linux 3.10? I want write a virtual usb device and I wan to reference the tusb module.But when I compile the module on ubuntu 12.04,I get many errors. Now I need your help.Please help me. Thanks very very much. |
From: Cyril H. <ch...@su...> - 2015-08-26 15:06:02
|
Hi! > +static int open_ns_fd(const char *pid, const char *ns) > +{ > + int fd; > + char file_buf[30]; > + > + sprintf(file_buf, "%s/%s/ns/%s", PROC_PATH, pid, ns); > + > + fd = open(file_buf, O_RDONLY); > + if (fd > 0) { > + ns_fd[ns_fd_index] = fd; > + ++ns_fd_index; > + return 0; > + } else if (fd == -1 && errno != ENOENT) { > + tst_resm(TINFO | TERRNO, "open"); > + return -1; > + } > + > + return 0; > +} > + > +static void close_ns_fd(void) > +{ > + int i; > + > + for (i = 0; i < ns_fd_index; i++) > + close(ns_fd[i]); > +} > + > +static int child_fn(void *arg) > +{ > + char **args = (char **)arg; > + > + execvp(args[2], args+2); > + tst_resm(TINFO | TERRNO, "execvp"); > + return 1; > +} > + > +/* > + * ./ns_exec <NS_PID> <PROGRAM> [ARGS] > + */ > +int main(int argc, char *argv[]) > +{ > + int i, rv, pid; > + > + rv = syscall(__NR_setns, -1, 0); > + if (rv == -1 && errno == ENOSYS) { > + tst_resm(TINFO, "setns is not supported in the kernel"); > + return 1; > + } > + > + if (argc < 3) { > + tst_resm(TINFO, "%s <NS_PID> <PROGRAM> [ARGS]\n", argv[0]); > + return 1; > + } > + > + rv = 0; > + memset(ns_fd, 0, sizeof(ns_fd)); > + rv |= open_ns_fd(argv[1], "ipc"); > + rv |= open_ns_fd(argv[1], "mnt"); > + rv |= open_ns_fd(argv[1], "net"); > + rv |= open_ns_fd(argv[1], "pid"); > + rv |= open_ns_fd(argv[1], "user"); > + rv |= open_ns_fd(argv[1], "uts"); > + if (rv != 0) > + return 1; > + > + if (ns_fd_index == 0) { > + tst_resm(TINFO, "no namespace entries in /proc/%s/ns/", > + argv[1]); > + close_ns_fd(); > + return 1; > + } > + > + for (i = 0; i < ns_fd_index; i++) { > + if (syscall(__NR_setns, ns_fd[i], 0) == -1) { > + tst_resm(TINFO | TERRNO, "setns"); > + close_ns_fd(); On SLES12 (kernel 3.12.28) setns() fails for the fd opened from "user" namespace. I'm getting EINVAL here. Everything seems to work fine if I comment the rf |= open_ns_fd(argv[1], "user"); line above. Unfortunately EINVAL seems to be catch-all error for setns(), any idea what is wrong here? -- Cyril Hrubis ch...@su... |
From: Jiri J. <jja...@re...> - 2015-08-25 15:36:50
|
On 08/25/2015 04:46 PM, Matus Marhefka wrote: > * renamed "dummy0" to "dummy_test0" to not collide with existing > interfaces > * added test case which checks that only "localhost" and "dummy" > interfaces are seen in /sys/class/net/ after mounting sysfs > in a new namespace > > Signed-off-by: Matus Marhefka <mma...@re...> > --- > testcases/kernel/containers/netns/netns_sysfs.sh | 39 +++++++++++++++++++----- > 1 file changed, 31 insertions(+), 8 deletions(-) > > diff --git a/testcases/kernel/containers/netns/netns_sysfs.sh b/testcases/kernel/containers/netns/netns_sysfs.sh > index c10fa36..a58495e 100755 > --- a/testcases/kernel/containers/netns/netns_sysfs.sh > +++ b/testcases/kernel/containers/netns/netns_sysfs.sh > @@ -23,13 +23,14 @@ > #============================================================================== > > TCID="netns_sysfs" > -TST_TOTAL=2 > +TST_TOTAL=3 > +DUMMYDEV="dummy_test0" > . test.sh > > cleanup() > { > tst_rmdir > - ip link del dummy0 2>/dev/null > + ip link del $DUMMYDEV 2>/dev/null > kill -9 $NS_HANDLE 2>/dev/null > } > > @@ -43,23 +44,45 @@ TST_CLEANUP=cleanup > ls /sys/class/net >sysfs_before > > > -ns_exec $NS_HANDLE ip link add dummy0 type dummy || \ > +ns_exec $NS_HANDLE ip link add $DUMMYDEV type dummy || \ > tst_brkm TBROK "failed to add a new dummy device" > ns_exec $NS_HANDLE mount -t sysfs none /sys 2>/dev/null > > -ns_exec $NS_HANDLE test -d /sys/class/net/dummy0 > + > +# TEST CASE #1 > +ns_exec $NS_HANDLE test -d "/sys/class/net/$DUMMYDEV" > if [ $? -eq 0 ]; then > - tst_resm TPASS "sysfs in new namespace has dummy0 interface" > + tst_resm TPASS "sysfs in new namespace has $DUMMYDEV interface" > +else > + tst_resm TFAIL "sysfs in new namespace does not have $DUMMYDEV interface" > +fi > + > + > +# TEST CASE #2 > +res=0 > +classnet=$(ns_exec $NS_HANDLE ls /sys/class/net/) > +for d in $classnet; do > + if [ "$d" != "lo" ]; then > + if [ "$d" != $DUMMYDEV ]; then > + tst_resm TINFO "sysfs in new namespace should not contain: $d" > + res=1 > + fi > + fi > +done What about for d in $(ns_exec $NS_HANDLE ls /sys/class/net/); do case "$d" in lo|$DUMMYDEV) ;; *) tst_resm TINFO "sysfs in new namespace should not contain: $d" res=1 ;; esac done ? > +if [ $res -eq 0 ]; then > + tst_resm TPASS "sysfs in new namespace has only lo and $DUMMYDEV interfaces" > else > - tst_resm TFAIL "sysfs in new namespace does not have dummy0 interface" > + tst_resm TFAIL "sysfs in new namespace has more than lo and $DUMMYDEV interfaces" > fi > > + > +# TEST CASE #3 > ls /sys/class/net >sysfs_after > diff sysfs_before sysfs_after > if [ $? -eq 0 ]; then > - tst_resm TPASS "sysfs not affected by a separate namespace" > + tst_resm TPASS "main sysfs not affected by a separate namespace" > else > - tst_resm TFAIL "sysfs affected by a separate namespace" > + tst_resm TFAIL "main sysfs affected by a separate namespace" > fi > > tst_exit > |
From: Matus M. <mma...@re...> - 2015-08-25 14:46:16
|
* renamed "dummy0" to "dummy_test0" to not collide with existing interfaces * added test case which checks that only "localhost" and "dummy" interfaces are seen in /sys/class/net/ after mounting sysfs in a new namespace Signed-off-by: Matus Marhefka <mma...@re...> --- testcases/kernel/containers/netns/netns_sysfs.sh | 39 +++++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/testcases/kernel/containers/netns/netns_sysfs.sh b/testcases/kernel/containers/netns/netns_sysfs.sh index c10fa36..a58495e 100755 --- a/testcases/kernel/containers/netns/netns_sysfs.sh +++ b/testcases/kernel/containers/netns/netns_sysfs.sh @@ -23,13 +23,14 @@ #============================================================================== TCID="netns_sysfs" -TST_TOTAL=2 +TST_TOTAL=3 +DUMMYDEV="dummy_test0" . test.sh cleanup() { tst_rmdir - ip link del dummy0 2>/dev/null + ip link del $DUMMYDEV 2>/dev/null kill -9 $NS_HANDLE 2>/dev/null } @@ -43,23 +44,45 @@ TST_CLEANUP=cleanup ls /sys/class/net >sysfs_before -ns_exec $NS_HANDLE ip link add dummy0 type dummy || \ +ns_exec $NS_HANDLE ip link add $DUMMYDEV type dummy || \ tst_brkm TBROK "failed to add a new dummy device" ns_exec $NS_HANDLE mount -t sysfs none /sys 2>/dev/null -ns_exec $NS_HANDLE test -d /sys/class/net/dummy0 + +# TEST CASE #1 +ns_exec $NS_HANDLE test -d "/sys/class/net/$DUMMYDEV" if [ $? -eq 0 ]; then - tst_resm TPASS "sysfs in new namespace has dummy0 interface" + tst_resm TPASS "sysfs in new namespace has $DUMMYDEV interface" +else + tst_resm TFAIL "sysfs in new namespace does not have $DUMMYDEV interface" +fi + + +# TEST CASE #2 +res=0 +classnet=$(ns_exec $NS_HANDLE ls /sys/class/net/) +for d in $classnet; do + if [ "$d" != "lo" ]; then + if [ "$d" != $DUMMYDEV ]; then + tst_resm TINFO "sysfs in new namespace should not contain: $d" + res=1 + fi + fi +done +if [ $res -eq 0 ]; then + tst_resm TPASS "sysfs in new namespace has only lo and $DUMMYDEV interfaces" else - tst_resm TFAIL "sysfs in new namespace does not have dummy0 interface" + tst_resm TFAIL "sysfs in new namespace has more than lo and $DUMMYDEV interfaces" fi + +# TEST CASE #3 ls /sys/class/net >sysfs_after diff sysfs_before sysfs_after if [ $? -eq 0 ]; then - tst_resm TPASS "sysfs not affected by a separate namespace" + tst_resm TPASS "main sysfs not affected by a separate namespace" else - tst_resm TFAIL "sysfs affected by a separate namespace" + tst_resm TFAIL "main sysfs affected by a separate namespace" fi tst_exit -- 1.8.3.1 |
From: Alexey K. <ale...@or...> - 2015-08-25 13:34:26
|
On 08/25/2015 02:18 PM, Cyril Hrubis wrote: > Hi! >> Can we apply this patch before release? > Sure, acked. > > (I wonder how we missed that in the review...) > Yeah, I was surprised as well. Patch applied. Thanks, Alexey |
From: Cyril H. <ch...@su...> - 2015-08-25 11:29:56
|
Hi! > Interesting, probably SRCU is much slower with this older kernel. From my > experiments 100 iterations isn't quite reliable to trigger the oops in my > testing instance. But 400 seem to be good enough. I've changed the nuber of iterations to 400 and pushed it to git, thanks. -- Cyril Hrubis ch...@su... |
From: Cyril H. <ch...@su...> - 2015-08-25 11:18:59
|
Hi! > Can we apply this patch before release? Sure, acked. (I wonder how we missed that in the review...) -- Cyril Hrubis ch...@su... |
From: Jan K. <ja...@su...> - 2015-08-25 10:38:16
|
Hi! On Tue 25-08-15 11:29:25, Cyril Hrubis wrote: > I've just started pre-release LTP testing and found out that the test > timeouts (after an half of hour) on an 3.0.101 kernel. > > It looks like one iteration takes 0.2s there and the test would need > > 5 hours to finish. Can we reduce the number of TEARDOWNs to 100 so that > it finishes in 20 seconds? Interesting, probably SRCU is much slower with this older kernel. From my experiments 100 iterations isn't quite reliable to trigger the oops in my testing instance. But 400 seem to be good enough. Honza -- Jan Kara <ja...@su...> SUSE Labs, CR |
From: Alexey K. <ale...@or...> - 2015-08-25 10:36:07
|
Hi Cyril, Can we apply this patch before release? Thanks, Alexey On 08/25/2015 11:51 AM, Alexey Kodanev wrote: > Signed-off-by: Alexey Kodanev <ale...@or...> > --- > testcases/network/tcp_fastopen/tcp_fastopen.c | 4 ++-- > 1 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/testcases/network/tcp_fastopen/tcp_fastopen.c b/testcases/network/tcp_fastopen/tcp_fastopen.c > index 6c0d7b8..08a6019 100644 > --- a/testcases/network/tcp_fastopen/tcp_fastopen.c > +++ b/testcases/network/tcp_fastopen/tcp_fastopen.c > @@ -669,7 +669,7 @@ static void check_opt(const char *name, char *arg, int *val, int lim) > if (sscanf(arg, "%i", val) != 1) > tst_brkm(TBROK, NULL, "-%s option arg is not a number", > name); > - if (clients_num < lim) > + if (*val < lim) > tst_brkm(TBROK, NULL, "-%s option arg is less than %d", > name, lim); > } > @@ -681,7 +681,7 @@ static void check_opt_l(const char *name, char *arg, long *val, long lim) > if (sscanf(arg, "%ld", val) != 1) > tst_brkm(TBROK, NULL, "-%s option arg is not a number", > name); > - if (clients_num < lim) > + if (*val < lim) > tst_brkm(TBROK, NULL, "-%s option arg is less than %ld", > name, lim); > } |
From: Cyril H. <ch...@su...> - 2015-08-25 09:30:01
|
Hi! I've just started pre-release LTP testing and found out that the test timeouts (after an half of hour) on an 3.0.101 kernel. It looks like one iteration takes 0.2s there and the test would need > 5 hours to finish. Can we reduce the number of TEARDOWNs to 100 so that it finishes in 20 seconds? -- Cyril Hrubis ch...@su... |
From: Alexey K. <ale...@or...> - 2015-08-25 08:48:25
|
Signed-off-by: Alexey Kodanev <ale...@or...> --- testcases/network/tcp_fastopen/tcp_fastopen.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/testcases/network/tcp_fastopen/tcp_fastopen.c b/testcases/network/tcp_fastopen/tcp_fastopen.c index 6c0d7b8..08a6019 100644 --- a/testcases/network/tcp_fastopen/tcp_fastopen.c +++ b/testcases/network/tcp_fastopen/tcp_fastopen.c @@ -669,7 +669,7 @@ static void check_opt(const char *name, char *arg, int *val, int lim) if (sscanf(arg, "%i", val) != 1) tst_brkm(TBROK, NULL, "-%s option arg is not a number", name); - if (clients_num < lim) + if (*val < lim) tst_brkm(TBROK, NULL, "-%s option arg is less than %d", name, lim); } @@ -681,7 +681,7 @@ static void check_opt_l(const char *name, char *arg, long *val, long lim) if (sscanf(arg, "%ld", val) != 1) tst_brkm(TBROK, NULL, "-%s option arg is not a number", name); - if (clients_num < lim) + if (*val < lim) tst_brkm(TBROK, NULL, "-%s option arg is less than %ld", name, lim); } -- 1.7.1 |