mirror of
				https://github.com/edera-dev/krata.git
				synced 2025-11-03 07:19:37 +00:00 
			
		
		
		
	network: virtual bridge now checks multicast bit to determine whether to broadcast packet
This commit is contained in:
		@ -19,8 +19,6 @@ use tokio::{
 | 
				
			|||||||
    task::JoinHandle,
 | 
					    task::JoinHandle,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const BROADCAST_MAC_ADDR: &[u8; 6] = &[0xff; 6];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const BRIDGE_TX_QUEUE_LEN: usize = 50;
 | 
					const BRIDGE_TX_QUEUE_LEN: usize = 50;
 | 
				
			||||||
const BRIDGE_RX_QUEUE_LEN: usize = 50;
 | 
					const BRIDGE_RX_QUEUE_LEN: usize = 50;
 | 
				
			||||||
const BROADCAST_RX_QUEUE_LEN: usize = 50;
 | 
					const BROADCAST_RX_QUEUE_LEN: usize = 50;
 | 
				
			||||||
@ -36,7 +34,7 @@ pub struct BridgeJoinHandle {
 | 
				
			|||||||
    pub broadcast_rx_receiver: BroadcastReceiver<BytesMut>,
 | 
					    pub broadcast_rx_receiver: BroadcastReceiver<BytesMut>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type VirtualBridgeMemberMap = Arc<Mutex<HashMap<[u8; 6], BridgeMember>>>;
 | 
					type VirtualBridgeMemberMap = Arc<Mutex<HashMap<EthernetAddress, BridgeMember>>>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone)]
 | 
					#[derive(Clone)]
 | 
				
			||||||
pub struct VirtualBridge {
 | 
					pub struct VirtualBridge {
 | 
				
			||||||
@ -87,7 +85,7 @@ impl VirtualBridge {
 | 
				
			|||||||
        let (bridge_rx_sender, bridge_rx_receiver) = channel::<BytesMut>(BRIDGE_RX_QUEUE_LEN);
 | 
					        let (bridge_rx_sender, bridge_rx_receiver) = channel::<BytesMut>(BRIDGE_RX_QUEUE_LEN);
 | 
				
			||||||
        let member = BridgeMember { bridge_rx_sender };
 | 
					        let member = BridgeMember { bridge_rx_sender };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        match self.members.lock().await.entry(mac.0) {
 | 
					        match self.members.lock().await.entry(mac) {
 | 
				
			||||||
            Entry::Occupied(_) => {
 | 
					            Entry::Occupied(_) => {
 | 
				
			||||||
                return Err(anyhow!(
 | 
					                return Err(anyhow!(
 | 
				
			||||||
                    "virtual bridge already has a member with address {}",
 | 
					                    "virtual bridge already has a member with address {}",
 | 
				
			||||||
@ -136,7 +134,7 @@ impl VirtualBridge {
 | 
				
			|||||||
                        // recalculate TCP checksums when routing packets.
 | 
					                        // recalculate TCP checksums when routing packets.
 | 
				
			||||||
                        // the xen network backend / frontend drivers for linux
 | 
					                        // the xen network backend / frontend drivers for linux
 | 
				
			||||||
                        // are very stupid and do not calculate these properly
 | 
					                        // are very stupid and do not calculate these properly
 | 
				
			||||||
                        // despite all best attempts as making it do so.
 | 
					                        // despite all best attempts at making it do so.
 | 
				
			||||||
                        if ipv4.protocol == IpNumber::TCP {
 | 
					                        if ipv4.protocol == IpNumber::TCP {
 | 
				
			||||||
                            let (mut tcp, payload) = TcpHeader::from_slice(payload)?;
 | 
					                            let (mut tcp, payload) = TcpHeader::from_slice(payload)?;
 | 
				
			||||||
                            tcp.checksum = tcp.calc_checksum_ipv4(&ipv4, payload)?;
 | 
					                            tcp.checksum = tcp.calc_checksum_ipv4(&ipv4, payload)?;
 | 
				
			||||||
@ -148,8 +146,8 @@ impl VirtualBridge {
 | 
				
			|||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    let destination = &header.destination;
 | 
					                    let destination = EthernetAddress(header.destination);
 | 
				
			||||||
                    if destination == BROADCAST_MAC_ADDR {
 | 
					                    if destination.is_multicast() {
 | 
				
			||||||
                        trace!(
 | 
					                        trace!(
 | 
				
			||||||
                            "broadcasting bridged packet from {}",
 | 
					                            "broadcasting bridged packet from {}",
 | 
				
			||||||
                            EthernetAddress(header.source)
 | 
					                            EthernetAddress(header.source)
 | 
				
			||||||
@ -157,7 +155,7 @@ impl VirtualBridge {
 | 
				
			|||||||
                        broadcast_rx_sender.send(packet.as_slice().into())?;
 | 
					                        broadcast_rx_sender.send(packet.as_slice().into())?;
 | 
				
			||||||
                        continue;
 | 
					                        continue;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    match members.lock().await.get(destination) {
 | 
					                    match members.lock().await.get(&destination) {
 | 
				
			||||||
                        Some(member) => {
 | 
					                        Some(member) => {
 | 
				
			||||||
                            member.bridge_rx_sender.try_send(packet.as_slice().into())?;
 | 
					                            member.bridge_rx_sender.try_send(packet.as_slice().into())?;
 | 
				
			||||||
                            trace!(
 | 
					                            trace!(
 | 
				
			||||||
@ -167,10 +165,7 @@ impl VirtualBridge {
 | 
				
			|||||||
                            );
 | 
					                            );
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        None => {
 | 
					                        None => {
 | 
				
			||||||
                            trace!(
 | 
					                            trace!("no bridge member with address: {}", destination);
 | 
				
			||||||
                                "no bridge member with address: {}",
 | 
					 | 
				
			||||||
                                EthernetAddress(*destination)
 | 
					 | 
				
			||||||
                            );
 | 
					 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user