diff --git a/configure.ac b/configure.ac index 573547e3..372e8910 100644 --- a/configure.ac +++ b/configure.ac @@ -1699,71 +1699,6 @@ fi fi # checking pcapnav version - -dnl (shamelessly ripped off from libpcap) -dnl Checks to see if unaligned memory accesses fail -dnl -dnl FORCE_ALIGN (DEFINED) -dnl -AC_MSG_CHECKING(for requires strict byte alignment) -AC_CACHE_VAL(unaligned_cv_fail, - [case "$host_cpu" in - - # XXX: should also check that they don't do weird things (like on arm) - alpha*|arm*|hp*|mips*|sparc*|ia64) - unaligned_cv_fail=yes - ;; - - *) - cat >conftest.c < - #include - #include - unsigned char a[[5]] = { 1, 2, 3, 4, 5 }; - main() { - unsigned int i; - pid_t pid; - int status; - /* avoid "core dumped" message */ - pid = fork(); - if (pid < 0) - exit(2); - if (pid > 0) { - /* parent */ - pid = waitpid(pid, &status, 0); - if (pid < 0) - exit(3); - exit(!WIFEXITED(status)); - } - /* child */ - i = *(unsigned int *)&a[[1]]; - printf("%d\n", i); - exit(0); - } -EOF - ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \ - conftest.c $LIBS >/dev/null 2>&1 - if test ! -x conftest ; then - dnl failed to compile for some reason - unaligned_cv_fail=yes - else - ./conftest >conftest.out - if test ! -s conftest.out ; then - unaligned_cv_fail=yes - else - unaligned_cv_fail=no - fi - fi - rm -f conftest* core core.conftest - ;; - - esac - ]) -AC_MSG_RESULT($unaligned_cv_fail) -if test $unaligned_cv_fail = yes ; then - AC_DEFINE([FORCE_ALIGN], [1], [Are we strictly aligned?]) -fi - dnl ################################################## dnl # Check for tcpdump. dnl ################################################## diff --git a/docs/CHANGELOG b/docs/CHANGELOG index f3b12e63..9da2347a 100644 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -1,4 +1,5 @@ 06/19/2021 Version 4.4.0-beta2 + - remove obsolete FORCE_ALIGN support to fix macOS 11 compile (#695) - add a security policy document (#689) - ability to specify directory of pcap files (#682) - incorrect PPS rate for long-running sessions (#679) diff --git a/src/common/get.c b/src/common/get.c index 19b7fd15..0011e275 100644 --- a/src/common/get.c +++ b/src/common/get.c @@ -460,29 +460,11 @@ get_ipv4(const u_char *pktdata, int datalen, int datalink, u_char **newbuff) l2len -= l2offset; pkt_len -= l2offset; -#ifdef FORCE_ALIGN - /* - * copy layer 3 and up to our temp packet buffer - * for now on, we have to edit the packetbuff because - * just before we send the packet, we copy the packetbuff - * back onto the pkt.data + l2len buffer - * we do all this work to prevent byte alignment issues - */ - if (l2len % sizeof(long)) { - memcpy(*newbuff, (packet + l2len), (pkt_len - l2len)); - ip_hdr = *newbuff; - } else { - - /* we don't have to do a memcpy if l2len lands on a boundary */ - ip_hdr = (packet + l2len); - } -#else /* * on non-strict byte align systems, don't need to memcpy(), * just point to l2len bytes into the existing buffer */ ip_hdr = (packet + l2len); -#endif return ip_hdr; } @@ -535,29 +517,11 @@ get_ipv6(const u_char *pktdata, int datalen, int datalink, u_char **newbuff) l2len -= l2offset; pkt_len -= l2offset; -#ifdef FORCE_ALIGN - /* - * copy layer 3 and up to our temp packet buffer - * for now on, we have to edit the packetbuff because - * just before we send the packet, we copy the packetbuff - * back onto the pkt.data + l2len buffer - * we do all this work to prevent byte alignment issues - */ - if (l2len % sizeof(long)) { - memcpy(*newbuff, (packet + l2len), (pkt_len - l2len)); - ip6_hdr = *newbuff; - } else { - - /* we don't have to do a memcpy if l2len lands on a boundary */ - ip6_hdr = (packet + l2len); - } -#else /* * on non-strict byte align systems, don't need to memcpy(), * just point to l2len bytes into the existing buffer */ ip6_hdr = (packet + l2len); -#endif return ip6_hdr; } diff --git a/src/tcpedit/edit_packet.c b/src/tcpedit/edit_packet.c index c5d7b0b4..6932c6a9 100644 --- a/src/tcpedit/edit_packet.c +++ b/src/tcpedit/edit_packet.c @@ -953,9 +953,6 @@ randomize_iparp(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, { arp_hdr_t *arp_hdr ; int l2len; -#ifdef FORCE_ALIGN - uint32_t iptemp; -#endif assert(tcpedit); assert(pkthdr); @@ -982,30 +979,12 @@ randomize_iparp(tcpedit_t *tcpedit, struct pcap_pkthdr *pkthdr, u_char *add_hdr = ((u_char *)arp_hdr) + sizeof(arp_hdr_t) + arp_hdr->ar_hln; -#ifdef FORCE_ALIGN - /* copy IP to a temporary buffer for processing */ - memcpy(&iptemp, add_hdr, sizeof(uint32_t)); - ip = &iptemp; -#else ip = (uint32_t *)add_hdr; -#endif *ip = randomize_ipv4_addr(tcpedit, *ip); -#ifdef FORCE_ALIGN - memcpy(add_hdr, &iptemp, sizeof(uint32_t)); -#endif add_hdr += arp_hdr->ar_pln + arp_hdr->ar_hln; -#ifdef FORCE_ALIGN - /* copy IP2 to a temporary buffer for processing */ - memcpy(&iptemp, add_hdr, sizeof(uint32_t)); - ip = &iptemp; -#else ip = (uint32_t *)add_hdr; -#endif *ip = randomize_ipv4_addr(tcpedit, *ip); -#ifdef FORCE_ALIGN - memcpy(add_hdr, &iptemp, sizeof(uint32_t)); -#endif } return 1; /* yes we changed the packet */ @@ -1027,9 +1006,6 @@ rewrite_iparp(tcpedit_t *tcpedit, arp_hdr_t *arp_hdr, int cache_mode) uint32_t newip = 0; tcpr_cidrmap_t *cidrmap1 = NULL, *cidrmap2 = NULL; int didsrc = 0, diddst = 0, loop = 1; -#ifdef FORCE_ALIGN - uint32_t iptemp; -#endif assert(tcpedit); assert(arp_hdr); @@ -1061,14 +1037,7 @@ rewrite_iparp(tcpedit_t *tcpedit, arp_hdr_t *arp_hdr, int cache_mode) add_hdr += sizeof(arp_hdr_t) + arp_hdr->ar_hln; ip1 = (uint32_t *)add_hdr; add_hdr += arp_hdr->ar_pln + arp_hdr->ar_hln; -#ifdef FORCE_ALIGN - /* copy IP2 to a temporary buffer for processing */ - memcpy(&iptemp, add_hdr, sizeof(uint32_t)); - ip2 = &iptemp; -#else ip2 = (uint32_t *)add_hdr; -#endif - /* loop through the cidrmap to rewrite */ do { @@ -1099,31 +1068,24 @@ rewrite_iparp(tcpedit_t *tcpedit, arp_hdr_t *arp_hdr, int cache_mode) } } -#ifdef FORCE_ALIGN - /* copy temporary IP to IP2 location in buffer */ - memcpy(add_hdr, &iptemp, sizeof(uint32_t)); -#endif - /* * loop while we haven't modified both src/dst AND * at least one of the cidr maps have a next pointer */ if ((! (diddst && didsrc)) && (! ((cidrmap1->next == NULL) && (cidrmap2->next == NULL)))) { - + /* increment our ptr's if possible */ if (cidrmap1->next != NULL) cidrmap1 = cidrmap1->next; - + if (cidrmap2->next != NULL) cidrmap2 = cidrmap2->next; - } else { loop = 0; } } while (loop); - } else { warn("ARP packet isn't for IPv4! Can't rewrite IP's"); } diff --git a/src/tcpedit/plugins/dlt_plugins.c b/src/tcpedit/plugins/dlt_plugins.c index c878e42c..b0b01382 100644 --- a/src/tcpedit/plugins/dlt_plugins.c +++ b/src/tcpedit/plugins/dlt_plugins.c @@ -130,9 +130,6 @@ tcpedit_dlt_init(tcpedit_t *tcpedit, const int srcdlt) ctx = (tcpeditdlt_t *)safe_malloc(sizeof(tcpeditdlt_t)); /* do we need a side buffer for L3 data? */ -#ifdef FORCE_ALIGN - ctx->l3buff = (u_char *)safe_malloc(MAXPACKET); -#endif /* copy our tcpedit context */ ctx->tcpedit = tcpedit; @@ -469,10 +466,6 @@ tcpedit_dlt_cleanup(tcpeditdlt_t *ctx) plugin = plugin_next; } -#ifdef FORCE_ALIGN - safe_free(ctx->l3buff); -#endif - if (ctx->decoded_extra != NULL) { safe_free(ctx->decoded_extra); ctx->decoded_extra = NULL; diff --git a/src/tcpedit/plugins/dlt_utils.c b/src/tcpedit/plugins/dlt_utils.c index 028f7749..e57db118 100644 --- a/src/tcpedit/plugins/dlt_utils.c +++ b/src/tcpedit/plugins/dlt_utils.c @@ -203,28 +203,11 @@ tcpedit_dlt_l3data_copy(tcpeditdlt_t *ctx, u_char *packet, int pktlen, int l2len if (pktlen <= l2len) return NULL; - -#ifdef FORCE_ALIGN - /* - * copy layer 3 and up to our temp packet buffer - * for now on, we have to edit the packetbuff because - * just before we send the packet, we copy the packetbuff - * back onto the pkt.data + l2len buffer - * we do all this work to prevent byte alignment issues - */ - if (l2len % 4 == 0) { - ptr = (&(packet)[l2len]); - } else { - ptr = ctx->l3buff; - memcpy(ptr, (&(packet)[l2len]), pktlen - l2len); - } -#else + /* - * on non-strict byte align systems, don't need to memcpy(), * just point to 14 bytes into the existing buffer */ ptr = (&(packet)[l2len]); -#endif return ptr; } @@ -239,14 +222,6 @@ tcpedit_dlt_l3data_merge(tcpeditdlt_t *ctx, u_char *packet, int pktlen, const u_ assert(pktlen >= 0); assert(l3data); assert(l2len >= 0); -#ifdef FORCE_ALIGN - /* - * put back the layer 3 and above back in the pkt.data buffer - * we can't edit the packet at layer 3 or above beyond this point - */ - if (l2len % 4 != 0) - memcpy((&(packet)[l2len]), l3data, pktlen - l2len); -#endif return packet; } diff --git a/src/tcpedit/plugins_types.h b/src/tcpedit/plugins_types.h index b3518807..e53ff74f 100644 --- a/src/tcpedit/plugins_types.h +++ b/src/tcpedit/plugins_types.h @@ -103,9 +103,7 @@ struct tcpeditdlt_plugin_s { */ struct tcpeditdlt_s { tcpedit_t *tcpedit; /* pointer to our tcpedit context */ -#ifdef FORCE_ALIGN u_char *l3buff; /* pointer for L3 buffer on strictly aligned systems */ -#endif tcpeditdlt_plugin_t *plugins; /* registered plugins */ tcpeditdlt_plugin_t *decoder; /* Encoder plugin */ tcpeditdlt_plugin_t *encoder; /* Decoder plugin */ diff --git a/src/tcpedit/tcpedit.c b/src/tcpedit/tcpedit.c index 2f48719c..1cd528f7 100644 --- a/src/tcpedit/tcpedit.c +++ b/src/tcpedit/tcpedit.c @@ -401,10 +401,6 @@ tcpedit_init(tcpedit_t **tcpedit_ex, int dlt) dbgx(1, "Input file (1) datalink type is %s", pcap_datalink_val_to_name(dlt)); -#ifdef FORCE_ALIGN - tcpedit->runtime.l3buff = (u_char *)safe_malloc(MAXPACKET); -#endif - return TCPEDIT_OK; } @@ -619,11 +615,6 @@ tcpedit_close(tcpedit_t **tcpedit_ex) tcpedit->portmap = NULL; } -#ifdef FORCE_ALIGN - safe_free(tcpedit->runtime.l3buff); - tcpedit->runtime.l3buff = NULL; -#endif - safe_free(*tcpedit_ex); *tcpedit_ex = NULL; diff --git a/src/tcpedit/tcpedit_types.h b/src/tcpedit/tcpedit_types.h index d3210458..c213fd8b 100644 --- a/src/tcpedit/tcpedit_types.h +++ b/src/tcpedit/tcpedit_types.h @@ -69,9 +69,6 @@ typedef struct { int dlt2; char errstr[TCPEDIT_ERRSTR_LEN]; char warnstr[TCPEDIT_ERRSTR_LEN]; -#ifdef FORCE_ALIGN - u_char *l3buff; -#endif } tcpedit_runtime_t; /*