All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v7 1/7] lib6: Remove runcc.* and the testcases that use it.
@ 2015-10-07 10:47 Zeng Linggang
  2015-10-07 10:47 ` [LTP] [PATCH v7 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
                   ` (5 more replies)
  0 siblings, 6 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-07 10:47 UTC (permalink / raw)
  To: ltp

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 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


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v7 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-10-07 10:47 [LTP] [PATCH v7 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
@ 2015-10-07 10:47 ` Zeng Linggang
  2015-10-07 13:07   ` Cyril Hrubis
  2015-10-07 13:28   ` Cyril Hrubis
  2015-10-07 10:47 ` [LTP] [PATCH v7 3/7] lib6/asapi_04.c: Cleanup Zeng Linggang
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-07 10:47 UTC (permalink / raw)
  To: ltp

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 include/safe_macros.h |   1 +
 include/safe_net.h    |  60 +++++++++++++++++
 lib/safe_net.c        | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 244 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..dc5da27
--- /dev/null
+++ b/include/safe_net.h
@@ -0,0 +1,60 @@
+/*
+ * 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>
+#include <sys/un.h>
+
+char *ltp_sock_addr(const struct sockaddr *sa, socklen_t salen);
+#define LTP_SOCK_ADDR(sa, salen)	ltp_sock_addr(sa, salen)
+
+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..395752f
--- /dev/null
+++ b/lib/safe_net.c
@@ -0,0 +1,183 @@
+/*
+ * 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"
+
+char *ltp_sock_addr(const struct sockaddr *sa, socklen_t salen)
+{
+	char portstr[8];
+	static char str[128];
+
+	switch (sa->sa_family) {
+
+	case AF_INET: {
+		struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+
+		if (!inet_ntop(AF_INET, &sin->sin_addr, str, sizeof(str)))
+			return NULL;
+
+		if (ntohs(sin->sin_port) != 0) {
+			snprintf(portstr, sizeof(portstr), ":%d",
+				 ntohs(sin->sin_port));
+			strcat(str, portstr);
+		}
+
+		return str;
+	}
+
+	case AF_INET6: {
+		struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
+
+		str[0] = '[';
+		if (!inet_ntop(AF_INET6, &sin6->sin6_addr, str + 1,
+			       sizeof(str) - 1))
+			return NULL;
+
+		if (ntohs(sin6->sin6_port) != 0) {
+			snprintf(portstr, sizeof(portstr), "]:%d",
+				 ntohs(sin6->sin6_port));
+			strcat(str, portstr);
+			return str;
+		}
+
+		return str + 1;
+	}
+
+	case AF_UNIX: {
+		struct sockaddr_un *unp = (struct sockaddr_un *)sa;
+
+		if (unp->sun_path[0] == '\0')
+			strcpy(str, "(no pathname bound)");
+		else
+			snprintf(str, sizeof(str), "%s", unp->sun_path);
+
+		return str;
+	}
+
+	default: {
+		snprintf(str, sizeof(str),
+			 "sock_ntop: unknown AF_xxx: %d, len: %d",
+			 sa->sa_family, salen);
+
+		return str;
+	}
+
+	}
+
+	return NULL;
+}
+
+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, LTP_SOCK_ADDR(address, address_len),
+				 address_len);
+		}
+
+		if ((i + 1) % 10 == 0) {
+			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, %s, %d) after 120 retries", file,
+		 lineno, socket, LTP_SOCK_ADDR(address, address_len),
+		 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, LTP_SOCK_ADDR(addr, addrlen), 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, %d) failed", file, lineno,
+			 sockfd, LTP_SOCK_ADDR(addr, *addrlen), *addrlen);
+	}
+
+	return rval;
+}
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v7 3/7] lib6/asapi_04.c: Cleanup
  2015-10-07 10:47 [LTP] [PATCH v7 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
  2015-10-07 10:47 ` [LTP] [PATCH v7 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
@ 2015-10-07 10:47 ` Zeng Linggang
  2015-10-07 10:47 ` [LTP] [PATCH v7 4/7] lib6/asapi_05.c: Cleanup Zeng Linggang
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-07 10:47 UTC (permalink / raw)
  To: ltp

* Add 'static' before some functions and global variables.
* Remove useless comments.
* Use SAFE_XXX().
* Modify the format of ptab[] and cstab[].
* Use 'pthread_join()' instead of 'sem_*'.
* Rewrite 'csum_test()' and 'isocketpair()'.
* Remove cleanup().
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_04.c | 301 +++++++++++++++-----------------------
 1 file changed, 117 insertions(+), 184 deletions(-)

diff --git a/testcases/network/lib6/asapi_04.c b/testcases/network/lib6/asapi_04.c
index 76de26b..df26494 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,33 @@
 #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 READ_TIMEOUT	5	/* secs */
+#define PTCOUNT		ARRAY_SIZE(ptab)
+#define READ_TIMEOUT	5
 
-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 csum_test(void);
 
 int main(int argc, char *argv[])
 {
@@ -82,52 +65,48 @@ int main(int argc, char *argv[])
 
 	tst_parse_opts(argc, argv, 0, 0);
 
-	pid = getpid();
-
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); ++lc)
 		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;
+			rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
+			a2.s6_addr32[word] |= newbit;
+			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 +120,7 @@ void do_tests(void)
 			 ptab[i].prt_name);
 	}
 /* RFC 3542, Section 3.1 */
-	csum_test("::1");
+	csum_test();
 }
 
 /*
@@ -162,10 +141,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 +152,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)
 
-static int recvtprot(int sd, unsigned char *packet, int psize)
+int TST_TOTAL = PTCOUNT + CSCOUNT;
+
+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;
@@ -210,15 +188,17 @@ static int recvtprot(int sd, unsigned char *packet, int psize)
 				gothead = 1;
 				expected += ntohl(tpt->tp_dlen);
 			}
-		} else
+		} else {
 			break;
+		}
 	}
 	if (cc < 0)
 		return cc;
 	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 +214,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 +222,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 +240,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;
@@ -322,9 +300,9 @@ static int client(int prot, int sfd)
 				 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 +312,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;
@@ -356,99 +334,60 @@ 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);
-	sem_post(&ilsem);
 	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;
 	socklen_t namelen;
 
-/* restrict to PF_INET for now */
-	if (pf != PF_INET) {
-		errno = EOPNOTSUPP;
-		return -1;
-	}
-	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;
-	}
-	sem_wait(&ilsem);
+
+	SAFE_CONNECT(NULL, fd[0], (struct sockaddr *)&sin4, sizeof(sin4));
+
+	pthread_join(thid, NULL);
+
 	fd[1] = connect_fd;
-	sem_destroy(&ilsem);
-	return 0;
 }
 
 #ifndef MAX
 #define MAX(a, b) (@ >= (b) ? (a) : (b))
 #endif /* MAX */
 
-int csum_test(char *rhost)
+static void 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 +396,16 @@ 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]);
+		client(csd[0]);
+		return;
 	}
 
 	tv.tv_sec = READ_TIMEOUT;
@@ -478,7 +417,7 @@ int csum_test(char *rhost)
 			exit(0);
 		} else if (nfds == 0) {
 			fprintf(stderr, "server read timed out");
-			return -1;
+			return;
 		}
 		if (FD_ISSET(sd, &rset)) {
 			static char packet[2048];
@@ -499,9 +438,8 @@ int csum_test(char *rhost)
 			char buf[2048];
 
 			cc = read(csd[1], buf, sizeof(buf));
-			if (cc == 0) {
+			if (cc == 0)
 				exit(0);
-			}
 			if (cc < 0) {
 				perror("server read");
 				exit(1);
@@ -512,16 +450,11 @@ int csum_test(char *rhost)
 		tv.tv_sec = READ_TIMEOUT;
 		tv.tv_usec = 0;
 	}
-	return 0;
 }
 
-void setup(void)
+static void setup(void)
 {
-	TEST_PAUSE;		/* if -P option specified */
-}
+	TEST_PAUSE;
 
-void cleanup(void)
-{
+	pid = getpid();
 }
-
-int TST_TOTAL = PTCOUNT + CSCOUNT;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v7 4/7] lib6/asapi_05.c: Cleanup
  2015-10-07 10:47 [LTP] [PATCH v7 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
  2015-10-07 10:47 ` [LTP] [PATCH v7 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
  2015-10-07 10:47 ` [LTP] [PATCH v7 3/7] lib6/asapi_04.c: Cleanup Zeng Linggang
@ 2015-10-07 10:47 ` Zeng Linggang
  2015-10-07 10:47 ` [LTP] [PATCH v7 5/7] lib6/asapi_06.c: Cleanup Zeng Linggang
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-07 10:47 UTC (permalink / raw)
  To: ltp

* Add 'static' before some functions and global variables.
* Remove cleanup().
* Remove useless comments.
* Use SAFE_XXX().
* Modify the format of etab[] and ftab[].
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_05.c | 159 ++++++++++++++------------------------
 1 file changed, 60 insertions(+), 99 deletions(-)

diff --git a/testcases/network/lib6/asapi_05.c b/testcases/network/lib6/asapi_05.c
index e251eee..f8c30f1 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,74 @@
 #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);
 
-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();
 }
 
-void cleanup(void)
-{
-}
-
-/*
- * 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 +113,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 +156,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 +167,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 +182,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 +197,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;
 
@@ -284,8 +246,9 @@ void icmp6_ft(void)
 			if (ic6_send1(ftab[i].ft_tname, ftab[i].ft_sndtype))
 				continue;
 			rv = ic6_recv1(ftab[i].ft_tname, sall, sf);
-		} else
+		} else {
 			rv = -1;
+		}
 
 		if (rv < 0)
 			continue;
@@ -296,5 +259,3 @@ void icmp6_ft(void)
 			tst_resm(TPASS, "%s", ftab[i].ft_tname);
 	}
 }
-
-int TST_TOTAL = FTCOUNT;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v7 5/7] lib6/asapi_06.c: Cleanup
  2015-10-07 10:47 [LTP] [PATCH v7 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                   ` (2 preceding siblings ...)
  2015-10-07 10:47 ` [LTP] [PATCH v7 4/7] lib6/asapi_05.c: Cleanup Zeng Linggang
@ 2015-10-07 10:47 ` Zeng Linggang
  2015-10-07 10:47 ` [LTP] [PATCH v7 6/7] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
  2015-10-07 10:47 ` [LTP] [PATCH v7 7/7] ipv6_lib: Add it into default Zeng Linggang
  5 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-07 10:47 UTC (permalink / raw)
  To: ltp

* Add 'static' before some functions and global variables.
* Remove cleanup().
* Remove useless comments.
* Use SAFE_XXX().
* Remove unused variables.
* Modify the format of sotab[] and cmtab[].
* Modify the initialization of sotab[].
* Remove IPV6_PKTINFO test. IPV6_PKTINFO is only implemented
  by setsockopt() not by getsockopt(). see:
  https://github.com/torvalds/linux/commit/b24a2516d10751d7ed5afb58420df25370c9dffb
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_06.c | 473 ++++++++------------------------------
 1 file changed, 99 insertions(+), 374 deletions(-)

diff --git a/testcases/network/lib6/asapi_06.c b/testcases/network/lib6/asapi_06.c
index 960ebb5..c6e2c8e 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,16 @@
 #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]))
-
 #define READ_TIMEOUT	5	/* secs */
 
-void do_tests(void);
-void setup(void), cleanup(void);
+static void do_tests(void);
+static void setup(void);
 
 int main(int argc, char *argv[])
 {
@@ -83,14 +58,11 @@ int main(int argc, char *argv[])
 
 	tst_parse_opts(argc, argv, NULL, NULL);
 
-	pid = getpid();
-
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); ++lc)
 		do_tests();
 
-	cleanup();
 	tst_exit();
 }
 
@@ -150,7 +122,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 +132,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 +186,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 +237,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;
@@ -300,63 +246,51 @@ void so_test(struct soent *psoe)
 	int st;
 
 	if (psoe->so_opt == -1) {
-		tst_resm(TBROK, "%s not present at compile time",
+		tst_brkm(TBROK | TERRNO, NULL, "%s not present at compile time",
 			 psoe->so_tname);
-		return;
 	}
 	if (psoe->so_clear || sr < 0) {
 		if (sr < 0)
 			close(sr);
-		sr = socket(PF_INET6, SOCK_RAW, NH_TEST);
-		if (sr < 0) {
-			tst_resm(TBROK, "%s socket: %s", psoe->so_tname,
-				 strerror(errno));
-			return;
-		}
+		sr = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
 	}
 	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,
-			 strerror(errno));
-		return;
+		tst_brkm(TBROK | TERRNO, NULL, "%s: setsockopt",
+			 psoe->so_tname);
 	}
+
 	TEST(setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_setval,
 			psoe->so_valsize));
 	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL, "%s set-get: setsockopt: %s", psoe->so_tname,
-			 strerror(errno));
+		tst_resm(TFAIL | TERRNO, "%s set-get: setsockopt",
+			 psoe->so_tname);
 		return;
 	}
+
 	valsize = psoe->so_valsize;
 	TEST(getsockopt(sr, SOL_IPV6, psoe->so_opt, &sobuf, &valsize));
 	if (TEST_RETURN != 0) {
-		tst_resm(TBROK, "%s set-get: getsockopt: %s", psoe->so_tname,
-			 strerror(errno));
-		return;
-	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize))
+		tst_brkm(TBROK | TERRNO, NULL, "%s set-get: getsockopt",
+			 psoe->so_tname);
+	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize)) {
 		tst_resm(TFAIL, "%s set-get optval != setval", psoe->so_tname);
-	else
+	} 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;
-	}
-	if (sendall(st) < 0) {
-		tst_resm(TBROK, "%s transmit sendto: %s", psoe->so_tname,
-			 strerror(errno));
-		close(st);
-		return;
 	}
+
+	st = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
+	if (sendall(st) < 0)
+		tst_brkm(TBROK | TERRNO, NULL, "%s transmit sendto",
+			 psoe->so_tname);
+
 	close(st);
 
 	/* receiver processing */
@@ -382,12 +316,11 @@ void so_test(struct soent *psoe)
 			if (nfds < 0) {
 				if (errno == EINTR)
 					continue;
-				tst_resm(TBROK, "%s select: %s", psoe->so_tname,
-					 strerror(errno));
-				return;
+				tst_brkm(TBROK | TERRNO, NULL, "%s select",
+					 psoe->so_tname);
 			}
 			if (nfds == 0) {
-				tst_resm(TBROK, "%s recvmsg timed out",
+				tst_brkm(TBROK, NULL, "%s recvmsg timed out",
 					 psoe->so_tname);
 				return;
 			}
@@ -405,11 +338,10 @@ void so_test(struct soent *psoe)
 
 			cc = recvmsg(sr, &msg, 0);
 			if (cc < 0) {
-				tst_resm(TBROK, "%s recvmsg: %s",
-					 psoe->so_tname, strerror(errno));
-				return;
+				tst_brkm(TBROK | TERRNO, NULL, "%s recvmsg",
+					 psoe->so_tname);
 			}
-/* check pid & seq here */
+			/* check pid & seq here */
 			break;
 		}
 		gotone = 0;
@@ -419,9 +351,9 @@ void so_test(struct soent *psoe)
 				break;
 			gotone = pcmsg->cmsg_level == SOL_IPV6 &&
 			    pcmsg->cmsg_type == psoe->so_cmtype;
-			if (gotone)
+			if (gotone) {
 				break;
-			else if (psoe->so_clear) {
+			} else if (psoe->so_clear) {
 				tst_resm(TFAIL, "%s receive: extraneous data "
 					 "in control: level %d type %d len %zu",
 					 psoe->so_tname, pcmsg->cmsg_level,
@@ -429,232 +361,25 @@ 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);
 	}
 }
 
-#define IPV6_ADDR_NODE		1
-#define IPV6_ADDR_LINK		2
-#define IPV6_ADDR_GLOBAL	3
-
-#ifdef HAVE_IFADDRS_H
-static int ipv6_addr_scope(struct in6_addr *pin6)
-{
-	if ((ntohl(pin6->s6_addr32[0]) & 0xFFC00000) == 0xFE800000)
-		return IPV6_ADDR_LINK;
-	if (memcmp(pin6, &in6addr_loopback, sizeof(*pin6)) == 0)
-		return IPV6_ADDR_NODE;
-	return IPV6_ADDR_GLOBAL;
-}
-#endif /* HAVE_IFADDRS_H */
-
-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 (psin6_arg)
-		ifindex = psin6_arg->sin6_scope_id;
-
-	/* first, find a global address */
-	for (pifa = pifa_head; pifa; pifa = pifa->ifa_next) {
-		int this_scope;
-
-		if (!(pifa->ifa_flags & IFF_UP))
-			continue;
-		if (pifa->ifa_addr->sa_family != AF_INET6)
-			continue;
-		psin6 = (struct sockaddr_in6 *)pifa->ifa_addr;
-		this_scope = ipv6_addr_scope(&psin6->sin6_addr);
-		if (this_scope &&
-		    ((this_scope < 0 && -this_scope == 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))
-			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;
-		}
-		if (psin6_arg) {
-			*psin6_arg = *psin6;
-			psin6_arg->sin6_scope_id =
-			    if_nametoindex(pifa->ifa_name);
-		}
-		return s;
-	}
-	{
-		char *scopestr, *intfstr;
-
-		switch (scope) {
-		case IPV6_ADDR_NODE:
-			scopestr = " node-local";
-			break;
-		case IPV6_ADDR_LINK:
-			scopestr = " link-local";
-			break;
-		case IPV6_ADDR_GLOBAL:
-			scopestr = " global";
-			break;
-		default:
-			scopestr = "";
-			break;
-		}
-		if (ifindex < 0) {
-			intfstr = " not on ifindex";
-			ifindex = -ifindex;
-		} else if (ifindex)
-			intfstr = " on ifindex";
-		else
-			intfstr = 0;
-
-		if (intfstr)
-			tst_resm(TBROK, "%s: getsock : no%s addresses%s %d",
-				 tname, scopestr, intfstr, ifindex);
-		else
-			tst_resm(TBROK, "%s: getsock : no%s addresses",
-				 tname, scopestr);
-	}
-	return -1;
-#else /* HAVE_IFADDRS_H */
-	return -1;
-#endif
-}
-
-#ifdef notyet
-/*
- * 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)
-{
-	int s_snd, s_rcv[3] = { -1, -1, -1 };
-	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;
-
-	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;
-	}
-	/* 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;
-	}
-	/* 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;
-	}
-	/* send to rcv1 to verify communication */
-	/* force to rcv2 w/ PKTINFO */
-/* TESTS: */
-/* sticky set-get */
-	tname = "IPV6_PKTINFO set";
-	pi.ipi6_addr = sa_rcv[1].sin6_addr;
-	pi.ipi6_ifindex = sa_rcv[1].sin6_scope_id;
-	TEST(setsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi, sizeof(pi)));
-	if (TEST_RETURN != 0)
-		tst_resm(TFAIL, "%s: %s", tname, strerror(errno));
-	else
-		tst_resm(TPASS, "%s", tname);
-
-	tname = "IPV6_PKTINFO get";
-	optlen = sizeof(pi_tmp);
-	TEST(getsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi_tmp, &optlen));
-	if (TEST_RETURN != 0)
-		tst_resm(TFAIL, "%s: %s", tname, strerror(errno));
-	else if (memcmp(&pi, &pi_tmp, sizeof(pi)) != 0) {
-		char strbuf2[64];
-		tst_resm(TFAIL, "%s: {\"%s\",%d} != {\"%s\",%d}", tname,
-			 inet_ntop(AF_INET6, &pi_tmp.ipi6_addr, strbuf,
-				   sizeof(strbuf)), pi_tmp.ipi6_ifindex,
-			 inet_ntop(AF_INET6, &pi.ipi6_addr, strbuf2,
-				   sizeof(strbuf2)), pi.ipi6_ifindex);
-	} else
-		tst_resm(TPASS, "%s", tname);
-/* 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;
-	TEST(setsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi, sizeof(pi)));
-	if (TEST_RETURN == 0)
-		tst_resm(TFAIL, "%s returns success, should be -1, EINVAL",
-			 tname);
-	else if (TEST_ERRNO != EINVAL)
-		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;
 		sotab[i].so_setval.sou_bool = 1;
 		so_test(&sotab[i]);
 	}
-#ifdef notyet
-	test_pktinfo();
-#endif /* notyet - see test_pktinfo() comment above */
-}
-
-void setup(void)
-{
-	TEST_PAUSE;		/* if -P option specified */
 }
 
-void cleanup(void)
+static void setup(void)
 {
+	TEST_PAUSE;
 }
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v7 6/7] lib6/getaddrinfo_01.c: Cleanup
  2015-10-07 10:47 [LTP] [PATCH v7 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                   ` (3 preceding siblings ...)
  2015-10-07 10:47 ` [LTP] [PATCH v7 5/7] lib6/asapi_06.c: Cleanup Zeng Linggang
@ 2015-10-07 10:47 ` Zeng Linggang
  2015-10-07 10:47 ` [LTP] [PATCH v7 7/7] ipv6_lib: Add it into default Zeng Linggang
  5 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-07 10:47 UTC (permalink / raw)
  To: ltp

* 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 <zenglg.jy@cn.fujitsu.com>
---
 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


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v7 7/7] ipv6_lib: Add it into default
  2015-10-07 10:47 [LTP] [PATCH v7 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                   ` (4 preceding siblings ...)
  2015-10-07 10:47 ` [LTP] [PATCH v7 6/7] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
@ 2015-10-07 10:47 ` Zeng Linggang
  5 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-07 10:47 UTC (permalink / raw)
  To: ltp

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 scenario_groups/default | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scenario_groups/default b/scenario_groups/default
index 3a55702..60b1b27 100644
--- a/scenario_groups/default
+++ b/scenario_groups/default
@@ -32,3 +32,4 @@ dma_thread_diotest
 cpuacct
 can
 cpuhotplug
+ipv6_lib
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v7 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-10-07 10:47 ` [LTP] [PATCH v7 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
@ 2015-10-07 13:07   ` Cyril Hrubis
  2015-10-08  1:34     ` Zeng Linggang
  2015-10-07 13:28   ` Cyril Hrubis
  1 sibling, 1 reply; 38+ messages in thread
From: Cyril Hrubis @ 2015-10-07 13:07 UTC (permalink / raw)
  To: ltp

Hi!
> +char *ltp_sock_addr(const struct sockaddr *sa, socklen_t salen);
> +#define LTP_SOCK_ADDR(sa, salen)	ltp_sock_addr(sa, salen)

Why do we define the LTP_SOCK_ADDR() as a macro?

As far as I can see it's does not add any value over calling the
function.

Also we tend to prefix LTP internal funciton with tst_ rather than ltp_
but that is minor.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v7 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-10-07 10:47 ` [LTP] [PATCH v7 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
  2015-10-07 13:07   ` Cyril Hrubis
@ 2015-10-07 13:28   ` Cyril Hrubis
  2015-10-08 11:29     ` [LTP] [PATCH v8 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
  1 sibling, 1 reply; 38+ messages in thread
From: Cyril Hrubis @ 2015-10-07 13:28 UTC (permalink / raw)
  To: ltp

Hi!
> +char *ltp_sock_addr(const struct sockaddr *sa, socklen_t salen)
> +{
> +	char portstr[8];
> +	static char str[128];

Also this is not thread safe and the testcases that use these fucntions
run in several threads. Even if the race condition where two threads
write to the str buffer at the same time is unlikely we should rather
change the interface to print the result into user supplied buffer.

So it reads:

char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen,
                    char *res, size_t res_len);


And the caller would just define array and pass it to the function as:


char buf[128];

...
	tst_resm(..., tst_sock_addr(sa, salen, buf, sizeof(buf)), ...);

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v7 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-10-07 13:07   ` Cyril Hrubis
@ 2015-10-08  1:34     ` Zeng Linggang
  0 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-08  1:34 UTC (permalink / raw)
  To: ltp

Hi,

On Wed, 2015-10-07 at 15:07 +0200, Cyril Hrubis wrote:
> Hi!
> > +char *ltp_sock_addr(const struct sockaddr *sa, socklen_t salen);
> > +#define LTP_SOCK_ADDR(sa, salen)	ltp_sock_addr(sa, salen)
> 
> Why do we define the LTP_SOCK_ADDR() as a macro?
> 

Indeed, it is not necessary.

> As far as I can see it's does not add any value over calling the
> function.
> 
> Also we tend to prefix LTP internal funciton with tst_ rather than ltp_
> but that is minor.

OK, I got it.

Thanks for your review.

Best regards,
Zeng
> 



^ permalink raw reply	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v8 1/7] lib6: Remove runcc.* and the testcases that use it.
  2015-10-07 13:28   ` Cyril Hrubis
@ 2015-10-08 11:29     ` Zeng Linggang
  2015-10-08 11:29       ` [LTP] [PATCH v8 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
                         ` (5 more replies)
  0 siblings, 6 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-08 11:29 UTC (permalink / raw)
  To: ltp

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 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


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v8 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-10-08 11:29     ` [LTP] [PATCH v8 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
@ 2015-10-08 11:29       ` Zeng Linggang
  2015-10-13 10:45         ` Alexey Kodanev
  2015-10-08 11:29       ` [LTP] [PATCH v8 3/7] lib6/asapi_04.c: Cleanup Zeng Linggang
                         ` (4 subsequent siblings)
  5 siblings, 1 reply; 38+ messages in thread
From: Zeng Linggang @ 2015-10-08 11:29 UTC (permalink / raw)
  To: ltp

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 include/safe_macros.h |   1 +
 include/safe_net.h    |  60 ++++++++++++++++
 lib/safe_net.c        | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 250 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..2f8811c
--- /dev/null
+++ b/include/safe_net.h
@@ -0,0 +1,60 @@
+/*
+ * 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>
+#include <sys/un.h>
+
+char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen, char *res,
+		    size_t len);
+
+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..5703b59
--- /dev/null
+++ b/lib/safe_net.c
@@ -0,0 +1,189 @@
+/*
+ * 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"
+
+char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen, char *res,
+		    size_t len)
+{
+	char portstr[8];
+
+	switch (sa->sa_family) {
+
+	case AF_INET: {
+		struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+
+		if (!inet_ntop(AF_INET, &sin->sin_addr, res, len))
+			return NULL;
+
+		if (ntohs(sin->sin_port) != 0) {
+			snprintf(portstr, sizeof(portstr), ":%d",
+				 ntohs(sin->sin_port));
+			strcat(res, portstr);
+		}
+
+		return res;
+	}
+
+	case AF_INET6: {
+		struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
+
+		res[0] = '[';
+		if (!inet_ntop(AF_INET6, &sin6->sin6_addr, res + 1, len - 1))
+			return NULL;
+
+		if (ntohs(sin6->sin6_port) != 0) {
+			snprintf(portstr, sizeof(portstr), "]:%d",
+				 ntohs(sin6->sin6_port));
+			strcat(res, portstr);
+			return res;
+		}
+
+		return res + 1;
+	}
+
+	case AF_UNIX: {
+		struct sockaddr_un *unp = (struct sockaddr_un *)sa;
+
+		if (unp->sun_path[0] == '\0')
+			strcpy(res, "(no pathname bound)");
+		else
+			snprintf(res, len, "%s", unp->sun_path);
+
+		return res;
+	}
+
+	default: {
+		snprintf(res, len,
+			 "sock_ntop: unknown AF_xxx: %d, len: %d",
+			 sa->sa_family, salen);
+
+		return res;
+	}
+
+	}
+
+	return NULL;
+}
+
+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;
+	char buf[128];
+
+	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, tst_sock_addr(address, address_len,
+						       buf, sizeof(buf)),
+				 address_len);
+		}
+
+		if ((i + 1) % 10 == 0) {
+			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, %s, %d) after 120 retries", file,
+		 lineno, socket,
+		 tst_sock_addr(address, address_len, buf, sizeof(buf)),
+		 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;
+	char buf[128];
+
+	rval = connect(sockfd, addr, addrlen);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: connect(%d, %s, %d) failed", file, lineno,
+			 sockfd, tst_sock_addr(addr, addrlen, buf,
+					       sizeof(buf)), 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;
+	char buf[128];
+
+	rval = getsockname(sockfd, addr, addrlen);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: getsockname(%d, %s, %d) failed", file, lineno,
+			 sockfd, tst_sock_addr(addr, *addrlen, buf,
+					       sizeof(buf)), *addrlen);
+	}
+
+	return rval;
+}
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v8 3/7] lib6/asapi_04.c: Cleanup
  2015-10-08 11:29     ` [LTP] [PATCH v8 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
  2015-10-08 11:29       ` [LTP] [PATCH v8 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
@ 2015-10-08 11:29       ` Zeng Linggang
  2015-10-08 11:29       ` [LTP] [PATCH v8 4/7] lib6/asapi_05.c: Cleanup Zeng Linggang
                         ` (3 subsequent siblings)
  5 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-08 11:29 UTC (permalink / raw)
  To: ltp

* Add 'static' before some functions and global variables.
* Remove useless comments.
* Use SAFE_XXX().
* Modify the format of ptab[] and cstab[].
* Use 'pthread_join()' instead of 'sem_*'.
* Rewrite 'csum_test()' and 'isocketpair()'.
* Remove cleanup().
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_04.c | 301 +++++++++++++++-----------------------
 1 file changed, 117 insertions(+), 184 deletions(-)

diff --git a/testcases/network/lib6/asapi_04.c b/testcases/network/lib6/asapi_04.c
index 76de26b..df26494 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,33 @@
 #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 READ_TIMEOUT	5	/* secs */
+#define PTCOUNT		ARRAY_SIZE(ptab)
+#define READ_TIMEOUT	5
 
-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 csum_test(void);
 
 int main(int argc, char *argv[])
 {
@@ -82,52 +65,48 @@ int main(int argc, char *argv[])
 
 	tst_parse_opts(argc, argv, 0, 0);
 
-	pid = getpid();
-
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); ++lc)
 		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;
+			rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
+			a2.s6_addr32[word] |= newbit;
+			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 +120,7 @@ void do_tests(void)
 			 ptab[i].prt_name);
 	}
 /* RFC 3542, Section 3.1 */
-	csum_test("::1");
+	csum_test();
 }
 
 /*
@@ -162,10 +141,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 +152,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)
 
-static int recvtprot(int sd, unsigned char *packet, int psize)
+int TST_TOTAL = PTCOUNT + CSCOUNT;
+
+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;
@@ -210,15 +188,17 @@ static int recvtprot(int sd, unsigned char *packet, int psize)
 				gothead = 1;
 				expected += ntohl(tpt->tp_dlen);
 			}
-		} else
+		} else {
 			break;
+		}
 	}
 	if (cc < 0)
 		return cc;
 	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 +214,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 +222,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 +240,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;
@@ -322,9 +300,9 @@ static int client(int prot, int sfd)
 				 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 +312,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;
@@ -356,99 +334,60 @@ 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);
-	sem_post(&ilsem);
 	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;
 	socklen_t namelen;
 
-/* restrict to PF_INET for now */
-	if (pf != PF_INET) {
-		errno = EOPNOTSUPP;
-		return -1;
-	}
-	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;
-	}
-	sem_wait(&ilsem);
+
+	SAFE_CONNECT(NULL, fd[0], (struct sockaddr *)&sin4, sizeof(sin4));
+
+	pthread_join(thid, NULL);
+
 	fd[1] = connect_fd;
