Source-Changes-HG archive

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

[src/trunk]: src/sys/net Change a state of control protocol in thread context



details:   https://anonhg.NetBSD.org/src/rev/0ba6db7a819a
branches:  trunk
changeset: 957348:0ba6db7a819a
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Wed Nov 25 09:35:23 2020 +0000

description:
Change a state of control protocol in thread context

reviewed by knakahara@n.o.

diffstat:

 sys/net/if_spppsubr.c |  521 +++++++++++++++++++++++++++++++++----------------
 sys/net/if_spppvar.h  |   27 ++-
 2 files changed, 373 insertions(+), 175 deletions(-)

diffs (truncated from 1244 to 300 lines):

diff -r d2bc4b486b24 -r 0ba6db7a819a sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c     Wed Nov 25 09:30:49 2020 +0000
+++ b/sys/net/if_spppsubr.c     Wed Nov 25 09:35:23 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppsubr.c,v 1.197 2020/11/25 09:30:49 yamaguchi Exp $       */
+/*     $NetBSD: if_spppsubr.c,v 1.198 2020/11/25 09:35:23 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.197 2020/11/25 09:30:49 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.198 2020/11/25 09:35:23 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -237,11 +237,11 @@
 #define CP_QUAL                0x08    /* this is a quality reporting protocol */
        const char *name;       /* name of this control protocol */
        /* event handlers */
-       void    (*Up)(struct sppp *);
-       void    (*Down)(struct sppp *);
-       void    (*Open)(struct sppp *);
-       void    (*Close)(struct sppp *);
-       void    (*TO)(void *);
+       void    (*Up)(struct sppp *, void *);
+       void    (*Down)(struct sppp *, void *);
+       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);
@@ -271,6 +271,8 @@
        SPPP_LOCK(_sp, RW_WRITER);      \
 }while (0)
 #define SPPP_DOWNGRADE(_sp)    rw_downgrade(&(_sp)->pp_lock)
+#define SPPP_WQ_SET(_wk, _func, _arg)  \
+       sppp_wq_set((_wk), (_func), __UNCONST((_arg)))
 
 #ifdef INET
 #ifndef SPPPSUBR_MPSAFE
@@ -301,36 +303,51 @@
 static void sppp_cisco_send(struct sppp *, int, int32_t, int32_t);
 static void sppp_cisco_input(struct sppp *, struct mbuf *);
 
+static void sppp_cp_init(const struct cp *, struct sppp *);
+static void sppp_cp_fini(const struct cp *, struct sppp *);
+static void sppp_cp_input(const struct cp *, struct sppp *,
+                         struct mbuf *);
 static void sppp_cp_input(const struct cp *, struct sppp *,
                          struct mbuf *);
 static void sppp_cp_send(struct sppp *, u_short, u_char,
                         u_char, u_short, void *);
 /* static void sppp_cp_timeout(void *arg); */
 static void sppp_cp_change_state(const struct cp *, struct sppp *, int);
+static struct workqueue *
+    sppp_wq_create(struct sppp *, const char *, pri_t, int, int);
+static void sppp_wq_destroy(struct sppp *, struct workqueue *);
+static void sppp_wq_set(struct sppp_work *,
+    void (*)(struct sppp *, void *), void *);
+static void sppp_wq_add(struct workqueue *, struct sppp_work *);
+static void sppp_wq_wait(struct workqueue *, struct sppp_work *);
+static void sppp_cp_to_lcp(void *);
+static void sppp_cp_to_ipcp(void *);
+static void sppp_cp_to_ipv6cp(void *);
 static void sppp_auth_send(const struct cp *, struct sppp *,
                            unsigned int, unsigned int, ...);
 
-static void sppp_up_event(const struct cp *, struct sppp *);
-static void sppp_down_event(const struct cp *, struct sppp *);
-static void sppp_open_event(const struct cp *, struct sppp *);
-static void sppp_close_event(const struct cp *, struct sppp *);
-static void sppp_to_event(const struct cp *, struct sppp *);
-static void sppp_rcr_event(const struct cp *, struct sppp *);
-static void sppp_rca_event(const struct cp *, struct sppp *);
-static void sppp_rcn_event(const struct cp *, struct sppp *);
-static void sppp_rtr_event(const struct cp *, struct sppp *);
-static void sppp_rta_event(const struct cp *, struct sppp *);
-static void sppp_rxj_event(const struct cp *, struct sppp *);
+static void sppp_up_event(struct sppp *, void *);
+static void sppp_down_event(struct sppp *, void *);
+static void sppp_open_event(struct sppp *, void *);
+static void sppp_close_event(struct sppp *, void *);
+static void sppp_to_event(struct sppp *, void *);
+static void sppp_rcr_event(struct sppp *, void *);
+static void sppp_rca_event(struct sppp *, void *);
+static void sppp_rcn_event(struct sppp *, void *);
+static void sppp_rtr_event(struct sppp *, void *);
+static void sppp_rta_event(struct sppp *, void *);
+static void sppp_rxj_event(struct sppp *, void *);
+static void sppp_null_event(struct sppp *, void *);
 
 static void sppp_null(struct sppp *);
 static void sppp_sca_scn(const struct cp *, struct sppp *);
 
 static void sppp_lcp_init(struct sppp *);
