From 330bf5438c1b4761bda1aa814ccdceaa0c2a2990 Mon Sep 17 00:00:00 2001 From: liangbotong Date: Thu, 20 Apr 2023 10:58:50 +0800 Subject: [PATCH] Fix NewIP route issues and btdev Makefile Fix the issue that a network port can add a route or address when it is not running. The btdev Makefile adds a conditional compilation. Signed-off-by: liangbotong --- newip/src/linux-5.10/drivers/net/bt/Makefile | 2 +- newip/src/linux-5.10/net/newip/nip_addrconf.c | 6 ++++++ newip/src/linux-5.10/net/newip/route.c | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/newip/src/linux-5.10/drivers/net/bt/Makefile b/newip/src/linux-5.10/drivers/net/bt/Makefile index c69bd34..15494e8 100644 --- a/newip/src/linux-5.10/drivers/net/bt/Makefile +++ b/newip/src/linux-5.10/drivers/net/bt/Makefile @@ -1,3 +1,3 @@ # enable btdev: -# kernel/linux/linux-5.10/drivers/net/Makefile add obj-$(CONFIG_NEWIP) += bt/ +# kernel/linux/linux-5.10/drivers/net/Makefile add obj-y += bt/ or obj-$(CONFIG_NEWIP) += bt/ obj-y += btdev.o diff --git a/newip/src/linux-5.10/net/newip/nip_addrconf.c b/newip/src/linux-5.10/net/newip/nip_addrconf.c index 64d953e..1badbca 100644 --- a/newip/src/linux-5.10/net/newip/nip_addrconf.c +++ b/newip/src/linux-5.10/net/newip/nip_addrconf.c @@ -96,6 +96,12 @@ static struct ninet_ifaddr *nip_add_addr(struct ninet_dev *idev, goto rcu_lock_out; } + if (!netif_running(idev->dev)) { + nip_dbg("network interface is not running"); + err = -ENODEV; + goto rcu_lock_out; + } + if (idev->cnf.disable_nip) { err = -EACCES; goto rcu_lock_out; diff --git a/newip/src/linux-5.10/net/newip/route.c b/newip/src/linux-5.10/net/newip/route.c index 0ede62a..e7c8a4a 100644 --- a/newip/src/linux-5.10/net/newip/route.c +++ b/newip/src/linux-5.10/net/newip/route.c @@ -428,7 +428,13 @@ static struct nip_rt_info *nip_route_info_create(struct nip_fib_config *cfg) nip_dbg("fail to get ninet dev (ifindex=%u)", cfg->fc_ifindex); goto out; } - + /* Do not add a route when the network port is not running + * to avoid incorrect route selection + */ + if (!netif_running(idev->dev)) { + nip_dbg("network interface is not running"); + goto out; + } if (cfg->fc_metric == 0) cfg->fc_metric = NIP_RT_PRIO_USER; -- Gitee