-	sem_destroy(&ilsem);
-	return 0;
 }
 
 #ifndef MAX
 #define MAX(a, b) (@ >= (b) ? (a) : (b))
 #endif /* MAX */
 
-int csum_test(char *rhost)
+static void 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 +396,16 @@ 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]);
+		client(csd[0]);
+		return;
 	}
 
 	tv.tv_sec = READ_TIMEOUT;
@@ -478,7 +417,7 @@ int csum_test(char *rhost)
 			exit(0);
 		} else if (nfds == 0) {
 			fprintf(stderr, "server read timed out");
-			return -1;
+			return;
 		}
 		if (FD_ISSET(sd, &rset)) {
 			static char packet[2048];
@@ -499,9 +438,8 @@ int csum_test(char *rhost)
 			char buf[2048];
 
 			cc = read(csd[1], buf, sizeof(buf));
-			if (cc == 0) {
+			if (cc == 0)
 				exit(0);
-			}
 			if (cc < 0) {
 				perror("server read");
 				exit(1);
@@ -512,16 +450,11 @@ int csum_test(char *rhost)
 		tv.tv_sec = READ_TIMEOUT;
 		tv.tv_usec = 0;
 	}
-	return 0;
 }
 
-void setup(void)
+static void setup(void)
 {
-	TEST_PAUSE;		/* if -P option specified */
-}
+	TEST_PAUSE;
 
-void cleanup(void)
-{
+	pid = getpid();
 }
-
-int TST_TOTAL = PTCOUNT + CSCOUNT;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v8 4/7] lib6/asapi_05.c: Cleanup
  2015-10-08 11:29     ` [LTP] [PATCH v8 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
  2015-10-08 11:29       ` [LTP] [PATCH v8 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
  2015-10-08 11:29       ` [LTP] [PATCH v8 3/7] lib6/asapi_04.c: Cleanup Zeng Linggang
@ 2015-10-08 11:29       ` Zeng Linggang
  2015-10-08 11:29       ` [LTP] [PATCH v8 5/7] lib6/asapi_06.c: Cleanup Zeng Linggang
                         ` (2 subsequent siblings)
  5 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-08 11:29 UTC (permalink / raw)
  To: ltp

* Add 'static' before some functions and global variables.
* Remove cleanup().
* Remove useless comments.
* Use SAFE_XXX().
* Modify the format of etab[] and ftab[].
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_05.c | 159 ++++++++++++++------------------------
 1 file changed, 60 insertions(+), 99 deletions(-)

diff --git a/testcases/network/lib6/asapi_05.c b/testcases/network/lib6/asapi_05.c
index e251eee..f8c30f1 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,74 @@
 #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);
 
-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();
 }
 
-void cleanup(void)
-{
-}
-
-/*
- * 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 +113,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 +156,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 +167,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 +182,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 +197,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;
 
@@ -284,8 +246,9 @@ void icmp6_ft(void)
 			if (ic6_send1(ftab[i].ft_tname, ftab[i].ft_sndtype))
 				continue;
 			rv = ic6_recv1(ftab[i].ft_tname, sall, sf);
-		} else
+		} else {
 			rv = -1;
+		}
 
 		if (rv < 0)
 			continue;
@@ -296,5 +259,3 @@ void icmp6_ft(void)
 			tst_resm(TPASS, "%s", ftab[i].ft_tname);
 	}
 }
-
-int TST_TOTAL = FTCOUNT;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v8 5/7] lib6/asapi_06.c: Cleanup
  2015-10-08 11:29     ` [LTP] [PATCH v8 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                         ` (2 preceding siblings ...)
  2015-10-08 11:29       ` [LTP] [PATCH v8 4/7] lib6/asapi_05.c: Cleanup Zeng Linggang
@ 2015-10-08 11:29       ` Zeng Linggang
  2015-10-08 11:29       ` [LTP] [PATCH v8 6/7] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
  2015-10-08 11:29       ` [LTP] [PATCH v8 7/7] ipv6_lib: Add it into default Zeng Linggang
  5 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-08 11:29 UTC (permalink / raw)
  To: ltp

* Add 'static' before some functions and global variables.
* Remove cleanup().
* Remove useless comments.
* Use SAFE_XXX().
* Remove unused variables.
* Modify the format of sotab[] and cmtab[].
* Modify the initialization of sotab[].
* Remove IPV6_PKTINFO test. IPV6_PKTINFO is only implemented
  by setsockopt() not by getsockopt(). see:
  https://github.com/torvalds/linux/commit/b24a2516d10751d7ed5afb58420df25370c9dffb
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_06.c | 473 ++++++++------------------------------
 1 file changed, 99 insertions(+), 374 deletions(-)

diff --git a/testcases/network/lib6/asapi_06.c b/testcases/network/lib6/asapi_06.c
index 960ebb5..c6e2c8e 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,16 @@
 #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]))
-
 #define READ_TIMEOUT	5	/* secs */
 
-void do_tests(void);
-void setup(void), cleanup(void);
+static void do_tests(void);
+static void setup(void);
 
 int main(int argc, char *argv[])
 {
@@ -83,14 +58,11 @@ int main(int argc, char *argv[])
 
 	tst_parse_opts(argc, argv, NULL, NULL);
 
-	pid = getpid();
-
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); ++lc)
 		do_tests();
 
-	cleanup();
 	tst_exit();
 }
 
@@ -150,7 +122,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 +132,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 +186,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 +237,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;
@@ -300,63 +246,51 @@ void so_test(struct soent *psoe)
 	int st;
 
 	if (psoe->so_opt == -1) {
-		tst_resm(TBROK, "%s not present at compile time",
+		tst_brkm(TBROK | TERRNO, NULL, "%s not present at compile time",
 			 psoe->so_tname);
-		return;
 	}
 	if (psoe->so_clear || sr < 0) {
 		if (sr < 0)
 			close(sr);
-		sr = socket(PF_INET6, SOCK_RAW, NH_TEST);
-		if (sr < 0) {
-			tst_resm(TBROK, "%s socket: %s", psoe->so_tname,
-				 strerror(errno));
-			return;
-		}
+		sr = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
 	}
 	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,
-			 strerror(errno));
-		return;
+		tst_brkm(TBROK | TERRNO, NULL, "%s: setsockopt",
+			 psoe->so_tname);
 	}
+
 	TEST(setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_setval,
 			psoe->so_valsize));
 	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL, "%s set-get: setsockopt: %s", psoe->so_tname,
-			 strerror(errno));
+		tst_resm(TFAIL | TERRNO, "%s set-get: setsockopt",
+			 psoe->so_tname);
 		return;
 	}
+
 	valsize = psoe->so_valsize;
 	TEST(getsockopt(sr, SOL_IPV6, psoe->so_opt, &sobuf, &valsize));
 	if (TEST_RETURN != 0) {
-		tst_resm(TBROK, "%s set-get: getsockopt: %s", psoe->so_tname,
-			 strerror(errno));
-		return;
-	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize))
+		tst_brkm(TBROK | TERRNO, NULL, "%s set-get: getsockopt",
+			 psoe->so_tname);
+	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize)) {
 		tst_resm(TFAIL, "%s set-get optval != setval", psoe->so_tname);
-	else
+	} 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;
-	}
-	if (sendall(st) < 0) {
-		tst_resm(TBROK, "%s transmit sendto: %s", psoe->so_tname,
-			 strerror(errno));
-		close(st);
-		return;
 	}
+
+	st = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
+	if (sendall(st) < 0)
+		tst_brkm(TBROK | TERRNO, NULL, "%s transmit sendto",
+			 psoe->so_tname);
+
 	close(st);
 
 	/* receiver processing */
@@ -382,12 +316,11 @@ void so_test(struct soent *psoe)
 			if (nfds < 0) {
 				if (errno == EINTR)
 					continue;
-				tst_resm(TBROK, "%s select: %s", psoe->so_tname,
-					 strerror(errno));
-				return;
+				tst_brkm(TBROK | TERRNO, NULL, "%s select",
+					 psoe->so_tname);
 			}
 			if (nfds == 0) {
-				tst_resm(TBROK, "%s recvmsg timed out",
+				tst_brkm(TBROK, NULL, "%s recvmsg timed out",
 					 psoe->so_tname);
 				return;
 			}
@@ -405,11 +338,10 @@ void so_test(struct soent *psoe)
 
 			cc = recvmsg(sr, &msg, 0);
 			if (cc < 0) {
-				tst_resm(TBROK, "%s recvmsg: %s",
-					 psoe->so_tname, strerror(errno));
-				return;
+				tst_brkm(TBROK | TERRNO, NULL, "%s recvmsg",
+					 psoe->so_tname);
 			}
-/* check pid & seq here */
+			/* check pid & seq here */
 			break;
 		}
 		gotone = 0;
@@ -419,9 +351,9 @@ void so_test(struct soent *psoe)
 				break;
 			gotone = pcmsg->cmsg_level == SOL_IPV6 &&
 			    pcmsg->cmsg_type == psoe->so_cmtype;
-			if (gotone)
+			if (gotone) {
 				break;
-			else if (psoe->so_clear) {
+			} else if (psoe->so_clear) {
 				tst_resm(TFAIL, "%s receive: extraneous data "
 					 "in control: level %d type %d len %zu",
 					 psoe->so_tname, pcmsg->cmsg_level,
@@ -429,232 +361,25 @@ 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);
 	}
 }
 
-#define IPV6_ADDR_NODE		1
-#define IPV6_ADDR_LINK		2
-#define IPV6_ADDR_GLOBAL	3
-
-#ifdef HAVE_IFADDRS_H
-static int ipv6_addr_scope(struct in6_addr *pin6)
-{
-	if ((ntohl(pin6->s6_addr32[0]) & 0xFFC00000) == 0xFE800000)
-		return IPV6_ADDR_LINK;
-	if (memcmp(pin6, &in6addr_loopback, sizeof(*pin6)) == 0)
-		return IPV6_ADDR_NODE;
-	return IPV6_ADDR_GLOBAL;
-}
-#endif /* HAVE_IFADDRS_H */
-
-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 (psin6_arg)
-		ifindex = psin6_arg->sin6_scope_id;
-
-	/* first, find a global address */
-	for (pifa = pifa_head; pifa; pifa = pifa->ifa_next) {
-		int this_scope;
-
-		if (!(pifa->ifa_flags & IFF_UP))
-			continue;
-		if (pifa->ifa_addr->sa_family != AF_INET6)
-			continue;
-		psin6 = (struct sockaddr_in6 *)pifa->ifa_addr;
-		this_scope = ipv6_addr_scope(&psin6->sin6_addr);
-		if (this_scope &&
-		    ((this_scope < 0 && -this_scope == 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))
-			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;
-		}
-		if (psin6_arg) {
-			*psin6_arg = *psin6;
-			psin6_arg->sin6_scope_id =
-			    if_nametoindex(pifa->ifa_name);
-		}
-		return s;
-	}
-	{
-		char *scopestr, *intfstr;
-
-		switch (scope) {
-		case IPV6_ADDR_NODE:
-			scopestr = " node-local";
-			break;
-		case IPV6_ADDR_LINK:
-			scopestr = " link-local";
-			break;
-		case IPV6_ADDR_GLOBAL:
-			scopestr = " global";
-			break;
-		default:
-			scopestr = "";
-			break;
-		}
-		if (ifindex < 0) {
-			intfstr = " not on ifindex";
-			ifindex = -ifindex;
-		} else if (ifindex)
-			intfstr = " on ifindex";
-		else
-			intfstr = 0;
-
-		if (intfstr)
-			tst_resm(TBROK, "%s: getsock : no%s addresses%s %d",
-				 tname, scopestr, intfstr, ifindex);
-		else
-			tst_resm(TBROK, "%s: getsock : no%s addresses",
-				 tname, scopestr);
-	}
-	return -1;
-#else /* HAVE_IFADDRS_H */
-	return -1;
-#endif
-}
-
-#ifdef notyet
-/*
- * 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)
-{
-	int s_snd, s_rcv[3] = { -1, -1, -1 };
-	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;
-
-	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;
-	}
-	/* 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;
-	}
-	/* 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;
-	}
-	/* send to rcv1 to verify communication */
-	/* force to rcv2 w/ PKTINFO */
-/* TESTS: */
-/* sticky set-get */
-	tname = "IPV6_PKTINFO set";
-	pi.ipi6_addr = sa_rcv[1].sin6_addr;
-	pi.ipi6_ifindex = sa_rcv[1].sin6_scope_id;
-	TEST(setsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi, sizeof(pi)));
-	if (TEST_RETURN != 0)
-		tst_resm(TFAIL, "%s: %s", tname, strerror(errno));
-	else
-		tst_resm(TPASS, "%s", tname);
-
-	tname = "IPV6_PKTINFO get";
-	optlen = sizeof(pi_tmp);
-	TEST(getsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi_tmp, &optlen));
-	if (TEST_RETURN != 0)
-		tst_resm(TFAIL, "%s: %s", tname, strerror(errno));
-	else if (memcmp(&pi, &pi_tmp, sizeof(pi)) != 0) {
-		char strbuf2[64];
-		tst_resm(TFAIL, "%s: {\"%s\",%d} != {\"%s\",%d}", tname,
-			 inet_ntop(AF_INET6, &pi_tmp.ipi6_addr, strbuf,
-				   sizeof(strbuf)), pi_tmp.ipi6_ifindex,
-			 inet_ntop(AF_INET6, &pi.ipi6_addr, strbuf2,
-				   sizeof(strbuf2)), pi.ipi6_ifindex);
-	} else
-		tst_resm(TPASS, "%s", tname);
-/* 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;
-	TEST(setsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi, sizeof(pi)));
-	if (TEST_RETURN == 0)
-		tst_resm(TFAIL, "%s returns success, should be -1, EINVAL",
-			 tname);
-	else if (TEST_ERRNO != EINVAL)
-		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;
 		sotab[i].so_setval.sou_bool = 1;
 		so_test(&sotab[i]);
 	}
-#ifdef notyet
-	test_pktinfo();
-#endif /* notyet - see test_pktinfo() comment above */
-}
-
-void setup(void)
-{
-	TEST_PAUSE;		/* if -P option specified */
 }
 
-void cleanup(void)
+static void setup(void)
 {
+	TEST_PAUSE;
 }
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v8 6/7] lib6/getaddrinfo_01.c: Cleanup
  2015-10-08 11:29     ` [LTP] [PATCH v8 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                         ` (3 preceding siblings ...)
  2015-10-08 11:29       ` [LTP] [PATCH v8 5/7] lib6/asapi_06.c: Cleanup Zeng Linggang
@ 2015-10-08 11:29       ` Zeng Linggang
  2015-10-08 11:29       ` [LTP] [PATCH v8 7/7] ipv6_lib: Add it into default Zeng Linggang
  5 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-08 11:29 UTC (permalink / raw)
  To: ltp

* 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 <zenglg.jy@cn.fujitsu.com>
---
 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


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v8 7/7] ipv6_lib: Add it into default
  2015-10-08 11:29     ` [LTP] [PATCH v8 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                         ` (4 preceding siblings ...)
  2015-10-08 11:29       ` [LTP] [PATCH v8 6/7] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
@ 2015-10-08 11:29       ` Zeng Linggang
  5 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-08 11:29 UTC (permalink / raw)
  To: ltp

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 scenario_groups/default | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scenario_groups/default b/scenario_groups/default
index 3a55702..60b1b27 100644
--- a/scenario_groups/default
+++ b/scenario_groups/default
@@ -32,3 +32,4 @@ dma_thread_diotest
 cpuacct
 can
 cpuhotplug
+ipv6_lib
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v8 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-10-08 11:29       ` [LTP] [PATCH v8 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
@ 2015-10-13 10:45         ` Alexey Kodanev
  2015-10-14  6:27           ` Zeng Linggang
  2015-10-14  8:21           ` [LTP] [PATCH v9 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
  0 siblings, 2 replies; 38+ messages in thread
From: Alexey Kodanev @ 2015-10-13 10:45 UTC (permalink / raw)
  To: ltp

Hi,
On 10/08/2015 02:29 PM, Zeng Linggang wrote:
> +#include <errno.h>
> +#include "test.h"
> +#include "safe_net.h"
> +
> +char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen, char *res,
> +		    size_t len)
> +{
> +	char portstr[8];
> +
> +	switch (sa->sa_family) {
> +
> +	case AF_INET: {
> +		struct sockaddr_in *sin = (struct sockaddr_in *)sa;
> +
> +		if (!inet_ntop(AF_INET, &sin->sin_addr, res, len))
> +			return NULL;
> +
> +		if (ntohs(sin->sin_port) != 0) {
> +			snprintf(portstr, sizeof(portstr), ":%d",
> +				 ntohs(sin->sin_port));
> +			strcat(res, portstr);
> +		}
> +
> +		return res;
> +	}
> +
> +	case AF_INET6: {
> +		struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
> +
> +		res[0] = '[';
> +		if (!inet_ntop(AF_INET6, &sin6->sin6_addr, res + 1, len - 1))
> +			return NULL;
> +
> +		if (ntohs(sin6->sin6_port) != 0) {
> +			snprintf(portstr, sizeof(portstr), "]:%d",
> +				 ntohs(sin6->sin6_port));
> +			strcat(res, portstr);
> +			return res;
> +		}
> +
> +		return res + 1;
> +	}
> +
> +	case AF_UNIX: {
> +		struct sockaddr_un *unp = (struct sockaddr_un *)sa;
> +
> +		if (unp->sun_path[0] == '\0')
> +			strcpy(res, "(no pathname bound)");
> +		else
> +			snprintf(res, len, "%s", unp->sun_path);
> +
> +		return res;
> +	}
> +
> +	default: {
> +		snprintf(res, len,
> +			 "sock_ntop: unknown AF_xxx: %d, len: %d",
> +			 sa->sa_family, salen);
> +
> +		return res;
> +	}
> +
> +	}
> +
> +	return NULL;

The last return is redundant here.

> +}
> +
> +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;
> +	char buf[128];
> +
> +	for (i = 0; i < 120; i++) {
> +		if (!bind(socket, address, address_len)) {
> +			tst_resm(TINFO, "bind is OK now");

I doubt that we need to print "bind is OK now"... the other library 
functions don't print anything on success.

Otherwise it looks good.

Also, could you please send a patch that renames asapi_04/05/06 to 
asapi_01/02/03?

Best regards,
Alexey


^ permalink raw reply	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v8 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-10-13 10:45         ` Alexey Kodanev
@ 2015-10-14  6:27           ` Zeng Linggang
  2015-10-14  8:21           ` [LTP] [PATCH v9 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
  1 sibling, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-14  6:27 UTC (permalink / raw)
  To: ltp

Hi,

On Tue, 2015-10-13 at 13:45 +0300, Alexey Kodanev wrote:
> Hi,
> On 10/08/2015 02:29 PM, Zeng Linggang wrote:
> > +#include <errno.h>
> > +#include "test.h"
> > +#include "safe_net.h"
> > +
> > +char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen, char *res,
> > +		    size_t len)
> > +{
> > +	char portstr[8];
> > +
> > +	switch (sa->sa_family) {
> > +
> > +	case AF_INET: {
> > +		struct sockaddr_in *sin = (struct sockaddr_in *)sa;
> > +
> > +		if (!inet_ntop(AF_INET, &sin->sin_addr, res, len))
> > +			return NULL;
> > +
> > +		if (ntohs(sin->sin_port) != 0) {
> > +			snprintf(portstr, sizeof(portstr), ":%d",
> > +				 ntohs(sin->sin_port));
> > +			strcat(res, portstr);
> > +		}
> > +
> > +		return res;
> > +	}
> > +
> > +	case AF_INET6: {
> > +		struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
> > +
> > +		res[0] = '[';
> > +		if (!inet_ntop(AF_INET6, &sin6->sin6_addr, res + 1, len - 1))
> > +			return NULL;
> > +
> > +		if (ntohs(sin6->sin6_port) != 0) {
> > +			snprintf(portstr, sizeof(portstr), "]:%d",
> > +				 ntohs(sin6->sin6_port));
> > +			strcat(res, portstr);
> > +			return res;
> > +		}
> > +
> > +		return res + 1;
> > +	}
> > +
> > +	case AF_UNIX: {
> > +		struct sockaddr_un *unp = (struct sockaddr_un *)sa;
> > +
> > +		if (unp->sun_path[0] == '\0')
> > +			strcpy(res, "(no pathname bound)");
> > +		else
> > +			snprintf(res, len, "%s", unp->sun_path);
> > +
> > +		return res;
> > +	}
> > +
> > +	default: {
> > +		snprintf(res, len,
> > +			 "sock_ntop: unknown AF_xxx: %d, len: %d",
> > +			 sa->sa_family, salen);
> > +
> > +		return res;
> > +	}
> > +
> > +	}
> > +
> > +	return NULL;
> 
> The last return is redundant here.
> 

Yep.

> > +}
> > +
> > +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;
> > +	char buf[128];
> > +
> > +	for (i = 0; i < 120; i++) {
> > +		if (!bind(socket, address, address_len)) {
> > +			tst_resm(TINFO, "bind is OK now");
> 
> I doubt that we need to print "bind is OK now"... the other library 
> functions don't print anything on success.

"Silence is golden" :)

> 
> Otherwise it looks good.
> 
> Also, could you please send a patch that renames asapi_04/05/06 to 
> asapi_01/02/03?

Hmm, OK. I will rename them in the next version(V9).

Thank you very much.

Best regards,
Zeng

> 
> Best regards,
> Alexey
> 



^ permalink raw reply	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v9 1/8] lib6: Remove runcc.* and the testcases that use it.
  2015-10-13 10:45         ` Alexey Kodanev
  2015-10-14  6:27           ` Zeng Linggang
@ 2015-10-14  8:21           ` Zeng Linggang
  2015-10-14  8:21             ` [LTP] [PATCH v9 2/8] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
                               ` (6 more replies)
  1 sibling, 7 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-14  8:21 UTC (permalink / raw)
  To: ltp

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 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


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v9 2/8] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-10-14  8:21           ` [LTP] [PATCH v9 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
@ 2015-10-14  8:21             ` Zeng Linggang
  2015-10-14  8:21             ` [LTP] [PATCH v9 3/8] lib6/asapi_04.c: Cleanup Zeng Linggang
                               ` (5 subsequent siblings)
  6 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-14  8:21 UTC (permalink / raw)
  To: ltp

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 include/safe_macros.h |   1 +
 include/safe_net.h    |  60 ++++++++++++++++
 lib/safe_net.c        | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 246 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..2f8811c
--- /dev/null
+++ b/include/safe_net.h
@@ -0,0 +1,60 @@
+/*
+ * 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>
+#include <sys/un.h>
+
+char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen, char *res,
+		    size_t len);
+
+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..f02e68e
--- /dev/null
+++ b/lib/safe_net.c
@@ -0,0 +1,185 @@
+/*
+ * 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"
+
+char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen, char *res,
+		    size_t len)
+{
+	char portstr[8];
+
+	switch (sa->sa_family) {
+
+	case AF_INET: {
+		struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+
+		if (!inet_ntop(AF_INET, &sin->sin_addr, res, len))
+			return NULL;
+
+		if (ntohs(sin->sin_port) != 0) {
+			snprintf(portstr, sizeof(portstr), ":%d",
+				 ntohs(sin->sin_port));
+			strcat(res, portstr);
+		}
+
+		return res;
+	}
+
+	case AF_INET6: {
+		struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
+
+		res[0] = '[';
+		if (!inet_ntop(AF_INET6, &sin6->sin6_addr, res + 1, len - 1))
+			return NULL;
+
+		if (ntohs(sin6->sin6_port) != 0) {
+			snprintf(portstr, sizeof(portstr), "]:%d",
+				 ntohs(sin6->sin6_port));
+			strcat(res, portstr);
+			return res;
+		}
+
+		return res + 1;
+	}
+
+	case AF_UNIX: {
+		struct sockaddr_un *unp = (struct sockaddr_un *)sa;
+
+		if (unp->sun_path[0] == '\0')
+			strcpy(res, "(no pathname bound)");
+		else
+			snprintf(res, len, "%s", unp->sun_path);
+
+		return res;
+	}
+
+	default: {
+		snprintf(res, len,
+			 "sock_ntop: unknown AF_xxx: %d, len: %d",
+			 sa->sa_family, salen);
+
+		return res;
+	}
+
+	}
+}
+
+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;
+	char buf[128];
+
+	for (i = 0; i < 120; i++) {
+		if (!bind(socket, address, address_len))
+			return 0;
+
+		if (errno != EADDRINUSE) {
+			tst_brkm(TBROK | TERRNO, cleanup_fn,
+				 "%s:%d: bind(%d, %s, %d) failed", file, lineno,
+				 socket, tst_sock_addr(address, address_len,
+						       buf, sizeof(buf)),
+				 address_len);
+		}
+
+		if ((i + 1) % 10 == 0) {
+			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, %s, %d) after 120 retries", file,
+		 lineno, socket,
+		 tst_sock_addr(address, address_len, buf, sizeof(buf)),
+		 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;
+	char buf[128];
+
+	rval = connect(sockfd, addr, addrlen);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: connect(%d, %s, %d) failed", file, lineno,
+			 sockfd, tst_sock_addr(addr, addrlen, buf,
+					       sizeof(buf)), 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;
+	char buf[128];
+
+	rval = getsockname(sockfd, addr, addrlen);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: getsockname(%d, %s, %d) failed", file, lineno,
+			 sockfd, tst_sock_addr(addr, *addrlen, buf,
+					       sizeof(buf)), *addrlen);
+	}
+
+	return rval;
+}
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v9 3/8] lib6/asapi_04.c: Cleanup
  2015-10-14  8:21           ` [LTP] [PATCH v9 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
  2015-10-14  8:21             ` [LTP] [PATCH v9 2/8] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
@ 2015-10-14  8:21             ` Zeng Linggang
  2015-10-14  8:21             ` [LTP] [PATCH v9 4/8] lib6/asapi_05.c: Cleanup Zeng Linggang
                               ` (4 subsequent siblings)
  6 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-14  8:21 UTC (permalink / raw)
  To: ltp

* Add 'static' before some functions and global variables.
* Remove useless comments.
* Use SAFE_XXX().
* Modify the format of ptab[] and cstab[].
* Use 'pthread_join()' instead of 'sem_*'.
* Rewrite 'csum_test()' and 'isocketpair()'.
* Remove cleanup().
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_04.c | 301 +++++++++++++++-----------------------
 1 file changed, 117 insertions(+), 184 deletions(-)

diff --git a/testcases/network/lib6/asapi_04.c b/testcases/network/lib6/asapi_04.c
index 76de26b..df26494 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,33 @@
 #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 READ_TIMEOUT	5	/* secs */
+#define PTCOUNT		ARRAY_SIZE(ptab)
+#define READ_TIMEOUT	5
 
-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 csum_test(void);
 
 int main(int argc, char *argv[])
 {
@@ -82,52 +65,48 @@ int main(int argc, char *argv[])
 
 	tst_parse_opts(argc, argv, 0, 0);
 
-	pid = getpid();
-
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); ++lc)
 		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;
+			rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
+			a2.s6_addr32[word] |= newbit;
+			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 +120,7 @@ void do_tests(void)
 			 ptab[i].prt_name);
 	}
 /* RFC 3542, Section 3.1 */
-	csum_test("::1");
+	csum_test();
 }
 
 /*
@@ -162,10 +141,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 +152,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)
 
-static int recvtprot(int sd, unsigned char *packet, int psize)
+int TST_TOTAL = PTCOUNT + CSCOUNT;
+
+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;
@@ -210,15 +188,17 @@ static int recvtprot(int sd, unsigned char *packet, int psize)
 				gothead = 1;
 				expected += ntohl(tpt->tp_dlen);
 			}
-		} else
+		} else {
 			break;
+		}
 	}
 	if (cc < 0)
 		return cc;
 	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 +214,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 +222,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 +240,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;
@@ -322,9 +300,9 @@ static int client(int prot, int sfd)
 				 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 +312,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;
@@ -356,99 +334,60 @@ 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);
-	sem_post(&ilsem);
 	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;
 	socklen_t namelen;
 
-/* restrict to PF_INET for now */
-	if (pf != PF_INET) {
-		errno = EOPNOTSUPP;
-		return -1;
-	}
-	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;
-	}
-	sem_wait(&ilsem);
+
+	SAFE_CONNECT(NULL, fd[0], (struct sockaddr *)&sin4, sizeof(sin4));
+
+	pthread_join(thid, NULL);
+
 	fd[1] = connect_fd;
