Source-Changes-HG archive

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

[src/trunk]: src/sys/net Make functions that use for logging MP-safe



details:   https://anonhg.NetBSD.org/src/rev/f75eb04976f2
branches:  trunk
changeset: 1021237:f75eb04976f2
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Wed May 19 02:14:19 2021 +0000

description:
Make functions that use for logging MP-safe

There is no change in behavior.

diffstat:

 sys/net/if_spppsubr.c |  295 +++++++++++++++++++++++++++++++++----------------
 1 files changed, 196 insertions(+), 99 deletions(-)

diffs (truncated from 720 to 300 lines):

diff -r db4bd5c24654 -r f75eb04976f2 sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c     Wed May 19 02:07:20 2021 +0000
+++ b/sys/net/if_spppsubr.c     Wed May 19 02:14:19 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppsubr.c,v 1.245 2021/05/19 02:07:20 yamaguchi Exp $       */
+/*     $NetBSD: if_spppsubr.c,v 1.246 2021/05/19 02:14:19 yamaguchi Exp $       */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.245 2021/05/19 02:07:20 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.246 2021/05/19 02:14:19 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -116,6 +116,14 @@
 #define SPPP_ALIVE_INTERVAL            DEFAULT_ALIVE_INTERVAL
 #endif
 
+#define SPPP_CPTYPE_NAMELEN    5       /* buf size of cp type name */
+#define SPPP_AUTHTYPE_NAMELEN  32      /* buf size of auth type name */
+#define SPPP_LCPOPT_NAMELEN    5       /* buf size of lcp option name  */
+#define SPPP_IPCPOPT_NAMELEN   5       /* buf size of ipcp option name */
+#define SPPP_IPV6CPOPT_NAMELEN 5       /* buf size of ipv6cp option name */
+#define SPPP_PROTO_NAMELEN     7       /* buf size of protocol name */
+#define SPPP_DOTQUAD_BUFLEN    16      /* length of "aa.bb.cc.dd" */
+
 /*
  * Interface flags that can be set in an ifconfig command.
  *
@@ -437,16 +445,16 @@
 static void sppp_chap_scr(struct sppp *);
 static void sppp_chap_rcv_challenge_event(struct sppp *, void *);
 
-static const char *sppp_auth_type_name(u_short, u_char);
-static const char *sppp_cp_type_name(u_char);
-static const char *sppp_dotted_quad(uint32_t);
-static const char *sppp_ipcp_opt_name(u_char);
+static const char *sppp_auth_type_name(char *, size_t, u_short, u_char);
+static const char *sppp_cp_type_name(char *, size_t, u_char);
+static const char *sppp_dotted_quad(char *, size_t, uint32_t);
+static const char *sppp_ipcp_opt_name(char *, size_t, u_char);
 #ifdef INET6
-static const char *sppp_ipv6cp_opt_name(u_char);
+static const char *sppp_ipv6cp_opt_name(char *, size_t, u_char);
 #endif
-static const char *sppp_lcp_opt_name(u_char);
+static const char *sppp_lcp_opt_name(char *, size_t, u_char);
 static const char *sppp_phase_name(int);
-static const char *sppp_proto_name(u_short);
+static const char *sppp_proto_name(char *, size_t, u_short);
 static const char *sppp_state_name(int);
 static int sppp_params(struct sppp *, u_long, void *);
 #ifdef INET
@@ -1612,10 +1620,15 @@
                memcpy(lh + 1, data, len);
 
        if (debug) {
+               char pbuf[SPPP_PROTO_NAMELEN];
+               char tbuf[SPPP_CPTYPE_NAMELEN];
+               const char *pname, *cpname;
+
+               pname = sppp_proto_name(pbuf, sizeof(pbuf), proto);
+               cpname = sppp_cp_type_name(tbuf, sizeof(tbuf), lh->type);
                log(LOG_DEBUG, "%s: %s output <%s id=0x%x len=%d",
-                   ifp->if_xname,
-                   sppp_proto_name(proto),
-                   sppp_cp_type_name(lh->type), lh->ident, ntohs(lh->len));
+                   ifp->if_xname, pname, cpname,
+                   lh->ident, ntohs(lh->len));
                if (len)
                        sppp_print_bytes((u_char *)(lh + 1), len);
                addlog(">\n");
@@ -1756,6 +1769,8 @@
        int printlen, len = m->m_pkthdr.len;
        u_char *p;
        uint32_t u32;
+       char tbuf[SPPP_CPTYPE_NAMELEN];
+       const char *cpname;
 
        SPPP_LOCK(sp, RW_WRITER);
 
@@ -1771,11 +1786,12 @@
        h = mtod(m, struct lcp_header *);
        if (debug) {
                printlen = ntohs(h->len);
+               cpname = sppp_cp_type_name(tbuf, sizeof(tbuf), h->type);
                log(LOG_DEBUG,
                    "%s: %s input(%s): <%s id=0x%x len=%d",
                    ifp->if_xname, cp->name,
                    sppp_state_name(scp->state),
-                   sppp_cp_type_name(h->type), h->ident, printlen);
+                   cpname, h->ident, printlen);
                if (len < printlen)
                        printlen = len;
                if (printlen > 4)
@@ -1855,11 +1871,11 @@
                break;
        case CODE_REJ:
                /* XXX catastrophic rejects (RXJ-) aren't handled yet. */
