Commit Graph

1081 Commits

Author SHA1 Message Date
joerg
db0043926a Provide a simplified inplace version of in6_cksum.
Tested by is@ on amd64.
2008-02-12 13:02:24 +00:00
bjs
5fb9f423de ip_newid() -> ip_newid(NULL) due to Matt Thomas' commit some hours ago;
The function now requires a pointer (to struct in_ifaddr) as an argument,
i.e. it is no longer ip_newid(void).

Fixes ipsec+inet6 kernel builds.
2008-02-06 07:42:43 +00:00
joerg
6e869e402d Refactor in_cksum/in4_cksum/in6_cksum implementations:
- All three functions are included in the kernel by default.
  They call a backend function cpu_in_cksum after possibly
  computing the checksum of the pseudo header.
- cpu_in_cksum is the core to implement the one-complement sum.
  The default implementation is moderate fast on most platforms
  and provides a 32bit accumulator with 16bit addends for L32 platforms
  and a 64bit accumulator with 32bit addends for L64 platforms.
  It handles edge cases like very large mbuf chains (could happen with
  native IPv6 in the future) and provides a good base for new native
  implementations.
- Modify i386 and amd64 assembly to use the new interface.

This disables the MD implementations on !x86 until the conversion is
done. For Alpha, the portable version is faster.
2008-01-25 21:12:10 +00:00
dyoung
19dd9ed4a7 Use rtcache_validate() instead of rtcache_getrt(). Shorten staircase
in in6_losing().
2008-01-14 04:16:45 +00:00
dyoung
6a0b0c88d2 Use rtcache_lookup() instead of rtcache_lookup() + rtcache_getrt(). 2008-01-14 04:14:37 +00:00
dyoung
1386ee4adf Good-bye, rtcache_check(). Call both rtcache_validate() and
rtcache_update(,1) instead of rtcache_check().
2008-01-12 02:58:58 +00:00
dyoung
45485bd0b7 Save some rtcache_getrt() calls. 2008-01-10 08:06:11 +00:00
dyoung
1c6cf449e1 Constify. 2008-01-04 23:35:00 +00:00
dyoung
a4455600d4 Replace rtcache_down() with rtcache_validate() and update rtcache_down()
uses.
2008-01-04 23:26:44 +00:00
perry
b6a2ef7569 Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
2007-12-25 18:33:32 +00:00
dyoung
72fa642a86 Poison struct route->ro_rt uses in the kernel by changing the name
to _ro_rt.  Use rtcache_getrt() to access a route cache's struct
rtentry *.

Introduce struct ifnet->if_dl that always points at the interface
identifier/link-layer address.  Make code that treated the first
ifaddr on struct ifnet->if_addrlist as the interface address use
if_dl, instead.

Remove stale debugging code from net/route.c.  Move the rtflush()
code into rtcache_clear() and delete rtflush().  Delete rtalloc(),
because nothing uses it any more.

Make ND6_HINT an inline, lowercase subroutine, nd6_hint.

I've done my best to convert IP Filter, the ISO stack, and the
AppleTalk stack to rtcache_getrt().  They compile, but I have not
tested them.  I have given the changes to PF, GRE, IPv4 and IPv6
stacks a lot of exercise.
2007-12-20 19:53:29 +00:00
lukem
456279df8f use __KERNEL_RCSID() 2007-12-11 12:29:11 +00:00
degroote
939a0dbd0a Kill _IP_VHL ifdef (from netinet/ip.h history, it has never been used in NetBSD so ...) 2007-12-09 18:27:39 +00:00
dyoung
b579a81e92 Use ifa_insert(), ifa_remove(). 2007-12-06 00:28:36 +00:00
dyoung
b8f324fabd Extract common code, creating a subroutine if_purgeaddrs(ifp,
family, purgeaddr) which applies function `purgeaddr' to each
address on `ifp' belonging to `family'.
2007-12-05 23:47:17 +00:00
dyoung
b039c2dbef Use IFADDR_FIRST(), IFADDR_NEXT(). 2007-12-05 23:00:58 +00:00
dyoung
8e3ac3ec9f Use IFADDR_FOREACH(). 2007-12-05 01:17:16 +00:00
dyoung
5bbde3d775 Use IFNET_FOREACH() and IFADDR_FOREACH(). 2007-12-04 10:27:33 +00:00
christos
a9c710744b require that the options argument is the right size, not that it is greater
or equal to the requested size. Suggested by Matt Thomas.
2007-11-27 22:45:29 +00:00
yamt
5e36d79445 in6_pcbsetport: add missing htons. (fixes ephemeral port allocation.) 2007-11-26 08:12:33 +00:00
drochner
e3e9b75351 Fix in6_pcbrtentry() for the case of IPv6-mapped IPv4 addresses:
don't assume that the cached route is a sockaddr_in6, and do the
right comparisions so that no out-of-bounds memory is accessed.

