Debian Codegraph @

src/interface/linux.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#, osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::RawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/RawFd#};
2
3 use libcrust-analyzer cargo libc 0.2.152 crate/::recvrust-analyzer cargo libc 0.2.152 recv().;
4 use tokiorust-analyzer cargo tokio 1.35.1 crate/::iorust-analyzer cargo tokio 1.35.1 io/::{unixrust-analyzer cargo tokio 1.35.1 io/unix/::AsyncFdrust-analyzer cargo tokio 1.35.1 io/async_fd/AsyncFd#, Interestrust-analyzer cargo tokio 1.35.1 io/interest/Interest#};
5
6 use craterust-analyzer cargo timestamped-socket 0.2.2 crate/::{cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr()., control_messagerust-analyzer cargo timestamped-socket 0.2.2 control_message/::zeroed_sockaddr_storagerust-analyzer cargo timestamped-socket 0.2.2 control_message/zeroed_sockaddr_storage().};
7
8 pub struct ChangeDetectorrust-analyzer cargo timestamped-socket 0.2.2 interface/linux/ChangeDetector# {
9 fdrust-analyzer cargo timestamped-socket 0.2.2 interface/linux/ChangeDetector#fd.: AsyncFdrust-analyzer cargo tokio 1.35.1 io/async_fd/AsyncFd#<RawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/RawFd#>,
10 }
11
12 impl ChangeDetectorrust-analyzer cargo timestamped-socket 0.2.2 interface/linux/ChangeDetector# {
13 pub fn newrust-analyzer cargo timestamped-socket 0.2.2 interface/linux/impl#[ChangeDetector]new().() -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo timestamped-socket 0.2.2 interface/linux/impl#[ChangeDetector]> {
14 const _: () = assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
15 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<libcrust-analyzer cargo libc 0.2.152 crate/::sockaddr_storagerust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_storage#>()
16 >= stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<libcrust-analyzer cargo libc 0.2.152 crate/::sockaddr_nlrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/sockaddr_nl#>()
17 );
18 const _: () = assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
19 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::align_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/align_of().::<libcrust-analyzer cargo libc 0.2.152 crate/::sockaddr_storagerust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_storage#>()
20 >= stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::align_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/align_of().::<libcrust-analyzer cargo libc 0.2.152 crate/::sockaddr_nlrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/sockaddr_nl#>()
21 );
22
23 let mut address_buf = zeroed_sockaddr_storagerust-analyzer cargo timestamped-socket 0.2.2 control_message/zeroed_sockaddr_storage().();
24 // Safety: the above assertions guarantee that alignment and size are correct.
25 // the resulting reference won't outlast the function, and result lives the entire
26 // duration of the function
27 let address = unsafe {
28 &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().(&mut address_buf as *mut libcrust-analyzer cargo libc 0.2.152 crate/::sockaddr_storagerust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_storage# as *mut libcrust-analyzer cargo libc 0.2.152 crate/::sockaddr_nlrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/sockaddr_nl#)
29 };
30
31 address.nl_familyrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/sockaddr_nl#nl_family. = libcrust-analyzer cargo libc 0.2.152 crate/::AF_NETLINKrust-analyzer cargo libc 0.2.152 unix/linux_like/AF_NETLINK. as _;
32 address.nl_groupsrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/sockaddr_nl#nl_groups. =
33 (libcrust-analyzer cargo libc 0.2.152 crate/::RTMGRP_IPV4_IFADDRrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/RTMGRP_IPV4_IFADDR. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor().libcrust-analyzer cargo libc 0.2.152 crate/::RTMGRP_IPV6_IFADDRrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/RTMGRP_IPV6_IFADDR. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOr<Self>`]bitor().libcrust-analyzer cargo libc 0.2.152 crate/::RTMGRP_LINKrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/RTMGRP_LINK.) as _;
34
35 // Safety: calling socket is safe
36 let fd =
37 cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(unsafe { libcrust-analyzer cargo libc 0.2.152 crate/::socketrust-analyzer cargo libc 0.2.152 socket().(libcrust-analyzer cargo libc 0.2.152 crate/::AF_NETLINKrust-analyzer cargo libc 0.2.152 unix/linux_like/AF_NETLINK., libcrust-analyzer cargo libc 0.2.152 crate/::SOCK_RAWrust-analyzer cargo libc 0.2.152 unix/linux_like/SOCK_RAW., libcrust-analyzer cargo libc 0.2.152 crate/::NETLINK_ROUTErust-analyzer cargo libc 0.2.152 unix/linux_like/linux/NETLINK_ROUTE.) })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
38 // Safety: address is valid for the duration of the call
39 cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(unsafe {
40 libcrust-analyzer cargo libc 0.2.152 crate/::bindrust-analyzer cargo libc 0.2.152 bind().(
41 fd,
42 address as *mut _ as *mut _,
43 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_of_valrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of_val().(address) as _,
44 )
45 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
46
47 let nonblocking = 1 as libcrust-analyzer cargo libc 0.2.152 crate/::c_intrust-analyzer cargo libc 0.2.152 unix/c_int#;
48 // Safety: nonblocking lives for the duration of the call, and is 4 bytes long as expected for FIONBIO
49 cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(unsafe { libcrust-analyzer cargo libc 0.2.152 crate/::ioctlrust-analyzer cargo libc 0.2.152 ioctl().(fd, libcrust-analyzer cargo libc 0.2.152 crate/::FIONBIOrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/arch/generic/FIONBIO., &nonblocking) })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
50
51 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ChangeDetectorrust-analyzer cargo timestamped-socket 0.2.2 interface/linux/ChangeDetector# {
52 fdrust-analyzer cargo timestamped-socket 0.2.2 interface/linux/ChangeDetector#fd.: AsyncFdrust-analyzer cargo tokio 1.35.1 io/async_fd/AsyncFd#::newrust-analyzer cargo tokio 1.35.1 io/async_fd/impl#[`AsyncFd<T>`]new().(fd)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
53 })
54 }
55
56 fn emptyrust-analyzer cargo timestamped-socket 0.2.2 interface/linux/impl#[ChangeDetector]empty().(fd: i32) {
57 loop {
58 // Safety: buf is valid for the duration of the call, and it's length is passed as the len argument
59 let mut buf = [0u8; 16];
60 match cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(unsafe {
61 recvrust-analyzer cargo libc 0.2.152 recv().(
62 fd,
63 &mut buf as *mut _ as *mut _,
64 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_of_valrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of_val().(&buf) as _,
65 0,
66 ) as _
67 }) {
68 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => continue,
69 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) if e.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::WouldBlockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#WouldBlock# => break,
70 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => {
71 tracingrust-analyzer cargo tracing 0.1.37 crate/::errorrust-analyzer cargo tracing 0.1.37 macros/error!!("Could not receive on change socket: {}", e);
72 break;
73 }
74 }
75 }
76 }
77
78 pub async fn wait_for_changerust-analyzer cargo timestamped-socket 0.2.2 interface/linux/impl#[ChangeDetector]wait_for_change().(&mut self) {
79 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) = self
80 .fdrust-analyzer cargo timestamped-socket 0.2.2 interface/linux/ChangeDetector#fd.
81 .async_iorust-analyzer cargo tokio 1.35.1 io/async_fd/impl#[`AsyncFd<T>`]async_io().(Interestrust-analyzer cargo tokio 1.35.1 io/interest/Interest#::READABLErust-analyzer cargo tokio 1.35.1 io/interest/impl#[Interest]READABLE., |fd| {
82 // Safety: buf is valid for the duration of the call, and it's length is passed as the len argument
83 let mut buf = [0u8; 16];
84 cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(unsafe {
85 recvrust-analyzer cargo libc 0.2.152 recv().(
86 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().fd,
87 &mut buf as *mut _ as *mut _,
88 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_of_valrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of_val().(&buf) as _,
89 0,
90 ) as _
91 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
92 Selfrust-analyzer cargo timestamped-socket 0.2.2 interface/linux/impl#[ChangeDetector]::emptyrust-analyzer cargo timestamped-socket 0.2.2 interface/linux/impl#[ChangeDetector]empty().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().fd);
93 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
94 })
95 .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
96 {
97 tracingrust-analyzer cargo tracing 0.1.37 crate/::errorrust-analyzer cargo tracing 0.1.37 macros/error!!("Could not receive on change socket: {}", e);
98 }
99 }
100 }