Author: ae
Date: Mon Nov 10 16:12:51 2014
New Revision: 274348
URL: https://svnweb.freebsd.org/changeset/base/274348

Log:
  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

Modified:
  head/sys/netinet6/scope6.c
  head/sys/netinet6/scope6_var.h

Modified: head/sys/netinet6/scope6.c
==============================================================================
--- head/sys/netinet6/scope6.c  Mon Nov 10 16:01:39 2014        (r274347)
+++ head/sys/netinet6/scope6.c  Mon Nov 10 16:12:51 2014        (r274348)
@@ -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));
+}
+
 

Modified: head/sys/netinet6/scope6_var.h
==============================================================================
--- head/sys/netinet6/scope6_var.h      Mon Nov 10 16:01:39 2014        
(r274347)
+++ head/sys/netinet6/scope6_var.h      Mon Nov 10 16:12:51 2014        
(r274348)
@@ -58,6 +58,7 @@ u_int32_t scope6_addr2default(struct in6
 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 *);
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to