Skip to contentSkip to conversation

ethtool netlink interface

RFC In review Thomas Graf 3 participants 4 messages Feb 25, 2008 – Feb 27, 2008

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

RFC 1/1 ethtool netlink interface

Hello,

Before I continue to finish this work I'd like to get a few comments on my implementation attempt.

The following patch implements the ETHTOOL_SSET and ETHTOOL_GSET command via netlink. The individual commands are implemented as separate functions and hooked into a table holding a validate, set and fill function for each command. Additionaly an entry must be made in the attribute policy to validate attributes when received.

Each ethtool command bundle is stored as a nested attribute in the regular link netlink message, therefore, unlike the ioctl interface, multiple ethtool commands can be issued in the same message allowing for links to be fully configured with a single message.

There is one big disadvantage: Due to the nature of ioctl it is basically not possible to share any code between the ioctl and neltink implementation therefore it implies duplicating code unless we want to do the same hack as fib fronted by constructing netlink messages inside the kernel.

include/linux/if_link.h +1 -0
Index: net-2.6.26/include/linux/if_link.h
===================================================================
@@ -79,6 +79,7 @@
 	IFLA_LINKINFO,
 #define IFLA_LINKINFO IFLA_LINKINFO
 	IFLA_NET_NS_PID,
+	IFLA_ETHTOOL,
 	__IFLA_MAX
 };
 
net/core/ethtool.c +134 -0

149 lines not on this page · raw message

net/core/rtnetlink.c +19 -0
Index: net-2.6.26/net/core/rtnetlink.c
===================================================================
@@ -43,6 +43,7 @@
 
 #include <linux/inet.h>
 #include <linux/netdevice.h>
+#include <linux/ethtool.h>
 #include <net/ip.h>
 #include <net/protocol.h>
 #include <net/arp.h>
@@ -657,6 +658,9 @@
 			goto nla_put_failure;
 	}
 
+	if (dev->ethtool_ops && ethtool_fill_nlattr(skb, dev) < 0)
+		goto nla_put_failure;
+
 	return nlmsg_end(skb, nlh);
 
 nla_put_failure:
@@ -700,6 +704,7 @@
 	[IFLA_LINKMODE]		= { .type = NLA_U8 },
 	[IFLA_LINKINFO]		= { .type = NLA_NESTED },
 	[IFLA_NET_NS_PID]	= { .type = NLA_U32 },
+	[IFLA_ETHTOOL]		= { .type = NLA_NESTED },
 };
 
 static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
@@ -728,6 +733,8 @@
 
 static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[])
 {
+	int err;
+
 	if (dev) {
 		if (tb[IFLA_ADDRESS] &&
 		    nla_len(tb[IFLA_ADDRESS]) < dev->addr_len)
@@ -736,6 +743,12 @@
 		if (tb[IFLA_BROADCAST] &&
 		    nla_len(tb[IFLA_BROADCAST]) < dev->addr_len)
 			return -EINVAL;
+
+		if (tb[IFLA_ETHTOOL]) {
+			err = ethtool_validate_nlattr(dev, tb[IFLA_ETHTOOL]);
+			if (err < 0)
+				return err;
+		}
 	}
 
 	return 0;
@@ -875,6 +888,12 @@
 		}
 	}
 
+	if (tb[IFLA_ETHTOOL]) {
+		if ((err = ethtool_execute_nlattr(dev, tb[IFLA_ETHTOOL])) < 0)
+			goto errout;
+		modified = 1;
+	}
+
 	err = 0;
 
 errout:
include/linux/ethtool.h +14 -0
Index: net-2.6.26/include/linux/ethtool.h
===================================================================
@@ -274,6 +274,8 @@
 #ifdef __KERNEL__
 
 struct net_device;
+struct nlattr;
+struct sk_buff;
 
 /* Some generic methods drivers may use in their ethtool_ops */
 u32 ethtool_op_get_link(struct net_device *dev);
@@ -290,6 +292,10 @@
 u32 ethtool_op_get_flags(struct net_device *dev);
 int ethtool_op_set_flags(struct net_device *dev, u32 data);
 
+extern int ethtool_validate_nlattr(struct net_device *, struct nlattr *);
+extern int ethtool_execute_nlattr(struct net_device *, struct nlattr *);
+extern int ethtool_fill_nlattr(struct sk_buff *, struct net_device *);
+
 /**
  * &ethtool_ops - Alter and report network device settings
  * get_settings: Get device-specific settings
@@ -527,4 +533,12 @@
 #define WAKE_MAGIC		(1 << 5)
 #define WAKE_MAGICSECURE	(1 << 6) /* only meaningful if WAKE_MAGIC */
 
+enum {
+	IFLA_ET_UNSPEC,
+	IFLA_ET_SETTINGS,
+	__IFLA_ET_MAX,
+};
+
+#define IFLA_ET_MAX (__IFLA_ET_MAX - 1)
+
 #endif /* _LINUX_ETHTOOL_H */
#1 lore raw
Quoted 17 lines · Thomas Graf

Hello,

Before I continue to finish this work I'd like to get a few comments on my implementation attempt.

The following patch implements the ETHTOOL_SSET and ETHTOOL_GSET command via netlink. The individual commands are implemented as separate functions and hooked into a table holding a validate, set and fill function for each command. Additionaly an entry must be made in the attribute policy to validate attributes when received.

Each ethtool command bundle is stored as a nested attribute in the regular link netlink message, therefore, unlike the ioctl interface, multiple ethtool commands can be issued in the same message allowing for links to be fully configured with a single message.

Quoted 5 lines

There is one big disadvantage: Due to the nature of ioctl it is basically not possible to share any code between the ioctl and neltink implementation therefore it implies duplicating code unless we want to do the same hack as fib fronted by constructing netlink messages inside the kernel.

No objections, and it certainly makes sense that you would need a separate "thunking" layer to unwrap ethtool-nl msgs rather than handling an ioctl.

However, I would think it inconsistent to only do SSET/GSET. If others are OK with this patch, are you open to implementing the full set of ethtool operations?

Jeff

#2 lore raw

* Jeff Garzik <[email protected]> 2008-02-25 12:30

Quoted 3 lines

However, I would think it inconsistent to only do SSET/GSET. If others are OK with this patch, are you open to implementing the full set of ethtool operations?

Of course, I would also provide a documented userspace api within libnl.

maintainer
#3 lore raw

From: Thomas Graf <[email protected]>
Date: Mon, 25 Feb 2008 19:23:43 +0100

Quoted 6 lines

* Jeff Garzik <[email protected]> 2008-02-25 12:30

Quoted 3 lines

However, I would think it inconsistent to only do SSET/GSET. If others are OK with this patch, are you open to implementing the full set of ethtool operations?

Of course, I would also provide a documented userspace api within libnl.

I'm perfectly fine with all of this.