MFC r206021, r206032, r206049, r206050:

Remove some more alignment constraints.
This commit is contained in:
Alexander Motin 2010-04-15 12:46:16 +00:00
parent a35d181273
commit d9b0781af8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/stable/8/; revision=206661
5 changed files with 35 additions and 30 deletions

View File

@ -36,6 +36,7 @@
#include <sys/kernel.h>
#include <sys/mbuf.h>
#include <sys/malloc.h>
#include <sys/endian.h>
#include <sys/errno.h>
#include <sys/syslog.h>
@ -505,8 +506,8 @@ ng_deflate_compress(node_p node, struct mbuf *m, struct mbuf **resultp)
priv->stats.OutOctets+=inlen;
} else {
/* Install header. */
((u_int16_t *)priv->outbuf)[0] = htons(PROT_COMPD);
((u_int16_t *)priv->outbuf)[1] = htons(priv->seqnum);
be16enc(priv->outbuf, PROT_COMPD);
be16enc(priv->outbuf + 2, priv->seqnum);
/* Return packet in an mbuf. */
m_copyback(m, 0, outlen, (caddr_t)priv->outbuf);
@ -568,7 +569,7 @@ ng_deflate_decompress(node_p node, struct mbuf *m, struct mbuf **resultp)
proto = priv->inbuf[0];
offset = 1;
} else {
proto = ntohs(((uint16_t *)priv->inbuf)[0]);
proto = be16dec(priv->inbuf);
offset = 2;
}
@ -579,7 +580,7 @@ ng_deflate_decompress(node_p node, struct mbuf *m, struct mbuf **resultp)
priv->stats.FramesComp++;
/* Check sequence number. */
rseqnum = ntohs(((uint16_t *)(priv->inbuf + offset))[0]);
rseqnum = be16dec(priv->inbuf + offset);
offset += 2;
if (rseqnum != priv->seqnum) {
priv->stats.Errors++;

View File

@ -53,6 +53,7 @@
#include <sys/kernel.h>
#include <sys/mbuf.h>
#include <sys/malloc.h>
#include <sys/endian.h>
#include <sys/errno.h>
#include <sys/syslog.h>
@ -601,7 +602,7 @@ ng_mppc_compress(node_p node, struct mbuf **datap)
/* Install header */
M_PREPEND(m, MPPC_HDRLEN, M_DONTWAIT);
if (m != NULL)
*(mtod(m, uint16_t *)) = htons(header);
be16enc(mtod(m, void *), header);
*datap = m;
return (*datap == NULL ? ENOBUFS : 0);
@ -630,8 +631,7 @@ ng_mppc_decompress(node_p node, struct mbuf **datap)
m_freem(m);
return (EINVAL);
}
m_copydata(m, 0, MPPC_HDRLEN, (caddr_t)&header);
header = ntohs(header);
header = be16dec(mtod(m, void *));
cc = (header & MPPC_CCOUNT_MASK);
m_adj(m, MPPC_HDRLEN);

View File

@ -97,6 +97,7 @@
#include <sys/time.h>
#include <sys/mbuf.h>
#include <sys/malloc.h>
#include <sys/endian.h>
#include <sys/errno.h>
#include <sys/ctype.h>
@ -860,8 +861,8 @@ ng_ppp_rcvdata_bypass(hook_p hook, item_p item)
NG_FREE_ITEM(item);
return (ENOBUFS);
}
linkNum = ntohs(mtod(m, uint16_t *)[0]);
proto = ntohs(mtod(m, uint16_t *)[1]);
linkNum = be16dec(mtod(m, uint8_t *));
proto = be16dec(mtod(m, uint8_t *) + 2);
m_adj(m, 4);
NGI_M(item) = m;
@ -1544,7 +1545,7 @@ ng_ppp_mp_recv(node_p node, item_p item, uint16_t proto, uint16_t linkNum)
if (m->m_len < 2 && (m = m_pullup(m, 2)) == NULL)
ERROUT(ENOBUFS);
shdr = ntohs(*mtod(m, uint16_t *));
shdr = be16dec(mtod(m, void *));
frag->seq = MP_SHORT_EXTEND(shdr);
frag->first = (shdr & MP_SHORT_FIRST_FLAG) != 0;
frag->last = (shdr & MP_SHORT_LAST_FLAG) != 0;
@ -1561,7 +1562,7 @@ ng_ppp_mp_recv(node_p node, item_p item, uint16_t proto, uint16_t linkNum)
if (m->m_len < 4 && (m = m_pullup(m, 4)) == NULL)
ERROUT(ENOBUFS);
lhdr = ntohl(*mtod(m, uint32_t *));
lhdr = be32dec(mtod(m, void *));
frag->seq = MP_LONG_EXTEND(lhdr);
frag->first = (lhdr & MP_LONG_FIRST_FLAG) != 0;
frag->last = (lhdr & MP_LONG_LAST_FLAG) != 0;

View File

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

View File

@ -47,6 +47,7 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/endian.h>
#include <sys/errno.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
@ -410,9 +411,9 @@ correct_mss(struct tcphdr *tc, int hlen, uint16_t maxmss, int flags)
{
int olen, optlen;
u_char *opt;
uint16_t *mss;
int accumulate;
int res = 0;
uint16_t sum;
for (olen = hlen - sizeof(struct tcphdr), opt = (u_char *)(tc + 1);
olen > 0; olen -= optlen, opt += optlen) {
@ -427,13 +428,15 @@ correct_mss(struct tcphdr *tc, int hlen, uint16_t maxmss, int flags)
if (*opt == TCPOPT_MAXSEG) {
if (optlen != TCPOLEN_MAXSEG)
continue;
mss = (uint16_t *)(opt + 2);
if (ntohs(*mss) > maxmss) {
accumulate = *mss;
*mss = htons(maxmss);
accumulate -= *mss;
if ((flags & CSUM_TCP) == 0)
TCPMSS_ADJUST_CHECKSUM(accumulate, tc->th_sum);
accumulate = be16dec(opt + 2);
if (accumulate > maxmss) {
if ((flags & CSUM_TCP) == 0) {
accumulate -= maxmss;
sum = be16dec(&tc->th_sum);
TCPMSS_ADJUST_CHECKSUM(accumulate, sum);
be16enc(&tc->th_sum, sum);
}
be16enc(opt + 2, maxmss);
res = 1;
}
}