Skip to content

Commit 6875bab

Browse files
committed
RFC 2292 struct and constant definitions
This PR adds the icmp6_filter struct and constants as defined by RFC 2292 - Advanced Sockets API for IPv6. These constants are available for use in get/setsockopt on supported Unix platforms. The operations defined on the icmp6_filter struct are defined as C macros, so the implementations are not included here. See the RFC for definitions and use.
1 parent 97e6889 commit 6875bab

File tree

4 files changed

+185
-0
lines changed

4 files changed

+185
-0
lines changed

libc-test/build.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ fn test_apple(target: &str) {
254254
"netinet/ip.h",
255255
"netinet/tcp.h",
256256
"netinet/udp.h",
257+
"netinet/icmp6.h",
258+
"netinet/ip6.h",
257259
"netinet6/in6_var.h",
258260
"os/clock.h",
259261
"os/lock.h",
@@ -449,6 +451,8 @@ fn test_openbsd(target: &str) {
449451
"netinet/ip.h",
450452
"netinet/tcp.h",
451453
"netinet/udp.h",
454+
"netinet/icmp6.h",
455+
"netinet/ip6.h",
452456
"net/bpf.h",
453457
"regex.h",
454458
"resolv.h",
@@ -867,6 +871,7 @@ fn test_redox(target: &str) {
867871
"netinet/in.h",
868872
"netinet/ip.h",
869873
"netinet/tcp.h",
874+
"netinet/icmp6.h",
870875
"poll.h",
871876
"pwd.h",
872877
"semaphore.h",
@@ -945,6 +950,8 @@ fn test_solarish(target: &str) {
945950
"netinet/ip.h",
946951
"netinet/tcp.h",
947952
"netinet/udp.h",
953+
"netinet/icmp6.h",
954+
"netinet/ip6.h",
948955
"poll.h",
949956
"port.h",
950957
"pthread.h",
@@ -1229,6 +1236,8 @@ fn test_netbsd(target: &str) {
12291236
"netinet/ip.h",
12301237
"netinet/tcp.h",
12311238
"netinet/udp.h",
1239+
"netinet/icmp6.h",
1240+
"netinet/ip6.h",
12321241
"poll.h",
12331242
"pthread.h",
12341243
"pwd.h",
@@ -1518,6 +1527,8 @@ fn test_dragonflybsd(target: &str) {
15181527
"netinet/ip.h",
15191528
"netinet/tcp.h",
15201529
"netinet/udp.h",
1530+
"netinet/icmp6.h",
1531+
"netinet/ip6.h",
15211532
"poll.h",
15221533
"pthread.h",
15231534
"pthread_np.h",
@@ -1833,6 +1844,7 @@ fn test_android(target: &str) {
18331844
"netinet/ip.h",
18341845
"netinet/tcp.h",
18351846
"netinet/udp.h",
1847+
"netinet/icmp6.h",
18361848
"netpacket/packet.h",
18371849
"poll.h",
18381850
"pthread.h",
@@ -2373,6 +2385,8 @@ fn test_freebsd(target: &str) {
23732385
"netinet/sctp.h",
23742386
"netinet/tcp.h",
23752387
"netinet/udp.h",
2388+
"netinet/icmp6.h",
2389+
"netinet/ip6.h",
23762390
"poll.h",
23772391
"pthread.h",
23782392
"pthread_np.h",
@@ -3000,6 +3014,7 @@ fn test_emscripten(target: &str) {
30003014
"netinet/ip.h",
30013015
"netinet/tcp.h",
30023016
"netinet/udp.h",
3017+
"netinet/icmp6.h",
30033018
"netpacket/packet.h",
30043019
"poll.h",
30053020
"pthread.h",
@@ -3268,6 +3283,7 @@ fn test_neutrino(target: &str) {
32683283
"netinet/tcp.h",
32693284
"netinet/udp.h",
32703285
"netinet/ip_var.h",
3286+
"netinet/icmp6.h",
32713287
"sys/poll.h",
32723288
"pthread.h",
32733289
"pwd.h",
@@ -3762,8 +3778,10 @@ fn test_linux(target: &str) {
37623778
"netdb.h",
37633779
"netinet/in.h",
37643780
"netinet/ip.h",
3781+
"netinet/ip6.h",
37653782
"netinet/tcp.h",
37663783
"netinet/udp.h",
3784+
"netinet/icmp6.h",
37673785
(l4re, "netpacket/packet.h"),
37683786
"poll.h",
37693787
"pthread.h",
@@ -5022,6 +5040,7 @@ fn test_haiku(target: &str) {
50225040
"netinet/ip_var.h",
50235041
"netinet/tcp.h",
50245042
"netinet/udp.h",
5043+
"netinet/icmp6.h",
50255044
"netinet6/in6.h",
50265045
"nl_types.h",
50275046
"null.h",

src/unix/bsd/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ pub const IPV6_UNICAST_HOPS: c_int = 4;
211211
pub const IPV6_MULTICAST_IF: c_int = 9;
212212
pub const IPV6_MULTICAST_HOPS: c_int = 10;
213213
pub const IPV6_MULTICAST_LOOP: c_int = 11;
214+
pub const ICMP6_FILTER: c_int = 18;
214215
pub const IPV6_V6ONLY: c_int = 27;
215216
pub const IPV6_DONTFRAG: c_int = 62;
216217

src/unix/linux_like/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,8 @@ pub const IPV6_PMTUDISC_PROBE: c_int = 3;
977977
pub const IPV6_PMTUDISC_INTERFACE: c_int = 4;
978978
pub const IPV6_PMTUDISC_OMIT: c_int = 5;
979979

980+
pub const ICMP6_FILTER: c_int = 1;
981+
980982
pub const TCP_NODELAY: c_int = 1;
981983
pub const TCP_MAXSEG: c_int = 2;
982984
pub const TCP_CORK: c_int = 3;

src/unix/mod.rs

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,112 @@ s! {
217217
pub struct in6_addr {
218218
pub s6_addr: [u8; 16],
219219
}
220+
221+
pub struct ip6_hbh {
222+
pub ip6h_nxt: u8,
223+
pub ip6h_len: u8,
224+
}
225+
226+
pub struct ip6_dest {
227+
pub ip6d_nxt: u8,
228+
pub ip6d_len: u8,
229+
}
230+
231+
pub struct ip6_rthdr {
232+
pub ip6r_nxt: u8,
233+
pub ip6r_len: u8,
234+
pub ip6r_type: u8,
235+
pub ip6r_segleft: u8,
236+
}
237+
238+
pub struct ip6_rthdr0 {
239+
pub ip6r0_nxt: u8,
240+
pub ip6r0_len: u8,
241+
pub ip6r0_type: u8,
242+
pub ip6r0_segleft: u8,
243+
#[cfg(not(target_os = "linux"))]
244+
pub ip6r0_reserved: u32,
245+
#[cfg(target_os = "linux")]
246+
pub ip6r0_reserved: u8,
247+
#[cfg(target_os = "linux")]
248+
pub ip6r0_slmap: [u8; 3],
249+
#[cfg(target_os = "linux")]
250+
pub ip6r0_addr: [in6_addr; 0],
251+
}
252+
253+
pub struct ip6_frag {
254+
ip6f_nxt: u8,
255+
ip6f_reserved: u8,
256+
ip6f_offlg: u16,
257+
ip6f_ident: u32,
258+
}
259+
260+
pub struct icmp6_filter {
261+
pub icmp6_filt: [u32; 8],
262+
}
263+
264+
pub struct icmp6_hdr {
265+
pub icmp6_type: u8,
266+
pub icmp6_code: u8,
267+
pub icmp6_cksum: u16,
268+
pub icmp6_data8: [u8; 4],
269+
}
270+
271+
pub struct nd_router_solicit {
272+
pub nd_rs_hdr: icmp6_hdr,
273+
}
274+
275+
pub struct nd_router_advert {
276+
pub nd_ra_hdr: icmp6_hdr,
277+
pub nd_ra_reachable: u32,
278+
pub nd_ra_retransmit: u32,
279+
}
280+
281+
pub struct nd_neighbor_solicit {
282+
pub nd_ns_hdr: icmp6_hdr,
283+
pub nd_ns_target: in6_addr,
284+
}
285+
286+
pub struct nd_neighbor_advert {
287+
pub nd_na_hdr: icmp6_hdr,
288+
pub nd_na_target: in6_addr,
289+
}
290+
291+
pub struct nd_redirect {
292+
pub nd_rd_hdr: icmp6_hdr,
293+
pub nd_rd_target: in6_addr,
294+
pub nd_rd_dst: in6_addr,
295+
}
296+
297+
pub struct nd_opt_hdr {
298+
pub nd_opt_type: u8,
299+
pub nd_opt_len: u8,
300+
}
301+
302+
pub struct nd_opt_prefix_info {
303+
pub nd_opt_pi_type: u8,
304+
pub nd_opt_pi_len: u8,
305+
pub nd_opt_pi_prefix_len: u8,
306+
pub nd_opt_pi_flags_reserved: u8,
307+
pub nd_opt_pi_valid_time: u32,
308+
pub nd_opt_pi_preferred_time: u32,
309+
pub nd_opt_pi_reserved2: u32,
310+
pub nd_opt_pi_prefix: in6_addr,
311+
}
312+
313+
pub struct nd_opt_rd_hdr {
314+
pub nd_opt_rh_type: u8,
315+
pub nd_opt_rh_len: u8,
316+
pub nd_opt_rh_reserved1: u16,
317+
pub nd_opt_rh_reserved2: u32,
318+
}
319+
320+
pub struct nd_opt_mtu {
321+
pub nd_opt_mtu_type: u8,
322+
pub nd_opt_mtu_len: u8,
323+
pub nd_opt_mtu_reserved: u16,
324+
pub nd_opt_mtu_mtu: u32,
325+
}
220326
}
221327

222328
s_no_extra_traits! {
@@ -364,6 +470,63 @@ pub const ATF_PERM: c_int = 0x04;
364470
pub const ATF_PUBL: c_int = 0x08;
365471
pub const ATF_USETRAILERS: c_int = 0x10;
366472

473+
// ICMPv6 Type and Code Values
474+
pub const ICMP6_DST_UNREACH: u8 = 1;
475+
pub const ICMP6_PACKET_TOO_BIG: u8 = 2;
476+
pub const ICMP6_TIME_EXCEEDED: u8 = 3;
477+
pub const ICMP6_PARAM_PROB: u8 = 4;
478+
479+
pub const ICMP6_INFOMSG_MASK: u8 = 0x80;
480+
481+
pub const ICMP6_ECHO_REQUEST: u8 = 128;
482+
pub const ICMP6_ECHO_REPLY: u8 = 129;
483+
pub const MLD_LISTENER_QUERY: u8 = 130;
484+
pub const MLD_LISTENER_REPORT: u8 = 131;
485+
pub const MLD_LISTENER_REDUCTION: u8 = 132;
486+
487+
pub const ICMP6_DST_UNREACH_NOROUTE: u8 = 0;
488+
pub const ICMP6_DST_UNREACH_ADMIN: u8 = 1;
489+
pub const ICMP6_DST_UNREACH_BEYONDSCOPE: u8 = 2;
490+
pub const ICMP6_DST_UNREACH_ADDR: u8 = 3;
491+
pub const ICMP6_DST_UNREACH_NOPORT: u8 = 4;
492+
493+
pub const ICMP6_TIME_EXCEED_TRANSIT: u8 = 0;
494+
pub const ICMP6_TIME_EXCEED_REASSEMBLY: u8 = 1;
495+
496+
pub const ICMP6_PARAMPROB_HEADER: u8 = 0;
497+
pub const ICMP6_PARAMPROB_NEXTHEADER: u8 = 1;
498+
pub const ICMP6_PARAMPROB_OPTION: u8 = 2;
499+
500+
// ICMPv6 Neighbor Discovery Type and Code Values
501+
pub const ND_ROUTER_SOLICIT: u8 = 133;
502+
pub const ND_ROUTER_ADVERT: u8 = 134;
503+
pub const ND_NEIGHBOR_SOLICIT: u8 = 135;
504+
pub const ND_NEIGHBOR_ADVERT: u8 = 136;
505+
pub const ND_REDIRECT: u8 = 137;
506+
507+
pub const ND_RA_FLAG_MANAGED: u8 = 0x80;
508+
pub const ND_RA_FLAG_OTHER: u8 = 0x40;
509+
510+
cfg_if! {
511+
if #[cfg(target_endian = "big")] {
512+
pub const ND_NA_FLAG_ROUTER: u32 = 0x80000000;
513+
pub const ND_NA_FLAG_SOLICITED: u32 = 0x40000000;
514+
pub const ND_NA_FLAG_OVERRIDE: u32 = 0x20000000;
515+
} else {
516+
pub const ND_NA_FLAG_ROUTER: u32 = 0x00000080;
517+
pub const ND_NA_FLAG_SOLICITED: u32 = 0x00000040;
518+
pub const ND_NA_FLAG_OVERRIDE: u32 = 0x00000020;
519+
}
520+
}
521+
522+
pub const ND_OPT_SOURCE_LINKADDR: u8 = 1;
523+
pub const ND_OPT_TARGET_LINKADDR: u8 = 2;
524+
pub const ND_OPT_PREFIX_INFORMATION: u8 = 3;
525+
pub const ND_OPT_REDIRECTED_HEADER: u8 = 4;
526+
pub const ND_OPT_MTU: u8 = 5;
527+
pub const ND_OPT_PI_FLAG_ONLINK: u8 = 0x80;
528+
pub const ND_OPT_PI_FLAG_AUTO: u8 = 0x40;
529+
367530
cfg_if! {
368531
if #[cfg(any(target_os = "nto", target_os = "aix"))] {
369532
pub const FNM_PERIOD: c_int = 1 << 1;

0 commit comments

Comments
 (0)