From patchwork Tue Jun 20 03:00:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lawrence Brakmo X-Patchwork-Id: 778082 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wsCKV31Gxz9s78 for ; Tue, 20 Jun 2017 13:01:18 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=fb.com header.i=@fb.com header.b="fKtdcfeb"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751940AbdFTDBD (ORCPT ); Mon, 19 Jun 2017 23:01:03 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:51767 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751763AbdFTDA4 (ORCPT ); Mon, 19 Jun 2017 23:00:56 -0400 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v5K2wBvr024409 for ; Mon, 19 Jun 2017 20:00:55 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=ZIYb133pzHXME0QqcsHjjvoLfdtqxN5AcyEXTerf+bo=; b=fKtdcfebTcNj28PngbuYd/MbA3zXV+kEG4oZD9/XIy9DRxS49eJbhW40Tt4n0iJPh+zH qPSiM5L24bCkTFt0p6TW+n3lri62NA+cWCtpfEa36ecXIflxZF7NN9lnkGRXkBDlZ3P/ I0xs9Ci5HS727ww05GcCegA2H59EgC4d1E8= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2b6nvx8r6t-5 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Mon, 19 Jun 2017 20:00:55 -0700 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB07.TheFacebook.com (192.168.16.17) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 19 Jun 2017 20:00:54 -0700 Received: from facebook.com (2401:db00:11:d025:face:0:13:0) by mx-out.facebook.com (10.212.236.87) with ESMTP id abdcb240556411e7913c0002c9521c9e-6b9348f0 for ; Mon, 19 Jun 2017 20:00:52 -0700 Received: by dev11624.prn1.facebook.com (Postfix, from userid 10340) id A741C2E4A96; Mon, 19 Jun 2017 20:00:50 -0700 (PDT) Smtp-Origin-Hostprefix: dev From: Lawrence Brakmo Smtp-Origin-Hostname: dev11624.prn1.facebook.com To: netdev CC: Kernel Team , Blake Matheny , Alexei Starovoitov , Daniel Borkmann , David Ahern Smtp-Origin-Cluster: prn1c29 Subject: [PATCH net-next v3 09/15] bpf: Sample BPF program to set buffer sizes Date: Mon, 19 Jun 2017 20:00:42 -0700 Message-ID: <20170620030048.3275347-10-brakmo@fb.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170620030048.3275347-1-brakmo@fb.com> References: <20170620030048.3275347-1-brakmo@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-19_12:, , signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch contains a BPF program to set initial receive window to 40 packets and send and receive buffers to 1.5MB. This would usually be done after doing appropriate checks that indicate the hosts are far enough away (i.e. large RTT). Signed-off-by: Lawrence Brakmo --- samples/bpf/Makefile | 1 + samples/bpf/tcp_bufs_kern.c | 76 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 samples/bpf/tcp_bufs_kern.c diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index 9aca209..942c7c7 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -115,6 +115,7 @@ always += test_map_in_map_kern.o always += cookie_uid_helper_example.o always += tcp_synrto_kern.o always += tcp_rwnd_kern.o +always += tcp_bufs_kern.o HOSTCFLAGS += -I$(objtree)/usr/include HOSTCFLAGS += -I$(srctree)/tools/lib/ diff --git a/samples/bpf/tcp_bufs_kern.c b/samples/bpf/tcp_bufs_kern.c new file mode 100644 index 0000000..6cc096c --- /dev/null +++ b/samples/bpf/tcp_bufs_kern.c @@ -0,0 +1,76 @@ +/* Copyright (c) 2017 Facebook + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * BPF program to set initial receive window to 40 packets and send + * and receive buffers to 1.5MB. This would usually be done after + * doing appropriate checks that indicate the hosts are far enough + * away (i.e. large RTT). + */ + +#include +#include +#include +#include +#include +#include "bpf_helpers.h" + +#define DEBUG 1 + +SEC("sockops") +int bpf_bufs(struct bpf_sock_ops *skops) +{ + char fmt1[] = "BPF command: %d\n"; + char fmt2[] = " Returning %d\n"; + int bufsize = 1500000; + int rwnd_init = 40; + int rv = 0; + int op; + + /* For testing purposes, only execute rest of BPF program + * if neither port numberis 55601 + */ + if (skops->remote_port != 55601 && skops->local_port != 55601) + return -1; + + op = (int) skops->op; + +#ifdef DEBUG + bpf_trace_printk(fmt1, sizeof(fmt1), op); +#endif + + /* Usually there would be a check to insure the hosts are far + * from each other so it makes sense to increase buffer sizes + */ + switch (op) { + case BPF_SOCK_OPS_RWND_INIT: + rv = rwnd_init; + break; + case BPF_SOCK_OPS_TCP_CONNECT_CB: + /* Set sndbuf and rcvbuf of active connections */ + rv = bpf_setsockopt(skops, SOL_SOCKET, SO_SNDBUF, &bufsize, + sizeof(bufsize)); + rv = rv*100 + bpf_setsockopt(skops, SOL_SOCKET, SO_RCVBUF, + &bufsize, sizeof(bufsize)); + break; + case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB: + /* Nothing to do */ + break; + case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB: + /* Set sndbuf and rcvbuf of passive connections */ + rv = bpf_setsockopt(skops, SOL_SOCKET, SO_SNDBUF, &bufsize, + sizeof(bufsize)); + rv = rv*100 + bpf_setsockopt(skops, SOL_SOCKET, SO_RCVBUF, + &bufsize, sizeof(bufsize)); + break; + default: + rv = -1; + } +#ifdef DEBUG + bpf_trace_printk(fmt2, sizeof(fmt2), rv); +#endif + return rv; +} +char _license[] SEC("license") = "GPL";