From 93c5fbf758b50009b81a9ded73818a891dd0def1 Mon Sep 17 00:00:00 2001 From: Shu Ma Date: Mon, 24 Dec 2018 16:31:36 +0800 Subject: [PATCH] net-test: packetdrill: fix compilation/runtime error for linux 3.x For linux 3.10, TCP_CC_INFO and SO_MEMINFO are not supported. When we define HAVE_SO_MEMINFO / HAVE_TCP_CC_INFO as 0, functions like write_tcp_bbr_cc_info and write_so_meminfo will not be accessed. So wrap them with #ifdef and #endif. Also, for lower linux version, tcp_info option value has less fields(e.g. 120 bytes). So remove the size assert. Change-Id: Ibb4458067becdb857ff82f680bdd37727b5c2378 --- gtests/net/packetdrill/code.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gtests/net/packetdrill/code.c b/gtests/net/packetdrill/code.c index 0c38e400..3de6c0a5 100644 --- a/gtests/net/packetdrill/code.c +++ b/gtests/net/packetdrill/code.c @@ -141,8 +141,6 @@ static void write_tcp_info(struct code_state *code, const struct _tcp_info *info, int len) { - assert(len >= sizeof(struct _tcp_info)); - write_symbols(code); /* Emit the recorded values of tcpi_foo values. */ @@ -198,6 +196,7 @@ static void write_tcp_info(struct code_state *code, emit_var_end(code); } +#if HAVE_TCP_CC_INFO /* Write out a formatted representation of the given _tcp_bbr_info buffer. */ static void write_tcp_bbr_cc_info(struct code_state *code, const union _tcp_cc_info *info, @@ -264,7 +263,9 @@ static void write_tcp_cc_info(struct code_state *code, write_tcp_vegas_cc_info(code, info, len); emit_var_end(code); } +#endif /* HAVE_TCP_CC_INFO */ +#if HAVE_SO_MEMINFO /* Write out a formatted representation of the given mem_info buffer. */ static void write_so_meminfo(struct code_state *code, const u32 *mem_info, @@ -284,6 +285,7 @@ static void write_so_meminfo(struct code_state *code, emit_var_end(code); } +#endif /* HAVE_SO_MEMINFO */ #endif /* linux */ #if defined(__FreeBSD__) @@ -293,8 +295,6 @@ static void write_tcp_info(struct code_state *code, const struct _tcp_info *info, int len) { - assert(len >= sizeof(struct _tcp_info)); - write_symbols(code); /* Emit the recorded values of tcpi_foo values. */ @@ -729,7 +729,6 @@ void run_code_event(struct state *state, struct event *event, void *data = NULL; void *data_ext = NULL; - void *data_meminfo = NULL; int data_len = 0; #if HAVE_TCP_INFO code->data_type = DATA_TCP_INFO; @@ -755,6 +754,7 @@ void run_code_event(struct state *state, struct event *event, #endif /* HAVE_TCP_CC_INFO */ #if HAVE_SO_MEMINFO code->data_type = DATA_SO_MEMINFO; + void *data_meminfo = NULL; data_meminfo = get_data(state, event, fd, code->data_type, &data_len); if (data_meminfo) append_data(code, code->data_type, data_meminfo, data_len);