* [PATCH] Allow setting dev->weight using ip(8)
@ 2004-08-30 10:56 Eric Lemoine
2004-08-30 12:27 ` jamal
0 siblings, 1 reply; 8+ messages in thread
From: Eric Lemoine @ 2004-08-30 10:56 UTC (permalink / raw)
To: netdev
[-- 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;
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] Allow setting dev->weight using ip(8)
2004-08-30 10:56 [PATCH] Allow setting dev->weight using ip(8) Eric Lemoine
@ 2004-08-30 12:27 ` jamal
2004-08-30 12:42 ` jamal
2004-08-30 14:33 ` Eric Lemoine
0 siblings, 2 replies; 8+ messages in thread
From: jamal @ 2004-08-30 12:27 UTC (permalink / raw)
To: Eric Lemoine; +Cc: netdev
On Mon, 2004-08-30 at 06:56, Eric Lemoine wrote:
> 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.
>
Looks sane.
Not sure if you should encourage ioctl though ;->
Out of curiosity, what/when do you change weight? I think its valuable
to do so, just curious. BTW, As Dave pointed out alwauIFLA_WEIGHT
missing user space/ip patch btw.
cheers,
jamal
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] Allow setting dev->weight using ip(8)
2004-08-30 12:27 ` jamal
@ 2004-08-30 12:42 ` jamal
2004-08-30 14:35 ` Eric Lemoine
2004-08-30 14:33 ` Eric Lemoine
1 sibling, 1 reply; 8+ messages in thread
From: jamal @ 2004-08-30 12:42 UTC (permalink / raw)
To: Eric Lemoine; +Cc: netdev
On Mon, 2004-08-30 at 08:27, jamal wrote:
> to do so, just curious. BTW, As Dave pointed out alwauIFLA_WEIGHT
LOL ;->
As Dave pointed out any new attributes go to the end of the enumeration.
It may not matter in this case if Dave hasnt applied Thomas' patch.
Otherwise IFLA_WEIGHT should be last.
cheers,
jamal
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] Allow setting dev->weight using ip(8)
2004-08-30 12:42 ` jamal
@ 2004-08-30 14:35 ` Eric Lemoine
2004-08-30 23:58 ` David S. Miller
0 siblings, 1 reply; 8+ messages in thread
From: Eric Lemoine @ 2004-08-30 14:35 UTC (permalink / raw)
To: hadi; +Cc: netdev
[-- Attachment #1: Type: text/plain, Size: 224 bytes --]
> As Dave pointed out any new attributes go to the end of the enumeration.
> It may not matter in this case if Dave hasnt applied Thomas' patch.
> Otherwise IFLA_WEIGHT should be last.
Right.
New patch attached.
--
Eric
[-- Attachment #2: 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_MAP,
+ IFLA_WEIGHT,
};
===== 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;
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] Allow setting dev->weight using ip(8)
2004-08-30 14:35 ` Eric Lemoine
@ 2004-08-30 23:58 ` David S. Miller
2004-08-31 9:58 ` Eric Lemoine
0 siblings, 1 reply; 8+ messages in thread
From: David S. Miller @ 2004-08-30 23:58 UTC (permalink / raw)
To: Eric Lemoine; +Cc: hadi, netdev
On Mon, 30 Aug 2004 16:35:57 +0200
Eric Lemoine <eric.lemoine@gmail.com> wrote:
> > As Dave pointed out any new attributes go to the end of the enumeration.
> > It may not matter in this case if Dave hasnt applied Thomas' patch.
> > Otherwise IFLA_WEIGHT should be last.
>
> Right.
>
> New patch attached.
Please make a patch against Linus's current tree.
I put the rest of your rtnetlink device interface
changes in, and your patches here duplicate all of
that.
I agree also with Jamel wrt. ioctl(), let's not go
there if possible. :-)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] Allow setting dev->weight using ip(8)
2004-08-30 23:58 ` David S. Miller
@ 2004-08-31 9:58 ` Eric Lemoine
0 siblings, 0 replies; 8+ messages in thread
From: Eric Lemoine @ 2004-08-31 9:58 UTC (permalink / raw)
To: David S. Miller; +Cc: hadi, netdev
> Please make a patch against Linus's current tree.
> I put the rest of your rtnetlink device interface
> changes in, and your patches here duplicate all of
> that.
See below.
> I agree also with Jamel wrt. ioctl(), let's not go
> there if possible. :-)
Ok.
I did also go the ioctl() way because that's what iproute2-2.6.8 uses.
[Dave: sorry for the sending you this twice]
--
Eric
===== include/linux/rtnetlink.h 1.41 vs edited =====
--- 1.41/include/linux/rtnetlink.h Wed Aug 25 02:20:27 2004
+++ edited/include/linux/rtnetlink.h Tue Aug 31 11:22:55 2004
@@ -565,6 +565,8 @@
#define IFLA_TXQLEN IFLA_TXQLEN
IFLA_MAP,
#define IFLA_MAP IFLA_MAP
+ IFLA_WEIGHT,
+#define IFLA_WEIGHT IFLA_WEIGHT
__IFLA_MAX
};
===== net/core/rtnetlink.c 1.23 vs edited =====
--- 1.23/net/core/rtnetlink.c Wed Aug 25 02:20:27 2004
+++ edited/net/core/rtnetlink.c Tue Aug 31 11:27:15 2004
@@ -177,6 +177,11 @@
}
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,
@@ -331,6 +336,13 @@
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;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] Allow setting dev->weight using ip(8)
2004-08-30 12:27 ` jamal
2004-08-30 12:42 ` jamal
@ 2004-08-30 14:33 ` Eric Lemoine
2004-09-08 13:45 ` Thomas Graf
1 sibling, 1 reply; 8+ messages in thread
From: Eric Lemoine @ 2004-08-30 14:33 UTC (permalink / raw)
To: hadi; +Cc: netdev
[-- Attachment #1: Type: text/plain, Size: 1319 bytes --]
> > 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.
> Looks sane.
> Not sure if you should encourage ioctl though ;->
iproute still uses ioctl at that time, doesn't it?
> Out of curiosity, what/when do you change weight? I think its valuable
> to do so, just curious.
With weight one can have the NIC fetch rx descriptors while the rx
interrupt remains disabled. This further means that under high input
load, one single rx interrupt can result in more than RX_RING_SIZE rx
packets polled. Using this + tx polling, I could observe a system
fully loaded by the network with no interrupts at all.
> missing user space/ip patch btw.
I attached a patch to iproute-2.6.8. To make the patch compile I had
to tinker with the Makefile - it seems that KERNEL_INCLUDE does no
longer serve any purpose, except for ATM maybe.
--
Eric
[-- Attachment #2: patch-ioctl_dev_weight-iproute-2-6-8 --]
[-- Type: application/octet-stream, Size: 3130 bytes --]
--- ip/iplink.c.old 2004-08-30 15:32:20.361781064 +0200
+++ ip/iplink.c 2004-08-30 15:45:23.701826039 +0200
@@ -44,6 +44,7 @@
fprintf(stderr, " promisc { on | off } |\n");
fprintf(stderr, " trailers { on | off } |\n");
fprintf(stderr, " txqueuelen PACKETS |\n");
+ fprintf(stderr, " weight PACKETS |\n");
fprintf(stderr, " name NEWNAME |\n");
fprintf(stderr, " address LLADDR | broadcast LLADDR |\n");
fprintf(stderr, " mtu MTU }\n");
@@ -174,6 +175,28 @@
return 0;
}
+static int set_weight(char *dev, int weight)
+{
+ struct ifreq ifr;
+ int s;
+
+ s = get_ctl_fd();
+ if (s < 0)
+ return -1;
+
+ memset(&ifr, 0, sizeof(ifr));
+ strcpy(ifr.ifr_name, dev);
+ ifr.ifr_weight = weight;
+ if (ioctl(s, SIOCSIFWEIGHT, &ifr) < 0) {
+ perror("SIOCSIFWEIGHT");
+ close(s);
+ return -1;
+ }
+ close(s);
+
+ return 0;
+}
+
static int get_address(char *dev, int *htype)
{
struct ifreq ifr;
@@ -257,6 +280,7 @@
__u32 flags = 0;
int qlen = -1;
int mtu = -1;
+ int weight = -1;
char *newaddr = NULL;
char *newbrd = NULL;
struct ifreq ifr0, ifr1;
@@ -294,6 +318,12 @@
duparg("mtu", *argv);
if (get_integer(&mtu, *argv, 0))
invarg("Invalid \"mtu\" value\n", *argv);
+ } else if (matches(*argv, "weight") == 0) {
+ NEXT_ARG();
+ if (weight != -1)
+ duparg("weight", *argv);
+ if (get_integer(&weight, *argv, 0))
+ invarg("Invalid \"weight\" value\n", *argv);
} else if (strcmp(*argv, "multicast") == 0) {
NEXT_ARG();
mask |= IFF_MULTICAST;
@@ -395,6 +425,10 @@
if (set_mtu(dev, mtu) < 0)
return -1;
}
+ if (weight != -1) {
+ if (set_weight(dev, weight) < 0)
+ return -1;
+ }
if (newaddr || newbrd) {
if (newbrd) {
if (set_address(&ifr1, 1) < 0)
--- ip/ipaddress.c.old 2004-08-30 15:45:36.811492080 +0200
+++ ip/ipaddress.c 2004-08-30 16:14:10.722831419 +0200
@@ -40,6 +40,7 @@
int family;
int oneline;
int showqueue;
+ int showweight;
inet_prefix pfx;
int scope, scopemask;
int flags, flagmask;
@@ -126,6 +127,28 @@
printf("qlen %d", ifr.ifr_qlen);
}
+void print_weight(char *name)
+{
+ struct ifreq ifr;
+ int s;
+
+ s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s < 0)
+ return;
+
+ memset(&ifr, 0, sizeof(ifr));
+ strcpy(ifr.ifr_name, name);
+ if (ioctl(s, SIOCGIFWEIGHT, &ifr) < 0) {
+ perror("SIOCGIFWEIGHT");
+ close(s);
+ return;
+ }
+ close(s);
+
+ if (ifr.ifr_weight)
+ printf(" weight %d", ifr.ifr_weight);
+}
+
int print_linkinfo(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{
FILE *fp = (FILE*)arg;
@@ -191,6 +214,9 @@
if (filter.showqueue)
print_queuelen((char*)RTA_DATA(tb[IFLA_IFNAME]));
+ if (filter.showweight)
+ print_weight((char*)RTA_DATA(tb[IFLA_IFNAME]));
+
if (!filter.family || filter.family == AF_PACKET) {
SPRINT_BUF(b1);
fprintf(fp, "%s", _SL_);
@@ -496,6 +522,7 @@
ipaddr_reset_filter(oneline);
filter.showqueue = 1;
+ filter.showweight = 1;
if (filter.family == AF_UNSPEC)
filter.family = preferred_family;
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] Allow setting dev->weight using ip(8)
2004-08-30 14:33 ` Eric Lemoine
@ 2004-09-08 13:45 ` Thomas Graf
0 siblings, 0 replies; 8+ messages in thread
From: Thomas Graf @ 2004-09-08 13:45 UTC (permalink / raw)
To: Eric Lemoine; +Cc: hadi, netdev
* Eric Lemoine <5cac192f0408300733477c6c9@mail.gmail.com> 2004-08-30 16:33
> iproute still uses ioctl at that time, doesn't it?
> [...]
> I attached a patch to iproute-2.6.8. To make the patch compile I had
> to tinker with the Makefile - it seems that KERNEL_INCLUDE does no
> longer serve any purpose, except for ATM maybe.
I have a patch for it and added support for your new changes.
I'm currently holding it back until all issues with the 2.4
backport have been solved.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2004-09-08 13:45 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-30 10:56 [PATCH] Allow setting dev->weight using ip(8) Eric Lemoine
2004-08-30 12:27 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).