Subject: Re: sending IPv6 packets via kern_sendmsg

From: Roar Bjørgum Rotvik <[email-masked]>
Date: Wed, 06 Jun 2007 08:44:10 +0200

Anton wrote:
> Hi,
> 
> Following on from a previous (now lost :-)) posting, I have been trying 
> to send out IPv6 packets from a kernel module using the kern_sendmsg() 
> function. Since in theory I need this function to be started in 
> interrupt context (actually, softirq context), but since this is 
> impossible because kern_sendmsg() needs to sleep, I have created a work 
> queue which calls the kern_sendmsg() function separately. The work queue 
> is scheduled from the softirq context (actually, at the moment this 
> happens from a Netfilter hook). The work queue function creates a msghdr 
> structure, fills in a sin6_addr structure, calls sock_create_kern() and 
> then uses this socket to send an IPv6 packet, which consists of a header 
> (struct ipv6hdr *iphdr) and some data following on from this. The above 
> packet is placed in the msghdr structure by setting (after the 
> appropriate initializations):
> msg.msg_iov->iov_base = (char *) ip6hdr;
> msg.msg_iov->iov_len = sizeof( struct ipv6hdr + ntohs( 
> ip6hdr->payload_len ) );

Shouldn't this be:
msg.msg_iov->iov_len = sizeof (struct ipv6hdr) + ntohs (ip6hdr->payload_len);

Seems you use sizeof (nthos (...)), and that seems wrong.

-- 
Roar B. Rotvik