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
91b0fd96fd
commit
73d476cc64
@ -63,7 +63,9 @@ inet6_rthdr_init(bp, type)
|
||||
int type;
|
||||
{
|
||||
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_type = IPV6_RTHDR;
|
||||
@ -88,7 +90,9 @@ inet6_rthdr_add(cmsg, addr, flags)
|
||||
const struct in6_addr *addr;
|
||||
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) {
|
||||
case IPV6_RTHDR_TYPE_0:
|
||||
@ -135,7 +139,9 @@ inet6_rthdr_lasthop(cmsg, flags)
|
||||
struct cmsghdr *cmsg;
|
||||
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) {
|
||||
case IPV6_RTHDR_TYPE_0:
|
||||
@ -189,7 +195,9 @@ int
|
||||
inet6_rthdr_segments(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) {
|
||||
case IPV6_RTHDR_TYPE_0:
|
||||
@ -221,7 +229,9 @@ inet6_rthdr_getaddr(cmsg, index)
|
||||
struct cmsghdr *cmsg;
|
||||
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) {
|
||||
case IPV6_RTHDR_TYPE_0:
|
||||
@ -260,7 +270,9 @@ inet6_rthdr_getflags(cmsg, index)
|
||||
const struct cmsghdr *cmsg;
|
||||
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) {
|
||||
case IPV6_RTHDR_TYPE_0:
|
||||
|
@ -213,7 +213,7 @@ main(argc, argv)
|
||||
struct iovec iov;
|
||||
struct msghdr msg;
|
||||
struct sockaddr_in from;
|
||||
char ctrl[sizeof(struct cmsghdr) + sizeof(struct timeval)];
|
||||
char ctrl[CMSG_SPACE(sizeof(struct timeval))];
|
||||
#ifdef IPSEC_POLICY_IPSEC
|
||||
char *policy_in = NULL;
|
||||
char *policy_out = NULL;
|
||||
|
@ -839,16 +839,15 @@ sbcreatecontrol(p, size, type, level)
|
||||
register struct cmsghdr *cp;
|
||||
struct mbuf *m;
|
||||
|
||||
if ((u_int)size > MLEN)
|
||||
if (CMSG_SPACE((u_int)size) > MLEN)
|
||||
return ((struct mbuf *) NULL);
|
||||
if ((m = m_get(M_DONTWAIT, MT_CONTROL)) == NULL)
|
||||
return ((struct mbuf *) NULL);
|
||||
cp = mtod(m, struct cmsghdr *);
|
||||
/* XXX check size? */
|
||||
(void)memcpy(CMSG_DATA(cp), p, size);
|
||||
size += sizeof(*cp);
|
||||
m->m_len = size;
|
||||
cp->cmsg_len = size;
|
||||
m->m_len = CMSG_SPACE(size);
|
||||
cp->cmsg_len = CMSG_LEN(size);
|
||||
cp->cmsg_level = level;
|
||||
cp->cmsg_type = type;
|
||||
return (m);
|
||||
|
@ -839,16 +839,15 @@ sbcreatecontrol(p, size, type, level)
|
||||
register struct cmsghdr *cp;
|
||||
struct mbuf *m;
|
||||
|
||||
if ((u_int)size > MLEN)
|
||||
if (CMSG_SPACE((u_int)size) > MLEN)
|
||||
return ((struct mbuf *) NULL);
|
||||
if ((m = m_get(M_DONTWAIT, MT_CONTROL)) == NULL)
|
||||
return ((struct mbuf *) NULL);
|
||||
cp = mtod(m, struct cmsghdr *);
|
||||
/* XXX check size? */
|
||||
(void)memcpy(CMSG_DATA(cp), p, size);
|
||||
size += sizeof(*cp);
|
||||
m->m_len = size;
|
||||
cp->cmsg_len = size;
|
||||
m->m_len = CMSG_SPACE(size);
|
||||
cp->cmsg_len = CMSG_LEN(size);
|
||||
cp->cmsg_level = level;
|
||||
cp->cmsg_type = type;
|
||||
return (m);
|
||||
|
@ -1980,8 +1980,8 @@ ip6_setpktoptions(control, opt, priv)
|
||||
|
||||
opt->ip6po_m = control;
|
||||
|
||||
for (; control->m_len; control->m_data += CMSG_ALIGN(cm->cmsg_len),
|
||||
control->m_len -= CMSG_ALIGN(cm->cmsg_len)) {
|
||||
for (; control->m_len; control->m_data += ALIGN(cm->cmsg_len),
|
||||
control->m_len -= ALIGN(cm->cmsg_len)) {
|
||||
cm = mtod(control, struct cmsghdr *);
|
||||
if (cm->cmsg_len == 0 || cm->cmsg_len > control->m_len)
|
||||
return(EINVAL);
|
||||
|
@ -351,26 +351,21 @@ struct cmsgcred {
|
||||
};
|
||||
|
||||
/* given pointer to struct cmsghdr, return pointer to data */
|
||||
#define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1))
|
||||
|
||||
/*
|
||||
* 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)
|
||||
#define CMSG_DATA(cmsg) ((u_char *)(cmsg) + \
|
||||
ALIGN(sizeof(struct cmsghdr)))
|
||||
|
||||
/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
|
||||
#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) ? \
|
||||
(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_SPACE(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(l))
|
||||
#define CMSG_LEN(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))
|
||||
#define CMSG_SPACE(l) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(l))
|
||||
#define CMSG_LEN(l) (ALIGN(sizeof(struct cmsghdr)) + (l))
|
||||
|
||||
/* "Socket"-level control message types: */
|
||||
#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.
|
||||
*/
|
||||
if (cpp == NULL || lenp == NULL)
|
||||
return((unsigned long)-1);
|
||||
return -1;
|
||||
if (*cpp != NULL) {
|
||||
switch (res->ai_family) {
|
||||
case AF_INET:
|
||||
if (*lenp < 7)
|
||||
return((unsigned long)-1);
|
||||
return -1;
|
||||
break;
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
if (*lenp < (sizeof(struct cmsghdr) +
|
||||
sizeof(struct ip6_rthdr) +
|
||||
sizeof(struct in6_addr)))
|
||||
return((unsigned long)-1);
|
||||
if (*lenp < CMSG_SPACE(sizeof(struct ip6_rthdr) +
|
||||
sizeof(struct in6_addr)))
|
||||
return -1;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
@ -2904,7 +2903,7 @@ sourceroute(ai, arg, cpp, lenp, protop, optp)
|
||||
lsrp = *cpp;
|
||||
ep = lsrp + *lenp;
|
||||
} else {
|
||||
*cpp = lsrp = buf;
|
||||
*cpp = lsrp = ALIGN(buf);
|
||||
ep = lsrp + 1024;
|
||||
}
|
||||
|
||||
@ -2940,7 +2939,7 @@ sourceroute(ai, arg, cpp, lenp, protop, optp)
|
||||
#endif
|
||||
|
||||
if (*cp != '@')
|
||||
return((unsigned long)-1);
|
||||
return -1;
|
||||
|
||||
#ifndef sysV88
|
||||
lsrp++; /* skip over length, we'll fill it in later */
|
||||
@ -3016,16 +3015,15 @@ sourceroute(ai, arg, cpp, lenp, protop, optp)
|
||||
*/
|
||||
#ifdef INET6
|
||||
if (res->ai_family == AF_INET6) {
|
||||
if (((char *)cmsg +
|
||||
sizeof(struct cmsghdr) +
|
||||
if (((char *)CMSG_DATA(cmsg) +
|
||||
sizeof(struct ip6_rthdr) +
|
||||
((inet6_rthdr_segments(cmsg) + 1) *
|
||||
sizeof(struct in6_addr))) > ep)
|
||||
return((unsigned long)-1);
|
||||
return -1;
|
||||
} else
|
||||
#endif
|
||||
if (lsrp + 4 > ep)
|
||||
return((unsigned long)-1);
|
||||
return -1;
|
||||
freeaddrinfo(res);
|
||||
}
|
||||
#ifdef INET6
|
||||
@ -3039,7 +3037,7 @@ sourceroute(ai, arg, cpp, lenp, protop, optp)
|
||||
if ((*(*cpp+IPOPT_OLEN) = lsrp - *cpp) <= 7) {
|
||||
*cpp = 0;
|
||||
*lenp = 0;
|
||||
return((unsigned long)-1);
|
||||
return -1;
|
||||
}
|
||||
*lsrp++ = IPOPT_NOP; /* 32 bit word align it */
|
||||
*lenp = lsrp - *cpp;
|
||||
@ -3048,7 +3046,7 @@ sourceroute(ai, arg, cpp, lenp, protop, optp)
|
||||
if (ipopt.io_len <= 5) { /* Is 3 better ? */
|
||||
*cpp = 0;
|
||||
*lenp = 0;
|
||||
return((unsigned long)-1);
|
||||
return -1;
|
||||
}
|
||||
*lenp = sizeof(ipopt);
|
||||
*cpp = (char *) &ipopt;
|
||||
|
Loading…
Reference in New Issue
Block a user