3 * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne.
11 #define ALLNODES_MULTICAST { .s6_addr = \
12 { 0xff, 0x02, 0x00, 0x00,\
13 0x00, 0x00, 0x00, 0x00,\
14 0x00, 0x00, 0x00, 0x00,\
15 0x00, 0x00, 0x00, 0x01 } }
17 #define SOLICITED_NODE_PREFIX { .s6_addr = \
18 { 0xff, 0x02, 0x00, 0x00,\
19 0x00, 0x00, 0x00, 0x00,\
20 0x00, 0x00, 0x00, 0x01,\
21 0xff, 0x00, 0x00, 0x00 } }
23 #define LINKLOCAL_ADDR { .s6_addr = \
24 { 0xfe, 0x80, 0x00, 0x00,\
25 0x00, 0x00, 0x00, 0x00,\
26 0x00, 0x00, 0x00, 0x00,\
27 0x00, 0x00, 0x00, 0x02 } }
29 static inline bool in6_equal(const struct in6_addr
*a
, const struct in6_addr
*b
)
31 return memcmp(a
, b
, sizeof(*a
)) == 0;
34 static inline bool in6_equal_net(const struct in6_addr
*a
,
35 const struct in6_addr
*b
,
38 if (memcmp(a
, b
, prefix_len
/ 8) != 0) {
42 if (prefix_len
% 8 == 0) {
46 return a
->s6_addr
[prefix_len
/ 8] >> (8 - (prefix_len
% 8))
47 == b
->s6_addr
[prefix_len
/ 8] >> (8 - (prefix_len
% 8));
50 static inline bool in6_equal_mach(const struct in6_addr
*a
,
51 const struct in6_addr
*b
,
54 if (memcmp(&(a
->s6_addr
[(prefix_len
+ 7) / 8]),
55 &(b
->s6_addr
[(prefix_len
+ 7) / 8]),
56 16 - (prefix_len
+ 7) / 8) != 0) {
60 if (prefix_len
% 8 == 0) {
64 return (a
->s6_addr
[prefix_len
/ 8] & ((1U << (8 - (prefix_len
% 8))) - 1))
65 == (b
->s6_addr
[prefix_len
/ 8] & ((1U << (8 - (prefix_len
% 8))) - 1));
69 #define in6_equal_router(a)\
70 ((in6_equal_net(a, &slirp->vprefix_addr6, slirp->vprefix_len)\
71 && in6_equal_mach(a, &slirp->vhost_addr6, slirp->vprefix_len))\
72 || (in6_equal_net(a, &(struct in6_addr)LINKLOCAL_ADDR, 64)\
73 && in6_equal_mach(a, &slirp->vhost_addr6, 64)))
75 #define in6_equal_dns(a)\
76 ((in6_equal_net(a, &slirp->vprefix_addr6, slirp->vprefix_len)\
77 && in6_equal_mach(a, &slirp->vnameserver_addr6, slirp->vprefix_len))\
78 || (in6_equal_net(a, &(struct in6_addr)LINKLOCAL_ADDR, 64)\
79 && in6_equal_mach(a, &slirp->vnameserver_addr6, 64)))
81 #define in6_equal_host(a)\
82 (in6_equal_router(a) || in6_equal_dns(a))
84 #define in6_solicitednode_multicast(a)\
85 (in6_equal_net(a, &(struct in6_addr)SOLICITED_NODE_PREFIX, 104))
87 /* Compute emulated host MAC address from its ipv6 address */
88 static inline void in6_compute_ethaddr(struct in6_addr ip
,
89 uint8_t eth
[ETH_ALEN
])
93 memcpy(ð
[2], &ip
.s6_addr
[16 - (ETH_ALEN
- 2)], ETH_ALEN
- 2);
97 * Definitions for internet protocol version 6.
98 * Per RFC 2460, December 1998.
101 #define IP6_HOP_LIMIT 255
104 * Structure of an internet header, naked of options.
107 #ifdef HOST_WORDS_BIGENDIAN
109 ip_v
:4, /* version */
110 ip_tc_hi
:4, /* traffic class */
112 ip_fl_hi
:4, /* flow label */
122 uint16_t ip_pl
; /* payload length */
123 uint8_t ip_nh
; /* next header */
124 uint8_t ip_hl
; /* hop limit */
125 struct in6_addr ip_src
, ip_dst
; /* source and dest address */
129 * IPv6 pseudo-header used by upper-layer protocols
131 struct ip6_pseudohdr
{
132 struct in6_addr ih_src
; /* source internet address */
133 struct in6_addr ih_dst
; /* destination internet address */
134 uint32_t ih_pl
; /* upper-layer packet length */
135 uint16_t ih_zero_hi
; /* zero */
136 uint8_t ih_zero_lo
; /* zero */
137 uint8_t ih_nh
; /* next header */