Skip to content

Commit 46410c2

Browse files
committed
Merge branch 'pktgen-Behavior-flags-fixes'
Dmitry Safonov says: ==================== pktgen: Behavior flags fixes v2: o fixed a nitpick from David Miller There are a bunch of fixes/cleanups/Documentations. Diffstat says for itself, regardless added docs and missed flag parameters. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 969ade4 + 52e12d5 commit 46410c2

File tree

2 files changed

+103
-182
lines changed

2 files changed

+103
-182
lines changed

Documentation/networking/pktgen.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ suitable sample script and configure that.
1212
On a dual CPU:
1313

1414
ps aux | grep pkt
15-
root 129 0.3 0.0 0 0 ? SW 2003 523:20 [pktgen/0]
16-
root 130 0.3 0.0 0 0 ? SW 2003 509:50 [pktgen/1]
15+
root 129 0.3 0.0 0 0 ? SW 2003 523:20 [kpktgend_0]
16+
root 130 0.3 0.0 0 0 ? SW 2003 509:50 [kpktgend_1]
1717

1818

1919
For monitoring and control pktgen creates:
@@ -113,9 +113,16 @@ Configuring devices
113113
===================
114114
This is done via the /proc interface, and most easily done via pgset
115115
as defined in the sample scripts.
116+
You need to specify PGDEV environment variable to use functions from sample
117+
scripts, i.e.:
118+
export PGDEV=/proc/net/pktgen/eth4@0
119+
source samples/pktgen/functions.sh
116120

117121
Examples:
118122

123+
pg_ctrl start starts injection.
124+
pg_ctrl stop aborts injection. Also, ^C aborts generator.
125+
119126
pgset "clone_skb 1" sets the number of copies of the same packet
120127
pgset "clone_skb 0" use single SKB for all transmits
121128
pgset "burst 8" uses xmit_more API to queue 8 copies of the same
@@ -165,8 +172,12 @@ Examples:
165172
IPSEC # IPsec encapsulation (needs CONFIG_XFRM)
166173
NODE_ALLOC # node specific memory allocation
167174
NO_TIMESTAMP # disable timestamping
175+
pgset 'flag ![name]' Clear a flag to determine behaviour.
176+
Note that you might need to use single quote in
177+
interactive mode, so that your shell wouldn't expand
178+
the specified flag as a history command.
168179

169-
pgset spi SPI_VALUE Set specific SA used to transform packet.
180+
pgset "spi [SPI_VALUE]" Set specific SA used to transform packet.
170181

171182
pgset "udp_src_min 9" set UDP source port min, If < udp_src_max, then
172183
cycle through the port range.
@@ -207,8 +218,6 @@ Examples:
207218
pgset "tos XX" set former IPv4 TOS field (e.g. "tos 28" for AF11 no ECN, default 00)
208219
pgset "traffic_class XX" set former IPv6 TRAFFIC CLASS (e.g. "traffic_class B8" for EF no ECN, default 00)
209220

210-
pgset stop aborts injection. Also, ^C aborts generator.
211-
212221
pgset "rate 300M" set rate to 300 Mb/s
213222
pgset "ratep 1000000" set rate to 1Mpps
214223

net/core/pktgen.c

Lines changed: 89 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -184,25 +184,44 @@
184184

185185
#define func_enter() pr_debug("entering %s\n", __func__);
186186

