From 908fe217665f1be770f6a17dd74d001a0e2d422d Mon Sep 17 00:00:00 2001 From: Fred Date: Sun, 3 Sep 2023 20:13:31 -0700 Subject: [PATCH] Feature #822: fix compile issue --- .github/workflows/c-linter.yml | 2 +- .github/workflows/codeql.yml | 2 +- .github/workflows/github-actions-ci.yml | 2 +- src/common/sendpacket.c | 11 ++++------- src/common/sendpacket.h | 22 ++++++++++++---------- src/send_packets.c | 10 +++++----- src/tcpedit/plugins/dlt_en10mb/en10mb.c | 4 ++-- 7 files changed, 26 insertions(+), 27 deletions(-) diff --git a/.github/workflows/c-linter.yml b/.github/workflows/c-linter.yml index 30d9293f..375d8360 100644 --- a/.github/workflows/c-linter.yml +++ b/.github/workflows/c-linter.yml @@ -9,7 +9,7 @@ jobs: - uses: actions/checkout@v3 - run: | echo "Build Application" - sudo apt-get -y install libpcap-dev autogen + sudo apt-get -y install libpcap-dev autogen libbpf-dev libxdp-dev ./autogen.sh ./configure --disable-local-libopts - uses: cpp-linter/cpp-linter-action@v2 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 6349571a..f561577b 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -59,7 +59,7 @@ jobs: - run: | echo "Build Application" - sudo apt-get -y install libpcap-dev autogen + sudo apt-get -y install libpcap-dev autogen libbpf-dev libxdp-dev ./autogen.sh ./configure --disable-local-libopts make diff --git a/.github/workflows/github-actions-ci.yml b/.github/workflows/github-actions-ci.yml index 21b5e248..a3a144aa 100644 --- a/.github/workflows/github-actions-ci.yml +++ b/.github/workflows/github-actions-ci.yml @@ -14,7 +14,7 @@ jobs: - name: List interfaces run: ip a - name: Install prereqs - run: sudo apt -y install autogen libpcap-dev + run: sudo apt -y install autogen libpcap-dev libbpf-dev libxdp-dev - name: Create configure script run: ./autogen.sh - name: configure diff --git a/src/common/sendpacket.c b/src/common/sendpacket.c index a0d26608..3fae5c88 100644 --- a/src/common/sendpacket.c +++ b/src/common/sendpacket.c @@ -132,9 +132,6 @@ #ifdef HAVE_SYS_PARAM_H #include #endif -#ifdef HAVE_SYS_SYSCTL_H -#include -#endif #ifdef HAVE_NET_ROUTE_H #include #endif @@ -1353,8 +1350,8 @@ xsk_configure_socket(struct xsk_umem_info *umem, struct xsk_socket_config *cfg, { struct xsk_socket_info *xsk; struct xsk_ring_cons *rxr = NULL; - struct xsk_ring_prod *txr; int ret; + xsk = (struct xsk_socket_info *)safe_malloc(sizeof(struct xsk_socket_info)); xsk->umem = umem; ret = xsk_socket__create(&xsk->xsk, device, queue_id, umem->umem, rxr, &xsk->tx, cfg); @@ -1440,7 +1437,7 @@ create_umem_area(int nb_of_frames, int frame_size, int nb_of_completion_queue_de return umem; } -static struct xsk_socket_info * +struct xsk_socket_info * create_xsk_socket(struct xsk_umem_info *umem_info, int nb_of_tx_queue_desc, int nb_of_rx_queue_desc, @@ -1464,10 +1461,10 @@ create_xsk_socket(struct xsk_umem_info *umem_info, return xsk_info; } -/** +/* * gets the hardware address via Linux's PF packet interface */ -static struct tcpr_ether_addr * +static _U_ struct tcpr_ether_addr * sendpacket_get_hwaddr_libxdp(sendpacket_t *sp) { struct ifreq ifr; diff --git a/src/common/sendpacket.h b/src/common/sendpacket.h index b95b4934..73f2cddd 100644 --- a/src/common/sendpacket.h +++ b/src/common/sendpacket.h @@ -94,6 +94,7 @@ union sendpacket_handle { #ifdef HAVE_LIBXDP #include +#include #include #include @@ -212,7 +213,7 @@ struct sendpacket_s { unsigned int batch_size; unsigned int pckt_count; int frame_size; - int tx_idx; + unsigned int tx_idx; int tx_size; #endif bool abort; @@ -222,12 +223,12 @@ typedef struct sendpacket_s sendpacket_t; #ifdef HAVE_LIBXDP struct xsk_umem_info * create_umem_area(int nb_of_frames, int frame_size, int nb_of_completion_queue_descs, int nb_of_fill_queue_descs); -static struct xsk_socket_info *create_xsk_socket(struct xsk_umem_info *umem, - int nb_of_tx_queue_desc, - int nb_of_rx_queue_desc, - const char *device, - u_int32_t queue_id, - char *errbuf); +struct xsk_socket_info *create_xsk_socket(struct xsk_umem_info *umem, + int nb_of_tx_queue_desc, + int nb_of_rx_queue_desc, + const char *device, + u_int32_t queue_id, + char *errbuf); static inline void gen_eth_frame(struct xsk_umem_info *umem, u_int64_t addr, u_char *pkt_data, COUNTER pkt_size) { @@ -242,12 +243,13 @@ kick_tx(struct xsk_socket_info *xsk) return; } printf("%s\n", "Packet sending exited with error!"); - exit(ret); + exit (1); } + static inline void complete_tx_only(sendpacket_t *sp) { - int completion_idx = 0; + u_int32_t completion_idx = 0; if (sp->xsk_info->outstanding_tx == 0) { return; } @@ -255,7 +257,7 @@ complete_tx_only(sendpacket_t *sp) sp->xsk_info->app_stats.tx_wakeup_sendtos++; kick_tx(sp->xsk_info); } - unsigned int rcvd = xsk_ring_cons__peek(&sp->xsk_info->umem->cq, sp->pckt_count, &(completion_idx)); + unsigned int rcvd = xsk_ring_cons__peek(&sp->xsk_info->umem->cq, sp->pckt_count, &completion_idx); if (rcvd > 0) { xsk_ring_cons__release(&sp->xsk_info->umem->cq, rcvd); sp->xsk_info->outstanding_tx -= rcvd; diff --git a/src/send_packets.c b/src/send_packets.c index 69b8ce88..e9e445d9 100644 --- a/src/send_packets.c +++ b/src/send_packets.c @@ -386,7 +386,7 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx) * we've sent enough packets */ while (!ctx->abort && read_next_packet && - (pktdata = get_next_packet(ctx, pcap, &pkthdr, idx, prev_packet)) != NULL) { + (pktdata = get_next_packet(options, pcap, &pkthdr, idx, prev_packet)) != NULL) { now_is_now = false; packetnum++; #if defined TCPREPLAY || defined TCPREPLAY_EDIT @@ -515,7 +515,7 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx) #ifdef HAVE_LIBXDP if (sp->handle_type == SP_TYPE_LIBXDP) { /* Reserve frames for the batc h*/ - while (xsk_ring_prod__reserve(&(sp->xsk_info->tx), sp->batch_size, &(sp->tx_idx)) < sp->batch_size) { + while (xsk_ring_prod__reserve(&(sp->xsk_info->tx), sp->batch_size, &sp->tx_idx) < sp->batch_size) { complete_tx_only(sp); } /* The first packet is already in memory */ @@ -1315,8 +1315,8 @@ prepare_remaining_elements_of_batch(tcpreplay_t *ctx, } sp->pckt_count = pckt_count; dbgx(2, - "Sending packets with LIBXDP in batch, packet numbers from %llu to %llu\n", - packetnum - pckt_count + 1, - packetnum); + "Sending packets with LIBXDP in batch, packet numbers from " COUNTER_SPEC " to " COUNTER_SPEC "\n", + *packetnum - pckt_count + 1, + *packetnum); } #endif /* HAVE_LIBXDP */ diff --git a/src/tcpedit/plugins/dlt_en10mb/en10mb.c b/src/tcpedit/plugins/dlt_en10mb/en10mb.c index 0c24d8e5..957ce20d 100644 --- a/src/tcpedit/plugins/dlt_en10mb/en10mb.c +++ b/src/tcpedit/plugins/dlt_en10mb/en10mb.c @@ -184,7 +184,7 @@ dlt_en10mb_parse_subsmac(tcpeditdlt_t *ctx, en10mb_config_t *config, const char { size_t input_len = strlen(input); size_t possible_entries_number = (input_len / (SUBSMAC_ENTRY_LEN + 1)) + 1; - int entry; + size_t entry; en10mb_sub_entry_t *entries = safe_malloc(possible_entries_number * sizeof(en10mb_sub_entry_t)); @@ -524,7 +524,7 @@ dlt_en10mb_encode(tcpeditdlt_t *ctx, u_char *packet, int pktlen, tcpr_dir_t dir) newl2len = TCPR_802_1Q_H; } - if (pktlen < newl2len || pktlen + newl2len - ctx->l2len > MAXPACKET) { + if ((uint32_t)pktlen < newl2len || pktlen + newl2len - ctx->l2len > MAXPACKET) { tcpedit_seterr(ctx->tcpedit, "Unable to process packet #" COUNTER_SPEC " since its new length is %d bytes.", ctx->tcpedit->runtime.packetnum,