From owner-freebsd-net@FreeBSD.ORG Tue Jan 12 07:26:41 2010 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 B2CC6106566B for ; Tue, 12 Jan 2010 07:26:41 +0000 (UTC) (envelope-from mavbsd@gmail.com) Received: from mail-fx0-f227.google.com (mail-fx0-f227.google.com [209.85.220.227]) by mx1.freebsd.org (Postfix) with ESMTP id 42D308FC12 for ; Tue, 12 Jan 2010 07:26:40 +0000 (UTC) Received: by fxm27 with SMTP id 27so103959fxm.3 for ; Mon, 11 Jan 2010 23:26:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=mf0IDmMrKbgPItwqSFnzILElYhC9JpkFpc3pz+EVIQw=; b=TTbxHYVLPZk5NTcg1FOLg2vGVzN0zzwfiZxb0rJHeT+k8DFzAMXeuTpcV5d/6UFOpY FH4YPPjKJMBSMi5ryZUUyerWeT4dXmszfSNTLyYOaHWjJpU2aoWDqShOJb4RIMUkA7gz /3Y2L+kDdAtsXZQ8i8fgAiVhwlY2sjeYtm0So= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=MT3cs/9oaWfN0cRFqQfnmlyq7gTm3AVLvmbpGFKhsL+BBRZC2jC8FMkgrgkGD4RO1E eNxyLOu05TehRWiSjGZ9jrbTuAaN75HLh8pwmt/0I6mQqXXvllhV2ZOatFXKjHVHWP2I blNhKYt/NvSwXF8MHYaDiWRi0kDu3AvEJl1OU= Received: by 10.223.5.87 with SMTP id 23mr9548479fau.87.1263281191717; Mon, 11 Jan 2010 23:26:31 -0800 (PST) Received: from mavbook.mavhome.dp.ua (pc.mavhome.dp.ua [212.86.226.226]) by mx.google.com with ESMTPS id 14sm10056093fxm.7.2010.01.11.23.26.30 (version=SSLv3 cipher=RC4-MD5); Mon, 11 Jan 2010 23:26:31 -0800 (PST) Sender: Alexander Motin Message-ID: <4B4C2425.2010402@FreeBSD.org> Date: Tue, 12 Jan 2010 09:26:29 +0200 From: Alexander Motin User-Agent: Thunderbird 2.0.0.23 (X11/20091212) MIME-Version: 1.0 To: Maxim Ignatenko References: <1263262983.00205781.1263251401@10.7.7.3> In-Reply-To: <1263262983.00205781.1263251401@10.7.7.3> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: freebsd-net@freebsd.org Subject: Re: ng_patch node 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, 12 Jan 2010 07:26:41 -0000 Maxim Ignatenko wrote: > I've written netgraph node able to modify arbitrary (8|16|32)-bit > unsigned integer in passing packets. Node applies one of =,+,-,&,| and > ^ operations to number at given offset. > Modification applied to each packet received on "in" hook. If "out" > hook is connected - resulting packets passed on it, otherwise - > returned back on "in" (for more easy use with ng_ipfw). Packets > received on "out" hook passed on "in" unmodified. > Node supports two control messages: "getconfig" and "setconfig". > Configuration represented in next structure: > struct ng_patch_config { > uint32_t value; /* argument passed to requested operation */ > uint32_t offset; /* offset in bytes */ > uint32_t length; /* 1,2 or 4 bytes */ > uint32_t mode; /* operation code: 1 - "=", 2 - "+", 3 - > "-", 4 - "&", 5 - "|", 6 - "^" */ > }; > Same names used in ASCII representation. > > I wanted to make ipfw able to modify TTL and ToS fields in IP packets, > but after some generalization idea looked like described above. > > Next patch made against 8-STABLE r200201 Just few stones into your garden: > + if (((struct ng_patch_config *)msg->data)->offset < 0) > + error = EINVAL; As I see, offset field is unsigned there. > + case 4: > + *((uint32_t *)dst) += > priv->value4; I think such dereference may crash archs with strong alignment requirements. m_copydata/m_copyback could do it possibly slower, but safer and wouldn't require m_pullup. Also result of such multi-byte operations is endian-dependent. I would be nice to do hton/ntoh somewhere. Also, what's about checksums? -- Alexander Motin