+               cpname = sppp_cp_type_name(tbuf, sizeof(tbuf), h->type);
                log(LOG_INFO,
                    "%s: %s: ignoring RXJ (%s) for code ?, "
                    "danger will robinson\n",
-                   ifp->if_xname, cp->name,
-                   sppp_cp_type_name(h->type));
+                   ifp->if_xname, cp->name, cpname);
                sppp_wq_add(sp->wq_cp, &scp->work_rxj);
                break;
        case PROTO_REJ:
@@ -1881,13 +1897,14 @@
                if (upper == NULL)
                        catastrophic++;
 
-               if (debug)
+               if (debug) {
+                       cpname = sppp_cp_type_name(tbuf, sizeof(tbuf), h->type);
                        log(LOG_INFO,
                            "%s: %s: RXJ%c (%s) for proto 0x%x (%s/%s)\n",
                            ifp->if_xname, cp->name, catastrophic ? '-' : '+',
-                           sppp_cp_type_name(h->type), proto,
-                           upper ? upper->name : "unknown",
+                           cpname, proto, upper ? upper->name : "unknown",
                            upper ? sppp_state_name(sp->scp[upper->protoidx].state) : "?");
+               }
 
                /*
                 * if we got RXJ+ against conf-req, the peer does not implement
@@ -2800,6 +2817,7 @@
        int len, rlen;
        uint32_t nmagic;
        u_short authproto;
+       char lbuf[SPPP_LCPOPT_NAMELEN];
 
        KASSERT(SPPP_WLOCKED(sp));
 
@@ -2845,7 +2863,7 @@
                        goto end;
                }
                if (debug)
-                       addlog(" %s", sppp_lcp_opt_name(*p));
+                       addlog(" %s", sppp_lcp_opt_name(lbuf, sizeof(lbuf), *p));
                switch (p[0]) {
                case LCP_OPT_MAGIC:
                        /* Magic number. */
@@ -2964,7 +2982,7 @@
                        break;
 
                if (debug)
-                       addlog(" %s", sppp_lcp_opt_name(*p));
+                       addlog(" %s", sppp_lcp_opt_name(lbuf, sizeof(lbuf), *p));
                switch (p[0]) {
                case LCP_OPT_MAGIC:
                        /* Magic number -- extract. */
@@ -3050,10 +3068,18 @@
                                if (debug)
                                        addlog(" [chap without MD5]");
                        } else {
-                               if (debug)
+                               if (debug) {
+                                       char pbuf1[SPPP_PROTO_NAMELEN];
+                                       char pbuf2[SPPP_PROTO_NAMELEN];
+                                       const char *pname1, *pname2;
+
+                                       pname1 = sppp_proto_name(pbuf1,
+                                           sizeof(pbuf1), sp->myauth.proto);
+                                       pname2 = sppp_proto_name(pbuf2,
+                                           sizeof(pbuf2), authproto);
                                        addlog(" [mine %s != his %s]",
-                                              sppp_proto_name(sp->myauth.proto),
-                                              sppp_proto_name(authproto));
+                                              pname1, pname2);
+                               }
                        }
                        /* not agreed, nak */
                        if (sp->myauth.proto == PPP_CHAP) {
@@ -3176,8 +3202,10 @@
                            "dropping.\n", ifp->if_xname);
                        goto end;
                }
