Source-Changes-HG archive

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

[src/trunk]: src/sys/net Add a structure for params related to control protocols



details:   https://anonhg.NetBSD.org/src/rev/6d57356b16ed
branches:  trunk
changeset: 946369:6d57356b16ed
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Wed Nov 25 09:12:50 2020 +0000

description:
Add a structure for params related to control protocols

diffstat:

 sys/net/if_spppsubr.c |  308 ++++++++++++++++++++++++-------------------------
 sys/net/if_spppvar.h  |   19 +-
 2 files changed, 165 insertions(+), 162 deletions(-)

diffs (truncated from 1000 to 300 lines):

diff -r ef91b7cf99b6 -r 6d57356b16ed sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c     Wed Nov 25 09:09:24 2020 +0000
+++ b/sys/net/if_spppsubr.c     Wed Nov 25 09:12:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppsubr.c,v 1.191 2020/11/25 09:09:24 yamaguchi Exp $       */
+/*     $NetBSD: if_spppsubr.c,v 1.192 2020/11/25 09:12:50 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.191 2020/11/25 09:09:24 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.192 2020/11/25 09:12:50 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -626,12 +626,12 @@
 
        switch (protocol) {
        default:
-               if (sp->state[IDX_LCP] == STATE_OPENED) {
+               if (sp->scp[IDX_LCP].state == STATE_OPENED) {
                        uint16_t prot = htons(protocol);
 
                        SPPP_UPGRADE(sp);
                        sppp_cp_send(sp, PPP_LCP, PROTO_REJ,
-                           ++sp->pp_seq[IDX_LCP], m->m_pkthdr.len + 2,
+                           ++sp->scp[IDX_LCP].seq, m->m_pkthdr.len + 2,
                            &prot);
                        SPPP_DOWNGRADE(sp);
                }
@@ -669,7 +669,7 @@
                m_freem(m);
                return;
        case PPP_IP:
-               if (sp->state[IDX_IPCP] == STATE_OPENED) {
+               if (sp->scp[IDX_IPCP].state == STATE_OPENED) {
                        sp->pp_last_activity = time_uptime;
                        pktq = ip_pktq;
                }
@@ -685,7 +685,7 @@
                return;
 
        case PPP_IPV6:
-               if (sp->state[IDX_IPV6CP] == STATE_OPENED) {
+               if (sp->scp[IDX_IPV6CP].state == STATE_OPENED) {
                        sp->pp_last_activity = time_uptime;
                        pktq = ip6_pktq;
                }
@@ -888,7 +888,7 @@
                         * ENETDOWN, as opposed to ENOBUFS.
                         */
                        protocol = htons(PPP_IP);
-                       if (sp->state[IDX_IPCP] != STATE_OPENED)
+                       if (sp->scp[IDX_IPCP].state != STATE_OPENED)
                                error = ENETDOWN;
                }
                break;
@@ -908,7 +908,7 @@
                         * ENETDOWN, as opposed to ENOBUFS.
                         */
                        protocol = htons(PPP_IPV6);
-                       if (sp->state[IDX_IPV6CP] != STATE_OPENED)
+                       if (sp->scp[IDX_IPV6CP].state != STATE_OPENED)
                                error = ENETDOWN;
                }
                break;
@@ -995,13 +995,11 @@
        sp->pp_maxalive = DEFAULT_MAXALIVECNT;
        sp->pp_max_noreceive = DEFAULT_NORECV_TIME;
        sp->pp_idle_timeout = 0;
-       memset(&sp->pp_seq[0], 0, sizeof(sp->pp_seq));
-       memset(&sp->pp_rseq[0], 0, sizeof(sp->pp_rseq));
-       sp->pp_auth_failures = 0;
        sp->pp_max_auth_fail = DEFAULT_MAX_AUTH_FAILURES;
        sp->pp_phase = SPPP_PHASE_DEAD;
        sp->pp_up = sppp_notify_up;
        sp->pp_down = sppp_notify_down;
+       memset(sp->scp, 0, sizeof(sp->scp));
        rw_init(&sp->pp_lock);
 
        if_alloc_sadl(ifp);
@@ -1049,12 +1047,12 @@
        workqueue_destroy(sp->ipcp.update_addrs_wq);
        pcq_destroy(sp->ipcp.update_addrs_q);
 
-       callout_stop(&sp->ch[IDX_LCP]);
-       callout_stop(&sp->ch[IDX_IPCP]);
-       callout_stop(&sp->ch[IDX_PAP]);
-       callout_stop(&sp->ch[IDX_CHAP]);
+       callout_stop(&sp->scp[IDX_LCP].ch);
+       callout_stop(&sp->scp[IDX_IPCP].ch);
+       callout_stop(&sp->scp[IDX_PAP].ch);
+       callout_stop(&sp->scp[IDX_CHAP].ch);
 #ifdef INET6