btw, the use of "#ifdef INET" throughout the source doesn't look clean
to me: There are 2 cases -- whether AF_INET is usable by userland
programs, and whether IPv4 is supported as on-wire protocol.
2007-11-21 21:18:25 +00:00
dyoung
777dd06a99 We might leave nd6_ns_output() really early. Postpone memset()
until after we decide to stay.
2007-11-16 17:51:51 +00:00
dyoung
9044dcac49 Note danger of dangling pointers. 2007-11-16 17:50:07 +00:00
dyoung
c03a973fd0 KNF. Remove superfluous parentheses. In the switch-statement,
consolidate all of the 'error = EOPNOTSUPP;' cases.  No functional
change intended.
2007-11-14 22:58:27 +00:00
dyoung
5121052595 Use sockaddr_in6_init(). 2007-11-10 00:14:31 +00:00
dyoung
c44fbd164e Use sockaddr_in6_init(). Use a static initializer for all1_sa.
Constify a cast (may as well).  No functional change intended.
2007-11-10 00:07:57 +00:00
dyoung
db42e9d78b Use sockaddr_in6_init(). 2007-11-10 00:05:57 +00:00
dyoung
6c2f73d13c Delete dead code that I accidentally introduced before. Thanks
Arnaud Lacombe for pointing out to me Coverity CID 4562.
2007-11-06 23:50:41 +00:00
dyoung
b47fb23dd2 Use sockaddr_in6_init(). 2007-11-06 23:48:24 +00:00
dyoung
2bc0ce1e9b Take a clue from udp_usrreq(): block IPL_SOFTNET in udp6_usrreq(),
both while we purge an interface, and while we call udp6_output().

XXX udp6_usrreq() needs more attention.
2007-11-06 23:47:08 +00:00
dyoung
cfeb7f085e Use sockaddr_in6_init(). 2007-11-06 23:40:38 +00:00
dyoung
122b86e247 De-__P(). 2007-11-01 20:33:56 +00:00
dyoung
6cc9c359e3 De-__P(). frag6.c has always defined IN6_IFSTAT_STRICT, so remove
the definition and trim to the defined(IN6_IFSTAT_STRICT) code.
No functional change intended.
2007-11-01 20:33:00 +00:00
dyoung
6709ce7762 The IPv6 stack labels incoming packets with an m_tag whose payload
is a struct ip6aux.  A struct ip6aux used to contain a pointer to
an in6_ifaddr, but that pointer could become a dangling reference
in the lifetime of the m_tag, because ip6_setdstifaddr() did not
increase the in6_ifaddr's reference count.  I have removed the
pointer from ip6aux.  I load it with the interesting fields from
the in6_ifaddr (an IPv6 address, a scope ID, and some flags),
instead.
2007-10-29 16:54:42 +00:00
dyoung
d072fd0fb9 Replace rote sockaddr_in6 initializations (memset(), set sa6_family,
sa6_len, and sa6_add) with sockaddr_in6_init() calls.

De-__P().  Constify.  KNF.  Shorten a staircase.  Change bcmp() to
memcmp().

Extract subroutine in6_setzoneid() from in6_setscope(), for re-use
soon.
2007-10-24 06:37:20 +00:00
ad
a2a3828545 machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h 2007-10-19 11:59:34 +00:00
jld
5f139070d1 If callout_t is to be used, then <sys/callout.h> should be included.
Fixes the build of ifconfig(8), which failed otherwise.
2007-10-17 04:35:34 +00:00
joerg
1e1c64c041 Inline callout_t in struct in6_multi. This fixes a number of possible
memory leaks. Explicitly destroy the callout before freeing it.
Use callout_setfunc/callout_schedule instead of repeating it for
callout_reset.

Bump NetBSD version to 4.99.34 for kvm users.
2007-10-16 20:31:33 +00:00
joerg
4680156428 NetBSD doesn't have to care about missing bcmp on OpenBSD/SPARC,
just use memcmp in both kernel and userland.
2007-10-07 12:43:18 +00:00
degroote
7001a7668d {ah,esp,ipcomp}_output must return 0 on success. On failure, it returns the
error and m is freed. Previously, it was not the case in ipcomp and esp case
(aka in some case, it returns 0 with m freed, or an error and m was not freed).

In ipcomp_output, fix some leak of mcopy too.

Use the same error path in {ah,esp,ipcomp}_output.

Problem was reported by Wolfgang Stukenbrock in pr/36768.
2007-09-22 11:32:06 +00:00
degroote
78fb2c5288 In the IPSEC_NAT_T case, we must set the udp length even if the ESP entry
doesn't have an integrity algorithm.