-	sem_destroy(&ilsem);
-	return 0;
 }
 
 #ifndef MAX
 #define MAX(a, b) (@ >= (b) ? (a) : (b))
 #endif /* MAX */
 
-int csum_test(char *rhost)
+static void 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 +396,16 @@ 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]);
+		client(csd[0]);
+		return;
 	}
 
 	tv.tv_sec = READ_TIMEOUT;
@@ -478,7 +417,7 @@ int csum_test(char *rhost)
 			exit(0);
 		} else if (nfds == 0) {
 			fprintf(stderr, "server read timed out");
-			return -1;
+			return;
 		}
 		if (FD_ISSET(sd, &rset)) {
 			static char packet[2048];
@@ -499,9 +438,8 @@ int csum_test(char *rhost)
 			char buf[2048];
 
 			cc = read(csd[1], buf, sizeof(buf));
-			if (cc == 0) {
+			if (cc == 0)
 				exit(0);
-			}
 			if (cc < 0) {
 				perror("server read");
 				exit(1);
@@ -512,16 +450,11 @@ int csum_test(char *rhost)
 		tv.tv_sec = READ_TIMEOUT;
 		tv.tv_usec = 0;
 	}
-	return 0;
 }
 
-void setup(void)
+static void setup(void)
 {
-	TEST_PAUSE;		/* if -P option specified */
-}
+	TEST_PAUSE;
 
-void cleanup(void)
-{
+	pid = getpid();
 }
-
-int TST_TOTAL = PTCOUNT + CSCOUNT;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v9 4/8] lib6/asapi_05.c: Cleanup
  2015-10-14  8:21           ` [LTP] [PATCH v9 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
  2015-10-14  8:21             ` [LTP] [PATCH v9 2/8] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
  2015-10-14  8:21             ` [LTP] [PATCH v9 3/8] lib6/asapi_04.c: Cleanup Zeng Linggang
@ 2015-10-14  8:21             ` Zeng Linggang
  2015-10-14  8:21             ` [LTP] [PATCH v9 5/8] lib6/asapi_06.c: Cleanup Zeng Linggang
                               ` (3 subsequent siblings)
  6 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-14  8:21 UTC (permalink / raw)
  To: ltp

* Add 'static' before some functions and global variables.
* Remove cleanup().
* Remove useless comments.
* Use SAFE_XXX().
* Modify the format of etab[] and ftab[].
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_05.c | 159 ++++++++++++++------------------------
 1 file changed, 60 insertions(+), 99 deletions(-)

diff --git a/testcases/network/lib6/asapi_05.c b/testcases/network/lib6/asapi_05.c
index e251eee..f8c30f1 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,74 @@
 #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);
 
-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();
 }
 
-void cleanup(void)
-{
-}
-
-/*
- * 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 +113,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 +156,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 +167,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 +182,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 +197,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;
 
@@ -284,8 +246,9 @@ void icmp6_ft(void)
 			if (ic6_send1(ftab[i].ft_tname, ftab[i].ft_sndtype))
 				continue;
 			rv = ic6_recv1(ftab[i].ft_tname, sall, sf);
-		} else
+		} else {
 			rv = -1;
+		}
 
 		if (rv < 0)
 			continue;
@@ -296,5 +259,3 @@ void icmp6_ft(void)
 			tst_resm(TPASS, "%s", ftab[i].ft_tname);
 	}
 }
-
-int TST_TOTAL = FTCOUNT;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v9 5/8] lib6/asapi_06.c: Cleanup
  2015-10-14  8:21           ` [LTP] [PATCH v9 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                               ` (2 preceding siblings ...)
  2015-10-14  8:21             ` [LTP] [PATCH v9 4/8] lib6/asapi_05.c: Cleanup Zeng Linggang
@ 2015-10-14  8:21             ` Zeng Linggang
  2015-10-14  8:21             ` [LTP] [PATCH v9 6/8] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
                               ` (2 subsequent siblings)
  6 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-14  8:21 UTC (permalink / raw)
  To: ltp

* Add 'static' before some functions and global variables.
* Remove cleanup().
* Remove useless comments.
* Use SAFE_XXX().
* Remove unused variables.
* Modify the format of sotab[] and cmtab[].
* Modify the initialization of sotab[].
* Remove IPV6_PKTINFO test. IPV6_PKTINFO is only implemented
  by setsockopt() not by getsockopt(). see:
  https://github.com/torvalds/linux/commit/b24a2516d10751d7ed5afb58420df25370c9dffb
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_06.c | 473 ++++++++------------------------------
 1 file changed, 99 insertions(+), 374 deletions(-)

diff --git a/testcases/network/lib6/asapi_06.c b/testcases/network/lib6/asapi_06.c
index 960ebb5..c6e2c8e 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,16 @@
 #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]))
-
 #define READ_TIMEOUT	5	/* secs */
 
-void do_tests(void);
-void setup(void), cleanup(void);
+static void do_tests(void);
+static void setup(void);
 
 int main(int argc, char *argv[])
 {
@@ -83,14 +58,11 @@ int main(int argc, char *argv[])
 
 	tst_parse_opts(argc, argv, NULL, NULL);
 
-	pid = getpid();
-
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); ++lc)
 		do_tests();
 
-	cleanup();
 	tst_exit();
 }
 
@@ -150,7 +122,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 +132,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 +186,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 +237,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;
@@ -300,63 +246,51 @@ void so_test(struct soent *psoe)
 	int st;
 
 	if (psoe->so_opt == -1) {
-		tst_resm(TBROK, "%s not present at compile time",
+		tst_brkm(TBROK | TERRNO, NULL, "%s not present at compile time",
 			 psoe->so_tname);
-		return;
 	}
 	if (psoe->so_clear || sr < 0) {
 		if (sr < 0)
 			close(sr);
-		sr = socket(PF_INET6, SOCK_RAW, NH_TEST);
-		if (sr < 0) {
-			tst_resm(TBROK, "%s socket: %s", psoe->so_tname,
-				 strerror(errno));
-			return;
-		}
+		sr = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
 	}
 	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,
-			 strerror(errno));
-		return;
+		tst_brkm(TBROK | TERRNO, NULL, "%s: setsockopt",
+			 psoe->so_tname);
 	}
+
 	TEST(setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_setval,
 			psoe->so_valsize));
 	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL, "%s set-get: setsockopt: %s", psoe->so_tname,
-			 strerror(errno));
+		tst_resm(TFAIL | TERRNO, "%s set-get: setsockopt",
+			 psoe->so_tname);
 		return;
 	}
+
 	valsize = psoe->so_valsize;
 	TEST(getsockopt(sr, SOL_IPV6, psoe->so_opt, &sobuf, &valsize));
 	if (TEST_RETURN != 0) {
-		tst_resm(TBROK, "%s set-get: getsockopt: %s", psoe->so_tname,
-			 strerror(errno));
-		return;
-	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize))
+		tst_brkm(TBROK | TERRNO, NULL, "%s set-get: getsockopt",
+			 psoe->so_tname);
+	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize)) {
 		tst_resm(TFAIL, "%s set-get optval != setval", psoe->so_tname);
-	else
+	} 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;
-	}
-	if (sendall(st) < 0) {
-		tst_resm(TBROK, "%s transmit sendto: %s", psoe->so_tname,
-			 strerror(errno));
-		close(st);
-		return;
 	}
+
+	st = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
+	if (sendall(st) < 0)
+		tst_brkm(TBROK | TERRNO, NULL, "%s transmit sendto",
+			 psoe->so_tname);
+
 	close(st);
 
 	/* receiver processing */
@@ -382,12 +316,11 @@ void so_test(struct soent *psoe)
 			if (nfds < 0) {
 				if (errno == EINTR)
 					continue;
-				tst_resm(TBROK, "%s select: %s", psoe->so_tname,
-					 strerror(errno));
-				return;
+				tst_brkm(TBROK | TERRNO, NULL, "%s select",
+					 psoe->so_tname);
 			}
 			if (nfds == 0) {
-				tst_resm(TBROK, "%s recvmsg timed out",
+				tst_brkm(TBROK, NULL, "%s recvmsg timed out",
 					 psoe->so_tname);
 				return;
 			}
@@ -405,11 +338,10 @@ void so_test(struct soent *psoe)
 
 			cc = recvmsg(sr, &msg, 0);
 			if (cc < 0) {
-				tst_resm(TBROK, "%s recvmsg: %s",
-					 psoe->so_tname, strerror(errno));
-				return;
+				tst_brkm(TBROK | TERRNO, NULL, "%s recvmsg",
+					 psoe->so_tname);
 			}
-/* check pid & seq here */
+			/* check pid & seq here */
 			break;
 		}
 		gotone = 0;
@@ -419,9 +351,9 @@ void so_test(struct soent *psoe)
 				break;
 			gotone = pcmsg->cmsg_level == SOL_IPV6 &&
 			    pcmsg->cmsg_type == psoe->so_cmtype;
-			if (gotone)
+			if (gotone) {
 				break;
-			else if (psoe->so_clear) {
+			} else if (psoe->so_clear) {
 				tst_resm(TFAIL, "%s receive: extraneous data "
 					 "in control: level %d type %d len %zu",
 					 psoe->so_tname, pcmsg->cmsg_level,
@@ -429,232 +361,25 @@ 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);
 	}
 }
 
-#define IPV6_ADDR_NODE		1
-#define IPV6_ADDR_LINK		2
-#define IPV6_ADDR_GLOBAL	3
-
-#ifdef HAVE_IFADDRS_H
-static int ipv6_addr_scope(struct in6_addr *pin6)
-{
-	if ((ntohl(pin6->s6_addr32[0]) & 0xFFC00000) == 0xFE800000)
-		return IPV6_ADDR_LINK;
-	if (memcmp(pin6, &in6addr_loopback, sizeof(*pin6)) == 0)
-		return IPV6_ADDR_NODE;
-	return IPV6_ADDR_GLOBAL;
-}
-#endif /* HAVE_IFADDRS_H */
-
-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 (psin6_arg)
-		ifindex = psin6_arg->sin6_scope_id;
-
-	/* first, find a global address */
-	for (pifa = pifa_head; pifa; pifa = pifa->ifa_next) {
-		int this_scope;
-
-		if (!(pifa->ifa_flags & IFF_UP))
-			continue;
-		if (pifa->ifa_addr->sa_family != AF_INET6)
-			continue;
-		psin6 = (struct sockaddr_in6 *)pifa->ifa_addr;
-		this_scope = ipv6_addr_scope(&psin6->sin6_addr);
-		if (this_scope &&
-		    ((this_scope < 0 && -this_scope == 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))
-			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;
-		}
-		if (psin6_arg) {
-			*psin6_arg = *psin6;
-			psin6_arg->sin6_scope_id =
-			    if_nametoindex(pifa->ifa_name);
-		}
-		return s;
-	}
-	{
-		char *scopestr, *intfstr;
-
-		switch (scope) {
-		case IPV6_ADDR_NODE:
-			scopestr = " node-local";
-			break;
-		case IPV6_ADDR_LINK:
-			scopestr = " link-local";
-			break;
-		case IPV6_ADDR_GLOBAL:
-			scopestr = " global";
-			break;
-		default:
-			scopestr = "";
-			break;
-		}
-		if (ifindex < 0) {
-			intfstr = " not on ifindex";
-			ifindex = -ifindex;
-		} else if (ifindex)
-			intfstr = " on ifindex";
-		else
-			intfstr = 0;
-
-		if (intfstr)
-			tst_resm(TBROK, "%s: getsock : no%s addresses%s %d",
-				 tname, scopestr, intfstr, ifindex);
-		else
-			tst_resm(TBROK, "%s: getsock : no%s addresses",
-				 tname, scopestr);
-	}
-	return -1;
-#else /* HAVE_IFADDRS_H */
-	return -1;
-#endif
-}
-
-#ifdef notyet
-/*
- * 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)
-{
-	int s_snd, s_rcv[3] = { -1, -1, -1 };
-	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;
-
-	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;
-	}
-	/* 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;
-	}
-	/* 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;
-	}
-	/* send to rcv1 to verify communication */
-	/* force to rcv2 w/ PKTINFO */
-/* TESTS: */
-/* sticky set-get */
-	tname = "IPV6_PKTINFO set";
-	pi.ipi6_addr = sa_rcv[1].sin6_addr;
-	pi.ipi6_ifindex = sa_rcv[1].sin6_scope_id;
-	TEST(setsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi, sizeof(pi)));
-	if (TEST_RETURN != 0)
-		tst_resm(TFAIL, "%s: %s", tname, strerror(errno));
-	else
-		tst_resm(TPASS, "%s", tname);
-
-	tname = "IPV6_PKTINFO get";
-	optlen = sizeof(pi_tmp);
-	TEST(getsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi_tmp, &optlen));
-	if (TEST_RETURN != 0)
-		tst_resm(TFAIL, "%s: %s", tname, strerror(errno));
-	else if (memcmp(&pi, &pi_tmp, sizeof(pi)) != 0) {
-		char strbuf2[64];
-		tst_resm(TFAIL, "%s: {\"%s\",%d} != {\"%s\",%d}", tname,
-			 inet_ntop(AF_INET6, &pi_tmp.ipi6_addr, strbuf,
-				   sizeof(strbuf)), pi_tmp.ipi6_ifindex,
-			 inet_ntop(AF_INET6, &pi.ipi6_addr, strbuf2,
-				   sizeof(strbuf2)), pi.ipi6_ifindex);
-	} else
-		tst_resm(TPASS, "%s", tname);
-/* 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;
-	TEST(setsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi, sizeof(pi)));
-	if (TEST_RETURN == 0)
-		tst_resm(TFAIL, "%s returns success, should be -1, EINVAL",
-			 tname);
-	else if (TEST_ERRNO != EINVAL)
-		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;
 		sotab[i].so_setval.sou_bool = 1;
 		so_test(&sotab[i]);
 	}
-#ifdef notyet
-	test_pktinfo();
-#endif /* notyet - see test_pktinfo() comment above */
-}
-
-void setup(void)
-{
-	TEST_PAUSE;		/* if -P option specified */
 }
 
