mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-17 15:38:00 +00:00
Merge pull request #4854 from openanolis/runtime-rs-delete
runtime-rs: delete route model
This commit is contained in:
commit
830fb266e6
@ -98,7 +98,6 @@ In our case, there will be a variety of resources, and every resource has severa
|
|||||||
| | MACVTAP Endpoint | Stage 3 |
|
| | MACVTAP Endpoint | Stage 3 |
|
||||||
| | `VhostUserEndpoint` | Stage 3 |
|
| | `VhostUserEndpoint` | Stage 3 |
|
||||||
| Network Interworking Model | Tc filter | Stage 1 |
|
| Network Interworking Model | Tc filter | Stage 1 |
|
||||||
| | Route | Stage 1 |
|
|
||||||
| | `MacVtap` | Stage 3 |
|
| | `MacVtap` | Stage 3 |
|
||||||
| Storage | Virtio-fs | Stage 1 |
|
| Storage | Virtio-fs | Stage 1 |
|
||||||
| | `nydus` | Stage 2 |
|
| | `nydus` | Stage 2 |
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
pub mod none_model;
|
pub mod none_model;
|
||||||
pub mod route_model;
|
|
||||||
pub mod tc_filter_model;
|
pub mod tc_filter_model;
|
||||||
pub mod test_network_model;
|
pub mod test_network_model;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -16,12 +15,10 @@ use async_trait::async_trait;
|
|||||||
use super::NetworkPair;
|
use super::NetworkPair;
|
||||||
|
|
||||||
pub(crate) const TC_FILTER_NET_MODEL_STR: &str = "tcfilter";
|
pub(crate) const TC_FILTER_NET_MODEL_STR: &str = "tcfilter";
|
||||||
pub(crate) const ROUTE_NET_MODEL_STR: &str = "route";
|
|
||||||
|
|
||||||
pub enum NetworkModelType {
|
pub enum NetworkModelType {
|
||||||
NoneModel,
|
NoneModel,
|
||||||
TcFilter,
|
TcFilter,
|
||||||
Route,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@ -36,9 +33,6 @@ pub fn new(model: &str) -> Result<Arc<dyn NetworkModel>> {
|
|||||||
TC_FILTER_NET_MODEL_STR => Ok(Arc::new(
|
TC_FILTER_NET_MODEL_STR => Ok(Arc::new(
|
||||||
tc_filter_model::TcFilterModel::new().context("new tc filter model")?,
|
tc_filter_model::TcFilterModel::new().context("new tc filter model")?,
|
||||||
)),
|
)),
|
||||||
ROUTE_NET_MODEL_STR => Ok(Arc::new(
|
|
||||||
route_model::RouteModel::new().context("new route model")?,
|
|
||||||
)),
|
|
||||||
_ => Ok(Arc::new(
|
_ => Ok(Arc::new(
|
||||||
none_model::NoneModel::new().context("new none model")?,
|
none_model::NoneModel::new().context("new none model")?,
|
||||||
)),
|
)),
|
||||||
|
@ -1,88 +0,0 @@
|
|||||||
// Copyright (c) 2019-2022 Alibaba Cloud
|
|
||||||
// Copyright (c) 2019-2022 Ant Group
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
//
|
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
|
||||||
use async_trait::async_trait;
|
|
||||||
use tokio::process::Command;
|
|
||||||
|
|
||||||
use super::{NetworkModel, NetworkModelType};
|
|
||||||
use crate::network::NetworkPair;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub(crate) struct RouteModel {}
|
|
||||||
|
|
||||||
impl RouteModel {
|
|
||||||
pub fn new() -> Result<Self> {
|
|
||||||
Ok(Self {})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl NetworkModel for RouteModel {
|
|
||||||
fn model_type(&self) -> NetworkModelType {
|
|
||||||
NetworkModelType::Route
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn add(&self, pair: &NetworkPair) -> Result<()> {
|
|
||||||
let tap_name = &pair.tap.tap_iface.name;
|
|
||||||
let virt_name = &pair.virt_iface.name;
|
|
||||||
let virt_iface_addr = pair.virt_iface.addrs[0].addr.to_string();
|
|
||||||
|
|
||||||
let commands_args = vec![
|
|
||||||
vec![
|
|
||||||
"rule", "add", "pref", "10", "from", "all", "lookup", "local",
|
|
||||||
],
|
|
||||||
vec!["rule", "del", "pref", "0", "from", "all"],
|
|
||||||
vec!["rule", "add", "pref", "5", "iif", virt_name, "table", "10"],
|
|
||||||
vec![
|
|
||||||
"route", "replace", "default", "dev", tap_name, "table", "10",
|
|
||||||
],
|
|
||||||
vec![
|
|
||||||
"neigh",
|
|
||||||
"replace",
|
|
||||||
&virt_iface_addr,
|
|
||||||
"lladdr",
|
|
||||||
&pair.virt_iface.hard_addr,
|
|
||||||
"dev",
|
|
||||||
tap_name,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
for ca in commands_args {
|
|
||||||
let output = Command::new("/sbin/ip")
|
|
||||||
.args(&ca)
|
|
||||||
.output()
|
|
||||||
.await
|
|
||||||
.with_context(|| format!("run command ip args {:?}", &ca))?;
|
|
||||||
if !output.status.success() {
|
|
||||||
return Err(anyhow!(
|
|
||||||
"run command ip args {:?} error {}",
|
|
||||||
&ca,
|
|
||||||
String::from_utf8(output.stderr)?
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: support ipv6
|
|
||||||
// change sysctl for tap0_kata
|
|
||||||
// echo 1 > /proc/sys/net/ipv4/conf/tap0_kata/accept_local
|
|
||||||
let accept_local_path = format!("/proc/sys/net/ipv4/conf/{}/accept_local", &tap_name);
|
|
||||||
std::fs::write(&accept_local_path, "1")
|
|
||||||
.with_context(|| format!("Failed to echo 1 > {}", &accept_local_path))?;
|
|
||||||
|
|
||||||
// echo 1 > /proc/sys/net/ipv4/conf/eth0/proxy_arp
|
|
||||||
// This enabled ARP reply on peer eth0 to prevent without any reply on VPC
|
|
||||||
let proxy_arp_path = format!("/proc/sys/net/ipv4/conf/{}/proxy_arp", &virt_name);
|
|
||||||
std::fs::write(&proxy_arp_path, "1")
|
|
||||||
.with_context(|| format!("Failed to echo 1 > {}", &proxy_arp_path))?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn del(&self, _pair: &NetworkPair) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user