2003-01-09 19:58:15

by Eric Weigle

[permalink] [raw]
Subject: [PATCH][TRIVIAL] checksum.h header fixes for 2.4

All-

I'm making a loadable module that will send IP packets; and need to do IP
checksums. Unfortunately a simple #include of checksum.h fails because that
file does not itself include the headers required to compile correctly.
Several of the arch-specific files are this way.

* Some files use VERIFY_READ, VERIFY_WRITE, access_ok from uaccess.h but do
not include uaccess.h

* Some files have an IPv6 checksum with struct in6_addr, but do not include
linux/in6.h. x86_64 just defines the structure instead of including the
file. Either way works, but it's inconsistent. I've moved them all to the
#include, but they could all go to the struct in6_addr way too.

These need both linux/in6.h, and uaccess.h
File name VERIFY_ in6_addr | headers
asm-i386/checksum.h Y Y | -
asm-sh/checksum.h Y Y | config

These need just linux/in6.h
File name VERIFY_ in6_addr | headers
asm-mips/checksum.h N Y | uaccess
asm-mips64/checksum.h N Y | uaccess
asm-alpha/checksum.h N Y | -
asm-arm/checksum.h N Y | -
asm-m68k/checksum.h N Y | -
asm-parisc/checksum.h N Y | -
asm-x86_64/checksum.h N Y | uaccess/compiler/byteorder

The remainder are fine:
File name VERIFY_ in6_addr | headers
asm-sparc/checksum.h Y Y | uaccess/in6/cprefix
asm-sparc64/checksum.h N Y | uaccess/in6
asm-s390/checksum.h N N | uaccess
asm-s390x/checksum.h N N | uaccess
asm-cris/checksum.h N N | -
asm-ia64/checksum.h N N | -
asm-ppc/checksum.h N N | -
asm-ppc64/checksum.h N N | -

--------------------------------------------------------------------------------
--- linux/include/asm-i386/checksum.h.bak 2003-01-09 12:26:05.000000000 -0700
+++ linux/include/asm-i386/checksum.h 2003-01-09 12:52:01.000000000 -0700
@@ -1,6 +1,8 @@
#ifndef _I386_CHECKSUM_H
#define _I386_CHECKSUM_H

+#include <linux/in6.h>
+#include <asm/uaccess.h>

