From patchwork Mon Mar 5 05:24:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 1685 Return-Path: Received: from mail01.ipfire.org (mail01.ipfire.org [IPv6:2001:470:7183:25::1]) by web02.i.ipfire.org (Postfix) with ESMTP id 52F066095C for ; Sun, 4 Mar 2018 19:25:13 +0100 (CET) X-Virus-Scanned: ClamAV at mail01.ipfire.org X-Spam-Flag: NO X-Spam-Score: -1.099 X-Spam-Level: X-Spam-Status: No, score=-1.099 tagged_above=-999 required=5 tests=[ALL_TRUSTED=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mail01.i.ipfire.org (localhost [IPv6:::1]) by mail01.ipfire.org (Postfix) with ESMTP id 9D1A1111C4E7; Sun, 4 Mar 2018 18:25:11 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ipfire.org; s=201801; t=1520187911; x=1522779911; bh=vk8T44O+2tyeftOhecGS5EHNyzjzaLy8t4R2gfBeazw=; h=From:To:Subject:Date:Message-Id:Sender:From:To:Cc:Date: Content-Type:Message-ID:In-Reply-To:Subject:Reply-To:Sender; b=pit/7oz7LOKvVzo3nt199Zb5uAMuDzoyAn56F43KfwAA2slXGk+Ld3SSsxfifUm6I OCrnV2tfsD7X//VlS1MXxaiZyrDpqDL0OGxrAYM1qlFPZBlCUdMH73YwHh0HUyhKV1 qfdp58USCF7srprp8w35xF9XI3BIdKY5lFiqr/z/y/dOt3430bmyiOtD369eCdY4o4 dXPQ7wY2Ko7rEjCqfenkJdmJe13VPlxE//aOWCiCgd8d9viP+mgINymo5fx/Ns50yj qgZY0sk1ycAkWAmDf/FMoQNGD2ZYtmSxUy33mGAyu8JkJfP7oyclg/yUcaghwSZ38S +/FPjy4Qir99g== X-Virus-Scanned: ClamAV at mail01.ipfire.org Received: from localhost.localdomain (unknown [46.183.103.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 3A138111C4E7; Sun, 4 Mar 2018 18:25:09 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ipfire.org; s=201801; t=1520187909; x=1522779909; bh=vk8T44O+2tyeftOhecGS5EHNyzjzaLy8t4R2gfBeazw=; h=From:To:Cc:Subject:Date:Message-Id:From:To:Cc:Date:Content-Type: Message-ID:In-Reply-To:Subject:Reply-To:Sender; b=DB5h2Do+ANGR2ONq1eMIAaX87b/hR601KBQnaM/vt9kd0yhmHXh5If3Lg20wOuVTJ OF3x4yrqA8olQTf+PGvqMBS5BtCdfb/Ukol9AgUOCTyGamHP2RgkncDM3azzs5B3RA dhjnPmaD3ugU7sD+MwQ20DPF5yxgLRzBLbZGnfDk1oGiAE6RKDu/8LGDimeA3KOYd0 r8rAXG0yXSYfhGk7y5dXDgOx0lY4xJB625t67XOsEOB1wLzX5+2rcwKBVGXzQKtFTt 3JlUKd/bLS1CzwSWPtVu3iRaZ36e33vIlDoHLWO4pzGSRwS3m7/7hMQcek/4A4g37g ubg5A+AJJJVfw== From: Jonatan Schlag To: network@lists.ipfire.org Subject: [PATCH 1/5] ip-tunnel: add new function Date: Sun, 4 Mar 2018 18:24:55 +0000 Message-Id: <1520187899-5759-1-git-send-email-jonatan.schlag@ipfire.org> X-Mailer: git-send-email 2.6.3 X-BeenThere: network@lists.ipfire.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List for the network package List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: network-bounces@lists.ipfire.org Sender: "network" To be undependent from the IP protocol we use, when we use tunnel modes in our code, this function converts the modes to the modes the iproute2 tool uses which often depend on the IP protocol version. Signed-off-by: Jonatan Schlag --- src/functions/functions.ip-tunnel | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/functions/functions.ip-tunnel b/src/functions/functions.ip-tunnel index 7bb4e3f..550b0b3 100644 --- a/src/functions/functions.ip-tunnel +++ b/src/functions/functions.ip-tunnel @@ -21,6 +21,34 @@ IP_TUNNEL_MODES="gre sit vti" +# This function converts our modes into the type +# the iproute2 tool uses +ip_tunnel_convert_mode_to_iproute2_mode() { + local mode=${1} + local protocol=${2} + + if ! isset mode || ! isset protocol; then + log ERROR "Did not get mode and/or protocol" + return ${EXIT_ERROR} + fi + + if [[ "${protocol}" = "ipv4" ]]; then + # When we use IPv4 we can use our modes + echo "${mode}" + fi + + if [[ "${protocol}" = "ipv6" ]]; then + # When we use IPv6 we have to convert + case "${mode}" in + "vti") + echo "vti6" + ;; + "gre") + echo "ip6gre" + esac + fi +} + ip_tunnel_add() { local device=${1} shift