summaryrefslogtreecommitdiffstats
path: root/sys/netinet/ip_input.c
Commit message (Collapse)AuthorAgeFilesLines
* Make it so dummynet and bridge can be loaded as modules.ps2001-10-051-16/+6
| | | | Submitted by: billf
* Add a hash table that contains the list of internet addresses, and usejlemon2001-09-291-17/+30
| | | | | this in place of the in_ifaddr list when appropriate. This improves performance on hosts which have a large number of IP aliases.
* Centralize satosin(), sintosa() and ifatoia() macros in <netinet/in.h>jlemon2001-09-291-3/+1
| | | | Remove local definitions.
* Two main changes here:luigi2001-09-271-2/+2
| | | | | | | | | | | | | | | + implement "limit" rules, which permit to limit the number of sessions between certain host pairs (according to masks). These are a special type of stateful rules, which might be of interest in some cases. See the ipfw manpage for details. + merge the list pointers and ipfw rule descriptors in the kernel, so the code is smaller, faster and more readable. This patch basically consists in replacing "foo->rule->bar" with "rule->bar" all over the place. I have been willing to do this for ages! MFC after: 1 week
* Make faith loadable, unloadable, and clonable.brooks2001-09-251-7/+3
|
* Wrap array accesses in macros, which also happen to be lvalues:jlemon2001-09-061-2/+2
| | | | | | | ifnet_addrs[i - 1] -> ifaddr_byindex(i) ifindex2ifnet[i] -> ifnet_byindex(i) This is intended to ease the conversion to SMPng.
* Patches from Keiichi SHIMA <keiichi@iij.ad.jp>julian2001-09-031-9/+7
| | | | | | to make ip use the standard protosw structure again. Obtained from: Well, KAME I guess.
* When net.inet.tcp.icmp_may_rst is enabled, report ECONNREFUSED not ENETRESETjesper2001-08-271-1/+1
| | | | | | | | | | to the application as a RST would, this way we're compatible with the most applications. MFC candidate. Submitted by: Scott Renfro <scott@renfro.org> Reviewed by: Mike Silbersack <silby@silby.com>
* Add netstat(1) knob to reset net.inet.{ip|icmp|tcp|udp|igmp}.stats.ru2001-06-231-1/+1
| | | | | | For example, ``netstat -s -p ip -z'' will show and reset IP stats. PR: bin/17338
* Sync with recent KAME.ume2001-06-111-13/+53
| | | | | | | | | | | | | | | | | | This work was based on kame-20010528-freebsd43-snap.tgz and some critical problem after the snap was out were fixed. There are many many changes since last KAME merge. TODO: - The definitions of SADB_* in sys/net/pfkeyv2.h are still different from RFC2407/IANA assignment because of binary compatibility issue. It should be fixed under 5-CURRENT. - ip6po_m member of struct ip6_pktopts is no longer used. But, it is still there because of binary compatibility issue. It should be removed under 5-CURRENT. Reviewed by: itojun Obtained from: KAME MFC after: 3 weeks
* Make the default value of net.inet.ip.maxfragpackets andjesper2001-06-101-2/+3
| | | | | | | | net.inet6.ip6.maxfragpackets dependent on nmbclusters, defaulting to nmbclusters / 4 Reviewed by: bde MFC after: 1 week
* Prevent denial of service using bogus fragmented IPv4 packets.jesper2001-06-031-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | A attacker sending a lot of bogus fragmented packets to the target (with different IPv4 identification field - ip_id), may be able to put the target machine into mbuf starvation state. By setting a upper limit on the number of reassembly queues we prevent this situation. This upper limit is controlled by the new sysctl net.inet.ip.maxfragpackets which defaults to 200, as the IPv6 case, this should be sufficient for most systmes, but you might want to increase it if you have lots of TCP sessions. I'm working on making the default value dependent on nmbclusters. If you want old behaviour (no upper limit) set this sysctl to a negative value. If you don't want to accept any fragments (not recommended) set the sysctl to 0 (zero). Obtained from: NetBSD MFC after: 1 week
* Add ``options RANDOM_IP_ID'' which randomizes the ID field of IP packets.kris2001-06-011-0/+3
| | | | | | | | | This closes a minor information leak which allows a remote observer to determine the rate at which the machine is generating packets, since the default behaviour is to increment a counter for each packet sent. Reviewed by: -net Obtained from: OpenBSD
* Back out jesper's 2001/05/31 14:58:11 PDT commit. It does not compile.obrien2001-06-011-31/+0
|
* Prevent denial of service using bogus fragmented IPv4 packets.jesper2001-05-311-0/+31
| | | | | | | | | | | | | | | | | | | | | A attacker sending a lot of bogus fragmented packets to the target (with different IPv4 identification field - ip_id), may be able to put the target machine into mbuf starvation state. By setting a upper limit on the number of reassembly queues we prevent this situation. This upper limit is controlled by the new sysctl net.inet.ip.maxfragpackets which defaults to NMBCLUSTERS/4 If you want old behaviour (no upper limit) set this sysctl to a negative value. If you don't want to accept any fragments (not recommended) set the sysctl to 0 (zero) Obtained from: NetBSD (partially) MFC after: 1 week
* Invalidate cached forwarding route (ipforward_rt) whenever a new routeru2001-03-191-1/+1
| | | | | | | | is added to the routing table, otherwise we may end up using the wrong route when forwarding. PR: kern/10778 Reviewed by: silence on -net
* Make sure the cached forwarding route (ipforward_rt) is still up beforeru2001-03-181-19/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | using it. Not checking this may have caused the wrong IP address to be used when processing certain IP options (see example below). This also caused the wrong route to be passed to ip_output() when forwarding, but fortunately ip_output() is smart enough to detect this. This example demonstrates the wrong behavior of the Record Route option observed with this bug. Host ``freebsd'' is acting as the gateway for the ``sysv''. 1. On the gateway, we add the route to the destination. The new route will use the primary address of the loopback interface, 127.0.0.1: : freebsd# route add 10.0.0.66 -iface lo0 -reject : add host 10.0.0.66: gateway lo0 2. From the client, we ping the destination. We see the correct replies. Please note that this also causes the relevant route on the ``freebsd'' gateway to be cached in ipforward_rt variable: : sysv# ping -snv 10.0.0.66 : PING 10.0.0.66: 56 data bytes : ICMP Host Unreachable from gateway 192.168.0.115 : ICMP Host Unreachable from gateway 192.168.0.115 : ICMP Host Unreachable from gateway 192.168.0.115 : : ----10.0.0.66 PING Statistics---- : 3 packets transmitted, 0 packets received, 100% packet loss 3. On the gateway, we delete the route to the destination, thus making the destination reachable through the `default' route: : freebsd# route delete 10.0.0.66 : delete host 10.0.0.66 4. From the client, we ping destination again, now with the RR option turned on. The surprise here is the 127.0.0.1 in the first reply. This is caused by the bug in ip_rtaddr() not checking the cached route is still up befor use. The debug code also shows that the wrong (down) route is further passed to ip_output(). The latter detects that the route is down, and replaces the bogus route with the valid one, so we see the correct replies (192.168.0.115) on further probes: : sysv# ping -snRv 10.0.0.66 : PING 10.0.0.66: 56 data bytes : 64 bytes from 10.0.0.66: icmp_seq=0. time=10. ms : IP options: <record route> 127.0.0.1, 10.0.0.65, 10.0.0.66, : 192.168.0.65, 192.168.0.115, 192.168.0.120, : 0.0.0.0(Current), 0.0.0.0, 0.0.0.0 : 64 bytes from 10.0.0.66: icmp_seq=1. time=0. ms : IP options: <record route> 192.168.0.115, 10.0.0.65, 10.0.0.66, : 192.168.0.65, 192.168.0.115, 192.168.0.120, : 0.0.0.0(Current), 0.0.0.0, 0.0.0.0 : 64 bytes from 10.0.0.66: icmp_seq=2. time=0. ms : IP options: <record route> 192.168.0.115, 10.0.0.65, 10.0.0.66, : 192.168.0.65, 192.168.0.115, 192.168.0.120, : 0.0.0.0(Current), 0.0.0.0, 0.0.0.0 : : ----10.0.0.66 PING Statistics---- : 3 packets transmitted, 3 packets received, 0% packet loss : round-trip (ms) min/avg/max = 0/3/10
* <sys/queue.h> makeover.phk2001-03-161-33/+34
|
* It was possible for ip_forward() to supply to icmp_error()iedowse2001-03-081-7/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | an IP header with ip_len in network byte order. For certain values of ip_len, this could cause icmp_error() to write beyond the end of an mbuf, causing mbuf free-list corruption. This problem was observed during generation of ICMP redirects. We now make quite sure that the copy of the IP header kept for icmp_error() is stored in a non-shared mbuf header so that it will not be modified by ip_output(). Also: - Calculate the correct number of bytes that need to be retained for icmp_error(), instead of assuming that 64 is enough (it's not). - In icmp_error(), use m_copydata instead of bcopy() to copy from the supplied mbuf chain, in case the first 8 bytes of IP payload are not stored directly after the IP header. - Sanity-check ip_len in icmp_error(), and panic if it is less than sizeof(struct ip). Incoming packets with bad ip_len values are discarded in ip_input(), so this should only be triggered by bugs in the code, not by bad packets. This patch results from code and suggestions from Ruslan, Bosko, Jonathan Lemon and Matt Dillon, with important testing by Mike Tancsa, who could reproduce this problem at will. Reported by: Mike Tancsa <mike@sentex.net> Reviewed by: ru, bmilekic, jlemon, dillon
* Modify the comments to more closely resemble the English language.truckman2001-03-051-5/+4
|
* Move the loopback net check closer to the beginning of ip_input() so thattruckman2001-03-051-14/+26
| | | | | | | it doesn't block packets whose destination address has been translated to the loopback net by ipnat. Add warning comments about the ip_checkinterface feature.
* Disable interface checking for packets subject to "ipfw fwd".truckman2001-03-041-3/+4
| | | | Chris Johnson <cjohnson@palomine.net> tested this fix in -stable.
* Disable interface checking when IP forwarding is engaged so that packetstruckman2001-03-041-10/+45
| | | | | | | | | | | | | | | | | | | | | | | | addressed to the interface on the other side of the box follow their historical path. Explicitly block packets sent to the loopback network sent from the outside, which is consistent with the behavior of the forwarding path between interfaces as implemented in in_canforward(). Always check the arrival interface when matching the packet destination against the interface broadcast addresses. This bug allowed TCP connections to be made to the broadcast address of an interface on the far side of the system because the M_BCAST flag was not set because the packet was unicast to the interface on the near side. This was broken when the directed broadcast code was removed from revision 1.32. If the directed broadcast code was stil present, the destination would not have been recognized as local until the packet was forwarded to the output interface and ether_output() looped a copy back to ip_input() with M_BCAST set and the receive interface set to the output interface. Optimize the order of the tests. Reviewed by: jlemon
* Add a new sysctl net.inet.ip.check_interface, which will verify thatjlemon2001-03-021-1/+5
| | | | | an incoming packet arrivees on an interface that has an address matching the packet's address. This is turned on by default.
* When iterating over our list of interface addresses in order to determinejlemon2001-02-271-14/+18
| | | | | | if an arriving packet belongs to us, also check that the packet arrived through the correct interface. Skip this check if the packet was locally generated.
* Allow ICMP unreachables which map into PRC_UNREACH_ADMIN_PROHIB tojlemon2001-02-231-1/+1
| | | | | | | | | | | | | | | | reset TCP connections which are in the SYN_SENT state, if the sequence number in the echoed ICMP reply is correct. This behavior can be controlled by the sysctl net.inet.tcp.icmp_may_rst. Currently, only subtypes 2,3,10,11,12 are treated as such (port, protocol and administrative unreachables). Assocaiate an error code with these resets which is reported to the user application: ENETRESET. Disallow resetting TCP sessions which are not in a SYN_SENT state. Reviewed by: jesper, -net
* Backout change in 1.153, as it violate rfc1122 section 3.2.1.3.jesper2001-02-211-12/+1
| | | | Requested by: jlemon,ru
* Send a ICMP unreachable instead of dropping the packet silent, if wejesper2001-02-201-1/+12
| | | | | | | | receive a packet not for us, and forwarding disabled. PR: kern/24512 Reviewed by: jlemon Approved by: jlemon
* Another round of the <sys/queue.h> FOREACH transmogriffer.phk2001-02-041-2/+1
| | | | | Created with: sed(1) Reviewed by: md5(1)
* Mechanical change to use <sys/queue.h> macro API instead ofphk2001-02-041-1/+1
| | | | | | | fondling implementation details. Created with: sed(1) Reviewed by: md5(1)
* MFS: bridge/ipfw/dummynet fixes (bridge.c will be committed separately)luigi2001-02-021-2/+13
|
* Lock down the network interface queues. The queue mutex must be obtainedjlemon2000-11-251-4/+2
| | | | | | | | | | | | | | before adding/removing packets from the queue. Also, the if_obytes and if_omcasts fields should only be manipulated under protection of the mutex. IF_ENQUEUE, IF_PREPEND, and IF_DEQUEUE perform all necessary locking on the queue. An IF_LOCK macro is provided, as well as the old (mutex-less) versions of the macros in the form _IF_ENQUEUE, _IF_QFULL, for code which needs them, but their use is discouraged. Two new macros are introduced: IF_DRAIN() to drain a queue, and IF_HANDOFF, which takes care of locking/enqueue, and also statistics updating/start if necessary.
* Wrong checksum used for certain reassembled IP packets before diverting.ru2000-11-011-1/+4
|
* Convert all users of fldoff() to offsetof(). fldoff() is badphk2000-10-271-2/+0
| | | | | | | | | | | | | | | | | | | | | | | because it only takes a struct tag which makes it impossible to use unions, typedefs etc. Define __offsetof() in <machine/ansi.h> Define offsetof() in terms of __offsetof() in <stddef.h> and <sys/types.h> Remove myriad of local offsetof() definitions. Remove includes of <stddef.h> in kernel code. NB: Kernelcode should *never* include from /usr/include ! Make <sys/queue.h> include <machine/ansi.h> to avoid polluting the API. Deprecate <struct.h> with a warning. The warning turns into an error on 01-12-2000 and the file gets removed entirely on 01-01-2001. Paritials reviews by: various. Significant brucifications by: bde
* RFC 791 says that IP_RF bit should always be zero, but nothingru2000-10-261-52/+29
| | | | | | | | in the code enforces this. So, do not check for and attempt a false reassembly if only IP_RF is set. Also, removed the dead code, since we no longer use dtom() on return from ip_reass().
* Wrong header length used for certain reassembled IP packets.ru2000-10-261-2/+2
| | | | | | This was first fixed in rev 1.82 but then broken in rev 1.125. PR: 6177
* Augment the 'ifaddr' structure with a 'struct if_data' to keepjoe2000-10-191-1/+6
| | | | | | | | | | | statistics on a per network address basis. Teach the IPv4 and IPv6 input/output routines to log packets/bytes against the network address connected to the flow. Teach netstat to display the per-address stats for IP protocols when 'netstat -i' is evoked, instead of displaying the per-interface stats.
* Backout my wrong attempt to fix the compilation warning in ip_input.cru2000-10-121-1/+1
| | | | | | | | | | and instead reapply the revision 1.49 of mbuf.h, i.e. Fixed regression of the type of the `header' member of struct pkthdr from `void *' to caddr_t in rev.1.51. This mainly caused an annoying warning for compiling ip_input.c. Requested by: bde
* Fix the compilation warning.ru2000-10-121-1/+1
|
* m_cat() can free its second argument, so collect the checksum informationjlemon2000-09-141-1/+1
| | | | from the fragment before calling m_cat().
* Follow BSD/OS and NetBSD, keep the ip_id field in network order all the time.ru2000-09-141-4/+0
| | | | Requested by: wollman
* Fixed broken ICMP error generation, unified conversion of IP headerru2000-09-011-9/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fields between host and network byte order. The details: o icmp_error() now does not add IP header length. This fixes the problem when icmp_error() is called from ip_forward(). In this case the ip_len of the original IP datagram returned with ICMP error was wrong. o icmp_error() expects all three fields, ip_len, ip_id and ip_off in host byte order, so DTRT and convert these fields back to network byte order before sending a message. This fixes the problem described in PR 16240 and PR 20877 (ip_id field was returned in host byte order). o ip_ttl decrement operation in ip_forward() was moved down to make sure that it does not corrupt the copy of original IP datagram passed later to icmp_error(). o A copy of original IP datagram in ip_forward() was made a read-write, independent copy. This fixes the problem I first reported to Garrett Wollman and Bill Fenner and later put in audit trail of PR 16240: ip_output() (not always) converts fields of original datagram to network byte order, but because copy (mcopy) and its original (m) most likely share the same mbuf cluster, ip_output()'s manipulations on original also corrupted the copy. o ip_output() now expects all three fields, ip_len, ip_off and (what is significant) ip_id in host byte order. It was a headache for years that ip_id was handled differently. The only compatibility issue here is the raw IP socket interface with IP_HDRINCL socket option set and a non-zero ip_id field, but ip.4 manual page was unclear on whether in this case ip_id field should be in host or network byte order.
* Nonexistent <sys/pfil.h> -> <net/pfil.h>ache2000-07-311-1/+1
| | | | Kernel 'make depend' fails otherwise
* activate pfil_hooks and covert ipfilter to use itdarrenr2000-07-311-10/+28
|
* sync with kame tree as of july00. tons of bug fixes/improvements.itojun2000-07-041-5/+0
| | | | | | | API changes: - additional IPv6 ioctls - IPsec PF_KEY API was changed, it is mandatory to upgrade setkey(8). (also syntax change)
* Add boundary checks against IP options.jlemon2000-06-021-1/+5
| | | | Obtained from: OpenBSD
* Cast sizeof() calls to be of type (int) when they appear in a signedjlemon2000-05-171-3/+4
| | | | | | | integer expression. Otherwise the sizeof() call will force the expression to be evaluated as unsigned, which is not the intended behavior. Obtained from: NetBSD (in a different form)
* Do not call icmp_error() if ipfirewall(4) denied packet.ru2000-05-151-0/+4
| | | | PR: kern/10747, kern/18382
* correct more out-of-bounds memory access, if cnt == 1 and optlen > 1.itojun2000-05-101-0/+4
| | | | similar to recent fix to sys/netinet/ipf.c (by darren).
* Add support for offloading IP/TCP/UDP checksums to NIC hardware whichjlemon2000-03-271-3/+14
| | | | supports them.
OpenPOWER on IntegriCloud