diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2015-12-15 23:09:15 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2015-12-17 10:55:58 +0100 |
commit | 126e0038a73b38fac7b3e03173b2d791734cc497 (patch) | |
tree | 4ec36f3ba75e1ef4111134c1fc4afc1e8566dd66 | |
parent | 121119215276e645b358d7ce0593251f215920df (diff) |
trafgen: Added option to pass macro/define for C preprocessor
Add -D,--define option which allows to pass multiple
macro/defines which can be used in trafgen script
(e.g. by #ifdef ).
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r-- | trafgen.8 | 4 | ||||
-rw-r--r-- | trafgen.c | 19 | ||||
-rw-r--r-- | trafgen_conf.h | 3 | ||||
-rw-r--r-- | trafgen_parser.y | 5 |
4 files changed, 24 insertions, 7 deletions
@@ -79,6 +79,10 @@ Pass the packet configuration to the C preprocessor before reading it into trafgen. This allows #define and #include directives (e.g. to include definitions from system headers) to be used in the trafgen configuration file. .PP +.SS -D <name>=<definition>, --define <name>=<definition> +Add macro definition for the C preprocessor to use it within trafgen file. This +option is used in combination with the -p,--cpp option. +.PP .SS -J, --jumbo-support By default trafgen's ring buffer frames are of a fixed size of 2048 bytes. This means that if you're expecting jumbo frames or even super jumbo frames to @@ -83,7 +83,7 @@ size_t plen = 0; struct packet_dyn *packet_dyn = NULL; size_t dlen = 0; -static const char *short_options = "d:c:n:t:vJhS:rk:i:o:VRs:P:eE:pu:g:CHQq"; +static const char *short_options = "d:c:n:t:vJhS:rk:i:o:VRs:P:eE:pu:g:CHQqD:"; static const struct option long_options[] = { {"dev", required_argument, NULL, 'd'}, {"out", required_argument, NULL, 'o'}, @@ -105,6 +105,7 @@ static const struct option long_options[] = { {"jumbo-support", no_argument, NULL, 'J'}, {"no-cpu-stats", no_argument, NULL, 'C'}, {"cpp", no_argument, NULL, 'p'}, + {"define", required_argument, NULL, 'D'}, {"rfraw", no_argument, NULL, 'R'}, {"rand", no_argument, NULL, 'r'}, {"verbose", no_argument, NULL, 'V'}, @@ -163,6 +164,7 @@ static void __noreturn help(void) " -i|-c|--in|--conf <cfg/-> Packet configuration file/stdin\n" " -o|-d|--out|--dev <netdev> Networking device i.e., eth0\n" " -p|--cpp Run packet config through C preprocessor\n" + " -D|--define Add macro/define for C preprocessor\n" " -J|--jumbo-support Support 64KB super jumbo frames (def: 2048B)\n" " -R|--rfraw Inject raw 802.11 frames\n" " -s|--smoke-test <ipv4> Probe if machine survived fuzz-tested packet\n" @@ -823,12 +825,13 @@ static void xmit_packet_precheck(struct ctx *ctx, unsigned int cpu) } static void main_loop(struct ctx *ctx, char *confname, bool slow, - unsigned int cpu, bool invoke_cpp, unsigned long orig_num) + unsigned int cpu, bool invoke_cpp, char **cpp_argv, + unsigned long orig_num) { if (ctx->packet_str) compile_packets_str(ctx->packet_str, ctx->verbose, cpu); else - compile_packets(confname, ctx->verbose, cpu, invoke_cpp); + compile_packets(confname, ctx->verbose, cpu, invoke_cpp, cpp_argv); preprocess_packets(); @@ -896,6 +899,8 @@ int main(int argc, char **argv) unsigned long long tx_packets, tx_bytes; struct ctx ctx; int min_opts = 5; + char **cpp_argv = NULL; + size_t cpp_argc = 0; fmemset(&ctx, 0, sizeof(ctx)); ctx.cpus = get_number_cpus_online(); @@ -924,6 +929,10 @@ int main(int argc, char **argv) case 'p': invoke_cpp = true; break; + case 'D': + cpp_argv = argv_insert(cpp_argv, &cpp_argc, "-D"); + cpp_argv = argv_insert(cpp_argv, &cpp_argc, optarg); + break; case 'V': ctx.verbose = true; break; @@ -1133,7 +1142,8 @@ int main(int argc, char **argv) srand(seed); cpu_affinity(i); - main_loop(&ctx, confname, slow, i, invoke_cpp, orig_num); + main_loop(&ctx, confname, slow, i, invoke_cpp, + cpp_argv, orig_num); goto thread_out; case -1: @@ -1179,6 +1189,7 @@ thread_out: if (set_irq_aff) device_restore_irq_affinity_list(); + argv_free(cpp_argv); free(ctx.device); free(ctx.device_trans); free(ctx.rhost); diff --git a/trafgen_conf.h b/trafgen_conf.h index deadb7c..db3258f 100644 --- a/trafgen_conf.h +++ b/trafgen_conf.h @@ -56,7 +56,8 @@ static inline bool packet_dyn_has_only_csums(struct packet_dyn *p) } extern void compile_packets_str(char *str, bool verbose, unsigned int cpu); -extern void compile_packets(char *file, bool verbose, unsigned int cpu, bool invoke_cpp); +extern void compile_packets(char *file, bool verbose, unsigned int cpu, + bool invoke_cpp, char **cpp_argv); extern void cleanup_packets(void); #endif /* TRAFGEN_CONF */ diff --git a/trafgen_parser.y b/trafgen_parser.y index 8a0f3b7..24370ee 100644 --- a/trafgen_parser.y +++ b/trafgen_parser.y @@ -590,7 +590,8 @@ void cleanup_packets(void) free(packet_dyn); } -void compile_packets(char *file, bool verbose, unsigned int cpu, bool invoke_cpp) +void compile_packets(char *file, bool verbose, unsigned int cpu, bool invoke_cpp, + char **cpp_argv) { char tmp_file[128]; int ret = -1; @@ -599,7 +600,7 @@ void compile_packets(char *file, bool verbose, unsigned int cpu, bool invoke_cpp our_cpu = cpu; if (invoke_cpp) { - if (cpp_exec(file, tmp_file, sizeof(tmp_file), NULL)) { + if (cpp_exec(file, tmp_file, sizeof(tmp_file), cpp_argv)) { fprintf(stderr, "Failed to invoke C preprocessor!\n"); goto err; } |