Skip to content

Commit c0eb283

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 c0eb283

File tree

4 files changed

+175
-0
lines changed

4 files changed

+175
-0
lines changed

libc-test/build.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ fn test_apple(target: &str) {
254254
"netinet/ip.h",
255255
"netinet/tcp.h",
256256
"netinet/udp.h",
257+
"netinet/icmp6.h",
257258
"netinet6/in6_var.h",
258259
"os/clock.h",
259260
"os/lock.h",
@@ -449,6 +450,7 @@ fn test_openbsd(target: &str) {
449450
"netinet/ip.h",
450451
"netinet/tcp.h",
451452
"netinet/udp.h",
453+
"netinet/icmp6.h",
452454
"net/bpf.h",
453455
"regex.h",
454456
"resolv.h",
@@ -867,6 +869,7 @@ fn test_redox(target: &str) {
867869
"netinet/in.h",
868870
"netinet/ip.h",
869871
"netinet/tcp.h",
872+
"netinet/icmp6.h",
870873
"poll.h",
871874
"pwd.h",
872875
"semaphore.h",
@@ -945,6 +948,7 @@ fn test_solarish(target: &str) {
945948
"netinet/ip.h",
946949
"netinet/tcp.h",
947950
"netinet/udp.h",
951+
"netinet/icmp6.h",
948952
"poll.h",
949953
"port.h",
950954
"pthread.h",
@@ -1229,6 +1233,7 @@ fn test_netbsd(target: &str) {
12291233
"netinet/ip.h",
12301234
"netinet/tcp.h",
12311235
"netinet/udp.h",
1236+
"netinet/icmp6.h",
12321237
"poll.h",
12331238
"pthread.h",
12341239
"pwd.h",
@@ -1518,6 +1523,7 @@ fn test_dragonflybsd(target: &str) {
15181523
"netinet/ip.h",
15191524
"netinet/tcp.h",
15201525
"netinet/udp.h",
1526+
"netinet/icmp6.h",
15211527
"poll.h",
15221528
"pthread.h",
15231529
"pthread_np.h",
@@ -1833,6 +1839,7 @@ fn test_android(target: &str) {
18331839
"netinet/ip.h",
18341840
"netinet/tcp.h",
18351841
"netinet/udp.h",
1842+
"netinet/icmp6.h",
18361843
"netpacket/packet.h",
18371844
"poll.h",
18381845
"pthread.h",
@@ -2373,6 +2380,7 @@ fn test_freebsd(target: &str) {
23732380
"netinet/sctp.h",
23742381
"netinet/tcp.h",
23752382
"netinet/udp.h",
2383+
"netinet/icmp6.h",
23762384
"poll.h",
23772385
"pthread.h",
23782386
"pthread_np.h",
@@ -3000,6 +3008,7 @@ fn test_emscripten(target: &str) {
30003008
"netinet/ip.h",
30013009
"netinet/tcp.h",
30023010
"netinet/udp.h",
3011+
"netinet/icmp6.h",
30033012
"netpacket/packet.h",
30043013
"poll.h",
30053014
"pthread.h",
@@ -3268,6 +3277,7 @@ fn test_neutrino(target: &str) {
32683277
"netinet/tcp.h",
32693278
"netinet/udp.h",
32703279
"netinet/ip_var.h",
3280+
"netinet/icmp6.h",
32713281
"sys/poll.h",
32723282
"pthread.h",
32733283
"pwd.h",
@@ -3764,6 +3774,7 @@ fn test_linux(target: &str) {
37643774
"netinet/ip.h",
37653775
"netinet/tcp.h",
37663776
"netinet/udp.h",
3777+
"netinet/icmp6.h",
37673778
(l4re, "netpacket/packet.h"),
37683779
"poll.h",
37693780
"pthread.h",
@@ -5022,6 +5033,7 @@ fn test_haiku(target: &str) {
50225033
"netinet/ip_var.h",
50235034
"netinet/tcp.h",
50245035
"netinet/udp.h",
5036+
"netinet/icmp6.h",
50255037
"netinet6/in6.h",
50265038
"nl_types.h",
50275039
"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: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,108 @@ 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+
pub ip6r0_reserved: u8,
244+
pub ip6r0_slmap: [u8; 3],
245+
pub ip6r0_addr: in6_addr,
246+
}
247+
248+
pub struct ip6_frag {
249+
ip6f_nxt: u8,
250+
ip6f_reserved: u8,
251+
ip6f_offlg: u16,
252+
ip6f_ident: u32,
253+
}
254+
255+
pub struct icmp6_filter {
256+
pub icmp6_filt: [u32; 8],
257+
}
258+
259+
pub struct icmp6_hdr {
260+
pub icmp6_type: u8,
261+
pub icmp6_code: u8,
262+
pub icmp6_chksum: u16,
263+
pub icmp6_un_data: [u8; 4],
264+
}
265+
266+
pub struct nd_router_solicit {
267+
pub nd_rs_hdr: icmp6_hdr,
268+
}
269+
270+
pub struct nd_router_advert {
271+
pub nd_ra_hdr: icmp6_hdr,
272+
pub nd_ra_reachable: u32,
273+
pub nd_ra_retransmit: u32,
274+
}
275+
276+
pub struct nd_neighbor_solicit {
277+
pub nd_ns_hdr: icmp6_hdr,
278+
pub nd_ns_target: in6_addr,
279+
}
280+
281+
pub struct nd_neighbor_advert {
282+
pub nd_na_hdr: icmp6_hdr,
283+
pub nd_na_target: in6_addr,
284+
}
285+
286+
pub struct nd_redirect {
287+
pub nd_rd_hdr: icmp6_hdr,
288+
pub nd_rd_target: in6_addr,
289+
pub nd_rd_dst: in6_addr,
290+
}
291+
292+
pub struct nd_opt_hdr {
293+
pub nd_opt_type: u8,
294+
pub nd_opt_len: u8,
295+
}
296+
297+
pub struct nd_opt_prefix_info {
298+
pub nd_opt_pi_type: u8,
299+
pub nd_opt_pi_len: u8,
300+
pub nd_opt_pi_prefix_len: u8,
301+
pub nd_opt_pi_flags_reserved: u8,
302+
pub nd_opt_pi_valid_time: u32,
303+
pub nd_opt_pi_preferred_time: u32,
304+
pub nd_opt_pi_reserved2: u32,
305+
pub nd_opt_pi_prefix: in6_addr,
306+
}
307+
308+
pub struct nd_opt_rd_hdr {
309+
pub nd_opt_rh_type: u8,
310+
pub nd_opt_rh_len: u8,
311+
pub nd_opt_rh_reserved1: u16,
312+
pub nd_opt_rh_reserved2: u32,
313+
}
314+
315+
pub struct nd_opt_mtu {
316+
pub nd_opt_mtu_type: u8,
317+
pub nd_opt_mtu_len: u8,
318+
pub nd_opt_mtu_reserved1: u16,
319+
pub nd_opt_mtu_reserved2: u32,
320+
}
321+
220322
}
221323

222324
s_no_extra_traits! {
@@ -364,6 +466,64 @@ pub const ATF_PERM: c_int = 0x04;
364466
pub const ATF_PUBL: c_int = 0x08;
365467
pub const ATF_USETRAILERS: c_int = 0x10;
366468

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

0 commit comments

Comments
 (0)