Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Dec 2008 21:36:07 +0000
From:      Ferner Cilloniz <fernercc@gmail.com>
To:        freebsd-net@freebsd.org
Subject:   Re: kernel network
Message-ID:  <1230672967.4966.26.camel@mobiliare.Belkin>
In-Reply-To: <1230657412.4966.24.camel@mobiliare.Belkin>
References:  <1230637795.4966.20.camel@mobiliare.Belkin> <200812301905.57164.max@love2party.net> <alpine.BSF.2.00.0812301837170.40328@fledge.watson.org> <1230657412.4966.24.camel@mobiliare.Belkin>

next in thread | previous in thread | raw e-mail | index | archive | help
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@cs.utexas.edu




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1230672967.4966.26.camel>