-       callout_stop(&sp->ch[IDX_IPV6CP]);
+       callout_stop(&sp->scp[IDX_IPV6CP].ch);
 #endif
        callout_stop(&sp->pap_my_to_ch);
 
@@ -1296,8 +1294,8 @@
                break;
        case CISCO_KEEPALIVE_REQ:
                sp->pp_alivecnt = 0;
-               sp->pp_rseq[IDX_LCP] = ntohl(h->par1);
-               if (sp->pp_seq[IDX_LCP] == sp->pp_rseq[IDX_LCP]) {
+               sp->scp[IDX_LCP].rseq = ntohl(h->par1);
+               if (sp->scp[IDX_LCP].seq == sp->scp[IDX_LCP].rseq) {
                        /* Local and remote sequence numbers are equal.
                         * Probably, the line is in loopback mode. */
                        if (sp->pp_loopcnt >= LOOPALIVECNT) {
@@ -1315,7 +1313,7 @@
                        ++sp->pp_loopcnt;
 
                        /* Generate new local sequence number */
-                       sp->pp_seq[IDX_LCP] = cprng_fast32();
+                       sp->scp[IDX_LCP].seq = cprng_fast32();
                        break;
                }
                sp->pp_loopcnt = 0;
@@ -1500,7 +1498,7 @@
                log(LOG_DEBUG,
                    "%s: %s input(%s): <%s id=0x%x len=%d",
                    ifp->if_xname, cp->name,
-                   sppp_state_name(sp->state[cp->protoidx]),
+                   sppp_state_name(sp->scp[cp->protoidx].state),
                    sppp_cp_type_name(h->type), h->ident, printlen);
                if (len < printlen)
                        printlen = len;
@@ -1522,7 +1520,7 @@
                        break;
                }
                /* handle states where RCR doesn't get a SCA/SCN */
-               switch (sp->state[cp->protoidx]) {
+               switch (sp->scp[cp->protoidx].state) {
                case STATE_CLOSING:
                case STATE_STOPPING:
                        SPPP_UNLOCK(sp);
@@ -1541,7 +1539,7 @@
                        SPPP_UNLOCK(sp);
                        return;
                }
-               switch (sp->state[cp->protoidx]) {
+               switch (sp->scp[cp->protoidx].state) {
                case STATE_OPENED:
                        (cp->tld)(sp);
                        (cp->scr)(sp);
@@ -1552,7 +1550,7 @@
                                             STATE_ACK_SENT: STATE_REQ_SENT);
                        break;
                case STATE_STOPPED:
-                       sp->rst_counter[cp->protoidx] = sp->lcp.max_configure;
+                       sp->scp[cp->protoidx].rst_counter = sp->lcp.max_configure;
                        (cp->scr)(sp);
                        sppp_cp_change_state(cp, sp, rv?
                                             STATE_ACK_SENT: STATE_REQ_SENT);
@@ -1572,20 +1570,20 @@
                        printf("%s: %s illegal %s in state %s\n",
                               ifp->if_xname, cp->name,
                               sppp_cp_type_name(h->type),
-                              sppp_state_name(sp->state[cp->protoidx]));
+                              sppp_state_name(sp->scp[cp->protoidx].state));
                        if_statinc(ifp, if_ierrors);
                }
                break;
        case CONF_ACK:
-               if (h->ident != sp->confid[cp->protoidx]) {
+               if (h->ident != sp->scp[cp->protoidx].confid) {
                        if (debug)
                                addlog("%s: %s id mismatch 0x%x != 0x%x\n",
                                       ifp->if_xname, cp->name,
-                                      h->ident, sp->confid[cp->protoidx]);
+                                      h->ident, sp->scp[cp->protoidx].confid);
                        if_statinc(ifp, if_ierrors);
                        break;
                }
-               switch (sp->state[cp->protoidx]) {
+               switch (sp->scp[cp->protoidx].state) {
                case STATE_CLOSED:
                case STATE_STOPPED:
                        sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0);
@@ -1594,7 +1592,7 @@
                case STATE_STOPPING:
                        break;
                case STATE_REQ_SENT:
-                       sp->rst_counter[cp->protoidx] = sp->lcp.max_configure;
+                       sp->scp[cp->protoidx].rst_counter = sp->lcp.max_configure;
                        sppp_cp_change_state(cp, sp, STATE_ACK_RCVD);
                        break;
                case STATE_OPENED:
@@ -1605,7 +1603,7 @@
                        sppp_cp_change_state(cp, sp, STATE_REQ_SENT);
                        break;
                case STATE_ACK_SENT:
-                       sp->rst_counter[cp->protoidx] = sp->lcp.max_configure;
+                       sp->scp[cp->protoidx].rst_counter = sp->lcp.max_configure;
                        sppp_cp_change_state(cp, sp, STATE_OPENED);
                        if (debug)
                                log(LOG_DEBUG, "%s: %s tlu\n",
@@ -1616,17 +1614,17 @@
                        printf("%s: %s illegal %s in state %s\n",
                               ifp->if_xname, cp->name,
                               sppp_cp_type_name(h->type),
-                              sppp_state_name(sp->state[cp->protoidx]));
+                              sppp_state_name(sp->scp[cp->protoidx].state));
                        if_statinc(ifp, if_ierrors);
                }
                break;
        case CONF_NAK:
        case CONF_REJ:
-               if (h->ident != sp->confid[cp->protoidx]) {
+               if (h->ident != sp->scp[cp->protoidx].confid) {
                        if (debug)
                                addlog("%s: %s id mismatch 0x%x != 0x%x\n",
                                       ifp->if_xname, cp->name,
-                                      h->ident, sp->confid[cp->protoidx]);
+                                      h->ident, sp->scp[cp->protoidx].confid);
                        if_statinc(ifp, if_ierrors);
                        break;
                }
@@ -1635,14 +1633,14 @@
                else /* CONF_REJ */
                        (cp->RCN_rej)(sp, h, len);
 
-               switch (sp->state[cp->protoidx]) {
+               switch (sp->scp[cp->protoidx].state) {
                case STATE_CLOSED:
                case STATE_STOPPED:
                        sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0);
                        break;
                case STATE_REQ_SENT:
                case STATE_ACK_SENT:
-                       sp->rst_counter[cp->protoidx] = sp->lcp.max_configure;
+                       sp->scp[cp->protoidx].rst_counter = sp->lcp.max_configure;
                        (cp->scr)(sp);
                        break;
                case STATE_OPENED:
@@ -1659,13 +1657,13 @@
                        printf("%s: %s illegal %s in state %s\n",
                               ifp->if_xname, cp->name,
                               sppp_cp_type_name(h->type),
-                              sppp_state_name(sp->state[cp->protoidx]));
+                              sppp_state_name(sp->scp[cp->protoidx].state));
                        if_statinc(ifp, if_ierrors);
                }
                break;
 
        case TERM_REQ:
-               switch (sp->state[cp->protoidx]) {
+               switch (sp->scp[cp->protoidx].state) {
                case STATE_ACK_RCVD:
                case STATE_ACK_SENT:
                        sppp_cp_change_state(cp, sp, STATE_REQ_SENT);
@@ -1684,19 +1682,19 @@
                        break;
                case STATE_OPENED:
                        (cp->tld)(sp);
-                       sp->rst_counter[cp->protoidx] = 0;
+                       sp->scp[cp->protoidx].rst_counter = 0;
                        sppp_cp_change_state(cp, sp, STATE_STOPPING);
                        goto sta;
                default:
                        printf("%s: %s illegal %s in state %s\n",
                               ifp->if_xname, cp->name,
                               sppp_cp_type_name(h->type),
-                              sppp_state_name(sp->state[cp->protoidx]));
+                              sppp_state_name(sp->scp[cp->protoidx].state));
                        if_statinc(ifp, if_ierrors);
                }
                break;
        case TERM_ACK:
-               switch (sp->state[cp->protoidx]) {
+               switch (sp->scp[cp->protoidx].state) {
                case STATE_CLOSED:
                case STATE_STOPPED:
                case STATE_REQ_SENT:
@@ -1724,7 +1722,7 @@
                        printf("%s: %s illegal %s in state %s\n",
                               ifp->if_xname, cp->name,
                               sppp_cp_type_name(h->type),
-                              sppp_state_name(sp->state[cp->protoidx]));
+                              sppp_state_name(sp->scp[cp->protoidx].state));
                        if_statinc(ifp, if_ierrors);
                }
                break;
@@ -1735,7 +1733,7 @@
                    "danger will robinson\n",
                    ifp->if_xname, cp->name,
                    sppp_cp_type_name(h->type));
-               switch (sp->state[cp->protoidx]) {
+               switch (sp->scp[cp->protoidx].state) {
                case STATE_CLOSED:
                case STATE_STOPPED:
                case STATE_REQ_SENT:
@@ -1751,7 +1749,7 @@
                        printf("%s: %s illegal %s in state %s\n",
                               ifp->if_xname, cp->name,
                               sppp_cp_type_name(h->type),



Home | Main Index | Thread Index | Old Index