All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ethtool: add get permanent address option
@ 2010-10-18 18:41 Stephen Hemminger
  2010-10-18 19:52 ` Ben Hutchings
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2010-10-18 18:41 UTC (permalink / raw)
  To: Jeff Garzik, Jeff Garzik, netdev

Add command level support for showing permanent address.
The ioctl has been around for a long time but there was
no option to display it.

Note: MAX_ADDR_LEN is defined in netdevice.h but including
netdevice.h leads to multiple definition errors with if.h.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

---
 ethtool.8 |    6 ++++++
 ethtool.c |   36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 41 insertions(+), 1 deletions(-)

diff --git a/ethtool.8 b/ethtool.8
index 3ca403c..84d5cc0 100644
--- a/ethtool.8
+++ b/ethtool.8
@@ -176,6 +176,9 @@ ethtool \- Display or change ethernet card settings
 .I ethX
 .RI [ N ]
 
+.B ethtool \-P|\-\-show-permaddr
+.I ethX
+
 .B ethtool \-r|\-\-negotiate
 .I ethX
 
@@ -388,6 +391,9 @@ blinking one or more LEDs on the specific ethernet port.
 .B N
 Length of time to perform phys-id, in seconds.
 .TP
+.B \-P \-\-show-permaddr
+Queries the specified ethernet device for permanent hardware address.
+.TP
 .B \-r \-\-negotiate
 Restarts auto-negotiation on the specified ethernet device, if
 auto-negotiation is enabled.
diff --git a/ethtool.c b/ethtool.c
index 6b2b7c8..845e65d 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -51,6 +51,9 @@
 #ifndef SIOCETHTOOL
 #define SIOCETHTOOL     0x8946
 #endif
+#ifndef MAX_ADDR_LEN
+#define MAX_ADDR_LEN	32
+#endif
 #ifndef ARRAY_SIZE
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 #endif
@@ -107,6 +110,8 @@ static int do_srxfhindir(int fd, struct ifreq *ifr);
 static int do_srxntuple(int fd, struct ifreq *ifr);
 static int do_grxntuple(int fd, struct ifreq *ifr);
 static int do_flash(int fd, struct ifreq *ifr);
+static int do_permaddr(int fd, struct ifreq *ifr);
+
 static int send_ioctl(int fd, struct ifreq *ifr);
 
 static enum {
@@ -136,6 +141,7 @@ static enum {
 	MODE_SNTUPLE,
 	MODE_GNTUPLE,
 	MODE_FLASHDEV,
+	MODE_PERMADDR,
 } mode = MODE_GSET;
 
 static struct option {
@@ -247,6 +253,8 @@ static struct option {
 		"action <queue or drop>\n" },
     { "-u", "--show-ntuple", MODE_GNTUPLE,
 		"Get Rx ntuple filters and actions\n" },
+    { "-P", "--show-permaddr", MODE_PERMADDR,
+      		"Show permanent hardware address" },
     { "-h", "--help", MODE_HELP, "Show this help" },
     {}
 };
@@ -750,7 +758,8 @@ static void parse_cmdline(int argc, char **argp)
 			    (mode == MODE_SNTUPLE) ||
 			    (mode == MODE_GNTUPLE) ||
 			    (mode == MODE_PHYS_ID) ||
-			    (mode == MODE_FLASHDEV)) {
+			    (mode == MODE_FLASHDEV) |
+			    (mode == MODE_PERMADDR)) {
 				devname = argp[i];
 				break;
 			}
@@ -1868,6 +1877,8 @@ static int doit(void)
 		return do_grxntuple(fd, &ifr);
 	} else if (mode == MODE_FLASHDEV) {
 		return do_flash(fd, &ifr);
+	} else if (mode == MODE_PERMADDR) {
+		return do_permaddr(fd, &ifr);
 	}
 
 	return 69;
@@ -2950,6 +2961,29 @@ static int do_flash(int fd, struct ifreq *ifr)
 	return err;
 }
 
+static int do_permaddr(int fd, struct ifreq *ifr)
+{
+	int i, err;
+	struct ethtool_perm_addr *epaddr;
+
+	epaddr = malloc(sizeof(struct ethtool_perm_addr) + MAX_ADDR_LEN);
+	epaddr->cmd = ETHTOOL_GPERMADDR;
+	epaddr->size = MAX_ADDR_LEN;
+	ifr->ifr_data = (caddr_t)epaddr;
+
+	err = send_ioctl(fd, ifr);
+	if (err < 0)
+		perror("Cannot read permanent address\n");
+	else {
+		printf("Permanent address:");
+		for (i = 0; i < epaddr->size; i++)
+			printf("%c%02x", (i == 0) ? ' ' : ':',
+			       epaddr->data[i]);
+		printf("\n");
+	}
+	return err;
+}
+
 static int do_srxntuple(int fd, struct ifreq *ifr)
 {
 	int err;
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ethtool: add get permanent address option
  2010-10-18 18:41 [PATCH] ethtool: add get permanent address option Stephen Hemminger
@ 2010-10-18 19:52 ` Ben Hutchings
  2010-10-18 20:11   ` [PATCH] ethtool: add get permanent address option (v2) Stephen Hemminger
  0 siblings, 1 reply; 5+ messages in thread
From: Ben Hutchings @ 2010-10-18 19:52 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Jeff Garzik, netdev

On Mon, 2010-10-18 at 11:41 -0700, Stephen Hemminger wrote:
> Add command level support for showing permanent address.
> The ioctl has been around for a long time but there was
> no option to display it.
> 
> Note: MAX_ADDR_LEN is defined in netdevice.h but including
> netdevice.h leads to multiple definition errors with if.h.
[...]
> @@ -2950,6 +2961,29 @@ static int do_flash(int fd, struct ifreq *ifr)
>  	return err;
>  }
>  
> +static int do_permaddr(int fd, struct ifreq *ifr)
> +{
> +	int i, err;
> +	struct ethtool_perm_addr *epaddr;
> +
> +	epaddr = malloc(sizeof(struct ethtool_perm_addr) + MAX_ADDR_LEN);
> +	epaddr->cmd = ETHTOOL_GPERMADDR;
> +	epaddr->size = MAX_ADDR_LEN;
> +	ifr->ifr_data = (caddr_t)epaddr;
> +
> +	err = send_ioctl(fd, ifr);
> +	if (err < 0)
> +		perror("Cannot read permanent address\n");
[...]

Don't include a newline in the argument to perror().

Ben.

-- 
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] ethtool: add get permanent address option (v2)
  2010-10-18 19:52 ` Ben Hutchings
