diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 2953b2a..391cecc 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -114,6 +114,9 @@ * Fixed src_mac command to set source mac of packet to value specified in * command by Adit Ranadive * + * Added support for increasing src / dst ip by values larger than one (1) when + * doing src or dst min/max by Kristian Larsson + * */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt @@ -288,6 +291,10 @@ struct pktgen_dev { char src_min[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ char src_max[IP_NAME_SZ]; /* IP, ie 1.2.3.4 */ + unsigned long long dst_step; + unsigned long long src_step; /* Step up (ie increase) IP src / dst by this + much. 1 by default. */ + struct in6_addr in6_saddr; struct in6_addr in6_daddr; struct in6_addr cur_in6_daddr; @@ -572,11 +579,11 @@ static int pktgen_if_show(struct seq_file *seq, void *v) } else { seq_printf(seq, - " dst_min: %s dst_max: %s\n", - pkt_dev->dst_min, pkt_dev->dst_max); + " dst_min: %s dst_max: %s dst_step: %llu\n", + pkt_dev->dst_min, pkt_dev->dst_max, pkt_dev->dst_step); seq_printf(seq, - " src_min: %s src_max: %s\n", - pkt_dev->src_min, pkt_dev->src_max); + " src_min: %s src_max: %s src_step: %llu\n", + pkt_dev->src_min, pkt_dev->src_max, pkt_dev->src_step); } seq_puts(seq, " src_mac: "); @@ -1359,6 +1366,21 @@ static ssize_t pktgen_if_write(struct file *file, sprintf(pg_result, "OK: dst6_max=%s", buf); return count; } + if (!strcmp(name, "dst_step")) { + len = num_arg(&user_buffer[i], 10, &value); + if (len < 0) + return len; + + i += len; + if (!value) + return len; + pkt_dev->dst_step = value; + if (debug) + pr_info("pktgen: dst_step set to: %llu\n", pkt_dev->dst_step); + + sprintf(pg_result, "OK: dst_step=%llu", pkt_dev->dst_step); + return count; + } if (!strcmp(name, "src6")) { len = strn_len(&user_buffer[i], sizeof(buf) - 1); if (len < 0) @@ -1424,6 +1446,21 @@ static ssize_t pktgen_if_write(struct file *file, sprintf(pg_result, "OK: src_max=%s", pkt_dev->src_max); return count; } + if (!strcmp(name, "src_step")) { + len = num_arg(&user_buffer[i], 10, &value); + if (len < 0) + return len; + + i += len; + if (!value) + return len; + pkt_dev->src_step = value; + if (debug) + pr_info("pktgen: src_step set to: %llu\n", pkt_dev->src_step); + + sprintf(pg_result, "OK: src_step=%llu", pkt_dev->src_step); + return count; + } if (!strcmp(name, "dst_mac")) { char *v = valstr; unsigned char old_dmac[ETH_ALEN]; @@ -2160,8 +2197,17 @@ static void pktgen_setup_inject(struct pktgen_dev *pkt_dev) /* Initialize current values. */ pkt_dev->cur_dst_mac_offset = 0; pkt_dev->cur_src_mac_offset = 0; - pkt_dev->cur_saddr = pkt_dev->saddr_min; - pkt_dev->cur_daddr = pkt_dev->daddr_min; + + /* + * Setting init value of current src / dst addr to max value seems + * backwards, but it's not, it is increased for every run, including + * the first one and so setting it to min value means we never actually + * use the min value as it will be increased before we send the first + * packet. Max on the other hand means we wrap on first run and thus + * send first packet with min value. + */ + pkt_dev->cur_saddr = pkt_dev->saddr_max; + pkt_dev->cur_daddr = pkt_dev->daddr_max; pkt_dev->cur_udp_dst = pkt_dev->udp_dst_min; pkt_dev->cur_udp_src = pkt_dev->udp_src_min; pkt_dev->nflows = 0; @@ -2414,7 +2460,7 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) t = random32() % (imx - imn) + imn; else { t = ntohl(pkt_dev->cur_saddr); - t++; + t += pkt_dev->src_step; if (t > imx) t = imn; @@ -2446,7 +2492,7 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev) pkt_dev->cur_daddr = s; } else { t = ntohl(pkt_dev->cur_daddr); - t++; + t += pkt_dev->dst_step; if (t > imx) { t = imn; } @@ -3752,6 +3798,8 @@ static int pktgen_add_device(struct pktgen_thread *t, const char *ifname) pkt_dev->udp_src_max = 9; pkt_dev->udp_dst_min = 9; pkt_dev->udp_dst_max = 9; + pkt_dev->dst_step = 1; + pkt_dev->src_step = 1; pkt_dev->vlan_p = 0; pkt_dev->vlan_cfi = 0;