Further fix receive_packet() by using BPF_WORDALIGN to insure the offset
is properly aligned when we move to the next packet. Obtained from: ISC dhclient via krw at OpenBSD
This commit is contained in:
parent
096dd4065f
commit
289d89d80f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=148484
@ -325,7 +325,9 @@ receive_packet(struct interface_info *interface, unsigned char *buf,
|
|||||||
* do is drop it.
|
* do is drop it.
|
||||||
*/
|
*/
|
||||||
if (hdr.bh_caplen != hdr.bh_datalen) {
|
if (hdr.bh_caplen != hdr.bh_datalen) {
|
||||||
interface->rbuf_offset += hdr.bh_caplen;
|
interface->rbuf_offset =
|
||||||
|
BPF_WORDALIGN(interface->rbuf_offset +
|
||||||
|
hdr.bh_caplen);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,7 +341,9 @@ receive_packet(struct interface_info *interface, unsigned char *buf,
|
|||||||
* this packet.
|
* this packet.
|
||||||
*/
|
*/
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
interface->rbuf_offset += hdr.bh_caplen;
|
interface->rbuf_offset =
|
||||||
|
BPF_WORDALIGN(interface->rbuf_offset +
|
||||||
|
hdr.bh_caplen);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
interface->rbuf_offset += offset;
|
interface->rbuf_offset += offset;
|
||||||
@ -351,7 +355,9 @@ receive_packet(struct interface_info *interface, unsigned char *buf,
|
|||||||
|
|
||||||
/* If the IP or UDP checksum was bad, skip the packet... */
|
/* If the IP or UDP checksum was bad, skip the packet... */
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
interface->rbuf_offset += hdr.bh_caplen;
|
interface->rbuf_offset =
|
||||||
|
BPF_WORDALIGN(interface->rbuf_offset +
|
||||||
|
hdr.bh_caplen);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
interface->rbuf_offset += offset;
|
interface->rbuf_offset += offset;
|
||||||
@ -363,14 +369,18 @@ receive_packet(struct interface_info *interface, unsigned char *buf,
|
|||||||
* life, though).
|
* life, though).
|
||||||
*/
|
*/
|
||||||
if (hdr.bh_caplen > len) {
|
if (hdr.bh_caplen > len) {
|
||||||
interface->rbuf_offset += hdr.bh_caplen;
|
interface->rbuf_offset =
|
||||||
|
BPF_WORDALIGN(interface->rbuf_offset +
|
||||||
|
hdr.bh_caplen);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy out the data in the packet... */
|
/* Copy out the data in the packet... */
|
||||||
memcpy(buf, interface->rbuf + interface->rbuf_offset,
|
memcpy(buf, interface->rbuf + interface->rbuf_offset,
|
||||||
hdr.bh_caplen);
|
hdr.bh_caplen);
|
||||||
interface->rbuf_offset += hdr.bh_caplen;
|
interface->rbuf_offset =
|
||||||
|
BPF_WORDALIGN(interface->rbuf_offset +
|
||||||
|
hdr.bh_caplen);
|
||||||
return (hdr.bh_caplen);
|
return (hdr.bh_caplen);
|
||||||
} while (!length);
|
} while (!length);
|
||||||
return (0);
|
return (0);
|
||||||
|
Loading…
Reference in New Issue
Block a user