Skip to content

Add support for ip addr add <IP> peer <PEER_IP> #77

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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/addr/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl AddressAddRequest {
index: u32,
address: IpAddr,
prefix_len: u8,
peer_address: Option<IpAddr>,
) -> Self {
let mut message = AddressMessage::default();

Expand All @@ -45,14 +46,18 @@ impl AddressAddRequest {
message.attributes.push(AddressAttribute::Multicast(a));
}
} else {
message.attributes.push(AddressAttribute::Address(address));

// for IPv4 the IFA_LOCAL address can be set to the same value as
// IFA_ADDRESS
message.attributes.push(AddressAttribute::Local(address));
// If peer_address is provided, use it as IFA_ADDRESS
if let Some(peer) = peer_address {
message.attributes.push(AddressAttribute::Address(peer));
message.attributes.push(AddressAttribute::Local(address));
} else {
message.attributes.push(AddressAttribute::Address(address));
// for IPv4 the IFA_LOCAL address can be set to the same value as
// IFA_ADDRESS when no peer is specified
message.attributes.push(AddressAttribute::Local(address));
}

// set the IFA_BROADCAST address as well (IPv6 does not support
// broadcast)
// set the IFA_BROADCAST address as well (IPv6 does not support broadcast)
if let IpAddr::V4(a) = address {
if prefix_len == 32 {
message.attributes.push(AddressAttribute::Broadcast(a));
Expand Down
9 changes: 8 additions & 1 deletion src/addr/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ impl AddressHandle {
index: u32,
address: IpAddr,
prefix_len: u8,
peer_address: Option<IpAddr>,
) -> AddressAddRequest {
AddressAddRequest::new(self.0.clone(), index, address, prefix_len)
AddressAddRequest::new(
self.0.clone(),
index,
address,
prefix_len,
peer_address,
)
}

/// Delete the given address
Expand Down