diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2018-03-06 18:44:11 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2018-03-06 18:44:11 +0100 |
commit | 2af099cae27fef1a57aa25d48fc915d619ea216d (patch) | |
tree | ff661aad6ab62c6db94b68a3eacba930ffb87881 | |
parent | 18f5d4dde7ef18efa0489f2007f5ebeed89975ea (diff) |
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 <tklauser@distanz.ch>
-rw-r--r-- | built_in.h | 8 | ||||
-rw-r--r-- | csum.h | 8 | ||||
-rw-r--r-- | curve.c | 16 | ||||
-rw-r--r-- | netsniff-ng.c | 6 | ||||
-rw-r--r-- | pcap_mm.c | 8 | ||||
-rw-r--r-- | pcap_sg.c | 16 | ||||
-rw-r--r-- | ring.c | 4 | ||||
-rw-r--r-- | ring_rx.c | 4 | ||||
-rw-r--r-- | ring_tx.c | 4 | ||||
-rw-r--r-- | trafgen.c | 10 |
10 files changed, 39 insertions, 45 deletions
@@ -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 @@ -1,6 +1,8 @@ #ifndef CSUM_H #define CSUM_H +#include <string.h> + #include <netinet/in.h> #include <netinet/ip.h> #include <netinet/ip6.h> @@ -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; @@ -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); } @@ -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; @@ -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); @@ -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; @@ -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); @@ -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); @@ -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(); |