Reported by Wolfgang Stukenbrock in pr/36781 . Thanks you a lot.
2007-09-21 21:23:59 +00:00
dyoung
4c9b6756a5 1) Introduce a new socket option, (SOL_SOCKET, SO_NOHEADER), that
tells a socket that it should both add a protocol header to tx'd
   datagrams and remove the header from rx'd datagrams:

        int onoff = 1, s = socket(...);
        setsockopt(s, SOL_SOCKET, SO_NOHEADER, &onoff);

2) Add an implementation of (SOL_SOCKET, SO_NOHEADER) for raw IPv4
   sockets.

3) Reorganize the protocols' pr_ctloutput implementations a bit.
   Consistently return ENOPROTOOPT when an option is unsupported,
   and EINVAL if a supported option's arguments are incorrect.
   Reorganize the flow of code so that it's more clear how/when
   options are passed down the stack until they are handled.

   Shorten some pr_ctloutput staircases for readability.

4) Extract common mbuf code into subroutines, add new sockaddr
   methods, and introduce a new subroutine, fsocreate(), for reuse
   later; use it first in sys_socket():

struct mbuf *m_getsombuf(struct socket *so)

        Create an mbuf and make its owner the socket `so'.

struct mbuf *m_intopt(struct socket *so, int val)

        Create an mbuf, make its owner the socket `so', put the
        int `val' into it, and set its length to sizeof(int).


int fsocreate(..., int *fd)

        Create a socket, a la socreate(9), put the socket into the
        given LWP's descriptor table, return the descriptor at `fd'
        on success.

void *sockaddr_addr(struct sockaddr *sa, socklen_t *slenp)
const void *sockaddr_const_addr(const struct sockaddr *sa, socklen_t *slenp)

        Extract a pointer to the address part of a sockaddr.  Write
        the length of the address  part at `slenp', if `slenp' is
        not NULL.

socklen_t sockaddr_getlen(const struct sockaddr *sa)

        Return the length of a sockaddr.  This just evaluates to
        sa->sa_len.  I only add this for consistency with code that
        appears in a portable userland library that I am going to
        import.

const struct sockaddr *sockaddr_any(const struct sockaddr *sa)

        Return the "don't care" sockaddr in the same family as
        `sa'.  This is the address a client should sobind(9) if it
        does not care the source address and, if applicable, the
        port et cetera that it uses.

const void *sockaddr_anyaddr(const struct sockaddr *sa, socklen_t *slenp)

        Return the "don't care" sockaddr in the same family as
        `sa'.  This is the address a client should sobind(9) if it
        does not care the source address and, if applicable, the
        port et cetera that it uses.
2007-09-19 04:33:42 +00:00
dyoung
6418bbd280 Cosmetic: shorten staircase. 2007-09-16 18:01:30 +00:00
gdt
8f7e0bd6a5 Remove SIOCSIFALIFETIME_IN6, which could not possibly have ever worked.
Problem reported in kern/35897 by Robert Elz.
2007-09-11 19:54:51 +00:00
degroote
640e23d7c9 In some FAST_IPSEC, spl level is not restored correctly. Fix that.
Spotted by Wolfgang Stukenbrock in pr/36800
2007-09-11 14:18:09 +00:00
dyoung
88399b6877 We cannot sleep in a software interrupt, so do not sockaddr_dl_alloc(...,
M_WAITOK).  Instead, sockaddr_dl_init() a sockaddr_dl on the stack.
2007-09-02 19:42:21 +00:00
dyoung
c2a1a6621f Use sockaddr_in6_init(). 2007-08-31 21:40:41 +00:00
dyoung
b3fc296326 Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain.  Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.

Return sockaddr_dl to its "historical" size.  Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.

Avoid using sizeof(struct sockaddr_dl) in the kernel.

Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.

Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().

Constify: LLADDR() -> CLLADDR().

Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead.  Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 02:17:34 +00:00
dyoung
5204966a96 Constify: LLADDR -> CLLADDR. I'm aiming here to make it easier to
identify sockaddr_dl abuse that remains in the kernel, especially
the potential for overwriting memory past the end of a sockaddr_dl
with, e.g., memcpy(LLADDR(), ...).

Use sockaddr_dl_setaddr() in a few places.
2007-08-26 22:59:08 +00:00
dyoung
bd98464c6f Don't call rtcache_check() from the fast-forward code, which runs
at IPL_NET, because rtcache_check() may read the forwarding table.
Elsewhere, the kernel only blocks interrupts at priority IPL_SOFTNET
and below while it modifies the forwarding table, so rtcache_check()
could be reading the table in an inconsistent state.  Use
rtcache_done(), instead.

XXX netinet/ip_flow.c and netinet6/ip6_flow.c are virtually identical.
XXX They should share code.
2007-08-20 19:42:34 +00:00