From f14c3bda44fa0a848a56d984661f9685bba97044 Mon Sep 17 00:00:00 2001 From: lile Date: Sun, 19 Mar 2000 21:34:39 +0000 Subject: o Replace most magic numbers related to token ring with #defines from iso88025.h. o Add minimal llc support to iso88025_input. o Clean up most of the source routing code. * Submitted by: Nikolai Saoukh --- sys/net/if_iso88025subr.c | 104 +++++++++++++++++++++++++++------------------- sys/net/iso88025.h | 58 +++++++++++++++----------- 2 files changed, 96 insertions(+), 66 deletions(-) (limited to 'sys/net') diff --git a/sys/net/if_iso88025subr.c b/sys/net/if_iso88025subr.c index fae8799..5d7b902 100644 --- a/sys/net/if_iso88025subr.c +++ b/sys/net/if_iso88025subr.c @@ -83,17 +83,16 @@ #include void -iso88025_ifattach(ifp) - register struct ifnet *ifp; +iso88025_ifattach(struct ifnet *ifp) { register struct ifaddr *ifa = NULL; register struct sockaddr_dl *sdl; ifp->if_type = IFT_ISO88025; - ifp->if_addrlen = 6; - ifp->if_hdrlen=18; + ifp->if_addrlen = ISO88025_ADDR_LEN; + ifp->if_hdrlen = ISO88025_HDR_LEN; if (ifp->if_baudrate == 0) - ifp->if_baudrate = 16000000; /* 1, 4, or 16Mbit default? */ + ifp->if_baudrate = TR_16MBPS; /* 16Mbit should be a safe default */ if (ifp->if_mtu == 0) ifp->if_mtu = ISO88025_DEFAULT_MTU; @@ -146,7 +145,7 @@ iso88025_ioctl(struct ifnet *ifp, int command, caddr_t data) /* * Set the interface MTU. */ - if (ifr->ifr_mtu > ISO88025MTU) { + if (ifr->ifr_mtu > ISO88025_MAX_MTU) { error = EINVAL; } else { ifp->if_mtu = ifr->ifr_mtu; @@ -160,11 +159,7 @@ iso88025_ioctl(struct ifnet *ifp, int command, caddr_t data) * ISO88025 encapsulation */ int -iso88025_output(ifp, m, dst, rt0) - register struct ifnet *ifp; - struct mbuf *m; - struct sockaddr *dst; - struct rtentry *rt0; +iso88025_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt0) { register struct iso88025_header *th; struct iso88025_header gen_th; @@ -208,17 +203,17 @@ iso88025_output(ifp, m, dst, rt0) /* Calculate routing info length based on arp table entry */ if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway)) if (sdl->sdl_rcf != NULL) - rif_len = (ntohs(sdl->sdl_rcf) & 0x1f00) >> 8; + rif_len = TR_RCF_RIFLEN(sdl->sdl_rcf); /* Generate a generic 802.5 header for the packet */ - gen_th.ac = 0x10; - gen_th.fc = 0x40; + gen_th.ac = TR_AC; + gen_th.fc = TR_LLC_FRAME; memcpy(gen_th.iso88025_shost, ac->ac_enaddr, sizeof(ac->ac_enaddr)); if (rif_len) { - gen_th.iso88025_shost[0] |= 0x80; + gen_th.iso88025_shost[0] |= TR_RII; if (rif_len > 2) { gen_th.rcf = sdl->sdl_rcf; - memcpy(gen_th.rseg, sdl->sdl_route, rif_len - 2); + memcpy(gen_th.rd, sdl->sdl_route, rif_len - 2); } } @@ -234,9 +229,8 @@ iso88025_output(ifp, m, dst, rt0) senderr(ENOBUFS); l = mtod(m, struct llc *); l->llc_un.type_snap.ether_type = htons(ETHERTYPE_IP); - l->llc_dsap = 0xaa; - l->llc_ssap = 0xaa; - l->llc_un.type_snap.control = 0x3; + l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP; + l->llc_un.type_snap.control = LLC_UI; l->llc_un.type_snap.org_code[0] = 0x0; l->llc_un.type_snap.org_code[1] = 0x0; l->llc_un.type_snap.org_code[2] = 0x0; @@ -294,11 +288,9 @@ iso88025_output(ifp, m, dst, rt0) (loop_copy != -1)) { if ((m->m_flags & M_BCAST) || (loop_copy > 0)) { struct mbuf *n = m_copy(m, 0, (int)M_COPYALL); - /*printf("iso88025_output: if_simloop broadcast.\n");*/ (void) if_simloop(ifp, n, dst, ISO88025_HDR_LEN); } else if (bcmp(th->iso88025_dhost, th->iso88025_shost, ETHER_ADDR_LEN) == 0) { - /*printf("iso88025_output: if_simloop to ourselves.\n");*/ (void) if_simloop(ifp, m, dst, ISO88025_HDR_LEN); return(0); /* XXX */ } @@ -316,7 +308,6 @@ iso88025_output(ifp, m, dst, rt0) senderr(ENOBUFS); } IF_ENQUEUE(&ifp->if_snd, m); - /*printf("iso88025_output: packet queued.\n");*/ if ((ifp->if_flags & IFF_OACTIVE) == 0) (*ifp->if_start)(ifp); splx(s); @@ -328,7 +319,6 @@ iso88025_output(ifp, m, dst, rt0) bad: if (m) m_freem(m); - /*printf("iso88025_output: something went wrong, bailing to bad.\n");*/ return (error); } @@ -336,31 +326,66 @@ bad: * ISO 88025 de-encapsulation */ void -iso88025_input(ifp, th, m) - struct ifnet *ifp; - register struct iso88025_header *th; - struct mbuf *m; +iso88025_input(struct ifnet *ifp, struct iso88025_header *th, struct mbuf *m) { register struct ifqueue *inq; u_short ether_type; int s; register struct llc *l = mtod(m, struct llc *); - /*printf("iso88025_input: entered.\n");*/ + if ((ifp->if_flags & IFF_UP) == 0) { + m_freem(m); + return; + } + + switch (l->llc_control) { + case LLC_UI: + break; + case LLC_TEST: + case LLC_TEST_P: + { + struct sockaddr sa; + struct arpcom *ac = (struct arpcom *)ifp; + struct iso88025_sockaddr_data *th2; + int i; + u_char c = l->llc_dsap; + + if (th->iso88025_shost[0] & TR_RII) { /* XXX */ + printf("iso88025_input: dropping source routed LLC_TEST\n"); + m_free(m); + return; + } + l->llc_dsap = l->llc_ssap; + l->llc_ssap = c; + if (m->m_flags & (M_BCAST | M_MCAST)) + bcopy((caddr_t)ac->ac_enaddr, + (caddr_t)th->iso88025_dhost, ISO88025_ADDR_LEN); + sa.sa_family = AF_UNSPEC; + sa.sa_len = sizeof(sa); + th2 = (struct iso88025_sockaddr_data *)sa.sa_data; + for (i = 0; i < ISO88025_ADDR_LEN; i++) { + th2->ether_shost[i] = c = th->iso88025_dhost[i]; + th2->ether_dhost[i] = th->iso88025_dhost[i] = th->iso88025_shost[i]; + th->iso88025_shost[i] = c; + } + th2->ac = TR_AC; + th2->fc = TR_LLC_FRAME; + ifp->if_output(ifp, m, &sa, NULL); + return; + } + default: + printf("iso88025_input: unexpected llc control 0x%02x\n", l->llc_control); + m_freem(m); + return; + } - /*m->m_pkthdr.len = m->m_len = m->m_len - 8;*/ /* Length of LLC header in our case */ m->m_pkthdr.len -= 8; m->m_len -= 8; m->m_data += 8; /* Length of LLC header in our case */ - if ((ifp->if_flags & IFF_UP) == 0) { - m_freem(m); - return; - } - ifp->if_ibytes += m->m_pkthdr.len + sizeof (*th); + ifp->if_ibytes += m->m_pkthdr.len + sizeof(*th); if (th->iso88025_dhost[0] & 1) { - if (bcmp((caddr_t)etherbroadcastaddr, (caddr_t)th->iso88025_dhost, - sizeof(etherbroadcastaddr)) == 0) + if (bcmp((caddr_t)etherbroadcastaddr, (caddr_t)th->iso88025_dhost, sizeof(etherbroadcastaddr)) == 0) m->m_flags |= M_BCAST; else m->m_flags |= M_MCAST; @@ -370,13 +395,10 @@ iso88025_input(ifp, th, m) ether_type = ntohs(l->llc_un.type_snap.ether_type); - /*printf("iso88025_input: source %6D dest %6D ethertype %x\n", th->iso88025_shost, ":", th->iso88025_dhost, ":", ether_type);*/ - switch (ether_type) { #ifdef INET case ETHERTYPE_IP: - /*printf("iso88025_input: IP Packet\n");*/ - th->iso88025_shost[0] &= ~(0x80); /* Turn off source route bit XXX */ + th->iso88025_shost[0] &= ~(TR_RII); if (ipflow_fastforward(m)) return; schednetisr(NETISR_IP); @@ -384,7 +406,6 @@ iso88025_input(ifp, th, m) break; case ETHERTYPE_ARP: - /*printf("iso88025_input: ARP Packet\n");*/ schednetisr(NETISR_ARP); inq = &arpintrq; break; @@ -401,6 +422,5 @@ iso88025_input(ifp, th, m) printf("iso88025_input: Packet dropped (Queue full).\n"); } else IF_ENQUEUE(inq, m); - /*printf("iso88025_input: Packet queued.\n");*/ splx(s); } diff --git a/sys/net/iso88025.h b/sys/net/iso88025.h index ccb16e1..b77327b 100644 --- a/sys/net/iso88025.h +++ b/sys/net/iso88025.h @@ -44,26 +44,37 @@ #define _NET_ISO88025_H_ /* - * The number of bytes in an iso 802.5 (MAC) address. + * General ISO 802.5 definitions */ #define ISO88025_ADDR_LEN 6 +#define ISO88025_HDR_LEN (ISO88025_CF_LEN + (ISO88025_ADDR_LEN * 2)) +#define ISO88025_CF_LEN 2 +#define RCF_LEN 2 +#define RIF_MAX_RD 14 +#define RIF_MAX_LEN 16 -/* - */ -#define ISO88025_HDR_LEN (ISO88025_CF_LEN + ISO88025_ADDR_LEN*2) -#define ISO88025_CF_LEN 2 -#define RCF_LEN 2 -#define RIF_LEN 16 +#define TR_AC 0x10 +#define TR_LLC_FRAME 0x40 +#define TR_4MBPS 4000000 +#define TR_16MBPS 16000000 +#define TR_100MBPS 100000000 /* - * The minimum packet length. + * Source routing */ -#define ISO88025_MIN_LEN 0 /* This offends my morality */ +#define TR_RII 0x80 +#define TR_RCF_BCST_MASK 0xe000 +#define TR_RCF_LEN_MASK 0x1f00 +#define TR_RCF_DIR 0x0080 +#define TR_RCF_LF_MASK 0x0070 + +#define TR_RCF_RIFLEN(x) ((ntohs(x) & TR_RCF_LEN_MASK) >> 8) /* - * The maximum packet length. + * Minimum and maximum packet payload lengths. */ +#define ISO88025_MIN_LEN 0 #define ISO88025_MAX_LEN 17960 /* @@ -73,15 +84,15 @@ ((foo) >= ISO88025_MIN_LEN && (foo) <= ISO88025_MAX_LEN) /* - * ISO 802.5 physical header + * ISO 802.5 physical header */ struct iso88025_header { - u_char ac; /* access control field */ - u_char fc; /* frame control field */ - u_char iso88025_dhost[ISO88025_ADDR_LEN]; /* destination address */ - u_char iso88025_shost[ISO88025_ADDR_LEN]; /* source address */ - u_short rcf; /* route control field */ - u_short rseg[RIF_LEN]; /* routing registers */ + u_char ac; /* access control field */ + u_char fc; /* frame control field */ + u_char iso88025_dhost[ISO88025_ADDR_LEN]; /* destination address */ + u_char iso88025_shost[ISO88025_ADDR_LEN]; /* source address */ + u_short rcf; /* route control field */ + u_short rd[RIF_MAX_RD]; /* routing designators */ }; struct iso88025_sockaddr_data { @@ -99,14 +110,13 @@ struct iso88025_addr { u_char octet[ISO88025_ADDR_LEN]; }; -#define ISO88025MTU 18000 -#define ISO88025_DEFAULT_MTU 1500 +#define ISO88025_MAX_MTU 18000 +#define ISO88025_DEFAULT_MTU 1500 #define senderr(e) { error = (e); goto bad;} -void iso88025_ifattach __P((struct ifnet *)); -int iso88025_ioctl __P((struct ifnet *, int , caddr_t )); -int iso88025_output __P((struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *)); -void iso88025_input __P((struct ifnet *, struct iso88025_header *, struct mbuf *)); - +void iso88025_ifattach __P((struct ifnet *)); +int iso88025_ioctl __P((struct ifnet *, int , caddr_t )); +int iso88025_output __P((struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *)); +void iso88025_input __P((struct ifnet *, struct iso88025_header *, struct mbuf *)); #endif -- cgit v1.1