Source-Changes-HG archive

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

[src/trunk]: src/sys/net restart LCP when loopback packets are detected



details:   https://anonhg.NetBSD.org/src/rev/6179ec07f841
branches:  trunk
changeset: 379446:6179ec07f841
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Tue Jun 01 03:27:23 2021 +0000

description:
restart LCP when loopback packets are detected

In if_spppsubr.c down and up do not mean that LCP is stopping
or running, but mean that the lower layer of LCP is up or down.
And, restarting of LCP is had to use close event and open event.

diffstat:

 sys/net/if_spppsubr.c |  87 ++++++++++++++++++++++++++++----------------------
 sys/net/if_spppvar.h  |   9 ++--
 2 files changed, 54 insertions(+), 42 deletions(-)

diffs (182 lines):

diff -r f1abf5171fa4 -r 6179ec07f841 sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c     Tue Jun 01 00:59:01 2021 +0000
+++ b/sys/net/if_spppsubr.c     Tue Jun 01 03:27:23 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppsubr.c,v 1.246 2021/05/19 02:14:19 yamaguchi Exp $       */
+/*     $NetBSD: if_spppsubr.c,v 1.247 2021/06/01 03:27: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.246 2021/05/19 02:14:19 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.247 2021/06/01 03:27:23 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1480,15 +1480,18 @@ sppp_cisco_input(struct sppp *sp, struct
                                printf ("%s: loopback\n",
                                        ifp->if_xname);
                                sp->pp_loopcnt = 0;
-                               if (ifp->if_flags & IFF_UP) {
-                                       SPPP_UNLOCK(sp);
-                                       if_down(ifp);
-                                       SPPP_LOCK(sp, RW_WRITER);
-
-                                       IF_PURGE(&sp->pp_cpq);
-                               }
+
+                               sp->pp_flags |= PP_LOOPBACK;
+                               sppp_wq_add(sp->wq_cp,
+                                   &sp->work_ifdown);
+
+                               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 {
+                               ++sp->pp_loopcnt;
                        }
-                       ++sp->pp_loopcnt;
 
                        /* Generate new local sequence number */
                        sp->scp[IDX_LCP].seq = cprng_fast32();
@@ -1500,6 +1503,7 @@ sppp_cisco_input(struct sppp *sp, struct
                        SPPP_UNLOCK(sp);
                        if_up(ifp);
                        SPPP_LOCK(sp, RW_WRITER);
+                       sp->pp_flags &= ~PP_LOOPBACK;
                }
                break;
        case CISCO_ADDR_REQ:
@@ -1946,20 +1950,16 @@ sppp_cp_input(const struct cp *cp, struc
                if (ntohl(u32) == sp->lcp.magic) {
                        /* Line loopback mode detected. */
                        printf("%s: loopback\n", ifp->if_xname);
-                       /*
-                        * There is no change for items of sp->scp[cp->protoidx]
-                        * while if_down() even without SPPP_LOCK
-                        */
-                       SPPP_UNLOCK(sp);
-                       if_down(ifp);
-                       SPPP_LOCK(sp, RW_WRITER);
-
-                       IF_PURGE(&sp->pp_cpq);
+
+                       sp->pp_flags |= PP_LOOPBACK;
+                       sppp_wq_add(sp->wq_cp,
+                           &sp->work_ifdown);
 
                        /* Shut down the PPP link. */
-                       /* XXX */
-                       sppp_wq_add(sp->wq_cp, &sp->scp[IDX_LCP].work_down);
-                       sppp_wq_add(sp->wq_cp, &sp->scp[IDX_LCP].work_up);
+                       sppp_wq_add(sp->wq_cp,
+                           &sp->scp[IDX_LCP].work_close);
+                       sppp_wq_add(sp->wq_cp,
+                           &sp->scp[IDX_LCP].work_open);
                        break;
                }
                u32 = htonl(sp->lcp.magic);
@@ -3000,21 +3000,20 @@ sppp_lcp_confreq(struct sppp *sp, struct
                                printf ("%s: loopback\n",
                                        ifp->if_xname);
                                sp->pp_loopcnt = 0;
-                               if (ifp->if_flags & IFF_UP) {
-                                       SPPP_UNLOCK(sp);
-                                       if_down(ifp);
-                                       SPPP_LOCK(sp, RW_WRITER);
-
-                                       IF_PURGE(&sp->pp_cpq);
-                                       /* XXX ? */
-                                       sppp_wq_add(sp->wq_cp,
-                                           &sp->scp[IDX_LCP].work_down);
-                                       sppp_wq_add(sp->wq_cp,
-                                           &sp->scp[IDX_LCP].work_up);
-                               }
-                       } else if (debug)
-                               addlog(" [glitch]");
-                       ++sp->pp_loopcnt;
+
+                               sp->pp_flags |= PP_LOOPBACK;
+                               sppp_wq_add(sp->wq_cp,
+                                   &sp->work_ifdown);
+
+                               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 (debug)
+                                       addlog(" [glitch]");
+                               ++sp->pp_loopcnt;
+                       }
                        /*
                         * We negate our magic here, and NAK it.  If
                         * we see it later in an NAK packet, we
@@ -3351,22 +3350,34 @@ sppp_lcp_tlu(struct sppp *sp)
 {
        STDDCL;
        int i;
+       bool going_up;
 
        KASSERT(SPPP_WLOCKED(sp));
 
        /* unlock for IFNET_LOCK and if_up() */
        SPPP_UNLOCK(sp);
 
-       /* XXX ? */
        if (! (ifp->if_flags & IFF_UP) &&
            (ifp->if_flags & IFF_RUNNING)) {
                /* Coming out of loopback mode. */
+               going_up = true;
                if_up(ifp);
+       } else {
+               going_up = false;
        }
 
        IFNET_LOCK(ifp);
        SPPP_LOCK(sp, RW_WRITER);
 
+       if (going_up) {
+               if ((sp->pp_flags & PP_LOOPBACK) == 0) {
+                       log(LOG_DEBUG, "%s: interface is going up, "
+                           "but no loopback packet is deteted\n",
+                           ifp->if_xname);
+               }
+               sp->pp_flags &= ~PP_LOOPBACK;
+       }
+
        if (ifp->if_mtu > sp->lcp.their_mru) {
                sp->pp_saved_mtu = ifp->if_mtu;
                ifp->if_mtu = sp->lcp.their_mru;
diff -r f1abf5171fa4 -r 6179ec07f841 sys/net/if_spppvar.h
--- a/sys/net/if_spppvar.h      Tue Jun 01 00:59:01 2021 +0000
+++ b/sys/net/if_spppvar.h      Tue Jun 01 03:27:23 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppvar.h,v 1.38 2021/05/14 08:41:25 yamaguchi Exp $        */
+/*     $NetBSD: if_spppvar.h,v 1.39 2021/06/01 03:27:23 yamaguchi Exp $        */
 
 #ifndef _NET_IF_SPPPVAR_H_
 #define _NET_IF_SPPPVAR_H_
@@ -203,14 +203,15 @@ struct sppp {
        void    (*pp_chg)(struct sppp *, int);
 };
 
-#define PP_KEEPALIVE    0x01    /* use keepalive protocol */
-#define PP_CISCO        0x02    /* use Cisco protocol instead of PPP */
+#define PP_KEEPALIVE   0x01    /* use keepalive protocol */
+#define PP_CISCO       0x02    /* use Cisco protocol instead of PPP */
                                /* 0x04 was PP_TIMO */
 #define PP_CALLIN      0x08    /* we are being called */
 #define PP_NEEDAUTH    0x10    /* remote requested authentication */
-#define        PP_NOFRAMING    0x20    /* do not add/expect encapsulation
+#define PP_NOFRAMING   0x20    /* do not add/expect encapsulation
                                   around PPP frames (i.e. the serial
                                   HDLC like encapsulation, RFC1662) */
+#define PP_LOOPBACK    0x40    /* in line loopback mode */
 
 
 #define PP_MTU          1500    /* default/minimal MRU */



Home | Main Index | Thread Index | Old Index