af-packet: parse message to find lack of checksum

Emitted packet can have checksum offloading. This patch reads
af-packet message parameter to see if the kernel has sent a non
checksummed packet.
remotes/origin/master-1.2.x
Eric Leblond 14 years ago committed by Victor Julien
parent 5dc46ae7c7
commit f6ddaf3341

@ -228,22 +228,18 @@ int AFPRead(AFPThreadVars *ptv)
struct sockaddr_ll from;
struct iovec iov;
struct msghdr msg;
#if 0
struct cmsghdr *cmsg;
union {
struct cmsghdr cmsg;
char buf[CMSG_SPACE(sizeof(struct tpacket_auxdata))];
} cmsg_buf;
#endif
msg.msg_name = &from;
msg.msg_namelen = sizeof(from);
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
#if 0
msg.msg_control = &cmsg_buf;
msg.msg_controllen = sizeof(cmsg_buf);
#endif
msg.msg_flags = 0;
if (ptv->cooked)
@ -293,6 +289,21 @@ int AFPRead(AFPThreadVars *ptv)
SCLogDebug("pktlen: %" PRIu32 " (pkt %p, pkt data %p)",
GET_PKT_LEN(p), p, GET_PKT_DATA(p));
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
struct tpacket_auxdata *aux;
if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct tpacket_auxdata)) ||
cmsg->cmsg_level != SOL_PACKET ||
cmsg->cmsg_type != PACKET_AUXDATA)
continue;
aux = (struct tpacket_auxdata *)CMSG_DATA(cmsg);
if (aux->tp_status & TP_STATUS_CSUMNOTREADY) {
p->flags |= PKT_IGNORE_CHECKSUM;
}
}
if (TmThreadsSlotProcessPkt(ptv->tv, ptv->slot, p) != TM_ECODE_OK) {
TmqhOutputPacketpool(ptv->tv, p);
SCReturnInt(AFP_FAILURE);
@ -510,6 +521,15 @@ static int AFPCreateSocket(AFPThreadVars *ptv, char *devname, int verbose)
return -1;
}
}
{ int val = 1;
if (setsockopt(ptv->socket, SOL_PACKET, PACKET_AUXDATA, &val,
sizeof(val)) == -1 && errno != ENOPROTOOPT) {
/* FIXME */
return -1;
}
}
/* set socket recv buffer size */
if (ptv->buffer_size != 0) {
/*

Loading…
Cancel
Save