From patchwork Wed Feb 17 18:07:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Roeseler X-Patchwork-Id: 12092007 X-Patchwork-Delegate: kuba@kernel.org 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.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,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 9435FC433DB for ; Wed, 17 Feb 2021 18:08:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 625B864DEC for ; Wed, 17 Feb 2021 18:08:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234754AbhBQSIo (ORCPT ); Wed, 17 Feb 2021 13:08:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231817AbhBQSIg (ORCPT ); Wed, 17 Feb 2021 13:08:36 -0500 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F9EFC061756 for ; Wed, 17 Feb 2021 10:07:56 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id o7so8992359pgl.1 for ; Wed, 17 Feb 2021 10:07:56 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=mq4jIowVCJDBpsMy8oSEIRebwN9HreAuVKbDCOXh2ug=; b=a01YoAoaPSTUufe0H+c33gJSkp7O5VzMZ9IG15S6teFnvF/Xi8v1w05KuwaBcGJ9Ch yVVJfGdeqZ0LsL7gOat+nhMwaTDsZOiVAb9H1U/wSu/ZZS0HeYuWAN3ah4MYKxEygNdQ pvZEJxDxX2L+jfra6fASzkEwB2vlbVvRckkcOiBUA9G4pnKyZ6rtvxmUQj47UslDQKiG QbsP2fBoCKwnmVhBcEmCE4qcgDwkeCJ0wmU9jPeWRVV7qA2Dsf0joxSi/rxBtKiSuKIF T/eWtD32ZWXhi7rzyRGFnEGxkbvPQ5YzDAE1Lo18jHfDm0bbMCfbr6MmLe5VvZRIeKOm KrfQ== 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:mime-version:content-transfer-encoding; bh=mq4jIowVCJDBpsMy8oSEIRebwN9HreAuVKbDCOXh2ug=; b=WbjVZ0/ddHKNygJoLw2dpwm/xzytkGqkDP57Fb8k5C3qvFxW4fxjcZnfiBx2c5IWkj IcEd+fbC3njvmOLimk+5EHZjjd6/00ur4WY7DNAkhOu9rsHxDitdrkOvQ6ybUMeaAv8l 4p6kFSX+4NlC4t/uJWxnTxl1TEAp/8VXueEySqORnCjes9SLgZf/4p8Ah502q8hFLuHe IKS3q5/m+Xc5Yg18JEnOGvi2J2XeD/OirWB9CELB0ogHfZJKKZs1v47Il4vU3UXoxN0e Dmujzd5jVqXENnV9y+z1pDIKppdTMzSlV9kS1x8BJwHZ+KHjmoSd/HR0aEuMogXn5IC5 GwXg== X-Gm-Message-State: AOAM530b1Lg64D8mJVLazOHNG+ckOXDo1XOw6zRhEyy2FbmA3wYCyTMj j/BUPjoNOhrI5tx+3Wvmrgo= X-Google-Smtp-Source: ABdhPJzxSho5+xQ+Q1Y77DqHDhxSRpptAPXY1oYKY8NFFuCAnf3kSITcTVVcTtT0Nlgh60Y4dLK5iQ== X-Received: by 2002:a63:c148:: with SMTP id p8mr536825pgi.188.1613585275749; Wed, 17 Feb 2021 10:07:55 -0800 (PST) Received: from localhost.localdomain (h134-215-166-75.lapior.broadband.dynamic.tds.net. [134.215.166.75]) by smtp.gmail.com with ESMTPSA id w3sm2902460pjt.4.2021.02.17.10.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 10:07:55 -0800 (PST) From: Andreas Roeseler To: davem@davemloft.net Cc: yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, netdev@vger.kernel.org Subject: [PATCH V3 net-next 1/5] icmp: add support for RFC 8335 PROBE Date: Wed, 17 Feb 2021 10:07:54 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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 since v1: - Add AFI_IP and AFI_IP6 definitions Changes since v2: Suggested by Willem de Brujin - Add prefix for PROBE specific defined variables - Create struct icmp_ext_echo_iio for parsing incoming packet --- include/uapi/linux/icmp.h | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/include/uapi/linux/icmp.h b/include/uapi/linux/icmp.h index fb169a50895e..166ca77561de 100644 --- a/include/uapi/linux/icmp.h +++ b/include/uapi/linux/icmp.h @@ -66,6 +66,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)/* position of active flag in reply */ +#define EXT_ECHOREPLY_IPV4 (1 << 1)/* position of ipv4 flag in reply */ +#define EXT_ECHOREPLY_IPV6 1 /* position of ipv6 flag in reply */ +#define EXT_ECHO_CTYPE_NAME 1 +#define EXT_ECHO_CTYPE_INDEX 2 +#define EXT_ECHO_CTYPE_ADDR 3 +#define EXT_ECHO_AFI_IP 1 /* Address Family Identifier for IPV4 */ +#define EXT_ECHO_AFI_IP6 2 /* Address Family Identifier for IPV6 */ struct icmphdr { __u8 type; @@ -118,4 +135,27 @@ struct icmp_extobj_hdr { __u8 class_type; }; +/* RFC 8335: 2.1 Header for C-type 3 payload */ +struct icmp_ext_echo_ctype3_hdr { + __u16 afi; + __u8 addrlen; + __u8 reserved; +}; + +/* RFC 8335: Interface Identification Object */ +struct icmp_ext_echo_iio { + struct icmp_extobj_hdr extobj_hdr; + union { + __u32 ifIndex; + char name; + struct { + struct icmp_ext_echo_ctype3_hdr ctype3_hdr; + union { + __be32 ipv4_addr; + struct in6_addr ipv6_addr; + } ip_addr; + } addr; + } ident; +}; + #endif /* _UAPI_LINUX_ICMP_H */ From patchwork Wed Feb 17 18:08:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Roeseler X-Patchwork-Id: 12092009 X-Patchwork-Delegate: kuba@kernel.org 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.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,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 A650AC433E9 for ; Wed, 17 Feb 2021 18:08:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 78E2E64E5B for ; Wed, 17 Feb 2021 18:08:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234776AbhBQSIr (ORCPT ); Wed, 17 Feb 2021 13:08:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234761AbhBQSIo (ORCPT ); Wed, 17 Feb 2021 13:08:44 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 981F7C0613D6 for ; Wed, 17 Feb 2021 10:08:04 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id t25so8994998pga.2 for ; Wed, 17 Feb 2021 10:08:04 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=6OppbIT1M1gvXOWsdS8QHmLhNPa/v+vgtcvDuscwBAU=; b=UqtIF1fr5ZmskUEOK8hSkSQ8fRyP/pvxLOfAusV3ShQaA0M/mSrmMhf03LQ6TAxvLq WdudHxyU5d44PHDb0t/Zwjf+Zii8Gr5DMZb4h80GWVKsO/CrCVuuCK0Z0U1on5YtHyNM lDcCcvXS6RfSdWmhZrANEfSQ0jVBbvsxLS0nt5gwCz4HHBi3XMlZmQRtU5WKoW0nPqpa 8CylD5V5Cr5aH8aRGiwtIhHH6BXwcsSuOAW1kuxgT/aScDCNpcjZW5cAyLbYt/sMsMyZ 3hsZTj1S3Dji9Ej70ztpEtoyx7UE740q/PmfZpiBJiM1egjuukUxbqPZPwf9RimJejnu niYQ== 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:mime-version:content-transfer-encoding; bh=6OppbIT1M1gvXOWsdS8QHmLhNPa/v+vgtcvDuscwBAU=; b=C8gEEmxnues5Nek+JiZMFu3RJf3CH3joZ+l86VmuQvRZ0d/sISGJi9nVVblzuwt7BK KgiZw8yVkrMjm6QwmKoUVENwfou1AKZQwp+pVz02oDtaLuhR2DShjlyegQwYj7RyVQvL ErcX6xEIFbMEFkUWSrYtQym1pChu125YvEt+ahUstTe5CBKTz/OApivx57WOThmrwlUt KJY9yDRpjSQ8/4Rg0KLhjQDQDbWE4z0Dxi4YVo3tZJPGclryImkmSHRB9nAPzB9Fvu3Z ryDkqWajDrjg8gmj2hzK8YS+s1CZCnvLgIH/sXMP6pKdVKk6L6xkmw8M87CyWzDuM8kC wP0Q== X-Gm-Message-State: AOAM53293Ifiz8Ov20eG1EQlEj96KEZ2twu5+NVefE+rf6OSgijWIIpy 52bmyy6aNafpXgYbDuOgk4Q= X-Google-Smtp-Source: ABdhPJwPH0jjNOVx6BoIrg3vvVurrhycb+v2NB2NtP5Ivk9BTPDKdHQIjOBE5vVoLK00rMx8OdJ05w== X-Received: by 2002:a05:6a00:2286:b029:1ae:6c7f:31ce with SMTP id f6-20020a056a002286b02901ae6c7f31cemr507610pfe.6.1613585284239; Wed, 17 Feb 2021 10:08:04 -0800 (PST) Received: from localhost.localdomain (h134-215-166-75.lapior.broadband.dynamic.tds.net. [134.215.166.75]) by smtp.gmail.com with ESMTPSA id m23sm3181293pgv.14.2021.02.17.10.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 10:08:03 -0800 (PST) From: Andreas Roeseler To: davem@davemloft.net Cc: yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, netdev@vger.kernel.org Subject: [PATCH V3 net-next 2/5] ICMPV6: add support for RFC 8335 PROBE Date: Wed, 17 Feb 2021 10:08:03 -0800 Message-Id: <8eb733939ea7b22513ba6682571d1a44f651cf55.1613583620.git.andreas.a.roeseler@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add definitions for the ICMPV6 type of Extended Echo Request and Extended Echo Reply, as defined in sections 2 and 3 of RFC 8335. Signed-off-by: Andreas Roeseler --- include/uapi/linux/icmpv6.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/uapi/linux/icmpv6.h b/include/uapi/linux/icmpv6.h index 0564fd7ccde4..b2a9017ddb2d 100644 --- a/include/uapi/linux/icmpv6.h +++ b/include/uapi/linux/icmpv6.h @@ -140,6 +140,12 @@ 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 Wed Feb 17 18:08:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Roeseler X-Patchwork-Id: 12092011 X-Patchwork-Delegate: kuba@kernel.org 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.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,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 A7293C433DB for ; Wed, 17 Feb 2021 18:09:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6400464E42 for ; Wed, 17 Feb 2021 18:09:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232969AbhBQSI5 (ORCPT ); Wed, 17 Feb 2021 13:08:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232913AbhBQSIx (ORCPT ); Wed, 17 Feb 2021 13:08:53 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA0E1C061786 for ; Wed, 17 Feb 2021 10:08:12 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id t11so8972736pgu.8 for ; Wed, 17 Feb 2021 10:08:12 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=TrX1T47rpnOsKpdHaCeKXRVaeQNpP+K3spEqPXN+7r0=; b=Wd2EUxsW4/AF+UUmIvrHr04egQihLwvlQ/XKaBzqlQ3oh2Rw/LxcgoxM7gR+F67csS znaCol9fr/banJtu0Jo7WT+uRCOVnXODWH830cSZF+unb0pYGdjhukapglEYGisWFIHh QQUEgHwOMPNFu5lNDWM5qlEL76qvSYSdfrHrhGgK39oasQfr7oJgw72/kMQO7YDqoNBE +N+ZiubZJCwdRYfMVOcgHXkCNkjHmihd1iYP7bxbLZXdnlUQNq3WuhtwDuFkMZeeqbOI j17ugd1+PdWzsYG/1K1BfpHl4v1QqqnrTnXGF5BHtgWnTy4BK6jl/S0f3hZAK/k2P/f8 etWQ== 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:mime-version:content-transfer-encoding; bh=TrX1T47rpnOsKpdHaCeKXRVaeQNpP+K3spEqPXN+7r0=; b=beGKxSf222OMVbcLG7F9PJQLXwvv0kfPrHcfGshfRi+PbSYvbs/zKUGkgzIBcUR4ki LY5UnPrFrZc+l+HcQC/8kqRpkhl3/R6OwJD85Na93DiR0Mg0kODv3HEaGj5IsgA0YkGX G1nVnYfCStTxfvOWbz0YP6b3M36+wuzZ5xbwEbrtyXacFhsKzDp/NaK16djK5nqts8DI Ji0gFcNX4vsZyym/nWcBsJTjaFMR2ThQpTALkpJRjzQua7INjnFKikqyK6yh6fDBVHiH uS/wVC6iB4MXtYlit7bdd6/Fkf062VMPE949hr+Z07EMZhbvVz1UzDd/5D9lNJjQ5PqF 3uzg== X-Gm-Message-State: AOAM531lXPObM18wrEUUoizwxPSsMR3G8CWMpWtQngPS4e+NGJQLRF9S wUxAc3n/0IlGk+Qqm9uAmIU= X-Google-Smtp-Source: ABdhPJwAEf7kh04WdHU0/gWRjAd0mglw1LVBp2Q77pr5Lvx6iniKHFGWedJfCt/v8u8IgiBJNc2/Qw== X-Received: by 2002:a63:cc05:: with SMTP id x5mr523347pgf.254.1613585290877; Wed, 17 Feb 2021 10:08:10 -0800 (PST) Received: from localhost.localdomain (h134-215-166-75.lapior.broadband.dynamic.tds.net. [134.215.166.75]) by smtp.gmail.com with ESMTPSA id q15sm2820084pja.22.2021.02.17.10.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 10:08:10 -0800 (PST) From: Andreas Roeseler To: davem@davemloft.net Cc: yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, netdev@vger.kernel.org Subject: [PATCH V3 net-next 3/5] net: add sysctl for enabling RFC 8335 PROBE messages Date: Wed, 17 Feb 2021 10:08:09 -0800 Message-Id: <4061fa49b789385eb6de616128c8472dacce9896.1613583620.git.andreas.a.roeseler@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Section 8 of RFC 8335 specifies potential security concerns of responding to PROBE requests, and states that nodes that support PROBE functionality MUST be able to enable/disable responses and it is disabled by default. Add sysctl to enable responses to PROBE messages. Signed-off-by: Andreas Roeseler --- Changes since v1: - Combine patches related to sysctl into one patch Changes since v2: Suggested by Willem de Brujin - Use proc_dointvec_minmax with zero and one --- include/net/netns/ipv4.h | 1 + net/ipv4/sysctl_net_ipv4.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h index 70a2a085dd1a..362388ab40c8 100644 --- a/include/net/netns/ipv4.h +++ b/include/net/netns/ipv4.h @@ -85,6 +85,7 @@ struct netns_ipv4 { #endif int sysctl_icmp_echo_ignore_all; + int sysctl_icmp_echo_enable_probe; int sysctl_icmp_echo_ignore_broadcasts; int sysctl_icmp_ignore_bogus_error_responses; int sysctl_icmp_ratelimit; diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index f55095d3ed16..fec3f142d8c9 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -599,6 +599,15 @@ static struct ctl_table ipv4_net_table[] = { .mode = 0644, .proc_handler = proc_dointvec }, + { + .procname = "icmp_echo_enable_probe", + .data = &init_net.ipv4.sysctl_icmp_echo_enable_probe, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE + }, { .procname = "icmp_echo_ignore_broadcasts", .data = &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts, From patchwork Wed Feb 17 18:08:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Roeseler X-Patchwork-Id: 12092013 X-Patchwork-Delegate: kuba@kernel.org 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.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,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 C26ECC433E0 for ; Wed, 17 Feb 2021 18:09:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8466D64DEC for ; Wed, 17 Feb 2021 18:09:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233069AbhBQSJK (ORCPT ); Wed, 17 Feb 2021 13:09:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232913AbhBQSI6 (ORCPT ); Wed, 17 Feb 2021 13:08:58 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 833C6C061788 for ; Wed, 17 Feb 2021 10:08:18 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id m2so8982680pgq.5 for ; Wed, 17 Feb 2021 10:08:18 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=cCET9WBqWjygW6XCStVpWhmRU/4x/+TmAJlTpAVop6s=; b=p+IaIuWFFkmokc3g4KwFW6xT4Tn0Q5L7nmb+PFWe4DDAek9JQxTI7OaObBWnEk4iBN cCQLMT32L8JdRRD9SLR0yiCq6t75mVo7E5cxblodQutlJPGfRLXEdW67SoOV/0UVpx+F tezdyTB+JclEV7CsS7UrkWNJ3liO0FkYfOrQzzovepfur5fD5xAA0vwcDsg9QXODrTiX BvgNIMbAPNcd8JHqewK5O7q4aqNAGWUHzUzijIDTwYCmy4rE4HKGvIAksz04amobnMT0 FrkCHgf2eFD4HceY0VDaRVaEH294g7+x280SjKCeq3zbyawW6XwyPclarWAbuk21kiMf eyTA== 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:mime-version:content-transfer-encoding; bh=cCET9WBqWjygW6XCStVpWhmRU/4x/+TmAJlTpAVop6s=; b=M6H+g7Zz6X2tW0hl9/ccppF1zjnWnss5Jmhhh0rNrw1QrCkWtUXA4qwTPTSna67pci oABXn3nHKhadxmpJpcstA7qnW6c+foZN9CwZCoAkZdVBtfz+qT9GA2ll2nINe4Nb2G6Z d0kuVfNEz1OXoiGcgxGv6g9qepJ8BipHsohQl7KVYy79W4pBRlWtsIsdINsdQc55B5Y8 pu0zuiMivlJUqzGBRZEGw8NujCBpM2coBJkN5VVA36Dp/NA3q7jSVJnjEuyn3ix11R1d 5yoFAtIOQLprqtxgssAxWaI4l22NOBbQOl2A0MfvPu40azMb8eacuoBqEFfJ1zf6/dZ7 afIQ== X-Gm-Message-State: AOAM5310HabAv1J2lYnpmafO4N9we75BxlSRtiDkv9njTG8fDYujerLV KlGIFYNrYpKZDejb95ISjIo= X-Google-Smtp-Source: ABdhPJwO7YJsdZRY2QF410cH7sMhkTu2z5r+XEn6NbmaAn07Kwl8WN+GXYAlKUshCRoTd0fdaQJaDA== X-Received: by 2002:a63:2254:: with SMTP id t20mr537205pgm.230.1613585298158; Wed, 17 Feb 2021 10:08:18 -0800 (PST) Received: from localhost.localdomain (h134-215-166-75.lapior.broadband.dynamic.tds.net. [134.215.166.75]) by smtp.gmail.com with ESMTPSA id s7sm3218558pgb.89.2021.02.17.10.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 10:08:17 -0800 (PST) From: Andreas Roeseler To: davem@davemloft.net Cc: yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, netdev@vger.kernel.org Subject: [PATCH V3 net-next 4/5] net: add support for sending RFC 8335 PROBE messages Date: Wed, 17 Feb 2021 10:08:16 -0800 Message-Id: <4b9b6324310cfea00e8f8a0c0dea2c35134ee2e0.1613583620.git.andreas.a.roeseler@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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 Wed Feb 17 18:08:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Roeseler X-Patchwork-Id: 12092015 X-Patchwork-Delegate: kuba@kernel.org 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.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,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 DD225C433E6 for ; Wed, 17 Feb 2021 18:09:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4AF664E5B for ; Wed, 17 Feb 2021 18:09:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233119AbhBQSJP (ORCPT ); Wed, 17 Feb 2021 13:09:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233050AbhBQSJH (ORCPT ); Wed, 17 Feb 2021 13:09:07 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2514C06178A for ; Wed, 17 Feb 2021 10:08:25 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id p21so3319413pgl.12 for ; Wed, 17 Feb 2021 10:08:25 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=bNo72LUMDna5zhFukHr7znkipTWgQyuQ1sN47ZJAVmA=; b=gAMDv0rI0i9jFX3QGbU9ouhiPpGYLLCmDJHeq+ZO70kSgtvylm9U8SuixrwgQ22vGA 8Y8/vQ9pJVxfRHWjzwHQdPGnO96TNEX0RiZKuthn62I9cq60rbQ+xloT+hJ3qKEu9i8a XwPgXDbQq7H75UKpxdOlM/DKG7rj+oliAKA7fsxTInYKC3JIsHYg9ytzYQdCUjt5HBX4 /nqdYcQYMf/GZgSFaGOV6WrqXuxPL1CN30jbcIf745yg2LtxArfpz4HC1f2I/w8vg7l/ S3wihItXFXoMCsyenH1yqKnJA4xBbq/hFfM805ZZPgi2b41zkigbZfSYosfEpBDyern2 l1zA== 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:mime-version:content-transfer-encoding; bh=bNo72LUMDna5zhFukHr7znkipTWgQyuQ1sN47ZJAVmA=; b=jk71RIPmdyfchboMpzZTjvwKw1wHG9tsYHTtYoYsU20uJWBjSC8DlCL7ViY+cf3ioL fNoB+zqhAr2Rk7Qsje/Slde35janzJ6eNUsVMcM0Wyor8vdphRKw21ECdN5uwflfWP1x nEC3MVCx53gEQ+IlL/cAPHeHyKTwyJXa3sYVfVrMBkr/G3pnwhvdZ2+Z6B9jXPfHIA9v GweLn1tSQqejs7ciXDPuNQVw4M+8CNySiGdN5Vr+P13FmEWtz+ruy/FsdB0lmZ+stuyA f6Fe8LwjSKpUGmBLTPlfzYk+UDI2PIekMETQdSwSO+ta2yh1vkJs32KbHFJ59g77NesZ 760Q== X-Gm-Message-State: AOAM5332Xh4MVfVdpfyP9RJ0x/21HkFWs0bGmu1E10Ec/VH9ynxG8tea sHzLu3RYyCUFPuAYkJlBQ/M= X-Google-Smtp-Source: ABdhPJwDje4odMop+swzmcBx8j+ddUOvgaq723PlC3p+Vb7xtUOWBMtpq9ZN+yJMPX4tj+wq2kiDSQ== X-Received: by 2002:a63:4504:: with SMTP id s4mr539958pga.184.1613585305376; Wed, 17 Feb 2021 10:08:25 -0800 (PST) Received: from localhost.localdomain (h134-215-166-75.lapior.broadband.dynamic.tds.net. [134.215.166.75]) by smtp.gmail.com with ESMTPSA id m16sm3219705pfd.203.2021.02.17.10.08.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 10:08:25 -0800 (PST) From: Andreas Roeseler To: davem@davemloft.net Cc: yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, netdev@vger.kernel.org, kernel test robot , Dan Carpenter Subject: [PATCH V3 net-next 5/5] icmp: add response to RFC 8335 PROBE messages Date: Wed, 17 Feb 2021 10:08:24 -0800 Message-Id: <7bff18c2cffe77b2ea66fd8774a5d0374ff6dd97.1613583620.git.andreas.a.roeseler@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Modify the icmp_rcv function to check for PROBE messages and call icmp_echo if a PROBE request is detected. Modify the existing icmp_echo function to respond to both ping and PROBE requests. This was tested using a custom modification of 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). Signed-off-by: Andreas Roeseler --- Changes since v1: - Reorder variable declarations to follow coding style - Switch to functions such as dev_get_by_name and ip_dev_find to lookup net devices Changes since v2: Suggested by Willem de Brujin - 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 --- net/ipv4/icmp.c | 133 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 122 insertions(+), 11 deletions(-) diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index 396b492c804f..3caca9f2aa07 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -92,6 +92,7 @@ #include #include #include +#include /* * Build xmit assembly blocks @@ -970,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. @@ -978,26 +979,122 @@ 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_echo_iio *iio; + struct icmp_ext_hdr *ext_hdr; + struct icmp_bxm icmp_param; + struct net_device *dev; struct net *net; + __u16 ident_len; + __u8 status; + char *buff; 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.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); + 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? */ + 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 = (struct icmp_ext_hdr *)(icmp_hdr(skb) + 1); + iio = (struct icmp_ext_echo_iio *)(ext_hdr + 1); + 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: + if (ident_len >= skb->len - sizeof(struct icmphdr) - sizeof(iio->extobj_hdr)) { + icmp_param.data.icmph.code = ICMP_EXT_MAL_QUERY; + goto send_reply; + } + buff = kcalloc(ident_len + 1, sizeof(char), GFP_KERNEL); + if (!buff) + return -ENOMEM; + memcpy(buff, &iio->ident.name, ident_len); + dev = dev_get_by_name(net, buff); + kfree(buff); + break; + case EXT_ECHO_CTYPE_INDEX: + if (ident_len != sizeof(iio->ident.ifIndex)) { + icmp_param.data.icmph.code = ICMP_EXT_MAL_QUERY; + goto send_reply; + } + dev = dev_get_by_index(net, ntohl(iio->ident.ifIndex)); + break; + case EXT_ECHO_CTYPE_ADDR: + switch (ntohs(iio->ident.addr.ctype3_hdr.afi)) { + case EXT_ECHO_AFI_IP: + if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + sizeof(__be32) || + ident_len != sizeof(iio->ident.addr.ctype3_hdr) + iio->ident.addr.ctype3_hdr.addrlen) { + icmp_param.data.icmph.code = ICMP_EXT_MAL_QUERY; + goto send_reply; + } + dev = ip_dev_find(net, iio->ident.addr.ip_addr.ipv4_addr); + break; + case EXT_ECHO_AFI_IP6: + if (ident_len != sizeof(iio->ident.addr.ctype3_hdr) + sizeof(struct in6_addr) || + ident_len != sizeof(iio->ident.addr.ctype3_hdr) + iio->ident.addr.ctype3_hdr.addrlen) { + icmp_param.data.icmph.code = ICMP_EXT_MAL_QUERY; + goto send_reply; + } + dev = ipv6_dev_find(net, &iio->ident.addr.ip_addr.ipv6_addr, dev); + if (dev) + dev_hold(dev); + break; + default: + icmp_param.data.icmph.code = ICMP_EXT_MAL_QUERY; + goto send_reply; + } + break; + default: + icmp_param.data.icmph.code = ICMP_EXT_MAL_QUERY; + goto send_reply; + } + if (!dev) { + icmp_param.data.icmph.code = ICMP_EXT_NO_IF; + goto send_reply; + } + /* RFC 8335: 3 the last 8 bits of the Extended Echo Reply Message + * are laid out as follows: + * +-+-+-+-+-+-+-+-+ + * |State|Res|A|4|6| + * +-+-+-+-+-+-+-+-+ + */ + if (dev->flags & IFF_UP) + status |= EXT_ECHOREPLY_ACTIVE; + if (dev->ip_ptr->ifa_list) + status |= EXT_ECHOREPLY_IPV4; + if (!list_empty(&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; } @@ -1087,6 +1184,13 @@ 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 || icmph->type == ICMPV6_EXT_ECHO_REQUEST) + goto probe; + /* * 18 is the highest 'known' ICMP type. Anything else is a mystery * @@ -1096,7 +1200,6 @@ int icmp_rcv(struct sk_buff *skb) if (icmph->type > NR_ICMP_TYPES) goto error; - /* * Parse the ICMP message */ @@ -1123,6 +1226,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; @@ -1136,6 +1240,13 @@ int icmp_rcv(struct sk_buff *skb) error: __ICMP_INC_STATS(net, ICMP_MIB_INERRORS); goto drop; +probe: + /* + * We can't use icmp_pointers[].handler() because the codes for PROBE + * messages are 42 or 160 + */ + success = icmp_echo(skb); + goto success_check; } static bool ip_icmp_error_rfc4884_validate(const struct sk_buff *skb, int off)