From: Alexander Aring <alex.aring@gmail.com>
To: davem@davemloft.net
Cc: kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org, kuba@kernel.org,
dav.lebrun@gmail.com, mcr@sandelman.ca,
stefan@datenfreihafen.org, kai.beckmann@hs-rm.de,
martin.gergeleit@hs-rm.de, robert.kaiser@hs-rm.de,
netdev@vger.kernel.org, Alexander Aring <alex.aring@gmail.com>
Subject: [PATCHv3 net-next 2/5] addrconf: add functionality to check on rpl requirements
Date: Fri, 27 Mar 2020 18:00:19 -0400 [thread overview]
Message-ID: <20200327220022.15220-3-alex.aring@gmail.com> (raw)
In-Reply-To: <20200327220022.15220-1-alex.aring@gmail.com>
This patch adds a functionality to addrconf to check on a specific RPL
address configuration. According to RFC 6554:
To detect loops in the SRH, a router MUST determine if the SRH
includes multiple addresses assigned to any interface on that
router. If such addresses appear more than once and are separated by
at least one address not assigned to that router.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
include/net/addrconf.h | 3 +++
net/ipv6/addrconf.c | 53 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+)
diff --git a/include/net/addrconf.h b/include/net/addrconf.h
index a088349dd94f..e0eabe58aa8b 100644
--- a/include/net/addrconf.h
+++ b/include/net/addrconf.h
@@ -90,6 +90,9 @@ int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
int ipv6_chk_home_addr(struct net *net, const struct in6_addr *addr);
#endif
+int ipv6_chk_rpl_srh_loop(struct net *net, const struct in6_addr *segs,
+ unsigned char nsegs);
+
bool ipv6_chk_custom_prefix(const struct in6_addr *addr,
const unsigned int prefix_len,
struct net_device *dev);
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 5b9de773ce73..594963a7e1ec 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -4398,6 +4398,59 @@ int ipv6_chk_home_addr(struct net *net, const struct in6_addr *addr)
}
#endif
+/* RFC6554 has some algorithm to avoid loops in segment routing by
+ * checking if the segments contains any of a local interface address.
+ *
+ * Quote:
+ *
+ * To detect loops in the SRH, a router MUST determine if the SRH
+ * includes multiple addresses assigned to any interface on that router.
+ * If such addresses appear more than once and are separated by at least
+ * one address not assigned to that router.
+ */
+int ipv6_chk_rpl_srh_loop(struct net *net, const struct in6_addr *segs,
+ unsigned char nsegs)
+{
+ const struct in6_addr *addr;
+ int i, ret = 0, found = 0;
+ struct inet6_ifaddr *ifp;
+ bool separated = false;
+ unsigned int hash;
+ bool hash_found;
+
+ rcu_read_lock();
+ for (i = 0; i < nsegs; i++) {
+ addr = &segs[i];
+ hash = inet6_addr_hash(net, addr);
+
+ hash_found = false;
+ hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) {
+ if (!net_eq(dev_net(ifp->idev->dev), net))
+ continue;
+
+ if (ipv6_addr_equal(&ifp->addr, addr)) {
+ hash_found = true;
+ break;
+ }
+ }
+
+ if (hash_found) {
+ if (found > 1 && separated) {
+ ret = 1;
+ break;
+ }
+
+ separated = false;
+ found++;
+ } else {
+ separated = true;
+ }
+ }
+ rcu_read_unlock();
+
+ return ret;
+}
+
/*
* Periodic address status verification
*/
--
2.20.1
next prev parent reply other threads:[~2020-03-27 22:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-27 22:00 [PATCHv3 net-next 0/5] net: ipv6: add rpl source routing Alexander Aring
2020-03-27 22:00 ` [PATCHv3 net-next 1/5] include: uapi: linux: add rpl sr header definition Alexander Aring
2020-03-27 22:00 ` Alexander Aring [this message]
2020-03-27 22:00 ` [PATCHv3 net-next 3/5] net: ipv6: add support for rpl sr exthdr Alexander Aring
2020-03-27 22:00 ` [PATCHv3 net-next 4/5] net: add net available in build_state Alexander Aring
2020-03-27 22:00 ` [PATCHv3 net-next 5/5] net: ipv6: add rpl sr tunnel Alexander Aring
2020-03-30 5:31 ` [PATCHv3 net-next 0/5] net: ipv6: add rpl source routing David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200327220022.15220-3-alex.aring@gmail.com \
--to=alex.aring@gmail.com \
--cc=dav.lebrun@gmail.com \
--cc=davem@davemloft.net \
--cc=kai.beckmann@hs-rm.de \
--cc=kuba@kernel.org \
--cc=kuznet@ms2.inr.ac.ru \
--cc=martin.gergeleit@hs-rm.de \
--cc=mcr@sandelman.ca \
--cc=netdev@vger.kernel.org \
--cc=robert.kaiser@hs-rm.de \
--cc=stefan@datenfreihafen.org \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).