Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752341AbbEATzS (ORCPT ); Fri, 1 May 2015 15:55:18 -0400 Received: from mail-ig0-f180.google.com ([209.85.213.180]:36603 "EHLO mail-ig0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751888AbbEATzO (ORCPT ); Fri, 1 May 2015 15:55:14 -0400 MIME-Version: 1.0 In-Reply-To: <1430505777.3711.135.camel@edumazet-glaptop2.roam.corp.google.com> References: <1430502237-5619-1-git-send-email-emunson@akamai.com> <1430505777.3711.135.camel@edumazet-glaptop2.roam.corp.google.com> Date: Fri, 1 May 2015 12:55:13 -0700 Message-ID: Subject: Re: [PATCH] Allow TCP connections to cache SYN packet for userspace inspection From: Tom Herbert To: Eric Dumazet Cc: Eric B Munson , "David S. Miller" , Alexey Kuznetsov , James Morris , Hideaki YOSHIFUJI , Patrick McHardy , Linux Kernel Network Developers , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2429 Lines: 54 On Fri, May 1, 2015 at 11:42 AM, Eric Dumazet wrote: > On Fri, 2015-05-01 at 13:43 -0400, Eric B Munson wrote: >> In order to enable policy decisions in userspace, the data contained in >> the SYN packet would be useful for tracking or identifying connections. >> Only parts of this data are available to userspace after the hand shake >> is completed. This patch exposes a new setsockopt() option that will, >> when used with a listening socket, ask the kernel to cache the skb >> holding the SYN packet for retrieval later. The SYN skbs will not be >> saved while the kernel is in syn cookie mode. >> >> The same option will ask the kernel for the packet headers when used >> with getsockopt() with the socket returned from accept(). The cached >> packet will only be available for the first getsockopt() call, the skb >> is consumed after the requested data is copied to userspace. Subsequent >> calls will return -ENOENT. Because of this behavior, getsockopt() will >> return -E2BIG if the caller supplied a buffer that is too small to hold >> the skb header. >> >> Signed-off-by: Eric B Munson >> Cc: Alexey Kuznetsov >> Cc: James Morris >> Cc: Hideaki YOSHIFUJI >> Cc: Patrick McHardy >> Cc: netdev@vger.kernel.org >> Cc: linux-api@vger.kernel.org >> Cc: linux-kernel@vger.kernel.org >> --- > > We have a similar patch here at Google, but we do not hold one skb and > dst per saved syn. That can be ~4KB for some drivers. > > Only a kmalloc() with the needed part (headers), usually less than 128 > bytes. We store the length in first byte of this allocation. > > This has a huge difference if you want to have ~4 million request socks. > +1 on kmalloc solution. I posted a similar patch a couple of years ago https://patchwork.ozlabs.org/patch/146034/. There was pushback on memory usage and this having to narrow of a use case. Tom > > > > -- > To unsubscribe from this list: send the line "unsubscribe netdev" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/