#29 part networking tier1 test cases
Opened 6 months ago by jishi. Modified 6 months ago
https://github.com/linup2011/kernel-test-fedora networking-test  into  master

tests: add tier1 test case for ipv6 and route
jishi • 6 months ago  
tests/networking.yml
file added
+13

@@ -0,0 +1,13 @@

+ - hosts: localhost

+   tags:

+   - classic

+   roles:

+   - role: standard-test-beakerlib

+     tests:

+     - networking/ipv6/socket

+     - networking/ipv6/socket/sock_raw/icmpfilter

+     - networking/ipv6/socket/ioctl/timestamp

+     - networking/route/route_func

+     required_packages:

+     - beakerlib-libraries

+     - gcc

tests/networking/ipv6/socket/Makefile
file added
+88

@@ -0,0 +1,88 @@

+ # Copyright (c) 2006 Red Hat, Inc.  This copyrighted material 

+ # is made available to anyone wishing to use, modify, copy, or

+ # redistribute it subject to the terms and conditions of the GNU General

+ # Public License v.2.

+ #

+ # 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.

+ #

+ # Author: <Your Name> 

+ 

+ #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

+ # Example Makefile for RHTS                                          #

+ # This example is geared towards a test for a specific package       #

+ # It does most of the work for you, but may require further coding   #

+ #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

+ 

+ # The toplevel namespace within which the test lives.

+ # FIXME: You will need to change this:

+ TOPLEVEL_NAMESPACE=kernel/networking/ipv6

+ 

+ # The name of the package under test:

+ # FIXME: you wil need to change this:

+ PACKAGE_NAME=

+ 

+ # The path of the test below the package:

+ # FIXME: you wil need to change this:

+ RELATIVE_PATH=socket

+ 

+ # Version of the Test. Used with make tag.

+ export TESTVERSION=1.1

+ 

+ # The combined namespace of the test.

+ export TEST=/$(TOPLEVEL_NAMESPACE)/$(RELATIVE_PATH)

+ 

+ 

+ # A phony target is one that is not really the name of a file.

+ # It is just a name for some commands to be executed when you

+ # make an explicit request. There are two reasons to use a

+ # phony target: to avoid a conflict with a file of the same

+ # name, and to improve performance.

+ .PHONY: all install download clean

+ 

+ # executables to be built should be added here, they will be generated on the system under test.

+ BUILT_FILES= 

+ 

+ # data files, .c files, scripts anything needed to either compile the test and/or run it.

+ FILES=$(METADATA) runtest.sh Makefile PURPOSE func_tests nonlocal_bind

+ 

+ run: $(FILES) build

+ 	./runtest.sh

+ 

+ build: $(BUILT_FILES)

+ 	chmod a+x ./runtest.sh

+ 

+ clean:

+ 	rm -f *~ *.rpm $(BUILT_FILES)

+ 

+ # You may need to add other targets e.g. to build executables from source code

+ # Add them here:

+ 

+ 

+ # Include Common Makefile

+ include /usr/share/rhts/lib/rhts-make.include

+ 

+ # Generate the testinfo.desc here:

+ $(METADATA): Makefile

+ 	@touch $(METADATA)

+ # Change to the test owner's name

+ 	@echo "Owner:        Hangbin Liu <haliu@redhat.com>" > $(METADATA) # FIXME: customize this

+ 	@echo "Name:         $(TEST)" >> $(METADATA)

+ 	@echo "Path:         $(TEST_DIR)"	>> $(METADATA)

+ 	@echo "License:      FIXME: add correct license here" >> $(METADATA)

+ 	@echo "TestVersion:  $(TESTVERSION)"	>> $(METADATA)

+ 	@echo "Description:  FIXME: add a description here ">> $(METADATA)

+ 	@echo "TestTime:     15m" >> $(METADATA)

+ 	@echo "RunFor:       $(PACKAGE_NAME)" >> $(METADATA)  

+ # add any other packages for which your test ought to run here

+ 	@echo "Requires:     $(PACKAGE_NAME)" >> $(METADATA)  

+ 	@echo "Requires:     gcc" >> $(METADATA) 

+ # add any other requirements for the script to run here

+ 

+ # You may need other fields here; see the documentation

+ 	rhts-lint $(METADATA)

tests/networking/ipv6/socket/PURPOSE
file added
+1

@@ -0,0 +1,1 @@

+ 1. Add non local bind test.

tests/networking/ipv6/socket/func_tests/3_Socket_Interface.c
file added
+82

@@ -0,0 +1,82 @@

+ #include	"network.h"

+ 

+ int main(int argc, char *argv[])

+ {

+ 

+ /* 

+  * 3.1 IPv6 Address Family and Protocol Family

+  * Defined family name AF_INET6 and PF_INET6 in <sys/socket.h>

+  */

+ 

+ #ifndef AF_INET6

+ 	fprintf(stdout, "BROK: We have not defined AF_INET6\n");

+ 	exit(1);

+ #endif

+ 	fprintf(stdout, "PASS: We have defined AF_INET6\n");

+ 

+ #ifndef PF_INET6

+ 	fprintf(stdout, "BROK: We have not defined PF_INET6\n");

+ 	exit(1);

+ #endif

+ 	fprintf(stdout, "PASS: We have defined PF_INET6\n");

+ 	

+ /*

+  * 3.2 IPv6 Address Structure

+  * Defined struct in6_addr

+  * 

+  * 3.8 IPv6 Wildcard Address

+  * 3.9 IPv6 Loopback Address

+  */

+  

+ 	char addr[MAXLINE + 1];

+ 

+ 	struct in6_addr anyaddr = IN6ADDR_ANY_INIT;

+ 	if (inet_ntop(AF_INET6, &anyaddr, addr, sizeof(addr)) != NULL) {

+ 		fprintf(stdout, "PASS: Our IPv6 any addr is %s\n", addr);

+ 	} else {

+ 		perror("BROK: inet_ntop error: ");

+ 		exit(1);

+ 	}

+ 	

+ 	struct in6_addr loaddr = IN6ADDR_LOOPBACK_INIT;

+ 	if (inet_ntop(AF_INET6, &loaddr, addr, sizeof(addr)) != NULL) {

+ 		fprintf(stdout, "PASS: Our IPv6 loopback addr is %s\n", addr);

+ 	} else {

+ 		perror("BROK: inet_ntop error: ");

+ 		exit(1);

+ 	}

+ 	

+ /* 3.3 Socket Address Structure

+  * Defined struct sockaddr_in6

+  * We don't have a sin6_len field in Linux

+  * */

+ 

+ /*

+ 	if ( (len = sizeof(servaddr.sin6_len)) != NULL ){

+ 		fprintf(stdout, "size of sockaddr_in6.sin6_len is %d", len);

+ 	} else {

+ 		fprintf(stdout, "We don't have a sin6_len field");

+ 	}

+ */

+ 

+ 	struct sockaddr_in6 loaddrinfo;	

+ 	

+ 	bzero(&loaddrinfo, sizeof(loaddrinfo));

+ 	loaddrinfo.sin6_family = AF_INET6;

+ 	loaddrinfo.sin6_port = htons(TCPPORT);

+ 	loaddrinfo.sin6_addr = in6addr_loopback;

+ 	

+ 	/* Display the address information */

+ 	fprintf(stdout, 

+ 			"PASS: Address info:\n"

+ 			"	sin6_family	= %d (AF_INET = %d, AF_INET6 = %d)\n"

+ 			"	sin6_port	= %d\n"

+ 			"	sin6_flowinfo	= %d\n"

+ 			"	sin6_addr	= %d\n"

+ 			"	sin6_scope_id	= %d\n",

+ 			loaddrinfo.sin6_family, AF_INET, AF_INET6, loaddrinfo.sin6_port,

+ 			loaddrinfo.sin6_flowinfo, loaddrinfo.sin6_addr, 

+ 			loaddrinfo.sin6_scope_id);

+ 			

+ 	exit(0);

+ }

