aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/addr.rs72
-rw-r--r--src/main.rs5
2 files changed, 74 insertions, 3 deletions
diff --git a/src/addr.rs b/src/addr.rs
index ceae1ec..fa4fb89 100644
--- a/src/addr.rs
+++ b/src/addr.rs
@@ -4,7 +4,7 @@ use std::net::IpAddr;
use futures::future;
use futures_util::TryStreamExt;
-use netlink_packet_route::{AddressMessage, AF_INET6, RT_SCOPE_LINK, RT_SCOPE_UNIVERSE};
+use netlink_packet_route::{AddressMessage, AF_INET, AF_INET6, RT_SCOPE_LINK, RT_SCOPE_UNIVERSE};
use tokio::runtime::Runtime;
async fn do_flush(link: String) -> Result<()> {
@@ -41,6 +41,76 @@ pub fn flush(link: String) -> Result<()> {
Runtime::new()?.block_on(do_flush(link))
}
+async fn do_flush4(link: String) -> Result<()> {
+ let (conn, handle, _) = rtnetlink::new_connection()?;
+ tokio::spawn(conn);
+
+ let link = handle
+ .link()
+ .get()
+ .match_name(link.clone())
+ .execute()
+ .try_next()
+ .await?
+ .ok_or(Error::LinkNotFound(link))?;
+
+ let id = link.header.index;
+
+ let addrs: Vec<AddressMessage> = handle
+ .address()
+ .get()
+ .set_link_index_filter(id)
+ .execute()
+ .try_filter(|addr| future::ready(addr.header.family == AF_INET as u8))
+ .try_collect()
+ .await?;
+
+ for addr in addrs {
+ handle.address().del(addr).execute().await?;
+ }
+
+ Ok(())
+}
+
+pub fn flush4(link: String) -> Result<()> {
+ Runtime::new()?.block_on(do_flush4(link))
+}
+
+async fn do_flush6(link: String) -> Result<()> {
+ let (conn, handle, _) = rtnetlink::new_connection()?;
+ tokio::spawn(conn);
+
+ let link = handle
+ .link()
+ .get()
+ .match_name(link.clone())
+ .execute()
+ .try_next()
+ .await?
+ .ok_or(Error::LinkNotFound(link))?;
+
+ let id = link.header.index;
+
+ let addrs: Vec<AddressMessage> = handle
+ .address()
+ .get()
+ .set_link_index_filter(id)
+ .execute()
+ .try_filter(|addr| future::ready(addr.header.family == AF_INET6 as u8))
+ .try_collect()
+ .await?;
+
+ for addr in addrs {
+ handle.address().del(addr).execute().await?;
+ }
+
+ Ok(())
+}
+
+pub fn flush6(link: String) -> Result<()> {
+ Runtime::new()?.block_on(do_flush6(link))
+}
+
async fn do_flush6_global() -> Result<()> {
let (conn, handle, _) = rtnetlink::new_connection()?;
tokio::spawn(conn);
diff --git a/src/main.rs b/src/main.rs
index eef8154..d72250d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -180,20 +180,20 @@ fn configure_ipv6() {
}
fn configure_all_v6() -> Result<()> {
- addr::flush6_global()?;
-
let mut file = File::open(rsdsl_pd_config::LOCATION)?;
let pd_config: PdConfig = serde_json::from_reader(&mut file)?;
let prefix = Ipv6Net::new(pd_config.prefix, pd_config.len)?.trunc();
let mut subnets = prefix.subnets(64)?;
+ addr::flush6_global()?;
addr::add("ppp0".into(), IpAddr::V6(next_ifid1(&mut subnets)?), 64)?;
let addr = next_ifid1(&mut subnets)?;
fs::write("/proc/sys/net/ipv6/conf/eth0/accept_ra", "0")?;
+ addr::flush6("eth0".into())?;
addr::add_link_local("eth0".into(), LINK_LOCAL.into(), 64)?;
addr::add("eth0".into(), addr.into(), 64)?;
@@ -210,6 +210,7 @@ fn configure_all_v6() -> Result<()> {
"0",
)?;
+ addr::flush6(vlan_name.clone())?;
addr::add_link_local(vlan_name.clone(), LINK_LOCAL.into(), 64)?;
addr::add(vlan_name.clone(), vlan_addr.into(), 64)?;