-
Notifications
You must be signed in to change notification settings - Fork 162
net_consomme: Add support for ipv6 #2398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
damanm24
wants to merge
37
commits into
microsoft:main
Choose a base branch
from
damanm24:consomme_ipv6
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
f9bc169
.
83b3cee
Merge branch 'main' into proc_topology
3600e7a
wip
87cf158
Merge branch 'main' of https://github.com/microsoft/openvmm
damanm24 bedd466
Merge branch 'main' of https://github.com/microsoft/openvmm
damanm24 01fe341
Merge branch 'main' into consomme_ipv6
8acde53
wip
bc383e2
Finish UDP over IPv6 and DNS on unix
c60bd6d
Use AF_UNSPEC for 1 syscall instead
damanm24 116b411
Merge branch 'main' of https://github.com/microsoft/openvmm
damanm24 2bc543b
checkpt
damanm24 30dac28
Remove un-needed message handling for DHCPv6
damanm24 99b277d
checkpt
damanm24 441db93
Windows guest recognizes IPv6 capabilities
damanm24 f5b97f1
minor changes
damanm24 a77bea0
Merge branch 'main' of https://github.com/microsoft/openvmm
damanm24 2b57eea
Use already existing types
damanm24 cb23c36
checkpt
damanm24 dd84e24
bit of cleanup
damanm24 36c6cb5
Prepare for review
damanm24 31b7a60
More cleanup
damanm24 b439e0e
update comment with accurate default network state
damanm24 423a20b
Clippy + xtask fixes
235da5e
checkpt
damanm24 ab27f38
minor changes
damanm24 9121770
Merge branch 'main' of https://github.com/microsoft/openvmm
damanm24 4493f2b
Merge branch 'main' into consomme_ipv6
damanm24 6f56fbf
Merge branch 'consomme_ipv6' of https://github.com/damanm24/openvmm i…
damanm24 6bedac1
clippy fixes
damanm24 6a01be6
remove dhcproto dep
damanm24 1b78011
undo
damanm24 e1c2455
.
damanm24 2dc273d
.
damanm24 6fdce76
Merge branch 'main' into consomme_ipv6
damanm24 9577aa8
Address feedback
damanm24 9005164
Update bind_port fn
6e43b51
Address comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,158 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| use std::str::FromStr; | ||
|
|
||
| use super::Access; | ||
| use super::Client; | ||
| use super::DropReason; | ||
| use crate::ChecksumState; | ||
| use crate::MIN_MTU; | ||
| use dhcproto::Decodable; | ||
| use dhcproto::Encodable; | ||
| use dhcproto::v6; | ||
| use smoltcp::phy::ChecksumCapabilities; | ||
| use smoltcp::wire::EthernetFrame; | ||
| use smoltcp::wire::EthernetProtocol; | ||
| use smoltcp::wire::EthernetRepr; | ||
| use smoltcp::wire::IpAddress; | ||
| use smoltcp::wire::IpProtocol; | ||
| use smoltcp::wire::Ipv6Address; | ||
| use smoltcp::wire::Ipv6Packet; | ||
| use smoltcp::wire::Ipv6Repr; | ||
| use smoltcp::wire::UdpPacket; | ||
| use smoltcp::wire::UdpRepr; | ||
|
|
||
| impl<T: Client> Access<'_, T> { | ||
| pub(crate) fn handle_dhcpv6( | ||
| &mut self, | ||
| payload: &[u8], | ||
| client_ip: Option<Ipv6Address>, | ||
| ) -> Result<(), DropReason> { | ||
| // Parse the DHCPv6 message | ||
| let msg = v6::Message::decode(&mut dhcproto::Decoder::new(payload)).map_err(|x| { | ||
| tracing::info!( | ||
| error = &x as &dyn std::error::Error, | ||
| "failed to decode DHCPv6 message" | ||
| ); | ||
| DropReason::Packet(smoltcp::Error::Malformed) | ||
| })?; | ||
|
|
||
| match msg.msg_type() { | ||
| v6::MessageType::InformationRequest => { | ||
| // Handle InformationRequest message (stateless DHCPv6) | ||
| tracing::info!("Received DHCPv6 InformationRequest message"); | ||
|
|
||
| // Build DHCPv6 Reply response | ||
| let mut reply = v6::Message::new(v6::MessageType::Reply); | ||
| reply.set_xid(msg.xid()); | ||
|
|
||
| // Add Client Identifier option (echo back from the InformationRequest) | ||
| if let Some(v6::DhcpOption::ClientId(client_id)) = | ||
| msg.opts().get(v6::OptionCode::ClientId) | ||
| { | ||
| reply | ||
| .opts_mut() | ||
| .insert(v6::DhcpOption::ClientId(client_id.clone())); | ||
| } | ||
|
|
||
| // Add Server Identifier option | ||
| // Use DUID-LL (type 3: Link-layer address) | ||
| let gateway_mac = self.inner.state.params.gateway_mac_ipv6.0; | ||
| let mut duid_bytes = vec![0x00, 0x03, 0x00, 0x01]; // Type 3 (LL), Hardware type 1 (Ethernet) | ||
| duid_bytes.extend_from_slice(&gateway_mac); | ||
| reply | ||
| .opts_mut() | ||
| .insert(v6::DhcpOption::ServerId(duid_bytes)); | ||
|
|
||
| // Add DNS Recursive Name Server option if we have nameservers | ||
| let dns_servers: Vec<std::net::Ipv6Addr> = self | ||
| .inner | ||
| .state | ||
| .params | ||
| .nameservers | ||
| .iter() | ||
| .filter_map(|ip| match ip { | ||
| IpAddress::Ipv6(addr) => Some(*addr), | ||
| _ => None, | ||
| }) | ||
| .filter(|addr| { | ||
| !(addr.is_unspecified() | ||
| || addr.is_loopback() | ||
| || addr.is_link_local() | ||
| || addr.is_multicast() | ||
| || addr.0.starts_with(&[0xfc, 0x00]) | ||
| || addr.0.starts_with(&[0xfe, 0xc0])) | ||
damanm24 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
damanm24 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }) | ||
| .map(|addr| addr.into()) | ||
| .collect(); | ||
|
|
||
| if !dns_servers.is_empty() { | ||
| reply | ||
| .opts_mut() | ||
| .insert(v6::DhcpOption::DomainNameServers(dns_servers)); | ||
| } | ||
|
|
||
| let mut dhcpv6_buffer = Vec::new(); | ||
| let mut encoder = dhcproto::Encoder::new(&mut dhcpv6_buffer); | ||
| reply.encode(&mut encoder).map_err(|x| { | ||
| tracing::error!( | ||
| error = &x as &dyn std::error::Error, | ||
| "failed to encode DHCPv6 message" | ||
| ); | ||
| DropReason::Packet(smoltcp::Error::Malformed) | ||
| })?; | ||
|
|
||
| let resp_udp = UdpRepr { | ||
| src_port: v6::SERVER_PORT, | ||
| dst_port: v6::CLIENT_PORT, | ||
| }; | ||
|
|
||
| let client_link_local = | ||
| client_ip.unwrap_or_else(|| Ipv6Address::from_str("ff02::1:2").unwrap()); | ||
damanm24 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let resp_ipv6 = Ipv6Repr { | ||
| src_addr: self.inner.state.params.gateway_link_local_ipv6, | ||
| dst_addr: client_link_local, | ||
| next_header: IpProtocol::Udp, | ||
| payload_len: resp_udp.header_len() + dhcpv6_buffer.len(), | ||
| hop_limit: 64, | ||
| }; | ||
| let resp_eth = EthernetRepr { | ||
| src_addr: self.inner.state.params.gateway_mac_ipv6, | ||
| dst_addr: self.inner.state.params.client_mac, | ||
| ethertype: EthernetProtocol::Ipv6, | ||
| }; | ||
|
|
||
| // Construct the complete packet | ||
| let mut buffer = [0; MIN_MTU]; | ||
| let mut eth_frame = EthernetFrame::new_unchecked(&mut buffer); | ||
| resp_eth.emit(&mut eth_frame); | ||
|
|
||
| let mut ipv6_packet = Ipv6Packet::new_unchecked(eth_frame.payload_mut()); | ||
| resp_ipv6.emit(&mut ipv6_packet); | ||
|
|
||
| let mut udp_packet = UdpPacket::new_unchecked(ipv6_packet.payload_mut()); | ||
| resp_udp.emit( | ||
| &mut udp_packet, | ||
| &IpAddress::Ipv6(resp_ipv6.src_addr), | ||
| &IpAddress::Ipv6(resp_ipv6.dst_addr), | ||
| dhcpv6_buffer.len(), | ||
| |udp_payload| { | ||
| udp_payload[..dhcpv6_buffer.len()].copy_from_slice(&dhcpv6_buffer); | ||
| }, | ||
| &ChecksumCapabilities::default(), | ||
| ); | ||
|
|
||
| let total_len = resp_eth.buffer_len() | ||
| + resp_ipv6.buffer_len() | ||
| + resp_udp.header_len() | ||
| + dhcpv6_buffer.len(); | ||
|
|
||
| self.client.recv(&buffer[..total_len], &ChecksumState::NONE); | ||
| } | ||
| _ => return Err(DropReason::UnsupportedDhcpv6(msg.msg_type())), | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.