Deleted Added
full compact
if_spppsubr.c (25955) if_spppsubr.c (26018)
1/*
2 * Synchronous PPP/Cisco link level subroutines.
3 * Keepalive protocol implemented in both Cisco and PPP modes.
4 *
5 * Copyright (C) 1994 Cronyx Ltd.
6 * Author: Serge Vakulenko, <vak@cronyx.ru>
7 *
8 * Heavily revamped to conform to RFC 1661.
9 * Copyright (C) 1997, Joerg Wunsch.
10 *
11 * This software is distributed with NO WARRANTIES, not even the implied
12 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 * Authors grant any other persons or organisations permission to use
15 * or modify this software as long as this message is kept with the software,
16 * all derivative works or modified versions.
17 *
18 * From: Version 1.9, Wed Oct 4 18:58:15 MSK 1995
19 *
1/*
2 * Synchronous PPP/Cisco link level subroutines.
3 * Keepalive protocol implemented in both Cisco and PPP modes.
4 *
5 * Copyright (C) 1994 Cronyx Ltd.
6 * Author: Serge Vakulenko, <vak@cronyx.ru>
7 *
8 * Heavily revamped to conform to RFC 1661.
9 * Copyright (C) 1997, Joerg Wunsch.
10 *
11 * This software is distributed with NO WARRANTIES, not even the implied
12 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 * Authors grant any other persons or organisations permission to use
15 * or modify this software as long as this message is kept with the software,
16 * all derivative works or modified versions.
17 *
18 * From: Version 1.9, Wed Oct 4 18:58:15 MSK 1995
19 *
20 * $Id: if_spppsubr.c,v 1.19 1997/05/19 22:03:09 joerg Exp $
20 * $Id: if_spppsubr.c,v 1.20 1997/05/20 22:54:04 joerg Exp $
21 */
22
23#include <sys/param.h>
24#include <sys/systm.h>
25#include <sys/kernel.h>
26#include <sys/sockio.h>
27#include <sys/socket.h>
28#include <sys/syslog.h>

--- 601 unchanged lines hidden (view full) ---

630
631 /* Insert new entry into the keepalive list. */
632 sp->pp_next = spppq;
633 spppq = sp;
634
635 sp->pp_if.if_type = IFT_PPP;
636 sp->pp_if.if_output = sppp_output;
637 sp->pp_fastq.ifq_maxlen = 32;
21 */
22
23#include <sys/param.h>
24#include <sys/systm.h>
25#include <sys/kernel.h>
26#include <sys/sockio.h>
27#include <sys/socket.h>
28#include <sys/syslog.h>

--- 601 unchanged lines hidden (view full) ---

630
631 /* Insert new entry into the keepalive list. */
632 sp->pp_next = spppq;
633 spppq = sp;
634
635 sp->pp_if.if_type = IFT_PPP;
636 sp->pp_if.if_output = sppp_output;
637 sp->pp_fastq.ifq_maxlen = 32;
638 sp->pp_cpq.ifq_maxlen = 20;
638 sp->pp_loopcnt = 0;
639 sp->pp_alivecnt = 0;
640 sp->pp_seq = 0;
641 sp->pp_rseq = 0;
642 sp->pp_phase = PHASE_DEAD;
643 sp->pp_up = lcp.Up;
644 sp->pp_down = lcp.Down;
645

--- 27 unchanged lines hidden (view full) ---

673 */
674void
675sppp_flush(struct ifnet *ifp)
676{
677 struct sppp *sp = (struct sppp*) ifp;
678
679 sppp_qflush (&sp->pp_if.if_snd);
680 sppp_qflush (&sp->pp_fastq);
639 sp->pp_loopcnt = 0;
640 sp->pp_alivecnt = 0;
641 sp->pp_seq = 0;
642 sp->pp_rseq = 0;
643 sp->pp_phase = PHASE_DEAD;
644 sp->pp_up = lcp.Up;
645 sp->pp_down = lcp.Down;
646

--- 27 unchanged lines hidden (view full) ---

674 */
675void
676sppp_flush(struct ifnet *ifp)
677{
678 struct sppp *sp = (struct sppp*) ifp;
679
680 sppp_qflush (&sp->pp_if.if_snd);
681 sppp_qflush (&sp->pp_fastq);
682 sppp_qflush (&sp->pp_cpq);
681}
682
683/*
684 * Check if the output queue is empty.
685 */
686int
687sppp_isempty(struct ifnet *ifp)
688{
689 struct sppp *sp = (struct sppp*) ifp;
690 int empty, s;
691
692 s = splimp();
683}
684
685/*
686 * Check if the output queue is empty.
687 */
688int
689sppp_isempty(struct ifnet *ifp)
690{
691 struct sppp *sp = (struct sppp*) ifp;
692 int empty, s;
693
694 s = splimp();
693 empty = !sp->pp_fastq.ifq_head && !sp->pp_if.if_snd.ifq_head;
695 empty = !sp->pp_fastq.ifq_head && !sp->pp_cpq.ifq_head &&
696 !sp->pp_if.if_snd.ifq_head;
694 splx(s);
695 return (empty);
696}
697
698/*
699 * Get next packet to send.
700 */
701struct mbuf *
702sppp_dequeue(struct ifnet *ifp)
703{
704 struct sppp *sp = (struct sppp*) ifp;
705 struct mbuf *m;
706 int s;
707
708 s = splimp();
697 splx(s);
698 return (empty);
699}
700
701/*
702 * Get next packet to send.
703 */
704struct mbuf *
705sppp_dequeue(struct ifnet *ifp)
706{
707 struct sppp *sp = (struct sppp*) ifp;
708 struct mbuf *m;
709 int s;
710
711 s = splimp();
709 IF_DEQUEUE (&sp->pp_fastq, m);
710 if (! m)
711 IF_DEQUEUE (&sp->pp_if.if_snd, m);
712 splx (s);
713 return (m);
712 /*
713 * Process only the control protocol queue until we are in
714 * network phase.
715 *
716 * XXX Network phase itself is still not a sufficient test, we
717 * normally should keep a separate queue for each supported
718 * protocol family, and only serve these queues as the
719 * respective NCPs were opened. The simplistic logic used
720 * here might cause some loss of network traffic while the
721 * NCPs are being negotiated, in particular if the NCPs take a
722 * long time to negotiate.
723 *
724 * Do always serve all three queues in Cisco mode.
725 */
726 IF_DEQUEUE(&sp->pp_cpq, m);
727 if (m == NULL &&
728 (sp->pp_phase == PHASE_NETWORK ||
729 (sp->pp_flags & PP_CISCO) != 0)) {
730 IF_DEQUEUE(&sp->pp_fastq, m);
731 if (m == NULL)
732 IF_DEQUEUE (&sp->pp_if.if_snd, m);
733 }
734 splx(s);
735 return m;
714}
715
716/*
717 * Process an ioctl request. Called on low priority level.
718 */
719int
720sppp_ioctl(struct ifnet *ifp, int cmd, void *data)
721{

--- 25 unchanged lines hidden (view full) ---

747
748 if (going_up || going_down)
749 lcp.Close(sp);
750 if (going_up && newmode == 0) {
751 /* neither auto-dial nor passive */
752 ifp->if_flags |= IFF_RUNNING;
753 if (!(sp->pp_flags & PP_CISCO))
754 lcp.Open(sp);
736}
737
738/*
739 * Process an ioctl request. Called on low priority level.
740 */
741int
742sppp_ioctl(struct ifnet *ifp, int cmd, void *data)
743{

--- 25 unchanged lines hidden (view full) ---

769
770 if (going_up || going_down)
771 lcp.Close(sp);
772 if (going_up && newmode == 0) {
773 /* neither auto-dial nor passive */
774 ifp->if_flags |= IFF_RUNNING;
775 if (!(sp->pp_flags & PP_CISCO))
776 lcp.Open(sp);
755 } else if (going_down)
777 } else if (going_down) {
778 sppp_flush(ifp);
756 ifp->if_flags &= ~IFF_RUNNING;
779 ifp->if_flags &= ~IFF_RUNNING;
780 }
757
758 break;
759
760#ifdef SIOCSIFMTU
761#ifndef ifr_mtu
762#define ifr_mtu ifr_metric
763#endif
764 case SIOCSIFMTU:

--- 77 unchanged lines hidden (view full) ---

842 /* Local and remote sequence numbers are equal.
843 * Probably, the line is in loopback mode. */
844 if (sp->pp_loopcnt >= MAXALIVECNT) {
845 printf ("%s%d: loopback\n",
846 ifp->if_name, ifp->if_unit);
847 sp->pp_loopcnt = 0;
848 if (ifp->if_flags & IFF_UP) {
849 if_down (ifp);
781
782 break;
783
784#ifdef SIOCSIFMTU
785#ifndef ifr_mtu
786#define ifr_mtu ifr_metric
787#endif
788 case SIOCSIFMTU:

--- 77 unchanged lines hidden (view full) ---

866 /* Local and remote sequence numbers are equal.
867 * Probably, the line is in loopback mode. */
868 if (sp->pp_loopcnt >= MAXALIVECNT) {
869 printf ("%s%d: loopback\n",
870 ifp->if_name, ifp->if_unit);
871 sp->pp_loopcnt = 0;
872 if (ifp->if_flags & IFF_UP) {
873 if_down (ifp);
850 sppp_qflush (&sp->pp_fastq);
874 sppp_qflush (&sp->pp_cpq);
851 }
852 }
853 ++sp->pp_loopcnt;
854
855 /* Generate new local sequence number */
856 sp->pp_seq ^= time.tv_sec ^ time.tv_usec;
857 break;
858 }

--- 54 unchanged lines hidden (view full) ---

913 ch->time1 = htons ((u_short) t);
914
915 if (debug)
916 log(LOG_DEBUG,
917 "%s%d: cisco output: <0x%lx 0x%lx 0x%lx 0x%x 0x%x-0x%x>\n",
918 ifp->if_name, ifp->if_unit, ntohl (ch->type), ch->par1,
919 ch->par2, ch->rel, ch->time0, ch->time1);
920
875 }
876 }
877 ++sp->pp_loopcnt;
878
879 /* Generate new local sequence number */
880 sp->pp_seq ^= time.tv_sec ^ time.tv_usec;
881 break;
882 }

--- 54 unchanged lines hidden (view full) ---

937 ch->time1 = htons ((u_short) t);
938
939 if (debug)
940 log(LOG_DEBUG,
941 "%s%d: cisco output: <0x%lx 0x%lx 0x%lx 0x%x 0x%x-0x%x>\n",
942 ifp->if_name, ifp->if_unit, ntohl (ch->type), ch->par1,
943 ch->par2, ch->rel, ch->time0, ch->time1);
944
921 if (IF_QFULL (&sp->pp_fastq)) {
945 if (IF_QFULL (&sp->pp_cpq)) {
946 IF_DROP (&sp->pp_fastq);
922 IF_DROP (&ifp->if_snd);
923 m_freem (m);
924 } else
947 IF_DROP (&ifp->if_snd);
948 m_freem (m);
949 } else
925 IF_ENQUEUE (&sp->pp_fastq, m);
950 IF_ENQUEUE (&sp->pp_cpq, m);
926 if (! (ifp->if_flags & IFF_OACTIVE))
927 (*ifp->if_start) (ifp);
928 ifp->if_obytes += m->m_pkthdr.len + 3;
929}
930
931 /*
932 * PPP protocol implementation.
933 */

--- 35 unchanged lines hidden (view full) ---

969 ifp->if_name, ifp->if_unit,
970 sppp_proto_name(proto),
971 sppp_cp_type_name (lh->type), lh->ident,
972 ntohs (lh->len));
973 if (len)
974 sppp_print_bytes ((u_char*) (lh+1), len);
975 addlog(">\n");
976 }
951 if (! (ifp->if_flags & IFF_OACTIVE))
952 (*ifp->if_start) (ifp);
953 ifp->if_obytes += m->m_pkthdr.len + 3;
954}
955
956 /*
957 * PPP protocol implementation.
958 */

--- 35 unchanged lines hidden (view full) ---

994 ifp->if_name, ifp->if_unit,
995 sppp_proto_name(proto),
996 sppp_cp_type_name (lh->type), lh->ident,
997 ntohs (lh->len));
998 if (len)
999 sppp_print_bytes ((u_char*) (lh+1), len);
1000 addlog(">\n");
1001 }
977 if (IF_QFULL (&sp->pp_fastq)) {
1002 if (IF_QFULL (&sp->pp_cpq)) {
1003 IF_DROP (&sp->pp_fastq);
978 IF_DROP (&ifp->if_snd);
979 m_freem (m);
980 ++ifp->if_oerrors;
981 } else
1004 IF_DROP (&ifp->if_snd);
1005 m_freem (m);
1006 ++ifp->if_oerrors;
1007 } else
982 IF_ENQUEUE (&sp->pp_fastq, m);
1008 IF_ENQUEUE (&sp->pp_cpq, m);
983 if (! (ifp->if_flags & IFF_OACTIVE))
984 (*ifp->if_start) (ifp);
985 ifp->if_obytes += m->m_pkthdr.len + 3;
986}
987
988/*
989 * Handle incoming PPP control protocol packets.
990 */

--- 274 unchanged lines hidden (view full) ---

