Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net port FreeBSD's serial ppp layer to NetBSD. The PPP ...
details: https://anonhg.NetBSD.org/src/rev/a3d01945633e
branches: trunk
changeset: 467466:a3d01945633e
user: explorer <explorer%NetBSD.org@localhost>
date: Thu Mar 25 03:38:00 1999 +0000
description:
port FreeBSD's serial ppp layer to NetBSD. The PPP part seems broken still,
but the lmc driver uses the HDLC bits from here anyway.
diffstat:
sys/net/if_sppp.h | 72 ++
sys/net/if_spppsubr.c | 1403 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 1475 insertions(+), 0 deletions(-)
diffs (truncated from 1483 to 300 lines):
diff -r 80e2b676e268 -r a3d01945633e sys/net/if_sppp.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/net/if_sppp.h Thu Mar 25 03:38:00 1999 +0000
@@ -0,0 +1,72 @@
+/*
+ * Defines for synchronous PPP/Cisco link level subroutines.
+ *
+ * Copyright (C) 1994 Cronyx Ltd.
+ * Author: Serge Vakulenko, <vak%zebub.msk.su@localhost>
+ *
+ * This software is distributed with NO WARRANTIES, not even the implied
+ * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Authors grant any other persons or organizations permission to use
+ * or modify this software as long as this message is kept with the software,
+ * all derivative works or modified versions.
+ *
+ * Version 1.7, Wed Jun 7 22:12:02 MSD 1995
+ */
+
+#ifndef _NET_IF_HDLC_H_
+#define _NET_IF_HDLC_H_ 1
+
+struct slcp {
+ u_int16_t state; /* state machine */
+ u_int32_t magic; /* local magic number */
+ u_int8_t echoid; /* id of last keepalive echo request */
+ u_int8_t confid; /* id of last configuration request */
+};
+
+struct sipcp {
+ u_int16_t state; /* state machine */
+ u_int8_t confid; /* id of last configuration request */
+};
+
+struct sppp {
+ struct ifnet pp_if; /* network interface data */
+ struct ifqueue pp_fastq; /* fast output queue */
+ struct sppp *pp_next; /* next interface in keepalive list */
+ u_int pp_flags; /* use Cisco protocol instead of PPP */
+ u_int16_t pp_alivecnt; /* keepalive packets counter */
+ u_int16_t pp_loopcnt; /* loopback detection counter */
+ u_int32_t pp_seq; /* local sequence number */
+ u_int32_t pp_rseq; /* remote sequence number */
+ struct slcp lcp; /* LCP params */
+ struct sipcp ipcp; /* IPCP params */
+};
+
+#define PP_KEEPALIVE 0x01 /* use keepalive protocol */
+#define PP_CISCO 0x02 /* use Cisco protocol instead of PPP */
+#define PP_TIMO 0x04 /* cp_timeout routine active */
+
+#define PP_MTU 1500 /* max. transmit unit */
+
+#define LCP_STATE_CLOSED 0 /* LCP state: closed (conf-req sent) */
+#define LCP_STATE_ACK_RCVD 1 /* LCP state: conf-ack received */
+#define LCP_STATE_ACK_SENT 2 /* LCP state: conf-ack sent */
+#define LCP_STATE_OPENED 3 /* LCP state: opened */
+
+#define IPCP_STATE_CLOSED 0 /* IPCP state: closed (conf-req sent) */
+#define IPCP_STATE_ACK_RCVD 1 /* IPCP state: conf-ack received */
+#define IPCP_STATE_ACK_SENT 2 /* IPCP state: conf-ack sent */
+#define IPCP_STATE_OPENED 3 /* IPCP state: opened */
+
+#ifdef _KERNEL
+void spppattach(void);
+void sppp_attach (struct ifnet *ifp);
+void sppp_detach (struct ifnet *ifp);
+void sppp_input (struct ifnet *ifp, struct mbuf *m);
+int sppp_ioctl (struct ifnet *ifp, int cmd, void *data);
+struct mbuf *sppp_dequeue (struct ifnet *ifp);
+int sppp_isempty (struct ifnet *ifp);
+void sppp_flush (struct ifnet *ifp);
+#endif
+
+#endif /* _NET_IF_HDLC_H_ */
diff -r 80e2b676e268 -r a3d01945633e sys/net/if_spppsubr.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/net/if_spppsubr.c Thu Mar 25 03:38:00 1999 +0000
@@ -0,0 +1,1403 @@
+/*
+ * Synchronous PPP/Cisco link level subroutines.
+ * Keepalive protocol implemented in both Cisco and PPP modes.
+ *
+ * Copyright (C) 1994 Cronyx Ltd.
+ * Author: Serge Vakulenko, <vak%zebub.msk.su@localhost>
+ *
+ * This software is distributed with NO WARRANTIES, not even the implied
+ * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Authors grant any other persons or organisations permission to use
+ * or modify this software as long as this message is kept with the software,
+ * all derivative works or modified versions.
+ *
+ * Version 1.9, Wed Oct 4 18:58:15 MSK 1995
+ *
+ * $Id: if_spppsubr.c,v 1.1 1999/03/25 03:38:00 explorer Exp $
+ */
+#undef DEBUG
+
+#include "opt_inet.h"
+#include "opt_ns.h"
+#include "opt_iso.h"
+#include "opt_ipx.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/mbuf.h>
+
+#include <net/if.h>
+#include <net/netisr.h>
+#include <net/if_types.h>
+
+#ifdef INET
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
+#include <netinet/ip.h>
+#include <netinet/tcp.h>
+#endif
+
+#if defined(__NetBSD__)
+#include <net/if_ether.h>
+#elif defined(__FreeBSD__)
+#include <netinet/if_ether.h>
+#endif
+
+#ifdef IPX
+#include <netipx/ipx.h>
+#include <netipx/ipx_if.h>
+#endif
+
+#ifdef NS
+#include <netns/ns.h>
+#include <netns/ns_if.h>
+#endif
+
+#ifdef ISO
+#include <netiso/argo_debug.h>
+#include <netiso/iso.h>
+#include <netiso/iso_var.h>
+#include <netiso/iso_snpac.h>
+#endif
+
+#include <net/if_sppp.h>
+
+#ifdef DEBUG
+#define print(s) printf s
+#else
+#define print(s) {/*void*/}
+#endif
+
+#if defined(__NetBSD__)
+#define SPPP_PRINTF_FMT "%s"
+#define SPPP_PRINTF_ARG(x) (x->if_xname)
+#elif defined(__FreeBSD__)
+#define SPPP_PRINTF_FMT "%s%d"
+#define SPPP_PRINTF_ARG(x) (x->if_name), (x->if_unit)
+#endif
+
+#define MAXALIVECNT 3 /* max. alive packets */
+
+#define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */
+#define PPP_UI 0x03 /* Unnumbered Information */
+#define PPP_IP 0x0021 /* Internet Protocol */
+#define PPP_ISO 0x0023 /* ISO OSI Protocol */
+#define PPP_XNS 0x0025 /* Xerox NS Protocol */
+#define PPP_IPX 0x002b /* Novell IPX Protocol */
+#define PPP_LCP 0xc021 /* Link Control Protocol */
+#define PPP_IPCP 0x8021 /* Internet Protocol Control Protocol */
+
+#define LCP_CONF_REQ 1 /* PPP LCP configure request */
+#define LCP_CONF_ACK 2 /* PPP LCP configure acknowledge */
+#define LCP_CONF_NAK 3 /* PPP LCP configure negative ack */
+#define LCP_CONF_REJ 4 /* PPP LCP configure reject */
+#define LCP_TERM_REQ 5 /* PPP LCP terminate request */
+#define LCP_TERM_ACK 6 /* PPP LCP terminate acknowledge */
+#define LCP_CODE_REJ 7 /* PPP LCP code reject */
+#define LCP_PROTO_REJ 8 /* PPP LCP protocol reject */
+#define LCP_ECHO_REQ 9 /* PPP LCP echo request */
+#define LCP_ECHO_REPLY 10 /* PPP LCP echo reply */
+#define LCP_DISC_REQ 11 /* PPP LCP discard request */
+
+#define LCP_OPT_MRU 1 /* maximum receive unit */
+#define LCP_OPT_ASYNC_MAP 2 /* async control character map */
+#define LCP_OPT_AUTH_PROTO 3 /* authentication protocol */
+#define LCP_OPT_QUAL_PROTO 4 /* quality protocol */
+#define LCP_OPT_MAGIC 5 /* magic number */
+#define LCP_OPT_RESERVED 6 /* reserved */
+#define LCP_OPT_PROTO_COMP 7 /* protocol field compression */
+#define LCP_OPT_ADDR_COMP 8 /* address/control field compression */
+
+#define IPCP_CONF_REQ LCP_CONF_REQ /* PPP IPCP configure request */
+#define IPCP_CONF_ACK LCP_CONF_ACK /* PPP IPCP configure acknowledge */
+#define IPCP_CONF_NAK LCP_CONF_NAK /* PPP IPCP configure negative ack */
+#define IPCP_CONF_REJ LCP_CONF_REJ /* PPP IPCP configure reject */
+#define IPCP_TERM_REQ LCP_TERM_REQ /* PPP IPCP terminate request */
+#define IPCP_TERM_ACK LCP_TERM_ACK /* PPP IPCP terminate acknowledge */
+#define IPCP_CODE_REJ LCP_CODE_REJ /* PPP IPCP code reject */
+
+#define CISCO_MULTICAST 0x8f /* Cisco multicast address */
+#define CISCO_UNICAST 0x0f /* Cisco unicast address */
+#define CISCO_KEEPALIVE 0x8035 /* Cisco keepalive protocol */
+#define CISCO_ADDR_REQ 0 /* Cisco address request */
+#define CISCO_ADDR_REPLY 1 /* Cisco address reply */
+#define CISCO_KEEPALIVE_REQ 2 /* Cisco keepalive request */
+
+struct ppp_header {
+ u_int8_t address;
+ u_int8_t control;
+ u_int16_t protocol;
+};
+#define PPP_HEADER_LEN sizeof (struct ppp_header)
+
+struct lcp_header {
+ u_int8_t type;
+ u_int8_t ident;
+ u_int16_t len;
+};
+#define LCP_HEADER_LEN sizeof (struct lcp_header)
+
+struct cisco_packet {
+ u_int32_t type;
+ u_int32_t par1;
+ u_int32_t par2;
+ u_int16_t rel;
+ u_int16_t time0;
+ u_int16_t time1;
+};
+#define CISCO_PACKET_LEN 18
+
+static struct sppp *spppq;
+
+/*
+ * The following disgusting hack gets around the problem that IP TOS
+ * can't be set yet. We want to put "interactive" traffic on a high
+ * priority queue. To decide if traffic is interactive, we check that
+ * a) it is TCP and b) one of its ports is telnet, rlogin or ftp control.
+ */
+static u_int16_t interactive_ports[8] = {
+ 0, 513, 0, 0,
+ 0, 21, 0, 23,
+};
+#define INTERACTIVE(p) (interactive_ports[(p) & 7] == (p))
+
+/*
+ * Timeout routine activation macros.
+ */
+#define TIMO(p,s) if (! ((p)->pp_flags & PP_TIMO)) { \
+ timeout (sppp_cp_timeout, (void*) (p), (s)*hz); \
+ (p)->pp_flags |= PP_TIMO; }
+#define UNTIMO(p) if ((p)->pp_flags & PP_TIMO) { \
+ untimeout (sppp_cp_timeout, (void*) (p)); \
+ (p)->pp_flags &= ~PP_TIMO; }
+
+static void sppp_keepalive (void *dummy);
+static void sppp_cp_send (struct sppp *sp, u_int16_t proto, u_int8_t type,
+ u_int8_t ident, u_int16_t len, void *data);
+static void sppp_cisco_send (struct sppp *sp, int type, int32_t par1, int32_t par2);
+static void sppp_lcp_input (struct sppp *sp, struct mbuf *m);
+static void sppp_cisco_input (struct sppp *sp, struct mbuf *m);
+static void sppp_ipcp_input (struct sppp *sp, struct mbuf *m);
+static void sppp_lcp_open (struct sppp *sp);
+static void sppp_ipcp_open (struct sppp *sp);
+static int sppp_lcp_conf_parse_options (struct sppp *sp, struct lcp_header *h,
+ int len, u_int32_t *magic);
+static void sppp_cp_timeout (void *arg);
+static char *sppp_lcp_type_name (u_int8_t type);
+static char *sppp_ipcp_type_name (u_int8_t type);
+static void sppp_print_bytes (u_int8_t *p, u_int16_t len);
+static int sppp_output (struct ifnet *ifp, struct mbuf *m,
+ struct sockaddr *dst, struct rtentry *rt);
+
+#if defined(__NetBSD__)
+void
+spppattach()
+{
+}
+#endif
+
+/*
+ * Flush interface queue.
+ */
+static void qflush (struct ifqueue *ifq)
+{
+ struct mbuf *m, *n;
+
+ n = ifq->ifq_head;
+ while ((m = n)) {
+ n = m->m_act;
+ m_freem (m);
+ }
+ ifq->ifq_head = 0;
+ ifq->ifq_tail = 0;
+ ifq->ifq_len = 0;
+}
+
Home |
Main Index |
Thread Index |
Old Index