From owner-freebsd-net@FreeBSD.ORG Wed Dec 31 06:06:55 2008 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E1150106566C for ; Wed, 31 Dec 2008 06:06:54 +0000 (UTC) (envelope-from fernercc@gmail.com) Received: from yw-out-2324.google.com (yw-out-2324.google.com [74.125.46.29]) by mx1.freebsd.org (Postfix) with ESMTP id 985848FC1A for ; Wed, 31 Dec 2008 06:06:54 +0000 (UTC) (envelope-from fernercc@gmail.com) Received: by yw-out-2324.google.com with SMTP id 9so2600244ywe.13 for ; Tue, 30 Dec 2008 22:06:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:cc :in-reply-to:references:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; bh=+5xnjxL6rQNhDGUDysLhUsWFmKx3VxHV+pJ8T89YK/A=; b=O6Nd+3QDhTN+EskwhJEILFCXaQ3ccq5jbHasxJ9o2vD/WUaBWrxp/WHgvUiaVpj7wo FuHkNau+SNMpCEm8UIVGPezK5EOvt89k8gAkRKdF/RdTbCrKESIO64uKOGPkvrTShfla f283kvHEXJrFgAIKgfzriyedkBYRI+dJU6OWw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding; b=Bkr3AXm+XLsOecHTcPMQVlBtvOVvYp5l4m5SLHjq83H8YjbzQGQ/PhX+n+qilAao3T FzpR7GV6tA606GH5Tdmf3j/R6NQHoAfIVBdgc5gvhbW+snTZcbbTqwN7rR8NbwWMp7ly 1A85ihJO2Di9dIMLPYT6kSTuvfY2GqfrSJpbk= Received: by 10.100.191.9 with SMTP id o9mr8774929anf.63.1230703613278; Tue, 30 Dec 2008 22:06:53 -0800 (PST) Received: from ?192.168.2.2? (cpe-70-112-179-136.austin.res.rr.com [70.112.179.136]) by mx.google.com with ESMTPS id c28sm20891128anc.47.2008.12.30.22.06.52 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 30 Dec 2008 22:06:52 -0800 (PST) From: Ferner Cilloniz To: Gerry Weaver In-Reply-To: <20081231050318.616ef838@mail01.compvia.com> References: <20081231050318.616ef838@mail01.compvia.com> Content-Type: text/plain Date: Wed, 31 Dec 2008 00:06:50 +0000 Message-Id: <1230682010.4966.27.camel@mobiliare.Belkin> Mime-Version: 1.0 X-Mailer: Evolution 2.24.2 Content-Transfer-Encoding: 7bit Cc: freebsd-net@freebsd.org Subject: Re: kernel network X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Dec 2008 06:06:56 -0000 Thanks! That solved it. On Tue, 2008-12-30 at 23:03 -0600, Gerry Weaver wrote: > > ______________________________________________________________ > From: Ferner Cilloniz [mailto:fernercc@gmail.com] > To: freebsd-net@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@cs.utexas.edu > > _______________________________________________ > freebsd-net@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-net > To unsubscribe, send any mail to > "freebsd-net-unsubscribe@freebsd.org" > Hello Ferner, > > I believe you need a packet header in your mbuf. Try m_gethdr instead > of > m_getclr. > > Thanks, > Gerry -- 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