From patchwork Fri Nov 4 06:20:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Vehlow X-Patchwork-Id: 1699336 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=yRJJg2s8; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=jv-coder.de header.i=@jv-coder.de header.a=rsa-sha256 header.s=dkim header.b=dG25XEnU; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N3VwX5hY9z23ly for ; Fri, 4 Nov 2022 17:25:00 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=L+Z1XlXODjL5xUjyTmU2o74fvwELuOvdl9Hk1DyoNMY=; b=yRJJg2s83Rc0es r0s5Kt+P+GdatXxGDm2GfIV1HiLoabauibMir2ADB6FEwILA6PKKXqgSDInligHU25X81hlyKmGC/ Xnt+wcvG+MFu9YqNUDlGMfqxlKgKCYTB0lcRQgBeydjQCHdno4bHOh5BwINZjChx9qYV3N1doX/j8 sA2cRFmHT/T+sGXyk6yHYbaOHys8S9N1BrVRCMuyGCE/V6p3lVdyXgzMT9Jy6zFxDWUlHC1F8pN6X DJl6PBM/wvX3pjkD5EkXWr2i7TrElhh+419DWwZlR9gLXjozQy2vcN0eGfXsNry4AR+nk8/soIXes 6YBPvtqDQwZop6KRwp+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqq5P-002VxY-7z; Fri, 04 Nov 2022 06:21:51 +0000 Received: from mail.jv-coder.de ([5.9.79.73]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqq4g-002Vjg-B2 for openwrt-devel@lists.openwrt.org; Fri, 04 Nov 2022 06:21:11 +0000 Received: from ubuntu.localdomain (unknown [188.192.100.83]) by mail.jv-coder.de (Postfix) with ESMTPSA id C0740A0A37; Fri, 4 Nov 2022 06:21:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jv-coder.de; s=dkim; t=1667542860; bh=EvwbWklj1M6F3i0d03m2hjq0iyh/T/SIRpRSJByoklQ=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=dG25XEnUWSd83Qb/prdNljrmkVXShaY7v8lwP1ROftwRt4ZD8QNbbb9gWYab9nkFH VmYukR7iCvC5w3o8NHHBbNfJWKyj6cZJNP8C+rftdWYbr91zYnM6uL9lWs9OZUPk4W ZNFCXNdoCcOOkQmI6Y+8HBGJgziVxnfO6X9ZSoc0= From: Joerg Vehlow To: openwrt-devel@lists.openwrt.org Cc: Joerg Vehlow Subject: [PATCH 1/6] add device setting for ip forwarding Date: Fri, 4 Nov 2022 07:20:48 +0100 Message-Id: <20221104062053.1236988-2-lkml@jv-coder.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221104062053.1236988-1-lkml@jv-coder.de> References: <20221104062053.1236988-1-lkml@jv-coder.de> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,UNPARSEABLE_RELAY autolearn=disabled version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mail X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221103_232106_608327_18CB3853 X-CRM114-Status: GOOD ( 13.27 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Joerg Vehlow This allows changing the ip_forwarding setting per device for ipv4 and ipv6 with ip_forwarding and ip6_forwarding --- device.c | 18 ++++++++++++++++++ device.h | 6 ++++++ system-linux.c | 37 +++++++++ [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Joerg Vehlow This allows changing the ip_forwarding setting per device for ipv4 and ipv6 with ip_forwarding and ip6_forwarding --- device.c | 18 ++++++++++++++++++ device.h | 6 ++++++ system-linux.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/device.c b/device.c index b3d0e85..4f55906 100644 --- a/device.c +++ b/device.c @@ -63,6 +63,8 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = { [DEV_ATTR_AUTH] = { .name = "auth", .type = BLOBMSG_TYPE_BOOL }, [DEV_ATTR_SPEED] = { .name = "speed", .type = BLOBMSG_TYPE_INT32 }, [DEV_ATTR_DUPLEX] = { .name = "duplex", .type = BLOBMSG_TYPE_BOOL }, + [DEV_ATTR_IP_FORWARDING] = { .name = "ip_forwarding", .type = BLOBMSG_TYPE_BOOL}, + [DEV_ATTR_IP6_FORWARDING] = { .name = "ip6_forwarding", .type = BLOBMSG_TYPE_BOOL}, }; const struct uci_blob_param_list device_attr_list = { @@ -280,6 +282,8 @@ device_merge_settings(struct device *dev, struct device_settings *n) n->auth = s->flags & DEV_OPT_AUTH ? s->auth : os->auth; n->speed = s->flags & DEV_OPT_SPEED ? s->speed : os->speed; n->duplex = s->flags & DEV_OPT_DUPLEX ? s->duplex : os->duplex; + n->ip_forwarding = s->flags & DEV_OPT_IP_FORWARDING ? s->ip_forwarding : os->ip_forwarding; + n->ip6_forwarding = s->flags & DEV_OPT_IP6_FORWARDING ? s->ip6_forwarding : os->ip6_forwarding; n->flags = s->flags | os->flags | os->valid_flags; } @@ -464,6 +468,16 @@ device_init_settings(struct device *dev, struct blob_attr **tb) s->flags |= DEV_OPT_DUPLEX; } + if ((cur = tb[DEV_ATTR_IP_FORWARDING])) { + s->ip_forwarding = blobmsg_get_bool(cur); + s->flags |= DEV_OPT_IP_FORWARDING; + } + + if ((cur = tb[DEV_ATTR_IP6_FORWARDING])) { + s->ip6_forwarding = blobmsg_get_bool(cur); + s->flags |= DEV_OPT_IP6_FORWARDING; + } + device_set_disabled(dev, disabled); } @@ -1210,6 +1224,10 @@ device_dump_status(struct blob_buf *b, struct device *dev) blobmsg_add_u8(b, "arp_accept", st.arp_accept); if (st.flags & DEV_OPT_AUTH) blobmsg_add_u8(b, "auth", st.auth); + if (st.flags & DEV_OPT_IP_FORWARDING) + blobmsg_add_u8(b, "ip_forwarding", st.ip_forwarding); + if (st.flags & DEV_OPT_IP6_FORWARDING) + blobmsg_add_u8(b, "ip6_forwarding", st.ip6_forwarding); } s = blobmsg_open_table(b, "statistics"); diff --git a/device.h b/device.h index 37f8c37..066f537 100644 --- a/device.h +++ b/device.h @@ -62,6 +62,8 @@ enum { DEV_ATTR_AUTH, DEV_ATTR_SPEED, DEV_ATTR_DUPLEX, + DEV_ATTR_IP_FORWARDING, + DEV_ATTR_IP6_FORWARDING, __DEV_ATTR_MAX, }; @@ -126,6 +128,8 @@ enum { DEV_OPT_ARP_ACCEPT = (1ULL << 29), DEV_OPT_SPEED = (1ULL << 30), DEV_OPT_DUPLEX = (1ULL << 31), + DEV_OPT_IP_FORWARDING = (1ULL << 32), + DEV_OPT_IP6_FORWARDING = (1ULL << 33), }; /* events broadcasted to all users of a device */ @@ -203,6 +207,8 @@ struct device_settings { bool auth; unsigned int speed; bool duplex; + bool ip_forwarding; + bool ip6_forwarding; }; /* diff --git a/system-linux.c b/system-linux.c index 0f13a99..6232a26 100644 --- a/system-linux.c +++ b/system-linux.c @@ -460,6 +460,16 @@ static void system_set_arp_accept(struct device *dev, const char *val) system_set_dev_sysctl("ipv4/conf", "arp_accept", dev->ifname, val); } +static void system_set_ip_forwarding(struct device *dev, const char *val) +{ + system_set_dev_sysctl("ipv4/conf", "forwarding", dev->ifname, val); +} + +static void system_set_ip6_forwarding(struct device *dev, const char *val) +{ + system_set_dev_sysctl("ipv6/conf", "forwarding", dev->ifname, val); +} + static void system_bridge_set_multicast_to_unicast(struct device *dev, const char *val) { system_set_dev_sysfs("brport/multicast_to_unicast", dev->ifname, val); @@ -621,6 +631,18 @@ static int system_get_arp_accept(struct device *dev, char *buf, const size_t buf dev->ifname, buf, buf_sz); } +static int system_get_ip_forwarding(struct device *dev, char *buf, const size_t buf_sz) +{ + return system_get_dev_sysctl("ipv4/conf", "forwarding", + dev->ifname, buf, buf_sz); +} + +static int system_get_ip6_forwarding(struct device *dev, char *buf, const size_t buf_sz) +{ + return system_get_dev_sysctl("ipv6/conf", "forwarding", + dev->ifname, buf, buf_sz); +} + /* Evaluate netlink messages */ static int cb_rtnl_event(struct nl_msg *msg, void *arg) { @@ -1795,6 +1817,16 @@ system_if_get_settings(struct device *dev, struct device_settings *s) s->arp_accept = strtoul(buf, NULL, 0); s->flags |= DEV_OPT_ARP_ACCEPT; } + + if (!system_get_ip_forwarding(dev, buf, sizeof(buf))) { + s->ip_forwarding = strtoul(buf, NULL, 0); + s->flags |= DEV_OPT_IP_FORWARDING; + } + + if (!system_get_ip6_forwarding(dev, buf, sizeof(buf))) { + s->ip6_forwarding = strtoul(buf, NULL, 0); + s->flags |= DEV_OPT_IP6_FORWARDING; + } } void @@ -1893,6 +1925,11 @@ system_if_apply_settings(struct device *dev, struct device_settings *s, uint64_t system_set_drop_unsolicited_na(dev, s->drop_unsolicited_na ? "1" : "0"); if (apply_mask & DEV_OPT_ARP_ACCEPT) system_set_arp_accept(dev, s->arp_accept ? "1" : "0"); + if (apply_mask & DEV_OPT_IP_FORWARDING) + system_set_ip_forwarding(dev, s->ip_forwarding ? "1" : "0"); + if (apply_mask & DEV_OPT_IP6_FORWARDING) + system_set_ip6_forwarding(dev, s->ip6_forwarding ? "1" : "0"); + system_set_ethtool_settings(dev, s); }