Source-Changes-HG archive

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

[src/trunk]: src/sys/net change function name(RCR => parse_confreq)



details:   https://anonhg.NetBSD.org/src/rev/fb7b7d116390
branches:  trunk
changeset: 957355:fb7b7d116390
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Wed Nov 25 10:03:38 2020 +0000

description:
change function name(RCR => parse_confreq)

reviewed by knakahara@n.o.

diffstat:

 sys/net/if_spppsubr.c |  371 ++++++++++++++++++++++++++++---------------------
 1 files changed, 208 insertions(+), 163 deletions(-)

diffs (truncated from 858 to 300 lines):

diff -r 291c87f30026 -r fb7b7d116390 sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c     Wed Nov 25 09:59:52 2020 +0000
+++ b/sys/net/if_spppsubr.c     Wed Nov 25 10:03:38 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppsubr.c,v 1.204 2020/11/25 09:59:52 yamaguchi Exp $       */
+/*     $NetBSD: if_spppsubr.c,v 1.205 2020/11/25 10:03:38 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.204 2020/11/25 09:59:52 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.205 2020/11/25 10:03:38 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -197,6 +197,15 @@
 #define STATE_ACK_SENT 8
 #define STATE_OPENED   9
 
+enum cp_rcr_type {
+       CP_RCR_NONE = 0,        /* initial value */
+       CP_RCR_ACK,     /* RCR+ */
+       CP_RCR_NAK,     /* RCR- */
+       CP_RCR_REJ,     /* RCR- */
+       CP_RCR_DROP,    /* DROP message */
+       CP_RCR_ERR,     /* internal error */
+};
+
 struct ppp_header {
        uint8_t address;
        uint8_t control;
@@ -242,9 +251,6 @@
        void    (*Open)(struct sppp *, void *);
        void    (*Close)(struct sppp *, void *);
        void    (*TO)(struct sppp *, void *);
-       int     (*RCR)(struct sppp *, struct lcp_header *, int);
-       void    (*RCN_rej)(struct sppp *, struct lcp_header *, int);
-       void    (*RCN_nak)(struct sppp *, struct lcp_header *, int);
        /* actions */
        void    (*tlu)(struct sppp *);
        void    (*tld)(struct sppp *);
@@ -252,6 +258,13 @@
        void    (*tlf)(const struct cp *, struct sppp *);
        void    (*scr)(struct sppp *);
        void    (*scan)(const struct cp *, struct sppp *);
+
+       /* message parser */
+       enum cp_rcr_type
+               (*parse_confreq)(struct sppp *, struct lcp_header *, int,
+                           uint8_t **, size_t *, size_t *);
+       void    (*parse_confrej)(struct sppp *, struct lcp_header *, int);
+       void    (*parse_confnak)(struct sppp *, struct lcp_header *, int);
 };
 
 enum auth_role {
@@ -357,9 +370,11 @@
 static void sppp_lcp_up(struct sppp *, void *);
 static void sppp_lcp_down(struct sppp *, void *);
 static void sppp_lcp_open(struct sppp *, void *);
-static int sppp_lcp_RCR(struct sppp *, struct lcp_header *, int);
-static void sppp_lcp_RCN_rej(struct sppp *, struct lcp_header *, int);
-static void sppp_lcp_RCN_nak(struct sppp *, struct lcp_header *, int);
+static enum cp_rcr_type
+           sppp_lcp_confreq(struct sppp *, struct lcp_header *, int,
+                   uint8_t **, size_t *, size_t *);
+static void sppp_lcp_confrej(struct sppp *, struct lcp_header *, int);
+static void sppp_lcp_confnak(struct sppp *, struct lcp_header *, int);
 static void sppp_lcp_tlu(struct sppp *);
 static void sppp_lcp_tld(struct sppp *);
 static void sppp_lcp_tls(const struct cp *, struct sppp *);
@@ -371,17 +386,21 @@
 static void sppp_ipcp_init(struct sppp *);
 static void sppp_ipcp_open(struct sppp *, void *);
 static void sppp_ipcp_close(struct sppp *, void *);
-static int sppp_ipcp_RCR(struct sppp *, struct lcp_header *, int);
-static void sppp_ipcp_RCN_rej(struct sppp *, struct lcp_header *, int);
-static void sppp_ipcp_RCN_nak(struct sppp *, struct lcp_header *, int);
+static enum cp_rcr_type
+           sppp_ipcp_confreq(struct sppp *, struct lcp_header *, int,
+                   uint8_t **, size_t *, size_t *);
+static void sppp_ipcp_confrej(struct sppp *, struct lcp_header *, int);
+static void sppp_ipcp_confnak(struct sppp *, struct lcp_header *, int);
 static void sppp_ipcp_tlu(struct sppp *);
 static void sppp_ipcp_scr(struct sppp *);
 
 static void sppp_ipv6cp_init(struct sppp *);
 static void sppp_ipv6cp_open(struct sppp *, void *);
-static int sppp_ipv6cp_RCR(struct sppp *, struct lcp_header *, int);
-static void sppp_ipv6cp_RCN_rej(struct sppp *, struct lcp_header *, int);
-static void sppp_ipv6cp_RCN_nak(struct sppp *, struct lcp_header *, int);
+static enum cp_rcr_type
+           sppp_ipv6cp_confreq(struct sppp *, struct lcp_header *, int,
+                   uint8_t **, size_t *, size_t *);
+static void sppp_ipv6cp_confrej(struct sppp *, struct lcp_header *, int);
+static void sppp_ipv6cp_confnak(struct sppp *, struct lcp_header *, int);
 static void sppp_ipv6cp_tlu(struct sppp *);
 static void sppp_ipv6cp_scr(struct sppp *);
 
@@ -447,10 +466,11 @@
 /* our control protocol descriptors */
 static const struct cp lcp = {
        PPP_LCP, IDX_LCP, CP_LCP, "lcp",
-       sppp_lcp_up, sppp_lcp_down, sppp_lcp_open, sppp_close_event,
-       sppp_to_event, sppp_lcp_RCR, sppp_lcp_RCN_rej, sppp_lcp_RCN_nak,
-       sppp_lcp_tlu, sppp_lcp_tld, sppp_lcp_tls, sppp_lcp_tlf,
-       sppp_lcp_scr, sppp_sca_scn
+       sppp_lcp_up, sppp_lcp_down, sppp_lcp_open,
+       sppp_close_event, sppp_to_event,
+       sppp_lcp_tlu, sppp_lcp_tld, sppp_lcp_tls,
+       sppp_lcp_tlf, sppp_lcp_scr, sppp_sca_scn,
+       sppp_lcp_confreq, sppp_lcp_confrej, sppp_lcp_confnak
 };
 
 static const struct cp ipcp = {
@@ -461,10 +481,11 @@
        0,
 #endif
        "ipcp",
-       sppp_up_event, sppp_down_event, sppp_ipcp_open, sppp_ipcp_close,
-       sppp_to_event, sppp_ipcp_RCR, sppp_ipcp_RCN_rej, sppp_ipcp_RCN_nak,
-       sppp_ipcp_tlu, sppp_null, sppp_tls, sppp_tlf,
-       sppp_ipcp_scr, sppp_sca_scn
+       sppp_up_event, sppp_down_event, sppp_ipcp_open,
+       sppp_ipcp_close, sppp_to_event,
+       sppp_ipcp_tlu, sppp_null, sppp_tls,
+       sppp_tlf, sppp_ipcp_scr, sppp_sca_scn,
+       sppp_ipcp_confreq, sppp_ipcp_confrej, sppp_ipcp_confnak,
 };
 
 static const struct cp ipv6cp = {
@@ -475,26 +496,29 @@
        0,
 #endif
        "ipv6cp",
-       sppp_up_event, sppp_down_event, sppp_ipv6cp_open, sppp_close_event,
-       sppp_to_event, sppp_ipv6cp_RCR, sppp_ipv6cp_RCN_rej, sppp_ipv6cp_RCN_nak,
-       sppp_ipv6cp_tlu, sppp_null, sppp_tls, sppp_tlf,
-       sppp_ipv6cp_scr, sppp_sca_scn
+       sppp_up_event, sppp_down_event, sppp_ipv6cp_open,
+       sppp_close_event, sppp_to_event,
+       sppp_ipv6cp_tlu, sppp_null, sppp_tls,
+       sppp_tlf, sppp_ipv6cp_scr, sppp_sca_scn,
+       sppp_ipv6cp_confreq, sppp_ipv6cp_confrej, sppp_ipv6cp_confnak,
 };
 
 static const struct cp pap = {
        PPP_PAP, IDX_PAP, CP_AUTH, "pap",
-       sppp_up_event, sppp_down_event, sppp_open_event, sppp_close_event,
-       sppp_to_event, 0, 0, 0,
+       sppp_up_event, sppp_down_event, sppp_open_event,
+       sppp_close_event, sppp_to_event,
        sppp_pap_tlu, sppp_null, sppp_tls, sppp_tlf,
-       sppp_pap_scr, sppp_auth_sca_scn
+       sppp_pap_scr, sppp_auth_sca_scn,
+       NULL, NULL, NULL
 };
 
 static const struct cp chap = {
        PPP_CHAP, IDX_CHAP, CP_AUTH, "chap",
-       sppp_up_event, sppp_down_event, sppp_chap_open, sppp_close_event,
-       sppp_auth_to_event, 0, 0, 0,
+       sppp_up_event, sppp_down_event, sppp_chap_open,
+       sppp_close_event, sppp_auth_to_event,
        sppp_chap_tlu, sppp_null, sppp_tls, sppp_tlf,
-       sppp_chap_scr, sppp_auth_sca_scn
+       sppp_chap_scr, sppp_auth_sca_scn,
+       NULL, NULL, NULL
 };
 
 static const struct cp *cps[IDX_COUNT] = {
@@ -1593,9 +1617,11 @@
        STDDCL;
        struct lcp_header *h;
        int printlen, len = m->m_pkthdr.len;
-       int rv;
+       enum cp_rcr_type type;
+       size_t blen, rlen;
        u_char *p;
        uint32_t u32;
+       uint8_t *buf;
 
        SPPP_LOCK(sp, RW_WRITER);
 
@@ -1634,16 +1660,33 @@
                        if_statinc(ifp, if_ierrors);
                        break;
                }
-               rv = (cp->RCR)(sp, h, len);
-               if (rv < 0) {
+
+               buf = NULL;
+               blen = 0;
+               rlen = 0;
+
+               type = (cp->parse_confreq)(sp, h, len,
+                   &buf, &blen, &rlen);
+
+               if  (type == CP_RCR_ERR) {
                        /* fatal error, shut down */
-                       (cp->tld)(sp);
-                       lcp.tlf(&lcp, sp);
-                       SPPP_UNLOCK(sp);
-                       return;
+                       sppp_wq_add(sp->wq_cp, &sp->scp[IDX_LCP].work_close);
+                       sppp_wq_add(sp->wq_cp, &sp->scp[IDX_LCP].work_open);
+               } else if (buf != NULL) {
+                       if (sp->scp[cp->protoidx].rcr_buf != NULL) {
+                               kmem_intr_free(sp->scp[cp->protoidx].rcr_buf,
+                                   sp->scp[cp->protoidx].rcr_blen);
+                       }
+
+                       sp->scp[cp->protoidx].rcr_buf = (void *)buf;
+                       buf = NULL;
+
+                       sp->scp[cp->protoidx].rcr_blen = blen;
+                       sp->scp[cp->protoidx].rcr_rlen = rlen;
+                       sp->scp[cp->protoidx].rcr_type = type;
+                       sp->scp[cp->protoidx].rconfid = h->ident;
+                       sppp_wq_add(sp->wq_cp, &sp->scp[cp->protoidx].work_rcr);
                }
-               sp->scp[cp->protoidx].rconfid = h->ident;
-               sppp_wq_add(sp->wq_cp, &sp->scp[cp->protoidx].work_rcr);
                break;
        case CONF_ACK:
                if (h->ident != sp->scp[cp->protoidx].confid) {
@@ -1667,9 +1710,9 @@
                        break;
                }
                if (h->type == CONF_NAK)
-                       (cp->RCN_nak)(sp, h, len);
+                       (cp->parse_confnak)(sp, h, len);
                else /* CONF_REJ */
-                       (cp->RCN_rej)(sp, h, len);
+                       (cp->parse_confrej)(sp, h, len);
 
                sppp_wq_add(sp->wq_cp, &sp->scp[cp->protoidx].work_rcn);
                break;
@@ -2049,7 +2092,7 @@
 sppp_rcr_event(struct sppp *sp, void *xcp)
 {
        const struct cp *cp = xcp;
-       u_char type;
+       enum cp_rcr_type type;
        void *buf;
        size_t blen;
        STDDCL;
@@ -2058,7 +2101,7 @@
        buf = sp->scp[cp->protoidx].rcr_buf;
        blen = sp->scp[cp->protoidx].rcr_blen;
 
-       if (type == CONF_ACK) {
+       if (type == CP_RCR_ACK) {
                /* RCR+ event */
                switch (sp->scp[cp->protoidx].state) {
                case STATE_OPENED:
@@ -2512,11 +2555,13 @@
  * caused action scn.  (The return value is used to make the state
  * transition decision in the state automaton.)
  */
-static int
-sppp_lcp_RCR(struct sppp *sp, struct lcp_header *h, int origlen)
+static enum cp_rcr_type
+sppp_lcp_confreq(struct sppp *sp, struct lcp_header *h, int origlen,
+    uint8_t **msgbuf, size_t *buflen, size_t *msglen)
 {
        STDDCL;
-       u_char *buf, *r, *p, l, blen, type;
+       u_char *buf, *r, *p, l, blen;
+       enum cp_rcr_type type;
        int len, rlen;
        uint32_t nmagic;
        u_short authproto;
@@ -2524,19 +2569,20 @@
        KASSERT(SPPP_WLOCKED(sp));
 
        if (origlen < sizeof(*h))
-               return 0;
+               return CP_RCR_DROP;
 
        origlen -= sizeof(*h);
+       type = CP_RCR_NONE;
        type = 0;
 
        if (origlen <= 0)
-               return 0;
+               return CP_RCR_DROP;
        else
                blen = origlen;
 
        buf = kmem_intr_alloc(blen, KM_NOSLEEP);
        if (buf == NULL)
-               return 0;
+               return CP_RCR_DROP;
 
        if (debug)
                log(LOG_DEBUG, "%s: lcp parse opts:",
@@ -2560,7 +2606,7 @@



Home | Main Index | Thread Index | Old Index