]> xenbits.xensource.com Git - people/julieng/freebsd.git/commitdiff
Add sa6_checkzone_ifp() function. It checks correctness of struct
authorae <ae@FreeBSD.org>
Mon, 10 Nov 2014 16:12:51 +0000 (16:12 +0000)
committerae <ae@FreeBSD.org>
Mon, 10 Nov 2014 16:12:51 +0000 (16:12 +0000)
sockaddr_in6, usually obtained from the user level through ioctl.
It initializes sin6_scope_id using given interface.

Sponsored by: Yandex LLC

sys/netinet6/scope6.c
sys/netinet6/scope6_var.h

index f19909189b1815fe65f552ff7de28df171b0a1bc..0e4d303cfaa6b4094a9046b5e03c3509de1589fb 100644 (file)
@@ -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));
+}
+
 
index 8a4b6fcf77542cf8b0259d59c2807ba31f00402e..d4d0478aaf5dd62b5a25bfa6bf9bce40b5b5846d 100644 (file)
@@ -58,6 +58,7 @@ u_int32_t scope6_addr2default(struct in6_addr *);
 int    sa6_embedscope(struct sockaddr_in6 *, int);
 int    sa6_recoverscope(struct sockaddr_in6 *);
 int    sa6_checkzone(struct sockaddr_in6 *);
+int    sa6_checkzone_ifp(struct ifnet *, struct sockaddr_in6 *);
 int    in6_setscope(struct in6_addr *, struct ifnet *, u_int32_t *);
 int    in6_clearscope(struct in6_addr *);
 uint16_t in6_getscope(struct in6_addr *);