: rtnl_link support
Subsystems (2)
cover : rtnl_link support
Hi Stephen,
these patches add support for the rtnl_link stuff and VLAN configuration to iproute. Since the old link configuration was entirely ioctl based and mixing the two would be really ugly, this patch keeps the old ioctl stuff guarded by an ifdef (defaults to enabled) and probes for support for using RTM_NEWLINK. Tested to work properly on both old and patched kernel.
I've added a new -d[etail] flag to ip, the driver specific things are only printed when it is specified. I did this mainly because I'm not sure how careful we want to be not to confuse people using sed/awk/... on iproute output. I would prefer to have the information always shown, but I'll leave that decision up to you.
Changes since the last post:
- Only call link argument parsing function if arguments are present
- Support xstats dumping
- Add sanitized if_vlan.h file for VLAN flag definition
- Support setting/changing VLAN flags
Please apply, thanks.
include/linux/if_link.h | 47 +++++++ include/linux/if_vlan.h | 61 +++++++++ ip/Makefile | 4 ip/ip.c | 5 ip/ip_common.h | 15 ++ ip/ipaddress.c | 39 ++++++ ip/iplink.c | 311 +++++++++++++++++++++++++++++++++++++++++++++++- ip/iplink_vlan.c | 184 ++++++++++++++++++++++++++++ 8 files changed, 663 insertions(+), 3 deletions(-)
Patrick McHardy (2):
[IPROUTE]: iplink: use netlink for link configuration [IPROUTE]: VLAN support
PATCH 1/2 : iplink: use netlink for link configuration
[IPROUTE]: iplink: use netlink for link configuration
Add support for using netlink for link configuration. Kernel-support is probed, when not available it falls back to using ioctls.
---
commit 4feb48d12295eb41850c39996f3a8c1dd7909ed5
tree dbb34cf5a9b38adb0c2602a88b09823f922c8a2c
parent b16621cafd599499fdbaa79236266d72a53106bb
author Patrick McHardy <[email protected]> Wed, 13 Jun 2007 14:10:57 +0200 committer Patrick McHardy <[email protected]> Wed, 13 Jun 2007 14:10:57 +0200
include/linux/if_link.h | 13 ++ ip/Makefile | 2 ip/ip.c | 5 + ip/ip_common.h | 15 ++ ip/ipaddress.c | 39 ++++++ ip/iplink.c | 311 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 382 insertions(+), 3 deletions(-)
include/linux/if_link.h +13 -0
@@ -76,6 +76,8 @@ enum#define IFLA_WEIGHT IFLA_WEIGHTIFLA_OPERSTATE ,IFLA_LINKMODE , +IFLA_LINKINFO , +#define IFLA_LINKINFO IFLA_LINKINFO __IFLA_MAX };
@@ -137,4 +139,15 @@ struct ifla_cacheinfo __u32 retrans_time; }; +enum +{ +IFLA_INFO_UNSPEC , +IFLA_INFO_KIND , +IFLA_INFO_DATA , +IFLA_INFO_XSTATS , + __IFLA_INFO_MAX, +}; + +#define IFLA_INFO_MAX (__IFLA_INFO_MAX - 1) +#endif /* _LINUX_IF_LINK_H */
ip/Makefile +2 -0
@@ -22,3 +22,5 @@ install: all clean: rm -f $(ALLOBJ) $(TARGETS) +LDLIBS += -ldl +LDFLAGS += -Wl,-export-dynamic
ip/ip.c +4 -1
@@ -30,6 +30,7 @@int preferred_family =AF_UNSPEC ;int show_stats =0 ; +int show_details =0 ;int resolve_hosts =0 ;int oneline =0 ;int timestamp =0 ;
@@ -47,7 +48,7 @@ static void usage(void)" ip [ -force ] [-batch filename\n" "where OBJECT := { link | addr | route | rule | neigh | ntable | tunnel |\n" " maddr | mroute | monitor | xfrm }\n" -" OPTIONS := { -V[ersion] | -s[tatistics] | -r[esolve] |\n" +" OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n" " -f[amily] { inet | inet6 | ipx | dnet | link } |\n" " -o[neline] | -t[imestamp] }\n");exit (-1 );
@@ -188,6 +189,8 @@ int main(int argc, char **argv) }else if (matches (opt,"-stats" ) ==0 ||matches (opt,"-statistics" ) ==0 ) { ++show_stats; + }else if (matches (opt,"-details" ) ==0 ) { + ++show_details; }else if (matches (opt,"-resolve" ) ==0 ) { ++resolve_hosts; }else if (matches (opt,"-oneline" ) ==0 ) {
ip/ip_common.h +15 -0
@@ -45,6 +45,21 @@ static inline int rtm_get_table(struct rtmsg *r, struct rtattr **tb)extern struct rtnl_handle rth; +struct link_util +{ +struct link_util *next; +const char *id; +int maxattr; +int (*parse_opt)(struct link_util *,int ,char **, +struct nlmsghdr *); +void (*print_opt)(struct link_util *,FILE *, +struct rtattr *[]); +void (*print_xstats)(struct link_util *,FILE *, +struct rtattr *); +}; + +struct link_util *get_link_kind (const char *kind); +#ifndef INFINITY_LIFE_TIME #define INFINITY_LIFE_TIME 0xFFFFFFFFU#endif
ip/ipaddress.c +39 -0
@@ -134,6 +134,41 @@ void print_queuelen(char *name)printf ("qlen %d" , ifr.ifr_qlen); } +static void print_linktype (FILE *fp,struct rtattr *tb) +{ +struct rtattr *linkinfo[IFLA_INFO_MAX +1 ]; +struct link_util *lu; +char *kind; + +parse_rtattr_nested (linkinfo,IFLA_INFO_MAX , tb); + +if (!linkinfo[IFLA_INFO_KIND ]) +return ; + kind =RTA_DATA (linkinfo[IFLA_INFO_KIND ]); + +fprintf (fp,"%s" , _SL_); +fprintf (fp," %s " , kind); + + lu =get_link_kind (kind); +if (!lu || !lu->print_opt) +return ; + +if (1 ) { +struct rtattr *attr[lu->maxattr+1 ], **data =NULL ; + +if (linkinfo[IFLA_INFO_DATA ]) { +parse_rtattr_nested (attr, lu->maxattr, + linkinfo[IFLA_INFO_DATA ]); + data = attr; + } + lu->print_opt (lu, fp, data); + +if (linkinfo[IFLA_INFO_XSTATS ] && show_stats && + lu->print_xstats) + lu->print_xstats (lu, fp, linkinfo[IFLA_INFO_XSTATS ]); + } +} +int print_linkinfo (const struct sockaddr_nl *who,struct nlmsghdr *n,void *arg) {
@@ -221,6 +256,10 @@ int print_linkinfo(const struct sockaddr_nl *who, b1, sizeof(b1))); } } + +if (do_link && tb[IFLA_LINKINFO ] && show_details) +print_linktype (fp, tb[IFLA_LINKINFO ]); +if (do_link && tb[IFLA_STATS ] && show_stats) {struct rtnl_link_stats slocal;struct rtnl_link_stats *s =RTA_DATA (tb[IFLA_STATS ]);
ip/iplink.c +309 -2
339 lines not on this page · raw message
PATCH 2/2 : VLAN support
In reply to Patrick McHardy[IPROUTE]: VLAN support
---
commit 90727b2bf5b4a7ef9d0638ca80206083b965a0b5
tree 173722acd855b7fe1eb1a5f22cf7706814f72c8f
parent 4feb48d12295eb41850c39996f3a8c1dd7909ed5
author Patrick McHardy <[email protected]> Wed, 13 Jun 2007 18:46:21 +0200 committer Patrick McHardy <[email protected]> Wed, 13 Jun 2007 18:46:21 +0200
include/linux/if_link.h | 34 +++++++++ include/linux/if_vlan.h | 61 ++++++++++++++++ ip/Makefile | 2 + ip/iplink_vlan.c | 184 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 281 insertions(+), 0 deletions(-)
include/linux/if_link.h +34 -0
@@ -150,4 +150,38 @@ enum#define IFLA_INFO_MAX (__IFLA_INFO_MAX - 1) +/* VLAN section */ + +enum +{ +IFLA_VLAN_UNSPEC , +IFLA_VLAN_ID , +IFLA_VLAN_FLAGS , +IFLA_VLAN_EGRESS_QOS , +IFLA_VLAN_INGRESS_QOS , + __IFLA_VLAN_MAX, +}; + +#define IFLA_VLAN_MAX (__IFLA_VLAN_MAX - 1) + +struct ifla_vlan_flags { +__u32 flags; +__u32 mask; +}; + +enum +{ +IFLA_VLAN_QOS_UNSPEC , +IFLA_VLAN_QOS_MAPPING , + __IFLA_VLAN_QOS_MAX +}; + +#define IFLA_VLAN_QOS_MAX (__IFLA_VLAN_QOS_MAX - 1) + +struct ifla_vlan_qos_mapping +{ +__u32 from; +__u32 to; +}; +#endif /* _LINUX_IF_LINK_H */
include/linux/if_vlan.h new file +61 -0
61 lines not on this page · raw message
ip/Makefile +2 -0
@@ -3,6 +3,8 @@ IPOBJ=ip.o ipaddress.o iproute.o iprule.o \ ipmaddr.o ipmonitor.o ipmroute.o ipprefix.o \ ipxfrm.o xfrm_state.o xfrm_policy.o xfrm_monitor.o +IPOBJ += iplink_vlan.o + RTMONOBJ=rtmon.o ALLOBJ=$(IPOBJ) $(RTMONOBJ)
ip/iplink_vlan.c new file +184 -0
184 lines not on this page · raw message
Quoted 14 lines · On Wed, 13 Jun 2007 19:02:32 +0200 (MEST) Patrick McHardy <[email protected]>…
Hi Stephen,
these patches add support for the
rtnl_linkstuff and VLAN configuration to iproute. Since the old link configuration was entirely ioctl based and mixing the two would be really ugly, this patch keeps the old ioctl stuff guarded by an ifdef (defaults to enabled) and probes for support for usingRTM_NEWLINK. Tested to work properly on both old and patched kernel.I've added a new -d[etail] flag to ip, the driver specific things are only printed when it is specified. I did this mainly because I'm not sure how careful we want to be not to confuse people using sed/awk/... on iproute output. I would prefer to have the information always shown, but I'll leave that decision up to you.
Quoted 8 lines
Changes since the last post:
- Only call link argument parsing function if arguments are present
- Support xstats dumping
- Add sanitizedif_vlan.hfile for VLAN flag definition
- Support setting/changing VLAN flagsPlease apply, thanks.
I'm putting out a new iproute2 next week. IF this is in mainline, it will go in then. If not, then there will be a development branch
Quoted 8 lines · Stephen Hemminger
Quoted 1 line · On Wed, 13 Jun 2007 19:02:32 +0200 (MEST) Patrick McHardy <[email protected]>…
Please apply, thanks.
I'm putting out a new iproute2 next week. IF this is in mainline, it will go in then. If not, then there will be a development branch
Thanks. The first version of these patches are already in the net-2.6.23 tree, Dave is going to replace them with this version. Unlikely to be in mainline until next week though :)
David Miller
maintainerFrom: Patrick McHardy <[email protected]>
Date: Wed, 13 Jun 2007 20:11:58 +0200
Quoted 7 lines
Quoted 6 lines · Stephen Hemminger
Quoted 1 line · On Wed, 13 Jun 2007 19:02:32 +0200 (MEST) Patrick McHardy <[email protected]>…
Please apply, thanks.
Quoted 7 lines
Quoted 2 lines
I'm putting out a new iproute2 next week. IF this is in mainline, it will go in then. If not, then there will be a development branch
Thanks. The first version of these patches are already in the net-2.6.23 tree, Dave is going to replace them with this version. Unlikely to be in mainline until next week though :)
Right this is 2.6.23 stuff and it is in my net-2.6.23 tree already.