diff options
author | Vincent Gross <vgross@cvs.openbsd.org> | 2016-09-05 10:15:25 +0000 |
---|---|---|
committer | Vincent Gross <vgross@cvs.openbsd.org> | 2016-09-05 10:15:25 +0000 |
commit | b6b17665304af4e913f6551a0997e0c117382ccc (patch) | |
tree | 5b13cf776234d089610bd4523e50f2010b7fa7f8 /regress/sys | |
parent | 938ab1f8d7d0a20adbaebd080965aa70379c9b45 (diff) |
Big refactoring in main(), simplify the invocation syntax.
Diffstat (limited to 'regress/sys')
-rw-r--r-- | regress/sys/netinet/in_pcbbind/Makefile | 10 | ||||
-rw-r--r-- | regress/sys/netinet/in_pcbbind/runtest.c | 158 |
2 files changed, 86 insertions, 82 deletions
diff --git a/regress/sys/netinet/in_pcbbind/Makefile b/regress/sys/netinet/in_pcbbind/Makefile index 457fb6278cc..cb35b6cdb7c 100644 --- a/regress/sys/netinet/in_pcbbind/Makefile +++ b/regress/sys/netinet/in_pcbbind/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.4 2016/09/03 15:59:28 vgross Exp $ +# $OpenBSD: Makefile,v 1.5 2016/09/05 10:15:24 vgross Exp $ PROG = runtest PORT = 23000 @@ -6,15 +6,15 @@ IFADDR != route -n show -inet | awk '$$8 !~ "lo0" && $$3 ~ /U.*l/ { print $$1; e IF6ADDR != route -n show -inet6 | awk '$$8 !~ "lo0" && $$3 ~ /U.*l/ && $$1 !~ /^fe80/ { print $$1; exit }' run-regress-runtest4: ${PROG} - ${.OBJDIR}/${PROG} unicast ${PORT} ${IFADDR} - ${.OBJDIR}/${PROG} mcast ${PORT} 224.1.1.2 ${IFADDR} + ${.OBJDIR}/${PROG} ${IFADDR} ${PORT} + ${.OBJDIR}/${PROG} 224.0.2.1 ${PORT} ${IFADDR} REGRESS_TARGETS += run-regress-runtest4 .if ! empty(IF6ADDR) run-regress-runtest6: ${PROG} - ${.OBJDIR}/${PROG} unicast ${PORT} ${IF6ADDR} - ${SUDO} ${.OBJDIR}/${PROG} mcast ${PORT} ff1e::123 ${IF6ADDR} + ${.OBJDIR}/${PROG} ${IF6ADDR} ${PORT} + ${SUDO} ${.OBJDIR}/${PROG} ff1e::123 ${PORT} ${IF6ADDR} REGRESS_TARGETS += run-regress-runtest6 .endif diff --git a/regress/sys/netinet/in_pcbbind/runtest.c b/regress/sys/netinet/in_pcbbind/runtest.c index 2bccdb04c75..5baba0cb5de 100644 --- a/regress/sys/netinet/in_pcbbind/runtest.c +++ b/regress/sys/netinet/in_pcbbind/runtest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: runtest.c,v 1.3 2015/12/22 13:23:24 vgross Exp $ */ +/* $OpenBSD: runtest.c,v 1.4 2016/09/05 10:15:24 vgross Exp $ */ /* * Copyright (c) 2015 Vincent Gross <vincent.gross@kilob.yt> * @@ -344,7 +344,8 @@ int main(int argc, char *argv[]) { int error, rc; - struct addrinfo hints, *local, *any, *mifa; + char *baddr_s, *bport_s, *bmifa_s; + struct addrinfo hints, *baddr, *any, *mifa; struct ifaddrs *ifap, *curifa; struct ip_mreq local_imr, any_imr; struct ipv6_mreq local_i6mr, any_i6mr; @@ -357,91 +358,94 @@ main(int argc, char *argv[]) AI_PASSIVE; hints.ai_socktype = SOCK_DGRAM; - if (strcmp(argv[1],"unicast") == 0) { - if ((error = getaddrinfo(argv[3], argv[2], &hints, &local))) - errx(2, "getaddrinfo(%s,%s): %s", argv[3], argv[2], - gai_strerror(error)); - local->ai_canonname = argv[3]; + baddr_s = argv[1]; + bport_s = argv[2]; + + if ((error = getaddrinfo(baddr_s, bport_s, &hints, &baddr))) + errx(2, "getaddrinfo(%s,%s): %s", baddr_s, bport_s, + gai_strerror(error)); + baddr->ai_canonname = baddr_s; + + hints.ai_family = baddr->ai_family; + if ((error = getaddrinfo(NULL, bport_s, &hints, &any))) + errx(2, "getaddrinfo(NULL,%s): %s", bport_s, + gai_strerror(error)); + any->ai_canonname = "*"; + + switch (baddr->ai_family) { + case AF_INET: + sin = (struct sockaddr_in *)baddr->ai_addr; + if (!IN_MULTICAST( ntohl(sin->sin_addr.s_addr) )) { + puts("executing unicast testsuite"); + return unicast_testsuite(baddr, any); + } + bmifa_s = argv[3]; + hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICHOST; - hints.ai_family = local->ai_family; - if ((error = getaddrinfo(NULL, argv[2], &hints, &any))) - errx(2, "getaddrinfo(NULL,%s): %s", argv[2], + if ((error = getaddrinfo(bmifa_s, NULL, &hints, &mifa))) + errx(2, "getaddrinfo(%s,NULL): %s", bmifa_s, gai_strerror(error)); - any->ai_canonname = "ANY"; - - return unicast_testsuite(local, any); - } + local_imr.imr_interface = + ((struct sockaddr_in *)mifa->ai_addr)->sin_addr; + local_imr.imr_multiaddr = + ((struct sockaddr_in *)baddr->ai_addr)->sin_addr; - if (strcmp(argv[1], "mcast") == 0) { - if ((error = getaddrinfo(argv[3], argv[2], &hints, &local))) - errx(2, "getaddrinfo(%s,%s): %s", argv[3], argv[2], - gai_strerror(error)); - local->ai_canonname = argv[3]; - - hints.ai_family = local->ai_family; - if ((error = getaddrinfo(NULL, argv[2], &hints, &any))) - errx(2, "getaddrinfo(NULL,%s): %s", argv[2], - gai_strerror(error)); - any->ai_canonname = "ANY"; + puts("executing ipv4 multicast testsuite"); + /* no 'any' mcast group in ipv4 */ + return mcast_reuse_testsuite(baddr, &local_imr); + case AF_INET6: + sin6 = (struct sockaddr_in6 *)baddr->ai_addr; + if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) { + puts("executing unicast testsuite"); + return unicast_testsuite(baddr, any); + } + bmifa_s = argv[3]; hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICHOST; - if ((error = getaddrinfo(argv[4], NULL, &hints, &mifa))) - errx(2, "getaddrinfo(%s,NULL): %s", argv[4], - gai_strerror(error)); + if ((error = getaddrinfo(bmifa_s, NULL, &hints, &mifa))) + errx(2, "getaddrinfo(%s,NULL): %s", bmifa_s, + gai_strerror(error)); - switch (hints.ai_family) { - case AF_INET: - sin = (struct sockaddr_in *)(mifa->ai_addr); - local_imr.imr_interface = sin->sin_addr; - sin = (struct sockaddr_in *)(local->ai_addr); - local_imr.imr_multiaddr = sin->sin_addr; - - /* no 'any' mcast group in ipv4 */ - return mcast_reuse_testsuite(local, &local_imr); - - case AF_INET6: - if (getifaddrs(&ifap)) - err(2, "getifaddrs()"); - curifa = ifap; - while (curifa) { - if (memcmp(curifa->ifa_addr, - mifa->ai_addr, - mifa->ai_addrlen) == 0) - break; - curifa = curifa->ifa_next; - } - if (curifa == NULL) - errx(2, "no interface configured with %s", argv[4]); - local_i6mr.ipv6mr_interface = - if_nametoindex(curifa->ifa_name); - if (local_i6mr.ipv6mr_interface == 0) - errx(2, "unable to get \"%s\" index", - curifa->ifa_name); - freeifaddrs(ifap); - - sin6 = (struct sockaddr_in6 *)(local->ai_addr); - local_i6mr.ipv6mr_multiaddr = sin6->sin6_addr; - - any_i6mr.ipv6mr_interface = local_i6mr.ipv6mr_interface; - sin6 = (struct sockaddr_in6 *)(any->ai_addr); - any_i6mr.ipv6mr_multiaddr = sin6->sin6_addr; - - rc = 0; - rc |= mcast_reuse_testsuite(local, &local_i6mr); - if (geteuid() == 0) - rc |= mcast6_testsuite(local, &local_i6mr, any, &any_i6mr); - else - warnx("skipping mcast6_testsuite() due to insufficient privs, please run again as root"); - return (rc); - - default: - errx(2, "no multicast test suite for af %d", hints.ai_family); + if (getifaddrs(&ifap)) + err(2, "getifaddrs()"); + curifa = ifap; + while (curifa) { + if (memcmp(curifa->ifa_addr, + mifa->ai_addr, + mifa->ai_addrlen) == 0) + break; + curifa = curifa->ifa_next; } - + if (curifa == NULL) + errx(2, "no interface configured with %s", argv[4]); + local_i6mr.ipv6mr_interface = + if_nametoindex(curifa->ifa_name); + if (local_i6mr.ipv6mr_interface == 0) + errx(2, "unable to get \"%s\" index", + curifa->ifa_name); + freeifaddrs(ifap); + + local_i6mr.ipv6mr_multiaddr = + ((struct sockaddr_in6 *)baddr->ai_addr)->sin6_addr; + + any_i6mr.ipv6mr_interface = local_i6mr.ipv6mr_interface; + any_i6mr.ipv6mr_multiaddr = + ((struct sockaddr_in6 *)any->ai_addr)->sin6_addr; + + puts("executing ipv6 multicast testsuite"); + + rc = 0; + rc |= mcast_reuse_testsuite(baddr, &local_i6mr); + if (geteuid() == 0) + rc |= mcast6_testsuite(baddr, &local_i6mr, any, &any_i6mr); + else + warnx("skipping mcast6_testsuite() due to insufficient privs, please run again as root"); + return (rc); + default: + errx(2,"unknown AF"); } - return (2); } |