tests/networking/ipv6/socket/func_tests/4_Interface_Identification.c
file added
+54

@@ -0,0 +1,54 @@

+ #include	"network.h"

+ 

+ int main(int argc, char *argv[])

+ {

+ 	int		loi, ifi;

+ 	const char	lo[] = "lo";

+ 	char	iface[MAXLINE];

+ 	int		n = 0;

+ 	char	*ifname = NULL;

+ 	struct if_nameindex	*allif;

+ 

+ /*

+  * 4.1 Name-to-Index

+  * */

+ 

+ 	if ( (loi = if_nametoindex(lo)) == 0) {

+ 		fprintf(stdout, "BROK: if_nametoindex error, no such device");

+ 	}

+ 	printf("PASS : lo index is %d\n", loi);

+ 

+ /*

+  * 4.2 Index-to-Name

+  * */

+ 

+ 	if ( if_indextoname(loi, iface) == NULL) {

+ 		perror("BROK: if_indextoname error, ");

+ 		exit(1);

+ 	}

+ 	printf("PASS : interface name is %s\n", iface);

+ 

+ /*

+  * 4.3 Return All Interface Names and Indexes

+  * */

+ 

+ 	if ( (allif = if_nameindex()) ==NULL){

+ 		perror("BROK : if_nameindex error, ");

+ 		exit(1);

+ 	}

+ 	printf("PASS : get all interface names.\n");

+ 	while ( allif[n].if_index != 0) {

+ 		printf("\tinterface index is %d, name is %s\n", 

+ 				allif[n].if_index, allif[n].if_name);

+ 		n++;

+ 	}

+ 

+ /*

+  * 4.4 Free Memory

+  * */

+ 

+ 	if_freenameindex(allif);

+ 	printf("PASS : free nameindex memory.\n");

+ 

+ 	exit(0);

+ }

tests/networking/ipv6/socket/func_tests/5-1_Socket_Options_Unicast.c
file added
+27

@@ -0,0 +1,27 @@

+ #include	"network.h"

+ 

+ int main(int argc, char *argv[])

+ {

+ 	int	sockfd, hops;

+ 	int	hoplimit = 10;

+ 	socklen_t	len = sizeof(hops);

+ 

+ 	if ( (sockfd = socket(AF_INET6, SOCK_STREAM, 0)) == -1) {

+ 		perror("BROK : socket error, ");

+ 		exit(1);

+ 	}

+ 

+ 	if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_UNICAST_HOPS,

+ 				(char *) &hoplimit, sizeof(hoplimit)) == -1)

+ 		perror("BROK : setsockopt IPV6_UNICAST_HOPS error");

+ 	else

+ 		printf("PASS : setsockopt IPV6_UNICAST_HOPS.\n");

+ 	

+ 	if (getsockopt(sockfd, IPPROTO_IPV6, IPV6_UNICAST_HOPS,

+ 				(char *) &hops, &len) == -1)

+ 		perror("BROK : getsockopt IPV6_UNICAST_HOPS");

+ 	else

+ 		printf("PASS : Using %d for hop limit.\n", hops);

+ 

+ 	exit(0);

+ }

tests/networking/ipv6/socket/func_tests/5-2_Socket_Options_Multicast.c
file added
+121

@@ -0,0 +1,121 @@

+ #include	"network.h"

+ 

+ int	is_bad_interface_name(char *);

+ int get_first_interface(void);

+ 

+ int main(int argc, char argv[])

+ {

+ 	int		sockfd;

+ 	unsigned int	ifi;

+ 	struct ipv6_mreq	mreq6;

+ 	struct in6_addr	maddr6;

+ 	char	*maddr;

+ 

+ 	if (argc == 2)

+ 		maddr = &argv[1];

+ 	else

+ 		maddr = MADDR6;

+ 

+ 	if ( (ifi = get_first_interface()) == -1){

+ 		perror("BROK : get_first_interface error ");

+ 		exit(1);

+ 	}

+ 

+ 	if ( inet_pton(AF_INET6, maddr,  &maddr6) == -1) {

+ 		perror("BROK : inet_pton error ");

+ 		exit(1);

+ 	}

+ 

+ /* Test IPV6_JOIN_GROUP */

+ 

+ 	if ( (sockfd = socket(AF_INET6, SOCK_DGRAM, 0)) == -1 ){

+ 		perror("BROK : socket error ");

+ 		exit(1);

+ 	}

+ 	mreq6.ipv6mr_interface = ifi;

+ 	mreq6.ipv6mr_multiaddr = maddr6;

+ 	if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, 

+ 				&mreq6, sizeof(mreq6)) == -1) {

+ 		perror("BROK : setsockopt IPV6_JOIN_GROUP fail ");

+ 		exit(1);

+ 	}

+ 	

+ 	const char	lo[] = "lo";

+ 	int			loi;

+ 	if ( (loi = if_nametoindex(lo)) == 0) {

+ 		fprintf(stdout, "BROK: if_nametoindex error, no such device");

+ 	}

+ 	if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_IF,

+ 				(char *) &loi , sizeof(loi)) == -1){

+ 		perror("BROK : setsockopt IPV6_MULTICAST_IF fail ");

+ 		exit(1);

+ 	} else

+ 		printf("PASS : setsockopt IPV6_MULTICAST_IF.\n");

+ 

+ 	int		hoplimit = 2;

+ 	int		hops;

+ 	socklen_t	len = sizeof(hops);

+ 	if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, 

+ 				(char *) &hoplimit, sizeof(hoplimit)) == -1)

+ 		perror("BROK : setsockopt IPV6_UNICAST_HOPS error");

+ 	else

+ 		printf("PASS : setsockopt IPV6_UNICAST_HOPS.\n");

+ 

+ 

+ 	int		enable_loop;

+ 	socklen_t	llen = sizeof(enable_loop);

+ 	if ( getsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,

+ 				(char *) &enable_loop, &llen) == -1) {

+ 		perror("BROK : getsockopt IPV6_MULTICAST_LOOP fail ");

+ 		exit(1);

+ 	}

+ 	printf("PASS : getsockopt IPV6_MULTICAST_LOOP value %d\n", enable_loop);

+ 

+ 	exit(0);

+ }

+ 

+ static char	*bad_interface_name[] = {

+ 	"lo:",

+ 	"lo",

+ 	"stf",	/* pseudo-device 6to4 tunnel interface */

+ 	"gif",	/* psuedo-device generic tunnel interface */

+ 	"dummy",

+ 	"vmnet",

+ 	NULL	/* last entry must be NULL */

+ };

+ 

+ int	is_bad_interface_name(char *i)

+ {

+ 	char	**p;

+ 	for ( p = bad_interface_name; *p; ++p)

+ 		if(strncmp(i, *p, strlen(*p)) == 0)

+ 			return 1;

+ 	return 0;

+ }

+ 

+ //static char	*get_first_interface(void)

+ int	get_first_interface(void)

+ {

+ 	struct if_nameindex	*nameindex;

+ 	char	*i = NULL;

+ 	int		 j = 0;

+ 	unsigned int	n;

+ 

+ 	nameindex = if_nameindex();

+ 	if(nameindex == NULL) {

+ 		return -1;

+ 	}

+ 

+ 	while (nameindex[j].if_index != 0){

+ 		if (strcmp(nameindex[j].if_name, "lo") != 0 && 

+ 				!is_bad_interface_name(nameindex[j].if_name)){

+ //			i = xstrdup(nameindex[j].if_name);

+ 			n = nameindex[j].if_index;

+ 			break;

+ 		}

+ 		j++;

+ 	}

+ 	if_freenameindex(nameindex);

+ //	return i;

+ 	return n;

+ }

tests/networking/ipv6/socket/func_tests/6_Library_Functions.c
file added
+62

@@ -0,0 +1,62 @@

+ #include	"network.h"

+ 

+ int main(int argc, char *argv[])

+ {

+ 	int		err;

+ 	char	*node = "localhost6";

+ 	char	*service = "ssh";

+ 	struct addrinfo	hints, *res;

+ 

+ 	bzero(&hints, sizeof(hints));

+ 	hints.ai_flags = AI_CANONNAME;

+ 	hints.ai_family = AF_INET6;

+ 

+ /*

+  * 6.1 Protocol-Independent Nodename and Service Name Translation

+  * */

+ 

+ 	err = getaddrinfo(node, service, &hints, &res);

+ 	if ( err != 0) {

+ 		printf("BROK : getaddrinfo fail, %s\n", gai_strerror(err));

+ 		exit(1);

+ 	} else 

+ 		printf("PASS : getaddrinfo \n");

+ 

+ //	while(res->ai_next != NULL)

+ 	while(1)

+ 	{

+ 		printf("ai_family is %d\n", res->ai_family);

+ 		if (res->ai_next != NULL)

+ 			res = res->ai_next;

+ 		else

+ 			break;

+ 	}

+ 

+ 	freeaddrinfo(res);

+ 	printf("PASS : freeaddrinfo");

+ 

+ /*

+  * 6.2 Socket Address Structure to Node Name and Service Name

+  * */

+ 

+ /* Test getnameinfo */

+ 	struct sockaddr_in6 sa;

+ 	char	host[MAXLINE], serv[MAXLINE];

+ 

+ 	bzero(&sa, sizeof(sa));

+ 	sa.sin6_family = AF_INET6;

+ 	sa.sin6_addr = in6addr_loopback;

+ 	sa.sin6_port = htons(443);

+ 	

+ 	err = getnameinfo((struct sockaddr *) &sa, sizeof(sa), host,

+ 			sizeof(host), serv, sizeof(serv), 0);

+ 	if ( err != 0) {

+ 		printf("BROK : getnameinfo fail, %s\n", gai_strerror(err));

+ 		exit(1);

+ 	} else 

+ 		printf("PASS : getnameinfo \n");

+ 

+ 	printf("hostname is %s, service is %s\n", host, serv);

+ 

+ 	exit(0);

+ }

tests/networking/ipv6/socket/func_tests/Makefile
file added
+12

@@ -0,0 +1,12 @@

+ # Makefile

+ 

+ TARGET	:= $(patsubst %.c,%,$(wildcard *.c))

+ 

+ all : $(TARGET)

+ .PHONY : all

+ % : %.c

+ 	cc $^ -o $@

+ 

+ .PHONY : clean

+ clean :

+ 	rm -f $(TARGET)

tests/networking/ipv6/socket/func_tests/network.h
file added
+42

@@ -0,0 +1,42 @@

+ /* This is a include file for C networking programs */

+ 

+ /* include functions */

+ /* printf fprintf */

+ #include	<stdio.h>

+ 

+ /* perror() also need stdio.h */

+ #include	<errno.h>

+ 

+ /* exit() */

+ #include	<stdlib.h>

+ 

+ /* bzero() strcmp() */

+ #include	<string.h>

+ 

+ /* write() read() */

+ #include	<unistd.h>

+ 

+ /* getaddrinfo() freeaddrinfo() */

+ #include	<netdb.h>

+ 

+ /* write() read() */

+ #include	<unistd.h>

+ 

+ /* socket() connect() */

+ #include	<sys/types.h>

+ #include	<sys/socket.h>

+ 

+ /* inet_pton() */

+ #include	<arpa/inet.h>

+ 

+ /* if_nametoindex() if_indextoname() */

+ #include	<net/if.h>

+ 

+ /* all IPPROTO_IPV6 Options */

+ #include	<netinet/in.h>

+ 

+ #define	MAXLINE	1024

+ #define	TCPPORT	9998

+ #define	UDPPORT	9999

+ #define	LISTENQ	10

+ #define	MADDR6	"ff01::123"

tests/networking/ipv6/socket/func_tests/socket_func_client.c
file added
+67

@@ -0,0 +1,67 @@

+ #include	"network.h"

+ 

+ /*

+  * 3.5 The Socket Functions

+  * Usage: a.out [ IPv6 address ]

+  * */

+ 

+  

+ int main(int argc, char *argv[])

