* Copyright (c) 1991 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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
* from: @(#)if_eon.c 7.16 (Berkeley) 6/27/91
* $Id: if_eon.c,v 1.4 1993/11/25 01:35:54 wollman Exp $
/***********************************************************
Copyright IBM Corporation 1987
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of IBM not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
******************************************************************/
* ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
* Layer between IP and CLNL
* Put together a current rfc986 address format and get the right offset
#include "../net/if_types.h"
#include "../net/if_dl.h"
#include "../net/netisr.h"
#include "../net/route.h"
#include "machine/mtpr.h"
#include "../netinet/in.h"
#include "../netinet/in_systm.h"
#include "../netinet/in_var.h"
#include "../netinet/ip.h"
#include "../netinet/ip_var.h"
#include "../netinet/if_ether.h"
extern struct timeval time
;
extern struct ifnet loif
;
void eoninput(struct mbuf
*, int);
static int eonoutput(struct ifnet
*, struct mbuf
*, struct sockaddr
*, struct rtentry
*);
static int eonioctl(struct ifnet
*, int, caddr_t
);
static void eonattach(void);
static void eoninit(int);
static void eonrtrequest(int, struct rtentry
*, struct sockaddr
*);
struct eon_llinfo eon_llinfo
;
* PURPOSE: autoconf attach routine
register struct ifnet
*ifp
= eonif
;
/* since everything will go out over ether or token ring */
ifp
->if_ioctl
= eonioctl
;
ifp
->if_output
= eonoutput
;
ifp
->if_hdrlen
= EONIPLEN
;
ifp
->if_flags
= IFF_BROADCAST
;
eonioctl(ifp
, SIOCSIFADDR
, (caddr_t
)ifp
->if_addrlist
);
eon_llinfo
.el_qhdr
.link
=
eon_llinfo
.el_qhdr
.rlink
= &(eon_llinfo
.el_qhdr
);
* PURPOSE: io controls - ifconfig
* link-UP (core addr) (flags: ES, IS)
* link-DOWN (core addr) (flags: ES, IS)
* must be callable from kernel or user
register struct ifnet
*ifp
;
printf("eonioctl (cmd 0x%x) \n", cmd
);
register struct ifaddr
*ifa
;
if (ifa
= (struct ifaddr
*)data
) {
if (ifa
->ifa_addr
->sa_family
!= AF_LINK
)
ifa
->ifa_rtrequest
= eonrtrequest
;
ifa
->ifa_llinfolen
= sizeof(struct eon_llinfo
);
eoniphdr(hdr
, loc
, ro
, class, zero
)
register struct eon_iphdr
*hdr
;
register struct sockaddr_in
*sin
= (struct sockaddr_in
*)&ro
->ro_dst
;
bzero((caddr_t
)hdr
, sizeof (*hdr
));
bzero((caddr_t
)ro
, sizeof (*ro
));
sin
->sin_family
= AF_INET
;
sin
->sin_len
= sizeof (*sin
);
bcopy(loc
, (caddr_t
)&sin
->sin_addr
, sizeof(struct in_addr
));
* If there is a cached route,
* check that it is to the same destination
* and is still up. If not, free it and try again.
struct sockaddr_in
*dst
=
(struct sockaddr_in
*)rt_key(ro
->ro_rt
);
if ((ro
->ro_rt
->rt_flags
& RTF_UP
) == 0 ||
sin
->sin_addr
.s_addr
!= dst
->sin_addr
.s_addr
) {
ro
->ro_rt
= (struct rtentry
*)0;
hdr
->ei_ip
.ip_dst
= sin
->sin_addr
;
hdr
->ei_ip
.ip_p
= IPPROTO_EON
;
hdr
->ei_ip
.ip_ttl
= MAXTTL
;
hdr
->ei_eh
.eonh_class
= class;
hdr
->ei_eh
.eonh_vers
= EON_VERSION
;
hdr
->ei_eh
.eonh_csum
= 0;
mhead
.m_data
= (caddr_t
) &hdr
->ei_eh
;
mhead
.m_len
= sizeof(struct eon_hdr
);
printf("eonoutput : gen csum (0x%x, offset %d, datalen %d)\n",
_offsetof(struct eon_hdr
, eonh_csum
), sizeof(struct eon_hdr
));
_offsetof(struct eon_hdr
, eonh_csum
), sizeof(struct eon_hdr
));
* PURPOSE: maintains list of direct eon recipients.
* sets up IP route for rest.
eonrtrequest(cmd
, rt
, gate
)
register struct rtentry
*rt
;
register struct sockaddr
*gate
;
unsigned long zerodst
= 0;
caddr_t ipaddrloc
= (caddr_t
) &zerodst
;
register struct eon_llinfo
*el
= (struct eon_llinfo
*)rt
->rt_llinfo
;
if (el
->el_iproute
.ro_rt
)
RTFREE(el
->el_iproute
.ro_rt
);
rt
->rt_rmx
.rmx_mtu
= loif
.if_mtu
; /* unless better below */
R_Malloc(el
, struct eon_llinfo
*, sizeof(*el
));
rt
->rt_llinfo
= (caddr_t
)el
;
insque(&(el
->el_qhdr
), &eon_llinfo
.el_qhdr
);
if (gate
|| (gate
= rt
->rt_gateway
)) switch (gate
->sa_family
) {
#define SDL(x) ((struct sockaddr_dl *)x)
if (SDL(gate
)->sdl_alen
= 1)
el
->el_snpaoffset
= *(u_char
*)LLADDR(SDL(gate
));
ipaddrloc
= LLADDR(SDL(gate
));
#define SIN(x) ((struct sockaddr_in *)x)
ipaddrloc
= (caddr_t
) &SIN(gate
)->sin_addr
;
eoniphdr(&el
->el_ei
, ipaddrloc
, &el
->el_iproute
, EON_NORMAL_ADDR
, 0);
if (el
->el_iproute
.ro_rt
)
rt
->rt_rmx
.rmx_mtu
= el
->el_iproute
.ro_rt
->rt_rmx
.rmx_mtu
* PURPOSE: initialization
printf("eon driver-init eon%d\n", unit
);
* PURPOSE: prepend an eon header and hand to IP
* ARGUMENTS: (ifp) is points to the ifnet structure for this unit/device
* (m) is an mbuf *, *m is a CLNL packet
* (dst) is a destination address - have to interp. as
* multicast or broadcast or real address.
* RETURNS: unix error code
eonoutput(ifp
, m
, xdst
, rt
)
register struct mbuf
*m
; /* packet */
struct sockaddr_iso
*dst
= (struct sockaddr_iso
*)xdst
;
register struct eon_llinfo
*el
;
register struct eon_iphdr
*ei
;
int error
= 0, class = 0, alen
= 0;
static struct eon_iphdr eon_iphdr
;
static struct route route
;
ifp
->if_lastchange
= time
;
if (rt
== 0 || (el
= (struct eon_llinfo
*)rt
->rt_llinfo
) == 0) {
if (dst
->siso_family
== AF_LINK
) {
register struct sockaddr_dl
*sdl
= (struct sockaddr_dl
*)dst
;
} else if (dst
->siso_family
== AF_ISO
&& dst
->siso_data
[0] == AFI_SNA
) {
alen
= dst
->siso_nlen
- 1;
ipaddrloc
= (caddr_t
) dst
->siso_data
+ 1;
class = 4[(u_char
*)ipaddrloc
];
eoniphdr(ei
, ipaddrloc
, ro
, class, 1);
if ((el
->el_flags
& RTF_UP
) == 0) {
eonrtrequest(RTM_CHANGE
, rt
, (struct sockaddr
*)0);
if ((el
->el_flags
& RTF_UP
) == 0) {
if ((m
->m_flags
& M_PKTHDR
) == 0) {
printf("eon: got non headered packet\n");
if (dst
->siso_family
== AF_ISO
) {
bcopy((caddr_t
) &dst
->siso_data
[el
->el_snpaoffset
],
(caddr_t
) &ei
->ei_ip
.ip_dst
, sizeof(ei
->ei_ip
.ip_dst
));
/* put an eon_hdr in the buffer, prepended by an ip header */
datalen
= m
->m_pkthdr
.len
+ EONIPLEN
;
MGETHDR(mh
, M_DONTWAIT
, MT_HEADER
);
if(mh
== (struct mbuf
*)0)
MH_ALIGN(m
, sizeof(struct eon_iphdr
));
m
->m_len
= sizeof(struct eon_iphdr
);
(ei
->ei_ip
.ip_len
= (u_short
)(m
->m_pkthdr
.len
= datalen
));
*mtod(m
, struct eon_iphdr
*) = *ei
;
printf("eonoutput dst ip addr : %x\n", ei
->ei_ip
.ip_dst
.s_addr
);
printf("eonoutput ip_output : eonip header:\n");
dump_buf(ei
, sizeof(struct eon_iphdr
));
error
= ip_output(m
, (struct mbuf
*)0, ro
, 0);
ifp
->if_obytes
-= datalen
;
register struct eon_hdr
*eonhdr
;
register struct ip
*iphdr
;
eonifp
= &eonif
[0]; /* kludge - really want to give CLNP
* the ifp for eon, not for the real device
printf("eoninput() 0x%x m_data 0x%x m_len 0x%x dequeued\n",
m
, m
?m
->m_data
:0, m
?m
->m_len
:0);
if (iphlen
> sizeof (struct ip
))
ip_stripoptions(m
, (struct mbuf
*)0);
if (m
->m_len
< EONIPLEN
) {
if ((m
= m_pullup(m
, EONIPLEN
)) == 0) {
printf("eoninput: DROP \n" );
eonif
->if_ibytes
+= m
->m_pkthdr
.len
;
eonif
->if_lastchange
= time
;
iphdr
= mtod(m
, struct ip
*);
/* do a few checks for debugging */
if( iphdr
->ip_p
!= IPPROTO_EON
) {
/* temporarily drop ip header from the mbuf */
m
->m_data
+= sizeof(struct ip
);
eonhdr
= mtod(m
, struct eon_hdr
*);
if( iso_check_csum( m
, sizeof(struct eon_hdr
) ) != EOK
) {
m
->m_data
-= sizeof(struct ip
);
printf("eoninput csum ok class 0x%x\n", eonhdr
->eonh_class
);
printf("eoninput: eon header:\n");
dump_buf(eonhdr
, sizeof(struct eon_hdr
));
/* checks for debugging */
if( eonhdr
->eonh_vers
!= EON_VERSION
) {
m
->m_flags
&= ~(M_BCAST
|M_MCAST
);
switch( eonhdr
->eonh_class
) {
/* put it on the CLNP queue and set soft interrupt */
extern struct ifqueue clnlintrq
;
m
->m_pkthdr
.rcvif
= eonifp
; /* KLUDGE */
printf("eoninput to clnl IFQ\n");
"0x%x enqueued on clnp Q: m_len 0x%x m_type 0x%x m_data 0x%x\n",
m
, m
->m_len
, m
->m_type
, m
->m_data
);
dump_buf(mtod(m
, caddr_t
), m
->m_len
);
extern u_char inetctlerrmap
[];
printf("eonctlinput: cmd 0x%x addr: ", cmd
);
dump_isoaddr((struct sockaddr_iso
*)sin
);
if (cmd
< 0 || cmd
> PRC_NCMDS
)
/* TODO: set the dec bit */
case PRC_TIMXCEED_INTRANS
:
/* TODO: mark the link down */
case PRC_UNREACH_PROTOCOL
:
case PRC_UNREACH_SRCFAIL
:
case PRC_REDIRECT_TOSNET
:
case PRC_REDIRECT_TOSHOST
:
/* printf("eonctlinput: ICMP cmd 0x%x\n", cmd );*/