Path: blob/main/sys/compat/linuxkpi/common/include/net/ipv6.h
39604 views
/*-1* Copyright (c) 2010 Isilon Systems, Inc.2* Copyright (c) 2010 iX Systems, Inc.3* Copyright (c) 2010 Panasas, Inc.4* Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice unmodified, this list of conditions, and the following12* disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR18* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES19* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.20* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,21* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT22* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF26* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27*/28#ifndef _LINUXKPI_NET_IPV6_H_29#define _LINUXKPI_NET_IPV6_H_3031#include <sys/types.h>32#include <netinet/in.h>33#include <linux/types.h>34#include <linux/bitops.h>3536#define IPV6_DEFAULT_HOPLIMIT 643738#define NEXTHDR_HOP IPPROTO_HOPOPTS39#define NEXTHDR_ROUTING IPPROTO_ROUTING40#define NEXTHDR_NONE IPPROTO_NONE41#define NEXTHDR_DEST IPPROTO_DSTOPTS4243#define ipv6_addr_loopback(addr) IN6_IS_ADDR_LOOPBACK(addr)44#define ipv6_addr_any(addr) IN6_IS_ADDR_UNSPECIFIED(addr)4546#define ipv6_addr_copy(dst, src) \47memcpy((dst), (src), sizeof(struct in6_addr))4849static inline void50ipv6_ib_mc_map(const struct in6_addr *addr, const unsigned char *broadcast,51char *buf)52{53unsigned char scope;5455scope = broadcast[5] & 0xF;56buf[0] = 0;57buf[1] = 0xff;58buf[2] = 0xff;59buf[3] = 0xff;60buf[4] = 0xff;61buf[5] = 0x10 | scope;62buf[6] = 0x60;63buf[7] = 0x1b;64buf[8] = broadcast[8];65buf[9] = broadcast[9];66memcpy(&buf[10], &addr->s6_addr[6], 10);67}6869static inline void __ipv6_addr_set_half(__be32 *addr, __be32 wh, __be32 wl)70{71#if BITS_PER_LONG == 6472#if defined(__BIG_ENDIAN)73if (__builtin_constant_p(wh) && __builtin_constant_p(wl)) {74*(__force u64 *)addr = ((__force u64)(wh) << 32 | (__force u64)(wl));75return;76}77#elif defined(__LITTLE_ENDIAN)78if (__builtin_constant_p(wl) && __builtin_constant_p(wh)) {79*(__force u64 *)addr = ((__force u64)(wl) << 32 | (__force u64)(wh));80return;81}82#endif83#endif84addr[0] = wh;85addr[1] = wl;86}8788static inline void ipv6_addr_set(struct in6_addr *addr,89__be32 w1, __be32 w2,90__be32 w3, __be32 w4)91{92__ipv6_addr_set_half(&addr->s6_addr32[0], w1, w2);93__ipv6_addr_set_half(&addr->s6_addr32[2], w3, w4);94}9596static inline void ipv6_addr_set_v4mapped(const __be32 addr,97struct in6_addr *v4mapped)98{99ipv6_addr_set(v4mapped,1000, 0,101htonl(0x0000FFFF),102addr);103}104105static inline int ipv6_addr_v4mapped(const struct in6_addr *a)106{107return ((a->s6_addr32[0] | a->s6_addr32[1] |108(a->s6_addr32[2] ^ htonl(0x0000ffff))) == 0);109}110111static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr *a2)112{113return memcmp(a1, a2, sizeof(struct in6_addr));114}115116#endif /* _LINUXKPI_NET_IPV6_H_ */117118119