Source-Changes-HG archive

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

[src/trunk]: src/sys/net Simplify commonly used functions



details:   https://anonhg.NetBSD.org/src/rev/1b7d2bf926a9
branches:  trunk
changeset: 946379:1b7d2bf926a9
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Wed Nov 25 09:55:01 2020 +0000

description:
Simplify commonly used functions

reviewed by knakahara@n.o.

diffstat:

 sys/net/if_spppsubr.c |  599 ++++++++++---------------------------------------
 1 files changed, 130 insertions(+), 469 deletions(-)

diffs (truncated from 998 to 300 lines):

diff -r bad42d37c56f -r 1b7d2bf926a9 sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c     Wed Nov 25 09:46:05 2020 +0000
+++ b/sys/net/if_spppsubr.c     Wed Nov 25 09:55:01 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppsubr.c,v 1.201 2020/11/25 09:46:05 yamaguchi Exp $       */
+/*     $NetBSD: if_spppsubr.c,v 1.202 2020/11/25 09:55:01 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.201 2020/11/25 09:46:05 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.202 2020/11/25 09:55:01 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -102,9 +102,6 @@
 #define        DEFAULT_NORECV_TIME             15      /* before we get worried */
 #define DEFAULT_MAX_AUTH_FAILURES      5       /* max. auth. failures */
 
-#define FAILMSG "Failed..."
-#define SUCCMSG "Welcome!"
-
 /*
  * Interface flags that can be set in an ifconfig command.
  *
@@ -249,11 +246,11 @@
        void    (*RCN_rej)(struct sppp *, struct lcp_header *, int);
        void    (*RCN_nak)(struct sppp *, struct lcp_header *, int);
        /* actions */
-       void    (*tlu)(struct sppp *sp);
-       void    (*tld)(struct sppp *sp);
-       void    (*tls)(struct sppp *sp);
-       void    (*tlf)(struct sppp *sp);
-       void    (*scr)(struct sppp *sp);
+       void    (*tlu)(struct sppp *);
+       void    (*tld)(struct sppp *);
+       void    (*tls)(const struct cp *, struct sppp *);
+       void    (*tlf)(const struct cp *, struct sppp *);
+       void    (*scr)(struct sppp *);
        void    (*scan)(const struct cp *, struct sppp *);
 };
 
@@ -335,7 +332,8 @@
 static void sppp_auth_send(const struct cp *, struct sppp *,
                            unsigned int, unsigned int, ...);
 static int sppp_auth_role(const struct cp *, struct sppp *);
-static void sppp_auth_to_event(const struct cp *, struct sppp *);
+static void sppp_auth_to_event(struct sppp *, void *);
+static void sppp_auth_sca_scn(const struct cp *, struct sppp *);
 
 static void sppp_up_event(struct sppp *, void *);
 static void sppp_down_event(struct sppp *, void *);
@@ -350,6 +348,8 @@
 static void sppp_rxj_event(struct sppp *, void *);
 
 static void sppp_null(struct sppp *);
+static void sppp_tls(const struct cp *, struct sppp *);
+static void sppp_tlf(const struct cp *, struct sppp *);
 static void sppp_sca_scn(const struct cp *, struct sppp *);
 static void sppp_ifdown(struct sppp *, void *);
 
@@ -357,76 +357,45 @@
 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);
 static void sppp_lcp_tlu(struct sppp *);
 static void sppp_lcp_tld(struct sppp *);
-static void sppp_lcp_tls(struct sppp *);
-static void sppp_lcp_tlf(struct sppp *);
+static void sppp_lcp_tls(const struct cp *, struct sppp *);
+static void sppp_lcp_tlf(const struct cp *, struct sppp *);
 static void sppp_lcp_scr(struct sppp *);
 static void sppp_lcp_check_and_close(struct sppp *);
-static int sppp_ncp_check(struct sppp *);
-static int sppp_auth_check(struct sppp *);
+static int sppp_cp_check(struct sppp *, u_char);
 
 static void sppp_ipcp_init(struct sppp *);
-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);
 static void sppp_ipcp_tlu(struct sppp *);
-static void sppp_ipcp_tld(struct sppp *);
-static void sppp_ipcp_tls(struct sppp *);
-static void sppp_ipcp_tlf(struct sppp *);
 static void sppp_ipcp_scr(struct sppp *);
 
 static void sppp_ipv6cp_init(struct sppp *);
