diff options
Diffstat (limited to 'freebsd/lib/libc/net/ip6opt.c')
-rw-r--r-- | freebsd/lib/libc/net/ip6opt.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/freebsd/lib/libc/net/ip6opt.c b/freebsd/lib/libc/net/ip6opt.c index a09f05d8..2fbd6cc6 100644 --- a/freebsd/lib/libc/net/ip6opt.c +++ b/freebsd/lib/libc/net/ip6opt.c @@ -35,7 +35,6 @@ __FBSDID("$FreeBSD$"); #include <rtems/bsd/sys/param.h> -#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> @@ -47,6 +46,18 @@ __FBSDID("$FreeBSD$"); static int ip6optlen(u_int8_t *opt, u_int8_t *lim); static void inet6_insert_padopt(u_char *p, int len); +#ifndef IPV6_2292HOPOPTS +#define IPV6_2292HOPOPTS 22 +#endif +#ifndef IPV6_2292DSTOPTS +#define IPV6_2292DSTOPTS 23 +#endif + +#define is_ipv6_hopopts(x) \ + ((x) == IPV6_HOPOPTS || (x) == IPV6_2292HOPOPTS) +#define is_ipv6_dstopts(x) \ + ((x) == IPV6_DSTOPTS || (x) == IPV6_2292DSTOPTS) + /* * This function returns the number of bytes required to hold an option * when it is stored as ancillary data, including the cmsghdr structure @@ -74,9 +85,9 @@ inet6_option_init(void *bp, struct cmsghdr **cmsgp, int type) struct cmsghdr *ch = (struct cmsghdr *)bp; /* argument validation */ - if (type != IPV6_HOPOPTS && type != IPV6_DSTOPTS) + if (!is_ipv6_hopopts(type) && !is_ipv6_dstopts(type)) return(-1); - + ch->cmsg_level = IPPROTO_IPV6; ch->cmsg_type = type; ch->cmsg_len = CMSG_LEN(0); @@ -121,8 +132,7 @@ inet6_option_append(struct cmsghdr *cmsg, const u_int8_t *typep, int multx, /* calculate pad length before the option. */ off = bp - (u_char *)eh; - padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - - (off % multx); + padlen = roundup2(off % multx, multx) - (off % multx); padlen += plusy; padlen %= multx; /* keep the pad as short as possible */ /* insert padding */ @@ -191,8 +201,7 @@ inet6_option_alloc(struct cmsghdr *cmsg, int datalen, int multx, int plusy) /* calculate pad length before the option. */ off = bp - (u_char *)eh; - padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - - (off % multx); + padlen = roundup2(off % multx, multx) - (off % multx); padlen += plusy; padlen %= multx; /* keep the pad as short as possible */ /* insert padding */ @@ -236,8 +245,8 @@ inet6_option_next(const struct cmsghdr *cmsg, u_int8_t **tptrp) u_int8_t *lim; if (cmsg->cmsg_level != IPPROTO_IPV6 || - (cmsg->cmsg_type != IPV6_HOPOPTS && - cmsg->cmsg_type != IPV6_DSTOPTS)) + (!is_ipv6_hopopts(cmsg->cmsg_type) && + !is_ipv6_dstopts(cmsg->cmsg_type))) return(-1); /* message length validation */ @@ -292,8 +301,8 @@ inet6_option_find(const struct cmsghdr *cmsg, u_int8_t **tptrp, int type) u_int8_t *optp, *lim; if (cmsg->cmsg_level != IPPROTO_IPV6 || - (cmsg->cmsg_type != IPV6_HOPOPTS && - cmsg->cmsg_type != IPV6_DSTOPTS)) + (!is_ipv6_hopopts(cmsg->cmsg_type) && + !is_ipv6_dstopts(cmsg->cmsg_type))) return(-1); /* message length validation */ @@ -383,11 +392,8 @@ inet6_opt_init(void *extbuf, socklen_t extlen) { struct ip6_ext *ext = (struct ip6_ext *)extbuf; - if (extlen < 0 || (extlen % 8)) - return(-1); - if (ext) { - if (extlen == 0) + if (extlen <= 0 || (extlen % 8)) return(-1); ext->ip6e_len = (extlen >> 3) - 1; } @@ -412,7 +418,7 @@ inet6_opt_append(void *extbuf, socklen_t extlen, int offset, u_int8_t type, * The option data length must have a value between 0 and 255, * inclusive, and is the length of the option data that follows. */ - if (len < 0 || len > 255) + if (len > 255 || len < 0 ) return(-1); /* |