Author: melifaro
Date: Sat Jan 18 20:32:59 2014
New Revision: 260860
URL: http://svnweb.freebsd.org/changeset/base/260860

Log:
  Add in6_prepare_ifra() function to ease preparing in-kernel IPv6
  address requests.
  
  MFC after:    2 weeks

Modified:
  head/sys/netinet6/in6.c
  head/sys/netinet6/in6_ifattach.c
  head/sys/netinet6/in6_var.h
  head/sys/netinet6/nd6_rtr.c

Modified: head/sys/netinet6/in6.c
==============================================================================
--- head/sys/netinet6/in6.c     Sat Jan 18 20:02:59 2014        (r260859)
+++ head/sys/netinet6/in6.c     Sat Jan 18 20:32:59 2014        (r260860)
@@ -1036,6 +1036,27 @@ in6_update_ifa(struct ifnet *ifp, struct
        return (error);
 }
 
+/*
+ * Fill in basic IPv6 address request info
+ */
+void
+in6_prepare_ifra(struct in6_aliasreq *ifra, const struct in6_addr *addr,
+    const struct in6_addr *mask)
+{
+
+       memset(ifra, 0, sizeof(struct in6_aliasreq));
+
+       ifra->ifra_addr.sin6_family = AF_INET6;
+       ifra->ifra_addr.sin6_len = sizeof(struct sockaddr_in6);
+       if (addr != NULL)
+               ifra->ifra_addr.sin6_addr = *addr;
+
+       ifra->ifra_prefixmask.sin6_family = AF_INET6;
+       ifra->ifra_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
+       if (mask != NULL)
+               ifra->ifra_prefixmask.sin6_addr = *mask;
+}
+
 static int
 in6_validate_ifra(struct ifnet *ifp, struct in6_aliasreq *ifra,
     struct in6_ifaddr *ia, int flags)