-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);
 static void sppp_ipv6cp_tlu(struct sppp *);
-static void sppp_ipv6cp_tld(struct sppp *);
-static void sppp_ipv6cp_tls(struct sppp *);
-static void sppp_ipv6cp_tlf(struct sppp *);
 static void sppp_ipv6cp_scr(struct sppp *);
 
 static void sppp_pap_input(struct sppp *, struct mbuf *);
 static void sppp_pap_init(struct sppp *);
-static void sppp_pap_up(struct sppp *, void *);
-static void sppp_pap_down(struct sppp *, void *);
-static void sppp_pap_open(struct sppp *, void *);
-static void sppp_pap_close(struct sppp *, void *);
-static void sppp_pap_TO(struct sppp *, void *);
-static void sppp_pap_tls(struct sppp *);
-static void sppp_pap_tlf(struct sppp *);
 static void sppp_pap_tlu(struct sppp *);
 static void sppp_pap_scr(struct sppp *);
 static void sppp_pap_scr(struct sppp *);
-static void sppp_pap_scan(const struct cp *, struct sppp *);
 
 static void sppp_chap_input(struct sppp *, struct mbuf *);
 static void sppp_chap_init(struct sppp *);
-static void sppp_chap_up(struct sppp *, void *);
-static void sppp_chap_down(struct sppp *, void *);
 static void sppp_chap_open(struct sppp *, void *);
-static void sppp_chap_close(struct sppp *, void *);
-static void sppp_chap_TO(struct sppp *, void *);
 static void sppp_chap_tlu(struct sppp *);
-static void sppp_chap_tls(struct sppp *);
-static void sppp_chap_tlf(struct sppp *);
 static void sppp_chap_scr(struct sppp *);
-static void sppp_chap_scan(const struct cp *, struct sppp *);
 static void sppp_chap_rcv_challenge_event(struct sppp *, void *);
 
 static const char *sppp_auth_type_name(u_short, u_char);
