Nikolay Aleksandrov
2015-May-21 10:42 UTC
[Bridge] [PATCH net-next] bridge: skip fdb add if the port shouldn't learn
From: Wilson Kok <wkok at cumulusnetworks.com>
Check in fdb_add_entry() if the source port should learn, similar
check is used in br_fdb_update.
Note that new fdb entries which are added manually or
as local ones are still permitted.
This patch has been tested by running traffic via a bridge port and
switching the port's state, also by manually adding/removing entries
from the bridge's fdb.
Signed-off-by: Wilson Kok <wkok at cumulusnetworks.com>
Signed-off-by: Nikolay Aleksandrov <nikolay at cumulusnetworks.com>
---
Nik: Maybe it'd be better if we returned an error even though it
doesn't look necessary. I'm open to suggestions.
net/bridge/br_fdb.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index e0670d7054f9..27de0b7bd76b 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -736,6 +736,12 @@ static int fdb_add_entry(struct net_bridge_port *source,
const __u8 *addr,
struct net_bridge_fdb_entry *fdb;
bool modified = false;
+ /* If the port cannot learn allow only local and static entries */
+ if (!(state & NUD_PERMANENT) && !(state & NUD_NOARP)
&&
+ !(source->state == BR_STATE_LEARNING ||
+ source->state == BR_STATE_FORWARDING))
+ return 0;
+
fdb = fdb_find(head, addr, vid);
if (fdb == NULL) {
if (!(flags & NLM_F_CREATE))
--
1.9.3
David Miller
2015-May-25 02:59 UTC
[Bridge] [PATCH net-next] bridge: skip fdb add if the port shouldn't learn
From: Nikolay Aleksandrov <nikolay at cumulusnetworks.com> Date: Thu, 21 May 2015 03:42:57 -0700> From: Wilson Kok <wkok at cumulusnetworks.com> > > Check in fdb_add_entry() if the source port should learn, similar > check is used in br_fdb_update. > Note that new fdb entries which are added manually or > as local ones are still permitted. > This patch has been tested by running traffic via a bridge port and > switching the port's state, also by manually adding/removing entries > from the bridge's fdb. > > Signed-off-by: Wilson Kok <wkok at cumulusnetworks.com> > Signed-off-by: Nikolay Aleksandrov <nikolay at cumulusnetworks.com> > --- > Nik: Maybe it'd be better if we returned an error even though it > doesn't look necessary. I'm open to suggestions.If you don't return an error, then rtnetlink.c is going to emit a NEWNEIGH netlink message. I seriously doubt we want that to happen.
Nikolay Aleksandrov
2015-May-25 13:39 UTC
[Bridge] [PATCH net-next v2] bridge: skip fdb add if the port shouldn't learn
From: Wilson Kok <wkok at cumulusnetworks.com>
Check in fdb_add_entry() if the source port should learn, similar
check is used in br_fdb_update.
Note that new fdb entries which are added manually or
as local ones are still permitted.
This patch has been tested by running traffic via a bridge port and
switching the port's state, also by manually adding/removing entries
from the bridge's fdb.
Signed-off-by: Wilson Kok <wkok at cumulusnetworks.com>
Signed-off-by: Nikolay Aleksandrov <nikolay at cumulusnetworks.com>
---
v2: return an error instead of silently failing.
net/bridge/br_fdb.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index e0670d7054f9..7896cf143045 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -736,6 +736,12 @@ static int fdb_add_entry(struct net_bridge_port *source,
const __u8 *addr,
struct net_bridge_fdb_entry *fdb;
bool modified = false;
+ /* If the port cannot learn allow only local and static entries */
+ if (!(state & NUD_PERMANENT) && !(state & NUD_NOARP)
&&
+ !(source->state == BR_STATE_LEARNING ||
+ source->state == BR_STATE_FORWARDING))
+ return -EPERM;
+
fdb = fdb_find(head, addr, vid);
if (fdb == NULL) {
if (!(flags & NLM_F_CREATE))
--
1.7.10.4
Stephen Hemminger
2015-May-26 17:28 UTC
[Bridge] [PATCH net-next] bridge: skip fdb add if the port shouldn't learn
On Thu, 21 May 2015 03:42:57 -0700 Nikolay Aleksandrov <nikolay at cumulusnetworks.com> wrote:> From: Wilson Kok <wkok at cumulusnetworks.com> > > Check in fdb_add_entry() if the source port should learn, similar > check is used in br_fdb_update. > Note that new fdb entries which are added manually or > as local ones are still permitted. > This patch has been tested by running traffic via a bridge port and > switching the port's state, also by manually adding/removing entries > from the bridge's fdb. > > Signed-off-by: Wilson Kok <wkok at cumulusnetworks.com> > Signed-off-by: Nikolay Aleksandrov <nikolay at cumulusnetworks.com>What is the problem this is trying to solve? I think user should be allowed to manually add any entry even if learning.