Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net Support routines for Token-Ring network drivers.
details: https://anonhg.NetBSD.org/src/rev/cdadd1e9a0f1
branches: trunk
changeset: 467300:cdadd1e9a0f1
user: bad <bad%NetBSD.org@localhost>
date: Mon Mar 22 22:22:52 1999 +0000
description:
Support routines for Token-Ring network drivers.
By Onno van der Linden.
diffstat:
sys/net/if_token.h | 126 +++++++++
sys/net/if_tokensubr.c | 675 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 801 insertions(+), 0 deletions(-)
diffs (truncated from 809 to 300 lines):
diff -r 6d69b6845ee3 -r cdadd1e9a0f1 sys/net/if_token.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/net/if_token.h Mon Mar 22 22:22:52 1999 +0000
@@ -0,0 +1,126 @@
+/* $NetBSD: if_token.h,v 1.1 1999/03/22 22:22:52 bad Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if_tr.h 8.1 (Berkeley) 6/10/93
+ * from: $NetBSD: if_fddi.h,v 1.2 1995/08/19 04:35:28 cgd Exp
+ */
+
+#ifndef _NET_IF_TOKEN_H_
+#define _NET_IF_TOKEN_H_
+
+#define ISO88025_ADDR_LEN 6
+
+/* Token Ring physical header */
+struct token_header {
+ u_int8_t token_ac; /* access control field */
+ u_int8_t token_fc; /* frame control field */
+ u_int8_t token_dhost[ISO88025_ADDR_LEN]; /* dest. address */
+ u_int8_t token_shost[ISO88025_ADDR_LEN]; /* source address */
+};
+
+#define TOKEN_MAX_BRIDGE 8
+
+/* Token Ring routing information field */
+struct token_rif {
+ u_int16_t tr_rcf; /* route control field */
+ u_int16_t tr_rdf[TOKEN_MAX_BRIDGE]; /* route-designator fields */
+};
+
+/* standard values for adress control and frame control field */
+#define TOKEN_AC 0x10
+#define TOKEN_FC 0x40
+
+#define TOKEN_RI_PRESENT 0x80 /* routing info present bit */
+#define TOKEN_RCF_LEN_MASK 0x1f00
+#define TOKEN_RCF_BROADCAST_MASK 0xe000
+#define TOKEN_RCF_BROADCAST_ALL 0x8000 /* all routes broadcast */
+#define TOKEN_RCF_BROADCAST_SINGLE 0xc000 /* single route broadcast */
+
+/*
+ * A Token-ring frame consists of
+ * header + rif + llcinfo + fcs
+ * 14 + 2 * (0 ... 9) + x + 4 octets
+ * where llcinfo contains the llcsnap header (8 octets) and the IP frame
+ */
+ /* LLC INFO (802.5PD-2) */
+#define TOKEN_RCF_FRAME0 0x0000 /* 516 */
+#define TOKEN_RCF_FRAME1 0x0010 /* 1500 */
+#define TOKEN_RCF_FRAME2 0x0020 /* 2052 */
+#define TOKEN_RCF_FRAME3 0x0030 /* 4472 */
+#define TOKEN_RCF_FRAME4 0x0040 /* 8144 */
+#define TOKEN_RCF_FRAME5 0x0050 /* 11407 */
+#define TOKEN_RCF_FRAME6 0x0060 /* 17800 */
+#define TOKEN_RCF_FRAME7 0x0070 /* 65535 */
+#define TOKEN_RCF_FRAME_MASK 0x0070
+
+#define TOKEN_RCF_DIRECTION 0x0080
+
+/*
+ * According to RFC 1042
+ */
+#define IPMTU_4MBIT_MAX 4464
+#define IPMTU_16MBIT_MAX 8188
+
+/*
+ * RFC 1042:
+ * It is recommended that all implementations support IP packets
+ * of at least 2002 octets.
+ */
+#define ISO88025_MTU 2002
+
+/*
+ * This assumes that route information fields are appended to
+ * existing structures like llinfo_arp and tr_header
+ */
+#define TOKEN_RIF(x) ((struct token_rif *) ((x) + 1))
+
+#if defined(_KERNEL)
+/*
+ * XXX we need if_ethersubr.c with all these defines
+ */
+#define tokenbroadcastaddr etherbroadcastaddr
+#define token_ipmulticast_min ether_ipmulticast_min
+#define token_ipmulticast_max ether_ipmulticast_max
+#define token_addmulti ether_addmulti
+#define token_delmulti ether_delmulti
+#define token_sprintf ether_sprintf
+
+void token_ifattach __P((struct ifnet *, caddr_t));
+void token_input __P((struct ifnet *, struct token_header *, struct mbuf *));
+int token_output __P((struct ifnet *,
+ struct mbuf *, struct sockaddr *, struct rtentry *));
+
+#endif
+
+#endif _NET_IF_TOKEN_H_
diff -r 6d69b6845ee3 -r cdadd1e9a0f1 sys/net/if_tokensubr.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/net/if_tokensubr.c Mon Mar 22 22:22:52 1999 +0000
@@ -0,0 +1,675 @@
+/*
+ * Copyright (c) 1997-1999
+ * Onno van der Linden
+ * Copyright (c) 1995
+ * Matt Thomas. All rights reserved.
+ * Copyright (c) 1982, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)if_trsubr.c 8.1 (Berkeley) 6/10/93
+ * from: $NetBSD: if_tokensubr.c,v 1.1 1999/03/22 22:22:52 bad Exp $
+ */
+#include "opt_inet.h"
+#include "opt_atalk.h"
+#include "opt_ccitt.h"
+#include "opt_llc.h"
+#include "opt_iso.h"
+#include "opt_ns.h"
+#include "opt_gateway.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/errno.h>
+#include <sys/syslog.h>
+
+#include <machine/cpu.h>
+
+#include <net/if.h>
+#include <net/netisr.h>
+#include <net/route.h>
+#include <net/if_llc.h>
+#include <net/if_dl.h>
+#include <net/if_types.h>
+
+#include <net/if_ether.h>
+
+#ifdef INET
+#include <netinet/in.h>
+#include <netinet/in_var.h>
+#include <netinet/if_inarp.h>
+#include <net/if_token.h>
+#endif
+
+#ifdef NS
+#include <netns/ns.h>
+#include <netns/ns_if.h>
+#endif
+
+#ifdef DECNET
+#include <netdnet/dn.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 "bpfilter.h"
+
+#ifdef LLC
+#include <netccitt/dll.h>
+#include <netccitt/llc_var.h>
+#endif
+
+/*
+ * TODO:
+ * handle source routing via send_xid()
+ * source routing for ISO,LLC,CCITT protocols
+ * need sockaddr_dl_8025 to handle this correctly
+ * IPX cases
+ * handle "fast" forwarding like if_ether and if_fddi
+ */
+
+#if defined(LLC) && defined(CCITT)
+extern struct ifqueue pkintrq;
+#endif
+
+#define senderr(e) { error = (e); goto bad;}
+
+#if defined(__bsdi__) || defined(__NetBSD__)
+#define RTALLOC1(a, b) rtalloc1(a, b)
+#define ARPRESOLVE(a, b, c, d, e, f) arpresolve(a, b, c, d, e)
+#define TYPEHTONS(t) (t)
+#elif defined(__FreeBSD__)
+#define RTALLOC1(a, b) rtalloc1(a, b, 0UL)
+#define ARPRESOLVE(a, b, c, d, e, f) arpresolve(a, b, c, d, e, f)
+#define TYPEHTONS(t) (htons(t))
+#endif
+
+#define RCF_ALLROUTES (2 << 8) | TOKEN_RCF_FRAME2 | TOKEN_RCF_BROADCAST_ALL
+#define RCF_SINGLEROUTE (2 << 8) | TOKEN_RCF_FRAME2 | TOKEN_RCF_BROADCAST_SINGLE
+
+/*
+ * Token Ring output routine.
+ * Encapsulate a packet of type family for the local net.
+ * Assumes that ifp is actually pointer to arphdr structure.
+ * XXX route info has to go into the same mbuf as the header
+ */
+int
+token_output(ifp, m0, dst, rt0)
+ register struct ifnet *ifp;
+ struct mbuf *m0;
+ struct sockaddr *dst;
+ struct rtentry *rt0;
+{
+ u_int16_t etype;
+ int s, error = 0;
+ u_char edst[ISO88025_ADDR_LEN];
+ register struct mbuf *m = m0;
+ register struct rtentry *rt;
+ struct mbuf *mcopy = (struct mbuf *)0;
+ struct token_header *trh;
+#ifdef INET
+ struct arphdr *ah = (struct arphdr *)ifp;
+#endif /* INET */
+ struct token_rif *rif = (struct token_rif *)0;
+ struct token_rif bcastrif;
+ size_t riflen = 0;
+
+ if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
+ senderr(ENETDOWN);
+ ifp->if_lastchange = time;
+ if ((rt = rt0)) {
+ if ((rt->rt_flags & RTF_UP) == 0) {
+ if ((rt0 = rt = RTALLOC1(dst, 1)))
+ rt->rt_refcnt--;
+ else
+ senderr(EHOSTUNREACH);
+ }
+ if (rt->rt_flags & RTF_GATEWAY) {
+ if (rt->rt_gwroute == 0)
Home |
Main Index |
Thread Index |
Old Index