Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys sync with kame.



details:   https://anonhg.NetBSD.org/src/rev/7f44266f0c9c
branches:  trunk
changeset: 494535:7f44266f0c9c
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Jul 07 15:54:16 2000 +0000

description:
sync with kame.
introduce in6_{recover,embed}scope, for in-kernel scoped-address manipulation.
improve in6_pcbnotify.

diffstat:

 sys/netinet/udp_usrreq.c   |   28 +++------
 sys/netinet6/icmp6.c       |   14 +---
 sys/netinet6/in6_pcb.c     |  131 +++++++++++---------------------------------
 sys/netinet6/in6_pcb.h     |   12 +++-
 sys/netinet6/in6_src.c     |  129 +++++++++++++++++++++++++++++++++++++++++++-
 sys/netinet6/raw_ip6.c     |  126 +++++++++++++++++++++++-------------------
 sys/netinet6/udp6_usrreq.c |   74 +++++--------------------
 7 files changed, 265 insertions(+), 249 deletions(-)

diffs (truncated from 827 to 300 lines):

diff -r 3662ddaff603 -r 7f44266f0c9c sys/netinet/udp_usrreq.c
--- a/sys/netinet/udp_usrreq.c  Fri Jul 07 15:45:00 2000 +0000
+++ b/sys/netinet/udp_usrreq.c  Fri Jul 07 15:54:16 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: udp_usrreq.c,v 1.68 2000/07/06 12:51:40 itojun Exp $   */
+/*     $NetBSD: udp_usrreq.c,v 1.69 2000/07/07 15:54:16 itojun Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -353,6 +353,10 @@
        }
 #endif
        ulen = ntohs((u_short)uh->uh_ulen);
+       /*
+        * RFC2675 section 4: jumbograms will have 0 in the UDP header field,
+        * iff payload length > 0xffff.
+        */
        if (ulen == 0 && plen > 0xffff)
                ulen = plen;
 
@@ -389,28 +393,14 @@
        bzero(&src, sizeof(src));
        src.sin6_family = AF_INET6;
        src.sin6_len = sizeof(struct sockaddr_in6);
-       bcopy(&ip6->ip6_src, &src.sin6_addr, sizeof(src.sin6_addr));
-       if (IN6_IS_SCOPE_LINKLOCAL(&src.sin6_addr))
-               src.sin6_addr.s6_addr16[1] = 0;
-       if (m->m_pkthdr.rcvif) {
-               if (IN6_IS_SCOPE_LINKLOCAL(&src.sin6_addr))
-                       src.sin6_scope_id = m->m_pkthdr.rcvif->if_index;
-               else
-                       src.sin6_scope_id = 0;
-       }
+       /* KAME hack: recover scopeid */
+       (void)in6_recoverscope(&src, &ip6->ip6_src, m->m_pkthdr.rcvif);
        src.sin6_port = uh->uh_sport;
        bzero(&dst, sizeof(dst));
        dst.sin6_family = AF_INET6;
        dst.sin6_len = sizeof(struct sockaddr_in6);
-       bcopy(&ip6->ip6_dst, &dst.sin6_addr, sizeof(dst.sin6_addr));
-       if (IN6_IS_SCOPE_LINKLOCAL(&dst.sin6_addr))
-               dst.sin6_addr.s6_addr16[1] = 0;
-       if (m->m_pkthdr.rcvif) {
-               if (IN6_IS_SCOPE_LINKLOCAL(&dst.sin6_addr))
-                       dst.sin6_scope_id = m->m_pkthdr.rcvif->if_index;
-               else
-                       dst.sin6_scope_id = 0;
-       }
+       /* KAME hack: recover scopeid */
+       (void)in6_recoverscope(&dst, &ip6->ip6_dst, m->m_pkthdr.rcvif);
        dst.sin6_port = uh->uh_dport;
 
        if (udp6_realinput(AF_INET6, &src, &dst, m, off) == 0) {
diff -r 3662ddaff603 -r 7f44266f0c9c sys/netinet6/icmp6.c
--- a/sys/netinet6/icmp6.c      Fri Jul 07 15:45:00 2000 +0000
+++ b/sys/netinet6/icmp6.c      Fri Jul 07 15:54:16 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: icmp6.c,v 1.35 2000/07/06 12:36:18 itojun Exp $        */
+/*     $NetBSD: icmp6.c,v 1.36 2000/07/07 15:54:17 itojun Exp $        */
 /*     $KAME: icmp6.c,v 1.120 2000/07/06 11:47:20 itojun Exp $ */
 
 /*
@@ -1704,16 +1704,8 @@
        bzero(&rip6src, sizeof(rip6src));
        rip6src.sin6_len = sizeof(struct sockaddr_in6);
        rip6src.sin6_family = AF_INET6;
-       rip6src.sin6_addr = ip6->ip6_src;
-       if (IN6_IS_SCOPE_LINKLOCAL(&rip6src.sin6_addr))
-               rip6src.sin6_addr.s6_addr16[1] = 0;
-       if (m->m_pkthdr.rcvif) {
-               if (IN6_IS_SCOPE_LINKLOCAL(&rip6src.sin6_addr))
-                       rip6src.sin6_scope_id = m->m_pkthdr.rcvif->if_index;
-               else
-                       rip6src.sin6_scope_id = 0;
-       } else
-               rip6src.sin6_scope_id = 0;
+       /* KAME hack: recover scopeid */
+       (void)in6_recoverscope(&rip6src, &ip6->ip6_src, m->m_pkthdr.rcvif);
 
        for (in6p = rawin6pcb.in6p_next;
             in6p != &rawin6pcb; in6p = in6p->in6p_next)
diff -r 3662ddaff603 -r 7f44266f0c9c sys/netinet6/in6_pcb.c
--- a/sys/netinet6/in6_pcb.c    Fri Jul 07 15:45:00 2000 +0000
+++ b/sys/netinet6/in6_pcb.c    Fri Jul 07 15:54:16 2000 +0000
@@ -1,5 +1,5 @@
-/*     $NetBSD: in6_pcb.c,v 1.28 2000/07/06 12:51:41 itojun Exp $      */
-/*     $KAME: in6_pcb.c,v 1.56 2000/07/03 13:23:28 itojun Exp $        */
+/*     $NetBSD: in6_pcb.c,v 1.29 2000/07/07 15:54:18 itojun Exp $      */
+/*     $KAME: in6_pcb.c,v 1.57 2000/07/07 10:27:12 itojun Exp $        */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -143,7 +143,6 @@
        struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)NULL;
        u_int16_t lport = 0;
        int wild = 0, reuseport = (so->so_options & SO_REUSEPORT);
