Remove alignment constraints.

This commit is contained in:
Alexander Motin 2010-04-01 16:20:36 +00:00
parent b652a5fa66
commit 38f2d636ca

View File

@ -62,6 +62,7 @@
#include <sys/malloc.h> #include <sys/malloc.h>
#include <sys/mbuf.h> #include <sys/mbuf.h>
#include <sys/mutex.h> #include <sys/mutex.h>
#include <sys/endian.h>
#include <sys/errno.h> #include <sys/errno.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -572,9 +573,9 @@ ng_pptpgre_xmit(hpriv_p hpriv, item_p item)
} }
/* Build GRE header */ /* Build GRE header */
((u_int32_t *)gre)[0] = htonl(PPTP_INIT_VALUE); be32enc(gre, PPTP_INIT_VALUE);
gre->length = (m != NULL) ? htons((u_short)m->m_pkthdr.len) : 0; be16enc(&gre->length, (m != NULL) ? m->m_pkthdr.len : 0);
gre->cid = htons(hpriv->conf.peerCid); be16enc(&gre->cid, hpriv->conf.peerCid);
/* Include sequence number if packet contains any data */ /* Include sequence number if packet contains any data */
if (m != NULL) { if (m != NULL) {
@ -584,13 +585,13 @@ ng_pptpgre_xmit(hpriv_p hpriv, item_p item)
= ng_pptpgre_time(); = ng_pptpgre_time();
} }
hpriv->xmitSeq++; hpriv->xmitSeq++;
gre->data[0] = htonl(hpriv->xmitSeq); be32enc(&gre->data[0], hpriv->xmitSeq);
} }
/* Include acknowledgement (and stop send ack timer) if needed */ /* Include acknowledgement (and stop send ack timer) if needed */
if (hpriv->conf.enableAlwaysAck || hpriv->xmitAck != hpriv->recvSeq) { if (hpriv->conf.enableAlwaysAck || hpriv->xmitAck != hpriv->recvSeq) {
gre->hasAck = 1; gre->hasAck = 1;
gre->data[gre->hasSeq] = htonl(hpriv->recvSeq); be32enc(&gre->data[gre->hasSeq], hpriv->recvSeq);
hpriv->xmitAck = hpriv->recvSeq; hpriv->xmitAck = hpriv->recvSeq;
if (hpriv->conf.enableDelayedAck) if (hpriv->conf.enableDelayedAck)
ng_uncallout(&hpriv->sackTimer, hpriv->node); ng_uncallout(&hpriv->sackTimer, hpriv->node);
@ -705,18 +706,17 @@ ng_pptpgre_rcvdata_lower(hook_p hook, item_p item)
/* Sanity check packet length and GRE header bits */ /* Sanity check packet length and GRE header bits */
extralen = m->m_pkthdr.len extralen = m->m_pkthdr.len
- (iphlen + grelen + gre->hasSeq * (u_int16_t)ntohs(gre->length)); - (iphlen + grelen + gre->hasSeq * be16dec(&gre->length));
if (extralen < 0) { if (extralen < 0) {
priv->stats.recvBadGRE++; priv->stats.recvBadGRE++;
ERROUT(EINVAL); ERROUT(EINVAL);
} }
if ((ntohl(*((const u_int32_t *)gre)) & PPTP_INIT_MASK) if ((be32dec(gre) & PPTP_INIT_MASK) != PPTP_INIT_VALUE) {
!= PPTP_INIT_VALUE) {
priv->stats.recvBadGRE++; priv->stats.recvBadGRE++;
ERROUT(EINVAL); ERROUT(EINVAL);
} }
hpriv = ng_pptpgre_find_session(priv, ntohs(gre->cid)); hpriv = ng_pptpgre_find_session(priv, be16dec(&gre->cid));
if (hpriv == NULL || hpriv->hook == NULL || !hpriv->conf.enabled) { if (hpriv == NULL || hpriv->hook == NULL || !hpriv->conf.enabled) {
priv->stats.recvBadCID++; priv->stats.recvBadCID++;
ERROUT(EINVAL); ERROUT(EINVAL);
@ -725,7 +725,7 @@ ng_pptpgre_rcvdata_lower(hook_p hook, item_p item)
/* Look for peer ack */ /* Look for peer ack */
if (gre->hasAck) { if (gre->hasAck) {
const u_int32_t ack = ntohl(gre->data[gre->hasSeq]); const u_int32_t ack = be32dec(&gre->data[gre->hasSeq]);
const int index = ack - hpriv->recvAck - 1; const int index = ack - hpriv->recvAck - 1;
long sample; long sample;
long diff; long diff;
@ -776,7 +776,7 @@ badAck:
/* See if frame contains any data */ /* See if frame contains any data */
if (gre->hasSeq) { if (gre->hasSeq) {
const u_int32_t seq = ntohl(gre->data[0]); const u_int32_t seq = be32dec(&gre->data[0]);
/* Sanity check sequence number */ /* Sanity check sequence number */
if (PPTP_SEQ_DIFF(seq, hpriv->recvSeq) <= 0) { if (PPTP_SEQ_DIFF(seq, hpriv->recvSeq) <= 0) {