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 <nms@otdel-1.org>
This commit is contained in:
Larry Lile 2000-03-19 21:34:39 +00:00
parent e6fdad5c40
commit b149dd6c66
3 changed files with 129 additions and 98 deletions

View File

@ -83,17 +83,16 @@
#include <net/iso88025.h>
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 @@ iso88025_output(ifp, m, dst, rt0)
* 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");*/
/*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);
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 -= 8;
m->m_len -= 8;
m->m_data += 8; /* Length of LLC header in our case */
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);
}

View File

@ -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 TR_AC 0x10
#define TR_LLC_FRAME 0x40
#define TR_4MBPS 4000000
#define TR_16MBPS 16000000
#define TR_100MBPS 100000000
/*
* Source routing
*/
#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_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 minimum packet length.
*/
#define ISO88025_MIN_LEN 0 /* This offends my morality */
/*
* 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

View File

@ -58,6 +58,7 @@
#include <net/if_types.h>
#include <net/route.h>
#include <net/netisr.h>
#include <net/if_llc.h>
#include <netinet/in.h>
#include <netinet/in_var.h>
@ -290,23 +291,24 @@ arprequest(ac, sip, tip, enaddr)
register struct ether_header *eh;
register struct ether_arp *ea;
struct sockaddr sa;
static u_char llcx[] = { 0x82, 0x40, LLC_SNAP_LSAP, LLC_SNAP_LSAP,
LLC_UI, 0x00, 0x00, 0x00, 0x08, 0x06 };
if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL)
return;
m->m_pkthdr.rcvif = (struct ifnet *)0;
switch (ac->ac_if.if_type) {
case IFT_ISO88025:
m->m_len = sizeof(*ea) + 10;
m->m_pkthdr.len = sizeof(*ea) + 10;
MH_ALIGN(m, sizeof(*ea) + 10);
(void)memcpy(mtod(m, caddr_t),
"\x82\x40\xaa\xaa\x03\x00\x00\x00\x08\x06", 10);
m->m_len = sizeof(*ea) + sizeof(llcx);
m->m_pkthdr.len = sizeof(*ea) + sizeof(llcx);
MH_ALIGN(m, sizeof(*ea) + sizeof(llcx));
(void)memcpy(mtod(m, caddr_t), llcx, sizeof(llcx));
(void)memcpy(sa.sa_data, etherbroadcastaddr, 6);
(void)memcpy(sa.sa_data + 6, enaddr, 6);
sa.sa_data[6] |= 0x80;
sa.sa_data[12] = 0x10;
sa.sa_data[13] = 0x40;
ea = (struct ether_arp *)(mtod(m, char *) + 10);
sa.sa_data[6] |= TR_RII;
sa.sa_data[12] = TR_AC;
sa.sa_data[13] = TR_LLC_FRAME;
ea = (struct ether_arp *)(mtod(m, char *) + sizeof(llcx));
bzero((caddr_t)ea, sizeof (*ea));
ea->arp_hrd = htons(ARPHRD_IEEE802);
break;
@ -511,7 +513,7 @@ in_arpinput(m)
struct sockaddr_dl *sdl;
struct sockaddr sa;
struct in_addr isaddr, itaddr, myaddr;
int op;
int op, rif_len;
ea = mtod(m, struct ether_arp *);
op = ntohs(ea->arp_op);
@ -587,7 +589,7 @@ in_arpinput(m)
}
(void)memcpy(LLADDR(sdl), ea->arp_sha, sizeof(ea->arp_sha));
sdl->sdl_alen = sizeof(ea->arp_sha);
sdl->sdl_rcf = NULL;
sdl->sdl_rcf = (u_short)0;
/*
* If we receive an arp from a token-ring station over
* a token-ring nic then try to save the source
@ -595,30 +597,29 @@ in_arpinput(m)
*/
if (ac->ac_if.if_type == IFT_ISO88025) {
th = (struct iso88025_header *)m->m_pkthdr.header;
if ((th->iso88025_shost[0] & 0x80) &&
((th->rcf & 0x001f) > 2)) {
sdl->sdl_rcf = (th->rcf & 0x8000) ?
(th->rcf & 0x7fff) :
(th->rcf | 0x8000);
memcpy(sdl->sdl_route, th->rseg,
(th->rcf & 0x001f) - 2);
sdl->sdl_rcf = sdl->sdl_rcf & 0xff1f;
rif_len = TR_RCF_RIFLEN(th->rcf);
if ((th->iso88025_shost[0] & TR_RII) &&
(rif_len > 2)) {
sdl->sdl_rcf = th->rcf;
sdl->sdl_rcf ^= htons(TR_RCF_DIR);
memcpy(sdl->sdl_route, th->rd, rif_len - 2);
sdl->sdl_rcf &= ~htons(TR_RCF_BCST_MASK);
/*
* Set up source routing information for
* reply packet (XXX)
*/
m->m_data -= (th->rcf & 0x001f);
m->m_len += (th->rcf & 0x001f);
m->m_pkthdr.len += (th->rcf & 0x001f);
m->m_data -= rif_len;
m->m_len += rif_len;
m->m_pkthdr.len += rif_len;
} else {
th->iso88025_shost[0] &= 0x7f;
th->iso88025_shost[0] &= ~TR_RII;
}
m->m_data -= 8;
m->m_len += 8;
m->m_pkthdr.len += 8;
th->rcf = sdl->sdl_rcf;
} else {
sdl->sdl_rcf = NULL;
sdl->sdl_rcf = (u_short)0;
}
if (rt->rt_expire)
rt->rt_expire = time_second + arpt_keep;
@ -696,16 +697,16 @@ in_arpinput(m)
memcpy(th->iso88025_shost, ac->ac_enaddr,
sizeof(th->iso88025_shost));
/* Set the source routing bit if neccesary */
if (th->iso88025_dhost[0] & 0x80) {
th->iso88025_dhost[0] &= 0x7f;
if ((th->rcf & 0x001f) - 2)
th->iso88025_shost[0] |= 0x80;
if (th->iso88025_dhost[0] & TR_RII) {
th->iso88025_dhost[0] &= ~TR_RII;
if (TR_RCF_RIFLEN(th->rcf) > 2)
th->iso88025_shost[0] |= TR_RII;
}
/* Copy the addresses, ac and fc into sa_data */
memcpy(sa.sa_data, th->iso88025_dhost,
sizeof(th->iso88025_dhost) * 2);
sa.sa_data[(sizeof(th->iso88025_dhost) * 2)] = 0x10;
sa.sa_data[(sizeof(th->iso88025_dhost) * 2) + 1] = 0x40;
sa.sa_data[(sizeof(th->iso88025_dhost) * 2)] = TR_AC;
sa.sa_data[(sizeof(th->iso88025_dhost) * 2) + 1] = TR_LLC_FRAME;
break;
case IFT_ETHER:
case IFT_FDDI: