little-dude / netlink

netlink libraries for rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Removing interface from bridge

gabrik opened this issue · comments

Hi,

It is possible to remove an interface from a bridge after we have assigned it?

Nowadays I can easily assign an interface to a bridge by doing like this:

let (connection, handle, _) = new_connection().unwrap();
            tokio::spawn(connection);
            let mut links = handle.link().get().set_name_filter(iface).execute();
            if let Some(link) = links
                .try_next()
                .await
                .map_err(|e| FError::NetworkingError(format!("{}", e)))?
            {
                let mut masters = handle.link().get().set_name_filter(master).execute();
                if let Some(master) = masters
                    .try_next()
                    .await
                    .map_err(|e| FError::NetworkingError(format!("{}", e)))?
                {
                    handle
                        .link()
                        .set(link.header.index)
                        .master(master.header.index)
                        .execute()
                        .await
                        .map_err(|e| FError::NetworkingError(format!("{}", e)))
                } else {
                    log::error!("set_iface_master master not found");
                    Err(FError::NotFound)
                }
            } else {
                log::error!("set_iface_master iface not found");
                Err(FError::NotFound)
            }

But I see that in set there is nothing like no_master() that would be similar to ip link set IFACE nomaster.

So it is possible or it is something actually missing?

I've looked at the code and it seems it is missing. If not missing we should document this.

I will check what ip link set <iface> nomaster does and I'll try to implement it.

This comment is to keep track of the investigation.

From an strace on ip link set <dev> nomaster

I see this message sent to netlink.

...
28779 sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base={{len=40, type=RTM_NEWLINK, flags=NLM_F_REQUEST|NLM_F_ACK, seq=1607600465, pid=0}, {ifi_family=AF_UNSPEC, ifi_type=ARPHRD_NETROM, ifi_index=if_nametoindex("d0"), ifi_flags=0, ifi_change=0}, {{nla_len=8, nla_type=IFLA_MASTER}, 0}}, iov_len=40}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 40
....

Thus seems that is sufficient to set the IFLA_MASTER to 0 to remove the master