@ 2010-10-18 20:11   ` Stephen Hemminger
  2010-10-18 20:16     ` Joe Perches
  2010-11-16 23:12     ` Ben Hutchings
  0 siblings, 2 replies; 5+ messages in thread
From: Stephen Hemminger @ 2010-10-18 20:11 UTC (permalink / raw)
  To: Ben Hutchings, Jeff Garzik; +Cc: netdev

Add command level support for showing permanent address.
The ioctl has been around for a long time but there was
no option to display it.

Note: MAX_ADDR_LEN is defined in netdevice.h but including
netdevice.h leads to multiple definition errors with if.h.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

---
Fix perror(), memory leak and indenting (v2)

 ethtool.8 |    6 ++++++
 ethtool.c |   38 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 1 deletions(-)

diff --git a/ethtool.8 b/ethtool.8
index 3ca403c..84d5cc0 100644
--- a/ethtool.8
+++ b/ethtool.8
@@ -176,6 +176,9 @@ ethtool \- Display or change ethernet card settings
 .I ethX
 .RI [ N ]
 
+.B ethtool \-P|\-\-show-permaddr
+.I ethX
+
 .B ethtool \-r|\-\-negotiate
 .I ethX
 
@@ -388,6 +391,9 @@ blinking one or more LEDs on the specific ethernet port.
 .B N
 Length of time to perform phys-id, in seconds.
 .TP
+.B \-P \-\-show-permaddr
+Queries the specified ethernet device for permanent hardware address.
+.TP
 .B \-r \-\-negotiate
 Restarts auto-negotiation on the specified ethernet device, if
 auto-negotiation is enabled.
diff --git a/ethtool.c b/ethtool.c
index 6b2b7c8..1326f54 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -51,6 +51,9 @@
 #ifndef SIOCETHTOOL
 #define SIOCETHTOOL     0x8946
 #endif
+#ifndef MAX_ADDR_LEN
+#define MAX_ADDR_LEN	32
+#endif
 #ifndef ARRAY_SIZE
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 #endif
@@ -107,6 +110,8 @@ static int do_srxfhindir(int fd, struct ifreq *ifr);
 static int do_srxntuple(int fd, struct ifreq *ifr);
 static int do_grxntuple(int fd, struct ifreq *ifr);
 static int do_flash(int fd, struct ifreq *ifr);
+static int do_permaddr(int fd, struct ifreq *ifr);
+
 static int send_ioctl(int fd, struct ifreq *ifr);
 
 static enum {
@@ -136,6 +141,7 @@ static enum {
 	MODE_SNTUPLE,
 	MODE_GNTUPLE,
 	MODE_FLASHDEV,
+	MODE_PERMADDR,
 } mode = MODE_GSET;
 
 static struct option {
@@ -247,6 +253,8 @@ static struct option {
 		"action <queue or drop>\n" },
     { "-u", "--show-ntuple", MODE_GNTUPLE,
 		"Get Rx ntuple filters and actions\n" },
+    { "-P", "--show-permaddr", MODE_PERMADDR,
+		"Show permanent hardware address" },
     { "-h", "--help", MODE_HELP, "Show this help" },
     {}
 };
@@ -750,7 +758,8 @@ static void parse_cmdline(int argc, char **argp)
 			    (mode == MODE_SNTUPLE) ||
 			    (mode == MODE_GNTUPLE) ||
 			    (mode == MODE_PHYS_ID) ||
-			    (mode == MODE_FLASHDEV)) {
+			    (mode == MODE_FLASHDEV) |
+			    (mode == MODE_PERMADDR)) {
 				devname = argp[i];
 				break;
 			}
@@ -1868,6 +1877,8 @@ static int doit(void)
 		return do_grxntuple(fd, &ifr);
 	} else if (mode == MODE_FLASHDEV) {
 		return do_flash(fd, &ifr);
+	} else if (mode == MODE_PERMADDR) {
+		return do_permaddr(fd, &ifr);
 	}
 
 	return 69;
@@ -2950,6 +2961,31 @@ static int do_flash(int fd, struct ifreq *ifr)
 	return err;
 }
 
+static int do_permaddr(int fd, struct ifreq *ifr)
+{
+	int i, err;
+	struct ethtool_perm_addr *epaddr;
+
+	epaddr = malloc(sizeof(struct ethtool_perm_addr) + MAX_ADDR_LEN);
+	epaddr->cmd = ETHTOOL_GPERMADDR;
+	epaddr->size = MAX_ADDR_LEN;
+	ifr->ifr_data = (caddr_t)epaddr;
+
+	err = send_ioctl(fd, ifr);
+	if (err < 0)
+		perror("Cannot read permanent address");
+	else {
+		printf("Permanent address:");
+		for (i = 0; i < epaddr->size; i++)
+			printf("%c%02x", (i == 0) ? ' ' : ':',
+			       epaddr->data[i]);
+		printf("\n");
+	}
+	free(epaddr);
+
+	return err;
+}
+
 static int do_srxntuple(int fd, struct ifreq *ifr)
 {
 	int err;
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ethtool: add get permanent address option (v2)
  2010-10-18 20:11   ` [PATCH] ethtool: add get permanent address option (v2) Stephen Hemminger
@ 2010-10-18 20:16     ` Joe Perches
  2010-11-16 23:12     ` Ben Hutchings
  1 sibling, 0 replies; 5+ messages in thread
From: Joe Perches @ 2010-10-18 20:16 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Ben Hutchings, Jeff Garzik, netdev

On Mon, 2010-10-18 at 13:11 -0700, Stephen Hemminger wrote:
> diff --git a/ethtool.c b/ethtool.c
[]
> @@ -750,7 +758,8 @@ static void parse_cmdline(int argc, char **argp)
>  			    (mode == MODE_SNTUPLE) ||
>  			    (mode == MODE_GNTUPLE) ||
>  			    (mode == MODE_PHYS_ID) ||
> -			    (mode == MODE_FLASHDEV)) {
> +			    (mode == MODE_FLASHDEV) |
> +			    (mode == MODE_PERMADDR)) {

One more vertical bar please.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ethtool: add get permanent address option (v2)
  2010-10-18 20:11   ` [PATCH] ethtool: add get permanent address option (v2) Stephen Hemminger
  2010-10-18 20:16     ` Joe Perches
@ 2010-11-16 23:12     ` Ben Hutchings
  1 sibling, 0 replies; 5+ messages in thread
From: Ben Hutchings @ 2010-11-16 23:12 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Jeff Garzik, netdev, Joe Perches

On Mon, 2010-10-18 at 13:11 -0700, Stephen Hemminger wrote:
> Add command level support for showing permanent address.
> The ioctl has been around for a long time but there was
> no option to display it.
> 
> Note: MAX_ADDR_LEN is defined in netdevice.h but including
> netdevice.h leads to multiple definition errors with if.h.
[...]

Applied, along with the fix-up noted by Joe Perches.

Ben.

-- 
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-11-16 23:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-18 18:41 [PATCH] ethtool: add get permanent address option Stephen Hemminger
2010-10-18 19:52 ` Ben Hutchings
2010-10-18 20:11   ` [PATCH] ethtool: add get permanent address option (v2) Stephen Hemminger
2010-10-18 20:16     ` Joe Perches
2010-11-16 23:12     ` Ben Hutchings

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.