From owner-freebsd-net@FreeBSD.ORG Tue Dec 30 23:16: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 DDF0D106566B for ; Tue, 30 Dec 2008 23:16:55 +0000 (UTC) (envelope-from fernercc@gmail.com) Received: from yw-out-2324.google.com (yw-out-2324.google.com [74.125.46.30]) by mx1.freebsd.org (Postfix) with ESMTP id 957498FC08 for ; Tue, 30 Dec 2008 23:16:55 +0000 (UTC) (envelope-from fernercc@gmail.com) Received: by yw-out-2324.google.com with SMTP id 9so2565247ywe.13 for ; Tue, 30 Dec 2008 15:16:55 -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:in-reply-to :references:content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=2hVjlr3K07MVZczkHObpHOR0R6b5qLQ74kDsKHtCkVE=; b=iYbjUDtG6xNgQvqT1Dos63Q7Y7ThWHimNZsPsq4VEO9ZUdL2z2Bb3nFMEO2Ma1hCPk F5IGhd7bBK+X19YyUFhe0RoCqa3X7kBk45BG9LCvYJWFGU3adBHYof+mNVd8b6bdewW1 m9ide2N9zOCUa9zYNcuHmYuX9XqixmJhXTlCQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:in-reply-to:references:content-type:date:message-id :mime-version:x-mailer:content-transfer-encoding; b=tNIcKHFf6cltZ6Dodvc0HTyemtUCRKgTkYdLw9Q/t/cMy3jtjnrC9TOzK/SgKPPhL+ 5nUbF53jP+yKYsOH3yC5WV3OmGICGVay35Zy6VDdpkbPxrSQzZRROsQytodxvMboT/lk /wtD6II9pGytaQic5SNkMw1KzoDkdVut7XpKU= Received: by 10.100.209.5 with SMTP id h5mr8646084ang.79.1230679014742; Tue, 30 Dec 2008 15:16:54 -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 b29sm12945640ana.13.2008.12.30.15.16.53 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 30 Dec 2008 15:16:54 -0800 (PST) From: Ferner Cilloniz To: freebsd-net@freebsd.org In-Reply-To: References: <1230637795.4966.20.camel@mobiliare.Belkin> <200812301905.57164.max@love2party.net> Content-Type: text/plain Date: Tue, 30 Dec 2008 17:16:52 +0000 Message-Id: <1230657412.4966.24.camel@mobiliare.Belkin> Mime-Version: 1.0 X-Mailer: Evolution 2.24.2 Content-Transfer-Encoding: 7bit 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: Tue, 30 Dec 2008 23:16:56 -0000 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