-void cleanup(void)
+static void setup(void)
 {
+	TEST_PAUSE;
 }
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v9 6/8] lib6/getaddrinfo_01.c: Cleanup
  2015-10-14  8:21           ` [LTP] [PATCH v9 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                               ` (3 preceding siblings ...)
  2015-10-14  8:21             ` [LTP] [PATCH v9 5/8] lib6/asapi_06.c: Cleanup Zeng Linggang
@ 2015-10-14  8:21             ` Zeng Linggang
  2015-10-20  8:07               ` Alexey Kodanev
  2015-10-14  8:21             ` [LTP] [PATCH v9 7/8] lib6: Rename Zeng Linggang
  2015-10-14  8:21             ` [LTP] [PATCH v9 8/8] ipv6_lib: Add it into default Zeng Linggang
  6 siblings, 1 reply; 38+ messages in thread
From: Zeng Linggang @ 2015-10-14  8:21 UTC (permalink / raw)
  To: ltp

* 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 <zenglg.jy@cn.fujitsu.com>
---
 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


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v9 7/8] lib6: Rename
  2015-10-14  8:21           ` [LTP] [PATCH v9 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                               ` (4 preceding siblings ...)
  2015-10-14  8:21             ` [LTP] [PATCH v9 6/8] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
@ 2015-10-14  8:21             ` Zeng Linggang
  2015-10-14  8:21             ` [LTP] [PATCH v9 8/8] ipv6_lib: Add it into default Zeng Linggang
  6 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-14  8:21 UTC (permalink / raw)
  To: ltp

rename:    asapi_04.c -> asapi_01.c
rename:    asapi_05.c -> asapi_02.c
rename:    asapi_06.c -> asapi_03.c

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 runtest/ipv6_lib                  |   6 +-
 testcases/network/.gitignore      |   6 +-
 testcases/network/lib6/asapi_01.c | 460 ++++++++++++++++++++++++++++++++++++++
 testcases/network/lib6/asapi_02.c | 261 +++++++++++++++++++++
 testcases/network/lib6/asapi_03.c | 385 +++++++++++++++++++++++++++++++
 testcases/network/lib6/asapi_04.c | 460 --------------------------------------
 testcases/network/lib6/asapi_05.c | 261 ---------------------
 testcases/network/lib6/asapi_06.c | 385 -------------------------------
 8 files changed, 1112 insertions(+), 1112 deletions(-)
 create mode 100644 testcases/network/lib6/asapi_01.c
 create mode 100644 testcases/network/lib6/asapi_02.c
 create mode 100644 testcases/network/lib6/asapi_03.c
 delete mode 100644 testcases/network/lib6/asapi_04.c
 delete mode 100644 testcases/network/lib6/asapi_05.c
 delete mode 100644 testcases/network/lib6/asapi_06.c

diff --git a/runtest/ipv6_lib b/runtest/ipv6_lib
index 203e275..636232b 100644
--- a/runtest/ipv6_lib
+++ b/runtest/ipv6_lib
@@ -2,6 +2,6 @@
 in6_01 in6_01
 in6_02 in6_02
 getaddrinfo_01 getaddrinfo_01
-asapi_04 asapi_04
-asapi_05 asapi_05
-asapi_06 asapi_06
+asapi_01 asapi_01
+asapi_02 asapi_02
+asapi_03 asapi_03
diff --git a/testcases/network/.gitignore b/testcases/network/.gitignore
index 18b0203..77a350b 100644
--- a/testcases/network/.gitignore
+++ b/testcases/network/.gitignore
@@ -1,9 +1,9 @@
 /can/filter-tests/can_filter
 /can/filter-tests/can_rcv_own_msgs
 /datafiles/
-/lib6/asapi_04
-/lib6/asapi_05
-/lib6/asapi_06
+/lib6/asapi_01
+/lib6/asapi_02
+/lib6/asapi_03
 /lib6/getaddrinfo_01
 /lib6/in6_01
 /lib6/in6_02
diff --git a/testcases/network/lib6/asapi_01.c b/testcases/network/lib6/asapi_01.c
new file mode 100644
index 0000000..df26494
--- /dev/null
+++ b/testcases/network/lib6/asapi_01.c
@@ -0,0 +1,460 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * 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 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/>.
+ *
+ * Author: David L Stevens
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <netdb.h>
+#include <libgen.h>
+#include <pthread.h>
+#include <semaphore.h>
+
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include "test.h"
+#include "safe_macros.h"
+
+char *TCID = "asapi_04";
+
+static pid_t pid;
+
+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		ARRAY_SIZE(ptab)
+#define READ_TIMEOUT	5
+
+static void do_tests(void);
+static void setup(void);
+static void csum_test(void);
+
+int main(int argc, char *argv[])
+{
+	int lc;
+
+	tst_parse_opts(argc, argv, 0, 0);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); ++lc)
+		do_tests();
+
+	tst_exit();
+}
+
+static void do_tests(void)
+{
+	unsigned int i;
+
+/* RFC 3542, Section 2.3 */
+#ifndef IN6_ARE_ADDR_EQUAL
+	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;
+
+	memset(&a1, 0, sizeof(a1));
+	memset(&a2, 0, sizeof(a2));
+
+	rv = IN6_ARE_ADDR_EQUAL(&a1, &a2);
+
+	for (word = 0; word < 4; ++word) {
+		for (bit = 0; bit < 32; ++bit) {
+			uint32_t newbit = 1U << bit;
+
+			a1.s6_addr32[word] |= newbit;
+			rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
+			a2.s6_addr32[word] |= newbit;
+			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 */
+	for (i = 0; i < PTCOUNT; ++i) {
+		struct protoent *pe;
+		int pass;
+
+		pe = getprotobyname(ptab[i].prt_name);
+		pass = pe && pe->p_proto == ptab[i].prt_value;
+		tst_resm(pass ? TPASS : TFAIL, "\"%s\" protocols entry",
+			 ptab[i].prt_name);
+	}
+/* RFC 3542, Section 3.1 */
+	csum_test();
+}
+
+/*
+ * this next-header value shouldn't be a real protocol!!
+ * 0x9f = 01 0 11111
+ *         | |     |
+ *         | |     |--- rest- ~0
+ *         | |--------- chg - "no change enroute"
+ *         |----------- act - "discard unknown"
+ */
+#define	NH_TEST	0x9f
+
+struct tprot {
+	int tp_pid;		/* sender PID */
+	int tp_seq;		/* sequence # */
+	int tp_offset;		/* offset of cksum */
+	int tp_dlen;		/* tp_dat length */
+	unsigned char tp_dat[0];	/* user data */
+};
+
+static unsigned char tpbuf[sizeof(struct tprot) + 2048];
+static unsigned char rpbuf[sizeof(struct tprot) + 2048];
+
+static struct csent {
+	int cs_offset;
+	int cs_dlen;
+	int cs_setresult;	/* setsockopt expected result */
+	int cs_seterrno;	/* setsockopt expected errno */
+	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) */
+};
+
+#define CSCOUNT	ARRAY_SIZE(cstab)
+
+int TST_TOTAL = PTCOUNT + CSCOUNT;
+
+static int recvtprot(int sd, unsigned char *packet)
+{
+	struct tprot *tpt;
+	int cc;
+	unsigned int total, expected;
+	int gothead;
+
+	tpt = (struct tprot *)packet;
+	total = cc = recv(sd, packet, sizeof(struct tprot), 0);
+	expected = sizeof(struct tprot);	/* until we get tp_dlen */
+	gothead = total >= sizeof(struct tprot);
+	if (gothead)
+		expected += ntohl(tpt->tp_dlen);
+	if (cc <= 0)
+		return cc;
+	while (cc > 0 && total < expected) {
+		cc = recv(sd, &packet[total], expected - total, 0);
+		if (cc >= 0) {
+			total += cc;
+			if (!gothead && total >= sizeof(struct tprot)) {
+				gothead = 1;
+				expected += ntohl(tpt->tp_dlen);
+			}
+		} else {
+			break;
+		}
+	}
+	if (cc < 0)
+		return cc;
+	return total;
+}
+
+static unsigned short csum(unsigned short partial, unsigned char *packet,
+			   int len)
+{
+	unsigned long sum = partial;
+	unsigned short *ps;
+	int i;
+
+	ps = (unsigned short *)packet;
+	for (i = 0; i < len / 2; ++i)
+		sum += *ps++;
+	if (len & 1)
+		sum += htons(packet[len - 1] << 8);
+	sum = (sum >> 16) + (sum & 0xffff);
+	sum += (sum >> 16);
+	return ~sum;
+}
+
+static struct ph {
+	struct in6_addr ph_sa;
+	struct in6_addr ph_da;
+	uint32_t ph_len;
+	uint8_t ph_mbz[3];
+	uint8_t ph_nh;
+} ph;
+
+static int client(int sfd)
+{
+	struct tprot *pttp = (struct tprot *)tpbuf;
+	struct tprot *prtp = (struct tprot *)rpbuf;
+	struct sockaddr_in6 rsin6;
+	static int seq;
+	unsigned int i;
+	int sd, cc, cs;
+
+	memset(&rsin6, 0, sizeof(rsin6));
+	rsin6.sin6_family = AF_INET6;
+	rsin6.sin6_addr = in6addr_loopback;
+
+	memset(&ph, 0, sizeof(ph));
+	ph.ph_sa = rsin6.sin6_addr;
+	ph.ph_da = rsin6.sin6_addr;
+	ph.ph_nh = NH_TEST;
+
+	sd = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
+	for (i = 0; i < CSCOUNT; ++i) {
+		int offset, len, xlen;
+		int rv;
+		unsigned char *p, *pend;
+
+		offset = sizeof(struct tprot) + cstab[i].cs_offset;
+		len = sizeof(struct tprot) + cstab[i].cs_dlen;
+
+		memset(pttp, 0, sizeof(*pttp));
+		memset(pttp->tp_dat, 0xA5, cstab[i].cs_dlen);
+
+		pttp->tp_pid = htonl(pid);
+		pttp->tp_offset = ntohl(offset);
+		pttp->tp_dlen = ntohl(cstab[i].cs_dlen);
+		pttp->tp_seq = ntohl(++seq);
+
+		TEST(setsockopt(sd, IPPROTO_IPV6, IPV6_CHECKSUM, &offset,
+				sizeof(offset)));
+		if (TEST_RETURN != cstab[i].cs_setresult) {
+			tst_resm(TFAIL | TTERRNO,
+				 "IPV6_CHECKSUM offset %d len %d "
+				 "- result %ld != %d", offset, len, TEST_RETURN,
+				 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)));
+		xlen = (cstab[i].cs_sndresult < 0) ? -1 : len;
+		if (TEST_RETURN != xlen) {
+			tst_resm(TFAIL | TTERRNO,
+				 "IPV6_CHECKSUM offset %d len %d "
+				 "- sndresult %ld != %d", offset, len,
+				 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))) {
+			if (htonl(prtp->tp_pid) == (uint32_t)pid &&
+			    htonl(prtp->tp_seq) == (uint32_t)seq)
+				break;
+		}
+		rv = 1;
+		pend = rpbuf + sizeof(struct tprot) + ntohl(prtp->tp_dlen);
+		for (p = &prtp->tp_dat[0]; p < pend; ++p) {
+			if (p == &rpbuf[offset] || p == &rpbuf[offset + 1])
+				continue;
+			if (*p != 0xa5) {
+				tst_resm(TFAIL, "IPV6_CHECKSUM corrupt data "
+					 "0x%02x != 0xa5@offset %zd in packet",
+					 *p, p - rpbuf);
+				rv = 0;
+				break;
+			}
+		}
+		if (rv == 0)
+			continue;
+		ph.ph_len = htonl(xlen);
+		cs = csum(0, (unsigned char *)&ph, sizeof(ph));
+		cs = csum(~cs, rpbuf, xlen);
+		if (!csum(0, rpbuf, xlen)) {
+			tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d (bad "
+				 "checksum)", offset, len);
+			continue;
+		}
+		tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d", offset, len);
+	}
+	return 0;
+}
+
+static int listen_fd, connect_fd;
+
+static void *ilistener(void *arg LTP_ATTRIBUTE_UNUSED)
+{
+	connect_fd = accept(listen_fd, 0, 0);
+	close(listen_fd);
+	return NULL;
+}
+
+static void isocketpair(int pf, int type, int proto, int fd[2])
+{
+	pthread_t thid;
+	struct sockaddr_in sin4;
+	socklen_t namelen;
+
+	listen_fd = SAFE_SOCKET(NULL, pf, type, proto);
+
+	memset(&sin4, 0, sizeof(sin4));
+
+	SAFE_BIND(NULL, listen_fd, (struct sockaddr *)&sin4, sizeof(sin4));
+
+	SAFE_LISTEN(NULL, listen_fd, 10);
+
+	namelen = sizeof(sin4);
+	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);
+
+	sin4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+	SAFE_CONNECT(NULL, fd[0], (struct sockaddr *)&sin4, sizeof(sin4));
+
+	pthread_join(thid, NULL);
+
+	fd[1] = connect_fd;
+}
+
+#ifndef MAX
+#define MAX(a, b) (@ >= (b) ? (a) : (b))
+#endif /* MAX */
+
+static void csum_test(void)
+{
+	fd_set rset, rset_save;
+	int csd[2];		/* control sockets */
+	int sd, nfds, maxfd, cc;
+	struct timeval tv;
+
+	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);
+	memcpy(&rset, &rset_save, sizeof(rset));
+	maxfd = MAX(sd, csd[1]);
+
+	/* server socket set; now start the client */
+	switch (fork()) {
+	case 0:
+		close(csd[0]);
+		break;
+	case -1:
+		tst_brkm(TBROK, NULL, "can't fork rserver");
+	default:
+		close(sd);
+		close(csd[1]);
+		client(csd[0]);
+		return;
+	}
+
+	tv.tv_sec = READ_TIMEOUT;
+	tv.tv_usec = 0;
+	while ((nfds = select(maxfd + 1, &rset, 0, 0, &tv)) >= 0) {
+		if (nfds < 0) {
+			if (errno == EINTR)
+				continue;
+			exit(0);
+		} else if (nfds == 0) {
+			fprintf(stderr, "server read timed out");
+			return;
+		}
+		if (FD_ISSET(sd, &rset)) {
+			static char packet[2048];
+
+			cc = recv(sd, packet, sizeof(packet), 0);
+			if (cc < 0) {
+				perror("server recvtprot");
+				exit(1);
+			}
+			if (cc == 0)
+				exit(0);
+			if (write(csd[1], packet, cc) < 0) {
+				perror("server write UNIX socket");
+				exit(0);
+			}
+		}
+		if (FD_ISSET(csd[1], &rset)) {
+			char buf[2048];
+
+			cc = read(csd[1], buf, sizeof(buf));
+			if (cc == 0)
+				exit(0);
+			if (cc < 0) {
+				perror("server read");
+				exit(1);
+			}
+			/* handle commands here, if any added later */
+		}
+		memcpy(&rset, &rset_save, sizeof(rset));
+		tv.tv_sec = READ_TIMEOUT;
+		tv.tv_usec = 0;
+	}
+}
+
+static void setup(void)
+{
+	TEST_PAUSE;
+
+	pid = getpid();
+}
diff --git a/testcases/network/lib6/asapi_02.c b/testcases/network/lib6/asapi_02.c
new file mode 100644
index 0000000..f8c30f1
--- /dev/null
+++ b/testcases/network/lib6/asapi_02.c
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * 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 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/>.
+ *
+ * Author: David L Stevens
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <sys/wait.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <netinet/ip6.h>
+#include <netinet/icmp6.h>
+
+#include "test.h"
+#include "safe_macros.h"
+
+char *TCID = "asapi_05";
+
+static void setup(void);
+
+static void icmp6_ft(void);
+
+int main(int argc, char *argv[])
+{
+	int lc;
+
+	tst_parse_opts(argc, argv, NULL, NULL);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); ++lc)
+		icmp6_ft();
+
+	tst_exit();
+}
+
+static void setup(void)
+{
+	TEST_PAUSE;
+	tst_require_root();
+}
+
+enum tt {
+	T_WILLPASS,
+	T_WILLBLOCK,
+	T_SETPASS,
+	T_SETBLOCK,
+	T_SETPASSALL,
+	T_SETBLOCKALL
+};
+
+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? */
+} 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	ARRAY_SIZE(ftab)
+
+static int ic6_send1(char *tname, unsigned char type)
+{
+	struct sockaddr_in6 sin6;
+	struct icmp6_hdr ic6;
+	int s;
+
+	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());
+
+	memset(&sin6, 0, sizeof(sin6));
+	sin6.sin6_family = AF_INET6;
+	sin6.sin6_addr = in6addr_loopback;
+	if (sendto(s, &ic6, sizeof(ic6), 0, (struct sockaddr *)&sin6,
+		   sizeof(sin6)) == -1) {
+		tst_resm(TBROK | TERRNO, "%s: sendto failed", tname);
+		return 1;
+	}
+	return 0;
+}
+
+static int ic6_recv1(char *tname, int sall, int sf)
+{
+	fd_set readfds, readfds_saved;
+	struct timeval tv;
+	int maxfd, nfds;
+	int gotall, gotone;
+	int cc;
+	static unsigned char rbuf[2048];
+
+	tv.tv_sec = 0;
+	tv.tv_usec = 250000;
+
+	FD_ZERO(&readfds_saved);
+	FD_SET(sall, &readfds_saved);
+	FD_SET(sf, &readfds_saved);
+	maxfd = MAX(sall, sf);
+
+	memcpy(&readfds, &readfds_saved, sizeof(readfds));
+
+	gotall = gotone = 0;
+	/*
+	 * Note: this relies on linux-specific behavior (select
+	 * updating tv with time elapsed)
+	 */
+	while (!gotall || !gotone) {
+		struct icmp6_hdr *pic6 = (struct icmp6_hdr *)rbuf;
+
+		nfds = select(maxfd + 1, &readfds, 0, 0, &tv);
+		if (nfds == 0)
+			break;	/* timed out */
+		if (nfds < 0) {
+			if (errno == EINTR)
+				continue;
+			tst_resm(TBROK | TERRNO, "%s: select failed", tname);
+		}
+		if (FD_ISSET(sall, &readfds)) {
+			cc = recv(sall, rbuf, sizeof(rbuf), 0);
+			if (cc < 0) {
+				tst_resm(TBROK | TERRNO,
+					 "%s: recv(sall, ..) failed", tname);
+				return -1;
+			}
+			/* if packet check succeeds... */
+			if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid())
+				gotall = 1;
+		}
+		if (FD_ISSET(sf, &readfds)) {
+			cc = recv(sf, rbuf, sizeof(rbuf), 0);
+			if (cc < 0) {
+				tst_resm(TBROK | TERRNO,
+					 "%s: recv(sf, ..) failed", tname);
+				return -1;
+			}
+			/* if packet check succeeds... */
+			if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid())
+				gotone = 1;
+		}
+		memcpy(&readfds, &readfds_saved, sizeof(readfds));
+	}
+	if (!gotall) {
+		tst_resm(TBROK, "%s: recv all timed out", tname);
+		return -1;
+	}
+	if (gotone)
+		return 1;
+	return 0;
+}
+
+/* functional tests */
+static void icmp6_ft(void)
+{
+	struct icmp6_filter i6f;
+	int sall, sf;
+	unsigned int i;
+
+	sall = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
+
+	ICMP6_FILTER_SETPASSALL(&i6f);
+	if (setsockopt(sall, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f,
+		       sizeof(i6f)) < 0) {
+		tst_resm(TBROK | TERRNO,
+			 "setsockopt pass all ICMP6_FILTER failed");
+	}
+
+	sf = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
+
+	int rv;
+
+	for (i = 0; i < FTCOUNT; ++i) {
+
+		rv = -1;
+
+		switch (ftab[i].ft_test) {
+		case T_SETPASS:
+			ICMP6_FILTER_SETBLOCKALL(&i6f);
+			ICMP6_FILTER_SETPASS(ftab[i].ft_flttype, &i6f);
+			break;
+		case T_SETPASSALL:
+			ICMP6_FILTER_SETPASSALL(&i6f);
+			break;
+		case T_SETBLOCK:
+			ICMP6_FILTER_SETPASSALL(&i6f);
+			ICMP6_FILTER_SETBLOCK(ftab[i].ft_flttype, &i6f);
+			break;
+		case T_SETBLOCKALL:
+			ICMP6_FILTER_SETBLOCKALL(&i6f);
+			break;
+		case T_WILLBLOCK:
+			ICMP6_FILTER_SETPASSALL(&i6f);
+			ICMP6_FILTER_SETBLOCK(ftab[i].ft_flttype, &i6f);
+			rv = ICMP6_FILTER_WILLBLOCK(ftab[i].ft_sndtype, &i6f);
+			break;
+		case T_WILLPASS:
+			ICMP6_FILTER_SETBLOCKALL(&i6f);
+			ICMP6_FILTER_SETPASS(ftab[i].ft_flttype, &i6f);
+			rv = ICMP6_FILTER_WILLPASS(ftab[i].ft_sndtype, &i6f);
+			break;
+		default:
+			tst_resm(TBROK, "%s: unknown test type %d",
+				 ftab[i].ft_tname, ftab[i].ft_test);
+			continue;
+		}
+		if (ftab[i].ft_test != T_WILLBLOCK &&
+		    ftab[i].ft_test != T_WILLPASS) {
+			if (setsockopt(sf, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f,
+				       sizeof(i6f)) < 0) {
+				tst_resm(TFAIL | TERRNO,
+					 "setsockopt ICMP6_FILTER");
+				continue;
+			}
+			if (ic6_send1(ftab[i].ft_tname, ftab[i].ft_sndtype))
+				continue;
+			rv = ic6_recv1(ftab[i].ft_tname, sall, sf);
+		} else {
+			rv = -1;
+		}
+
+		if (rv < 0)
+			continue;
+		if (rv != ftab[i].ft_expected)
+			tst_resm(TFAIL, "%s: rv %d != expected %d",
+				 ftab[i].ft_tname, rv, ftab[i].ft_expected);
+		else
+			tst_resm(TPASS, "%s", ftab[i].ft_tname);
+	}
+}
diff --git a/testcases/network/lib6/asapi_03.c b/testcases/network/lib6/asapi_03.c
new file mode 100644
index 0000000..c6e2c8e
--- /dev/null
+++ b/testcases/network/lib6/asapi_03.c
@@ -0,0 +1,385 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * 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 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/>.
+ *
+ * Author: David L Stevens
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <netdb.h>
+#include <libgen.h>
+#include <pthread.h>
+#include <semaphore.h>
+
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <netinet/ip6.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#ifdef HAVE_IFADDRS_H
+#include <ifaddrs.h>
+#endif
+#include <arpa/inet.h>
+
+#include "test.h"
+#include "safe_macros.h"
+
+char *TCID = "asapi_06";
+
+int TST_TOTAL = 1;
+
+#define READ_TIMEOUT	5	/* secs */
+
+static void do_tests(void);
+static void setup(void);
+
+int main(int argc, char *argv[])
+{
+	int lc;
+
+	tst_parse_opts(argc, argv, NULL, NULL);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); ++lc)
+		do_tests();
+
+	tst_exit();
+}
+
+#define NH_TEST	0x9f
+
+#ifndef IPV6_RECVPKTINFO
+#define IPV6_RECVPKTINFO	-1
+#endif
+#ifndef IPV6_RECVHOPLIMIT
+#define IPV6_RECVHOPLIMIT	-1
+#endif
+#ifndef IPV6_RECVRTHDR
+#define IPV6_RECVRTHDR		-1
+#endif
+#ifndef IPV6_RECVHOPOPTS
+#define IPV6_RECVHOPOPTS	-1
+#endif
+#ifndef IPV6_RECVDSTOPTS
+#define IPV6_RECVDSTOPTS	-1
+#endif
+#ifndef IPV6_RECVTCLASS
+#define IPV6_RECVTCLASS		-1
+#endif
+#ifndef IPV6_TCLASS
+#define IPV6_TCLASS		-1
+#endif
+#ifndef IPV6_2292PKTINFO
+#define	IPV6_2292PKTINFO	-1
+#endif
+#ifndef IPV6_2292HOPLIMIT
+#define	IPV6_2292HOPLIMIT	-1
+#endif
+#ifndef IPV6_2292RTHDR
+#define	IPV6_2292RTHDR		-1
+#endif
+#ifndef IPV6_2292HOPOPTS
+#define	IPV6_2292HOPOPTS	-1
+#endif
+#ifndef IPV6_2292DSTOPTS
+#define	IPV6_2292DSTOPTS	-1
+#endif
+
+union soval {
+	struct in6_pktinfo sou_pktinfo;
+	int sou_hoplimit;
+	struct sockaddr_in6 sou_nexthop;
+	struct ip6_rthdr sou_rthdr;
+	struct ip6_hbh sou_hopopts;
+	struct ip6_dest sou_dstopts;
+	struct ip6_dest sou_rthdrdstopts;
+	int sou_tclass;
+	int sou_bool;
+};
+
+/* in6_addr initializer for loopback interface */
+#define IN6_LOOP	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
+#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 */
+static struct soent {
+	char *so_tname;
+	int so_opt;
+	int so_dorecv;		/* do receive test? */
+	int so_cmtype;
+	int so_clear;		/* get fresh socket? */
+	union soval so_clrval;
+	union soval so_setval;
+	socklen_t so_valsize;
+} sotab[] = {
+	/* 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 */
+	unsigned char sop_dat[0];	/* user data */
+};
+
+static unsigned char tpbuf[sizeof(struct soprot) + 2048];
+static unsigned char rpbuf[sizeof(struct soprot) + 2048];
+
+static unsigned char control[2048];
+
+static int seq;
+
+static struct cme {
+	int cm_len;
+	int cm_level;
+	int cm_type;
+	union {
+		uint32_t cmu_tclass;
+		uint32_t cmu_hops;
+	} cmu;
+} cmtab[] = {
+	{sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {0x12} },
+	{sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {0x21} },
+};
+
+#define CMCOUNT	ARRAY_SIZE(cmtab)
+
+static ssize_t sendall(int st)
+{
+	struct sockaddr_in6 sin6;
+	struct msghdr msg;
+	struct iovec iov;
+	struct soprot *psop;
+	unsigned char *pd;
+	unsigned int i;
+	int ctotal;
+
+	psop = (struct soprot *)tpbuf;
+	psop->sop_pid = htonl(getpid());
+	psop->sop_seq = ++seq;
+	psop->sop_dlen = 0;
+
+	memset(&sin6, 0, sizeof(sin6));
+	sin6.sin6_family = AF_INET6;
+	sin6.sin6_addr = in6addr_loopback;
+
+	memset(&msg, 0, sizeof(msg));
+	msg.msg_name = &sin6;
+	msg.msg_namelen = sizeof(sin6);
+	iov.iov_base = tpbuf;
+	iov.iov_len = sizeof(struct soprot) + ntohl(psop->sop_dlen);
+	msg.msg_iov = &iov;
+	msg.msg_iovlen = 1;
+
+	pd = control;
+	ctotal = 0;
+	for (i = 0; i < CMCOUNT; ++i) {
+		struct cmsghdr *pcmsg = (struct cmsghdr *)pd;
+
+		pcmsg->cmsg_len = CMSG_LEN(cmtab[i].cm_len);
+		pcmsg->cmsg_level = cmtab[i].cm_level;
+		pcmsg->cmsg_type = cmtab[i].cm_type;
+		memcpy(CMSG_DATA(pcmsg), &cmtab[i].cmu, cmtab[i].cm_len);
+		pd += CMSG_SPACE(cmtab[i].cm_len);
+		ctotal += CMSG_SPACE(cmtab[i].cm_len);
+	}
+	msg.msg_control = ctotal ? control : 0;
+	msg.msg_controllen = ctotal;
+
+	return sendmsg(st, &msg, 0);
+}
+
+static void so_test(struct soent *psoe)
+{
+	struct sockaddr_in6 sin6;
+	union soval sobuf;
+	socklen_t valsize;
+	static int sr = -1;
+	int st;
+
+	if (psoe->so_opt == -1) {
+		tst_brkm(TBROK | TERRNO, NULL, "%s not present at compile time",
+			 psoe->so_tname);
+	}
+	if (psoe->so_clear || sr < 0) {
+		if (sr < 0)
+			close(sr);
+		sr = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+	}
+	memset(&sin6, 0, sizeof(sin6));
+	sin6.sin6_family = AF_INET6;
+	sin6.sin6_addr = in6addr_loopback;
+
+	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_brkm(TBROK | TERRNO, NULL, "%s: setsockopt",
+			 psoe->so_tname);
+	}
+
+	TEST(setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_setval,
+			psoe->so_valsize));
+	if (TEST_RETURN != 0) {
+		tst_resm(TFAIL | TERRNO, "%s set-get: setsockopt",
+			 psoe->so_tname);
+		return;
+	}
+
+	valsize = psoe->so_valsize;
+	TEST(getsockopt(sr, SOL_IPV6, psoe->so_opt, &sobuf, &valsize));
+	if (TEST_RETURN != 0) {
+		tst_brkm(TBROK | TERRNO, NULL, "%s set-get: getsockopt",
+			 psoe->so_tname);
+	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize)) {
+		tst_resm(TFAIL, "%s set-get optval != setval", psoe->so_tname);
+	} else {
+		tst_resm(TPASS, "%s set-get", psoe->so_tname);
+	}
+
+	st = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
+	if (sendall(st) < 0)
+		tst_brkm(TBROK | TERRNO, NULL, "%s transmit sendto",
+			 psoe->so_tname);
+
+	close(st);
+
+	/* receiver processing */
+	{
+		fd_set rfds, rfds_saved;
+		int nfds, cc;
+		int gotone;
+		struct timeval tv;
+		struct msghdr msg;
+		unsigned char cmsg[2048];
+		struct cmsghdr *pcmsg;
+		struct iovec iov;
+
+		FD_ZERO(&rfds_saved);
+		FD_SET(sr, &rfds_saved);
+
+		tv.tv_sec = 0;
+		tv.tv_usec = 250000;
+
+		while (1) {
+			memcpy(&rfds, &rfds_saved, sizeof(rfds));
+			nfds = select(sr + 1, &rfds, 0, 0, &tv);
+			if (nfds < 0) {
+				if (errno == EINTR)
+					continue;
+				tst_brkm(TBROK | TERRNO, NULL, "%s select",
+					 psoe->so_tname);
+			}
+			if (nfds == 0) {
+				tst_brkm(TBROK, NULL, "%s recvmsg timed out",
+					 psoe->so_tname);
+				return;
+			}
+			/* else, nfds == 1 */
+			if (!FD_ISSET(sr, &rfds))
+				continue;
+
+			memset(&msg, 0, sizeof(msg));
+			iov.iov_base = rpbuf;
+			iov.iov_len = sizeof(rpbuf);
+			msg.msg_iov = &iov;
+			msg.msg_iovlen = 1;
+			msg.msg_control = cmsg;
+			msg.msg_controllen = sizeof(cmsg);
+
+			cc = recvmsg(sr, &msg, 0);
+			if (cc < 0) {
+				tst_brkm(TBROK | TERRNO, NULL, "%s recvmsg",
+					 psoe->so_tname);
+			}
+			/* check pid & seq here */
+			break;
+		}
+		gotone = 0;
+		for (pcmsg = CMSG_FIRSTHDR(&msg); pcmsg != NULL;
+		     pcmsg = CMSG_NXTHDR(&msg, pcmsg)) {
+			if (!psoe->so_dorecv)
+				break;
+			gotone = pcmsg->cmsg_level == SOL_IPV6 &&
+			    pcmsg->cmsg_type == psoe->so_cmtype;
+			if (gotone) {
+				break;
+			} else if (psoe->so_clear) {
+				tst_resm(TFAIL, "%s receive: extraneous data "
+					 "in control: level %d type %d len %zu",
+					 psoe->so_tname, pcmsg->cmsg_level,
+					 pcmsg->cmsg_type, pcmsg->cmsg_len);
+				return;
+			}
+		}
+		/* check contents here */
+		if (psoe->so_dorecv)
+			tst_resm(gotone ? TPASS : TFAIL, "%s receive",
+				 psoe->so_tname);
+	}
+}
+
+static void do_tests(void)
+{
+	unsigned int i;
+
+	for (i = 0; i < SOCOUNT; ++i) {
+		sotab[i].so_clrval.sou_bool = 0;
+		sotab[i].so_setval.sou_bool = 1;
+		so_test(&sotab[i]);
+	}
+}
+
+static void setup(void)
+{
+	TEST_PAUSE;
+}
diff --git a/testcases/network/lib6/asapi_04.c b/testcases/network/lib6/asapi_04.c
deleted file mode 100644
index df26494..0000000
--- a/testcases/network/lib6/asapi_04.c
+++ /dev/null
@@ -1,460 +0,0 @@
-/*
- * Copyright (c) 2015 Fujitsu Ltd.
- * 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 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/>.
- *
- * Author: David L Stevens
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <netdb.h>
-#include <libgen.h>
-#include <pthread.h>
-#include <semaphore.h>
-
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "asapi_04";
-
-static pid_t pid;
-
-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		ARRAY_SIZE(ptab)
-#define READ_TIMEOUT	5
-
-static void do_tests(void);
-static void setup(void);
-static void csum_test(void);
-
-int main(int argc, char *argv[])
-{
-	int lc;
-
-	tst_parse_opts(argc, argv, 0, 0);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc)
-		do_tests();
-
-	tst_exit();
-}
-
-static void do_tests(void)
-{
-	unsigned int i;
-
-/* RFC 3542, Section 2.3 */
-#ifndef IN6_ARE_ADDR_EQUAL
-	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;
-
-	memset(&a1, 0, sizeof(a1));
-	memset(&a2, 0, sizeof(a2));
-
-	rv = IN6_ARE_ADDR_EQUAL(&a1, &a2);
-
-	for (word = 0; word < 4; ++word) {
-		for (bit = 0; bit < 32; ++bit) {
-			uint32_t newbit = 1U << bit;
-
-			a1.s6_addr32[word] |= newbit;
-			rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
-			a2.s6_addr32[word] |= newbit;
-			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 */
-	for (i = 0; i < PTCOUNT; ++i) {
-		struct protoent *pe;
-		int pass;
-
-		pe = getprotobyname(ptab[i].prt_name);
-		pass = pe && pe->p_proto == ptab[i].prt_value;
-		tst_resm(pass ? TPASS : TFAIL, "\"%s\" protocols entry",
-			 ptab[i].prt_name);
-	}
-/* RFC 3542, Section 3.1 */
-	csum_test();
-}
-
-/*
- * this next-header value shouldn't be a real protocol!!
- * 0x9f = 01 0 11111
- *         | |     |
- *         | |     |--- rest- ~0
- *         | |--------- chg - "no change enroute"
- *         |----------- act - "discard unknown"
- */
-#define	NH_TEST	0x9f
-
-struct tprot {
-	int tp_pid;		/* sender PID */
-	int tp_seq;		/* sequence # */
-	int tp_offset;		/* offset of cksum */
-	int tp_dlen;		/* tp_dat length */
-	unsigned char tp_dat[0];	/* user data */
-};
-
-static unsigned char tpbuf[sizeof(struct tprot) + 2048];
-static unsigned char rpbuf[sizeof(struct tprot) + 2048];
-
-static struct csent {
-	int cs_offset;
-	int cs_dlen;
-	int cs_setresult;	/* setsockopt expected result */
-	int cs_seterrno;	/* setsockopt expected errno */
-	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) */
-};
-
-#define CSCOUNT	ARRAY_SIZE(cstab)
-
-int TST_TOTAL = PTCOUNT + CSCOUNT;
-
-static int recvtprot(int sd, unsigned char *packet)
-{
-	struct tprot *tpt;
-	int cc;
-	unsigned int total, expected;
-	int gothead;
-
-	tpt = (struct tprot *)packet;
-	total = cc = recv(sd, packet, sizeof(struct tprot), 0);
-	expected = sizeof(struct tprot);	/* until we get tp_dlen */
-	gothead = total >= sizeof(struct tprot);
-	if (gothead)
-		expected += ntohl(tpt->tp_dlen);
-	if (cc <= 0)
-		return cc;
-	while (cc > 0 && total < expected) {
-		cc = recv(sd, &packet[total], expected - total, 0);
-		if (cc >= 0) {
-			total += cc;
-			if (!gothead && total >= sizeof(struct tprot)) {
-				gothead = 1;
-				expected += ntohl(tpt->tp_dlen);
-			}
-		} else {
-			break;
-		}
-	}
-	if (cc < 0)
-		return cc;
-	return total;
-}
-
-static unsigned short csum(unsigned short partial, unsigned char *packet,
-			   int len)
-{
-	unsigned long sum = partial;
-	unsigned short *ps;
-	int i;
-
-	ps = (unsigned short *)packet;
-	for (i = 0; i < len / 2; ++i)
-		sum += *ps++;
-	if (len & 1)
-		sum += htons(packet[len - 1] << 8);
-	sum = (sum >> 16) + (sum & 0xffff);
-	sum += (sum >> 16);
-	return ~sum;
-}
-
-static struct ph {
-	struct in6_addr ph_sa;
-	struct in6_addr ph_da;
-	uint32_t ph_len;
-	uint8_t ph_mbz[3];
-	uint8_t ph_nh;
-} ph;
-
-static int client(int sfd)
-{
-	struct tprot *pttp = (struct tprot *)tpbuf;
-	struct tprot *prtp = (struct tprot *)rpbuf;
-	struct sockaddr_in6 rsin6;
-	static int seq;
-	unsigned int i;
-	int sd, cc, cs;
-
-	memset(&rsin6, 0, sizeof(rsin6));
-	rsin6.sin6_family = AF_INET6;
-	rsin6.sin6_addr = in6addr_loopback;
-
-	memset(&ph, 0, sizeof(ph));
-	ph.ph_sa = rsin6.sin6_addr;
-	ph.ph_da = rsin6.sin6_addr;
-	ph.ph_nh = NH_TEST;
-
-	sd = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
-
-	for (i = 0; i < CSCOUNT; ++i) {
-		int offset, len, xlen;
-		int rv;
-		unsigned char *p, *pend;
-
-		offset = sizeof(struct tprot) + cstab[i].cs_offset;
-		len = sizeof(struct tprot) + cstab[i].cs_dlen;
-
-		memset(pttp, 0, sizeof(*pttp));
-		memset(pttp->tp_dat, 0xA5, cstab[i].cs_dlen);
-
-		pttp->tp_pid = htonl(pid);
-		pttp->tp_offset = ntohl(offset);
-		pttp->tp_dlen = ntohl(cstab[i].cs_dlen);
-		pttp->tp_seq = ntohl(++seq);
-
-		TEST(setsockopt(sd, IPPROTO_IPV6, IPV6_CHECKSUM, &offset,
-				sizeof(offset)));
-		if (TEST_RETURN != cstab[i].cs_setresult) {
-			tst_resm(TFAIL | TTERRNO,
-				 "IPV6_CHECKSUM offset %d len %d "
-				 "- result %ld != %d", offset, len, TEST_RETURN,
-				 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)));
-		xlen = (cstab[i].cs_sndresult < 0) ? -1 : len;
-		if (TEST_RETURN != xlen) {
-			tst_resm(TFAIL | TTERRNO,
-				 "IPV6_CHECKSUM offset %d len %d "
-				 "- sndresult %ld != %d", offset, len,
-				 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))) {
-			if (htonl(prtp->tp_pid) == (uint32_t)pid &&
-			    htonl(prtp->tp_seq) == (uint32_t)seq)
-				break;
-		}
-		rv = 1;
-		pend = rpbuf + sizeof(struct tprot) + ntohl(prtp->tp_dlen);
-		for (p = &prtp->tp_dat[0]; p < pend; ++p) {
-			if (p == &rpbuf[offset] || p == &rpbuf[offset + 1])
-				continue;
-			if (*p != 0xa5) {
-				tst_resm(TFAIL, "IPV6_CHECKSUM corrupt data "
-					 "0x%02x != 0xa5@offset %zd in packet",
-					 *p, p - rpbuf);
-				rv = 0;
-				break;
-			}
-		}
-		if (rv == 0)
-			continue;
-		ph.ph_len = htonl(xlen);
-		cs = csum(0, (unsigned char *)&ph, sizeof(ph));
-		cs = csum(~cs, rpbuf, xlen);
-		if (!csum(0, rpbuf, xlen)) {
-			tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d (bad "
-				 "checksum)", offset, len);
-			continue;
-		}
-		tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d", offset, len);
-	}
-	return 0;
-}
-
-static int listen_fd, connect_fd;
-
-static void *ilistener(void *arg LTP_ATTRIBUTE_UNUSED)
-{
-	connect_fd = accept(listen_fd, 0, 0);
-	close(listen_fd);
-	return NULL;
-}
-
-static void isocketpair(int pf, int type, int proto, int fd[2])
-{
-	pthread_t thid;
-	struct sockaddr_in sin4;
-	socklen_t namelen;
-
-	listen_fd = SAFE_SOCKET(NULL, pf, type, proto);
-
-	memset(&sin4, 0, sizeof(sin4));
-
-	SAFE_BIND(NULL, listen_fd, (struct sockaddr *)&sin4, sizeof(sin4));
-
-	SAFE_LISTEN(NULL, listen_fd, 10);
-
-	namelen = sizeof(sin4);
-	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);
-
-	sin4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-
-	SAFE_CONNECT(NULL, fd[0], (struct sockaddr *)&sin4, sizeof(sin4));
-
-	pthread_join(thid, NULL);
-
-	fd[1] = connect_fd;
-}
-
-#ifndef MAX
-#define MAX(a, b) (@ >= (b) ? (a) : (b))
-#endif /* MAX */
-
-static void csum_test(void)
-{
-	fd_set rset, rset_save;
-	int csd[2];		/* control sockets */
-	int sd, nfds, maxfd, cc;
-	struct timeval tv;
-
-	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);
-	memcpy(&rset, &rset_save, sizeof(rset));
-	maxfd = MAX(sd, csd[1]);
-
-	/* server socket set; now start the client */
-	switch (fork()) {
-	case 0:
-		close(csd[0]);
-		break;
-	case -1:
-		tst_brkm(TBROK, NULL, "can't fork rserver");
-	default:
-		close(sd);
-		close(csd[1]);
-		client(csd[0]);
-		return;
-	}
-
-	tv.tv_sec = READ_TIMEOUT;
-	tv.tv_usec = 0;
-	while ((nfds = select(maxfd + 1, &rset, 0, 0, &tv)) >= 0) {
-		if (nfds < 0) {
-			if (errno == EINTR)
-				continue;
-			exit(0);
-		} else if (nfds == 0) {
-			fprintf(stderr, "server read timed out");
-			return;
-		}
-		if (FD_ISSET(sd, &rset)) {
-			static char packet[2048];
-
-			cc = recv(sd, packet, sizeof(packet), 0);
-			if (cc < 0) {
-				perror("server recvtprot");
-				exit(1);
-			}
-			if (cc == 0)
-				exit(0);
-			if (write(csd[1], packet, cc) < 0) {
-				perror("server write UNIX socket");
-				exit(0);
-			}
-		}
-		if (FD_ISSET(csd[1], &rset)) {
-			char buf[2048];
-
-			cc = read(csd[1], buf, sizeof(buf));
-			if (cc == 0)
-				exit(0);
-			if (cc < 0) {
-				perror("server read");
-				exit(1);
-			}
-			/* handle commands here, if any added later */
-		}
-		memcpy(&rset, &rset_save, sizeof(rset));
-		tv.tv_sec = READ_TIMEOUT;
-		tv.tv_usec = 0;
-	}
-}
-
-static void setup(void)
-{
-	TEST_PAUSE;
-
-	pid = getpid();
-}
diff --git a/testcases/network/lib6/asapi_05.c b/testcases/network/lib6/asapi_05.c
deleted file mode 100644
index f8c30f1..0000000
--- a/testcases/network/lib6/asapi_05.c
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- * Copyright (c) 2015 Fujitsu Ltd.
- * 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 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/>.
- *
- * Author: David L Stevens
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <sys/wait.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <netinet/ip6.h>
-#include <netinet/icmp6.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "asapi_05";
-
-static void setup(void);
-
-static void icmp6_ft(void);
-
-int main(int argc, char *argv[])
-{
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc)
-		icmp6_ft();
-
-	tst_exit();
-}
-
-static void setup(void)
-{
-	TEST_PAUSE;
-	tst_require_root();
-}
-
-enum tt {
-	T_WILLPASS,
-	T_WILLBLOCK,
-	T_SETPASS,
-	T_SETBLOCK,
-	T_SETPASSALL,
-	T_SETBLOCKALL
-};
-
-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? */
-} 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	ARRAY_SIZE(ftab)
-
-static int ic6_send1(char *tname, unsigned char type)
-{
-	struct sockaddr_in6 sin6;
-	struct icmp6_hdr ic6;
-	int s;
-
-	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());
-
-	memset(&sin6, 0, sizeof(sin6));
-	sin6.sin6_family = AF_INET6;
-	sin6.sin6_addr = in6addr_loopback;
-	if (sendto(s, &ic6, sizeof(ic6), 0, (struct sockaddr *)&sin6,
-		   sizeof(sin6)) == -1) {
-		tst_resm(TBROK | TERRNO, "%s: sendto failed", tname);
-		return 1;
-	}
-	return 0;
-}
-
-static int ic6_recv1(char *tname, int sall, int sf)
-{
-	fd_set readfds, readfds_saved;
-	struct timeval tv;
-	int maxfd, nfds;
-	int gotall, gotone;
-	int cc;
-	static unsigned char rbuf[2048];
-
-	tv.tv_sec = 0;
-	tv.tv_usec = 250000;
-
-	FD_ZERO(&readfds_saved);
-	FD_SET(sall, &readfds_saved);
-	FD_SET(sf, &readfds_saved);
-	maxfd = MAX(sall, sf);
-
-	memcpy(&readfds, &readfds_saved, sizeof(readfds));
-
-	gotall = gotone = 0;
-	/*
-	 * Note: this relies on linux-specific behavior (select
-	 * updating tv with time elapsed)
-	 */
-	while (!gotall || !gotone) {
-		struct icmp6_hdr *pic6 = (struct icmp6_hdr *)rbuf;
-
-		nfds = select(maxfd + 1, &readfds, 0, 0, &tv);
-		if (nfds == 0)
-			break;	/* timed out */
-		if (nfds < 0) {
-			if (errno == EINTR)
-				continue;
-			tst_resm(TBROK | TERRNO, "%s: select failed", tname);
-		}
-		if (FD_ISSET(sall, &readfds)) {
-			cc = recv(sall, rbuf, sizeof(rbuf), 0);
-			if (cc < 0) {
-				tst_resm(TBROK | TERRNO,
-					 "%s: recv(sall, ..) failed", tname);
-				return -1;
-			}
-			/* if packet check succeeds... */
-			if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid())
-				gotall = 1;
-		}
-		if (FD_ISSET(sf, &readfds)) {
-			cc = recv(sf, rbuf, sizeof(rbuf), 0);
-			if (cc < 0) {
-				tst_resm(TBROK | TERRNO,
-					 "%s: recv(sf, ..) failed", tname);
-				return -1;
-			}
-			/* if packet check succeeds... */
-			if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid())
-				gotone = 1;
-		}
-		memcpy(&readfds, &readfds_saved, sizeof(readfds));
-	}
-	if (!gotall) {
-		tst_resm(TBROK, "%s: recv all timed out", tname);
-		return -1;
-	}
-	if (gotone)
-		return 1;
-	return 0;
-}
-
-/* functional tests */
-static void icmp6_ft(void)
-{
-	struct icmp6_filter i6f;
-	int sall, sf;
-	unsigned int i;
-
-	sall = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
-
-	ICMP6_FILTER_SETPASSALL(&i6f);
-	if (setsockopt(sall, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f,
-		       sizeof(i6f)) < 0) {
-		tst_resm(TBROK | TERRNO,
-			 "setsockopt pass all ICMP6_FILTER failed");
-	}
-
-	sf = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
-
-	int rv;
-
-	for (i = 0; i < FTCOUNT; ++i) {
-
-		rv = -1;
-
-		switch (ftab[i].ft_test) {
-		case T_SETPASS:
-			ICMP6_FILTER_SETBLOCKALL(&i6f);
-			ICMP6_FILTER_SETPASS(ftab[i].ft_flttype, &i6f);
-			break;
-		case T_SETPASSALL:
-			ICMP6_FILTER_SETPASSALL(&i6f);
-			break;
-		case T_SETBLOCK:
-			ICMP6_FILTER_SETPASSALL(&i6f);
-			ICMP6_FILTER_SETBLOCK(ftab[i].ft_flttype, &i6f);
-			break;
-		case T_SETBLOCKALL:
-			ICMP6_FILTER_SETBLOCKALL(&i6f);
-			break;
-		case T_WILLBLOCK:
-			ICMP6_FILTER_SETPASSALL(&i6f);
-			ICMP6_FILTER_SETBLOCK(ftab[i].ft_flttype, &i6f);
-			rv = ICMP6_FILTER_WILLBLOCK(ftab[i].ft_sndtype, &i6f);
-			break;
-		case T_WILLPASS:
-			ICMP6_FILTER_SETBLOCKALL(&i6f);
-			ICMP6_FILTER_SETPASS(ftab[i].ft_flttype, &i6f);
-			rv = ICMP6_FILTER_WILLPASS(ftab[i].ft_sndtype, &i6f);
-			break;
-		default:
-			tst_resm(TBROK, "%s: unknown test type %d",
-				 ftab[i].ft_tname, ftab[i].ft_test);
-			continue;
-		}
-		if (ftab[i].ft_test != T_WILLBLOCK &&
-		    ftab[i].ft_test != T_WILLPASS) {
-			if (setsockopt(sf, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f,
-				       sizeof(i6f)) < 0) {
-				tst_resm(TFAIL | TERRNO,
-					 "setsockopt ICMP6_FILTER");
-				continue;
-			}
-			if (ic6_send1(ftab[i].ft_tname, ftab[i].ft_sndtype))
-				continue;
-			rv = ic6_recv1(ftab[i].ft_tname, sall, sf);
-		} else {
-			rv = -1;
-		}
-
-		if (rv < 0)
-			continue;
-		if (rv != ftab[i].ft_expected)
-			tst_resm(TFAIL, "%s: rv %d != expected %d",
-				 ftab[i].ft_tname, rv, ftab[i].ft_expected);
-		else
-			tst_resm(TPASS, "%s", ftab[i].ft_tname);
-	}
-}
diff --git a/testcases/network/lib6/asapi_06.c b/testcases/network/lib6/asapi_06.c
deleted file mode 100644
index c6e2c8e..0000000
--- a/testcases/network/lib6/asapi_06.c
+++ /dev/null
@@ -1,385 +0,0 @@
-/*
- * Copyright (c) 2015 Fujitsu Ltd.
- * 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 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/>.
- *
- * Author: David L Stevens
- */
-
-#include "config.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <netdb.h>
-#include <libgen.h>
-#include <pthread.h>
-#include <semaphore.h>
-
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <netinet/ip6.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <sys/ioctl.h>
-#ifdef HAVE_IFADDRS_H
-#include <ifaddrs.h>
-#endif
-#include <arpa/inet.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "asapi_06";
-
-int TST_TOTAL = 1;
-
-#define READ_TIMEOUT	5	/* secs */
-
-static void do_tests(void);
-static void setup(void);
-
-int main(int argc, char *argv[])
-{
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc)
-		do_tests();
-
-	tst_exit();
-}
-
-#define NH_TEST	0x9f
-
-#ifndef IPV6_RECVPKTINFO
-#define IPV6_RECVPKTINFO	-1
-#endif
-#ifndef IPV6_RECVHOPLIMIT
-#define IPV6_RECVHOPLIMIT	-1
-#endif
-#ifndef IPV6_RECVRTHDR
-#define IPV6_RECVRTHDR		-1
-#endif
-#ifndef IPV6_RECVHOPOPTS
-#define IPV6_RECVHOPOPTS	-1
-#endif
-#ifndef IPV6_RECVDSTOPTS
-#define IPV6_RECVDSTOPTS	-1
-#endif
-#ifndef IPV6_RECVTCLASS
-#define IPV6_RECVTCLASS		-1
-#endif
-#ifndef IPV6_TCLASS
-#define IPV6_TCLASS		-1
-#endif
-#ifndef IPV6_2292PKTINFO
-#define	IPV6_2292PKTINFO	-1
-#endif
-#ifndef IPV6_2292HOPLIMIT
-#define	IPV6_2292HOPLIMIT	-1
-#endif
-#ifndef IPV6_2292RTHDR
-#define	IPV6_2292RTHDR		-1
-#endif
-#ifndef IPV6_2292HOPOPTS
-#define	IPV6_2292HOPOPTS	-1
-#endif
-#ifndef IPV6_2292DSTOPTS
-#define	IPV6_2292DSTOPTS	-1
-#endif
-
-union soval {
-	struct in6_pktinfo sou_pktinfo;
-	int sou_hoplimit;
-	struct sockaddr_in6 sou_nexthop;
-	struct ip6_rthdr sou_rthdr;
-	struct ip6_hbh sou_hopopts;
-	struct ip6_dest sou_dstopts;
-	struct ip6_dest sou_rthdrdstopts;
-	int sou_tclass;
-	int sou_bool;
-};
-
-/* in6_addr initializer for loopback interface */
-#define IN6_LOOP	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
-#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 */
-static struct soent {
-	char *so_tname;
-	int so_opt;
-	int so_dorecv;		/* do receive test? */
-	int so_cmtype;
-	int so_clear;		/* get fresh socket? */
-	union soval so_clrval;
-	union soval so_setval;
-	socklen_t so_valsize;
-} sotab[] = {
-	/* 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 */
-	unsigned char sop_dat[0];	/* user data */
-};
-
-static unsigned char tpbuf[sizeof(struct soprot) + 2048];
-static unsigned char rpbuf[sizeof(struct soprot) + 2048];
-
-static unsigned char control[2048];
-
-static int seq;
-
-static struct cme {
-	int cm_len;
-	int cm_level;
-	int cm_type;
-	union {
-		uint32_t cmu_tclass;
-		uint32_t cmu_hops;
-	} cmu;
-} cmtab[] = {
-	{sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {0x12} },
-	{sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {0x21} },
-};
-
-#define CMCOUNT	ARRAY_SIZE(cmtab)
-
-static ssize_t sendall(int st)
-{
-	struct sockaddr_in6 sin6;
-	struct msghdr msg;
-	struct iovec iov;
-	struct soprot *psop;
-	unsigned char *pd;
-	unsigned int i;
-	int ctotal;
-
-	psop = (struct soprot *)tpbuf;
-	psop->sop_pid = htonl(getpid());
-	psop->sop_seq = ++seq;
-	psop->sop_dlen = 0;
-
-	memset(&sin6, 0, sizeof(sin6));
-	sin6.sin6_family = AF_INET6;
-	sin6.sin6_addr = in6addr_loopback;
-
-	memset(&msg, 0, sizeof(msg));
-	msg.msg_name = &sin6;
-	msg.msg_namelen = sizeof(sin6);
-	iov.iov_base = tpbuf;
-	iov.iov_len = sizeof(struct soprot) + ntohl(psop->sop_dlen);
-	msg.msg_iov = &iov;
-	msg.msg_iovlen = 1;
-
-	pd = control;
-	ctotal = 0;
-	for (i = 0; i < CMCOUNT; ++i) {
-		struct cmsghdr *pcmsg = (struct cmsghdr *)pd;
-
-		pcmsg->cmsg_len = CMSG_LEN(cmtab[i].cm_len);
-		pcmsg->cmsg_level = cmtab[i].cm_level;
-		pcmsg->cmsg_type = cmtab[i].cm_type;
-		memcpy(CMSG_DATA(pcmsg), &cmtab[i].cmu, cmtab[i].cm_len);
-		pd += CMSG_SPACE(cmtab[i].cm_len);
-		ctotal += CMSG_SPACE(cmtab[i].cm_len);
-	}
-	msg.msg_control = ctotal ? control : 0;
-	msg.msg_controllen = ctotal;
-
-	return sendmsg(st, &msg, 0);
-}
-
-static void so_test(struct soent *psoe)
-{
-	struct sockaddr_in6 sin6;
-	union soval sobuf;
-	socklen_t valsize;
-	static int sr = -1;
-	int st;
-
-	if (psoe->so_opt == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "%s not present at compile time",
-			 psoe->so_tname);
-	}
-	if (psoe->so_clear || sr < 0) {
-		if (sr < 0)
-			close(sr);
-		sr = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
-	}
-	memset(&sin6, 0, sizeof(sin6));
-	sin6.sin6_family = AF_INET6;
-	sin6.sin6_addr = in6addr_loopback;
-
-	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_brkm(TBROK | TERRNO, NULL, "%s: setsockopt",
-			 psoe->so_tname);
-	}
-
-	TEST(setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_setval,
-			psoe->so_valsize));
-	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL | TERRNO, "%s set-get: setsockopt",
-			 psoe->so_tname);
-		return;
-	}
-
-	valsize = psoe->so_valsize;
-	TEST(getsockopt(sr, SOL_IPV6, psoe->so_opt, &sobuf, &valsize));
-	if (TEST_RETURN != 0) {
-		tst_brkm(TBROK | TERRNO, NULL, "%s set-get: getsockopt",
-			 psoe->so_tname);
-	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize)) {
-		tst_resm(TFAIL, "%s set-get optval != setval", psoe->so_tname);
-	} else {
-		tst_resm(TPASS, "%s set-get", psoe->so_tname);
-	}
-
-	st = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
-
-	if (sendall(st) < 0)
-		tst_brkm(TBROK | TERRNO, NULL, "%s transmit sendto",
-			 psoe->so_tname);
-
-	close(st);
-
-	/* receiver processing */
-	{
-		fd_set rfds, rfds_saved;
-		int nfds, cc;
-		int gotone;
-		struct timeval tv;
-		struct msghdr msg;
-		unsigned char cmsg[2048];
-		struct cmsghdr *pcmsg;
-		struct iovec iov;
-
-		FD_ZERO(&rfds_saved);
-		FD_SET(sr, &rfds_saved);
-
-		tv.tv_sec = 0;
-		tv.tv_usec = 250000;
-
-		while (1) {
-			memcpy(&rfds, &rfds_saved, sizeof(rfds));
-			nfds = select(sr + 1, &rfds, 0, 0, &tv);
-			if (nfds < 0) {
-				if (errno == EINTR)
-					continue;
-				tst_brkm(TBROK | TERRNO, NULL, "%s select",
-					 psoe->so_tname);
-			}
-			if (nfds == 0) {
-				tst_brkm(TBROK, NULL, "%s recvmsg timed out",
-					 psoe->so_tname);
-				return;
-			}
-			/* else, nfds == 1 */
-			if (!FD_ISSET(sr, &rfds))
-				continue;
-
-			memset(&msg, 0, sizeof(msg));
-			iov.iov_base = rpbuf;
-			iov.iov_len = sizeof(rpbuf);
-			msg.msg_iov = &iov;
-			msg.msg_iovlen = 1;
-			msg.msg_control = cmsg;
-			msg.msg_controllen = sizeof(cmsg);
-
-			cc = recvmsg(sr, &msg, 0);
-			if (cc < 0) {
-				tst_brkm(TBROK | TERRNO, NULL, "%s recvmsg",
-					 psoe->so_tname);
-			}
-			/* check pid & seq here */
-			break;
-		}
-		gotone = 0;
-		for (pcmsg = CMSG_FIRSTHDR(&msg); pcmsg != NULL;
-		     pcmsg = CMSG_NXTHDR(&msg, pcmsg)) {
-			if (!psoe->so_dorecv)
-				break;
-			gotone = pcmsg->cmsg_level == SOL_IPV6 &&
-			    pcmsg->cmsg_type == psoe->so_cmtype;
-			if (gotone) {
-				break;
-			} else if (psoe->so_clear) {
-				tst_resm(TFAIL, "%s receive: extraneous data "
-					 "in control: level %d type %d len %zu",
-					 psoe->so_tname, pcmsg->cmsg_level,
-					 pcmsg->cmsg_type, pcmsg->cmsg_len);
-				return;
-			}
-		}
-		/* check contents here */
-		if (psoe->so_dorecv)
-			tst_resm(gotone ? TPASS : TFAIL, "%s receive",
-				 psoe->so_tname);
-	}
-}
-
-static void do_tests(void)
-{
-	unsigned int i;
-
-	for (i = 0; i < SOCOUNT; ++i) {
-		sotab[i].so_clrval.sou_bool = 0;
-		sotab[i].so_setval.sou_bool = 1;
-		so_test(&sotab[i]);
-	}
-}
-
-static void setup(void)
-{
-	TEST_PAUSE;
-}
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v9 8/8] ipv6_lib: Add it into default
  2015-10-14  8:21           ` [LTP] [PATCH v9 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                               ` (5 preceding siblings ...)
  2015-10-14  8:21             ` [LTP] [PATCH v9 7/8] lib6: Rename Zeng Linggang
@ 2015-10-14  8:21             ` Zeng Linggang
  6 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-14  8:21 UTC (permalink / raw)
  To: ltp

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 scenario_groups/default | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scenario_groups/default b/scenario_groups/default
index 3a55702..60b1b27 100644
--- a/scenario_groups/default
+++ b/scenario_groups/default
@@ -32,3 +32,4 @@ dma_thread_diotest
 cpuacct
 can
 cpuhotplug
