Source-Changes-HG archive

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

[src/trunk]: src/sys Make ip6_sprintf(), in_fmtaddr(), lla_snprintf() and icm...



details:   https://anonhg.NetBSD.org/src/rev/166aa7747984
branches:  trunk
changeset: 350677:166aa7747984
user:      ryo <ryo%NetBSD.org@localhost>
date:      Mon Jan 16 07:33:36 2017 +0000

description:
Make ip6_sprintf(), in_fmtaddr(), lla_snprintf() and icmp6_redirect_diag() mpsafe.

Reviewed by ozaki-r@

diffstat:

 sys/dist/pf/net/pf_osfp.c  |    9 +--
 sys/net/if_spppsubr.c      |   14 +++--
 sys/netinet/dccp_usrreq.c  |    9 ++-
 sys/netinet/if_arp.c       |   78 +++++++++++++++++---------------
 sys/netinet/in.c           |   19 +++----
 sys/netinet/in_var.h       |    4 +-
 sys/netinet/ip_carp.c      |   11 ++--
 sys/netinet/ip_output.c    |    7 +-
 sys/netinet/sctp_asconf.c  |   12 +++-
 sys/netinet/sctputil.c     |    7 +-
 sys/netinet6/icmp6.c       |   63 ++++++++++++++++---------
 sys/netinet6/in6.c         |   40 +++++++++-------
 sys/netinet6/in6_gif.c     |    7 +-
 sys/netinet6/in6_src.c     |   10 ++-
 sys/netinet6/in6_var.h     |    4 +-
 sys/netinet6/ip6_forward.c |   11 ++-
 sys/netinet6/ip6_input.c   |   10 ++-
 sys/netinet6/ip6_mroute.c  |  107 +++++++++++++++++++++++++++++---------------
 sys/netinet6/ip6_output.c  |    7 +-
 sys/netinet6/mld6.c        |    9 ++-
 sys/netinet6/nd6.c         |   26 ++++++----
 sys/netinet6/nd6_nbr.c     |   64 +++++++++++++++-----------
 sys/netinet6/nd6_rtr.c     |   77 ++++++++++++++++++++------------
 sys/netinet6/scope6.c      |    7 +-
 sys/netipsec/ipsec.c       |   10 ++-
 sys/netipsec/ipsec_input.c |   10 ++-
 26 files changed, 376 insertions(+), 256 deletions(-)

diffs (truncated from 2202 to 300 lines):

diff -r f214e3a7f2e4 -r 166aa7747984 sys/dist/pf/net/pf_osfp.c
--- a/sys/dist/pf/net/pf_osfp.c Mon Jan 16 04:45:06 2017 +0000
+++ b/sys/dist/pf/net/pf_osfp.c Mon Jan 16 07:33:36 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pf_osfp.c,v 1.11 2011/05/18 12:54:15 drochner Exp $    */
+/*     $NetBSD: pf_osfp.c,v 1.12 2017/01/16 07:33:36 ryo Exp $ */
 /*     $OpenBSD: pf_osfp.c,v 1.12 2006/12/13 18:14:10 itojun Exp $ */
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pf_osfp.c,v 1.11 2011/05/18 12:54:15 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pf_osfp.c,v 1.12 2017/01/16 07:33:36 ryo Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -172,9 +172,8 @@
                fp.fp_flags |= PF_OSFP_DF;
                fp.fp_flags |= PF_OSFP_INET6;
 #ifdef _KERNEL
-               strlcpy(srcname,
-                   ip6_sprintf((const struct in6_addr *)&ip6->ip6_src),
-                   sizeof(srcname));
+               CTASSERT(sizeof(srcname) >= INET6_ADDRSTRLEN);
+               ip6_sprintf(srcname, (const struct in6_addr *)&ip6->ip6_src);
 #else
                memset(&sin6, 0, sizeof(sin6));
                sin6.sin6_family = AF_INET6;
diff -r f214e3a7f2e4 -r 166aa7747984 sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c     Mon Jan 16 04:45:06 2017 +0000
+++ b/sys/net/if_spppsubr.c     Mon Jan 16 07:33:36 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppsubr.c,v 1.165 2016/12/27 13:49:58 christos Exp $        */
+/*     $NetBSD: if_spppsubr.c,v 1.166 2017/01/16 07:33:36 ryo Exp $     */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.165 2016/12/27 13:49:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.166 2017/01/16 07:33:36 ryo Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -3584,6 +3584,7 @@
        int ifidcount;
        int type;
        int collision, nohisaddr;
+       char ip6buf[INET6_ADDRSTRLEN];
 
        KASSERT(sppp_locked(sp));
 
@@ -3690,7 +3691,7 @@
 
                                if (debug) {
                                        addlog(" %s [%s]",
-                                           ip6_sprintf(&desiredaddr),
+                                           ip6_sprintf(ip6buf, &desiredaddr),
                                            sppp_cp_type_name(type));
                                }
                                continue;
@@ -3712,7 +3713,7 @@
                                memcpy(&p[2], &suggestaddr.s6_addr[8], 8);
                        }
                        if (debug)