/*
* computes the checksum of a memory block at buff, length len,
--- linux/include/asm-sh/checksum.h.bak 2003-01-09 12:26:11.000000000 -0700
+++ linux/include/asm-sh/checksum.h 2003-01-09 12:52:02.000000000 -0700
@@ -1,6 +1,9 @@
#ifndef __ASM_SH_CHECKSUM_H
#define __ASM_SH_CHECKSUM_H

+#include <linux/in6.h>
+#include <asm/uaccess.h>
+
/*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
--- linux/include/asm-mips/checksum.h.bak 2003-01-09 12:50:34.000000000 -0700
+++ linux/include/asm-mips/checksum.h 2003-01-09 12:52:02.000000000 -0700
@@ -8,6 +8,7 @@
#ifndef _ASM_CHECKSUM_H
#define _ASM_CHECKSUM_H

+#include <linux/in6.h>
#include <asm/uaccess.h>

/*
--- linux/include/asm-mips64/checksum.h.bak 2003-01-09 12:50:34.000000000 -0700
+++ linux/include/asm-mips64/checksum.h 2003-01-09 12:52:02.000000000 -0700
@@ -11,6 +11,7 @@
#ifndef _ASM_CHECKSUM_H
#define _ASM_CHECKSUM_H

+#include <linux/in6.h>
#include <asm/uaccess.h>

/*
--- linux/include/asm-alpha/checksum.h.bak 2003-01-09 12:50:34.000000000 -0700
+++ linux/include/asm-alpha/checksum.h 2003-01-09 12:52:03.000000000 -0700
@@ -1,6 +1,7 @@
#ifndef _ALPHA_CHECKSUM_H
#define _ALPHA_CHECKSUM_H

+#include <linux/in6.h>

/*
* This is a version of ip_compute_csum() optimized for IP headers,
--- linux/include/asm-arm/checksum.h.bak 2003-01-09 12:50:34.000000000 -0700
+++ linux/include/asm-arm/checksum.h 2003-01-09 12:52:03.000000000 -0700
@@ -9,6 +9,8 @@
#ifndef __ASM_ARM_CHECKSUM_H
#define __ASM_ARM_CHECKSUM_H

+#include <linux/in6.h>
+
/*
* computes the checksum of a memory block at buff, length len,
* and adds in "sum" (32-bit)
--- linux/include/asm-m68k/checksum.h.bak 2003-01-09 12:50:34.000000000 -0700
+++ linux/include/asm-m68k/checksum.h 2003-01-09 12:52:03.000000000 -0700
@@ -1,6 +1,8 @@
#ifndef _M68K_CHECKSUM_H
#define _M68K_CHECKSUM_H

+#include <linux/in6.h>
+
/*
* computes the checksum of a memory block at buff, length len,
* and adds in "sum" (32-bit)
--- linux/include/asm-parisc/checksum.h.bak 2003-01-09 12:50:34.000000000 -0700
+++ linux/include/asm-parisc/checksum.h 2003-01-09 12:52:04.000000000 -0700
@@ -1,6 +1,8 @@
#ifndef _PARISC_CHECKSUM_H
#define _PARISC_CHECKSUM_H

+#include <linux/in6.h>
+
/*
* computes the checksum of a memory block at buff, length len,
* and adds in "sum" (32-bit)
--- ./linux/include/asm-x86_64/checksum.h.bak 2003-01-09 12:50:34.000000000 -0700
+++ ./linux/include/asm-x86_64/checksum.h 2003-01-09 12:59:58.000000000 -0700
@@ -1,6 +1,8 @@
#ifndef _X86_64_CHECKSUM_H
#define _X86_64_CHECKSUM_H

+#include <linux/in6.h>
+
/*
* Checksums for x86-64
* Copyright 2002 by Andi Kleen, SuSE Labs
@@ -171,9 +173,6 @@
* into UDP/TCP packets and contains some link layer information.
* Returns the unfolded 32bit checksum.
*/
-
-struct in6_addr;
-
#define _HAVE_ARCH_IPV6_CSUM 1
extern unsigned short
csum_ipv6_magic(struct in6_addr *saddr, struct in6_addr *daddr,
--------------------------------------------------------------------------------

Marcelo, please apply.

-Eric

--
------------------------------------------------------------
Eric H. Weigle -- http://public.lanl.gov/ehw/
"They that can give up essential liberty to obtain a little
temporary safety deserve neither" -- Benjamin Franklin
------------------------------------------------------------


2003-01-09 22:07:22

by Alan

[permalink] [raw]
Subject: Re: [PATCH][TRIVIAL] checksum.h header fixes for 2.4

On Thu, 2003-01-09 at 20:06, Eric Weigle wrote:
> I'm making a loadable module that will send IP packets; and need to do IP
> checksums. Unfortunately a simple #include of checksum.h fails because that
> file does not itself include the headers required to compile correctly.
> Several of the arch-specific files are this way.

Include the other files you need first. The kernel headers are not
really intended to always include everything you might want. That
rapidly becomes unmanagable

2003-01-09 22:44:01

by Eric Weigle

[permalink] [raw]
Subject: Re: [PATCH][TRIVIAL] checksum.h header fixes for 2.4

> On Thu, 2003-01-09 at 20:06, Eric Weigle wrote:
> > I'm making a loadable module that will send IP packets; and need to
> > do IP
> > checksums. Unfortunately a simple #include of checksum.h fails
> > because that
> > file does not itself include the headers required to compile
> > correctly.
> > Several of the arch-specific files are this way.
> Include the other files you need first. The kernel headers are not
> really intended to always include everything you might want. That
> rapidly becomes unmanagable
These files include the ipv6 and VERIFY_* stuff unconditionally. _EVERY_
caller must know to include the in6.h/uaccess.h header files simply to get
it to compile. This is what the net/checksum.h file does. There are 31 files
including <asm/checksum.h> directly, and all of these _must_ track down the
dependencies by hand.

This isn't a _want_, it's an unconditional requirement. The files are broken.

<flamebait>
Of course, it's really C's bug, by doing brain-dead textual inclusion.
Trust me, I know the difficulties in managing #includes.
</flamebait>


-Eric


--
------------------------------------------------------------
Eric H. Weigle -- http://public.lanl.gov/ehw/
"They that can give up essential liberty to obtain a little
temporary safety deserve neither" -- Benjamin Franklin
------------------------------------------------------------

2003-01-10 09:03:47

by Rusty Russell

[permalink] [raw]
Subject: Re: [PATCH][TRIVIAL] checksum.h header fixes for 2.4

In message <[email protected]> you write:
> All-
>
> I'm making a loadable module that will send IP packets; and need to do IP
> checksums. Unfortunately a simple #include of checksum.h fails because that
> file does not itself include the headers required to compile correctly.
> Several of the arch-specific files are this way.
>
> * Some files use VERIFY_READ, VERIFY_WRITE, access_ok from uaccess.h but do
> not include uaccess.h
>
> * Some files have an IPv6 checksum with struct in6_addr, but do not include
> linux/in6.h. x86_64 just defines the structure instead of including the
> file. Either way works, but it's inconsistent. I've moved them all to the
> #include, but they could all go to the struct in6_addr way too.

Two general rules I like:
1) Never include asm/xxx when there is a linux/xxx.
2) asm/ headers shouldn't include linux/ headers. It's
too easy to cause insoluble loops.

I this case, I suspect #include <net/checksum.h> is what you really
want.

Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.