Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp318908pxf; Thu, 25 Mar 2021 05:02:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3vd9aXzGHIp9JyysSBs9wXvYEWgi6h6394zOISOLw9Psy3dUF7+YamD/pS6dIVPZhiT7B X-Received: by 2002:a05:6402:1a4f:: with SMTP id bf15mr8735904edb.304.1616673778185; Thu, 25 Mar 2021 05:02:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616673778; cv=none; d=google.com; s=arc-20160816; b=MI5WzA/3nEQ3S1OuIu859IMJ5S4ntx/3IkVh1s7EIVCO7bzqTd50HqFoHO61HT+GGC D+HWZFwm8nL1uODNP29NzRQNW+5YQfUznbPXtZfLCBp5tAVoImwrR/2g57lXH0QtTUuK hN7U3+qlLwpkxTCJO8d91xz55PQHoxrvaNM4G92WRntN1sJd5eEuvHup35iXK5lCuOao kgG6ETNL6PKBq9E6MyVzUJxX2hfsgbWzmb16bogmjG8bg1sy/3bcRXCLNBViB8cgqwvO YalDgzTpZRvEse1OiReU20ivmbUAhM5nOHogD15mvqiXqBTuHACq3pyHAaH2FPsMptB4 9zfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=WvEHsPjKIq/P2TsSWLeMiXHZ4cDxRks9I5jtQKX/b+k=; b=OGY2jOvGryV9PrHp8CLQGGND8kNpTBvd09GF1WjrHg7Uk7pAoezcf3GlLOcnMbMbKk bq98ofDWnWNYgzY9qSyvhS+UAVKhAFjjbt93koN8hMTrs0j7haiyZMBnH6er12mqxEgX 10ZHaOHkML+Xij95VRLSV4z8+6PoaT8Dfdg7j+eO/HjSju+E74N3po4uK3pOa84Y3Ddb BXzuDr14weW13ZEZoFpuSO0MP/36pirNucvb8K19gOA64fTOWY3mLQv0Ek9oOhL+f6sE MsIFdUkzXCWnIGZsyIIXPvIcJFeMe6rMjbf0YPVMd4Vb8dQTMLKbNuFKA/OtlkA+td+z kBjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=K1e2lO9t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id de22si4139649edb.314.2021.03.25.05.02.34; Thu, 25 Mar 2021 05:02:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=K1e2lO9t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230228AbhCYMBd (ORCPT + 99 others); Thu, 25 Mar 2021 08:01:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229888AbhCYMBB (ORCPT ); Thu, 25 Mar 2021 08:01:01 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D7EAC06174A; Thu, 25 Mar 2021 05:01:01 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id v186so1546478pgv.7; Thu, 25 Mar 2021 05:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WvEHsPjKIq/P2TsSWLeMiXHZ4cDxRks9I5jtQKX/b+k=; b=K1e2lO9tvzR3LDoDU86xEEwPisR7tDiX4AfI2nUBu4Tih6W4ixNZVdMKEC4pFWWKlN 3XItzPX5i57JZwLYtQsvyc9kXwIuQY+foL7hGmS7hkDxS1a+UKn+uQ104knm7rAUdmQo hVNYRxupAJNKI9wpBYdBxOL2BArNd5xTZpjVYK+iizoiiwU/dDWqikMuDNnQGUUNbTM6 OmIVDwRzIhJ50RlK4gUYw2ntSkopWnbEwccie3iysM3ZYOEHF52txgEbFmZh/UHw9l1O dKfJm76W6aEMBHnE/2pvESO+qOfoAckGift3RWJZGmoC+6M7IoeysQH2WYkUUA9bRf8p 9NLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WvEHsPjKIq/P2TsSWLeMiXHZ4cDxRks9I5jtQKX/b+k=; b=T4Je16WVV6rrFZR4btG070SW9zoZWi69GEKFYC7PWpVZhDxcD0XwoBVopxq1VaixVl T/mDwc26E0iEuwXrBesipgRiVOWy9UpDyq7WWdw18XVxJVoTByysLuwO0e8k4iZX5wtX DsL2jtSFJw5vQ6iFzyymFgRT5MDpaXibcKzpDx6FXFyMYfsOIBwYQmE4nBJmI6D6AWsb 2bV+ZhJY+utwjNn2D0Hpco/V/cQdzc8fwop8m5Xa/fTblvv78wag7LI9dWd4I+cD5za+ Qff3kq6qmLsBrfDPTOK5fy0yECXe/aCWxlC+sIHtiO9iHkpIAGEc386lZSxZ1gbHGXXj Ahmw== X-Gm-Message-State: AOAM532Anx3GzP7gip537+HaGV2H09yLsz0OLxt75ksO3QJYvpjhODqP Yuq2f+xTKGRCy8sKrbmGwFjcpGlSvxKnvg== X-Received: by 2002:a62:5f83:0:b029:20e:70c3:c3e3 with SMTP id t125-20020a625f830000b029020e70c3c3e3mr7225214pfb.60.1616673660425; Thu, 25 Mar 2021 05:01:00 -0700 (PDT) Received: from localhost ([112.79.237.176]) by smtp.gmail.com with ESMTPSA id a15sm5545035pju.34.2021.03.25.05.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 05:01:00 -0700 (PDT) From: Kumar Kartikeya Dwivedi To: bpf@vger.kernel.org Cc: brouer@redhat.com, Kumar Kartikeya Dwivedi , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Shuah Khan , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , Peter Zijlstra , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next 0/5] libbpf: Add TC-BPF API Date: Thu, 25 Mar 2021 17:29:58 +0530 Message-Id: <20210325120020.236504-1-memxor@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series adds support to libbpf for attaching SCHED_CLS and SCHED_ACT bpf programs to their respective tc attach points. Currently, a user needs to shell out to the tc command line for add, change, replace, and del operations, which is not ideal. Some of the features that have been omitted for the CLS API: * TCA_BPF_POLICE Support for adding police actions to filter has been omitted for now. * TCA_RATE Support for packet rate estimator has been omitted for now. * Attaching actions directly to the classifier This allows the attached actions to be bound to classifier and get auto detached when it is deleted. It translates to 'bind' refcount in the kernel internally. They run after a successful classification from the SCHED_CLS prog. Support for this can be added later, but has been omitted for now, primarily because direct-action mode provides a better alternative. A high level TC-BPF API is also provided, and currently only supports attach and destroy operations. These functions return a pointer to a bpf_link object. When falling back to the low level API, the link must be disconnected to take over its ownership. It can be released using bpf_link__destroy, which will also cause the filter/action to be detached if not disconnected. The individual commits contain a general API summary and examples. Kumar Kartikeya Dwivedi (5): tools pkt_cls.h: sync with kernel sources libbpf: add helpers for preparing netlink attributes libbpf: add low level TC-BPF API libbpf: add high level TC-BPF API libbpf: add selftests for TC-BPF API tools/include/uapi/linux/pkt_cls.h | 174 +++- tools/lib/bpf/libbpf.c | 110 ++- tools/lib/bpf/libbpf.h | 133 ++++ tools/lib/bpf/libbpf.map | 17 + tools/lib/bpf/netlink.c | 752 +++++++++++++++++- tools/lib/bpf/nlattr.h | 43 + .../selftests/bpf/prog_tests/test_tc_bpf.c | 261 ++++++ .../selftests/bpf/progs/test_tc_bpf_kern.c | 18 + 8 files changed, 1476 insertions(+), 32 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/test_tc_bpf.c create mode 100644 tools/testing/selftests/bpf/progs/test_tc_bpf_kern.c -- 2.30.2