-static void sppp_lcp_up(struct sppp *);
-static void sppp_lcp_down(struct sppp *);
-static void sppp_lcp_open(struct sppp *);
-static void sppp_lcp_close(struct sppp *);
-static void sppp_lcp_TO(void *);
+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 void sppp_lcp_close(struct sppp *, void *);
+static void sppp_lcp_TO(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);
@@ -343,11 +360,11 @@
 static int sppp_ncp_check(struct sppp *);
 
 static void sppp_ipcp_init(struct sppp *);
-static void sppp_ipcp_up(struct sppp *);
-static void sppp_ipcp_down(struct sppp *);
-static void sppp_ipcp_open(struct sppp *);
-static void sppp_ipcp_close(struct sppp *);
-static void sppp_ipcp_TO(void *);
+static void sppp_ipcp_up(struct sppp *, void *);
+static void sppp_ipcp_down(struct sppp *, void *);
+static void sppp_ipcp_open(struct sppp *, void *);
+static void sppp_ipcp_close(struct sppp *, void *);
+static void sppp_ipcp_TO(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);
@@ -358,11 +375,11 @@
 static void sppp_ipcp_scr(struct sppp *);
 
 static void sppp_ipv6cp_init(struct sppp *);
-static void sppp_ipv6cp_up(struct sppp *);
-static void sppp_ipv6cp_down(struct sppp *);
-static void sppp_ipv6cp_open(struct sppp *);
-static void sppp_ipv6cp_close(struct sppp *);
-static void sppp_ipv6cp_TO(void *);
+static void sppp_ipv6cp_up(struct sppp *, void *);
+static void sppp_ipv6cp_down(struct sppp *, void *);
+static void sppp_ipv6cp_open(struct sppp *, void *);
+static void sppp_ipv6cp_close(struct sppp *, void *);
+static void sppp_ipv6cp_TO(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);
@@ -374,8 +391,8 @@
 
 static void sppp_pap_input(struct sppp *, struct mbuf *);
 static void sppp_pap_init(struct sppp *);
-static void sppp_pap_open(struct sppp *);
-static void sppp_pap_close(struct sppp *);
+static void sppp_pap_open(struct sppp *, void *);
+static void sppp_pap_close(struct sppp *, void *);
 static void sppp_pap_TO(void *);
 static void sppp_pap_my_TO(void *);
 static void sppp_pap_tlu(struct sppp *);
@@ -384,8 +401,8 @@
 
 static void sppp_chap_input(struct sppp *, struct mbuf *);
 static void sppp_chap_init(struct sppp *);
-static void sppp_chap_open(struct sppp *);
-static void sppp_chap_close(struct sppp *);
+static void sppp_chap_open(struct sppp *, void *);
+static void sppp_chap_close(struct sppp *, void *);
 static void sppp_chap_TO(void *);
 static void sppp_chap_tlu(struct sppp *);
 static void sppp_chap_tld(struct sppp *);
@@ -476,16 +493,16 @@
 
 static const struct cp pap = {
        PPP_PAP, IDX_PAP, CP_AUTH, "pap",
-       sppp_null, sppp_null, sppp_pap_open, sppp_pap_close,
-       sppp_pap_TO, 0, 0, 0,
+       sppp_null_event, sppp_null_event, sppp_pap_open, sppp_pap_close,
+       sppp_null_event, 0, 0, 0,
        sppp_pap_tlu, sppp_pap_tld, sppp_null, sppp_null,
        sppp_pap_scr, 0
 };
 
 static const struct cp chap = {
        PPP_CHAP, IDX_CHAP, CP_AUTH, "chap",
-       sppp_null, sppp_null, sppp_chap_open, sppp_chap_close,
-       sppp_chap_TO, 0, 0, 0,
+       sppp_null_event, sppp_null_event, sppp_chap_open, sppp_chap_close,
+       sppp_null_event, 0, 0, 0,
        sppp_chap_tlu, sppp_chap_tld, sppp_null, sppp_null,
        sppp_chap_scr, 0
 };
