All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Lemoine <eric.lemoine@gmail.com>
To: netdev@oss.sgi.com
Subject: [PATCH] Allow setting dev->weight using ip(8)
Date: Mon, 30 Aug 2004 12:56:20 +0200	[thread overview]
Message-ID: <5cac192f040830035669628d1@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 518 bytes --]

Hello

For my own testing purposes, I often need to modify dev->weight. So I
patched the kernel and iproute2 to be able to modify dev->weight using
ip(8). After all, one can modify tx_queue_len so why not weight?

Two kernel patches attached: one using the ioctl framework and another
using the rtnetlink framework. Warning: the attached rtnetlink patch
is a superset of Thomas Graf's rtnetlink patch for setting mtu and
tx_queue_len.

PS: both patches are against 2.6.5-rc3-ben0 but should apply to any 2.6.

--
Eric

[-- Attachment #2: patch-ioctl_dev_weight-2-6-5-rc3-ben0-A0 --]
[-- Type: application/octet-stream, Size: 2714 bytes --]

===== fs/compat_ioctl.c 1.23 vs edited =====
--- 1.23/fs/compat_ioctl.c	2004-03-25 02:14:27 +01:00
+++ edited/fs/compat_ioctl.c	2004-07-30 15:42:21 +02:00
@@ -694,6 +694,7 @@
 		case SIOCGIFDSTADDR:
 		case SIOCGIFNETMASK:
 		case SIOCGIFTXQLEN:
+		case SIOCGIFWEIGHT:
 			if (copy_to_user(uifr32, &ifr, sizeof(*uifr32)))
 				return -EFAULT;
 			break;
@@ -3121,6 +3122,8 @@
 HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc)
 HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc)
 HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc)
+HANDLE_IOCTL(SIOCGIFWEIGHT, dev_ifsioc)
+HANDLE_IOCTL(SIOCSIFWEIGHT, dev_ifsioc)
 HANDLE_IOCTL(TUNSETIFF, dev_ifsioc)
 HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl)
 HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl)
===== include/linux/if.h 1.8 vs edited =====
--- 1.8/include/linux/if.h	2003-04-18 20:28:37 +02:00
+++ edited/include/linux/if.h	2004-07-30 15:38:37 +02:00
@@ -164,6 +164,7 @@
 #define ifr_ifindex	ifr_ifru.ifru_ivalue	/* interface index	*/
 #define ifr_bandwidth	ifr_ifru.ifru_ivalue    /* link bandwidth	*/
 #define ifr_qlen	ifr_ifru.ifru_ivalue	/* Queue length 	*/
+#define ifr_weight	ifr_ifru.ifru_ivalue	/* dev poll weight	*/
 #define ifr_newname	ifr_ifru.ifru_newname	/* New name		*/
 #define ifr_settings	ifr_ifru.ifru_settings	/* Device/proto settings*/
 
===== include/linux/sockios.h 1.7 vs edited =====
--- 1.7/include/linux/sockios.h	2002-03-07 08:40:16 +01:00
+++ edited/include/linux/sockios.h	2004-07-30 15:40:48 +02:00
@@ -83,6 +83,9 @@
 
 #define SIOCWANDEV	0x894A		/* get/set netdev parameters	*/
 
+#define SIOCGIFWEIGHT	0x894B		/* get dev poll weight		*/
+#define SIOCSIFWEIGHT	0x894C		/* set dev poll weight		*/
+
 /* ARP cache control calls. */
 		    /*  0x8950 - 0x8952  * obsolete calls, don't re-use */
 #define SIOCDARP	0x8953		/* delete ARP table entry	*/
===== net/core/dev.c 1.135 vs edited =====
--- 1.135/net/core/dev.c	2004-03-19 23:17:34 +01:00
+++ edited/net/core/dev.c	2004-07-30 15:36:58 +02:00
@@ -2487,6 +2487,16 @@
 			dev->tx_queue_len = ifr->ifr_qlen;
 			return 0;
 
+		case SIOCGIFWEIGHT:
+			ifr->ifr_weight = dev->weight;
+			return 0;
+
+		case SIOCSIFWEIGHT:
+			if (ifr->ifr_weight < 0)
+				return -EINVAL;
+			dev->weight = ifr->ifr_weight;
+			return 0;
+
 		case SIOCSIFNAME:
 			ifr->ifr_newname[IFNAMSIZ-1] = '\0';
 			return dev_change_name(dev, ifr->ifr_newname);
@@ -2587,6 +2597,7 @@
 		case SIOCGIFMAP:
 		case SIOCGIFINDEX:
 		case SIOCGIFTXQLEN:
+		case SIOCGIFWEIGHT:
 			dev_load(ifr.ifr_name);
 			read_lock(&dev_base_lock);
 			ret = dev_ifsioc(&ifr, cmd);
@@ -2654,6 +2665,7 @@
 		case SIOCDELMULTI:
 		case SIOCSIFHWBROADCAST:
 		case SIOCSIFTXQLEN:
+		case SIOCSIFWEIGHT:
 		case SIOCSMIIREG:
 		case SIOCBONDENSLAVE:
 		case SIOCBONDRELEASE:

[-- Attachment #3: patch-qlen_mtu_weight_setget-2-6-5-rc3-ben0 --]
[-- Type: application/octet-stream, Size: 3646 bytes --]

===== include/linux/rtnetlink.h 1.32 vs edited =====
--- 1.32/include/linux/rtnetlink.h	2004-01-16 11:05:24 +01:00
+++ edited/include/linux/rtnetlink.h	2004-08-26 12:41:37 +02:00
@@ -544,6 +544,9 @@
 #define IFLA_WIRELESS IFLA_WIRELESS
 	IFLA_PROTINFO,		/* Protocol specific information for a link */
 #define IFLA_PROTINFO IFLA_PROTINFO
+	IFLA_TXQLEN,
+	IFLA_WEIGHT,
+	IFLA_MAP,
 };
 
 
