Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Dec 2008 23:03:18 -0600
From:      "Gerry Weaver" <gerryw@compvia.com>
To:        "Ferner Cilloniz" <fernercc@gmail.com>, freebsd-net@freebsd.org
Subject:   Re: kernel network
Message-ID:  <20081231050318.616ef838@mail01.compvia.com>
In-Reply-To: 1230672967.4966.26.camel@mobiliare.Belkin

next in thread | raw e-mail | index | archive | help
=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



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