{"id":2225109,"url":"http://patchwork.ozlabs.org/api/1.1/covers/2225109/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/cover/20260420105816.72168-1-mahe.tardy@gmail.com/","project":{"id":26,"url":"http://patchwork.ozlabs.org/api/1.1/projects/26/?format=json","name":"Netfilter Development","link_name":"netfilter-devel","list_id":"netfilter-devel.vger.kernel.org","list_email":"netfilter-devel@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20260420105816.72168-1-mahe.tardy@gmail.com>","date":"2026-04-20T10:58:10","name":"[bpf-next,v4,0/6] bpf: add icmp_send_unreach kfunc","submitter":{"id":91349,"url":"http://patchwork.ozlabs.org/api/1.1/people/91349/?format=json","name":"Mahe Tardy","email":"mahe.tardy@gmail.com"},"mbox":"http://patchwork.ozlabs.org/project/netfilter-devel/cover/20260420105816.72168-1-mahe.tardy@gmail.com/mbox/","series":[{"id":500597,"url":"http://patchwork.ozlabs.org/api/1.1/series/500597/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/list/?series=500597","date":"2026-04-20T10:58:10","name":"bpf: add icmp_send_unreach kfunc","version":4,"mbox":"http://patchwork.ozlabs.org/series/500597/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/covers/2225109/comments/","headers":{"Return-Path":"\n <netfilter-devel+bounces-12039-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","netfilter-devel@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=TqqLys1i;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org;\n envelope-from=netfilter-devel+bounces-12039-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=\"TqqLys1i\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.128.41","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=gmail.com"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org\n [IPv6:2600:3c04:e001:36c::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fzjCS34z7z1yGs\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 20 Apr 2026 20:58:44 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id CF7F33031F32\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 20 Apr 2026 10:58:37 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id EFCEE39B97E;\n\tMon, 20 Apr 2026 10:58:33 +0000 (UTC)","from mail-wm1-f41.google.com (mail-wm1-f41.google.com\n [209.85.128.41])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D32939B483\n\tfor <netfilter-devel@vger.kernel.org>; Mon, 20 Apr 2026 10:58:31 +0000 (UTC)","by mail-wm1-f41.google.com with SMTP id\n 5b1f17b1804b1-488e1a8ac40so38967425e9.2\n        for <netfilter-devel@vger.kernel.org>;\n Mon, 20 Apr 2026 03:58:31 -0700 (PDT)","from mtardy-friendly-lvh-runner.local ([2600:1900:4010:1a8::])\n        by smtp.googlemail.com with ESMTPSA id\n 5b1f17b1804b1-488fc1cfbf2sm290929495e9.15.2026.04.20.03.58.29\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Mon, 20 Apr 2026 03:58:29 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776682713; cv=none;\n b=afGg6P/AogQSymG02AY8RU2rgGyFKM17K4doTjZILH6Dq+lRs56PtGL2IgJRLV7JnWf6R2NPWJhyum/316c6DeGJP8VrFKjf8OfrBZSvmydJ53X5r8WnkhbNpHupcwO5wBaFT/6p5RUdI4T4r4ZvrZBYVPvT6pbHLFErjcg3XWs=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776682713; c=relaxed/simple;\n\tbh=jeNe6hoVFvSWp1WGUu4CvjQgGHlygFkkp2Jz+ownf9E=;\n\th=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:\n\t MIME-Version;\n b=Oro3u6O9syvl1mYqz+GRzGvZ4afsEqL9Mxgg0R7M13Du02HTFAOt+I6m3Y4J8zt3Kv07fH1ET6jQRD3mXnvb4LztRzAcUodrxhZqCxK1LM2VXP8vhvWWRi3iHSFkftXSMdjrX6AkbOyOdrpz0Xj775vMU4PYGUAllDVSksjd2w4=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com;\n spf=pass smtp.mailfrom=gmail.com;\n dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=TqqLys1i; arc=none smtp.client-ip=209.85.128.41","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1776682710; x=1777287510;\n darn=vger.kernel.org;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=mSip2mFo5UpUa5K/ga6S7Tqbsc6g4uU5VZLY4tip40A=;\n        b=TqqLys1iJM4sTOPZfTjaqobStjkvZ/Zpiln+pUcYqaiSTBaK8amwfTrhA5c3N4DP/A\n         yqEtJdQ2jnXB8Do28HaagK3G+WSgmqcNdOvZ6jGEqOul3tlAnFtLPTOV7OID865vcU8n\n         u641aYqnr7amhEY9t5qBHFtnXWlE88jhRB52ThSCGm1fJ3v5YOf114t4JNabJ0G+pTSX\n         DCCy8ajmrI48NF+FQE07lw7UXRKESBeCWDU1OjJ2nqIqHxKeNa2+B2I5gOX5BqzXt/BL\n         J1k/XwXmNeO6CmQGksPfr3QbDMphxDIgllEjAXtfSEXCKtqZm5v8h7NE+C0OEcOKmBm9\n         PNTw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1776682710; x=1777287510;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n         :to:cc:subject:date:message-id:reply-to;\n        bh=mSip2mFo5UpUa5K/ga6S7Tqbsc6g4uU5VZLY4tip40A=;\n        b=jWhapkYEJZazJRj709Gv4rQjXzlIOpqV9Oq8h6zlzvuWmtei1Tl/Ve0iekbdNbEIXt\n         H3Ue1W68RM5adrCUR/jHDsEuUNVnhNa+rgoz/69AipQmoALWJDAeOsXYvZLQtpRWaUMg\n         LI9IR051BeACGg+mVNSahwX/c+WKAWnAAo3o67JcOh+0dr4Rrvn8LBKQgx/ChHX7XUI6\n         Sl8dRkOuD7eJa+0Ew9Ak5IHP9NPXjNLEHY0lCK9Mgc54gAljImWYVVYmVGLnNyLSTnkG\n         m8HYhhyGWUGpE6gMnCJyeqY42E5hsLzGz1jxvxOqHei9vWOrjOSyE0ZmYtOEc6UZyuhg\n         HcMg==","X-Forwarded-Encrypted":"i=1;\n AFNElJ8rJ3VuP/rKbflxDj0bziU0KNd/zXgND+oPY4nQ7iQZWVgpDECv9zMkZo9tlvJJsvxa7sMrzSTPY9h0TUKD8aQ=@vger.kernel.org","X-Gm-Message-State":"AOJu0YzvlkwbxIJl61BQ2UtA9sv3CzwDB5naMHpwVG3ge3P0z4K77pzP\n\tFoF6m2YQkhDNnWjSgPiE4aLQCUZ4ND3wgsRL+7UcACDta3+5C4G2eyAm","X-Gm-Gg":"AeBDievojfRz2a98tIZzzg/RRdDCs/OflriAvtZoXwlYNZUeOzEU+F4aq52C1HMCRBR\n\tknRvL/8r9exyh+MQmXhf8vDsLa7vyy2inVORjY2JR3ypxu50hFJIF7pc4pHWB/jUoBcCiAnZpAK\n\teKANObblJgK+HNWGzAeRZtl//6WPztMP375tv3zcYPv/Blb1ZdcXs3FFCFs0pp2H8NaCoIoU76Q\n\tp96cz2YzYlRy1pvvqSr9PbHudLmBJnveuac6HPGanrBeLFJ8DfmztjSy4M9xR/bFMG6eR07BMsl\n\trdayfsGm2zCPF1sYw/89cndsxE20opq4oGgGDALSBvYbf4R71of3QdqQq1sWfrf01xA6udEEe0c\n\tRm1JPN3cs7FDDpLbl/KfGCxoUVrgu2ykOluQS6939m2sAAxNXlY8jpu8dBy3oCEraf8qrdxl+Go\n\tXidzp7JKW3S5AW7NiTmTZXgkrvjLb6aV43vUy1ow==","X-Received":"by 2002:a05:600c:c108:b0:488:a82f:bbb6 with SMTP id\n 5b1f17b1804b1-488fb78e576mr125872725e9.27.1776682710104;\n        Mon, 20 Apr 2026 03:58:30 -0700 (PDT)","From":"Mahe Tardy <mahe.tardy@gmail.com>","To":"mahe.tardy@gmail.com","Cc":"alexei.starovoitov@gmail.com,\n\tandrii@kernel.org,\n\tast@kernel.org,\n\tbpf@vger.kernel.org,\n\tcoreteam@netfilter.org,\n\tdaniel@iogearbox.net,\n\tfw@strlen.de,\n\tjohn.fastabend@gmail.com,\n\tlkp@intel.com,\n\tmartin.lau@linux.dev,\n\tnetdev@vger.kernel.org,\n\tnetfilter-devel@vger.kernel.org,\n\toe-kbuild-all@lists.linux.dev,\n\tpablo@netfilter.org","Subject":"[PATCH bpf-next v4 0/6] bpf: add icmp_send_unreach kfunc","Date":"Mon, 20 Apr 2026 10:58:10 +0000","Message-Id":"<20260420105816.72168-1-mahe.tardy@gmail.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<aI0MkNvWlE4FXMV8@gmail.com>","References":"<aI0MkNvWlE4FXMV8@gmail.com>","Precedence":"bulk","X-Mailing-List":"netfilter-devel@vger.kernel.org","List-Id":"<netfilter-devel.vger.kernel.org>","List-Subscribe":"<mailto:netfilter-devel+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:netfilter-devel+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"Hello,\n\nThis is v4 of adding the icmp_send_unreach kfunc, as suggested during\nLSF/MM/BPF 2025[^1]. The goal is to allow cgroup_skb programs to\nactively reject east-west traffic, similarly to what is possible to do\nwith netfilter reject target.\n\nThe first step to implement this is using ICMP control messages, with\nthe ICMP_DEST_UNREACH type with various code ICMP_NET_UNREACH,\nICMP_HOST_UNREACH, ICMP_PROT_UNREACH, etc. This is easier to implement\nthan a TCP RST reply and will already hint the client TCP stack to abort\nthe connection and not retry extensively.\n\nNote that this is different than the sock_destroy kfunc, that along\ncalls tcp_abort and thus sends a reset, destroying the underlying\nsocket.\n\nCaveats of this kfunc design are that a program can call this function N\ntimes, thus send N ICMP unreach control messages and that the program\ncan return from the BPF filter with pass leading to a potential\nconfusing situation where the TCP connection was established while the\nclient received ICMP_DEST_UNREACH messages.\n\nInitially, this kfunc was added only to cgroup_skb programs, Alexei\nsuggested not creating its own kfunc set and adding it to the more\nglobal bpf_kfunc_set_skb. Now that recursion is handled and I realized,\nthanks to Martin, that fetching the dst route might be only useful in\nsituation in which the packet was not yet routed, I decided to extend\nthe kfunc to more program types and route the packet only if needed.\n\nv2 updates:\n- fix a build error from a missing function call rename;\n- avoid changing return line in bpf_kfunc_init;\n- return SK_DROP from the kfunc (similarly to bpf_redirect);\n- check the return value in the selftest.\n\nv3 update:\n- fix an undefined reference build error.\n\nv4 updates:\n- prevent the kfunc to be called recursively and add a test (thanks to\n  Martin).\n- do not fetch dst route when unnecessary (thanks to Martin).\n- extend the test for IPv6 (thanks to Martin).\n- use SK_DROP in examples and use non blocking sockets for testing\n  (thanks to Martin).\n- test when the kfunc returns -EINVAL (thanks to Jordan).\n- add the kfunc to bpf_kfunc_set_skb as suggested by Alexei.\n- guard the IPv4 parts with IS_ENABLED(CONFIG_INET).\n- fix a wrong initial value for client_fd (thanks to Yonghong).\n- add documentation to the kfunc.\n- to Jordan: I couldn't include <linux/icmp.h> because of redefines from\n  <network_helpers.h>.\n\n[^1]: https://lwn.net/Articles/1022034/\n\nMahe Tardy (6):\n  net: move netfilter nf_reject_fill_skb_dst to core ipv4\n  net: move netfilter nf_reject6_fill_skb_dst to core ipv6\n  bpf: add bpf_icmp_send_unreach kfunc\n  selftests/bpf: add icmp_send_unreach kfunc tests\n  selftests/bpf: add icmp_send_unreach kfunc IPv6 tests\n  selftests/bpf: add icmp_send_unreach_recursion test\n\n include/net/ip6_route.h                       |   2 +\n include/net/route.h                           |   1 +\n net/core/filter.c                             |  85 ++++++++\n net/ipv4/netfilter/nf_reject_ipv4.c           |  19 +-\n net/ipv4/route.c                              |  15 ++\n net/ipv6/netfilter/nf_reject_ipv6.c           |  17 +-\n net/ipv6/route.c                              |  18 ++\n .../bpf/prog_tests/icmp_send_unreach_kfunc.c  | 202 ++++++++++++++++++\n .../selftests/bpf/progs/icmp_send_unreach.c   | 100 +++++++++\n 9 files changed, 426 insertions(+), 33 deletions(-)\n create mode 100644 tools/testing/selftests/bpf/prog_tests/icmp_send_unreach_kfunc.c\n create mode 100644 tools/testing/selftests/bpf/progs/icmp_send_unreach.c\n\n--\n2.34.1"}