-       int error;
 
        if (in6p->in6p_lport || !IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr))
                return(EINVAL);
@@ -170,36 +169,11 @@
                if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr))
                        return(EADDRNOTAVAIL);
 
-               /*
-                * If the scope of the destination is link-local, embed the
-                * interface index in the address.
-                */
-               if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) {
-                       /* XXX boundary check is assumed to be already done. */
-                       /* XXX sin6_scope_id is weaker than advanced-api. */
-                       struct in6_pktinfo *pi;
-                       if (in6p->in6p_outputopts &&
-                           (pi = in6p->in6p_outputopts->ip6po_pktinfo) &&
-                           pi->ipi6_ifindex) {
-                               sin6->sin6_addr.s6_addr16[1]
-                                       = htons(pi->ipi6_ifindex);
-                       } else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)
-                               && in6p->in6p_moptions
-                               && in6p->in6p_moptions->im6o_multicast_ifp) {
-                               sin6->sin6_addr.s6_addr16[1] =
-                                       htons(in6p->in6p_moptions->im6o_multicast_ifp->if_index);
-                       } else if (sin6->sin6_scope_id) {
-                               /* boundary check */
-                               if (sin6->sin6_scope_id < 0
-                                || if_index < sin6->sin6_scope_id) {
-                                       return ENXIO;  /* XXX EINVAL? */
-                               }
-                               sin6->sin6_addr.s6_addr16[1]
-                                       = htons(sin6->sin6_scope_id & 0xffff);/*XXX*/
-                               /* this must be cleared for ifa_ifwithaddr() */
-                               sin6->sin6_scope_id = 0;
-                       }
-               }
+               /* KAME hack: embed scopeid */
+               if (in6_embedscope(&sin6->sin6_addr, sin6, in6p, NULL) != 0)
+                       return EINVAL;
+               /* this must be cleared for ifa_ifwithaddr() */
+               sin6->sin6_scope_id = 0;
 
                lport = sin6->sin6_port;
                if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
