All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [RFC PATCH v4 0/3] Simplify network setup
@ 2017-04-05 20:44 Petr Vorel
  2017-04-05 20:44 ` [LTP] [RFC PATCH v4 1/3] gitignore: Prefixing filenames Petr Vorel
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Petr Vorel @ 2017-04-05 20:44 UTC (permalink / raw)
  To: ltp

Hi,

hopefully last version.
v3->v4:
* Rewritten unused network generation. It uses 10.23 resp. fd00:23 as default,
  in case of collision it's 10.x resp. fdxx:23, x is random value. BTW code in
  previous version was wrong as it had the same size as network.
* Forbidden prefixes are only 0 and 32 resp. 128, but they're rounded up by 8 resp. 16 anyway.

Comments are highly appreciated.

Kind regards,
Petr

Petr Vorel (3):
  gitignore: Prefixing filenames
  network: Add tool for setup IP variables
  network: Use tst_net_vars to set up IPv4 and IPv6 related variables

 testcases/lib/.gitignore     |  13 +-
 testcases/lib/Makefile       |   2 +-
 testcases/lib/test_net.sh    |  33 +--
 testcases/lib/tst_net_vars.c | 616 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 632 insertions(+), 32 deletions(-)
 create mode 100644 testcases/lib/tst_net_vars.c

-- 
2.12.0


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

* [LTP] [RFC PATCH v4 1/3] gitignore: Prefixing filenames
  2017-04-05 20:44 [LTP] [RFC PATCH v4 0/3] Simplify network setup Petr Vorel
@ 2017-04-05 20:44 ` Petr Vorel
  2017-04-05 20:44 ` [LTP] [RFC PATCH v4 2/3] network: Add tool for setup IP variables Petr Vorel
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 18+ messages in thread
From: Petr Vorel @ 2017-04-05 20:44 UTC (permalink / raw)
  To: ltp

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/.gitignore | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index 920817cac..522889bed 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -1,6 +1,6 @@
-tst_sleep
-tst_random
-tst_checkpoint
-tst_rod
-tst_kvcmp
-tst_device
+/tst_sleep
+/tst_random
+/tst_checkpoint
+/tst_rod
+/tst_kvcmp
+/tst_device
-- 
2.12.0


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

* [LTP] [RFC PATCH v4 2/3] network: Add tool for setup IP variables
  2017-04-05 20:44 [LTP] [RFC PATCH v4 0/3] Simplify network setup Petr Vorel
  2017-04-05 20:44 ` [LTP] [RFC PATCH v4 1/3] gitignore: Prefixing filenames Petr Vorel
@ 2017-04-05 20:44 ` Petr Vorel
  2017-04-10 10:36   ` Alexey Kodanev
  2017-04-05 20:44 ` [LTP] [RFC PATCH v4 3/3] network: Use tst_net_vars to set up IPv4 and IPv6 related variables Petr Vorel
  2017-04-06 14:42 ` [LTP] [RFC PATCH v4 0/3] Simplify network setup Alexey Kodanev
  3 siblings, 1 reply; 18+ messages in thread
From: Petr Vorel @ 2017-04-05 20:44 UTC (permalink / raw)
  To: ltp

These environment variables are defined by setup_network_variables:
IPV4_NETWORK
LHOST_IPV4_HOST
RHOST_IPV4_HOST
IPV4_NET_REV
IPV6_NETWORK
LHOST_IPV6_HOST
RHOST_IPV6_HOST
IPV6_NET_REV
LHOST_IPV6_REV
RHOST_IPV6_REV
IPV4_NET16_UNUSED
IPV6_NET32_UNUSED

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/.gitignore     |   1 +
 testcases/lib/Makefile       |   2 +-
 testcases/lib/tst_net_vars.c | 616 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 618 insertions(+), 1 deletion(-)
 create mode 100644 testcases/lib/tst_net_vars.c

diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index 522889bed..e1274df64 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -4,3 +4,4 @@
 /tst_rod
 /tst_kvcmp
 /tst_device
+/tst_net_vars
diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index 1127a59fe..49ef2ec01 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -27,6 +27,6 @@ include $(top_srcdir)/include/mk/testcases.mk
 INSTALL_TARGETS		:= *.sh
 
 MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