@@ -478,8 +447,8 @@
 /* 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_lcp_close,
-       sppp_lcp_TO, sppp_lcp_RCR, sppp_lcp_RCN_rej, sppp_lcp_RCN_nak,
+       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
 };
@@ -492,9 +461,9 @@
        0,
 #endif
        "ipcp",
-       sppp_ipcp_up, sppp_ipcp_down, sppp_ipcp_open, sppp_ipcp_close,
-       sppp_ipcp_TO, sppp_ipcp_RCR, sppp_ipcp_RCN_rej, sppp_ipcp_RCN_nak,
-       sppp_ipcp_tlu, sppp_ipcp_tld, sppp_ipcp_tls, sppp_ipcp_tlf,
+       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
 };
 
@@ -506,26 +475,26 @@
        0,
 #endif
        "ipv6cp",
-       sppp_ipv6cp_up, sppp_ipv6cp_down, sppp_ipv6cp_open, sppp_ipv6cp_close,
-       sppp_ipv6cp_TO, sppp_ipv6cp_RCR, sppp_ipv6cp_RCN_rej, sppp_ipv6cp_RCN_nak,
-       sppp_ipv6cp_tlu, sppp_ipv6cp_tld, sppp_ipv6cp_tls, sppp_ipv6cp_tlf,
+       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
 };
 
 static const struct cp pap = {
        PPP_PAP, IDX_PAP, CP_AUTH, "pap",
-       sppp_pap_up, sppp_pap_down, sppp_pap_open, sppp_pap_close,
-       sppp_pap_TO, 0, 0, 0,
-       sppp_pap_tlu, sppp_null, sppp_pap_tls, sppp_pap_tlf,
-       sppp_pap_scr, sppp_pap_scan
+       sppp_up_event, sppp_down_event, sppp_open_event, sppp_close_event,
+       sppp_to_event, 0, 0, 0,
+       sppp_pap_tlu, sppp_null, sppp_tls, sppp_tlf,
+       sppp_pap_scr, sppp_auth_sca_scn
 };
 
 static const struct cp chap = {
        PPP_CHAP, IDX_CHAP, CP_AUTH, "chap",
-       sppp_chap_up, sppp_chap_down, sppp_chap_open, sppp_chap_close,
-       sppp_chap_TO, 0, 0, 0,
-       sppp_chap_tlu, sppp_null, sppp_chap_tls, sppp_chap_tlf,
-       sppp_chap_scr, sppp_chap_scan
+       sppp_up_event, sppp_down_event, sppp_chap_open, sppp_close_event,
+       sppp_auth_to_event, 0, 0, 0,
+       sppp_chap_tlu, sppp_null, sppp_tls, sppp_tlf,
+       sppp_chap_scr, sppp_auth_sca_scn
 };
 
 static const struct cp *cps[IDX_COUNT] = {
@@ -1163,7 +1132,7 @@
         */
        IF_DEQUEUE(&sp->pp_cpq, m);
        if (m == NULL &&
-           (sppp_ncp_check(sp) || (sp->pp_flags & PP_CISCO) != 0)) {
+           (sppp_cp_check(sp, CP_NCP) || (sp->pp_flags & PP_CISCO) != 0)) {
                IF_DEQUEUE(&sp->pp_fastq, m);
                if (m == NULL)
                        IFQ_DEQUEUE(&sp->pp_if.if_snd, m);
@@ -1665,7 +1634,7 @@
                if (rv < 0) {
                        /* fatal error, shut down */
                        (cp->tld)(sp);
-                       sppp_lcp_tlf(sp);
+                       lcp.tlf(&lcp, sp);
                        SPPP_UNLOCK(sp);
                        return;
                }
@@ -1900,7 +1869,7 @@
                sppp_cp_change_state(cp, sp, STATE_INITIAL);
                break;
        case STATE_STOPPED:
-               (cp->tls)(sp);
+               (cp->tls)(cp, sp);
                /* fall through */
        case STATE_STOPPING:
        case STATE_REQ_SENT:
@@ -1940,7 +1909,7 @@
        switch (sp->scp[cp->protoidx].state) {
        case STATE_INITIAL:
                sppp_cp_change_state(cp, sp, STATE_STARTING);
-               (cp->tls)(sp);
+               (cp->tls)(cp, sp);
                break;
        case STATE_STARTING:
                break;
@@ -1987,7 +1956,7 @@
                break;
        case STATE_STARTING:
                sppp_cp_change_state(cp, sp, STATE_INITIAL);
-               (cp->tlf)(sp);
+               (cp->tlf)(cp, sp);
                break;
        case STATE_STOPPED:
                sppp_cp_change_state(cp, sp, STATE_CLOSED);
@@ -2033,17 +2002,17 @@
                switch (sp->scp[cp->protoidx].state) {
                case STATE_CLOSING:
                        sppp_cp_change_state(cp, sp, STATE_CLOSED);
-                       (cp->tlf)(sp);
+                       (cp->tlf)(cp, sp);
                        break;
                case STATE_STOPPING:
                        sppp_cp_change_state(cp, sp, STATE_STOPPED);
-                       (cp->tlf)(sp);
+                       (cp->tlf)(cp, sp);
                        break;
                case STATE_REQ_SENT:
                case STATE_ACK_RCVD:
                case STATE_ACK_SENT:
                        sppp_cp_change_state(cp, sp, STATE_STOPPED);
-                       (cp->tlf)(sp);
+                       (cp->tlf)(cp, sp);
                        break;
                }
        else
@@ -2315,11 +2284,11 @@
                break;
        case STATE_CLOSING:
                sppp_cp_change_state(cp, sp, STATE_CLOSED);
-               (cp->tlf)(sp);
+               (cp->tlf)(cp, sp);
                break;
        case STATE_STOPPING:
                sppp_cp_change_state(cp, sp, STATE_STOPPED);
-               (cp->tlf)(sp);
+               (cp->tlf)(cp, sp);
                break;
        case STATE_ACK_RCVD:
                sppp_cp_change_state(cp, sp, STATE_REQ_SENT);
@@ -2470,10 +2439,13 @@
 static void
 sppp_lcp_down(struct sppp *sp, void *xcp)
 {
+       const struct cp *cp = xcp;
+       int pidx;
        STDDCL;
 
        KASSERT(SPPP_WLOCKED(sp));
 
+       pidx = cp->protoidx;
        sppp_down_event(sp, xcp);
 
        /*



Home | Main Index | Thread Index | Old Index