Skip to content

Commit

Permalink
feat: introduce label when adding address
Browse files Browse the repository at this point in the history
Signed-off-by: Shuoran Liu <[email protected]>
  • Loading branch information
Shuoran Liu committed May 22, 2023
1 parent 0a8eddd commit 6e3fbc1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 6 additions & 1 deletion examples/add_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ async fn add_address(
if let Some(link) = links.try_next().await? {
handle
.address()
.add(link.header.index, ip.ip(), ip.prefix())
.add(
link.header.index,
ip.ip(),
ip.prefix(),
Some(format!("{}:vip", link_name)),
)
.execute()
.await?
}
Expand Down
5 changes: 5 additions & 0 deletions src/addr/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl AddressAddRequest {
index: u32,
address: IpAddr,
prefix_len: u8,
label: Option<String>,
) -> Self {
let mut message = AddressMessage::default();

Expand All @@ -54,6 +55,10 @@ impl AddressAddRequest {
} else {
message.nlas.push(Nla::Address(address_vec.clone()));

if let Some(l) = label {
message.nlas.push(Nla::Label(l));
}

// for IPv4 the IFA_LOCAL address can be set to the same value as
// IFA_ADDRESS
message.nlas.push(Nla::Local(address_vec.clone()));
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,
label: Option<String>,
) -> AddressAddRequest {
AddressAddRequest::new(self.0.clone(), index, address, prefix_len)
AddressAddRequest::new(
self.0.clone(),
index,
address,
prefix_len,
label,
)
}

/// Delete the given address
Expand Down

0 comments on commit 6e3fbc1

Please sign in to comment.