+ipv6_lib
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v9 6/8] lib6/getaddrinfo_01.c: Cleanup
  2015-10-14  8:21             ` [LTP] [PATCH v9 6/8] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
@ 2015-10-20  8:07               ` Alexey Kodanev
  2015-10-21  2:47                 ` Zeng Linggang
  2015-10-21  3:15                 ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
  0 siblings, 2 replies; 38+ messages in thread
From: Alexey Kodanev @ 2015-10-20  8:07 UTC (permalink / raw)
  To: ltp

Hi,
On 10/14/2015 11:21 AM, Zeng Linggang wrote:
> * 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.

Sorry for delay, I was going to push the patch-set but encountered with 
a lot of warnings produced by checkpatch utility. Basically, they are 
all because of either "else is not generally usefull after break or 
return" or "quoted string split across lines". Then I noted that 
test-cases there have wrong structure, comments are below.

Also,
asapi_06.c: "commit description ... possible unwrapped" - you can trim 
commit id a little, it will still be accessable.


>   
> -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;
> +	}
>   

If you write the description of the particular test-case before the 
test, you don't need to repeat the same description in each TPASS/TFAIL 
messages after. Test-case should end with either TPASS or TFAIL, not 
TINFO. Therefore all test-cases below could be something like this:

tst_resm(TINFO, "getaddrinfo IPv4 basic lookup");
TEST(...);
if (!TEST_RETURN) {
     if (error) {
         tst_resm(TFAIL, "");
         return;
     }

     tst_resm(TPASS, "test finished");
} else {
     tst_resm(TFAIL, "...");
}

Best regards,
Alexey


^ permalink raw reply	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v9 6/8] lib6/getaddrinfo_01.c: Cleanup
  2015-10-20  8:07               ` Alexey Kodanev
@ 2015-10-21  2:47                 ` Zeng Linggang
  2015-10-21  3:15                 ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
  1 sibling, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-21  2:47 UTC (permalink / raw)
  To: ltp

Hello,

On Tue, 2015-10-20 at 11:07 +0300, Alexey Kodanev wrote:
> Hi,
> On 10/14/2015 11:21 AM, Zeng Linggang wrote:
> > * 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.
> 
> Sorry for delay, I was going to push the patch-set but encountered with 
> a lot of warnings produced by checkpatch utility. Basically, they are 
> all because of either "else is not generally usefull after break or 
> return" or "quoted string split across lines". Then I noted that 
> test-cases there have wrong structure, comments are below.
> 
> Also,
> asapi_06.c: "commit description ... possible unwrapped" - you can trim 
> commit id a little, it will still be accessable.
> 

Hmm, I found the 'checkpatch.pl' which I used is a little out of date,
it did not output this ERROR.

> 
> >   
> > -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;
> > +	}
> >   
> 
> If you write the description of the particular test-case before the 
> test, you don't need to repeat the same description in each TPASS/TFAIL 
> messages after. Test-case should end with either TPASS or TFAIL, not 
> TINFO. Therefore all test-cases below could be something like this:
> 
> tst_resm(TINFO, "getaddrinfo IPv4 basic lookup");
> TEST(...);
> if (!TEST_RETURN) {
>      if (error) {
>          tst_resm(TFAIL, "");
>          return;
>      }
> 
>      tst_resm(TPASS, "test finished");
> } else {
>      tst_resm(TFAIL, "...");
> }
> 

This is OK.

Thanks and best regards,
Zeng

> Best regards,
> Alexey
> 



^ permalink raw reply	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it.
  2015-10-20  8:07               ` Alexey Kodanev
  2015-10-21  2:47                 ` Zeng Linggang
@ 2015-10-21  3:15                 ` Zeng Linggang
  2015-10-21  3:15                   ` [LTP] [PATCH v10 2/8] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
                                     ` (7 more replies)
  1 sibling, 8 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-21  3:15 UTC (permalink / raw)
  To: ltp

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 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


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v10 2/8] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname()
  2015-10-21  3:15                 ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
@ 2015-10-21  3:15                   ` Zeng Linggang
  2015-10-21  3:15                   ` [LTP] [PATCH v10 3/8] lib6/asapi_04.c: Cleanup Zeng Linggang
                                     ` (6 subsequent siblings)
  7 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-21  3:15 UTC (permalink / raw)
  To: ltp

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 include/safe_macros.h |   1 +
 include/safe_net.h    |  60 ++++++++++++++++
 lib/safe_net.c        | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 246 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..2f8811c
--- /dev/null
+++ b/include/safe_net.h
@@ -0,0 +1,60 @@
+/*
+ * 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>
+#include <sys/un.h>
+
+char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen, char *res,
+		    size_t len);
+
+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..f02e68e
--- /dev/null
+++ b/lib/safe_net.c
@@ -0,0 +1,185 @@
+/*
+ * 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"
+
+char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen, char *res,
+		    size_t len)
+{
+	char portstr[8];
+
+	switch (sa->sa_family) {
+
+	case AF_INET: {
+		struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+
+		if (!inet_ntop(AF_INET, &sin->sin_addr, res, len))
+			return NULL;
+
+		if (ntohs(sin->sin_port) != 0) {
+			snprintf(portstr, sizeof(portstr), ":%d",
+				 ntohs(sin->sin_port));
+			strcat(res, portstr);
+		}
+
+		return res;
+	}
+
+	case AF_INET6: {
+		struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
+
+		res[0] = '[';
+		if (!inet_ntop(AF_INET6, &sin6->sin6_addr, res + 1, len - 1))
+			return NULL;
+
+		if (ntohs(sin6->sin6_port) != 0) {
+			snprintf(portstr, sizeof(portstr), "]:%d",
+				 ntohs(sin6->sin6_port));
+			strcat(res, portstr);
+			return res;
+		}
+
+		return res + 1;
+	}
+
+	case AF_UNIX: {
+		struct sockaddr_un *unp = (struct sockaddr_un *)sa;
+
+		if (unp->sun_path[0] == '\0')
+			strcpy(res, "(no pathname bound)");
+		else
+			snprintf(res, len, "%s", unp->sun_path);
+
+		return res;
+	}
+
+	default: {
+		snprintf(res, len,
+			 "sock_ntop: unknown AF_xxx: %d, len: %d",
+			 sa->sa_family, salen);
+
+		return res;
+	}
+
+	}
+}
+
+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;
+	char buf[128];
+
+	for (i = 0; i < 120; i++) {
+		if (!bind(socket, address, address_len))
+			return 0;
+
+		if (errno != EADDRINUSE) {
+			tst_brkm(TBROK | TERRNO, cleanup_fn,
+				 "%s:%d: bind(%d, %s, %d) failed", file, lineno,
+				 socket, tst_sock_addr(address, address_len,
+						       buf, sizeof(buf)),
+				 address_len);
+		}
+
+		if ((i + 1) % 10 == 0) {
+			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, %s, %d) after 120 retries", file,
+		 lineno, socket,
+		 tst_sock_addr(address, address_len, buf, sizeof(buf)),
+		 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;
+	char buf[128];
+
+	rval = connect(sockfd, addr, addrlen);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: connect(%d, %s, %d) failed", file, lineno,
+			 sockfd, tst_sock_addr(addr, addrlen, buf,
+					       sizeof(buf)), 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;
+	char buf[128];
+
+	rval = getsockname(sockfd, addr, addrlen);
+
+	if (rval < 0) {
+		tst_brkm(TBROK | TERRNO, cleanup_fn,
+			 "%s:%d: getsockname(%d, %s, %d) failed", file, lineno,
+			 sockfd, tst_sock_addr(addr, *addrlen, buf,
+					       sizeof(buf)), *addrlen);
+	}
+
+	return rval;
+}
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v10 3/8] lib6/asapi_04.c: Cleanup
  2015-10-21  3:15                 ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
  2015-10-21  3:15                   ` [LTP] [PATCH v10 2/8] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
