kernel network
Gerry Weaver
gerryw at compvia.com
Wed Dec 31 05:03:23 UTC 2008
_____
From: Ferner Cilloniz [mailto:fernercc at gmail.com]
To: freebsd-net at freebsd.org
Sent: Tue, 30 Dec 2008 15:36:07 -0600
Subject: Re: kernel network
I tried another approach. The code is below. However, wireshark does not
pick up anything happening. I don't know what is going on.
static int my_udp_send(struct thread *td, void *syscall_args)
{
struct socket *sock = NULL;
if( socreate(AF_INET, &sock, SOCK_DGRAM, 0, td->td_proc->p_ucred,
td) != 0 ) {
uprintf("socreate() returned error\n");
return -1;
}
struct sockaddr_in sin;
sin.sin_len = sizeof(struct sockaddr_in);
sin.sin_family = AF_INET;
sin.sin_port = htons(8080);
inet_aton("192.168.2.2", &sin.sin_addr);
struct mbuf *top = m_getclr(M_TRYWAIT, MT_CONTROL);
// IP is 0
int sosend_error = sosend(sock, (struct sockaddr *)&sin, NULL, top,
NULL, 0, td);
uprintf("sosend(): %d\n", sosend_error);
soclose(sock);
return 0;
}
On Tue, 2008-12-30 at 17:16 +0000, Ferner Cilloniz wrote:
> I have been tackling this today. This is what i have so far:
>
> -------------------------------------------------------------------------
> static int my_udp_send(struct thread *td, void *syscall_args)
> {
> struct socket *sock = NULL;
>
> if( socreate(AF_INET, &sock, SOCK_DGRAM, 0, td->td_proc->p_ucred,
> td) != 0 ) {
> uprintf("socreate() returned error\n");
> return -1;
> }
>
> struct sockaddr sa;
> sa.sa_len = sizeof(struct sockaddr_in);
>
> struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
> sin->sin_family = AF_INET;
> inet_aton("192.168.2.2", (struct sockaddr_in *)&sin->sin_addr);
> sin->sin_port = htons(8080);
> sin->sin_len = sizeof(*sin);
> memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
>
> // int soconnect_error = soconnect(sock, (struct sockaddr *)sin, td);
> // uprintf("soconnect(): %d\n", soconnect_error);
>
> struct mbuf *top = m_getclr(M_TRYWAIT, MT_CONTROL);
>
> // IP is 0
> int sosend_error = sosend(sock, (struct sockaddr *)sin, NULL, top,
> NULL, 0, td);
> uprintf("sosend(): %d\n", sosend_error);
>
> soclose(sock);
>
> return 0;
> }
> -------------------------------------------------------------------------
>
>
> However, when listening to my home network using wireshark, I filter out
> everything but UDP packets with the 192.168.2.2 address on them. I'm
> afraid to say that there aren't any packets showing.
>
> Am i doing something wrong? Note, that I am not filling in the mbuf and
> all the wacking casting done.
>
> Thanks.
>
> On Tue, 2008-12-30 at 18:46 +0000, Robert Watson wrote:
> > On Tue, 30 Dec 2008, Max Laier wrote:
> >
> > > On Tuesday 30 December 2008 12:49:55 Ferner Cilloniz wrote:
> > >
> > >> I do not think I could ever be more tired of this topic but I cannot seem
> > >> to understand what to do. I have tried more about a month now to send
> > >> arbitrary UDP packets from a kernel module but cannot achieve it. I have
> > >> looked at udp_send but found that building a socket* was much to tedious.
> > >> Later i looked at in-kernel webservers (http://openketa.sourceforge.net/)
> > >> but could not find anything useful.
> > >>
> > >> Netgraph is a possibility, but there isn't any documentation on accessing
> > >> the network from kernel space.
> > >>
> > >> What do you all suggest?
> > >
> > > $ man 9 socket
> >
> > Definitely the preferred solution, if it meets the application model. Call
> > socreate(9) to allocate the socket, sobind(9) if required, calls to sosend(9)
> > to generate packets, and soclose(9) when done. Direct calls to the
> > udp_output() and udp_send() functions won't work without a socket context, and
> > doing sosend(9) will isolate in-kernel consumers from future changes in UDP
> > internals. ip_output() could be invoked directly to generate IP packets, but
> > won't allow you to easily receive replies, etc.
> >
> > Robert N M Watson
> > Computer Laboratory
> > University of Cambridge
--
Cilloniz Bicchi, Ferner
Research Assistant
Dept. of Computer Sciences
The University of Texas at Austin
http://www.cs.utexas.edu/~fernercc
fernercc at cs.utexas.edu
_______________________________________________
freebsd-net at freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscribe at freebsd.org"Hello Ferner,
I believe you need a packet header in your mbuf. Try m_gethdr instead of
m_getclr.
Thanks,
Gerry
More information about the freebsd-net
mailing list