187+
#define PKT_FLAGS \
188+
pf(IPV6) /* Interface in IPV6 Mode */ \
189+
pf(IPSRC_RND) /* IP-Src Random */ \
190+
pf(IPDST_RND) /* IP-Dst Random */ \
191+
pf(TXSIZE_RND) /* Transmit size is random */ \
192+
pf(UDPSRC_RND) /* UDP-Src Random */ \
193+
pf(UDPDST_RND) /* UDP-Dst Random */ \
194+
pf(UDPCSUM) /* Include UDP checksum */ \
195+
pf(NO_TIMESTAMP) /* Don't timestamp packets (default TS) */ \
196+
pf(MPLS_RND) /* Random MPLS labels */ \
197+
pf(QUEUE_MAP_RND) /* queue map Random */ \
198+
pf(QUEUE_MAP_CPU) /* queue map mirrors smp_processor_id() */ \
199+
pf(FLOW_SEQ) /* Sequential flows */ \
200+
pf(IPSEC) /* ipsec on for flows */ \
201+
pf(MACSRC_RND) /* MAC-Src Random */ \
202+
pf(MACDST_RND) /* MAC-Dst Random */ \
203+
pf(VID_RND) /* Random VLAN ID */ \
204+
pf(SVID_RND) /* Random SVLAN ID */ \
205+
pf(NODE) /* Node memory alloc*/ \
206+
207+
#define pf(flag) flag##_SHIFT,
208+
enum pkt_flags {
209+
PKT_FLAGS
210+
};
211+
#undef pf
212+
187213
/* Device flag bits */
188-
#define F_IPSRC_RND (1<<0) /* IP-Src Random */
189-
#define F_IPDST_RND (1<<1) /* IP-Dst Random */
190-
#define F_UDPSRC_RND (1<<2) /* UDP-Src Random */
191-
#define F_UDPDST_RND (1<<3) /* UDP-Dst Random */
192-
#define F_MACSRC_RND (1<<4) /* MAC-Src Random */
193-
#define F_MACDST_RND (1<<5) /* MAC-Dst Random */
194-
#define F_TXSIZE_RND (1<<6) /* Transmit size is random */
195-
#define F_IPV6 (1<<7) /* Interface in IPV6 Mode */
196-
#define F_MPLS_RND (1<<8) /* Random MPLS labels */
197-
#define F_VID_RND (1<<9) /* Random VLAN ID */
198-
#define F_SVID_RND (1<<10) /* Random SVLAN ID */
199-
#define F_FLOW_SEQ (1<<11) /* Sequential flows */
200-
#define F_IPSEC_ON (1<<12) /* ipsec on for flows */
201-
#define F_QUEUE_MAP_RND (1<<13) /* queue map Random */
202-
#define F_QUEUE_MAP_CPU (1<<14) /* queue map mirrors smp_processor_id() */
203-
#define F_NODE (1<<15) /* Node memory alloc*/
204-
#define F_UDPCSUM (1<<16) /* Include UDP checksum */
205-
#define F_NO_TIMESTAMP (1<<17) /* Don't timestamp packets (default TS) */
214+
#define pf(flag) static const __u32 F_##flag = (1<<flag##_SHIFT);
215+
PKT_FLAGS
216+
#undef pf
217+
218+
#define pf(flag) __stringify(flag),
219+
static char *pkt_flag_names[] = {
220+
PKT_FLAGS
221+
};
222+
#undef pf
223+
224+
#define NR_PKT_FLAGS ARRAY_SIZE(pkt_flag_names)
206225

207226
/* Thread control flag bits */
208227
#define T_STOP (1<<0) /* Stop run */
@@ -534,6 +553,7 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
534553
{
535554
const struct pktgen_dev *pkt_dev = seq->private;
536555
ktime_t stopped;
556+
unsigned int i;
537557
u64 idle;
538558

539559
seq_printf(seq,
@@ -595,7 +615,6 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
595615
pkt_dev->src_mac_count, pkt_dev->dst_mac_count);
596616

597617
if (pkt_dev->nr_labels) {
598-
unsigned int i;
599618
seq_puts(seq, " mpls: ");
600619
for (i = 0; i < pkt_dev->nr_labels; i++)
601620
seq_printf(seq, "%08x%s", ntohl(pkt_dev->labels[i]),
@@ -631,68 +650,21 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
631650

632651
seq_puts(seq, " Flags: ");
633652

634-
if (pkt_dev->flags & F_IPV6)
635-
seq_puts(seq, "IPV6 ");
636-
637-
if (pkt_dev->flags & F_IPSRC_RND)
638-
seq_puts(seq, "IPSRC_RND ");
639-
640-
if (pkt_dev->flags & F_IPDST_RND)
641-
seq_puts(seq, "IPDST_RND ");
642-
643-
if (pkt_dev->flags & F_TXSIZE_RND)
644-
seq_puts(seq, "TXSIZE_RND ");
645-
646-
if (pkt_dev->flags & F_UDPSRC_RND)
647-
seq_puts(seq, "UDPSRC_RND ");
648-
649-
if (pkt_dev->flags & F_UDPDST_RND)
650-
seq_puts(seq, "UDPDST_RND ");
651-
652-
if (pkt_dev->flags & F_UDPCSUM)
653-
seq_puts(seq, "UDPCSUM ");
654-
655-
if (pkt_dev->flags & F_NO_TIMESTAMP)
656-
seq_puts(seq, "NO_TIMESTAMP ");
657-
658-
if (pkt_dev->flags & F_MPLS_RND)
659-
seq_puts(seq, "MPLS_RND ");
660-
661-
if (pkt_dev->flags & F_QUEUE_MAP_RND)
662-
seq_puts(seq, "QUEUE_MAP_RND ");
653+
for (i = 0; i < NR_PKT_FLAGS; i++) {
654+
if (i == F_FLOW_SEQ)
655+
if (!pkt_dev->cflows)
656+
continue;
663657

664-
if (pkt_dev->flags & F_QUEUE_MAP_CPU)
665-
seq_puts(seq, "QUEUE_MAP_CPU ");
666-
667-
if (pkt_dev->cflows) {
668-
if (pkt_dev->flags & F_FLOW_SEQ)
669-
seq_puts(seq, "FLOW_SEQ "); /*in sequence flows*/
670-
else
671-
seq_puts(seq, "FLOW_RND ");
672-
}
658+
if (pkt_dev->flags & (1 << i))
659+
seq_printf(seq, "%s ", pkt_flag_names[i]);
660+
else if (i == F_FLOW_SEQ)
661+
seq_puts(seq, "FLOW_RND ");
673662

674663
#ifdef CONFIG_XFRM
675-
if (pkt_dev->flags & F_IPSEC_ON) {
676-
seq_puts(seq, "IPSEC ");
677-
if (pkt_dev->spi)
664+
if (i == F_IPSEC && pkt_dev->spi)
678665
seq_printf(seq, "spi:%u", pkt_dev->spi);
679-
}
680666
#endif
681-
682-
if (pkt_dev->flags & F_MACSRC_RND)
683-
seq_puts(seq, "MACSRC_RND ");
684-
685-
if (pkt_dev->flags & F_MACDST_RND)
686-
seq_puts(seq, "MACDST_RND ");
687-
688-
if (pkt_dev->flags & F_VID_RND)
689-
seq_puts(seq, "VID_RND ");
690-
691-
if (pkt_dev->flags & F_SVID_RND)
692-
seq_puts(seq, "SVID_RND ");
693-
694-
if (pkt_dev->flags & F_NODE)
695-
seq_puts(seq, "NODE_ALLOC ");
667+
}
696668

697669
seq_puts(seq, "\n");
698670

@@ -858,6 +830,35 @@ static ssize_t get_labels(const char __user *buffer, struct pktgen_dev *pkt_dev)
858830
return i;
859831
}
860832

833+
static __u32 pktgen_read_flag(const char *f, bool *disable)
834+
{
835+
__u32 i;
836+
837+
if (f[0] == '!') {
838+
*disable = true;
839+
f++;
840+
}
841+
842+
for (i = 0; i < NR_PKT_FLAGS; i++) {
843+
if (!IS_ENABLED(CONFIG_XFRM) && i == IPSEC_SHIFT)
844+
continue;
845+
846+
/* allow only disabling ipv6 flag */
847+
if (!*disable && i == IPV6_SHIFT)
848+
continue;
849+
850+
if (strcmp(f, pkt_flag_names[i]) == 0)
851+
return 1 << i;
852+
}
853+
854+
if (strcmp(f, "FLOW_RND") == 0) {
855+
*disable = !*disable;
856+
return F_FLOW_SEQ;
857+
}
858+
859+
return 0;
860+
}
861+
861862
static ssize_t pktgen_if_write(struct file *file,
862863
const char __user * user_buffer, size_t count,
863864
loff_t * offset)
@@ -1215,7 +1216,10 @@ static ssize_t pktgen_if_write(struct file *file,
12151216
return count;
12161217
}
12171218
if (!strcmp(name, "flag")) {
1219+
__u32 flag;
12181220
char f[32];
1221+
bool disable = false;
1222+
12191223
memset(f, 0, 32);
12201224
len = strn_len(&user_buffer[i], sizeof(f) - 1);
12211225
if (len < 0)
@@ -1224,107 +1228,15 @@ static ssize_t pktgen_if_write(struct file *file,
12241228
if (copy_from_user(f, &user_buffer[i], len))
12251229
return -EFAULT;
12261230
i += len;
1227-
if (strcmp(f, "IPSRC_RND") == 0)
1228-
pkt_dev->flags |= F_IPSRC_RND;
1229-
1230-
else if (strcmp(f, "!IPSRC_RND") == 0)
1231-
pkt_dev->flags &= ~F_IPSRC_RND;
1232-
1233-
else if (strcmp(f, "TXSIZE_RND") == 0)
1234-
pkt_dev->flags |= F_TXSIZE_RND;
1235-
1236-
else if (strcmp(f, "!TXSIZE_RND") == 0)
1237-
pkt_dev->flags &= ~F_TXSIZE_RND;
1238-
1239-
else if (strcmp(f, "IPDST_RND") == 0)
1240-
pkt_dev->flags |= F_IPDST_RND;
1241-
1242-
else if (strcmp(f, "!IPDST_RND") == 0)
1243-
pkt_dev->flags &= ~F_IPDST_RND;
1244-
1245-
else if (strcmp(f, "UDPSRC_RND") == 0)
1246-
pkt_dev->flags |= F_UDPSRC_RND;
1247-
1248-
else if (strcmp(f, "!UDPSRC_RND") == 0)
1249-
pkt_dev->flags &= ~F_UDPSRC_RND;
1250-
1251-
else if (strcmp(f, "UDPDST_RND") == 0)
1252-
pkt_dev->flags |= F_UDPDST_RND;
1253-
1254-
else if (strcmp(f, "!UDPDST_RND") == 0)
1255-
pkt_dev->flags &= ~F_UDPDST_RND;
1256-
1257-
else if (strcmp(f, "MACSRC_RND") == 0)
1258-
pkt_dev->flags |= F_MACSRC_RND;
1259-
1260-
else if (strcmp(f, "!MACSRC_RND") == 0)
1261-
pkt_dev->flags &= ~F_MACSRC_RND;
1262-
1263-
else if (strcmp(f, "MACDST_RND") == 0)
1264-
pkt_dev->flags |= F_MACDST_RND;
1265-
1266-
else if (strcmp(f, "!MACDST_RND") == 0)
1267-
pkt_dev->flags &= ~F_MACDST_RND;
1268-
1269-
else if (strcmp(f, "MPLS_RND") == 0)
1270-
pkt_dev->flags |= F_MPLS_RND;
1271-
1272-
else if (strcmp(f, "!MPLS_RND") == 0)
1273-
pkt_dev->flags &= ~F_MPLS_RND;
12741231

1275-
else if (strcmp(f, "VID_RND") == 0)
1276-
pkt_dev->flags |= F_VID_RND;
1232+
flag = pktgen_read_flag(f, &disable);
12771233

1278-
else if (strcmp(f, "!VID_RND") == 0)
1279-
pkt_dev->flags &= ~F_VID_RND;
1280-
1281-
else if (strcmp(f, "SVID_RND") == 0)
1282-
pkt_dev->flags |= F_SVID_RND;
1283-
1284-
else if (strcmp(f, "!SVID_RND") == 0)
1285-
pkt_dev->flags &= ~F_SVID_RND;
1286-
1287-
else if (strcmp(f, "FLOW_SEQ") == 0)
1288-
pkt_dev->flags |= F_FLOW_SEQ;
1289-
1290-
else if (strcmp(f, "QUEUE_MAP_RND") == 0)
1291-
pkt_dev->flags |= F_QUEUE_MAP_RND;
1292-
1293-
else if (strcmp(f, "!QUEUE_MAP_RND") == 0)
1294-
pkt_dev->flags &= ~F_QUEUE_MAP_RND;
1295-
1296-
else if (strcmp(f, "QUEUE_MAP_CPU") == 0)
1297-
pkt_dev->flags |= F_QUEUE_MAP_CPU;
1298-
1299-
else if (strcmp(f, "!QUEUE_MAP_CPU") == 0)
1300-
pkt_dev->flags &= ~F_QUEUE_MAP_CPU;
1301-
#ifdef CONFIG_XFRM
1302-
else if (strcmp(f, "IPSEC") == 0)
1303-
pkt_dev->flags |= F_IPSEC_ON;
1304-
#endif
1305-
1306-
else if (strcmp(f, "!IPV6") == 0)
1307-
pkt_dev->flags &= ~F_IPV6;
1308-
1309-
else if (strcmp(f, "NODE_ALLOC") == 0)
1310-
pkt_dev->flags |= F_NODE;
1311-
1312-
else if (strcmp(f, "!NODE_ALLOC") == 0)
1313-
pkt_dev->flags &= ~F_NODE;
1314-
1315-
else if (strcmp(f, "UDPCSUM") == 0)
1316-
pkt_dev->flags |= F_UDPCSUM;
1317-
1318-
else if (strcmp(f, "!UDPCSUM") == 0)
1319-
pkt_dev->flags &= ~F_UDPCSUM;
1320-
1321-
else if (strcmp(f, "NO_TIMESTAMP") == 0)
1322-
pkt_dev->flags |= F_NO_TIMESTAMP;
1323-
1324-
else if (strcmp(f, "!NO_TIMESTAMP") == 0)
1325-
pkt_dev->flags &= ~F_NO_TIMESTAMP;
1326-
1327-
else {
1234+
if (flag) {
1235+
if (disable)
1236+
pkt_dev->flags &= ~flag;
1237+
else
1238+
pkt_dev->flags |= flag;
1239+
} else {
13281240
sprintf(pg_result,
13291241
"Flag -:%s:- unknown\nAvailable flags, (prepend ! to un-set flag):\n%s",
13301242
f,
@@ -2541,7 +2453,7 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev)
25412453
pkt_dev->flows[flow].cur_daddr =
25422454
pkt_dev->cur_daddr;
25432455
#ifdef CONFIG_XFRM
2544-
if (pkt_dev->flags & F_IPSEC_ON)
2456+
if (pkt_dev->flags & F_IPSEC)
25452457
get_ipsec_sa(pkt_dev, flow);
25462458
#endif
25472459
pkt_dev->nflows++;
@@ -2646,7 +2558,7 @@ static void free_SAs(struct pktgen_dev *pkt_dev)
26462558
static int process_ipsec(struct pktgen_dev *pkt_dev,
26472559
struct sk_buff *skb, __be16 protocol)
26482560
{
2649-
if (pkt_dev->flags & F_IPSEC_ON) {
2561+
if (pkt_dev->flags & F_IPSEC) {
26502562
struct xfrm_state *x = pkt_dev->flows[pkt_dev->curfl].x;
26512563
int nhead = 0;
26522564
if (x) {

0 commit comments

Comments
 (0)