CMSG_XXX macros alignment fixes to follow RFC2292.
Approved by: jkh Submitted by: Partly from tech@openbsd Reviewed by: itojun
This commit is contained in:
parent
e3ca50a712
commit
d72ee94428
@ -63,7 +63,9 @@ inet6_rthdr_init(bp, type)
|
|||||||
int type;
|
int type;
|
||||||
{
|
{
|
||||||
register struct cmsghdr *ch = (struct cmsghdr *)bp;
|
register struct cmsghdr *ch = (struct cmsghdr *)bp;
|
||||||
register struct ip6_rthdr *rthdr = (struct ip6_rthdr *)(ch + 1);
|
register struct ip6_rthdr *rthdr;
|
||||||
|
|
||||||
|
rthdr = (struct ip6_rthdr *)CMSG_DATA(ch);
|
||||||
|
|
||||||
ch->cmsg_level = IPPROTO_IPV6;
|
ch->cmsg_level = IPPROTO_IPV6;
|
||||||
ch->cmsg_type = IPV6_RTHDR;
|
ch->cmsg_type = IPV6_RTHDR;
|
||||||
@ -88,7 +90,9 @@ inet6_rthdr_add(cmsg, addr, flags)
|
|||||||
const struct in6_addr *addr;
|
const struct in6_addr *addr;
|
||||||
u_int flags;
|
u_int flags;
|
||||||
{
|
{
|
||||||
register struct ip6_rthdr *rthdr = (struct ip6_rthdr *)(cmsg + 1);
|
register struct ip6_rthdr *rthdr;
|
||||||
|
|
||||||
|
rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg);
|
||||||
|
|
||||||
switch(rthdr->ip6r_type) {
|
switch(rthdr->ip6r_type) {
|
||||||
case IPV6_RTHDR_TYPE_0:
|
case IPV6_RTHDR_TYPE_0:
|
||||||
@ -135,7 +139,9 @@ inet6_rthdr_lasthop(cmsg, flags)
|
|||||||
struct cmsghdr *cmsg;
|
struct cmsghdr *cmsg;
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
{
|
{
|
||||||
register struct ip6_rthdr *rthdr = (struct ip6_rthdr *)(cmsg + 1);
|
register struct ip6_rthdr *rthdr;
|
||||||
|
|
||||||
|
rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg);
|
||||||
|
|
||||||
switch(rthdr->ip6r_type) {
|
switch(rthdr->ip6r_type) {
|
||||||
case IPV6_RTHDR_TYPE_0:
|
case IPV6_RTHDR_TYPE_0:
|
||||||
@ -189,7 +195,9 @@ int
|
|||||||
inet6_rthdr_segments(cmsg)
|
inet6_rthdr_segments(cmsg)
|
||||||
const struct cmsghdr *cmsg;
|
const struct cmsghdr *cmsg;
|
||||||
{
|
{
|
||||||
register struct ip6_rthdr *rthdr = (struct ip6_rthdr *)(cmsg + 1);
|
register struct ip6_rthdr *rthdr;
|
||||||
|
|
||||||
|
rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg);
|
||||||
|
|
||||||
switch(rthdr->ip6r_type) {
|
switch(rthdr->ip6r_type) {
|
||||||
case IPV6_RTHDR_TYPE_0:
|
case IPV6_RTHDR_TYPE_0:
|
||||||
@ -221,7 +229,9 @@ inet6_rthdr_getaddr(cmsg, index)
|
|||||||
struct cmsghdr *cmsg;
|
struct cmsghdr *cmsg;
|
||||||
int index;
|
int index;
|
||||||
{
|
{
|
||||||
register struct ip6_rthdr *rthdr = (struct ip6_rthdr *)(cmsg + 1);
|
register struct ip6_rthdr *rthdr;
|
||||||
|
|
||||||
|
rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg);
|
||||||
|
|
||||||
switch(rthdr->ip6r_type) {
|
switch(rthdr->ip6r_type) {
|
||||||
case IPV6_RTHDR_TYPE_0:
|
case IPV6_RTHDR_TYPE_0:
|
||||||
@ -260,7 +270,9 @@ inet6_rthdr_getflags(cmsg, index)
|
|||||||
const struct cmsghdr *cmsg;
|
const struct cmsghdr *cmsg;
|
||||||
int index;
|
int index;
|
||||||
{
|
{
|
||||||
register struct ip6_rthdr *rthdr = (struct ip6_rthdr *)(cmsg + 1);
|
register struct ip6_rthdr *rthdr;
|
||||||
|
|
||||||
|
rthdr = (struct ip6_rthdr *)CMSG_DATA(cmsg);
|
||||||
|
|
||||||
switch(rthdr->ip6r_type) {
|
switch(rthdr->ip6r_type) {
|
||||||
case IPV6_RTHDR_TYPE_0:
|
case IPV6_RTHDR_TYPE_0:
|
||||||
|
@ -213,7 +213,7 @@ main(argc, argv)
|
|||||||
struct iovec iov;
|
struct iovec iov;
|
||||||
struct msghdr msg;
|
struct msghdr msg;
|
||||||
struct sockaddr_in from;
|
struct sockaddr_in from;
|
||||||
char ctrl[sizeof(struct cmsghdr) + sizeof(struct timeval)];
|
char ctrl[CMSG_SPACE(sizeof(struct timeval))];
|
||||||
#ifdef IPSEC_POLICY_IPSEC
|
#ifdef IPSEC_POLICY_IPSEC
|
||||||
char *policy_in = NULL;
|
char *policy_in = NULL;
|
||||||
char *policy_out = NULL;
|
char *policy_out = NULL;
|
||||||
|
@ -839,16 +839,15 @@ sbcreatecontrol(p, size, type, level)
|
|||||||
register struct cmsghdr *cp;
|
register struct cmsghdr *cp;
|
||||||
struct mbuf *m;
|
struct mbuf *m;
|
||||||
|
|
||||||
if ((u_int)size > MLEN)
|
if (CMSG_SPACE((u_int)size) > MLEN)
|
||||||
return ((struct mbuf *) NULL);
|
return ((struct mbuf *) NULL);
|
||||||
if ((m = m_get(M_DONTWAIT, MT_CONTROL)) == NULL)
|
if ((m = m_get(M_DONTWAIT, MT_CONTROL)) == NULL)
|
||||||
return ((struct mbuf *) NULL);
|
return ((struct mbuf *) NULL);
|
||||||
cp = mtod(m, struct cmsghdr *);
|
cp = mtod(m, struct cmsghdr *);
|
||||||
/* XXX check size? */
|
/* XXX check size? */
|
||||||
(void)memcpy(CMSG_DATA(cp), p, size);
|
(void)memcpy(CMSG_DATA(cp), p, size);
|
||||||
size += sizeof(*cp);
|
m->m_len = CMSG_SPACE(size);
|
||||||
m->m_len = size;
|
cp->cmsg_len = CMSG_LEN(size);
|
||||||
cp->cmsg_len = size;
|
|
||||||
cp->cmsg_level = level;
|
cp->cmsg_level = level;
|
||||||
cp->cmsg_type = type;
|
cp->cmsg_type = type;
|
||||||
return (m);
|
return (m);
|
||||||
|
@ -839,16 +839,15 @@ sbcreatecontrol(p, size, type, level)
|
|||||||
register struct cmsghdr *cp;
|
register struct cmsghdr *cp;
|
||||||
struct mbuf *m;
|
struct mbuf *m;
|
||||||
|
|
||||||
if ((u_int)size > MLEN)
|
if (CMSG_SPACE((u_int)size) > MLEN)
|
||||||
return ((struct mbuf *) NULL);
|
return ((struct mbuf *) NULL);
|
||||||
if ((m = m_get(M_DONTWAIT, MT_CONTROL)) == NULL)
|
if ((m = m_get(M_DONTWAIT, MT_CONTROL)) == NULL)
|
||||||
return ((struct mbuf *) NULL);
|
return ((struct mbuf *) NULL);
|
||||||
cp = mtod(m, struct cmsghdr *);
|
cp = mtod(m, struct cmsghdr *);
|
||||||
/* XXX check size? */
|
/* XXX check size? */
|
||||||
(void)memcpy(CMSG_DATA(cp), p, size);
|
(void)memcpy(CMSG_DATA(cp), p, size);
|
||||||
size += sizeof(*cp);
|
m->m_len = CMSG_SPACE(size);
|
||||||
m->m_len = size;
|
cp->cmsg_len = CMSG_LEN(size);
|
||||||
cp->cmsg_len = size;
|
|
||||||
cp->cmsg_level = level;
|
cp->cmsg_level = level;
|
||||||
cp->cmsg_type = type;
|
cp->cmsg_type = type;
|
||||||
return (m);
|
return (m);
|
||||||
|
@ -1980,8 +1980,8 @@ ip6_setpktoptions(control, opt, priv)
|
|||||||
|
|
||||||
opt->ip6po_m = control;
|
opt->ip6po_m = control;
|
||||||
|
|
||||||
for (; control->m_len; control->m_data += CMSG_ALIGN(cm->cmsg_len),
|
for (; control->m_len; control->m_data += ALIGN(cm->cmsg_len),
|
||||||
control->m_len -= CMSG_ALIGN(cm->cmsg_len)) {
|
control->m_len -= ALIGN(cm->cmsg_len)) {
|
||||||
cm = mtod(control, struct cmsghdr *);
|
cm = mtod(control, struct cmsghdr *);
|
||||||
if (cm->cmsg_len == 0 || cm->cmsg_len > control->m_len)
|
if (cm->cmsg_len == 0 || cm->cmsg_len > control->m_len)
|
||||||
return(EINVAL);
|
return(EINVAL);
|
||||||
|
@ -351,26 +351,21 @@ struct cmsgcred {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* given pointer to struct cmsghdr, return pointer to data */
|
/* given pointer to struct cmsghdr, return pointer to data */
|
||||||
#define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1))
|
#define CMSG_DATA(cmsg) ((u_char *)(cmsg) + \
|
||||||
|
ALIGN(sizeof(struct cmsghdr)))
|
||||||
/*
|
|
||||||
* Alignment requirement for CMSG struct manipulation.
|
|
||||||
* This is different from ALIGN() defined in ARCH/include/param.h.
|
|
||||||
* XXX think again carefully about architecture dependencies.
|
|
||||||
*/
|
|
||||||
#define CMSG_ALIGN(n) (((n) + 3) & ~3)
|
|
||||||
|
|
||||||
/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
|
/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
|
||||||
#define CMSG_NXTHDR(mhdr, cmsg) \
|
#define CMSG_NXTHDR(mhdr, cmsg) \
|
||||||
(((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
|
(((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len) + \
|
||||||
|
ALIGN(sizeof(struct cmsghdr)) > \
|
||||||
(caddr_t)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \
|
(caddr_t)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \
|
||||||
(struct cmsghdr *)NULL : \
|
(struct cmsghdr *)NULL : \
|
||||||
(struct cmsghdr *)((caddr_t)(cmsg) + CMSG_ALIGN((cmsg)->cmsg_len)))
|
(struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
|
||||||
|
|
||||||
#define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
|
#define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
|
||||||
|
|
||||||
#define CMSG_SPACE(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(l))
|
#define CMSG_SPACE(l) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(l))
|
||||||
#define CMSG_LEN(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))
|
#define CMSG_LEN(l) (ALIGN(sizeof(struct cmsghdr)) + (l))
|
||||||
|
|
||||||
/* "Socket"-level control message types: */
|
/* "Socket"-level control message types: */
|
||||||
#define SCM_RIGHTS 0x01 /* access rights (array of int) */
|
#define SCM_RIGHTS 0x01 /* access rights (array of int) */
|
||||||
|
@ -2879,19 +2879,18 @@ sourceroute(ai, arg, cpp, lenp, protop, optp)
|
|||||||
* at least 7 bytes for the option.
|
* at least 7 bytes for the option.
|
||||||
*/
|
*/
|
||||||
if (cpp == NULL || lenp == NULL)
|
if (cpp == NULL || lenp == NULL)
|
||||||
return((unsigned long)-1);
|
return -1;
|
||||||
if (*cpp != NULL) {
|
if (*cpp != NULL) {
|
||||||
switch (res->ai_family) {
|
switch (res->ai_family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
if (*lenp < 7)
|
if (*lenp < 7)
|
||||||
return((unsigned long)-1);
|
return -1;
|
||||||
break;
|
break;
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
if (*lenp < (sizeof(struct cmsghdr) +
|
if (*lenp < CMSG_SPACE(sizeof(struct ip6_rthdr) +
|
||||||
sizeof(struct ip6_rthdr) +
|
sizeof(struct in6_addr)))
|
||||||
sizeof(struct in6_addr)))
|
return -1;
|
||||||
return((unsigned long)-1);
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -2904,7 +2903,7 @@ sourceroute(ai, arg, cpp, lenp, protop, optp)
|
|||||||
lsrp = *cpp;
|
lsrp = *cpp;
|
||||||
ep = lsrp + *lenp;
|
ep = lsrp + *lenp;
|
||||||
} else {
|
} else {
|
||||||
*cpp = lsrp = buf;
|
*cpp = lsrp = ALIGN(buf);
|
||||||
ep = lsrp + 1024;
|
ep = lsrp + 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2940,7 +2939,7 @@ sourceroute(ai, arg, cpp, lenp, protop, optp)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (*cp != '@')
|
if (*cp != '@')
|
||||||
return((unsigned long)-1);
|
return -1;
|
||||||
|
|
||||||
#ifndef sysV88
|
#ifndef sysV88
|
||||||
lsrp++; /* skip over length, we'll fill it in later */
|
lsrp++; /* skip over length, we'll fill it in later */
|
||||||
@ -3016,16 +3015,15 @@ sourceroute(ai, arg, cpp, lenp, protop, optp)
|
|||||||
*/
|
*/
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
if (res->ai_family == AF_INET6) {
|
if (res->ai_family == AF_INET6) {
|
||||||
if (((char *)cmsg +
|
if (((char *)CMSG_DATA(cmsg) +
|
||||||
sizeof(struct cmsghdr) +
|
|
||||||
sizeof(struct ip6_rthdr) +
|
sizeof(struct ip6_rthdr) +
|
||||||
((inet6_rthdr_segments(cmsg) + 1) *
|
((inet6_rthdr_segments(cmsg) + 1) *
|
||||||
sizeof(struct in6_addr))) > ep)
|
sizeof(struct in6_addr))) > ep)
|
||||||
return((unsigned long)-1);
|
return -1;
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
if (lsrp + 4 > ep)
|
if (lsrp + 4 > ep)
|
||||||
return((unsigned long)-1);
|
return -1;
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
}
|
}
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
@ -3039,7 +3037,7 @@ sourceroute(ai, arg, cpp, lenp, protop, optp)
|
|||||||
if ((*(*cpp+IPOPT_OLEN) = lsrp - *cpp) <= 7) {
|
if ((*(*cpp+IPOPT_OLEN) = lsrp - *cpp) <= 7) {
|
||||||
*cpp = 0;
|
*cpp = 0;
|
||||||
*lenp = 0;
|
*lenp = 0;
|
||||||
return((unsigned long)-1);
|
return -1;
|
||||||
}
|
}
|
||||||
*lsrp++ = IPOPT_NOP; /* 32 bit word align it */
|
*lsrp++ = IPOPT_NOP; /* 32 bit word align it */
|
||||||
*lenp = lsrp - *cpp;
|
*lenp = lsrp - *cpp;
|
||||||
@ -3048,7 +3046,7 @@ sourceroute(ai, arg, cpp, lenp, protop, optp)
|
|||||||
if (ipopt.io_len <= 5) { /* Is 3 better ? */
|
if (ipopt.io_len <= 5) { /* Is 3 better ? */
|
||||||
*cpp = 0;
|
*cpp = 0;
|
||||||
*lenp = 0;
|
*lenp = 0;
|
||||||
return((unsigned long)-1);
|
return -1;
|
||||||
}
|
}
|
||||||
*lenp = sizeof(ipopt);
|
*lenp = sizeof(ipopt);
|
||||||
*cpp = (char *) &ipopt;
|
*cpp = (char *) &ipopt;
|
||||||
|
Loading…
Reference in New Issue
Block a user