iproute2 patch introducing mtu/txqlen/weight via rtnetlink
Subsystems (3)
- Convert mtu and txqlen to use rtnetlink instead of ioctl.
- Introduces weight.
- Updates local copy of rtnetlink.h.
Against iproute2-2.6.9-jamal, tested and working.
Will look into remaining ioctls later.
include/linux/rtnetlink.h +88 -0
@@ -561,6 +561,12 @@#define IFLA_WIRELESS IFLA_WIRELESS IFLA_PROTINFO, /* Protocol specific information for a link */#define IFLA_PROTINFO IFLA_PROTINFO + IFLA_TXQLEN, +#define IFLA_TXQLEN IFLA_TXQLEN + IFLA_MAP, +#define IFLA_MAP IFLA_MAP + IFLA_WEIGHT, +#define IFLA_WEIGHT IFLA_WEIGHT __IFLA_MAX };
@@ -693,6 +699,88 @@/* End of information exported to user level */ +#ifdef __KERNEL__ + +#include <linux/config.h> + +static __inline__int rtattr_strcmp (const struct rtattr *rta,const char *str) +{ +int len =strlen (str) +1 ; +return len > rta->rta_len ||memcmp (RTA_DATA (rta), str, len); +} + +extern int rtattr_parse (struct rtattr *tb[],int maxattr,struct rtattr *rta,int len); + +extern struct sock *rtnl; + +struct rtnetlink_link +{ +int (*doit)(struct sk_buff *,struct nlmsghdr *,void *attr); +int (*dumpit)(struct sk_buff *,struct netlink_callback *cb); +}; + +extern struct rtnetlink_link * rtnetlink_links[NPROTO ]; +extern int rtnetlink_dump_ifinfo (struct sk_buff *skb,struct netlink_callback *cb); +extern int rtnetlink_send (struct sk_buff *skb,u32 pid,u32 group,int echo); +extern int rtnetlink_put_metrics (struct sk_buff *skb,u32 *metrics); + +extern void __rta_fill (struct sk_buff *skb,int attrtype,int attrlen,const void *data); + +#define RTA_PUT (skb, attrtype, attrlen, data) \ +({ if (unlikely(skb_tailroom(skb) < (int)RTA_SPACE(attrlen))) \ + goto rtattr_failure; \ + __rta_fill(skb, attrtype, attrlen, data); }) + +static inline struct rtattr * +__rta_reserve (struct sk_buff *skb,int attrtype,int attrlen) +{ +struct rtattr *rta; +int size =RTA_LENGTH (attrlen); + + rta = (struct rtattr *)skb_put (skb,RTA_ALIGN (size)); + rta->rta_type = attrtype; + rta->rta_len = size; +return rta; +} + +#define __RTA_PUT (skb, attrtype, attrlen) \ +({ if (unlikely(skb_tailroom(skb) < (int)RTA_SPACE(attrlen))) \ + goto rtattr_failure; \ + __rta_reserve(skb, attrtype, attrlen); }) + +extern void rtmsg_ifinfo (int type,struct net_device *dev,unsigned change); + +extern struct semaphore rtnl_sem; + +#define rtnl_shlock () down(&rtnl_sem) +#define rtnl_shlock_nowait () down_trylock(&rtnl_sem) + +#define rtnl_shunlock () do { up(&rtnl_sem); \ + if (rtnl && rtnl->sk_receive_queue.qlen) \ + rtnl->sk_data_ready(rtnl, 0); \ + } while(0) + +extern void rtnl_lock (void ); +extern void rtnl_unlock (void ); +extern void rtnetlink_init (void ); + +#define ASSERT_RTNL () do { \ + if (unlikely(down_trylock(&rtnl_sem) == 0)) { \ + up(&rtnl_sem); \ + printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \ + __FILE__, __LINE__); \ + dump_stack(); \ + } \ +} while(0) + +#define BUG_TRAP (x) do { \ + if (unlikely(!(x))) { \ + printk(KERN_ERR "KERNEL: assertion (%s) failed at %s (%d)\n", \ + #x, __FILE__ , __LINE__); \ + } \ +} while(0) + +#endif /* __KERNEL__ */ #endif /* __LINUX_RTNETLINK_H */
ip/ipaddress.c +2 -0
@@ -182,6 +182,8 @@fprintf (fp,"mtu %u " , *(int *)RTA_DATA (tb[IFLA_MTU ]));if (tb[IFLA_QDISC ])fprintf (fp,"qdisc %s " , (char *)RTA_DATA (tb[IFLA_QDISC ])); +if (tb[IFLA_WEIGHT ]) +fprintf (fp,"weight %u " , *(uint32_t *)RTA_DATA (tb[IFLA_WEIGHT ]));#ifdef IFLA_MASTER if (tb[IFLA_MASTER ]) {SPRINT_BUF (b1);
ip/iplink.c +45 -55
165 lines not on this page · raw message
David S. Miller
maintainerQuoted 6 lines · On Thu, 9 Sep 2004 18:48:34 +0200 Thomas Graf <[email protected]> wrote:
- Convert mtu and txqlen to use rtnetlink instead of ioctl.
- Introduces weight.
- Updates local copy ofrtnetlink.h.Against iproute2-2.6.9-jamal, tested and working.
Will look into remaining ioctls later.
Please don't blindly update rtnetlink.h in iproute2 with the current kernel copy. The "__KERNEL__" ifdef area is omitted on purpose, yet you added it back in.
* David S. Miller <[email protected]> 2004-09-09 10:33
Quoted 7 lines
Quoted 4 lines · On Thu, 9 Sep 2004 18:48:34 +0200 Thomas Graf <[email protected]> wrote:
- Convert mtu and txqlen to use rtnetlink instead of ioctl.
- Introduces weight.
- Updates local copy ofrtnetlink.h.
Quoted 6 lines
Quoted 2 lines
Against iproute2-2.6.9-jamal, tested and working.
Will look into remaining ioctls later.Please don't blindly update
rtnetlink.hin iproute2 with the current kernel copy. The "__KERNEL__" ifdef area is omitted on purpose, yet you added it back in.
Sorry, included old patch, this is a correct one:
include/linux/rtnetlink.h +6 -0
@@ -561,6 +561,12 @@#define IFLA_WIRELESS IFLA_WIRELESS IFLA_PROTINFO, /* Protocol specific information for a link */#define IFLA_PROTINFO IFLA_PROTINFO + IFLA_TXQLEN, +#define IFLA_TXQLEN IFLA_TXQLEN + IFLA_MAP, +#define IFLA_MAP IFLA_MAP + IFLA_WEIGHT, +#define IFLA_WEIGHT IFLA_WEIGHT __IFLA_MAX };
ip/ipaddress.c +2 -0
@@ -182,6 +182,8 @@fprintf (fp,"mtu %u " , *(int *)RTA_DATA (tb[IFLA_MTU ]));if (tb[IFLA_QDISC ])fprintf (fp,"qdisc %s " , (char *)RTA_DATA (tb[IFLA_QDISC ])); +if (tb[IFLA_WEIGHT ]) +fprintf (fp,"weight %u " , *(uint32_t *)RTA_DATA (tb[IFLA_WEIGHT ]));#ifdef IFLA_MASTER if (tb[IFLA_MASTER ]) {SPRINT_BUF (b1);
ip/iplink.c +48 -55
168 lines not on this page · raw message
In article <[email protected]> (at Thu, 9 Sep 2004 19:54:11 +0200), Thomas Graf <[email protected]> says:
Quoted 8 lines
* David S. Miller <[email protected]> 2004-09-09 10:33
Quoted 7 lines
Quoted 4 lines · On Thu, 9 Sep 2004 18:48:34 +0200 Thomas Graf <[email protected]> wrote:
- Convert mtu and txqlen to use rtnetlink instead of ioctl.
- Introduces weight.
- Updates local copy ofrtnetlink.h.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Against iproute2-2.6.9-jamal, tested and working.
Will look into remaining ioctls later.Please don't blindly update
rtnetlink.hin iproute2 with the current kernel copy. The "__KERNEL__" ifdef area is omitted on purpose, yet you added it back in.Sorry, included old patch, this is a correct one:
Well, I think we should maintain old ioctl path for backward compatibility. (or ifdefs at least.)
Signature · 2 lines
Hideaki YOSHIFUJI @ USAGI Project <[email protected]> GPG FP: 9022 65EB 1ECF 3AD1 0BDF 80D8 4807 F894 E062 0EEA
* YOSHIFUJI Hideaki / ?$B5HF#1QL@ <[email protected]> 2004-09-10 10:33
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines · On Thu, 9 Sep 2004 18:48:34 +0200 Thomas Graf <[email protected]> wrote:
- Convert mtu and txqlen to use rtnetlink instead of ioctl.
- Introduces weight.
- Updates local copy ofrtnetlink.h.Well, I think we should maintain old ioctl path for backward compatibility. (or ifdefs at least.)
I agree, however I think that the only good solution would be to have iproute2 negotiate with the kernel at runtime. I therefore suggest to consider my iproute2 patches as development only and don't include them in any releases as long as the whole 'new iproute2 with old kernel' issue, also affecting the new tc-actions, has been resolved.
Unless there is some compelling reason, I think that keeping the old ioctl interface for a least a year until the kernel changes become more ubiquitous.
Quoted 2 lines · Stephen Hemminger
Unless there is some compelling reason, I think that keeping the old ioctl interface for a least a year until the kernel changes become more ubiquitous.
I think that iproute2 should first attempt to use netlink and on failure switch to ioctls.
Maybe Thomas can create such a patch.
cheers,
jamal
* jamal <[email protected]> 2004-09-10 09:16
Quoted 8 lines · Stephen Hemminger
Quoted 2 lines
Unless there is some compelling reason, I think that keeping the old ioctl interface for a least a year until the kernel changes become more ubiquitous.
I think that iproute2 should first attempt to use netlink and on failure switch to ioctls.
Maybe Thomas can create such a patch.
- Uses rtnetlink whenver possible and falls back to ioctl if the rtnetlink call fails or one of the changes was not successful. Not 100% perfect yet but you'll get the point.
- Fixes memory corruption issue. buffer for address and brd was too small (14) for bigger addresses, e.g. interfaces with ipv6 ll addresses. Introduced a ADDRBUFSIZ and a check in ll_init_map to avoid further problems.
- Uses ifinfomsg.ifi_type instead of getting hw type from packet socket. I hope this is correct.
just a small hack...
include/linux/rtnetlink.h +6 -0
@@ -561,6 +561,12 @@#define IFLA_WIRELESS IFLA_WIRELESS IFLA_PROTINFO, /* Protocol specific information for a link */#define IFLA_PROTINFO IFLA_PROTINFO + IFLA_TXQLEN, +#define IFLA_TXQLEN IFLA_TXQLEN + IFLA_MAP, +#define IFLA_MAP IFLA_MAP + IFLA_WEIGHT, +#define IFLA_WEIGHT IFLA_WEIGHT __IFLA_MAX };
include/ll_map.h +5 -0
@@ -1,12 +1,17 @@#ifndef __LL_MAP_H__#define __LL_MAP_H__ 1 +#define ADDRBUFSIZ 32 +extern int ll_remember_index (struct sockaddr_nl *who,struct nlmsghdr *n,void *arg);extern int ll_init_map (struct rtnl_handle *rth);extern int ll_name_to_index (char *name);extern const char *ll_index_to_name (int idx);extern const char *ll_idx_n2a (int idx,char *buf);extern int ll_index_to_type (int idx); +extern int ll_index_to_alen (int idx); +extern unsigned char *ll_index_to_addr (int idx); +extern unsigned char *ll_index_to_brd (int idx);extern unsigned ll_index_to_flags (int idx);#endif /* __LL_MAP_H__ */
ip/ipaddress.c +4 -0
@@ -182,6 +182,10 @@fprintf (fp,"mtu %u " , *(int *)RTA_DATA (tb[IFLA_MTU ]));if (tb[IFLA_QDISC ])fprintf (fp,"qdisc %s " , (char *)RTA_DATA (tb[IFLA_QDISC ])); +#ifdef IFLA_WEIGT +if (tb[IFLA_WEIGHT ]) +fprintf (fp,"weight %u " , *(uint32_t *)RTA_DATA (tb[IFLA_WEIGHT ])); +#endif #ifdef IFLA_MASTER if (tb[IFLA_MASTER ]) {SPRINT_BUF (b1);
ip/iplink.c +120 -47
251 lines not on this page · raw message
lib/ll_map.c +53 -1
78 lines not on this page · raw message
David S. Miller
maintainerQuoted 7 lines · On 10 Sep 2004 09:16:46 -0400 jamal <[email protected]> wrote:
Quoted 2 lines · Stephen Hemminger
Unless there is some compelling reason, I think that keeping the old ioctl interface for a least a year until the kernel changes become more ubiquitous.
I think that iproute2 should first attempt to use netlink and on failure switch to ioctls.
This is what I would recommend too.