forked from virt-do/cloudlet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get internet access (virt-do#39)
* feat: create bridge interface Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr> * feat: create bridge only if not exist Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr> * fix: cargo clippy Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr> * feat: send code though gRPC to the agent (virt-do#37) * feat(agent/proto): add agent configuration in execute request Signed-off-by: Martin Moreira de Jesus <martin.moreira-de-jesus@protonmail.com> * feat: send code through cli and api to vm Signed-off-by: Mauran <thomas.mauran@etu.umontpellier.fr> --------- Signed-off-by: Martin Moreira de Jesus <martin.moreira-de-jesus@protonmail.com> Signed-off-by: Mauran <thomas.mauran@etu.umontpellier.fr> Co-authored-by: Martin Moreira de Jesus <martin.moreira-de-jesus@protonmail.com> * Feat: add initramfs implementation for vmm (virt-do#34) * feat(vmm): implemented automatic generation of rootfs with initramfs Signed-off-by: Muriel Paraire <72733662+MurielParaire@users.noreply.github.com> * feat: image generation based off language Signed-off-by: Muriel Paraire <72733662+MurielParaire@users.noreply.github.com> * feat(vmm): implemented automatic generation of rootfs with initramfs Signed-off-by: Muriel Paraire <72733662+MurielParaire@users.noreply.github.com> * fix(vmm): fix logging & language order Signed-off-by: Muriel Paraire <72733662+MurielParaire@users.noreply.github.com> * feat(vmm): one image per language Signed-off-by: Muriel Paraire <72733662+MurielParaire@users.noreply.github.com> * feat(vmm): implemented initramfs Signed-off-by: Muriel Paraire <72733662+MurielParaire@users.noreply.github.com> * fix(vmm): code cleanup Signed-off-by: Muriel Paraire <72733662+MurielParaire@users.noreply.github.com> * fix(vmm): code cleanup Signed-off-by: Muriel Paraire <72733662+MurielParaire@users.noreply.github.com> * fix(vmm): code cleanup Signed-off-by: Muriel Paraire <72733662+MurielParaire@users.noreply.github.com> * fix: rust export for cargo agent and increase MMIO_GAP_END Signed-off-by: Mauran <thomas.mauran@etu.umontpellier.fr> * chore: lint Signed-off-by: Mauran <thomas.mauran@etu.umontpellier.fr> * fix: add back tracing Signed-off-by: Mauran <thomas.mauran@etu.umontpellier.fr> --------- Signed-off-by: Muriel Paraire <72733662+MurielParaire@users.noreply.github.com> Signed-off-by: Mauran <thomas.mauran@etu.umontpellier.fr> Co-authored-by: Mauran <thomas.mauran@etu.umontpellier.fr> * feat: internet works Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr> * fix: cargo clippy Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr> --------- Signed-off-by: sylvain-pierrot <sylvain.pierrot@etu.umontpellier.fr> Signed-off-by: Martin Moreira de Jesus <martin.moreira-de-jesus@protonmail.com> Signed-off-by: Mauran <thomas.mauran@etu.umontpellier.fr> Signed-off-by: Muriel Paraire <72733662+MurielParaire@users.noreply.github.com> Co-authored-by: Thomas Mauran <78204354+thomas-mauran@users.noreply.github.com> Co-authored-by: Martin Moreira de Jesus <martin.moreira-de-jesus@protonmail.com> Co-authored-by: Muriel Paraire <72733662+MurielParaire@users.noreply.github.com> Co-authored-by: Mauran <thomas.mauran@etu.umontpellier.fr> Signed-off-by: Muriel Paraire <72733662+MurielParaire@users.noreply.github.com>
- Loading branch information
1 parent
cfdb10d
commit 3c3bceb
Showing
9 changed files
with
198 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
use std::net::{IpAddr, Ipv4Addr}; | ||
|
||
use futures::stream::TryStreamExt; | ||
use rtnetlink::{new_connection, Error, Handle}; | ||
|
||
use super::xx_netmask_width; | ||
|
||
#[derive(Clone)] | ||
pub struct Bridge { | ||
name: String, | ||
handle: Handle, | ||
} | ||
|
||
impl Bridge { | ||
pub fn new(name: String) -> Self { | ||
let (connection, handle, _) = new_connection().unwrap(); | ||
tokio::spawn(connection); | ||
|
||
let br = Self { name, handle }; | ||
br.create_bridge_if_not_exist(); | ||
|
||
br | ||
} | ||
|
||
fn create_bridge_if_not_exist(&self) { | ||
futures::executor::block_on(async { | ||
let mut bridge_names = self | ||
.handle | ||
.link() | ||
.get() | ||
.match_name(self.name.clone()) | ||
.execute(); | ||
|
||
let _ = match bridge_names.try_next().await { | ||
Ok(_) => Ok(()), | ||
Err(_) => self | ||
.handle | ||
.link() | ||
.add() | ||
.bridge(self.name.clone()) | ||
.execute() | ||
.await | ||
.map_err(|_| Error::RequestFailed), | ||
}; | ||
}); | ||
} | ||
|
||
pub fn set_addr(&self, addr: Ipv4Addr, netmask: Ipv4Addr) { | ||
futures::executor::block_on(async { | ||
let mut bridge_names = self | ||
.handle | ||
.link() | ||
.get() | ||
.match_name(self.name.clone()) | ||
.execute(); | ||
|
||
let bridge_index = match bridge_names.try_next().await { | ||
Ok(Some(link)) => link.header.index, | ||
Ok(None) => panic!(), | ||
Err(_) => panic!(), | ||
}; | ||
|
||
let prefix_len = xx_netmask_width(netmask.octets()); | ||
|
||
let _ = self | ||
.handle | ||
.address() | ||
.add(bridge_index, IpAddr::V4(addr), prefix_len) | ||
.execute() | ||
.await | ||
.map_err(|_| Error::RequestFailed); | ||
}); | ||
} | ||
|
||
pub fn set_up(&self) { | ||
futures::executor::block_on(async { | ||
let mut bridge_names = self | ||
.handle | ||
.link() | ||
.get() | ||
.match_name(self.name.clone()) | ||
.execute(); | ||
|
||
let bridge_index = match bridge_names.try_next().await { | ||
Ok(Some(link)) => link.header.index, | ||
Ok(None) => panic!(), | ||
Err(_) => panic!(), | ||
}; | ||
|
||
let _ = self | ||
.handle | ||
.link() | ||
.set(bridge_index) | ||
.up() | ||
.execute() | ||
.await | ||
.map_err(|_| Error::RequestFailed); | ||
}); | ||
} | ||
|
||
pub fn attach_link(&self, link_name: String) { | ||
futures::executor::block_on(async { | ||
let mut link_names = self | ||
.handle | ||
.link() | ||
.get() | ||
.match_name(link_name.clone()) | ||
.execute(); | ||
let mut master_names = self | ||
.handle | ||
.link() | ||
.get() | ||
.match_name(self.name.clone()) | ||
.execute(); | ||
|
||
let link_index = match link_names.try_next().await { | ||
Ok(Some(link)) => link.header.index, | ||
Ok(None) => panic!(), | ||
Err(_) => panic!(), | ||
}; | ||
let master_index = match master_names.try_next().await { | ||
Ok(Some(link)) => link.header.index, | ||
Ok(None) => panic!(), | ||
Err(_) => panic!(), | ||
}; | ||
|
||
let _ = self | ||
.handle | ||
.link() | ||
.set(link_index) | ||
.controller(master_index) | ||
.execute() | ||
.await | ||
.map_err(|_| Error::RequestFailed); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use std::net::Ipv4Addr; | ||
|
||
use super::xx_netmask_width; | ||
|
||
pub fn iptables_ip_masq(network: Ipv4Addr, netmask: Ipv4Addr, link_name: String) { | ||
let prefix_len = xx_netmask_width(netmask.octets()); | ||
let source = format!("{}/{}", network, prefix_len); | ||
|
||
let ipt = iptables::new(false).unwrap(); | ||
let rule = format!("-s {} ! -o {} -j MASQUERADE", source, link_name); | ||
|
||
let exists = ipt.exists("nat", "POSTROUTING", rule.as_str()).unwrap(); | ||
if !exists { | ||
let _ = ipt.insert_unique("nat", "POSTROUTING", rule.as_str(), 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters