netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2.6 NET] Fix ifmap alignment issues over rtnetlink
@ 2004-09-21 22:41 Thomas Graf
  2004-09-21 23:57 ` David S. Miller
  2004-09-22  2:18 ` Herbert Xu
  0 siblings, 2 replies; 6+ messages in thread
From: Thomas Graf @ 2004-09-21 22:41 UTC (permalink / raw)
  To: David S. Miller; +Cc: netdev

Introduces a fixed size variant for ifmap for rtnetlink. Fixes
issues with address size mismatch between kernel and userspace.
I couldn't find a better solution than using 64bit for memory
addresses and cast them in the kernel. Obviously this will fail
if userspace provides an address greater than 32bit.

Signed-off-by: Thomas Graf <tgraf@suug.ch>

Is it actually worth to keep trying to do this or should we just
declare that it's only possible via ethtool? Providing the
settings over rtnetlink is definitely a good thing in my eyes.

--- linux-2.6.9-rc2-bk7.orig/include/linux/rtnetlink.h	2004-09-21 23:26:54.000000000 +0200
+++ linux-2.6.9-rc2-bk7/include/linux/rtnetlink.h	2004-09-21 23:52:06.000000000 +0200
@@ -577,6 +577,17 @@
 	__u32	tx_compressed;
 };
 