-                               addlog(" %s [%s]", ip6_sprintf(&desiredaddr),
+                               addlog(" %s [%s]", ip6_sprintf(ip6buf, &desiredaddr),
                                    sppp_cp_type_name(type));
                        break;
                }
@@ -3739,7 +3740,7 @@
 
                if (debug) {
                        addlog(" send %s suggest %s\n",
-                           sppp_cp_type_name(type), ip6_sprintf(&suggestaddr));
+                           sppp_cp_type_name(type), ip6_sprintf(ip6buf, &suggestaddr));
                }
                sppp_cp_send(sp, PPP_IPV6CP, type, h->ident, rlen, buf);
        }
@@ -3818,6 +3819,7 @@
        struct ifnet *ifp = &sp->pp_if;
        int debug = ifp->if_flags & IFF_DEBUG;
        struct in6_addr suggestaddr;
+       char ip6buf[INET6_ADDRSTRLEN];
 
        KASSERT(sppp_locked(sp));
 
@@ -3857,7 +3859,7 @@
                        sp->ipv6cp.opts |= (1 << IPV6CP_OPT_IFID);
                        if (debug)
                                addlog(" [suggestaddr %s]",
-                                      ip6_sprintf(&suggestaddr));
+                                      ip6_sprintf(ip6buf, &suggestaddr));
 #ifdef IPV6CP_MYIFID_DYN
                        /*
                         * When doing dynamic address assignment,
diff -r f214e3a7f2e4 -r 166aa7747984 sys/netinet/dccp_usrreq.c
--- a/sys/netinet/dccp_usrreq.c Mon Jan 16 04:45:06 2017 +0000
+++ b/sys/netinet/dccp_usrreq.c Mon Jan 16 07:33:36 2017 +0000
@@ -1,5 +1,5 @@
 /*     $KAME: dccp_usrreq.c,v 1.67 2005/11/03 16:05:04 nishida Exp $   */
-/*     $NetBSD: dccp_usrreq.c,v 1.10 2016/12/13 08:29:03 ozaki-r Exp $ */
+/*     $NetBSD: dccp_usrreq.c,v 1.11 2017/01/16 07:33:36 ryo Exp $ */
 
 /*
  * Copyright (c) 2003 Joacim Häggmark, Magnus Erixzon, Nils-Erik Mattsson 
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.c,v 1.10 2016/12/13 08:29:03 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.c,v 1.11 2017/01/16 07:33:36 ryo Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -377,11 +377,12 @@
 
 #ifdef INET6
                        if (isipv6) {
+                               char ip6buf[INET6_ADDRSTRLEN];
                                strlcpy(dbuf, "[", sizeof dbuf);
-                               strlcat(dbuf, ip6_sprintf(&ip6->ip6_dst), sizeof dbuf);
+                               strlcat(dbuf, ip6_sprintf(ip6buf, &ip6->ip6_dst), sizeof dbuf);
                                strlcat(dbuf, "]", sizeof dbuf);
                                strlcpy(sbuf, "[", sizeof sbuf);
-                               strlcat(sbuf, ip6_sprintf(&ip6->ip6_src), sizeof sbuf);
+                               strlcat(sbuf, ip6_sprintf(ip6buf, &ip6->ip6_src), sizeof sbuf);
                                strlcat(sbuf, "]", sizeof sbuf);
                        } else
 #endif
diff -r f214e3a7f2e4 -r 166aa7747984 sys/netinet/if_arp.c
--- a/sys/netinet/if_arp.c      Mon Jan 16 04:45:06 2017 +0000
+++ b/sys/netinet/if_arp.c      Mon Jan 16 07:33:36 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arp.c,v 1.233 2016/12/12 03:55:57 ozaki-r Exp $     */
+/*     $NetBSD: if_arp.c,v 1.234 2017/01/16 07:33:36 ryo Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.233 2016/12/12 03:55:57 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.234 2017/01/16 07:33:36 ryo Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -221,34 +221,30 @@
  * this should be elsewhere.
  */
 
-static char *
-lla_snprintf(u_int8_t *, int);
+#define        LLA_ADDRSTRLEN  (16 * 3)
 
 static char *
