Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/SharedDependencies/Sources/libslirp/include/ip6_icmp.h
2 views
1
/* SPDX-License-Identifier: BSD-3-Clause */
2
/*
3
* Copyright (c) 2013
4
* Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne.
5
*/
6
7
#ifndef SLIRP_IP6_ICMP_H
8
#define SLIRP_IP6_ICMP_H
9
10
/*
11
* Interface Control Message Protocol version 6 Definitions.
12
* Per RFC 4443, March 2006.
13
*
14
* Network Discover Protocol Definitions.
15
* Per RFC 4861, September 2007.
16
*/
17
18
struct icmp6_echo { /* Echo Messages */
19
uint16_t id;
20
uint16_t seq_num;
21
};
22
23
union icmp6_error_body {
24
uint32_t unused;
25
uint32_t pointer;
26
uint32_t mtu;
27
};
28
29
/*
30
* NDP Messages
31
*/
32
struct ndp_rs { /* Router Solicitation Message */
33
uint32_t reserved;
34
};
35
36
struct ndp_ra { /* Router Advertisement Message */
37
uint8_t chl; /* Cur Hop Limit */
38
#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)
39
uint8_t M : 1, O : 1, reserved : 6;
40
#else
41
uint8_t reserved : 6, O : 1, M : 1;
42
#endif
43
uint16_t lifetime; /* Router Lifetime */
44
uint32_t reach_time; /* Reachable Time */
45
uint32_t retrans_time; /* Retrans Timer */
46
};
47
48
G_STATIC_ASSERT(sizeof(struct ndp_ra) == 12);
49
50
struct ndp_ns { /* Neighbor Solicitation Message */
51
uint32_t reserved;
52
struct in6_addr target; /* Target Address */
53
};
54
55
G_STATIC_ASSERT(sizeof(struct ndp_ns) == 20);
56
57
struct ndp_na { /* Neighbor Advertisement Message */
58
#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)
59
uint8_t R : 1, /* Router Flag */
60
S : 1, /* Solicited Flag */
61
O : 1, /* Override Flag */
62
reserved_1 : 5;
63
#else
64
uint8_t reserved_1 : 5, O : 1, S : 1, R : 1;
65
#endif
66
uint8_t reserved_2;
67
uint16_t reserved_3;
68
struct in6_addr target; /* Target Address */
69
};
70
71
G_STATIC_ASSERT(sizeof(struct ndp_na) == 20);
72
73
struct ndp_redirect {
74
uint32_t reserved;
75
struct in6_addr target; /* Target Address */
76
struct in6_addr dest; /* Destination Address */
77
};
78
79
G_STATIC_ASSERT(sizeof(struct ndp_redirect) == 36);
80
81
/*
82
* Structure of an icmpv6 header.
83
*/
84
struct icmp6 {
85
uint8_t icmp6_type; /* type of message, see below */
86
uint8_t icmp6_code; /* type sub code */
87
uint16_t icmp6_cksum; /* ones complement cksum of struct */
88
union {
89
union icmp6_error_body error_body;
90
struct icmp6_echo echo;
91
struct ndp_rs ndp_rs;
92
struct ndp_ra ndp_ra;
93
struct ndp_ns ndp_ns;
94
struct ndp_na ndp_na;
95
struct ndp_redirect ndp_redirect;
96
} icmp6_body;
97
#define icmp6_err icmp6_body.error_body
98
#define icmp6_echo icmp6_body.echo
99
#define icmp6_id icmp6_body.echo.id
100
#define icmp6_seq icmp6_body.echo.seq_num
101
#define icmp6_nrs icmp6_body.ndp_rs
102
#define icmp6_nra icmp6_body.ndp_ra
103
#define icmp6_nns icmp6_body.ndp_ns
104
#define icmp6_nna icmp6_body.ndp_na
105
#define icmp6_redirect icmp6_body.ndp_redirect
106
};
107
108
G_STATIC_ASSERT(sizeof(struct icmp6) == 40);
109
110
#define ICMP6_MINLEN 4
111
#define ICMP6_ERROR_MINLEN 8
112
#define ICMP6_ECHO_MINLEN 8
113
#define ICMP6_NDP_RS_MINLEN 8
114
#define ICMP6_NDP_RA_MINLEN 16
115
#define ICMP6_NDP_NS_MINLEN 24
116
#define ICMP6_NDP_NA_MINLEN 24
117
#define ICMP6_NDP_REDIRECT_MINLEN 40
118
119
/*
120
* NDP Options
121
*/
122
SLIRP_PACKED_BEGIN
123
struct ndpopt {
124
uint8_t ndpopt_type; /* Option type */
125
uint8_t ndpopt_len; /* /!\ In units of 8 octets */
126
union {
127
unsigned char linklayer_addr[6]; /* Source/Target Link-layer */
128
#define ndpopt_linklayer ndpopt_body.linklayer_addr
129
SLIRP_PACKED_BEGIN
130
struct prefixinfo { /* Prefix Information */
131
uint8_t prefix_length;
132
#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)
133
uint8_t L : 1, A : 1, reserved1 : 6;
134
#else
135
uint8_t reserved1 : 6, A : 1, L : 1;
136
#endif
137
uint32_t valid_lt; /* Valid Lifetime */
138
uint32_t pref_lt; /* Preferred Lifetime */
139
uint32_t reserved2;
140
struct in6_addr prefix;
141
} SLIRP_PACKED_END prefixinfo;
142
#define ndpopt_prefixinfo ndpopt_body.prefixinfo
143
SLIRP_PACKED_BEGIN
144
struct rdnss {
145
uint16_t reserved;
146
uint32_t lifetime;
147
struct in6_addr addr;
148
} SLIRP_PACKED_END rdnss;
149
#define ndpopt_rdnss ndpopt_body.rdnss
150
} ndpopt_body;
151
} SLIRP_PACKED_END;
152
153
/* NDP options type */
154
#define NDPOPT_LINKLAYER_SOURCE 1 /* Source Link-Layer Address */
155
#define NDPOPT_LINKLAYER_TARGET 2 /* Target Link-Layer Address */
156
#define NDPOPT_PREFIX_INFO 3 /* Prefix Information */
157
#define NDPOPT_RDNSS 25 /* Recursive DNS Server Address */
158
159
/* NDP options size, in octets. */
160
#define NDPOPT_LINKLAYER_LEN 8
161
#define NDPOPT_PREFIXINFO_LEN 32
162
#define NDPOPT_RDNSS_LEN 24
163
164
/*
165
* Definition of type and code field values.
166
* Per https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xml
167
* Last Updated 2012-11-12
168
*/
169
170
/* Errors */
171
#define ICMP6_UNREACH 1 /* Destination Unreachable */
172
#define ICMP6_UNREACH_NO_ROUTE 0 /* no route to dest */
173
#define ICMP6_UNREACH_DEST_PROHIB 1 /* com with dest prohibited */
174
#define ICMP6_UNREACH_SCOPE 2 /* beyond scope of src addr */
175
#define ICMP6_UNREACH_ADDRESS 3 /* address unreachable */
176
#define ICMP6_UNREACH_PORT 4 /* port unreachable */
177
#define ICMP6_UNREACH_SRC_FAIL 5 /* src addr failed */
178
#define ICMP6_UNREACH_REJECT_ROUTE 6 /* reject route to dest */
179
#define ICMP6_UNREACH_SRC_HDR_ERROR 7 /* error in src routing header */
180
#define ICMP6_TOOBIG 2 /* Packet Too Big */
181
#define ICMP6_TIMXCEED 3 /* Time Exceeded */
182
#define ICMP6_TIMXCEED_INTRANS 0 /* hop limit exceeded in transit */
183
#define ICMP6_TIMXCEED_REASS 1 /* ttl=0 in reass */
184
#define ICMP6_PARAMPROB 4 /* Parameter Problem */
185
#define ICMP6_PARAMPROB_HDR_FIELD 0 /* err header field */
186
#define ICMP6_PARAMPROB_NXTHDR_TYPE 1 /* unrecognized Next Header type */
187
#define ICMP6_PARAMPROB_IPV6_OPT 2 /* unrecognized IPv6 option */
188
189
/* Informational Messages */
190
#define ICMP6_ECHO_REQUEST 128 /* Echo Request */
191
#define ICMP6_ECHO_REPLY 129 /* Echo Reply */
192
#define ICMP6_NDP_RS 133 /* Router Solicitation (NDP) */
193
#define ICMP6_NDP_RA 134 /* Router Advertisement (NDP) */
194
#define ICMP6_NDP_NS 135 /* Neighbor Solicitation (NDP) */
195
#define ICMP6_NDP_NA 136 /* Neighbor Advertisement (NDP) */
196
#define ICMP6_NDP_REDIRECT 137 /* Redirect Message (NDP) */
197
198
/*
199
* Router Configuration Variables (rfc4861#section-6)
200
*/
201
#define NDP_IsRouter 1
202
#define NDP_AdvSendAdvertisements 1
203
#define NDP_MaxRtrAdvInterval 600000
204
#define NDP_MinRtrAdvInterval \
205
((NDP_MaxRtrAdvInterval >= 9) ? NDP_MaxRtrAdvInterval / 3 : \
206
NDP_MaxRtrAdvInterval)
207
#define NDP_AdvManagedFlag 0
208
#define NDP_AdvOtherConfigFlag 0
209
#define NDP_AdvLinkMTU 0
210
#define NDP_AdvReachableTime 0
211
#define NDP_AdvRetransTime 0
212
#define NDP_AdvCurHopLimit 64
213
#define NDP_AdvDefaultLifetime ((3 * NDP_MaxRtrAdvInterval) / 1000)
214
#define NDP_AdvValidLifetime 86400
215
#define NDP_AdvOnLinkFlag 1
216
#define NDP_AdvPrefLifetime 14400
217
#define NDP_AdvAutonomousFlag 1
218
219
/* Called from slirp_new, but after other initialization */
220
void icmp6_post_init(Slirp *slirp);
221
222
/* Called from slirp_cleanup */
223
void icmp6_cleanup(Slirp *slirp);
224
225
/* Process an ICMPv6 packet from the guest */
226
void icmp6_input(struct mbuf *);
227
228
/* Send an ICMPv6 error related to the given packet, using the given ICMPv6 type and code, using the given source */
229
void icmp6_forward_error(struct mbuf *m, uint8_t type, uint8_t code, struct in6_addr *src);
230
231
/* Similar to icmp6_forward_error, but use the link-local address as source */
232
void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code);
233
234
/* Forward the ICMP packet to the guest (probably a ping reply) */
235
void icmp6_reflect(struct mbuf *);
236
237
/* Handle ICMP data from the ICMP socket, and forward it to the guest (using so_m as reference) */
238
void icmp6_receive(struct socket *so);
239
240
/* Send a neighbour sollicitation, to resolve the given IPV6 address */
241
void ndp_send_ns(Slirp *slirp, struct in6_addr addr);
242
243
/* Timer handler for router advertisement, to send it and reschedule the timer */
244
void ra_timer_handler(Slirp *slirp, void *unused);
245
246
#endif
247
248