+/* The struct should be in sync with struct ifmap */
+struct rtnl_link_ifmap
+{
+	__u64	mem_start;
+	__u64	mem_end;
+	__u64	base_addr;
+	__u16	irq;
+	__u8	dma;
+	__u8	port;
+};
+
 enum
 {
 	IFLA_UNSPEC,
--- linux-2.6.9-rc2-bk7.orig/net/core/rtnetlink.c	2004-09-21 23:27:28.000000000 +0200
+++ linux-2.6.9-rc2-bk7/net/core/rtnetlink.c	2004-09-22 00:27:29.000000000 +0200
@@ -182,7 +182,7 @@
 	}
 
 	if (1) {
-		struct ifmap map = {
+		struct rtnl_link_ifmap map = {
 			.mem_start   = dev->mem_start,
 			.mem_end     = dev->mem_end,
 			.base_addr   = dev->base_addr,
@@ -277,6 +277,9 @@
 		dev_change_flags(dev, ifm->ifi_flags);
 
 	if (ida[IFLA_MAP - 1]) {
+		struct rtnl_link_ifmap *u_map;
+		struct ifmap k_map;
+
 		if (!dev->set_config) {
 			err = -EOPNOTSUPP;
 			goto out;
@@ -287,11 +290,19 @@
 			goto out;
 		}
 		
-		if (ida[IFLA_MAP - 1]->rta_len != RTA_LENGTH(sizeof(struct ifmap)))
+		if (ida[IFLA_MAP - 1]->rta_len != RTA_LENGTH(sizeof(*u_map)))
 			goto out;
-		
-		err = dev->set_config(dev, (struct ifmap *)
-				RTA_DATA(ida[IFLA_MAP - 1]));
+
+		u_map = RTA_DATA(ida[IFLA_MAP - 1]);
+
+		k_map.mem_start = (unsigned long) u_map->mem_start;
+		k_map.mem_end = (unsigned long) u_map->mem_end;
+		k_map.base_addr = (unsigned short) u_map->base_addr;
+		k_map.irq = (unsigned char) u_map->irq;
+		k_map.dma = (unsigned char) u_map->dma;
+		k_map.port = (unsigned char) u_map->port;
+
+		err = dev->set_config(dev, (struct ifmap *) &k_map);
 
 		if (err)
 			goto out;

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

* Re: [PATCH 2.6 NET] Fix ifmap alignment issues over rtnetlink
  2004-09-21 22:41 [PATCH 2.6 NET] Fix ifmap alignment issues over rtnetlink Thomas Graf
@ 2004-09-21 23:57 ` David S. Miller
  2004-09-22  0:03   ` Thomas Graf
  2004-09-22  2:18 ` Herbert Xu
  1 sibling, 1 reply; 6+ messages in thread
From: David S. Miller @ 2004-09-21 23:57 UTC (permalink / raw)
  To: Thomas Graf; +Cc: netdev

On Wed, 22 Sep 2004 00:41:27 +0200
Thomas Graf <tgraf@suug.ch> wrote:

> +		k_map.mem_start = (unsigned long) u_map->mem_start;
> +		k_map.mem_end = (unsigned long) u_map->mem_end;
> +		k_map.base_addr = (unsigned short) u_map->base_addr;
> +		k_map.irq = (unsigned char) u_map->irq;
> +		k_map.dma = (unsigned char) u_map->dma;
> +		k_map.port = (unsigned char) u_map->port;

Please cast to the actual types that struct ifmap uses,
otherwise the change is OK.

Thanks for catching this.

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

* Re: [PATCH 2.6 NET] Fix ifmap alignment issues over rtnetlink
  2004-09-21 23:57 ` David S. Miller
@ 2004-09-22  0:03   ` Thomas Graf
  2004-09-22  0:21     ` David S. Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Graf @ 2004-09-22  0:03 UTC (permalink / raw)
  To: David S. Miller; +Cc: netdev

* David S. Miller <20040921165733.3e0d31d8.davem@davemloft.net> 2004-09-21 16:57
> On Wed, 22 Sep 2004 00:41:27 +0200
> Thomas Graf <tgraf@suug.ch> wrote:
> 
> > +		k_map.mem_start = (unsigned long) u_map->mem_start;
> > +		k_map.mem_end = (unsigned long) u_map->mem_end;
> > +		k_map.base_addr = (unsigned short) u_map->base_addr;
> > +		k_map.irq = (unsigned char) u_map->irq;
> > +		k_map.dma = (unsigned char) u_map->dma;
> > +		k_map.port = (unsigned char) u_map->port;
> 
> Please cast to the actual types that struct ifmap uses,
> otherwise the change is OK.

It is or am I missing something?

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

* Re: [PATCH 2.6 NET] Fix ifmap alignment issues over rtnetlink
  2004-09-22  0:03   ` Thomas Graf
@ 2004-09-22  0:21     ` David S. Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David S. Miller @ 2004-09-22  0:21 UTC (permalink / raw)
  To: Thomas Graf; +Cc: netdev

On Wed, 22 Sep 2004 02:03:25 +0200
Thomas Graf <tgraf@suug.ch> wrote:

> * David S. Miller <20040921165733.3e0d31d8.davem@davemloft.net> 2004-09-21 16:57
> > On Wed, 22 Sep 2004 00:41:27 +0200
> > Thomas Graf <tgraf@suug.ch> wrote:
> > 
> > > +		k_map.mem_start = (unsigned long) u_map->mem_start;
> > > +		k_map.mem_end = (unsigned long) u_map->mem_end;
> > > +		k_map.base_addr = (unsigned short) u_map->base_addr;
> > > +		k_map.irq = (unsigned char) u_map->irq;
> > > +		k_map.dma = (unsigned char) u_map->dma;
> > > +		k_map.port = (unsigned char) u_map->port;
> > 
> > Please cast to the actual types that struct ifmap uses,
> > otherwise the change is OK.
> 
> It is or am I missing something?

I'm retarded and I was looking at the wrong structure
definition, sorry.

Please resend your patch to me via private email and I'll
add it to my tree, thanks Thomas.

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

* Re: [PATCH 2.6 NET] Fix ifmap alignment issues over rtnetlink
  2004-09-21 22:41 [PATCH 2.6 NET] Fix ifmap alignment issues over rtnetlink Thomas Graf
  2004-09-21 23:57 ` David S. Miller
@ 2004-09-22  2:18 ` Herbert Xu
  2004-09-22  2:36   ` David S. Miller
  1 sibling, 1 reply; 6+ messages in thread
From: Herbert Xu @ 2004-09-22  2:18 UTC (permalink / raw)
  To: Thomas Graf; +Cc: davem, netdev

Thomas Graf <tgraf@suug.ch> wrote:
>
> @@ -277,6 +277,9 @@
>                dev_change_flags(dev, ifm->ifi_flags);
> 
>        if (ida[IFLA_MAP - 1]) {
> +               struct rtnl_link_ifmap *u_map;
> +               struct ifmap k_map;
> +
>                if (!dev->set_config) {
>                        err = -EOPNOTSUPP;
>                        goto out;
> @@ -287,11 +290,19 @@

<snipped>

> +               err = dev->set_config(dev, (struct ifmap *) &k_map);

What's this cast for?
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [PATCH 2.6 NET] Fix ifmap alignment issues over rtnetlink
  2004-09-22  2:18 ` Herbert Xu
@ 2004-09-22  2:36   ` David S. Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David S. Miller @ 2004-09-22  2:36 UTC (permalink / raw)
  To: Herbert Xu; +Cc: tgraf, netdev

On Wed, 22 Sep 2004 12:18:28 +1000
Herbert Xu <herbert@gondor.apana.org.au> wrote:

> > +               err = dev->set_config(dev, (struct ifmap *) &k_map);
> 
> What's this cast for?

Good catch, I deleted the cast when I applied his
patch.

Thanks Herbert.

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

end of thread, other threads:[~2004-09-22  2:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-21 22:41 [PATCH 2.6 NET] Fix ifmap alignment issues over rtnetlink Thomas Graf
2004-09-21 23:57 ` David S. Miller
2004-09-22  0:03   ` Thomas Graf
2004-09-22  0:21     ` David S. Miller
2004-09-22  2:18 ` Herbert Xu
2004-09-22  2:36   ` David S. Miller

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).