Skip to contentSkip to conversation

Add support for setting net_device flags via RTM_SETLINK

RFC/PATCH Thomas Graf 1 participant 2 messages Aug 23, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello

The patch below extends RTM_SETLINK to change net_device flags if a new value is provided via ifinfomsg and modifies the way flags are shown to userspace to maintain balance and only show flags which can be modified (as in ioctl handlers):

The change in behaviour:

old:

    r->ifi_flags = dev->flags;

    if (!netif_running(dev) || !netif_carrier_ok(dev))
        r->ifi_flags &= ~IFF_RUNNING;
    else
        r->ifi_flags |= IFF_RUNNING;

new:

    flags = (dev->flags & ~(IFF_PROMISC | IFF_ALLMULTI | IFF_RUNNING)) | 
            (dev->gflags & (IFF_PROMISC | IFF_ALLMULTI));

    if (netif_running(dev) && netif_carrier_ok(dev))
        flags |= IFF_RUNNING;

I will implement the 2 hidden flags IFF_PROMISC and IFF_ALLMULTI as separate message attributes (IFLA_PROMISC and IFLA_ALLMULTI) as soon as I get some comments on this idea.

net/core/rtnetlink.c +4 -6
@@ -166,14 +166,9 @@
 	r->ifi_family = AF_UNSPEC;
 	r->ifi_type = dev->type;
 	r->ifi_index = dev->ifindex;
-	r->ifi_flags = dev->flags;
+	r->ifi_flags = dev_get_flags(dev);
 	r->ifi_change = change;
 
-	if (!netif_running(dev) || !netif_carrier_ok(dev))
-		r->ifi_flags &= ~IFF_RUNNING;
-	else
-		r->ifi_flags |= IFF_RUNNING;
-
 	RTA_PUT(skb, IFLA_IFNAME, strlen(dev->name)+1, dev->name);
 	RTA_PUT(skb, IFLA_TXQLEN, sizeof(unsigned long), &dev->tx_queue_len);
 	if (dev->addr_len) {
@@ -246,6 +241,9 @@
 		return -ENODEV;
 
 	err = -EINVAL;
+
+	if (ifm->ifi_flags)
+		dev_change_flags(dev, ifm->ifi_flags);
 
 	if (ida[IFLA_ADDRESS - 1]) {
 		if (!dev->set_mac_address) {
#1 lore raw

* Thomas Graf <[email protected]> 2004-08-23 23:16

Quoted 3 lines

I will implement the 2 hidden flags IFF_PROMISC and IFF_ALLMULTI as separate message attributes (IFLA_PROMISC and IFLA_ALLMULTI) as soon as I get some comments on this idea.

Ignore the above statement, it's nonsense. Sorry.

Thomas