From owner-freebsd-net@FreeBSD.ORG Wed Dec 31 05:03:22 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 EB9E5106564A for ; Wed, 31 Dec 2008 05:03:22 +0000 (UTC) (envelope-from gerryw@compvia.com) Received: from mail01.compvia.com (mail01.compvia.com [12.147.132.91]) by mx1.freebsd.org (Postfix) with ESMTP id A877A8FC14 for ; Wed, 31 Dec 2008 05:03:22 +0000 (UTC) (envelope-from gerryw@compvia.com) Received: from [10.10.20.11] ([10.10.20.11]) by mail01.compvia.com (Kerio MailServer 6.5.1); Tue, 30 Dec 2008 23:03:18 -0600 To: "Ferner Cilloniz" , freebsd-net@freebsd.org From: "Gerry Weaver" In-Reply-To: 1230672967.4966.26.camel@mobiliare.Belkin Message-ID: <20081231050318.616ef838@mail01.compvia.com> Date: Tue, 30 Dec 2008 23:03:18 -0600 X-Mailer: Kerio MailServer 6.5.1 WebMail X-User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1b1) Gecko/20081007 Firefox/3.1b1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: 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 05:03:23 -0000 =5F=5F=5F=5F=5F =20 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. =20 static int my=5Fudp=5Fsend(struct thread *td, void *syscall=5Fargs) { struct socket *sock =3D NULL; =20 if( socreate(AF=5FINET, &sock, SOCK=5FDGRAM, 0, td->td=5Fproc->p= =5Fucred, td) !=3D 0 ) { uprintf("socreate() returned error\n"); return -1; } =20 struct sockaddr=5Fin sin; sin.sin=5Flen =3D sizeof(struct sockaddr=5Fin); sin.sin=5Ffamily =3D AF=5FINET; sin.sin=5Fport =3D htons(8080); inet=5Faton("192.168.2.2", &sin.sin=5Faddr); =20 struct mbuf *top =3D m=5Fgetclr(M=5FTRYWAIT, MT=5FCONTROL); =20 // IP is 0 int sosend=5Ferror =3D sosend(sock, (struct sockaddr *)&sin, NULL,= top, NULL, 0, td); uprintf("sosend(): %d\n", sosend=5Ferror); =20 soclose(sock); =20 return 0; } =20 =20 =20 =20 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: >=20 > --------------------------------------------------------------------= ----- > static int my=5Fudp=5Fsend(struct thread *td, void *syscall=5Fargs) > { > struct socket *sock =3D NULL; >=20 > if( socreate(AF=5FINET, &sock, SOCK=5FDGRAM, 0, td->td=5Fproc->p= =5Fucred, > td) !=3D 0 ) { > uprintf("socreate() returned error\n"); > return -1; > } >=20 > struct sockaddr sa; > sa.sa=5Flen =3D sizeof(struct sockaddr=5Fin); >=20 > struct sockaddr=5Fin *sin =3D (struct sockaddr=5Fin *)&sa; > sin->sin=5Ffamily =3D AF=5FINET; > inet=5Faton("192.168.2.2", (struct sockaddr=5Fin *)&sin->sin=5Fa= ddr); > sin->sin=5Fport =3D htons(8080); > sin->sin=5Flen =3D sizeof(*sin); > memset(sin->sin=5Fzero, 0, sizeof(sin->sin=5Fzero)); >=20 > // int soconnect=5Ferror =3D soconnect(sock, (struct sockaddr *)s= in, td); > // uprintf("soconnect(): %d\n", soconnect=5Ferror); >=20 > struct mbuf *top =3D m=5Fgetclr(M=5FTRYWAIT, MT=5FCONTROL); >=20 > // IP is 0 > int sosend=5Ferror =3D sosend(sock, (struct sockaddr *)sin, NULL= , top, > NULL, 0, td); > uprintf("sosend(): %d\n", sosend=5Ferror); >=20 > soclose(sock); >=20 > return 0; > } > --------------------------------------------------------------------= ----- >=20 >=20 > 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. >=20 > Am i doing something wrong=3F Note, that I am not filling in the mbu= f and > all the wacking casting done. >=20 > Thanks.=20 >=20 > On Tue, 2008-12-30 at 18:46 +0000, Robert Watson wrote: > > On Tue, 30 Dec 2008, Max Laier wrote: > >=20 > > > 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 c= annot seem=20 > > >> to understand what to do. I have tried more about a month now t= o send=20 > > >> arbitrary UDP packets from a kernel module but cannot achieve i= t. I have=20 > > >> looked at udp=5Fsend but found that building a socket* was much= to tedious.=20 > > >> Later i looked at in-kernel webservers (http://openketa.sourcef= orge.net/)=20 > > >> but could not find anything useful. > > >> > > >> Netgraph is a possibility, but there isn't any documentation on= accessing=20 > > >> the network from kernel space. > > >> > > >> What do you all suggest=3F > > > > > > $ man 9 socket > >=20 > > Definitely the preferred solution, if it meets the application mod= el. Call=20 > > socreate(9) to allocate the socket, sobind(9) if required, calls t= o sosend(9)=20 > > to generate packets, and soclose(9) when done. Direct calls to th= e=20 > > udp=5Foutput() and udp=5Fsend() functions won't work without a soc= ket context, and=20 > > doing sosend(9) will isolate in-kernel consumers from future chang= es in UDP=20 > > internals. ip=5Foutput() could be invoked directly to generate IP= packets, but=20 > > won't allow you to easily receive replies, etc. > >=20 > > Robert N M Watson > > Computer Laboratory > > University of Cambridge --=20 Cilloniz Bicchi, Ferner =20 Research Assistant Dept. of Computer Sciences The University of Texas at Austin http://www.cs.utexas.edu/~fernercc fernercc@cs.utexas.edu =20 =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F 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=5Fgethdr instead = of=20 m=5Fgetclr. Thanks, Gerry