示例#1
0
static int
natm_usr_disconnect(struct socket *so)
{
	struct natmpcb *npcb;
	struct atmio_closevcc cl;
	struct ifnet *ifp;
	int error = 0;

	npcb = (struct natmpcb *)so->so_pcb;
	KASSERT(npcb != NULL, ("natm_usr_disconnect: npcb == NULL"));

	NATM_LOCK();
	if ((npcb->npcb_flags & NPCB_CONNECTED) == 0) {
		NATM_UNLOCK();
		printf("natm: disconnected check\n");
		return (EIO);
	}
	ifp = npcb->npcb_ifp;

	/*
	 * Disable rx.
	 *
	 * XXXRW: Eventually desirable to hold mutex over ioctl?
	 */
	cl.vpi = npcb->npcb_vpi;
	cl.vci = npcb->npcb_vci;
	NATM_UNLOCK();
	if (ifp->if_ioctl != NULL)
		ifp->if_ioctl(ifp, SIOCATMCLOSEVCC, (caddr_t)&cl);
	soisdisconnected(so);
	return (error);
}
示例#2
0
/*
 * natmintr: interrupt
 *
 * Note: we expect a socket pointer in rcvif rather than an interface
 * pointer.  We can get the interface pointer from the so's PCB if we really
 * need it.
 */
void
natmintr(struct mbuf *m)
{
	struct socket *so;
	struct natmpcb *npcb;

#ifdef DIAGNOSTIC
	M_ASSERTPKTHDR(m);
#endif

	NATM_LOCK();
	npcb = (struct natmpcb *)m->m_pkthdr.rcvif;	/* XXX: overloaded */
	so = npcb->npcb_socket;

	npcb->npcb_inq--;

	if (npcb->npcb_flags & NPCB_DRAIN) {
		if (npcb->npcb_inq == 0)
			free(npcb, M_PCB);			/* done! */
		NATM_UNLOCK();
		m_freem(m);
		return;
	}

	if (npcb->npcb_flags & NPCB_FREE) {
		NATM_UNLOCK();
		m_freem(m);					/* drop */
		return;
	}

#ifdef NEED_TO_RESTORE_IFP
	m->m_pkthdr.rcvif = npcb->npcb_ifp;
#else
#ifdef DIAGNOSTIC
	m->m_pkthdr.rcvif = NULL;	/* null it out to be safe */
#endif
#endif

	if (sbspace(&so->so_rcv) > m->m_pkthdr.len) {
#ifdef NATM_STAT
		natm_sookcnt++;
		natm_sookbytes += m->m_pkthdr.len;
#endif
		sbappendrecord(&so->so_rcv, m);
		sorwakeup(so);
		NATM_UNLOCK();
	} else {
#ifdef NATM_STAT
		natm_sodropcnt++;
		natm_sodropbytes += m->m_pkthdr.len;
#endif
		NATM_UNLOCK();
		m_freem(m);
	}
}
示例#3
0
static void
natm_usr_detach(struct socket *so)
{
	struct natmpcb *npcb;

	npcb = (struct natmpcb *)so->so_pcb;
	KASSERT(npcb != NULL, ("natm_usr_detach: npcb == NULL"));

	NATM_LOCK();
	npcb_free(npcb, NPCB_DESTROY);	/* drain */
	so->so_pcb = NULL;
	NATM_UNLOCK();
}
示例#4
0
static int
natm_usr_send(struct socket *so, int flags, struct mbuf *m, 
	struct sockaddr *nam, struct mbuf *control, struct thread *p)
{
	struct natmpcb *npcb;
	struct atm_pseudohdr *aph;
	int error = 0;
	int proto = so->so_proto->pr_protocol;

	npcb = (struct natmpcb *)so->so_pcb;
	KASSERT(npcb != NULL, ("natm_usr_send: npcb == NULL"));

	NATM_LOCK();
	if (control && control->m_len) {
		NATM_UNLOCK();
		m_freem(control);
		m_freem(m);
		return (EINVAL);
	}

	/*
	 * Send the data.  We must put an atm_pseudohdr on first.
	 */
	M_PREPEND(m, sizeof(*aph), M_DONTWAIT);
	if (m == NULL) {
		NATM_UNLOCK();
		m_freem(control);
		return (ENOBUFS);
	}
	aph = mtod(m, struct atm_pseudohdr *);
	ATM_PH_VPI(aph) = npcb->npcb_vpi;
	ATM_PH_SETVCI(aph, npcb->npcb_vci);
	ATM_PH_FLAGS(aph) = (proto == PROTO_NATMAAL5) ? ATM_PH_AAL5 : 0;
	error = atm_output(npcb->npcb_ifp, m, NULL, NULL);
	NATM_UNLOCK();
	return (error);
}
示例#5
0
static int
natm_usr_peeraddr(struct socket *so, struct sockaddr **nam)
{
	struct natmpcb *npcb;
	struct sockaddr_natm *snatm, ssnatm;

	npcb = (struct natmpcb *)so->so_pcb;
	KASSERT(npcb != NULL, ("natm_usr_peeraddr: npcb == NULL"));

	NATM_LOCK();
	snatm = &ssnatm;
	bzero(snatm, sizeof(*snatm));
	snatm->snatm_len = sizeof(*snatm);
	snatm->snatm_family = AF_NATM;
	strlcpy(snatm->snatm_if, npcb->npcb_ifp->if_xname,
	    sizeof(snatm->snatm_if));
	snatm->snatm_vci = npcb->npcb_vci;
	snatm->snatm_vpi = npcb->npcb_vpi;
	NATM_UNLOCK();
	*nam = sodupsockaddr((struct sockaddr *)snatm, M_WAITOK);
	return (0);
}
示例#6
0
/*
 * atm_rtrequest: handle ATM rt request (in support of generic code)
 *   inputs: "req" = request code
 *           "rt" = route entry
 *           "info" = rt_addrinfo
 */
void
atm_rtrequest(int req, struct rtentry *rt, struct rt_addrinfo *info)
{
	struct sockaddr *gate = rt->rt_gateway;
	struct atmio_openvcc op;
	struct atmio_closevcc cl;
	u_char *addr;
	u_int alen;
#ifdef NATM
	struct sockaddr_in *sin;
	struct natmpcb *npcb = NULL;
#endif
	static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};

	if (rt->rt_flags & RTF_GATEWAY)   /* link level requests only */
		return;

	switch (req) {

	case RTM_RESOLVE: /* resolve: only happens when cloning */
		printf("atm_rtrequest: RTM_RESOLVE request detected?\n");
		break;

	case RTM_ADD:
		/*
		 * route added by a command (e.g. ifconfig, route, arp...).
		 *
		 * first check to see if this is not a host route, in which
		 * case we are being called via "ifconfig" to set the address.
		 */
		if ((rt->rt_flags & RTF_HOST) == 0) {
			rt_setgate(rt,rt_key(rt),(struct sockaddr *)&null_sdl);
			gate = rt->rt_gateway;
			SDL(gate)->sdl_type = rt->rt_ifp->if_type;
			SDL(gate)->sdl_index = rt->rt_ifp->if_index;
			break;
		}

		if (gate->sa_family != AF_LINK ||
		    gate->sa_len < sizeof(null_sdl)) {
			log(LOG_DEBUG, "atm_rtrequest: bad gateway value");
			break;
		}

		KASSERT(rt->rt_ifp->if_ioctl != NULL,
		    ("atm_rtrequest: null ioctl"));

		/*
		 * Parse and verify the link level address as
		 * an open request
		 */
#ifdef NATM
		NATM_LOCK();
#endif
		bzero(&op, sizeof(op));
		addr = LLADDR(SDL(gate));
		alen = SDL(gate)->sdl_alen;
		if (alen < 4) {
			printf("%s: bad link-level address\n", __func__);
			goto failed;
		}

		if (alen == 4) {
			/* old type address */
			GET1BYTE(op.param.flags, addr, alen);
			GET1BYTE(op.param.vpi, addr, alen);
			GET2BYTE(op.param.vci, addr, alen);
			op.param.traffic = ATMIO_TRAFFIC_UBR;
			op.param.aal = (op.param.flags & ATM_PH_AAL5) ?
			    ATMIO_AAL_5 : ATMIO_AAL_0;
		} else {
			/* new address */
			op.param.aal = ATMIO_AAL_5;

			GET1BYTE(op.param.flags, addr, alen);
			op.param.flags &= ATM_PH_LLCSNAP;

			GET1BYTE(op.param.vpi, addr, alen);
			GET2BYTE(op.param.vci, addr, alen);

			GET1BYTE(op.param.traffic, addr, alen);

			switch (op.param.traffic) {

			  case ATMIO_TRAFFIC_UBR:
				if (alen >= 3)
					GET3BYTE(op.param.tparam.pcr,
					    addr, alen);
				break;

			  case ATMIO_TRAFFIC_CBR:
				if (alen < 3)
					goto bad_param;
				GET3BYTE(op.param.tparam.pcr, addr, alen);
				break;

			  case ATMIO_TRAFFIC_VBR:
				if (alen < 3 * 3)
					goto bad_param;
				GET3BYTE(op.param.tparam.pcr, addr, alen);
				GET3BYTE(op.param.tparam.scr, addr, alen);
				GET3BYTE(op.param.tparam.mbs, addr, alen);
				break;

			  case ATMIO_TRAFFIC_ABR:
				if (alen < 4 * 3 + 2 + 1 * 2 + 3)
					goto bad_param;
				GET3BYTE(op.param.tparam.pcr, addr, alen);
				GET3BYTE(op.param.tparam.mcr, addr, alen);
				GET3BYTE(op.param.tparam.icr, addr, alen);
				GET3BYTE(op.param.tparam.tbe, addr, alen);
				GET1BYTE(op.param.tparam.nrm, addr, alen);
				GET1BYTE(op.param.tparam.trm, addr, alen);
				GET2BYTE(op.param.tparam.adtf, addr, alen);
				GET1BYTE(op.param.tparam.rif, addr, alen);
				GET1BYTE(op.param.tparam.rdf, addr, alen);
				GET1BYTE(op.param.tparam.cdf, addr, alen);
				break;

			  default:
			  bad_param:
				printf("%s: bad traffic params\n", __func__);
				goto failed;
			}
		}
		op.param.rmtu = op.param.tmtu = rt->rt_ifp->if_mtu;
#ifdef NATM
		/*
		 * let native ATM know we are using this VCI/VPI
		 * (i.e. reserve it)
		 */
		sin = (struct sockaddr_in *) rt_key(rt);
		if (sin->sin_family != AF_INET)
			goto failed;
		npcb = npcb_add(NULL, rt->rt_ifp, op.param.vci,  op.param.vpi);
		if (npcb == NULL)
			goto failed;
		npcb->npcb_flags |= NPCB_IP;
		npcb->ipaddr.s_addr = sin->sin_addr.s_addr;
		/* XXX: move npcb to llinfo when ATM ARP is ready */
		rt->rt_llinfo = (caddr_t) npcb;
		rt->rt_flags |= RTF_LLINFO;
#endif
		/*
		 * let the lower level know this circuit is active
		 */
		op.rxhand = NULL;
		op.param.flags |= ATMIO_FLAG_ASYNC;
		if (rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMOPENVCC,
		    (caddr_t)&op) != 0) {
			printf("atm: couldn't add VC\n");
			goto failed;
		}

		SDL(gate)->sdl_type = rt->rt_ifp->if_type;
		SDL(gate)->sdl_index = rt->rt_ifp->if_index;

