/* * Mausezahn - A fast versatile traffic generator * Copyright (C) 2008-2010 Herbert Haas * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 2 as published by the * Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html * */ #include "mz.h" #include "mops.h" // -- TOC: -- // // u_int16_t mops_sum16 (u_int16_t len, u_int8_t buff[]) // int mops_get_transport_sum (struct mops *mp) ////////////////////////////////////////////////////////////////////////////////// // // See also: // // RFC1071 - Computing the Internet checksum // ////////////////////////////////////////////////////////////////////////////////// // Generic 16-bit checksum code as required for IP and other headers. // The checksum is calculated over buff[] which is of length len. // // RETURN VALUE: The checksum! (Validated - correct!!!) // // Example: t16 = mops_sum16 (20, &mp->frame[fp]); // u_int16_t mops_sum16 (u_int16_t len, u_int8_t buff[]) { u_int16_t word16; u_int32_t sum=0; u_int16_t i; // make 16 bit words out of every two adjacent 8 bit words in the packet and add them up for (i=0; i>16) sum = (sum & 0xFFFF)+(sum >> 16); // one's complement the result sum = ~sum; return ((u_int16_t) sum); } // sets UDP or TCP checksum within mp[]->frame // TODO: copying the whole segment is ugly and slow; // make it more efficient and realize it in-place. // int mops_get_transport_sum(struct mops *mp) { u_int8_t buf[MAX_PAYLOAD_SIZE]; u_int16_t len; int udp_used; u_int16_t sum; udp_used = mp->use_UDP; // 0 or 1, 0 means TCP // IP Pseudoheader (12 Bytes) mops_hton4(&mp->ip_src, &buf[0]); mops_hton4(&mp->ip_dst, &buf[4]); buf[9]=0x00; // Copy segment if (udp_used) { buf[10]=0x11; // proto UDP (17 dec) len = mp->udp_len; mops_hton2(&len, &buf[11]); memcpy(&buf[13], &mp->frame[mp->begin_UDP], len); // reset checksum to zero buf[19] = 0x00; buf[20] = 0x00; sum = mops_sum16(len+12, buf); // insert checksum in UDP header (in frame) mops_hton2 (&sum, &mp->frame[(mp->begin_UDP)+7]); } else { buf[10]=0x06; // proto TCP len = mp->ip_len - mp->ip_IHL; mops_hton2((u_int16_t*)&len, &buf[11]); memcpy(&buf[13], &mp->frame[mp->begin_TCP], len); // reset checksum to zero buf[29] = 0x00; buf[30] = 0x00; sum = mops_sum16(len+12, buf); // insert checksum in TCP header (in frame) mops_hton2 (&sum, &mp->frame[(mp->begin_TCP)+17]); } return 0; } ion>space:mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-05-24 12:55:26 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-24 12:55:26 -0700
commit0e01df100b6bf22a1de61b66657502a6454153c5 (patch)
treeaae8f9787efc3014696b3e5ae854c1cf9e472bdd
parenta56f489502e28caac56c8a0735549740f0ae0711 (diff)
parent12735f881952c32b31bc4e433768f18489f79ec9 (diff)
Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
Pull ext4 updates from Ted Ts'o: "Fix a number of bugs, most notably a potential stale data exposure after a crash and a potential BUG_ON crash if a file has the data journalling flag enabled while it has dirty delayed allocation blocks that haven't been written yet. Also fix a potential crash in the new project quota code and a maliciously corrupted file system. In addition, fix some DAX-specific bugs, including when there is a transient ENOSPC situation and races between writes via direct I/O and an mmap'ed segment that could lead to lost I/O. Finally the usual set of miscellaneous cleanups" * tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (23 commits) ext4: pre-zero allocated blocks for DAX IO ext4: refactor direct IO code ext4: fix race in transient ENOSPC detection ext4: handle transient ENOSPC properly for DAX dax: call get_blocks() with create == 1 for write faults to unwritten extents ext4: remove unmeetable inconsisteny check from ext4_find_extent() jbd2: remove excess descriptions for handle_s ext4: remove unnecessary bio get/put ext4: silence UBSAN in ext4_mb_init() ext4: address UBSAN warning in mb_find_order_for_block() ext4: fix oops on corrupted filesystem ext4: fix check of dqget() return value in ext4_ioctl_setproject() ext4: clean up error handling when orphan list is corrupted ext4: fix hang when processing corrupted orphaned inode list ext4: remove trailing \n from ext4_warning/ext4_error calls ext4: fix races between changing inode journal mode and ext4_writepages ext4: handle unwritten or delalloc buffers before enabling data journaling ext4: fix jbd2 handle extension in ext4_ext_truncate_extend_restart() ext4: do not ask jbd2 to write data for delalloc buffers jbd2: add support for avoiding data writes during transaction commits ...
Diffstat