summaryrefslogtreecommitdiffstats
path: root/sys/netinet6/scope6.c
diff options
context:
space:
mode:
authorae <ae@FreeBSD.org>2014-11-10 16:12:51 +0000
committerae <ae@FreeBSD.org>2014-11-10 16:12:51 +0000
commit253f06cd2a21cdcc0562a1e6c43bcdd8aa4b8ffe (patch)
treed4976f3b44c568f5658731011b8c985947809df8 /sys/netinet6/scope6.c
parent89eb9b8cc2d7a499792547f54bc313545396a330 (diff)
downloadFreeBSD-src-253f06cd2a21cdcc0562a1e6c43bcdd8aa4b8ffe.zip
FreeBSD-src-253f06cd2a21cdcc0562a1e6c43bcdd8aa4b8ffe.tar.gz
Add sa6_checkzone_ifp() function. It checks correctness of struct
sockaddr_in6, usually obtained from the user level through ioctl. It initializes sin6_scope_id using given interface. Sponsored by: Yandex LLC
Diffstat (limited to 'sys/netinet6/scope6.c')
-rw-r--r--sys/netinet6/scope6.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/sys/netinet6/scope6.c b/sys/netinet6/scope6.c
index f199091..0e4d303 100644
--- a/sys/netinet6/scope6.c
+++ b/sys/netinet6/scope6.c
@@ -532,4 +532,25 @@ sa6_checkzone(struct sockaddr_in6 *sa6)
return (sa6->sin6_scope_id ? 0: EADDRNOTAVAIL);
}
+/*
+ * This function is similar to sa6_checkzone, but it uses given ifp
+ * to initialize sin6_scope_id.
+ */
+int
+sa6_checkzone_ifp(struct ifnet *ifp, struct sockaddr_in6 *sa6)
+{
+ int scope;
+
+ scope = in6_addrscope(&sa6->sin6_addr);
+ if (scope == IPV6_ADDR_SCOPE_LINKLOCAL ||
+ scope == IPV6_ADDR_SCOPE_INTFACELOCAL) {
+ if (sa6->sin6_scope_id == 0) {
+ sa6->sin6_scope_id = in6_getscopezone(ifp, scope);
+ return (0);
+ } else if (sa6->sin6_scope_id != in6_getscopezone(ifp, scope))
+ return (EADDRNOTAVAIL);
+ }
+ return (sa6_checkzone(sa6));
+}
+
OpenPOWER on IntegriCloud