#ifdef NATM
		NATM_UNLOCK();
#endif
		break;

failed:
#ifdef NATM
		if (npcb) {
			npcb_free(npcb, NPCB_DESTROY);
			rt->rt_llinfo = NULL;
			rt->rt_flags &= ~RTF_LLINFO;
		}
		NATM_UNLOCK();
#endif
		/* mark as invalid. We cannot RTM_DELETE the route from
		 * here, because the recursive call to rtrequest1 does
		 * not really work. */
		rt->rt_flags |= RTF_REJECT;
		break;

	case RTM_DELETE:
#ifdef NATM
		/*
		 * tell native ATM we are done with this VC
		 */
		if (rt->rt_flags & RTF_LLINFO) {
			NATM_LOCK();
			npcb_free((struct natmpcb *)rt->rt_llinfo,
			    NPCB_DESTROY);
			rt->rt_llinfo = NULL;
			rt->rt_flags &= ~RTF_LLINFO;
			NATM_UNLOCK();
		}
#endif
		/*
		 * tell the lower layer to disable this circuit
		 */
		bzero(&op, sizeof(op));
		addr = LLADDR(SDL(gate));
		addr++;
		cl.vpi = *addr++;
		cl.vci = *addr++ << 8;
		cl.vci |= *addr++;
		(void)rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMCLOSEVCC,
		    (caddr_t)&cl);
		break;
	}
}
示例#7
0
static int
natm_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *p)
{
	struct natmpcb *npcb;
	struct sockaddr_natm *snatm;
	struct atmio_openvcc op;
	struct ifnet *ifp;
	int error = 0;
	int proto = so->so_proto->pr_protocol;

	npcb = (struct natmpcb *)so->so_pcb;
	KASSERT(npcb != NULL, ("natm_usr_connect: npcb == NULL"));

	/*
	 * Validate nam and npcb.
	 */
	NATM_LOCK();
	snatm = (struct sockaddr_natm *)nam;
	if (snatm->snatm_len != sizeof(*snatm) ||
		(npcb->npcb_flags & NPCB_FREE) == 0) {
		NATM_UNLOCK();
		return (EINVAL);
	}
	if (snatm->snatm_family != AF_NATM) {
		NATM_UNLOCK();
		return (EAFNOSUPPORT);
	}

	snatm->snatm_if[IFNAMSIZ - 1] = '\0';	/* XXX ensure null termination
						   since ifunit() uses strcmp */

	/*
	 * Convert interface string to ifp, validate.
	 */
	ifp = ifunit(snatm->snatm_if);
	if (ifp == NULL || (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
		NATM_UNLOCK();
		return (ENXIO);
	}
	if (ifp->if_output != atm_output) {
		NATM_UNLOCK();
		return (EAFNOSUPPORT);
	}

	/*
	 * Register us with the NATM PCB layer.
	 */
	if (npcb_add(npcb, ifp, snatm->snatm_vci, snatm->snatm_vpi) != npcb) {
		NATM_UNLOCK();
		return (EADDRINUSE);
	}

	/*
	 * Open the channel.
	 *
	 * XXXRW: Eventually desirable to hold mutex over ioctl?
	 */
	bzero(&op, sizeof(op));
	op.rxhand = npcb;
	op.param.flags = ATMIO_FLAG_PVC;
	op.param.vpi = npcb->npcb_vpi;
	op.param.vci = npcb->npcb_vci;
	op.param.rmtu = op.param.tmtu = ifp->if_mtu;
	op.param.aal = (proto == PROTO_NATMAAL5) ? ATMIO_AAL_5 : ATMIO_AAL_0;
	op.param.traffic = ATMIO_TRAFFIC_UBR;
	NATM_UNLOCK();

	if (ifp->if_ioctl == NULL || 
	    ifp->if_ioctl(ifp, SIOCATMOPENVCC, (caddr_t)&op) != 0)
		return (EIO);
	soisconnected(so);
	return (error);
}
示例#8
0
/*
 * Process a received ATM packet;
 * the packet is in the mbuf chain m.
 */
void
atm_input(struct ifnet *ifp, struct atm_pseudohdr *ah, struct mbuf *m,
    void *rxhand)
{
	int isr;
	u_int16_t etype = ETHERTYPE_IP;		/* default */

	if ((ifp->if_flags & IFF_UP) == 0) {
		m_freem(m);
		return;
	}
#ifdef MAC
	mac_ifnet_create_mbuf(ifp, m);
#endif
	ifp->if_ibytes += m->m_pkthdr.len;

	if (ng_atm_input_p != NULL) {
		(*ng_atm_input_p)(ifp, &m, ah, rxhand);
		if (m == NULL)
			return;
	}

	/* not eaten by ng_atm. Maybe it's a pseudo-harp PDU? */
	if (atm_harp_input_p != NULL) {
		(*atm_harp_input_p)(ifp, &m, ah, rxhand);
		if (m == NULL)
			return;
	}

	if (rxhand) {
#ifdef NATM
		struct natmpcb *npcb;

		/*
		 * XXXRW: this use of 'rxhand' is not a very good idea, and
		 * was subject to races even before SMPng due to the release
		 * of spl here.
		 */
		NATM_LOCK();
		npcb = rxhand;
		npcb->npcb_inq++;	/* count # in queue */
		isr = NETISR_NATM;
		m->m_pkthdr.rcvif = rxhand; /* XXX: overload */
		NATM_UNLOCK();
#else
		printf("atm_input: NATM detected but not "
		    "configured in kernel\n");
		goto dropit;
#endif
	} else {
		/*
		 * handle LLC/SNAP header, if present
		 */
		if (ATM_PH_FLAGS(ah) & ATM_PH_LLCSNAP) {
			struct atmllc *alc;

			if (m->m_len < sizeof(*alc) &&
			    (m = m_pullup(m, sizeof(*alc))) == 0)
				return; /* failed */
			alc = mtod(m, struct atmllc *);
			if (bcmp(alc, ATMLLC_HDR, 6)) {
				printf("%s: recv'd invalid LLC/SNAP frame "
				    "[vp=%d,vc=%d]\n", ifp->if_xname,
				    ATM_PH_VPI(ah), ATM_PH_VCI(ah));
				m_freem(m);
				return;
			}
			etype = ATM_LLC_TYPE(alc);
			m_adj(m, sizeof(*alc));
		}

		switch (etype) {

#ifdef INET
		case ETHERTYPE_IP:
			isr = NETISR_IP;
			break;
#endif

#ifdef INET6
		case ETHERTYPE_IPV6:
			isr = NETISR_IPV6;
			break;
#endif
		default:
#ifndef NATM
  dropit:
#endif
			if (ng_atm_input_orphan_p != NULL)
				(*ng_atm_input_orphan_p)(ifp, m, ah, rxhand);
			else
				m_freem(m);
			return;
		}
	}
	M_SETFIB(m, ifp->if_fib);
	netisr_dispatch(isr, m);
}