1265 "packet length: %d bytes\n",
1266 ifp->if_name, ifp->if_unit, len);
1267 break;
1268 }
1269 if (ntohl (*(long*)(h+1)) == sp->lcp.magic) {
1270 /* Line loopback mode detected. */
1271 printf("%s%d: loopback\n", ifp->if_name, ifp->if_unit);
1272 if_down (ifp);
1009 if (! (ifp->if_flags & IFF_OACTIVE))
1010 (*ifp->if_start) (ifp);
1011 ifp->if_obytes += m->m_pkthdr.len + 3;
1012}
1013
1014/*
1015 * Handle incoming PPP control protocol packets.
1016 */

--- 274 unchanged lines hidden (view full) ---

1291 "packet length: %d bytes\n",
1292 ifp->if_name, ifp->if_unit, len);
1293 break;
1294 }
1295 if (ntohl (*(long*)(h+1)) == sp->lcp.magic) {
1296 /* Line loopback mode detected. */
1297 printf("%s%d: loopback\n", ifp->if_name, ifp->if_unit);
1298 if_down (ifp);
1273 sppp_qflush (&sp->pp_fastq);
1299 sppp_qflush (&sp->pp_cpq);
1274
1275 /* Shut down the PPP link. */
1276 /* XXX */
1277 lcp.Down(sp);
1278 lcp.Up(sp);
1279 break;
1280 }
1281 *(long*)(h+1) = htonl (sp->lcp.magic);

--- 447 unchanged lines hidden (view full) ---

1729 * Local and remote magics equal -- loopback?
1730 */
1731 if (sp->pp_loopcnt >= MAXALIVECNT*5) {
1732 printf ("\n%s%d: loopback\n",
1733 ifp->if_name, ifp->if_unit);
1734 sp->pp_loopcnt = 0;
1735 if (ifp->if_flags & IFF_UP) {
1736 if_down(ifp);
1300
1301 /* Shut down the PPP link. */
1302 /* XXX */
1303 lcp.Down(sp);
1304 lcp.Up(sp);
1305 break;
1306 }
1307 *(long*)(h+1) = htonl (sp->lcp.magic);

--- 447 unchanged lines hidden (view full) ---

1755 * Local and remote magics equal -- loopback?
1756 */
1757 if (sp->pp_loopcnt >= MAXALIVECNT*5) {
1758 printf ("\n%s%d: loopback\n",
1759 ifp->if_name, ifp->if_unit);
1760 sp->pp_loopcnt = 0;
1761 if (ifp->if_flags & IFF_UP) {
1762 if_down(ifp);
1737 sppp_qflush(&sp->pp_fastq);
1763 sppp_qflush(&sp->pp_cpq);
1738 /* XXX ? */
1739 lcp.Down(sp);
1740 lcp.Up(sp);
1741 }
1742 } else if (debug)
1743 addlog("[glitch] ");
1744 ++sp->pp_loopcnt;
1745 /*

--- 768 unchanged lines hidden (view full) ---

2514 if (! (sp->pp_flags & PP_CISCO) &&
2515 sp->pp_phase < PHASE_AUTHENTICATE)
2516 continue;
2517
2518 if (sp->pp_alivecnt == MAXALIVECNT) {
2519 /* No keepalive packets got. Stop the interface. */
2520 printf ("%s%d: down\n", ifp->if_name, ifp->if_unit);
2521 if_down (ifp);
1764 /* XXX ? */
1765 lcp.Down(sp);
1766 lcp.Up(sp);
1767 }
1768 } else if (debug)
1769 addlog("[glitch] ");
1770 ++sp->pp_loopcnt;
1771 /*

--- 768 unchanged lines hidden (view full) ---

2540 if (! (sp->pp_flags & PP_CISCO) &&
2541 sp->pp_phase < PHASE_AUTHENTICATE)
2542 continue;
2543
2544 if (sp->pp_alivecnt == MAXALIVECNT) {
2545 /* No keepalive packets got. Stop the interface. */
2546 printf ("%s%d: down\n", ifp->if_name, ifp->if_unit);
2547 if_down (ifp);
2522 sppp_qflush (&sp->pp_fastq);
2548 sppp_qflush (&sp->pp_cpq);
2523 if (! (sp->pp_flags & PP_CISCO)) {
2524 /* XXX */
2525 /* Shut down the PPP link. */
2526 lcp.Down(sp);
2527 /* Initiate negotiation. XXX */
2528 lcp.Up(sp);
2529 }
2530 }

--- 189 unchanged lines hidden ---
2549 if (! (sp->pp_flags & PP_CISCO)) {
2550 /* XXX */
2551 /* Shut down the PPP link. */
2552 lcp.Down(sp);
2553 /* Initiate negotiation. XXX */
2554 lcp.Up(sp);
2555 }
2556 }

--- 189 unchanged lines hidden ---