Skip to content

Commit b8f20e4

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 b8f20e4

4 files changed

Lines changed: 197 additions & 0 deletions

File tree

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: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,124 @@ 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+
#[repr(align(1))]
239+
pub struct ip6_rthdr0 {
240+
pub ip6r0_nxt: u8,
241+
pub ip6r0_len: u8,
242+
pub ip6r0_type: u8,
243+
pub ip6r0_segleft: u8,
244+
#[cfg(not(target_os = "linux"))]
245+
pub ip6r0_reserved: u32,
246+
#[cfg(target_os = "linux")]
247+
pub ip6r0_reserved: u8,
248+
#[cfg(target_os = "linux")]
249+
pub ip6r0_slmap: [u8; 3],
250+
#[cfg(target_os = "linux")]
251+
pub ip6r0_addr: [in6_addr; 0],
252+
}
253+
254+
#[repr(align(1))]
255+
pub struct ip6_frag {
256+
ip6f_nxt: u8,
257+
ip6f_reserved: u8,
258+
ip6f_offlg: u16,
259+
ip6f_ident: u32,
260+
}
261+
262+
pub struct icmp6_filter {
263+
pub icmp6_filt: [u32; 8],
264+
}
265+
266+
#[repr(align(1))]
267+
pub struct icmp6_hdr {
268+
pub icmp6_type: u8,
269+
pub icmp6_code: u8,
270+
pub icmp6_cksum: u16,
271+
pub icmp6_data8: [u8; 4],
272+
}
273+
274+
#[repr(align(1))]
275+
pub struct nd_router_solicit {
276+
pub nd_rs_hdr: icmp6_hdr,
277+
}
278+
279+
#[repr(align(1))]
280+
pub struct nd_router_advert {
281+
pub nd_ra_hdr: icmp6_hdr,
282+
pub nd_ra_reachable: u32,
283+
pub nd_ra_retransmit: u32,
284+
}
285+
286+
#[repr(align(1))]
287+
pub struct nd_neighbor_solicit {
288+
pub nd_ns_hdr: icmp6_hdr,
289+
pub nd_ns_target: in6_addr,
290+
}
291+
292+
#[repr(align(1))]
293+
pub struct nd_neighbor_advert {
294+
pub nd_na_hdr: icmp6_hdr,
295+
pub nd_na_target: in6_addr,
296+
}
297+
298+
#[repr(align(1))]
299+
pub struct nd_redirect {
300+
pub nd_rd_hdr: icmp6_hdr,
301+
pub nd_rd_target: in6_addr,
302+
pub nd_rd_dst: in6_addr,
303+
}
304+
305+
#[repr(align(1))]
306+
pub struct nd_opt_hdr {
307+
pub nd_opt_type: u8,
308+
pub nd_opt_len: u8,
309+
}
310+
311+
#[repr(align(1))]
312+
pub struct nd_opt_prefix_info {
313+
pub nd_opt_pi_type: u8,
314+
pub nd_opt_pi_len: u8,
315+
pub nd_opt_pi_prefix_len: u8,
316+
pub nd_opt_pi_flags_reserved: u8,
317+
pub nd_opt_pi_valid_time: u32,
318+
pub nd_opt_pi_preferred_time: u32,
319+
pub nd_opt_pi_reserved2: u32,
320+
pub nd_opt_pi_prefix: in6_addr,
321+
}
322+
323+
#[repr(align(1))]
324+
pub struct nd_opt_rd_hdr {
325+
pub nd_opt_rh_type: u8,
326+
pub nd_opt_rh_len: u8,
327+
pub nd_opt_rh_reserved1: u16,
328+
pub nd_opt_rh_reserved2: u32,
329+
}
330+
331+
#[repr(align(1))]
332+
pub struct nd_opt_mtu {
333+
pub nd_opt_mtu_type: u8,
334+
pub nd_opt_mtu_len: u8,
335+
pub nd_opt_mtu_reserved: u16,
336+
pub nd_opt_mtu_mtu: u32,
337+
}
220338
}
221339

222340
s_no_extra_traits! {
@@ -364,6 +482,63 @@ pub const ATF_PERM: c_int = 0x04;
364482
pub const ATF_PUBL: c_int = 0x08;
365483
pub const ATF_USETRAILERS: c_int = 0x10;
366484

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

0 commit comments

Comments
 (0)