From owner-freebsd-net@FreeBSD.ORG Wed Dec 31 03:36:11 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 0AC561065670 for ; Wed, 31 Dec 2008 03:36:11 +0000 (UTC) (envelope-from fernercc@gmail.com) Received: from rn-out-0910.google.com (rn-out-0910.google.com [64.233.170.187]) by mx1.freebsd.org (Postfix) with ESMTP id AFF878FC08 for ; Wed, 31 Dec 2008 03:36:10 +0000 (UTC) (envelope-from fernercc@gmail.com) Received: by rn-out-0910.google.com with SMTP id j71so3655286rne.12 for ; Tue, 30 Dec 2008 19:36:10 -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=8yu0HAeQqq9CnZpQTnFXkWxM1SViEzJQ9e8vpPdllC8=; b=BXo+5W7lyUB+i89xq7mWAz9fXLfJzMedhrA/1wSyrxOzCPdl5Enu1J+NQmJINgohmm bLoX1rv8EErIJ7H072ifWbxdEa4QjwT2XZRL00W4qxuY82Ho5w3L29HQP5X3+KSAx6tC YRHAmCMQLMFd6kLaWOpw5uZhtTbwkeRDHbjxw= 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=u4fm0jvWu16tqvvkSTcUVZ4k6DXAJAJW4Kq0VZ1HcYBpLbteKpUNqnCK7SGJns5Mdk P775UDvtNqbYCAL5ZqnzfepGMj6hO9SXsdAnXtK/i/9AwsevQbJf1Cc+0EjYj7giq6C3 TcQmJzUA08cMT43/hxipwlXbnmEoVmZvilLgk= Received: by 10.100.41.9 with SMTP id o9mr8738098ano.49.1230694569531; Tue, 30 Dec 2008 19:36:09 -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 d35sm27424131and.45.2008.12.30.19.36.08 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 30 Dec 2008 19:36:09 -0800 (PST) From: Ferner Cilloniz To: freebsd-net@freebsd.org In-Reply-To: <1230657412.4966.24.camel@mobiliare.Belkin> References: <1230637795.4966.20.camel@mobiliare.Belkin> <200812301905.57164.max@love2party.net> <1230657412.4966.24.camel@mobiliare.Belkin> Content-Type: text/plain Date: Tue, 30 Dec 2008 21:36:07 +0000 Message-Id: <1230672967.4966.26.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: Wed, 31 Dec 2008 03:36:11 -0000 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