-			   tst_device
+			   tst_device tst_net_vars
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/lib/tst_net_vars.c b/testcases/lib/tst_net_vars.c
new file mode 100644
index 000000000..d4c91224c
--- /dev/null
+++ b/testcases/lib/tst_net_vars.c
@@ -0,0 +1,616 @@
+/*
+ * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+ * Copyright (c) 1997-2015 Red Hat, Inc. All rights reserved.
+ * Copyright (c) 2011-2013 Rich Felker, et al.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <errno.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#define FLAG_GET_NETWORK 1
+#define FLAG_GET_NETWORK_UNUSED 2
+#define FLAG_GET_HOST 4
+
+#define DEFAULT_IPV4_UNUSED_PART1 10
+#define DEFAULT_IPV6_UNUSED_PART1 0xfd
+
+#define DEFAULT_IPV4_UNUSED_PART2 23
+#define DEFAULT_IPV6_UNUSED_PART2 0x23
+
+typedef struct ltp_net_variables {
+	char *ipv4_network;
+	char *ipv4_net_rev;
+	char *lhost_ipv4_host;
+	char *rhost_ipv4_host;
+	char *ipv6_network;
+	char *ipv6_net_rev;
+	char *lhost_ipv6_host;
+	char *lhost_ipv6_rev;
+	char *rhost_ipv6_host;
+	char *rhost_ipv6_rev;
+	char *ipv4_net16_unused;
+	char *ipv6_net32_unused;
+} ltp_net_variables;
+
+static ltp_net_variables vars;
+
+/*
+ * Function inet_ntop6_impl is based on musl libc project,
+ * inet_ntop/inet_ntop.c.
+ */
+static char *inet_ntop6_impl(const unsigned char *a0, unsigned int prefix,
+	int flags)
+{
+	const unsigned char *a = a0;
+	unsigned int i, j, max, best, tmp2, border = 0;
+	char buf[100];
+	char ret[100];
+	char tmp[100];
+	char *p_ret = ret;
+	char *p_tmp = tmp;
+	size_t offset;
+
+	int isNet = !(flags & FLAG_GET_HOST);
+	int isUnused = flags & FLAG_GET_NETWORK_UNUSED;
+
+	snprintf(buf, sizeof(buf),
+		"%x:%x:%x:%x:%x:%x:%x:%x",
+		256 * a[0] + a[1], 256 * a[2] + a[3],
+		256 * a[4] + a[5], 256 * a[6] + a[7],
+		256 * a[8] + a[9], 256 * a[10] + a[11],
+		256 * a[12] + a[13], 256 * a[14] + a[15]);
+
+	for (i = 0; i < 8; i++) {
+		if (i < prefix >> 4) {
+			border += sprintf(p_tmp, "%x", 256 * a[2 * i] + a[2 * i + 1]);
+			if (i > 0)
+				border++;
+		}
+
+		if (isNet && i >= prefix >> 4)
+			break;
+
+		if (!isNet && i < prefix >> 4)
+			continue;
+
+		/* ':' only if no leading in host or ending in net */
+		if ((isNet && i > 0)
+			 || (!isNet && i > prefix >> 4))
+			*p_ret++ = ':';
+
+		tmp2 = 256 * a[2 * i] + a[2 * i + 1];
+
+		/*
+		 * For unused network we use
+		 * DEFAULT_IPV6_UNUSED_PART1:DEFAULT_IPV6_UNUSED_PART2 or
+		 * {DEFAULT_IPV6_UNUSED_PART1}XY:DEFAULT_IPV6_UNUSED_PART2, when there
+		 * is a collision with IP.
+		 */
+		if (isUnused) {
+			srand(time(NULL));
+			if (i == 0) {
+				tmp2 = 256*DEFAULT_IPV6_UNUSED_PART1;
+				if (a[0] == 0xfd && a[1] == 0)
+					tmp2 += (rand() % 128) + (a[1] < 128 ? 128 : 0);
+			} else
+				tmp2 = DEFAULT_IPV6_UNUSED_PART2;
+		}
+
+		offset = sprintf(p_ret, "%x", tmp2);
+		p_ret += offset;
+	}
+
+	*p_ret = '\0';
+
+	/* Find longest /(^0|:)[:0]{2,}/ */
+	for (i = best = 0, max = 2; buf[i]; i++) {
+		if (i && buf[i] != ':') continue;
+		j = strspn(buf + i, ":0");
+		if (j > max) best = i, max = j;
+	}
+
+	size_t length = strlen(ret);
+	size_t best_end = best + max - 1;
+
+	if (!isUnused && max > 2 && ((isNet && best < border) ||
+					(!isNet && best_end + 2 > border))) {
+		p_ret = ret;
+		/* Replace longest /(^0|:)[:0]{2,}/ with "::" */
+		if (isNet) {
+			if (best == 0 && best_end >= border) {
+				/* zeros in whole net part or continue to host */
+				ret[0] = ':';
+				ret[1] = '\0';
+			} else if (best == 0 && best_end < border) {
+				/* zeros on beginning, not whole part */
+				ret[0] = ':';
+				memmove(p_ret + 1, p_ret + best_end, border - best_end + 1);
+			} else if (best > 0 && best_end >= border) {
+				/* zeros not from beginning to border or continue to host */
+				ret[best] = ':';
+				ret[best + 1] = '\0';
+			} else {
+				/* zeros somewhere in the middle */
+				ret[best] = ':';
+				memmove(p_ret + best + 1, p_ret + best_end,
+						border - best + 1);
+			}
+		} else {
+			if (best <= border + 1 && best_end >= length + border) {
+				/* zeros in whole host part or continue to net */
+				ret[0] = '0';
+				ret[1] = '\0';
+			} else if (best <= border + 1 && best_end < length + border) {
+				if (best == border) {
+					/* zeros start in host, ends before end */
+					p_ret[0] = ':';
+					memmove(p_ret + 1, p_ret + best_end - border, length +
+							border - best_end + 2);
+				} else
+					/* zeros start in net, ends before end */
+					memmove(p_ret, p_ret + best_end - border, length +
+							border - best_end + 1);
+			} else if (best > border && best_end == border + length) {
+				/* zeros at the end */
+				ret[best - border] = ':';
+				ret[best - border + 1] = '\0';
+			} else {
+				/* zeros somewhere in the middle */
+				ret[best - border] = ':';
+				memmove(p_ret + best - border + 1, p_ret + best_end - border,
+						length + border - best_end + 1);
+			}
+		}
+	}
+
+	if (length < INET6_ADDRSTRLEN)
+		return strdup(ret);
+
+	return NULL;
+}
+
+/*
+ * Function bit_count is from ipcalc project, ipcalc.c.
+ */
+static int bit_count(uint32_t i)
+{
+	int c = 0;
+	unsigned int seen_one = 0;
+
+	while (i > 0) {
+		if (i & 1) {
+			seen_one = 1;
+			c++;
+		} else {
+			if (seen_one)
+				return -1;
+		}
+		i >>= 1;
+	}
+	return c;
+}
+
+/*
+ * Function mask2prefix is from ipcalc project, ipcalc.c.
+ */
+static int mask2prefix(struct in_addr mask)
+{
+	return bit_count(ntohl(mask.s_addr));
+}
+
+/*
+ * Function ipv4_mask_to_int is from ipcalc project, ipcalc.c.
+ */
+static int ipv4_mask_to_int(const char *prefix)
+{
+	int ret;
+	struct in_addr in;
+
+	ret = inet_pton(AF_INET, prefix, &in);
+	if (ret == 0)
+		return -1;
+
+	return mask2prefix(in);
+}
+
+/*
+ * Function safe_atoi is from ipcalc project, ipcalc.c.
+ */
+static int safe_atoi(const char *s, int *ret_i)
+{
+	char *x = NULL;
+	long l;
+
+	errno = 0;
+	l = strtol(s, &x, 0);
+
+	if (!x || x == s || *x || errno)
+		return errno > 0 ? -errno : -EINVAL;
+
+	if ((long)(int)l != l)
+		return -ERANGE;
+
+	*ret_i = (int)l;
+	return 0;
+}
+
+/*
+ * Function get_prefix use code from ipcalc project, str_to_prefix/ipcalc.c.
+ */
+static int get_prefix(const char *ipStr, int isIPv6)
+{
+	char *prefixStr = NULL;
+	int prefix, r;
+
+	prefixStr = strchr(ipStr, '/');
+	if (!prefixStr) {
+		fprintf(stderr, "Missing prefix, is that IP address? ipStr: '%s'\n",
+				ipStr);
+		exit(3);
+	}
+
+	*(prefixStr++) = '\0';
+
+	if (!isIPv6 && strchr(prefixStr, '.'))
+		prefix = ipv4_mask_to_int(prefixStr);
+	else {
+		r = safe_atoi(prefixStr, &prefix);
+		if (r != 0)
+			exit(3);
+	}
+
+	if (prefix < 0 || ((isIPv6 && prefix > 128) || (!isIPv6 && prefix > 32))) {
+		fprintf(stderr, "Bad %s prefix: %s\n", isIPv6 ? "IPv6" : "IPv4",
+				prefixStr);
+		exit(3);
+	}
+
+	if (prefix == 0 || (!isIPv6 && prefix == 32) || (isIPv6 && prefix == 128)) {
+		fprintf(stderr, "Please don't use prefix: %d for %s\n",
+				prefix, isIPv6 ? "IPv6" : "IPv4");
+		exit(3);
+	}
+
+	/* Round up prefix */
+	int basePrefix = isIPv6 ? 15 : 7;
+	prefix = (prefix + basePrefix) & ~basePrefix;
+
+	if (!isIPv6 && prefix == 32)
+		prefix = 24;
+	if (isIPv6 && prefix == 128)
+		prefix = 112;
+
+	return prefix;
+}
+
+static char *get_ipv4_host(int ip, int prefix)
+{
+	char buf[INET_ADDRSTRLEN + 1];
+	char *p_buf = buf;
+	unsigned char byte;
+
+	if (prefix < 0 || prefix > 32)
+		return NULL;
+
+	prefix &= 0x18;
+
+	for (int i = 0; i < 32; i+= 8) {
+		if (i < prefix)
+			continue;
+
+		if (i > prefix) {
+			sprintf(p_buf, ".");
+			p_buf++;
+		}
+
+		if (i == 0)
+			byte = ip & 0xff;
+		else
+			byte = (ip >> i) & 0xff;
+
+		sprintf(p_buf, "%d", byte);
+		p_buf += strlen(p_buf);
+	}
+
+	return strdup(buf);
+}
+
+static char *get_ipv4_net_rev(int ip, int prefix)
+{
+	char buf[INET_ADDRSTRLEN + 1];
+	char *p_buf = buf;
+    unsigned char byte;
+
+	if (prefix < 0 || prefix > 32)
+		return NULL;
+
+	prefix &= 0x18;
+
+	for (int i = prefix - 8; i >= 0; i-= 8) {
+
+		if (i < prefix - 8) {
+			sprintf(p_buf, ".");
+			p_buf++;
+		}
+
+		if (i == 0)
+			byte = ip & 0xff;
+		else
+			byte = (ip >> i) & 0xff;
+
+		sprintf(p_buf, "%d", byte);
+		p_buf += strlen(p_buf);
+	}
+
+	return strdup(buf);
+}
+
+static char *get_ipv4_network(int ip, int prefix, int flags)
+{
+	char buf[INET_ADDRSTRLEN + 1];
+	char *p_buf = buf;
+    unsigned char byte;
+	int isUnused = flags & FLAG_GET_NETWORK_UNUSED;
+
+	if (prefix < 0 || prefix > 32)
+		return NULL;
+
+	prefix &= 0x18;
+
+	/*
+	 * For unused network we use
+	 * DEFAULT_IPV4_UNUSED_PART1:DEFAULT_IPV4_UNUSED_PART2 or
+	 * {DEFAULT_IPV4_UNUSED_PART1}.XY, when there is a collision with IP.
+	 */
+	for (int i = 0; i < 32 && i < prefix; i+= 8) {
+		if (i == 0) {
+			byte = ip & 0xff;
+			if (isUnused)
+				byte = DEFAULT_IPV4_UNUSED_PART1;
+			sprintf(p_buf, "%d", byte);
+		} else {
+			byte = (ip >> i) & 0xff;
+			if (isUnused && i > 0) {
+				if (byte == DEFAULT_IPV4_UNUSED_PART2 &&
+					((ip >> 0) & 0xff) == DEFAULT_IPV4_UNUSED_PART1) {
+					srand(time(NULL));
+					byte = (rand() % 128) + (byte < 128 ? 128 : 0);
+				} else
+					byte = DEFAULT_IPV4_UNUSED_PART2;
+			}
+			sprintf(p_buf, ".%d", byte);
+		}
+		p_buf += strlen(p_buf);
+	}
+
+	return strdup(buf);
+}
+
+/*
+ * Function bit_count is from ipcalc project, ipcalc-reverse.c.
+ */
+static char hexchar(unsigned int val)
+{
+	if (val < 10)
+		return '0' + val;
+	if (val < 16)
+		return 'a' + val - 10;
+	abort();
+}
+
+static char *get_ipv6_net_rev(struct in6_addr *ip, unsigned prefix)
+{
+	unsigned i, j = 0;
+	char str[256];
+	unsigned max = prefix/8;
+
+	if (prefix % 4 != 0)
+		return NULL;
+
+	if (prefix % 8 == 4) {
+		str[j++] = hexchar(ip->s6_addr[(prefix + 4)/8 - 1] >> 4);
+		str[j++] = '.';
+	}
+
+	for (i = 0; i < max; i++) {
+		str[j++] = hexchar(ip->s6_addr[max - 1 - i] & 0xf);
+		str[j++] = '.';
+
+		str[j++] = hexchar(ip->s6_addr[max - 1 - i] >> 4);
+		str[j++] = '.';
+	}
+	str[--j] = '\0';
+
+	return strdup(str);
+}
+
+static char *get_ipv6_host_rev(struct in6_addr *ip, unsigned prefix)
+{
+	unsigned i, j = 0;
+	char str[256];
+
+	if (prefix % 4 != 0)
+		return NULL;
+
+	for (i = 15; i >= (prefix >> 4) * 2; i--) {
+		str[j++] = hexchar(ip->s6_addr[i] & 0xf);
+		str[j++] = '.';
+
+		str[j++] = hexchar(ip->s6_addr[i] >> 4);
+		str[j++] = '.';
+	}
+	str[--j] = '\0';
+
+	return strdup(str);
+}
+
+static int get_in_addr(const char *ipStr, struct in_addr *ip)
+{
+	if (inet_pton(AF_INET, ipStr, ip) <= 0) {
+		fprintf(stderr, "Bad IPv4 address: '%s'\n", ipStr);
+		return -1;
+	}
+	return 0;
+}
+
+static int get_ipv4_info(struct in_addr *lIp, struct in_addr *rIp, int prefix)
+{
+	vars.ipv4_network = get_ipv4_network(lIp->s_addr, prefix,
+		FLAG_GET_NETWORK);
+	if (strcmp(vars.ipv4_network, get_ipv4_network(rIp->s_addr, prefix,
+			FLAG_GET_NETWORK))) {
+		fprintf(stderr, "Please use the same network for both IP addresses\n");
+		return -1;
+	}
+
+	vars.ipv4_net_rev = get_ipv4_net_rev(lIp->s_addr, prefix);
+	vars.lhost_ipv4_host = get_ipv4_host(lIp->s_addr, prefix);
+	vars.rhost_ipv4_host = get_ipv4_host(rIp->s_addr, prefix);
+	vars.ipv4_net16_unused = get_ipv4_network(lIp->s_addr, 16,
+		FLAG_GET_NETWORK_UNUSED);
+
+	return 0;
+}
+
+static int get_in6_addr(const char *ipStr, struct in6_addr *ip6)
+{
+	if (inet_pton(AF_INET6, ipStr, ip6) <= 0) {
+		fprintf(stderr, "bad IPv6 address: '%s'\n", ipStr);
+		return -1;
+	}
+	return 0;
+}
+
+static int get_ipv6_info(struct in6_addr *lIp, struct in6_addr *rIp, int prefix)
+{
+	vars.ipv6_network = inet_ntop6_impl(lIp->s6_addr, prefix, FLAG_GET_NETWORK);
+	if (strcmp(vars.ipv6_network,
+			   inet_ntop6_impl(rIp->s6_addr, prefix, FLAG_GET_NETWORK))) {
+		fprintf(stderr, "Please use the same network for both IP addresses\n");
+		return -1;
+	}
+
+	vars.ipv6_net_rev = get_ipv6_net_rev(lIp, prefix);
+	vars.lhost_ipv6_host = inet_ntop6_impl(lIp->s6_addr, prefix, FLAG_GET_HOST);
+	vars.lhost_ipv6_rev = get_ipv6_host_rev(lIp, prefix);
+	vars.rhost_ipv6_host = inet_ntop6_impl(rIp->s6_addr, prefix, FLAG_GET_HOST);
+	vars.rhost_ipv6_rev = get_ipv6_host_rev(rIp, prefix);
+	vars.ipv6_net32_unused = inet_ntop6_impl(lIp->s6_addr, 32,
+		FLAG_GET_NETWORK_UNUSED);
+
+	return 0;
+}
+
+static void print_var(const char *name, const char *val)
+{
+	if (name && val)
+		printf("export %s='%s'\n", name, val);
+}
+static void print_vars(int isIPv6)
+{
+	if (isIPv6) {
+		print_var("IPV6_NETWORK", vars.ipv6_network);
+		print_var("IPV6_NET_REV", vars.ipv6_net_rev);
+		print_var("LHOST_IPV6_HOST", vars.lhost_ipv6_host);
+		print_var("LHOST_IPV6_REV", vars.lhost_ipv6_rev);
+		print_var("RHOST_IPV6_HOST", vars.rhost_ipv6_host);
+		print_var("RHOST_IPV6_REV", vars.rhost_ipv6_rev);
+		print_var("IPV6_NET32_UNUSED", vars.ipv6_net32_unused);
+	} else {
+		print_var("IPV4_NETWORK", vars.ipv4_network);
+		print_var("IPV4_NET_REV", vars.ipv4_net_rev);
+		print_var("LHOST_IPV4_HOST", vars.lhost_ipv4_host);
+		print_var("RHOST_IPV4_HOST", vars.rhost_ipv4_host);
+		print_var("IPV4_NET16_UNUSED", vars.ipv4_net16_unused);
+	}
+}
+
+static void usage(char *name)
+{
+	fprintf(stderr, "USAGE:\n"
+		"%s IPv4/PREFIX IPv4/PREFIX\n"
+		"%s IPv6/PREFIX IPv6/PREFIX\n\n"
+		"IP addresses must be different, within the same subnet.\n"
+		"Prefixes must be the same.\n"
+		"IPv4 prefixes must be in range <1, 31>, prefix will be round up by 8.\n"
+		"IPv6 prefixes must be <1, 127>, prefix will be round up by 16.\n",
+		name, name);
+}
+
+int main(int argc, char *argv[])
+{
+	char *lIpStr = NULL, *rIpStr = NULL;
+	struct in_addr lIp, rIp;
+	struct in6_addr lIp6, rIp6;
+	int isIPv6, lprefix, rprefix;
+	int r = 0;
+
+	int isUsage = argc > 1 && (!strcmp(argv[1], "-h") ||
+		!strcmp(argv[1], "--help"));
+	if (argc < 3 || isUsage) {
+		usage(argv[0]);
+		exit(isUsage ? 0 : 1);
+	}
+
+	lIpStr = argv[1];
+	rIpStr = argv[2];
+
+	isIPv6 = !!strchr(lIpStr, ':');
+	if (isIPv6 != !(strchr(rIpStr, ':') == NULL)) {
+		fprintf(stderr, "Mixed IPv4 and IPv6 addresses");
+		exit(2);
+	}
+
+	lprefix = get_prefix(lIpStr, isIPv6);
+	rprefix = get_prefix(rIpStr, isIPv6);
+
+	if (isIPv6) {
+		if (get_in6_addr(lIpStr, &lIp6) < 0 || get_in6_addr(rIpStr, &rIp6) < 0)
+			exit(4);
+	} else {
+		if (get_in_addr(lIpStr, &lIp) < 0 || get_in_addr(rIpStr, &rIp) < 0)
+			exit(4);
+	}
+
+	if (!strcmp(lIpStr, rIpStr)) {
+		fprintf(stderr, "IP addresses cannot be the same\n");
+		exit(5);
+	}
+
+	if (lprefix != rprefix) {
+		fprintf(stderr, "Prefixes must be the same\n");
+		exit(6);
+	}
+
+	if (isIPv6)
+		r = get_ipv6_info(&lIp6, &rIp6, lprefix);
+	else
+		r = get_ipv4_info(&lIp, &rIp, lprefix);
+
+	if (r < 0)
+		exit(7);
+
+	print_vars(isIPv6);
+
+	exit(0);
+}
-- 
2.12.0


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

