Embedded TCP/IP stack  4.7.0
fnet_ip6.h
1 /**************************************************************************
2 *
3 * Copyright 2008-2018 by Andrey Butok. FNET Community.
4 *
5 ***************************************************************************
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ***************************************************************************
20 *
21 * IPv6 protocol API.
22 *
23 ***************************************************************************/
24 
25 #ifndef _FNET_IP6_H_
26 
27 #define _FNET_IP6_H_
28 
32 /**************************************************************************/
35 FNET_COMP_PACKED_BEGIN
36 /* 128-bit IP6 address */
37 typedef union
38 {
39  fnet_uint8_t addr[16];
40  fnet_uint16_t addr16[8];
41  fnet_uint32_t addr32[4];
43 FNET_COMP_PACKED_END
44 
45 /**************************************************************************/
52 #define FNET_IP6_ADDR_STR_SIZE sizeof("abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd")
53 
56 /******************************************************************
57 * Constants
58 *******************************************************************/
59 #define FNET_IP6_HEAD_SIZE 40u /* IPv6 Header size. */
60 
61 #define FNET_IP6_DEFAULT_MTU 1280u /* Minimum IPv6 datagram size which
62  * must be supported by all IPv6 hosts */
63 
64 /****************************************************************
65  *
66  * Helpful macros.
67  *
68  *****************************************************************/
69 #define FNET_IP6_ADDR_INIT(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16) \
70  {{ (a1), (a2), (a3), (a4), (a5), (a6), (a7), (a8), (a9), (a10), (a11), (a12), (a13), (a14), (a15), (a16) }}
71 
72 /*
73  * Definition of some useful macros to handle IP6 addresses
74  */
75 #define FNET_IP6_ADDR_ANY_INIT FNET_IP6_ADDR_INIT(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
76 #define FNET_IP6_ADDR_LOOPBACK_INIT FNET_IP6_ADDR_INIT(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
77 #define FNET_IP6_ADDR_NODELOCAL_ALLNODES_INIT FNET_IP6_ADDR_INIT(0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
78 #define FNET_IP6_ADDR_INTFACELOCAL_ALLNODES_INIT FNET_IP6_ADDR_INIT(0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
79 #define FNET_IP6_ADDR_LINKLOCAL_ALLNODES_INIT FNET_IP6_ADDR_INIT(0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
80 #define FNET_IP6_ADDR_LINKLOCAL_ALLROUTERS_INIT FNET_IP6_ADDR_INIT(0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02)
81 #define FNET_IP6_ADDR_LINKLOCAL_ALLV2ROUTERS_INIT FNET_IP6_ADDR_INIT(0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16)
82 #define FNET_IP6_ADDR_LINKLOCAL_PREFIX_INIT FNET_IP6_ADDR_INIT(0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
83 
84 extern const fnet_ip6_addr_t fnet_ip6_addr_any;
85 extern const fnet_ip6_addr_t fnet_ip6_addr_loopback;
86 extern const fnet_ip6_addr_t fnet_ip6_addr_nodelocal_allnodes;
87 extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_allnodes;
88 extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_allrouters;
89 extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_allv2routers;
90 extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_prefix;
91 
92 /* Equality. */
93 #define FNET_IP6_ADDR_EQUAL(a, b) \
94  ((fnet_memcmp(&(a)->addr[0], &(b)->addr[0], sizeof(fnet_ip6_addr_t)) == 0)?FNET_TRUE:FNET_FALSE)
95 
96 /* Copying address. */
97 #define FNET_IP6_ADDR_COPY(from_addr, to_addr) \
98  (fnet_memcpy(&(to_addr)->addr[0], &(from_addr)->addr[0], sizeof(fnet_ip6_addr_t)))
99 
100 /* Unspecified.*/
101 #define FNET_IP6_ADDR_IS_UNSPECIFIED(a) \
102  (((((a)->addr32[0]) == 0U) && \
103  (((a)->addr32[1]) == 0U) && \
104  (((a)->addr32[2]) == 0U) && \
105  (((a)->addr32[3]) == 0U))?FNET_TRUE:FNET_FALSE)
106 
107 /* Loopback.*/
108 #define FNET_IP6_ADDR_IS_LOOPBACK(a) \
109  ((((a)->addr32[0]) == 0U) && \
110  (((a)->addr32[1]) == 0U) && \
111  (((a)->addr32[2]) == 0U) && \
112  (((a)->addr32[3]) == FNET_NTOHL(1U)))
113 
114 /* Multicast. */
115 #define FNET_IP6_ADDR_IS_MULTICAST(a) ((((a)->addr[0]) == 0xffU)?FNET_TRUE:FNET_FALSE)
116 
117 /* Unicast Scope.*/
118 #define FNET_IP6_ADDR_IS_LINKLOCAL(a) \
119  ((((a)->addr[0]) == 0xfeU) && ((((a)->addr[1]) & 0xc0U) == 0x80U))
120 #define FNET_IP6_ADDR_IS_SITELOCAL(a) \
121  ((((a)->addr[0]) == 0xfeU) && ((((a)->addr[1]) & 0xc0U) == 0xc0U))
122 
123 /************************************************************************
124 * Function Prototypes
125 *************************************************************************/
126 #if defined(__cplusplus)
127 extern "C" {
128 #endif
129 
130 /* Selects the best source address to use with a destination address, Based on RFC3484. */
131 const fnet_ip6_addr_t *fnet_ip6_select_src_addr(const fnet_ip6_addr_t *dest_addr);
132 
133 #if defined(__cplusplus)
134 }
135 #endif
136 
137 #endif /* _FNET_IP6_H_ */
128-bit IPv6 address type.
Definition: fnet_ip6.h:37

© 2005-2020 by Andrej Butok. http://fnet.sourceforge.net