From 2af099cae27fef1a57aa25d48fc915d619ea216d Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 6 Mar 2018 18:44:11 +0100 Subject: all: drop fmem{cpy,set} There is no need to explicity use the builtins. According to [1], GCC will recognize mem{cpy,set} as built-in functions, unless the corresponding -fno-builtin-* option is specified (which is not the case for netsniff-ng). [1] https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html Signed-off-by: Tobias Klauser --- built_in.h | 8 -------- csum.h | 8 +++++--- curve.c | 16 ++++++++-------- netsniff-ng.c | 6 +++--- pcap_mm.c | 8 ++++---- pcap_sg.c | 16 ++++++++-------- ring.c | 4 ++-- ring_rx.c | 4 ++-- ring_tx.c | 4 ++-- trafgen.c | 10 +++++----- 10 files changed, 39 insertions(+), 45 deletions(-) diff --git a/built_in.h b/built_in.h index da04dbd..24af1bc 100644 --- a/built_in.h +++ b/built_in.h @@ -65,14 +65,6 @@ typedef uint8_t u8; # define constant(x) __builtin_constant_p(x) #endif -#ifndef fmemset -# define fmemset __builtin_memset -#endif - -#ifndef fmemcpy -# define fmemcpy __builtin_memcpy -#endif - #ifndef __maybe_unused # define __maybe_unused __attribute__((__unused__)) #endif diff --git a/csum.h b/csum.h index 96211c5..0470dcb 100644 --- a/csum.h +++ b/csum.h @@ -1,6 +1,8 @@ #ifndef CSUM_H #define CSUM_H +#include + #include #include #include @@ -182,10 +184,10 @@ static inline uint16_t p6_csum(const struct ip6_hdr *ip6, const uint8_t *data, uint8_t proto; } __packed ph; - fmemcpy(&ph.src, ip6->ip6_src.s6_addr, sizeof(ph.src)); - fmemcpy(&ph.dst, ip6->ip6_dst.s6_addr, sizeof(ph.dst)); + memcpy(&ph.src, ip6->ip6_src.s6_addr, sizeof(ph.src)); + memcpy(&ph.dst, ip6->ip6_dst.s6_addr, sizeof(ph.dst)); ph.len = htons(len); - fmemset(&ph.mbz, 0, sizeof(ph.mbz)); + memset(&ph.mbz, 0, sizeof(ph.mbz)); ph.proto = next_proto; vec[0].ptr = (const uint8_t *) (void *) &ph; diff --git a/curve.c b/curve.c index 319991b..75354ab 100644 --- a/curve.c +++ b/curve.c @@ -79,8 +79,8 @@ void curve25519_proto_init(struct curve25519_proto *proto, unsigned char secretkey_own[crypto_box_sec_key_size]; unsigned char publickey_own[crypto_box_pub_key_size]; - fmemset(secretkey_own, 0, sizeof(secretkey_own)); - fmemset(publickey_own, 0, sizeof(publickey_own)); + memset(secretkey_own, 0, sizeof(secretkey_own)); + memset(publickey_own, 0, sizeof(publickey_own)); if (unlikely(!pubkey_remote || len != sizeof(publickey_own))) panic("Invalid argument on curve25519_proto_init!\n"); @@ -96,8 +96,8 @@ void curve25519_proto_init(struct curve25519_proto *proto, crypto_box_beforenm(proto->key, pubkey_remote, secretkey_own); - fmemset(proto->enonce, 0, sizeof(proto->enonce)); - fmemset(proto->dnonce, 0, sizeof(proto->dnonce)); + memset(proto->enonce, 0, sizeof(proto->enonce)); + memset(proto->dnonce, 0, sizeof(proto->dnonce)); xmemset(secretkey_own, 0, sizeof(secretkey_own)); xmemset(publickey_own, 0, sizeof(publickey_own)); @@ -121,7 +121,7 @@ ssize_t curve25519_encode(struct curve25519_struct *curve, taia_now(&packet_taia); taia_pack(NONCE_EDN_OFFSET(proto->enonce), &packet_taia); - fmemset(curve->enc, 0, curve->enc_size); + memset(curve->enc, 0, curve->enc_size); ret = crypto_box_afternm(curve->enc, plaintext, size, proto->enonce, proto->key); if (unlikely(ret)) { @@ -129,7 +129,7 @@ ssize_t curve25519_encode(struct curve25519_struct *curve, goto out; } - fmemcpy(NONCE_PKT_OFFSET(curve->enc), + memcpy(NONCE_PKT_OFFSET(curve->enc), NONCE_EDN_OFFSET(proto->enonce), NONCE_LENGTH); for (i = 0; i < NONCE_RND_LENGTH; ++i) curve->enc[i] = (uint8_t) secrand(); @@ -167,9 +167,9 @@ ssize_t curve25519_decode(struct curve25519_struct *curve, goto out; } - fmemcpy(NONCE_EDN_OFFSET(proto->dnonce), + memcpy(NONCE_EDN_OFFSET(proto->dnonce), NONCE_PKT_OFFSET(ciphertext), NONCE_LENGTH); - fmemset(curve->dec, 0, curve->dec_size); + memset(curve->dec, 0, curve->dec_size); ret = crypto_box_open_afternm(curve->dec, ciphertext, size, proto->dnonce, proto->key); diff --git a/netsniff-ng.c b/netsniff-ng.c index 2c41a33..cbd837b 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -515,7 +515,7 @@ static void receive_to_xmit(struct ctx *ctx) } tpacket_hdr_clone(&hdr_out->tp_h, &hdr_in->tp_h); - fmemcpy(out, in, hdr_in->tp_h.tp_len); + memcpy(out, in, hdr_in->tp_h.tp_len); kernel_may_pull_from_tx(&hdr_out->tp_h); if (ctx->randomize) @@ -660,7 +660,7 @@ static void read_pcap(struct ctx *ctx) panic("Error prepare reading pcap!\n"); } - fmemset(&fm, 0, sizeof(fm)); + memset(&fm, 0, sizeof(fm)); bpf_parse_rules(ctx->filter, &bpf_ops, ctx->link_type); if (ctx->dump_bpf) @@ -786,7 +786,7 @@ static void finish_multi_pcap_file(struct ctx *ctx, int fd) close(fd); - fmemset(&itimer, 0, sizeof(itimer)); + memset(&itimer, 0, sizeof(itimer)); setitimer(ITIMER_REAL, &itimer, NULL); } diff --git a/pcap_mm.c b/pcap_mm.c index f7b248e..75ee0af 100644 --- a/pcap_mm.c +++ b/pcap_mm.c @@ -56,9 +56,9 @@ static ssize_t pcap_mm_write(int fd, pcap_pkthdr_t *phdr, enum pcap_type type, if ((off_t) (ptr_va_curr - ptr_va_start) + hdrsize + len > map_size) __pcap_mmap_write_need_remap(fd); - fmemcpy(ptr_va_curr, &phdr->raw, hdrsize); + memcpy(ptr_va_curr, &phdr->raw, hdrsize); ptr_va_curr += hdrsize; - fmemcpy(ptr_va_curr, packet, len); + memcpy(ptr_va_curr, packet, len); ptr_va_curr += len; return hdrsize + len; @@ -72,7 +72,7 @@ static ssize_t pcap_mm_read(int fd __maybe_unused, pcap_pkthdr_t *phdr, if (unlikely((off_t) (ptr_va_curr + hdrsize - ptr_va_start) > (off_t) map_size)) return -EIO; - fmemcpy(&phdr->raw, ptr_va_curr, hdrsize); + memcpy(&phdr->raw, ptr_va_curr, hdrsize); ptr_va_curr += hdrsize; hdrlen = pcap_get_length(phdr, type); @@ -81,7 +81,7 @@ static ssize_t pcap_mm_read(int fd __maybe_unused, pcap_pkthdr_t *phdr, if (unlikely(hdrlen == 0 || hdrlen > len)) return -EINVAL; - fmemcpy(packet, ptr_va_curr, hdrlen); + memcpy(packet, ptr_va_curr, hdrlen); ptr_va_curr += hdrlen; return hdrsize + hdrlen; diff --git a/pcap_sg.c b/pcap_sg.c index 80c2c5d..60dc1b2 100644 --- a/pcap_sg.c +++ b/pcap_sg.c @@ -33,10 +33,10 @@ static ssize_t pcap_sg_write(int fd, pcap_pkthdr_t *phdr, enum pcap_type type, iov_slot = 0; } - fmemcpy(iov[iov_slot].iov_base, &phdr->raw, hdrsize); + memcpy(iov[iov_slot].iov_base, &phdr->raw, hdrsize); iov[iov_slot].iov_len = hdrsize; - fmemcpy(iov[iov_slot].iov_base + iov[iov_slot].iov_len, packet, len); + memcpy(iov[iov_slot].iov_base + iov[iov_slot].iov_len, packet, len); ret = (iov[iov_slot].iov_len += len); iov_slot++; @@ -57,7 +57,7 @@ static ssize_t __pcap_sg_inter_iov_hdr_read(int fd, pcap_pkthdr_t *phdr, bug_on(offset + remainder != hdrsize); - fmemcpy(&phdr->raw, iov[iov_slot].iov_base + iov_off_rd, offset); + memcpy(&phdr->raw, iov[iov_slot].iov_base + iov_off_rd, offset); iov_off_rd = 0; iov_slot++; @@ -68,7 +68,7 @@ static ssize_t __pcap_sg_inter_iov_hdr_read(int fd, pcap_pkthdr_t *phdr, return -EIO; } - fmemcpy(&phdr->raw + offset, iov[iov_slot].iov_base + iov_off_rd, remainder); + memcpy(&phdr->raw + offset, iov[iov_slot].iov_base + iov_off_rd, remainder); iov_off_rd += remainder; return hdrsize; @@ -87,7 +87,7 @@ static ssize_t __pcap_sg_inter_iov_data_read(int fd, uint8_t *packet, size_t hdr bug_on(offset + remainder != hdrlen); - fmemcpy(packet, iov[iov_slot].iov_base + iov_off_rd, offset); + memcpy(packet, iov[iov_slot].iov_base + iov_off_rd, offset); iov_off_rd = 0; iov_slot++; @@ -98,7 +98,7 @@ static ssize_t __pcap_sg_inter_iov_data_read(int fd, uint8_t *packet, size_t hdr return -EIO; } - fmemcpy(packet + offset, iov[iov_slot].iov_base + iov_off_rd, remainder); + memcpy(packet + offset, iov[iov_slot].iov_base + iov_off_rd, remainder); iov_off_rd += remainder; return hdrlen; @@ -111,7 +111,7 @@ static ssize_t pcap_sg_read(int fd, pcap_pkthdr_t *phdr, enum pcap_type type, size_t hdrsize = pcap_get_hdr_length(phdr, type), hdrlen; if (likely(iov[iov_slot].iov_len - iov_off_rd >= hdrsize)) { - fmemcpy(&phdr->raw, iov[iov_slot].iov_base + iov_off_rd, hdrsize); + memcpy(&phdr->raw, iov[iov_slot].iov_base + iov_off_rd, hdrsize); iov_off_rd += hdrsize; } else { ret = __pcap_sg_inter_iov_hdr_read(fd, phdr, hdrsize); @@ -124,7 +124,7 @@ static ssize_t pcap_sg_read(int fd, pcap_pkthdr_t *phdr, enum pcap_type type, return -EINVAL; if (likely(iov[iov_slot].iov_len - iov_off_rd >= hdrlen)) { - fmemcpy(packet, iov[iov_slot].iov_base + iov_off_rd, hdrlen); + memcpy(packet, iov[iov_slot].iov_base + iov_off_rd, hdrlen); iov_off_rd += hdrlen; } else { ret = __pcap_sg_inter_iov_data_read(fd, packet, hdrlen); diff --git a/ring.c b/ring.c index b5c626c..00f54e5 100644 --- a/ring.c +++ b/ring.c @@ -23,7 +23,7 @@ void setup_ring_layout_generic(struct ring *ring, size_t size, bool jumbo_support) { - fmemset(&ring->layout, 0, sizeof(ring->layout)); + memset(&ring->layout, 0, sizeof(ring->layout)); ring->layout.tp_block_size = (jumbo_support ? RUNTIME_PAGE_SIZE << 4 : @@ -65,7 +65,7 @@ void bind_ring_generic(int sock, struct ring *ring, int ifindex, bool tx_only) * dev_add_pack(), so we have one single RX_RING for all devs * otherwise you'll get the packet twice. */ - fmemset(&ring->s_ll, 0, sizeof(ring->s_ll)); + memset(&ring->s_ll, 0, sizeof(ring->s_ll)); ring->s_ll.sll_family = AF_PACKET; ring->s_ll.sll_ifindex = ifindex; diff --git a/ring_rx.c b/ring_rx.c index 99f8da0..13c86b4 100644 --- a/ring_rx.c +++ b/ring_rx.c @@ -132,7 +132,7 @@ void destroy_rx_ring(int sock, struct ring *ring) if (v3) return; - fmemset(&ring->layout, 0, sizeof(ring->layout)); + memset(&ring->layout, 0, sizeof(ring->layout)); ret = setsockopt(sock, SOL_PACKET, PACKET_RX_RING, &ring->layout, sizeof(ring->layout)); if (unlikely(ret)) @@ -218,7 +218,7 @@ void ring_rx_setup(struct ring *ring, int sock, size_t size, int ifindex, struct pollfd *poll, bool v3, bool jumbo_support, bool verbose, uint32_t fanout_group, uint32_t fanout_type) { - fmemset(ring, 0, sizeof(*ring)); + memset(ring, 0, sizeof(*ring)); setup_rx_ring_layout(sock, ring, size, jumbo_support, v3); create_rx_ring(sock, ring, verbose); mmap_ring_generic(sock, ring); diff --git a/ring_tx.c b/ring_tx.c index 4041bc4..d7f602b 100644 --- a/ring_tx.c +++ b/ring_tx.c @@ -37,7 +37,7 @@ void destroy_tx_ring(int sock, struct ring *ring) munmap(ring->mm_space, ring->mm_len); ring->mm_len = 0; - fmemset(&ring->layout, 0, sizeof(ring->layout)); + memset(&ring->layout, 0, sizeof(ring->layout)); ret = setsockopt(sock, SOL_PACKET, PACKET_TX_RING, &ring->layout, sizeof(ring->layout)); if (unlikely(ret)) @@ -89,7 +89,7 @@ static void alloc_tx_ring_frames(int sock __maybe_unused, struct ring *ring) void ring_tx_setup(struct ring *ring, int sock, size_t size, int ifindex, bool jumbo_support, bool verbose) { - fmemset(ring, 0, sizeof(*ring)); + memset(ring, 0, sizeof(*ring)); set_packet_loss_discard(sock); setup_tx_ring_layout(sock, ring, size, jumbo_support); create_tx_ring(sock, ring, verbose); diff --git a/trafgen.c b/trafgen.c index 0996703..d9e0e0e 100644 --- a/trafgen.c +++ b/trafgen.c @@ -343,7 +343,7 @@ static void apply_csum16(int id) uint16_t sum = 0; struct csum16 *csum = &packet_dyn[id].csum[j]; - fmemset(&packets[id].payload[csum->off], 0, sizeof(sum)); + memset(&packets[id].payload[csum->off], 0, sizeof(sum)); if (unlikely((size_t) csum->to >= packets[id].len)) csum->to = packets[id].len - 1; @@ -381,7 +381,7 @@ static void apply_csum16(int id) break; } - fmemcpy(&packets[id].payload[csum->off], &sum, sizeof(sum)); + memcpy(&packets[id].payload[csum->off], &sum, sizeof(sum)); } } @@ -490,7 +490,7 @@ static int xmit_smoke_probe(int icmp_sock, struct ctx *ctx) .events = POLLIN, }; - fmemset(idstore, 0, sizeof(idstore)); + memset(idstore, 0, sizeof(idstore)); for (j = 0; j < SMOKE_N_PROBES; j++) { while ((ident = htons((short) rand())) == 0) sleep(0); @@ -776,7 +776,7 @@ static void xmit_fastpath_or_die(struct ctx *ctx, unsigned int cpu, unsigned lon packet_apply_dyn_elements(i); - fmemcpy(out, packets[i].payload, packets[i].len); + memcpy(out, packets[i].payload, packets[i].len); tx_bytes += packets[i].len; tx_packets++; @@ -1021,7 +1021,7 @@ int main(int argc, char **argv) enum shaper_type shape_type; struct timespec delay; - fmemset(&ctx, 0, sizeof(ctx)); + memset(&ctx, 0, sizeof(ctx)); ctx.cpus = get_number_cpus_online(); ctx.uid = getuid(); ctx.gid = getgid(); -- cgit v1.2.3-54-g00ecf