-lla_snprintf(u_int8_t *adrp, int len)
+lla_snprintf(char *, u_int8_t *, int);
+
+static char *
+lla_snprintf(char *dst, u_int8_t *adrp, int len)
 {
-#define NUMBUFS 3
-       static char buf[NUMBUFS][16*3];
-       static int bnum = 0;
-
        int i;
        char *p;
 
-       p = buf[bnum];
+       p = dst;
 
-       *p++ = hexdigits[(*adrp)>>4];
-       *p++ = hexdigits[(*adrp++)&0xf];
+       *p++ = hexdigits[(*adrp) >> 4];
+       *p++ = hexdigits[(*adrp++) & 0xf];
 
-       for (i=1; i<len && i<16; i++) {
+       for (i = 1; i < len && i < 16; i++) {
                *p++ = ':';
-               *p++ = hexdigits[(*adrp)>>4];
-               *p++ = hexdigits[(*adrp++)&0xf];
+               *p++ = hexdigits[(*adrp) >> 4];
+               *p++ = hexdigits[(*adrp++) & 0xf];
        }
 
        *p = 0;
-       p = buf[bnum];
-       bnum = (bnum + 1) % NUMBUFS;
-       return p;
+       return dst;
 }
 
 DOMAIN_DEFINE(arpdomain);      /* forward declare and add to link set */
@@ -693,9 +689,10 @@
 {
        struct in_ifaddr *ia = ifatoia(ifa);
        struct in_addr *ip = &IA_SIN(ifa)->sin_addr;
+       char ipbuf[INET_ADDRSTRLEN];
 
        if (ia->ia4_flags & (IN_IFF_NOTREADY | IN_IFF_DETACHED)) {
-               arplog(LOG_DEBUG, "%s not ready\n", in_fmtaddr(*ip));
+               arplog(LOG_DEBUG, "%s not ready\n", in_fmtaddr(ipbuf, *ip));
                return;
        }
        arprequest(ifp, ip, ip, enaddr);
@@ -1016,6 +1013,8 @@
        uint64_t *arps;
        struct psref psref, psref_ia;
        int s;
+       char llabuf[LLA_ADDRSTRLEN];
+       char ipbuf[INET_ADDRSTRLEN];
 
        if (__predict_false(m_makewritable(&m, 0, m->m_pkthdr.len, M_DONTWAIT)))
                goto out;
@@ -1125,7 +1124,7 @@
                ARP_STATINC(ARP_STAT_RCVBCASTSHA);
                log(LOG_ERR,
                    "%s: arp: link address is broadcast for IP address %s!\n",
-                   ifp->if_xname, in_fmtaddr(isaddr));
+                   ifp->if_xname, in_fmtaddr(ipbuf, isaddr));
                goto out;
        }
 
@@ -1152,7 +1151,7 @@
            (in_nullhost(isaddr) && in_hosteq(itaddr, myaddr)))
        {
                arp_dad_duplicated((struct ifaddr *)ia,
-                   lla_snprintf(ar_sha(ah), ah->ar_hln));
+                   lla_snprintf(llabuf, ar_sha(ah), ah->ar_hln));
                goto out;
        }
 
@@ -1175,8 +1174,8 @@
                        log(LOG_INFO,
                            "%s tried to overwrite permanent arp info"
                            " for %s\n",
-                           lla_snprintf(ar_sha(ah), ah->ar_hln),
-                           in_fmtaddr(isaddr));
+                           lla_snprintf(llabuf, ar_sha(ah), ah->ar_hln),
+                           in_fmtaddr(ipbuf, isaddr));
                        goto out;
                } else if (la->lle_tbl->llt_ifp != ifp) {
                        /* XXX should not happen? */
@@ -1186,8 +1185,8 @@
                        log(LOG_INFO,
                            "%s on %s tried to overwrite "
                            "arp info for %s on %s\n",
-                           lla_snprintf(ar_sha(ah), ah->ar_hln),
-                           ifp->if_xname, in_fmtaddr(isaddr),
+                           lla_snprintf(llabuf, ar_sha(ah), ah->ar_hln),
+                           ifp->if_xname, in_fmtaddr(ipbuf, isaddr),
                            la->lle_tbl->llt_ifp->if_xname);
                                goto out;
                } else {
@@ -1195,8 +1194,8 @@
                        if (log_movements)
                                log(LOG_INFO, "arp info overwritten "
                                    "for %s by %s\n",
-                                   in_fmtaddr(isaddr),
-                                   lla_snprintf(ar_sha(ah),
+                                   in_fmtaddr(ipbuf, isaddr),
+                                   lla_snprintf(llabuf, ar_sha(ah),
                                    ah->ar_hln));
                }
        }
@@ -1212,7 +1211,7 @@
                ARP_STATINC(ARP_STAT_RCVLENCHG);
                log(LOG_WARNING,
                    "arp from %s: new addr len %d, was %d\n",
-                   in_fmtaddr(isaddr), ah->ar_hln, sdl->sdl_alen);
+                   in_fmtaddr(ipbuf, isaddr), ah->ar_hln, sdl->sdl_alen);
        }
 #endif
 
@@ -1220,7 +1219,7 @@
                ARP_STATINC(ARP_STAT_RCVBADLEN);
                log(LOG_WARNING,
                    "arp from %s: addr len: new %d, i/f %d (ignored)\n",
-                   in_fmtaddr(isaddr), ah->ar_hln,
+                   in_fmtaddr(ipbuf, isaddr), ah->ar_hln,
                    ifp->if_addrlen);
                goto reply;
        }
@@ -1574,6 +1573,7 @@
 {
        struct in_ifaddr *ia = (struct in_ifaddr *)ifa;
        struct dadq *dp;
+       char ipbuf[INET_ADDRSTRLEN];
 
        if (!dad_init) {
                TAILQ_INIT(&dadq);
@@ -1588,7 +1588,7 @@
        if (!(ia->ia4_flags & IN_IFF_TENTATIVE)) {
                log(LOG_DEBUG,



Home | Main Index | Thread Index | Old Index