Skip to content

Commit 16f3cea

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 16f3cea

File tree

4 files changed

+269
-0
lines changed

4 files changed

+269
-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: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,196 @@ 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+
#[cfg_attr(any(
239+
target_os = "freebsd",
240+
target_os = "openbsd",
241+
target_os = "netbsd",
242+
target_os = "dragonfly",
243+
target_os = "macos"
244+
), repr(packed))]
245+
pub struct ip6_rthdr0 {
246+
pub ip6r0_nxt: u8,
247+
pub ip6r0_len: u8,
248+
pub ip6r0_type: u8,
249+
pub ip6r0_segleft: u8,
250+
#[cfg(not(target_os = "linux"))]
251+
pub ip6r0_reserved: u32,
252+
#[cfg(target_os = "linux")]
253+
pub ip6r0_reserved: u8,
254+
#[cfg(target_os = "linux")]
255+
pub ip6r0_slmap: [u8; 3],
256+
#[cfg(target_os = "linux")]
257+
pub ip6r0_addr: [in6_addr; 0],
258+
}
259+
260+
#[cfg_attr(any(
261+
target_os = "freebsd",
262+
target_os = "openbsd",
263+
target_os = "netbsd",
264+
target_os = "dragonfly",
265+
target_os = "macos"
266+
), repr(packed))]
267+
pub struct ip6_frag {
268+
ip6f_nxt: u8,
269+
ip6f_reserved: u8,
270+
ip6f_offlg: u16,
271+
ip6f_ident: u32,
272+
}
273+
274+
pub struct icmp6_filter {
275+
pub icmp6_filt: [u32; 8],
276+
}
277+
278+
#[cfg_attr(any(
279+
target_os = "freebsd",
280+
target_os = "openbsd",
281+
target_os = "netbsd",
282+
target_os = "dragonfly",
283+
target_os = "macos"
284+
), repr(packed))]
285+
pub struct icmp6_hdr {
286+
pub icmp6_type: u8,
287+
pub icmp6_code: u8,
288+
pub icmp6_cksum: u16,
289+
pub icmp6_data8: [u8; 4],
290+
}
291+
292+
#[cfg_attr(any(
293+
target_os = "freebsd",
294+
target_os = "openbsd",
295+
target_os = "netbsd",
296+
target_os = "dragonfly",
297+
target_os = "macos"
298+
), repr(packed))]
299+
pub struct nd_router_solicit {
300+
pub nd_rs_hdr: icmp6_hdr,
301+
}
302+
303+
#[cfg_attr(any(
304+
target_os = "freebsd",
305+
target_os = "openbsd",
306+
target_os = "netbsd",
307+
target_os = "dragonfly",
308+
target_os = "macos"
309+
), repr(packed))]
310+
pub struct nd_router_advert {
311+
pub nd_ra_hdr: icmp6_hdr,
312+
pub nd_ra_reachable: u32,
313+
pub nd_ra_retransmit: u32,
314+
}
315+
316+
#[cfg_attr(any(
317+
target_os = "freebsd",
318+
target_os = "openbsd",
319+
target_os = "netbsd",
320+
target_os = "dragonfly",
321+
target_os = "macos"
322+
), repr(packed))]
323+
pub struct nd_neighbor_solicit {
324+
pub nd_ns_hdr: icmp6_hdr,
325+
pub nd_ns_target: in6_addr,
326+
}
327+
328+
#[cfg_attr(any(
329+
target_os = "freebsd",
330+
target_os = "openbsd",
331+
target_os = "netbsd",
332+
target_os = "dragonfly",
333+
target_os = "macos"
334+
), repr(packed))]
335+
pub struct nd_neighbor_advert {
336+
pub nd_na_hdr: icmp6_hdr,
337+
pub nd_na_target: in6_addr,
338+
}
339+
340+
#[cfg_attr(any(
341+
target_os = "freebsd",
342+
target_os = "openbsd",
343+
target_os = "netbsd",
344+
target_os = "dragonfly",
345+
target_os = "macos"
346+
), repr(packed))]
347+
pub struct nd_redirect {
348+
pub nd_rd_hdr: icmp6_hdr,
349+
pub nd_rd_target: in6_addr,
350+
pub nd_rd_dst: in6_addr,
351+
}
352+
353+
#[cfg_attr(any(
354+
target_os = "freebsd",
355+
target_os = "openbsd",
356+
target_os = "netbsd",
357+
target_os = "dragonfly",
358+
target_os = "macos"
359+
), repr(packed))]
360+
pub struct nd_opt_hdr {
361+
pub nd_opt_type: u8,
362+
pub nd_opt_len: u8,
363+
}
364+
365+
#[cfg_attr(any(
366+
target_os = "freebsd",
367+
target_os = "openbsd",
368+
target_os = "netbsd",
369+
target_os = "dragonfly",
370+
target_os = "macos"
371+
), repr(packed))]
372+
pub struct nd_opt_prefix_info {
373+
pub nd_opt_pi_type: u8,
374+
pub nd_opt_pi_len: u8,
375+
pub nd_opt_pi_prefix_len: u8,
376+
pub nd_opt_pi_flags_reserved: u8,
377+
pub nd_opt_pi_valid_time: u32,
378+
pub nd_opt_pi_preferred_time: u32,
379+
pub nd_opt_pi_reserved2: u32,
380+
pub nd_opt_pi_prefix: in6_addr,
381+
}
382+
383+
#[cfg_attr(any(
384+
target_os = "freebsd",
385+
target_os = "openbsd",
386+
target_os = "netbsd",
387+
target_os = "dragonfly",
388+
target_os = "macos"
389+
), repr(packed))]
390+
pub struct nd_opt_rd_hdr {
391+
pub nd_opt_rh_type: u8,
392+
pub nd_opt_rh_len: u8,
393+
pub nd_opt_rh_reserved1: u16,
394+
pub nd_opt_rh_reserved2: u32,
395+
}
396+
397+
#[cfg_attr(any(
398+
target_os = "freebsd",
399+
target_os = "openbsd",
400+
target_os = "netbsd",
401+
target_os = "dragonfly",
402+
target_os = "macos"
403+
), repr(packed))]
404+
pub struct nd_opt_mtu {
405+
pub nd_opt_mtu_type: u8,
406+
pub nd_opt_mtu_len: u8,
407+
pub nd_opt_mtu_reserved: u16,
408+
pub nd_opt_mtu_mtu: u32,
409+
}
220410
}
221411