===== net/core/rtnetlink.c 1.18 vs edited =====
--- 1.18/net/core/rtnetlink.c	2003-09-28 18:51:50 +02:00
+++ edited/net/core/rtnetlink.c	2004-08-26 12:42:52 +02:00
@@ -166,31 +166,58 @@
 	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);
+
+	if (1) {
+		u32 txqlen = dev->tx_queue_len;
+		RTA_PUT(skb, IFLA_TXQLEN, sizeof(txqlen), &txqlen);
+	}
+
+	if (1) {
+		u32 weight = dev->weight;
+		RTA_PUT(skb, IFLA_WEIGHT, sizeof(weight), &weight);
+	}
+
+	if (1) {
+		struct ifmap map = {
+			.mem_start   = dev->mem_start,
+			.mem_end     = dev->mem_end,
+			.base_addr   = dev->base_addr,
+			.irq         = dev->irq,
+			.dma         = dev->dma,
+			.port        = dev->if_port,
+		};
+		RTA_PUT(skb, IFLA_MAP, sizeof(map), &map);
+	}
+
 	if (dev->addr_len) {
 		RTA_PUT(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr);
 		RTA_PUT(skb, IFLA_BROADCAST, dev->addr_len, dev->broadcast);
 	}
+
 	if (1) {
-		unsigned mtu = dev->mtu;
+		u32 mtu = dev->mtu;
 		RTA_PUT(skb, IFLA_MTU, sizeof(mtu), &mtu);
 	}
-	if (dev->ifindex != dev->iflink)
-		RTA_PUT(skb, IFLA_LINK, sizeof(int), &dev->iflink);
+
+	if (dev->ifindex != dev->iflink) {
+		u32 iflink = dev->iflink;
+		RTA_PUT(skb, IFLA_LINK, sizeof(iflink), &iflink);
+	}
+
 	if (dev->qdisc_sleeping)
 		RTA_PUT(skb, IFLA_QDISC,
 			strlen(dev->qdisc_sleeping->ops->id) + 1,
 			dev->qdisc_sleeping->ops->id);
-	if (dev->master)
-		RTA_PUT(skb, IFLA_MASTER, sizeof(int), &dev->master->ifindex);
+
+	if (dev->master) {
+		u32 master = dev->master->ifindex;
+		RTA_PUT(skb, IFLA_MASTER, sizeof(master), &master);
+	}
+
 	if (dev->get_stats) {
 		unsigned long *stats = (unsigned long*)dev->get_stats(dev);
 		if (stats) {
@@ -246,6 +273,30 @@
 
 	err = -EINVAL;
 
+	if (ifm->ifi_flags)
+		dev_change_flags(dev, ifm->ifi_flags);
+
+	if (ida[IFLA_MAP - 1]) {
+		if (!dev->set_config) {
+			err = -EOPNOTSUPP;
+			goto out;
+		}
+
+		if (!netif_device_present(dev)) {
+			err = -ENODEV;
+			goto out;
+		}
+
+		if (ida[IFLA_MAP - 1]->rta_len != RTA_LENGTH(sizeof(struct ifmap)))
+			goto out;
+
+		err = dev->set_config(dev, (struct ifmap *)
+				RTA_DATA(ida[IFLA_MAP - 1]));
+
+		if (err)
+			goto out;
+	}
+
 	if (ida[IFLA_ADDRESS - 1]) {
 		if (!dev->set_mac_address) {
 			err = -EOPNOTSUPP;
@@ -268,6 +319,30 @@
 			goto out;
 		memcpy(dev->broadcast, RTA_DATA(ida[IFLA_BROADCAST - 1]),
 		       dev->addr_len);
+	}
+
+	if (ida[IFLA_MTU - 1]) {
+		if (ida[IFLA_MTU - 1]->rta_len != RTA_LENGTH(sizeof(u32)))
+			goto out;
+		err = dev_set_mtu(dev, *((u32 *) RTA_DATA(ida[IFLA_MTU - 1])));
+
+		if (err)
+			goto out;
+
+	}
+
+	if (ida[IFLA_TXQLEN - 1]) {
+		if (ida[IFLA_TXQLEN - 1]->rta_len != RTA_LENGTH(sizeof(u32)))
+			goto out;
+
+		dev->tx_queue_len = *((u32 *) RTA_DATA(ida[IFLA_TXQLEN - 1]));
+	}
+
+	if (ida[IFLA_WEIGHT -1 ]) {
+		if (ida[IFLA_WEIGHT - 1]->rta_len != RTA_LENGTH(sizeof(u32)))
+			goto out;
+
+		dev->weight = *((u32 *) RTA_DATA(ida[IFLA_WEIGHT - 1]));
 	}
 
 	err = 0;

             reply	other threads:[~2004-08-30 10:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-30 10:56 Eric Lemoine [this message]
2004-08-30 12:27 ` [PATCH] Allow setting dev->weight using ip(8) jamal
2004-08-30 12:42   ` jamal
2004-08-30 14:35     ` Eric Lemoine
2004-08-30 23:58       ` David S. Miller
2004-08-31  9:58         ` Eric Lemoine
2004-08-30 14:33   ` Eric Lemoine
2004-09-08 13:45     ` Thomas Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5cac192f040830035669628d1@mail.gmail.com \
    --to=eric.lemoine@gmail.com \
    --cc=netdev@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.