#include <sys/param.h>
#include <sys/types.h>
#include <sys/proc.h>
#include <sys/file.h>
#include <sys/user.h>
#include <sys/vnode.h>
#include <sys/errno.h>
#include <sys/stream.h>
#include <sys/ioctl.h>
#include <sys/stropts.h>
#include <sys/strsubr.h>
#include <sys/tihdr.h>
#include <sys/timod.h>
#include <sys/tiuser.h>
#include <sys/t_kuser.h>
#include <sys/strsun.h>
#include <inet/common.h>
#include <inet/mi.h>
#include <netinet/ip6.h>
#include <inet/ip.h>
extern int getiocseqno(void);
int
tli_send(TIUSER *tiptr, mblk_t *bp, int fmode)
{
vnode_t *vp;
int error;
vp = tiptr->fp->f_vnode;
error = kstrputmsg(vp, bp, NULL, 0, 0, MSG_BAND | MSG_HOLDSIG, fmode);
return (error);
}
int
tli_recv(TIUSER *tiptr, mblk_t **bp, int fmode)
{
vnode_t *vp;
int error;
uchar_t pri;
int pflag;
rval_t rval;
clock_t timout;
vp = tiptr->fp->f_vnode;
if (fmode & (FNDELAY|FNONBLOCK))
timout = 0;
else
timout = -1;
pflag = MSG_ANY;
pri = 0;
*bp = NULL;
error = kstrgetmsg(vp, bp, NULL, &pri, &pflag, timout, &rval);
if (error == ETIME)
error = EAGAIN;
return (error);
}
int
get_ok_ack(TIUSER *tiptr, int type, int fmode)
{
int msgsz;
union T_primitives *pptr;
mblk_t *bp;
int error;
error = 0;
bp = NULL;
if ((error = tli_recv(tiptr, &bp, fmode)) != 0)
return (error);
if ((msgsz = (int)MBLKL(bp)) < sizeof (int)) {
freemsg(bp);
return (EPROTO);
}
pptr = (void *)bp->b_rptr;
switch (pptr->type) {
case T_OK_ACK:
if (msgsz < TOKACKSZ || pptr->ok_ack.CORRECT_prim != type)
error = EPROTO;
break;
case T_ERROR_ACK:
if (msgsz < TERRORACKSZ) {
error = EPROTO;
break;
}
if (pptr->error_ack.TLI_error == TSYSERR)
error = pptr->error_ack.UNIX_error;
else
error = t_tlitosyserr(pptr->error_ack.TLI_error);
break;
default:
error = EPROTO;
break;
}
freemsg(bp);
return (error);
}
static const int tli_errs[] = {
0,
EADDRNOTAVAIL,
ENOPROTOOPT,
EACCES,
EBADF,
EADDRNOTAVAIL,
EPROTO,
EPROTO,
0,
EPROTO,
EMSGSIZE,
EMSGSIZE,
EPROTO,
EWOULDBLOCK,
EPROTO,
EPROTO,
EINVAL,
EPROTO,
EOPNOTSUPP,
EPROTO,
};
int
t_tlitosyserr(int terr)
{
if (terr < 0 || (terr >= (sizeof (tli_errs) / sizeof (tli_errs[0]))))
return (EPROTO);
else
return (tli_errs[terr]);
}
void
t_kadvise(TIUSER *tiptr, uchar_t *addr, int addr_len)
{
file_t *fp;
vnode_t *vp;
struct iocblk *iocp;
ipid_t *ipid;
mblk_t *mp;
fp = tiptr->fp;
vp = fp->f_vnode;
mp = mkiocb(IP_IOCTL);
if (!mp)
return;
iocp = (void *)mp->b_rptr;
iocp->ioc_count = sizeof (ipid_t) + addr_len;
mp->b_cont = allocb(iocp->ioc_count, BPRI_HI);
if (!mp->b_cont) {
freeb(mp);
return;
}
ipid = (void *)mp->b_cont->b_rptr;
mp->b_cont->b_wptr += iocp->ioc_count;
bzero(ipid, sizeof (*ipid));
ipid->ipid_cmd = IP_IOC_IRE_DELETE_NO_REPLY;
ipid->ipid_ire_type = 0;
ipid->ipid_addr_offset = sizeof (ipid_t);
ipid->ipid_addr_length = addr_len;
bcopy(addr, &ipid[1], addr_len);
(void) kstrputmsg(vp, mp, NULL, 0, 0,
MSG_BAND | MSG_IGNFLOW | MSG_HOLDSIG | MSG_IGNERROR, 0);
}
#ifdef KTLIDEBUG
int ktlilog = 0;
int
ktli_log(int level, char *str, int a1)
{
if (level & ktlilog)
printf(str, a1);
}
#endif