From patchwork Tue Mar 30 01:45:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Roeseler X-Patchwork-Id: 412341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CFBDC433DB for ; Tue, 30 Mar 2021 01:45:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D2FC6195D for ; Tue, 30 Mar 2021 01:45:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230220AbhC3BpU (ORCPT ); Mon, 29 Mar 2021 21:45:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230271AbhC3BpT (ORCPT ); Mon, 29 Mar 2021 21:45:19 -0400 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1085C061762 for ; Mon, 29 Mar 2021 18:45:18 -0700 (PDT) Received: by mail-ot1-x32e.google.com with SMTP id w21-20020a9d63950000b02901ce7b8c45b4so14136401otk.5 for ; Mon, 29 Mar 2021 18:45:18 -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:in-reply-to:references; bh=bBO2cd1qd3fbWL44FOOcOnUmpEptHmAjPUxtPNN1Qro=; b=R42vDIR6GfweOhu3rbVBepbmFGdE305ETGOyGpMc9LqDesYccyAgW0SBOjMSJ4sZIW aIoP483hvgynG8fNFqXX9G8FXHcLAcmnQFQ4+JQLZyRKbbXIrHzVUgPRdwiLK65WZKJz 8FH3wZw2E6rgJh1MqePCJIJZyxCJHSAvr7IMbYH7xMAlZjEUHperEI0JXZS6CjNlKeBb kTv6+YGJleEwqM1qL4J9BZarb9K1BzP3N9EChCZtBqPJ+42JHna3PPiy/vpnHsVI/RjF D/X2VM8wykjurYaCK2Vpr1RskVy5Er/b3FrP/K7+agVYmp7CkIj+03ROGt7tuT0atJyL KIiA== 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:in-reply-to :references; bh=bBO2cd1qd3fbWL44FOOcOnUmpEptHmAjPUxtPNN1Qro=; b=VjIq9zlqvJocKVEpWqYlOmRlTqLhsOHYDYA3yrp3gYltcfSEAPI9bp25hDMMB9d4bP EdF7BHmoenreNfY9bOFeTSiwzSFQ9G0Fxc01wqC5MYAJm8efx9gjDjnHKLrEvY+E6daq qe1nVio/YEccpI95c5zQsoZHnLmXS4VkPXibuVy6qyJ+SHKQqggeyZVbz2KcPfM4N9zY bOQDtXscquf49iHiZI4CQGpydd9Hs/1raTOWn4ZchswY20KB5qP2XAONqZvXiV6dIVX+ 1PiMpNHTPmrLH4YX2MEoTjdQ0ablhL9sEfIDVPkxeyNyUY+TsRAHK1maYuHvxVd1dJBV SZjQ== X-Gm-Message-State: AOAM530AkwRCU52GVernko1+f9gn1iWQD2CkRrNNFGV4cQQNrN31c8Kx 6Q1tHrDssk5Z5sP7SqTox5TV7e363k8= X-Google-Smtp-Source: ABdhPJzSBLvchHjrc3Cn568tFSAGg8PmUcsRPyXQb4uTWFWyMZ9egk+CBPMN98OnyIznU5Nhz6LLwA== X-Received: by 2002:a05:6830:1506:: with SMTP id k6mr25846180otp.26.1617068718024; Mon, 29 Mar 2021 18:45:18 -0700 (PDT) Received: from clinic20-Precision-T3610.hsd1.ut.comcast.net ([2601:681:8800:baf9:35b:834f:7126:8db]) by smtp.googlemail.com with ESMTPSA id m14sm4916001otn.69.2021.03.29.18.45.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 18:45:17 -0700 (PDT) From: Andreas Roeseler To: netdev@vger.kernel.org Cc: davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, Andreas Roeseler Subject: [PATCH net-next V6 1/6] icmp: add support for RFC 8335 PROBE Date: Mon, 29 Mar 2021 18:45:15 -0700 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add definitions for PROBE ICMP types and codes. Add AFI definitions for IP and IPV6 as specified by IANA Add a struct to represent the additional header when probing by IP address (ctype == 3) for use in parsing incoming PROBE messages Add a struct to represent the entire Interface Identification Object (IIO) section of an incoming PROBE packet Signed-off-by: Andreas Roeseler --- Changes: v1 -> v2: - Add AFI_IP and AFI_IP6 definitions v2 -> v3: Suggested by Willem de Bruijn - Add prefix for PROBE specific defined variables - Create struct icmp_ext_echo_iio for parsing incoming packet v3 -> v4: - Use in_addr instead of __be32 for storing IPV4 addresses - Use IFNAMSIZ to statically allocate space for name in icmp_ext_echo_iio v4 -> v5: - Use __be32 instead of __u32 in defined structs --- include/uapi/linux/icmp.h | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/include/uapi/linux/icmp.h b/include/uapi/linux/icmp.h index fb169a50895e..222325d1d80e 100644 --- a/include/uapi/linux/icmp.h +++ b/include/uapi/linux/icmp.h @@ -20,6 +20,9 @@ #include #include +#include +#include +#include #define ICMP_ECHOREPLY 0 /* Echo Reply */ #define ICMP_DEST_UNREACH 3 /* Destination Unreachable */ @@ -66,6 +69,23 @@ #define ICMP_EXC_TTL 0 /* TTL count exceeded */ #define ICMP_EXC_FRAGTIME 1 /* Fragment Reass time exceeded */ +/* Codes for EXT_ECHO (PROBE) */ +#define ICMP_EXT_ECHO 42 +#define ICMP_EXT_ECHOREPLY 43 +#define ICMP_EXT_MAL_QUERY 1 /* Malformed Query */ +#define ICMP_EXT_NO_IF 2 /* No such Interface */ +#define ICMP_EXT_NO_TABLE_ENT 3 /* No such Table Entry */ +#define ICMP_EXT_MULT_IFS 4 /* Multiple Interfaces Satisfy Query */ + +/* Constants for EXT_ECHO (PROBE) */ +#define EXT_ECHOREPLY_ACTIVE (1 << 2)/* active bit in reply message */ +#define EXT_ECHOREPLY_IPV4 (1 << 1)/* ipv4 bit in reply message */ +#define EXT_ECHOREPLY_IPV6 1 /* ipv6 bit in reply message */ +#define EXT_ECHO_CTYPE_NAME 1 +#define EXT_ECHO_CTYPE_INDEX 2 +#define EXT_ECHO_CTYPE_ADDR 3 +#define ICMP_AFI_IP 1 /* Address Family Identifier for ipv4 */ +#define ICMP_AFI_IP6 2 /* Address Family Identifier for ipv6 */ struct icmphdr { __u8 type; @@ -118,4 +138,26 @@ struct icmp_extobj_hdr { __u8 class_type; }; +/* RFC 8335: 2.1 Header for c-type 3 payload */ +struct icmp_ext_echo_ctype3_hdr { + __be16 afi; + __u8 addrlen; + __u8 reserved; +}; + +/* RFC 8335: 2.1 Interface Identification Object */ +struct icmp_ext_echo_iio { + struct icmp_extobj_hdr extobj_hdr; + union { + char name[IFNAMSIZ]; + __be32 ifindex; + struct { + struct icmp_ext_echo_ctype3_hdr ctype3_hdr; + union { + struct in_addr ipv4_addr; + struct in6_addr ipv6_addr; + } ip_addr; + } addr; + } ident; +}; #endif /* _UAPI_LINUX_ICMP_H */ From patchwork Tue Mar 30 01:45:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Roeseler X-Patchwork-Id: 412340 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F21A6C433DB for ; Tue, 30 Mar 2021 01:46:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98EB461989 for ; Tue, 30 Mar 2021 01:46:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230361AbhC3Bpy (ORCPT ); Mon, 29 Mar 2021 21:45:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230210AbhC3BpZ (ORCPT ); Mon, 29 Mar 2021 21:45:25 -0400 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24C25C061762 for ; Mon, 29 Mar 2021 18:45:25 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id m21-20020a9d7ad50000b02901b83efc84a0so14099096otn.10 for ; Mon, 29 Mar 2021 18:45:25 -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:in-reply-to:references; bh=Lio5CHdjePdGCdvRLilg1iaYE0Vy2lHPlsFlnZ4SNRQ=; b=sjdiIKj8jBI94tLeS/ACxHnKtsI/g/KngzQkwxEndDXMSwJAeRwUNGSADxXXlmIA6U C2Hez6wCQys33NvpvjbxeTl3VgCekQd3yya13toFUwr+x/ipFUUvQpIOAtnWcVbfzuxD 8DlCdi/eMwyuIKstBfer8BT2RJcasqytwU8XkjTvxbp3LNhq2yf+KnqC8Lo4Y6vy0clJ ddJzDjcpaJ7O4k15eJyT5DTPf6Tz3AjNR43Ge3Hu1W4Qf8cXx/WDE7Pi4tZOxSkQYCyS 5J4zOufGQa/+L2ci9XoW6XBy0bvZOeOiWS8K5d9zG2agFOdTrk+VtZSjOVQRYn8yIgWr uplA== 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:in-reply-to :references; bh=Lio5CHdjePdGCdvRLilg1iaYE0Vy2lHPlsFlnZ4SNRQ=; b=m6JuKAo7uxyjsFaAIlz7069ZUSH1CZ4ZpiB8vkdrw5l7hkcZhA9DXPn8BarEZoUuVJ 4+EH72FSfI5liKUmGji7ALPhUgjg65TWYgT1rabJExnxwj3UCzYPztii4y6J6G/zfACb LQNIugg2DGDLtJ0lUhaKFagMfB6I93RQFewJKaEchLpNh36iJg9rnxAPTkL6YM5jifQK kFlTFxvHZmry1BvraBxKnGFtrdL3+hCAxEYhuB+jalL+tdbEI4t2EPGQe1PY3Cc+J311 v32/281dJQyvy3E/Q/tZ1S/bUWGoNI1HxzzuKdAbmutDSR2y+t3Y+SiSMI6RHuQkaTY8 5IZQ== X-Gm-Message-State: AOAM533y1UfXywAeDaI8uVq4avOfjS9ED8j1WsOIel7FJPoyW0EP9h7k OLyeLk50wsx1cS0NSc8CDiT+2kHyXDo= X-Google-Smtp-Source: ABdhPJxXp0GKhIh6inC/XImdrcx97gJ5Msdr66vaGa/tTqtyzTnAY6+vEo5nRCzb7nGf28reEMBK3Q== X-Received: by 2002:a05:6830:817:: with SMTP id r23mr24399653ots.234.1617068724556; Mon, 29 Mar 2021 18:45:24 -0700 (PDT) Received: from clinic20-Precision-T3610.hsd1.ut.comcast.net ([2601:681:8800:baf9:35b:834f:7126:8db]) by smtp.googlemail.com with ESMTPSA id j11sm3191262ooo.45.2021.03.29.18.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 18:45:24 -0700 (PDT) From: Andreas Roeseler To: netdev@vger.kernel.org Cc: davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, Andreas Roeseler Subject: [PATCH net-next V6 2/6] ICMPV6: add support for RFC 8335 PROBE Date: Mon, 29 Mar 2021 18:45:21 -0700 Message-Id: <3d570c53c4b3f4932a6011a699db06e732cb7b0c.1617067968.git.andreas.a.roeseler@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add definitions for the ICMPV6 type of Extended Echo Request and Extended Echo Reply, as defined by sections 2 and 3 of RFC 8335. Signed-off-by: Andreas Roeseler --- include/uapi/linux/icmpv6.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/uapi/linux/icmpv6.h b/include/uapi/linux/icmpv6.h index 0564fd7ccde4..ecaece3af38d 100644 --- a/include/uapi/linux/icmpv6.h +++ b/include/uapi/linux/icmpv6.h @@ -140,6 +140,9 @@ struct icmp6hdr { #define ICMPV6_UNK_OPTION 2 #define ICMPV6_HDR_INCOMP 3 +/* Codes for EXT_ECHO (PROBE) */ +#define ICMPV6_EXT_ECHO_REQUEST 160 +#define ICMPV6_EXT_ECHO_REPLY 161 /* * constants for (set|get)sockopt */ From patchwork Tue Mar 30 01:45:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Roeseler X-Patchwork-Id: 412339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2041C433E3 for ; Tue, 30 Mar 2021 01:46:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7569619B1 for ; Tue, 30 Mar 2021 01:46:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230418AbhC3Bp4 (ORCPT ); Mon, 29 Mar 2021 21:45:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230271AbhC3Bpj (ORCPT ); Mon, 29 Mar 2021 21:45:39 -0400 Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D1DBC061762 for ; Mon, 29 Mar 2021 18:45:39 -0700 (PDT) Received: by mail-oo1-xc34.google.com with SMTP id w1-20020a4adec10000b02901bc77feac3eso3425384oou.3 for ; Mon, 29 Mar 2021 18:45:39 -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:in-reply-to:references; bh=BzVco/Eg/onFpe1i6nNSzFOzajJSuv5MLzRUu8zpDpk=; b=nEN3LUPUmCnQUtgtMr2jIaiP+3pVS7r/kKKspBTA1peTUUvnL4YDv2Tvnot1iiq9pV ZzmR1lwjhiefaHx/Uzkzo+dMUL54ZAnBD17wiusrX7RZfLzTE9dmYD0G6cEtsaV4cDD3 p0AlxNqlSzcBnmy8Vg3s3/mrbSjWsmczGJDNwzW8CgcBZbyNseoGEtaXmaFmKaUNcX4k tgWXaMjMeSDEphWBgMMsc4Sb1OF6IXDZSkEOBqT3gRIyNf/orVR+TVnVnMOC8PWYUbwb zq+EeWj420/8opWVI/3k7jFT3OV9/1ez24KBA4R8KdnDcib7KIoHKaCRlWilhJpkDBnX YNqQ== 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:in-reply-to :references; bh=BzVco/Eg/onFpe1i6nNSzFOzajJSuv5MLzRUu8zpDpk=; b=h3NEFVgojYUvGWtoi4/5IyUwoO7vCinb856ruQyvbpCXpYQPrdpqUlXCnaFfRuWbUk +lCPBbKw3il83s1pYKCWTibZJVjLN9yDXlAvXHwQ54CEuzYNYeGYa2XnNHNYzbFJNdww 7zeLOya88498+LnO3xmuwpYTRVOFwCZnZ6rQTaGiUhJfUloHu++Obf0bzNYFOq3ft0P2 OLv9PPSP79rdjzCO4+o0GMQ2UGDeUzBoKATTAFaejWcz+c6A/bHHpW2CKFoEZGdcJrh8 dzGo4v7nQ/fe1lG4nLG/7sNYpEDii1mSWrY6o1qr80aGNof60GLcvAejd+ztuSeLFVOI hnJQ== X-Gm-Message-State: AOAM533YB58Zu1MC72reeGMTb4blx9BcDMc5SesK1XbHe/LwuGkoacU2 Uar6U08jFlJy0Nod8k+g3Zhgb47ir0o= X-Google-Smtp-Source: ABdhPJzzMzqvpDG6f8ESjY73TcTHQEaXMejxdpKYZb0pyxZkUJ/6wem0y4dOSegx/9TNjIEaQQUWDA== X-Received: by 2002:a4a:bd1a:: with SMTP id n26mr23435245oop.45.1617068738934; Mon, 29 Mar 2021 18:45:38 -0700 (PDT) Received: from clinic20-Precision-T3610.hsd1.ut.comcast.net ([2601:681:8800:baf9:35b:834f:7126:8db]) by smtp.googlemail.com with ESMTPSA id 9sm3810560oid.17.2021.03.29.18.45.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 18:45:38 -0700 (PDT) From: Andreas Roeseler To: netdev@vger.kernel.org Cc: davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, Andreas Roeseler Subject: [PATCH net-next V6 4/6] net: add support for sending RFC 8335 PROBE messages Date: Mon, 29 Mar 2021 18:45:36 -0700 Message-Id: <7354b0300e04d2987c63c3f22fc9c38c27773f0c.1617067968.git.andreas.a.roeseler@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Modify the ping_supported function to support PROBE message types. This allows tools such as the ping command in the iputils package to be modified to send PROBE requests through the existing framework for sending ping requests. Signed-off-by: Andreas Roeseler --- net/ipv4/ping.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c index 8b943f85fff9..1c9f71a37258 100644 --- a/net/ipv4/ping.c +++ b/net/ipv4/ping.c @@ -453,7 +453,9 @@ EXPORT_SYMBOL_GPL(ping_bind); static inline int ping_supported(int family, int type, int code) { return (family == AF_INET && type == ICMP_ECHO && code == 0) || - (family == AF_INET6 && type == ICMPV6_ECHO_REQUEST && code == 0); + (family == AF_INET && type == ICMP_EXT_ECHO && code == 0) || + (family == AF_INET6 && type == ICMPV6_ECHO_REQUEST && code == 0) || + (family == AF_INET6 && type == ICMPV6_EXT_ECHO_REQUEST && code == 0); } /* From patchwork Tue Mar 30 01:45:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Roeseler X-Patchwork-Id: 412338 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3E4FC433DB for ; Tue, 30 Mar 2021 01:46:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9A4916198F for ; Tue, 30 Mar 2021 01:46:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230402AbhC3Bq0 (ORCPT ); Mon, 29 Mar 2021 21:46:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230377AbhC3Bpz (ORCPT ); Mon, 29 Mar 2021 21:45:55 -0400 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAD78C061762 for ; Mon, 29 Mar 2021 18:45:54 -0700 (PDT) Received: by mail-oi1-x233.google.com with SMTP id d12so14928326oiw.12 for ; Mon, 29 Mar 2021 18:45:54 -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:in-reply-to:references; bh=oucHm+WlVG9Nj+s8diaqokSa755KYPpHqIvp8Wop1f0=; b=hmjaxUkp7q3SXDnSREbY4BvB1ZL1V2JQg5gl+ISmo7lB1dtRs1nEuEnUWAvQfTXCaX /YheRMyYIV5sdwkky8mjAlz5qnf4Yp7ZlO6B5dgZNvyh/l56+SBM7NySpdd84nw080ve u3fXcvkz8jN9WgjV5MtNMrFjPktvXVkDPNykR6XznC1RH4BcGrxgNOTpaRqAF4YMlv1S gm3dBsKC9fMJRRwrXFzIqcIhyoywDubs/oNu/dqC2FknZVdS/9znkI7t+o4owSXvl7ZM t5gJ2g33nuMdN/mBV5krm8Dj2388vT1bgZcYo2wMNs9Lgv2RaqEG5XfWqvoQZL2Klj03 NkDg== 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:in-reply-to :references; bh=oucHm+WlVG9Nj+s8diaqokSa755KYPpHqIvp8Wop1f0=; b=hK0pxoaPeuuh/XXrPr37sGlKlRHs0Mh5fk5gxC9/OgE/28Um/AL1mdzLA91W42nQLd LeqJCIsy9QfgrHg8ZQbovDFf1K8UlML9vI74RMmx9GC36Ak8XexZh5Lw6NZPQSPhmPzS 0lbZYLYoCZsPZktuW8Dg0Axx1ZefM6jUp2QSPA+lbwaUZ7wUPaEw8Iokfyp8IHhMAn3C eBHU1z8AxkLiwGivjT00osiTk6XlLs7z3cHnrgfedqA74MeezyAE1R5mlVAbLeb44jiu XyjVMOvTGrnERNDo89ULhkU0dQW+rFLfA7YAZaeoWs+p+yKOCiJs6lGdZikJAsAAbUPH uVMA== X-Gm-Message-State: AOAM530bIV4vpWKzQbXpmlWa2tmF0sus/ob7YLgWYr0lZEgvfg9ReO+d q6kDjoKej9GXxNRaTR2q1/lea0ymJ90= X-Google-Smtp-Source: ABdhPJw92vj588SQiQbnPgAYA1R79Fq1A98k3snNuVUXunve145eafXblfUThRejBBI1FQ+LS1cENQ== X-Received: by 2002:aca:d442:: with SMTP id l63mr1419394oig.49.1617068753981; Mon, 29 Mar 2021 18:45:53 -0700 (PDT) Received: from clinic20-Precision-T3610.hsd1.ut.comcast.net ([2601:681:8800:baf9:35b:834f:7126:8db]) by smtp.googlemail.com with ESMTPSA id d1sm4005504oop.0.2021.03.29.18.45.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 18:45:53 -0700 (PDT) From: Andreas Roeseler To: netdev@vger.kernel.org Cc: davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, Andreas Roeseler Subject: [PATCH net-next V6 6/6] icmp: add response to RFC 8335 PROBE messages Date: Mon, 29 Mar 2021 18:45:51 -0700 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Modify the icmp_rcv function to check PROBE messages and call icmp_echo if a PROBE request is detected. Modify the existing icmp_echo function to respond ot both ping and PROBE requests. This was tested using a custom modification to the iputils package and wireshark. It supports IPV4 probing by name, ifindex, and probing by both IPV4 and IPV6 addresses. It currently does not support responding to probes off the proxy node (see RFC 8335 Section 2). The modification to the iputils package is still in development and can be found here: https://github.com/Juniper-Clinic-2020/iputils.git. It supports full sending functionality of PROBE requests, but currently does not parse the response messages, which is why Wireshark is required to verify the sent and recieved PROBE messages. The modification adds the ``-e'' flag to the command which allows the user to specify the interface identifier to query the probed host. An example usage would be <./ping -4 -e 1 [destination]> to send a PROBE request of ifindex 1 to the destination node. Signed-off-by: Andreas Roeseler --- Changes: v1 -> v2: - Reorder variable declarations to follow coding style - Switch to functions such as dev_get_by_name and ip_dev_find to lookup net devices v2 -> v3: Suggested by Willem de Bruijn - Add verification of incoming messages before looking up netdev Reported-by: kernel test robot Reported-by: Dan Carpenter - Include net/addrconf.h library for ipv6_dev_find v3 -> v4: Suggested by Willem de Bruijn - Use skb_header_pointer to verify fields in incoming message - Add check to ensure that extobj_hdr.length is valid - Check to ensure object payload is padded with ASCII NULL characters when probing by name, as specified by RFC 8335 - Statically allocate buff using IFNAMSIZ - Add rcu blocking around ipv6_dev_find - Use __in_dev_get_rcu to access IPV4 addresses of identified net_device - Remove check for ICMPV6 PROBE types v4 -> v5: - Statically allocate buff to size IFNAMSIZ on declaration - Remove goto probe in favor of single branch - Remove strict check for incoming PROBE requests padding to nearest 32-bit boundary Reported-by: kernel test robot - Use rcu_dereference when accessing i6_ptr in net_device v5 -> v6: - Remove RCU locking around ipv6_dev_find() - Assign iio based on length specified by ctype --- net/ipv4/icmp.c | 134 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 121 insertions(+), 13 deletions(-) diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index 616e2dc1c8fa..76990e13a2f9 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -971,7 +971,7 @@ static bool icmp_redirect(struct sk_buff *skb) } /* - * Handle ICMP_ECHO ("ping") requests. + * Handle ICMP_ECHO ("ping") and ICMP_EXT_ECHO ("PROBE") requests. * * RFC 1122: 3.2.2.6 MUST have an echo server that answers ICMP echo * requests. @@ -979,27 +979,125 @@ static bool icmp_redirect(struct sk_buff *skb) * included in the reply. * RFC 1812: 4.3.3.6 SHOULD have a config option for silently ignoring * echo requests, MUST have default=NOT. + * RFC 8335: 8 MUST have a config option to enable/disable ICMP + * Extended Echo Functionality, MUST be disabled by default * See also WRT handling of options once they are done and working. */ static bool icmp_echo(struct sk_buff *skb) { + struct icmp_ext_hdr *ext_hdr, _ext_hdr; + struct icmp_ext_echo_iio *iio, _iio; + struct icmp_bxm icmp_param; + struct net_device *dev; + char buff[IFNAMSIZ]; struct net *net; + u16 ident_len; + u8 status; net = dev_net(skb_dst(skb)->dev); - if (!net->ipv4.sysctl_icmp_echo_ignore_all) { - struct icmp_bxm icmp_param; + /* should there be an ICMP stat for ignored echos? */ + if (net->ipv4.sysctl_icmp_echo_ignore_all) + return true; + + icmp_param.data.icmph = *icmp_hdr(skb); + icmp_param.skb = skb; + icmp_param.offset = 0; + icmp_param.data_len = skb->len; + icmp_param.head_len = sizeof(struct icmphdr); - icmp_param.data.icmph = *icmp_hdr(skb); + if (icmp_param.data.icmph.type == ICMP_ECHO) { icmp_param.data.icmph.type = ICMP_ECHOREPLY; - icmp_param.skb = skb; - icmp_param.offset = 0; - icmp_param.data_len = skb->len; - icmp_param.head_len = sizeof(struct icmphdr); - icmp_reply(&icmp_param, skb); + goto send_reply; } - /* should there be an ICMP stat for ignored echos? */ - return true; + if (!net->ipv4.sysctl_icmp_echo_enable_probe) + return true; + /* We currently only support probing interfaces on the proxy node + * Check to ensure L-bit is set + */ + if (!(ntohs(icmp_param.data.icmph.un.echo.sequence) & 1)) + return true; + /* Clear status bits in reply message */ + icmp_param.data.icmph.un.echo.sequence &= htons(0xFF00); + icmp_param.data.icmph.type = ICMP_EXT_ECHOREPLY; + ext_hdr = skb_header_pointer(skb, 0, sizeof(_ext_hdr), &_ext_hdr); + /* Size of iio is class_type dependent. + * Only check header here and assign length based on ctype in the switch statement + */ + iio = skb_header_pointer(skb, sizeof(_ext_hdr), sizeof(iio->extobj_hdr), &_iio); + if (!ext_hdr || !iio) + goto send_mal_query; + if (ntohs(iio->extobj_hdr.length) <= sizeof(iio->extobj_hdr)) + goto send_mal_query; + ident_len = ntohs(iio->extobj_hdr.length) - sizeof(iio->extobj_hdr); + status = 0; + dev = NULL; + switch (iio->extobj_hdr.class_type) { + case EXT_ECHO_CTYPE_NAME: + iio = skb_header_pointer(skb, sizeof(_ext_hdr), sizeof(_iio), &_iio); + if (ident_len >= IFNAMSIZ) + goto send_mal_query; + memset(buff, 0, sizeof(buff)); + memcpy(buff, &iio->ident.name, ident_len); + dev = dev_get_by_name(net, buff); + break; + case EXT_ECHO_CTYPE_INDEX: + iio = skb_header_pointer(skb, sizeof(_ext_hdr), sizeof(iio->extobj_hdr) + + sizeof(iio->ident.ifindex), &_iio); + if (ident_len != sizeof(iio->ident.ifindex)) + goto send_mal_query; + dev = dev_get_by_index(net, ntohl(iio->ident.ifindex)); + break; + case EXT_ECHO_CTYPE_ADDR: + if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + + iio->ident.addr.ctype3_hdr.addrlen) + goto send_mal_query; + switch (ntohs(iio->ident.addr.ctype3_hdr.afi)) { + case ICMP_AFI_IP: + iio = skb_header_pointer(skb, sizeof(_ext_hdr), sizeof(iio->extobj_hdr) + + sizeof(struct in_addr), &_iio); + if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + + sizeof(struct in_addr)) + goto send_mal_query; + dev = ip_dev_find(net, iio->ident.addr.ip_addr.ipv4_addr.s_addr); + break; +#if IS_ENABLED(CONFIG_IPV6) + case ICMP_AFI_IP6: + iio = skb_header_pointer(skb, sizeof(_ext_hdr), sizeof(_iio), &_iio); + if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + + sizeof(struct in6_addr)) + goto send_mal_query; + dev = ipv6_stub->ipv6_dev_find(net, &iio->ident.addr.ip_addr.ipv6_addr, dev); + if (dev) + dev_hold(dev); + break; +#endif + default: + goto send_mal_query; + } + break; + default: + goto send_mal_query; + } + if (!dev) { + icmp_param.data.icmph.code = ICMP_EXT_NO_IF; + goto send_reply; + } + /* Fill bits in reply message */ + if (dev->flags & IFF_UP) + status |= EXT_ECHOREPLY_ACTIVE; + if (__in_dev_get_rcu(dev) && __in_dev_get_rcu(dev)->ifa_list) + status |= EXT_ECHOREPLY_IPV4; + if (!list_empty(&rcu_dereference(dev->ip6_ptr)->addr_list)) + status |= EXT_ECHOREPLY_IPV6; + dev_put(dev); + icmp_param.data.icmph.un.echo.sequence |= htons(status); +send_reply: + icmp_reply(&icmp_param, skb); + return true; +send_mal_query: + icmp_param.data.icmph.code = ICMP_EXT_MAL_QUERY; + goto send_reply; } /* @@ -1088,6 +1186,16 @@ int icmp_rcv(struct sk_buff *skb) icmph = icmp_hdr(skb); ICMPMSGIN_INC_STATS(net, icmph->type); + + /* Check for ICMP Extended Echo (PROBE) messages */ + if (icmph->type == ICMP_EXT_ECHO) { + /* We can't use icmp_pointers[].handler() because it is an array of + * size NR_ICMP_TYPES + 1 (19 elements) and PROBE has code 42. + */ + success = icmp_echo(skb); + goto success_check; + } + /* * 18 is the highest 'known' ICMP type. Anything else is a mystery * @@ -1097,7 +1205,6 @@ int icmp_rcv(struct sk_buff *skb) if (icmph->type > NR_ICMP_TYPES) goto error; - /* * Parse the ICMP message */ @@ -1123,7 +1230,7 @@ int icmp_rcv(struct sk_buff *skb) } success = icmp_pointers[icmph->type].handler(skb); - +success_check: if (success) { consume_skb(skb); return NET_RX_SUCCESS; @@ -1340,6 +1447,7 @@ static int __net_init icmp_sk_init(struct net *net) /* Control parameters for ECHO replies. */ net->ipv4.sysctl_icmp_echo_ignore_all = 0; + net->ipv4.sysctl_icmp_echo_enable_probe = 0; net->ipv4.sysctl_icmp_echo_ignore_broadcasts = 1; /* Control parameter - ignore bogus broadcast responses? */