@@ -247,10 +221,15 @@
                }
                if (lport) {
 #ifndef IPNOPRIVPORTS
+                       int priv;
+
+                       /*
+                        * NOTE: all operating systems use suser() for
+                        * privilege check!  do not rewrite it into SS_PRIV.
+                        */
+                       priv = (p && !suser(p->p_ucred, &p->p_acflag)) ? 1 : 0;
                        /* GROSS */
-                       if (ntohs(lport) < IPV6PORT_RESERVED &&
-                           (p == 0 ||
-                            (error = suser(p->p_ucred, &p->p_acflag))))
+                       if (ntohs(lport) < IPV6PORT_RESERVED && !priv)
                                return(EACCES);
 #endif
 
@@ -302,7 +281,6 @@
 {
        struct in6_addr *in6a = NULL;
        struct sockaddr_in6 *sin6 = mtod(nam, struct sockaddr_in6 *);
-       struct in6_pktinfo *pi;
        struct ifnet *ifp = NULL;       /* outgoing interface */
        int error = 0;
        struct in6_addr mapped;
@@ -332,36 +310,9 @@
        tmp = *sin6;
        sin6 = &tmp;
 
-       /*
-        * If the scope of the destination is link-local, embed the interface
-        * index in the address.
-        */
-       if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) {
-               /* XXX boundary check is assumed to be already done. */
-               /* XXX sin6_scope_id is weaker than advanced-api. */
-               if (in6p->in6p_outputopts &&
-                   (pi = in6p->in6p_outputopts->ip6po_pktinfo) &&
-                   pi->ipi6_ifindex) {
-                       sin6->sin6_addr.s6_addr16[1] = htons(pi->ipi6_ifindex);
-                       ifp = ifindex2ifnet[pi->ipi6_ifindex];
-               }
-               else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr) &&
-                        in6p->in6p_moptions &&
-                        in6p->in6p_moptions->im6o_multicast_ifp) {
-                       sin6->sin6_addr.s6_addr16[1] =
-                               htons(in6p->in6p_moptions->im6o_multicast_ifp->if_index);
-                       ifp = ifindex2ifnet[in6p->in6p_moptions->im6o_multicast_ifp->if_index];
-               } else if (sin6->sin6_scope_id) {
-                       /* boundary check */
-                       if (sin6->sin6_scope_id < 0
-                        || if_index < sin6->sin6_scope_id) {
-                               return ENXIO;  /* XXX EINVAL? */
-                       }
-                       sin6->sin6_addr.s6_addr16[1]
-                               = htons(sin6->sin6_scope_id & 0xffff);/*XXX*/
-                       ifp = ifindex2ifnet[sin6->sin6_scope_id];
-               }
-       }
+       /* KAME hack: embed scopeid */
+       if (in6_embedscope(&sin6->sin6_addr, sin6, in6p, &ifp) != 0)
+               return EINVAL;
 
        /* Source address selection. */
        if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr)
@@ -416,9 +367,14 @@
        if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)
         || (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr)
          && in6p->in6p_laddr.s6_addr32[3] == 0)) {
-               if (in6p->in6p_lport == 0)
+               if (in6p->in6p_lport == 0) {
+#ifdef __NetBSD__
                        (void)in6_pcbbind(in6p, (struct mbuf *)0,
                            (struct proc *)0);
+#else
+                       (void)in6_pcbbind(in6p, (struct mbuf *)0);
+#endif
+               }
                in6p->in6p_laddr = *in6a;
        }
        in6p->in6p_faddr = sin6->sin6_addr;
@@ -484,13 +440,8 @@
        sin6->sin6_family = AF_INET6;
        sin6->sin6_len = sizeof(struct sockaddr_in6);
        sin6->sin6_port = in6p->in6p_lport;
-       sin6->sin6_addr = in6p->in6p_laddr;
-       if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
-               sin6->sin6_scope_id = ntohs(sin6->sin6_addr.s6_addr16[1]);
-       else
-               sin6->sin6_scope_id = 0;        /*XXX*/
-       if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
-               sin6->sin6_addr.s6_addr16[1] = 0;
+       /* KAME hack: recover scopeid */
+       (void)in6_recoverscope(sin6, &in6p->in6p_laddr, NULL);
 }
 
 void
@@ -506,13 +457,8 @@
        sin6->sin6_family = AF_INET6;
        sin6->sin6_len = sizeof(struct sockaddr_in6);
        sin6->sin6_port = in6p->in6p_fport;
-       sin6->sin6_addr = in6p->in6p_faddr;
-       if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
-               sin6->sin6_scope_id = ntohs(sin6->sin6_addr.s6_addr16[1]);
-       else
-               sin6->sin6_scope_id = 0;        /*XXX*/
-       if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
-               sin6->sin6_addr.s6_addr16[1] = 0;
+       /* KAME hack: recover scopeid */
+       (void)in6_recoverscope(sin6, &in6p->in6p_faddr, NULL);
 }
 
 /*
@@ -540,9 +486,7 @@
        u_int16_t fport = fport_arg, lport = lport_arg;
        int errno;
        int nmatch = 0;
-       void (*notify2) __P((struct in6pcb *, int));
-
-       notify2 = NULL;
+       int do_rtchange = (notify == in6_rtchange);
 
        if ((unsigned)cmd > PRC_NCMDS || dst->sa_family != AF_INET6)
                return 0;
@@ -563,14 +507,7 @@
                lport = 0;
                bzero((caddr_t)laddr6, sizeof(*laddr6));
 
-               /*
-                * Keep the old notify function to store a soft error
-                * in each PCB.
-                */
-               if (cmd == PRC_HOSTDEAD && notify != in6_rtchange)
-                       notify2 = notify;
-
-               notify = in6_rtchange;
+               do_rtchange = 1;
        }
 
        if (notify == NULL)
@@ -580,7 +517,7 @@
        for (in6p = head->in6p_next; in6p != head; in6p = nin6p) {
                nin6p = in6p->in6p_next;
 
-               if (notify == in6_rtchange) {
+               if (do_rtchange) {
                        /*
                         * Since a non-connected PCB might have a cached route,
                         * we always call in6_rtchange without matching
@@ -592,10 +529,8 @@
                                               &faddr6))
                                in6_rtchange(in6p, errno);
 
-                       if (notify2 == NULL)
-                               continue;
-



Home | Main Index | Thread Index | Old Index