* [LTP] [RFC PATCH v4 3/3] network: Use tst_net_vars to set up IPv4 and IPv6 related variables
  2017-04-05 20:44 [LTP] [RFC PATCH v4 0/3] Simplify network setup Petr Vorel
  2017-04-05 20:44 ` [LTP] [RFC PATCH v4 1/3] gitignore: Prefixing filenames Petr Vorel
  2017-04-05 20:44 ` [LTP] [RFC PATCH v4 2/3] network: Add tool for setup IP variables Petr Vorel
@ 2017-04-05 20:44 ` Petr Vorel
  2017-04-06 14:42 ` [LTP] [RFC PATCH v4 0/3] Simplify network setup Alexey Kodanev
  3 siblings, 0 replies; 18+ messages in thread
From: Petr Vorel @ 2017-04-05 20:44 UTC (permalink / raw)
  To: ltp

tst_net_vars simplifies setup as it only needs to have passed 4 IP
addresses (2 IPv4 and 2 IPv6).

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/test_net.sh | 33 ++++++++-------------------------
 1 file changed, 8 insertions(+), 25 deletions(-)

diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
index f0e05b13d..4540694c7 100644
--- a/testcases/lib/test_net.sh
+++ b/testcases/lib/test_net.sh
@@ -487,31 +487,14 @@ export PASSWD="${PASSWD:-}"
 # Don't use it in new tests, use tst_rhost_run() from test_net.sh instead.
 export LTP_RSH="${LTP_RSH:-rsh -n}"
 
-# Test Links
-# Set first three octets of the network address, default is '10.0.0'
-export IPV4_NETWORK="${IPV4_NETWORK:-10.0.0}"
-# Set local host last octet, default is '2'
-export LHOST_IPV4_HOST="${LHOST_IPV4_HOST:-2}"
-# Set remote host last octet, default is '1'
-export RHOST_IPV4_HOST="${RHOST_IPV4_HOST:-1}"
-# Set the reverse of IPV4_NETWORK
-export IPV4_NET_REV="${IPV4_NET_REV:-0.0.10}"
-# Set first three octets of the network address, default is 'fd00:1:1:1'
-export IPV6_NETWORK="${IPV6_NETWORK:-fd00:1:1:1}"
-# Set local host last octet, default is '2'
-export LHOST_IPV6_HOST="${LHOST_IPV6_HOST:-:2}"
-# Set remote host last octet, default is '1'
-export RHOST_IPV6_HOST="${RHOST_IPV6_HOST:-:1}"
-# Reverse network portion of the IPv6 address
-export IPV6_NET_REV="${IPV6_NET_REV:-1.0.0.0.1.0.0.0.1.0.0.0.0.0.d.f}"
-# Reverse host portion of the IPv6 address of the local host
-export LHOST_IPV6_REV="${LHOST_IPV6_REV:-2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0}"
-# Reverse host portion of the IPv6 address of the remote host
-export RHOST_IPV6_REV="${RHOST_IPV6_REV:-1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0}"
-
-# Networks that aren't reachable through the test links
-export IPV4_NET16_UNUSED="${IPV4_NET16_UNUSED:-10.23}"
-export IPV6_NET32_UNUSED="${IPV6_NET32_UNUSED:-fd00:23}"
+# set test links + networks that aren't reachable through the test links
+IPV4_LHOST="${IPV4_LHOST:-10.0.0.2/24}"
+IPV4_RHOST="${IPV4_RHOST:-10.0.0.1/24}"
+eval `tst_net_vars $IPV4_LHOST $IPV4_RHOST`
+
+IPV6_LHOST="${IPV6_LHOST:-fd00:1:1:1::2/64}"
+IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
+eval `tst_net_vars $IPV6_LHOST $IPV6_RHOST`
 
 export HTTP_DOWNLOAD_DIR="${HTTP_DOWNLOAD_DIR:-/var/www/html}"
 export FTP_DOWNLOAD_DIR="${FTP_DOWNLOAD_DIR:-/var/ftp}"
-- 
2.12.0


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

* [LTP] [RFC PATCH v4 0/3] Simplify network setup
  2017-04-05 20:44 [LTP] [RFC PATCH v4 0/3] Simplify network setup Petr Vorel
                   ` (2 preceding siblings ...)
  2017-04-05 20:44 ` [LTP] [RFC PATCH v4 3/3] network: Use tst_net_vars to set up IPv4 and IPv6 related variables Petr Vorel
@ 2017-04-06 14:42 ` Alexey Kodanev
  2017-04-06 15:50   ` Petr Vorel
  2017-04-14  9:12   ` Petr Vorel
  3 siblings, 2 replies; 18+ messages in thread
From: Alexey Kodanev @ 2017-04-06 14:42 UTC (permalink / raw)
  To: ltp

Hi,
On 05.04.2017 23:44, Petr Vorel wrote:
> Hi,
>
> hopefully last version.
> v3->v4:
> * Rewritten unused network generation. It uses 10.23 resp. fd00:23 as default,
>   in case of collision it's 10.x resp. fdxx:23, x is random value. BTW code in
>   previous version was wrong as it had the same size as network.
> * Forbidden prefixes are only 0 and 32 resp. 128, but they're rounded up by 8 resp. 16 anyway.

I tried to run several examples and got wrong results, e.g.

 ./tst_net_vars fd00::1/64 fd00::2/64
export IPV6_NETWORK='fd00:'
export IPV6_NET_REV='0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.f'
export LHOST_IPV6_HOST='1'
export LHOST_IPV6_REV='1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'
export RHOST_IPV6_HOST='2'
export RHOST_IPV6_REV='2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'
export IPV6_NET32_UNUSED='fdb4:23' <--- got random one

fd00:23::/32 should suffice for unused network because fd00::/64
not overlap with it.

./tst_net_vars 10.2.0.1/22 10.2.1.1/22  <--- valid configuration
Please use the same network for both IP addresses

If we look at how IPV4/6_NETWORK and LHOST_IPV4/6_HOST used
inside test_net.sh:

tst_ipaddr()
{
        local type="${1:-lhost}"
        local ipv="${TST_IPV6:-4}"
        local tst_host=

        if [ "$type" = "lhost" ]; then
                eval "tst_host=\$LHOST_IPV${ipv}_HOST"
        else
                eval "tst_host=\$RHOST_IPV${ipv}_HOST"
        fi

        if [ "$TST_IPV6" ]; then
                echo "${IPV6_NETWORK}:${tst_host}"
        else
                echo "${IPV4_NETWORK}.${tst_host}"
        fi
}

it is a simple concatenation of two variables. The only reason that
we didn't remove them is that we still have some old tests which are
using these variables in the same way.

Given that the number of such tests are really small (stress/route,
stress/multicast) and they don't source test_net.sh (only through
network.sh), may be it is time to get rid of these variables inside
test_net.sh and use just one, for reverse addresses as well?

Regarding the usage of subnet mask in IP_HOST, it should really be
optional or not used@all, only a few tests might require it:

* when configuring netns ltp_ns, default will be /24 and /64,

* grep tst_restore_ipaddr -r .
./stress/interface/if4-addr-change:     tst_restore_ipaddr
./stress/interface/if-lib.sh:   tst_restore_ipaddr || return $?
./stress/interface/if-mtu-change:       tst_restore_ipaddr
./stress/interface/if-mtu-change:       tst_restore_ipaddr rhost


Please also use checkpatch and fix any errors/warnings reported:
    total: 5 errors, 37 warnings

Got compiler errors as well:
tst_net_vars.c: In function ‘get_ipv4_host’:
tst_net_vars.c:317: error: ‘for’ loop initial declarations are only
allowed in C99 mode
tst_net_vars.c:317: note: use option -std=c99 or -std=gnu99 to compile
your code
tst_net_vars.c: In function ‘get_ipv4_net_rev’:
tst_net_vars.c:349: error: ‘for’ loop initial declarations are only
allowed in C99 mode
tst_net_vars.c: In function ‘get_ipv4_network’:
tst_net_vars.c:385: error: ‘for’ loop initial declarations are only
allowed in C99 mode

Thanks,
Alexey


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

* [LTP] [RFC PATCH v4 0/3] Simplify network setup
  2017-04-06 14:42 ` [LTP] [RFC PATCH v4 0/3] Simplify network setup Alexey Kodanev
@ 2017-04-06 15:50   ` Petr Vorel
  2017-04-07 11:04     ` Alexey Kodanev
  2017-04-14  9:12   ` Petr Vorel
  1 sibling, 1 reply; 18+ messages in thread
From: Petr Vorel @ 2017-04-06 15:50 UTC (permalink / raw)
  To: ltp

Hi Alexey,

thank you for your comments.

> I tried to run several examples and got wrong results, e.g.

>  ./tst_net_vars fd00::1/64 fd00::2/64
> export IPV6_NETWORK='fd00:'
> export IPV6_NET_REV='0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.f'
> export LHOST_IPV6_HOST='1'
> export LHOST_IPV6_REV='1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'
> export RHOST_IPV6_HOST='2'
> export RHOST_IPV6_REV='2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'
> export IPV6_NET32_UNUSED='fdb4:23' <--- got random one

> fd00:23::/32 should suffice for unused network because fd00::/64
> not overlap with it.
Ah, thanks. I didn't realized that check for overlap is meaningful for prefix 16
(IPv4) and 32 (IPv6).

> ./tst_net_vars 10.2.0.1/22 10.2.1.1/22  <--- valid configuration
> Please use the same network for both IP addresses
Sorry, wrong fix in v4, I'll fix this.

> If we look at how IPV4/6_NETWORK and LHOST_IPV4/6_HOST used
> inside test_net.sh:

> tst_ipaddr()
> {
>         local type="${1:-lhost}"
>         local ipv="${TST_IPV6:-4}"
>         local tst_host=

>         if [ "$type" = "lhost" ]; then
>                 eval "tst_host=\$LHOST_IPV${ipv}_HOST"
>         else
>                 eval "tst_host=\$RHOST_IPV${ipv}_HOST"
>         fi

>         if [ "$TST_IPV6" ]; then
>                 echo "${IPV6_NETWORK}:${tst_host}"
>         else
>                 echo "${IPV4_NETWORK}.${tst_host}"
>         fi
> }

> it is a simple concatenation of two variables. The only reason that
> we didn't remove them is that we still have some old tests which are
> using these variables in the same way.

> Given that the number of such tests are really small (stress/route,
> stress/multicast) and they don't source test_net.sh (only through
> network.sh), may be it is time to get rid of these variables inside
> test_net.sh and use just one, for reverse addresses as well?
testcases/network/stress/dns/dns-stress sources test_net.sh. I suppose we can
"fix it" by removing test_net.sh and setting necessary variables directly in
the script like other scripts do (e.g.
testcases/network/stress/route/route6-change-dst).
I agree that this would simplify things greatly (tst_net_vars.c would be much
smaller and use mainly glibc network related functions), but on the other hand I
wanted all network tests using test_net.sh. I don't like the idea that part of
the tests which are using the same variables, but their values are hardwired
into the script.
It's also confusing that you need to check whether script actually use
test_net.sh or not.


> Regarding the usage of subnet mask in IP_HOST, it should really be
> optional or not used at all, only a few tests might require it:
I use it for finding "the border" between network and host part.

> * when configuring netns ltp_ns, default will be /24 and /64,
Right, I'll make these default for tst_net_vars.c.

> * grep tst_restore_ipaddr -r .
> ./stress/interface/if4-addr-change:     tst_restore_ipaddr
> ./stress/interface/if-lib.sh:   tst_restore_ipaddr || return $?
> ./stress/interface/if-mtu-change:       tst_restore_ipaddr
> ./stress/interface/if-mtu-change:       tst_restore_ipaddr rhost

> Please also use checkpatch and fix any errors/warnings reported:
>     total: 5 errors, 37 warnings

> Got compiler errors as well:
> tst_net_vars.c: In function ‘get_ipv4_host’:
> tst_net_vars.c:317: error: ‘for’ loop initial declarations are only
> allowed in C99 mode
> tst_net_vars.c:317: note: use option -std=c99 or -std=gnu99 to compile
> your code
> tst_net_vars.c: In function ‘get_ipv4_net_rev’:
> tst_net_vars.c:349: error: ‘for’ loop initial declarations are only
> allowed in C99 mode
> tst_net_vars.c: In function ‘get_ipv4_network’:
> tst_net_vars.c:385: error: ‘for’ loop initial declarations are only
> allowed in C99 mode
Sure I will, thanks!


Kind regards,
Petr

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

* [LTP] [RFC PATCH v4 0/3] Simplify network setup
  2017-04-06 15:50   ` Petr Vorel
@ 2017-04-07 11:04     ` Alexey Kodanev
  2017-04-10 12:53       ` Petr Vorel
  0 siblings, 1 reply; 18+ messages in thread
From: Alexey Kodanev @ 2017-04-07 11:04 UTC (permalink / raw)
  To: ltp

On 06.04.2017 18:50, Petr Vorel wrote:
> ...
>> Given that the number of such tests are really small (stress/route,
>> stress/multicast) and they don't source test_net.sh (only through
>> network.sh), may be it is time to get rid of these variables inside
>> test_net.sh and use just one, for reverse addresses as well?
> testcases/network/stress/dns/dns-stress sources test_net.sh. I suppose we can
> "fix it" by removing test_net.sh and setting necessary variables directly in
> the script like other scripts do (e.g.
> testcases/network/stress/route/route6-change-dst).
> I agree that this would simplify things greatly (tst_net_vars.c would be much
> smaller and use mainly glibc network related functions), but on the other hand I
> wanted all network tests using test_net.sh. I don't like the idea that part of
> the tests which are using the same variables, but their values are hardwired
> into the script.

And if we convert them to use test_net.sh and add missing interfaces
like the ones
needed for dns-stress tests, i.e. tst_ip_reverse(), etc., there would be
no need to
use them directly in the tests.

Actually, we can still update tst_ipaddr() to use IP_HOSTs variables
without adding
together two variables :)

I guess subnet mask should be set as a separate variable, similar to
stress/multicast
tests (to support these tests), and if not provided, we can get it with
getifaddr(), or at
least set to predefined default value, for IPv6 it is almost always /64.

Thanks,
Alexey


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

* [LTP] [RFC PATCH v4 2/3] network: Add tool for setup IP variables
  2017-04-05 20:44 ` [LTP] [RFC PATCH v4 2/3] network: Add tool for setup IP variables Petr Vorel
@ 2017-04-10 10:36   ` Alexey Kodanev
  2017-04-10 13:09     ` Petr Vorel
  0 siblings, 1 reply; 18+ messages in thread
From: Alexey Kodanev @ 2017-04-10 10:36 UTC (permalink / raw)
  To: ltp

Hi,
On 04/05/2017 11:44 PM, Petr Vorel wrote:
> ...
> +static int get_ipv4_info(struct in_addr *lIp, struct in_addr *rIp, int prefix)
> +{
> +	vars.ipv4_network = get_ipv4_network(lIp->s_addr, prefix,
> +		FLAG_GET_NETWORK);
> +	if (strcmp(vars.ipv4_network, get_ipv4_network(rIp->s_addr, prefix,
> +			FLAG_GET_NETWORK))) {
> +		fprintf(stderr, "Please use the same network for both IP addresses\n");
> +		return -1;

Thinking more about this, we shouldn't put such restrictions on
network configuration as well. There could be more complex setup
involving routers, NAT, etc.

Thanks,
Alexey


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

* [LTP] [RFC PATCH v4 0/3] Simplify network setup
  2017-04-07 11:04     ` Alexey Kodanev
@ 2017-04-10 12:53       ` Petr Vorel
  2017-04-10 17:49         ` Alexey Kodanev
  0 siblings, 1 reply; 18+ messages in thread
From: Petr Vorel @ 2017-04-10 12:53 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> On 06.04.2017 18:50, Petr Vorel wrote:
> > ...
> >> Given that the number of such tests are really small (stress/route,
> >> stress/multicast) and they don't source test_net.sh (only through
> >> network.sh), may be it is time to get rid of these variables inside
> >> test_net.sh and use just one, for reverse addresses as well?
> > testcases/network/stress/dns/dns-stress sources test_net.sh. I suppose we can
> > "fix it" by removing test_net.sh and setting necessary variables directly in
> > the script like other scripts do (e.g.
> > testcases/network/stress/route/route6-change-dst).
> > I agree that this would simplify things greatly (tst_net_vars.c would be much
> > smaller and use mainly glibc network related functions), but on the other hand I
> > wanted all network tests using test_net.sh. I don't like the idea that part of
> > the tests which are using the same variables, but their values are hardwired
> > into the script.

> And if we convert them to use test_net.sh and add missing interfaces
> like the ones
> needed for dns-stress tests, i.e. tst_ip_reverse(), etc., there would be
> no need to
> use them directly in the tests.

> Actually, we can still update tst_ipaddr() to use IP_HOSTs variables
> without adding
> together two variables :)

IMHO it's not about what is in tst_ipaddr(), but that we need IPV{4,6}_NETWORK and
IPV{4,6}_NET_REV variables in some scripts:

* testcases/network/stress/dns/dns-stress (which already sources test_net.sh) needs
IPV{4,6}_NETWORK and IPV{4,6}_NET_REV variables. This is the only test which uses all
of these variables.
	if [ "$TST_IPV6" ]; then
		record="AAAA"
		net="$IPV6_NETWORK"
		net_rev="$IPV6_NET_REV"
	else
		record="A"
		net="$IPV4_NETWORK"
		net_rev="$IPV4_NET_REV"
	fi
...
	zone "$net_rev.$ip_zone_opt.arpa" {
		type master;
		file "ltp-ns.rev";
	};

* testcases/network/stress/ns-tools/set_ipv4addr requires IPV4_NETWORK (called here as
network_part). This script is used by 29 tests.

netmask=`echo $network_part | sed "s/[[:digit:]]*/255/g"`.`echo $host_part | sed "s/[[:digit:]]*/0/g"`
broadcast=${network_part}.`echo $host_part | sed "s/[[:digit:]]*/255/g"`

Given this info, I'd keep IPV{4,6}_NETWORK and IPV{4,6}_NET_REV variables and fix
tst_net_vars.c according to your requirements.
But I agree it's better to use IP_HOSTs variables where possible (at least in
tst_ipaddr()). But it's up to you to decide. Or do you see any solution which allows us to
drop these variables?