-               if (debug)
-                       addlog(" %s", sppp_lcp_opt_name(*p));
+               if (debug) {
+                       char lbuf[SPPP_LCPOPT_NAMELEN];
+                       addlog(" %s", sppp_lcp_opt_name(lbuf, sizeof(lbuf), *p));
+               }
                switch (p[0]) {
                case LCP_OPT_MAGIC:
                        /* Magic number -- can't use it, use 0 */
@@ -3258,8 +3286,10 @@
                            "dropping.\n", ifp->if_xname);
                        goto end;
                }
-               if (debug)
-                       addlog(" %s", sppp_lcp_opt_name(*p));
+               if (debug) {
+                       char lbuf[SPPP_LCPOPT_NAMELEN];
+                       addlog(" %s", sppp_lcp_opt_name(lbuf, sizeof(lbuf),*p));
+               }
                switch (p[0]) {
                case LCP_OPT_MAGIC:
                        /* Magic number -- renegotiate */
@@ -3687,6 +3717,9 @@
        struct ifnet *ifp = &sp->pp_if;
        int rlen, len, debug = ifp->if_flags & IFF_DEBUG;
        uint32_t hisaddr, desiredaddr;
+       char ipbuf[SPPP_IPCPOPT_NAMELEN];
+       char dqbuf[SPPP_DOTQUAD_BUFLEN];
+       const char *dq;
 
        KASSERT(SPPP_WLOCKED(sp));
 
@@ -3726,8 +3759,10 @@
                        type = CP_RCR_ERR;
                        goto end;
                }
-               if (debug)
-                       addlog(" %s", sppp_ipcp_opt_name(*p));
+               if (debug) {
+                       addlog(" %s",
+                           sppp_ipcp_opt_name(ipbuf, sizeof(ipbuf), *p));
+               }
                switch (p[0]) {
 #ifdef notyet
                case IPCP_OPT_COMPRESSION:
@@ -3792,8 +3827,10 @@
                if (l == 0)
                        break;
 
-               if (debug)
-                       addlog(" %s", sppp_ipcp_opt_name(*p));
+               if (debug) {
+                       addlog(" %s",
+                           sppp_ipcp_opt_name(ipbuf, sizeof(ipbuf), *p));
+               }
                switch (p[0]) {
 #ifdef notyet
                case IPCP_OPT_COMPRESSION:
@@ -3809,9 +3846,11 @@
                                * this is agreeable.  Gonna conf-ack
                                * it.
                                */
-                               if (debug)
-                                       addlog(" %s [ack]",
-                                               sppp_dotted_quad(hisaddr));
+                               if (debug) {
+                                       dq = sppp_dotted_quad(dqbuf,
+                                           sizeof(dqbuf), hisaddr);
+                                       addlog(" %s [ack]", dq);
+                               }
                                /* record that we've seen it already */
                                sp->ipcp.flags |= IPCP_HISADDR_SEEN;
                                sp->ipcp.req_hisaddr = desiredaddr;
@@ -3826,11 +3865,13 @@
                        * conf-nak it with our value.
                        */
                        if (debug) {
-                               if (desiredaddr == 0)
+                               if (desiredaddr == 0) {
                                        addlog(" [addr requested]");
-                               else
-                                       addlog(" %s [not agreed]",
-                                               sppp_dotted_quad(desiredaddr));
+                               } else {
+                                       dq = sppp_dotted_quad(dqbuf,
+                                           sizeof(dqbuf), desiredaddr);
+                                       addlog(" %s [not agreed]", dq);
+                               }
                        }
 
                        p[2] = hisaddr >> 24;
@@ -3932,8 +3973,11 @@
                            ifp->if_xname);
                        goto end;
                }
-               if (debug)
-                       addlog(" %s", sppp_ipcp_opt_name(*p));
+               if (debug) {
+                       char ipbuf[SPPP_IPCPOPT_NAMELEN];
+                       addlog(" %s",
+                           sppp_ipcp_opt_name(ipbuf, sizeof(ipbuf), *p));
+               }
                switch (p[0]) {
                case IPCP_OPT_ADDRESS:
                        /*
@@ -4000,8 +4044,11 @@
                            ifp->if_xname);
                        return;
                }
-               if (debug)
-                       addlog(" %s", sppp_ipcp_opt_name(*p));
+               if (debug) {
+                       char ipbuf[SPPP_IPCPOPT_NAMELEN];
+                       addlog(" %s",
+                           sppp_ipcp_opt_name(ipbuf, sizeof(ipbuf), *p));
+               }
                switch (*p) {



Home | Main Index | Thread Index | Old Index