+ {

+ 	

+ 	int		tcpsockfd, udpsockfd;

+ 	struct	sockaddr_in6	tcpservaddr, udpservaddr;

+ 	char	line[] = "Hello World!" ;

+ 	struct in6_addr servaddr = in6addr_any;

+ 	

+ 	if (argc == 2) {

+ 		if( inet_pton(AF_INET6, argv[1], &servaddr) < 0) {

+ 			perror("BORK: inet_pton ");

+ 			exit(1);

+ 		}

+ 	}

+ 

+ 	bzero(&tcpservaddr, sizeof(tcpservaddr));

+ 	bzero(&udpservaddr, sizeof(udpservaddr));

+ 

+ 	tcpservaddr.sin6_family = AF_INET6;

+ 	tcpservaddr.sin6_addr = servaddr;

+ 	tcpservaddr.sin6_port = htons(TCPPORT);

+ 

+ 	udpservaddr.sin6_family = AF_INET6;

+ 	udpservaddr.sin6_addr = servaddr;

+ 	udpservaddr.sin6_port = htons(UDPPORT);

+ 	

+ 	if ( (tcpsockfd = socket(AF_INET6, SOCK_STREAM, 0)) < 0 ) {

+ 		perror("socket error: ");

+ 		exit(1);

+ 	}

+ 	if ( (udpsockfd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0 ) {

+ 		perror("socket error: ");

+ 		exit(1);

+ 	}

+ 	

+ 	if ( connect(tcpsockfd, (struct sockaddr *) &tcpservaddr, sizeof(tcpservaddr)) < 0){

+ 		perror("connect error:");

+ 		exit(1);

+ 	}

+ 	if ( write(tcpsockfd, line, strlen(line)) < 0) {

+ 		perror("wirte error: ");

+ 		exit(1);

+ 	}

+ 	

+ 	if ( sendto(udpsockfd, line, strlen(line), 0, (struct sockaddr *) &udpservaddr, sizeof(udpservaddr)) < 0){

+ 		perror("BROK: sendto ");

+ 		exit(1);

+ 	}

+ 	

+ 	

+ 	if ( close(tcpsockfd) < 0) {

+ 		perror("close error: ");

+ 		exit(1);

+ 	}	

+ 	if ( close(udpsockfd) < 0) {

+ 		perror("close error: ");

+ 		exit(1);

+ 	}

+ }

tests/networking/ipv6/socket/func_tests/socket_func_server.c
file added
+115

@@ -0,0 +1,115 @@

+ #include	"network.h"

+ 

+ /*

+  * 3.5 The Socket Functions

+  * */

+ 

+ int main(int argc, char *argv[])

+ {

+ 	int		tcplen, udplen, n;

+ 	int		tcpsockfd, udpsockfd, tcpclifd;

+ 	struct	sockaddr_in6	tcpservaddr, udpservaddr;

+ 	struct	sockaddr_in6	tcpcliaddr, udpcliaddr;

+ 	char	buff[MAXLINE + 1];

+ 	char	addr[MAXLINE + 1];

+ 

+ 	bzero(&tcpservaddr, sizeof(tcpservaddr));

+ 	bzero(&udpservaddr, sizeof(udpservaddr));

+ 

+ 	tcpservaddr.sin6_family = AF_INET6;

+ 	tcpservaddr.sin6_addr = in6addr_any;

+ 	tcpservaddr.sin6_port = htons(TCPPORT);

+ 

+ 	udpservaddr.sin6_family = AF_INET6;

+ 	udpservaddr.sin6_addr = in6addr_any;

+ 	udpservaddr.sin6_port = htons(UDPPORT);

+ 

+ 	if ( (tcpsockfd = socket(AF_INET6, SOCK_STREAM, 0)) < 0 ) {

+ 		perror("socket error: ");

+ 		exit(1);

+ 	}

+ 	if ( (udpsockfd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0 ) {

+ 		perror("socket error: ");

+ 		exit(1);

+ 	}

+ 	

+ 	if( bind(tcpsockfd, (struct sockaddr *) &tcpservaddr, sizeof(tcpservaddr)) < 0) {

+ 		perror("bind error: ");

+ 		exit(1);

+ 	}

+ 	if ( listen(tcpsockfd, LISTENQ) < 0) {

+ 		perror("listen error: ");

+ 		exit(1);

+ 	}

+ 	if( bind(udpsockfd, (struct sockaddr *) &udpservaddr, sizeof(udpservaddr)) < 0) {

+ 		perror("bind error: ");

+ 		exit(1);

+ 	}

+ 	

+ 	/* Test getsockname(), not understand why use this function */

+ 	udplen = sizeof(udpservaddr);

+ 	if ( getsockname(udpsockfd, (struct sockaddr *) &udpservaddr, &udplen) < 0) {

+ 		perror("BROK: getpeername error: ");

+ 		exit(1);

+ 	}

+ 	if ( inet_ntop(AF_INET6, &udpservaddr.sin6_addr, addr, sizeof(addr)) != NULL) {

+ 		printf("PASS : Connection from %s, port %d\n", addr, ntohs(udpservaddr.sin6_port));

+ 	} else 

+ 	{

+ 		perror("inet_ntop error: ");

+ 		exit(1);

+ 	}

+ 

+ 

+ 	tcplen = sizeof(tcpcliaddr);

+ //	if ( (tcpclifd = accept(tcplistenfd, (struct sockaddr *) &tcpcliaddr, &tcplen)) < 0) {

+ 	if ( (tcpclifd = accept(tcpsockfd, NULL , NULL)) < 0) {

+ 		perror("accept error: ");

+ 		exit(1);

+ 	}

+ 	

+ 		/* Test getpeername() */

+ 	if ( getpeername(tcpclifd, (struct sockaddr *) &tcpcliaddr, &tcplen) < 0) {

+ 		perror("BROK: getpeername error: ");

+ 		exit(1);

+ 	}

+ 	if ( inet_ntop(AF_INET6, &tcpcliaddr.sin6_addr, addr, sizeof(addr)) != NULL) {

+ 		printf("PASS : Connection from %s, port %d\n", addr, ntohs(tcpcliaddr.sin6_port));

+ 	} else 

+ 	{

+ 		perror("inet_ntop error: ");

+ 		exit(1);

+ 	}

+ 

+ 	/* Receive TCP message */

+ 	while( (n = recvfrom(tcpclifd, buff, MAXLINE, 0, NULL , NULL)) > 0){

+ 		buff[n] = 0;

+ 		printf("PASS : Got a message '%s' from tcpclient\n", buff);

+ 		break;

+ 	}

+ 	if ( n < 0 ){

+ 		perror("recvfrom error: ");

+ 		exit(1);

+ 	}

+ 	

+ 	/* Receive UDP message */

+ 	while( (n = recvfrom(udpsockfd, buff, MAXLINE, 0, NULL , NULL)) > 0){

+ 		buff[n] = 0;

+ 		printf("PASS : Got a message '%s' from udpclient\n", buff);

+ 		break;

+ 	}

+ 	if ( n < 0 ){

+ 		perror("recvfrom error: ");

+ 		exit(1);

+ 	}

+ 	

+ 	if ( close(tcpsockfd) < 0) {

+ 		perror("close error: ");

+ 		exit(1);

+ 	}	

+ 	if ( close(udpsockfd) < 0) {

+ 		perror("close error: ");

+ 		exit(1);

+ 	}

+ 

+ }

tests/networking/ipv6/socket/ioctl/timestamp/Makefile
file added
+82

@@ -0,0 +1,82 @@

+ # Copyright (c) 2014 Red Hat, Inc.  This copyrighted material

+ # is made available to anyone wishing to use, modify, copy, or

+ # redistribute it subject to the terms and conditions of the GNU General

+ # Public License v.2.

+ #

+ # 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.

+ #

+ # Author: Wei Chen <weichen@redhat.com>

+ 

+ # The toplevel namespace within which the test lives.

+ # FIXME: You will need to change this:

+ TOPLEVEL_NAMESPACE=kernel

+ 

+ # The name of the package under test:

+ # FIXME: you wil need to change this:

+ PACKAGE_NAME=

+ 

+ # The path of the test below the package:

+ # FIXME: you wil need to change this:

+ RELATIVE_PATH=networking/ipv6/socket/ioctl/timestamp

+ 

+ # Version of the Test. Used with make tag.

+ export TESTVERSION=0.1

+ 

+ # The combined namespace of the test.

+ export TEST=/$(TOPLEVEL_NAMESPACE)/$(RELATIVE_PATH)

+ 

+ 

+ # A phony target is one that is not really the name of a file.

+ # It is just a name for some commands to be executed when you

+ # make an explicit request. There are two reasons to use a

+ # phony target: to avoid a conflict with a file of the same

+ # name, and to improve performance.

+ .PHONY: all install download clean

+ 

+ # executables to be built should be added here, they will be generated on the system under test.

+ BUILT_FILES=

+ 

+ # data files, .c files, scripts anything needed to either compile the test and/or run it.

+ FILES=$(METADATA) runtest.sh Makefile PURPOSE ipv6_ioctl_timestamp.c

+ 

+ run: $(FILES) build

+ 	./runtest.sh

+ 

+ build: $(BUILT_FILES)

+ 	chmod a+x ./runtest.sh

+ 

+ clean:

+ 	rm -f *~ *.rpm $(BUILT_FILES)

+ 

+ # You may need to add other targets e.g. to build executables from source code

+ # Add them here:

+ 

+ 

+ # Include Common Makefile

+ include /usr/share/rhts/lib/rhts-make.include

+ 

+ # Generate the testinfo.desc here:

+ $(METADATA): Makefile

+ 	@touch $(METADATA)

+ # Change to the test owner's name

+ 	@echo "Owner:        Wei Chen <weichen@redhat.com>" > $(METADATA)

+ 	@echo "Name:         $(TEST)" >> $(METADATA)

+ 	@echo "Path:         $(TEST_DIR)"	>> $(METADATA)

+ 	@echo "License:      GPLv2" >> $(METADATA)

+ 	@echo "TestVersion:  $(TESTVERSION)"	>> $(METADATA)

+ 	@echo "Description:  /home/weichen/workingfolder/inet6_ioctl">> $(METADATA)

+ 	@echo "TestTime:     10m" >> $(METADATA)

+ 	@echo "Type:         Regression" >> $(METADATA)

+ 	@echo "RunFor:       $(PACKAGE_NAME)" >> $(METADATA)

+ # add any other packages for which your test ought to run here

+ 	@echo "Requires:     $(PACKAGE_NAME)" >> $(METADATA)

+ # add any other requirements for the script to run here

+ 

+ # You may need other fields here; see the documentation

+ 	rhts-lint $(METADATA)

tests/networking/ipv6/socket/ioctl/timestamp/PURPOSE
file added
+8

@@ -0,0 +1,8 @@

+   SIOCGSTAMP

+     Return  a  struct  timeval with the receive timestamp of the last packet passed to the user.  This is useful for accurate round trip time measure-

+     ments.  See setitimer(2) for a description of struct timeval.  This ioctl should be used only if the socket option SO_TIMESTAMP is not set on  the

+     socket.   Otherwise,  it  returns the timestamp of the last packet that was received while SO_TIMESTAMP was not set, or it fails if no such packet

+     has been received, (i.e., ioctl(2) returns -1 with errno set to ENOENT).

+   SIOCGSTAMPNS

+     Return timestamp of the last packet passed to the user with ns resolution.

+ 

tests/networking/ipv6/socket/ioctl/timestamp/ipv6_ioctl_timestamp.c
file added
+197

@@ -0,0 +1,197 @@

+ #include <stdio.h>

+ #include <unistd.h>

+ #include <fcntl.h>

+ #include <stdlib.h>

+ #include <string.h>

+ #include <sys/types.h>

+ #include <sys/socket.h>

+ #include <sys/ioctl.h>

+ #include <sys/syscall.h>

+ #include <netinet/in.h>

+ #include <arpa/inet.h>

+ #include <errno.h>

+ #include <netinet/in.h>

+ #include <netinet/sctp.h>

+ #include <sys/uio.h>

+ #include <linux/in6.h>

+ #include <linux/socket.h>

+ #include <linux/ipv6.h>

+ #include <netdb.h>

+ 

+ 

+ #define MY_PORT_NUM 51111 /* This can be changed to suit the need and should be same in server and client */

+ #define TRUE 1

+ #define FALSE 0

+ 

+ 

+ int main ()

+ {

+ 

+   int listenSock, connectSock, ret, retime, flags;

+   int  rc, new_sd;

+   struct timeval valbefore, valafter;

+   struct timespec specbefore, specafter;

+   struct sockaddr_in6 servaddrs;

+   struct sockaddr_in6 servaddrc;

+   struct sctp_initmsg initmsg;

+   struct sctp_sndrcvinfo sndrcvinfo; 

+ 

+   flags = 0;

+ 

+   /* Create listen socket */

+   listenSock = socket( AF_INET6, SOCK_STREAM, IPPROTO_SCTP );

+ 

+   bzero( (void *)&servaddrs, sizeof(servaddrs) );

+   servaddrs.sin6_family = AF_INET6;

+   inet_pton(AF_INET6, "0::1", &(servaddrs.sin6_addr));

+   servaddrs.sin6_port = htons(51111);

+   ret = bind( listenSock, (struct sockaddr *)&servaddrs, sizeof(servaddrs) );

+ 

+ 

+   /* Specify that a maximum of 5 streams will be available per socket */

+   memset( &initmsg, 0, sizeof(initmsg) );

+   initmsg.sinit_num_ostreams = 5;

+   initmsg.sinit_max_instreams = 5;

+   initmsg.sinit_max_attempts = 4;

+   ret = setsockopt( listenSock, IPPROTO_SCTP, SCTP_INITMSG,

+                     &initmsg, sizeof(initmsg) );

+ 

+   listen( listenSock, 5 );

+ 

+   /* Create connect socket */

+   connectSock = socket( AF_INET6, SOCK_STREAM, IPPROTO_SCTP );

+ 

+   bzero( (void *)&servaddrc, sizeof(servaddrc) );

+   servaddrc.sin6_family = AF_INET6;

+   servaddrc.sin6_port = htons(51111);

+   inet_pton(AF_INET6, "0::1", &(servaddrc.sin6_addr));

+ 

+   ret = connect( connectSock, (struct sockaddr *)&servaddrc, sizeof(servaddrc) );

+ 

+   /* Accept connection */

+   new_sd = accept(listenSock, NULL, NULL);

+   if (new_sd < 0)

+   {

+      

+      perror("accept() failed");

+      close ( connectSock );

+      close ( listenSock );

+      exit (1);

+       

+   }

+   else

+   {

+    

+      printf("  New incoming connection - %d\n", new_sd);

+      printf("  Accept new connection OK.\n " );

+ 

+   }

+  

+ 

+   char out[20480];

+   char in[20480];

+   int i = 0;

+   int n = 2;

+   int len = 0;

+   bzero ( out, 20480 );

+   bzero ( in, 20480 );

+   strcpy( out, "Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,\

+           Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th,Zara ali a DPS student in class 10th" );

+ 

+   for ( i = 0; i < 2; i++ )

+   {

+   

+       rc = sctp_sendmsg( connectSock, out, (size_t)strlen(out), NULL,0,0,0,0,0,0 );

+       if (rc < 0)

+       {

+       

+          perror("  send() failed");

+          close ( connectSock );

+          close ( new_sd );

+          close ( listenSock );

+          exit (1);

+    

+       }

+   

+       printf("send OK.\n");   

+   

+       rc = sctp_recvmsg( new_sd, in, sizeof(in),

+                      (struct sockaddr *)NULL, 0, &sndrcvinfo, &flags );

+       if (rc <= 0)

+       {

+      

+          perror("  recv() failed");

+          close ( connectSock );

+          close ( listenSock );

+          close ( new_sd );

+          exit (1);

+    

+       }

+ 

+       len = rc;

+       printf("  %d bytes received\n", len);

+ 

+       n = n - 1;    

+       if ( n == 0 )

+       {

+ 

+          /* Get timestamp of struct timeval before 2nd receiving message */

+          retime = ioctl ( new_sd, SIOCGSTAMP, &valbefore );

+          if ( retime < 0 )

+             perror ( "inet6_ioctl failed.");

+          else

+             printf ( "timestamp before receiving: %ld s, %ld us \n", valbefore.tv_sec, valbefore.tv_usec ); 

+ 

+          /* Get timestamp of struct timespec before 2nd receiving message */

+          retime = ioctl ( new_sd, SIOCGSTAMPNS, &specbefore );

+          if ( retime < 0 )

+             perror ( "iinet6_ioctl failed.");

+          else

+             printf ( "timestamp before receiving: %ld s, %ld ns \n", specbefore.tv_sec, specbefore.tv_nsec );

+       

+       }

+   }

+ 

+  

+   /* Get timestamp of struct timeval after 2nd receiving message */

+   retime = ioctl ( new_sd, SIOCGSTAMP, &valafter );

+   if ( retime < 0 )

+      perror ( "inet6_ioctl failed after.");

+   else

+      printf ( "timestamp after receiving: %ld s, %ld us \n", valafter.tv_sec, valafter.tv_usec );

+ 

+ 

+   /* Get timestamp of struct timespec after 2nd receiving message */

+   retime = ioctl ( new_sd, SIOCGSTAMPNS, &specafter );

+   if ( retime < 0 )

+      perror ( "iinet6_ioctl failed after.");

+   else

+      printf ( "timestamp after receiving: %ld s, %ld ns \n", specafter.tv_sec, specafter.tv_nsec );

+ 

+    

+   printf ( "Exiting normally. \n");     

+   exit (0);

+ 

+ }

tests/networking/ipv6/socket/ioctl/timestamp/runtest.sh
file added
+61

@@ -0,0 +1,61 @@

+ #!/bin/bash

+ # vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   runtest.sh of /kernel/networking/

+ #   Description: /home/weichen/workingfolder/inet6_ioctl

+ #   Author: Wei Chen <weichen@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2014 Red Hat, Inc. 

+ #

+ #   This copyrighted material is made available to anyone wishing

+ #   to use, modify, copy, or redistribute it subject to the terms

+ #   and conditions of the GNU General Public License version 2.

+ #

+ #   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.

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ # Global parameters

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 

+ # Include Beaker environment

+ . /usr/share/beakerlib-libraries/kernel/Library/networking-common/include.sh

+ 

+ rlJournalStart

+ 

+         rlPhaseStartSetup

+ 

+             rlRun "yum install -y lksctp-tools-devel"

+             rlRun "modprobe sctp"

+             rlRun "gcc -o ipv6_ioctl_timestamp ipv6_ioctl_timestamp.c -lpthread -lsctp -lc"

+ 

+         rlPhaseEnd

+ 

+         rlPhaseStartTest

+ 

+             rlRun "tcpdump -i any -vvv -n -nn -l -w /root/tcpdumplog.pcap &"

+               

+             rlRun "./ipv6_ioctl_timestamp" 0

+ 

+         rlPhaseEnd

+ 

+         rlPhaseStartCleanup

+                 

+             pkill "./ipv6_ioctl_timestamp";

+             pkill "tcpdump";

+     

+         rlPhaseEnd

+ 

+         rlJournalPrintText

+ 

+ rlJournalEnd

tests/networking/ipv6/socket/nonlocal_bind/nonlocal_bind.c
file added
+97

@@ -0,0 +1,97 @@

+ #include <errno.h>

+ #include <netinet/in.h>

+ #include <stdio.h>

+ #include <stdlib.h>

+ #include <string.h>

+ #include <sys/socket.h>

+ #include <sys/types.h>

+ #include <unistd.h>

+ #include <netdb.h>

+ 

+ int main(int argc, char **argv)

+ {

+ 	struct addrinfo *spoof_info;

+ 	char family_vec[16] = "AF_INET6";

+ 	char type_vec[16] = "SOCK_STREAM";

+ 	char proto_vec[16] = "0";

+ 	int fd, ret = 0, i = 0;

+ 	int type = SOCK_STREAM;

+ 	int protocol = 0;

+ 

+ 	if (argc < 4 ) {

+ 		printf("Usage: %s spoof_ip6_addr spoof_port type [protocol]\n", argv[0]);

+ 		printf("\t type - stream, dgram, seqpacket, raw\n");

+ 		printf("\t protocol - default 0, tcp, udp, sctp, icmp\n");

+ 		return -1;

+ 	}

+ 

+ 	if (getaddrinfo(argv[1], argv[2], NULL, &spoof_info) != 0) {

+ 		perror("getaddrinfo");

+ 		return -1;

+ 	}

+ 

+ 	if (spoof_info->ai_family == AF_INET) {

+ 		strcpy(family_vec, "AF_INET");

+ 	}

+ 

+ 	if (!strcasecmp(argv[3], "stream")) {

+ 		type = SOCK_STREAM;

+ 		strcpy(type_vec, "SOCK_STREAM");

+ 	} else if (!strcasecmp(argv[3], "dgram")) {

+ 		type = SOCK_DGRAM;

+ 		strcpy(type_vec, "SOCK_DGRAM");

+ 	} else if (!strcasecmp(argv[3], "seqpacket")) {

+ 		type = SOCK_SEQPACKET;

+ 		strcpy(type_vec, "SOCK_SEQPACKET");

+ 	} else if (!strcasecmp(argv[3], "raw")) {

+ 		type = SOCK_RAW;

+ 		strcpy(type_vec, "SOCK_RAW");

+ 	} else {

+ 		printf("%s, not support yet!\n", type);

+ 		return -1;

+ 	}

+ 

+ 	if (argc == 5) {

+ 		if (!strcasecmp(argv[4], "tcp")) {

+ 			protocol = IPPROTO_TCP;

+ 			strcpy(proto_vec, "IPPROTO_TCP");

+ 		} else if (!strcasecmp(argv[4], "udp")) {

+ 			protocol = IPPROTO_UDP;

+ 			strcpy(proto_vec, "IPPROTO_UDP");

+ 		} else if (!strcasecmp(argv[4], "sctp")) {

+ 			protocol = IPPROTO_SCTP;

+ 			strcpy(proto_vec, "IPPROTO_SCTP");

+ 		} else if (!strcasecmp(argv[4], "icmp")) {

+ 			protocol = IPPROTO_ICMP;

+ 			strcpy(proto_vec, "IPPROTO_ICMP");

+ 		} else {

+ 			printf("%s, not support yet!\n", protocol);

+ 			return -1;

+ 		}

+ 	}

+ 

+ 	fd = socket(spoof_info->ai_family, type, protocol);

+ 	if (fd == -1) {

+ 		perror("socket");

+ 		return -1;

+ 	}

+ 

+ 	if (spoof_info->ai_family == AF_INET6) {

+ 		struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)spoof_info->ai_addr;

+ 		addr6->sin6_scope_id = 1;

+ 	}

+ 

+ 	ret = bind(fd, spoof_info->ai_addr, spoof_info->ai_addrlen);

+ 	if (ret != 0) {

+ 		printf("bind failed: [%d] - %s\n", errno, strerror(errno));

+ 		printf("===== Test Item:(%s, %s, %s) Fail ===\n", family_vec, type_vec, proto_vec);

+ 		ret = errno;

+ 	} else {

+ 		printf("===== Test Item:(%s, %s, %s) Pass ===\n", family_vec, type_vec, proto_vec);

+ 	}

+ 

+ 	free(spoof_info);

+ 	close(fd);

+ 	return ret;

+ }

+ 

tests/networking/ipv6/socket/runtest.sh
file added
+172

@@ -0,0 +1,172 @@

+ #!/bin/bash

+ 

+ # Copyright (c) 2006 Red Hat, Inc.  This copyrighted material 

+ # is made available to anyone wishing to use, modify, copy, or

+ # redistribute it subject to the terms and conditions of the GNU General

+ # Public License v.2.

+ #

+ # 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.

+ #

+ # Hangbin Liu: <haliu@redhat.com> 

+ 

+ . /usr/share/beakerlib-libraries/kernel/Library/networking-common/include.sh

+ 

+ fail=0

+ pass=0

+ 

+ myecho()

+ {

+ 	echo -e "$1" | tee -a $OUTPUTFILE

+ }

+ 

+ rlJournalStart

+ 

+ 	rlPhaseStartTest "IPv6 non local bind test"

+ setenforce 0

+ service iptables stop

+ 

+ myecho "=============== Basic Socket Interface for IPv6 TESTING ==============="

+ pushd ./func_tests

+ make >/dev/null 2>&1

+ scripts=`ls | grep -Ev "(\.c|\.h|Makefile|CVS|client|server)"`

+ for i in $scripts

+ do

+ 	OUTPUTFILE=`mktemp /tmp/tmp.XXXXXX`

+ 	myecho "\n++++++++++++++++++++ Begin Testing $i ++++++++++++++++++++\n"

+ 	./$i 2>&1 | tee -a $OUTPUTFILE

+ 	if [ "`grep BROK $OUTPUTFILE`" ] || [ -z "`grep PASS $OUTPUTFILE`" ]; then

+ 		myecho "\n:: [	 FAIL	] :: RESULT $i\n"

+ 		fail=$(($fail + 1))

+ 		rlFail $TEST/$i

+ 	else

+ 		myecho "\n:: [	 PASS	] :: RESULT $i\n"

+ 		pass=$(($pass + 1))

+ 		rlPass $TEST/$i

+ 	fi

+ 	sleep 10

+ #	rhts_submit_log -l $OUTPUTFILE

+ done

+ 

+ OUTPUTFILE=`mktemp /tmp/tmp.XXXXXX`

+ myecho "\n++++++++++++++++++++ Begin Testing Socket Functions ++++++++++++++++++++\n"	

+ ./socket_func_server 2>&1 | tee -a $OUTPUTFILE &

+ sleep 5

+ ./socket_func_client ::1 2>&1 | tee -a $OUTPUTFILE

+ if [ "`grep BROK $OUTPUTFILE`" ] || [ -z "`grep PASS $OUTPUTFILE`" ]; then

+ 	myecho "\n:: [	 FAIL	] :: RESULT $i\n"

+ 	fail=$(($fail + 1))

+ 	rlFail $TEST/$i

+ else

+ 	myecho "\n:: [	 PASS	] :: RESULT $i\n"

+ 	pass=$(($pass + 1))

+ 	rlPass $TEST/Socket_Functions

+ fi

+ 

+ make clean

+ popd

+ 

+ if [ $fail -gt 0 ];then

+ 	rlFail $TEST/all

+ else

+ 	rlPass $TEST/all

+ fi

+ 

+ 

+ spoof_part=$(($RANDOM % 1000 + 2000))

+ port=$(($RANDOM % 1000 + 6000))

+ 

+ echo "sysctl -a | grep 'net.ipv6.ip_nonlocal_bind'"

+ sysctl -a | grep 'net.ipv6.ip_nonlocal_bind'

+ if [ $? -ne 0 ]; then

+ 	echo "Not supoort net.ipv6.ip_nonlocal_bind yet!"

+ 	exit 0

+ fi

+ 

+ ping_with_nonlocal_ip()

+ {

+ 	HA="ip netns exec ha"

+ 	HB="ip netns exec hb"

+ 

+ 	netns_1_net.sh

+ 	rlRun "$HA ip -6 rule add from ::/0 iif ha_veth0 lookup 200"

+ 	rlRun "$HA ip -6 route add local 2001:0:0:1::/64 dev lo proto kernel scope host table 200"

+ 	rlRun "$HA ip -6 route add default dev ha_veth0"

+ 	rlRun "$HA sysctl -w net.ipv6.ip_nonlocal_bind=1"

+ 	rlRun "$HA ip -6 rule"

+ 	rlRun "$HA ip -6 route show table 200"

+ 	rlRun "$HA tcpdump -ni ha_veth0 ip6 -w nonlocal.pcap &"

+ 

+ 	sleep 5

+ 

+ 	rlRun "$HB ip addr add 2001:0:0:1::2/64 dev hb_veth0"

+ 	rlRun "$HB ip -6 route"

+ 

+ 	# In this test scenario, it will sent out 'echo request' packets, 

+ 	# but won't receive 'echo reply'. So expect ping6 return non-zero(1)

+ 	rlRun "$HA ping6 -I 2001:0:0:1::1 2001:0:0:1::2 -c 5" 1

+ 	rlRun "pkill tcpdump"

+ 	sleep 5

+ 	tcpdump -nnr nonlocal.pcap | grep "2001:0:0:1::1 > 2001:0:0:1::2: ICMP6, echo request"

+ 	if [ $? -eq 0 ]; then

+ 		rlPass "ping6 with non local ip"

+ 	else

+ 		rlFail "ping6 with non local ip"

+ 	fi

+ 	netns_clean.sh

+ 	#rhts_submit_log -l nonlocal.pcap

+ }

+ 

+ ping_with_nonlocal_ip

+ 	rlPhaseEnd

+ 

+ 	rlPhaseStartSetup

+ 		rlRun "gcc -o nonlocalbind nonlocal_bind/nonlocal_bind.c"

+ 	rlPhaseEnd

+ 

+ 	rlPhaseStartTest "IPv6 non local bind test"

+ 		rlRun "sysctl -w net.ipv6.ip_nonlocal_bind=0"

+ 		# expect EADDRNOTAVAIL  99

+ 		rlRun "./nonlocalbind 2016:${spoof_part}::2345 $port stream tcp" 99

+ 		rlRun "./nonlocalbind 2016:${spoof_part}::2345 $port dgram udp" 99

+ 		rlRun "./nonlocalbind 2016:${spoof_part}::2345 $port raw tcp" 99

+ 		rlRun "./nonlocalbind 2016:${spoof_part}::2345 $port raw udp" 99

+ 		rlRun "./nonlocalbind 2016:${spoof_part}::2345 $port raw sctp" 99

+ 		rlRun "./nonlocalbind 2016:${spoof_part}::2345 $port raw icmp" 99

+ 

+ 		rlRun "sysctl -w net.ipv6.ip_nonlocal_bind=1"

+ 		rlRun "./nonlocalbind 2016:${spoof_part}::2345 $port stream tcp"

+ 		rlRun "./nonlocalbind 2016:${spoof_part}::2345 $port dgram udp"

+ 		rlRun "./nonlocalbind 2016:${spoof_part}::2345 $port raw tcp"

+ 		rlRun "./nonlocalbind 2016:${spoof_part}::2345 $port raw udp"

+ 		rlRun "./nonlocalbind 2016:${spoof_part}::2345 $port raw sctp"

+ 		rlRun "./nonlocalbind 2016:${spoof_part}::2345 $port raw icmp"

+ 		# seems that not support STREAM/SEQPACKET SCTP yet

+ 		# enable sctp nonlocal bind testing, RHEL7.3 will support it.

+ 		rlRun "./nonlocalbind 2016:${spoof_part}::2345 $port seqpacket sctp"

+ 		rlRun "./nonlocalbind 2016:${spoof_part}::2345 $port stream sctp"

+ 

+ 		# bind link local ipv6 to sctp socket

+ 		rlRun "get_test_iface"

+ 		rlRun "iface_lladdr=`ip -6 addr sh $TEST_IFACE | grep fe80 | awk '{print $2}' | cut -d'/' -f1`"

+ 		rlRun "./nonlocalbind $iface_lladdr $port stream sctp"

+ 		rlRun "./nonlocalbind $iface_lladdr $port stream tcp"

+ 		rlRun "./nonlocalbind $iface_lladdr $port dgram udp"

+ 		rlRun "./nonlocalbind $iface_lladdr $port raw sctp"

+ 		rlRun "./nonlocalbind $iface_lladdr $port raw tcp"

+ 		rlRun "./nonlocalbind $iface_lladdr $port raw udp"

+ 		rlRun "./nonlocalbind $iface_lladdr $port raw icmp"

+ 	rlPhaseEnd

+ 

+ 	rlPhaseStartCleanup

+ 		rlRun "sysctl -w net.ipv6.ip_nonlocal_bind=0"

+ 		rlRun "rm -rf nonlocalbind"

+ 	rlPhaseEnd

+ rlJournalEnd

+ 

+ exit 0

tests/networking/ipv6/socket/sock_raw/icmpfilter/Makefile
file added
+83

@@ -0,0 +1,83 @@

+ # Copyright (c) 2014 Red Hat, Inc.  This copyrighted material

+ # is made available to anyone wishing to use, modify, copy, or

+ # redistribute it subject to the terms and conditions of the GNU General

+ # Public License v.2.

+ #

+ # 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.

+ #

+ # Author: Wei Chen <weichen@redhat.com>

+ 

+ # The toplevel namespace within which the test lives.

+ # FIXME: You will need to change this:

+ TOPLEVEL_NAMESPACE=kernel

+ 

+ # The name of the package under test:

+ # FIXME: you wil need to change this:

+ PACKAGE_NAME=

+ 

+ # The path of the test below the package:

+ # FIXME: you wil need to change this:

+ RELATIVE_PATH=networking/ipv6/socket/sock_raw/icmpfilter

+ 

+ # Version of the Test. Used with make tag.

+ export TESTVERSION=0.1

+ 

+ # The combined namespace of the test.

+ export TEST=/$(TOPLEVEL_NAMESPACE)/$(RELATIVE_PATH)

+ 

+ 

+ # A phony target is one that is not really the name of a file.

+ # It is just a name for some commands to be executed when you

+ # make an explicit request. There are two reasons to use a

+ # phony target: to avoid a conflict with a file of the same

+ # name, and to improve performance.

+ .PHONY: all install download clean

+ 

+ # executables to be built should be added here, they will be generated on the system under test.

+ BUILT_FILES=

+ 

+ # data files, .c files, scripts anything needed to either compile the test and/or run it.

+ FILES=$(METADATA) runtest.sh Makefile PURPOSE ipv6_icmpfilter.c

+ 

+ run: $(FILES) build

+ 	./runtest.sh

+ 

+ build: $(BUILT_FILES)

+ 	chmod a+x ./runtest.sh

+ 

+ clean:

+ 	rm -f *~ *.rpm $(BUILT_FILES)

+ 

+ # You may need to add other targets e.g. to build executables from source code

+ # Add them here:

+ 

+ 

+ # Include Common Makefile

+ include /usr/share/rhts/lib/rhts-make.include

+ 

+ # Generate the testinfo.desc here:

+ $(METADATA): Makefile

+ 	@touch $(METADATA)

+ # Change to the test owner's name

+ 	@echo "Owner:        Wei Chen <weichen@redhat.com>" > $(METADATA)

+ 	@echo "Name:         $(TEST)" >> $(METADATA)

+ 	@echo "Path:         $(TEST_DIR)"	>> $(METADATA)

+ 	@echo "License:      GPLv2" >> $(METADATA)

+ 	@echo "TestVersion:  $(TESTVERSION)"	>> $(METADATA)

+ 	@echo "Description:  cover rawv6_geticmpfilter()">> $(METADATA)

+ 	@echo "TestTime:     10m" >> $(METADATA)

+ 	@echo "Type:         Regression" >> $(METADATA)

+ 	@echo "Type:	     Singlehost" >> $(METADATA)

+ 	@echo "RunFor:       $(PACKAGE_NAME)" >> $(METADATA)

+ # add any other packages for which your test ought to run here

+ 	@echo "Requires:     $(PACKAGE_NAME)" >> $(METADATA)

+ # add any other requirements for the script to run here

+ 

+ # You may need other fields here; see the documentation

+ 	rhts-lint $(METADATA)

tests/networking/ipv6/socket/sock_raw/icmpfilter/PURPOSE
file added
+10

@@ -0,0 +1,10 @@

+ In standard sockets, the payload to be transmitted is encapsulated according to the chosen transport layer protocol (e.g. TCP, UDP).

+ In contrast, raw sockets usually receive raw packets including the header. When transmitting packets, the automatic addition of a header

+ may be a configurable option of the socket.

+ 

+ The system calls sendmsg() that are used to transmit a message to another socket. Next rawv6_sendmgs() and rawv6_send_hdrinc() are called

+ to transmit the message from sending raw socket. If IPPROTO_RAW or IP_HDRINCL option is specified in socket() or setsockopt(), user needs 

+ to construct his/her own IP and uppder layer header structures.

+ 

+ rawv6_getsockopt should be called if socket is rawv6 prot type. Operation not supported is returned if socket protocl is not equal to

+ IPPROTO_ICMPV6, otherwise rawv6_geticmpfilter() should be called.

tests/networking/ipv6/socket/sock_raw/icmpfilter/ipv6_icmpfilter.c
file added
+184

@@ -0,0 +1,184 @@

+ #include <stdio.h>

+ #include <unistd.h>

+ #include <fcntl.h>

+ #include <stdlib.h>

+ #include <string.h>

+ #include <sys/types.h>

+ #include <sys/socket.h>

+ #include <sys/ioctl.h>

+ #include <sys/syscall.h>

+ #include <netinet/in.h>

+ #include <arpa/inet.h>

+ #include <errno.h>

+ #include <netinet/in.h>

+ #include <sys/uio.h>

+ #include <linux/in6.h>

+ #include <linux/udp.h>

+ #include <linux/socket.h>

+ #include <linux/ipv6.h>

+ #include <linux/icmpv6.h>

+ #include <netdb.h>

+ 

+ #define MY_PORT_NUM 51111 /* This can be changed to suit the need and should be same in server and client */

+ #define TRUE 1

+ #define FALSE 0

+ #define __BIG_ENDIAN_BITFIELD 1

+ 

+ 

+ int main ( int argc, char *argv[] )  

+ {

+ 

+   int rawSock1, rawSock2, ret, flags, rc, on;

+   struct sockaddr_in6 servaddrs;

+   struct sockaddr_in6 servaddrc;

+   bzero( (void *)&servaddrs, sizeof(servaddrs) );