> I guess subnet mask should be set as a separate variable, similar to
> stress/multicast
> tests (to support these tests),
I agree. Something like IPV6_NETWORK_MASK=64

> and if not provided, we can get it with getifaddr(), or at least set to predefined
> default value, for IPv6 it is almost always /64.
Ok if not set directly in IP_HOST variables I'd do try to get it with getifaddr() and if
it fail for any reason I'd use default (64 for IPv6 and 24 for IPv4).


Kind regards,
Petr

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

* [LTP] [RFC PATCH v4 2/3] network: Add tool for setup IP variables
  2017-04-10 10:36   ` Alexey Kodanev
@ 2017-04-10 13:09     ` Petr Vorel
  0 siblings, 0 replies; 18+ messages in thread
From: Petr Vorel @ 2017-04-10 13:09 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> On 04/05/2017 11:44 PM, Petr Vorel wrote:
> > ...
> > +static int get_ipv4_info(struct in_addr *lIp, struct in_addr *rIp, int prefix)
> > +{
> > +	vars.ipv4_network = get_ipv4_network(lIp->s_addr, prefix,
> > +		FLAG_GET_NETWORK);
> > +	if (strcmp(vars.ipv4_network, get_ipv4_network(rIp->s_addr, prefix,
> > +			FLAG_GET_NETWORK))) {
> > +		fprintf(stderr, "Please use the same network for both IP addresses\n");
> > +		return -1;

> Thinking more about this, we shouldn't put such restrictions on
> network configuration as well. There could be more complex setup
> involving routers, NAT, etc.
Well, if we want to keep IPV{4,6}_NETWORK and
IPV{4,6}_NET_REV variables (see my reply today [1]), we'd have to somehow solve scenarios
with completely different addresses which have nothing in common (e.g. 10.2.0.1/22
10.2.1.1/22 => IPV4_NETWORK=10.2 - that's ok, but 10.2.0.1/24 and 192.168.1.2/24 will lead
to empty IPV4_NETWORK).
I'd try to avoid using {L,R}HOST_IPV{4,6}_NETWORK.

[1] http://lists.linux.it/pipermail/ltp/2017-April/004268.html


Kind regards,
Petr


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

* [LTP] [RFC PATCH v4 0/3] Simplify network setup
  2017-04-10 12:53       ` Petr Vorel
@ 2017-04-10 17:49         ` Alexey Kodanev
  2017-04-11  8:50           ` Alexey Kodanev
  2017-04-18 16:34           ` Petr Vorel
  0 siblings, 2 replies; 18+ messages in thread
From: Alexey Kodanev @ 2017-04-10 17:49 UTC (permalink / raw)
  To: ltp


On 04/10/2017 03:53 PM, Petr Vorel wrote:
> ...
> IMHO it's not about what is in tst_ipaddr(), but that we need IPV{4,6}_NETWORK and
> IPV{4,6}_NET_REV variables in some scripts:
>
> * testcases/network/stress/dns/dns-stress (which already sources test_net.sh) needs
> IPV{4,6}_NETWORK and IPV{4,6}_NET_REV variables. This is the only test which uses all
> of these variables.
> 	if [ "$TST_IPV6" ]; then
> 		record="AAAA"
> 		net="$IPV6_NETWORK"
> 		net_rev="$IPV6_NET_REV"
> 	else
> 		record="A"
> 		net="$IPV4_NETWORK"
> 		net_rev="$IPV4_NET_REV"
> 	fi
> ...
> 	zone "$net_rev.$ip_zone_opt.arpa" {
> 		type master;
> 		file "ltp-ns.rev";
> 	};


Looking at this test, there is no need to use IP4|6_NETWORK vars
and *_L|RHOST_. We could just use "unused network" variables there.
I'll prepare the patch... but still we need to get a reverse net,
though these variables more or less static.

If we want to automate it, may be create reverse IP program as
a separate tool in LTP so it can be invoked inside tests, like
dns-stress?

Thanks,
Alexey


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

* [LTP] [RFC PATCH v4 0/3] Simplify network setup
  2017-04-10 17:49         ` Alexey Kodanev
@ 2017-04-11  8:50           ` Alexey Kodanev
  2017-04-13  9:33             ` Petr Vorel
  2017-04-18 16:34           ` Petr Vorel
  1 sibling, 1 reply; 18+ messages in thread
From: Alexey Kodanev @ 2017-04-11  8:50 UTC (permalink / raw)
  To: ltp

On 10.04.2017 20:49, Alexey Kodanev wrote:
> On 04/10/2017 03:53 PM, Petr Vorel wrote:
>> ...
>> IMHO it's not about what is in tst_ipaddr(), but that we need IPV{4,6}_NETWORK and
>> IPV{4,6}_NET_REV variables in some scripts:
>>
>> * testcases/network/stress/dns/dns-stress (which already sources test_net.sh) needs
>> IPV{4,6}_NETWORK and IPV{4,6}_NET_REV variables. This is the only test which uses all
>> of these variables.
>> 	if [ "$TST_IPV6" ]; then
>> 		record="AAAA"
>> 		net="$IPV6_NETWORK"
>> 		net_rev="$IPV6_NET_REV"
>> 	else
>> 		record="A"
>> 		net="$IPV4_NETWORK"
>> 		net_rev="$IPV4_NET_REV"
>> 	fi
>> ...
>> 	zone "$net_rev.$ip_zone_opt.arpa" {
>> 		type master;
>> 		file "ltp-ns.rev";
>> 	};
>
> Looking at this test, there is no need to use IP4|6_NETWORK vars
> and *_L|RHOST_. We could just use "unused network" variables there.
> I'll prepare the patch... but still we need to get a reverse net,
> though these variables more or less static.

Sent 'dns-stress' patch-set, with it the test is only using
tst_ipaddr(), other vars defined inside setup().

Thanks,
Alexey


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

* [LTP] [RFC PATCH v4 0/3] Simplify network setup
  2017-04-11  8:50           ` Alexey Kodanev
@ 2017-04-13  9:33             ` Petr Vorel
  0 siblings, 0 replies; 18+ messages in thread
From: Petr Vorel @ 2017-04-13  9:33 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> Sent 'dns-stress' patch-set, with it the test is only using
> tst_ipaddr(), other vars defined inside setup().
Great, thanks. I'll remove now unnecessary code and fix the other issues.


Kind regards,
Petr

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

* [LTP] [RFC PATCH v4 0/3] Simplify network setup
  2017-04-06 14:42 ` [LTP] [RFC PATCH v4 0/3] Simplify network setup Alexey Kodanev
  2017-04-06 15:50   ` Petr Vorel
@ 2017-04-14  9:12   ` Petr Vorel
  2017-04-14  9:17     ` Petr Vorel
  1 sibling, 1 reply; 18+ messages in thread
From: Petr Vorel @ 2017-04-14  9:12 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> Please also use checkpatch and fix any errors/warnings reported:
>     total: 5 errors, 37 warnings
I fixed all errors but "line over 80 characters".
How does checkpatch.pl [1] counts line length As I get many "line over 80
characters", but my Vim shows that line is less than 80 chars.

> Got compiler errors as well:
> tst_net_vars.c: In function ‘get_ipv4_host’:
> tst_net_vars.c:317: error: ‘for’ loop initial declarations are only
> allowed in C99 mode
> tst_net_vars.c:317: note: use option -std=c99 or -std=gnu99 to compile
> your code
> tst_net_vars.c: In function ‘get_ipv4_net_rev’:
> tst_net_vars.c:349: error: ‘for’ loop initial declarations are only
> allowed in C99 mode
> tst_net_vars.c: In function ‘get_ipv4_network’:
> tst_net_vars.c:385: error: ‘for’ loop initial declarations are only
> allowed in C99 mode

Silly question, but how did you compile to get this error? I don't get them
$ i=testcases/lib/tst_net_vars; rm -fv $i; ma -C `dirname $i`

Thanks!
Petr

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/scripts/checkpatch.pl

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

* [LTP] [RFC PATCH v4 0/3] Simplify network setup
  2017-04-14  9:12   ` Petr Vorel
@ 2017-04-14  9:17     ` Petr Vorel
  2017-04-14  9:44       ` Alexey Kodanev
  0 siblings, 1 reply; 18+ messages in thread
From: Petr Vorel @ 2017-04-14  9:17 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> Silly question, but how did you compile to get this error? I don't get them
> $ i=testcases/lib/tst_net_vars; rm -fv $i; ma -C `dirname $i`

Sorry, I mean this:
$ i=testcases/lib/tst_net_vars; rm -fv $i; make -j$(getconf _NPROCESSORS_ONLN) -C `dirname $i`
removed 'testcases/lib/tst_net_vars'
make: Entering directory '/home/pevik/install/src/ltp.git/testcases/lib'
make -C "/home/pevik/install/src/ltp.git/lib" -f "/home/pevik/install/src/ltp.git/lib/Makefile" all
make[1]: Entering directory '/home/pevik/install/src/ltp.git/lib'
make[2]: Entering directory '/home/pevik/install/src/ltp.git/lib/newlib_tests'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/pevik/install/src/ltp.git/lib/newlib_tests'
make[2]: Entering directory '/home/pevik/install/src/ltp.git/lib/tests'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/pevik/install/src/ltp.git/lib/tests'
make[1]: Leaving directory '/home/pevik/install/src/ltp.git/lib'
gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/home/pevik/install/src/ltp.git/testcases/kernel/include -I../../include -I../../include -I../../include/old/   -L../../lib  tst_net_vars.c   -lltp -o tst_net_vars
make: Leaving directory '/home/pevik/install/src/ltp.git/testcases/lib'


Thanks!
Petr

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

* [LTP] [RFC PATCH v4 0/3] Simplify network setup
  2017-04-14  9:17     ` Petr Vorel
@ 2017-04-14  9:44       ` Alexey Kodanev
  2017-04-14 12:16         ` Petr Vorel
  0 siblings, 1 reply; 18+ messages in thread
From: Alexey Kodanev @ 2017-04-14  9:44 UTC (permalink / raw)
  To: ltp

On 14.04.2017 12:17, Petr Vorel wrote:
> Hi Alexey,
>
>> Silly question, but how did you compile to get this error? I don't get them
>> $ i=testcases/lib/tst_net_vars; rm -fv $i; ma -C `dirname $i`
> Sorry, I mean this:
> $ i=testcases/lib/tst_net_vars; rm -fv $i; make -j$(getconf _NPROCESSORS_ONLN) -C `dirname $i`
> removed 'testcases/lib/tst_net_vars'
> make: Entering directory '/home/pevik/install/src/ltp.git/testcases/lib'
> make -C "/home/pevik/install/src/ltp.git/lib" -f "/home/pevik/install/src/ltp.git/lib/Makefile" all
> make[1]: Entering directory '/home/pevik/install/src/ltp.git/lib'
> make[2]: Entering directory '/home/pevik/install/src/ltp.git/lib/newlib_tests'
> make[2]: Nothing to be done for 'all'.
> make[2]: Leaving directory '/home/pevik/install/src/ltp.git/lib/newlib_tests'
> make[2]: Entering directory '/home/pevik/install/src/ltp.git/lib/tests'
> make[2]: Nothing to be done for 'all'.
> make[2]: Leaving directory '/home/pevik/install/src/ltp.git/lib/tests'
> make[1]: Leaving directory '/home/pevik/install/src/ltp.git/lib'
> gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I/home/pevik/install/src/ltp.git/testcases/kernel/include -I../../include -I../../include -I../../include/old/   -L../../lib  tst_net_vars.c   -lltp -o tst_net_vars
> make: Leaving directory '/home/pevik/install/src/ltp.git/testcases/lib'

Used default options for gcc in OL6, I guess in my case it has --std=gnu89
by default and you have something different, may be gnu99...

Thanks,
Alexey


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

* [LTP] [RFC PATCH v4 0/3] Simplify network setup
  2017-04-14  9:44       ` Alexey Kodanev
@ 2017-04-14 12:16         ` Petr Vorel
  0 siblings, 0 replies; 18+ messages in thread
From: Petr Vorel @ 2017-04-14 12:16 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> Used default options for gcc in OL6, I guess in my case it has --std=gnu89
> by default and you have something different, may be gnu99...
Right! Wouldn't it be better to have it explicitly set as default in
include/mk/config.mk.default? I'm going to send RFC patch about it.


Kind regards,
Petr

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

* [LTP] [RFC PATCH v4 0/3] Simplify network setup
  2017-04-10 17:49         ` Alexey Kodanev
  2017-04-11  8:50           ` Alexey Kodanev
@ 2017-04-18 16:34           ` Petr Vorel
  1 sibling, 0 replies; 18+ messages in thread
From: Petr Vorel @ 2017-04-18 16:34 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> If we want to automate it, may be create reverse IP program as
> a separate tool in LTP so it can be invoked inside tests, like
> dns-stress?
Good idea. I'll prepare this patch after I finish tst_net_vars.


Kind regards,
Petr

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

end of thread, other threads:[~2017-04-18 16:34 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-05 20:44 [LTP] [RFC PATCH v4 0/3] Simplify network setup Petr Vorel
2017-04-05 20:44 ` [LTP] [RFC PATCH v4 1/3] gitignore: Prefixing filenames Petr Vorel
2017-04-05 20:44 ` [LTP] [RFC PATCH v4 2/3] network: Add tool for setup IP variables Petr Vorel
2017-04-10 10:36   ` Alexey Kodanev
2017-04-10 13:09     ` Petr Vorel
2017-04-05 20:44 ` [LTP] [RFC PATCH v4 3/3] network: Use tst_net_vars to set up IPv4 and IPv6 related variables Petr Vorel
2017-04-06 14:42 ` [LTP] [RFC PATCH v4 0/3] Simplify network setup Alexey Kodanev
2017-04-06 15:50   ` Petr Vorel
2017-04-07 11:04     ` Alexey Kodanev
2017-04-10 12:53       ` Petr Vorel
2017-04-10 17:49         ` Alexey Kodanev
2017-04-11  8:50           ` Alexey Kodanev
2017-04-13  9:33             ` Petr Vorel
2017-04-18 16:34           ` Petr Vorel
2017-04-14  9:12   ` Petr Vorel
2017-04-14  9:17     ` Petr Vorel
2017-04-14  9:44       ` Alexey Kodanev
2017-04-14 12:16         ` Petr Vorel

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.