@ 2015-10-21  3:15                   ` Zeng Linggang
  2015-10-21  3:15                   ` [LTP] [PATCH v10 4/8] lib6/asapi_05.c: Cleanup Zeng Linggang
                                     ` (5 subsequent siblings)
  7 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-21  3:15 UTC (permalink / raw)
  To: ltp

* Add 'static' before some functions and global variables.
* Remove useless comments.
* Use SAFE_XXX().
* Modify the format of ptab[] and cstab[].
* Use 'pthread_join()' instead of 'sem_*'.
* Rewrite 'csum_test()' and 'isocketpair()'.
* Remove cleanup().
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_04.c | 301 +++++++++++++++-----------------------
 1 file changed, 117 insertions(+), 184 deletions(-)

diff --git a/testcases/network/lib6/asapi_04.c b/testcases/network/lib6/asapi_04.c
index 76de26b..ff310ea 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,33 @@
 #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 READ_TIMEOUT	5	/* secs */
+#define PTCOUNT		ARRAY_SIZE(ptab)
+#define READ_TIMEOUT	5
 
-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 csum_test(void);
 
 int main(int argc, char *argv[])
 {
@@ -82,52 +65,48 @@ int main(int argc, char *argv[])
 
 	tst_parse_opts(argc, argv, 0, 0);
 
-	pid = getpid();
-
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); ++lc)
 		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;
+			rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
+			a2.s6_addr32[word] |= newbit;
+			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 +120,7 @@ void do_tests(void)
 			 ptab[i].prt_name);
 	}
 /* RFC 3542, Section 3.1 */
-	csum_test("::1");
+	csum_test();
 }
 
 /*
@@ -162,10 +141,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 +152,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)
 
-static int recvtprot(int sd, unsigned char *packet, int psize)
+int TST_TOTAL = PTCOUNT + CSCOUNT;
+
+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;
@@ -210,15 +188,17 @@ static int recvtprot(int sd, unsigned char *packet, int psize)
 				gothead = 1;
 				expected += ntohl(tpt->tp_dlen);
 			}
-		} else
+		} else {
 			break;
+		}
 	}
 	if (cc < 0)
 		return cc;
 	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 +214,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 +222,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 +240,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;
@@ -322,9 +300,9 @@ static int client(int prot, int sfd)
 				 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 +312,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, offset %zd in packet",
 					 *p, p - rpbuf);
 				rv = 0;
 				break;
@@ -356,99 +334,60 @@ 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);
-	sem_post(&ilsem);
 	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;
 	socklen_t namelen;
 
-/* restrict to PF_INET for now */
-	if (pf != PF_INET) {
-		errno = EOPNOTSUPP;
-		return -1;
-	}
-	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;
-	}
-	sem_wait(&ilsem);
+
+	SAFE_CONNECT(NULL, fd[0], (struct sockaddr *)&sin4, sizeof(sin4));
+
+	pthread_join(thid, NULL);
+
 	fd[1] = connect_fd;
-	sem_destroy(&ilsem);
-	return 0;
 }
 
 #ifndef MAX
 #define MAX(a, b) (@ >= (b) ? (a) : (b))
 #endif /* MAX */
 
-int csum_test(char *rhost)
+static void 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 +396,16 @@ 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]);
+		client(csd[0]);
+		return;
 	}
 
 	tv.tv_sec = READ_TIMEOUT;
@@ -478,7 +417,7 @@ int csum_test(char *rhost)
 			exit(0);
 		} else if (nfds == 0) {
 			fprintf(stderr, "server read timed out");
-			return -1;
+			return;
 		}
 		if (FD_ISSET(sd, &rset)) {
 			static char packet[2048];
@@ -499,9 +438,8 @@ int csum_test(char *rhost)
 			char buf[2048];
 
 			cc = read(csd[1], buf, sizeof(buf));
-			if (cc == 0) {
+			if (cc == 0)
 				exit(0);
-			}
 			if (cc < 0) {
 				perror("server read");
 				exit(1);
@@ -512,16 +450,11 @@ int csum_test(char *rhost)
 		tv.tv_sec = READ_TIMEOUT;
 		tv.tv_usec = 0;
 	}
-	return 0;
 }
 
-void setup(void)
+static void setup(void)
 {
-	TEST_PAUSE;		/* if -P option specified */
-}
+	TEST_PAUSE;
 
-void cleanup(void)
-{
+	pid = getpid();
 }
-
-int TST_TOTAL = PTCOUNT + CSCOUNT;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v10 4/8] lib6/asapi_05.c: Cleanup
  2015-10-21  3:15                 ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
  2015-10-21  3:15                   ` [LTP] [PATCH v10 2/8] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
  2015-10-21  3:15                   ` [LTP] [PATCH v10 3/8] lib6/asapi_04.c: Cleanup Zeng Linggang
@ 2015-10-21  3:15                   ` Zeng Linggang
  2015-10-21  3:15                   ` [LTP] [PATCH v10 5/8] lib6/asapi_06.c: Cleanup Zeng Linggang
                                     ` (4 subsequent siblings)
  7 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-21  3:15 UTC (permalink / raw)
  To: ltp

* Add 'static' before some functions and global variables.
* Remove cleanup().
* Remove useless comments.
* Use SAFE_XXX().
* Modify the format of etab[] and ftab[].
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_05.c | 159 ++++++++++++++------------------------
 1 file changed, 60 insertions(+), 99 deletions(-)

diff --git a/testcases/network/lib6/asapi_05.c b/testcases/network/lib6/asapi_05.c
index e251eee..f8c30f1 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,74 @@
 #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);
 
-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();
 }
 
-void cleanup(void)
-{
-}
-
-/*
- * 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 +113,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 +156,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 +167,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 +182,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 +197,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;
 
@@ -284,8 +246,9 @@ void icmp6_ft(void)
 			if (ic6_send1(ftab[i].ft_tname, ftab[i].ft_sndtype))
 				continue;
 			rv = ic6_recv1(ftab[i].ft_tname, sall, sf);
-		} else
+		} else {
 			rv = -1;
+		}
 
 		if (rv < 0)
 			continue;
@@ -296,5 +259,3 @@ void icmp6_ft(void)
 			tst_resm(TPASS, "%s", ftab[i].ft_tname);
 	}
 }
-
-int TST_TOTAL = FTCOUNT;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v10 5/8] lib6/asapi_06.c: Cleanup
  2015-10-21  3:15                 ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                                     ` (2 preceding siblings ...)
  2015-10-21  3:15                   ` [LTP] [PATCH v10 4/8] lib6/asapi_05.c: Cleanup Zeng Linggang
@ 2015-10-21  3:15                   ` Zeng Linggang
  2015-10-21  3:15                   ` [LTP] [PATCH v10 6/8] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
                                     ` (3 subsequent siblings)
  7 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-21  3:15 UTC (permalink / raw)
  To: ltp

* Add 'static' before some functions and global variables.
* Remove cleanup().
* Remove useless comments.
* Use SAFE_XXX().
* Remove unused variables.
* Modify the format of sotab[] and cmtab[].
* Modify the initialization of sotab[].
* Remove IPV6_PKTINFO test. IPV6_PKTINFO is only implemented
  by setsockopt() not by getsockopt(). see:
  'commit b24a2516d107
  ("ipv6: Add IPV6_PKTINFO sticky option support to setsockopt()")'
  in Linux kernel.
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_06.c | 473 ++++++++------------------------------
 1 file changed, 99 insertions(+), 374 deletions(-)

diff --git a/testcases/network/lib6/asapi_06.c b/testcases/network/lib6/asapi_06.c
index 960ebb5..c6e2c8e 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,16 @@
 #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]))
-
 #define READ_TIMEOUT	5	/* secs */
 
-void do_tests(void);
-void setup(void), cleanup(void);
+static void do_tests(void);
+static void setup(void);
 
 int main(int argc, char *argv[])
 {
@@ -83,14 +58,11 @@ int main(int argc, char *argv[])
 
 	tst_parse_opts(argc, argv, NULL, NULL);
 
-	pid = getpid();
-
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); ++lc)
 		do_tests();
 
-	cleanup();
 	tst_exit();
 }
 
@@ -150,7 +122,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 +132,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 +186,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 +237,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;
@@ -300,63 +246,51 @@ void so_test(struct soent *psoe)
 	int st;
 
 	if (psoe->so_opt == -1) {
-		tst_resm(TBROK, "%s not present at compile time",
+		tst_brkm(TBROK | TERRNO, NULL, "%s not present at compile time",
 			 psoe->so_tname);
-		return;
 	}
 	if (psoe->so_clear || sr < 0) {
 		if (sr < 0)
 			close(sr);
-		sr = socket(PF_INET6, SOCK_RAW, NH_TEST);
-		if (sr < 0) {
-			tst_resm(TBROK, "%s socket: %s", psoe->so_tname,
-				 strerror(errno));
-			return;
-		}
+		sr = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
 	}
 	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,
-			 strerror(errno));
-		return;
+		tst_brkm(TBROK | TERRNO, NULL, "%s: setsockopt",
+			 psoe->so_tname);
 	}
+
 	TEST(setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_setval,
 			psoe->so_valsize));
 	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL, "%s set-get: setsockopt: %s", psoe->so_tname,
-			 strerror(errno));
+		tst_resm(TFAIL | TERRNO, "%s set-get: setsockopt",
+			 psoe->so_tname);
 		return;
 	}
+
 	valsize = psoe->so_valsize;
 	TEST(getsockopt(sr, SOL_IPV6, psoe->so_opt, &sobuf, &valsize));
 	if (TEST_RETURN != 0) {
-		tst_resm(TBROK, "%s set-get: getsockopt: %s", psoe->so_tname,
-			 strerror(errno));
-		return;
-	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize))
+		tst_brkm(TBROK | TERRNO, NULL, "%s set-get: getsockopt",
+			 psoe->so_tname);
+	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize)) {
 		tst_resm(TFAIL, "%s set-get optval != setval", psoe->so_tname);
-	else
+	} 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;
-	}
-	if (sendall(st) < 0) {
-		tst_resm(TBROK, "%s transmit sendto: %s", psoe->so_tname,
-			 strerror(errno));
-		close(st);
-		return;
 	}
+
+	st = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
+	if (sendall(st) < 0)
+		tst_brkm(TBROK | TERRNO, NULL, "%s transmit sendto",
+			 psoe->so_tname);
+
 	close(st);
 
 	/* receiver processing */
@@ -382,12 +316,11 @@ void so_test(struct soent *psoe)
 			if (nfds < 0) {
 				if (errno == EINTR)
 					continue;
-				tst_resm(TBROK, "%s select: %s", psoe->so_tname,
-					 strerror(errno));
-				return;
+				tst_brkm(TBROK | TERRNO, NULL, "%s select",
+					 psoe->so_tname);
 			}
 			if (nfds == 0) {
-				tst_resm(TBROK, "%s recvmsg timed out",
+				tst_brkm(TBROK, NULL, "%s recvmsg timed out",
 					 psoe->so_tname);
 				return;
 			}
@@ -405,11 +338,10 @@ void so_test(struct soent *psoe)
 
 			cc = recvmsg(sr, &msg, 0);
 			if (cc < 0) {
-				tst_resm(TBROK, "%s recvmsg: %s",
-					 psoe->so_tname, strerror(errno));
-				return;
+				tst_brkm(TBROK | TERRNO, NULL, "%s recvmsg",
+					 psoe->so_tname);
 			}
-/* check pid & seq here */
+			/* check pid & seq here */
 			break;
 		}
 		gotone = 0;
@@ -419,9 +351,9 @@ void so_test(struct soent *psoe)
 				break;
 			gotone = pcmsg->cmsg_level == SOL_IPV6 &&
 			    pcmsg->cmsg_type == psoe->so_cmtype;
-			if (gotone)
+			if (gotone) {
 				break;
-			else if (psoe->so_clear) {
+			} else if (psoe->so_clear) {
 				tst_resm(TFAIL, "%s receive: extraneous data "
 					 "in control: level %d type %d len %zu",
 					 psoe->so_tname, pcmsg->cmsg_level,
@@ -429,232 +361,25 @@ 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);
 	}
 }
 
-#define IPV6_ADDR_NODE		1
-#define IPV6_ADDR_LINK		2
-#define IPV6_ADDR_GLOBAL	3
-
-#ifdef HAVE_IFADDRS_H
-static int ipv6_addr_scope(struct in6_addr *pin6)
-{
-	if ((ntohl(pin6->s6_addr32[0]) & 0xFFC00000) == 0xFE800000)
-		return IPV6_ADDR_LINK;
-	if (memcmp(pin6, &in6addr_loopback, sizeof(*pin6)) == 0)
-		return IPV6_ADDR_NODE;
-	return IPV6_ADDR_GLOBAL;
-}
-#endif /* HAVE_IFADDRS_H */
-
-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 (psin6_arg)
-		ifindex = psin6_arg->sin6_scope_id;
-
-	/* first, find a global address */
-	for (pifa = pifa_head; pifa; pifa = pifa->ifa_next) {
-		int this_scope;
-
-		if (!(pifa->ifa_flags & IFF_UP))
-			continue;
-		if (pifa->ifa_addr->sa_family != AF_INET6)
-			continue;
-		psin6 = (struct sockaddr_in6 *)pifa->ifa_addr;
-		this_scope = ipv6_addr_scope(&psin6->sin6_addr);
-		if (this_scope &&
-		    ((this_scope < 0 && -this_scope == 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))
-			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;
-		}
-		if (psin6_arg) {
-			*psin6_arg = *psin6;
-			psin6_arg->sin6_scope_id =
-			    if_nametoindex(pifa->ifa_name);
-		}
-		return s;
-	}
-	{
-		char *scopestr, *intfstr;
-
-		switch (scope) {
-		case IPV6_ADDR_NODE:
-			scopestr = " node-local";
-			break;
-		case IPV6_ADDR_LINK:
-			scopestr = " link-local";
-			break;
-		case IPV6_ADDR_GLOBAL:
-			scopestr = " global";
-			break;
-		default:
-			scopestr = "";
-			break;
-		}
-		if (ifindex < 0) {
-			intfstr = " not on ifindex";
-			ifindex = -ifindex;
-		} else if (ifindex)
-			intfstr = " on ifindex";
-		else
-			intfstr = 0;
-
-		if (intfstr)
-			tst_resm(TBROK, "%s: getsock : no%s addresses%s %d",
-				 tname, scopestr, intfstr, ifindex);
-		else
-			tst_resm(TBROK, "%s: getsock : no%s addresses",
-				 tname, scopestr);
-	}
-	return -1;
-#else /* HAVE_IFADDRS_H */
-	return -1;
-#endif
-}
-
-#ifdef notyet
-/*
- * 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)
-{
-	int s_snd, s_rcv[3] = { -1, -1, -1 };
-	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;
-
-	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;
-	}
-	/* 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;
-	}
-	/* 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;
-	}
-	/* send to rcv1 to verify communication */
-	/* force to rcv2 w/ PKTINFO */
-/* TESTS: */
-/* sticky set-get */
-	tname = "IPV6_PKTINFO set";
-	pi.ipi6_addr = sa_rcv[1].sin6_addr;
-	pi.ipi6_ifindex = sa_rcv[1].sin6_scope_id;
-	TEST(setsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi, sizeof(pi)));
-	if (TEST_RETURN != 0)
-		tst_resm(TFAIL, "%s: %s", tname, strerror(errno));
-	else
-		tst_resm(TPASS, "%s", tname);
-
-	tname = "IPV6_PKTINFO get";
-	optlen = sizeof(pi_tmp);
-	TEST(getsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi_tmp, &optlen));
-	if (TEST_RETURN != 0)
-		tst_resm(TFAIL, "%s: %s", tname, strerror(errno));
-	else if (memcmp(&pi, &pi_tmp, sizeof(pi)) != 0) {
-		char strbuf2[64];
-		tst_resm(TFAIL, "%s: {\"%s\",%d} != {\"%s\",%d}", tname,
-			 inet_ntop(AF_INET6, &pi_tmp.ipi6_addr, strbuf,
-				   sizeof(strbuf)), pi_tmp.ipi6_ifindex,
-			 inet_ntop(AF_INET6, &pi.ipi6_addr, strbuf2,
-				   sizeof(strbuf2)), pi.ipi6_ifindex);
-	} else
-		tst_resm(TPASS, "%s", tname);
-/* 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;
-	TEST(setsockopt(s_snd, SOL_IPV6, IPV6_PKTINFO, &pi, sizeof(pi)));
-	if (TEST_RETURN == 0)
-		tst_resm(TFAIL, "%s returns success, should be -1, EINVAL",
-			 tname);
-	else if (TEST_ERRNO != EINVAL)
-		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;
 		sotab[i].so_setval.sou_bool = 1;
 		so_test(&sotab[i]);
 	}
-#ifdef notyet
-	test_pktinfo();
-#endif /* notyet - see test_pktinfo() comment above */
-}
-
-void setup(void)
-{
-	TEST_PAUSE;		/* if -P option specified */
 }
 
-void cleanup(void)
+static void setup(void)
 {
+	TEST_PAUSE;
 }
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v10 6/8] lib6/getaddrinfo_01.c: Cleanup
  2015-10-21  3:15                 ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                                     ` (3 preceding siblings ...)
  2015-10-21  3:15                   ` [LTP] [PATCH v10 5/8] lib6/asapi_06.c: Cleanup Zeng Linggang
