* sending IPv6 packets via kern_sendmsg
@ 2007-06-06 4:23 Anton
2007-06-06 6:44 ` Roar Bjørgum Rotvik
0 siblings, 1 reply; 2+ messages in thread
From: Anton @ 2007-06-06 4:23 UTC (permalink / raw)
To: netdev
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 ) );
msg.msg_iovlen = 1;
msg.msg_name = &sin6addr;
msg.msg_namelen = sizeof( struct sin6_addr );
However, when trying to send this using kern_sendmsg() (or even
sock_sendmsg()) to perform the send operation, I get an error (-22 -
EINVAL), which, according to the user-space sendmsg(), corresponds to:
"The sum of the iov_len values overflows an ssize_t. "
Certainly this is not the case, since the packet in question is an
ICMPv6 ping packet whose header size and data would rarely exceed 100
bytes.
The test is being run on kernel 2.6.18.
From what I have read on the internet, in books and in a previous
suggestion from the netdev mailing-list, the use of kern_sendmsg() seems
to be the appropriate way of sending packets from a kernel module. Am I
doing something incorrectly above, or should I be using some other
function instead of kern_sendmsg() (or sock_sendmsg())?
I would appreciate any ideas.
Regards,
Anton
IMPORTANT: This email remains the property of the Australian Defence Organisation and is subject to the jurisdiction of section 70 of the CRIMES ACT 1914. If you have received this email in error, you are requested to contact the sender and delete the email.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: sending IPv6 packets via kern_sendmsg
2007-06-06 4:23 sending IPv6 packets via kern_sendmsg Anton
@ 2007-06-06 6:44 ` Roar Bjørgum Rotvik
0 siblings, 0 replies; 2+ messages in thread
From: Roar Bjørgum Rotvik @ 2007-06-06 6:44 UTC (permalink / raw)
To: Anton; +Cc: netdev
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-06-06 7:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-06 4:23 sending IPv6 packets via kern_sendmsg Anton
2007-06-06 6:44 ` Roar Bjørgum Rotvik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).