Skip to content
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

Introduce LinkMessageBuilder #73

Merged
merged 2 commits into from
Aug 5, 2024
Merged

Conversation

cathay4t
Copy link
Member

@cathay4t cathay4t commented Jul 9, 2024

API BREAK

To remove the duplicate error of LinkAddRequest and LinkSetRequest,
this patch introduce LinkMessageBuilder to generate LinkMessage for
link handlers to use.

The impl LinkMessageBuilder<T> holds the common functions available for all
interface types.
The impl LinkMessageBuilder<LinkVlan> holds VLAN specific functions.

The LinkMessageBuilder is designed for advanced user, wrapper functions
are created for common use cases. For example, to create a VLAN
interface:

let (connection, handle, _) = new_connection().unwrap();
tokio::spawn(connection);

handle
    .link()
    .add(
        LinkVlan::new("vlan100", 10, 100)
            .up()
            .build()
    )
    .execute()
    .await
    .map_err(|e| format!("{e}"))

These patches included these new structures to generate matching
LinkMessageBuilder:

  • LinkUnspec (for matching existing interface)
  • LinkDummy
  • LinkVeth
  • LinkVlan
  • LinkVxlan
  • LinkMacVlan
  • LinkMacVtap
  • LinkWireguard
  • LinkBondPort

Special note:

  • Due to confliction, the previous VxLAN link() function changed to
    dev(). The link() is the share function for all interface types. The
    API is matching with ip link command line option for vxlan.
    Please check examples/create_vxlan.rs for usage.

  • The LinkHandler::set_bond_port() changed to
    LinkHandler::set_port(), please check examples/set_bond_port.rs
    for usage.

  • The message_mut() function is removed from LinkSetRequest and
    LinkAddRequest, user should modify the LinkMessage before sent to
    handler.

@cathay4t
Copy link
Member Author

cathay4t commented Jul 9, 2024

@little-dude I could use your expertise on this PR review.

@cathay4t cathay4t force-pushed the link_builder branch 2 times, most recently from aa1820a to 531bf57 Compare July 9, 2024 06:35
**API BREAK**

To remove the duplicate error of `LinkAddRequest` and `LinkSetRequest`,
this patch introduce `LinkMessageBuilder` to generate `LinkMessage` for
link handlers to use.

The `impl LinkMessageBuilder<T>` holds the common functions available for all
interface types.
The `impl LinkMessageBuilder<LinkVlan>` holds VLAN specific functions.

The LinkMessageBuilder is designed for advanced user, wrapper functions
are created for common use cases. For example, to create a VLAN
interface:

```rus
let (connection, handle, _) = new_connection().unwrap();
tokio::spawn(connection);

handle
    .link()
    .add(
        LinkVlan::new("vlan100", 10, 100)
            .up()
            .build()
    )
    .execute()
    .await
    .map_err(|e| format!("{e}"))
```

These patches included these new structures to generate matching
LinkMessageBuilder:

 * `LinkUnspec` (for matching existing interface)
 * `LinkDummy`
 * `LinkVeth`
 * `LinkVlan`
 * `LinkVxlan`
 * `LinkMacVlan`
 * `LinkMacVtap`
 * `LinkWireguard`
 * `LinkBondPort`

Special note:

 * Due to confliction, the previous VxLAN `link()` function changed to
   `dev()`. The `link()` is the share function for all interface types. The
   API is matching with `ip link` command line option for vxlan.
   Please check `examples/create_vxlan.rs` for usage.

 * The `LinkHandler::set_bond_port()` changed to
   `LinkHandler::set_port()`, please check `examples/set_bond_port.rs`
   for usage.

 * The `message_mut()` function is removed from `LinkSetRequest` and
   `LinkAddRequest`, user should modify the LinkMessage before sent to
   handler.

Signed-off-by: Gris Ge <[email protected]>
@little-dude little-dude self-requested a review July 10, 2024 08:25
@cathay4t
Copy link
Member Author

@little-dude Do you have any free time for this PR?

@cathay4t
Copy link
Member Author

@little-dude ping again

@cathay4t
Copy link
Member Author

cathay4t commented Aug 5, 2024

Let's move on and fix stuff later.

@cathay4t cathay4t merged commit 5fca904 into rust-netlink:main Aug 5, 2024
3 checks passed
@cathay4t cathay4t deleted the link_builder branch August 5, 2024 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant