Source-Changes-HG archive

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

[src/trunk]: src/sys/net Add another option for encapsulation: PP_NOFRAMING.



details:   https://anonhg.NetBSD.org/src/rev/3903e0c83471
branches:  trunk
changeset: 508316:3903e0c83471
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Apr 09 19:33:01 2001 +0000

description:
Add another option for encapsulation: PP_NOFRAMING.
In this mode, the PPP packets start with the protocol identifier and don't
have any explicit framing (which may be added by the lower level driver).

Make input/output statistics a little bit more correct by adding a hardware
driver adjustable framing length for each packet (instead of the constant
value "3" used before).

While there, bump authentication name length from 32 to 48 (I have a
connection where I need more than 32). XXX - this should not be artificialy
limited at all.

diffstat:

 sys/net/if_sppp.h     |    8 +-
 sys/net/if_spppsubr.c |  437 +++++++++++++++++++++++++++----------------------
 2 files changed, 247 insertions(+), 198 deletions(-)

diffs (truncated from 659 to 300 lines):

diff -r 7c59bd85f55c -r 3903e0c83471 sys/net/if_sppp.h
--- a/sys/net/if_sppp.h Mon Apr 09 19:23:32 2001 +0000
+++ b/sys/net/if_sppp.h Mon Apr 09 19:33:01 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_sppp.h,v 1.8 2001/03/25 19:39:20 martin Exp $       */
+/*     $NetBSD: if_sppp.h,v 1.9 2001/04/09 19:33:01 martin Exp $       */
 
 /*
  * Defines for synchronous PPP/Cisco link level subroutines.
@@ -59,7 +59,7 @@
 #define IPV6CP_MYIFID_SEEN  4  /* have seen his ifid already */
 };
 
-#define AUTHNAMELEN    32
+#define AUTHNAMELEN    48
 #define AUTHKEYLEN     16
 
 struct sauth {
@@ -95,6 +95,7 @@
        struct  ifqueue pp_cpq; /* PPP control protocol queue */
        struct  sppp *pp_next;  /* next interface in keepalive list */
        u_int   pp_flags;       /* use Cisco protocol instead of PPP */
+       u_int   pp_framebytes;  /* number of bytes added by (hardware) framing */
        u_short pp_alivecnt;    /* keepalive packets counter */
        u_short pp_loopcnt;     /* loopback detection counter */
        u_long  pp_seq[IDX_COUNT];      /* local sequence number */
@@ -151,6 +152,9 @@
                                /* 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
+                                  around PPP frames (i.e. the serial
+                                  HDLC like encapsulation, RFC1662) */
 
 
 #define PP_MTU          1500    /* default/minimal MRU */
diff -r 7c59bd85f55c -r 3903e0c83471 sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c     Mon Apr 09 19:23:32 2001 +0000
+++ b/sys/net/if_spppsubr.c     Mon Apr 09 19:33:01 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppsubr.c,v 1.21 2001/03/25 19:39:21 martin Exp $   */
+/*     $NetBSD: if_spppsubr.c,v 1.22 2001/04/09 19:33:01 martin Exp $   */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -470,15 +470,16 @@
 void
 sppp_input(struct ifnet *ifp, struct mbuf *m)
 {
-       struct ppp_header *h;
+       struct ppp_header *h = NULL;
        struct ifqueue *inq = 0;
+       u_int16_t protocol;
        int s;
        struct sppp *sp = (struct sppp *)ifp;
        int debug = ifp->if_flags & IFF_DEBUG;
 
        if (ifp->if_flags & IFF_UP)
-               /* Count received bytes, add FCS and one flag */
-               ifp->if_ibytes += m->m_pkthdr.len + 3;
+               /* Count received bytes, add hardware framing */
+               ifp->if_ibytes += m->m_pkthdr.len + sp->pp_framebytes;
 
        if (m->m_pkthdr.len <= PPP_HEADER_LEN) {
                /* Too small packet, drop it. */
@@ -493,164 +494,174 @@
                return;
        }
 
-       /* Get PPP header. */
-       h = mtod (m, struct ppp_header*);
-       m_adj (m, PPP_HEADER_LEN);
-
-       switch (h->address) {
-       case PPP_ALLSTATIONS:
-               if (h->control != PPP_UI)
-                       goto invalid;
-               if (sp->pp_flags & PP_CISCO) {
+       if (sp->pp_flags & PP_NOFRAMING) {
+               protocol = *(mtod(m, u_int16_t*));
+               protocol = ntohs(protocol);
+               m_adj(m, 2);
+       } else {
+
+               /* Get PPP header. */
+               h = mtod (m, struct ppp_header*);
+               m_adj (m, PPP_HEADER_LEN);
+
+               switch (h->address) {
+               case PPP_ALLSTATIONS:
+                       if (h->control != PPP_UI)
+                               goto invalid;
+                       if (sp->pp_flags & PP_CISCO) {
+                               if (debug)
+                                       log(LOG_DEBUG,
+                                           SPP_FMT "PPP packet in Cisco mode "
+                                           "<addr=0x%x ctrl=0x%x proto=0x%x>\n",
+                                           SPP_ARGS(ifp),
+                                           h->address, h->control, ntohs(h->protocol));
+                               goto drop;
+                       }
+                       break;
+               case CISCO_MULTICAST:
+               case CISCO_UNICAST:
+                       /* Don't check the control field here (RFC 1547). */
+                       if (! (sp->pp_flags & PP_CISCO)) {
+                               if (debug)
+                                       log(LOG_DEBUG,
+                                           SPP_FMT "Cisco packet in PPP mode "
+                                           "<addr=0x%x ctrl=0x%x proto=0x%x>\n",
+                                           SPP_ARGS(ifp),
+                                           h->address, h->control, ntohs(h->protocol));
+                               goto drop;
+                       }
+                       switch (ntohs (h->protocol)) {
+                       default:
+                               ++ifp->if_noproto;
+                               goto invalid;
+                       case CISCO_KEEPALIVE:
+                               sppp_cisco_input ((struct sppp*) ifp, m);
+                               m_freem (m);
+                               return;
+#ifdef INET
+                       case ETHERTYPE_IP:
+                               schednetisr (NETISR_IP);
+                               inq = &ipintrq;
+                               break;
+#endif
+#ifdef INET6
+                       case ETHERTYPE_IPV6:
+                               schednetisr (NETISR_IPV6);
+                               inq = &ip6intrq;
+                               break;
+#endif
+#ifdef IPX
+                       case ETHERTYPE_IPX:
+                               schednetisr (NETISR_IPX);
+                               inq = &ipxintrq;
+                               break;
+#endif
+#ifdef NS
+                       case ETHERTYPE_NS:
+                               schednetisr (NETISR_NS);
+                               inq = &nsintrq;
+                               break;
+#endif
+                       }
+                       goto queue_pkt;
+               default:        /* Invalid PPP packet. */
+                 invalid:
                        if (debug)
                                log(LOG_DEBUG,
-                                   SPP_FMT "PPP packet in Cisco mode "
+                                   SPP_FMT "invalid input packet "
                                    "<addr=0x%x ctrl=0x%x proto=0x%x>\n",
                                    SPP_ARGS(ifp),
                                    h->address, h->control, ntohs(h->protocol));
                        goto drop;
                }
-               switch (ntohs (h->protocol)) {
-               default:
-                       if (sp->state[IDX_LCP] == STATE_OPENED)
-                               sppp_cp_send (sp, PPP_LCP, PROTO_REJ,
-                                   ++sp->pp_seq[IDX_LCP], m->m_pkthdr.len + 2,
-                                   &h->protocol);
-                       if (debug)
-                               log(LOG_DEBUG,
-                                   SPP_FMT "invalid input protocol "
-                                   "<addr=0x%x ctrl=0x%x proto=0x%x>\n",
-                                   SPP_ARGS(ifp),
-                                   h->address, h->control, ntohs(h->protocol));
-                       ++ifp->if_noproto;
-                       goto drop;
-               case PPP_LCP:
-                       sppp_cp_input(&lcp, sp, m);
-                       m_freem (m);
-                       return;
-               case PPP_PAP:
-                       if (sp->pp_phase >= PHASE_AUTHENTICATE)
-                               sppp_pap_input(sp, m);
-                       m_freem (m);
-                       return;
-               case PPP_CHAP:
-                       if (sp->pp_phase >= PHASE_AUTHENTICATE)
-                               sppp_chap_input(sp, m);
-                       m_freem (m);
-                       return;
+               protocol = ntohs (h->protocol);
+       }
+
+       switch (protocol) {
+       default:
+               if (sp->state[IDX_LCP] == STATE_OPENED) {
+                       u_int16_t prot = htons(protocol);
+                       sppp_cp_send (sp, PPP_LCP, PROTO_REJ,
+                           ++sp->pp_seq[IDX_LCP], m->m_pkthdr.len + 2,
+                           &prot);
+               }
+               if (debug)
+                       log(LOG_DEBUG,
+                           SPP_FMT "invalid input protocol "
+                           "<proto=0x%x>\n", SPP_ARGS(ifp), ntohs(protocol));
+               ++ifp->if_noproto;
+               goto drop;
+       case PPP_LCP:
+               sppp_cp_input(&lcp, sp, m);
+               m_freem (m);
+               return;
+       case PPP_PAP:
+               if (sp->pp_phase >= PHASE_AUTHENTICATE)
+                       sppp_pap_input(sp, m);
+               m_freem (m);
+               return;
+       case PPP_CHAP:
+               if (sp->pp_phase >= PHASE_AUTHENTICATE)
+                       sppp_chap_input(sp, m);
+               m_freem (m);
+               return;
 #ifdef INET
-               case PPP_IPCP:
-                       if (sp->pp_phase == PHASE_NETWORK)
-                               sppp_cp_input(&ipcp, sp, m);
-                       m_freem (m);
-                       return;
-               case PPP_IP:
-                       if (sp->state[IDX_IPCP] == STATE_OPENED) {
-                               schednetisr (NETISR_IP);
-                               inq = &ipintrq;
-                       }
-                       break;
+       case PPP_IPCP:
+               if (sp->pp_phase == PHASE_NETWORK)
+                       sppp_cp_input(&ipcp, sp, m);
+               m_freem (m);
+               return;
+       case PPP_IP:
+               if (sp->state[IDX_IPCP] == STATE_OPENED) {
+                       schednetisr (NETISR_IP);
+                       inq = &ipintrq;
+               }
+               break;
 #endif
 #ifdef INET6
-               case PPP_IPV6CP:
-                       if (sp->pp_phase == PHASE_NETWORK)
-                               sppp_cp_input(&ipv6cp, sp, m);
-                       m_freem (m);
-                       return;
-
-               case PPP_IPV6:
-                       if (sp->state[IDX_IPV6CP] == STATE_OPENED) {
-                               schednetisr (NETISR_IPV6);
-                               inq = &ip6intrq;
-                       }
-                       break;
+       case PPP_IPV6CP:
+               if (sp->pp_phase == PHASE_NETWORK)
+                       sppp_cp_input(&ipv6cp, sp, m);
+               m_freem (m);
+               return;
+
+       case PPP_IPV6:
+               if (sp->state[IDX_IPV6CP] == STATE_OPENED) {
+                       schednetisr (NETISR_IPV6);
+                       inq = &ip6intrq;
+               }
+               break;
 #endif
 #ifdef IPX
-               case PPP_IPX:
-                       /* IPX IPXCP not implemented yet */
-                       if (sp->pp_phase == PHASE_NETWORK) {
-                               schednetisr (NETISR_IPX);
-                               inq = &ipxintrq;
-                       }
-                       break;
+       case PPP_IPX:
+               /* IPX IPXCP not implemented yet */
+               if (sp->pp_phase == PHASE_NETWORK) {
+                       schednetisr (NETISR_IPX);
+                       inq = &ipxintrq;
+               }
+               break;
 #endif
 #ifdef NS
-               case PPP_XNS:
-                       /* XNS IDPCP not implemented yet */
-                       if (sp->pp_phase == PHASE_NETWORK) {
-                               schednetisr (NETISR_NS);
-                               inq = &nsintrq;
-                       }
-                       break;
-#endif
-#ifdef ISO
-               case PPP_ISO:
-                       /* OSI NLCP not implemented yet */
-                       if (sp->pp_phase == PHASE_NETWORK) {
-                               schednetisr (NETISR_ISO);
-                               inq = &clnlintrq;
-                       }



Home | Main Index | Thread Index | Old Index