-
Notifications
You must be signed in to change notification settings - Fork 89
nlas: Add type for AfSpecBridge
which allows links
to configure various bridge flags with SETLINK
calls
#222
Conversation
af6198a
to
adb9579
Compare
@little-dude @cathay4t PTAL. Let me know if any example file is needed with this, however simple example like this works. /* bridge vlan add ... */
let mut links = handle.link().get().match_name("my-bridge-1".to_string().clone()).execute();
if let Some(link) = links.try_next().await? {
let mut request = handle.link().set(link.header.index);
request.message_mut().header.interface_family = AF_BRIDGE as u8;
request.message_mut().header.flags = 0;
let my_struct = BridgeVlanInfo { id: 6u16, data: 100u16};
let bytes: &[u8] = unsafe { any_as_u8_slice(&my_struct) };
let bridge_flags = AfSpecBridge::Flags(BRIDGE_FLAGS_SELF);
let bridge_vlan_info = AfSpecBridge::VlanInfo(bytes.to_vec());
request.message_mut().nlas.push(Nla::AfSpecBridge(vec![bridge_flags, bridge_vlan_info]));
request.execute().await.map_err(|e| format!("{}", e));
} else {
println!("no link link found");
}
Ok(()) |
@cathay4t @little-dude Gentle reminder. Were you guys able to take a look at this. No rush. |
Even if this is merged I would be not able to use quickly due to version dependency across all netlink crates will have to wait for release of So no rush here. |
Not related to this PR but we could avoid this drift it if all crates share same version and are released together. But it has its own problems. I'll open a separate GH issue to discuss this. |
Hey @flouthoc, Just a heads up, I'm not ignoring you. I've had covid symptoms since last Friday. It's getting better but I'm not going to look at pending PRs for a couple more days. |
Ah Please take care. This PR is not urgent we can do this later. Get well soon. |
I can make a release once this is merged. I'll try to make more smaller releases as we go. Big releases are a pain. |
Probably no need for an example in |
@little-dude thanks for the review. I'll fix nits and add example by this weekend. |
@flouthoc gentle ping :) Are you planning to finish this one off? Fwiw I'm up to date with releases so I can make one as soon as this is merged. |
@little-dude Sorry I got stuck in few other things. But I need this PR so i'll get back to this, and would probably close this in this week. So if not in this release we can get this in by next release. So please don't stop release because of this but I'll make sure that it will not miss this in another release. |
b204fee
to
fd198aa
Compare
Fix wrong values of constants IFLA_BRIDGE_* Signed-off-by: Aditya R <arajan@redhat.com>
Configuration for `IFLA_BRIDGE_FLAG` and `IFLA_BRIDGE_VLAN_INFO` should belong with `Nla` so remove it from here. As `IFLA_BRIDGE_FLAG` and `IFLA_BRIDGE_VLAN_INFO` could be configured for any link not just bridge Signed-off-by: Aditya R <arajan@redhat.com>
Nla::AfSpecBridge should consume nested types implemented in a different module just like AfSpecInet Signed-off-by: Aditya R <arajan@redhat.com>
fd198aa
to
499199c
Compare
@little-dude I didn't add example yet but other than that resolved all the nits you requested. |
I'm a little worried that
I think the first one is only to be used if |
@stbuehler Yeah but issue is i'm not able to use |
Most attributes (and pub enum AfSpecElem {
AfSpecIpv4(AfSpecInet),
AfSpecIpv6(AfSpecInet),
AfSpecBridge(AfSpecBridge),
AfSpecUnknown {
family: u8,
data: Vec<u8>,
}
}
/// rtnl::link::nlas::Nla
pub enum Nla {
...
AfSpec(Vec<AfSpecElem>),
} (I'm not a fan of these pub struct AfSpec {
ipv4: Option<AfSpecInet>,
ipv6: Option<AfSpecInet>,
bridge: Option<AfSpecBridge>,
unknown: Vec<(u8, Vec<u8>)>,
}
/// rtnl::link::nlas::Nla
pub enum Nla {
...
AfSpec(AfSpec),
} But that is not how it is done in this library, and more work to implement the encode/decode things for.) When parsing you could now map the Or you could add a different /// rtnl::link::nlas::Nla
pub enum Nla {
...
// only with `rtgen_family != AF_BRIDGE`
AfSpec(Vec<AfSpecElem>),
// only with `rtgen_family == AF_BRIDGE`
AfSpecBridge(AfSpecBridge),
} On parsing you should have the family as context to distinguish the two cases, and on emit it would be the users responsibility to choose the correct one. (Note that I'm still not sure whether the contained |
Hm. It seems I didn't look closely enough at This So this does look alright after all. |
@stbuehler Thank you so much for spending time on this and confirming. I really appreciate it 😄 . Just waiting for reviewers to take final look @cathay4t @little-dude PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need more time on kernel code reading to decide whether current code is correct or not.
To reply #222 (comment) The kernel code
This is the snippet of kernel code, in case you would like to read C: af_spec = nla_nest_start_noflag(skb, IFLA_AF_SPEC);
if (!af_spec)
return -EMSGSIZE;
list_for_each_entry_rcu(af_ops, &rtnl_af_ops, list) {
struct nlattr *af;
int err;
if (!af_ops->fill_link_af)
continue;
af = nla_nest_start_noflag(skb, af_ops->family); Just some notes on kernel code reading. |
This is the partial output of But, apparently , this is too complex for this PR to fix. I intend to merge this PR and continue the fix in new PR for this
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Will continue the work in another PR.
Thanks @cathay4t for the review and findings, let me know if there is anything i can help with. |
Hi @flouthoc , we can merge this once we fix https://github.com/little-dude/netlink/pull/222/files#r858245460 |
Conclusion on this
For kernel code reference: rtnl_register(PF_UNSPEC, RTM_GETLINK, rtnl_getlink,
rtnl_dump_ifinfo, 0);
// omitted
rtnl_register(PF_BRIDGE, RTM_GETLINK, NULL, rtnl_bridge_getlink, 0); |
Allows users to set more advanced options with `Nla::AfSpecBridge` which now accepts types from AfSpecBridge just like AfSpecInet Allows users to create things like `bridge vlan add ....` and more Signed-off-by: Aditya R <arajan@redhat.com>
I have |
@cathay4t My bad sorry for the delay and thanks for merging this :) |
Following PR allows
handle.link().set(
orRTM_SETLINK
calls to configure variousbridge
attributes like.IFLA_BRIDGE_FLAGS
IFLA_BRIDGE_VLAN_INFO
With this PR its easy to implement functionality like
bridge vlan add ...
This PR also corrects some changes made in
#212 and #213