@ 2015-10-21  3:15                   ` Zeng Linggang
  2015-10-21  3:15                   ` [LTP] [PATCH v10 7/8] lib6: Rename Zeng Linggang
                                     ` (2 subsequent siblings)
  7 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-21  3:15 UTC (permalink / raw)
  To: ltp

* Add 'static' before some functions and global variables.
* Remove cleanup() function.
* Remove useless comments.
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/network/lib6/getaddrinfo_01.c | 466 +++++++++++++++++---------------
 1 file changed, 248 insertions(+), 218 deletions(-)

diff --git a/testcases/network/lib6/getaddrinfo_01.c b/testcases/network/lib6/getaddrinfo_01.c
index ec29b5d..bbf8f77 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;
-
-void setup(void), cleanup(void);
+static void setup(void);
+static void gaiv4(void);
+static void gaiv6(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 = 22;
 
 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];
@@ -96,8 +72,7 @@ void gaiv4(void)
 	char *p;
 
 	if (gethostname(hostname, sizeof(hostname)) < 0)
-		tst_brkm(TBROK, NULL, "gethostname failed - %s",
-			 strerror(errno));
+		tst_brkm(TBROK | TERRNO, NULL, "gethostname failed");
 	strncpy(shortname, hostname, MAXHOSTNAMELEN);
 	shortname[MAXHOSTNAMELEN] = '\0';
 	p = strchr(shortname, '.');
@@ -132,13 +107,17 @@ 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);
+			return;
+		}
+		tst_resm(TPASS, "getaddrinfo IPv4 basic lookup");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 basic "
+	} 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 +131,25 @@ 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);
+			return;
+		}
+		tst_resm(TPASS, "getaddrinfo IPv4 canonical name");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 "
+	} 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 +184,17 @@ 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);
+			return;
+		}
+		tst_resm(TPASS, "getaddrinfo IPv4 host+service");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 host+"
+	} 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 +232,20 @@ 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 PASSIVE");
+			freeaddrinfo(aires);
+			return;
+		}
+		tst_resm(TPASS, "getaddrinfo IPv4 host+service PASSIVE");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 host+"
+	} 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 +256,11 @@ void gaiv4(void)
 		tst_resm(TFAIL, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname: "
 			 "returns %ld expected %d (EAI_NONAME)",
 			 TEST_RETURN, EAI_NONAME);
-	} else
-		tst_resm(TPASS, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname");
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
+	}
+	tst_resm(TPASS, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname");
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 
@@ -306,17 +299,27 @@ 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);
+			return;
+		}
+		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));
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TPASS, "getaddrinfo IPv4 0+service,"
+				" PASSIVE (\"\", \"%s\") returns %ld (\"%s\")",
+				service, TEST_RETURN,
+				gai_strerror(TEST_RETURN));
+		} else {
+			tst_resm(TFAIL, "getaddrinfo IPv4 0+service,"
+				" 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 +353,29 @@ 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);
+			return;
+		}
+		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));
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TPASS, "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 +389,16 @@ 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,
-			 "getaddrinfo IPv4 host+service, AI_NUMERICSERV");
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
+	}
+	tst_resm(TPASS, "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 +410,11 @@ 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 "
-			 "hints");
+		return;
+	}
+	tst_resm(TPASS, "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 +452,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)
+			freeaddrinfo(aires);
+			return;
+		} else if (got_tcp && got_udp) {
 			tst_resm(TPASS, "getaddrinfo IPv4 socktype 0,513");
-		else
+			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(TPASS, "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 +506,21 @@ 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);
+			return;
+		}
+		tst_resm(TPASS, "getaddrinfo IPv4 AI_V4MAPPED");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv4 "
+	} else {
+		tst_resm(TFAIL, "getaddrinfo IPv4 "
 			 "AI_V4MAPPED (\"%s\") returns %ld (\"%s\")", hostname,
 			 TEST_RETURN, gai_strerror(TEST_RETURN));
+		return;
+	}
 }
 
 /* getaddrinfo tests (v6) */
-
-void gaiv6(void)
+static void gaiv6(void)
 {
 	struct addrinfo *aires, hints, *pai;
 	char hostname[MAXHOSTNAMELEN + 1];
@@ -539,13 +566,17 @@ 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);
+			return;
+		}
+		tst_resm(TPASS, "getaddrinfo IPv6 basic lookup");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 basic "
+	} 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 +590,25 @@ 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);
+			return;
+		}
+		tst_resm(TPASS, "getaddrinfo IPv6 canonical name");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 "
+	} 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 +643,17 @@ 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);
+			return;
+		}
+		tst_resm(TPASS, "getaddrinfo IPv6 host+service");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 host+"
+	} 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 +692,20 @@ 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 PASSIVE");
+			freeaddrinfo(aires);
+			return;
+		}
+		tst_resm(TPASS, "getaddrinfo IPv6 host+service PASSIVE");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 host+"
+	} 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 +716,11 @@ void gaiv6(void)
 		tst_resm(TFAIL, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname: "
 			 "returns %ld expected %d (EAI_NONAME)",
 			 TEST_RETURN, EAI_NONAME);
-	} else
-		tst_resm(TPASS, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname");
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
+	}
+	tst_resm(TPASS, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname");
 	if (!TEST_RETURN)
 		freeaddrinfo(aires);
 
@@ -715,17 +760,25 @@ 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);
+			return;
+		}
+		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));
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TPASS, "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 +813,27 @@ 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);
+			return;
+		}
+		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));
+	} else {
+		if (TEST_RETURN == EAI_BADFLAGS) {
+			tst_resm(TPASS, "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 +847,16 @@ void gaiv6(void)
 			 "getaddrinfo IPv6 host+service, AI_NUMERICSERV: "
 			 "returns %ld (\"%s\") expected %d (EAI_NONAME)",
 			 TEST_RETURN, gai_strerror(TEST_RETURN), EAI_NONAME);
-	} else
-		tst_resm(TPASS,
-			 "getaddrinfo IPv6 host+service, AI_NUMERICSERV");
+		if (!TEST_RETURN)
+			freeaddrinfo(aires);
+		return;
+	}
+	tst_resm(TPASS, "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 +868,11 @@ 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 "
-			 "hints");
+		return;
+	}
+	tst_resm(TPASS, "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 +911,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)
+			freeaddrinfo(aires);
+			return;
+		} else if (got_tcp && got_udp) {
 			tst_resm(TPASS, "getaddrinfo IPv6 socktype 0,513");
-		else
+			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(TPASS, "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 +964,15 @@ 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);
+			return;
+		}
+		tst_resm(TPASS, "getaddrinfo IPv6 AI_V4MAPPED");
 		freeaddrinfo(aires);
-	} else
-		tst_resm(TEST_RETURN ? TFAIL : TPASS, "getaddrinfo IPv6 "
+	} 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)
-{
-}
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v10 7/8] lib6: Rename
  2015-10-21  3:15                 ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                                     ` (4 preceding siblings ...)
  2015-10-21  3:15                   ` [LTP] [PATCH v10 6/8] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
@ 2015-10-21  3:15                   ` Zeng Linggang
  2015-10-21  3:15                   ` [LTP] [PATCH v10 8/8] ipv6_lib: Add it into default Zeng Linggang
  2015-10-22 11:12                   ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Alexey Kodanev
  7 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-21  3:15 UTC (permalink / raw)
  To: ltp

rename:    asapi_04.c -> asapi_01.c
rename:    asapi_05.c -> asapi_02.c
rename:    asapi_06.c -> asapi_03.c

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 runtest/ipv6_lib                  |   6 +-
 testcases/network/.gitignore      |   6 +-
 testcases/network/lib6/asapi_01.c | 460 ++++++++++++++++++++++++++++++++++++++
 testcases/network/lib6/asapi_02.c | 261 +++++++++++++++++++++
 testcases/network/lib6/asapi_03.c | 385 +++++++++++++++++++++++++++++++
 testcases/network/lib6/asapi_04.c | 460 --------------------------------------
 testcases/network/lib6/asapi_05.c | 261 ---------------------
 testcases/network/lib6/asapi_06.c | 385 -------------------------------
 8 files changed, 1112 insertions(+), 1112 deletions(-)
 create mode 100644 testcases/network/lib6/asapi_01.c
 create mode 100644 testcases/network/lib6/asapi_02.c
 create mode 100644 testcases/network/lib6/asapi_03.c
 delete mode 100644 testcases/network/lib6/asapi_04.c
 delete mode 100644 testcases/network/lib6/asapi_05.c
 delete mode 100644 testcases/network/lib6/asapi_06.c

diff --git a/runtest/ipv6_lib b/runtest/ipv6_lib
index 203e275..636232b 100644
--- a/runtest/ipv6_lib
+++ b/runtest/ipv6_lib
@@ -2,6 +2,6 @@
 in6_01 in6_01
 in6_02 in6_02
 getaddrinfo_01 getaddrinfo_01
-asapi_04 asapi_04
-asapi_05 asapi_05
-asapi_06 asapi_06
+asapi_01 asapi_01
+asapi_02 asapi_02
+asapi_03 asapi_03
diff --git a/testcases/network/.gitignore b/testcases/network/.gitignore
index 18b0203..77a350b 100644
--- a/testcases/network/.gitignore
+++ b/testcases/network/.gitignore
@@ -1,9 +1,9 @@
 /can/filter-tests/can_filter
 /can/filter-tests/can_rcv_own_msgs
 /datafiles/
-/lib6/asapi_04
-/lib6/asapi_05
-/lib6/asapi_06
+/lib6/asapi_01
+/lib6/asapi_02
+/lib6/asapi_03
 /lib6/getaddrinfo_01
 /lib6/in6_01
 /lib6/in6_02
diff --git a/testcases/network/lib6/asapi_01.c b/testcases/network/lib6/asapi_01.c
new file mode 100644
index 0000000..ff310ea
--- /dev/null
+++ b/testcases/network/lib6/asapi_01.c
@@ -0,0 +1,460 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * 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 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/>.
+ *
+ * Author: David L Stevens
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <netdb.h>
+#include <libgen.h>
+#include <pthread.h>
+#include <semaphore.h>
+
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include "test.h"
+#include "safe_macros.h"
+
+char *TCID = "asapi_04";
+
+static pid_t pid;
+
+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		ARRAY_SIZE(ptab)
+#define READ_TIMEOUT	5
+
+static void do_tests(void);
+static void setup(void);
+static void csum_test(void);
+
+int main(int argc, char *argv[])
+{
+	int lc;
+
+	tst_parse_opts(argc, argv, 0, 0);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); ++lc)
+		do_tests();
+
+	tst_exit();
+}
+
+static void do_tests(void)
+{
+	unsigned int i;
+
+/* RFC 3542, Section 2.3 */
+#ifndef IN6_ARE_ADDR_EQUAL
+	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;
+
+	memset(&a1, 0, sizeof(a1));
+	memset(&a2, 0, sizeof(a2));
+
+	rv = IN6_ARE_ADDR_EQUAL(&a1, &a2);
+
+	for (word = 0; word < 4; ++word) {
+		for (bit = 0; bit < 32; ++bit) {
+			uint32_t newbit = 1U << bit;
+
+			a1.s6_addr32[word] |= newbit;
+			rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
+			a2.s6_addr32[word] |= newbit;
+			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 */
+	for (i = 0; i < PTCOUNT; ++i) {
+		struct protoent *pe;
+		int pass;
+
+		pe = getprotobyname(ptab[i].prt_name);
+		pass = pe && pe->p_proto == ptab[i].prt_value;
+		tst_resm(pass ? TPASS : TFAIL, "\"%s\" protocols entry",
+			 ptab[i].prt_name);
+	}
+/* RFC 3542, Section 3.1 */
+	csum_test();
+}
+
+/*
+ * this next-header value shouldn't be a real protocol!!
+ * 0x9f = 01 0 11111
+ *         | |     |
+ *         | |     |--- rest- ~0
+ *         | |--------- chg - "no change enroute"
+ *         |----------- act - "discard unknown"
+ */
+#define	NH_TEST	0x9f
+
+struct tprot {
+	int tp_pid;		/* sender PID */
+	int tp_seq;		/* sequence # */
+	int tp_offset;		/* offset of cksum */
+	int tp_dlen;		/* tp_dat length */
+	unsigned char tp_dat[0];	/* user data */
+};
+
+static unsigned char tpbuf[sizeof(struct tprot) + 2048];
+static unsigned char rpbuf[sizeof(struct tprot) + 2048];
+
+static struct csent {
+	int cs_offset;
+	int cs_dlen;
+	int cs_setresult;	/* setsockopt expected result */
+	int cs_seterrno;	/* setsockopt expected errno */
+	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) */
+};
+
+#define CSCOUNT	ARRAY_SIZE(cstab)
+
+int TST_TOTAL = PTCOUNT + CSCOUNT;
+
+static int recvtprot(int sd, unsigned char *packet)
+{
+	struct tprot *tpt;
+	int cc;
+	unsigned int total, expected;
+	int gothead;
+
+	tpt = (struct tprot *)packet;
+	total = cc = recv(sd, packet, sizeof(struct tprot), 0);
+	expected = sizeof(struct tprot);	/* until we get tp_dlen */
+	gothead = total >= sizeof(struct tprot);
+	if (gothead)
+		expected += ntohl(tpt->tp_dlen);
+	if (cc <= 0)
+		return cc;
+	while (cc > 0 && total < expected) {
+		cc = recv(sd, &packet[total], expected - total, 0);
+		if (cc >= 0) {
+			total += cc;
+			if (!gothead && total >= sizeof(struct tprot)) {
+				gothead = 1;
+				expected += ntohl(tpt->tp_dlen);
+			}
+		} else {
+			break;
+		}
+	}
+	if (cc < 0)
+		return cc;
+	return total;
+}
+
+static unsigned short csum(unsigned short partial, unsigned char *packet,
+			   int len)
+{
+	unsigned long sum = partial;
+	unsigned short *ps;
+	int i;
+
+	ps = (unsigned short *)packet;
+	for (i = 0; i < len / 2; ++i)
+		sum += *ps++;
+	if (len & 1)
+		sum += htons(packet[len - 1] << 8);
+	sum = (sum >> 16) + (sum & 0xffff);
+	sum += (sum >> 16);
+	return ~sum;
+}
+
+static struct ph {
+	struct in6_addr ph_sa;
+	struct in6_addr ph_da;
+	uint32_t ph_len;
+	uint8_t ph_mbz[3];
+	uint8_t ph_nh;
+} ph;
+
+static int client(int sfd)
+{
+	struct tprot *pttp = (struct tprot *)tpbuf;
+	struct tprot *prtp = (struct tprot *)rpbuf;
+	struct sockaddr_in6 rsin6;
+	static int seq;
+	unsigned int i;
+	int sd, cc, cs;
+
+	memset(&rsin6, 0, sizeof(rsin6));
+	rsin6.sin6_family = AF_INET6;
+	rsin6.sin6_addr = in6addr_loopback;
+
+	memset(&ph, 0, sizeof(ph));
+	ph.ph_sa = rsin6.sin6_addr;
+	ph.ph_da = rsin6.sin6_addr;
+	ph.ph_nh = NH_TEST;
+
+	sd = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
+	for (i = 0; i < CSCOUNT; ++i) {
+		int offset, len, xlen;
+		int rv;
+		unsigned char *p, *pend;
+
+		offset = sizeof(struct tprot) + cstab[i].cs_offset;
+		len = sizeof(struct tprot) + cstab[i].cs_dlen;
+
+		memset(pttp, 0, sizeof(*pttp));
+		memset(pttp->tp_dat, 0xA5, cstab[i].cs_dlen);
+
+		pttp->tp_pid = htonl(pid);
+		pttp->tp_offset = ntohl(offset);
+		pttp->tp_dlen = ntohl(cstab[i].cs_dlen);
+		pttp->tp_seq = ntohl(++seq);
+
+		TEST(setsockopt(sd, IPPROTO_IPV6, IPV6_CHECKSUM, &offset,
+				sizeof(offset)));
+		if (TEST_RETURN != cstab[i].cs_setresult) {
+			tst_resm(TFAIL | TTERRNO,
+				 "IPV6_CHECKSUM offset %d len %d "
+				 "- result %ld != %d", offset, len, TEST_RETURN,
+				 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)));
+		xlen = (cstab[i].cs_sndresult < 0) ? -1 : len;
+		if (TEST_RETURN != xlen) {
+			tst_resm(TFAIL | TTERRNO,
+				 "IPV6_CHECKSUM offset %d len %d "
+				 "- sndresult %ld != %d", offset, len,
+				 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))) {
+			if (htonl(prtp->tp_pid) == (uint32_t)pid &&
+			    htonl(prtp->tp_seq) == (uint32_t)seq)
+				break;
+		}
+		rv = 1;
+		pend = rpbuf + sizeof(struct tprot) + ntohl(prtp->tp_dlen);
+		for (p = &prtp->tp_dat[0]; p < pend; ++p) {
+			if (p == &rpbuf[offset] || p == &rpbuf[offset + 1])
+				continue;
+			if (*p != 0xa5) {
+				tst_resm(TFAIL, "IPV6_CHECKSUM corrupt data "
+					 "0x%02x != 0xa5, offset %zd in packet",
+					 *p, p - rpbuf);
+				rv = 0;
+				break;
+			}
+		}
+		if (rv == 0)
+			continue;
+		ph.ph_len = htonl(xlen);
+		cs = csum(0, (unsigned char *)&ph, sizeof(ph));
+		cs = csum(~cs, rpbuf, xlen);
+		if (!csum(0, rpbuf, xlen)) {
+			tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d (bad "
+				 "checksum)", offset, len);
+			continue;
+		}
+		tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d", offset, len);
+	}
+	return 0;
+}
+
+static int listen_fd, connect_fd;
+
+static void *ilistener(void *arg LTP_ATTRIBUTE_UNUSED)
+{
+	connect_fd = accept(listen_fd, 0, 0);
+	close(listen_fd);
+	return NULL;
+}
+
+static void isocketpair(int pf, int type, int proto, int fd[2])
+{
+	pthread_t thid;
+	struct sockaddr_in sin4;
+	socklen_t namelen;
+
+	listen_fd = SAFE_SOCKET(NULL, pf, type, proto);
+
+	memset(&sin4, 0, sizeof(sin4));
+
+	SAFE_BIND(NULL, listen_fd, (struct sockaddr *)&sin4, sizeof(sin4));
+
+	SAFE_LISTEN(NULL, listen_fd, 10);
+
+	namelen = sizeof(sin4);
+	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);
+
+	sin4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+	SAFE_CONNECT(NULL, fd[0], (struct sockaddr *)&sin4, sizeof(sin4));
+
+	pthread_join(thid, NULL);
+
+	fd[1] = connect_fd;
+}
+
+#ifndef MAX
+#define MAX(a, b) (@ >= (b) ? (a) : (b))
+#endif /* MAX */
+
+static void csum_test(void)
+{
+	fd_set rset, rset_save;
+	int csd[2];		/* control sockets */
+	int sd, nfds, maxfd, cc;
+	struct timeval tv;
+
+	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);
+	memcpy(&rset, &rset_save, sizeof(rset));
+	maxfd = MAX(sd, csd[1]);
+
+	/* server socket set; now start the client */
+	switch (fork()) {
+	case 0:
+		close(csd[0]);
+		break;
+	case -1:
+		tst_brkm(TBROK, NULL, "can't fork rserver");
+	default:
+		close(sd);
+		close(csd[1]);
+		client(csd[0]);
+		return;
+	}
+
+	tv.tv_sec = READ_TIMEOUT;
+	tv.tv_usec = 0;
+	while ((nfds = select(maxfd + 1, &rset, 0, 0, &tv)) >= 0) {
+		if (nfds < 0) {
+			if (errno == EINTR)
+				continue;
+			exit(0);
+		} else if (nfds == 0) {
+			fprintf(stderr, "server read timed out");
+			return;
+		}
+		if (FD_ISSET(sd, &rset)) {
+			static char packet[2048];
+
+			cc = recv(sd, packet, sizeof(packet), 0);
+			if (cc < 0) {
+				perror("server recvtprot");
+				exit(1);
+			}
+			if (cc == 0)
+				exit(0);
+			if (write(csd[1], packet, cc) < 0) {
+				perror("server write UNIX socket");
+				exit(0);
+			}
+		}
+		if (FD_ISSET(csd[1], &rset)) {
+			char buf[2048];
+
+			cc = read(csd[1], buf, sizeof(buf));
+			if (cc == 0)
+				exit(0);
+			if (cc < 0) {
+				perror("server read");
+				exit(1);
+			}
+			/* handle commands here, if any added later */
+		}
+		memcpy(&rset, &rset_save, sizeof(rset));
+		tv.tv_sec = READ_TIMEOUT;
+		tv.tv_usec = 0;
+	}
+}
+
+static void setup(void)
+{
+	TEST_PAUSE;
+
+	pid = getpid();
+}
diff --git a/testcases/network/lib6/asapi_02.c b/testcases/network/lib6/asapi_02.c
new file mode 100644
index 0000000..f8c30f1
--- /dev/null
+++ b/testcases/network/lib6/asapi_02.c
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * 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 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/>.
+ *
+ * Author: David L Stevens
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <sys/wait.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <netinet/ip6.h>
+#include <netinet/icmp6.h>
+
+#include "test.h"
+#include "safe_macros.h"
+
+char *TCID = "asapi_05";
+
+static void setup(void);
+
+static void icmp6_ft(void);
+
+int main(int argc, char *argv[])
+{
+	int lc;
+
+	tst_parse_opts(argc, argv, NULL, NULL);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); ++lc)
+		icmp6_ft();
+
+	tst_exit();
+}
+
+static void setup(void)
+{
+	TEST_PAUSE;
+	tst_require_root();
+}
+
+enum tt {
+	T_WILLPASS,
+	T_WILLBLOCK,
+	T_SETPASS,
+	T_SETBLOCK,
+	T_SETPASSALL,
+	T_SETBLOCKALL
+};
+
+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? */
+} 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	ARRAY_SIZE(ftab)
+
+static int ic6_send1(char *tname, unsigned char type)
+{
+	struct sockaddr_in6 sin6;
+	struct icmp6_hdr ic6;
+	int s;
+
+	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());
+
+	memset(&sin6, 0, sizeof(sin6));
+	sin6.sin6_family = AF_INET6;
+	sin6.sin6_addr = in6addr_loopback;
+	if (sendto(s, &ic6, sizeof(ic6), 0, (struct sockaddr *)&sin6,
+		   sizeof(sin6)) == -1) {
+		tst_resm(TBROK | TERRNO, "%s: sendto failed", tname);
+		return 1;
+	}
+	return 0;
+}
+
+static int ic6_recv1(char *tname, int sall, int sf)
+{
+	fd_set readfds, readfds_saved;
+	struct timeval tv;
+	int maxfd, nfds;
+	int gotall, gotone;
+	int cc;
+	static unsigned char rbuf[2048];
+
+	tv.tv_sec = 0;
+	tv.tv_usec = 250000;
+
+	FD_ZERO(&readfds_saved);
+	FD_SET(sall, &readfds_saved);
+	FD_SET(sf, &readfds_saved);
+	maxfd = MAX(sall, sf);
+
+	memcpy(&readfds, &readfds_saved, sizeof(readfds));
+
+	gotall = gotone = 0;
+	/*
+	 * Note: this relies on linux-specific behavior (select
+	 * updating tv with time elapsed)
+	 */
+	while (!gotall || !gotone) {
+		struct icmp6_hdr *pic6 = (struct icmp6_hdr *)rbuf;
+
+		nfds = select(maxfd + 1, &readfds, 0, 0, &tv);
+		if (nfds == 0)
+			break;	/* timed out */
+		if (nfds < 0) {
+			if (errno == EINTR)
+				continue;
+			tst_resm(TBROK | TERRNO, "%s: select failed", tname);
+		}
+		if (FD_ISSET(sall, &readfds)) {
+			cc = recv(sall, rbuf, sizeof(rbuf), 0);
+			if (cc < 0) {
+				tst_resm(TBROK | TERRNO,
+					 "%s: recv(sall, ..) failed", tname);
+				return -1;
+			}
+			/* if packet check succeeds... */
+			if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid())
+				gotall = 1;
+		}
+		if (FD_ISSET(sf, &readfds)) {
+			cc = recv(sf, rbuf, sizeof(rbuf), 0);
+			if (cc < 0) {
+				tst_resm(TBROK | TERRNO,
+					 "%s: recv(sf, ..) failed", tname);
+				return -1;
+			}
+			/* if packet check succeeds... */
+			if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid())
+				gotone = 1;
+		}
+		memcpy(&readfds, &readfds_saved, sizeof(readfds));
+	}
+	if (!gotall) {
+		tst_resm(TBROK, "%s: recv all timed out", tname);
+		return -1;
+	}
+	if (gotone)
+		return 1;
+	return 0;
+}
+
+/* functional tests */
+static void icmp6_ft(void)
+{
+	struct icmp6_filter i6f;
+	int sall, sf;
+	unsigned int i;
+
+	sall = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
+
+	ICMP6_FILTER_SETPASSALL(&i6f);
+	if (setsockopt(sall, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f,
+		       sizeof(i6f)) < 0) {
+		tst_resm(TBROK | TERRNO,
+			 "setsockopt pass all ICMP6_FILTER failed");
+	}
+
+	sf = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
+
+	int rv;
+
+	for (i = 0; i < FTCOUNT; ++i) {
+
+		rv = -1;
+
+		switch (ftab[i].ft_test) {
+		case T_SETPASS:
+			ICMP6_FILTER_SETBLOCKALL(&i6f);
+			ICMP6_FILTER_SETPASS(ftab[i].ft_flttype, &i6f);
+			break;
+		case T_SETPASSALL:
+			ICMP6_FILTER_SETPASSALL(&i6f);
+			break;
+		case T_SETBLOCK:
+			ICMP6_FILTER_SETPASSALL(&i6f);
+			ICMP6_FILTER_SETBLOCK(ftab[i].ft_flttype, &i6f);
+			break;
+		case T_SETBLOCKALL:
+			ICMP6_FILTER_SETBLOCKALL(&i6f);
+			break;
+		case T_WILLBLOCK:
+			ICMP6_FILTER_SETPASSALL(&i6f);
+			ICMP6_FILTER_SETBLOCK(ftab[i].ft_flttype, &i6f);
+			rv = ICMP6_FILTER_WILLBLOCK(ftab[i].ft_sndtype, &i6f);
+			break;
+		case T_WILLPASS:
+			ICMP6_FILTER_SETBLOCKALL(&i6f);
+			ICMP6_FILTER_SETPASS(ftab[i].ft_flttype, &i6f);
+			rv = ICMP6_FILTER_WILLPASS(ftab[i].ft_sndtype, &i6f);
+			break;
+		default:
+			tst_resm(TBROK, "%s: unknown test type %d",
+				 ftab[i].ft_tname, ftab[i].ft_test);
+			continue;
+		}
+		if (ftab[i].ft_test != T_WILLBLOCK &&
+		    ftab[i].ft_test != T_WILLPASS) {
+			if (setsockopt(sf, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f,
+				       sizeof(i6f)) < 0) {
+				tst_resm(TFAIL | TERRNO,
+					 "setsockopt ICMP6_FILTER");
+				continue;
+			}
+			if (ic6_send1(ftab[i].ft_tname, ftab[i].ft_sndtype))
+				continue;
+			rv = ic6_recv1(ftab[i].ft_tname, sall, sf);
+		} else {
+			rv = -1;
+		}
+
+		if (rv < 0)
+			continue;
+		if (rv != ftab[i].ft_expected)
+			tst_resm(TFAIL, "%s: rv %d != expected %d",
+				 ftab[i].ft_tname, rv, ftab[i].ft_expected);
+		else
+			tst_resm(TPASS, "%s", ftab[i].ft_tname);
+	}
+}
diff --git a/testcases/network/lib6/asapi_03.c b/testcases/network/lib6/asapi_03.c
new file mode 100644
index 0000000..c6e2c8e
--- /dev/null
+++ b/testcases/network/lib6/asapi_03.c
@@ -0,0 +1,385 @@
+/*
+ * Copyright (c) 2015 Fujitsu Ltd.
+ * 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 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/>.
+ *
+ * Author: David L Stevens
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <netdb.h>
+#include <libgen.h>
+#include <pthread.h>
+#include <semaphore.h>
+
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <netinet/ip6.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#ifdef HAVE_IFADDRS_H
+#include <ifaddrs.h>
+#endif
+#include <arpa/inet.h>
+
+#include "test.h"
+#include "safe_macros.h"
+
+char *TCID = "asapi_06";
+
+int TST_TOTAL = 1;
+
+#define READ_TIMEOUT	5	/* secs */
+
+static void do_tests(void);
+static void setup(void);
+
+int main(int argc, char *argv[])
+{
+	int lc;
+
+	tst_parse_opts(argc, argv, NULL, NULL);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); ++lc)
+		do_tests();
+
+	tst_exit();
+}
+
+#define NH_TEST	0x9f
+
+#ifndef IPV6_RECVPKTINFO
+#define IPV6_RECVPKTINFO	-1
+#endif
+#ifndef IPV6_RECVHOPLIMIT
+#define IPV6_RECVHOPLIMIT	-1
+#endif
+#ifndef IPV6_RECVRTHDR
+#define IPV6_RECVRTHDR		-1
+#endif
+#ifndef IPV6_RECVHOPOPTS
+#define IPV6_RECVHOPOPTS	-1
+#endif
+#ifndef IPV6_RECVDSTOPTS
+#define IPV6_RECVDSTOPTS	-1
+#endif
+#ifndef IPV6_RECVTCLASS
+#define IPV6_RECVTCLASS		-1
+#endif
+#ifndef IPV6_TCLASS
+#define IPV6_TCLASS		-1
+#endif
+#ifndef IPV6_2292PKTINFO
+#define	IPV6_2292PKTINFO	-1
+#endif
+#ifndef IPV6_2292HOPLIMIT
+#define	IPV6_2292HOPLIMIT	-1
+#endif
+#ifndef IPV6_2292RTHDR
+#define	IPV6_2292RTHDR		-1
+#endif
+#ifndef IPV6_2292HOPOPTS
+#define	IPV6_2292HOPOPTS	-1
+#endif
+#ifndef IPV6_2292DSTOPTS
+#define	IPV6_2292DSTOPTS	-1
+#endif
+
+union soval {
+	struct in6_pktinfo sou_pktinfo;
+	int sou_hoplimit;
+	struct sockaddr_in6 sou_nexthop;
+	struct ip6_rthdr sou_rthdr;
+	struct ip6_hbh sou_hopopts;
+	struct ip6_dest sou_dstopts;
+	struct ip6_dest sou_rthdrdstopts;
+	int sou_tclass;
+	int sou_bool;
+};
+
+/* in6_addr initializer for loopback interface */
+#define IN6_LOOP	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
+#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 */
+static struct soent {
+	char *so_tname;
+	int so_opt;
+	int so_dorecv;		/* do receive test? */
+	int so_cmtype;
+	int so_clear;		/* get fresh socket? */
+	union soval so_clrval;
+	union soval so_setval;
+	socklen_t so_valsize;
+} sotab[] = {
+	/* 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 */
+	unsigned char sop_dat[0];	/* user data */
+};
+
+static unsigned char tpbuf[sizeof(struct soprot) + 2048];
+static unsigned char rpbuf[sizeof(struct soprot) + 2048];
+
+static unsigned char control[2048];
+
+static int seq;
+
+static struct cme {
+	int cm_len;
+	int cm_level;
+	int cm_type;
+	union {
+		uint32_t cmu_tclass;
+		uint32_t cmu_hops;
+	} cmu;
+} cmtab[] = {
+	{sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {0x12} },
+	{sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {0x21} },
+};
+
+#define CMCOUNT	ARRAY_SIZE(cmtab)
+
+static ssize_t sendall(int st)
+{
+	struct sockaddr_in6 sin6;
+	struct msghdr msg;
+	struct iovec iov;
+	struct soprot *psop;
+	unsigned char *pd;
+	unsigned int i;
+	int ctotal;
+
+	psop = (struct soprot *)tpbuf;
+	psop->sop_pid = htonl(getpid());
+	psop->sop_seq = ++seq;
+	psop->sop_dlen = 0;
+
+	memset(&sin6, 0, sizeof(sin6));
+	sin6.sin6_family = AF_INET6;
+	sin6.sin6_addr = in6addr_loopback;
+
+	memset(&msg, 0, sizeof(msg));
+	msg.msg_name = &sin6;
+	msg.msg_namelen = sizeof(sin6);
+	iov.iov_base = tpbuf;
+	iov.iov_len = sizeof(struct soprot) + ntohl(psop->sop_dlen);
+	msg.msg_iov = &iov;
+	msg.msg_iovlen = 1;
+
+	pd = control;
+	ctotal = 0;
+	for (i = 0; i < CMCOUNT; ++i) {
+		struct cmsghdr *pcmsg = (struct cmsghdr *)pd;
+
+		pcmsg->cmsg_len = CMSG_LEN(cmtab[i].cm_len);
+		pcmsg->cmsg_level = cmtab[i].cm_level;
+		pcmsg->cmsg_type = cmtab[i].cm_type;
+		memcpy(CMSG_DATA(pcmsg), &cmtab[i].cmu, cmtab[i].cm_len);
+		pd += CMSG_SPACE(cmtab[i].cm_len);
+		ctotal += CMSG_SPACE(cmtab[i].cm_len);
+	}
+	msg.msg_control = ctotal ? control : 0;
+	msg.msg_controllen = ctotal;
+
+	return sendmsg(st, &msg, 0);
+}
+
+static void so_test(struct soent *psoe)
+{
+	struct sockaddr_in6 sin6;
+	union soval sobuf;
+	socklen_t valsize;
+	static int sr = -1;
+	int st;
+
+	if (psoe->so_opt == -1) {
+		tst_brkm(TBROK | TERRNO, NULL, "%s not present at compile time",
+			 psoe->so_tname);
+	}
+	if (psoe->so_clear || sr < 0) {
+		if (sr < 0)
+			close(sr);
+		sr = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+	}
+	memset(&sin6, 0, sizeof(sin6));
+	sin6.sin6_family = AF_INET6;
+	sin6.sin6_addr = in6addr_loopback;
+
+	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_brkm(TBROK | TERRNO, NULL, "%s: setsockopt",
+			 psoe->so_tname);
+	}
+
+	TEST(setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_setval,
+			psoe->so_valsize));
+	if (TEST_RETURN != 0) {
+		tst_resm(TFAIL | TERRNO, "%s set-get: setsockopt",
+			 psoe->so_tname);
+		return;
+	}
+
+	valsize = psoe->so_valsize;
+	TEST(getsockopt(sr, SOL_IPV6, psoe->so_opt, &sobuf, &valsize));
+	if (TEST_RETURN != 0) {
+		tst_brkm(TBROK | TERRNO, NULL, "%s set-get: getsockopt",
+			 psoe->so_tname);
+	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize)) {
+		tst_resm(TFAIL, "%s set-get optval != setval", psoe->so_tname);
+	} else {
+		tst_resm(TPASS, "%s set-get", psoe->so_tname);
+	}
+
+	st = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
+
+	if (sendall(st) < 0)
+		tst_brkm(TBROK | TERRNO, NULL, "%s transmit sendto",
+			 psoe->so_tname);
+
+	close(st);
+
+	/* receiver processing */
+	{
+		fd_set rfds, rfds_saved;
+		int nfds, cc;
+		int gotone;
+		struct timeval tv;
+		struct msghdr msg;
+		unsigned char cmsg[2048];
+		struct cmsghdr *pcmsg;
+		struct iovec iov;
+
+		FD_ZERO(&rfds_saved);
+		FD_SET(sr, &rfds_saved);
+
+		tv.tv_sec = 0;
+		tv.tv_usec = 250000;
+
+		while (1) {
+			memcpy(&rfds, &rfds_saved, sizeof(rfds));
+			nfds = select(sr + 1, &rfds, 0, 0, &tv);
+			if (nfds < 0) {
+				if (errno == EINTR)
+					continue;
+				tst_brkm(TBROK | TERRNO, NULL, "%s select",
+					 psoe->so_tname);
+			}
+			if (nfds == 0) {
+				tst_brkm(TBROK, NULL, "%s recvmsg timed out",
+					 psoe->so_tname);
+				return;
+			}
+			/* else, nfds == 1 */
+			if (!FD_ISSET(sr, &rfds))
+				continue;
+
+			memset(&msg, 0, sizeof(msg));
+			iov.iov_base = rpbuf;
+			iov.iov_len = sizeof(rpbuf);
+			msg.msg_iov = &iov;
+			msg.msg_iovlen = 1;
+			msg.msg_control = cmsg;
+			msg.msg_controllen = sizeof(cmsg);
+
+			cc = recvmsg(sr, &msg, 0);
+			if (cc < 0) {
+				tst_brkm(TBROK | TERRNO, NULL, "%s recvmsg",
+					 psoe->so_tname);
+			}
+			/* check pid & seq here */
+			break;
+		}
+		gotone = 0;
+		for (pcmsg = CMSG_FIRSTHDR(&msg); pcmsg != NULL;
+		     pcmsg = CMSG_NXTHDR(&msg, pcmsg)) {
+			if (!psoe->so_dorecv)
+				break;
+			gotone = pcmsg->cmsg_level == SOL_IPV6 &&
+			    pcmsg->cmsg_type == psoe->so_cmtype;
+			if (gotone) {
+				break;
+			} else if (psoe->so_clear) {
+				tst_resm(TFAIL, "%s receive: extraneous data "
+					 "in control: level %d type %d len %zu",
+					 psoe->so_tname, pcmsg->cmsg_level,
+					 pcmsg->cmsg_type, pcmsg->cmsg_len);
+				return;
+			}
+		}
+		/* check contents here */
+		if (psoe->so_dorecv)
+			tst_resm(gotone ? TPASS : TFAIL, "%s receive",
+				 psoe->so_tname);
+	}
+}
+
+static void do_tests(void)
+{
+	unsigned int i;
+
+	for (i = 0; i < SOCOUNT; ++i) {
+		sotab[i].so_clrval.sou_bool = 0;
+		sotab[i].so_setval.sou_bool = 1;
+		so_test(&sotab[i]);
+	}
+}
+
+static void setup(void)
+{
+	TEST_PAUSE;
+}
diff --git a/testcases/network/lib6/asapi_04.c b/testcases/network/lib6/asapi_04.c
deleted file mode 100644
index ff310ea..0000000
--- a/testcases/network/lib6/asapi_04.c
+++ /dev/null
@@ -1,460 +0,0 @@
-/*
- * Copyright (c) 2015 Fujitsu Ltd.
- * 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 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/>.
- *
- * Author: David L Stevens
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <netdb.h>
-#include <libgen.h>
-#include <pthread.h>
-#include <semaphore.h>
-
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "asapi_04";
-
-static pid_t pid;
-
-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		ARRAY_SIZE(ptab)
-#define READ_TIMEOUT	5
-
-static void do_tests(void);
-static void setup(void);
-static void csum_test(void);
-
-int main(int argc, char *argv[])
-{
-	int lc;
-
-	tst_parse_opts(argc, argv, 0, 0);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc)
-		do_tests();
-
-	tst_exit();
-}
-
-static void do_tests(void)
-{
-	unsigned int i;
-
-/* RFC 3542, Section 2.3 */
-#ifndef IN6_ARE_ADDR_EQUAL
-	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;
-
-	memset(&a1, 0, sizeof(a1));
-	memset(&a2, 0, sizeof(a2));
-
-	rv = IN6_ARE_ADDR_EQUAL(&a1, &a2);
-
-	for (word = 0; word < 4; ++word) {
-		for (bit = 0; bit < 32; ++bit) {
-			uint32_t newbit = 1U << bit;
-
-			a1.s6_addr32[word] |= newbit;
-			rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
-			a2.s6_addr32[word] |= newbit;
-			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 */
-	for (i = 0; i < PTCOUNT; ++i) {
-		struct protoent *pe;
-		int pass;
-
-		pe = getprotobyname(ptab[i].prt_name);
-		pass = pe && pe->p_proto == ptab[i].prt_value;
-		tst_resm(pass ? TPASS : TFAIL, "\"%s\" protocols entry",
-			 ptab[i].prt_name);
-	}
-/* RFC 3542, Section 3.1 */
-	csum_test();
-}
-
-/*
- * this next-header value shouldn't be a real protocol!!
- * 0x9f = 01 0 11111
- *         | |     |
- *         | |     |--- rest- ~0
- *         | |--------- chg - "no change enroute"
- *         |----------- act - "discard unknown"
- */
-#define	NH_TEST	0x9f
-
-struct tprot {
-	int tp_pid;		/* sender PID */
-	int tp_seq;		/* sequence # */
-	int tp_offset;		/* offset of cksum */
-	int tp_dlen;		/* tp_dat length */
-	unsigned char tp_dat[0];	/* user data */
-};
-
-static unsigned char tpbuf[sizeof(struct tprot) + 2048];
-static unsigned char rpbuf[sizeof(struct tprot) + 2048];
-
-static struct csent {
-	int cs_offset;
-	int cs_dlen;
-	int cs_setresult;	/* setsockopt expected result */
-	int cs_seterrno;	/* setsockopt expected errno */
-	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) */
-};
-
-#define CSCOUNT	ARRAY_SIZE(cstab)
-
-int TST_TOTAL = PTCOUNT + CSCOUNT;
-
-static int recvtprot(int sd, unsigned char *packet)
-{
-	struct tprot *tpt;
-	int cc;
-	unsigned int total, expected;
-	int gothead;
-
-	tpt = (struct tprot *)packet;
-	total = cc = recv(sd, packet, sizeof(struct tprot), 0);
-	expected = sizeof(struct tprot);	/* until we get tp_dlen */
-	gothead = total >= sizeof(struct tprot);
-	if (gothead)
-		expected += ntohl(tpt->tp_dlen);
-	if (cc <= 0)
-		return cc;
-	while (cc > 0 && total < expected) {
-		cc = recv(sd, &packet[total], expected - total, 0);
-		if (cc >= 0) {
-			total += cc;
-			if (!gothead && total >= sizeof(struct tprot)) {
-				gothead = 1;
-				expected += ntohl(tpt->tp_dlen);
-			}
-		} else {
-			break;
-		}
-	}
-	if (cc < 0)
-		return cc;
-	return total;
-}
-
-static unsigned short csum(unsigned short partial, unsigned char *packet,
-			   int len)
-{
-	unsigned long sum = partial;
-	unsigned short *ps;
-	int i;
-
-	ps = (unsigned short *)packet;
-	for (i = 0; i < len / 2; ++i)
-		sum += *ps++;
-	if (len & 1)
-		sum += htons(packet[len - 1] << 8);
-	sum = (sum >> 16) + (sum & 0xffff);
-	sum += (sum >> 16);
-	return ~sum;
-}
-
-static struct ph {
-	struct in6_addr ph_sa;
-	struct in6_addr ph_da;
-	uint32_t ph_len;
-	uint8_t ph_mbz[3];
-	uint8_t ph_nh;
-} ph;
-
-static int client(int sfd)
-{
-	struct tprot *pttp = (struct tprot *)tpbuf;
-	struct tprot *prtp = (struct tprot *)rpbuf;
-	struct sockaddr_in6 rsin6;
-	static int seq;
-	unsigned int i;
-	int sd, cc, cs;
-
-	memset(&rsin6, 0, sizeof(rsin6));
-	rsin6.sin6_family = AF_INET6;
-	rsin6.sin6_addr = in6addr_loopback;
-
-	memset(&ph, 0, sizeof(ph));
-	ph.ph_sa = rsin6.sin6_addr;
-	ph.ph_da = rsin6.sin6_addr;
-	ph.ph_nh = NH_TEST;
-
-	sd = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
-
-	for (i = 0; i < CSCOUNT; ++i) {
-		int offset, len, xlen;
-		int rv;
-		unsigned char *p, *pend;
-
-		offset = sizeof(struct tprot) + cstab[i].cs_offset;
-		len = sizeof(struct tprot) + cstab[i].cs_dlen;
-
-		memset(pttp, 0, sizeof(*pttp));
-		memset(pttp->tp_dat, 0xA5, cstab[i].cs_dlen);
-
-		pttp->tp_pid = htonl(pid);
-		pttp->tp_offset = ntohl(offset);
-		pttp->tp_dlen = ntohl(cstab[i].cs_dlen);
-		pttp->tp_seq = ntohl(++seq);
-
-		TEST(setsockopt(sd, IPPROTO_IPV6, IPV6_CHECKSUM, &offset,
-				sizeof(offset)));
-		if (TEST_RETURN != cstab[i].cs_setresult) {
-			tst_resm(TFAIL | TTERRNO,
-				 "IPV6_CHECKSUM offset %d len %d "
-				 "- result %ld != %d", offset, len, TEST_RETURN,
-				 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)));
-		xlen = (cstab[i].cs_sndresult < 0) ? -1 : len;
-		if (TEST_RETURN != xlen) {
-			tst_resm(TFAIL | TTERRNO,
-				 "IPV6_CHECKSUM offset %d len %d "
-				 "- sndresult %ld != %d", offset, len,
-				 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))) {
-			if (htonl(prtp->tp_pid) == (uint32_t)pid &&
-			    htonl(prtp->tp_seq) == (uint32_t)seq)
-				break;
-		}
-		rv = 1;
-		pend = rpbuf + sizeof(struct tprot) + ntohl(prtp->tp_dlen);
-		for (p = &prtp->tp_dat[0]; p < pend; ++p) {
-			if (p == &rpbuf[offset] || p == &rpbuf[offset + 1])
-				continue;
-			if (*p != 0xa5) {
-				tst_resm(TFAIL, "IPV6_CHECKSUM corrupt data "
-					 "0x%02x != 0xa5, offset %zd in packet",
-					 *p, p - rpbuf);
-				rv = 0;
-				break;
-			}
-		}
-		if (rv == 0)
-			continue;
-		ph.ph_len = htonl(xlen);
-		cs = csum(0, (unsigned char *)&ph, sizeof(ph));
-		cs = csum(~cs, rpbuf, xlen);
-		if (!csum(0, rpbuf, xlen)) {
-			tst_resm(TFAIL, "IPV6_CHECKSUM offset %d len %d (bad "
-				 "checksum)", offset, len);
-			continue;
-		}
-		tst_resm(TPASS, "IPV6_CHECKSUM offset %d len %d", offset, len);
-	}
-	return 0;
-}
-
-static int listen_fd, connect_fd;
-
-static void *ilistener(void *arg LTP_ATTRIBUTE_UNUSED)
-{
-	connect_fd = accept(listen_fd, 0, 0);
-	close(listen_fd);
-	return NULL;
-}
-
-static void isocketpair(int pf, int type, int proto, int fd[2])
-{
-	pthread_t thid;
-	struct sockaddr_in sin4;
-	socklen_t namelen;
-
-	listen_fd = SAFE_SOCKET(NULL, pf, type, proto);
-
-	memset(&sin4, 0, sizeof(sin4));
-
-	SAFE_BIND(NULL, listen_fd, (struct sockaddr *)&sin4, sizeof(sin4));
-
-	SAFE_LISTEN(NULL, listen_fd, 10);
-
-	namelen = sizeof(sin4);
-	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);
-
-	sin4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-
-	SAFE_CONNECT(NULL, fd[0], (struct sockaddr *)&sin4, sizeof(sin4));
-
-	pthread_join(thid, NULL);
-
-	fd[1] = connect_fd;
-}
-
-#ifndef MAX
-#define MAX(a, b) (@ >= (b) ? (a) : (b))
-#endif /* MAX */
-
-static void csum_test(void)
-{
-	fd_set rset, rset_save;
-	int csd[2];		/* control sockets */
-	int sd, nfds, maxfd, cc;
-	struct timeval tv;
-
-	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);
-	memcpy(&rset, &rset_save, sizeof(rset));
-	maxfd = MAX(sd, csd[1]);
-
-	/* server socket set; now start the client */
-	switch (fork()) {
-	case 0:
-		close(csd[0]);
-		break;
-	case -1:
-		tst_brkm(TBROK, NULL, "can't fork rserver");
-	default:
-		close(sd);
-		close(csd[1]);
-		client(csd[0]);
-		return;
-	}
-
-	tv.tv_sec = READ_TIMEOUT;
-	tv.tv_usec = 0;
-	while ((nfds = select(maxfd + 1, &rset, 0, 0, &tv)) >= 0) {
-		if (nfds < 0) {
-			if (errno == EINTR)
-				continue;
-			exit(0);
-		} else if (nfds == 0) {
-			fprintf(stderr, "server read timed out");
-			return;
-		}
-		if (FD_ISSET(sd, &rset)) {
-			static char packet[2048];
-
-			cc = recv(sd, packet, sizeof(packet), 0);
-			if (cc < 0) {
-				perror("server recvtprot");
-				exit(1);
-			}
-			if (cc == 0)
-				exit(0);
-			if (write(csd[1], packet, cc) < 0) {
-				perror("server write UNIX socket");
-				exit(0);
-			}
-		}
-		if (FD_ISSET(csd[1], &rset)) {
-			char buf[2048];
-
-			cc = read(csd[1], buf, sizeof(buf));
-			if (cc == 0)
-				exit(0);
-			if (cc < 0) {
-				perror("server read");
-				exit(1);
-			}
-			/* handle commands here, if any added later */
-		}
-		memcpy(&rset, &rset_save, sizeof(rset));
-		tv.tv_sec = READ_TIMEOUT;
-		tv.tv_usec = 0;
-	}
-}
-
-static void setup(void)
-{
-	TEST_PAUSE;
-
-	pid = getpid();
-}
diff --git a/testcases/network/lib6/asapi_05.c b/testcases/network/lib6/asapi_05.c
deleted file mode 100644
index f8c30f1..0000000
--- a/testcases/network/lib6/asapi_05.c
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- * Copyright (c) 2015 Fujitsu Ltd.
- * 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 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/>.
- *
- * Author: David L Stevens
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <sys/wait.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <netinet/ip6.h>
-#include <netinet/icmp6.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "asapi_05";
-
-static void setup(void);
-
-static void icmp6_ft(void);
-
-int main(int argc, char *argv[])
-{
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc)
-		icmp6_ft();
-
-	tst_exit();
-}
-
-static void setup(void)
-{
-	TEST_PAUSE;
-	tst_require_root();
-}
-
-enum tt {
-	T_WILLPASS,
-	T_WILLBLOCK,
-	T_SETPASS,
-	T_SETBLOCK,
-	T_SETPASSALL,
-	T_SETBLOCKALL
-};
-
-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? */
-} 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	ARRAY_SIZE(ftab)
-
-static int ic6_send1(char *tname, unsigned char type)
-{
-	struct sockaddr_in6 sin6;
-	struct icmp6_hdr ic6;
-	int s;
-
-	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());
-
-	memset(&sin6, 0, sizeof(sin6));
-	sin6.sin6_family = AF_INET6;
-	sin6.sin6_addr = in6addr_loopback;
-	if (sendto(s, &ic6, sizeof(ic6), 0, (struct sockaddr *)&sin6,
-		   sizeof(sin6)) == -1) {
-		tst_resm(TBROK | TERRNO, "%s: sendto failed", tname);
-		return 1;
-	}
-	return 0;
-}
-
-static int ic6_recv1(char *tname, int sall, int sf)
-{
-	fd_set readfds, readfds_saved;
-	struct timeval tv;
-	int maxfd, nfds;
-	int gotall, gotone;
-	int cc;
-	static unsigned char rbuf[2048];
-
-	tv.tv_sec = 0;
-	tv.tv_usec = 250000;
-
-	FD_ZERO(&readfds_saved);
-	FD_SET(sall, &readfds_saved);
-	FD_SET(sf, &readfds_saved);
-	maxfd = MAX(sall, sf);
-
-	memcpy(&readfds, &readfds_saved, sizeof(readfds));
-
-	gotall = gotone = 0;
-	/*
-	 * Note: this relies on linux-specific behavior (select
-	 * updating tv with time elapsed)
-	 */
-	while (!gotall || !gotone) {
-		struct icmp6_hdr *pic6 = (struct icmp6_hdr *)rbuf;
-
-		nfds = select(maxfd + 1, &readfds, 0, 0, &tv);
-		if (nfds == 0)
-			break;	/* timed out */
-		if (nfds < 0) {
-			if (errno == EINTR)
-				continue;
-			tst_resm(TBROK | TERRNO, "%s: select failed", tname);
-		}
-		if (FD_ISSET(sall, &readfds)) {
-			cc = recv(sall, rbuf, sizeof(rbuf), 0);
-			if (cc < 0) {
-				tst_resm(TBROK | TERRNO,
-					 "%s: recv(sall, ..) failed", tname);
-				return -1;
-			}
-			/* if packet check succeeds... */
-			if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid())
-				gotall = 1;
-		}
-		if (FD_ISSET(sf, &readfds)) {
-			cc = recv(sf, rbuf, sizeof(rbuf), 0);
-			if (cc < 0) {
-				tst_resm(TBROK | TERRNO,
-					 "%s: recv(sf, ..) failed", tname);
-				return -1;
-			}
-			/* if packet check succeeds... */
-			if (htonl(pic6->icmp6_data32[0]) == (uint32_t)getpid())
-				gotone = 1;
-		}
-		memcpy(&readfds, &readfds_saved, sizeof(readfds));
-	}
-	if (!gotall) {
-		tst_resm(TBROK, "%s: recv all timed out", tname);
-		return -1;
-	}
-	if (gotone)
-		return 1;
-	return 0;
-}
-
-/* functional tests */
-static void icmp6_ft(void)
-{
-	struct icmp6_filter i6f;
-	int sall, sf;
-	unsigned int i;
-
-	sall = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
-
-	ICMP6_FILTER_SETPASSALL(&i6f);
-	if (setsockopt(sall, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f,
-		       sizeof(i6f)) < 0) {
-		tst_resm(TBROK | TERRNO,
-			 "setsockopt pass all ICMP6_FILTER failed");
-	}
-
-	sf = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
-
-	int rv;
-
-	for (i = 0; i < FTCOUNT; ++i) {
-
-		rv = -1;
-
-		switch (ftab[i].ft_test) {
-		case T_SETPASS:
-			ICMP6_FILTER_SETBLOCKALL(&i6f);
-			ICMP6_FILTER_SETPASS(ftab[i].ft_flttype, &i6f);
-			break;
-		case T_SETPASSALL:
-			ICMP6_FILTER_SETPASSALL(&i6f);
-			break;
-		case T_SETBLOCK:
-			ICMP6_FILTER_SETPASSALL(&i6f);
-			ICMP6_FILTER_SETBLOCK(ftab[i].ft_flttype, &i6f);
-			break;
-		case T_SETBLOCKALL:
-			ICMP6_FILTER_SETBLOCKALL(&i6f);
-			break;
-		case T_WILLBLOCK:
-			ICMP6_FILTER_SETPASSALL(&i6f);
-			ICMP6_FILTER_SETBLOCK(ftab[i].ft_flttype, &i6f);
-			rv = ICMP6_FILTER_WILLBLOCK(ftab[i].ft_sndtype, &i6f);
-			break;
-		case T_WILLPASS:
-			ICMP6_FILTER_SETBLOCKALL(&i6f);
-			ICMP6_FILTER_SETPASS(ftab[i].ft_flttype, &i6f);
-			rv = ICMP6_FILTER_WILLPASS(ftab[i].ft_sndtype, &i6f);
-			break;
-		default:
-			tst_resm(TBROK, "%s: unknown test type %d",
-				 ftab[i].ft_tname, ftab[i].ft_test);
-			continue;
-		}
-		if (ftab[i].ft_test != T_WILLBLOCK &&
-		    ftab[i].ft_test != T_WILLPASS) {
-			if (setsockopt(sf, IPPROTO_ICMPV6, ICMP6_FILTER, &i6f,
-				       sizeof(i6f)) < 0) {
-				tst_resm(TFAIL | TERRNO,
-					 "setsockopt ICMP6_FILTER");
-				continue;
-			}
-			if (ic6_send1(ftab[i].ft_tname, ftab[i].ft_sndtype))
-				continue;
-			rv = ic6_recv1(ftab[i].ft_tname, sall, sf);
-		} else {
-			rv = -1;
-		}
-
-		if (rv < 0)
-			continue;
-		if (rv != ftab[i].ft_expected)
-			tst_resm(TFAIL, "%s: rv %d != expected %d",
-				 ftab[i].ft_tname, rv, ftab[i].ft_expected);
-		else
-			tst_resm(TPASS, "%s", ftab[i].ft_tname);
-	}
-}
diff --git a/testcases/network/lib6/asapi_06.c b/testcases/network/lib6/asapi_06.c
deleted file mode 100644
index c6e2c8e..0000000
--- a/testcases/network/lib6/asapi_06.c
+++ /dev/null
@@ -1,385 +0,0 @@
-/*
- * Copyright (c) 2015 Fujitsu Ltd.
- * 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 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/>.
- *
- * Author: David L Stevens
- */
-
-#include "config.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <netdb.h>
-#include <libgen.h>
-#include <pthread.h>
-#include <semaphore.h>
-
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <netinet/ip6.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <sys/ioctl.h>
-#ifdef HAVE_IFADDRS_H
-#include <ifaddrs.h>
-#endif
-#include <arpa/inet.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "asapi_06";
-
-int TST_TOTAL = 1;
-
-#define READ_TIMEOUT	5	/* secs */
-
-static void do_tests(void);
-static void setup(void);
-
-int main(int argc, char *argv[])
-{
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc)
-		do_tests();
-
-	tst_exit();
-}
-
-#define NH_TEST	0x9f
-
-#ifndef IPV6_RECVPKTINFO
-#define IPV6_RECVPKTINFO	-1
-#endif
-#ifndef IPV6_RECVHOPLIMIT
-#define IPV6_RECVHOPLIMIT	-1
-#endif
-#ifndef IPV6_RECVRTHDR
-#define IPV6_RECVRTHDR		-1
-#endif
-#ifndef IPV6_RECVHOPOPTS
-#define IPV6_RECVHOPOPTS	-1
-#endif
-#ifndef IPV6_RECVDSTOPTS
-#define IPV6_RECVDSTOPTS	-1
-#endif
-#ifndef IPV6_RECVTCLASS
-#define IPV6_RECVTCLASS		-1
-#endif
-#ifndef IPV6_TCLASS
-#define IPV6_TCLASS		-1
-#endif
-#ifndef IPV6_2292PKTINFO
-#define	IPV6_2292PKTINFO	-1
-#endif
-#ifndef IPV6_2292HOPLIMIT
-#define	IPV6_2292HOPLIMIT	-1
-#endif
-#ifndef IPV6_2292RTHDR
-#define	IPV6_2292RTHDR		-1
-#endif
-#ifndef IPV6_2292HOPOPTS
-#define	IPV6_2292HOPOPTS	-1
-#endif
-#ifndef IPV6_2292DSTOPTS
-#define	IPV6_2292DSTOPTS	-1
-#endif
-
-union soval {
-	struct in6_pktinfo sou_pktinfo;
-	int sou_hoplimit;
-	struct sockaddr_in6 sou_nexthop;
-	struct ip6_rthdr sou_rthdr;
-	struct ip6_hbh sou_hopopts;
-	struct ip6_dest sou_dstopts;
-	struct ip6_dest sou_rthdrdstopts;
-	int sou_tclass;
-	int sou_bool;
-};
-
-/* in6_addr initializer for loopback interface */
-#define IN6_LOOP	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
-#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 */
-static struct soent {
-	char *so_tname;
-	int so_opt;
-	int so_dorecv;		/* do receive test? */
-	int so_cmtype;
-	int so_clear;		/* get fresh socket? */
-	union soval so_clrval;
-	union soval so_setval;
-	socklen_t so_valsize;
-} sotab[] = {
-	/* 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 */
-	unsigned char sop_dat[0];	/* user data */
-};
-
-static unsigned char tpbuf[sizeof(struct soprot) + 2048];
-static unsigned char rpbuf[sizeof(struct soprot) + 2048];
-
-static unsigned char control[2048];
-
-static int seq;
-
-static struct cme {
-	int cm_len;
-	int cm_level;
-	int cm_type;
-	union {
-		uint32_t cmu_tclass;
-		uint32_t cmu_hops;
-	} cmu;
-} cmtab[] = {
-	{sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {0x12} },
-	{sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {0x21} },
-};
-
-#define CMCOUNT	ARRAY_SIZE(cmtab)
-
-static ssize_t sendall(int st)
-{
-	struct sockaddr_in6 sin6;
-	struct msghdr msg;
-	struct iovec iov;
-	struct soprot *psop;
-	unsigned char *pd;
-	unsigned int i;
-	int ctotal;
-
-	psop = (struct soprot *)tpbuf;
-	psop->sop_pid = htonl(getpid());
-	psop->sop_seq = ++seq;
-	psop->sop_dlen = 0;
-
-	memset(&sin6, 0, sizeof(sin6));
-	sin6.sin6_family = AF_INET6;
-	sin6.sin6_addr = in6addr_loopback;
-
-	memset(&msg, 0, sizeof(msg));
-	msg.msg_name = &sin6;
-	msg.msg_namelen = sizeof(sin6);
-	iov.iov_base = tpbuf;
-	iov.iov_len = sizeof(struct soprot) + ntohl(psop->sop_dlen);
-	msg.msg_iov = &iov;
-	msg.msg_iovlen = 1;
-
-	pd = control;
-	ctotal = 0;
-	for (i = 0; i < CMCOUNT; ++i) {
-		struct cmsghdr *pcmsg = (struct cmsghdr *)pd;
-
-		pcmsg->cmsg_len = CMSG_LEN(cmtab[i].cm_len);
-		pcmsg->cmsg_level = cmtab[i].cm_level;
-		pcmsg->cmsg_type = cmtab[i].cm_type;
-		memcpy(CMSG_DATA(pcmsg), &cmtab[i].cmu, cmtab[i].cm_len);
-		pd += CMSG_SPACE(cmtab[i].cm_len);
-		ctotal += CMSG_SPACE(cmtab[i].cm_len);
-	}
-	msg.msg_control = ctotal ? control : 0;
-	msg.msg_controllen = ctotal;
-
-	return sendmsg(st, &msg, 0);
-}
-
-static void so_test(struct soent *psoe)
-{
-	struct sockaddr_in6 sin6;
-	union soval sobuf;
-	socklen_t valsize;
-	static int sr = -1;
-	int st;
-
-	if (psoe->so_opt == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "%s not present at compile time",
-			 psoe->so_tname);
-	}
-	if (psoe->so_clear || sr < 0) {
-		if (sr < 0)
-			close(sr);
-		sr = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
-	}
-	memset(&sin6, 0, sizeof(sin6));
-	sin6.sin6_family = AF_INET6;
-	sin6.sin6_addr = in6addr_loopback;
-
-	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_brkm(TBROK | TERRNO, NULL, "%s: setsockopt",
-			 psoe->so_tname);
-	}
-
-	TEST(setsockopt(sr, SOL_IPV6, psoe->so_opt, &psoe->so_setval,
-			psoe->so_valsize));
-	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL | TERRNO, "%s set-get: setsockopt",
-			 psoe->so_tname);
-		return;
-	}
-
-	valsize = psoe->so_valsize;
-	TEST(getsockopt(sr, SOL_IPV6, psoe->so_opt, &sobuf, &valsize));
-	if (TEST_RETURN != 0) {
-		tst_brkm(TBROK | TERRNO, NULL, "%s set-get: getsockopt",
-			 psoe->so_tname);
-	} else if (memcmp(&psoe->so_setval, &sobuf, psoe->so_valsize)) {
-		tst_resm(TFAIL, "%s set-get optval != setval", psoe->so_tname);
-	} else {
-		tst_resm(TPASS, "%s set-get", psoe->so_tname);
-	}
-
-	st = SAFE_SOCKET(NULL, PF_INET6, SOCK_RAW, NH_TEST);
-
-	if (sendall(st) < 0)
-		tst_brkm(TBROK | TERRNO, NULL, "%s transmit sendto",
-			 psoe->so_tname);
-
-	close(st);
-
-	/* receiver processing */
-	{
-		fd_set rfds, rfds_saved;
-		int nfds, cc;
-		int gotone;
-		struct timeval tv;
-		struct msghdr msg;
-		unsigned char cmsg[2048];
-		struct cmsghdr *pcmsg;
-		struct iovec iov;
-
-		FD_ZERO(&rfds_saved);
-		FD_SET(sr, &rfds_saved);
-
-		tv.tv_sec = 0;
-		tv.tv_usec = 250000;
-
-		while (1) {
-			memcpy(&rfds, &rfds_saved, sizeof(rfds));
-			nfds = select(sr + 1, &rfds, 0, 0, &tv);
-			if (nfds < 0) {
-				if (errno == EINTR)
-					continue;
-				tst_brkm(TBROK | TERRNO, NULL, "%s select",
-					 psoe->so_tname);
-			}
-			if (nfds == 0) {
-				tst_brkm(TBROK, NULL, "%s recvmsg timed out",
-					 psoe->so_tname);
-				return;
-			}
-			/* else, nfds == 1 */
-			if (!FD_ISSET(sr, &rfds))
-				continue;
-
-			memset(&msg, 0, sizeof(msg));
-			iov.iov_base = rpbuf;
-			iov.iov_len = sizeof(rpbuf);
-			msg.msg_iov = &iov;
-			msg.msg_iovlen = 1;
-			msg.msg_control = cmsg;
-			msg.msg_controllen = sizeof(cmsg);
-
-			cc = recvmsg(sr, &msg, 0);
-			if (cc < 0) {
-				tst_brkm(TBROK | TERRNO, NULL, "%s recvmsg",
-					 psoe->so_tname);
-			}
-			/* check pid & seq here */
-			break;
-		}
-		gotone = 0;
-		for (pcmsg = CMSG_FIRSTHDR(&msg); pcmsg != NULL;
-		     pcmsg = CMSG_NXTHDR(&msg, pcmsg)) {
-			if (!psoe->so_dorecv)
-				break;
-			gotone = pcmsg->cmsg_level == SOL_IPV6 &&
-			    pcmsg->cmsg_type == psoe->so_cmtype;
-			if (gotone) {
-				break;
-			} else if (psoe->so_clear) {
-				tst_resm(TFAIL, "%s receive: extraneous data "
-					 "in control: level %d type %d len %zu",
-					 psoe->so_tname, pcmsg->cmsg_level,
-					 pcmsg->cmsg_type, pcmsg->cmsg_len);
-				return;
-			}
-		}
-		/* check contents here */
-		if (psoe->so_dorecv)
-			tst_resm(gotone ? TPASS : TFAIL, "%s receive",
-				 psoe->so_tname);
-	}
-}
-
-static void do_tests(void)
-{
-	unsigned int i;
-
-	for (i = 0; i < SOCOUNT; ++i) {
-		sotab[i].so_clrval.sou_bool = 0;
-		sotab[i].so_setval.sou_bool = 1;
-		so_test(&sotab[i]);
-	}
-}
-
-static void setup(void)
-{
-	TEST_PAUSE;
-}
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v10 8/8] ipv6_lib: Add it into default
  2015-10-21  3:15                 ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                                     ` (5 preceding siblings ...)
  2015-10-21  3:15                   ` [LTP] [PATCH v10 7/8] lib6: Rename Zeng Linggang
@ 2015-10-21  3:15                   ` Zeng Linggang
  2015-10-22 11:12                   ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Alexey Kodanev
  7 siblings, 0 replies; 38+ messages in thread
From: Zeng Linggang @ 2015-10-21  3:15 UTC (permalink / raw)
  To: ltp

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 scenario_groups/default | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scenario_groups/default b/scenario_groups/default
index 3a55702..60b1b27 100644
--- a/scenario_groups/default
+++ b/scenario_groups/default
@@ -32,3 +32,4 @@ dma_thread_diotest
 cpuacct
 can
 cpuhotplug
+ipv6_lib
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it.
  2015-10-21  3:15                 ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
                                     ` (6 preceding siblings ...)
  2015-10-21  3:15                   ` [LTP] [PATCH v10 8/8] ipv6_lib: Add it into default Zeng Linggang
@ 2015-10-22 11:12                   ` Alexey Kodanev
  7 siblings, 0 replies; 38+ messages in thread
From: Alexey Kodanev @ 2015-10-22 11:12 UTC (permalink / raw)
  To: ltp

Hi,

Patch-set applied, thank you!

Best regards,
Alexey


^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2015-10-22 11:12 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-07 10:47 [LTP] [PATCH v7 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
2015-10-07 10:47 ` [LTP] [PATCH v7 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
2015-10-07 13:07   ` Cyril Hrubis
2015-10-08  1:34     ` Zeng Linggang
2015-10-07 13:28   ` Cyril Hrubis
2015-10-08 11:29     ` [LTP] [PATCH v8 1/7] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
2015-10-08 11:29       ` [LTP] [PATCH v8 2/7] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
2015-10-13 10:45         ` Alexey Kodanev
2015-10-14  6:27           ` Zeng Linggang
2015-10-14  8:21           ` [LTP] [PATCH v9 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
2015-10-14  8:21             ` [LTP] [PATCH v9 2/8] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
2015-10-14  8:21             ` [LTP] [PATCH v9 3/8] lib6/asapi_04.c: Cleanup Zeng Linggang
2015-10-14  8:21             ` [LTP] [PATCH v9 4/8] lib6/asapi_05.c: Cleanup Zeng Linggang
2015-10-14  8:21             ` [LTP] [PATCH v9 5/8] lib6/asapi_06.c: Cleanup Zeng Linggang
2015-10-14  8:21             ` [LTP] [PATCH v9 6/8] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
2015-10-20  8:07               ` Alexey Kodanev
2015-10-21  2:47                 ` Zeng Linggang
2015-10-21  3:15                 ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Zeng Linggang
2015-10-21  3:15                   ` [LTP] [PATCH v10 2/8] SAFE_MACROS: Add socket(), bind(), listen(), connect() and getsockname() Zeng Linggang
2015-10-21  3:15                   ` [LTP] [PATCH v10 3/8] lib6/asapi_04.c: Cleanup Zeng Linggang
2015-10-21  3:15                   ` [LTP] [PATCH v10 4/8] lib6/asapi_05.c: Cleanup Zeng Linggang
2015-10-21  3:15                   ` [LTP] [PATCH v10 5/8] lib6/asapi_06.c: Cleanup Zeng Linggang
2015-10-21  3:15                   ` [LTP] [PATCH v10 6/8] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
2015-10-21  3:15                   ` [LTP] [PATCH v10 7/8] lib6: Rename Zeng Linggang
2015-10-21  3:15                   ` [LTP] [PATCH v10 8/8] ipv6_lib: Add it into default Zeng Linggang
2015-10-22 11:12                   ` [LTP] [PATCH v10 1/8] lib6: Remove runcc.* and the testcases that use it Alexey Kodanev
2015-10-14  8:21             ` [LTP] [PATCH v9 7/8] lib6: Rename Zeng Linggang
2015-10-14  8:21             ` [LTP] [PATCH v9 8/8] ipv6_lib: Add it into default Zeng Linggang
2015-10-08 11:29       ` [LTP] [PATCH v8 3/7] lib6/asapi_04.c: Cleanup Zeng Linggang
2015-10-08 11:29       ` [LTP] [PATCH v8 4/7] lib6/asapi_05.c: Cleanup Zeng Linggang
2015-10-08 11:29       ` [LTP] [PATCH v8 5/7] lib6/asapi_06.c: Cleanup Zeng Linggang
2015-10-08 11:29       ` [LTP] [PATCH v8 6/7] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
2015-10-08 11:29       ` [LTP] [PATCH v8 7/7] ipv6_lib: Add it into default Zeng Linggang
2015-10-07 10:47 ` [LTP] [PATCH v7 3/7] lib6/asapi_04.c: Cleanup Zeng Linggang
2015-10-07 10:47 ` [LTP] [PATCH v7 4/7] lib6/asapi_05.c: Cleanup Zeng Linggang
2015-10-07 10:47 ` [LTP] [PATCH v7 5/7] lib6/asapi_06.c: Cleanup Zeng Linggang
2015-10-07 10:47 ` [LTP] [PATCH v7 6/7] lib6/getaddrinfo_01.c: Cleanup Zeng Linggang
2015-10-07 10:47 ` [LTP] [PATCH v7 7/7] ipv6_lib: Add it into default Zeng Linggang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.