Modified: head/sys/netinet6/in6_ifattach.c
==============================================================================
--- head/sys/netinet6/in6_ifattach.c    Sat Jan 18 20:02:59 2014        
(r260859)
+++ head/sys/netinet6/in6_ifattach.c    Sat Jan 18 20:32:59 2014        
(r260860)
@@ -460,16 +460,8 @@ in6_ifattach_linklocal(struct ifnet *ifp
        /*
         * configure link-local address.
         */
-       bzero(&ifra, sizeof(ifra));
+       in6_prepare_ifra(&ifra, NULL, &in6mask64);
 
-       /*
-        * in6_update_ifa() does not use ifra_name, but we accurately set it
-        * for safety.
-        */
-       strncpy(ifra.ifra_name, if_name(ifp), sizeof(ifra.ifra_name));
-
-       ifra.ifra_addr.sin6_family = AF_INET6;
-       ifra.ifra_addr.sin6_len = sizeof(struct sockaddr_in6);
        ifra.ifra_addr.sin6_addr.s6_addr32[0] = htonl(0xfe800000);
        ifra.ifra_addr.sin6_addr.s6_addr32[1] = 0;
        if ((ifp->if_flags & IFF_LOOPBACK) != 0) {
@@ -485,9 +477,6 @@ in6_ifattach_linklocal(struct ifnet *ifp
        if (in6_setscope(&ifra.ifra_addr.sin6_addr, ifp, NULL))
                return (-1);
 
-       ifra.ifra_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
-       ifra.ifra_prefixmask.sin6_family = AF_INET6;
-       ifra.ifra_prefixmask.sin6_addr = in6mask64;
        /* link-local addresses should NEVER expire. */
        ifra.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
        ifra.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
@@ -565,17 +554,7 @@ in6_ifattach_loopback(struct ifnet *ifp)
        struct in6_aliasreq ifra;
        int error;
 
-       bzero(&ifra, sizeof(ifra));
-
-       /*
-        * in6_update_ifa() does not use ifra_name, but we accurately set it
-        * for safety.
-        */
-       strncpy(ifra.ifra_name, if_name(ifp), sizeof(ifra.ifra_name));
-
-       ifra.ifra_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
-       ifra.ifra_prefixmask.sin6_family = AF_INET6;
-       ifra.ifra_prefixmask.sin6_addr = in6mask128;
+       in6_prepare_ifra(&ifra, &in6addr_loopback, &in6mask128);
 
        /*
         * Always initialize ia_dstaddr (= broadcast address) to loopback
@@ -585,10 +564,6 @@ in6_ifattach_loopback(struct ifnet *ifp)
        ifra.ifra_dstaddr.sin6_family = AF_INET6;
        ifra.ifra_dstaddr.sin6_addr = in6addr_loopback;
 
-       ifra.ifra_addr.sin6_len = sizeof(struct sockaddr_in6);
-       ifra.ifra_addr.sin6_family = AF_INET6;
-       ifra.ifra_addr.sin6_addr = in6addr_loopback;
-
        /* the loopback  address should NEVER expire. */
        ifra.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
        ifra.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;

Modified: head/sys/netinet6/in6_var.h
==============================================================================
--- head/sys/netinet6/in6_var.h Sat Jan 18 20:02:59 2014        (r260859)
+++ head/sys/netinet6/in6_var.h Sat Jan 18 20:32:59 2014        (r260860)
@@ -799,6 +799,8 @@ int in6_control(struct socket *, u_long,
        struct thread *);
 int    in6_update_ifa(struct ifnet *, struct in6_aliasreq *,
        struct in6_ifaddr *, int);
+void   in6_prepare_ifra(struct in6_aliasreq *, const struct in6_addr *,
+       const struct in6_addr *);
 void   in6_purgeaddr(struct ifaddr *);
 int    in6if_do_dad(struct ifnet *);
 void   in6_purgeif(struct ifnet *);

Modified: head/sys/netinet6/nd6_rtr.c
==============================================================================
--- head/sys/netinet6/nd6_rtr.c Sat Jan 18 20:02:59 2014        (r260859)
+++ head/sys/netinet6/nd6_rtr.c Sat Jan 18 20:32:59 2014        (r260860)
@@ -1829,19 +1829,9 @@ in6_ifadd(struct nd_prefixctl *pr, int m
        }
 
        /* make ifaddr */
+       in6_prepare_ifra(&ifra, &pr->ndpr_prefix.sin6_addr, &mask);
 
-       bzero(&ifra, sizeof(ifra));
-       /*
-        * in6_update_ifa() does not use ifra_name, but we accurately set it
-        * for safety.
-        */
-       strncpy(ifra.ifra_name, if_name(ifp), sizeof(ifra.ifra_name));
-       ifra.ifra_addr.sin6_family = AF_INET6;
-       ifra.ifra_addr.sin6_len = sizeof(struct sockaddr_in6);
-       /* prefix */
-       ifra.ifra_addr.sin6_addr = pr->ndpr_prefix.sin6_addr;
        IN6_MASK_ADDR(&ifra.ifra_addr.sin6_addr, &mask);
-
        /* interface ID */
        ifra.ifra_addr.sin6_addr.s6_addr32[0] |=
            (ib->ia_addr.sin6_addr.s6_addr32[0] & ~mask.s6_addr32[0]);
@@ -1853,12 +1843,6 @@ in6_ifadd(struct nd_prefixctl *pr, int m
            (ib->ia_addr.sin6_addr.s6_addr32[3] & ~mask.s6_addr32[3]);
        ifa_free(ifa);
 
-       /* new prefix mask. */
-       ifra.ifra_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
-       ifra.ifra_prefixmask.sin6_family = AF_INET6;
-       bcopy(&mask, &ifra.ifra_prefixmask.sin6_addr,
-           sizeof(ifra.ifra_prefixmask.sin6_addr));
-
        /* lifetimes. */
        ifra.ifra_lifetime.ia6t_vltime = pr->ndpr_vltime;
        ifra.ifra_lifetime.ia6t_pltime = pr->ndpr_pltime;
@@ -1923,11 +1907,10 @@ in6_tmpifadd(const struct in6_ifaddr *ia
        u_int32_t randid[2];
        time_t vltime0, pltime0;
 
-       bzero(&ifra, sizeof(ifra));
-       strncpy(ifra.ifra_name, if_name(ifp), sizeof(ifra.ifra_name));
-       ifra.ifra_addr = ia0->ia_addr;
-       /* copy prefix mask */
-       ifra.ifra_prefixmask = ia0->ia_prefixmask;
+       in6_prepare_ifra(&ifra, &ia0->ia_addr.sin6_addr,
+           &ia0->ia_prefixmask.sin6_addr);
+
+       ifra.ifra_addr = ia0->ia_addr;  /* XXX: do we need this ? */
        /* clear the old IFID */
        IN6_MASK_ADDR(&ifra.ifra_addr.sin6_addr,
            &ifra.ifra_prefixmask.sin6_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