Skip to content

Commit

Permalink
Bug #695 remove FORCE_ALIGN
Browse files Browse the repository at this point in the history
macOS 11.6 mistakenly detected as a system that requires FORCE_ALIGN,
which caused many tcprewrite tests to fail. It appears that this code
has become broken over the years, and this bug was never detected. That's
because there probably aren't any ULTRA Sparc systems out there anymore.

Rather than attempting to fix, removed FORCE_ALIGN. Too bad if you still
run an ULTRA Sparc.
  • Loading branch information
fklassen committed Jan 28, 2022
1 parent 5628312 commit dd8a85a
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 188 deletions.
65 changes: 0 additions & 65 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
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 ##################################################
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
36 changes: 0 additions & 36 deletions src/common/get.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
42 changes: 2 additions & 40 deletions src/tcpedit/edit_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
}
Expand Down
7 changes: 0 additions & 7 deletions src/tcpedit/plugins/dlt_plugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
27 changes: 1 addition & 26 deletions src/tcpedit/plugins/dlt_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
2 changes: 0 additions & 2 deletions src/tcpedit/plugins_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
9 changes: 0 additions & 9 deletions src/tcpedit/tcpedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

Expand Down
3 changes: 0 additions & 3 deletions src/tcpedit/tcpedit_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand Down

0 comments on commit dd8a85a

Please sign in to comment.