222412
s_no_extra_traits! {
@@ -364,6 +554,63 @@ pub const ATF_PERM: c_int = 0x04;
364554
pub const ATF_PUBL: c_int = 0x08;
365555
pub const ATF_USETRAILERS: c_int = 0x10;
366556

557+
// ICMPv6 Type and Code Values
558+
pub const ICMP6_DST_UNREACH: u8 = 1;
559+
pub const ICMP6_PACKET_TOO_BIG: u8 = 2;
560+
pub const ICMP6_TIME_EXCEEDED: u8 = 3;
561+
pub const ICMP6_PARAM_PROB: u8 = 4;
562+
563+
pub const ICMP6_INFOMSG_MASK: u8 = 0x80;
564+
565+
pub const ICMP6_ECHO_REQUEST: u8 = 128;
566+
pub const ICMP6_ECHO_REPLY: u8 = 129;
567+
pub const MLD_LISTENER_QUERY: u8 = 130;
568+
pub const MLD_LISTENER_REPORT: u8 = 131;
569+
pub const MLD_LISTENER_REDUCTION: u8 = 132;
570+
571+
pub const ICMP6_DST_UNREACH_NOROUTE: u8 = 0;
572+
pub const ICMP6_DST_UNREACH_ADMIN: u8 = 1;
573+
pub const ICMP6_DST_UNREACH_BEYONDSCOPE: u8 = 2;
574+
pub const ICMP6_DST_UNREACH_ADDR: u8 = 3;
575+
pub const ICMP6_DST_UNREACH_NOPORT: u8 = 4;
576+
577+
pub const ICMP6_TIME_EXCEED_TRANSIT: u8 = 0;
578+
pub const ICMP6_TIME_EXCEED_REASSEMBLY: u8 = 1;
579+
580+
pub const ICMP6_PARAMPROB_HEADER: u8 = 0;
581+
pub const ICMP6_PARAMPROB_NEXTHEADER: u8 = 1;
582+
pub const ICMP6_PARAMPROB_OPTION: u8 = 2;
583+
584+
// ICMPv6 Neighbor Discovery Type and Code Values
585+
pub const ND_ROUTER_SOLICIT: u8 = 133;
586+
pub const ND_ROUTER_ADVERT: u8 = 134;
587+
pub const ND_NEIGHBOR_SOLICIT: u8 = 135;
588+
pub const ND_NEIGHBOR_ADVERT: u8 = 136;
589+
pub const ND_REDIRECT: u8 = 137;
590+
591+
pub const ND_RA_FLAG_MANAGED: u8 = 0x80;
592+
pub const ND_RA_FLAG_OTHER: u8 = 0x40;
593+
594+
cfg_if! {
595+
if #[cfg(target_endian = "big")] {
596+
pub const ND_NA_FLAG_ROUTER: u32 = 0x80000000;
597+
pub const ND_NA_FLAG_SOLICITED: u32 = 0x40000000;
598+
pub const ND_NA_FLAG_OVERRIDE: u32 = 0x20000000;
599+
} else {
600+
pub const ND_NA_FLAG_ROUTER: u32 = 0x00000080;
601+
pub const ND_NA_FLAG_SOLICITED: u32 = 0x00000040;
602+
pub const ND_NA_FLAG_OVERRIDE: u32 = 0x00000020;
603+
}
604+
}
605+
606+
pub const ND_OPT_SOURCE_LINKADDR: u8 = 1;
607+
pub const ND_OPT_TARGET_LINKADDR: u8 = 2;
608+
pub const ND_OPT_PREFIX_INFORMATION: u8 = 3;
609+
pub const ND_OPT_REDIRECTED_HEADER: u8 = 4;
610+
pub const ND_OPT_MTU: u8 = 5;
611+
pub const ND_OPT_PI_FLAG_ONLINK: u8 = 0x80;
612+
pub const ND_OPT_PI_FLAG_AUTO: u8 = 0x40;
613+
367614
cfg_if! {
368615
if #[cfg(any(target_os = "nto", target_os = "aix"))] {
369616
pub const FNM_PERIOD: c_int = 1 << 1;

0 commit comments

Comments
 (0)