| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Authors: |
|---|
| 3 | 4 | * Copyright 2001, 2002 by Robert Olsson <robert.olsson@its.uu.se> |
|---|
| .. | .. |
|---|
| 7 | 8 | * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> |
|---|
| 8 | 9 | * Ben Greear <greearb@candelatech.com> |
|---|
| 9 | 10 | * Jens Låås <jens.laas@data.slu.se> |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is free software; you can redistribute it and/or |
|---|
| 12 | | - * modify it under the terms of the GNU General Public License |
|---|
| 13 | | - * as published by the Free Software Foundation; either version |
|---|
| 14 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 15 | | - * |
|---|
| 16 | 11 | * |
|---|
| 17 | 12 | * A tool for loading the network with preconfigurated packets. |
|---|
| 18 | 13 | * The tool is implemented as a linux module. Parameters are output |
|---|
| .. | .. |
|---|
| 60 | 55 | * |
|---|
| 61 | 56 | * Integrated to 2.5.x 021029 --Lucio Maciel (luciomaciel@zipmail.com.br) |
|---|
| 62 | 57 | * |
|---|
| 63 | | - * |
|---|
| 64 | 58 | * 021124 Finished major redesign and rewrite for new functionality. |
|---|
| 65 | | - * See Documentation/networking/pktgen.txt for how to use this. |
|---|
| 59 | + * See Documentation/networking/pktgen.rst for how to use this. |
|---|
| 66 | 60 | * |
|---|
| 67 | 61 | * The new operation: |
|---|
| 68 | 62 | * For each CPU one thread/process is created at start. This process checks |
|---|
| .. | .. |
|---|
| 114 | 108 | * |
|---|
| 115 | 109 | * Fixed src_mac command to set source mac of packet to value specified in |
|---|
| 116 | 110 | * command by Adit Ranadive <adit.262@gmail.com> |
|---|
| 117 | | - * |
|---|
| 118 | 111 | */ |
|---|
| 119 | 112 | |
|---|
| 120 | 113 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| .. | .. |
|---|
| 158 | 151 | #include <linux/etherdevice.h> |
|---|
| 159 | 152 | #include <linux/kthread.h> |
|---|
| 160 | 153 | #include <linux/prefetch.h> |
|---|
| 154 | +#include <linux/mmzone.h> |
|---|
| 161 | 155 | #include <net/net_namespace.h> |
|---|
| 162 | 156 | #include <net/checksum.h> |
|---|
| 163 | 157 | #include <net/ipv6.h> |
|---|
| .. | .. |
|---|
| 541 | 535 | return single_open(file, pgctrl_show, PDE_DATA(inode)); |
|---|
| 542 | 536 | } |
|---|
| 543 | 537 | |
|---|
| 544 | | -static const struct file_operations pktgen_fops = { |
|---|
| 545 | | - .open = pgctrl_open, |
|---|
| 546 | | - .read = seq_read, |
|---|
| 547 | | - .llseek = seq_lseek, |
|---|
| 548 | | - .write = pgctrl_write, |
|---|
| 549 | | - .release = single_release, |
|---|
| 538 | +static const struct proc_ops pktgen_proc_ops = { |
|---|
| 539 | + .proc_open = pgctrl_open, |
|---|
| 540 | + .proc_read = seq_read, |
|---|
| 541 | + .proc_lseek = seq_lseek, |
|---|
| 542 | + .proc_write = pgctrl_write, |
|---|
| 543 | + .proc_release = single_release, |
|---|
| 550 | 544 | }; |
|---|
| 551 | 545 | |
|---|
| 552 | 546 | static int pktgen_if_show(struct seq_file *seq, void *v) |
|---|
| .. | .. |
|---|
| 928 | 922 | pkt_dev->min_pkt_size = value; |
|---|
| 929 | 923 | pkt_dev->cur_pkt_size = value; |
|---|
| 930 | 924 | } |
|---|
| 931 | | - sprintf(pg_result, "OK: min_pkt_size=%u", |
|---|
| 925 | + sprintf(pg_result, "OK: min_pkt_size=%d", |
|---|
| 932 | 926 | pkt_dev->min_pkt_size); |
|---|
| 933 | 927 | return count; |
|---|
| 934 | 928 | } |
|---|
| .. | .. |
|---|
| 945 | 939 | pkt_dev->max_pkt_size = value; |
|---|
| 946 | 940 | pkt_dev->cur_pkt_size = value; |
|---|
| 947 | 941 | } |
|---|
| 948 | | - sprintf(pg_result, "OK: max_pkt_size=%u", |
|---|
| 942 | + sprintf(pg_result, "OK: max_pkt_size=%d", |
|---|
| 949 | 943 | pkt_dev->max_pkt_size); |
|---|
| 950 | 944 | return count; |
|---|
| 951 | 945 | } |
|---|
| .. | .. |
|---|
| 965 | 959 | pkt_dev->max_pkt_size = value; |
|---|
| 966 | 960 | pkt_dev->cur_pkt_size = value; |
|---|
| 967 | 961 | } |
|---|
| 968 | | - sprintf(pg_result, "OK: pkt_size=%u", pkt_dev->min_pkt_size); |
|---|
| 962 | + sprintf(pg_result, "OK: pkt_size=%d", pkt_dev->min_pkt_size); |
|---|
| 969 | 963 | return count; |
|---|
| 970 | 964 | } |
|---|
| 971 | 965 | |
|---|
| .. | .. |
|---|
| 987 | 981 | |
|---|
| 988 | 982 | i += len; |
|---|
| 989 | 983 | pkt_dev->nfrags = value; |
|---|
| 990 | | - sprintf(pg_result, "OK: frags=%u", pkt_dev->nfrags); |
|---|
| 984 | + sprintf(pg_result, "OK: frags=%d", pkt_dev->nfrags); |
|---|
| 991 | 985 | return count; |
|---|
| 992 | 986 | } |
|---|
| 993 | 987 | if (!strcmp(name, "delay")) { |
|---|
| .. | .. |
|---|
| 1152 | 1146 | (!(pkt_dev->odev->priv_flags & IFF_TX_SKB_SHARING))))) |
|---|
| 1153 | 1147 | return -ENOTSUPP; |
|---|
| 1154 | 1148 | pkt_dev->burst = value < 1 ? 1 : value; |
|---|
| 1155 | | - sprintf(pg_result, "OK: burst=%d", pkt_dev->burst); |
|---|
| 1149 | + sprintf(pg_result, "OK: burst=%u", pkt_dev->burst); |
|---|
| 1156 | 1150 | return count; |
|---|
| 1157 | 1151 | } |
|---|
| 1158 | 1152 | if (!strcmp(name, "node")) { |
|---|
| .. | .. |
|---|
| 1713 | 1707 | return single_open(file, pktgen_if_show, PDE_DATA(inode)); |
|---|
| 1714 | 1708 | } |
|---|
| 1715 | 1709 | |
|---|
| 1716 | | -static const struct file_operations pktgen_if_fops = { |
|---|
| 1717 | | - .open = pktgen_if_open, |
|---|
| 1718 | | - .read = seq_read, |
|---|
| 1719 | | - .llseek = seq_lseek, |
|---|
| 1720 | | - .write = pktgen_if_write, |
|---|
| 1721 | | - .release = single_release, |
|---|
| 1710 | +static const struct proc_ops pktgen_if_proc_ops = { |
|---|
| 1711 | + .proc_open = pktgen_if_open, |
|---|
| 1712 | + .proc_read = seq_read, |
|---|
| 1713 | + .proc_lseek = seq_lseek, |
|---|
| 1714 | + .proc_write = pktgen_if_write, |
|---|
| 1715 | + .proc_release = single_release, |
|---|
| 1722 | 1716 | }; |
|---|
| 1723 | 1717 | |
|---|
| 1724 | 1718 | static int pktgen_thread_show(struct seq_file *seq, void *v) |
|---|
| .. | .. |
|---|
| 1850 | 1844 | return single_open(file, pktgen_thread_show, PDE_DATA(inode)); |
|---|
| 1851 | 1845 | } |
|---|
| 1852 | 1846 | |
|---|
| 1853 | | -static const struct file_operations pktgen_thread_fops = { |
|---|
| 1854 | | - .open = pktgen_thread_open, |
|---|
| 1855 | | - .read = seq_read, |
|---|
| 1856 | | - .llseek = seq_lseek, |
|---|
| 1857 | | - .write = pktgen_thread_write, |
|---|
| 1858 | | - .release = single_release, |
|---|
| 1847 | +static const struct proc_ops pktgen_thread_proc_ops = { |
|---|
| 1848 | + .proc_open = pktgen_thread_open, |
|---|
| 1849 | + .proc_read = seq_read, |
|---|
| 1850 | + .proc_lseek = seq_lseek, |
|---|
| 1851 | + .proc_write = pktgen_thread_write, |
|---|
| 1852 | + .proc_release = single_release, |
|---|
| 1859 | 1853 | }; |
|---|
| 1860 | 1854 | |
|---|
| 1861 | 1855 | /* Think find or remove for NN */ |
|---|
| .. | .. |
|---|
| 1932 | 1926 | |
|---|
| 1933 | 1927 | pkt_dev->entry = proc_create_data(dev->name, 0600, |
|---|
| 1934 | 1928 | pn->proc_dir, |
|---|
| 1935 | | - &pktgen_if_fops, |
|---|
| 1929 | + &pktgen_if_proc_ops, |
|---|
| 1936 | 1930 | pkt_dev); |
|---|
| 1937 | 1931 | if (!pkt_dev->entry) |
|---|
| 1938 | 1932 | pr_err("can't move proc entry for '%s'\n", |
|---|
| .. | .. |
|---|
| 2009 | 2003 | return -ENODEV; |
|---|
| 2010 | 2004 | } |
|---|
| 2011 | 2005 | |
|---|
| 2012 | | - if (odev->type != ARPHRD_ETHER) { |
|---|
| 2013 | | - pr_err("not an ethernet device: \"%s\"\n", ifname); |
|---|
| 2006 | + if (odev->type != ARPHRD_ETHER && odev->type != ARPHRD_LOOPBACK) { |
|---|
| 2007 | + pr_err("not an ethernet or loopback device: \"%s\"\n", ifname); |
|---|
| 2014 | 2008 | err = -EINVAL; |
|---|
| 2015 | 2009 | } else if (!netif_running(odev)) { |
|---|
| 2016 | 2010 | pr_err("device is down: \"%s\"\n", ifname); |
|---|
| .. | .. |
|---|
| 2124 | 2118 | rcu_read_lock(); |
|---|
| 2125 | 2119 | in_dev = __in_dev_get_rcu(pkt_dev->odev); |
|---|
| 2126 | 2120 | if (in_dev) { |
|---|
| 2127 | | - if (in_dev->ifa_list) { |
|---|
| 2128 | | - pkt_dev->saddr_min = |
|---|
| 2129 | | - in_dev->ifa_list->ifa_address; |
|---|
| 2121 | + const struct in_ifaddr *ifa; |
|---|
| 2122 | + |
|---|
| 2123 | + ifa = rcu_dereference(in_dev->ifa_list); |
|---|
| 2124 | + if (ifa) { |
|---|
| 2125 | + pkt_dev->saddr_min = ifa->ifa_address; |
|---|
| 2130 | 2126 | pkt_dev->saddr_max = pkt_dev->saddr_min; |
|---|
| 2131 | 2127 | } |
|---|
| 2132 | 2128 | } |
|---|
| .. | .. |
|---|
| 2160 | 2156 | s64 remaining; |
|---|
| 2161 | 2157 | struct hrtimer_sleeper t; |
|---|
| 2162 | 2158 | |
|---|
| 2163 | | - hrtimer_init_sleeper_on_stack(&t, CLOCK_MONOTONIC, HRTIMER_MODE_ABS, |
|---|
| 2164 | | - current); |
|---|
| 2159 | + hrtimer_init_sleeper_on_stack(&t, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); |
|---|
| 2165 | 2160 | hrtimer_set_expires(&t.timer, spin_until); |
|---|
| 2166 | 2161 | |
|---|
| 2167 | 2162 | remaining = ktime_to_ns(hrtimer_expires_remaining(&t.timer)); |
|---|
| .. | .. |
|---|
| 2175 | 2170 | end_time = ktime_get(); |
|---|
| 2176 | 2171 | } while (ktime_compare(end_time, spin_until) < 0); |
|---|
| 2177 | 2172 | } else { |
|---|
| 2178 | | - /* see do_nanosleep */ |
|---|
| 2179 | 2173 | do { |
|---|
| 2180 | 2174 | set_current_state(TASK_INTERRUPTIBLE); |
|---|
| 2181 | | - hrtimer_start_expires(&t.timer, HRTIMER_MODE_ABS); |
|---|
| 2175 | + hrtimer_sleeper_start_expires(&t, HRTIMER_MODE_ABS); |
|---|
| 2182 | 2176 | |
|---|
| 2183 | 2177 | if (likely(t.task)) |
|---|
| 2184 | 2178 | schedule(); |
|---|
| .. | .. |
|---|
| 2520 | 2514 | skb->_skb_refdst = (unsigned long)&pkt_dev->xdst.u.dst | SKB_DST_NOREF; |
|---|
| 2521 | 2515 | |
|---|
| 2522 | 2516 | rcu_read_lock_bh(); |
|---|
| 2523 | | - err = x->outer_mode->output(x, skb); |
|---|
| 2517 | + err = pktgen_xfrm_outer_mode_output(x, skb); |
|---|
| 2524 | 2518 | rcu_read_unlock_bh(); |
|---|
| 2525 | 2519 | if (err) { |
|---|
| 2526 | 2520 | XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEMODEERROR); |
|---|
| .. | .. |
|---|
| 2656 | 2650 | } |
|---|
| 2657 | 2651 | get_page(pkt_dev->page); |
|---|
| 2658 | 2652 | skb_frag_set_page(skb, i, pkt_dev->page); |
|---|
| 2659 | | - skb_shinfo(skb)->frags[i].page_offset = 0; |
|---|
| 2653 | + skb_frag_off_set(&skb_shinfo(skb)->frags[i], 0); |
|---|
| 2660 | 2654 | /*last fragment, fill rest of data*/ |
|---|
| 2661 | 2655 | if (i == (frags - 1)) |
|---|
| 2662 | 2656 | skb_frag_size_set(&skb_shinfo(skb)->frags[i], |
|---|
| .. | .. |
|---|
| 3368 | 3362 | /* skb was 'freed' by stack, so clean few |
|---|
| 3369 | 3363 | * bits and reuse it |
|---|
| 3370 | 3364 | */ |
|---|
| 3371 | | - skb_reset_tc(skb); |
|---|
| 3365 | + skb_reset_redirect(skb); |
|---|
| 3372 | 3366 | } while (--burst > 0); |
|---|
| 3373 | 3367 | goto out; /* Skips xmit_mode M_START_XMIT */ |
|---|
| 3374 | 3368 | } else if (pkt_dev->xmit_mode == M_QUEUE_XMIT) { |
|---|
| .. | .. |
|---|
| 3410 | 3404 | HARD_TX_LOCK(odev, txq, smp_processor_id()); |
|---|
| 3411 | 3405 | |
|---|
| 3412 | 3406 | if (unlikely(netif_xmit_frozen_or_drv_stopped(txq))) { |
|---|
| 3413 | | - ret = NETDEV_TX_BUSY; |
|---|
| 3414 | 3407 | pkt_dev->last_ok = 0; |
|---|
| 3415 | 3408 | goto unlock; |
|---|
| 3416 | 3409 | } |
|---|
| .. | .. |
|---|
| 3437 | 3430 | net_info_ratelimited("%s xmit error: %d\n", |
|---|
| 3438 | 3431 | pkt_dev->odevname, ret); |
|---|
| 3439 | 3432 | pkt_dev->errors++; |
|---|
| 3440 | | - /* fallthru */ |
|---|
| 3433 | + fallthrough; |
|---|
| 3441 | 3434 | case NETDEV_TX_BUSY: |
|---|
| 3442 | 3435 | /* Retry it next time */ |
|---|
| 3443 | 3436 | refcount_dec(&(pkt_dev->skb->users)); |
|---|
| .. | .. |
|---|
| 3636 | 3629 | pkt_dev->svlan_cfi = 0; |
|---|
| 3637 | 3630 | pkt_dev->svlan_id = 0xffff; |
|---|
| 3638 | 3631 | pkt_dev->burst = 1; |
|---|
| 3639 | | - pkt_dev->node = -1; |
|---|
| 3632 | + pkt_dev->node = NUMA_NO_NODE; |
|---|
| 3640 | 3633 | |
|---|
| 3641 | 3634 | err = pktgen_setup_dev(t->net, pkt_dev, ifname); |
|---|
| 3642 | 3635 | if (err) |
|---|
| .. | .. |
|---|
| 3645 | 3638 | pkt_dev->clone_skb = pg_clone_skb_d; |
|---|
| 3646 | 3639 | |
|---|
| 3647 | 3640 | pkt_dev->entry = proc_create_data(ifname, 0600, t->net->proc_dir, |
|---|
| 3648 | | - &pktgen_if_fops, pkt_dev); |
|---|
| 3641 | + &pktgen_if_proc_ops, pkt_dev); |
|---|
| 3649 | 3642 | if (!pkt_dev->entry) { |
|---|
| 3650 | 3643 | pr_err("cannot create %s/%s procfs entry\n", |
|---|
| 3651 | 3644 | PG_PROC_DIR, ifname); |
|---|
| .. | .. |
|---|
| 3706 | 3699 | cpu_to_node(cpu), |
|---|
| 3707 | 3700 | "kpktgend_%d", cpu); |
|---|
| 3708 | 3701 | if (IS_ERR(p)) { |
|---|
| 3709 | | - pr_err("kernel_thread() failed for cpu %d\n", t->cpu); |
|---|
| 3702 | + pr_err("kthread_create_on_node() failed for cpu %d\n", t->cpu); |
|---|
| 3710 | 3703 | list_del(&t->th_list); |
|---|
| 3711 | 3704 | kfree(t); |
|---|
| 3712 | 3705 | return PTR_ERR(p); |
|---|
| .. | .. |
|---|
| 3715 | 3708 | t->tsk = p; |
|---|
| 3716 | 3709 | |
|---|
| 3717 | 3710 | pe = proc_create_data(t->tsk->comm, 0600, pn->proc_dir, |
|---|
| 3718 | | - &pktgen_thread_fops, t); |
|---|
| 3711 | + &pktgen_thread_proc_ops, t); |
|---|
| 3719 | 3712 | if (!pe) { |
|---|
| 3720 | 3713 | pr_err("cannot create %s/%s procfs entry\n", |
|---|
| 3721 | 3714 | PG_PROC_DIR, t->tsk->comm); |
|---|
| .. | .. |
|---|
| 3800 | 3793 | pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR); |
|---|
| 3801 | 3794 | return -ENODEV; |
|---|
| 3802 | 3795 | } |
|---|
| 3803 | | - pe = proc_create(PGCTRL, 0600, pn->proc_dir, &pktgen_fops); |
|---|
| 3796 | + pe = proc_create(PGCTRL, 0600, pn->proc_dir, &pktgen_proc_ops); |
|---|
| 3804 | 3797 | if (pe == NULL) { |
|---|
| 3805 | 3798 | pr_err("cannot create %s procfs entry\n", PGCTRL); |
|---|
| 3806 | 3799 | ret = -EINVAL; |
|---|