@@ -771,16 +788,7 @@
                 * to start LCP for it.
                 */
                ifp->if_flags |= IFF_RUNNING;
-
-               SPPP_UNLOCK(sp);
-               splx(s);
-
-               SPPP_LOCK(sp, RW_WRITER);
-               lcp.Open(sp);
-               SPPP_UNLOCK(sp);
-
-               s = splnet();
-               SPPP_LOCK(sp, RW_READER);
+               sppp_wq_add(sp->wq_cp, &sp->scp[IDX_LCP].work_open);
        }
 
        /*
@@ -978,6 +986,7 @@
 sppp_attach(struct ifnet *ifp)
 {
        struct sppp *sp = (struct sppp *) ifp;
+       char xnamebuf[MAXCOMLEN];
 
        /* Initialize keepalive handler. */
        if (! spppq) {
@@ -1015,6 +1024,10 @@
        /* Lets not beat about the bush, we know we're down. */
        ifp->if_link_state = LINK_STATE_DOWN;
 
+       snprintf(xnamebuf, sizeof(xnamebuf), "%s.wq_cp", ifp->if_xname);
+       sp->wq_cp = sppp_wq_create(sp, xnamebuf,
+           PRI_SOFTNET, IPL_SOFTNET, WQ_MPSAFE);
+
        memset(&sp->myauth, 0, sizeof sp->myauth);
        memset(&sp->hisauth, 0, sizeof sp->hisauth);
        SPPP_LOCK(sp, RW_WRITER);
@@ -1055,13 +1068,14 @@
        workqueue_destroy(sp->ipcp.update_addrs_wq);
        pcq_destroy(sp->ipcp.update_addrs_q);
 
-       callout_stop(&sp->scp[IDX_LCP].ch);
-       callout_stop(&sp->scp[IDX_IPCP].ch);
+       sppp_cp_fini(&lcp, sp);
+       sppp_cp_fini(&ipcp, sp);
        callout_stop(&sp->scp[IDX_PAP].ch);
        callout_stop(&sp->scp[IDX_CHAP].ch);
 #ifdef INET6
-       callout_stop(&sp->scp[IDX_IPV6CP].ch);
+       sppp_cp_fini(&ipv6cp, sp);
 #endif
+       sppp_wq_destroy(sp, sp->wq_cp);
        callout_stop(&sp->pap_my_to_ch);
 
        /* free authentication info */
@@ -1172,13 +1186,16 @@
                }
 
                if (going_up || going_down) {
-                       lcp.Close(sp);
+                       sp->lcp.reestablish = false;
+                       sppp_wq_add(sp->wq_cp, &sp->scp[IDX_LCP].work_close);
                }
                if (going_up && newmode == 0) {
                        /* neither auto-dial nor passive */
                        ifp->if_flags |= IFF_RUNNING;
-                       if (!(sp->pp_flags & PP_CISCO))
-                               lcp.Open(sp);
+                       if (!(sp->pp_flags & PP_CISCO)) {
+                               sppp_wq_add(sp->wq_cp,
+                                   &sp->scp[IDX_LCP].work_open);
+                       }
                } else if (going_down) {
                        SPPP_UNLOCK(sp);
                        sppp_flush(ifp);
@@ -1477,6 +1494,81 @@
        }
 }
 
+static void
+sppp_cp_to_lcp(void *xsp)
+{
+       struct sppp *sp = xsp;
+
+       sppp_wq_add(sp->wq_cp, &sp->scp[IDX_LCP].work_to);
+}
+
+static void
+sppp_cp_to_ipcp(void *xsp)
+{
+       struct sppp *sp = xsp;
+
+       sppp_wq_add(sp->wq_cp, &sp->scp[IDX_IPCP].work_to);
+}
+
+static void
+sppp_cp_to_ipv6cp(void *xsp)
+{
+       struct sppp *sp = xsp;
+
+       sppp_wq_add(sp->wq_cp, &sp->scp[IDX_IPV6CP].work_to);
+}
+
+static void
+sppp_cp_init(const struct cp *cp, struct sppp *sp)
+{
+       struct sppp_cp *scp;
+       typedef void (*sppp_co_cb_t)(void *);
+       static const sppp_co_cb_t to_cb[IDX_COUNT] = {
+               [IDX_LCP] = sppp_cp_to_lcp,
+               [IDX_IPCP] = sppp_cp_to_ipcp,



Home | Main Index | Thread Index | Old Index